2 * Lexical scanner for command line parsing
4 * Copyright 1993 Eric Youngdale
14 #ifndef DONT_USE_READLINE
16 #define YY_INPUT(buf,result,max_size) \
17 if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
18 YY_FATAL_ERROR( "read() in flex scanner failed" );
20 static int dbg_read(char * buf, int size);
22 #endif /* DONT_USE_READLINE */
26 static int syntax_error;
32 IDENTIFIER [_a-zA-Z~][_a-zA-Z0-9~@]*
33 PATHNAME [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
49 /* set to special state when no process is loaded. */
50 if (!DEBUG_CurrProcess && YYSTATE == INITIAL) {BEGIN(NOPROCESS);}
52 <*>\n { BEGIN(INITIAL); syntax_error = 0; return tEOL; }
53 /* Indicates end of command. Reset state. */
55 "||" { return OP_LOR; }
56 "&&" { return OP_LAND; }
57 "==" { return OP_EQ; }
58 "!=" { return OP_NE; }
59 "<=" { return OP_LE; }
60 ">=" { return OP_GE; }
61 "<<" { return OP_SHL; }
62 ">>" { return OP_SHR; }
63 "->" { return OP_DRF; }
64 [-+<=>|&^()*/%:!~,\.] { return *yytext; }
65 "[" { return *yytext; }
66 "]" { return *yytext; }
68 "0x"{HEXDIGIT}+ { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
69 {DIGIT}+ { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
71 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT} { char* last;
72 yylval.integer = strtol( yytext+1, &last, 0 ) << 8;
73 yylval.integer |= *last;
76 <FORMAT_EXPECTED>"/"{FORMAT} { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
78 {STRING} { yylval.string = DEBUG_MakeSymbol(yytext); return tSTRING; }
79 <ASTRING_EXPECTED>[^\n]+ { char* p = yytext; while (*p == ' ' || *p == '\t') p++;
80 yylval.string = DEBUG_MakeSymbol(p); return tSTRING; }
82 <INITIAL>info|inf|in { BEGIN(INFO_CMD); return tINFO; }
83 <INITIAL>up { BEGIN(NOCMD); return tUP; }
84 <INITIAL>down|dow|do { BEGIN(NOCMD); return tDOWN; }
85 <INITIAL>frame|fram|fra|fr { BEGIN(NOCMD); return tFRAME; }
86 <INITIAL>list|lis|li|l { BEGIN(PATH_EXPECTED); return tLIST; }
87 <INITIAL>enable|enabl|enab|ena { BEGIN(NOCMD); return tENABLE;}
88 <INITIAL>disable|disabl|disab|disa|dis { BEGIN(NOCMD); return tDISABLE; }
89 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
90 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
91 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und { BEGIN(NOCMD); return tUNDISPLAY; }
92 <INITIAL>delete|delet|dele|del { BEGIN(DEL_CMD); return tDELETE; }
93 <INITIAL,NOPROCESS>quit|qui|qu|q { BEGIN(NOCMD); return tQUIT; }
94 <INITIAL>set|se { BEGIN(NOCMD); return tSET; }
95 <INITIAL,NOPROCESS>walk|w { BEGIN(WALK_CMD); return tWALK; }
96 <INITIAL>x { BEGIN(FORMAT_EXPECTED); return tEXAM; }
97 <INITIAL>help|hel|he|"?" { BEGIN(HELP_CMD); return tHELP; }
99 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
100 <INITIAL>where|wher|whe { BEGIN(NOCMD); return tBACKTRACE; }
102 <INITIAL>cont|con|co|c { BEGIN(NOCMD); return tCONT; }
103 <INITIAL>pass|pas|pa { BEGIN(NOCMD); return tPASS; }
104 <INITIAL>condition|conditio|conditi|condit|condi|cond { BEGIN(NOCMD); return tCOND; }
105 <INITIAL>step|ste|st|s { BEGIN(NOCMD); return tSTEP; }
106 <INITIAL>next|nex|ne|n { BEGIN(NOCMD); return tNEXT; }
107 <INITIAL>stepi|si { BEGIN(NOCMD); return tSTEPI; }
108 <INITIAL>nexti|ni { BEGIN(NOCMD); return tNEXTI; }
109 <INITIAL>finish|finis|fini|fin|fi { BEGIN(NOCMD); return tFINISH; }
111 <INITIAL>abort|abor|abo { BEGIN(NOCMD); return tABORT; }
112 <INITIAL>print|prin|pri|pr|p { BEGIN(FORMAT_EXPECTED); return tPRINT; }
114 <INITIAL>mode { BEGIN(MODE_CMD); return tMODE; }
115 <INITIAL>show|sho|sh { BEGIN(SHOW_CMD); return tSHOW; }
116 <INITIAL>symbolfile|symbols|symbol|sf { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
118 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b { BEGIN(NOCMD); return tBREAK; }
119 <INITIAL>watch|watc|wat { BEGIN(NOCMD); return tWATCH; }
120 <INITIAL>whatis|whati|what { BEGIN(NOCMD); return tWHATIS; }
121 <INITIAL,NOPROCESS>run|ru|r { BEGIN(ASTRING_EXPECTED); return tRUN;}
122 <NOPROCESS>attach|attac|atta|att { BEGIN(NOCMD); return tATTACH; }
123 <INFO_CMD>share|shar|sha { return tSHARE; }
124 <INFO_CMD>locals|local|loca|loc { return tLOCAL; }
125 <INFO_CMD,WALK_CMD>class|clas|cla { return tCLASS; }
126 <INFO_CMD,WALK_CMD>module|modul|modu|mod { return tMODULE; }
127 <INFO_CMD,WALK_CMD>queue|queu|que { return tQUEUE; }
128 <INFO_CMD,WALK_CMD>process|proces|proce|proc { return tPROCESS; }
129 <INFO_CMD,WALK_CMD>threads|thread|threa|thre|thr|th { return tTHREAD; }
130 <INFO_CMD,WALK_CMD>modref|modre|modr { return tMODREF; }
131 <INFO_CMD>registers|regs|reg|re { return tREGS; }
132 <INFO_CMD>segments|segment|segm|seg|se { return tSEGMENTS; }
133 <INFO_CMD>stack|stac|sta|st { return tSTACK; }
134 <INFO_CMD>maps|map { return tMAPS; }
135 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd { return tWND; }
136 <HELP_CMD>info|inf|in { return tINFO; }
137 <MODE_CMD>vm86 { return tVM86; }
139 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir {
140 BEGIN(PATH_EXPECTED); return tDIR; }
142 char { return tCHAR; }
143 short { return tSHORT; }
145 long { return tLONG; }
146 float { return tFLOAT; }
147 double { return tDOUBLE; }
148 unsigned { return tUNSIGNED; }
149 signed { return tSIGNED; }
150 struct { return tSTRUCT; }
151 union { return tUNION; }
152 enum { return tENUM; }
154 {IDENTIFIER} { yylval.string = DEBUG_MakeSymbol(yytext); return tIDENTIFIER; }
155 "$"{IDENTIFIER} { yylval.string = DEBUG_MakeSymbol(yytext+1); return tINTVAR; }
157 <PATH_EXPECTED>{PATHNAME} { yylval.string = DEBUG_MakeSymbol(yytext); return tPATH; }
159 <*>[ \t]+ /* Eat up whitespace */
161 <NOPROCESS>. { BEGIN(ASTRING_EXPECTED); yyless(0); return tNOPROCESS;}
162 <*>. { if (syntax_error == 0) {
164 DEBUG_Printf(DBG_CHN_MESG, "Syntax Error (%s)\n", yytext); }
169 int yywrap(void) { return 1; }
172 #ifndef DONT_USE_READLINE
175 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
179 /* Strip whitespace from the start and end of STRING. */
180 static void stripwhite (char *string)
184 while (whitespace (string[i]))
188 strcpy (string, string + i);
190 i = strlen (string) - 1;
192 while (i > 0 && whitespace (string[i]))
198 static int dbg_read(char * buf, int size)
200 static char last_line[256] = "";
206 DEBUG_FlushSymbols();
207 line = readline ("Wine-dbg>");
210 DEBUG_Printf( DBG_CHN_MESG, "\n" );
214 /* Remove leading and trailing whitespace from the line */
218 /* If there is anything left, add it to the history list
219 and execute it. Otherwise, re-execute last command. */
224 strncpy( last_line, line, 255 );
225 last_line[255] = '\0';
231 if ((len = strlen(line)) > 0)
235 DEBUG_Printf(DBG_CHN_MESG,"Fatal readline goof.\n");
246 static char *local_symbols[30];
247 static int next_symbol;
249 char * DEBUG_MakeSymbol(const char * symbol)
251 assert(0 <= next_symbol && next_symbol < (sizeof(local_symbols) / sizeof(local_symbols[0])));
252 return local_symbols[next_symbol++] = DBG_strdup(symbol);
255 void DEBUG_FlushSymbols(void)
257 while(--next_symbol >= 0) DBG_free(local_symbols[next_symbol]);
261 #endif /* DONT_USE_READLINE */