2 * Lexical scanner for command line parsing
4 * Copyright 1993 Eric Youngdale
15 #ifndef DONT_USE_READLINE
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" );
21 extern char * readline(char *);
22 extern void add_history(char *);
23 static int dbg_read(char * buf, int size);
24 static char * make_symbol(char *);
27 #endif /* DONT_USE_READLINE */
31 static int syntax_error;
37 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
41 \n { syntax_error = 0; return tEOL; } /*Indicates end of command*/
43 "||" { return OP_LOR; }
44 "&&" { return OP_LAND; }
45 "==" { return OP_EQ; }
46 "!=" { return OP_NE; }
47 "<=" { return OP_LE; }
48 ">=" { return OP_GE; }
49 "<<" { return OP_SHL; }
50 ">>" { return OP_SHR; }
51 [-+<=>|&^()*/%:!~] { return *yytext; }
53 "0x"{HEXDIGIT}+ { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
54 {DIGIT}+ { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
56 "/"{DIGIT}+{FORMAT} { char * last;
57 yylval.integer = strtol( yytext+1, &last, NULL );
58 yylval.integer = (yylval.integer << 8) | *last;
60 "/"{FORMAT} { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
62 $pc { yylval.reg = REG_EIP; return tREG; }
63 $flags { yylval.reg = REG_EFL; return tREG; }
64 $eip { yylval.reg = REG_EIP; return tREG; }
65 $ip { yylval.reg = REG_IP; return tREG; }
66 $esp { yylval.reg = REG_ESP; return tREG; }
67 $sp { yylval.reg = REG_SP; return tREG; }
68 $eax { yylval.reg = REG_EAX; return tREG; }
69 $ebx { yylval.reg = REG_EBX; return tREG; }
70 $ecx { yylval.reg = REG_ECX; return tREG; }
71 $edx { yylval.reg = REG_EDX; return tREG; }
72 $esi { yylval.reg = REG_ESI; return tREG; }
73 $edi { yylval.reg = REG_EDI; return tREG; }
74 $ebp { yylval.reg = REG_EBP; return tREG; }
75 $ax { yylval.reg = REG_AX; return tREG; }
76 $bx { yylval.reg = REG_BX; return tREG; }
77 $cx { yylval.reg = REG_CX; return tREG; }
78 $dx { yylval.reg = REG_DX; return tREG; }
79 $si { yylval.reg = REG_SI; return tREG; }
80 $di { yylval.reg = REG_DI; return tREG; }
81 $bp { yylval.reg = REG_BP; return tREG; }
82 $es { yylval.reg = REG_ES; return tREG; }
83 $ds { yylval.reg = REG_DS; return tREG; }
84 $cs { yylval.reg = REG_CS; return tREG; }
85 $ss { yylval.reg = REG_SS; return tREG; }
86 $fs { yylval.reg = REG_FS; return tREG; }
87 $gs { yylval.reg = REG_GS; return tREG; }
89 info|inf|in { return tINFO; }
90 show|sho|sh { return tINFO; }
91 list|lis|li|l { return tLIST; }
92 break|brea|bre|br|b { return tBREAK; }
93 enable|enabl|enab|ena { return tENABLE;}
94 disable|disabl|disab|disa|dis { return tDISABLE; }
95 delete|delet|dele|del { return tDELETE; }
96 quit|qui|qu|q { return tQUIT; }
97 set|se { return tSET; }
98 walk|w { return tWALK; }
101 class|clas|cla { return tCLASS; }
102 module|modul|modu|mod { return tMODULE; }
103 queue|queu|que { return tQUEUE; }
104 registers|regs|reg|re { return tREGS; }
105 segments|segment|segm|seg|se { return tSEGMENTS; }
106 stack|stac|sta|st { return tSTACK; }
107 window|windo|wind|win|wnd { return tWND; }
109 help|hel|he|"?" { return tHELP; }
111 backtrace|backtrac|backtra|backt|back|bac|ba|bt { return tBACKTRACE; }
112 where|wher|whe { return tBACKTRACE; }
114 cont|con|co|c { return tCONT; }
115 step|ste|st|s { return tSTEP; }
116 next|nex|ne|n { return tNEXT; }
118 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return tSYMBOLFILE; }
120 define|defin|defi|def|de { return tDEFINE; }
121 abort|abor|abo { return tABORT; }
122 print|prin|pri|pr|p { return tPRINT; }
124 mode { return tMODE; }
126 {IDENTIFIER} { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
128 [ \t]+ /* Eat up whitespace */
130 . { if (syntax_error == 0)
132 syntax_error ++; fprintf(stderr, "Syntax Error\n");
139 int yywrap(void) { return 1; }
142 #ifndef DONT_USE_READLINE
145 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
149 /* Strip whitespace from the start and end of STRING. */
150 static void stripwhite (char *string)
154 while (whitespace (string[i]))
158 strcpy (string, string + i);
160 i = strlen (string) - 1;
162 while (i > 0 && whitespace (string[i]))
168 static int dbg_read(char * buf, int size)
170 static char last_line[256] = "";
177 line = readline ("Wine-dbg>");
180 fprintf( stderr, "\n" );
184 /* Remove leading and trailing whitespace from the line */
188 /* If there is anything left, add it to the history list
189 and execute it. Otherwise, re-execute last command. */
194 strncpy( last_line, line, 255 );
195 last_line[255] = '\0';
201 if ((len = strlen(line)) > 0)
205 fprintf(stderr,"Fatal readline goof.\n");
216 static char *local_symbols[10];
217 static int next_symbol;
219 char * make_symbol(char * symbol){
220 return local_symbols[next_symbol++] = xstrdup(symbol);
225 while(--next_symbol>= 0) free(local_symbols[next_symbol]);
229 #endif /* DONT_USE_READLINE */