diff --git a/Parser.cc b/Parser.cc index 1e1b066..db5b9e4 100644 --- a/Parser.cc +++ b/Parser.cc @@ -30,10 +30,14 @@ static void writeDefine(ostream & out, out << "#define " << defname << " " << definition << endl; } -void Parser::write(const string & fname) +bool Parser::write(const string & fname) { + if (m_tokens.size() < 1 || m_rules.size() < 1) + return false; + string header_fname = fname + ".h"; string body_fname = fname + "." + m_extension; + ofstream header(header_fname.c_str()); ofstream body(body_fname.c_str()); @@ -53,6 +57,7 @@ void Parser::write(const string & fname) header.close(); body.close(); + return true; } bool Parser::parseInputFile(char * buff, int size) diff --git a/Parser.h b/Parser.h index 76e605f..10360a4 100644 --- a/Parser.h +++ b/Parser.h @@ -21,7 +21,7 @@ class Parser { m_rules.push_back(rd); } - void write(const std::string & fname); + bool write(const std::string & fname); bool parseInputFile(char * buff, int size); void setClassName(const std::string & cn) { m_classname = cn; } diff --git a/imbecile.cc b/imbecile.cc index cb5178b..4c73587 100644 --- a/imbecile.cc +++ b/imbecile.cc @@ -49,7 +49,7 @@ int main(int argc, char * argv[]) if (optind >= argc) { cerr << "Usage: imbecile [options] " << endl; - return 2; + return 1; } string input_fname = argv[optind]; @@ -70,8 +70,16 @@ int main(int argc, char * argv[]) if (outfile == "") outfile = buildOutputFilename(input_fname); - p.parseInputFile(buff, size); - p.write(outfile); + if (!p.parseInputFile(buff, size)) + { + cerr << "Error parsing " << input_fname << endl; + return 3; + } + if (!p.write(outfile)) + { + cerr << "Error processing " << input_fname << endl; + return 4; + } delete[] buff; return 0;