Release 0.4.3
[wine] / debugger / debug.l
1
2
3 /* Lexical scanner for command line parsing in the Wine debugger
4  *
5  * Version 1.0
6  * Eric Youngdale
7  * 9/93
8  */
9
10 %{
11 #include <stdio.h>
12 #include <string.h>
13 #include "dbg.tab.h"
14 #include "regpos.h"
15
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
22
23 extern char * readline(char *);
24 static char * make_symbol(char *);
25 void flush_symbols();
26 static int syntax_error;
27 %}
28
29 DIGIT   [0-9]
30 HEXDIGIT [0-9a-fA-F]
31
32 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
33
34 %%
35
36 \n              { syntax_error = 0; return '\n'; } /* Indicate end of command */
37
38 "+"             { return '+'; } 
39
40 "-"             { return '-'; } 
41
42 "/"             { return '/'; } 
43
44 "="             { return '='; } 
45
46 "("             { return '('; } 
47
48 ")"             { return ')'; } 
49
50 "*"             { return '*'; } 
51
52 "?"             { return HELP; }
53
54 "0x"+{HEXDIGIT}+   {
55                 sscanf(yytext, "%lx", &yylval);
56                 return NUM;
57                 }
58
59 {DIGIT}+   {
60                 sscanf(yytext, "%lx", &yylval);
61                 return NUM;
62                 }
63
64 $pc             { yylval = RN_EIP; return REG;}
65 $sp             { yylval = RN_ESP; return REG;}
66 $eip            { yylval = RN_EIP; return REG;}
67 $esp            { yylval = RN_ESP; 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;}
75
76 info|inf|in             { return INFO; }
77
78 quit|qui|qu     { return QUIT; }
79
80 help|hel|he     { return HELP; }
81
82 set|se          { return SET; }
83
84 cont|con|co             { return CONT; }
85
86 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
87
88 define|defin|defi|def|de        { return DEFINE; }
89 print|prin|pri|pr               { return PRINT; }
90
91 regs|reg|re     { return REGS; }
92
93 stack|stac|sta|st       { return STACK; }
94
95 x               { return 'x'; }
96 d               { return 'd'; }
97 i               { return 'i'; }
98 w               { return 'w'; }
99 b               { return 'b'; }
100 s               { return 's'; }
101 c               { return 'c'; }
102
103 {IDENTIFIER}    {yylval = (int) make_symbol(yytext); 
104                   return IDENTIFIER;
105                  }
106
107 [ \t]+        /* Eat up whitespace */
108
109 .               { if(syntax_error == 0) {
110                 syntax_error ++; fprintf(stderr, "Syntax Error\n"); }
111                 }
112
113 %%
114
115 #ifdef USE_READLINE
116 #ifndef whitespace
117 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
118 #endif
119
120 #if 0
121 /* Used only with GNU readline */
122 #include "readline/readline.h"
123 #include "readline/chardefs.h"
124 #endif
125
126 dbg_read(char * buf, int size){
127         char * line;
128         int len;
129
130         do{
131                 flush_symbols();
132                 line = readline ("Wine-dbg>");
133                 len = strlen(line);
134                                 
135                 if (!line)
136                 {
137                         return 0;
138                 }
139                 else
140                 {
141                         /* Remove leading and trailing whitespace from the line.
142                            Then, if there is anything left, add it to the history list
143                            and execute it. */
144                         stripwhite (line);
145                         
146                         if (*line)
147                         {
148                                 add_history (line);
149                                 if(size < len + 1){
150                                         fprintf(stderr,"Fatal readline goof.\n");
151                                         exit(0);
152                                 };
153                                 strcpy(buf, line);
154                                 buf[len] = '\n';
155                                 buf[len+1] = 0;
156                                 free(line);
157                                 return len + 1;
158                         }
159                 }
160
161         } while (1==1);
162 }
163
164 /* Strip whitespace from the start and end of STRING. */
165 stripwhite (string)
166      char *string;
167 {
168   register int i = 0;
169
170   while (whitespace (string[i]))
171     i++;
172
173   if (i)
174     strcpy (string, string + i);
175
176   i = strlen (string) - 1;
177
178   while (i > 0 && whitespace (string[i]))
179     i--;
180
181   string[++i] = '\0';
182 }
183
184 static char *local_symbols[10];
185 static int next_symbol;
186
187 char * make_symbol(char * symbol){
188         return local_symbols[next_symbol++] = strdup(symbol);
189 }
190
191 void
192 flush_symbols(){
193         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
194         next_symbol = 0;
195 }
196
197 #endif