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, size_t& riResult, size_t uMaxSize);
29 static void ReadLexBuff(char* pcBuff, int& riResult, size_t uMaxSize);
30 static void FatalLexError(yyconst char msg[]);
32 static char* _pszLexBuff;
33 static char* _pszLexStr;
43 [ ] { /* Skip blanks. */ }
44 "OR" { return TOK_OR; }
45 "AND" { return TOK_AND; }
46 "NOT" { return TOK_NOT; }
48 "ed2k::"[a-fA-F0-9]{32} {
49 yylval.pstr = new wxString(UTF82unicode(yytext));
54 yylval.pstr = new wxString(UTF82unicode(yytext));
60 char* psz = (char*)malloc(l);
63 while ((c = yyinput()) != '\"')
65 if (c == EOF || c == '\n'){
67 yyerror(wxT("Search expression error: unterminated string"));
70 if (c == '\\'){ /*Escape sequence*/
71 switch (c = yyinput())
78 case 'n': /*Linefeed*/
81 case 'f': /*Formfeed*/
84 case 'r': /*Carriage return*/
87 case '\\': /*Backslash*/
90 case '"': /*Double quotation mark*/
93 case '\'': /*Single quotation mark*/
96 case '?': /*Question mark*/
99 case 'v': /*Vertical Tab*/
105 case 'b': /*Backspace*/
108 case 'x': /*Hexadecimal number*/
111 for (n = 1, octv = 0; n <= 3; n++) {
112 if ((c = yyinput()) >= '0' && c <= '9')
114 else if (c >= 'a' && c <= 'f')
116 else if (c >= 'A' && c <= 'F')
120 octv = octv * 16 + c;
131 if ((unsigned char)c >= 0x80/* && IsDBCSLeadByte(yytext[0]) */){
132 psz[i++] = (unsigned char)c;
134 char *tmp = (char*)realloc(psz, l += 128);
136 yyerror("Less memory for string");
146 psz[i++] = (unsigned char)c;
148 char *tmp = (char*)realloc(psz, l += 128);
150 yyerror("Less memory for string");
158 yylval.pstr = new wxString(UTF82unicode(psz));
163 . { return yytext[0]; }
167 static void ReadLexBuff(char* pcBuff, size_t& riResult, size_t uMaxSize)
169 wxASSERT( _pszLexBuff != NULL );
171 if (_pszLexBuff == NULL) {
172 YY_FATAL_ERROR("Input in flex scanner failed");
175 wxASSERT( sizeof(YY_CHAR) == sizeof(char) );
176 size_t uCharsInBuff = strlen(_pszLexBuff);
177 size_t uCharsRead = min(uMaxSize, uCharsInBuff);
178 riResult = uCharsRead;
179 memcpy(pcBuff, _pszLexBuff, uCharsRead);
180 _pszLexBuff += uCharsRead;
183 static void ReadLexBuff(char* pcBuff, int& riResult, size_t uMaxSize)
185 size_t st_result = static_cast<size_t>(riResult);
186 ReadLexBuff(pcBuff, st_result, uMaxSize);
187 riResult = static_cast<int>(st_result);
190 static void FatalLexError(yyconst char msg[])
193 printf("Fatal error in flex scanner: %s\n", msg);
195 printf("Fatal error in flex scanner: %s\n", msg);
199 void LexInit(const wxString& pszInput)
201 _pszLexStr = strdup(unicode2UTF8(pszInput));
202 _pszLexBuff = _pszLexStr;
217 yy_did_buffer_switch_on_eof = 0;
218 yy_last_accepting_state = 0;
219 yy_last_accepting_cpos = NULL;
222 yy_start_stack_ptr = 0;
223 yy_start_stack_depth = 0;
224 yy_start_stack = NULL;