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 * except 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"
132 /* Berkeley yacc (byacc) doesn't seem to know about these */
133 /* Some *BSD supplied versions do define these though */
135 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
138 # define YYLEX yylex()
141 #elif defined(YYBISON)
142 /* Bison was used for original development */
143 /* #define YYEMPTY -2 */
144 /* #define YYLEX yylex() */
147 /* No yacc we know yet */
148 # if !defined(YYEMPTY) || !defined(YYLEX)
149 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
150 # elif defined(__GNUC__) /* gcc defines the #warning directive */
151 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
152 /* #else we just take a chance that it works... */
156 int want_nl = 0; /* Signal flex that we need the next newline */
157 int want_id = 0; /* Signal flex that we need the next identifier */
158 stringtable_t *tagstt; /* Stringtable tag.
159 * It is set while parsing a stringtable to one of
160 * the stringtables in the sttres list or a new one
161 * if the language was not parsed before.
163 stringtable_t *sttres; /* Stringtable resources. This holds the list of
164 * stringtables with different lanuages
166 static int dont_want_id = 0; /* See language parsing for details */
168 /* Set to the current options of the currently scanning stringtable */
169 static int *tagstt_memopt;
170 static characts_t *tagstt_characts;
171 static version_t *tagstt_version;
173 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
175 /* Prototypes of here defined functions */
176 static event_t *get_event_head(event_t *p);
177 static control_t *get_control_head(control_t *p);
178 static ver_value_t *get_ver_value_head(ver_value_t *p);
179 static ver_block_t *get_ver_block_head(ver_block_t *p);
180 static resource_t *get_resource_head(resource_t *p);
181 static menuex_item_t *get_itemex_head(menuex_item_t *p);
182 static menu_item_t *get_item_head(menu_item_t *p);
183 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
184 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
185 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
186 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
187 static raw_data_t *str2raw_data(string_t *str);
188 static raw_data_t *int2raw_data(int i);
189 static raw_data_t *long2raw_data(int i);
190 static raw_data_t *load_file(string_t *name);
191 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
192 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
193 static event_t *add_event(int key, int id, int flags, event_t *prev);
194 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
195 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
196 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
197 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
198 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
199 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
200 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
201 static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
202 static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
203 static name_id_t *convert_ctlclass(name_id_t *cls);
204 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
205 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
206 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
207 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
208 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
209 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
210 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
211 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
212 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
213 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
214 static resource_t *build_stt_resources(stringtable_t *stthead);
215 static stringtable_t *find_stringtable(lvc_t *lvc);
216 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
217 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
218 static string_t *make_filename(string_t *s);
219 static resource_t *build_fontdirs(resource_t *tail);
220 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
221 static int rsrcid_to_token(int lookahead);
252 menuex_item_t *menexitm;
260 toolbar_item_t *tlbarItems;
262 style_pair_t *styles;
268 %token <num> tNUMBER tLNUMBER
269 %token <str> tSTRING tIDENT tFILENAME
270 %token <raw> tRAWDATA
271 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
272 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
273 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
274 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
275 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
276 %token tCONTROL tEDITTEXT
277 %token tRTEXT tCTEXT tLTEXT
279 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
280 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
281 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
282 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
283 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
285 %token tSTRING tIDENT tRAWDATA
286 %token tTOOLBAR tBUTTON
297 %type <res> resource_file resource resources resource_definition
298 %type <stt> stringtable strings
301 %type <acc> accelerators
304 %type <ani> cursor icon
305 %type <dlg> dialog dlg_attributes
306 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
308 %type <dlgex> dialogex dlgex_attribs
309 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
311 %type <raw> raw_data raw_elements opt_data file_raw
312 %type <veri> versioninfo fix_version
313 %type <verw> ver_words
314 %type <blk> ver_blocks ver_block
315 %type <val> ver_values ver_value
317 %type <menitm> item_definitions menu_body
319 %type <menexitm> itemex_definitions menuex_body
320 %type <exopt> itemex_p_options itemex_options
321 %type <msg> messagetable
323 %type <num> item_options
324 %type <nid> nameid nameid_s ctlclass usertype
325 %type <num> acc_opt acc accs
326 %type <iptr> loadmemopts lamo lama
327 %type <fntid> opt_font opt_exfont opt_expr
329 %type <lan> opt_language
330 %type <chars> opt_characts
331 %type <ver> opt_version
334 %type <tlbar> toolbar
335 %type <tlbarItems> toolbar_items
336 %type <dginit> dlginit
337 %type <styles> optional_style_pair
339 %type <style> optional_style
348 /* First add stringtables to the resource-list */
349 rsc = build_stt_resources(sttres);
350 /* 'build_stt_resources' returns a head and $1 is a tail */
359 /* Find the tail again */
360 while($1 && $1->next)
362 /* Now add any fontdirecory */
363 rsc = build_fontdirs($1);
364 /* 'build_fontdir' returns a head and $1 is a tail */
373 /* Final statement before were done */
374 resource_top = get_resource_head($1);
378 /* Resources are put into a linked list */
380 : /* Empty */ { $$ = NULL; want_id = 1; }
381 | resources resource {
384 resource_t *tail = $2;
385 resource_t *head = $2;
394 /* Check for duplicate identifiers */
397 resource_t *rsc = $1;
400 if(rsc->type == head->type
401 && rsc->lan->id == head->lan->id
402 && rsc->lan->sub == head->lan->sub
403 && !compare_name_id(rsc->name, head->name))
405 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
414 resource_t *tail = $1;
422 if(!dont_want_id) /* See comments in language parsing below */
427 * The following newline rule will never get reduced because we never
428 * get the tNL token, unless we explicitely set the 'want_nl'
429 * flag, which we don't.
430 * The *ONLY* reason for this to be here is because Berkeley
431 * yacc (byacc), at least version 1.9, has a bug.
432 * (identified in the generated parser on the second
434 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
436 * This extra rule fixes it.
437 * The problem is that the expression handling rule "expr: xpr"
438 * is not reduced on non-terminal tokens, defined above in the
439 * %token declarations. Token tNL is the only non-terminal that
440 * can occur. The error becomes visible in the language parsing
441 * rule below, which looks at the look-ahead token and tests it
442 * for tNL. However, byacc already generates an error upon reading
443 * the token instead of keeping it as a lookahead. The reason
444 * lies in the lack of a $default transition in the "expr : xpr . "
445 * state (currently state 25). It is probably ommitted because tNL
446 * is a non-terminal and the state contains 2 s/r conflicts. The
447 * state enumerates all possible transitions instead of using a
448 * $default transition.
449 * All in all, it is a bug in byacc. (period)
455 /* Parse top level resource definitions etc. */
457 : expr usrcvt resource_definition {
461 if($1 > 65535 || $1 < -32768)
462 yyerror("Resource's ID out of range (%d)", $1);
463 $$->name = new_name_id();
464 $$->name->type = name_ord;
465 $$->name->name.i_name = $1;
466 chat("Got %s (%d)", get_typename($3), $$->name->name.i_name);
469 | tIDENT usrcvt resource_definition {
473 $$->name = new_name_id();
474 $$->name->type = name_str;
475 $$->name->name.s_name = $1;
476 chat("Got %s (%s)", get_typename($3), $$->name->name.s_name->str.cstr);
480 /* Don't do anything, stringtables are converted to
481 * resource_t structures when we are finished parsing and
482 * the final rule of the parser is reduced (see above)
485 chat("Got STRINGTABLE");
487 | tLANGUAGE {want_nl = 1; } expr ',' expr {
488 /* We *NEED* the newline to delimit the expression.
489 * Otherwise, we would not be able to set the next
490 * want_id anymore because of the token-lookahead.
492 * However, we can test the lookahead-token for
493 * being "non-expression" type, in which case we
494 * continue. Fortunately, tNL is the only token that
495 * will break expression parsing and is implicitely
496 * void, so we just remove it. This scheme makes it
497 * possible to do some (not all) fancy preprocessor
499 * BTW, we also need to make sure that the next
500 * reduction of 'resources' above will *not* set
501 * want_id because we already have a lookahead that
504 if(yychar != YYEMPTY && yychar != tNL)
508 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
509 /* direct access to yychar in rule 'usrcvt' below. */
510 else if(yychar == tIDENT)
511 yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
513 want_nl = 0; /* We don't want it anymore if we didn't get it */
516 yywarning("LANGUAGE not supported in 16-bit mode");
518 free(currentlanguage);
519 currentlanguage = new_language($3, $5);
521 chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
526 * Remapping of numerical resource types
527 * (see also comment of called function below)
529 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
533 * Get a valid name/id
536 if($1 > 65535 || $1 < -32768)
537 yyerror("Resource's ID out of range (%d)", $1);
540 $$->name.i_name = $1;
545 $$->name.s_name = $1;
550 * Extra string recognition for CLASS statement in dialogs
552 nameid_s: nameid { $$ = $1; }
556 $$->name.s_name = $1;
560 /* get the value for a single resource*/
562 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
563 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
566 if($1->type == res_anicur)
568 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
570 else if($1->type == res_curg)
573 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
574 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
576 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
577 rsc->prev->next = rsc;
579 rsc->name = new_name_id();
580 rsc->name->type = name_ord;
581 rsc->name->name.i_name = cur->id;
585 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
588 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
591 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
595 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
596 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
597 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
600 if($1->type == res_aniico)
602 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
604 else if($1->type == res_icog)
607 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
608 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
610 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
611 rsc->prev->next = rsc;
613 rsc->name = new_name_id();
614 rsc->name->type = name_ord;
615 rsc->name->name.i_name = ico->id;
619 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
622 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
625 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
629 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
630 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
631 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
632 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
633 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
637 filename: tFILENAME { $$ = make_filename($1); }
638 | tIDENT { $$ = make_filename($1); }
639 | tSTRING { $$ = make_filename($1); }
642 /* ------------------------------ Bitmap ------------------------------ */
643 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
646 /* ------------------------------ Cursor ------------------------------ */
647 cursor : tCURSOR loadmemopts file_raw {
649 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
651 $$->type = res_anicur;
652 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
657 $$->u.curg = new_cursor_group($3, $2);
662 /* ------------------------------ Icon ------------------------------ */
663 icon : tICON loadmemopts file_raw {
665 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
667 $$->type = res_aniico;
668 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
673 $$->u.icog = new_icon_group($3, $2);
678 /* ------------------------------ Font ------------------------------ */
680 * The reading of raw_data for fonts is a Borland BRC
681 * extension. MS generates an error. However, it is
682 * most logical to support this, considering how wine
683 * enters things in CVS (ascii).
685 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
689 * The fontdir is a Borland BRC extension which only
690 * reads the data as 'raw_data' from the file.
691 * I don't know whether it is interpreted.
692 * The fontdir is generated if it was not present and
693 * fonts are defined in the source.
695 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
698 /* ------------------------------ MessageTable ------------------------------ */
699 /* It might be interesting to implement the MS Message compiler here as well
700 * to get everything in one source. Might be a future project.
703 : tMESSAGETABLE loadmemopts file_raw {
705 yywarning("MESSAGETABLE not supported in 16-bit mode");
706 $$ = new_messagetable($3, $2);
710 /* ------------------------------ RCData ------------------------------ */
711 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
714 /* ------------------------------ DLGINIT ------------------------------ */
715 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
718 /* ------------------------------ UserType ------------------------------ */
719 userres : usertype loadmemopts file_raw {
720 #ifdef WORDS_BIGENDIAN
721 if(pedantic && byteorder != WRC_BO_LITTLE)
723 if(pedantic && byteorder == WRC_BO_BIG)
725 yywarning("Byteordering is not little-endian and type cannot be interpreted");
726 $$ = new_user($1, $3, $2);
733 $$->name.i_name = $1;
738 $$->name.s_name = $1;
742 /* ------------------------------ Accelerator ------------------------------ */
744 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
745 $$ = new_accelerator();
753 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
756 yyerror("Accelerator table must have at least one entry");
757 $$->events = get_event_head($5);
763 if(!$$->lvc.language)
764 $$->lvc.language = dup_language(currentlanguage);
768 events : /* Empty */ { $$=NULL; }
769 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
770 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
774 * The empty rule generates a s/r conflict because of {bi,u}nary expr
775 * on - and +. It cannot be solved in any way because it is the same as
776 * the if/then/else problem (LALR(1) problem). The conflict is moved
777 * away by forcing it to be in the expression handling below.
779 acc_opt : /* Empty */ { $$ = 0; }
780 | ',' accs { $$ = $2; }
783 accs : acc { $$ = $1; }
784 | accs ',' acc { $$ = $1 | $3; }
787 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
788 | tSHIFT { $$ = WRC_AF_SHIFT; }
789 | tCONTROL { $$ = WRC_AF_CONTROL; }
790 | tALT { $$ = WRC_AF_ALT; }
791 | tASCII { $$ = WRC_AF_ASCII; }
792 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
795 /* ------------------------------ Dialog ------------------------------ */
796 /* FIXME: Support EXSTYLE in the dialog line itself */
797 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
805 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
810 $10->controls = get_control_head($12);
814 $$->style->or_mask = WS_POPUP;
818 $$->style->or_mask |= WS_CAPTION;
820 $$->style->or_mask |= DS_SETFONT;
822 $$->style->or_mask &= ~($$->style->and_mask);
823 $$->style->and_mask = 0;
825 if(!$$->lvc.language)
826 $$->lvc.language = dup_language(currentlanguage);
831 : /* Empty */ { $$=new_dialog(); }
832 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
833 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
834 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
835 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
836 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
837 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
838 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
839 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
840 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
843 ctrls : /* Empty */ { $$ = NULL; }
844 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
845 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
846 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
847 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
848 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
849 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
850 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
851 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
852 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
853 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
854 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
855 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
856 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
857 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
858 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
859 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
860 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
861 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
862 /* special treatment for icons, as the extent is optional */
863 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
868 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
873 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style {
875 $$->title = new_name_id();
876 $$->title->type = name_str;
877 $$->title->name.s_name = $1;
892 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
907 iconinfo: /* Empty */
908 { $$ = new_control(); }
910 | ',' expr ',' expr {
915 | ',' expr ',' expr ',' style {
922 | ',' expr ',' expr ',' style ',' style {
929 $$->gotexstyle = TRUE;
933 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
937 $$->ctlclass = convert_ctlclass($5);
945 $$->gotexstyle = TRUE;
947 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
951 $$->ctlclass = convert_ctlclass($5);
962 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
965 /* ------------------------------ style flags ------------------------------ */
966 optional_style /* Abbused once to get optional ExStyle */
967 : /* Empty */ { $$ = NULL; }
968 | ',' style { $$ = $2; }
972 : /* Empty */ { $$ = NULL; }
973 | ',' style { $$ = new_style_pair($2, 0); }
974 | ',' style ',' style { $$ = new_style_pair($2, $4); }
978 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
979 | '(' style ')' { $$ = $2; }
980 | any_num { $$ = new_style($1, 0); }
981 | tNOT any_num { $$ = new_style(0, $2); }
988 $$->name.i_name = $1;
993 $$->name.s_name = $1;
997 /* ------------------------------ DialogEx ------------------------------ */
998 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
999 tBEGIN exctrls tEND {
1001 yywarning("DIALOGEX not supported in 16-bit mode");
1004 $11->memopt = *($2);
1008 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1015 $11->helpid = *($10);
1016 $11->gothelpid = TRUE;
1019 $11->controls = get_control_head($13);
1022 assert($$->style != NULL);
1025 $$->style->or_mask = WS_POPUP;
1026 $$->gotstyle = TRUE;
1029 $$->style->or_mask |= WS_CAPTION;
1031 $$->style->or_mask |= DS_SETFONT;
1033 $$->style->or_mask &= ~($$->style->and_mask);
1034 $$->style->and_mask = 0;
1036 if(!$$->lvc.language)
1037 $$->lvc.language = dup_language(currentlanguage);
1042 : /* Empty */ { $$=new_dialogex(); }
1043 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
1044 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
1045 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1046 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1047 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1048 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1049 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1050 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1051 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1052 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1055 exctrls : /* Empty */ { $$ = NULL; }
1056 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1057 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1058 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1059 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1060 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1061 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1062 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1063 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1064 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1065 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1066 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1067 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1068 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1069 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1070 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1071 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1072 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1073 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1074 /* special treatment for icons, as the extent is optional */
1075 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1080 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1085 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1086 expr ',' style helpid opt_data {
1090 $$->ctlclass = convert_ctlclass($5);
1092 $$->gotstyle = TRUE;
1100 $$->gotexstyle = TRUE;
1104 $$->helpid = *($18);
1105 $$->gothelpid = TRUE;
1110 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1115 $$->gotstyle = TRUE;
1116 $$->ctlclass = convert_ctlclass($5);
1126 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1128 $$->title = new_name_id();
1129 $$->title->type = name_str;
1130 $$->title->name.s_name = $1;
1138 $$->style = $12->style;
1139 $$->gotstyle = TRUE;
1143 $$->exstyle = $12->exstyle;
1144 $$->gotexstyle = TRUE;
1154 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1163 $$->style = $10->style;
1164 $$->gotstyle = TRUE;
1168 $$->exstyle = $10->exstyle;
1169 $$->gotexstyle = TRUE;
1177 opt_data: /* Empty */ { $$ = NULL; }
1178 | raw_data { $$ = $1; }
1181 helpid : /* Empty */ { $$ = NULL; }
1182 | ',' expr { $$ = new_int($2); }
1186 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1190 * FIXME: This odd expression is here to nullify an extra token found
1191 * in some appstudio produced resources which appear to do nothing.
1193 opt_expr: /* Empty */ { $$ = NULL; }
1194 | ',' expr { $$ = NULL; }
1197 /* ------------------------------ Menu ------------------------------ */
1198 menu : tMENU loadmemopts opt_lvc menu_body {
1200 yyerror("Menu must contain items");
1208 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1209 $$->items = get_item_head($4);
1215 if(!$$->lvc.language)
1216 $$->lvc.language = dup_language(currentlanguage);
1221 : tBEGIN item_definitions tEND { $$ = $2; }
1225 : /* Empty */ {$$ = NULL;}
1226 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1235 | item_definitions tMENUITEM tSEPARATOR {
1241 | item_definitions tPOPUP tSTRING item_options menu_body {
1242 $$ = new_menu_item();
1246 $$->popup = get_item_head($5);
1251 /* NOTE: item_options is right recursive because it would introduce
1252 * a shift/reduce conflict on ',' in itemex_options due to the
1253 * empty rule here. The parser is now forced to look beyond the ','
1254 * before reducing (force shift).
1255 * Right recursion here is not a problem because we cannot expect
1256 * more than 7 parserstack places to be occupied while parsing this
1257 * (who would want to specify a MF_x flag twice?).
1260 : /* Empty */ { $$ = 0; }
1261 | ',' tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1262 | ',' tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1263 | ',' tHELP item_options { $$ = $3 | MF_HELP; }
1264 | ',' tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1265 | ',' tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1266 | ',' tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1269 /* ------------------------------ MenuEx ------------------------------ */
1270 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1272 yywarning("MENUEX not supported in 16-bit mode");
1274 yyerror("MenuEx must contain items");
1282 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1283 $$->items = get_itemex_head($4);
1289 if(!$$->lvc.language)
1290 $$->lvc.language = dup_language(currentlanguage);
1295 : tBEGIN itemex_definitions tEND { $$ = $2; }
1299 : /* Empty */ {$$ = NULL; }
1300 | itemex_definitions tMENUITEM tSTRING itemex_options {
1301 $$ = new_menuex_item();
1307 $$->type = $4->type;
1308 $$->state = $4->state;
1309 $$->helpid = $4->helpid;
1310 $$->gotid = $4->gotid;
1311 $$->gottype = $4->gottype;
1312 $$->gotstate = $4->gotstate;
1313 $$->gothelpid = $4->gothelpid;
1316 | itemex_definitions tMENUITEM tSEPARATOR {
1317 $$ = new_menuex_item();
1322 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1323 $$ = new_menuex_item();
1327 $$->popup = get_itemex_head($5);
1330 $$->type = $4->type;
1331 $$->state = $4->state;
1332 $$->helpid = $4->helpid;
1333 $$->gotid = $4->gotid;
1334 $$->gottype = $4->gottype;
1335 $$->gotstate = $4->gotstate;
1336 $$->gothelpid = $4->gothelpid;
1342 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1344 $$ = new_itemex_opt($2, 0, 0, 0);
1347 | ',' e_expr ',' e_expr item_options {
1348 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1351 $$->gotstate = TRUE;
1355 | ',' e_expr ',' e_expr ',' expr {
1356 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1359 $$->gotstate = TRUE;
1366 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1368 $$ = new_itemex_opt($2, 0, 0, 0);
1371 | ',' e_expr ',' expr {
1372 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1377 | ',' e_expr ',' e_expr ',' expr {
1378 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1383 $$->gotstate = TRUE;
1385 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1386 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1392 $$->gotstate = TRUE;
1393 $$->gothelpid = TRUE;
1397 /* ------------------------------ StringTable ------------------------------ */
1398 /* Stringtables are parsed differently than other resources because their
1399 * layout is substantially different from other resources.
1400 * The table is parsed through a _global_ variable 'tagstt' which holds the
1401 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1402 * list of stringtables of different languages.
1405 : stt_head tBEGIN strings tEND {
1408 yyerror("Stringtable must have at least one entry");
1413 /* Check if we added to a language table or created
1416 for(stt = sttres; stt; stt = stt->next)
1423 /* It is a new one */
1426 sttres->prev = tagstt;
1427 tagstt->next = sttres;
1433 /* Else were done */
1437 free(tagstt_memopt);
1438 tagstt_memopt = NULL;
1445 /* This is to get the language of the currently parsed stringtable */
1446 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1447 if((tagstt = find_stringtable($3)) == NULL)
1448 tagstt = new_stringtable($3);
1450 tagstt_version = $3->version;
1451 tagstt_characts = $3->characts;
1457 strings : /* Empty */ { $$ = NULL; }
1458 | strings expr opt_comma tSTRING {
1460 assert(tagstt != NULL);
1461 if($2 > 65535 || $2 < -32768)
1462 yyerror("Stringtable entry's ID out of range (%d)", $2);
1463 /* Search for the ID */
1464 for(i = 0; i < tagstt->nentries; i++)
1466 if(tagstt->entries[i].id == $2)
1467 yyerror("Stringtable ID %d already in use", $2);
1469 /* If we get here, then we have a new unique entry */
1471 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1472 tagstt->entries[tagstt->nentries-1].id = $2;
1473 tagstt->entries[tagstt->nentries-1].str = $4;
1475 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1477 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1478 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1479 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1481 if(pedantic && !$4->size)
1482 yywarning("Zero length strings make no sense");
1483 if(!win32 && $4->size > 254)
1484 yyerror("Stringtable entry more than 254 characters");
1485 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1486 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1491 opt_comma /* There seem to be two ways to specify a stringtable... */
1496 /* ------------------------------ VersionInfo ------------------------------ */
1498 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1506 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1507 $$->blocks = get_ver_block_head($5);
1508 /* Set language; there is no version or characteristics */
1509 $$->lvc.language = dup_language(currentlanguage);
1514 : /* Empty */ { $$ = new_versioninfo(); }
1515 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1517 yyerror("FILEVERSION already defined");
1519 $$->filever_maj1 = $3;
1520 $$->filever_maj2 = $5;
1521 $$->filever_min1 = $7;
1522 $$->filever_min2 = $9;
1525 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1527 yyerror("PRODUCTVERSION already defined");
1529 $$->prodver_maj1 = $3;
1530 $$->prodver_maj2 = $5;
1531 $$->prodver_min1 = $7;
1532 $$->prodver_min2 = $9;
1535 | fix_version tFILEFLAGS expr {
1537 yyerror("FILEFLAGS already defined");
1542 | fix_version tFILEFLAGSMASK expr {
1544 yyerror("FILEFLAGSMASK already defined");
1546 $$->fileflagsmask = $3;
1549 | fix_version tFILEOS expr {
1551 yyerror("FILEOS already defined");
1556 | fix_version tFILETYPE expr {
1558 yyerror("FILETYPE already defined");
1563 | fix_version tFILESUBTYPE expr {
1565 yyerror("FILESUBTYPE already defined");
1567 $$->filesubtype = $3;
1573 : /* Empty */ { $$ = NULL; }
1574 | ver_blocks ver_block {
1583 : tBLOCK tSTRING tBEGIN ver_values tEND {
1584 $$ = new_ver_block();
1586 $$->values = get_ver_value_head($4);
1591 : /* Empty */ { $$ = NULL; }
1592 | ver_values ver_value {
1602 $$ = new_ver_value();
1603 $$->type = val_block;
1604 $$->value.block = $1;
1606 | tVALUE tSTRING ',' tSTRING {
1607 $$ = new_ver_value();
1612 | tVALUE tSTRING ',' ver_words {
1613 $$ = new_ver_value();
1614 $$->type = val_words;
1616 $$->value.words = $4;
1621 : expr { $$ = new_ver_words($1); }
1622 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1625 /* ------------------------------ Toolbar ------------------------------ */
1626 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1628 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1629 $$ = new_toolbar($3, $5, items, nitems);
1637 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1644 if(!$$->lvc.language)
1646 $$->lvc.language = dup_language(currentlanguage);
1652 : /* Empty */ { $$ = NULL; }
1653 | toolbar_items tBUTTON expr {
1654 toolbar_item_t *idrec = new_toolbar_item();
1656 $$ = ins_tlbr_button($1, idrec);
1658 | toolbar_items tSEPARATOR {
1659 toolbar_item_t *idrec = new_toolbar_item();
1661 $$ = ins_tlbr_button($1, idrec);
1665 /* ------------------------------ Memory options ------------------------------ */
1667 : /* Empty */ { $$ = NULL; }
1668 | loadmemopts lamo {
1678 | loadmemopts lama {
1687 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1693 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1694 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1695 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1696 | tPURE { $$ = new_int(WRC_MO_PURE); }
1699 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1700 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1701 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1704 /* ------------------------------ Win32 options ------------------------------ */
1705 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1706 | opt_lvc opt_language {
1708 yywarning("LANGUAGE not supported in 16-bit mode");
1710 yyerror("Language already defined");
1714 | opt_lvc opt_characts {
1716 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1718 yyerror("Characteristics already defined");
1722 | opt_lvc opt_version {
1724 yywarning("VERSION not supported in 16-bit mode");
1726 yyerror("Version already defined");
1733 * This here is another s/r conflict on {bi,u}nary + and -.
1734 * It is due to the look-ahead which must determine when the
1735 * rule opt_language ends. It could be solved with adding a
1736 * tNL at the end, but that seems unreasonable to do.
1737 * The conflict is now moved to the expression handling below.
1740 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4); }
1744 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1748 : tVERSION expr { $$ = new_version($2); }
1751 /* ------------------------------ Raw data handling ------------------------------ */
1752 raw_data: opt_lvc tBEGIN raw_elements tEND {
1759 if(!$3->lvc.language)
1760 $3->lvc.language = dup_language(currentlanguage);
1767 : tRAWDATA { $$ = $1; }
1768 | tNUMBER { $$ = int2raw_data($1); }
1769 | tLNUMBER { $$ = long2raw_data($1); }
1770 | tSTRING { $$ = str2raw_data($1); }
1771 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1772 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1773 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1774 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1777 /* File data or raw data */
1778 file_raw: filename {
1780 $$->lvc.language = dup_language(currentlanguage);
1782 | raw_data { $$ = $1; }
1785 /* ------------------------------ Win32 expressions ------------------------------ */
1786 /* All win16 numbers are also handled here. This is inconsistent with MS'
1787 * resource compiler, but what the heck, its just handy to have.
1789 e_expr : /* Empty */ { $$ = 0; }
1790 | expr { $$ = new_int($1); }
1793 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1794 expr : xpr { $$ = ($1); }
1797 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1798 | xpr '-' xpr { $$ = ($1) - ($3); }
1799 | xpr '|' xpr { $$ = ($1) | ($3); }
1800 | xpr '&' xpr { $$ = ($1) & ($3); }
1801 | xpr '*' xpr { $$ = ($1) * ($3); }
1802 | xpr '/' xpr { $$ = ($1) / ($3); }
1803 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1804 | '~' xpr { $$ = ~($2); }
1805 | '-' xpr %prec pUPM { $$ = -($2); }
1806 | '+' xpr %prec pUPM { $$ = $2; }
1807 | '(' xpr ')' { $$ = $2; }
1808 | any_num { $$ = $1; }
1809 | tNOT any_num { $$ = ~($2); }
1812 any_num : tNUMBER { $$ = $1; }
1813 | tLNUMBER { $$ = $1; }
1817 /* Dialog specific functions */
1818 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1820 assert(dlg != NULL);
1821 if(dlg->style == NULL)
1823 dlg->style = new_style(0,0);
1828 yywarning("Style already defined, or-ing together");
1832 dlg->style->or_mask = 0;
1833 dlg->style->and_mask = 0;
1835 dlg->style->or_mask |= st->or_mask;
1836 dlg->style->and_mask |= st->and_mask;
1837 dlg->gotstyle = TRUE;
1842 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1844 assert(dlg != NULL);
1845 if(dlg->exstyle == NULL)
1847 dlg->exstyle = new_style(0,0);
1852 yywarning("ExStyle already defined, or-ing together");
1856 dlg->exstyle->or_mask = 0;
1857 dlg->exstyle->and_mask = 0;
1859 dlg->exstyle->or_mask |= st->or_mask;
1860 dlg->exstyle->and_mask |= st->and_mask;
1861 dlg->gotexstyle = TRUE;
1866 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1868 assert(dlg != NULL);
1870 yyerror("Caption already defined");
1875 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1877 assert(dlg != NULL);
1879 yyerror("Font already defined");
1884 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1886 assert(dlg != NULL);
1888 yyerror("Class already defined");
1893 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1895 assert(dlg != NULL);
1897 yyerror("Menu already defined");
1902 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1904 assert(dlg != NULL);
1905 if(dlg->lvc.language)
1906 yyerror("Language already defined");
1907 dlg->lvc.language = l;
1911 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1913 assert(dlg != NULL);
1914 if(dlg->lvc.characts)
1915 yyerror("Characteristics already defined");
1916 dlg->lvc.characts = c;
1920 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1922 assert(dlg != NULL);
1923 if(dlg->lvc.version)
1924 yyerror("Version already defined");
1925 dlg->lvc.version = v;
1929 /* Controls specific functions */
1930 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1932 /* Hm... this seems to be jammed in at all time... */
1933 int defaultstyle = WS_CHILD | WS_VISIBLE;
1935 assert(ctrl != NULL);
1943 ctrl->ctlclass = new_name_id();
1944 ctrl->ctlclass->type = name_ord;
1945 ctrl->ctlclass->name.i_name = type;
1951 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1952 defaultstyle |= WS_TABSTOP;
1955 defaultstyle |= WS_TABSTOP | WS_BORDER;
1958 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1961 defaultstyle |= CBS_SIMPLE;
1964 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1965 defaultstyle |= WS_GROUP;
1969 if(!ctrl->gotstyle) /* Handle default style setting */
1974 defaultstyle |= ES_LEFT;
1977 defaultstyle |= LBS_NOTIFY;
1980 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1983 defaultstyle |= SBS_HORZ;
1986 switch(special_style)
1989 case BS_DEFPUSHBUTTON:
1992 /* case BS_PUSHBOX: */
1993 case BS_AUTORADIOBUTTON:
1996 case BS_AUTOCHECKBOX:
1997 defaultstyle |= WS_TABSTOP;
2000 yywarning("Unknown default button control-style 0x%08x", special_style);
2001 case BS_RADIOBUTTON:
2007 switch(special_style)
2012 defaultstyle |= WS_GROUP;
2014 case SS_ICON: /* Special case */
2017 yywarning("Unknown default static control-style 0x%08x", special_style);
2021 case -1: /* Generic control */
2025 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2029 /* The SS_ICON flag is always forced in for icon controls */
2030 if(type == CT_STATIC && special_style == SS_ICON)
2031 defaultstyle |= SS_ICON;
2033 if (!ctrl->gotstyle)
2034 ctrl->style = new_style(0,0);
2036 /* combine all styles */
2037 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2038 ctrl->gotstyle = TRUE;
2040 /* combine with NOT mask */
2043 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2044 ctrl->style->and_mask = 0;
2046 if (ctrl->gotexstyle)
2048 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2049 ctrl->exstyle->and_mask = 0;
2054 static name_id_t *convert_ctlclass(name_id_t *cls)
2059 if(cls->type == name_ord)
2061 assert(cls->type == name_str);
2062 if(cls->type == str_unicode)
2064 yyerror("Don't yet support unicode class comparison");
2067 cc = cls->name.s_name->str.cstr;
2069 if(!strcasecmp("BUTTON", cc))
2071 else if(!strcasecmp("COMBOBOX", cc))
2072 iclass = CT_COMBOBOX;
2073 else if(!strcasecmp("LISTBOX", cc))
2074 iclass = CT_LISTBOX;
2075 else if(!strcasecmp("EDIT", cc))
2077 else if(!strcasecmp("STATIC", cc))
2079 else if(!strcasecmp("SCROLLBAR", cc))
2080 iclass = CT_SCROLLBAR;
2082 return cls; /* No default, return user controlclass */
2084 free(cls->name.s_name->str.cstr);
2085 free(cls->name.s_name);
2086 cls->type = name_ord;
2087 cls->name.i_name = iclass;
2091 /* DialogEx specific functions */
2092 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2094 assert(dlg != NULL);
2095 if(dlg->style == NULL)
2097 dlg->style = new_style(0,0);
2102 yywarning("Style already defined, or-ing together");
2106 dlg->style->or_mask = 0;
2107 dlg->style->and_mask = 0;
2109 dlg->style->or_mask |= st->or_mask;
2110 dlg->style->and_mask |= st->and_mask;
2111 dlg->gotstyle = TRUE;
2116 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2118 assert(dlg != NULL);
2119 if(dlg->exstyle == NULL)
2121 dlg->exstyle = new_style(0,0);
2126 yywarning("ExStyle already defined, or-ing together");
2130 dlg->exstyle->or_mask = 0;
2131 dlg->exstyle->and_mask = 0;
2133 dlg->exstyle->or_mask |= st->or_mask;
2134 dlg->exstyle->and_mask |= st->and_mask;
2135 dlg->gotexstyle = TRUE;
2140 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2142 assert(dlg != NULL);
2144 yyerror("Caption already defined");
2149 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2151 assert(dlg != NULL);
2153 yyerror("Font already defined");
2158 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2160 assert(dlg != NULL);
2162 yyerror("Class already defined");
2167 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2169 assert(dlg != NULL);
2171 yyerror("Menu already defined");
2176 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2178 assert(dlg != NULL);
2179 if(dlg->lvc.language)
2180 yyerror("Language already defined");
2181 dlg->lvc.language = l;
2185 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2187 assert(dlg != NULL);
2188 if(dlg->lvc.characts)
2189 yyerror("Characteristics already defined");
2190 dlg->lvc.characts = c;
2194 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2196 assert(dlg != NULL);
2197 if(dlg->lvc.version)
2198 yyerror("Version already defined");
2199 dlg->lvc.version = v;
2203 /* Accelerator specific functions */
2204 static event_t *add_event(int key, int id, int flags, event_t *prev)
2206 event_t *ev = new_event();
2208 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2209 yyerror("Cannot use both ASCII and VIRTKEY");
2213 ev->flags = flags & ~WRC_AF_ASCII;
2220 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2223 event_t *ev = new_event();
2225 if(key->type != str_char)
2226 yyerror("Key code must be an ascii string");
2228 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
2229 yyerror("VIRTKEY code is not equal to ascii value");
2231 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2233 yyerror("Cannot use both '^' and CONTROL modifier");
2235 else if(key->str.cstr[0] == '^')
2237 keycode = toupper(key->str.cstr[1]) - '@';
2239 yyerror("Control-code out of range");
2242 keycode = key->str.cstr[0];
2245 ev->flags = flags & ~WRC_AF_ASCII;
2252 /* MenuEx specific functions */
2253 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2255 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2259 opt->helpid = helpid;
2263 /* Raw data functions */
2264 static raw_data_t *load_file(string_t *name)
2268 if(name->type != str_char)
2269 yyerror("Filename must be ASCII string");
2271 fp = open_include(name->str.cstr, 1, NULL);
2273 yyerror("Cannot open file %s", name->str.cstr);
2274 rd = new_raw_data();
2275 fseek(fp, 0, SEEK_END);
2276 rd->size = ftell(fp);
2277 fseek(fp, 0, SEEK_SET);
2278 rd->data = (char *)xmalloc(rd->size);
2279 fread(rd->data, rd->size, 1, fp);
2284 static raw_data_t *int2raw_data(int i)
2288 if((int)((short)i) != i)
2289 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2291 rd = new_raw_data();
2292 rd->size = sizeof(short);
2293 rd->data = (char *)xmalloc(rd->size);
2296 #ifdef WORDS_BIGENDIAN
2300 rd->data[0] = HIBYTE(i);
2301 rd->data[1] = LOBYTE(i);
2304 #ifndef WORDS_BIGENDIAN
2308 rd->data[1] = HIBYTE(i);
2309 rd->data[0] = LOBYTE(i);
2315 static raw_data_t *long2raw_data(int i)
2318 rd = new_raw_data();
2319 rd->size = sizeof(int);
2320 rd->data = (char *)xmalloc(rd->size);
2323 #ifdef WORDS_BIGENDIAN
2327 rd->data[0] = HIBYTE(HIWORD(i));
2328 rd->data[1] = LOBYTE(HIWORD(i));
2329 rd->data[2] = HIBYTE(LOWORD(i));
2330 rd->data[3] = LOBYTE(LOWORD(i));
2333 #ifndef WORDS_BIGENDIAN
2337 rd->data[3] = HIBYTE(HIWORD(i));
2338 rd->data[2] = LOBYTE(HIWORD(i));
2339 rd->data[1] = HIBYTE(LOWORD(i));
2340 rd->data[0] = LOBYTE(LOWORD(i));
2346 static raw_data_t *str2raw_data(string_t *str)
2349 rd = new_raw_data();
2350 rd->size = str->size * (str->type == str_char ? 1 : 2);
2351 rd->data = (char *)xmalloc(rd->size);
2352 if(str->type == str_char)
2353 memcpy(rd->data, str->str.cstr, rd->size);
2354 else if(str->type == str_unicode)
2359 #ifdef WORDS_BIGENDIAN
2363 for(i = 0; i < str->size; i++)
2365 rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
2366 rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
2369 #ifndef WORDS_BIGENDIAN
2373 for(i = 0; i < str->size; i++)
2375 rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
2376 rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
2382 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2386 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2388 r1->data = xrealloc(r1->data, r1->size + r2->size);
2389 memcpy(r1->data + r1->size, r2->data, r2->size);
2390 r1->size += r2->size;
2394 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2396 raw_data_t *t = int2raw_data(i);
2397 merge_raw_data(r1, t);
2403 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2405 raw_data_t *t = long2raw_data(i);
2406 merge_raw_data(r1, t);
2412 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2414 raw_data_t *t = str2raw_data(str);
2415 merge_raw_data(r1, t);
2421 /* Function the go back in a list to get the head */
2422 static menu_item_t *get_item_head(menu_item_t *p)
2431 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2440 static resource_t *get_resource_head(resource_t *p)
2449 static ver_block_t *get_ver_block_head(ver_block_t *p)
2458 static ver_value_t *get_ver_value_head(ver_value_t *p)
2467 static control_t *get_control_head(control_t *p)
2476 static event_t *get_event_head(event_t *p)
2485 /* Find a stringtable with given language */
2486 static stringtable_t *find_stringtable(lvc_t *lvc)
2490 assert(lvc != NULL);
2493 lvc->language = dup_language(currentlanguage);
2495 for(stt = sttres; stt; stt = stt->next)
2497 if(stt->lvc.language->id == lvc->language->id
2498 && stt->lvc.language->sub == lvc->language->sub)
2500 /* Found a table with the same language */
2501 /* The version and characteristics are now handled
2502 * in the generation of the individual stringtables.
2503 * This enables localized analysis.
2504 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2505 || (!stt->lvc.version && lvc->version)
2506 || (stt->lvc.version && !lvc->version))
2507 yywarning("Stringtable's versions are not the same, using first definition");
2509 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2510 || (!stt->lvc.characts && lvc->characts)
2511 || (stt->lvc.characts && !lvc->characts))
2512 yywarning("Stringtable's characteristics are not the same, using first definition");
2520 /* qsort sorting function for string table entries */
2521 #define STE(p) ((stt_entry_t *)(p))
2522 static int sort_stt_entry(const void *e1, const void *e2)
2524 return STE(e1)->id - STE(e2)->id;
2528 static resource_t *build_stt_resources(stringtable_t *stthead)
2531 stringtable_t *newstt;
2533 resource_t *rsclist = NULL;
2534 resource_t *rsctail = NULL;
2539 characts_t *characts;
2545 /* For all languages defined */
2546 for(stt = stthead; stt; stt = stt->next)
2548 assert(stt->nentries > 0);
2550 /* Sort the entries */
2551 if(stt->nentries > 1)
2552 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2554 for(i = 0; i < stt->nentries; )
2556 newstt = new_stringtable(&stt->lvc);
2557 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2558 newstt->nentries = 16;
2559 newstt->idbase = stt->entries[i].id & ~0xf;
2560 for(j = 0; j < 16 && i < stt->nentries; j++)
2562 if(stt->entries[i].id - newstt->idbase == j)
2564 newstt->entries[j] = stt->entries[i];
2572 /* Check individual memory options and get
2573 * the first characteristics/version
2575 for(j = 0; j < 16; j++)
2577 if(!newstt->entries[j].str)
2579 andsum &= newstt->entries[j].memopt;
2580 orsum |= newstt->entries[j].memopt;
2582 characts = newstt->entries[j].characts;
2584 version = newstt->entries[j].version;
2588 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2590 /* Check version and characteristics */
2591 for(j = 0; j < 16; j++)
2594 && newstt->entries[j].characts
2595 && *newstt->entries[j].characts != *characts)
2596 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2598 && newstt->entries[j].version
2599 && *newstt->entries[j].version != *version)
2600 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2602 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2603 rsc->name = new_name_id();
2604 rsc->name->type = name_ord;
2605 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2606 rsc->memopt = andsum; /* Set to least common denominator */
2607 newstt->memopt = andsum;
2608 newstt->lvc.characts = characts;
2609 newstt->lvc.version = version;
2617 rsctail->next = rsc;
2618 rsc->prev = rsctail;
2627 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2636 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2655 static string_t *make_filename(string_t *str)
2659 if(str->type != str_char)
2660 yyerror("Cannot handle UNICODE filenames");
2662 /* Remove escaped backslash and convert to forward */
2663 cptr = str->str.cstr;
2664 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2668 memmove(cptr, cptr+1, strlen(cptr));
2674 /* Convert to lower case. Seems to be reasonable to do */
2675 for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
2677 *cptr = tolower(*cptr);
2683 * Process all resources to extract fonts and build
2684 * a fontdir resource.
2686 * Note: MS' resource compiler (build 1472) does not
2687 * handle font resources with different languages.
2688 * The fontdir is generated in the last active language
2689 * and font identifiers must be unique across the entire
2691 * This is not logical considering the localization
2692 * constraints of all other resource types. MS has,
2693 * most probably, never testet localized fonts. However,
2694 * using fontresources is rare, so it might not occur
2695 * in normal applications.
2696 * Wine does require better localization because a lot
2697 * of languages are coded into the same executable.
2698 * Therefore, I will generate fontdirs for *each*
2699 * localized set of fonts.
2701 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2703 static int once = 0;
2706 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
2712 static resource_t *build_fontdirs(resource_t *tail)
2715 resource_t *lst = NULL;
2716 resource_t **fnt = NULL; /* List of all fonts */
2718 resource_t **fnd = NULL; /* List of all fontdirs */
2720 resource_t **lanfnt = NULL;
2727 nid.type = name_str;
2728 nid.name.s_name = &str;
2729 str.type = str_char;
2730 str.str.cstr = "FONTDIR";
2733 /* Extract all fonts and fontdirs */
2734 for(rsc = tail; rsc; rsc = rsc->prev)
2736 if(rsc->type == res_fnt)
2739 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2742 else if(rsc->type == res_fntdir)
2745 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2750 /* Verify the name of the present fontdirs */
2751 for(i = 0; i < nfnd; i++)
2753 if(compare_name_id(&nid, fnd[i]->name))
2755 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2756 get_nameid_str(fnd[i]->name));
2765 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2770 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2772 /* Get all fonts covered by fontdirs */
2773 for(i = 0; i < nfnd; i++)
2781 for(j = 0; j < nfnt; j++)
2785 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2787 lanfnt[nlanfnt] = fnt[j];
2793 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2796 else if(nlanfnt == BYTESWAP_WORD(cnt))
2799 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2800 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2801 #ifdef WORDS_BIGENDIAN
2802 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2804 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2807 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2811 /* We now have fonts left where we need to make a fontdir resource */
2812 for(i = fntleft = 0; i < nfnt; i++)
2819 /* Get fonts of same language in lanfnt[] */
2820 for(i = nlanfnt = 0; i < nfnt; i++)
2827 lanfnt[nlanfnt] = fnt[i];
2832 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2836 /* and build a fontdir */
2837 rsc = build_fontdir(lanfnt, nlanfnt);
2859 * This gets invoked to determine whether the next resource
2860 * is to be of a standard-type (e.g. bitmaps etc.), or should
2861 * be a user-type resource. This function is required because
2862 * there is the _possibility_ of a lookahead token in the
2863 * parser, which is generated from the "expr" state in the
2866 * The general resource format is:
2867 * <identifier> <type> <flags> <resourcebody>
2869 * The <identifier> can either be tIDENT or "expr". The latter
2870 * will always generate a lookahead, which is the <type> of the
2871 * resource to parse. Otherwise, we need to get a new token from
2872 * the scanner to determine the next step.
2874 * The problem arrises when <type> is numerical. This case should
2875 * map onto default resource-types and be parsed as such instead
2876 * of being mapped onto user-type resources.
2878 * The trick lies in the fact that yacc (bison) doesn't care about
2879 * intermediate changes of the lookahead while reducing a rule. We
2880 * simply replace the lookahead with a token that will result in
2881 * a shift to the appropriate rule for the specific resource-type.
2883 static int rsrcid_to_token(int lookahead)
2888 /* Get a token if we don't have one yet */
2889 if(lookahead == YYEMPTY)
2892 /* Only numbers are possibly interesting */
2922 case WRC_RT_FONTDIR:
2930 case WRC_RT_MESSAGETABLE:
2931 type = "MESSAGETABLE";
2932 token = tMESSAGETABLE;
2934 case WRC_RT_DLGINIT:
2938 case WRC_RT_ACCELERATOR:
2939 type = "ACCELERATOR";
2940 token = tACCELERATORS;
2950 case WRC_RT_VERSION:
2952 token = tVERSIONINFO;
2954 case WRC_RT_TOOLBAR:
2960 type = "STRINGTABLE";
2963 case WRC_RT_ANICURSOR:
2964 case WRC_RT_ANIICON:
2965 case WRC_RT_GROUP_CURSOR:
2966 case WRC_RT_GROUP_ICON:
2967 yywarning("Usertype uses reserved type-ID %d, which is auto-generated", yylval.num);
2970 case WRC_RT_DLGINCLUDE:
2971 case WRC_RT_PLUGPLAY:
2974 yywarning("Usertype uses reserved type-ID %d, which is not supported by wrc", yylval.num);
2982 yywarning("Usertype uses reserved type-ID %d, which is used by %s", yylval.num, type);