3 #include "SearchExpr.h"
8 #include "libs/common/StringFunctions.h"
11 #define isatty(DUMMY) 0
17 static char THIS_FILE[] = __FILE__;
20 #define YY_NEVER_INTERACTIVE 1
22 extern int yyerror(const char* errstr);
23 extern int yyerror(wxString errstr);
25 #define YY_INPUT ReadLexBuff
26 #define YY_FATAL_ERROR FatalLexError
28 static void ReadLexBuff(char* pcBuff, int& riResult, size_t uMaxSize);
29 static void FatalLexError(yyconst char msg[]);
31 static char* _pszLexBuff;
32 static char* _pszLexStr;
42 [ ] { /* Skip blanks. */ }
43 "OR" { return TOK_OR; }
44 "AND" { return TOK_AND; }
45 "NOT" { return TOK_NOT; }
47 "ed2k::"[a-fA-F0-9]{32} {
48 yylval.pstr = new wxString(UTF82unicode(yytext));
53 yylval.pstr = new wxString(UTF82unicode(yytext));
59 char* psz = (char*)malloc(l);
62 while ((c = yyinput()) != '\"')
64 if (c == EOF || c == '\n'){
66 yyerror(wxT("Search expression error: unterminated string"));
69 if (c == '\\'){ /*Escape sequence*/
70 switch (c = yyinput())
77 case 'n': /*Linefeed*/
80 case 'f': /*Formfeed*/
83 case 'r': /*Carriage return*/
86 case '\\': /*Backslash*/
89 case '"': /*Double quotation mark*/
92 case '\'': /*Single quotation mark*/
95 case '?': /*Question mark*/
98 case 'v': /*Vertical Tab*/
104 case 'b': /*Backspace*/
107 case 'x': /*Hexadecimal number*/
110 for (n = 1, octv = 0; n <= 3; n++) {
111 if ((c = yyinput()) >= '0' && c <= '9')
113 else if (c >= 'a' && c <= 'f')
115 else if (c >= 'A' && c <= 'F')
119 octv = octv * 16 + c;
130 if ((unsigned char)c >= 0x80/* && IsDBCSLeadByte(yytext[0]) */){
131 psz[i++] = (unsigned char)c;
133 char *tmp = (char*)realloc(psz, l += 128);
135 yyerror("Less memory for string");
145 psz[i++] = (unsigned char)c;
147 char *tmp = (char*)realloc(psz, l += 128);
149 yyerror("Less memory for string");
157 yylval.pstr = new wxString(UTF82unicode(psz));
162 . { return yytext[0]; }
166 static void ReadLexBuff(char* pcBuff, int& riResult, size_t uMaxSize)
168 wxASSERT( _pszLexBuff != NULL );
170 if (_pszLexBuff == NULL) {
171 YY_FATAL_ERROR("Input in flex scanner failed");
174 wxASSERT( sizeof(YY_CHAR) == sizeof(char) );
175 size_t uCharsInBuff = strlen(_pszLexBuff);
176 size_t uCharsRead = min(uMaxSize, uCharsInBuff);
177 riResult = uCharsRead;
178 memcpy(pcBuff, _pszLexBuff, uCharsRead);
179 _pszLexBuff += uCharsRead;
182 static void FatalLexError(yyconst char msg[])
185 printf("Fatal error in flex scanner: %s\n", msg);
187 printf("Fatal error in flex scanner: %s\n", msg);
191 void LexInit(const wxString& pszInput)
193 _pszLexStr = strdup(unicode2UTF8(pszInput));
194 _pszLexBuff = _pszLexStr;
209 yy_did_buffer_switch_on_eof = 0;
210 yy_last_accepting_state = 0;
211 yy_last_accepting_cpos = NULL;
214 yy_start_stack_ptr = 0;
215 yy_start_stack_depth = 0;
216 yy_start_stack = NULL;