3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 24-Jul-2000 BS - Made a fix for broken Berkeley yacc on
23 * non-terminals (see cjunk rule).
24 * 21-May-2000 BS - Partial implementation of font resources.
25 * - Corrected language propagation for binary
26 * resources such as bitmaps, icons, cursors,
27 * userres and rcdata. The language is now
28 * correct in .res files.
29 * - Fixed reading the resource name as ident,
30 * so that it may overlap keywords.
31 * 20-May-2000 BS - Implemented animated cursors and icons
33 * 30-Apr-2000 BS - Reintegration into the wine-tree
34 * 14-Jan-2000 BS - Redid the usertype resources so that they
36 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
37 * except for the # command (line numbers).
39 * 06-Nov-1999 JS - see CHANGES
41 * 29-Dec-1998 AdH - Grammar and function extensions.
42 * grammar: TOOLBAR resources, Named ICONs in
44 * functions: semantic actions for the grammar
45 * changes, resource files can now be anywhere
46 * on the include path instead of just in the
49 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
50 * printed out correctly.
52 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
53 * also accept a tSTRING as argument.
55 * 25-May-1998 BS - Found out that I need to support language, version
56 * and characteristics in inline resources (bitmap,
57 * cursor, etc) but they can also be specified with
58 * a filename. This renders my filename-scanning scheme
59 * worthless. Need to build newline parsing to solve
61 * It will come with version 1.1.0 (sigh).
63 * 19-May-1998 BS - Started to build a builtin preprocessor
65 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
66 * ideas had some serious flaws.
68 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
71 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
72 * - This file is growing too big. It is time to strip
73 * things and put it in a support file.
75 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
76 * resource will be created. This because the table
77 * has a different layout than other resources. The
78 * table has to be sorted, and divided into smaller
79 * resource entries (see comment in source).
81 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
82 * as string_t which include unicode strings upon
84 * - Parser now emits a warning when compiling win32
85 * extensions in win16 mode.
87 * 16-Apr-1998 BS - Raw data elements are now *optionally* separated
88 * by commas. Read the comments in file sq2dq.l.
89 * - FIXME: there are instances in the source that rely
90 * on the fact that int==32bit and pointers are int size.
91 * - Fixed the conflict in menuex by changing a rule
92 * back into right recursion. See note in source.
93 * - UserType resources cannot have an expression as its
94 * typeclass. See note in source.
96 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
97 * get reduction of the parsestack.
98 * This also helps communication between bison and flex.
99 * Main advantage is that the Empty rule gets reduced
100 * first, which is used to allocate/link things.
101 * It also added a shift/reduce conflict in the menuex
102 * handling, due to expression/option possibility,
103 * although not serious.
105 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
106 * about making it more efficient, but readable (for me)
107 * and slightly easier to expand/change.
108 * This is done primarily by using more reduce states
109 * with many (intuitive) types for the various resource
111 * - Added expression handling for all resources where a
112 * number is accepted (not only for win32). Also added
113 * multiply and division (not MS compatible, but handy).
114 * Unary minus introduced a shift/reduce conflict, but
117 * 13-Apr-1998 BS - Reordered a lot of things
118 * - Made the source more readable
119 * - Added Win32 resource definitions
120 * - Corrected syntax problems with an old yacc (;)
121 * - Added extra comment about grammar
124 #include "wine/port.h"
138 #include "newstruc.h"
140 #include "wine/wpp.h"
141 #include "wine/unicode.h"
149 /* Berkeley yacc (byacc) doesn't seem to know about these */
150 /* Some *BSD supplied versions do define these though */
152 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
155 # define YYLEX yylex()
158 #elif defined(YYBISON)
159 /* Bison was used for original development */
160 /* #define YYEMPTY -2 */
161 /* #define YYLEX yylex() */
164 /* No yacc we know yet */
165 # if !defined(YYEMPTY) || !defined(YYLEX)
166 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
167 # elif defined(__GNUC__) /* gcc defines the #warning directive */
168 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
169 /* #else we just take a chance that it works... */
173 int want_nl = 0; /* Signal flex that we need the next newline */
174 int want_id = 0; /* Signal flex that we need the next identifier */
175 stringtable_t *tagstt; /* Stringtable tag.
176 * It is set while parsing a stringtable to one of
177 * the stringtables in the sttres list or a new one
178 * if the language was not parsed before.
180 stringtable_t *sttres; /* Stringtable resources. This holds the list of
181 * stringtables with different lanuages
183 static int dont_want_id = 0; /* See language parsing for details */
185 /* Set to the current options of the currently scanning stringtable */
186 static int *tagstt_memopt;
187 static characts_t *tagstt_characts;
188 static version_t *tagstt_version;
190 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
192 /* Prototypes of here defined functions */
193 static event_t *get_event_head(event_t *p);
194 static control_t *get_control_head(control_t *p);
195 static ver_value_t *get_ver_value_head(ver_value_t *p);
196 static ver_block_t *get_ver_block_head(ver_block_t *p);
197 static resource_t *get_resource_head(resource_t *p);
198 static menuex_item_t *get_itemex_head(menuex_item_t *p);
199 static menu_item_t *get_item_head(menu_item_t *p);
200 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
201 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
202 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
203 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
204 static raw_data_t *str2raw_data(string_t *str);
205 static raw_data_t *int2raw_data(int i);
206 static raw_data_t *long2raw_data(int i);
207 static raw_data_t *load_file(string_t *name, language_t *lang);
208 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
209 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
210 static event_t *add_event(int key, int id, int flags, event_t *prev);
211 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
212 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
213 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
214 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
215 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
216 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
217 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
218 static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
219 static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
220 static name_id_t *convert_ctlclass(name_id_t *cls);
221 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
222 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
223 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
224 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
225 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
226 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
227 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
228 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
229 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
230 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
231 static resource_t *build_stt_resources(stringtable_t *stthead);
232 static stringtable_t *find_stringtable(lvc_t *lvc);
233 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
234 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
235 static string_t *make_filename(string_t *s);
236 static resource_t *build_fontdirs(resource_t *tail);
237 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
238 static int rsrcid_to_token(int lookahead);
270 menuex_item_t *menexitm;
278 toolbar_item_t *tlbarItems;
280 style_pair_t *styles;
286 %token <num> tNUMBER tLNUMBER
287 %token <str> tSTRING tIDENT tFILENAME
288 %token <raw> tRAWDATA
289 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
290 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
291 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
292 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
293 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
294 %token tCONTROL tEDITTEXT
295 %token tRTEXT tCTEXT tLTEXT
297 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
298 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
299 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
300 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
301 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
303 %token tSTRING tIDENT tRAWDATA
304 %token tTOOLBAR tBUTTON
315 %type <res> resource_file resource resources resource_definition
316 %type <stt> stringtable strings
319 %type <acc> accelerators
322 %type <ani> cursor icon
323 %type <dlg> dialog dlg_attributes
324 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
326 %type <dlgex> dialogex dlgex_attribs
327 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
330 %type <raw> raw_data raw_elements opt_data file_raw
331 %type <veri> versioninfo fix_version
332 %type <verw> ver_words
333 %type <blk> ver_blocks ver_block
334 %type <val> ver_values ver_value
336 %type <menitm> item_definitions menu_body
338 %type <menexitm> itemex_definitions menuex_body
339 %type <exopt> itemex_p_options itemex_options
340 %type <msg> messagetable
342 %type <num> item_options
343 %type <nid> nameid nameid_s ctlclass usertype
344 %type <num> acc_opt acc accs
345 %type <iptr> loadmemopts lamo lama
346 %type <fntid> opt_font opt_exfont opt_expr
348 %type <lan> opt_language
349 %type <chars> opt_characts
350 %type <ver> opt_version
353 %type <tlbar> toolbar
354 %type <tlbarItems> toolbar_items
355 %type <dginit> dlginit
356 %type <styles> optional_style_pair
366 /* First add stringtables to the resource-list */
367 rsc = build_stt_resources(sttres);
368 /* 'build_stt_resources' returns a head and $1 is a tail */
377 /* Find the tail again */
378 while($1 && $1->next)
380 /* Now add any fontdirecory */
381 rsc = build_fontdirs($1);
382 /* 'build_fontdir' returns a head and $1 is a tail */
391 /* Final statement before were done */
392 resource_top = get_resource_head($1);
396 /* Resources are put into a linked list */
398 : /* Empty */ { $$ = NULL; want_id = 1; }
399 | resources resource {
402 resource_t *tail = $2;
403 resource_t *head = $2;
412 /* Check for duplicate identifiers */
415 resource_t *rsc = $1;
418 if(rsc->type == head->type
419 && rsc->lan->id == head->lan->id
420 && rsc->lan->sub == head->lan->sub
421 && !compare_name_id(rsc->name, head->name))
423 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
432 resource_t *tail = $1;
440 if(!dont_want_id) /* See comments in language parsing below */
445 * The following newline rule will never get reduced because we never
446 * get the tNL token, unless we explicitely set the 'want_nl'
447 * flag, which we don't.
448 * The *ONLY* reason for this to be here is because Berkeley
449 * yacc (byacc), at least version 1.9, has a bug.
450 * (identified in the generated parser on the second
452 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
454 * This extra rule fixes it.
455 * The problem is that the expression handling rule "expr: xpr"
456 * is not reduced on non-terminal tokens, defined above in the
457 * %token declarations. Token tNL is the only non-terminal that
458 * can occur. The error becomes visible in the language parsing
459 * rule below, which looks at the look-ahead token and tests it
460 * for tNL. However, byacc already generates an error upon reading
461 * the token instead of keeping it as a lookahead. The reason
462 * lies in the lack of a $default transition in the "expr : xpr . "
463 * state (currently state 25). It is probably omitted because tNL
464 * is a non-terminal and the state contains 2 s/r conflicts. The
465 * state enumerates all possible transitions instead of using a
466 * $default transition.
467 * All in all, it is a bug in byacc. (period)
473 /* Parse top level resource definitions etc. */
475 : expr usrcvt resource_definition {
479 if($1 > 65535 || $1 < -32768)
480 yyerror("Resource's ID out of range (%d)", $1);
481 $$->name = new_name_id();
482 $$->name->type = name_ord;
483 $$->name->name.i_name = $1;
484 chat("Got %s (%d)", get_typename($3), $$->name->name.i_name);
487 | tIDENT usrcvt resource_definition {
491 $$->name = new_name_id();
492 $$->name->type = name_str;
493 $$->name->name.s_name = $1;
494 chat("Got %s (%s)", get_typename($3), $$->name->name.s_name->str.cstr);
498 /* Don't do anything, stringtables are converted to
499 * resource_t structures when we are finished parsing and
500 * the final rule of the parser is reduced (see above)
503 chat("Got STRINGTABLE");
505 | tLANGUAGE {want_nl = 1; } expr ',' expr {
506 /* We *NEED* the newline to delimit the expression.
507 * Otherwise, we would not be able to set the next
508 * want_id anymore because of the token-lookahead.
510 * However, we can test the lookahead-token for
511 * being "non-expression" type, in which case we
512 * continue. Fortunately, tNL is the only token that
513 * will break expression parsing and is implicitely
514 * void, so we just remove it. This scheme makes it
515 * possible to do some (not all) fancy preprocessor
517 * BTW, we also need to make sure that the next
518 * reduction of 'resources' above will *not* set
519 * want_id because we already have a lookahead that
522 if(yychar != YYEMPTY && yychar != tNL)
526 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
527 /* direct access to yychar in rule 'usrcvt' below. */
528 else if(yychar == tIDENT)
529 yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
531 want_nl = 0; /* We don't want it anymore if we didn't get it */
534 yywarning("LANGUAGE not supported in 16-bit mode");
536 free(currentlanguage);
537 if (get_language_codepage($3, $5) == -1)
538 yyerror( "Language %04x is not supported", ($5<<10) + $3);
539 currentlanguage = new_language($3, $5);
541 chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
546 * Remapping of numerical resource types
547 * (see also comment of called function below)
549 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
553 * Get a valid name/id
556 if($1 > 65535 || $1 < -32768)
557 yyerror("Resource's ID out of range (%d)", $1);
560 $$->name.i_name = $1;
565 $$->name.s_name = $1;
570 * Extra string recognition for CLASS statement in dialogs
572 nameid_s: nameid { $$ = $1; }
576 $$->name.s_name = $1;
580 /* get the value for a single resource*/
582 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
583 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
586 if($1->type == res_anicur)
588 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
590 else if($1->type == res_curg)
593 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
594 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
596 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
597 rsc->prev->next = rsc;
599 rsc->name = new_name_id();
600 rsc->name->type = name_ord;
601 rsc->name->name.i_name = cur->id;
605 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
608 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
611 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
615 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
616 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
617 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
620 if($1->type == res_aniico)
622 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
624 else if($1->type == res_icog)
627 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
628 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
630 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
631 rsc->prev->next = rsc;
633 rsc->name = new_name_id();
634 rsc->name->type = name_ord;
635 rsc->name->name.i_name = ico->id;
639 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
642 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
645 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
649 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
650 | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
651 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
652 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
653 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
654 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
658 filename: tFILENAME { $$ = make_filename($1); }
659 | tIDENT { $$ = make_filename($1); }
660 | tSTRING { $$ = make_filename($1); }
663 /* ------------------------------ Bitmap ------------------------------ */
664 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
667 /* ------------------------------ Cursor ------------------------------ */
668 cursor : tCURSOR loadmemopts file_raw {
670 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
672 $$->type = res_anicur;
673 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
678 $$->u.curg = new_cursor_group($3, $2);
683 /* ------------------------------ Icon ------------------------------ */
684 icon : tICON loadmemopts file_raw {
686 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
688 $$->type = res_aniico;
689 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
694 $$->u.icog = new_icon_group($3, $2);
699 /* ------------------------------ Font ------------------------------ */
701 * The reading of raw_data for fonts is a Borland BRC
702 * extension. MS generates an error. However, it is
703 * most logical to support this, considering how wine
704 * enters things in CVS (ascii).
706 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
710 * The fontdir is a Borland BRC extension which only
711 * reads the data as 'raw_data' from the file.
712 * I don't know whether it is interpreted.
713 * The fontdir is generated if it was not present and
714 * fonts are defined in the source.
716 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
719 /* ------------------------------ MessageTable ------------------------------ */
720 /* It might be interesting to implement the MS Message compiler here as well
721 * to get everything in one source. Might be a future project.
724 : tMESSAGETABLE loadmemopts file_raw {
726 yywarning("MESSAGETABLE not supported in 16-bit mode");
727 $$ = new_messagetable($3, $2);
731 /* ------------------------------ HTML ------------------------------ */
732 html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
735 /* ------------------------------ RCData ------------------------------ */
736 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
739 /* ------------------------------ DLGINIT ------------------------------ */
740 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
743 /* ------------------------------ UserType ------------------------------ */
744 userres : usertype loadmemopts file_raw {
745 #ifdef WORDS_BIGENDIAN
746 if(pedantic && byteorder != WRC_BO_LITTLE)
748 if(pedantic && byteorder == WRC_BO_BIG)
750 yywarning("Byteordering is not little-endian and type cannot be interpreted");
751 $$ = new_user($1, $3, $2);
758 $$->name.i_name = $1;
763 $$->name.s_name = $1;
767 /* ------------------------------ Accelerator ------------------------------ */
769 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
770 $$ = new_accelerator();
778 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
781 yyerror("Accelerator table must have at least one entry");
782 $$->events = get_event_head($5);
788 if(!$$->lvc.language)
789 $$->lvc.language = dup_language(currentlanguage);
793 events : /* Empty */ { $$=NULL; }
794 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
795 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
799 * The empty rule generates a s/r conflict because of {bi,u}nary expr
800 * on - and +. It cannot be solved in any way because it is the same as
801 * the if/then/else problem (LALR(1) problem). The conflict is moved
802 * away by forcing it to be in the expression handling below.
804 acc_opt : /* Empty */ { $$ = 0; }
805 | ',' accs { $$ = $2; }
808 accs : acc { $$ = $1; }
809 | accs ',' acc { $$ = $1 | $3; }
812 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
813 | tSHIFT { $$ = WRC_AF_SHIFT; }
814 | tCONTROL { $$ = WRC_AF_CONTROL; }
815 | tALT { $$ = WRC_AF_ALT; }
816 | tASCII { $$ = WRC_AF_ASCII; }
817 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
820 /* ------------------------------ Dialog ------------------------------ */
821 /* FIXME: Support EXSTYLE in the dialog line itself */
822 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
830 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
835 $10->controls = get_control_head($12);
839 $$->style = new_style(0,0);
840 $$->style->or_mask = WS_POPUP;
844 $$->style->or_mask |= WS_CAPTION;
846 $$->style->or_mask |= DS_SETFONT;
848 $$->style->or_mask &= ~($$->style->and_mask);
849 $$->style->and_mask = 0;
851 if(!$$->lvc.language)
852 $$->lvc.language = dup_language(currentlanguage);
857 : /* Empty */ { $$=new_dialog(); }
858 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
859 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
860 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
861 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
862 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
863 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
864 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
865 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
866 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
869 ctrls : /* Empty */ { $$ = NULL; }
870 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
871 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
872 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
873 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
874 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
875 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
876 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
877 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
878 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
879 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
880 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
881 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
882 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
883 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
884 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
885 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
886 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
887 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
888 /* special treatment for icons, as the extent is optional */
889 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
894 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
899 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
901 $$->title = new_name_id();
902 $$->title->type = name_str;
903 $$->title->name.s_name = $1;
911 $$->style = $12->style;
915 $$->exstyle = $12->exstyle;
916 $$->gotexstyle = TRUE;
924 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
933 $$->style = $10->style;
937 $$->exstyle = $10->exstyle;
938 $$->gotexstyle = TRUE;
945 iconinfo: /* Empty */
946 { $$ = new_control(); }
948 | ',' expr ',' expr {
953 | ',' expr ',' expr ',' style {
960 | ',' expr ',' expr ',' style ',' style {
967 $$->gotexstyle = TRUE;
971 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
975 $$->ctlclass = convert_ctlclass($5);
983 $$->gotexstyle = TRUE;
985 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
989 $$->ctlclass = convert_ctlclass($5);
1000 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
1003 /* ------------------------------ style flags ------------------------------ */
1005 : /* Empty */ { $$ = NULL; }
1006 | ',' style { $$ = new_style_pair($2, 0); }
1007 | ',' style ',' style { $$ = new_style_pair($2, $4); }
1011 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
1012 | '(' style ')' { $$ = $2; }
1013 | any_num { $$ = new_style($1, 0); }
1014 | tNOT any_num { $$ = new_style(0, $2); }
1020 $$->type = name_ord;
1021 $$->name.i_name = $1;
1025 $$->type = name_str;
1026 $$->name.s_name = $1;
1030 /* ------------------------------ DialogEx ------------------------------ */
1031 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
1032 tBEGIN exctrls tEND {
1034 yywarning("DIALOGEX not supported in 16-bit mode");
1037 $11->memopt = *($2);
1041 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1048 $11->helpid = *($10);
1049 $11->gothelpid = TRUE;
1052 $11->controls = get_control_head($13);
1055 assert($$->style != NULL);
1058 $$->style->or_mask = WS_POPUP;
1059 $$->gotstyle = TRUE;
1062 $$->style->or_mask |= WS_CAPTION;
1064 $$->style->or_mask |= DS_SETFONT;
1066 $$->style->or_mask &= ~($$->style->and_mask);
1067 $$->style->and_mask = 0;
1069 if(!$$->lvc.language)
1070 $$->lvc.language = dup_language(currentlanguage);
1075 : /* Empty */ { $$=new_dialogex(); }
1076 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
1077 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
1078 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1079 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1080 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1081 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1082 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1083 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1084 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1085 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1088 exctrls : /* Empty */ { $$ = NULL; }
1089 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1090 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1091 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1092 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1093 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1094 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1095 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1096 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1097 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1098 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1099 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1100 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1101 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1102 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1103 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1104 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1105 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1106 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1107 /* special treatment for icons, as the extent is optional */
1108 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1113 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1118 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1119 expr ',' style helpid opt_data {
1123 $$->ctlclass = convert_ctlclass($5);
1125 $$->gotstyle = TRUE;
1133 $$->gotexstyle = TRUE;
1137 $$->helpid = *($18);
1138 $$->gothelpid = TRUE;
1143 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1148 $$->gotstyle = TRUE;
1149 $$->ctlclass = convert_ctlclass($5);
1159 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1161 $$->title = new_name_id();
1162 $$->title->type = name_str;
1163 $$->title->name.s_name = $1;
1171 $$->style = $12->style;
1172 $$->gotstyle = TRUE;
1176 $$->exstyle = $12->exstyle;
1177 $$->gotexstyle = TRUE;
1187 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1196 $$->style = $10->style;
1197 $$->gotstyle = TRUE;
1201 $$->exstyle = $10->exstyle;
1202 $$->gotexstyle = TRUE;
1210 opt_data: /* Empty */ { $$ = NULL; }
1211 | raw_data { $$ = $1; }
1214 helpid : /* Empty */ { $$ = NULL; }
1215 | ',' expr { $$ = new_int($2); }
1219 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1223 * FIXME: This odd expression is here to nullify an extra token found
1224 * in some appstudio produced resources which appear to do nothing.
1226 opt_expr: /* Empty */ { $$ = NULL; }
1227 | ',' expr { $$ = NULL; }
1230 /* ------------------------------ Menu ------------------------------ */
1231 menu : tMENU loadmemopts opt_lvc menu_body {
1233 yyerror("Menu must contain items");
1241 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1242 $$->items = get_item_head($4);
1248 if(!$$->lvc.language)
1249 $$->lvc.language = dup_language(currentlanguage);
1254 : tBEGIN item_definitions tEND { $$ = $2; }
1258 : /* Empty */ {$$ = NULL;}
1259 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1268 | item_definitions tMENUITEM tSEPARATOR {
1274 | item_definitions tPOPUP tSTRING item_options menu_body {
1275 $$ = new_menu_item();
1279 $$->popup = get_item_head($5);
1284 /* NOTE: item_options is right recursive because it would introduce
1285 * a shift/reduce conflict on ',' in itemex_options due to the
1286 * empty rule here. The parser is now forced to look beyond the ','
1287 * before reducing (force shift).
1288 * Right recursion here is not a problem because we cannot expect
1289 * more than 7 parserstack places to be occupied while parsing this
1290 * (who would want to specify a MF_x flag twice?).
1293 : /* Empty */ { $$ = 0; }
1294 | opt_comma tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1295 | opt_comma tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1296 | opt_comma tHELP item_options { $$ = $3 | MF_HELP; }
1297 | opt_comma tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1298 | opt_comma tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1299 | opt_comma tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1302 /* ------------------------------ MenuEx ------------------------------ */
1303 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1305 yywarning("MENUEX not supported in 16-bit mode");
1307 yyerror("MenuEx must contain items");
1315 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1316 $$->items = get_itemex_head($4);
1322 if(!$$->lvc.language)
1323 $$->lvc.language = dup_language(currentlanguage);
1328 : tBEGIN itemex_definitions tEND { $$ = $2; }
1332 : /* Empty */ {$$ = NULL; }
1333 | itemex_definitions tMENUITEM tSTRING itemex_options {
1334 $$ = new_menuex_item();
1340 $$->type = $4->type;
1341 $$->state = $4->state;
1342 $$->helpid = $4->helpid;
1343 $$->gotid = $4->gotid;
1344 $$->gottype = $4->gottype;
1345 $$->gotstate = $4->gotstate;
1346 $$->gothelpid = $4->gothelpid;
1349 | itemex_definitions tMENUITEM tSEPARATOR {
1350 $$ = new_menuex_item();
1355 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1356 $$ = new_menuex_item();
1360 $$->popup = get_itemex_head($5);
1363 $$->type = $4->type;
1364 $$->state = $4->state;
1365 $$->helpid = $4->helpid;
1366 $$->gotid = $4->gotid;
1367 $$->gottype = $4->gottype;
1368 $$->gotstate = $4->gotstate;
1369 $$->gothelpid = $4->gothelpid;
1375 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1377 $$ = new_itemex_opt($2, 0, 0, 0);
1380 | ',' e_expr ',' e_expr item_options {
1381 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1384 $$->gotstate = TRUE;
1388 | ',' e_expr ',' e_expr ',' expr {
1389 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1392 $$->gotstate = TRUE;
1399 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1401 $$ = new_itemex_opt($2, 0, 0, 0);
1404 | ',' e_expr ',' expr {
1405 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1410 | ',' e_expr ',' e_expr ',' expr {
1411 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1416 $$->gotstate = TRUE;
1418 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1419 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1425 $$->gotstate = TRUE;
1426 $$->gothelpid = TRUE;
1430 /* ------------------------------ StringTable ------------------------------ */
1431 /* Stringtables are parsed differently than other resources because their
1432 * layout is substantially different from other resources.
1433 * The table is parsed through a _global_ variable 'tagstt' which holds the
1434 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1435 * list of stringtables of different languages.
1438 : stt_head tBEGIN strings tEND {
1441 yyerror("Stringtable must have at least one entry");
1446 /* Check if we added to a language table or created
1449 for(stt = sttres; stt; stt = stt->next)
1456 /* It is a new one */
1459 sttres->prev = tagstt;
1460 tagstt->next = sttres;
1466 /* Else were done */
1470 free(tagstt_memopt);
1471 tagstt_memopt = NULL;
1478 /* This is to get the language of the currently parsed stringtable */
1479 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1480 if((tagstt = find_stringtable($3)) == NULL)
1481 tagstt = new_stringtable($3);
1483 tagstt_version = $3->version;
1484 tagstt_characts = $3->characts;
1490 strings : /* Empty */ { $$ = NULL; }
1491 | strings expr opt_comma tSTRING {
1493 assert(tagstt != NULL);
1494 if($2 > 65535 || $2 < -32768)
1495 yyerror("Stringtable entry's ID out of range (%d)", $2);
1496 /* Search for the ID */
1497 for(i = 0; i < tagstt->nentries; i++)
1499 if(tagstt->entries[i].id == $2)
1500 yyerror("Stringtable ID %d already in use", $2);
1502 /* If we get here, then we have a new unique entry */
1504 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1505 tagstt->entries[tagstt->nentries-1].id = $2;
1506 tagstt->entries[tagstt->nentries-1].str = $4;
1508 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1510 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1511 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1512 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1514 if(pedantic && !$4->size)
1515 yywarning("Zero length strings make no sense");
1516 if(!win32 && $4->size > 254)
1517 yyerror("Stringtable entry more than 254 characters");
1518 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1519 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1524 opt_comma /* There seem to be two ways to specify a stringtable... */
1529 /* ------------------------------ VersionInfo ------------------------------ */
1531 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1539 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1540 $$->blocks = get_ver_block_head($5);
1541 /* Set language; there is no version or characteristics */
1542 $$->lvc.language = dup_language(currentlanguage);
1547 : /* Empty */ { $$ = new_versioninfo(); }
1548 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1550 yyerror("FILEVERSION already defined");
1552 $$->filever_maj1 = $3;
1553 $$->filever_maj2 = $5;
1554 $$->filever_min1 = $7;
1555 $$->filever_min2 = $9;
1558 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1560 yyerror("PRODUCTVERSION already defined");
1562 $$->prodver_maj1 = $3;
1563 $$->prodver_maj2 = $5;
1564 $$->prodver_min1 = $7;
1565 $$->prodver_min2 = $9;
1568 | fix_version tFILEFLAGS expr {
1570 yyerror("FILEFLAGS already defined");
1575 | fix_version tFILEFLAGSMASK expr {
1577 yyerror("FILEFLAGSMASK already defined");
1579 $$->fileflagsmask = $3;
1582 | fix_version tFILEOS expr {
1584 yyerror("FILEOS already defined");
1589 | fix_version tFILETYPE expr {
1591 yyerror("FILETYPE already defined");
1596 | fix_version tFILESUBTYPE expr {
1598 yyerror("FILESUBTYPE already defined");
1600 $$->filesubtype = $3;
1606 : /* Empty */ { $$ = NULL; }
1607 | ver_blocks ver_block {
1616 : tBLOCK tSTRING tBEGIN ver_values tEND {
1617 $$ = new_ver_block();
1619 $$->values = get_ver_value_head($4);
1624 : /* Empty */ { $$ = NULL; }
1625 | ver_values ver_value {
1635 $$ = new_ver_value();
1636 $$->type = val_block;
1637 $$->value.block = $1;
1639 | tVALUE tSTRING ',' tSTRING {
1640 $$ = new_ver_value();
1645 | tVALUE tSTRING ',' ver_words {
1646 $$ = new_ver_value();
1647 $$->type = val_words;
1649 $$->value.words = $4;
1654 : expr { $$ = new_ver_words($1); }
1655 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1658 /* ------------------------------ Toolbar ------------------------------ */
1659 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1661 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1662 $$ = new_toolbar($3, $5, items, nitems);
1670 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1677 if(!$$->lvc.language)
1679 $$->lvc.language = dup_language(currentlanguage);
1685 : /* Empty */ { $$ = NULL; }
1686 | toolbar_items tBUTTON expr {
1687 toolbar_item_t *idrec = new_toolbar_item();
1689 $$ = ins_tlbr_button($1, idrec);
1691 | toolbar_items tSEPARATOR {
1692 toolbar_item_t *idrec = new_toolbar_item();
1694 $$ = ins_tlbr_button($1, idrec);
1698 /* ------------------------------ Memory options ------------------------------ */
1700 : /* Empty */ { $$ = NULL; }
1701 | loadmemopts lamo {
1711 | loadmemopts lama {
1720 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1726 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1727 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1728 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1729 | tPURE { $$ = new_int(WRC_MO_PURE); }
1732 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1733 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1734 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1737 /* ------------------------------ Win32 options ------------------------------ */
1738 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1739 | opt_lvc opt_language {
1741 yywarning("LANGUAGE not supported in 16-bit mode");
1743 yyerror("Language already defined");
1747 | opt_lvc opt_characts {
1749 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1751 yyerror("Characteristics already defined");
1755 | opt_lvc opt_version {
1757 yywarning("VERSION not supported in 16-bit mode");
1759 yyerror("Version already defined");
1766 * This here is another s/r conflict on {bi,u}nary + and -.
1767 * It is due to the look-ahead which must determine when the
1768 * rule opt_language ends. It could be solved with adding a
1769 * tNL at the end, but that seems unreasonable to do.
1770 * The conflict is now moved to the expression handling below.
1773 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
1774 if (get_language_codepage($2, $4) == -1)
1775 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1780 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1784 : tVERSION expr { $$ = new_version($2); }
1787 /* ------------------------------ Raw data handling ------------------------------ */
1788 raw_data: opt_lvc tBEGIN raw_elements tEND {
1795 if(!$3->lvc.language)
1796 $3->lvc.language = dup_language(currentlanguage);
1803 : tRAWDATA { $$ = $1; }
1804 | tNUMBER { $$ = int2raw_data($1); }
1805 | '-' tNUMBER { $$ = int2raw_data(-($2)); }
1806 | tLNUMBER { $$ = long2raw_data($1); }
1807 | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
1808 | tSTRING { $$ = str2raw_data($1); }
1809 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1810 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1811 | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
1812 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1813 | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
1814 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1817 /* File data or raw data */
1818 file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
1819 | raw_data { $$ = $1; }
1822 /* ------------------------------ Win32 expressions ------------------------------ */
1823 /* All win16 numbers are also handled here. This is inconsistent with MS'
1824 * resource compiler, but what the heck, its just handy to have.
1826 e_expr : /* Empty */ { $$ = 0; }
1827 | expr { $$ = new_int($1); }
1830 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1831 expr : xpr { $$ = ($1); }
1834 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1835 | xpr '-' xpr { $$ = ($1) - ($3); }
1836 | xpr '|' xpr { $$ = ($1) | ($3); }
1837 | xpr '&' xpr { $$ = ($1) & ($3); }
1838 | xpr '*' xpr { $$ = ($1) * ($3); }
1839 | xpr '/' xpr { $$ = ($1) / ($3); }
1840 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1841 | '~' xpr { $$ = ~($2); }
1842 | '-' xpr %prec pUPM { $$ = -($2); }
1843 | '+' xpr %prec pUPM { $$ = $2; }
1844 | '(' xpr ')' { $$ = $2; }
1845 | any_num { $$ = $1; }
1846 | tNOT any_num { $$ = ~($2); }
1849 any_num : tNUMBER { $$ = $1; }
1850 | tLNUMBER { $$ = $1; }
1854 /* Dialog specific functions */
1855 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1857 assert(dlg != NULL);
1858 if(dlg->style == NULL)
1860 dlg->style = new_style(0,0);
1865 yywarning("Style already defined, or-ing together");
1869 dlg->style->or_mask = 0;
1870 dlg->style->and_mask = 0;
1872 dlg->style->or_mask |= st->or_mask;
1873 dlg->style->and_mask |= st->and_mask;
1874 dlg->gotstyle = TRUE;
1879 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1881 assert(dlg != NULL);
1882 if(dlg->exstyle == NULL)
1884 dlg->exstyle = new_style(0,0);
1889 yywarning("ExStyle already defined, or-ing together");
1893 dlg->exstyle->or_mask = 0;
1894 dlg->exstyle->and_mask = 0;
1896 dlg->exstyle->or_mask |= st->or_mask;
1897 dlg->exstyle->and_mask |= st->and_mask;
1898 dlg->gotexstyle = TRUE;
1903 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1905 assert(dlg != NULL);
1907 yyerror("Caption already defined");
1912 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1914 assert(dlg != NULL);
1916 yyerror("Font already defined");
1921 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1923 assert(dlg != NULL);
1925 yyerror("Class already defined");
1930 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1932 assert(dlg != NULL);
1934 yyerror("Menu already defined");
1939 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1941 assert(dlg != NULL);
1942 if(dlg->lvc.language)
1943 yyerror("Language already defined");
1944 dlg->lvc.language = l;
1948 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1950 assert(dlg != NULL);
1951 if(dlg->lvc.characts)
1952 yyerror("Characteristics already defined");
1953 dlg->lvc.characts = c;
1957 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1959 assert(dlg != NULL);
1960 if(dlg->lvc.version)
1961 yyerror("Version already defined");
1962 dlg->lvc.version = v;
1966 /* Controls specific functions */
1967 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1969 /* Hm... this seems to be jammed in at all time... */
1970 int defaultstyle = WS_CHILD | WS_VISIBLE;
1972 assert(ctrl != NULL);
1980 ctrl->ctlclass = new_name_id();
1981 ctrl->ctlclass->type = name_ord;
1982 ctrl->ctlclass->name.i_name = type;
1988 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1989 defaultstyle |= WS_TABSTOP;
1992 defaultstyle |= WS_TABSTOP | WS_BORDER;
1995 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1998 if (!(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
1999 defaultstyle |= CBS_SIMPLE;
2002 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
2003 defaultstyle |= WS_GROUP;
2007 if(!ctrl->gotstyle) /* Handle default style setting */
2012 defaultstyle |= ES_LEFT;
2015 defaultstyle |= LBS_NOTIFY;
2018 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
2021 defaultstyle |= SBS_HORZ;
2024 switch(special_style)
2027 case BS_DEFPUSHBUTTON:
2029 /* case BS_PUSHBOX: */
2030 case BS_AUTORADIOBUTTON:
2033 case BS_AUTOCHECKBOX:
2034 defaultstyle |= WS_TABSTOP;
2037 yywarning("Unknown default button control-style 0x%08x", special_style);
2039 case BS_RADIOBUTTON:
2045 switch(special_style)
2050 defaultstyle |= WS_GROUP;
2052 case SS_ICON: /* Special case */
2055 yywarning("Unknown default static control-style 0x%08x", special_style);
2059 case -1: /* Generic control */
2063 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2067 /* The SS_ICON flag is always forced in for icon controls */
2068 if(type == CT_STATIC && special_style == SS_ICON)
2069 defaultstyle |= SS_ICON;
2071 if (!ctrl->gotstyle)
2072 ctrl->style = new_style(0,0);
2074 /* combine all styles */
2075 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2076 ctrl->gotstyle = TRUE;
2078 /* combine with NOT mask */
2081 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2082 ctrl->style->and_mask = 0;
2084 if (ctrl->gotexstyle)
2086 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2087 ctrl->exstyle->and_mask = 0;
2092 static name_id_t *convert_ctlclass(name_id_t *cls)
2097 if(cls->type == name_ord)
2099 assert(cls->type == name_str);
2100 if(cls->type == str_unicode)
2102 yyerror("Don't yet support unicode class comparison");
2105 cc = cls->name.s_name->str.cstr;
2107 if(!strcasecmp("BUTTON", cc))
2109 else if(!strcasecmp("COMBOBOX", cc))
2110 iclass = CT_COMBOBOX;
2111 else if(!strcasecmp("LISTBOX", cc))
2112 iclass = CT_LISTBOX;
2113 else if(!strcasecmp("EDIT", cc))
2115 else if(!strcasecmp("STATIC", cc))
2117 else if(!strcasecmp("SCROLLBAR", cc))
2118 iclass = CT_SCROLLBAR;
2120 return cls; /* No default, return user controlclass */
2122 free(cls->name.s_name->str.cstr);
2123 free(cls->name.s_name);
2124 cls->type = name_ord;
2125 cls->name.i_name = iclass;
2129 /* DialogEx specific functions */
2130 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2132 assert(dlg != NULL);
2133 if(dlg->style == NULL)
2135 dlg->style = new_style(0,0);
2140 yywarning("Style already defined, or-ing together");
2144 dlg->style->or_mask = 0;
2145 dlg->style->and_mask = 0;
2147 dlg->style->or_mask |= st->or_mask;
2148 dlg->style->and_mask |= st->and_mask;
2149 dlg->gotstyle = TRUE;
2154 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2156 assert(dlg != NULL);
2157 if(dlg->exstyle == NULL)
2159 dlg->exstyle = new_style(0,0);
2164 yywarning("ExStyle already defined, or-ing together");
2168 dlg->exstyle->or_mask = 0;
2169 dlg->exstyle->and_mask = 0;
2171 dlg->exstyle->or_mask |= st->or_mask;
2172 dlg->exstyle->and_mask |= st->and_mask;
2173 dlg->gotexstyle = TRUE;
2178 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2180 assert(dlg != NULL);
2182 yyerror("Caption already defined");
2187 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2189 assert(dlg != NULL);
2191 yyerror("Font already defined");
2196 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2198 assert(dlg != NULL);
2200 yyerror("Class already defined");
2205 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2207 assert(dlg != NULL);
2209 yyerror("Menu already defined");
2214 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2216 assert(dlg != NULL);
2217 if(dlg->lvc.language)
2218 yyerror("Language already defined");
2219 dlg->lvc.language = l;
2223 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2225 assert(dlg != NULL);
2226 if(dlg->lvc.characts)
2227 yyerror("Characteristics already defined");
2228 dlg->lvc.characts = c;
2232 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2234 assert(dlg != NULL);
2235 if(dlg->lvc.version)
2236 yyerror("Version already defined");
2237 dlg->lvc.version = v;
2241 /* Accelerator specific functions */
2242 static event_t *add_event(int key, int id, int flags, event_t *prev)
2244 event_t *ev = new_event();
2246 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2247 yyerror("Cannot use both ASCII and VIRTKEY");
2251 ev->flags = flags & ~WRC_AF_ASCII;
2258 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2261 event_t *ev = new_event();
2263 if(key->type != str_char)
2264 yyerror("Key code must be an ascii string");
2266 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
2267 yyerror("VIRTKEY code is not equal to ascii value");
2269 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2271 yyerror("Cannot use both '^' and CONTROL modifier");
2273 else if(key->str.cstr[0] == '^')
2275 keycode = toupper(key->str.cstr[1]) - '@';
2277 yyerror("Control-code out of range");
2280 keycode = key->str.cstr[0];
2283 ev->flags = flags & ~WRC_AF_ASCII;
2290 /* MenuEx specific functions */
2291 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2293 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2297 opt->helpid = helpid;
2301 /* Raw data functions */
2302 static raw_data_t *load_file(string_t *filename, language_t *lang)
2308 int codepage = get_language_codepage(lang->id, lang->sub);
2310 /* FIXME: we may want to use utf-8 here */
2311 if (codepage <= 0 && filename->type != str_char)
2312 yyerror("Cannot convert filename to ASCII string");
2313 name = convert_string( filename, str_char, codepage );
2314 if (!(path = wpp_find_include(name->str.cstr, input_name)))
2315 yyerror("Cannot open file %s", name->str.cstr);
2316 if (!(fp = fopen( path, "rb" )))
2317 yyerror("Cannot open file %s", name->str.cstr);
2319 rd = new_raw_data();
2320 fseek(fp, 0, SEEK_END);
2321 rd->size = ftell(fp);
2322 fseek(fp, 0, SEEK_SET);
2325 rd->data = (char *)xmalloc(rd->size);
2326 fread(rd->data, rd->size, 1, fp);
2328 else rd->data = NULL;
2330 rd->lvc.language = lang;
2335 static raw_data_t *int2raw_data(int i)
2339 if( ( i >= 0 && (int)((unsigned short)i) != i) ||
2340 ( i < 0 && (int)((short)i) != i) )
2341 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2343 rd = new_raw_data();
2344 rd->size = sizeof(short);
2345 rd->data = (char *)xmalloc(rd->size);
2348 #ifdef WORDS_BIGENDIAN
2352 rd->data[0] = HIBYTE(i);
2353 rd->data[1] = LOBYTE(i);
2356 #ifndef WORDS_BIGENDIAN
2360 rd->data[1] = HIBYTE(i);
2361 rd->data[0] = LOBYTE(i);
2367 static raw_data_t *long2raw_data(int i)
2370 rd = new_raw_data();
2371 rd->size = sizeof(int);
2372 rd->data = (char *)xmalloc(rd->size);
2375 #ifdef WORDS_BIGENDIAN
2379 rd->data[0] = HIBYTE(HIWORD(i));
2380 rd->data[1] = LOBYTE(HIWORD(i));
2381 rd->data[2] = HIBYTE(LOWORD(i));
2382 rd->data[3] = LOBYTE(LOWORD(i));
2385 #ifndef WORDS_BIGENDIAN
2389 rd->data[3] = HIBYTE(HIWORD(i));
2390 rd->data[2] = LOBYTE(HIWORD(i));
2391 rd->data[1] = HIBYTE(LOWORD(i));
2392 rd->data[0] = LOBYTE(LOWORD(i));
2398 static raw_data_t *str2raw_data(string_t *str)
2401 rd = new_raw_data();
2402 rd->size = str->size * (str->type == str_char ? 1 : 2);
2403 rd->data = (char *)xmalloc(rd->size);
2404 if(str->type == str_char)
2405 memcpy(rd->data, str->str.cstr, rd->size);
2406 else if(str->type == str_unicode)
2411 #ifdef WORDS_BIGENDIAN
2415 for(i = 0; i < str->size; i++)
2417 rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
2418 rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
2421 #ifndef WORDS_BIGENDIAN
2425 for(i = 0; i < str->size; i++)
2427 rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
2428 rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
2434 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2438 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2440 r1->data = xrealloc(r1->data, r1->size + r2->size);
2441 memcpy(r1->data + r1->size, r2->data, r2->size);
2442 r1->size += r2->size;
2446 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2448 raw_data_t *t = int2raw_data(i);
2449 merge_raw_data(r1, t);
2455 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2457 raw_data_t *t = long2raw_data(i);
2458 merge_raw_data(r1, t);
2464 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2466 raw_data_t *t = str2raw_data(str);
2467 merge_raw_data(r1, t);
2473 /* Function the go back in a list to get the head */
2474 static menu_item_t *get_item_head(menu_item_t *p)
2483 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2492 static resource_t *get_resource_head(resource_t *p)
2501 static ver_block_t *get_ver_block_head(ver_block_t *p)
2510 static ver_value_t *get_ver_value_head(ver_value_t *p)
2519 static control_t *get_control_head(control_t *p)
2528 static event_t *get_event_head(event_t *p)
2537 /* Find a stringtable with given language */
2538 static stringtable_t *find_stringtable(lvc_t *lvc)
2542 assert(lvc != NULL);
2545 lvc->language = dup_language(currentlanguage);
2547 for(stt = sttres; stt; stt = stt->next)
2549 if(stt->lvc.language->id == lvc->language->id
2550 && stt->lvc.language->sub == lvc->language->sub)
2552 /* Found a table with the same language */
2553 /* The version and characteristics are now handled
2554 * in the generation of the individual stringtables.
2555 * This enables localized analysis.
2556 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2557 || (!stt->lvc.version && lvc->version)
2558 || (stt->lvc.version && !lvc->version))
2559 yywarning("Stringtable's versions are not the same, using first definition");
2561 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2562 || (!stt->lvc.characts && lvc->characts)
2563 || (stt->lvc.characts && !lvc->characts))
2564 yywarning("Stringtable's characteristics are not the same, using first definition");
2572 /* qsort sorting function for string table entries */
2573 #define STE(p) ((const stt_entry_t *)(p))
2574 static int sort_stt_entry(const void *e1, const void *e2)
2576 return STE(e1)->id - STE(e2)->id;
2580 static resource_t *build_stt_resources(stringtable_t *stthead)
2583 stringtable_t *newstt;
2585 resource_t *rsclist = NULL;
2586 resource_t *rsctail = NULL;
2591 characts_t *characts;
2597 /* For all languages defined */
2598 for(stt = stthead; stt; stt = stt->next)
2600 assert(stt->nentries > 0);
2602 /* Sort the entries */
2603 if(stt->nentries > 1)
2604 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2606 for(i = 0; i < stt->nentries; )
2608 newstt = new_stringtable(&stt->lvc);
2609 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2610 newstt->nentries = 16;
2611 newstt->idbase = stt->entries[i].id & ~0xf;
2612 for(j = 0; j < 16 && i < stt->nentries; j++)
2614 if(stt->entries[i].id - newstt->idbase == j)
2616 newstt->entries[j] = stt->entries[i];
2624 /* Check individual memory options and get
2625 * the first characteristics/version
2627 for(j = 0; j < 16; j++)
2629 if(!newstt->entries[j].str)
2631 andsum &= newstt->entries[j].memopt;
2632 orsum |= newstt->entries[j].memopt;
2634 characts = newstt->entries[j].characts;
2636 version = newstt->entries[j].version;
2640 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2642 /* Check version and characteristics */
2643 for(j = 0; j < 16; j++)
2646 && newstt->entries[j].characts
2647 && *newstt->entries[j].characts != *characts)
2648 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2650 && newstt->entries[j].version
2651 && *newstt->entries[j].version != *version)
2652 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2654 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2655 rsc->name = new_name_id();
2656 rsc->name->type = name_ord;
2657 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2658 rsc->memopt = andsum; /* Set to least common denominator */
2659 newstt->memopt = andsum;
2660 newstt->lvc.characts = characts;
2661 newstt->lvc.version = version;
2669 rsctail->next = rsc;
2670 rsc->prev = rsctail;
2679 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2688 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2707 static string_t *make_filename(string_t *str)
2709 if(str->type == str_char)
2713 /* Remove escaped backslash and convert to forward */
2714 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2718 memmove(cptr, cptr+1, strlen(cptr));
2728 /* Remove escaped backslash and convert to forward */
2729 for(wptr = str->str.wstr; (wptr = strchrW(wptr, '\\')) != NULL; wptr++)
2733 memmove(wptr, wptr+1, strlenW(wptr));
2743 * Process all resources to extract fonts and build
2744 * a fontdir resource.
2746 * Note: MS' resource compiler (build 1472) does not
2747 * handle font resources with different languages.
2748 * The fontdir is generated in the last active language
2749 * and font identifiers must be unique across the entire
2751 * This is not logical considering the localization
2752 * constraints of all other resource types. MS has,
2753 * most probably, never testet localized fonts. However,
2754 * using fontresources is rare, so it might not occur
2755 * in normal applications.
2756 * Wine does require better localization because a lot
2757 * of languages are coded into the same executable.
2758 * Therefore, I will generate fontdirs for *each*
2759 * localized set of fonts.
2761 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2763 static int once = 0;
2766 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
2772 static resource_t *build_fontdirs(resource_t *tail)
2775 resource_t *lst = NULL;
2776 resource_t **fnt = NULL; /* List of all fonts */
2778 resource_t **fnd = NULL; /* List of all fontdirs */
2780 resource_t **lanfnt = NULL;
2787 nid.type = name_str;
2788 nid.name.s_name = &str;
2789 str.type = str_char;
2790 str.str.cstr = xstrdup("FONTDIR");
2793 /* Extract all fonts and fontdirs */
2794 for(rsc = tail; rsc; rsc = rsc->prev)
2796 if(rsc->type == res_fnt)
2799 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2802 else if(rsc->type == res_fntdir)
2805 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2810 /* Verify the name of the present fontdirs */
2811 for(i = 0; i < nfnd; i++)
2813 if(compare_name_id(&nid, fnd[i]->name))
2815 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2816 get_nameid_str(fnd[i]->name));
2825 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2830 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2832 /* Get all fonts covered by fontdirs */
2833 for(i = 0; i < nfnd; i++)
2841 for(j = 0; j < nfnt; j++)
2845 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2847 lanfnt[nlanfnt] = fnt[j];
2853 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2856 else if(nlanfnt == BYTESWAP_WORD(cnt))
2859 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2860 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2861 #ifdef WORDS_BIGENDIAN
2862 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2864 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2867 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2871 /* We now have fonts left where we need to make a fontdir resource */
2872 for(i = fntleft = 0; i < nfnt; i++)
2879 /* Get fonts of same language in lanfnt[] */
2880 for(i = nlanfnt = 0; i < nfnt; i++)
2887 lanfnt[nlanfnt] = fnt[i];
2892 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2896 /* and build a fontdir */
2897 rsc = build_fontdir(lanfnt, nlanfnt);
2920 * This gets invoked to determine whether the next resource
2921 * is to be of a standard-type (e.g. bitmaps etc.), or should
2922 * be a user-type resource. This function is required because
2923 * there is the _possibility_ of a lookahead token in the
2924 * parser, which is generated from the "expr" state in the
2927 * The general resource format is:
2928 * <identifier> <type> <flags> <resourcebody>
2930 * The <identifier> can either be tIDENT or "expr". The latter
2931 * will always generate a lookahead, which is the <type> of the
2932 * resource to parse. Otherwise, we need to get a new token from
2933 * the scanner to determine the next step.
2935 * The problem arrises when <type> is numerical. This case should
2936 * map onto default resource-types and be parsed as such instead
2937 * of being mapped onto user-type resources.
2939 * The trick lies in the fact that yacc (bison) doesn't care about
2940 * intermediate changes of the lookahead while reducing a rule. We
2941 * simply replace the lookahead with a token that will result in
2942 * a shift to the appropriate rule for the specific resource-type.
2944 static int rsrcid_to_token(int lookahead)
2947 const char *type = "?";
2949 /* Get a token if we don't have one yet */
2950 if(lookahead == YYEMPTY)
2953 /* Only numbers are possibly interesting */
2983 case WRC_RT_FONTDIR:
2991 case WRC_RT_MESSAGETABLE:
2992 type = "MESSAGETABLE";
2993 token = tMESSAGETABLE;
2995 case WRC_RT_DLGINIT:
2999 case WRC_RT_ACCELERATOR:
3000 type = "ACCELERATOR";
3001 token = tACCELERATORS;
3011 case WRC_RT_VERSION:
3013 token = tVERSIONINFO;
3015 case WRC_RT_TOOLBAR:
3025 type = "STRINGTABLE";
3028 case WRC_RT_ANICURSOR:
3029 case WRC_RT_ANIICON:
3030 case WRC_RT_GROUP_CURSOR:
3031 case WRC_RT_GROUP_ICON:
3032 yywarning("Usertype uses reserved type ID %d, which is auto-generated", yylval.num);
3035 case WRC_RT_DLGINCLUDE:
3036 case WRC_RT_PLUGPLAY:
3038 yywarning("Usertype uses reserved type ID %d, which is not supported by wrc yet", yylval.num);