3 #include "SearchExpr.h"
8 #include "libs/common/StringFunctions.h"
11 #define isatty(DUMMY) 0
14 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
15 #include <algorithm> // for std::min and std::max
21 static char THIS_FILE[] = __FILE__;
24 #define YY_NEVER_INTERACTIVE 1
26 extern int yyerror(const char* errstr);
27 extern int yyerror(wxString errstr);
29 #define YY_INPUT ReadLexBuff
30 #define YY_FATAL_ERROR FatalLexError
32 static void ReadLexBuff(char* pcBuff, size_t& riResult, size_t uMaxSize);
33 static void FatalLexError(yyconst char msg[]);
35 static char* _pszLexBuff;
36 static char* _pszLexStr;
38 void LexInit(const wxString& pszInput);
49 [ ] { /* Skip blanks. */ }
50 "OR" { return TOK_OR; }
51 "AND" { return TOK_AND; }
52 "NOT" { return TOK_NOT; }
54 "ed2k::"[a-fA-F0-9]{32} {
55 yylval.pstr = new wxString(UTF82unicode(yytext));
60 yylval.pstr = new wxString(UTF82unicode(yytext));
66 char* psz = (char*)malloc(l);
69 while ((c = yyinput()) != '\"')
71 if (c == EOF || c == '\n'){
73 yyerror(wxT("Search expression error: unterminated string"));
76 if (c == '\\'){ /*Escape sequence*/
77 switch (c = yyinput())
84 case 'n': /*Linefeed*/
87 case 'f': /*Formfeed*/
90 case 'r': /*Carriage return*/
93 case '\\': /*Backslash*/
96 case '"': /*Double quotation mark*/
99 case '\'': /*Single quotation mark*/
102 case '?': /*Question mark*/
105 case 'v': /*Vertical Tab*/
111 case 'b': /*Backspace*/
114 case 'x': /*Hexadecimal number*/
117 for (n = 1, octv = 0; n <= 3; n++) {
118 if ((c = yyinput()) >= '0' && c <= '9')
120 else if (c >= 'a' && c <= 'f')
122 else if (c >= 'A' && c <= 'F')
126 octv = octv * 16 + c;
137 if ((unsigned char)c >= 0x80/* && IsDBCSLeadByte(yytext[0]) */){
138 psz[i++] = (unsigned char)c;
140 char *tmp = (char*)realloc(psz, l += 128);
142 yyerror("Less memory for string");
152 psz[i++] = (unsigned char)c;
154 char *tmp = (char*)realloc(psz, l += 128);
156 yyerror("Less memory for string");
164 yylval.pstr = new wxString(UTF82unicode(psz));
169 . { return yytext[0]; }
173 static void ReadLexBuff(char* pcBuff, size_t& riResult, size_t uMaxSize)
175 wxASSERT( _pszLexBuff != NULL );
177 if (_pszLexBuff == NULL) {
178 YY_FATAL_ERROR("Input in flex scanner failed");
181 wxASSERT( sizeof(YY_CHAR) == sizeof(char) );
182 size_t uCharsInBuff = strlen(_pszLexBuff);
183 size_t uCharsRead = min(uMaxSize, uCharsInBuff);
184 riResult = uCharsRead;
185 memcpy(pcBuff, _pszLexBuff, uCharsRead);
186 _pszLexBuff += uCharsRead;
189 static void FatalLexError(yyconst char msg[])
192 printf("Fatal error in flex scanner: %s\n", msg);
194 printf("Fatal error in flex scanner: %s\n", msg);
198 void LexInit(const wxString& pszInput)
200 _pszLexStr = strdup(unicode2UTF8(pszInput));
201 _pszLexBuff = _pszLexStr;
216 yy_did_buffer_switch_on_eof = 0;
217 yy_last_accepting_state = 0;
218 yy_last_accepting_cpos = NULL;