Terminate image data with a '>' [The PSLRM is rather vague about this].
[wine/multimedia.git] / debugger / debug.l
blob0adf93ce3111ca939e15f6a4d792780bbfbe2ee5
1 /* -*-C-*-
2  * Lexical scanner for command line parsing
3  *
4  * Copyright 1993 Eric Youngdale
5  */
7 %{
8 #include <stdlib.h>
9 #include <string.h>
10 #include "debugger.h"
11 #include "y.tab.h"
13 #ifdef DBG_need_heap
14 #define malloc(x) DBG_alloc(x)
15 #define realloc(x,y) DBG_realloc(x,y)
16 #define free(x) DBG_free(x)
17 #endif
19 #ifndef DONT_USE_READLINE
20 #undef YY_INPUT
21 #define YY_INPUT(buf,result,max_size) \
22         if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
23             YY_FATAL_ERROR( "read() in flex scanner failed" );
25 static int dbg_read(char * buf, int size);
26 static char * make_symbol(char *);
28 #endif  /* DONT_USE_READLINE */
30 #define YY_NO_UNPUT
32 static int syntax_error;
35 DIGIT      [0-9]
36 HEXDIGIT   [0-9a-fA-F]
37 FORMAT     [ubcdiswx]
38 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~@]*
39 PATHNAME   [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
40 STRING     \"[^\n"]+\"
42 %s FORMAT_EXPECTED
43 %s PATH_EXPECTED
44 %s INFO_CMD
45 %s HELP_CMD
46 %s DEL_CMD
47 %s WALK_CMD
48 %s SHOW_CMD
49 %s NOCMD
50 %s DEBUGSTR
54 \n              { BEGIN(0); syntax_error = 0; 
55                   return tEOL; } /*Indicates end of command.  Reset state. */
57 "||"            { return OP_LOR; }
58 "&&"            { return OP_LAND; }
59 "=="            { return OP_EQ; }
60 "!="            { return OP_NE; }
61 "<="            { return OP_LE; }
62 ">="            { return OP_GE; }
63 "<<"            { return OP_SHL; }
64 ">>"            { return OP_SHR; }
65 "->"            { return OP_DRF; }
66 [-+<=>|&^()*/%:!~,\.]   { return *yytext; }
67 "["             { return *yytext; }
68 "]"             { return *yytext; }
70 "0x"{HEXDIGIT}+      { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
71 {DIGIT}+             { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
74 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT}  { char * last;
75                        yylval.integer = strtol( yytext+1, &last, NULL );
76                        yylval.integer = (yylval.integer << 8) | *last;
77                        return tFORMAT; }
80 <FORMAT_EXPECTED>"/"{FORMAT}          { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
82 {STRING} { yylval.string = make_symbol(yytext); return tSTRING; }
83 <DEBUGSTR>[a-z+\-,]* { yylval.string = yytext; return tDEBUGSTR; }
85 <INITIAL>info|inf|in                    { BEGIN(INFO_CMD); return tINFO; }
86 <INITIAL>up                             { BEGIN(NOCMD); return tUP; }
87 <INITIAL>down|dow|do                    { BEGIN(NOCMD); return tDOWN; }
88 <INITIAL>frame|fram|fra|fr              { BEGIN(NOCMD); return tFRAME; }
89 <INITIAL>list|lis|li|l                  { BEGIN(PATH_EXPECTED); return tLIST; }
90 <INITIAL>enable|enabl|enab|ena          { BEGIN(NOCMD); return tENABLE;}
91 <INITIAL>disable|disabl|disab|disa|dis  { BEGIN(NOCMD); return tDISABLE; }
92 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
93 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp     { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
94 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und       { BEGIN(NOCMD); return tUNDISPLAY; }
95 <INITIAL>delete|delet|dele|del          { BEGIN(DEL_CMD); return tDELETE; }
96 <INITIAL>quit|qui|qu|q                  { BEGIN(NOCMD); return tQUIT; }
97 <INITIAL>set|se                         { BEGIN(NOCMD); return tSET; }
98 <INITIAL>walk|w                         { BEGIN(WALK_CMD); return tWALK; }
99 <INITIAL>x                              { BEGIN(FORMAT_EXPECTED); return tEXAM; }
100 <INITIAL>help|hel|he|"?"                { BEGIN(HELP_CMD); return tHELP; }
102 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
103 <INITIAL>where|wher|whe                 { BEGIN(NOCMD); return tBACKTRACE; }
105 <INITIAL>cont|con|co|c                  { BEGIN(NOCMD); return tCONT; }
106 <INITIAL>pass|pas|pa                    { BEGIN(NOCMD); return tPASS; }
107 <INITIAL>condition|conditio|conditi|condit|condi|cond   { BEGIN(NOCMD); return tCOND; }
108 <INITIAL>step|ste|st|s                  { BEGIN(NOCMD); return tSTEP; }
109 <INITIAL>next|nex|ne|n                  { BEGIN(NOCMD); return tNEXT; }
110 <INITIAL>stepi|si                       { BEGIN(NOCMD); return tSTEPI; }
111 <INITIAL>nexti|ni                       { BEGIN(NOCMD); return tNEXTI; }
112 <INITIAL>finish|finis|fini|fin|fi       { BEGIN(NOCMD); return tFINISH; }
114 <INITIAL>abort|abor|abo                 { BEGIN(NOCMD); return tABORT; }
115 <INITIAL>print|prin|pri|pr|p            { BEGIN(FORMAT_EXPECTED); return tPRINT; }
117 <INITIAL>mode                           { BEGIN(NOCMD); return tMODE; }
118 <INITIAL>show|sho|sh                    { BEGIN(SHOW_CMD); return tSHOW; }
119 <INITIAL>symbolfile|symbols|symbol|sf   { BEGIN(PATH_EXPECTED); return tSYMBOLFILE; }
121 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b   { BEGIN(PATH_EXPECTED); return tBREAK; }
122 <INITIAL>watch|watc|wat                 { BEGIN(PATH_EXPECTED); return tWATCH; }
123 <INITIAL>whatis|whati|what              { BEGIN(PATH_EXPECTED); return tWHATIS; }
125 <INFO_CMD>share|shar|sha                { return tSHARE; }
126 <INFO_CMD>locals|local|loca|loc         { return tLOCAL; }
127 <INFO_CMD,WALK_CMD>class|clas|cla       { return tCLASS; }
128 <INFO_CMD,WALK_CMD>module|modul|modu|mod  { return tMODULE; }
129 <INFO_CMD,WALK_CMD>queue|queu|que       { return tQUEUE; }
130 <INFO_CMD,WALK_CMD>process|proces|proce|proc            { return tPROCESS; }
131 <INFO_CMD,WALK_CMD>threads|thread|threa|thre|thr|th { return tTHREAD; }
132 <INFO_CMD,WALK_CMD>modref|modre|modr    { return tMODREF; }
133 <INFO_CMD>registers|regs|reg|re         { return tREGS; }
134 <INFO_CMD>segments|segment|segm|seg|se  { return tSEGMENTS; }
135 <INFO_CMD>stack|stac|sta|st             { return tSTACK; }
136 <INFO_CMD>maps|map                      { return tMAPS; }
137 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd    { return tWND; }
138 <HELP_CMD>info|inf|in                   { return tINFO; }
140 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir { 
141                         BEGIN(PATH_EXPECTED); return tDIR; }
143 char                                    { return tCHAR; }
144 short                                   { return tSHORT; }
145 int                                     { return tINT; }
146 long                                    { return tLONG; }
147 float                                   { return tFLOAT; }
148 double                                  { return tDOUBLE; }
149 unsigned                                { return tUNSIGNED; }
150 signed                                  { return tSIGNED; }
151 struct                                  { return tSTRUCT; }
152 union                                   { return tUNION; }
153 enum                                    { return tENUM; }
155 {IDENTIFIER}    { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
156 "$"{IDENTIFIER} { yylval.string = make_symbol(yytext+1); return tINTVAR; }
158 <PATH_EXPECTED>{PATHNAME}       { yylval.string = make_symbol(yytext); return tPATH; }
160 [ \t]+        /* Eat up whitespace */
162 .               { if (syntax_error == 0)
163                   {
164                     syntax_error ++; DEBUG_Printf(DBG_CHN_MESG, "Syntax Error\n");
165                   }
166                 }
171 #ifndef yywrap
172 int yywrap(void) { return 1; }
173 #endif
175 #ifndef DONT_USE_READLINE
177 #ifndef whitespace
178 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
179 #endif
182 /* Strip whitespace from the start and end of STRING. */
183 static void stripwhite (char *string)
185   register int i = 0;
187   while (whitespace (string[i]))
188     i++;
190   if (i)
191     strcpy (string, string + i);
193   i = strlen (string) - 1;
195   while (i > 0 && whitespace (string[i]))
196     i--;
198   string[++i] = '\0';
201 static int dbg_read(char * buf, int size)
203     static char last_line[256] = "";
204     char * line;
205     int len;
206     
207     for (;;)
208     {
209         flush_symbols();
210         line = readline ("Wine-dbg>");
211         if (!line)
212         {
213             DEBUG_Printf( DBG_CHN_MESG, "\n" );
214             DEBUG_Exit(0);
215         }
217         /* Remove leading and trailing whitespace from the line */
219         stripwhite (line);
221         /* If there is anything left, add it to the history list
222            and execute it. Otherwise, re-execute last command. */
224         if (*line)
225         {
226             add_history( line );
227             strncpy( last_line, line, 255 );
228             last_line[255] = '\0'; 
229        }
231         free( line );
232         line = last_line;
234         if ((len = strlen(line)) > 0)
235         {
236             if (size < len + 1)
237             {
238                 DEBUG_Printf(DBG_CHN_MESG,"Fatal readline goof.\n");
239                 DEBUG_Exit(0);
240             }
241             strcpy(buf, line);
242             buf[len] = '\n';
243             buf[len+1] = 0;
244             return len + 1;
245         }
246     }
249 static char *local_symbols[30];
250 static int next_symbol;
252 static char * make_symbol(char * symbol)
254         return local_symbols[next_symbol++] = DBG_strdup(symbol);
257 void flush_symbols(void)
259         while(--next_symbol>= 0) DBG_free(local_symbols[next_symbol]);
260         next_symbol = 0;
263 #endif  /* DONT_USE_READLINE */