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 EOL; } /*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 NUM; }
51 {DIGIT}+ { sscanf(yytext, "%d", &yylval.integer); return NUM; }
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 FORMAT; }
59 $pc { yylval.reg = REG_EIP; return REG; }
60 $flags { yylval.reg = REG_EFL; return REG; }
61 $eip { yylval.reg = REG_EIP; return REG; }
62 $ip { yylval.reg = REG_IP; return REG; }
63 $esp { yylval.reg = REG_ESP; return REG; }
64 $sp { yylval.reg = REG_SP; return REG; }
65 $eax { yylval.reg = REG_EAX; return REG; }
66 $ebx { yylval.reg = REG_EBX; return REG; }
67 $ecx { yylval.reg = REG_ECX; return REG; }
68 $edx { yylval.reg = REG_EDX; return REG; }
69 $esi { yylval.reg = REG_ESI; return REG; }
70 $edi { yylval.reg = REG_EDI; return REG; }
71 $ebp { yylval.reg = REG_EBP; return REG; }
72 $ax { yylval.reg = REG_AX; return REG; }
73 $bx { yylval.reg = REG_BX; return REG; }
74 $cx { yylval.reg = REG_CX; return REG; }
75 $dx { yylval.reg = REG_DX; return REG; }
76 $si { yylval.reg = REG_SI; return REG; }
77 $di { yylval.reg = REG_DI; return REG; }
78 $bp { yylval.reg = REG_BP; return REG; }
79 $es { yylval.reg = REG_ES; return REG; }
80 $ds { yylval.reg = REG_DS; return REG; }
81 $cs { yylval.reg = REG_CS; return REG; }
82 $ss { yylval.reg = REG_SS; return REG; }
84 info|inf|in { return INFO; }
85 show|sho|sh { return INFO; }
86 list|lis|li|l { return LIST; }
87 segments|segment|segm|seg|se { return SEGMENTS; }
88 break|brea|bre|br|b { return BREAK; }
89 enable|enabl|enab|ena { return ENABLE;}
90 disable|disabl|disab|disa|dis { return DISABLE; }
91 delete|delet|dele|del { return DELETE; }
92 quit|qui|qu|q { return QUIT; }
95 help|hel|he|"?" { return HELP; }
97 set|se { return SET; }
99 bt { return BACKTRACE; }
101 cont|con|co|c { return CONT; }
102 step|ste|st|s { return STEP; }
103 next|nex|ne|n { return NEXT; }
105 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
107 define|defin|defi|def|de { return DEFINE; }
108 abort|abor|abo { return ABORT; }
109 print|prin|pri|pr|p { return PRINT; }
111 mode { return MODE; }
113 registers|regs|reg|re { return REGS; }
115 stack|stac|sta|st { return STACK; }
117 {IDENTIFIER} { yylval.string = make_symbol(yytext); return IDENTIFIER; }
119 [ \t]+ /* Eat up whitespace */
121 . { if (syntax_error == 0)
123 syntax_error ++; fprintf(stderr, "Syntax Error\n");
130 int yywrap(void) { return 1; }
135 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
139 /* Strip whitespace from the start and end of STRING. */
140 static void stripwhite (char *string)
144 while (whitespace (string[i]))
148 strcpy (string, string + i);
150 i = strlen (string) - 1;
152 while (i > 0 && whitespace (string[i]))
158 static int dbg_read(char * buf, int size)
160 static char last_line[256] = "";
167 line = readline ("Wine-dbg>");
170 /* Remove leading and trailing whitespace from the line */
174 /* If there is anything left, add it to the history list
175 and execute it. Otherwise, re-execute last command. */
180 strncpy( last_line, line, 255 );
181 last_line[255] = '\0';
187 if ((len = strlen(line)) > 0)
191 fprintf(stderr,"Fatal readline goof.\n");
202 static char *local_symbols[10];
203 static int next_symbol;
205 char * make_symbol(char * symbol){
206 return local_symbols[next_symbol++] = xstrdup(symbol);
211 while(--next_symbol>= 0) free(local_symbols[next_symbol]);