3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * 24-Jul-2000 BS - Made a fix for broken Berkeley yacc on
8 * non-terminals (see cjunk rule).
9 * 21-May-2000 BS - Partial implementation of font resources.
10 * - Corrected language propagation for binary
11 * resources such as bitmaps, isons, cursors,
12 * userres and rcdata. The language is now
13 * correct in .res files.
14 * - Fixed reading the resource name as ident,
15 * so that it may overlap keywords.
16 * 20-May-2000 BS - Implemented animated cursors and icons
18 * 30-Apr-2000 BS - Reintegration into the wine-tree
19 * 14-Jan-2000 BS - Redid the usertype resources so that they
21 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
22 * expect for the # command (line numbers).
24 * 06-Nov-1999 JS - see CHANGES
26 * 29-Dec-1998 AdH - Grammar and function extensions.
27 * grammar: TOOLBAR resources, Named ICONs in
29 * functions: semantic actions for the grammar
30 * changes, resource files can now be anywhere
31 * on the include path instead of just in the
34 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
35 * printed out correctly.
37 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
38 * also accept a tSTRING as argument.
40 * 25-May-1998 BS - Found out that I need to support language, version
41 * and characteristics in inline resources (bitmap,
42 * cursor, etc) but they can also be specified with
43 * a filename. This renders my filename-scanning scheme
44 * worthless. Need to build newline parsing to solve
46 * It will come with version 1.1.0 (sigh).
48 * 19-May-1998 BS - Started to build a builtin preprocessor
50 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
51 * ideas had some serious flaws.
53 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
56 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
57 * - This file is growing too big. It is time to strip
58 * things and put it in a support file.
60 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
61 * resource will be created. This because the table
62 * has a different layout than other resources. The
63 * table has to be sorted, and divided into smaller
64 * resource entries (see comment in source).
66 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
67 * as string_t which include unicode strings upon
69 * - Parser now emits a warning when compiling win32
70 * extensions in win16 mode.
72 * 16-Apr-1998 BS - Raw data elements are now *optionally* seperated
73 * by commas. Read the comments in file sq2dq.l.
74 * - FIXME: there are instances in the source that rely
75 * on the fact that int==32bit and pointers are int size.
76 * - Fixed the conflict in menuex by changing a rule
77 * back into right recursion. See note in source.
78 * - UserType resources cannot have an expression as its
79 * typeclass. See note in source.
81 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
82 * get reduction of the parsestack.
83 * This also helps communication between bison and flex.
84 * Main advantage is that the Empty rule gets reduced
85 * first, which is used to allocate/link things.
86 * It also added a shift/reduce conflict in the menuex
87 * handling, due to expression/option possibility,
88 * although not serious.
90 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
91 * about making it more efficient, but readable (for me)
92 * and slightly easier to expand/change.
93 * This is done primarily by using more reduce states
94 * with many (intuitive) types for the various resource
96 * - Added expression handling for all resources where a
97 * number is accepted (not only for win32). Also added
98 * multiply and division (not MS compatible, but handy).
99 * Unary minus introduced a shift/reduce conflict, but
102 * 13-Apr-1998 BS - Reordered a lot of things
103 * - Made the source more readable
104 * - Added Win32 resource definitions
105 * - Corrected syntax problems with an old yacc (;)
106 * - Added extra comment about grammar
122 #include "newstruc.h"
131 /* Berkeley yacc (byacc) doesn't seem to know about these */
132 /* Some *BSD supplied versions do define these though */
134 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
137 # define YYLEX yylex()
140 #elif defined(YYBISON)
141 /* Bison was used for original development */
142 /* #define YYEMPTY -2 */
143 /* #define YYLEX yylex() */
146 /* No yacc we know yet */
147 # if !defined(YYEMPTY) || !defined(YYLEX)
148 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
149 # elif defined(__GNUC__) /* gcc defines the #warning directive */
150 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
151 /* #else we just take a chance that it works... */
155 int want_nl = 0; /* Signal flex that we need the next newline */
156 int want_id = 0; /* Signal flex that we need the next identifier */
157 stringtable_t *tagstt; /* Stringtable tag.
158 * It is set while parsing a stringtable to one of
159 * the stringtables in the sttres list or a new one
160 * if the language was not parsed before.
162 stringtable_t *sttres; /* Stringtable resources. This holds the list of
163 * stringtables with different lanuages
165 static int dont_want_id = 0; /* See language parsing for details */
167 /* Set to the current options of the currently scanning stringtable */
168 static int *tagstt_memopt;
169 static characts_t *tagstt_characts;
170 static version_t *tagstt_version;
172 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
174 /* Prototypes of here defined functions */
175 static event_t *get_event_head(event_t *p);
176 static control_t *get_control_head(control_t *p);
177 static ver_value_t *get_ver_value_head(ver_value_t *p);
178 static ver_block_t *get_ver_block_head(ver_block_t *p);
179 static resource_t *get_resource_head(resource_t *p);
180 static menuex_item_t *get_itemex_head(menuex_item_t *p);
181 static menu_item_t *get_item_head(menu_item_t *p);
182 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
183 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
184 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
185 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
186 static raw_data_t *str2raw_data(string_t *str);
187 static raw_data_t *int2raw_data(int i);
188 static raw_data_t *long2raw_data(int i);
189 static raw_data_t *load_file(string_t *name);
190 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
191 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
192 static event_t *add_event(int key, int id, int flags, event_t *prev);
193 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
194 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
195 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
196 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
197 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
198 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
199 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
200 static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
201 static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
202 static name_id_t *convert_ctlclass(name_id_t *cls);
203 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
204 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
205 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
206 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
207 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
208 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
209 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
210 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
211 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
212 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
213 static resource_t *build_stt_resources(stringtable_t *stthead);
214 static stringtable_t *find_stringtable(lvc_t *lvc);
215 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
216 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
217 static string_t *make_filename(string_t *s);
218 static resource_t *build_fontdirs(resource_t *tail);
219 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
220 static int rsrcid_to_token(int lookahead);
251 menuex_item_t *menexitm;
259 toolbar_item_t *tlbarItems;
261 style_pair_t *styles;
266 %token tTYPEDEF tEXTERN tSTRUCT tENUM tCPPCLASS tINLINE tSTATIC tNL
267 %token <num> tNUMBER tLNUMBER
268 %token <str> tSTRING tIDENT tFILENAME
269 %token <raw> tRAWDATA
270 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
271 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
272 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
273 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
274 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
275 %token tCONTROL tEDITTEXT
276 %token tRTEXT tCTEXT tLTEXT
278 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
279 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
280 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
281 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
282 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
284 %token tSTRING tIDENT tRAWDATA
285 %token tTOOLBAR tBUTTON
296 %type <res> resource_file resource resources resource_definition
297 %type <stt> stringtable strings
300 %type <acc> accelerators
303 %type <ani> cursor icon
304 %type <dlg> dialog dlg_attributes
305 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
307 %type <dlgex> dialogex dlgex_attribs
308 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
310 %type <raw> raw_data raw_elements opt_data file_raw
311 %type <veri> versioninfo fix_version
312 %type <verw> ver_words
313 %type <blk> ver_blocks ver_block
314 %type <val> ver_values ver_value
316 %type <menitm> item_definitions menu_body
318 %type <menexitm> itemex_definitions menuex_body
319 %type <exopt> itemex_p_options itemex_options
320 %type <msg> messagetable
322 %type <num> item_options
323 %type <nid> nameid nameid_s ctlclass usertype
324 %type <num> acc_opt acc accs
325 %type <iptr> loadmemopts lamo lama
326 %type <fntid> opt_font opt_exfont opt_expr
328 %type <lan> opt_language
329 %type <chars> opt_characts
330 %type <ver> opt_version
333 %type <tlbar> toolbar
334 %type <tlbarItems> toolbar_items
335 %type <dginit> dlginit
336 %type <styles> optional_style_pair
338 %type <style> optional_style
347 /* First add stringtables to the resource-list */
348 rsc = build_stt_resources(sttres);
349 /* 'build_stt_resources' returns a head and $1 is a tail */
358 /* Find the tail again */
359 while($1 && $1->next)
361 /* Now add any fontdirecory */
362 rsc = build_fontdirs($1);
363 /* 'build_fontdir' returns a head and $1 is a tail */
372 /* Final statement before were done */
373 resource_top = get_resource_head($1);
377 /* Resources are put into a linked list */
379 : /* Empty */ { $$ = NULL; want_id = 1; }
380 | resources resource {
383 resource_t *tail = $2;
384 resource_t *head = $2;
393 /* Check for duplicate identifiers */
396 resource_t *rsc = $1;
399 if(rsc->type == head->type
400 && rsc->lan->id == head->lan->id
401 && rsc->lan->sub == head->lan->sub
402 && !compare_name_id(rsc->name, head->name))
404 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
413 resource_t *tail = $1;
421 if(!dont_want_id) /* See comments in language parsing below */
425 | resources cjunk { $$ = $1; want_id = 1; }
430 cjunk : tTYPEDEF { strip_til_semicolon(); }
431 | tSTRUCT { strip_til_semicolon(); }
432 | tEXTERN { strip_til_semicolon(); }
433 | tENUM { strip_til_semicolon(); }
434 | tCPPCLASS { strip_til_semicolon(); }
435 | tSTATIC { strip_til_semicolon(); }
436 | tINLINE { internal_error(__FILE__, __LINE__, "Don't yet know how to strip inline functions\n"); }
437 /* | tIDENT tIDENT { strip_til_semicolon(); } */
438 | tIDENT tIDENT '(' { strip_til_parenthesis(); }
439 /* | tIDENT '(' { strip_til_parenthesis(); } */
440 | tIDENT '*' { strip_til_semicolon(); }
442 * This newline rule will never get reduced because we never
443 * get the tNL token, unless we explicitely set the 'want_nl'
444 * flag, which we don't.
445 * The *ONLY* reason for this to be here is because Berkeley
446 * yacc (byacc), at least version 1.9, has a bug.
447 * (identified in the generated parser on the second
449 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
451 * This extra rule fixes it.
452 * The problem is that the expression handling rule "expr: xpr"
453 * is not reduced on non-terminal tokens, defined above in the
454 * %token declarations. Token tNL is the only non-terminal that
455 * can occur. The error becomes visible in the language parsing
456 * rule below, which looks at the look-ahead token and tests it
457 * for tNL. However, byacc already generates an error upon reading
458 * the token instead of keeping it as a lookahead. The reason
459 * lies in the lack of a $default transition in the "expr : xpr . "
460 * state (currently state 25). It is probably ommitted because tNL
461 * is a non-terminal and the state contains 2 s/r conflicts. The
462 * state enumerates all possible transitions instead of using a
463 * $default transition.
464 * All in all, it is a bug in byacc. (period)
468 /* Parse top level resource definitions etc. */
470 : nameid usrcvt resource_definition {
475 if($1->type == name_ord)
477 chat("Got %s (%d)",get_typename($3),$1->name.i_name);
479 else if($1->type == name_str)
481 chat("Got %s (%s)",get_typename($3),$1->name.s_name->str.cstr);
486 /* Don't do anything, stringtables are converted to
487 * resource_t structures when we are finished parsing and
488 * the final rule of the parser is reduced (see above)
491 chat("Got STRINGTABLE");
493 | tLANGUAGE {want_nl = 1; } expr ',' expr {
494 /* We *NEED* the newline to delimit the expression.
495 * Otherwise, we would not be able to set the next
496 * want_id anymore because of the token-lookahead.
498 * However, we can test the lookahead-token for
499 * being "non-expression" type, in which case we
500 * continue. Fortunately, tNL is the only token that
501 * will break expression parsing and is implicitely
502 * void, so we just remove it. This scheme makes it
503 * possible to do some (not all) fancy preprocessor
505 * BTW, we also need to make sure that the next
506 * reduction of 'resources' above will *not* set
507 * want_id because we already have a lookahead that
510 if(yychar != YYEMPTY && yychar != tNL)
514 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
515 /* direct access to yychar in rule 'usrcvt' below. */
516 else if(yychar == tIDENT)
517 yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
519 want_nl = 0; /* We don't want it anymore if we didn't get it */
522 yywarning("LANGUAGE not supported in 16-bit mode");
524 free(currentlanguage);
525 currentlanguage = new_language($3, $5);
527 chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
532 * Remapping of numerical resource types
533 * (see also comment of called function below)
535 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
539 * Get a valid name/id
542 if($1 > 65535 || $1 < -32768)
543 yyerror("Resource's ID out of range (%d)", $1);
546 $$->name.i_name = $1;
551 $$->name.s_name = $1;
556 * Extra string recognition for CLASS statement in dialogs
558 nameid_s: nameid { $$ = $1; }
562 $$->name.s_name = $1;
566 /* get the value for a single resource*/
568 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
569 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
572 if($1->type == res_anicur)
574 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
576 else if($1->type == res_curg)
579 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
580 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
582 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
583 rsc->prev->next = rsc;
585 rsc->name = new_name_id();
586 rsc->name->type = name_ord;
587 rsc->name->name.i_name = cur->id;
591 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
594 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
597 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
601 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
602 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
603 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
606 if($1->type == res_aniico)
608 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
610 else if($1->type == res_icog)
613 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
614 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
616 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
617 rsc->prev->next = rsc;
619 rsc->name = new_name_id();
620 rsc->name->type = name_ord;
621 rsc->name->name.i_name = ico->id;
625 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
628 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
631 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
635 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
636 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
637 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
638 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
639 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
643 filename: tFILENAME { $$ = make_filename($1); }
644 | tIDENT { $$ = make_filename($1); }
645 | tSTRING { $$ = make_filename($1); }
648 /* ------------------------------ Bitmap ------------------------------ */
649 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
652 /* ------------------------------ Cursor ------------------------------ */
653 cursor : tCURSOR loadmemopts file_raw {
655 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
657 $$->type = res_anicur;
658 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
663 $$->u.curg = new_cursor_group($3, $2);
668 /* ------------------------------ Icon ------------------------------ */
669 icon : tICON loadmemopts file_raw {
671 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
673 $$->type = res_aniico;
674 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
679 $$->u.icog = new_icon_group($3, $2);
684 /* ------------------------------ Font ------------------------------ */
686 * The reading of raw_data for fonts is a Borland BRC
687 * extension. MS generates an error. However, it is
688 * most logical to support this, considering how wine
689 * enters things in CVS (ascii).
691 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
695 * The fontdir is a Borland BRC extension which only
696 * reads the data as 'raw_data' from the file.
697 * I don't know whether it is interpreted.
698 * The fontdir is generated if it was not present and
699 * fonts are defined in the source.
701 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
704 /* ------------------------------ MessageTable ------------------------------ */
705 /* It might be interesting to implement the MS Message compiler here as well
706 * to get everything in one source. Might be a future project.
709 : tMESSAGETABLE loadmemopts file_raw {
711 yywarning("MESSAGETABLE not supported in 16-bit mode");
712 $$ = new_messagetable($3, $2);
716 /* ------------------------------ RCData ------------------------------ */
717 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
720 /* ------------------------------ DLGINIT ------------------------------ */
721 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
724 /* ------------------------------ UserType ------------------------------ */
725 userres : usertype loadmemopts file_raw {
726 #ifdef WORDS_BIGENDIAN
727 if(pedantic && byteorder != WRC_BO_LITTLE)
729 if(pedantic && byteorder == WRC_BO_BIG)
731 yywarning("Byteordering is not little-endian and type cannot be interpreted");
732 $$ = new_user($1, $3, $2);
739 $$->name.i_name = $1;
744 $$->name.s_name = $1;
748 /* ------------------------------ Accelerator ------------------------------ */
750 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
751 $$ = new_accelerator();
759 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
762 yyerror("Accelerator table must have at least one entry");
763 $$->events = get_event_head($5);
769 if(!$$->lvc.language)
770 $$->lvc.language = dup_language(currentlanguage);
774 events : /* Empty */ { $$=NULL; }
775 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
776 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
780 * The empty rule generates a s/r conflict because of {bi,u}nary expr
781 * on - and +. It cannot be solved in any way because it is the same as
782 * the if/then/else problem (LALR(1) problem). The conflict is moved
783 * away by forcing it to be in the expression handling below.
785 acc_opt : /* Empty */ { $$ = 0; }
786 | ',' accs { $$ = $2; }
789 accs : acc { $$ = $1; }
790 | accs ',' acc { $$ = $1 | $3; }
793 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
794 | tSHIFT { $$ = WRC_AF_SHIFT; }
795 | tCONTROL { $$ = WRC_AF_CONTROL; }
796 | tALT { $$ = WRC_AF_ALT; }
797 | tASCII { $$ = WRC_AF_ASCII; }
798 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
801 /* ------------------------------ Dialog ------------------------------ */
802 /* FIXME: Support EXSTYLE in the dialog line itself */
803 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
811 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
816 $10->controls = get_control_head($12);
820 $$->style->or_mask = WS_POPUP;
824 $$->style->or_mask |= WS_CAPTION;
826 $$->style->or_mask |= DS_SETFONT;
828 $$->style->or_mask &= ~($$->style->and_mask);
829 $$->style->and_mask = 0;
831 if(!$$->lvc.language)
832 $$->lvc.language = dup_language(currentlanguage);
837 : /* Empty */ { $$=new_dialog(); }
838 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
839 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
840 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
841 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
842 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
843 | dlg_attributes tCPPCLASS nameid_s { $$=dialog_class($3,$1); }
844 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
845 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
846 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
847 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
850 ctrls : /* Empty */ { $$ = NULL; }
851 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
852 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
853 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
854 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
855 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
856 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
857 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
858 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
859 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
860 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
861 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
862 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
863 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
864 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
865 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
866 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
867 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
868 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
869 /* special treatment for icons, as the extent is optional */
870 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
875 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
880 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style {
882 $$->title = new_name_id();
883 $$->title->type = name_str;
884 $$->title->name.s_name = $1;
899 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
914 iconinfo: /* Empty */
915 { $$ = new_control(); }
917 | ',' expr ',' expr {
922 | ',' expr ',' expr ',' style {
929 | ',' expr ',' expr ',' style ',' style {
936 $$->gotexstyle = TRUE;
940 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
944 $$->ctlclass = convert_ctlclass($5);
952 $$->gotexstyle = TRUE;
954 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
958 $$->ctlclass = convert_ctlclass($5);
969 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
972 /* ------------------------------ style flags ------------------------------ */
973 optional_style /* Abbused once to get optional ExStyle */
974 : /* Empty */ { $$ = NULL; }
975 | ',' style { $$ = $2; }
979 : /* Empty */ { $$ = NULL; }
980 | ',' style { $$ = new_style_pair($2, 0); }
981 | ',' style ',' style { $$ = new_style_pair($2, $4); }
985 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
986 | '(' style ')' { $$ = $2; }
987 | any_num { $$ = new_style($1, 0); }
988 | tNOT any_num { $$ = new_style(0, $2); }
995 $$->name.i_name = $1;
1000 $$->name.s_name = $1;
1004 /* ------------------------------ DialogEx ------------------------------ */
1005 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
1006 tBEGIN exctrls tEND {
1008 yywarning("DIALOGEX not supported in 16-bit mode");
1011 $11->memopt = *($2);
1015 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1022 $11->helpid = *($10);
1023 $11->gothelpid = TRUE;
1026 $11->controls = get_control_head($13);
1029 assert($$->style != NULL);
1032 $$->style->or_mask = WS_POPUP;
1033 $$->gotstyle = TRUE;
1036 $$->style->or_mask |= WS_CAPTION;
1038 $$->style->or_mask |= DS_SETFONT;
1040 $$->style->or_mask &= ~($$->style->and_mask);
1041 $$->style->and_mask = 0;
1043 if(!$$->lvc.language)
1044 $$->lvc.language = dup_language(currentlanguage);
1049 : /* Empty */ { $$=new_dialogex(); }
1050 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
1051 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
1052 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1053 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1054 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1055 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1056 | dlgex_attribs tCPPCLASS nameid_s { $$=dialogex_class($3,$1); }
1057 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1058 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1059 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1060 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1063 exctrls : /* Empty */ { $$ = NULL; }
1064 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1065 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1066 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1067 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1068 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1069 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1070 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1071 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1072 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1073 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1074 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1075 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1076 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1077 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1078 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1079 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1080 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1081 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1082 /* special treatment for icons, as the extent is optional */
1083 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1088 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1093 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1094 expr ',' style helpid opt_data {
1098 $$->ctlclass = convert_ctlclass($5);
1100 $$->gotstyle = TRUE;
1108 $$->gotexstyle = TRUE;
1112 $$->helpid = *($18);
1113 $$->gothelpid = TRUE;
1118 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1123 $$->gotstyle = TRUE;
1124 $$->ctlclass = convert_ctlclass($5);
1134 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1136 $$->title = new_name_id();
1137 $$->title->type = name_str;
1138 $$->title->name.s_name = $1;
1146 $$->style = $12->style;
1147 $$->gotstyle = TRUE;
1151 $$->exstyle = $12->exstyle;
1152 $$->gotexstyle = TRUE;
1162 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1171 $$->style = $10->style;
1172 $$->gotstyle = TRUE;
1176 $$->exstyle = $10->exstyle;
1177 $$->gotexstyle = TRUE;
1185 opt_data: /* Empty */ { $$ = NULL; }
1186 | raw_data { $$ = $1; }
1189 helpid : /* Empty */ { $$ = NULL; }
1190 | ',' expr { $$ = new_int($2); }
1194 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1198 * FIXME: This odd expression is here to nullify an extra token found
1199 * in some appstudio produced resources which appear to do nothing.
1201 opt_expr: /* Empty */ { $$ = NULL; }
1202 | ',' expr { $$ = NULL; }
1205 /* ------------------------------ Menu ------------------------------ */
1206 menu : tMENU loadmemopts opt_lvc menu_body {
1208 yyerror("Menu must contain items");
1216 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1217 $$->items = get_item_head($4);
1223 if(!$$->lvc.language)
1224 $$->lvc.language = dup_language(currentlanguage);
1229 : tBEGIN item_definitions tEND { $$ = $2; }
1233 : /* Empty */ {$$ = NULL;}
1234 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1243 | item_definitions tMENUITEM tSEPARATOR {
1249 | item_definitions tPOPUP tSTRING item_options menu_body {
1250 $$ = new_menu_item();
1254 $$->popup = get_item_head($5);
1259 /* NOTE: item_options is right recursive because it would introduce
1260 * a shift/reduce conflict on ',' in itemex_options due to the
1261 * empty rule here. The parser is now forced to look beyond the ','
1262 * before reducing (force shift).
1263 * Right recursion here is not a problem because we cannot expect
1264 * more than 7 parserstack places to be occupied while parsing this
1265 * (who would want to specify a MF_x flag twice?).
1268 : /* Empty */ { $$ = 0; }
1269 | ',' tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1270 | ',' tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1271 | ',' tHELP item_options { $$ = $3 | MF_HELP; }
1272 | ',' tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1273 | ',' tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1274 | ',' tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1277 /* ------------------------------ MenuEx ------------------------------ */
1278 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1280 yywarning("MENUEX not supported in 16-bit mode");
1282 yyerror("MenuEx must contain items");
1290 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1291 $$->items = get_itemex_head($4);
1297 if(!$$->lvc.language)
1298 $$->lvc.language = dup_language(currentlanguage);
1303 : tBEGIN itemex_definitions tEND { $$ = $2; }
1307 : /* Empty */ {$$ = NULL; }
1308 | itemex_definitions tMENUITEM tSTRING itemex_options {
1309 $$ = new_menuex_item();
1315 $$->type = $4->type;
1316 $$->state = $4->state;
1317 $$->helpid = $4->helpid;
1318 $$->gotid = $4->gotid;
1319 $$->gottype = $4->gottype;
1320 $$->gotstate = $4->gotstate;
1321 $$->gothelpid = $4->gothelpid;
1324 | itemex_definitions tMENUITEM tSEPARATOR {
1325 $$ = new_menuex_item();
1330 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1331 $$ = new_menuex_item();
1335 $$->popup = get_itemex_head($5);
1338 $$->type = $4->type;
1339 $$->state = $4->state;
1340 $$->helpid = $4->helpid;
1341 $$->gotid = $4->gotid;
1342 $$->gottype = $4->gottype;
1343 $$->gotstate = $4->gotstate;
1344 $$->gothelpid = $4->gothelpid;
1350 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1352 $$ = new_itemex_opt($2, 0, 0, 0);
1355 | ',' e_expr ',' e_expr item_options {
1356 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1359 $$->gotstate = TRUE;
1363 | ',' e_expr ',' e_expr ',' expr {
1364 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1367 $$->gotstate = TRUE;
1374 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1376 $$ = new_itemex_opt($2, 0, 0, 0);
1379 | ',' e_expr ',' expr {
1380 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1385 | ',' e_expr ',' e_expr ',' expr {
1386 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1391 $$->gotstate = TRUE;
1393 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1394 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1400 $$->gotstate = TRUE;
1401 $$->gothelpid = TRUE;
1405 /* ------------------------------ StringTable ------------------------------ */
1406 /* Stringtables are parsed differently than other resources because their
1407 * layout is substantially different from other resources.
1408 * The table is parsed through a _global_ variable 'tagstt' which holds the
1409 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1410 * list of stringtables of different languages.
1413 : stt_head tBEGIN strings tEND {
1416 yyerror("Stringtable must have at least one entry");
1421 /* Check if we added to a language table or created
1424 for(stt = sttres; stt; stt = stt->next)
1431 /* It is a new one */
1434 sttres->prev = tagstt;
1435 tagstt->next = sttres;
1441 /* Else were done */
1445 free(tagstt_memopt);
1446 tagstt_memopt = NULL;
1453 /* This is to get the language of the currently parsed stringtable */
1454 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1455 if((tagstt = find_stringtable($3)) == NULL)
1456 tagstt = new_stringtable($3);
1458 tagstt_version = $3->version;
1459 tagstt_characts = $3->characts;
1465 strings : /* Empty */ { $$ = NULL; }
1466 | strings expr opt_comma tSTRING {
1468 assert(tagstt != NULL);
1469 if($2 > 65535 || $2 < -32768)
1470 yyerror("Stringtable entry's ID out of range (%d)", $2);
1471 /* Search for the ID */
1472 for(i = 0; i < tagstt->nentries; i++)
1474 if(tagstt->entries[i].id == $2)
1475 yyerror("Stringtable ID %d already in use", $2);
1477 /* If we get here, then we have a new unique entry */
1479 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1480 tagstt->entries[tagstt->nentries-1].id = $2;
1481 tagstt->entries[tagstt->nentries-1].str = $4;
1483 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1485 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1486 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1487 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1489 if(pedantic && !$4->size)
1490 yywarning("Zero length strings make no sense");
1491 if(!win32 && $4->size > 254)
1492 yyerror("Stringtable entry more than 254 characters");
1493 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1494 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1499 opt_comma /* There seem to be two ways to specify a stringtable... */
1504 /* ------------------------------ VersionInfo ------------------------------ */
1506 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1514 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1515 $$->blocks = get_ver_block_head($5);
1516 /* Set language; there is no version or characteristics */
1517 $$->lvc.language = dup_language(currentlanguage);
1522 : /* Empty */ { $$ = new_versioninfo(); }
1523 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1525 yyerror("FILEVERSION already defined");
1527 $$->filever_maj1 = $3;
1528 $$->filever_maj2 = $5;
1529 $$->filever_min1 = $7;
1530 $$->filever_min2 = $9;
1533 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1535 yyerror("PRODUCTVERSION already defined");
1537 $$->prodver_maj1 = $3;
1538 $$->prodver_maj2 = $5;
1539 $$->prodver_min1 = $7;
1540 $$->prodver_min2 = $9;
1543 | fix_version tFILEFLAGS expr {
1545 yyerror("FILEFLAGS already defined");
1550 | fix_version tFILEFLAGSMASK expr {
1552 yyerror("FILEFLAGSMASK already defined");
1554 $$->fileflagsmask = $3;
1557 | fix_version tFILEOS expr {
1559 yyerror("FILEOS already defined");
1564 | fix_version tFILETYPE expr {
1566 yyerror("FILETYPE already defined");
1571 | fix_version tFILESUBTYPE expr {
1573 yyerror("FILESUBTYPE already defined");
1575 $$->filesubtype = $3;
1581 : /* Empty */ { $$ = NULL; }
1582 | ver_blocks ver_block {
1591 : tBLOCK tSTRING tBEGIN ver_values tEND {
1592 $$ = new_ver_block();
1594 $$->values = get_ver_value_head($4);
1599 : /* Empty */ { $$ = NULL; }
1600 | ver_values ver_value {
1610 $$ = new_ver_value();
1611 $$->type = val_block;
1612 $$->value.block = $1;
1614 | tVALUE tSTRING ',' tSTRING {
1615 $$ = new_ver_value();
1620 | tVALUE tSTRING ',' ver_words {
1621 $$ = new_ver_value();
1622 $$->type = val_words;
1624 $$->value.words = $4;
1629 : expr { $$ = new_ver_words($1); }
1630 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1633 /* ------------------------------ Toolbar ------------------------------ */
1634 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1636 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1637 $$ = new_toolbar($3, $5, items, nitems);
1645 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1652 if(!$$->lvc.language)
1654 $$->lvc.language = dup_language(currentlanguage);
1660 : /* Empty */ { $$ = NULL; }
1661 | toolbar_items tBUTTON expr {
1662 toolbar_item_t *idrec = new_toolbar_item();
1664 $$ = ins_tlbr_button($1, idrec);
1666 | toolbar_items tSEPARATOR {
1667 toolbar_item_t *idrec = new_toolbar_item();
1669 $$ = ins_tlbr_button($1, idrec);
1673 /* ------------------------------ Memory options ------------------------------ */
1675 : /* Empty */ { $$ = NULL; }
1676 | loadmemopts lamo {
1686 | loadmemopts lama {
1695 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1701 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1702 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1703 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1704 | tPURE { $$ = new_int(WRC_MO_PURE); }
1707 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1708 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1709 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1712 /* ------------------------------ Win32 options ------------------------------ */
1713 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1714 | opt_lvc opt_language {
1716 yywarning("LANGUAGE not supported in 16-bit mode");
1718 yyerror("Language already defined");
1722 | opt_lvc opt_characts {
1724 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1726 yyerror("Characteristics already defined");
1730 | opt_lvc opt_version {
1732 yywarning("VERSION not supported in 16-bit mode");
1734 yyerror("Version already defined");
1741 * This here is another s/r conflict on {bi,u}nary + and -.
1742 * It is due to the look-ahead which must determine when the
1743 * rule opt_language ends. It could be solved with adding a
1744 * tNL at the end, but that seems unreasonable to do.
1745 * The conflict is now moved to the expression handling below.
1748 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4); }
1752 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1756 : tVERSION expr { $$ = new_version($2); }
1759 /* ------------------------------ Raw data handling ------------------------------ */
1760 raw_data: opt_lvc tBEGIN raw_elements tEND {
1767 if(!$3->lvc.language)
1768 $3->lvc.language = dup_language(currentlanguage);
1775 : tRAWDATA { $$ = $1; }
1776 | tNUMBER { $$ = int2raw_data($1); }
1777 | tLNUMBER { $$ = long2raw_data($1); }
1778 | tSTRING { $$ = str2raw_data($1); }
1779 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1780 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1781 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1782 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1785 /* File data or raw data */
1786 file_raw: filename {
1788 $$->lvc.language = dup_language(currentlanguage);
1790 | raw_data { $$ = $1; }
1793 /* ------------------------------ Win32 expressions ------------------------------ */
1794 /* All win16 numbers are also handled here. This is inconsistent with MS'
1795 * resource compiler, but what the heck, its just handy to have.
1797 e_expr : /* Empty */ { $$ = 0; }
1798 | expr { $$ = new_int($1); }
1801 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1802 expr : xpr { $$ = ($1); }
1805 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1806 | xpr '-' xpr { $$ = ($1) - ($3); }
1807 | xpr '|' xpr { $$ = ($1) | ($3); }
1808 | xpr '&' xpr { $$ = ($1) & ($3); }
1809 | xpr '*' xpr { $$ = ($1) * ($3); }
1810 | xpr '/' xpr { $$ = ($1) / ($3); }
1811 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1812 | '~' xpr { $$ = ~($2); }
1813 | '-' xpr %prec pUPM { $$ = -($2); }
1814 | '+' xpr %prec pUPM { $$ = $2; }
1815 | '(' xpr ')' { $$ = $2; }
1816 | any_num { $$ = $1; }
1817 | tNOT any_num { $$ = ~($2); }
1820 any_num : tNUMBER { $$ = $1; }
1821 | tLNUMBER { $$ = $1; }
1825 /* Dialog specific functions */
1826 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1828 assert(dlg != NULL);
1829 if(dlg->style == NULL)
1831 dlg->style = new_style(0,0);
1836 yywarning("Style already defined, or-ing together");
1840 dlg->style->or_mask = 0;
1841 dlg->style->and_mask = 0;
1843 dlg->style->or_mask |= st->or_mask;
1844 dlg->style->and_mask |= st->and_mask;
1845 dlg->gotstyle = TRUE;
1850 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1852 assert(dlg != NULL);
1853 if(dlg->exstyle == NULL)
1855 dlg->exstyle = new_style(0,0);
1860 yywarning("ExStyle already defined, or-ing together");
1864 dlg->exstyle->or_mask = 0;
1865 dlg->exstyle->and_mask = 0;
1867 dlg->exstyle->or_mask |= st->or_mask;
1868 dlg->exstyle->and_mask |= st->and_mask;
1869 dlg->gotexstyle = TRUE;
1874 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1876 assert(dlg != NULL);
1878 yyerror("Caption already defined");
1883 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1885 assert(dlg != NULL);
1887 yyerror("Font already defined");
1892 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1894 assert(dlg != NULL);
1896 yyerror("Class already defined");
1901 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1903 assert(dlg != NULL);
1905 yyerror("Menu already defined");
1910 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1912 assert(dlg != NULL);
1913 if(dlg->lvc.language)
1914 yyerror("Language already defined");
1915 dlg->lvc.language = l;
1919 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1921 assert(dlg != NULL);
1922 if(dlg->lvc.characts)
1923 yyerror("Characteristics already defined");
1924 dlg->lvc.characts = c;
1928 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1930 assert(dlg != NULL);
1931 if(dlg->lvc.version)
1932 yyerror("Version already defined");
1933 dlg->lvc.version = v;
1937 /* Controls specific functions */
1938 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1940 /* Hm... this seems to be jammed in at all time... */
1941 int defaultstyle = WS_CHILD | WS_VISIBLE;
1943 assert(ctrl != NULL);
1951 ctrl->ctlclass = new_name_id();
1952 ctrl->ctlclass->type = name_ord;
1953 ctrl->ctlclass->name.i_name = type;
1959 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1960 defaultstyle |= WS_TABSTOP;
1963 defaultstyle |= WS_TABSTOP | WS_BORDER;
1966 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1969 defaultstyle |= CBS_SIMPLE;
1972 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1973 defaultstyle |= WS_GROUP;
1977 if(!ctrl->gotstyle) /* Handle default style setting */
1982 defaultstyle |= ES_LEFT;
1985 defaultstyle |= LBS_NOTIFY;
1988 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1991 defaultstyle |= SBS_HORZ;
1994 switch(special_style)
1997 case BS_DEFPUSHBUTTON:
2000 /* case BS_PUSHBOX: */
2001 case BS_AUTORADIOBUTTON:
2004 case BS_AUTOCHECKBOX:
2005 defaultstyle |= WS_TABSTOP;
2008 yywarning("Unknown default button control-style 0x%08x", special_style);
2009 case BS_RADIOBUTTON:
2015 switch(special_style)
2020 defaultstyle |= WS_GROUP;
2022 case SS_ICON: /* Special case */
2025 yywarning("Unknown default static control-style 0x%08x", special_style);
2029 case -1: /* Generic control */
2033 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2037 /* The SS_ICON flag is always forced in for icon controls */
2038 if(type == CT_STATIC && special_style == SS_ICON)
2039 defaultstyle |= SS_ICON;
2041 if (!ctrl->gotstyle)
2042 ctrl->style = new_style(0,0);
2044 /* combine all styles */
2045 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2046 ctrl->gotstyle = TRUE;
2048 /* combine with NOT mask */
2051 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2052 ctrl->style->and_mask = 0;
2054 if (ctrl->gotexstyle)
2056 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2057 ctrl->exstyle->and_mask = 0;
2062 static name_id_t *convert_ctlclass(name_id_t *cls)
2067 if(cls->type == name_ord)
2069 assert(cls->type == name_str);
2070 if(cls->type == str_unicode)
2072 yyerror("Don't yet support unicode class comparison");
2075 cc = cls->name.s_name->str.cstr;
2077 if(!strcasecmp("BUTTON", cc))
2079 else if(!strcasecmp("COMBOBOX", cc))
2080 iclass = CT_COMBOBOX;
2081 else if(!strcasecmp("LISTBOX", cc))
2082 iclass = CT_LISTBOX;
2083 else if(!strcasecmp("EDIT", cc))
2085 else if(!strcasecmp("STATIC", cc))
2087 else if(!strcasecmp("SCROLLBAR", cc))
2088 iclass = CT_SCROLLBAR;
2090 return cls; /* No default, return user controlclass */
2092 free(cls->name.s_name->str.cstr);
2093 free(cls->name.s_name);
2094 cls->type = name_ord;
2095 cls->name.i_name = iclass;
2099 /* DialogEx specific functions */
2100 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2102 assert(dlg != NULL);
2103 if(dlg->style == NULL)
2105 dlg->style = new_style(0,0);
2110 yywarning("Style already defined, or-ing together");
2114 dlg->style->or_mask = 0;
2115 dlg->style->and_mask = 0;
2117 dlg->style->or_mask |= st->or_mask;
2118 dlg->style->and_mask |= st->and_mask;
2119 dlg->gotstyle = TRUE;
2124 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2126 assert(dlg != NULL);
2127 if(dlg->exstyle == NULL)
2129 dlg->exstyle = new_style(0,0);
2134 yywarning("ExStyle already defined, or-ing together");
2138 dlg->exstyle->or_mask = 0;
2139 dlg->exstyle->and_mask = 0;
2141 dlg->exstyle->or_mask |= st->or_mask;
2142 dlg->exstyle->and_mask |= st->and_mask;
2143 dlg->gotexstyle = TRUE;
2148 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2150 assert(dlg != NULL);
2152 yyerror("Caption already defined");
2157 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2159 assert(dlg != NULL);
2161 yyerror("Font already defined");
2166 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2168 assert(dlg != NULL);
2170 yyerror("Class already defined");
2175 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2177 assert(dlg != NULL);
2179 yyerror("Menu already defined");
2184 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2186 assert(dlg != NULL);
2187 if(dlg->lvc.language)
2188 yyerror("Language already defined");
2189 dlg->lvc.language = l;
2193 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2195 assert(dlg != NULL);
2196 if(dlg->lvc.characts)
2197 yyerror("Characteristics already defined");
2198 dlg->lvc.characts = c;
2202 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2204 assert(dlg != NULL);
2205 if(dlg->lvc.version)
2206 yyerror("Version already defined");
2207 dlg->lvc.version = v;
2211 /* Accelerator specific functions */
2212 static event_t *add_event(int key, int id, int flags, event_t *prev)
2214 event_t *ev = new_event();
2216 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2217 yyerror("Cannot use both ASCII and VIRTKEY");
2221 ev->flags = flags & ~WRC_AF_ASCII;
2228 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2231 event_t *ev = new_event();
2233 if(key->type != str_char)
2234 yyerror("Key code must be an ascii string");
2236 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
2237 yyerror("VIRTKEY code is not equal to ascii value");
2239 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2241 yyerror("Cannot use both '^' and CONTROL modifier");
2243 else if(key->str.cstr[0] == '^')
2245 keycode = toupper(key->str.cstr[1]) - '@';
2247 yyerror("Control-code out of range");
2250 keycode = key->str.cstr[0];
2253 ev->flags = flags & ~WRC_AF_ASCII;
2260 /* MenuEx specific functions */
2261 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2263 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2267 opt->helpid = helpid;
2271 /* Raw data functions */
2272 static raw_data_t *load_file(string_t *name)
2276 if(name->type != str_char)
2277 yyerror("Filename must be ASCII string");
2279 fp = open_include(name->str.cstr, 1, NULL);
2281 yyerror("Cannot open file %s", name->str.cstr);
2282 rd = new_raw_data();
2283 fseek(fp, 0, SEEK_END);
2284 rd->size = ftell(fp);
2285 fseek(fp, 0, SEEK_SET);
2286 rd->data = (char *)xmalloc(rd->size);
2287 fread(rd->data, rd->size, 1, fp);
2292 static raw_data_t *int2raw_data(int i)
2296 if((int)((short)i) != i)
2297 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2299 rd = new_raw_data();
2300 rd->size = sizeof(short);
2301 rd->data = (char *)xmalloc(rd->size);
2304 #ifndef WORDS_BIGENDIAN
2309 *(WORD *)(rd->data) = BYTESWAP_WORD((WORD)i);
2312 *(WORD *)(rd->data) = (WORD)i;
2318 static raw_data_t *long2raw_data(int i)
2321 rd = new_raw_data();
2322 rd->size = sizeof(int);
2323 rd->data = (char *)xmalloc(rd->size);
2326 #ifndef WORDS_BIGENDIAN
2331 *(DWORD *)(rd->data) = BYTESWAP_DWORD((DWORD)i);
2334 *(DWORD *)(rd->data) = (DWORD)i;
2340 static raw_data_t *str2raw_data(string_t *str)
2343 rd = new_raw_data();
2344 rd->size = str->size * (str->type == str_char ? 1 : 2);
2345 rd->data = (char *)xmalloc(rd->size);
2346 if(str->type == str_char)
2347 memcpy(rd->data, str->str.cstr, rd->size);
2348 else if(str->type == str_unicode)
2353 #ifndef WORDS_BIGENDIAN
2358 for(i = 0; i < str->size; i++)
2359 *(WORD *)&(rd->data[2*i]) = BYTESWAP_WORD((WORD)str->str.wstr[i]);
2362 for(i = 0; i < str->size; i++)
2363 *(WORD *)&(rd->data[2*i]) = (WORD)str->str.wstr[i];
2368 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2372 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2374 r1->data = xrealloc(r1->data, r1->size + r2->size);
2375 memcpy(r1->data + r1->size, r2->data, r2->size);
2376 r1->size += r2->size;
2380 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2382 raw_data_t *t = int2raw_data(i);
2383 merge_raw_data(r1, t);
2389 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2391 raw_data_t *t = long2raw_data(i);
2392 merge_raw_data(r1, t);
2398 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2400 raw_data_t *t = str2raw_data(str);
2401 merge_raw_data(r1, t);
2407 /* Function the go back in a list to get the head */
2408 static menu_item_t *get_item_head(menu_item_t *p)
2417 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2426 static resource_t *get_resource_head(resource_t *p)
2435 static ver_block_t *get_ver_block_head(ver_block_t *p)
2444 static ver_value_t *get_ver_value_head(ver_value_t *p)
2453 static control_t *get_control_head(control_t *p)
2462 static event_t *get_event_head(event_t *p)
2471 /* Find a stringtable with given language */
2472 static stringtable_t *find_stringtable(lvc_t *lvc)
2476 assert(lvc != NULL);
2479 lvc->language = dup_language(currentlanguage);
2481 for(stt = sttres; stt; stt = stt->next)
2483 if(stt->lvc.language->id == lvc->language->id
2484 && stt->lvc.language->sub == lvc->language->sub)
2486 /* Found a table with the same language */
2487 /* The version and characteristics are now handled
2488 * in the generation of the individual stringtables.
2489 * This enables localized analysis.
2490 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2491 || (!stt->lvc.version && lvc->version)
2492 || (stt->lvc.version && !lvc->version))
2493 yywarning("Stringtable's versions are not the same, using first definition");
2495 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2496 || (!stt->lvc.characts && lvc->characts)
2497 || (stt->lvc.characts && !lvc->characts))
2498 yywarning("Stringtable's characteristics are not the same, using first definition");
2506 /* qsort sorting function for string table entries */
2507 #define STE(p) ((stt_entry_t *)(p))
2508 static int sort_stt_entry(const void *e1, const void *e2)
2510 return STE(e1)->id - STE(e2)->id;
2514 static resource_t *build_stt_resources(stringtable_t *stthead)
2517 stringtable_t *newstt;
2519 resource_t *rsclist = NULL;
2520 resource_t *rsctail = NULL;
2525 characts_t *characts;
2531 /* For all languages defined */
2532 for(stt = stthead; stt; stt = stt->next)
2534 assert(stt->nentries > 0);
2536 /* Sort the entries */
2537 if(stt->nentries > 1)
2538 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2540 for(i = 0; i < stt->nentries; )
2542 newstt = new_stringtable(&stt->lvc);
2543 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2544 newstt->nentries = 16;
2545 newstt->idbase = stt->entries[i].id & ~0xf;
2546 for(j = 0; j < 16 && i < stt->nentries; j++)
2548 if(stt->entries[i].id - newstt->idbase == j)
2550 newstt->entries[j] = stt->entries[i];
2558 /* Check individual memory options and get
2559 * the first characteristics/version
2561 for(j = 0; j < 16; j++)
2563 if(!newstt->entries[j].str)
2565 andsum &= newstt->entries[j].memopt;
2566 orsum |= newstt->entries[j].memopt;
2568 characts = newstt->entries[j].characts;
2570 version = newstt->entries[j].version;
2574 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2576 /* Check version and characteristics */
2577 for(j = 0; j < 16; j++)
2580 && newstt->entries[j].characts
2581 && *newstt->entries[j].characts != *characts)
2582 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2584 && newstt->entries[j].version
2585 && *newstt->entries[j].version != *version)
2586 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2588 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2589 rsc->name = new_name_id();
2590 rsc->name->type = name_ord;
2591 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2592 rsc->memopt = andsum; /* Set to least common denominator */
2593 newstt->memopt = andsum;
2594 newstt->lvc.characts = characts;
2595 newstt->lvc.version = version;
2603 rsctail->next = rsc;
2604 rsc->prev = rsctail;
2613 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2622 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2641 static string_t *make_filename(string_t *str)
2645 if(str->type != str_char)
2646 yyerror("Cannot handle UNICODE filenames");
2648 /* Remove escaped backslash and convert to forward */
2649 cptr = str->str.cstr;
2650 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2654 memmove(cptr, cptr+1, strlen(cptr));
2660 /* Convert to lower case. Seems to be reasonable to do */
2661 for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
2663 *cptr = tolower(*cptr);
2669 * Process all resources to extract fonts and build
2670 * a fontdir resource.
2672 * Note: MS' resource compiler (build 1472) does not
2673 * handle font resources with different languages.
2674 * The fontdir is generated in the last active language
2675 * and font identifiers must be unique across the entire
2677 * This is not logical considering the localization
2678 * constraints of all other resource types. MS has,
2679 * most probably, never testet localized fonts. However,
2680 * using fontresources is rare, so it might not occur
2681 * in normal applications.
2682 * Wine does require better localization because a lot
2683 * of languages are coded into the same executable.
2684 * Therefore, I will generate fontdirs for *each*
2685 * localized set of fonts.
2687 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2689 static int once = 0;
2692 warning("Need to parse fonts, not yet implemented");
2698 static resource_t *build_fontdirs(resource_t *tail)
2701 resource_t *lst = NULL;
2702 resource_t **fnt = NULL; /* List of all fonts */
2704 resource_t **fnd = NULL; /* List of all fontdirs */
2706 resource_t **lanfnt = NULL;
2713 nid.type = name_str;
2714 nid.name.s_name = &str;
2715 str.type = str_char;
2716 str.str.cstr = "FONTDIR";
2719 /* Extract all fonts and fontdirs */
2720 for(rsc = tail; rsc; rsc = rsc->prev)
2722 if(rsc->type == res_fnt)
2725 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2728 else if(rsc->type == res_fntdir)
2731 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2736 /* Verify the name of the present fontdirs */
2737 for(i = 0; i < nfnd; i++)
2739 if(compare_name_id(&nid, fnd[i]->name))
2741 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2742 get_nameid_str(fnd[i]->name));
2751 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2756 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2758 /* Get all fonts covered by fontdirs */
2759 for(i = 0; i < nfnd; i++)
2767 for(j = 0; j < nfnt; j++)
2771 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2773 lanfnt[nlanfnt] = fnt[j];
2779 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2782 else if(nlanfnt == BYTESWAP_WORD(cnt))
2785 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2786 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2787 #ifdef WORDS_BIGENDIAN
2788 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2790 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2793 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2797 /* We now have fonts left where we need to make a fontdir resource */
2798 for(i = fntleft = 0; i < nfnt; i++)
2805 /* Get fonts of same language in lanfnt[] */
2806 for(i = nlanfnt = 0; i < nfnt; i++)
2813 lanfnt[nlanfnt] = fnt[i];
2818 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2822 /* and build a fontdir */
2823 rsc = build_fontdir(lanfnt, nlanfnt);
2845 * This gets invoked to determine whether the next resource
2846 * is to be of a standard-type (e.g. bitmaps etc.), or should
2847 * be a user-type resource. This function is required because
2848 * there is the _possibility_ of a lookahead token in the
2849 * parser, which is generated from the "expr" state in the
2852 * The general resource format is:
2853 * <identifier> <type> <flags> <resourcebody>
2855 * The <identifier> can either be tIDENT or "expr". The latter
2856 * will always generate a lookahead, which is the <type> of the
2857 * resource to parse. Otherwise, we need to get a new token from
2858 * the scanner to determine the next step.
2860 * The problem arrises when <type> is numerical. This case should
2861 * map onto default resource-types and be parsed as such instead
2862 * of being mapped onto user-type resources.
2864 * The trick lies in the fact that yacc (bison) doesn't care about
2865 * intermediate changes of the lookahead while reducing a rule. We
2866 * simply replace the lookahead with a token that will result in
2867 * a shift to the appropriate rule for the specific resource-type.
2869 static int rsrcid_to_token(int lookahead)
2874 /* Get a token if we don't have one yet */
2875 if(lookahead == YYEMPTY)
2878 /* Only numbers are possibly interesting */
2908 case WRC_RT_FONTDIR:
2916 case WRC_RT_MESSAGETABLE:
2917 type = "MESSAGETABLE";
2918 token = tMESSAGETABLE;
2920 case WRC_RT_DLGINIT:
2924 case WRC_RT_ACCELERATOR:
2925 type = "ACCELERATOR";
2926 token = tACCELERATORS;
2936 case WRC_RT_VERSION:
2938 token = tVERSIONINFO;
2940 case WRC_RT_TOOLBAR:
2946 type = "STRINGTABLE";
2949 case WRC_RT_ANICURSOR:
2950 case WRC_RT_ANIICON:
2951 case WRC_RT_GROUP_CURSOR:
2952 case WRC_RT_GROUP_ICON:
2953 yywarning("Usertype uses reserved type-ID %d, which is auto-generated", yylval.num);
2956 case WRC_RT_DLGINCLUDE:
2957 case WRC_RT_PLUGPLAY:
2960 yywarning("Usertype uses reserved type-ID %d, which is not supported by wrc", yylval.num);
2968 yywarning("Usertype uses reserved type-ID %d, which is used by %s", yylval.num, type);