Release 950522
[wine.git] / debugger / debug.l
blob18a6b5acf45a89c574c8e9b1e749da4af015dcab
1 /* Lexical scanner for command line parsing in the Wine debugger
2  *
3  * Version 1.0
4  * Eric Youngdale
5  * 9/93
6  */
8 %{
9 #include <stdio.h>
10 #include <string.h>
11 #include "dbg.tab.h"
12 #include "regpos.h"
14 #ifdef USE_READLINE
15 #undef YY_INPUT
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" );
19 #endif
21 extern char * readline(char *);
22 static char * make_symbol(char *);
23 void flush_symbols();
24 static int syntax_error;
25 extern int yylval;
28 DIGIT   [0-9]
29 HEXDIGIT [0-9a-fA-F]
31 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
32 FILE_IDENTIFIER [_a-zA-Z\.~/][_a-zA-Z\.~/]*
36 \n              { syntax_error = 0; return '\n'; } /* Indicate end of command */
38 "+"             { return '+'; } 
40 "-"             { return '-'; } 
42 "/"             { return '/'; } 
44 "="             { return '='; } 
46 "("             { return '('; } 
48 ")"             { return ')'; } 
50 "*"             { return '*'; } 
52 "?"             { return HELP; }
54 "0x"+{HEXDIGIT}+   {
55                 sscanf(yytext, "%x", &yylval);
56                 return NUM;
57                 }
59 {DIGIT}+   {
60                 sscanf(yytext, "%d", &yylval);
61                 return NUM;
62                 }
64 $pc             { yylval = RN_EIP; return REG;}
65 $sp             { yylval = RN_ESP_AT_SIGNAL; return REG;}
66 $eip            { yylval = RN_EIP; return REG;}
67 $esp            { yylval = RN_ESP_AT_SIGNAL; return REG;}
68 $ebp            { yylval = RN_EBP; return REG;}
69 $eax            { yylval = RN_EAX; return REG;}
70 $ebx            { yylval = RN_EBX; return REG;}
71 $ecx            { yylval = RN_ECX; return REG;}
72 $edx            { yylval = RN_EDX; return REG;}
73 $esi            { yylval = RN_ESI; return REG;}
74 $edi            { yylval = RN_EDI; return REG;}
76 $es             { yylval = RN_ES;  return REG;}
77 $ds             { yylval = RN_DS;  return REG;}
78 $cs             { yylval = RN_CS;  return REG;}
79 $ss             { yylval = RN_SS;  return REG;}
81 info|inf|in             { return INFO; }
82 segments|segm           { return SEGMENTS; }
83 break|brea|bre          { return BREAK; }
84 enable|enabl|enab|ena   { return ENABLE;}
85 disable|disabl|disab|disa|dis { return DISABLE; }
87 quit|qui|qu     { return QUIT; }
89 help|hel|he     { return HELP; }
91 set|se          { return SET; }
93 bt              { return BACKTRACE; }
95 cont|con|co             { return CONT; }
97 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
99 define|defin|defi|def|de        { return DEFINE; }
100 abort|abor|abo                  { return ABORT; }
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 p               { return 'p'; }
110 x               { return 'x'; }
111 d               { return 'd'; }
112 i               { return 'i'; }
113 w               { return 'w'; }
114 b               { return 'b'; }
115 s               { return 's'; }
116 c               { return 'c'; }
117 q               { return 'q'; }
119 {IDENTIFIER}    {yylval = (int) make_symbol(yytext); 
120                   return IDENTIFIER;
121                  }
123 {FILE_IDENTIFIER} {yylval = (int) make_symbol(yytext); 
124                   return FILE_IDENTIFIER;
125                  }
127 [ \t]+        /* Eat up whitespace */
129 .               { if(syntax_error == 0) {
130                 syntax_error ++; fprintf(stderr, "Syntax Error\n"); }
131                 }
135 #ifndef yywrap
136 int yywrap(void) { return 1; }
137 #endif
139 #ifdef USE_READLINE
140 #ifndef whitespace
141 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
142 #endif
144 #if 0
145 /* Used only with GNU readline */
146 #include "readline/readline.h"
147 #include "readline/chardefs.h"
148 #endif
150 /* Strip whitespace from the start and end of STRING. */
151 static void stripwhite (char *string)
153   register int i = 0;
155   while (whitespace (string[i]))
156     i++;
158   if (i)
159     strcpy (string, string + i);
161   i = strlen (string) - 1;
163   while (i > 0 && whitespace (string[i]))
164     i--;
166   string[++i] = '\0';
169 dbg_read(char * buf, int size){
170         char * line;
171         int len;
173         do{
174                 flush_symbols();
175                 line = readline ("Wine-dbg>");
176                 len = strlen(line);
177                                 
178                 if (!line)
179                 {
180                         return 0;
181                 }
182                 else
183                 {
184                         /* Remove leading and trailing whitespace from the line.
185                            Then, if there is anything left, add it to the history list
186                            and execute it. */
187                         stripwhite (line);
188                         
189                         if (*line)
190                         {
191                                 add_history (line);
192                                 if(size < len + 1){
193                                         fprintf(stderr,"Fatal readline goof.\n");
194                                         exit(0);
195                                 };
196                                 strcpy(buf, line);
197                                 buf[len] = '\n';
198                                 buf[len+1] = 0;
199                                 free(line);
200                                 return len + 1;
201                         }
202                 }
204         } while (1==1);
207 static char *local_symbols[10];
208 static int next_symbol;
210 char * make_symbol(char * symbol){
211         return local_symbols[next_symbol++] = strdup(symbol);
214 void
215 flush_symbols(){
216         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
217         next_symbol = 0;
220 #endif