Release 960717
[wine/multimedia.git] / debugger / debug.l
blob71b2215b65abd376e81394ddd4105377a542038d
1 /*
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 static int syntax_error;
32 DIGIT      [0-9]
33 HEXDIGIT   [0-9a-fA-F]
34 FORMAT     [bcdiswx]
35 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
39 \n              { syntax_error = 0; return tEOL; } /*Indicates end of command*/
41 "||"            { return OP_LOR; }
42 "&&"            { return OP_LAND; }
43 "=="            { return OP_EQ; }
44 "!="            { return OP_NE; }
45 "<="            { return OP_LE; }
46 ">="            { return OP_GE; }
47 "<<"            { return OP_SHL; }
48 ">>"            { return OP_SHR; }
49 [-+<=>|&^()*/%:!~]      { return *yytext; }
51 "0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
52 {DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
54 "/"{DIGIT}+{FORMAT}  { char * last;
55                        yylval.integer = strtol( yytext+1, &last, NULL );
56                        yylval.integer = (yylval.integer << 8) | *last;
57                        return tFORMAT; }
58 "/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
60 $pc     { yylval.reg = REG_EIP; return tREG; }
61 $flags  { yylval.reg = REG_EFL; return tREG; }
62 $eip    { yylval.reg = REG_EIP; return tREG; }
63 $ip     { yylval.reg = REG_IP;  return tREG; }
64 $esp    { yylval.reg = REG_ESP; return tREG; }
65 $sp     { yylval.reg = REG_SP;  return tREG; }
66 $eax    { yylval.reg = REG_EAX; return tREG; }
67 $ebx    { yylval.reg = REG_EBX; return tREG; }
68 $ecx    { yylval.reg = REG_ECX; return tREG; }
69 $edx    { yylval.reg = REG_EDX; return tREG; }
70 $esi    { yylval.reg = REG_ESI; return tREG; }
71 $edi    { yylval.reg = REG_EDI; return tREG; }
72 $ebp    { yylval.reg = REG_EBP; return tREG; }
73 $ax     { yylval.reg = REG_AX;  return tREG; }
74 $bx     { yylval.reg = REG_BX;  return tREG; }
75 $cx     { yylval.reg = REG_CX;  return tREG; }
76 $dx     { yylval.reg = REG_DX;  return tREG; }
77 $si     { yylval.reg = REG_SI;  return tREG; }
78 $di     { yylval.reg = REG_DI;  return tREG; }
79 $bp     { yylval.reg = REG_BP;  return tREG; }
80 $es     { yylval.reg = REG_ES;  return tREG; }
81 $ds     { yylval.reg = REG_DS;  return tREG; }
82 $cs     { yylval.reg = REG_CS;  return tREG; }
83 $ss     { yylval.reg = REG_SS;  return tREG; }
84 $fs     { yylval.reg = REG_FS;  return tREG; }
85 $gs     { yylval.reg = REG_GS;  return tREG; }
87 info|inf|in                     { return tINFO; }
88 show|sho|sh                     { return tINFO; }
89 list|lis|li|l                   { return tLIST; }
90 break|brea|bre|br|b             { return tBREAK; }
91 enable|enabl|enab|ena           { return tENABLE;}
92 disable|disabl|disab|disa|dis   { return tDISABLE; }
93 delete|delet|dele|del           { return tDELETE; }
94 quit|qui|qu|q                   { return tQUIT; }
95 set|se                          { return tSET; }
96 walk|w                          { return tWALK; }
97 x                               { return tEXAM; }
99 class|clas|cla                  { return tCLASS; }
100 module|modul|modu|mod           { return tMODULE; }
101 queue|queu|que                  { return tQUEUE; }
102 registers|regs|reg|re           { return tREGS; }
103 segments|segment|segm|seg|se    { return tSEGMENTS; }
104 stack|stac|sta|st               { return tSTACK; }
105 window|windo|wind|win|wnd       { return tWND; }
107 help|hel|he|"?"                 { return tHELP; }
109 backtrace|backtrac|backtra|backt|back|bac|ba|bt { return tBACKTRACE; }
110 where|wher|whe                  { return tBACKTRACE; }
112 cont|con|co|c                   { return tCONT; }
113 step|ste|st|s                   { return tSTEP; }
114 next|nex|ne|n                   { return tNEXT; }
116 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return tSYMBOLFILE; }
118 define|defin|defi|def|de        { return tDEFINE; }
119 abort|abor|abo                  { return tABORT; }
120 print|prin|pri|pr|p             { return tPRINT; }
122 mode                            { return tMODE; }
124 {IDENTIFIER}    { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
126 [ \t]+        /* Eat up whitespace */
128 .               { if (syntax_error == 0)
129                   {
130                     syntax_error ++; fprintf(stderr, "Syntax Error\n");
131                   }
132                 }
136 #ifndef yywrap
137 int yywrap(void) { return 1; }
138 #endif
140 #ifndef DONT_USE_READLINE
142 #ifndef whitespace
143 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
144 #endif
147 /* Strip whitespace from the start and end of STRING. */
148 static void stripwhite (char *string)
150   register int i = 0;
152   while (whitespace (string[i]))
153     i++;
155   if (i)
156     strcpy (string, string + i);
158   i = strlen (string) - 1;
160   while (i > 0 && whitespace (string[i]))
161     i--;
163   string[++i] = '\0';
166 static int dbg_read(char * buf, int size)
168     static char last_line[256] = "";
169     char * line;
170     int len;
171     
172     for (;;)
173     {
174         flush_symbols();
175         line = readline ("Wine-dbg>");
176         if (!line)
177         {
178             fprintf( stderr, "\n" );
179             exit(0);
180         }
182         /* Remove leading and trailing whitespace from the line */
184         stripwhite (line);
186         /* If there is anything left, add it to the history list
187            and execute it. Otherwise, re-execute last command. */
189         if (*line)
190         {
191             add_history( line );
192             strncpy( last_line, line, 255 );
193             last_line[255] = '\0'; 
194        }
196         free( line );
197         line = last_line;
199         if ((len = strlen(line)) > 0)
200         {
201             if (size < len + 1)
202             {
203                 fprintf(stderr,"Fatal readline goof.\n");
204                 exit(0);
205             }
206             strcpy(buf, line);
207             buf[len] = '\n';
208             buf[len+1] = 0;
209             return len + 1;
210         }
211     }
214 static char *local_symbols[10];
215 static int next_symbol;
217 char * make_symbol(char * symbol){
218         return local_symbols[next_symbol++] = xstrdup(symbol);
221 void flush_symbols()
223         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
224         next_symbol = 0;
227 #endif  /* DONT_USE_READLINE */