1 /* Lexical scanner for command line parsing in the Wine debugger
18 #define YY_INPUT(buf,result,max_size) \
19 if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
20 YY_FATAL_ERROR( "read() in flex scanner failed" );
23 extern char * readline(char *);
24 extern void add_history(char *);
25 static int dbg_read(char * buf, int size);
26 static char * make_symbol(char *);
28 static int syntax_error;
34 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
38 \n { syntax_error = 0; return tEOL; } /*Indicates end of command*/
40 "||" { return OP_LOR; }
41 "&&" { return OP_LAND; }
42 "==" { return OP_EQ; }
43 "!=" { return OP_NE; }
44 "<=" { return OP_LE; }
45 ">=" { return OP_GE; }
46 "<<" { return OP_SHL; }
47 ">>" { return OP_SHR; }
48 [-+<=>|&^()*/%:!~] { return *yytext; }
50 "0x"{HEXDIGIT}+ { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
51 {DIGIT}+ { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
53 "/"{DIGIT}+{FORMAT} { char * last;
54 yylval.integer = strtol( yytext+1, &last, NULL );
55 yylval.integer = (yylval.integer << 8) | *last;
57 "/"{FORMAT} { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
59 $pc { yylval.reg = REG_EIP; return tREG; }
60 $flags { yylval.reg = REG_EFL; return tREG; }
61 $eip { yylval.reg = REG_EIP; return tREG; }
62 $ip { yylval.reg = REG_IP; return tREG; }
63 $esp { yylval.reg = REG_ESP; return tREG; }
64 $sp { yylval.reg = REG_SP; return tREG; }
65 $eax { yylval.reg = REG_EAX; return tREG; }
66 $ebx { yylval.reg = REG_EBX; return tREG; }
67 $ecx { yylval.reg = REG_ECX; return tREG; }
68 $edx { yylval.reg = REG_EDX; return tREG; }
69 $esi { yylval.reg = REG_ESI; return tREG; }
70 $edi { yylval.reg = REG_EDI; return tREG; }
71 $ebp { yylval.reg = REG_EBP; return tREG; }
72 $ax { yylval.reg = REG_AX; return tREG; }
73 $bx { yylval.reg = REG_BX; return tREG; }
74 $cx { yylval.reg = REG_CX; return tREG; }
75 $dx { yylval.reg = REG_DX; return tREG; }
76 $si { yylval.reg = REG_SI; return tREG; }
77 $di { yylval.reg = REG_DI; return tREG; }
78 $bp { yylval.reg = REG_BP; return tREG; }
79 $es { yylval.reg = REG_ES; return tREG; }
80 $ds { yylval.reg = REG_DS; return tREG; }
81 $cs { yylval.reg = REG_CS; return tREG; }
82 $ss { yylval.reg = REG_SS; return tREG; }
84 info|inf|in { return tINFO; }
85 show|sho|sh { return tINFO; }
86 list|lis|li|l { return tLIST; }
87 break|brea|bre|br|b { return tBREAK; }
88 enable|enabl|enab|ena { return tENABLE;}
89 disable|disabl|disab|disa|dis { return tDISABLE; }
90 delete|delet|dele|del { return tDELETE; }
91 quit|qui|qu|q { return tQUIT; }
92 set|se { return tSET; }
93 walk|w { return tWALK; }
96 class|clas|cla { return tCLASS; }
97 module|modul|modu|mod { return tMODULE; }
98 queue|queu|que { return tQUEUE; }
99 registers|regs|reg|re { return tREGS; }
100 segments|segment|segm|seg|se { return tSEGMENTS; }
101 stack|stac|sta|st { return tSTACK; }
102 window|windo|wind|win|wnd { return tWND; }
104 help|hel|he|"?" { return tHELP; }
106 backtrace|bt { return tBACKTRACE; }
108 cont|con|co|c { return tCONT; }
109 step|ste|st|s { return tSTEP; }
110 next|nex|ne|n { return tNEXT; }
112 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return tSYMBOLFILE; }
114 define|defin|defi|def|de { return tDEFINE; }
115 abort|abor|abo { return tABORT; }
116 print|prin|pri|pr|p { return tPRINT; }
118 mode { return tMODE; }
120 {IDENTIFIER} { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
122 [ \t]+ /* Eat up whitespace */
124 . { if (syntax_error == 0)
126 syntax_error ++; fprintf(stderr, "Syntax Error\n");
133 int yywrap(void) { return 1; }
138 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
142 /* Strip whitespace from the start and end of STRING. */
143 static void stripwhite (char *string)
147 while (whitespace (string[i]))
151 strcpy (string, string + i);
153 i = strlen (string) - 1;
155 while (i > 0 && whitespace (string[i]))
161 static int dbg_read(char * buf, int size)
163 static char last_line[256] = "";
170 line = readline ("Wine-dbg>");
173 /* Remove leading and trailing whitespace from the line */
177 /* If there is anything left, add it to the history list
178 and execute it. Otherwise, re-execute last command. */
183 strncpy( last_line, line, 255 );
184 last_line[255] = '\0';
190 if ((len = strlen(line)) > 0)
194 fprintf(stderr,"Fatal readline goof.\n");
205 static char *local_symbols[10];
206 static int next_symbol;
208 char * make_symbol(char * symbol){
209 return local_symbols[next_symbol++] = xstrdup(symbol);
214 while(--next_symbol>= 0) free(local_symbols[next_symbol]);