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