expanded parse() to compile all tokens, ready to match them
This commit is contained in:
parent
8cc4edfca3
commit
67c051c866
@ -10,6 +10,11 @@ using namespace std;
|
||||
namespace I_NAMESPACE {
|
||||
#endif
|
||||
|
||||
I_CLASSNAME::I_CLASSNAME()
|
||||
: m_errstr(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
static void read_istream(istream & i, vector<char> & buff, int & size)
|
||||
{
|
||||
size = 0;
|
||||
@ -27,19 +32,50 @@ static void read_istream(istream & i, vector<char> & buff, int & size)
|
||||
|
||||
bool I_CLASSNAME::parse(istream & i)
|
||||
{
|
||||
struct { char * name; char * definition; } tokens[] = {
|
||||
struct { char * name; char * definition; pcre * re; } tokens[] = {
|
||||
I_TOKENLIST
|
||||
};
|
||||
|
||||
vector<char> buff;
|
||||
int size;
|
||||
read_istream(i, buff, size);
|
||||
|
||||
if (size <= 0)
|
||||
if (sizeof(tokens)/sizeof(tokens[0]) == 0)
|
||||
{
|
||||
m_errstr = "No tokens defined";
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<char> buff;
|
||||
int buff_size;
|
||||
read_istream(i, buff, buff_size);
|
||||
|
||||
if (buff_size <= 0)
|
||||
{
|
||||
m_errstr = "0-length input string";
|
||||
return false;
|
||||
}
|
||||
|
||||
/* append trailing NUL byte for pcre functions */
|
||||
buff.push_back('\0');
|
||||
|
||||
/* compile all token regular expressions */
|
||||
for (int i = 0; i < sizeof(tokens)/sizeof(tokens[0]); i++)
|
||||
{
|
||||
char * errptr;
|
||||
int erroffset;
|
||||
tokens[i].re = pcre_compile(tokens[i].definition, PCRE_DOTALL,
|
||||
&errptr, &erroffset, NULL);
|
||||
if (tokens[i].re == NULL)
|
||||
{
|
||||
cerr << "Error compiling token '" << tokens[i].name
|
||||
<< "' regular expression at position " << erroffset
|
||||
<< ": " << errptr << endl;
|
||||
m_errstr = "Error in token regular expression";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int buff_pos = 0;
|
||||
while (buff_pos < buff_size)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef I_NAMESPACE
|
||||
|
@ -11,9 +11,12 @@ namespace I_NAMESPACE {
|
||||
class I_CLASSNAME
|
||||
{
|
||||
public:
|
||||
I_CLASSNAME();
|
||||
bool parse(std::istream & in);
|
||||
char * getError(); { return m_errstr; }
|
||||
|
||||
protected:
|
||||
char * m_errstr;
|
||||
};
|
||||
|
||||
#ifdef I_NAMESPACE
|
||||
|
Loading…
x
Reference in New Issue
Block a user