2 * Lexical scanner for command line parsing
4 * Copyright 1993 Eric Youngdale
15 #define malloc(x) DBG_alloc(x)
16 #define realloc(x,y) DBG_realloc(x,y)
17 #define free(x) DBG_free(x)
20 #ifndef DONT_USE_READLINE
22 #define YY_INPUT(buf,result,max_size) \
23 if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
24 YY_FATAL_ERROR( "read() in flex scanner failed" );
26 extern char * readline(const char *);
27 extern void add_history(char *);
28 static int dbg_read(char * buf, int size);
29 static char * make_symbol(char *);
32 #endif /* DONT_USE_READLINE */
36 static int syntax_error;
42 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~@]*
43 PATHNAME [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
58 \n { BEGIN(0); syntax_error = 0;
59 return tEOL; } /*Indicates end of command. Reset state. */
61 "||" { return OP_LOR; }
62 "&&" { return OP_LAND; }
63 "==" { return OP_EQ; }
64 "!=" { return OP_NE; }
65 "<=" { return OP_LE; }
66 ">=" { return OP_GE; }
67 "<<" { return OP_SHL; }
68 ">>" { return OP_SHR; }
69 "->" { return OP_DRF; }
70 [-+<=>|&^()*/%:!~,\.] { return *yytext; }
71 "[" { return *yytext; }
72 "]" { return *yytext; }
74 "0x"{HEXDIGIT}+ { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
75 {DIGIT}+ { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
78 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT} { char * last;
79 yylval.integer = strtol( yytext+1, &last, NULL );
80 yylval.integer = (yylval.integer << 8) | *last;
84 <FORMAT_EXPECTED>"/"{FORMAT} { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
86 {STRING} { yylval.string = make_symbol(yytext); return tSTRING; }
87 <DEBUGSTR>[a-z+\-,]* { yylval.string = yytext; return tDEBUGSTR; }
89 $pc { yylval.reg = REG_EIP; return tREG; }
90 $flags { yylval.reg = REG_EFL; return tREG; }
91 $eip { yylval.reg = REG_EIP; return tREG; }
92 $ip { yylval.reg = REG_IP; return tREG; }
93 $esp { yylval.reg = REG_ESP; return tREG; }
94 $sp { yylval.reg = REG_SP; return tREG; }
95 $eax { yylval.reg = REG_EAX; return tREG; }
96 $ebx { yylval.reg = REG_EBX; return tREG; }
97 $ecx { yylval.reg = REG_ECX; return tREG; }
98 $edx { yylval.reg = REG_EDX; return tREG; }
99 $esi { yylval.reg = REG_ESI; return tREG; }
100 $edi { yylval.reg = REG_EDI; return tREG; }
101 $ebp { yylval.reg = REG_EBP; return tREG; }
102 $ax { yylval.reg = REG_AX; return tREG; }
103 $bx { yylval.reg = REG_BX; return tREG; }
104 $cx { yylval.reg = REG_CX; return tREG; }
105 $dx { yylval.reg = REG_DX; return tREG; }
106 $si { yylval.reg = REG_SI; return tREG; }
107 $di { yylval.reg = REG_DI; return tREG; }
108 $bp { yylval.reg = REG_BP; return tREG; }
109 $es { yylval.reg = REG_ES; return tREG; }
110 $ds { yylval.reg = REG_DS; return tREG; }
111 $cs { yylval.reg = REG_CS; return tREG; }
112 $ss { yylval.reg = REG_SS; return tREG; }
113 $fs { yylval.reg = REG_FS; return tREG; }
114 $gs { yylval.reg = REG_GS; return tREG; }
116 <INITIAL>info|inf|in { BEGIN(INFO_CMD); return tINFO; }
117 <INITIAL>up { BEGIN(NOCMD); return tUP; }
118 <INITIAL>down|dow|do { BEGIN(NOCMD); return tDOWN; }
119 <INITIAL>frame|fram|fra|fr { BEGIN(NOCMD); return tFRAME; }
120 <INITIAL>list|lis|li|l { BEGIN(PATH_EXPECTED); return tLIST; }
121 <INITIAL>enable|enabl|enab|ena { BEGIN(NOCMD); return tENABLE;}
122 <INITIAL>debugmsg|debugms|debugm|debug|debu|deb { BEGIN(DEBUGSTR); return tDEBUGMSG;}
123 <INITIAL>disable|disabl|disab|disa|dis { BEGIN(NOCMD); return tDISABLE; }
124 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
125 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
126 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und { BEGIN(NOCMD); return tUNDISPLAY; }
127 <INITIAL>delete|delet|dele|del { BEGIN(DEL_CMD); return tDELETE; }
128 <INITIAL>quit|qui|qu|q { BEGIN(NOCMD); return tQUIT; }
129 <INITIAL>set|se { BEGIN(NOCMD); return tSET; }
130 <INITIAL>walk|w { BEGIN(WALK_CMD); return tWALK; }
131 <INITIAL>x { BEGIN(FORMAT_EXPECTED); return tEXAM; }
132 <INITIAL>help|hel|he|"?" { BEGIN(HELP_CMD); return tHELP; }
134 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
135 <INITIAL>where|wher|whe { BEGIN(NOCMD); return tBACKTRACE; }
137 <INITIAL>cont|con|co|c { BEGIN(NOCMD); return tCONT; }
138 <INITIAL>pass|pas|pa { BEGIN(NOCMD); return tPASS; }
139 <INITIAL>condition|conditio|conditi|condit|condi|cond { BEGIN(NOCMD); return tCOND; }
140 <INITIAL>step|ste|st|s { BEGIN(NOCMD); return tSTEP; }
141 <INITIAL>next|nex|ne|n { BEGIN(NOCMD); return tNEXT; }
142 <INITIAL>stepi|si { BEGIN(NOCMD); return tSTEPI; }
143 <INITIAL>nexti|ni { BEGIN(NOCMD); return tNEXTI; }
144 <INITIAL>finish|finis|fini|fin|fi { BEGIN(NOCMD); return tFINISH; }
146 <INITIAL>abort|abor|abo { BEGIN(NOCMD); return tABORT; }
147 <INITIAL>print|prin|pri|pr|p { BEGIN(FORMAT_EXPECTED); return tPRINT; }
149 <INITIAL>mode { BEGIN(NOCMD); return tMODE; }
150 <INITIAL>show|sho|sh { BEGIN(SHOW_CMD); return tSHOW; }
151 <INITIAL>symbolfile|symbols|symbol|sf { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
153 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b { BEGIN(PATH_EXPECTED); return tBREAK; }
155 <INFO_CMD>share|shar|sha { return tSHARE; }
156 <INFO_CMD>locals|local|loca|loc { return tLOCAL; }
157 <INFO_CMD,WALK_CMD>class|clas|cla { return tCLASS; }
158 <INFO_CMD,WALK_CMD>module|modul|modu|mod { return tMODULE; }
159 <INFO_CMD,WALK_CMD>queue|queu|que { return tQUEUE; }
160 <INFO_CMD,WALK_CMD>process|proces|proce|proc { return tPROCESS; }
161 <INFO_CMD,WALK_CMD>modref|modre|modr { return tMODREF; }
162 <INFO_CMD>registers|regs|reg|re { return tREGS; }
163 <INFO_CMD>segments|segment|segm|seg|se { return tSEGMENTS; }
164 <INFO_CMD>stack|stac|sta|st { return tSTACK; }
165 <INFO_CMD>maps|map { return tMAPS; }
166 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd { return tWND; }
167 <HELP_CMD>info|inf|in { return tINFO; }
169 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir {
170 BEGIN(PATH_EXPECTED); return tDIR; }
172 char { return tCHAR; }
173 short { return tSHORT; }
175 long { return tLONG; }
176 float { return tFLOAT; }
177 double { return tDOUBLE; }
178 unsigned { return tUNSIGNED; }
179 signed { return tSIGNED; }
180 struct { return tSTRUCT; }
181 union { return tUNION; }
182 enum { return tENUM; }
184 {IDENTIFIER} { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
186 <PATH_EXPECTED>{PATHNAME} { yylval.string = make_symbol(yytext); return tPATH; }
188 [ \t]+ /* Eat up whitespace */
190 . { if (syntax_error == 0)
192 syntax_error ++; fprintf(stderr, "Syntax Error\n");
200 int yywrap(void) { return 1; }
203 #ifndef DONT_USE_READLINE
206 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
210 /* Strip whitespace from the start and end of STRING. */
211 static void stripwhite (char *string)
215 while (whitespace (string[i]))
219 strcpy (string, string + i);
221 i = strlen (string) - 1;
223 while (i > 0 && whitespace (string[i]))
229 static int dbg_read(char * buf, int size)
231 static char last_line[256] = "";
238 line = readline ("Wine-dbg>");
241 fprintf( stderr, "\n" );
245 /* Remove leading and trailing whitespace from the line */
249 /* If there is anything left, add it to the history list
250 and execute it. Otherwise, re-execute last command. */
255 strncpy( last_line, line, 255 );
256 last_line[255] = '\0';
262 if ((len = strlen(line)) > 0)
266 fprintf(stderr,"Fatal readline goof.\n");
277 static char *local_symbols[30];
278 static int next_symbol;
280 char * make_symbol(char * symbol){
281 return local_symbols[next_symbol++] = DBG_strdup(symbol);
286 while(--next_symbol>= 0) DBG_free(local_symbols[next_symbol]);
290 #endif /* DONT_USE_READLINE */