Release 940510
[wine/multimedia.git] / debugger / debug.l
blob90effe0241b10f137855335b5f2a6ac1f8dc24cd
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 print|prin|pri|pr               { return PRINT; }
103 mode                            { return MODE; }
105 regs|reg|re     { return REGS; }
107 stack|stac|sta|st       { return STACK; }
109 x               { return 'x'; }
110 d               { return 'd'; }
111 i               { return 'i'; }
112 w               { return 'w'; }
113 b               { return 'b'; }
114 s               { return 's'; }
115 c               { return 'c'; }
117 {IDENTIFIER}    {yylval = (int) make_symbol(yytext); 
118                   return IDENTIFIER;
119                  }
121 [ \t]+        /* Eat up whitespace */
123 .               { if(syntax_error == 0) {
124                 syntax_error ++; fprintf(stderr, "Syntax Error\n"); }
125                 }
129 #ifndef yywrap
130 int yywrap(void) { return 1; }
131 #endif
133 #ifdef USE_READLINE
134 #ifndef whitespace
135 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
136 #endif
138 #if 0
139 /* Used only with GNU readline */
140 #include "readline/readline.h"
141 #include "readline/chardefs.h"
142 #endif
144 dbg_read(char * buf, int size){
145         char * line;
146         int len;
148         do{
149                 flush_symbols();
150                 line = readline ("Wine-dbg>");
151                 len = strlen(line);
152                                 
153                 if (!line)
154                 {
155                         return 0;
156                 }
157                 else
158                 {
159                         /* Remove leading and trailing whitespace from the line.
160                            Then, if there is anything left, add it to the history list
161                            and execute it. */
162                         stripwhite (line);
163                         
164                         if (*line)
165                         {
166                                 add_history (line);
167                                 if(size < len + 1){
168                                         fprintf(stderr,"Fatal readline goof.\n");
169                                         exit(0);
170                                 };
171                                 strcpy(buf, line);
172                                 buf[len] = '\n';
173                                 buf[len+1] = 0;
174                                 free(line);
175                                 return len + 1;
176                         }
177                 }
179         } while (1==1);
182 /* Strip whitespace from the start and end of STRING. */
183 stripwhite (string)
184      char *string;
186   register int i = 0;
188   while (whitespace (string[i]))
189     i++;
191   if (i)
192     strcpy (string, string + i);
194   i = strlen (string) - 1;
196   while (i > 0 && whitespace (string[i]))
197     i--;
199   string[++i] = '\0';
202 static char *local_symbols[10];
203 static int next_symbol;
205 char * make_symbol(char * symbol){
206         return local_symbols[next_symbol++] = strdup(symbol);
209 void
210 flush_symbols(){
211         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
212         next_symbol = 0;
215 #endif