From edeb857c7760cdf3bfad668e3510b5a725979c92 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 11 May 2010 16:33:22 -0400 Subject: [PATCH] added I_TOKENLIST definition; build test now compiling --- Parser.cc | 11 +++++++++++ TokenDefinition.h | 1 + tmpl/parser.cc | 6 +++--- tmpl/parser.h | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Parser.cc b/Parser.cc index db5b9e4..d3fb7ec 100644 --- a/Parser.cc +++ b/Parser.cc @@ -47,6 +47,17 @@ bool Parser::write(const string & fname) writeDefine(header, "I_NAMESPACE", m_namespace); } writeDefine(header, "I_CLASSNAME", m_classname); + string tokenlist; + for (int i = 0; i < m_tokens.size(); i++) + { + if (i > 0) + tokenlist += " "; + tokenlist += "{\"" + m_tokens[i]->getName() + "\", \"" + + m_tokens[i]->getCString() + "\"}"; + if (i < m_tokens.size() - 1) + tokenlist += ", \\\n"; + } + writeDefine(header, "I_TOKENLIST", tokenlist); header << endl; header.write((const char *) tmpl_parser_h, tmpl_parser_h_len); diff --git a/TokenDefinition.h b/TokenDefinition.h index 7ee5a1c..003743e 100644 --- a/TokenDefinition.h +++ b/TokenDefinition.h @@ -10,6 +10,7 @@ class TokenDefinition bool create(const std::string & name, const std::string & definition, const std::string & flags); std::string getCString() const; + std::string getName() const { return m_name; } protected: std::string m_name; diff --git a/tmpl/parser.cc b/tmpl/parser.cc index e55697a..e03a327 100644 --- a/tmpl/parser.cc +++ b/tmpl/parser.cc @@ -36,8 +36,8 @@ static void read_istream(istream & i, vector & buff, int & size) bool I_CLASSNAME::parse(istream & i) { struct { - char * name; - char * definition; + const char * name; + const char * definition; pcre * re; pcre_extra * re_extra; } tokens[] = { @@ -93,7 +93,7 @@ bool I_CLASSNAME::parse(istream & i) for (int i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++) { int rc = pcre_exec(tokens[i].re, tokens[i].re_extra, - buff, buff_size, buff_pos, + &buff[0], buff_size, buff_pos, PCRE_ANCHORED | PCRE_NOTEMPTY, ovector, ovector_size); if (rc > 0) diff --git a/tmpl/parser.h b/tmpl/parser.h index 873ee72..1aff233 100644 --- a/tmpl/parser.h +++ b/tmpl/parser.h @@ -13,7 +13,7 @@ class I_CLASSNAME public: I_CLASSNAME(); bool parse(std::istream & in); - char * getError() { return m_errstr; } + const char * getError() { return m_errstr; } protected: const char * m_errstr;