3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * 21-May-2000 BS - Partial implementation of font resources.
8 * - Corrected language propagation for binary
9 * resources such as bitmaps, isons, cursors,
10 * userres and rcdata. The language is now
11 * correct in .res files.
12 * - Fixed reading the resource name as ident,
13 * so that it may overlap keywords.
14 * 20-May-2000 BS - Implemented animated cursors and icons
16 * 30-Apr-2000 BS - Reintegration into the wine-tree
17 * 14-Jan-2000 BS - Redid the usertype resources so that they
19 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
20 * expect for the # command (line numbers).
22 * 06-Nov-1999 JS - see CHANGES
24 * 29-Dec-1998 AdH - Grammar and function extensions.
25 * grammar: TOOLBAR resources, Named ICONs in
27 * functions: semantic actions for the grammar
28 * changes, resource files can now be anywhere
29 * on the include path instead of just in the
32 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
33 * printed out correctly.
35 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
36 * also accept a tSTRING as argument.
38 * 25-May-1998 BS - Found out that I need to support language, version
39 * and characteristics in inline resources (bitmap,
40 * cursor, etc) but they can also be specified with
41 * a filename. This renders my filename-scanning scheme
42 * worthless. Need to build newline parsing to solve
44 * It will come with version 1.1.0 (sigh).
46 * 19-May-1998 BS - Started to build a builtin preprocessor
48 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
49 * ideas had some serious flaws.
51 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
54 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
55 * - This file is growing too big. It is time to strip
56 * things and put it in a support file.
58 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
59 * resource will be created. This because the table
60 * has a different layout than other resources. The
61 * table has to be sorted, and divided into smaller
62 * resource entries (see comment in source).
64 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
65 * as string_t which include unicode strings upon
67 * - Parser now emits a warning when compiling win32
68 * extensions in win16 mode.
70 * 16-Apr-1998 BS - Raw data elements are now *optionally* seperated
71 * by commas. Read the comments in file sq2dq.l.
72 * - FIXME: there are instances in the source that rely
73 * on the fact that int==32bit and pointers are int size.
74 * - Fixed the conflict in menuex by changing a rule
75 * back into right recursion. See note in source.
76 * - UserType resources cannot have an expression as its
77 * typeclass. See note in source.
79 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
80 * get reduction of the parsestack.
81 * This also helps communication between bison and flex.
82 * Main advantage is that the Empty rule gets reduced
83 * first, which is used to allocate/link things.
84 * It also added a shift/reduce conflict in the menuex
85 * handling, due to expression/option possibility,
86 * although not serious.
88 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
89 * about making it more efficient, but readable (for me)
90 * and slightly easier to expand/change.
91 * This is done primarily by using more reduce states
92 * with many (intuitive) types for the various resource
94 * - Added expression handling for all resources where a
95 * number is accepted (not only for win32). Also added
96 * multiply and division (not MS compatible, but handy).
97 * Unary minus introduced a shift/reduce conflict, but
100 * 13-Apr-1998 BS - Reordered a lot of things
101 * - Made the source more readable
102 * - Added Win32 resource definitions
103 * - Corrected syntax problems with an old yacc (;)
104 * - Added extra comment about grammar
120 #include "newstruc.h"
128 int want_nl = 0; /* Signal flex that we need the next newline */
129 int want_id = 0; /* Signal flex that we need the next identifier */
130 stringtable_t *tagstt; /* Stringtable tag.
131 * It is set while parsing a stringtable to one of
132 * the stringtables in the sttres list or a new one
133 * if the language was not parsed before.
135 stringtable_t *sttres; /* Stringtable resources. This holds the list of
136 * stringtables with different lanuages
138 static int dont_want_id = 0; /* See language parsing for details */
140 /* Set to the current options of the currently scanning stringtable */
141 static int *tagstt_memopt;
142 static characts_t *tagstt_characts;
143 static version_t *tagstt_version;
145 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
147 /* Prototypes of here defined functions */
148 static event_t *get_event_head(event_t *p);
149 static control_t *get_control_head(control_t *p);
150 static ver_value_t *get_ver_value_head(ver_value_t *p);
151 static ver_block_t *get_ver_block_head(ver_block_t *p);
152 static resource_t *get_resource_head(resource_t *p);
153 static menuex_item_t *get_itemex_head(menuex_item_t *p);
154 static menu_item_t *get_item_head(menu_item_t *p);
155 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
156 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
157 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
158 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
159 static raw_data_t *str2raw_data(string_t *str);
160 static raw_data_t *int2raw_data(int i);
161 static raw_data_t *long2raw_data(int i);
162 static raw_data_t *load_file(string_t *name);
163 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
164 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
165 static event_t *add_event(int key, int id, int flags, event_t *prev);
166 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
167 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
168 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
169 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
170 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
171 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
172 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
173 static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
174 static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
175 static name_id_t *convert_ctlclass(name_id_t *cls);
176 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
177 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
178 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
179 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
180 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
181 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
182 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
183 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
184 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
185 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
186 static resource_t *build_stt_resources(stringtable_t *stthead);
187 static stringtable_t *find_stringtable(lvc_t *lvc);
188 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
189 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
190 static string_t *make_filename(string_t *s);
191 static resource_t *build_fontdirs(resource_t *tail);
192 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
193 static int rsrcid_to_token(int lookahead);
224 menuex_item_t *menexitm;
232 toolbar_item_t *tlbarItems;
234 style_pair_t *styles;
239 %token tTYPEDEF tEXTERN tSTRUCT tENUM tCPPCLASS tINLINE tSTATIC tNL
240 %token <num> tNUMBER tLNUMBER
241 %token <str> tSTRING tIDENT tFILENAME
242 %token <raw> tRAWDATA
243 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
244 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
245 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
246 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
247 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
248 %token tCONTROL tEDITTEXT
249 %token tRTEXT tCTEXT tLTEXT
251 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
252 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
253 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
254 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
255 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
257 %token tSTRING tIDENT tRAWDATA
258 %token tTOOLBAR tBUTTON
269 %type <res> resource_file resource resources resource_definition
270 %type <stt> stringtable strings
273 %type <acc> accelerators
276 %type <ani> cursor icon
277 %type <dlg> dialog dlg_attributes
278 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
280 %type <dlgex> dialogex dlgex_attribs
281 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
283 %type <raw> raw_data raw_elements opt_data file_raw
284 %type <veri> versioninfo fix_version
285 %type <verw> ver_words
286 %type <blk> ver_blocks ver_block
287 %type <val> ver_values ver_value
289 %type <menitm> item_definitions menu_body
291 %type <menexitm> itemex_definitions menuex_body
292 %type <exopt> itemex_p_options itemex_options
293 %type <msg> messagetable
295 %type <num> item_options
296 %type <nid> nameid nameid_s ctlclass usertype
297 %type <num> acc_opt acc accs
298 %type <iptr> loadmemopts lamo lama
299 %type <fntid> opt_font opt_exfont opt_expr
301 %type <lan> opt_language
302 %type <chars> opt_characts
303 %type <ver> opt_version
306 %type <tlbar> toolbar
307 %type <tlbarItems> toolbar_items
308 %type <dginit> dlginit
309 %type <styles> optional_style_pair
311 %type <style> optional_style
320 /* First add stringtables to the resource-list */
321 rsc = build_stt_resources(sttres);
322 /* 'build_stt_resources' returns a head and $1 is a tail */
331 /* Find the tail again */
332 while($1 && $1->next)
334 /* Now add any fontdirecory */
335 rsc = build_fontdirs($1);
336 /* 'build_fontdir' returns a head and $1 is a tail */
345 /* Final statement before were done */
346 resource_top = get_resource_head($1);
350 /* Resources are put into a linked list */
352 : /* Empty */ { $$ = NULL; want_id = 1; }
353 | resources resource {
356 resource_t *tail = $2;
357 resource_t *head = $2;
366 /* Check for duplicate identifiers */
369 resource_t *rsc = $1;
372 if(rsc->type == head->type
373 && rsc->lan->id == head->lan->id
374 && rsc->lan->sub == head->lan->sub
375 && !compare_name_id(rsc->name, head->name))
377 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
386 resource_t *tail = $1;
394 if(!dont_want_id) /* See comments in language parsing below */
398 | resources cjunk { $$ = $1; want_id = 1; }
403 cjunk : tTYPEDEF { strip_til_semicolon(); }
404 | tSTRUCT { strip_til_semicolon(); }
405 | tEXTERN { strip_til_semicolon(); }
406 | tENUM { strip_til_semicolon(); }
407 | tCPPCLASS { strip_til_semicolon(); }
408 | tSTATIC { strip_til_semicolon(); }
409 | tINLINE { internal_error(__FILE__, __LINE__, "Don't yet know how to strip inline functions\n"); }
410 /* | tIDENT tIDENT { strip_til_semicolon(); } */
411 | tIDENT tIDENT '(' { strip_til_parenthesis(); }
412 /* | tIDENT '(' { strip_til_parenthesis(); } */
413 | tIDENT '*' { strip_til_semicolon(); }
416 /* Parse top level resource definitions etc. */
418 : nameid usrcvt resource_definition {
423 if($1->type == name_ord)
425 chat("Got %s (%d)",get_typename($3),$1->name.i_name);
427 else if($1->type == name_str)
429 chat("Got %s (%s)",get_typename($3),$1->name.s_name->str.cstr);
434 /* Don't do anything, stringtables are converted to
435 * resource_t structures when we are finished parsing and
436 * the final rule of the parser is reduced (see above)
439 chat("Got STRINGTABLE");
441 | tLANGUAGE {want_nl = 1; } expr ',' expr {
442 /* We *NEED* the newline to delimit the expression.
443 * Otherwise, we would not be able to set the next
444 * want_id anymore because of the token-lookahead.
446 * However, we can test the lookahead-token for
447 * being "non-expression" type, in which case we
448 * continue. Fortunately, tNL is the only token that
449 * will break expression parsing and is implicitely
450 * void, so we just remove it. This scheme makes it
451 * possible to do some (not all) fancy preprocessor
453 * BTW, we also need to make sure that the next
454 * reduction of 'resources' above will *not* set
455 * want_id because we already have a lookahead that
458 if(yychar != YYEMPTY && yychar != tNL)
463 else if(yychar == tIDENT)
464 yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
466 want_nl = 0; /* We don't want it anymore if we didn't get it */
469 yywarning("LANGUAGE not supported in 16-bit mode");
471 free(currentlanguage);
472 currentlanguage = new_language($3, $5);
474 chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
479 * Remapping of numerical resource types
480 * (see also comment of called function below)
482 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
486 * Get a valid name/id
489 if($1 > 65535 || $1 < -32768)
490 yyerror("Resource's ID out of range (%d)", $1);
493 $$->name.i_name = $1;
498 $$->name.s_name = $1;
503 * Extra string recognition for CLASS statement in dialogs
505 nameid_s: nameid { $$ = $1; }
509 $$->name.s_name = $1;
513 /* get the value for a single resource*/
515 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
516 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
519 if($1->type == res_anicur)
521 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
523 else if($1->type == res_curg)
526 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
527 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
529 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
530 rsc->prev->next = rsc;
532 rsc->name = new_name_id();
533 rsc->name->type = name_ord;
534 rsc->name->name.i_name = cur->id;
538 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
541 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
544 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
548 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
549 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
550 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
553 if($1->type == res_aniico)
555 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
557 else if($1->type == res_icog)
560 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
561 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
563 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
564 rsc->prev->next = rsc;
566 rsc->name = new_name_id();
567 rsc->name->type = name_ord;
568 rsc->name->name.i_name = ico->id;
572 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
575 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
578 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
582 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
583 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
584 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
585 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
586 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
590 filename: tFILENAME { $$ = make_filename($1); }
591 | tIDENT { $$ = make_filename($1); }
592 | tSTRING { $$ = make_filename($1); }
595 /* ------------------------------ Bitmap ------------------------------ */
596 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
599 /* ------------------------------ Cursor ------------------------------ */
600 cursor : tCURSOR loadmemopts file_raw {
602 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
604 $$->type = res_anicur;
605 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
610 $$->u.curg = new_cursor_group($3, $2);
615 /* ------------------------------ Icon ------------------------------ */
616 icon : tICON loadmemopts file_raw {
618 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
620 $$->type = res_aniico;
621 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
626 $$->u.icog = new_icon_group($3, $2);
631 /* ------------------------------ Font ------------------------------ */
633 * The reading of raw_data for fonts is a Borland BRC
634 * extension. MS generates an error. However, it is
635 * most logical to support this, considering how wine
636 * enters things in CVS (ascii).
638 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
642 * The fontdir is a Borland BRC extension which only
643 * reads the data as 'raw_data' from the file.
644 * I don't know whether it is interpreted.
645 * The fontdir is generated if it was not present and
646 * fonts are defined in the source.
648 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
651 /* ------------------------------ MessageTable ------------------------------ */
652 /* It might be interesting to implement the MS Message compiler here as well
653 * to get everything in one source. Might be a future project.
656 : tMESSAGETABLE loadmemopts file_raw {
658 yywarning("MESSAGETABLE not supported in 16-bit mode");
659 $$ = new_messagetable($3, $2);
663 /* ------------------------------ RCData ------------------------------ */
664 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
667 /* ------------------------------ DLGINIT ------------------------------ */
668 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
671 /* ------------------------------ UserType ------------------------------ */
672 userres : usertype loadmemopts file_raw {
673 #ifdef WORDS_BIGENDIAN
674 if(pedantic && byteorder != WRC_BO_LITTLE)
676 if(pedantic && byteorder == WRC_BO_BIG)
678 yywarning("Byteordering is not little-endian and type cannot be interpreted");
679 $$ = new_user($1, $3, $2);
686 $$->name.i_name = $1;
691 $$->name.s_name = $1;
695 /* ------------------------------ Accelerator ------------------------------ */
697 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
698 $$ = new_accelerator();
706 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
709 yyerror("Accelerator table must have at least one entry");
710 $$->events = get_event_head($5);
716 if(!$$->lvc.language)
717 $$->lvc.language = dup_language(currentlanguage);
721 events : /* Empty */ { $$=NULL; }
722 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
723 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
727 * The empty rule generates a s/r conflict because of {bi,u}nary expr
728 * on - and +. It cannot be solved in any way because it is the same as
729 * the if/then/else problem (LALR(1) problem). The conflict is moved
730 * away by forcing it to be in the expression handling below.
732 acc_opt : /* Empty */ { $$ = 0; }
733 | ',' accs { $$ = $2; }
736 accs : acc { $$ = $1; }
737 | accs ',' acc { $$ = $1 | $3; }
740 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
741 | tSHIFT { $$ = WRC_AF_SHIFT; }
742 | tCONTROL { $$ = WRC_AF_CONTROL; }
743 | tALT { $$ = WRC_AF_ALT; }
744 | tASCII { $$ = WRC_AF_ASCII; }
745 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
748 /* ------------------------------ Dialog ------------------------------ */
749 /* FIXME: Support EXSTYLE in the dialog line itself */
750 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
758 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
763 $10->controls = get_control_head($12);
767 $$->style->or_mask = WS_POPUP;
771 $$->style->or_mask |= WS_CAPTION;
773 $$->style->or_mask |= DS_SETFONT;
775 $$->style->or_mask &= ~($$->style->and_mask);
776 $$->style->and_mask = 0;
778 if(!$$->lvc.language)
779 $$->lvc.language = dup_language(currentlanguage);
784 : /* Empty */ { $$=new_dialog(); }
785 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
786 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
787 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
788 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
789 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
790 | dlg_attributes tCPPCLASS nameid_s { $$=dialog_class($3,$1); }
791 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
792 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
793 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
794 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
797 ctrls : /* Empty */ { $$ = NULL; }
798 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
799 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
800 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
801 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
802 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
803 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
804 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
805 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
806 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
807 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
808 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
809 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
810 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
811 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
812 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
813 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
814 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
815 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
816 /* special treatment for icons, as the extent is optional */
817 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
822 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
827 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style {
829 $$->title = new_name_id();
830 $$->title->type = name_str;
831 $$->title->name.s_name = $1;
846 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
861 iconinfo: /* Empty */
862 { $$ = new_control(); }
864 | ',' expr ',' expr {
869 | ',' expr ',' expr ',' style {
876 | ',' expr ',' expr ',' style ',' style {
883 $$->gotexstyle = TRUE;
887 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
891 $$->ctlclass = convert_ctlclass($5);
899 $$->gotexstyle = TRUE;
901 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
905 $$->ctlclass = convert_ctlclass($5);
916 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
919 /* ------------------------------ style flags ------------------------------ */
920 optional_style /* Abbused once to get optional ExStyle */
921 : /* Empty */ { $$ = NULL; }
922 | ',' style { $$ = $2; }
926 : /* Empty */ { $$ = NULL; }
927 | ',' style { $$ = new_style_pair($2, 0); }
928 | ',' style ',' style { $$ = new_style_pair($2, $4); }
932 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
933 | '(' style ')' { $$ = $2; }
934 | any_num { $$ = new_style($1, 0); }
935 | tNOT any_num { $$ = new_style(0, $2); }
942 $$->name.i_name = $1;
947 $$->name.s_name = $1;
951 /* ------------------------------ DialogEx ------------------------------ */
952 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
953 tBEGIN exctrls tEND {
955 yywarning("DIALOGEX not supported in 16-bit mode");
962 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
969 $11->helpid = *($10);
970 $11->gothelpid = TRUE;
973 $11->controls = get_control_head($13);
976 assert($$->style != NULL);
979 $$->style->or_mask = WS_POPUP;
983 $$->style->or_mask |= WS_CAPTION;
985 $$->style->or_mask |= DS_SETFONT;
987 $$->style->or_mask &= ~($$->style->and_mask);
988 $$->style->and_mask = 0;
990 if(!$$->lvc.language)
991 $$->lvc.language = dup_language(currentlanguage);
996 : /* Empty */ { $$=new_dialogex(); }
997 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
998 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
999 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1000 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1001 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1002 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1003 | dlgex_attribs tCPPCLASS nameid_s { $$=dialogex_class($3,$1); }
1004 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1005 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1006 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1007 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1010 exctrls : /* Empty */ { $$ = NULL; }
1011 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1012 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1013 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1014 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1015 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1016 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1017 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1018 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1019 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1020 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1021 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1022 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1023 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1024 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1025 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1026 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1027 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1028 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1029 /* special treatment for icons, as the extent is optional */
1030 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1035 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1040 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1041 expr ',' style helpid opt_data {
1045 $$->ctlclass = convert_ctlclass($5);
1047 $$->gotstyle = TRUE;
1055 $$->gotexstyle = TRUE;
1059 $$->helpid = *($18);
1060 $$->gothelpid = TRUE;
1065 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1070 $$->gotstyle = TRUE;
1071 $$->ctlclass = convert_ctlclass($5);
1081 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1083 $$->title = new_name_id();
1084 $$->title->type = name_str;
1085 $$->title->name.s_name = $1;
1093 $$->style = $12->style;
1094 $$->gotstyle = TRUE;
1098 $$->exstyle = $12->exstyle;
1099 $$->gotexstyle = TRUE;
1109 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1118 $$->style = $10->style;
1119 $$->gotstyle = TRUE;
1123 $$->exstyle = $10->exstyle;
1124 $$->gotexstyle = TRUE;
1132 opt_data: /* Empty */ { $$ = NULL; }
1133 | raw_data { $$ = $1; }
1136 helpid : /* Empty */ { $$ = NULL; }
1137 | ',' expr { $$ = new_int($2); }
1141 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1145 * FIXME: This odd expression is here to nullify an extra token found
1146 * in some appstudio produced resources which appear to do nothing.
1148 opt_expr: /* Empty */ { $$ = NULL; }
1149 | ',' expr { $$ = NULL; }
1152 /* ------------------------------ Menu ------------------------------ */
1153 menu : tMENU loadmemopts opt_lvc menu_body {
1155 yyerror("Menu must contain items");
1163 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1164 $$->items = get_item_head($4);
1170 if(!$$->lvc.language)
1171 $$->lvc.language = dup_language(currentlanguage);
1176 : tBEGIN item_definitions tEND { $$ = $2; }
1180 : /* Empty */ {$$ = NULL;}
1181 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1190 | item_definitions tMENUITEM tSEPARATOR {
1196 | item_definitions tPOPUP tSTRING item_options menu_body {
1197 $$ = new_menu_item();
1201 $$->popup = get_item_head($5);
1206 /* NOTE: item_options is right recursive because it would introduce
1207 * a shift/reduce conflict on ',' in itemex_options due to the
1208 * empty rule here. The parser is now forced to look beyond the ','
1209 * before reducing (force shift).
1210 * Right recursion here is not a problem because we cannot expect
1211 * more than 7 parserstack places to be occupied while parsing this
1212 * (who would want to specify a MF_x flag twice?).
1215 : /* Empty */ { $$ = 0; }
1216 | ',' tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1217 | ',' tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1218 | ',' tHELP item_options { $$ = $3 | MF_HELP; }
1219 | ',' tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1220 | ',' tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1221 | ',' tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1224 /* ------------------------------ MenuEx ------------------------------ */
1225 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1227 yywarning("MENUEX not supported in 16-bit mode");
1229 yyerror("MenuEx must contain items");
1237 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1238 $$->items = get_itemex_head($4);
1244 if(!$$->lvc.language)
1245 $$->lvc.language = dup_language(currentlanguage);
1250 : tBEGIN itemex_definitions tEND { $$ = $2; }
1254 : /* Empty */ {$$ = NULL; }
1255 | itemex_definitions tMENUITEM tSTRING itemex_options {
1256 $$ = new_menuex_item();
1262 $$->type = $4->type;
1263 $$->state = $4->state;
1264 $$->helpid = $4->helpid;
1265 $$->gotid = $4->gotid;
1266 $$->gottype = $4->gottype;
1267 $$->gotstate = $4->gotstate;
1268 $$->gothelpid = $4->gothelpid;
1271 | itemex_definitions tMENUITEM tSEPARATOR {
1272 $$ = new_menuex_item();
1277 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1278 $$ = new_menuex_item();
1282 $$->popup = get_itemex_head($5);
1285 $$->type = $4->type;
1286 $$->state = $4->state;
1287 $$->helpid = $4->helpid;
1288 $$->gotid = $4->gotid;
1289 $$->gottype = $4->gottype;
1290 $$->gotstate = $4->gotstate;
1291 $$->gothelpid = $4->gothelpid;
1297 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1299 $$ = new_itemex_opt($2, 0, 0, 0);
1302 | ',' e_expr ',' e_expr item_options {
1303 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1306 $$->gotstate = TRUE;
1310 | ',' e_expr ',' e_expr ',' expr {
1311 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1314 $$->gotstate = TRUE;
1321 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1323 $$ = new_itemex_opt($2, 0, 0, 0);
1326 | ',' e_expr ',' expr {
1327 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1332 | ',' e_expr ',' e_expr ',' expr {
1333 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1338 $$->gotstate = TRUE;
1340 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1341 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1347 $$->gotstate = TRUE;
1348 $$->gothelpid = TRUE;
1352 /* ------------------------------ StringTable ------------------------------ */
1353 /* Stringtables are parsed differently than other resources because their
1354 * layout is substantially different from other resources.
1355 * The table is parsed through a _global_ variable 'tagstt' which holds the
1356 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1357 * list of stringtables of different languages.
1360 : stt_head tBEGIN strings tEND {
1363 yyerror("Stringtable must have at least one entry");
1368 /* Check if we added to a language table or created
1371 for(stt = sttres; stt; stt = stt->next)
1378 /* It is a new one */
1381 sttres->prev = tagstt;
1382 tagstt->next = sttres;
1388 /* Else were done */
1392 free(tagstt_memopt);
1393 tagstt_memopt = NULL;
1400 /* This is to get the language of the currently parsed stringtable */
1401 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1402 if((tagstt = find_stringtable($3)) == NULL)
1403 tagstt = new_stringtable($3);
1405 tagstt_version = $3->version;
1406 tagstt_characts = $3->characts;
1412 strings : /* Empty */ { $$ = NULL; }
1413 | strings expr opt_comma tSTRING {
1415 assert(tagstt != NULL);
1416 if($2 > 65535 || $2 < -32768)
1417 yyerror("Stringtable entry's ID out of range (%d)", $2);
1418 /* Search for the ID */
1419 for(i = 0; i < tagstt->nentries; i++)
1421 if(tagstt->entries[i].id == $2)
1422 yyerror("Stringtable ID %d already in use", $2);
1424 /* If we get here, then we have a new unique entry */
1426 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1427 tagstt->entries[tagstt->nentries-1].id = $2;
1428 tagstt->entries[tagstt->nentries-1].str = $4;
1430 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1432 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1433 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1434 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1436 if(pedantic && !$4->size)
1437 yywarning("Zero length strings make no sense");
1438 if(!win32 && $4->size > 254)
1439 yyerror("Stringtable entry more than 254 characters");
1440 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1441 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1446 opt_comma /* There seem to be two ways to specify a stringtable... */
1451 /* ------------------------------ VersionInfo ------------------------------ */
1453 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1461 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1462 $$->blocks = get_ver_block_head($5);
1463 /* Set language; there is no version or characteristics */
1464 $$->lvc.language = dup_language(currentlanguage);
1469 : /* Empty */ { $$ = new_versioninfo(); }
1470 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1472 yyerror("FILEVERSION already defined");
1474 $$->filever_maj1 = $3;
1475 $$->filever_maj2 = $5;
1476 $$->filever_min1 = $7;
1477 $$->filever_min2 = $9;
1480 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1482 yyerror("PRODUCTVERSION already defined");
1484 $$->prodver_maj1 = $3;
1485 $$->prodver_maj2 = $5;
1486 $$->prodver_min1 = $7;
1487 $$->prodver_min2 = $9;
1490 | fix_version tFILEFLAGS expr {
1492 yyerror("FILEFLAGS already defined");
1497 | fix_version tFILEFLAGSMASK expr {
1499 yyerror("FILEFLAGSMASK already defined");
1501 $$->fileflagsmask = $3;
1504 | fix_version tFILEOS expr {
1506 yyerror("FILEOS already defined");
1511 | fix_version tFILETYPE expr {
1513 yyerror("FILETYPE already defined");
1518 | fix_version tFILESUBTYPE expr {
1520 yyerror("FILESUBTYPE already defined");
1522 $$->filesubtype = $3;
1528 : /* Empty */ { $$ = NULL; }
1529 | ver_blocks ver_block {
1538 : tBLOCK tSTRING tBEGIN ver_values tEND {
1539 $$ = new_ver_block();
1541 $$->values = get_ver_value_head($4);
1546 : /* Empty */ { $$ = NULL; }
1547 | ver_values ver_value {
1557 $$ = new_ver_value();
1558 $$->type = val_block;
1559 $$->value.block = $1;
1561 | tVALUE tSTRING ',' tSTRING {
1562 $$ = new_ver_value();
1567 | tVALUE tSTRING ',' ver_words {
1568 $$ = new_ver_value();
1569 $$->type = val_words;
1571 $$->value.words = $4;
1576 : expr { $$ = new_ver_words($1); }
1577 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1580 /* ------------------------------ Toolbar ------------------------------ */
1581 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1583 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1584 $$ = new_toolbar($3, $5, items, nitems);
1592 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1599 if(!$$->lvc.language)
1601 $$->lvc.language = dup_language(currentlanguage);
1607 : /* Empty */ { $$ = NULL; }
1608 | toolbar_items tBUTTON expr {
1609 toolbar_item_t *idrec = new_toolbar_item();
1611 $$ = ins_tlbr_button($1, idrec);
1613 | toolbar_items tSEPARATOR {
1614 toolbar_item_t *idrec = new_toolbar_item();
1616 $$ = ins_tlbr_button($1, idrec);
1620 /* ------------------------------ Memory options ------------------------------ */
1622 : /* Empty */ { $$ = NULL; }
1623 | loadmemopts lamo {
1633 | loadmemopts lama {
1642 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1648 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1649 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1650 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1651 | tPURE { $$ = new_int(WRC_MO_PURE); }
1654 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1655 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1656 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1659 /* ------------------------------ Win32 options ------------------------------ */
1660 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1661 | opt_lvc opt_language {
1663 yywarning("LANGUAGE not supported in 16-bit mode");
1665 yyerror("Language already defined");
1669 | opt_lvc opt_characts {
1671 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1673 yyerror("Characteristics already defined");
1677 | opt_lvc opt_version {
1679 yywarning("VERSION not supported in 16-bit mode");
1681 yyerror("Version already defined");
1688 * This here is another s/r conflict on {bi,u}nary + and -.
1689 * It is due to the look-ahead which must determine when the
1690 * rule opt_language ends. It could be solved with adding a
1691 * tNL at the end, but that seems unreasonable to do.
1692 * The conflict is now moved to the expression handling below.
1695 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4); }
1699 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1703 : tVERSION expr { $$ = new_version($2); }
1706 /* ------------------------------ Raw data handling ------------------------------ */
1707 raw_data: opt_lvc tBEGIN raw_elements tEND {
1714 if(!$3->lvc.language)
1715 $3->lvc.language = dup_language(currentlanguage);
1722 : tRAWDATA { $$ = $1; }
1723 | tNUMBER { $$ = int2raw_data($1); }
1724 | tLNUMBER { $$ = long2raw_data($1); }
1725 | tSTRING { $$ = str2raw_data($1); }
1726 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1727 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1728 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1729 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1732 /* File data or raw data */
1733 file_raw: filename {
1735 $$->lvc.language = dup_language(currentlanguage);
1737 | raw_data { $$ = $1; }
1740 /* ------------------------------ Win32 expressions ------------------------------ */
1741 /* All win16 numbers are also handled here. This is inconsistent with MS'
1742 * resource compiler, but what the heck, its just handy to have.
1744 e_expr : /* Empty */ { $$ = 0; }
1745 | expr { $$ = new_int($1); }
1748 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1749 expr : xpr { $$ = ($1); }
1752 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1753 | xpr '-' xpr { $$ = ($1) - ($3); }
1754 | xpr '|' xpr { $$ = ($1) | ($3); }
1755 | xpr '&' xpr { $$ = ($1) & ($3); }
1756 | xpr '*' xpr { $$ = ($1) * ($3); }
1757 | xpr '/' xpr { $$ = ($1) / ($3); }
1758 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1759 | '~' xpr { $$ = ~($2); }
1760 | '-' xpr %prec pUPM { $$ = -($2); }
1761 | '+' xpr %prec pUPM { $$ = $2; }
1762 | '(' xpr ')' { $$ = $2; }
1763 | any_num { $$ = $1; }
1764 | tNOT any_num { $$ = ~($2); }
1767 any_num : tNUMBER { $$ = $1; }
1768 | tLNUMBER { $$ = $1; }
1772 /* Dialog specific functions */
1773 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1775 assert(dlg != NULL);
1776 if(dlg->style == NULL)
1778 dlg->style = new_style(0,0);
1783 yywarning("Style already defined, or-ing together");
1787 dlg->style->or_mask = 0;
1788 dlg->style->and_mask = 0;
1790 dlg->style->or_mask |= st->or_mask;
1791 dlg->style->and_mask |= st->and_mask;
1792 dlg->gotstyle = TRUE;
1797 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1799 assert(dlg != NULL);
1800 if(dlg->exstyle == NULL)
1802 dlg->exstyle = new_style(0,0);
1807 yywarning("ExStyle already defined, or-ing together");
1811 dlg->exstyle->or_mask = 0;
1812 dlg->exstyle->and_mask = 0;
1814 dlg->exstyle->or_mask |= st->or_mask;
1815 dlg->exstyle->and_mask |= st->and_mask;
1816 dlg->gotexstyle = TRUE;
1821 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1823 assert(dlg != NULL);
1825 yyerror("Caption already defined");
1830 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1832 assert(dlg != NULL);
1834 yyerror("Font already defined");
1839 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1841 assert(dlg != NULL);
1843 yyerror("Class already defined");
1848 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1850 assert(dlg != NULL);
1852 yyerror("Menu already defined");
1857 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1859 assert(dlg != NULL);
1860 if(dlg->lvc.language)
1861 yyerror("Language already defined");
1862 dlg->lvc.language = l;
1866 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1868 assert(dlg != NULL);
1869 if(dlg->lvc.characts)
1870 yyerror("Characteristics already defined");
1871 dlg->lvc.characts = c;
1875 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1877 assert(dlg != NULL);
1878 if(dlg->lvc.version)
1879 yyerror("Version already defined");
1880 dlg->lvc.version = v;
1884 /* Controls specific functions */
1885 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1887 /* Hm... this seems to be jammed in at all time... */
1888 int defaultstyle = WS_CHILD | WS_VISIBLE;
1890 assert(ctrl != NULL);
1898 ctrl->ctlclass = new_name_id();
1899 ctrl->ctlclass->type = name_ord;
1900 ctrl->ctlclass->name.i_name = type;
1906 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1907 defaultstyle |= WS_TABSTOP;
1910 defaultstyle |= WS_TABSTOP | WS_BORDER;
1913 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1916 defaultstyle |= CBS_SIMPLE;
1919 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1920 defaultstyle |= WS_GROUP;
1924 if(!ctrl->gotstyle) /* Handle default style setting */
1929 defaultstyle |= ES_LEFT;
1932 defaultstyle |= LBS_NOTIFY;
1935 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1938 defaultstyle |= SBS_HORZ;
1941 switch(special_style)
1944 case BS_DEFPUSHBUTTON:
1947 /* case BS_PUSHBOX: */
1948 case BS_AUTORADIOBUTTON:
1951 case BS_AUTOCHECKBOX:
1952 defaultstyle |= WS_TABSTOP;
1955 yywarning("Unknown default button control-style 0x%08x", special_style);
1956 case BS_RADIOBUTTON:
1962 switch(special_style)
1967 defaultstyle |= WS_GROUP;
1969 case SS_ICON: /* Special case */
1972 yywarning("Unknown default static control-style 0x%08x", special_style);
1976 case -1: /* Generic control */
1980 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
1984 /* The SS_ICON flag is always forced in for icon controls */
1985 if(type == CT_STATIC && special_style == SS_ICON)
1986 defaultstyle |= SS_ICON;
1988 if (!ctrl->gotstyle)
1989 ctrl->style = new_style(0,0);
1991 /* combine all styles */
1992 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
1993 ctrl->gotstyle = TRUE;
1995 /* combine with NOT mask */
1998 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
1999 ctrl->style->and_mask = 0;
2001 if (ctrl->gotexstyle)
2003 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2004 ctrl->exstyle->and_mask = 0;
2009 static name_id_t *convert_ctlclass(name_id_t *cls)
2014 if(cls->type == name_ord)
2016 assert(cls->type == name_str);
2017 if(cls->type == str_unicode)
2019 yyerror("Don't yet support unicode class comparison");
2022 cc = cls->name.s_name->str.cstr;
2024 if(!strcasecmp("BUTTON", cc))
2026 else if(!strcasecmp("COMBOBOX", cc))
2027 iclass = CT_COMBOBOX;
2028 else if(!strcasecmp("LISTBOX", cc))
2029 iclass = CT_LISTBOX;
2030 else if(!strcasecmp("EDIT", cc))
2032 else if(!strcasecmp("STATIC", cc))
2034 else if(!strcasecmp("SCROLLBAR", cc))
2035 iclass = CT_SCROLLBAR;
2037 return cls; /* No default, return user controlclass */
2039 free(cls->name.s_name->str.cstr);
2040 free(cls->name.s_name);
2041 cls->type = name_ord;
2042 cls->name.i_name = iclass;
2046 /* DialogEx specific functions */
2047 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2049 assert(dlg != NULL);
2050 if(dlg->style == NULL)
2052 dlg->style = new_style(0,0);
2057 yywarning("Style already defined, or-ing together");
2061 dlg->style->or_mask = 0;
2062 dlg->style->and_mask = 0;
2064 dlg->style->or_mask |= st->or_mask;
2065 dlg->style->and_mask |= st->and_mask;
2066 dlg->gotstyle = TRUE;
2071 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2073 assert(dlg != NULL);
2074 if(dlg->exstyle == NULL)
2076 dlg->exstyle = new_style(0,0);
2081 yywarning("ExStyle already defined, or-ing together");
2085 dlg->exstyle->or_mask = 0;
2086 dlg->exstyle->and_mask = 0;
2088 dlg->exstyle->or_mask |= st->or_mask;
2089 dlg->exstyle->and_mask |= st->and_mask;
2090 dlg->gotexstyle = TRUE;
2095 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2097 assert(dlg != NULL);
2099 yyerror("Caption already defined");
2104 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2106 assert(dlg != NULL);
2108 yyerror("Font already defined");
2113 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2115 assert(dlg != NULL);
2117 yyerror("Class already defined");
2122 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2124 assert(dlg != NULL);
2126 yyerror("Menu already defined");
2131 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2133 assert(dlg != NULL);
2134 if(dlg->lvc.language)
2135 yyerror("Language already defined");
2136 dlg->lvc.language = l;
2140 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2142 assert(dlg != NULL);
2143 if(dlg->lvc.characts)
2144 yyerror("Characteristics already defined");
2145 dlg->lvc.characts = c;
2149 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2151 assert(dlg != NULL);
2152 if(dlg->lvc.version)
2153 yyerror("Version already defined");
2154 dlg->lvc.version = v;
2158 /* Accelerator specific functions */
2159 static event_t *add_event(int key, int id, int flags, event_t *prev)
2161 event_t *ev = new_event();
2163 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2164 yyerror("Cannot use both ASCII and VIRTKEY");
2168 ev->flags = flags & ~WRC_AF_ASCII;
2175 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2178 event_t *ev = new_event();
2180 if(key->type != str_char)
2181 yyerror("Key code must be an ascii string");
2183 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
2184 yyerror("VIRTKEY code is not equal to ascii value");
2186 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2188 yyerror("Cannot use both '^' and CONTROL modifier");
2190 else if(key->str.cstr[0] == '^')
2192 keycode = toupper(key->str.cstr[1]) - '@';
2194 yyerror("Control-code out of range");
2197 keycode = key->str.cstr[0];
2200 ev->flags = flags & ~WRC_AF_ASCII;
2207 /* MenuEx specific functions */
2208 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2210 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2214 opt->helpid = helpid;
2218 /* Raw data functions */
2219 static raw_data_t *load_file(string_t *name)
2223 if(name->type != str_char)
2224 yyerror("Filename must be ASCII string");
2226 fp = open_include(name->str.cstr, 1, NULL);
2228 yyerror("Cannot open file %s", name->str.cstr);
2229 rd = new_raw_data();
2230 fseek(fp, 0, SEEK_END);
2231 rd->size = ftell(fp);
2232 fseek(fp, 0, SEEK_SET);
2233 rd->data = (char *)xmalloc(rd->size);
2234 fread(rd->data, rd->size, 1, fp);
2239 static raw_data_t *int2raw_data(int i)
2243 if((int)((short)i) != i)
2244 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2246 rd = new_raw_data();
2247 rd->size = sizeof(short);
2248 rd->data = (char *)xmalloc(rd->size);
2251 #ifndef WORDS_BIGENDIAN
2256 *(WORD *)(rd->data) = BYTESWAP_WORD((WORD)i);
2259 *(WORD *)(rd->data) = (WORD)i;
2265 static raw_data_t *long2raw_data(int i)
2268 rd = new_raw_data();
2269 rd->size = sizeof(int);
2270 rd->data = (char *)xmalloc(rd->size);
2273 #ifndef WORDS_BIGENDIAN
2278 *(DWORD *)(rd->data) = BYTESWAP_DWORD((DWORD)i);
2281 *(DWORD *)(rd->data) = (DWORD)i;
2287 static raw_data_t *str2raw_data(string_t *str)
2290 rd = new_raw_data();
2291 rd->size = str->size * (str->type == str_char ? 1 : 2);
2292 rd->data = (char *)xmalloc(rd->size);
2293 if(str->type == str_char)
2294 memcpy(rd->data, str->str.cstr, rd->size);
2295 else if(str->type == str_unicode)
2300 #ifndef WORDS_BIGENDIAN
2305 for(i = 0; i < str->size; i++)
2306 *(WORD *)&(rd->data[2*i]) = BYTESWAP_WORD((WORD)str->str.wstr[i]);
2309 for(i = 0; i < str->size; i++)
2310 *(WORD *)&(rd->data[2*i]) = (WORD)str->str.wstr[i];
2315 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2319 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2321 r1->data = xrealloc(r1->data, r1->size + r2->size);
2322 memcpy(r1->data + r1->size, r2->data, r2->size);
2323 r1->size += r2->size;
2327 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2329 raw_data_t *t = int2raw_data(i);
2330 merge_raw_data(r1, t);
2336 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2338 raw_data_t *t = long2raw_data(i);
2339 merge_raw_data(r1, t);
2345 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2347 raw_data_t *t = str2raw_data(str);
2348 merge_raw_data(r1, t);
2354 /* Function the go back in a list to get the head */
2355 static menu_item_t *get_item_head(menu_item_t *p)
2364 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2373 static resource_t *get_resource_head(resource_t *p)
2382 static ver_block_t *get_ver_block_head(ver_block_t *p)
2391 static ver_value_t *get_ver_value_head(ver_value_t *p)
2400 static control_t *get_control_head(control_t *p)
2409 static event_t *get_event_head(event_t *p)
2418 /* Find a stringtable with given language */
2419 static stringtable_t *find_stringtable(lvc_t *lvc)
2423 assert(lvc != NULL);
2426 lvc->language = dup_language(currentlanguage);
2428 for(stt = sttres; stt; stt = stt->next)
2430 if(stt->lvc.language->id == lvc->language->id
2431 && stt->lvc.language->sub == lvc->language->sub)
2433 /* Found a table with the same language */
2434 /* The version and characteristics are now handled
2435 * in the generation of the individual stringtables.
2436 * This enables localized analysis.
2437 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2438 || (!stt->lvc.version && lvc->version)
2439 || (stt->lvc.version && !lvc->version))
2440 yywarning("Stringtable's versions are not the same, using first definition");
2442 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2443 || (!stt->lvc.characts && lvc->characts)
2444 || (stt->lvc.characts && !lvc->characts))
2445 yywarning("Stringtable's characteristics are not the same, using first definition");
2453 /* qsort sorting function for string table entries */
2454 #define STE(p) ((stt_entry_t *)(p))
2455 static int sort_stt_entry(const void *e1, const void *e2)
2457 return STE(e1)->id - STE(e2)->id;
2461 static resource_t *build_stt_resources(stringtable_t *stthead)
2464 stringtable_t *newstt;
2466 resource_t *rsclist = NULL;
2467 resource_t *rsctail = NULL;
2472 characts_t *characts;
2478 /* For all languages defined */
2479 for(stt = stthead; stt; stt = stt->next)
2481 assert(stt->nentries > 0);
2483 /* Sort the entries */
2484 if(stt->nentries > 1)
2485 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2487 for(i = 0; i < stt->nentries; )
2489 newstt = new_stringtable(&stt->lvc);
2490 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2491 newstt->nentries = 16;
2492 newstt->idbase = stt->entries[i].id & ~0xf;
2493 for(j = 0; j < 16 && i < stt->nentries; j++)
2495 if(stt->entries[i].id - newstt->idbase == j)
2497 newstt->entries[j] = stt->entries[i];
2505 /* Check individual memory options and get
2506 * the first characteristics/version
2508 for(j = 0; j < 16; j++)
2510 if(!newstt->entries[j].str)
2512 andsum &= newstt->entries[j].memopt;
2513 orsum |= newstt->entries[j].memopt;
2515 characts = newstt->entries[j].characts;
2517 version = newstt->entries[j].version;
2521 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2523 /* Check version and characteristics */
2524 for(j = 0; j < 16; j++)
2527 && newstt->entries[j].characts
2528 && *newstt->entries[j].characts != *characts)
2529 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2531 && newstt->entries[j].version
2532 && *newstt->entries[j].version != *version)
2533 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2535 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2536 rsc->name = new_name_id();
2537 rsc->name->type = name_ord;
2538 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2539 rsc->memopt = andsum; /* Set to least common denominator */
2540 newstt->memopt = andsum;
2541 newstt->lvc.characts = characts;
2542 newstt->lvc.version = version;
2550 rsctail->next = rsc;
2551 rsc->prev = rsctail;
2560 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2569 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2588 static string_t *make_filename(string_t *str)
2592 if(str->type != str_char)
2593 yyerror("Cannot handle UNICODE filenames");
2595 /* Remove escaped backslash and convert to forward */
2596 cptr = str->str.cstr;
2597 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2601 memmove(cptr, cptr+1, strlen(cptr));
2607 /* Convert to lower case. Seems to be reasonable to do */
2608 for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
2610 *cptr = tolower(*cptr);
2616 * Process all resources to extract fonts and build
2617 * a fontdir resource.
2619 * Note: MS' resource compiler (build 1472) does not
2620 * handle font resources with different languages.
2621 * The fontdir is generated in the last active language
2622 * and font identifiers must be unique across the entire
2624 * This is not logical considering the localization
2625 * constraints of all other resource types. MS has,
2626 * most probably, never testet localized fonts. However,
2627 * using fontresources is rare, so it might not occur
2628 * in normal applications.
2629 * Wine does require better localization because a lot
2630 * of languages are coded into the same executable.
2631 * Therefore, I will generate fontdirs for *each*
2632 * localized set of fonts.
2634 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2636 static int once = 0;
2639 warning("Need to parse fonts, not yet implemented");
2645 static resource_t *build_fontdirs(resource_t *tail)
2648 resource_t *lst = NULL;
2649 resource_t **fnt = NULL; /* List of all fonts */
2651 resource_t **fnd = NULL; /* List of all fontdirs */
2653 resource_t **lanfnt = NULL;
2660 nid.type = name_str;
2661 nid.name.s_name = &str;
2662 str.type = str_char;
2663 str.str.cstr = "FONTDIR";
2666 /* Extract all fonts and fontdirs */
2667 for(rsc = tail; rsc; rsc = rsc->prev)
2669 if(rsc->type == res_fnt)
2672 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2675 else if(rsc->type == res_fntdir)
2678 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2683 /* Verify the name of the present fontdirs */
2684 for(i = 0; i < nfnd; i++)
2686 if(compare_name_id(&nid, fnd[i]->name))
2688 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2689 get_nameid_str(fnd[i]->name));
2698 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2703 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2705 /* Get all fonts covered by fontdirs */
2706 for(i = 0; i < nfnd; i++)
2714 for(j = 0; j < nfnt; j++)
2718 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2720 lanfnt[nlanfnt] = fnt[j];
2726 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2729 else if(nlanfnt == BYTESWAP_WORD(cnt))
2732 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2733 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2734 #ifdef WORDS_BIGENDIAN
2735 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2737 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2740 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2744 /* We now have fonts left where we need to make a fontdir resource */
2745 for(i = fntleft = 0; i < nfnt; i++)
2752 /* Get fonts of same language in lanfnt[] */
2753 for(i = nlanfnt = 0; i < nfnt; i++)
2760 lanfnt[nlanfnt] = fnt[i];
2765 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2769 /* and build a fontdir */
2770 rsc = build_fontdir(lanfnt, nlanfnt);
2792 * This gets invoked to determine whether the next resource
2793 * is to be of a standard-type (e.g. bitmaps etc.), or should
2794 * be a user-type resource. This function is required because
2795 * there is the _possibility_ of a lookahead token in the
2796 * parser, which is generated from the "expr" state in the
2799 * The general resource format is:
2800 * <identifier> <type> <flags> <resourcebody>
2802 * The <identifier> can either be tIDENT or "expr". The latter
2803 * will always generate a lookahead, which is the <type> of the
2804 * resource to parse. Otherwise, we need to get a new token from
2805 * the scanner to determine the next step.
2807 * The problem arrises when <type> is numerical. This case should
2808 * map onto default resource-types and be parsed as such instead
2809 * of being mapped onto user-type resources.
2811 * The trick lies in the fact that yacc (bison) doesn't care about
2812 * intermediate changes of the lookahead while reducing a rule. We
2813 * simply replace the lookahead with a token that will result in
2814 * a shift to the appropriate rule for the specific resource-type.
2816 static int rsrcid_to_token(int lookahead)
2821 /* Get a token if we don't have one yet */
2822 if(lookahead == YYEMPTY)
2825 /* Only numbers are possibly interesting */
2855 case WRC_RT_FONTDIR:
2863 case WRC_RT_MESSAGETABLE:
2864 type = "MESSAGETABLE";
2865 token = tMESSAGETABLE;
2867 case WRC_RT_DLGINIT:
2871 case WRC_RT_ACCELERATOR:
2872 type = "ACCELERATOR";
2873 token = tACCELERATORS;
2883 case WRC_RT_VERSION:
2885 token = tVERSIONINFO;
2887 case WRC_RT_TOOLBAR:
2893 type = "STRINGTABLE";
2896 case WRC_RT_ANICURSOR:
2897 case WRC_RT_ANIICON:
2898 case WRC_RT_GROUP_CURSOR:
2899 case WRC_RT_GROUP_ICON:
2900 yywarning("Usertype uses reserved type-ID %d, which is auto-generated", yylval.num);
2903 case WRC_RT_DLGINCLUDE:
2904 case WRC_RT_PLUGPLAY:
2907 yywarning("Usertype uses reserved type-ID %d, which is not supported by wrc", yylval.num);
2915 yywarning("Usertype uses reserved type-ID %d, which is used by %s", yylval.num, type);