Release 961222
[wine/multimedia.git] / debugger / debug.l
blob93e0929bd34877a3b7875a64c6e42e20513290ef
1 /* -*-C-*-
2  * Lexical scanner for command line parsing
3  *
4  * Copyright 1993 Eric Youngdale
5  */
7 %{
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "debugger.h"
12 #include "xmalloc.h"
13 #include "y.tab.h"
15 #ifndef DONT_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" );
21 extern char * readline(char *);
22 extern void add_history(char *);
23 static int dbg_read(char * buf, int size);
24 static char * make_symbol(char *);
25 void flush_symbols();
27 #endif  /* DONT_USE_READLINE */
29 #define YY_NO_UNPUT
31 static int syntax_error;
34 DIGIT      [0-9]
35 HEXDIGIT   [0-9a-fA-F]
36 FORMAT     [bcdiswx]
37 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
41 \n              { syntax_error = 0; return tEOL; } /*Indicates end of command*/
43 "||"            { return OP_LOR; }
44 "&&"            { return OP_LAND; }
45 "=="            { return OP_EQ; }
46 "!="            { return OP_NE; }
47 "<="            { return OP_LE; }
48 ">="            { return OP_GE; }
49 "<<"            { return OP_SHL; }
50 ">>"            { return OP_SHR; }
51 [-+<=>|&^()*/%:!~]      { return *yytext; }
53 "0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
54 {DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
56 "/"{DIGIT}+{FORMAT}  { char * last;
57                        yylval.integer = strtol( yytext+1, &last, NULL );
58                        yylval.integer = (yylval.integer << 8) | *last;
59                        return tFORMAT; }
60 "/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
62 $pc     { yylval.reg = REG_EIP; return tREG; }
63 $flags  { yylval.reg = REG_EFL; return tREG; }
64 $eip    { yylval.reg = REG_EIP; return tREG; }
65 $ip     { yylval.reg = REG_IP;  return tREG; }
66 $esp    { yylval.reg = REG_ESP; return tREG; }
67 $sp     { yylval.reg = REG_SP;  return tREG; }
68 $eax    { yylval.reg = REG_EAX; return tREG; }
69 $ebx    { yylval.reg = REG_EBX; return tREG; }
70 $ecx    { yylval.reg = REG_ECX; return tREG; }
71 $edx    { yylval.reg = REG_EDX; return tREG; }
72 $esi    { yylval.reg = REG_ESI; return tREG; }
73 $edi    { yylval.reg = REG_EDI; return tREG; }
74 $ebp    { yylval.reg = REG_EBP; return tREG; }
75 $ax     { yylval.reg = REG_AX;  return tREG; }
76 $bx     { yylval.reg = REG_BX;  return tREG; }
77 $cx     { yylval.reg = REG_CX;  return tREG; }
78 $dx     { yylval.reg = REG_DX;  return tREG; }
79 $si     { yylval.reg = REG_SI;  return tREG; }
80 $di     { yylval.reg = REG_DI;  return tREG; }
81 $bp     { yylval.reg = REG_BP;  return tREG; }
82 $es     { yylval.reg = REG_ES;  return tREG; }
83 $ds     { yylval.reg = REG_DS;  return tREG; }
84 $cs     { yylval.reg = REG_CS;  return tREG; }
85 $ss     { yylval.reg = REG_SS;  return tREG; }
86 $fs     { yylval.reg = REG_FS;  return tREG; }
87 $gs     { yylval.reg = REG_GS;  return tREG; }
89 up                              { return tUP; }
90 down|dow|do                     { return tDOWN; }
91 frame|fram|fra|fr               { return tFRAME; }
92 locals|local|loca|loc           { return tLOCAL; }
93 info|inf|in                     { return tINFO; }
94 show|sho|sh                     { return tINFO; }
95 list|lis|li|l                   { return tLIST; }
96 break|brea|bre|br|b             { return tBREAK; }
97 enable|enabl|enab|ena           { return tENABLE;}
98 disable|disabl|disab|disa|dis   { return tDISABLE; }
99 delete|delet|dele|del           { return tDELETE; }
100 quit|qui|qu|q                   { return tQUIT; }
101 set|se                          { return tSET; }
102 walk|w                          { return tWALK; }
103 x                               { return tEXAM; }
105 class|clas|cla                  { return tCLASS; }
106 module|modul|modu|mod           { return tMODULE; }
107 queue|queu|que                  { return tQUEUE; }
108 registers|regs|reg|re           { return tREGS; }
109 segments|segment|segm|seg|se    { return tSEGMENTS; }
110 stack|stac|sta|st               { return tSTACK; }
111 window|windo|wind|win|wnd       { return tWND; }
113 help|hel|he|"?"                 { return tHELP; }
115 backtrace|backtrac|backtra|backt|back|bac|ba|bt { return tBACKTRACE; }
116 where|wher|whe                  { return tBACKTRACE; }
118 cont|con|co|c                   { return tCONT; }
119 step|ste|st|s                   { return tSTEP; }
120 next|nex|ne|n                   { return tNEXT; }
122 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return tSYMBOLFILE; }
124 define|defin|defi|def|de        { return tDEFINE; }
125 abort|abor|abo                  { return tABORT; }
126 print|prin|pri|pr|p             { return tPRINT; }
128 mode                            { return tMODE; }
130 {IDENTIFIER}    { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
132 [ \t]+        /* Eat up whitespace */
134 .               { if (syntax_error == 0)
135                   {
136                     syntax_error ++; fprintf(stderr, "Syntax Error\n");
137                   }
138                 }
142 #ifndef yywrap
143 int yywrap(void) { return 1; }
144 #endif
146 #ifndef DONT_USE_READLINE
148 #ifndef whitespace
149 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
150 #endif
153 /* Strip whitespace from the start and end of STRING. */
154 static void stripwhite (char *string)
156   register int i = 0;
158   while (whitespace (string[i]))
159     i++;
161   if (i)
162     strcpy (string, string + i);
164   i = strlen (string) - 1;
166   while (i > 0 && whitespace (string[i]))
167     i--;
169   string[++i] = '\0';
172 static int dbg_read(char * buf, int size)
174     static char last_line[256] = "";
175     char * line;
176     int len;
177     
178     for (;;)
179     {
180         flush_symbols();
181         line = readline ("Wine-dbg>");
182         if (!line)
183         {
184             fprintf( stderr, "\n" );
185             exit(0);
186         }
188         /* Remove leading and trailing whitespace from the line */
190         stripwhite (line);
192         /* If there is anything left, add it to the history list
193            and execute it. Otherwise, re-execute last command. */
195         if (*line)
196         {
197             add_history( line );
198             strncpy( last_line, line, 255 );
199             last_line[255] = '\0'; 
200        }
202         free( line );
203         line = last_line;
205         if ((len = strlen(line)) > 0)
206         {
207             if (size < len + 1)
208             {
209                 fprintf(stderr,"Fatal readline goof.\n");
210                 exit(0);
211             }
212             strcpy(buf, line);
213             buf[len] = '\n';
214             buf[len+1] = 0;
215             return len + 1;
216         }
217     }
220 static char *local_symbols[10];
221 static int next_symbol;
223 char * make_symbol(char * symbol){
224         return local_symbols[next_symbol++] = xstrdup(symbol);
227 void flush_symbols()
229         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
230         next_symbol = 0;
233 #endif  /* DONT_USE_READLINE */