3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998 Bertho A. Stultiens (BS)
6 * 20-Jun-1998 BS - Changed the filename conversion. Filenames are
7 * case-sensitive inder *nix, but not under dos.
8 * default behaviour is to convert to lower case.
9 * - All backslashes are converted to forward and
10 * both single and double slash is recognized as
12 * - Fixed a bug in 'yywf' case that prevented
13 * double quoted names to be scanned propperly.
15 * 19-May-1998 BS - Started to build a preprocessor.
16 * - Changed keyword processing completely to
19 * 20-Apr-1998 BS - Added ';' comment stripping
21 * 17-Apr-1998 BS - Made the win32 keywords optional when compiling in
24 * 15-Apr-1998 BS - Changed string handling to include escapes
25 * - Added unicode string handling (no codepage
26 * translation though).
27 * - 'Borrowed' the main idea of string scanning from
28 * the flex manual pages.
29 * - Added conditional handling of scanning depending
30 * on the state of the parser. This was mainly required
31 * to distinguish a file to load or raw data that
32 * follows. MS's definition of filenames is rather
33 * complex... It can be unquoted or double quoted. If
34 * double quoted, then the '\\' char is not automatically
35 * escaped according to Borland's rc compiler, but it
36 * accepts both "\\path\\file.rc" and "\path\file.rc".
37 * This makes life very hard! I go for the escaped
38 * version, as this seems to be the documented way...
39 * - Single quoted strings are now parsed and converted
41 * - Added comment stripping. The implementation is
42 * 'borrowed' from the flex manpages.
43 * - Rebuild string processing so that it may contain
47 /* Exclusive rules when looking for a filename */
50 /* Exclusive string handling */
52 /* Exclusive unicode string handling */
54 /* Exclusive rcdata single quoted data handling */
56 /* Exclusive comment eating... */
58 /* Preprocessor exclusives */
69 /* Set when accumulating #define's expansion text */
71 /* Set when processing function type defines */
73 /* Set when need to strip to eol */
75 /* Set when handling a false #if case */
77 /* Set when stripping c-junk */
83 %option never-interactive
85 /* Some shortcut definitions */
87 cident [a-zA-Z_][0-9a-zA-Z_]*
91 #if !defined(YY_FLEX_MAJOR_VERSION) || (1000 * YY_FLEX_MAJOR_VERSION + YY_FLEX_MINOR_VERSION < 2005)
92 #error Must use flex version 2.5.1 or higher (yy_scan_* routines are required).
108 #include "newstruc.h"
112 #define YY_USE_PROTOS
115 /* Always update the current character position within a line */
116 #define YY_USER_ACTION char_number+=yyleng;
118 raw_data_t *new_raw_data(void);
120 void addcchar(char c);
121 void addwchar(short s);
122 string_t *get_buffered_cstring(void);
123 string_t *get_buffered_wstring(void);
124 string_t *make_string(char *s);
125 string_t *make_filename(char *s, int len);
127 int line_number = 1; /* The current line */
128 int char_number = 1; /* The current char pos within the line */
129 static char *cbuffer; /* Buffers for string collection */
131 static int cbufalloc = 0;
132 static short *wbuffer;
134 static int wbufalloc = 0;
135 static int want_nl = 0; /* Set when newline needs to go to parser */
136 static int want_ident = 0; /* Set is #ifdef, #ifndef or defined is seen */
137 static int stripslevel = 0; /* Count {} during pp_strips mode */
138 static int stripplevel = 0; /* Count () during pp_strips mode */
139 static char *substtext = NULL; /* Holds the substition text while getting a define */
140 static int cjunk_tagline; /* Where did we start stripping (helps error tracking) */
143 void push_to(int start) { yy_push_state(start); }
144 void pop_start(void) { yy_pop_state(start); }
146 #define MAXSTARTSTACK 32
147 static int startstack[MAXSTARTSTACK];
148 static int startstackidx = 0;
150 void push_to(int start)
153 printf("push_to(%d): %d -> %d\n", line_number, YY_START, start);
154 if(startstackidx >= MAXSTARTSTACK-1)
155 internal_error(__FILE__, __LINE__, "Start condition stack overflow");
156 startstack[startstackidx++] = YY_START;
163 printf("pop_start(%d): %d <- %d\n", line_number, startstack[startstackidx-1], YY_START);
164 if(startstackidx <= 0)
165 internal_error(__FILE__, __LINE__, "Start condition stack underflow");
167 BEGIN(startstack[startstackidx]);
172 struct bufferstackentry {
173 YY_BUFFER_STATE bufferstate; /* Buffer to switch back to */
174 struct pp_entry *define; /* Points to expanding define
175 or NULL if handling includes
177 int line_number; /* Line that we were handling */
178 int char_number; /* The current position */
179 char *filename; /* Filename that we were handling */
182 #define MAXBUFFERSTACK 128
183 static struct bufferstackentry bufferstack[MAXBUFFERSTACK];
184 static int bufferstackidx = 0;
186 void push_buffer(YY_BUFFER_STATE buf, struct pp_entry *ppp, char *filename)
189 printf("push_buffer: %p %p %p\n", buf, ppp, filename);
190 if(bufferstackidx >= MAXBUFFERSTACK-1)
191 internal_error(__FILE__, __LINE__, "Buffer stack overflow");
192 memset(&bufferstack[bufferstackidx], 0, sizeof(bufferstack[0]));
193 bufferstack[bufferstackidx].bufferstate = buf;
194 bufferstack[bufferstackidx].define = ppp;
199 /* These will track the yyerror to the correct file and line */
200 bufferstack[bufferstackidx].line_number = line_number;
201 bufferstack[bufferstackidx].char_number = char_number;
204 bufferstack[bufferstackidx].filename = input_name;
205 input_name = filename;
208 internal_error(__FILE__, __LINE__, "Pushing buffer without knowing where to go to");
212 YY_BUFFER_STATE pop_buffer(void)
214 if(bufferstackidx <= 0)
215 return (YY_BUFFER_STATE)0;
217 if(bufferstack[bufferstackidx].define)
218 bufferstack[bufferstackidx].define->expanding = 0;
221 line_number = bufferstack[bufferstackidx].line_number;
222 char_number = bufferstack[bufferstackidx].char_number;
223 input_name = bufferstack[bufferstackidx].filename;
227 printf("pop_buffer: %p %p (%d, %d) %p\n",
228 bufferstack[bufferstackidx].bufferstate,
229 bufferstack[bufferstackidx].define,
230 bufferstack[bufferstackidx].line_number,
231 bufferstack[bufferstackidx].char_number,
232 bufferstack[bufferstackidx].filename);
233 yy_switch_to_buffer(bufferstack[bufferstackidx].bufferstate);
234 return bufferstack[bufferstackidx].bufferstate;
237 void do_include(char *name, int namelen)
239 char *cpy = (char *)xmalloc(namelen);
240 strcpy(cpy, name+1); /* strip leading " or < */
241 cpy[namelen-2] = '\0'; /* strip trailing " or > */
242 if((yyin = open_include(cpy, name[0] == '"')) == NULL)
243 yyerror("Unable to open include file %s", cpy);
244 push_buffer(YY_CURRENT_BUFFER, NULL, cpy);
245 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
257 static struct keyword keywords[] = {
258 { "ACCELERATORS", ACCELERATORS, 0, 0, 0},
259 { "ALT", ALT, 0, 0, 0},
260 { "ASCII", ASCII, 0, 0, 0},
261 { "AUTO3STATE", AUTO3STATE, 1, 0, 0},
262 { "AUTOCHECKBOX", AUTOCHECKBOX, 1, 0, 0},
263 { "AUTORADIOBUTTON", AUTORADIOBUTTON, 1, 0, 0},
264 { "BEGIN", tBEGIN, 0, 0, 1},
265 { "BITMAP", tBITMAP, 0, 0, 0},
266 { "BLOCK", BLOCK, 0, 0, 1},
267 { "BUTTON", BUTTON, 1, 0, 0},
268 { "CAPTION", CAPTION, 0, 0, 0},
269 { "CHARACTERISTICS", CHARACTERISTICS, 1, 0, 0},
270 { "CHECKBOX", CHECKBOX, 0, 0, 0},
271 { "CHECKED", CHECKED, 0, 0, 0},
272 { "CLASS", CLASS, 0, 0, 0},
273 { "COMBOBOX", COMBOBOX, 0, 0, 0},
274 { "CONTROL", CONTROL, 0, 0, 0},
275 { "CTEXT", CTEXT, 0, 0, 0},
276 { "CURSOR", CURSOR, 0, 0, 0},
277 { "defined", tDEFINED, 0, 1, 1},
278 { "DEFPUSHBUTTON", DEFPUSHBUTTON, 0, 0, 1},
279 { "DIALOG", DIALOG, 0, 0, 0},
280 { "DIALOGEX", DIALOGEX, 1, 0, 0},
281 { "DISCARDABLE", DISCARDABLE, 0, 0, 0},
282 { "DLGINIT", DLGINIT, 0, 0, 0},
283 { "EDITTEXT", EDITTEXT, 0, 0, 0},
284 { "END", tEND, 0, 0, 1},
285 { "EXSTYLE", EXSTYLE, 0, 0, 0},
286 { "extern", tEXTERN, 0, 1, 1},
287 { "FILEFLAGS", FILEFLAGS, 0, 0, 0},
288 { "FILEFLAGSMASK", FILEFLAGSMASK, 0, 0, 0},
289 { "FILEOS", FILEOS, 0, 0, 0},
290 { "FILESUBTYPE", FILESUBTYPE, 0, 0, 0},
291 { "FILETYPE", FILETYPE, 0, 0, 0},
292 { "FILEVERSION", FILEVERSION, 0, 0, 0},
293 { "FIXED", tFIXED, 0, 0, 0},
294 { "FONT", FONT, 0, 0, 0},
295 { "GRAYED", GRAYED, 0, 0, 0},
296 { "GROUPBOX", GROUPBOX, 0, 0, 0},
297 { "HELP", HELP, 0, 0, 0},
298 { "ICON", ICON, 0, 0, 0},
299 { "IMPURE", IMPURE, 0, 0, 0},
300 { "INACTIVE", INACTIVE, 0, 0, 0},
301 { "LANGUAGE", LANGUAGE, 1, 0, 1},
302 { "LISTBOX", LISTBOX, 0, 0, 0},
303 { "LOADONCALL", LOADONCALL, 0, 0, 0},
304 { "LTEXT", LTEXT, 0, 0, 0},
305 { "MENU", MENU, 0, 0, 0},
306 { "MENUBARBREAK", MENUBARBREAK, 0, 0, 0},
307 { "MENUBREAK", MENUBREAK, 0, 0, 0},
308 { "MENUEX", MENUEX, 1, 0, 0},
309 { "MENUITEM", MENUITEM, 0, 0, 0},
310 { "MESSAGETABLE", MESSAGETABLE, 1, 0, 0},
311 { "MOVEABLE", MOVEABLE, 0, 0, 0},
312 { "NOINVERT", NOINVERT, 0, 0, 0},
313 { "NOT", NOT, 0, 0, 0},
314 { "POPUP", POPUP, 0, 0, 0},
315 { "PRELOAD", PRELOAD, 0, 0, 0},
316 { "PRODUCTVERSION", PRODUCTVERSION, 0, 0, 0},
317 { "PURE", tPURE, 0, 0, 0},
318 { "PUSHBUTTON", PUSHBUTTON, 0, 0, 0},
319 { "RADIOBUTTON", RADIOBUTTON, 0, 0, 0},
320 { "RCDATA", RCDATA, 0, 0, 0},
321 { "RTEXT", RTEXT, 0, 0, 0},
322 { "SCROLLBAR", SCROLLBAR, 0, 0, 0},
323 { "SEPARATOR", SEPARATOR, 0, 0, 0},
324 { "SHIFT", SHIFT, 0, 0, 0},
325 { "STATE3", STATE3, 1, 0, 0},
326 { "STRING", tSTRING, 0, 0, 0},
327 { "STRINGTABLE", STRINGTABLE, 0, 0, 1},
328 { "STYLE", STYLE, 0, 0, 0},
329 { "TOOLBAR", TOOLBAR, 1, 0, 0},
330 { "typedef", tTYPEDEF, 0, 1, 1},
331 { "VALUE", VALUE, 0, 0, 0},
332 { "VERSION", VERSION, 1, 0, 0},
333 { "VERSIONINFO", VERSIONINFO, 0, 0, 0},
334 { "VIRTKEY", VIRTKEY, 0, 0, 0}
337 #define NKEYWORDS (sizeof(keywords)/sizeof(keywords[0]))
338 #define KWP(p) ((struct keyword *)(p))
339 int kw_cmp_func(const void *s1, const void *s2)
342 ret = strcasecmp(KWP(s1)->keyword, KWP(s2)->keyword);
343 if(!ret && (KWP(s1)->needcase || KWP(s2)->needcase))
344 return strcmp(KWP(s1)->keyword, KWP(s2)->keyword);
351 struct keyword *iskeyword(char *kw)
359 /* Make sure that it is sorted for bsearsh */
360 static int sorted = 0;
363 qsort(keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
369 kwp = bsearch(&key, keywords, NKEYWORDS, sizeof(keywords[0]), kw_cmp_func);
373 for(i = 0; i < NKEYWORDS; i++)
375 if(!kw_cmp_func(&key, &keywords[i]))
386 if(kwp && !strcmp(kwp->keyword, "LANGUAGE"))
387 printf("Got Language\n");
389 if(kwp == NULL || (kwp->isextension && !extensions))
395 void add_to_substtext(char *text, int len)
399 substtext = xstrdup(text);
403 substtext = (char *)xrealloc(substtext, strlen(substtext)+len+1);
404 strcat(substtext, text);
411 /* #include handling */
412 ^{ws}*#{ws}*include{ws}* push_to(pp_incl);
413 <pp_incl>\<[^\n\>]+\> do_include(yytext, yyleng); pop_start();
414 <pp_incl>\"[^\n\>]+\" do_include(yytext, yyleng); pop_start();
415 <pp_incl>. yyerror("Malformed #include");
417 /* #define handling */
418 ^{ws}*#{ws}*define{ws}* push_to(pp_def);
423 <pp_def>{cident}\( push_to(pp_ignore); /* Ignore function-like defines for now*/
424 <pp_def>. yyerror("Malformed #define");
426 <pp_ignore,pp_def_s>[^\/\\\n]* {
427 if(YY_START == pp_def_s)
428 add_to_substtext(yytext, yyleng);
430 <pp_ignore,pp_def_s>\/[^\/\*][^\/\\\n]* { /* Comment is handled in normal handling */
431 if(YY_START == pp_def_s)
432 add_to_substtext(yytext, yyleng);
434 <pp_ignore,pp_def_s>\\{ws}*\n line_number++; char_number = 1; /* Line continuation */
435 <pp_ignore,pp_def_s>\n {
436 if(YY_START == pp_def_s)
438 add_define(substtext ? substtext : "");
448 /* #undef handling */
449 ^{ws}*#{ws}*undef{ws}* push_to(pp_undef);
453 /*push_to(pp_ignore);*/
456 /* Conditional handling */
457 <INITIAL,pp_strips,pp_stripp,pp_false>^{ws}*#{ws}*if{ws}* {
458 if(YY_START == pp_false)
461 printf("(%d)#if ignored\n", line_number);
463 push_to(pp_ignore_eol);
472 <INITIAL,pp_strips,pp_stripp,pp_false>^{ws}*#{ws}*ifdef{ws}* {
473 if(YY_START == pp_false)
476 printf("(%d)#ifdef ignored\n", line_number);
478 push_to(pp_ignore_eol);
488 <INITIAL,pp_strips,pp_stripp,pp_false>^{ws}*#{ws}*ifndef{ws}* {
489 if(YY_START == pp_false)
492 printf("(%d)#ifndef ignored\n", line_number);
494 push_to(pp_ignore_eol);
504 <INITIAL,pp_strips,pp_stripp,pp_false>^{ws}*#{ws}*elif{ws}* {
505 if(!isnevertrue_if())
511 else if(YY_START == pp_false)
512 push_to(pp_ignore_eol);
514 printf("(%d)#elif ignored\n", line_number);
516 <INITIAL,pp_strips,pp_stripp,pp_false>^{ws}*#{ws}*else{ws}* {
517 if(!isnevertrue_if())
524 printf("(%d)#else ignored\n", line_number);
526 <INITIAL,pp_strips,pp_stripp,pp_false>^{ws}*#{ws}*endif{ws}* {
527 if(!isnevertrue_if())
535 printf("(%d)#endif ignored\n", line_number);
540 /* The error directive */
541 ^{ws}*#{ws}*error{ws}* push_to(pp_error);
542 <pp_error>[^\n]* yyerror("Error directive: %s", yytext);
544 /* preprocessor junk */
545 ^{ws}*#{ws}*pragma[^\n]* ; /* Ignore #pragma */
546 ^{ws}*#{ws}*line[^\n]* ; /* Ignore #line */
547 /* We'll get an error on malformed #xxx statements
548 * by not recognising '#' at all. This helps tracking
549 * preprocessor errors.
551 /*^{ws}*#{ws}* ; Ignore # */
553 <pp_strips>\{ stripslevel++;
554 <pp_strips>\} stripslevel--;
555 <pp_strips>; if(!stripslevel) pop_start();
556 <pp_strips>\/[^*\n] ; /* To catch comments */
557 <pp_strips>[^\{\};\n#/]* ; /* Ignore rest */
559 <pp_stripp>\( stripplevel++;
565 push_to(pp_stripp_final);
568 <pp_stripp>\/[^*\n] ; /* To catch comments */
569 <pp_stripp>[^\(\);\n#/]* ; /* Ignore rest */
571 <pp_stripp_final>{ws}* ; /* Ignore */
572 <pp_stripp_final>; pop_start(); /* Kill the semicolon */
573 <pp_stripp_final>\n line_number++; char_number = 1; pop_start();
574 <pp_stripp_final>. yyless(0); pop_start();
576 <pp_false>. ; /* Ignore everything except #xxx during false #if state */
578 <pp_ignore_eol>[^\n]* pop_start();
580 /* These are special cases due to filename scanning */
581 <yywf>[Dd][Ii][Ss][Cc][Aa][Rr][Dd][Aa][Bb][Ll][Ee] return DISCARDABLE;
582 <yywf>[Ff][Ii][Xx][Ee][Dd] return tFIXED;
583 <yywf>[Ii][Mm][Pp][Uu][Rr][Ee] return IMPURE;
584 <yywf>[Mm][Oo][Vv][Ee][Aa][Bb][Ll][Ee] return MOVEABLE;
585 <yywf>[Ll][Oo][Aa][Dd][Oo][Nn][Cc][Aa][Ll][Ll] return LOADONCALL;
586 <yywf>[Pp][Rr][Ee][Ll][Oo][Aa][Dd] return PRELOAD;
587 <yywf>[Pp][Uu][Rr][Ee] return tPURE;
592 [0-9]+[lL]? { yylval.num = strtoul(yytext, 0, 10); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
593 0[xX][0-9A-Fa-f]+[lL]? { yylval.num = strtoul(yytext, 0, 16); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
594 0[oO][0-7]+[lL]? { yylval.num = strtoul(yytext+2, 0, 8); return toupper(yytext[yyleng-1]) == 'L' ? LNUMBER : NUMBER; }
596 struct keyword *token;
597 struct pp_entry *ppp;
603 /* Prevent preprocessor subst */
605 yylval.str = make_string(yytext);
607 printf("want IDENT (%s, %d, %d): <%s>\n", input_name, line_number, char_number, yytext);
611 else if((ppp = pp_lookup(yytext)) != NULL)
613 /* Do preprocessor substitution,
614 * but expand only if macro is not
620 printf("expand IDENT (%s, %d, %d): <%s>\n", input_name, line_number, char_number, yytext);
622 push_buffer(YY_CURRENT_BUFFER, ppp, NULL);
623 yy_scan_string(ppp->subst);
626 else if((token = iskeyword(yytext)) != NULL
627 && !(!token->alwayskeyword && want_rscname))
655 yylval.str = make_string(yytext);
657 printf("%s IDENT (%s, %d, %d): <%s>\n",
658 want_rscname ? "rscname" : "just",
674 <yywf>[^ \f\t\r\n\"]* { pop_start(); yylval.str = make_filename(yytext, yyleng); return FILENAME; }
675 <yywf>\" push_to(yywf_s);
676 <yywf_s>[^\"\n]*\" { pop_start(); pop_start(); yylval.str = make_filename(yytext, yyleng-1); return FILENAME; }
677 <yywf_s>\n yyerror("Newline in filename");
683 yywarning("16bit resource contains unicode strings\n");
687 yylval.str = get_buffered_wstring();
690 <yylstr>\n yyerror("Unterminated string");
691 <yylstr>\\[0-7]{1,6} { /* octal escape sequence */
693 result = strtol(yytext+1, 0, 8);
694 if ( result > 0xffff )
695 yyerror("Character constant out of range");
696 addwchar((short)result);
698 <yylstr>\\x[0-9a-fA-F]{4} { /* hex escape sequence */
700 result = strtol(yytext+2, 0, 16);
701 addwchar((short)result);
703 <yylstr>\\[0-9]+ yyerror("Bad escape secuence");
704 <yylstr>\\a addwchar('\a');
705 <yylstr>\\b addwchar('\b');
706 <yylstr>\\f addwchar('\f');
707 <yylstr>\\n addwchar('\n');
708 <yylstr>\\r addwchar('\r');
709 <yylstr>\\t addwchar('\t');
710 <yylstr>\\v addwchar('\v');
711 <yylstr>\\(.|\n) addwchar(yytext[1]);
712 <yylstr>\"\" addcchar('\"'); /* "bla""bla" -> "bla\"bla" */
713 <yylstr>\\\"\" addcchar('\"'); /* "bla\""bla" -> "bla\"bla" */
714 <yylstr>\"{ws}+\" ; /* "bla" "bla" -> "blabla" */
717 while(*yptr) /* FIXME: codepage translation */
718 addwchar(*yptr++ & 0xff);
727 yylval.str = get_buffered_cstring();
730 <yystr>\n yyerror("Unterminated string");
731 <yystr>\\[0-7]{1,3} { /* octal escape sequence */
733 result = strtol(yytext+1, 0, 8);
735 yyerror("Character constant out of range");
736 addcchar((char)result);
738 <yystr>\\x[0-9a-fA-F]{2} { /* hex escape sequence */
740 result = strtol(yytext+2, 0, 16);
741 addcchar((char)result);
743 <yystr>\\[0-9]+ yyerror("Bad escape secuence");
744 <yystr>\\a addcchar('\a');
745 <yystr>\\b addcchar('\b');
746 <yystr>\\f addcchar('\f');
747 <yystr>\\n addcchar('\n');
748 <yystr>\\r addcchar('\r');
749 <yystr>\\t addcchar('\t');
750 <yystr>\\v addcchar('\v');
751 <yystr>\\(.|\n) addcchar(yytext[1]);
757 <yystr>\"\" addcchar('\"'); /* "bla""bla" -> "bla\"bla" */
758 <yystr>\\\"\" addcchar('\"'); /* "bla\""bla" -> "bla\"bla" */
759 <yystr>\"{ws}+\" ; /* "bla" "bla" -> "blabla" */
760 <yystr>. yywarning("Matched %c");
769 yylval.raw = new_raw_data();
770 yylval.raw->size = cbufidx;
771 yylval.raw->data = xmalloc(yylval.raw->size);
772 memcpy(yylval.raw->data, cbuffer, yylval.raw->size);
775 <yyrcd>[0-9a-fA-F]{2} {
777 result = strtol(yytext, 0, 16);
778 addcchar((char)result);
780 <yyrcd>{ws}+ ; /* Ignore space */
781 <yyrcd>\n line_number++; char_number = 1;
782 <yyrcd>. yyerror("Malformed data-line");
784 <INITIAL,pp_ignore,pp_def_s,pp_strips,pp_stripp>"/*" push_to(comment); /* Eat comment */
786 <comment>"*"+[^*/\n]* ;
787 <comment>\n line_number++; char_number = 1;
788 <comment>"*"+"/" pop_start();
790 ;[^\n]* ; /* Eat comment */
791 <INITIAL,pp_ignore,pp_def_s>"//"[^\n]* ; /* Eat comment */
793 <INITIAL,yywf,pp_false,pp_strips,pp_stripp>\n {
804 <INITIAL,yywf>{ws}+ ; /* Eat whitespace */
806 <INITIAL>. return yytext[0];
808 YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
811 if(YY_START == pp_strips || YY_START == pp_stripp || YY_START == pp_stripp_final)
812 yyerror("Unexpected end of file during c-junk scanning (started at %d)", cjunk_tagline);
820 /* Catch all rule to find any unmatched text */
826 yywarning("Unmatched text '%c' (0x%02x) YY_START=%d",
827 isprint(*yytext) ? *yytext : '.', *yytext, YY_START);
836 if(bufferstackidx > 0)
845 /* These dup functions copy the enclosed '\0' from
846 * the resource string.
848 void addcchar(char c)
850 if(cbufidx >= cbufalloc)
853 cbuffer = xrealloc(cbuffer, cbufalloc * sizeof(cbuffer[0]));
854 if(cbufalloc > 65536)
855 yywarning("Reallocating string buffer larger than 64kB");
857 cbuffer[cbufidx++] = c;
860 void addwchar(short s)
862 if(wbufidx >= wbufalloc)
865 wbuffer = xrealloc(wbuffer, wbufalloc * sizeof(wbuffer[0]));
866 if(wbufalloc > 65536)
867 yywarning("Reallocating wide string buffer larger than 64kB");
871 * BS 08-Aug-1999 FIXME: The '& 0xff' is probably a bug, but I have
872 * not experienced it yet and I seem to remember that this was for
873 * a reason. But, as so many things you tend to forget why.
874 * I guess that there were problems due to the sign extension of
875 * shorts WRT chars (e.g. 0x80 becomes 0xff80 instead of 0x0080).
876 * This should then be fixed in the lexer calling the function.
878 wbuffer[wbufidx++] = (short)(s & 0xff);
881 string_t *get_buffered_cstring(void)
883 string_t *str = new_string();
885 str->type = str_char;
886 str->str.cstr = (char *)xmalloc(cbufidx+1);
887 memcpy(str->str.cstr, cbuffer, cbufidx);
888 str->str.cstr[cbufidx] = '\0';
889 /* printf("got cstring \"%s\"\n", str->str.cstr); */
893 string_t *get_buffered_wstring(void)
895 string_t *str = new_string();
897 str->type = str_unicode;
898 str->str.wstr = (short *)xmalloc(2*(wbufidx+1));
899 memcpy(str->str.wstr, wbuffer, wbufidx);
900 str->str.wstr[wbufidx] = 0;
904 string_t *make_string(char *s)
906 string_t *str = new_string();
907 str->size = strlen(s);
908 str->type = str_char;
909 str->str.cstr = (char *)xmalloc(str->size+1);
910 memcpy(str->str.cstr, s, str->size+1);
914 string_t *make_filename(char *s, int len)
917 string_t *str = new_string();
920 str->type = str_char;
921 str->str.cstr = (char *)xmalloc(str->size+1);
922 memcpy(str->str.cstr, s, str->size);
923 str->str.cstr[str->size] = '\0';
925 /* Remove escaped backslash and convert to forward */
926 cptr = str->str.cstr;
927 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
931 memmove(cptr, cptr+1, strlen(cptr));
937 /* Convert to lower case. Seems to be reasonable to do */
938 for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
940 *cptr = tolower(*cptr);
945 /* Called from the parser to signal filename request */
951 /* Called from the parser to signal preprocessor if case */
952 void set_pp_ignore(int state)
960 /* Called from the parser to kill c-junk */
961 void strip_til_semicolon(void)
963 cjunk_tagline = line_number;
967 void strip_til_parenthesis(void)
969 cjunk_tagline = line_number;
970 stripplevel = 1; /* One scanned already */