1 /* Lexical scanner for command line parsing in the Wine debugger
17 #define YY_INPUT(buf,result,max_size) \
18 if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
19 YY_FATAL_ERROR( "read() in flex scanner failed" );
22 extern char * readline(char *);
23 extern void add_history(char *);
24 static int dbg_read(char * buf, int size);
25 static char * make_symbol(char *);
27 static int syntax_error;
33 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
37 \n { syntax_error = 0; return EOL; } /*Indicates end of command*/
39 "||" { return OP_LOR; }
40 "&&" { return OP_LAND; }
41 "==" { return OP_EQ; }
42 "!=" { return OP_NE; }
43 "<=" { return OP_LE; }
44 ">=" { return OP_GE; }
45 "<<" { return OP_SHL; }
46 ">>" { return OP_SHR; }
47 [-+<=>|&^()*/%:!~] { return *yytext; }
49 "0x"{HEXDIGIT}+ { sscanf(yytext, "%x", &yylval.integer); return NUM; }
50 {DIGIT}+ { sscanf(yytext, "%d", &yylval.integer); return NUM; }
52 "/"{DIGIT}+{FORMAT} { char * last;
53 yylval.integer = strtol( yytext+1, &last, NULL );
54 yylval.integer = (yylval.integer << 8) | *last;
56 "/"{FORMAT} { yylval.integer = (1 << 8) | yytext[1]; return FORMAT; }
58 $pc { yylval.reg = REG_EIP; return REG; }
59 $flags { yylval.reg = REG_EFL; return REG; }
60 $eip { yylval.reg = REG_EIP; return REG; }
61 $ip { yylval.reg = REG_IP; return REG; }
62 $esp { yylval.reg = REG_ESP; return REG; }
63 $sp { yylval.reg = REG_SP; return REG; }
64 $eax { yylval.reg = REG_EAX; return REG; }
65 $ebx { yylval.reg = REG_EBX; return REG; }
66 $ecx { yylval.reg = REG_ECX; return REG; }
67 $edx { yylval.reg = REG_EDX; return REG; }
68 $esi { yylval.reg = REG_ESI; return REG; }
69 $edi { yylval.reg = REG_EDI; return REG; }
70 $ebp { yylval.reg = REG_EBP; return REG; }
71 $ax { yylval.reg = REG_AX; return REG; }
72 $bx { yylval.reg = REG_BX; return REG; }
73 $cx { yylval.reg = REG_CX; return REG; }
74 $dx { yylval.reg = REG_DX; return REG; }
75 $si { yylval.reg = REG_SI; return REG; }
76 $di { yylval.reg = REG_DI; return REG; }
77 $bp { yylval.reg = REG_BP; return REG; }
78 $es { yylval.reg = REG_ES; return REG; }
79 $ds { yylval.reg = REG_DS; return REG; }
80 $cs { yylval.reg = REG_CS; return REG; }
81 $ss { yylval.reg = REG_SS; return REG; }
83 info|inf|in { return INFO; }
84 show|sho|sh { return INFO; }
85 list|lis|li|l { return LIST; }
86 segments|segment|segm|seg|se { return SEGMENTS; }
87 break|brea|bre|br|b { return BREAK; }
88 enable|enabl|enab|ena { return ENABLE;}
89 disable|disabl|disab|disa|dis { return DISABLE; }
90 delete|delet|dele|del { return DELETE; }
91 quit|qui|qu|q { return QUIT; }
94 help|hel|he|"?" { return HELP; }
96 set|se { return SET; }
98 bt { return BACKTRACE; }
100 cont|con|co|c { return CONT; }
101 step|ste|st|s { return STEP; }
102 next|nex|ne|n { return NEXT; }
104 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
106 define|defin|defi|def|de { return DEFINE; }
107 abort|abor|abo { return ABORT; }
108 print|prin|pri|pr|p { return PRINT; }
110 mode { return MODE; }
112 registers|regs|reg|re { return REGS; }
114 stack|stac|sta|st { return STACK; }
116 {IDENTIFIER} { yylval.string = make_symbol(yytext); return IDENTIFIER; }
118 [ \t]+ /* Eat up whitespace */
120 . { if (syntax_error == 0)
122 syntax_error ++; fprintf(stderr, "Syntax Error\n");
129 int yywrap(void) { return 1; }
134 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
138 /* Strip whitespace from the start and end of STRING. */
139 static void stripwhite (char *string)
143 while (whitespace (string[i]))
147 strcpy (string, string + i);
149 i = strlen (string) - 1;
151 while (i > 0 && whitespace (string[i]))
157 static int dbg_read(char * buf, int size)
159 static char last_line[256] = "";
166 line = readline ("Wine-dbg>");
169 /* Remove leading and trailing whitespace from the line */
173 /* If there is anything left, add it to the history list
174 and execute it. Otherwise, re-execute last command. */
179 strncpy( last_line, line, 255 );
180 last_line[255] = '\0';
186 if ((len = strlen(line)) > 0)
190 fprintf(stderr,"Fatal readline goof.\n");
201 static char *local_symbols[10];
202 static int next_symbol;
204 char * make_symbol(char * symbol){
205 return local_symbols[next_symbol++] = strdup(symbol);
210 while(--next_symbol>= 0) free(local_symbols[next_symbol]);