From 2b23657a0c6e2d7d398b56d3f0409a128083cee5 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Wed, 28 Apr 2010 17:27:36 -0400 Subject: [PATCH] changed "outfile" parameter to be a base name, added "classname" parameter --- Parser.cc | 1 + Parser.h | 3 +++ imbecile.cc | 32 +++++++++++++++++++++----------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Parser.cc b/Parser.cc index 70de09e..61a26ef 100644 --- a/Parser.cc +++ b/Parser.cc @@ -15,6 +15,7 @@ using namespace std; Parser::Parser() + : m_classname("Parser") { } diff --git a/Parser.h b/Parser.h index 8f489cc..7c04fea 100644 --- a/Parser.h +++ b/Parser.h @@ -23,10 +23,13 @@ class Parser } void write(const std::string & fname); bool parseInputFile(char * buff, int size); + void setClassName(const std::string & cn) { m_classname = cn; } + std::string getClassName() { return m_classname; } protected: std::vector< refptr< TokenDefinition > > m_tokens; std::vector< refptr< RuleDefinition > > m_rules; + std::string m_classname; }; #endif diff --git a/imbecile.cc b/imbecile.cc index 3b85d00..4f108f6 100644 --- a/imbecile.cc +++ b/imbecile.cc @@ -15,10 +15,12 @@ int main(int argc, char * argv[]) { int longind = 1; int opt; - string output_fname; + string outfile; + string classname = "Parser"; static struct option longopts[] = { /* name, has_arg, flag, val */ + { "classname", required_argument, NULL, 'c' }, { "outfile", required_argument, NULL, 'o' }, { NULL, 0, NULL, 0 } }; @@ -27,12 +29,21 @@ int main(int argc, char * argv[]) { switch (opt) { + case 'c': /* classname */ + classname = optarg; + break; case 'o': /* outfile */ - output_fname = optarg; + outfile = optarg; break; } } + if (optind >= argc) + { + cerr << "Usage: imbecile [options] " << endl; + return 2; + } + string input_fname = argv[optind]; ifstream ifs; ifs.open(input_fname.c_str(), ios::binary); @@ -48,14 +59,13 @@ int main(int argc, char * argv[]) ifs.read(buff, size); ifs.close(); - if (output_fname == "") - output_fname = buildOutputFilename(input_fname); + if (outfile == "") + outfile = buildOutputFilename(input_fname); Parser p; - + p.setClassName(classname); p.parseInputFile(buff, size); - - p.write(output_fname); + p.write(outfile); delete[] buff; return 0; @@ -63,15 +73,15 @@ int main(int argc, char * argv[]) string buildOutputFilename(string & input_fname) { - string output_fname; + string outfile; size_t len = input_fname.length(); if (len > 2 && input_fname.substr(len - 2) == ".I") { - output_fname = input_fname.substr(0, len - 2) + ".cc"; + outfile = input_fname.substr(0, len - 2); } else { - output_fname = input_fname + ".cc"; + outfile = input_fname; } - return output_fname; + return outfile; }