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