combase: Add stub dll.
[wine.git] / tools / wrc / parser.l
blob16a487f5dd50ac6c3e3863375d5980032b540879
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 properly.
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_cstrip
80 /* Set when scanning #line style directives */
81 %x pp_line
82 /* Set when scanning #pragma */
83 %x pp_pragma
84 %x pp_code_page
86 %option stack
87 %option noinput nounput noyy_top_state noyywrap
88 %option 8bit never-interactive
89 %option prefix="parser_"
91 /* Some shortcut definitions */
92 ws      [ \f\t\r]
93 cident  [a-zA-Z_][0-9a-zA-Z_]*
97 /*#define LEX_DEBUG*/
99 #include "config.h"
101 #include <stdio.h>
102 #include <stdlib.h>
103 #include <string.h>
104 #include <ctype.h>
105 #include <assert.h>
106 #include <errno.h>
107 #include <limits.h>
109 #ifdef HAVE_UNISTD_H
110 #include <unistd.h>
111 #else
112 #define YY_NO_UNISTD_H
113 #endif
115 #include "wrc.h"
116 #include "utils.h"
117 #include "parser.h"
118 #include "newstruc.h"
120 #include "parser.tab.h"
122 /* Always update the current character position within a line */
123 #define YY_USER_ACTION  char_number+=yyleng; wanted_id = want_id; want_id = 0;
125 #define YY_USER_INIT current_codepage = -1;
127 static void addcchar(char c);
128 static void addwchar(WCHAR s);
129 static string_t *get_buffered_cstring(void);
130 static string_t *get_buffered_wstring(void);
131 static string_t *make_string(char *s);
133 static char *cbuffer;           /* Buffers for string collection */
134 static int cbufidx;
135 static int cbufalloc = 0;
136 static WCHAR *wbuffer;
137 static int wbufidx;
138 static int wbufalloc = 0;
140 static int current_codepage = -1;  /* use language default */
143  * This one is a bit tricky.
144  * We set 'want_id' in the parser to get the first
145  * identifier we get across in the scanner, but we
146  * also want it to be reset at nearly any token we
147  * see. Exceptions are:
148  * - newlines
149  * - comments
150  * - whitespace
152  * The scanner will automatically reset 'want_id'
153  * after *each* scanner reduction and puts is value
154  * into the var below. In this way we can see the
155  * state after the YY_RULE_SETUP (i.e. the user action;
156  * see above) and don't have to worry too much when
157  * it needs to be reset.
158  */
159 static int wanted_id = 0;
160 static int save_wanted_id;      /* To save across comment reductions */
162 struct keyword {
163         const char      *keyword;
164         int             token;
165         int             isextension;
166         int             needcase;
167         int             alwayskw;
170 static struct keyword keywords[] = {
171         { "ACCELERATORS",       tACCELERATORS,          0, 0, 0},
172         { "ALT",                tALT,                   0, 0, 0},
173         { "ASCII",              tASCII,                 0, 0, 0},
174         { "AUTO3STATE",         tAUTO3STATE,            1, 0, 0},
175         { "AUTOCHECKBOX",       tAUTOCHECKBOX,          1, 0, 0},
176         { "AUTORADIOBUTTON",    tAUTORADIOBUTTON,       1, 0, 0},
177         { "BEGIN",              tBEGIN,                 0, 0, 0},
178         { "BITMAP",             tBITMAP,                0, 0, 0},
179         { "BLOCK",              tBLOCK,                 0, 0, 0},
180         { "BUTTON",             tBUTTON,                1, 0, 0},
181         { "CAPTION",            tCAPTION,               0, 0, 0},
182         { "CHARACTERISTICS",    tCHARACTERISTICS,       1, 0, 0},
183         { "CHECKBOX",           tCHECKBOX,              0, 0, 0},
184         { "CHECKED",            tCHECKED,               0, 0, 0},
185         { "CLASS",              tCLASS,                 0, 0, 0},
186         { "COMBOBOX",           tCOMBOBOX,              0, 0, 0},
187         { "CONTROL",            tCONTROL,               0, 0, 0},
188         { "CTEXT",              tCTEXT,                 0, 0, 0},
189         { "CURSOR",             tCURSOR,                0, 0, 0},
190         { "DEFPUSHBUTTON",      tDEFPUSHBUTTON,         0, 0, 0},
191         { "DIALOG",             tDIALOG,                0, 0, 0},
192         { "DIALOGEX",           tDIALOGEX,              1, 0, 0},
193         { "DISCARDABLE",        tDISCARDABLE,           0, 0, 0},
194         { "DLGINIT",            tDLGINIT,               0, 0, 0},
195         { "EDITTEXT",           tEDITTEXT,              0, 0, 0},
196         { "END",                tEND,                   0, 0, 0},
197         { "EXSTYLE",            tEXSTYLE,               0, 0, 0},
198         { "FILEFLAGS",          tFILEFLAGS,             0, 0, 0},
199         { "FILEFLAGSMASK",      tFILEFLAGSMASK,         0, 0, 0},
200         { "FILEOS",             tFILEOS,                0, 0, 0},
201         { "FILESUBTYPE",        tFILESUBTYPE,           0, 0, 0},
202         { "FILETYPE",           tFILETYPE,              0, 0, 0},
203         { "FILEVERSION",        tFILEVERSION,           0, 0, 0},
204         { "FIXED",              tFIXED,                 0, 0, 0},
205         { "FONT",               tFONT,                  0, 0, 0},
206         { "FONTDIR",            tFONTDIR,               0, 0, 0},       /* This is a Borland BRC extension */
207         { "GRAYED",             tGRAYED,                0, 0, 0},
208         { "GROUPBOX",           tGROUPBOX,              0, 0, 0},
209         { "HELP",               tHELP,                  0, 0, 0},
210         { "HTML",               tHTML,                  0, 0, 0},
211         { "ICON",               tICON,                  0, 0, 0},
212         { "IMPURE",             tIMPURE,                0, 0, 0},
213         { "INACTIVE",           tINACTIVE,              0, 0, 0},
214         { "LANGUAGE",           tLANGUAGE,              1, 0, 1},
215         { "LISTBOX",            tLISTBOX,               0, 0, 0},
216         { "LOADONCALL",         tLOADONCALL,            0, 0, 0},
217         { "LTEXT",              tLTEXT,                 0, 0, 0},
218         { "MENU",               tMENU,                  0, 0, 0},
219         { "MENUBARBREAK",       tMENUBARBREAK,          0, 0, 0},
220         { "MENUBREAK",          tMENUBREAK,             0, 0, 0},
221         { "MENUEX",             tMENUEX,                1, 0, 0},
222         { "MENUITEM",           tMENUITEM,              0, 0, 0},
223         { "MESSAGETABLE",       tMESSAGETABLE,          1, 0, 0},
224         { "MOVEABLE",           tMOVEABLE,              0, 0, 0},
225         { "NOINVERT",           tNOINVERT,              0, 0, 0},
226         { "NOT",                tNOT,                   0, 0, 0},
227         { "POPUP",              tPOPUP,                 0, 0, 0},
228         { "PRELOAD",            tPRELOAD,               0, 0, 0},
229         { "PRODUCTVERSION",     tPRODUCTVERSION,        0, 0, 0},
230         { "PURE",               tPURE,                  0, 0, 0},
231         { "PUSHBUTTON",         tPUSHBUTTON,            0, 0, 0},
232         { "RADIOBUTTON",        tRADIOBUTTON,           0, 0, 0},
233         { "RCDATA",             tRCDATA,                0, 0, 0},
234         { "RTEXT",              tRTEXT,                 0, 0, 0},
235         { "SCROLLBAR",          tSCROLLBAR,             0, 0, 0},
236         { "SEPARATOR",          tSEPARATOR,             0, 0, 0},
237         { "SHIFT",              tSHIFT,                 0, 0, 0},
238         { "STATE3",             tSTATE3,                1, 0, 0},
239         { "STRING",             tSTRING,                0, 0, 0},
240         { "STRINGTABLE",        tSTRINGTABLE,           0, 0, 1},
241         { "STYLE",              tSTYLE,                 0, 0, 0},
242         { "TOOLBAR",            tTOOLBAR,               1, 0, 0},
243         { "VALUE",              tVALUE,                 0, 0, 0},
244         { "VERSION",            tVERSION,               1, 0, 0},
245         { "VERSIONINFO",        tVERSIONINFO,           0, 0, 0},
246         { "VIRTKEY",            tVIRTKEY,               0, 0, 0}
249 #define NKEYWORDS       (sizeof(keywords)/sizeof(keywords[0]))
250 #define KWP(p)          ((const struct keyword *)(p))
251 static int kw_cmp_func(const void *s1, const void *s2)
253         int ret;
254         ret = strcasecmp(KWP(s1)->keyword, KWP(s2)->keyword);
255         if(!ret && (KWP(s1)->needcase || KWP(s2)->needcase))
256                 return strcmp(KWP(s1)->keyword, KWP(s2)->keyword);
257         else
258                 return ret;
261 #define KW_BSEARCH
262 #define DO_SORT
263 static struct keyword *iskeyword(char *kw)
265         struct keyword *kwp;
266         struct keyword key;
267         key.keyword = kw;
268         key.needcase = 0;
269 #ifdef DO_SORT
270         {
271                 /* Make sure that it is sorted for bsearsh */
272                 static int sorted = 0;
273                 if(!sorted)
274                 {
275                         qsort(keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
276                         sorted = 1;
277                 }
278         }
279 #endif
280 #ifdef KW_BSEARCH
281         kwp = bsearch(&key, keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
282 #else
283         {
284                 int i;
285                 for(i = 0; i < NKEYWORDS; i++)
286                 {
287                         if(!kw_cmp_func(&key, &keywords[i]))
288                                 break;
289                 }
290                 if(i < NKEYWORDS)
291                         kwp = &keywords[i];
292                 else
293                         kwp = NULL;
294         }
295 #endif
297         if(kwp == NULL || (kwp->isextension && !extensions))
298                 return NULL;
299         else
300                 return kwp;
303 /* converts an integer in string form to an unsigned long and prints an error
304  * on overflow */
305 static unsigned long xstrtoul(const char *nptr, char **endptr, int base)
307     unsigned long l;
309     errno = 0;
310     l = strtoul(nptr, endptr, base);
311     if (l == ULONG_MAX && errno == ERANGE)
312         parser_error("integer constant %s is too large", nptr);
313     return l;
319  **************************************************************************
320  * The flexer starts here
321  **************************************************************************
322  */
324         /*
325          * Catch the GCC-style line statements here and parse them.
326          * This has the advantage that you can #include at any
327          * stage in the resource file.
328          * The preprocessor generates line directives in the format:
329          * # <linenum> "filename" <codes>
330          *
331          * Codes can be a sequence of:
332          * - 1 start of new file
333          * - 2 returning to previous
334          * - 3 system header
335          * - 4 interpret as C-code
336          *
337          * 4 is not used and 1 mutually excludes 2
338          * Anyhow, we are not really interested in these at all
339          * because we only want to know the linenumber and
340          * filename.
341          */
342 <INITIAL,pp_cstrip>^{ws}*\#{ws}*pragma{ws}+     yy_push_state(pp_pragma);
343 <INITIAL,pp_cstrip>^{ws}*\#{ws}*        yy_push_state(pp_line);
344 <pp_line>[^\n]* {
345                 int lineno, len;
346                 char *cptr;
347                 char *fname;
348                 yy_pop_state();
349                 lineno = (int)strtol(yytext, &cptr, 10);
350                 if(!lineno)
351                         parser_error("Malformed '#...' line-directive; invalid linenumber");
352                 fname = strchr(cptr, '"');
353                 if(!fname)
354                         parser_error("Malformed '#...' line-directive; missing filename");
355                 fname++;
356                 cptr = strchr(fname, '"');
357                 if(!cptr)
358                         parser_error("Malformed '#...' line-directive; missing terminating \"");
359                 *cptr = '\0';
360                 line_number = lineno - 1;       /* We didn't read the newline */
361                 input_name = xstrdup(fname);
362                 /* ignore contents of C include files */
363                 len = strlen(input_name);
364                 if (len > 1 && !strcasecmp( input_name + len - 2, ".h" ))
365                     BEGIN(pp_cstrip);
366                 else
367                     BEGIN(INITIAL);
368         }
370 <pp_pragma>code_page[^\n]*      yyless(9); yy_pop_state(); yy_push_state(pp_code_page);
371 <pp_pragma>[^\n]*               yy_pop_state(); if (pedantic) parser_warning("Unrecognized #pragma directive '%s'\n",yytext);
373 <pp_code_page>\({ws}*default{ws}*\)[^\n]*       current_codepage = -1; yy_pop_state();
374 <pp_code_page>\({ws}*utf8{ws}*\)[^\n]*          current_codepage = CP_UTF8; yy_pop_state();
375 <pp_code_page>\({ws}*[0-9]+{ws}*\)[^\n]* {
376         char *p = yytext;
377         yy_pop_state();
378         while (*p < '0' || *p > '9') p++;
379         current_codepage = strtol( p, NULL, 10 );
380         if (current_codepage != CP_UTF8 && !wine_cp_get_table( current_codepage ))
381         {
382             parser_error("Codepage %d not supported", current_codepage);
383             current_codepage = 0;
384         }
385     }
386 <pp_code_page>[^\n]*    yy_pop_state(); parser_error("Malformed #pragma code_page directive");
388         /*
389          * Strip everything until a ';' taking
390          * into account braces {} for structures,
391          * classes and enums.
392          */
393 <pp_cstrip>\n                   line_number++; char_number = 1;
394 <pp_cstrip>.                    ; /* ignore */
396 \{                      return tBEGIN;
397 \}                      return tEND;
399 [0-9]+[lL]?             { parser_lval.num = xstrtoul(yytext,  0, 10);
400                           return (yytext[yyleng-1] == 'L' || yytext[yyleng-1] == 'l') ? tLNUMBER : tNUMBER; }
401 0[xX][0-9A-Fa-f]+[lL]?  { parser_lval.num = xstrtoul(yytext,  0, 16);
402                           return (yytext[yyleng-1] == 'L' || yytext[yyleng-1] == 'l') ? tLNUMBER : tNUMBER; }
403 0[oO][0-7]+[lL]?        { parser_lval.num = xstrtoul(yytext+2, 0, 8);
404                           return (yytext[yyleng-1] == 'L' || yytext[yyleng-1] == 'l') ? tLNUMBER : tNUMBER; }
406 [A-Za-z_0-9./\\]+       {
407                                 struct keyword *tok = iskeyword(yytext);
409                                 if(tok)
410                                 {
411                                         if(wanted_id && !tok->alwayskw)
412                                         {
413                                                 parser_lval.str = make_string(yytext);
414                                                 return tIDENT;
415                                         }
416                                         else
417                                                 return tok->token;
418                                 }
419                                 else
420                                 {
421                                         parser_lval.str = make_string(yytext);
422                                         return tIDENT;
423                                 }
424                         }
426         /*
427          * Wide string scanning
428          */
429 L\"                     {
430                                 yy_push_state(tklstr);
431                                 wbufidx = 0;
432                                 if(!win32)
433                                         parser_warning("16bit resource contains unicode strings\n");
434                         }
435 <tklstr>\"{ws}+ |
436 <tklstr>\"              {
437                                 yy_pop_state();
438                                 parser_lval.str = get_buffered_wstring();
439                                 return tSTRING;
440                         }
441 <tklstr>\\[0-7]{1,6}    { /* octal escape sequence */
442                                 unsigned int result;
443                                 result = strtoul(yytext+1, 0, 8);
444                                 if ( result > 0xffff )
445                                         parser_error("Character constant out of range");
446                                 addwchar((WCHAR)result);
447                         }
448 <tklstr>\\x[0-9a-fA-F]{4} {  /* hex escape sequence */
449                                 unsigned int result;
450                                 result = strtoul(yytext+2, 0, 16);
451                                 addwchar((WCHAR)result);
452                         }
453 <tklstr>\\x[0-9a-fA-F]{1,3} {  parser_error("Invalid hex escape sequence '%s'", yytext); }
455 <tklstr>\\[0-9]+        parser_error("Bad escape sequence");
456 <tklstr>\\\n{ws}*       line_number++; char_number = 1; /* backslash at EOL continues string after leading whitespace on next line */
457 <tklstr>\\a             addwchar('\a');
458 <tklstr>\\b             addwchar('\b');
459 <tklstr>\\f             addwchar('\f');
460 <tklstr>\\n             addwchar('\n');
461 <tklstr>\\r             addwchar('\r');
462 <tklstr>\\t             addwchar('\t');
463 <tklstr>\\v             addwchar('\v');
464 <tklstr>\\.             {
465                             if (yytext[1] & 0x80)
466                                 parser_error("Invalid char %u in wide string", (unsigned char)yytext[1]);
467                             addwchar(yytext[1]);
468                         }
469 <tklstr>\\\r\n          addwchar(yytext[2]); line_number++; char_number = 1;
470 <tklstr>\"\"            addwchar('\"');         /* "bla""bla"  -> "bla\"bla" */
471 <tklstr>\\\"\"          addwchar('\"');         /* "bla\""bla" -> "bla\"bla" */
472 <tklstr>\"{ws}+\"       ;                       /* "bla" "bla" -> "blabla" */
473 <tklstr>[^\\\n\"]+      {
474                                 char *yptr = yytext;
475                                 while(*yptr)    /* FIXME: codepage translation */
476                                 {
477                                     if (*yptr & 0x80)
478                                         parser_error("Invalid char %u in wide string", (unsigned char)*yptr);
479                                     addwchar(*yptr++ & 0xff);
480                                 }
481                         }
482 <tklstr>\n              parser_error("Unterminated string");
484         /*
485          * Normal string scanning
486          */
487 \"                      yy_push_state(tkstr); cbufidx = 0;
488 <tkstr>\"{ws}+  |
489 <tkstr>\"               {
490                                 yy_pop_state();
491                                 parser_lval.str = get_buffered_cstring();
492                                 return tSTRING;
493                         }
494 <tkstr>\\[0-7]{1,3}     { /* octal escape sequence */
495                                 int result;
496                                 result = strtol(yytext+1, 0, 8);
497                                 if ( result > 0xff )
498                                         parser_error("Character constant out of range");
499                                 addcchar((char)result);
500                         }
501 <tkstr>\\x[0-9a-fA-F]{2} {  /* hex escape sequence */
502                                 int result;
503                                 result = strtol(yytext+2, 0, 16);
504                                 addcchar((char)result);
505                         }
506 <tkstr>\\x[0-9a-fA-F]   {  parser_error("Invalid hex escape sequence '%s'", yytext); }
508 <tkstr>\\[0-9]+         parser_error("Bad escape sequence");
509 <tkstr>\\\n{ws}*        line_number++; char_number = 1; /* backslash at EOL continues string after leading whitespace on next line */
510 <tkstr>\\a              addcchar('\a');
511 <tkstr>\\b              addcchar('\b');
512 <tkstr>\\f              addcchar('\f');
513 <tkstr>\\n              addcchar('\n');
514 <tkstr>\\r              addcchar('\r');
515 <tkstr>\\t              addcchar('\t');
516 <tkstr>\\v              addcchar('\v');
517 <tkstr>\\.              addcchar(yytext[1]);
518 <tkstr>\\\r\n           addcchar(yytext[2]); line_number++; char_number = 1;
519 <tkstr>[^\\\n\"]+       {
520                                 char *yptr = yytext;
521                                 while(*yptr)
522                                         addcchar(*yptr++);
523                         }
524 <tkstr>\"\"             addcchar('\"');         /* "bla""bla"   -> "bla\"bla" */
525 <tkstr>\\\"\"           addcchar('\"');         /* "bla\""bla"  -> "bla\"bla" */
526 <tkstr>\"{ws}+\"        ;                       /* "bla" "bla"  -> "blabla" */
527 <tkstr>\n               parser_error("Unterminated string");
529         /*
530          * Raw data scanning
531          */
532 \'                      yy_push_state(tkrcd); cbufidx = 0;
533 <tkrcd>\'               {
534                                 yy_pop_state();
535                                 parser_lval.raw = new_raw_data();
536                                 parser_lval.raw->size = cbufidx;
537                                 parser_lval.raw->data = xmalloc(parser_lval.raw->size);
538                                 memcpy(parser_lval.raw->data, cbuffer, parser_lval.raw->size);
539                                 return tRAWDATA;
540                         }
541 <tkrcd>[0-9a-fA-F]{2}   {
542                                 int result;
543                                 result = strtol(yytext, 0, 16);
544                                 addcchar((char)result);
545                         }
546 <tkrcd>{ws}+            ;       /* Ignore space */
547 <tkrcd>\n               line_number++; char_number = 1;
548 <tkrcd>.                parser_error("Malformed data-line");
550         /*
551          * Comment stripping
552          * Should never occur after preprocessing
553          */
554 <INITIAL,pp_cstrip>"/*" {
555                                 yy_push_state(comment);
556                                 save_wanted_id = wanted_id;
557                                 if(!no_preprocess)
558                                         parser_warning("Found comments after preprocessing, please report\n");
559                         }
560 <comment>[^*\n]*        ;
561 <comment>"*"+[^*/\n]*   ;
562 <comment>\n             line_number++; char_number = 1;
563 <comment>"*"+"/"        yy_pop_state(); want_id = save_wanted_id;
565 ;[^\n]*                 want_id = wanted_id; /* not really comment, but left-over c-junk */
566 "//"[^\n]*              want_id = wanted_id; if(!no_preprocess) parser_warning("Found comments after preprocessing, please report\n");
568 \n                      {
569                                 want_id = wanted_id;
570                                 line_number++;
571                                 char_number = 1;
572                                 if(want_nl)
573                                 {
574                                         want_nl = 0;
575                                         return tNL;
576                                 }
577                         }
578 {ws}+                   want_id = wanted_id;    /* Eat whitespace */
580 <INITIAL>[ -~]          return yytext[0];
582 <*>.|\n                 {
583                                 /* Catch all rule to find any unmatched text */
584                                 if(*yytext == '\n')
585                                 {
586                                         line_number++;
587                                         char_number = 1;
588                                 }
589                                 parser_error("Unmatched text '%c' (0x%02x) YY_START=%d",
590                                              isprint((unsigned char)*yytext) ? *yytext : '.', *yytext, YY_START);
591                         }
595 /* These dup functions copy the enclosed '\0' from
596  * the resource string.
597  */
598 static void addcchar(char c)
600         if(cbufidx >= cbufalloc)
601         {
602                 cbufalloc += 1024;
603                 cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
604                 if(cbufalloc > 65536)
605                         parser_warning("Reallocating string buffer larger than 64kB\n");
606         }
607         cbuffer[cbufidx++] = c;
610 static void addwchar(WCHAR s)
612         if(wbufidx >= wbufalloc)
613         {
614                 wbufalloc += 1024;
615                 wbuffer = xrealloc(wbuffer, wbufalloc * sizeof(wbuffer[0]));
616                 if(wbufalloc > 65536)
617                         parser_warning("Reallocating wide string buffer larger than 64kB\n");
618         }
619         wbuffer[wbufidx++] = s;
622 static string_t *get_buffered_cstring(void)
624     string_t *str = new_string();
626     str->size = cbufidx;
627     str->type = str_char;
628     str->str.cstr = xmalloc(cbufidx+1);
629     memcpy(str->str.cstr, cbuffer, cbufidx);
630     str->str.cstr[cbufidx] = '\0';
632     if (!current_codepage || current_codepage == -1 || !win32)  /* store as ANSI string */
633     {
634         if (!current_codepage) parser_error("Codepage set to Unicode only, cannot use ASCII string here");
635         return str;
636     }
637     else  /* convert to Unicode before storing */
638     {
639         string_t *str_w = convert_string( str, str_unicode, current_codepage );
640         if (!check_unicode_conversion( str, str_w, current_codepage ))
641             parser_error("String %s does not convert identically to Unicode and back in codepage %d. "
642                     "Try using a Unicode string instead", str->str.cstr, current_codepage );
643         if (check_valid_utf8( str, current_codepage ))
644             parser_warning( "string \"%s\" seems to be UTF-8 but codepage %u is in use.\n",
645                             str->str.cstr, current_codepage );
646         free_string( str );
647         return str_w;
648     }
651 static string_t *get_buffered_wstring(void)
653         string_t *str = new_string();
654         str->size = wbufidx;
655         str->type = str_unicode;
656         str->str.wstr = xmalloc((wbufidx+1)*sizeof(WCHAR));
657         memcpy(str->str.wstr, wbuffer, wbufidx*sizeof(WCHAR));
658         str->str.wstr[wbufidx] = 0;
659         return str;
662 static string_t *make_string(char *s)
664         string_t *str = new_string();
665         str->size = strlen(s);
666         str->type = str_char;
667         str->str.cstr = xmalloc(str->size+1);
668         memcpy(str->str.cstr, s, str->size+1);
669         return str;