Release 951124
[wine/multimedia.git] / debugger / debug.l
blobe6de8fcc1b34b1586037cfedc85cb92b2636f684
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 "y.tab.h"
15 #ifdef USE_READLINE
16 #undef YY_INPUT
17 #define YY_INPUT(buf,result,max_size) \
18         if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
19             YY_FATAL_ERROR( "read() in flex scanner failed" );
20 #endif
22 extern char * readline(char *);
23 extern void add_history(char *);
24 static int dbg_read(char * buf, int size);
25 static char * make_symbol(char *);
26 void flush_symbols();
27 static int syntax_error;
30 DIGIT      [0-9]
31 HEXDIGIT   [0-9a-fA-F]
32 FORMAT     [bcdiswx]
33 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
37 \n              { syntax_error = 0; return EOL; } /*Indicates end of command*/
39 "||"            { return OP_LOR; }
40 "&&"            { return OP_LAND; }
41 "=="            { return OP_EQ; }
42 "!="            { return OP_NE; }
43 "<="            { return OP_LE; }
44 ">="            { return OP_GE; }
45 "<<"            { return OP_SHL; }
46 ">>"            { return OP_SHR; }
47 [-+<=>|&^()*/%:!~]      { return *yytext; }
49 "0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return NUM; }
50 {DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return NUM; }
52 "/"{DIGIT}+{FORMAT}  { char * last;
53                        yylval.integer = strtol( yytext+1, &last, NULL );
54                        yylval.integer = (yylval.integer << 8) | *last;
55                        return FORMAT; }
56 "/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return FORMAT; }
58 $pc     { yylval.reg = REG_EIP; return REG; }
59 $flags  { yylval.reg = REG_EFL; return REG; }
60 $eip    { yylval.reg = REG_EIP; return REG; }
61 $ip     { yylval.reg = REG_IP;  return REG; }
62 $esp    { yylval.reg = REG_ESP; return REG; }
63 $sp     { yylval.reg = REG_SP;  return REG; }
64 $eax    { yylval.reg = REG_EAX; return REG; }
65 $ebx    { yylval.reg = REG_EBX; return REG; }
66 $ecx    { yylval.reg = REG_ECX; return REG; }
67 $edx    { yylval.reg = REG_EDX; return REG; }
68 $esi    { yylval.reg = REG_ESI; return REG; }
69 $edi    { yylval.reg = REG_EDI; return REG; }
70 $ebp    { yylval.reg = REG_EBP; return REG; }
71 $ax     { yylval.reg = REG_AX;  return REG; }
72 $bx     { yylval.reg = REG_BX;  return REG; }
73 $cx     { yylval.reg = REG_CX;  return REG; }
74 $dx     { yylval.reg = REG_DX;  return REG; }
75 $si     { yylval.reg = REG_SI;  return REG; }
76 $di     { yylval.reg = REG_DI;  return REG; }
77 $bp     { yylval.reg = REG_BP;  return REG; }
78 $es     { yylval.reg = REG_ES;  return REG; }
79 $ds     { yylval.reg = REG_DS;  return REG; }
80 $cs     { yylval.reg = REG_CS;  return REG; }
81 $ss     { yylval.reg = REG_SS;  return REG; }
83 info|inf|in                     { return INFO; }
84 show|sho|sh                     { return INFO; }
85 list|lis|li|l                   { return LIST; }
86 segments|segment|segm|seg|se    { return SEGMENTS; }
87 break|brea|bre|br|b             { return BREAK; }
88 enable|enabl|enab|ena           { return ENABLE;}
89 disable|disabl|disab|disa|dis   { return DISABLE; }
90 delete|delet|dele|del           { return DELETE; }
91 quit|qui|qu|q                   { return QUIT; }
92 x                               { return EXAM; }
94 help|hel|he|"?"                 { return HELP; }
96 set|se                          { return SET; }
98 bt                              { return BACKTRACE; }
100 cont|con|co|c                   { return CONT; }
101 step|ste|st|s                   { return STEP; }
102 next|nex|ne|n                   { return NEXT; }
104 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
106 define|defin|defi|def|de        { return DEFINE; }
107 abort|abor|abo                  { return ABORT; }
108 print|prin|pri|pr|p             { return PRINT; }
110 mode                            { return MODE; }
112 registers|regs|reg|re           { return REGS; }
114 stack|stac|sta|st               { return STACK; }
116 {IDENTIFIER}    { yylval.string = make_symbol(yytext); return IDENTIFIER; }
118 [ \t]+        /* Eat up whitespace */
120 .               { if (syntax_error == 0)
121                   {
122                     syntax_error ++; fprintf(stderr, "Syntax Error\n");
123                   }
124                 }
128 #ifndef yywrap
129 int yywrap(void) { return 1; }
130 #endif
132 #ifdef USE_READLINE
133 #ifndef whitespace
134 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
135 #endif
138 /* Strip whitespace from the start and end of STRING. */
139 static void stripwhite (char *string)
141   register int i = 0;
143   while (whitespace (string[i]))
144     i++;
146   if (i)
147     strcpy (string, string + i);
149   i = strlen (string) - 1;
151   while (i > 0 && whitespace (string[i]))
152     i--;
154   string[++i] = '\0';
157 static int dbg_read(char * buf, int size)
159     static char last_line[256] = "";
160     char * line;
161     int len;
162     
163     for (;;)
164     {
165         flush_symbols();
166         line = readline ("Wine-dbg>");
167         if (!line) exit(0);
169         /* Remove leading and trailing whitespace from the line */
171         stripwhite (line);
173         /* If there is anything left, add it to the history list
174            and execute it. Otherwise, re-execute last command. */
176         if (*line)
177         {
178             add_history( line );
179             strncpy( last_line, line, 255 );
180             last_line[255] = '\0'; 
181        }
183         free( line );
184         line = last_line;
186         if ((len = strlen(line)) > 0)
187         {
188             if (size < len + 1)
189             {
190                 fprintf(stderr,"Fatal readline goof.\n");
191                 exit(0);
192             }
193             strcpy(buf, line);
194             buf[len] = '\n';
195             buf[len+1] = 0;
196             return len + 1;
197         }
198     }
201 static char *local_symbols[10];
202 static int next_symbol;
204 char * make_symbol(char * symbol){
205         return local_symbols[next_symbol++] = strdup(symbol);
208 void
209 flush_symbols(){
210         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
211         next_symbol = 0;
214 #endif