winecfg: Don't try to load the arts driver, the arts library is too buggy.
[wine/dibdrv.git] / tools / wrc / parser.l
blob11d110fa33f1175eaf46bb08439f62ed02947e12
1 /* -*-C-*-
2  *
3  * Copyright 1998-2000  Bertho A. Stultiens (BS)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  *
19  * History:
20  * 21-May-2000 BS       - Fixed the ident requirement of resource names
21  *                        which can be keywords.
22  * 30-Apr-2000 BS       - Reintegration into the wine-tree
23  * 11-Jan-2000 BS       - Very drastic cleanup because we don't have a
24  *                        preprocessor in here anymore.
25  * 02-Jan-2000 BS       - Removed the preprocessor code
26  * 23-Dec-1999 BS       - Removed the copyright for Martin von Loewis.
27  *                        There is really nothing left of his code in
28  *                        this parser.
29  * 20-Jun-1998 BS       - Changed the filename conversion. Filenames are
30  *                        case-sensitive inder *nix, but not under dos.
31  *                        default behaviour is to convert to lower case.
32  *                      - All backslashes are converted to forward and
33  *                        both single and double slash is recognized as
34  *                        MS/Borland does.
35  *                      - Fixed a bug in 'yywf' case that prevented
36  *                        double quoted names to be scanned propperly.
37  *
38  * 19-May-1998 BS       - Started to build a preprocessor.
39  *                      - Changed keyword processing completely to
40  *                        table-lookups.
41  *
42  * 20-Apr-1998 BS       - Added ';' comment stripping
43  *
44  * 17-Apr-1998 BS       - Made the win32 keywords optional when compiling in
45  *                        16bit mode
46  *
47  * 15-Apr-1998 BS       - Changed string handling to include escapes
48  *                      - Added unicode string handling (no codepage
49  *                        translation though).
50  *                      - 'Borrowed' the main idea of string scanning from
51  *                        the flex manual pages.
52  *                      - Added conditional handling of scanning depending
53  *                        on the state of the parser. This was mainly required
54  *                        to distinguish a file to load or raw data that
55  *                        follows. MS's definition of filenames is rather
56  *                        complex... It can be unquoted or double quoted. If
57  *                        double quoted, then the '\\' char is not automatically
58  *                        escaped according to Borland's rc compiler, but it
59  *                        accepts both "\\path\\file.rc" and "\path\file.rc".
60  *                        This makes life very hard! I go for the escaped
61  *                        version, as this seems to be the documented way...
62  *                      - Single quoted strings are now parsed and converted
63  *                        here.
64  *                      - Added comment stripping. The implementation is
65  *                        'borrowed' from the flex manpages.
66  *                      - Rebuild string processing so that it may contain
67  *                        escaped '\0'.
68  */
70 /* Exclusive string handling */
71 %x tkstr
72 /* Exclusive unicode string handling */
73 %x tklstr
74 /* Exclusive rcdata single quoted data handling */
75 %x tkrcd
76 /* Exclusive comment eating... */
77 %x comment
78 /* Set when stripping c-junk */
79 %x pp_stripe
80 %x pp_strips
81 %x pp_stripp
82 %x pp_stripp_final
83 /* Set when scanning #line style directives */
84 %x pp_line
85 /* Set when scanning #pragma */
86 %x pp_pragma
87 %x pp_code_page
89 %option stack
90 %option nounput noyy_top_state
91 %option 8bit never-interactive
92 %option prefix="parser_"
94 /* Some shortcut definitions */
95 ws      [ \f\t\r]
96 cident  [a-zA-Z_][0-9a-zA-Z_]*
100 /*#define LEX_DEBUG*/
102 #include <stdio.h>
103 #include <stdlib.h>
104 #include <string.h>
105 #include <ctype.h>
106 #include <assert.h>
108 #include "wine/unicode.h"
109 #include "wrc.h"
110 #include "utils.h"
111 #include "parser.h"
112 #include "newstruc.h"
114 #include "parser.tab.h"
116 /* Always update the current character position within a line */
117 #define YY_USER_ACTION  char_number+=yyleng; wanted_id = want_id; want_id = 0;
119 static void addcchar(char c);
120 static void addwchar(WCHAR s);
121 static string_t *get_buffered_cstring(void);
122 static string_t *get_buffered_wstring(void);
123 static string_t *make_string(char *s);
125 static char *cbuffer;           /* Buffers for string collection */
126 static int cbufidx;
127 static int cbufalloc = 0;
128 static WCHAR *wbuffer;
129 static int wbufidx;
130 static int wbufalloc = 0;
131 static int stripslevel = 0;     /* Count {} during pp_strips/pp_stripe mode */
132 static int stripplevel = 0;     /* Count () during pp_strips mode */
133 static int cjunk_tagline;       /* Where did we start stripping (helps error tracking) */
135 static int current_codepage = -1;  /* use language default */
138  * This one is a bit tricky.
139  * We set 'want_id' in the parser to get the first
140  * identifier we get across in the scanner, but we
141  * also want it to be reset at nearly any token we
142  * see. Exceptions are:
143  * - newlines
144  * - comments
145  * - whitespace
147  * The scanner will automatically reset 'want_id'
148  * after *each* scanner reduction and puts is value
149  * into the var below. In this way we can see the
150  * state after the YY_RULE_SETUP (i.e. the user action;
151  * see above) and don't have to worry too much when
152  * it needs to be reset.
153  */
154 static int wanted_id = 0;
155 static int save_wanted_id;      /* To save across comment reductions */
157 struct keyword {
158         const char      *keyword;
159         int             token;
160         int             isextension;
161         int             needcase;
162         int             alwayskw;
165 static struct keyword keywords[] = {
166         { "ACCELERATORS",       tACCELERATORS,          0, 0, 0},
167         { "ALT",                tALT,                   0, 0, 0},
168         { "ASCII",              tASCII,                 0, 0, 0},
169         { "AUTO3STATE",         tAUTO3STATE,            1, 0, 0},
170         { "AUTOCHECKBOX",       tAUTOCHECKBOX,          1, 0, 0},
171         { "AUTORADIOBUTTON",    tAUTORADIOBUTTON,       1, 0, 0},
172         { "BEGIN",              tBEGIN,                 0, 0, 0},
173         { "BITMAP",             tBITMAP,                0, 0, 0},
174         { "BLOCK",              tBLOCK,                 0, 0, 0},
175         { "BUTTON",             tBUTTON,                1, 0, 0},
176         { "CAPTION",            tCAPTION,               0, 0, 0},
177         { "CHARACTERISTICS",    tCHARACTERISTICS,       1, 0, 0},
178         { "CHECKBOX",           tCHECKBOX,              0, 0, 0},
179         { "CHECKED",            tCHECKED,               0, 0, 0},
180         { "CLASS",              tCLASS,                 0, 0, 0},
181         { "COMBOBOX",           tCOMBOBOX,              0, 0, 0},
182         { "CONTROL",            tCONTROL,               0, 0, 0},
183         { "CTEXT",              tCTEXT,                 0, 0, 0},
184         { "CURSOR",             tCURSOR,                0, 0, 0},
185         { "DEFPUSHBUTTON",      tDEFPUSHBUTTON,         0, 0, 0},
186         { "DIALOG",             tDIALOG,                0, 0, 0},
187         { "DIALOGEX",           tDIALOGEX,              1, 0, 0},
188         { "DISCARDABLE",        tDISCARDABLE,           0, 0, 0},
189         { "DLGINIT",            tDLGINIT,               0, 0, 0},
190         { "EDITTEXT",           tEDITTEXT,              0, 0, 0},
191         { "END",                tEND,                   0, 0, 0},
192         { "EXSTYLE",            tEXSTYLE,               0, 0, 0},
193         { "FILEFLAGS",          tFILEFLAGS,             0, 0, 0},
194         { "FILEFLAGSMASK",      tFILEFLAGSMASK,         0, 0, 0},
195         { "FILEOS",             tFILEOS,                0, 0, 0},
196         { "FILESUBTYPE",        tFILESUBTYPE,           0, 0, 0},
197         { "FILETYPE",           tFILETYPE,              0, 0, 0},
198         { "FILEVERSION",        tFILEVERSION,           0, 0, 0},
199         { "FIXED",              tFIXED,                 0, 0, 0},
200         { "FONT",               tFONT,                  0, 0, 0},
201         { "FONTDIR",            tFONTDIR,               0, 0, 0},       /* This is a Borland BRC extension */
202         { "GRAYED",             tGRAYED,                0, 0, 0},
203         { "GROUPBOX",           tGROUPBOX,              0, 0, 0},
204         { "HELP",               tHELP,                  0, 0, 0},
205         { "HTML",               tHTML,                  0, 0, 0},
206         { "ICON",               tICON,                  0, 0, 0},
207         { "IMPURE",             tIMPURE,                0, 0, 0},
208         { "INACTIVE",           tINACTIVE,              0, 0, 0},
209         { "LANGUAGE",           tLANGUAGE,              1, 0, 1},
210         { "LISTBOX",            tLISTBOX,               0, 0, 0},
211         { "LOADONCALL",         tLOADONCALL,            0, 0, 0},
212         { "LTEXT",              tLTEXT,                 0, 0, 0},
213         { "MENU",               tMENU,                  0, 0, 0},
214         { "MENUBARBREAK",       tMENUBARBREAK,          0, 0, 0},
215         { "MENUBREAK",          tMENUBREAK,             0, 0, 0},
216         { "MENUEX",             tMENUEX,                1, 0, 0},
217         { "MENUITEM",           tMENUITEM,              0, 0, 0},
218         { "MESSAGETABLE",       tMESSAGETABLE,          1, 0, 0},
219         { "MOVEABLE",           tMOVEABLE,              0, 0, 0},
220         { "NOINVERT",           tNOINVERT,              0, 0, 0},
221         { "NOT",                tNOT,                   0, 0, 0},
222         { "POPUP",              tPOPUP,                 0, 0, 0},
223         { "PRELOAD",            tPRELOAD,               0, 0, 0},
224         { "PRODUCTVERSION",     tPRODUCTVERSION,        0, 0, 0},
225         { "PURE",               tPURE,                  0, 0, 0},
226         { "PUSHBUTTON",         tPUSHBUTTON,            0, 0, 0},
227         { "RADIOBUTTON",        tRADIOBUTTON,           0, 0, 0},
228         { "RCDATA",             tRCDATA,                0, 0, 0},
229         { "RTEXT",              tRTEXT,                 0, 0, 0},
230         { "SCROLLBAR",          tSCROLLBAR,             0, 0, 0},
231         { "SEPARATOR",          tSEPARATOR,             0, 0, 0},
232         { "SHIFT",              tSHIFT,                 0, 0, 0},
233         { "STATE3",             tSTATE3,                1, 0, 0},
234         { "STRING",             tSTRING,                0, 0, 0},
235         { "STRINGTABLE",        tSTRINGTABLE,           0, 0, 1},
236         { "STYLE",              tSTYLE,                 0, 0, 0},
237         { "TOOLBAR",            tTOOLBAR,               1, 0, 0},
238         { "VALUE",              tVALUE,                 0, 0, 0},
239         { "VERSION",            tVERSION,               1, 0, 0},
240         { "VERSIONINFO",        tVERSIONINFO,           0, 0, 0},
241         { "VIRTKEY",            tVIRTKEY,               0, 0, 0}
244 #define NKEYWORDS       (sizeof(keywords)/sizeof(keywords[0]))
245 #define KWP(p)          ((const struct keyword *)(p))
246 static int kw_cmp_func(const void *s1, const void *s2)
248         int ret;
249         ret = strcasecmp(KWP(s1)->keyword, KWP(s2)->keyword);
250         if(!ret && (KWP(s1)->needcase || KWP(s2)->needcase))
251                 return strcmp(KWP(s1)->keyword, KWP(s2)->keyword);
252         else
253                 return ret;
256 #define KW_BSEARCH
257 #define DO_SORT
258 static struct keyword *iskeyword(char *kw)
260         struct keyword *kwp;
261         struct keyword key;
262         key.keyword = kw;
263         key.needcase = 0;
264 #ifdef DO_SORT
265         {
266                 /* Make sure that it is sorted for bsearsh */
267                 static int sorted = 0;
268                 if(!sorted)
269                 {
270                         qsort(keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
271                         sorted = 1;
272                 }
273         }
274 #endif
275 #ifdef KW_BSEARCH
276         kwp = bsearch(&key, keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
277 #else
278         {
279                 int i;
280                 for(i = 0; i < NKEYWORDS; i++)
281                 {
282                         if(!kw_cmp_func(&key, &keywords[i]))
283                                 break;
284                 }
285                 if(i < NKEYWORDS)
286                         kwp = &keywords[i];
287                 else
288                         kwp = NULL;
289         }
290 #endif
292         if(kwp == NULL || (kwp->isextension && !extensions))
293                 return NULL;
294         else
295                 return kwp;
301  **************************************************************************
302  * The flexer starts here
303  **************************************************************************
304  */
306         /*
307          * Catch the GCC-style line statements here and parse them.
308          * This has the advantage that you can #include at any
309          * stage in the resource file.
310          * The preprocessor generates line directives in the format:
311          * # <linenum> "filename" <codes>
312          *
313          * Codes can be a sequence of:
314          * - 1 start of new file
315          * - 2 returning to previous
316          * - 3 system header
317          * - 4 interpret as C-code
318          *
319          * 4 is not used and 1 mutually excludes 2
320          * Anyhow, we are not really interested in these at all
321          * because we only want to know the linenumber and
322          * filename.
323          */
324 <INITIAL,pp_strips,pp_stripp>^{ws}*\#{ws}*pragma{ws}+   yy_push_state(pp_pragma);
325 <INITIAL,pp_strips,pp_stripp>^{ws}*\#{ws}*      yy_push_state(pp_line);
326 <pp_line>[^\n]* {
327                 int lineno;
328                 char *cptr;
329                 char *fname;
330                 yy_pop_state();
331                 lineno = (int)strtol(yytext, &cptr, 10);
332                 if(!lineno)
333                         parser_error("Malformed '#...' line-directive; invalid linenumber");
334                 fname = strchr(cptr, '"');
335                 if(!fname)
336                         parser_error("Malformed '#...' line-directive; missing filename");
337                 fname++;
338                 cptr = strchr(fname, '"');
339                 if(!cptr)
340                         parser_error("Malformed '#...' line-directive; missing terminating \"");
341                 *cptr = '\0';
342                 line_number = lineno - 1;       /* We didn't read the newline */
343                 input_name = xstrdup(fname);
344         }
346 <pp_pragma>code_page[^\n]*      yyless(9); yy_pop_state(); yy_push_state(pp_code_page);
347 <pp_pragma>[^\n]*               yy_pop_state(); if (pedantic) parser_warning("Unrecognized #pragma directive '%s'",yytext);
349 <pp_code_page>\({ws}*default{ws}*\)[^\n]*       current_codepage = -1; yy_pop_state();
350 <pp_code_page>\({ws}*[0-9]+{ws}*\)[^\n]* {
351         char *p = yytext;
352         yy_pop_state();
353         while (*p < '0' || *p > '9') p++;
354         current_codepage = strtol( p, NULL, 10 );
355         if (current_codepage && !wine_cp_get_table( current_codepage ))
356         {
357             parser_error("Codepage %d not supported", current_codepage);
358             current_codepage = 0;
359         }
360     }
361 <pp_code_page>[^\n]*    yy_pop_state(); parser_error("Malformed #pragma code_page directive");
363         /*
364          * Strip everything until a ';' taking
365          * into account braces {} for structures,
366          * classes and enums.
367          */
368 <pp_strips>\{                   stripslevel++;
369 <pp_strips>\}                   stripslevel--;
370 <pp_strips>;                    if(!stripslevel) yy_pop_state();
371 <pp_strips>\/[^*\n]             ; /* To catch comments */
372 <pp_strips>[^\{\};\n#/]*        ; /* Ignore rest */
373 <pp_strips>\n                   line_number++; char_number = 1;
375 <pp_stripp>\(                   stripplevel++;
376 <pp_stripp>\)                   {
377                                         stripplevel--;
378                                         if(!stripplevel)
379                                         {
380                                                 yy_pop_state();
381                                                 yy_push_state(pp_stripp_final);
382                                         }
383                                 }
384 <pp_stripp>\/[^*\n]             ; /* To catch comments */
385 <pp_stripp>[^\(\);\n#/]*        ; /* Ignore rest */
386 <pp_stripp>\n                   line_number++; char_number = 1;
388 <pp_stripp_final>{ws}*          ; /* Ignore */
389 <pp_stripp_final>;              yy_pop_state(); /* Kill the semicolon */
390 <pp_stripp_final>\n             line_number++; char_number = 1; yy_pop_state();
391 <pp_stripp_final>.              yyless(0); yy_pop_state();
393 \{                      return tBEGIN;
394 \}                      return tEND;
396 [0-9]+[lL]?             { parser_lval.num = strtoul(yytext,  0, 10); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
397 0[xX][0-9A-Fa-f]+[lL]?  { parser_lval.num = strtoul(yytext,  0, 16); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
398 0[oO][0-7]+[lL]?        { parser_lval.num = strtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? tLNUMBER : tNUMBER; }
400         /*
401          * The next two rules scan identifiers and filenames.
402          * This is achieved by using the priority ruling
403          * of the scanner where a '.' is valid in a filename
404          * and *only* in a filename. In this case, the second
405          * rule will be reduced because it is longer.
406          */
407 [A-Za-z_0-9.]+          {
408                                 struct keyword *tok = iskeyword(yytext);
410                                 if(tok)
411                                 {
412                                         if(wanted_id && !tok->alwayskw)
413                                         {
414                                                 parser_lval.str = make_string(yytext);
415                                                 return tIDENT;
416                                         }
417                                         else
418                                                 return tok->token;
419                                 }
420                                 else
421                                 {
422                                         parser_lval.str = make_string(yytext);
423                                         return tIDENT;
424                                 }
425                         }
426 [A-Za-z_0-9./\\]+               parser_lval.str = make_string(yytext); return tFILENAME;
428         /*
429          * Wide string scanning
430          */
431 L\"                     {
432                                 yy_push_state(tklstr);
433                                 wbufidx = 0;
434                                 if(!win32)
435                                         parser_warning("16bit resource contains unicode strings\n");
436                         }
437 <tklstr>\"{ws}+ |
438 <tklstr>\"              {
439                                 yy_pop_state();
440                                 parser_lval.str = get_buffered_wstring();
441                                 return tSTRING;
442                         }
443 <tklstr>\\[0-7]{1,6}    { /* octal escape sequence */
444                                 unsigned int result;
445                                 result = strtoul(yytext+1, 0, 8);
446                                 if ( result > 0xffff )
447                                         parser_error("Character constant out of range");
448                                 addwchar((WCHAR)result);
449                         }
450 <tklstr>\\x[0-9a-fA-F]{4} {  /* hex escape sequence */
451                                 unsigned int result;
452                                 result = strtoul(yytext+2, 0, 16);
453                                 addwchar((WCHAR)result);
454                         }
455 <tklstr>\\x[0-9a-fA-F]{1,3} {  parser_error("Invalid hex escape sequence '%s'", yytext); }
457 <tklstr>\\[0-9]+        parser_error("Bad escape sequence");
458 <tklstr>\\\n{ws}*       line_number++; char_number = 1; /* backslash at EOL continues string after leading whitespace on next line */
459 <tklstr>\\a             addwchar('\a');
460 <tklstr>\\b             addwchar('\b');
461 <tklstr>\\f             addwchar('\f');
462 <tklstr>\\n             addwchar('\n');
463 <tklstr>\\r             addwchar('\r');
464 <tklstr>\\t             addwchar('\t');
465 <tklstr>\\v             addwchar('\v');
466 <tklstr>\\.             addwchar(yytext[1]);
467 <tklstr>\\\r\n          addwchar(yytext[2]); line_number++; char_number = 1;
468 <tklstr>\"\"            addwchar('\"');         /* "bla""bla"  -> "bla\"bla" */
469 <tklstr>\\\"\"          addwchar('\"');         /* "bla\""bla" -> "bla\"bla" */
470 <tklstr>\"{ws}+\"       ;                       /* "bla" "bla" -> "blabla" */
471 <tklstr>[^\\\n\"]+      {
472                                 char *yptr = yytext;
473                                 while(*yptr)    /* FIXME: codepage translation */
474                                         addwchar(*yptr++ & 0xff);
475                         }
476 <tklstr>\n              parser_error("Unterminated string");
478         /*
479          * Normal string scanning
480          */
481 \"                      yy_push_state(tkstr); cbufidx = 0;
482 <tkstr>\"{ws}+  |
483 <tkstr>\"               {
484                                 yy_pop_state();
485                                 parser_lval.str = get_buffered_cstring();
486                                 return tSTRING;
487                         }
488 <tkstr>\\[0-7]{1,3}     { /* octal escape sequence */
489                                 int result;
490                                 result = strtol(yytext+1, 0, 8);
491                                 if ( result > 0xff )
492                                         parser_error("Character constant out of range");
493                                 addcchar((char)result);
494                         }
495 <tkstr>\\x[0-9a-fA-F]{2} {  /* hex escape sequence */
496                                 int result;
497                                 result = strtol(yytext+2, 0, 16);
498                                 addcchar((char)result);
499                         }
500 <tkstr>\\x[0-9a-fA-F]   {  parser_error("Invalid hex escape sequence '%s'", yytext); }
502 <tkstr>\\[0-9]+         parser_error("Bad escape sequence");
503 <tkstr>\\\n{ws}*        line_number++; char_number = 1; /* backslash at EOL continues string after leading whitespace on next line */
504 <tkstr>\\a              addcchar('\a');
505 <tkstr>\\b              addcchar('\b');
506 <tkstr>\\f              addcchar('\f');
507 <tkstr>\\n              addcchar('\n');
508 <tkstr>\\r              addcchar('\r');
509 <tkstr>\\t              addcchar('\t');
510 <tkstr>\\v              addcchar('\v');
511 <tkstr>\\.              addcchar(yytext[1]);
512 <tkstr>\\\r\n           addcchar(yytext[2]); line_number++; char_number = 1;
513 <tkstr>[^\\\n\"]+       {
514                                 char *yptr = yytext;
515                                 while(*yptr)
516                                         addcchar(*yptr++);
517                         }
518 <tkstr>\"\"             addcchar('\"');         /* "bla""bla"   -> "bla\"bla" */
519 <tkstr>\\\"\"           addcchar('\"');         /* "bla\""bla"  -> "bla\"bla" */
520 <tkstr>\"{ws}+\"        ;                       /* "bla" "bla"  -> "blabla" */
521 <tkstr>\n               parser_error("Unterminated string");
523         /*
524          * Raw data scanning
525          */
526 \'                      yy_push_state(tkrcd); cbufidx = 0;
527 <tkrcd>\'               {
528                                 yy_pop_state();
529                                 parser_lval.raw = new_raw_data();
530                                 parser_lval.raw->size = cbufidx;
531                                 parser_lval.raw->data = xmalloc(parser_lval.raw->size);
532                                 memcpy(parser_lval.raw->data, cbuffer, parser_lval.raw->size);
533                                 return tRAWDATA;
534                         }
535 <tkrcd>[0-9a-fA-F]{2}   {
536                                 int result;
537                                 result = strtol(yytext, 0, 16);
538                                 addcchar((char)result);
539                         }
540 <tkrcd>{ws}+            ;       /* Ignore space */
541 <tkrcd>\n               line_number++; char_number = 1;
542 <tkrcd>.                parser_error("Malformed data-line");
544         /*
545          * Comment stripping
546          * Should never occur after preprocessing
547          */
548 <INITIAL,pp_stripp,pp_strips>"/*"       {
549                                 yy_push_state(comment);
550                                 save_wanted_id = wanted_id;
551                                 if(!no_preprocess)
552                                         parser_warning("Found comments after preprocessing, please report");
553                         }
554 <comment>[^*\n]*        ;
555 <comment>"*"+[^*/\n]*   ;
556 <comment>\n             line_number++; char_number = 1;
557 <comment>"*"+"/"        yy_pop_state(); want_id = save_wanted_id;
559 ;[^\n]*                 want_id = wanted_id; /* not really comment, but left-over c-junk */
560 "//"[^\n]*              want_id = wanted_id; if(!no_preprocess) parser_warning("Found comments after preprocessing, please report");
562 \n                      {
563                                 want_id = wanted_id;
564                                 line_number++;
565                                 char_number = 1;
566                                 if(want_nl)
567                                 {
568                                         want_nl = 0;
569                                         return tNL;
570                                 }
571                         }
572 {ws}+                   want_id = wanted_id;    /* Eat whitespace */
574 <INITIAL>.              return yytext[0];
576 <<EOF>>                 {
577                                 if(YY_START == pp_strips || YY_START == pp_stripe || YY_START == pp_stripp || YY_START == pp_stripp_final)
578                                         parser_error("Unexpected end of file during c-junk scanning (started at %d)", cjunk_tagline);
579                                 else
580                                         yyterminate();
581                         }
583 <*>.|\n                 {
584                                 /* Catch all rule to find any unmatched text */
585                                 if(*yytext == '\n')
586                                 {
587                                         line_number++;
588                                         char_number = 1;
589                                 }
590                                 parser_warning("Unmatched text '%c' (0x%02x) YY_START=%d stripslevel=%d",
591                                         isprint(*yytext & 0xff) ? *yytext : '.', *yytext, YY_START,stripslevel);
592                         }
596 #ifndef parser_wrap
597 int parser_wrap(void)
599 #if 0
600         if(bufferstackidx > 0)
601         {
602                 return 0;
603         }
604 #endif
605         return 1;
607 #endif
609 /* These dup functions copy the enclosed '\0' from
610  * the resource string.
611  */
612 static void addcchar(char c)
614         if(cbufidx >= cbufalloc)
615         {
616                 cbufalloc += 1024;
617                 cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
618                 if(cbufalloc > 65536)
619                         parser_warning("Reallocating string buffer larger than 64kB");
620         }
621         cbuffer[cbufidx++] = c;
624 static void addwchar(WCHAR s)
626         if(wbufidx >= wbufalloc)
627         {
628                 wbufalloc += 1024;
629                 wbuffer = xrealloc(wbuffer, wbufalloc * sizeof(wbuffer[0]));
630                 if(wbufalloc > 65536)
631                         parser_warning("Reallocating wide string buffer larger than 64kB");
632         }
633         wbuffer[wbufidx++] = s;
636 static string_t *get_buffered_cstring(void)
638     string_t *str = new_string();
640     str->size = cbufidx;
641     str->type = str_char;
642     str->str.cstr = xmalloc(cbufidx+1);
643     memcpy(str->str.cstr, cbuffer, cbufidx);
644     str->str.cstr[cbufidx] = '\0';
646     if (!current_codepage || current_codepage == -1 || !win32)  /* store as ANSI string */
647     {
648         if (!current_codepage) parser_error("Codepage set to Unicode only, cannot use ASCII string here");
649         return str;
650     }
651     else  /* convert to Unicode before storing */
652     {
653         string_t *str_w = convert_string( str, str_unicode, current_codepage );
654         if (!check_unicode_conversion( str, str_w, current_codepage ))
655             parser_error("String %s does not convert identically to Unicode and back in codepage %d. "
656                     "Try using a Unicode string instead.", str->str.cstr, current_codepage );
657         free_string( str );
658         return str_w;
659     }
662 static string_t *get_buffered_wstring(void)
664         string_t *str = new_string();
665         str->size = wbufidx;
666         str->type = str_unicode;
667         str->str.wstr = xmalloc((wbufidx+1)*sizeof(WCHAR));
668         memcpy(str->str.wstr, wbuffer, wbufidx*sizeof(WCHAR));
669         str->str.wstr[wbufidx] = 0;
670         return str;
673 static string_t *make_string(char *s)
675         string_t *str = new_string();
676         str->size = strlen(s);
677         str->type = str_char;
678         str->str.cstr = xmalloc(str->size+1);
679         memcpy(str->str.cstr, s, str->size+1);
680         return str;