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