Parser::write() returning status; main() catching errors from Parser::parseInputFile() and Parser::write()
This commit is contained in:
parent
1dcde61d10
commit
b27a900b96
@ -30,10 +30,14 @@ static void writeDefine(ostream & out,
|
|||||||
out << "#define " << defname << " " << definition << endl;
|
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 header_fname = fname + ".h";
|
||||||
string body_fname = fname + "." + m_extension;
|
string body_fname = fname + "." + m_extension;
|
||||||
|
|
||||||
ofstream header(header_fname.c_str());
|
ofstream header(header_fname.c_str());
|
||||||
ofstream body(body_fname.c_str());
|
ofstream body(body_fname.c_str());
|
||||||
|
|
||||||
@ -53,6 +57,7 @@ void Parser::write(const string & fname)
|
|||||||
|
|
||||||
header.close();
|
header.close();
|
||||||
body.close();
|
body.close();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Parser::parseInputFile(char * buff, int size)
|
bool Parser::parseInputFile(char * buff, int size)
|
||||||
|
2
Parser.h
2
Parser.h
@ -21,7 +21,7 @@ class Parser
|
|||||||
{
|
{
|
||||||
m_rules.push_back(rd);
|
m_rules.push_back(rd);
|
||||||
}
|
}
|
||||||
void write(const std::string & fname);
|
bool write(const std::string & fname);
|
||||||
bool parseInputFile(char * buff, int size);
|
bool parseInputFile(char * buff, int size);
|
||||||
|
|
||||||
void setClassName(const std::string & cn) { m_classname = cn; }
|
void setClassName(const std::string & cn) { m_classname = cn; }
|
||||||
|
14
imbecile.cc
14
imbecile.cc
@ -49,7 +49,7 @@ int main(int argc, char * argv[])
|
|||||||
if (optind >= argc)
|
if (optind >= argc)
|
||||||
{
|
{
|
||||||
cerr << "Usage: imbecile [options] <input-file>" << endl;
|
cerr << "Usage: imbecile [options] <input-file>" << endl;
|
||||||
return 2;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
string input_fname = argv[optind];
|
string input_fname = argv[optind];
|
||||||
@ -70,8 +70,16 @@ int main(int argc, char * argv[])
|
|||||||
if (outfile == "")
|
if (outfile == "")
|
||||||
outfile = buildOutputFilename(input_fname);
|
outfile = buildOutputFilename(input_fname);
|
||||||
|
|
||||||
p.parseInputFile(buff, size);
|
if (!p.parseInputFile(buff, size))
|
||||||
p.write(outfile);
|
{
|
||||||
|
cerr << "Error parsing " << input_fname << endl;
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
if (!p.write(outfile))
|
||||||
|
{
|
||||||
|
cerr << "Error processing " << input_fname << endl;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
delete[] buff;
|
delete[] buff;
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user