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 psz = (char*)realloc(psz, l += 128);
135 yyerror("Less memory for string");
143 psz[i++] = (unsigned char)c;
145 psz = (char*)realloc(psz, l += 128);
147 yyerror("Less memory for string");
153 yylval.pstr = new wxString(UTF82unicode(psz));
158 . { return yytext[0]; }
162 static void ReadLexBuff(char* pcBuff, int& riResult, size_t uMaxSize)
164 wxASSERT( _pszLexBuff != NULL );
166 if (_pszLexBuff == NULL) {
167 YY_FATAL_ERROR("Input in flex scanner failed");
170 wxASSERT( sizeof(YY_CHAR) == sizeof(char) );
171 size_t uCharsInBuff = strlen(_pszLexBuff);
172 size_t uCharsRead = min(uMaxSize, uCharsInBuff);
173 riResult = uCharsRead;
174 memcpy(pcBuff, _pszLexBuff, uCharsRead);
175 _pszLexBuff += uCharsRead;
178 static void FatalLexError(yyconst char msg[])
181 printf("Fatal error in flex scanner: %s\n", msg);
183 printf("Fatal error in flex scanner: %s\n", msg);
187 void LexInit(const wxString& pszInput)
189 _pszLexStr = strdup(unicode2UTF8(pszInput));
190 _pszLexBuff = _pszLexStr;
205 yy_did_buffer_switch_on_eof = 0;
206 yy_last_accepting_state = 0;
207 yy_last_accepting_cpos = NULL;
210 yy_start_stack_ptr = 0;
211 yy_start_stack_depth = 0;
212 yy_start_stack = NULL;