3 #include "SearchExpr.h"
8 #include "libs/common/StringFunctions.h"
13 static char THIS_FILE[] = __FILE__;
16 #define YY_NEVER_INTERACTIVE 1
18 extern int yyerror(const char* errstr);
19 extern int yyerror(wxString errstr);
21 #define YY_INPUT ReadLexBuff
22 #define YY_FATAL_ERROR FatalLexError
24 static void ReadLexBuff(char* pcBuff, int& riResult, size_t uMaxSize);
25 static void FatalLexError(yyconst char msg[]);
27 static char* _pszLexBuff;
28 static char* _pszLexStr;
38 [ ] { /* Skip blanks. */ }
39 "OR" { return TOK_OR; }
40 "AND" { return TOK_AND; }
41 "NOT" { return TOK_NOT; }
43 "ed2k::"[a-fA-F0-9]{32} {
44 yylval.pstr = new wxString(UTF82unicode(yytext));
49 yylval.pstr = new wxString(UTF82unicode(yytext));
55 char* psz = (char*)malloc(l);
58 while ((c = yyinput()) != '\"')
60 if (c == EOF || c == '\n'){
62 yyerror(wxT("Search expression error: unterminated string"));
65 if (c == '\\'){ /*Escape sequence*/
66 switch (c = yyinput())
73 case 'n': /*Linefeed*/
76 case 'f': /*Formfeed*/
79 case 'r': /*Carriage return*/
82 case '\\': /*Backslash*/
85 case '"': /*Double quotation mark*/
88 case '\'': /*Single quotation mark*/
91 case '?': /*Question mark*/
94 case 'v': /*Vertical Tab*/
100 case 'b': /*Backspace*/
103 case 'x': /*Hexadecimal number*/
106 for (n = 1, octv = 0; n <= 3; n++) {
107 if ((c = yyinput()) >= '0' && c <= '9')
109 else if (c >= 'a' && c <= 'f')
111 else if (c >= 'A' && c <= 'F')
115 octv = octv * 16 + c;
126 if ((unsigned char)c >= 0x80/* && IsDBCSLeadByte(yytext[0]) */){
127 psz[i++] = (unsigned char)c;
129 psz = (char*)realloc(psz, l += 128);
131 yyerror("Less memory for string");
139 psz[i++] = (unsigned char)c;
141 psz = (char*)realloc(psz, l += 128);
143 yyerror("Less memory for string");
149 yylval.pstr = new wxString(UTF82unicode(psz));
154 . { return yytext[0]; }
158 static void ReadLexBuff(char* pcBuff, int& riResult, size_t uMaxSize)
160 wxASSERT( _pszLexBuff != NULL );
162 if (_pszLexBuff == NULL) {
163 YY_FATAL_ERROR("Input in flex scanner failed");
166 wxASSERT( sizeof(YY_CHAR) == sizeof(char) );
167 size_t uCharsInBuff = strlen(_pszLexBuff);
168 size_t uCharsRead = min(uMaxSize, uCharsInBuff);
169 riResult = uCharsRead;
170 memcpy(pcBuff, _pszLexBuff, uCharsRead);
171 _pszLexBuff += uCharsRead;
174 static void FatalLexError(yyconst char msg[])
177 printf("Fatal error in flex scanner: %s\n", msg);
179 printf("Fatal error in flex scanner: %s\n", msg);
183 void LexInit(const wxString& pszInput)
185 _pszLexStr = strdup(unicode2UTF8(pszInput));
186 _pszLexBuff = _pszLexStr;
201 yy_did_buffer_switch_on_eof = 0;
202 yy_last_accepting_state = 0;
203 yy_last_accepting_cpos = NULL;
206 yy_start_stack_ptr = 0;
207 yy_start_stack_depth = 0;
208 yy_start_stack = NULL;