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