Release 960225
[wine.git] / debugger / debug.l
blob50c66d73d489aa0db26b42b09be7aba131ad285b
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 <stdlib.h>
11 #include <string.h>
12 #include "debugger.h"
13 #include "xmalloc.h"
14 #include "y.tab.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 extern void add_history(char *);
25 static int dbg_read(char * buf, int size);
26 static char * make_symbol(char *);
27 void flush_symbols();
28 static int syntax_error;
31 DIGIT      [0-9]
32 HEXDIGIT   [0-9a-fA-F]
33 FORMAT     [bcdiswx]
34 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
38 \n              { syntax_error = 0; return EOL; } /*Indicates end of command*/
40 "||"            { return OP_LOR; }
41 "&&"            { return OP_LAND; }
42 "=="            { return OP_EQ; }
43 "!="            { return OP_NE; }
44 "<="            { return OP_LE; }
45 ">="            { return OP_GE; }
46 "<<"            { return OP_SHL; }
47 ">>"            { return OP_SHR; }
48 [-+<=>|&^()*/%:!~]      { return *yytext; }
50 "0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return NUM; }
51 {DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return NUM; }
53 "/"{DIGIT}+{FORMAT}  { char * last;
54                        yylval.integer = strtol( yytext+1, &last, NULL );
55                        yylval.integer = (yylval.integer << 8) | *last;
56                        return FORMAT; }
57 "/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return FORMAT; }
59 $pc     { yylval.reg = REG_EIP; return REG; }
60 $flags  { yylval.reg = REG_EFL; return REG; }
61 $eip    { yylval.reg = REG_EIP; return REG; }
62 $ip     { yylval.reg = REG_IP;  return REG; }
63 $esp    { yylval.reg = REG_ESP; return REG; }
64 $sp     { yylval.reg = REG_SP;  return REG; }
65 $eax    { yylval.reg = REG_EAX; return REG; }
66 $ebx    { yylval.reg = REG_EBX; return REG; }
67 $ecx    { yylval.reg = REG_ECX; return REG; }
68 $edx    { yylval.reg = REG_EDX; return REG; }
69 $esi    { yylval.reg = REG_ESI; return REG; }
70 $edi    { yylval.reg = REG_EDI; return REG; }
71 $ebp    { yylval.reg = REG_EBP; return REG; }
72 $ax     { yylval.reg = REG_AX;  return REG; }
73 $bx     { yylval.reg = REG_BX;  return REG; }
74 $cx     { yylval.reg = REG_CX;  return REG; }
75 $dx     { yylval.reg = REG_DX;  return REG; }
76 $si     { yylval.reg = REG_SI;  return REG; }
77 $di     { yylval.reg = REG_DI;  return REG; }
78 $bp     { yylval.reg = REG_BP;  return REG; }
79 $es     { yylval.reg = REG_ES;  return REG; }
80 $ds     { yylval.reg = REG_DS;  return REG; }
81 $cs     { yylval.reg = REG_CS;  return REG; }
82 $ss     { yylval.reg = REG_SS;  return REG; }
84 info|inf|in                     { return INFO; }
85 show|sho|sh                     { return INFO; }
86 list|lis|li|l                   { return LIST; }
87 segments|segment|segm|seg|se    { return SEGMENTS; }
88 break|brea|bre|br|b             { return BREAK; }
89 enable|enabl|enab|ena           { return ENABLE;}
90 disable|disabl|disab|disa|dis   { return DISABLE; }
91 delete|delet|dele|del           { return DELETE; }
92 quit|qui|qu|q                   { return QUIT; }
93 x                               { return EXAM; }
95 help|hel|he|"?"                 { return HELP; }
97 set|se                          { return SET; }
99 bt                              { return BACKTRACE; }
101 cont|con|co|c                   { return CONT; }
102 step|ste|st|s                   { return STEP; }
103 next|nex|ne|n                   { return NEXT; }
105 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
107 define|defin|defi|def|de        { return DEFINE; }
108 abort|abor|abo                  { return ABORT; }
109 print|prin|pri|pr|p             { return PRINT; }
111 mode                            { return MODE; }
113 registers|regs|reg|re           { return REGS; }
115 stack|stac|sta|st               { return STACK; }
117 {IDENTIFIER}    { yylval.string = make_symbol(yytext); return IDENTIFIER; }
119 [ \t]+        /* Eat up whitespace */
121 .               { if (syntax_error == 0)
122                   {
123                     syntax_error ++; fprintf(stderr, "Syntax Error\n");
124                   }
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
139 /* Strip whitespace from the start and end of STRING. */
140 static void stripwhite (char *string)
142   register int i = 0;
144   while (whitespace (string[i]))
145     i++;
147   if (i)
148     strcpy (string, string + i);
150   i = strlen (string) - 1;
152   while (i > 0 && whitespace (string[i]))
153     i--;
155   string[++i] = '\0';
158 static int dbg_read(char * buf, int size)
160     static char last_line[256] = "";
161     char * line;
162     int len;
163     
164     for (;;)
165     {
166         flush_symbols();
167         line = readline ("Wine-dbg>");
168         if (!line) exit(0);
170         /* Remove leading and trailing whitespace from the line */
172         stripwhite (line);
174         /* If there is anything left, add it to the history list
175            and execute it. Otherwise, re-execute last command. */
177         if (*line)
178         {
179             add_history( line );
180             strncpy( last_line, line, 255 );
181             last_line[255] = '\0'; 
182        }
184         free( line );
185         line = last_line;
187         if ((len = strlen(line)) > 0)
188         {
189             if (size < len + 1)
190             {
191                 fprintf(stderr,"Fatal readline goof.\n");
192                 exit(0);
193             }
194             strcpy(buf, line);
195             buf[len] = '\n';
196             buf[len+1] = 0;
197             return len + 1;
198         }
199     }
202 static char *local_symbols[10];
203 static int next_symbol;
205 char * make_symbol(char * symbol){
206         return local_symbols[next_symbol++] = xstrdup(symbol);
209 void
210 flush_symbols(){
211         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
212         next_symbol = 0;
215 #endif