reworked argument handling slightly, added --extension

This commit is contained in:
Josh Holtrop 2010-04-29 15:40:07 -04:00
parent 9720ea001f
commit 6d3a5403c3
3 changed files with 14 additions and 8 deletions

View File

@ -15,7 +15,7 @@
using namespace std; using namespace std;
Parser::Parser() Parser::Parser()
: m_classname("Parser"), m_namespace("") : m_classname("Parser"), m_namespace(""), m_extension("cc")
{ {
} }

View File

@ -23,16 +23,22 @@ class Parser
} }
void write(const std::string & fname); void 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; }
std::string getClassName() { return m_classname; } std::string getClassName() { return m_classname; }
void setNamespace(const std::string & ns) { m_namespace = ns; } void setNamespace(const std::string & ns) { m_namespace = ns; }
std::string getNamespace() { return m_namespace; } std::string getNamespace() { return m_namespace; }
void setExtension(const std::string & e) { m_extension = e; }
std::string getExtension() { return m_extension; }
protected: protected:
std::vector< refptr< TokenDefinition > > m_tokens; std::vector< refptr< TokenDefinition > > m_tokens;
std::vector< refptr< RuleDefinition > > m_rules; std::vector< refptr< RuleDefinition > > m_rules;
std::string m_classname; std::string m_classname;
std::string m_namespace; std::string m_namespace;
std::string m_extension;
}; };
#endif #endif

View File

@ -15,13 +15,13 @@ int main(int argc, char * argv[])
{ {
int longind = 1; int longind = 1;
int opt; int opt;
Parser p;
string outfile; string outfile;
string classname = "Parser";
string namespace_name = "";
static struct option longopts[] = { static struct option longopts[] = {
/* name, has_arg, flag, val */ /* name, has_arg, flag, val */
{ "classname", required_argument, NULL, 'c' }, { "classname", required_argument, NULL, 'c' },
{ "extension", required_argument, NULL, 'e' },
{ "namespace", required_argument, NULL, 'n' }, { "namespace", required_argument, NULL, 'n' },
{ "outfile", required_argument, NULL, 'o' }, { "outfile", required_argument, NULL, 'o' },
{ NULL, 0, NULL, 0 } { NULL, 0, NULL, 0 }
@ -32,10 +32,13 @@ int main(int argc, char * argv[])
switch (opt) switch (opt)
{ {
case 'c': /* classname */ case 'c': /* classname */
classname = optarg; p.setClassName(optarg);
break;
case 'e': /* extension */
p.setExtension(optarg);
break; break;
case 'n': /* namespace */ case 'n': /* namespace */
namespace_name = optarg; p.setNamespace(optarg);
break; break;
case 'o': /* outfile */ case 'o': /* outfile */
outfile = optarg; outfile = optarg;
@ -67,9 +70,6 @@ int main(int argc, char * argv[])
if (outfile == "") if (outfile == "")
outfile = buildOutputFilename(input_fname); outfile = buildOutputFilename(input_fname);
Parser p;
p.setClassName(classname);
p.setNamespace(namespace_name);
p.parseInputFile(buff, size); p.parseInputFile(buff, size);
p.write(outfile); p.write(outfile);