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>disable|disabl|disab|disa|dis { BEGIN(NOCMD); return tDISABLE; }
123 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
124 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
125 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und { BEGIN(NOCMD); return tUNDISPLAY; }
126 <INITIAL>delete|delet|dele|del { BEGIN(DEL_CMD); return tDELETE; }
127 <INITIAL>quit|qui|qu|q { BEGIN(NOCMD); return tQUIT; }
128 <INITIAL>set|se { BEGIN(NOCMD); return tSET; }
129 <INITIAL>walk|w { BEGIN(WALK_CMD); return tWALK; }
130 <INITIAL>x { BEGIN(FORMAT_EXPECTED); return tEXAM; }
131 <INITIAL>help|hel|he|"?" { BEGIN(HELP_CMD); return tHELP; }
133 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
134 <INITIAL>where|wher|whe { BEGIN(NOCMD); return tBACKTRACE; }
136 <INITIAL>cont|con|co|c { BEGIN(NOCMD); return tCONT; }
137 <INITIAL>pass|pas|pa { BEGIN(NOCMD); return tPASS; }
138 <INITIAL>condition|conditio|conditi|condit|condi|cond { BEGIN(NOCMD); return tCOND; }
139 <INITIAL>step|ste|st|s { BEGIN(NOCMD); return tSTEP; }
140 <INITIAL>next|nex|ne|n { BEGIN(NOCMD); return tNEXT; }
141 <INITIAL>stepi|si { BEGIN(NOCMD); return tSTEPI; }
142 <INITIAL>nexti|ni { BEGIN(NOCMD); return tNEXTI; }
143 <INITIAL>finish|finis|fini|fin|fi { BEGIN(NOCMD); return tFINISH; }
145 <INITIAL>abort|abor|abo { BEGIN(NOCMD); return tABORT; }
146 <INITIAL>print|prin|pri|pr|p { BEGIN(FORMAT_EXPECTED); return tPRINT; }
148 <INITIAL>mode { BEGIN(NOCMD); return tMODE; }
149 <INITIAL>show|sho|sh { BEGIN(SHOW_CMD); return tSHOW; }
150 <INITIAL>symbolfile|symbols|symbol|sf { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
152 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b { BEGIN(PATH_EXPECTED); return tBREAK; }
153 <INITIAL>watch|watc|wat { BEGIN(PATH_EXPECTED); return tWATCH; }
154 <INITIAL>whatis|whati|what { BEGIN(PATH_EXPECTED); return tWHATIS; }
156 <INFO_CMD>share|shar|sha { return tSHARE; }
157 <INFO_CMD>locals|local|loca|loc { return tLOCAL; }
158 <INFO_CMD,WALK_CMD>class|clas|cla { return tCLASS; }
159 <INFO_CMD,WALK_CMD>module|modul|modu|mod { return tMODULE; }
160 <INFO_CMD,WALK_CMD>queue|queu|que { return tQUEUE; }
161 <INFO_CMD,WALK_CMD>process|proces|proce|proc { return tPROCESS; }
162 <INFO_CMD,WALK_CMD>modref|modre|modr { return tMODREF; }
163 <INFO_CMD>registers|regs|reg|re { return tREGS; }
164 <INFO_CMD>segments|segment|segm|seg|se { return tSEGMENTS; }
165 <INFO_CMD>stack|stac|sta|st { return tSTACK; }
166 <INFO_CMD>maps|map { return tMAPS; }
167 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd { return tWND; }
168 <HELP_CMD>info|inf|in { return tINFO; }
170 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir {
171 BEGIN(PATH_EXPECTED); return tDIR; }
173 char { return tCHAR; }
174 short { return tSHORT; }
176 long { return tLONG; }
177 float { return tFLOAT; }
178 double { return tDOUBLE; }
179 unsigned { return tUNSIGNED; }
180 signed { return tSIGNED; }
181 struct { return tSTRUCT; }
182 union { return tUNION; }
183 enum { return tENUM; }
185 {IDENTIFIER} { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
187 <PATH_EXPECTED>{PATHNAME} { yylval.string = make_symbol(yytext); return tPATH; }
189 [ \t]+ /* Eat up whitespace */
191 . { if (syntax_error == 0)
193 syntax_error ++; fprintf(stderr, "Syntax Error\n");
201 int yywrap(void) { return 1; }
204 #ifndef DONT_USE_READLINE
207 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
211 /* Strip whitespace from the start and end of STRING. */
212 static void stripwhite (char *string)
216 while (whitespace (string[i]))
220 strcpy (string, string + i);
222 i = strlen (string) - 1;
224 while (i > 0 && whitespace (string[i]))
230 static int dbg_read(char * buf, int size)
232 static char last_line[256] = "";
239 line = readline ("Wine-dbg>");
242 fprintf( stderr, "\n" );
246 /* Remove leading and trailing whitespace from the line */
250 /* If there is anything left, add it to the history list
251 and execute it. Otherwise, re-execute last command. */
256 strncpy( last_line, line, 255 );
257 last_line[255] = '\0';
263 if ((len = strlen(line)) > 0)
267 fprintf(stderr,"Fatal readline goof.\n");
278 static char *local_symbols[30];
279 static int next_symbol;
281 char * make_symbol(char * symbol){
282 return local_symbols[next_symbol++] = DBG_strdup(symbol);
287 while(--next_symbol>= 0) DBG_free(local_symbols[next_symbol]);
291 #endif /* DONT_USE_READLINE */