$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
From: Aaron (yilu_at_[hidden])
Date: 2005-08-26 19:54:28
I want to make a program to grep all symbols in header file,like:
#define CMD_BASE      0x10000000
#define CMD_GETFile   (CMD_BASE + 0X00000001) /* Get a file from srv*/
A singl symbole definition line will be extract to three parts:
1. symbol itself
2. the value of a symbol, it's a signed 32-bit value
3. comments about the symbol
I use the following pattern:
std::string ptn = "\\s*#define\\s+([^\\s]+)\\s+([^/]*)([^\r\n]*)";
I hope this pattern could do what I want, but when I use grep to do
the parsing, I got from above two lines:
what[1]:  CMD_BASE
what[2]:  
0x00001000#define CMD_GET_ALL_DOMAINNAME			(CMD_IS_BASE+0x1) 
you see, the match extend to the new line!
I noticed that when I use the same text, same pattern, doing the same
thing in a vbscript program, if I set "Global match" option, this
wouldn't happen. So, what's the counterpoint at boost::regex?
My code here:
bool OnGrepSingleLineSymbols(const
boost::match_results<std::string::const_iterator>& what)
{
    Symbol* sym = new Symbol;
    
    strcpy(sym->szSymbolName, what[1].str().c_str());
    strcpy(sym->szSymbolInfo, what[3].str().c_str());
    
    MakePretty(sym->szSymbolName);
    MakePretty(sym->szSymbolInfo);
    
    sym->nSymbolValue = ResolveMsgValue(sym->szSymbolName,
what[2].str());
    
    GetMsgSrv().AddSymbols(sym);
    return true;
}
void GrepSingleLineSymbols(CString& strSymContainer)
{
    //#define ARN_SUCCESS 0l 			//ARRON!'HAHA
    //#define Arn_error1  ARN_SUCCESS + 0X0F  //AARON ERROR1
    static std::string ptn =
"\\s*#define\\s+([^\\s]+)\\s+([^/]*)([^\r\n]*)";
    static boost::regex re(ptn);
    std::string::const_iterator start, end;
    std::string text = strSymContainer;
    start = text.begin();
    end = text.end();
    
    boost::regex_grep(OnGrepSingleLineSymbols, start, end, re);
}