Release 941017
[wine/gsoc-2012-control.git] / debugger / debug.l
blob47135160fa24786b53917114d415bd86acf52611
3 /* Lexical scanner for command line parsing in the Wine debugger
4  *
5  * Version 1.0
6  * Eric Youngdale
7  * 9/93
8  */
11 #include <stdio.h>
12 #include <string.h>
13 #include "dbg.tab.h"
14 #include "regpos.h"
16 #ifdef USE_READLINE
17 #undef YY_INPUT
18 #define YY_INPUT(buf,result,max_size) \
19         if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
20             YY_FATAL_ERROR( "read() in flex scanner failed" );
21 #endif
23 extern char * readline(char *);
24 static char * make_symbol(char *);
25 void flush_symbols();
26 static int syntax_error;
27 extern int yylval;
30 DIGIT   [0-9]
31 HEXDIGIT [0-9a-fA-F]
33 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
37 \n              { syntax_error = 0; return '\n'; } /* Indicate end of command */
39 "+"             { return '+'; } 
41 "-"             { return '-'; } 
43 "/"             { return '/'; } 
45 "="             { return '='; } 
47 "("             { return '('; } 
49 ")"             { return ')'; } 
51 "*"             { return '*'; } 
53 "?"             { return HELP; }
55 "0x"+{HEXDIGIT}+   {
56                 sscanf(yytext, "%lx", &yylval);
57                 return NUM;
58                 }
60 {DIGIT}+   {
61                 sscanf(yytext, "%ld", &yylval);
62                 return NUM;
63                 }
65 $pc             { yylval = RN_EIP; return REG;}
66 $sp             { yylval = RN_ESP; return REG;}
67 $eip            { yylval = RN_EIP; return REG;}
68 $esp            { yylval = RN_ESP; return REG;}
69 $ebp            { yylval = RN_EBP; return REG;}
70 $eax            { yylval = RN_EAX; return REG;}
71 $ebx            { yylval = RN_EBX; return REG;}
72 $ecx            { yylval = RN_ECX; return REG;}
73 $edx            { yylval = RN_EDX; return REG;}
74 $esi            { yylval = RN_ESI; return REG;}
75 $edi            { yylval = RN_EDI; return REG;}
77 $es             { yylval = RN_ES;  return REG;}
78 $ds             { yylval = RN_DS;  return REG;}
79 $cs             { yylval = RN_CS;  return REG;}
80 $ss             { yylval = RN_SS;  return REG;}
82 info|inf|in             { return INFO; }
84 break|brea|bre          { return BREAK; }
85 enable|enabl|enab|ena   { return ENABLE;}
86 disable|disabl|disab|disa|dis { return DISABLE; }
88 quit|qui|qu     { return QUIT; }
90 help|hel|he     { return HELP; }
92 set|se          { return SET; }
94 bt              { return BACKTRACE; }
96 cont|con|co             { return CONT; }
98 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
100 define|defin|defi|def|de        { return DEFINE; }
101 abort|abor|abo                  { return ABORT; }
102 print|prin|pri|pr               { return PRINT; }
104 mode                            { return MODE; }
106 regs|reg|re     { return REGS; }
108 stack|stac|sta|st       { return STACK; }
110 p               { return 'p'; }
111 x               { return 'x'; }
112 d               { return 'd'; }
113 i               { return 'i'; }
114 w               { return 'w'; }
115 b               { return 'b'; }
116 s               { return 's'; }
117 c               { return 'c'; }
118 q               { return 'q'; }
120 {IDENTIFIER}    {yylval = (int) make_symbol(yytext); 
121                   return IDENTIFIER;
122                  }
124 [ \t]+        /* Eat up whitespace */
126 .               { if(syntax_error == 0) {
127                 syntax_error ++; fprintf(stderr, "Syntax Error\n"); }
128                 }
132 #ifndef yywrap
133 int yywrap(void) { return 1; }
134 #endif
136 #ifdef USE_READLINE
137 #ifndef whitespace
138 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
139 #endif
141 #if 0
142 /* Used only with GNU readline */
143 #include "readline/readline.h"
144 #include "readline/chardefs.h"
145 #endif
147 dbg_read(char * buf, int size){
148         char * line;
149         int len;
151         do{
152                 flush_symbols();
153                 line = readline ("Wine-dbg>");
154                 len = strlen(line);
155                                 
156                 if (!line)
157                 {
158                         return 0;
159                 }
160                 else
161                 {
162                         /* Remove leading and trailing whitespace from the line.
163                            Then, if there is anything left, add it to the history list
164                            and execute it. */
165                         stripwhite (line);
166                         
167                         if (*line)
168                         {
169                                 add_history (line);
170                                 if(size < len + 1){
171                                         fprintf(stderr,"Fatal readline goof.\n");
172                                         exit(0);
173                                 };
174                                 strcpy(buf, line);
175                                 buf[len] = '\n';
176                                 buf[len+1] = 0;
177                                 free(line);
178                                 return len + 1;
179                         }
180                 }
182         } while (1==1);
185 /* Strip whitespace from the start and end of STRING. */
186 stripwhite (string)
187      char *string;
189   register int i = 0;
191   while (whitespace (string[i]))
192     i++;
194   if (i)
195     strcpy (string, string + i);
197   i = strlen (string) - 1;
199   while (i > 0 && whitespace (string[i]))
200     i--;
202   string[++i] = '\0';
205 static char *local_symbols[10];
206 static int next_symbol;
208 char * make_symbol(char * symbol){
209         return local_symbols[next_symbol++] = strdup(symbol);
212 void
213 flush_symbols(){
214         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
215         next_symbol = 0;
218 #endif