Release 950620
[wine/multimedia.git] / debugger / debug.l
blob68975b7e9137ed1be1f97723247cffa670e7f630
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\.~]*
35 \n              { syntax_error = 0; return '\n'; } /* Indicate end of command */
37 "+"             { return '+'; } 
39 "-"             { return '-'; } 
41 "/"             { return '/'; } 
43 "="             { return '='; } 
45 "("             { return '('; } 
47 ")"             { return ')'; } 
49 "*"             { return '*'; } 
51 "?"             { return HELP; }
53 "0x"+{HEXDIGIT}+   {
54                 sscanf(yytext, "%x", &yylval);
55                 return NUM;
56                 }
58 {DIGIT}+   {
59                 sscanf(yytext, "%d", &yylval);
60                 return NUM;
61                 }
63 $pc             { yylval = RN_EIP; return REG;}
64 $sp             { yylval = RN_ESP_AT_SIGNAL; return REG;}
65 $eip            { yylval = RN_EIP; return REG;}
66 $esp            { yylval = RN_ESP_AT_SIGNAL; return REG;}
67 $ebp            { yylval = RN_EBP; return REG;}
68 $eax            { yylval = RN_EAX; return REG;}
69 $ebx            { yylval = RN_EBX; return REG;}
70 $ecx            { yylval = RN_ECX; return REG;}
71 $edx            { yylval = RN_EDX; return REG;}
72 $esi            { yylval = RN_ESI; return REG;}
73 $edi            { yylval = RN_EDI; return REG;}
75 $es             { yylval = RN_ES;  return REG;}
76 $ds             { yylval = RN_DS;  return REG;}
77 $cs             { yylval = RN_CS;  return REG;}
78 $ss             { yylval = RN_SS;  return REG;}
80 info|inf|in             { return INFO; }
81 segments|segm           { return SEGMENTS; }
82 break|brea|bre          { return BREAK; }
83 enable|enabl|enab|ena   { return ENABLE;}
84 disable|disabl|disab|disa|dis { return DISABLE; }
86 quit|qui|qu     { return QUIT; }
88 help|hel|he     { return HELP; }
90 set|se          { return SET; }
92 bt              { return BACKTRACE; }
94 cont|con|co             { return CONT; }
96 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
98 define|defin|defi|def|de        { return DEFINE; }
99 abort|abor|abo                  { return ABORT; }
100 print|prin|pri|pr               { return PRINT; }
102 mode                            { return MODE; }
104 regs|reg|re     { return REGS; }
106 stack|stac|sta|st       { return STACK; }
108 p               { return 'p'; }
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'; }
116 q               { return 'q'; }
118 {IDENTIFIER}    {yylval = (int) make_symbol(yytext); 
119                   return IDENTIFIER;
120                  }
122 [ \t]+        /* Eat up whitespace */
124 .               { if(syntax_error == 0) {
125                 syntax_error ++; fprintf(stderr, "Syntax Error\n"); }
126                 }
130 #ifndef yywrap
131 int yywrap(void) { return 1; }
132 #endif
134 #ifdef USE_READLINE
135 #ifndef whitespace
136 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
137 #endif
139 #if 0
140 /* Used only with GNU readline */
141 #include "readline/readline.h"
142 #include "readline/chardefs.h"
143 #endif
145 /* Strip whitespace from the start and end of STRING. */
146 static void stripwhite (char *string)
148   register int i = 0;
150   while (whitespace (string[i]))
151     i++;
153   if (i)
154     strcpy (string, string + i);
156   i = strlen (string) - 1;
158   while (i > 0 && whitespace (string[i]))
159     i--;
161   string[++i] = '\0';
164 dbg_read(char * buf, int size){
165         char * line;
166         int len;
168         do{
169                 flush_symbols();
170                 line = readline ("Wine-dbg>");
171                 if (!line) return 0;
172                 len = strlen(line);
174                 /* Remove leading and trailing whitespace from the line.
175                    Then, if there is anything left, add it to the history list
176                    and execute it. */
177                 stripwhite (line);
178                         
179                 if (*line)
180                 {
181                     add_history (line);
182                     if(size < len + 1){
183                         fprintf(stderr,"Fatal readline goof.\n");
184                         exit(0);
185                     }
186                     strcpy(buf, line);
187                     buf[len] = '\n';
188                     buf[len+1] = 0;
189                     free(line);
190                     return len + 1;
191                 }
192         } while (1==1);
195 static char *local_symbols[10];
196 static int next_symbol;
198 char * make_symbol(char * symbol){
199         return local_symbols[next_symbol++] = strdup(symbol);
202 void
203 flush_symbols(){
204         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
205         next_symbol = 0;
208 #endif