3 * Copyright Martin von Loewis, 1994
4 * Copyright 1998 Bertho A. Stultiens (BS)
6 * 29-Dec-1998 AdH - Grammar and function extensions.
7 * grammar: TOOLBAR resources, Named ICONs in
9 * functions: semantic actions for the grammar
10 * changes, resource files can now be anywhere
11 * on the include path instead of just in the
14 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
15 * printed out correctly.
17 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
18 * also accept a tSTRING as argument.
20 * 25-May-1998 BS - Found out that I need to support language, version
21 * and characteristics in inline resources (bitmap,
22 * cursor, etc) but they can also be specified with
23 * a filename. This renders my filename-scanning scheme
24 * worthless. Need to build newline parsing to solve
26 * It will come with version 1.1.0 (sigh).
28 * 19-May-1998 BS - Started to build a builtin preprocessor
30 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
31 * ideas had some serious flaws.
33 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
36 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
37 * - This file is growing too big. It is time to strip
38 * things and put it in a support file.
40 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
41 * resource will be created. This because the table
42 * has a different layout than other resources. The
43 * table has to be sorted, and divided into smaller
44 * resource entries (see comment in source).
46 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
47 * as string_t which include unicode strings upon
49 * - Parser now emits a warning when compiling win32
50 * extensions in win16 mode.
52 * 16-Apr-1998 BS - Raw data elements are now *optionally* seperated
53 * by commas. Read the comments in file sq2dq.l.
54 * - FIXME: there are instances in the source that rely
55 * on the fact that int==32bit and pointers are int size.
56 * - Fixed the conflict in menuex by changing a rule
57 * back into right recursion. See note in source.
58 * - UserType resources cannot have an expression as its
59 * typeclass. See note in source.
61 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
62 * get reduction of the parsestack.
63 * This also helps communication between bison and flex.
64 * Main advantage is that the Empty rule gets reduced
65 * first, which is used to allocate/link things.
66 * It also added a shift/reduce conflict in the menuex
67 * handling, due to expression/option possibility,
68 * although not serious.
70 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
71 * about making it more efficient, but readable (for me)
72 * and slightly easier to expand/change.
73 * This is done primarily by using more reduce states
74 * with many (intuitive) types for the various resource
76 * - Added expression handling for all resources where a
77 * number is accepted (not only for win32). Also added
78 * multiply and division (not MS compatible, but handy).
79 * Unary minus introduced a shift/reduce conflict, but
82 * 13-Apr-1998 BS - Reordered a lot of things
83 * - Made the source more readable
84 * - Added Win32 resource definitions
85 * - Corrected syntax problems with an old yacc (;)
86 * - Added extra comment about grammar
107 DWORD andmask; /* Used to parse 'NOT NUMBER' expressions */
108 int indialog = 0; /* Signal flex that we're parsing a dialog */
109 int want_rscname = 0; /* Set when a resource's name is required */
110 stringtable_t *tagstt; /* Stringtable tag.
111 * It is set while parsing a stringtable to one of
112 * the stringtables in the sttres list or a new one
113 * if the language was not parsed before.
115 stringtable_t *sttres; /* Stringtable resources. This holds the list of
116 * stringtables with different lanuages
118 /* Set to the current options of the currently scanning stringtable */
119 static int *tagstt_memopt;
120 static characts_t *tagstt_characts;
121 static version_t *tagstt_version;
123 /* Prototypes of here defined functions */
124 void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur);
125 void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico);
126 int alloc_cursor_id(language_t *);
127 int alloc_icon_id(language_t *);
128 void ins_stt_entry(stt_entry_t *ste);
129 int check_stt_entry(stringtable_t *tabs, stt_entry_t *ste);
130 event_t *get_event_head(event_t *p);
131 control_t *get_control_head(control_t *p);
132 ver_value_t *get_ver_value_head(ver_value_t *p);
133 ver_block_t *get_ver_block_head(ver_block_t *p);
134 resource_t *get_resource_head(resource_t *p);
135 menuex_item_t *get_itemex_head(menuex_item_t *p);
136 menu_item_t *get_item_head(menu_item_t *p);
137 raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
138 raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
139 raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
140 raw_data_t *str2raw_data(string_t *str);
141 raw_data_t *int2raw_data(int i);
142 raw_data_t *load_file(string_t *name);
143 itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
144 event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
145 event_t *add_event(int key, int id, int flags, event_t *prev);
146 dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
147 dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
148 dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
149 dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
150 dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
151 dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
152 dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
153 dialogex_t *dialogex_exstyle(int st, dialogex_t *dlg);
154 dialogex_t *dialogex_style(int st, dialogex_t *dlg);
155 name_id_t *convert_ctlclass(name_id_t *cls);
156 control_t *ins_ctrl(int type, int style, control_t *ctrl, control_t *prev);
157 dialog_t *dialog_version(version_t *v, dialog_t *dlg);
158 dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
159 dialog_t *dialog_language(language_t *l, dialog_t *dlg);
160 dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
161 dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
162 dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
163 dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
164 dialog_t *dialog_exstyle(int st, dialog_t *dlg);
165 dialog_t *dialog_style(int st, dialog_t *dlg);
166 resource_t *build_stt_resources(stringtable_t *stthead);
167 stringtable_t *find_stringtable(lvc_t *lvc);
168 toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
169 toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
180 cursor_group_t *curg;
202 menuex_item_t *menexitm;
210 toolbar_item_t *tlbarItems;
213 %token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
214 %token tTYPEDEF tEXTERN
216 %token <str> tSTRING IDENT FILENAME
218 %token ACCELERATORS tBITMAP CURSOR DIALOG DIALOGEX MENU MENUEX MESSAGETABLE
219 %token RCDATA VERSIONINFO STRINGTABLE FONT ICON
220 %token AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON CHECKBOX DEFPUSHBUTTON
221 %token PUSHBUTTON RADIOBUTTON STATE3 /* PUSHBOX */
222 %token GROUPBOX COMBOBOX LISTBOX SCROLLBAR
223 %token CONTROL EDITTEXT
224 %token RTEXT CTEXT LTEXT
226 %token SHIFT ALT ASCII VIRTKEY GRAYED CHECKED INACTIVE NOINVERT
227 %token tPURE IMPURE DISCARDABLE LOADONCALL PRELOAD tFIXED MOVEABLE
228 %token CLASS CAPTION CHARACTERISTICS EXSTYLE STYLE VERSION LANGUAGE
229 %token FILEVERSION PRODUCTVERSION FILEFLAGSMASK FILEOS FILETYPE FILEFLAGS FILESUBTYPE
230 %token MENUBARBREAK MENUBREAK MENUITEM POPUP SEPARATOR
232 %token tSTRING IDENT RAWDATA
233 %token TOOLBAR BUTTON
241 %left '<' LTE '>' GTE
246 %type <res> resource_file resource resources resource_definition
247 %type <stt> stringtable strings
250 %type <acc> accelerators
254 %type <dlg> dialog dlg_attributes
255 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
256 %type <iptr> optional_style helpid
257 %type <dlgex> dialogex dlgex_attribs
258 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
260 %type <raw> raw_data raw_elements opt_data
261 %type <veri> versioninfo fix_version
262 %type <verw> ver_words
263 %type <blk> ver_blocks ver_block
264 %type <val> ver_values ver_value
266 %type <menitm> item_definitions menu_body
268 %type <menexitm> itemex_definitions menuex_body
269 %type <exopt> itemex_p_options itemex_options
270 %type <msg> messagetable
272 %type <num> item_options
273 %type <nid> nameid nameid_s ctlclass usertype
275 %type <iptr> loadmemopts lamo lama
276 %type <fntid> opt_font opt_exfont
278 %type <lan> opt_language
279 %type <chars> opt_characts
280 %type <ver> opt_version
281 %type <num> expr xpr dummy
283 %type <iptr> pp_expr pp_constant
284 %type <tlbar> toolbar
285 %type <tlbarItems> toolbar_items
292 /* First add stringtables to the resource-list */
293 rsc = build_stt_resources(sttres);
294 /* 'build_stt_resources' returns a head and $1 is a tail */
303 /* Final statement before were done */
304 resource_top = get_resource_head($1);
308 /* Resources are put into a linked list */
310 : /* Empty */ { $$ = NULL; want_rscname = 1; }
311 | resources resource {
314 resource_t *tail = $2;
315 resource_t *head = $2;
327 resource_t *tail = $1;
336 | resources preprocessor { $$ = $1; want_rscname = 1; }
337 | resources cjunk { $$ = $1; want_rscname = 1; }
340 /* The buildin preprocessor */
342 : tIF pp_expr tNL { pop_start(); push_if($2 ? *($2) : 0, 0, 0); if($2) free($2);}
343 | tIFDEF IDENT tNL { pop_start(); push_if(pp_lookup($2->str.cstr) != NULL, 0, 0); }
344 | tIFNDEF IDENT tNL { pop_start(); push_if(pp_lookup($2->str.cstr) == NULL, 0, 0); }
345 | tELIF pp_expr tNL { pop_start(); push_if($2 ? *($2) : 0, pop_if(), 0); if($2) free($2); }
346 | tELSE tNL { pop_start(); push_if(1, pop_if(), 0); }
347 | tENDIF tNL { pop_if(); }
350 pp_expr : pp_constant { $$ = $1; }
351 | pp_expr LOGOR pp_expr { $$ = new_int($1 && $3 ? (*$1 || *$3) : 0); if($1) free($1); if($3) free($3); }
352 | pp_expr LOGAND pp_expr { $$ = new_int($1 && $3 ? (*$1 && *$3) : 0); if($1) free($1); if($3) free($3); }
353 | pp_expr '+' pp_expr { $$ = new_int($1 && $3 ? (*$1 + *$3) : 0); if($1) free($1); if($3) free($3); }
354 | pp_expr '-' pp_expr { $$ = new_int($1 && $3 ? (*$1 - *$3) : 0); if($1) free($1); if($3) free($3); }
355 | pp_expr '^' pp_expr { $$ = new_int($1 && $3 ? (*$1 ^ *$3) : 0); if($1) free($1); if($3) free($3); }
356 | pp_expr EQ pp_expr { $$ = new_int($1 && $3 ? (*$1 == *$3) : 0); if($1) free($1); if($3) free($3); }
357 | pp_expr NE pp_expr { $$ = new_int($1 && $3 ? (*$1 != *$3) : 0); if($1) free($1); if($3) free($3); }
358 | pp_expr '<' pp_expr { $$ = new_int($1 && $3 ? (*$1 < *$3) : 0); if($1) free($1); if($3) free($3); }
359 | pp_expr '>' pp_expr { $$ = new_int($1 && $3 ? (*$1 > *$3) : 0); if($1) free($1); if($3) free($3); }
360 | pp_expr LTE pp_expr { $$ = new_int($1 && $3 ? (*$1 <= *$3) : 0); if($1) free($1); if($3) free($3); }
361 | pp_expr GTE pp_expr { $$ = new_int($1 && $3 ? (*$1 >= *$3) : 0); if($1) free($1); if($3) free($3); }
362 | '~' pp_expr { $$ = $2; if($2) *$2 = ~(*$2); }
363 | '+' pp_expr { $$ = $2; }
364 | '-' pp_expr { $$ = $2; if($2) *$2 = -(*$2); }
365 | '!' pp_expr { $$ = $2; if($2) *$2 = !(*$2); }
366 | '(' pp_expr ')' { $$ = $2; }
370 : NUMBER { $$ = new_int($1); }
371 | IDENT { $$ = NULL; }
372 | tDEFINED IDENT { $$ = new_int(pp_lookup($2->str.cstr) != NULL); }
373 | tDEFINED '(' IDENT ')' { $$ = new_int(pp_lookup($3->str.cstr) != NULL); }
377 cjunk : tTYPEDEF { strip_til_semicolon(); }
378 | tEXTERN { strip_til_semicolon(); }
379 | IDENT IDENT { strip_til_semicolon(); }
380 | IDENT '(' { strip_til_parenthesis(); }
381 | IDENT '*' { strip_til_semicolon(); }
384 /* Parse top level resource definitions etc. */
386 : nameid resource_definition {
391 if($1->type == name_ord)
393 chat("Got %s (%d)",get_typename($2),$1->name.i_name);
395 else if($1->type == name_str)
397 chat("Got %s (%s)",get_typename($2),$1->name.s_name->str.cstr);
402 /* Don't do anything, stringtables are converted to
403 * resource_t structures when we are finished parsing and
404 * the final rule of the parser is reduced (see above)
407 chat("Got STRINGTABLE");
411 yywarning("LANGUAGE not supported in 16-bit mode");
413 free(currentlanguage);
414 currentlanguage = $1;
420 * Get a valid name/id
425 $$->name.i_name = $1;
431 $$->name.s_name = $1;
437 * Extra string recognition for CLASS statement in dialogs
439 nameid_s: nameid { $$ = $1; }
443 $$->name.s_name = $1;
448 /* get the value for a single resource*/
450 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
451 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, dup_language(currentlanguage)); }
455 $$ = rsc = new_resource(res_curg, $1, $1->memopt, dup_language(currentlanguage));
456 for(cur = $1->cursorlist; cur; cur = cur->next)
458 rsc->prev = new_resource(res_cur, cur, $1->memopt, dup_language(currentlanguage));
459 rsc->prev->next = rsc;
461 rsc->name = new_name_id();
462 rsc->name->type = name_ord;
463 rsc->name->name.i_name = cur->id;
466 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
469 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
473 | font { $$=new_resource(res_fnt, $1, $1->memopt, dup_language(currentlanguage)); }
477 $$ = rsc = new_resource(res_icog, $1, $1->memopt, dup_language(currentlanguage));
478 for(ico = $1->iconlist; ico; ico = ico->next)
480 rsc->prev = new_resource(res_ico, ico, $1->memopt, dup_language(currentlanguage));
481 rsc->prev->next = rsc;
483 rsc->name = new_name_id();
484 rsc->name->type = name_ord;
485 rsc->name->name.i_name = ico->id;
488 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
491 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
495 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
496 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->lvc.language); }
497 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
498 | userres { $$ = new_resource(res_usr, $1, $1->memopt, dup_language(currentlanguage)); }
499 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
502 /* ------------------------------ Bitmap ------------------------------ */
503 bitmap : tBITMAP loadmemopts FILENAME { $$ = new_bitmap(load_file($3), $2); }
504 | tBITMAP loadmemopts raw_data { $$ = new_bitmap($3, $2); }
507 /* ------------------------------ Cursor ------------------------------ */
508 cursor : CURSOR loadmemopts FILENAME { $$ = new_cursor_group(load_file($3), $2); }
509 | CURSOR loadmemopts raw_data { $$ = new_cursor_group($3, $2); }
512 /* ------------------------------ Font ------------------------------ */
513 /* FIXME: Should we allow raw_data here? */
514 font : FONT loadmemopts FILENAME { $$ = new_font(load_file($3), $2); }
517 /* ------------------------------ Icon ------------------------------ */
518 icon : ICON loadmemopts FILENAME { $$ = new_icon_group(load_file($3), $2); }
519 | ICON loadmemopts raw_data { $$ = new_icon_group($3, $2); }
522 /* ------------------------------ MessageTable ------------------------------ */
523 /* It might be interesting to implement the MS Message compiler here as well
524 * to get everything in one source. Might be a future project.
527 : MESSAGETABLE FILENAME {
529 yywarning("MESSAGETABLE not supported in 16-bit mode");
530 $$ = new_messagetable(load_file($2));
534 /* ------------------------------ RCData ------------------------------ */
535 rcdata : RCDATA loadmemopts opt_lvc raw_data {
536 $$ = new_rcdata($4, $2);
542 if(!$$->lvc.language)
543 $$->lvc.language = dup_language(currentlanguage);
547 /* ------------------------------ UserType ------------------------------ */
548 userres : usertype loadmemopts FILENAME { $$ = new_user($1, load_file($3), $2); }
549 | usertype loadmemopts raw_data { $$ = new_user($1, $3, $2); }
552 /* NOTE: This here is an exception where I do not allow an expression.
553 * Reason for this is that it is not possible to set the 'yywf' condition
554 * for flex if loadmemopts is empty. Reading an expression requires a
555 * lookahead to determine its end. In this case here, that would mean that
556 * the filename has been read as IDENT or tSTRING, which is incorrect.
557 * Note also that IDENT cannot be used as a file-name because it is lacking
561 /* I also allow string identifiers as classtypes. Not MS implemented, but
562 * seems to be reasonable to implement.
564 /* Allowing anything else than NUMBER makes it very hard to get rid of
565 * prototypes. So, I remove IDENT to be able to get prototypes out of the
571 $$->name.i_name = $1;
577 $$->name.s_name = $1;
583 $$->name.s_name = $1;
588 /* ------------------------------ Accelerator ------------------------------ */
590 : ACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
591 $$ = new_accelerator();
599 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
602 yyerror("Accelerator table must have at least one entry");
603 $$->events = get_event_head($5);
609 if(!$$->lvc.language)
610 $$->lvc.language = dup_language(currentlanguage);
614 events : /* Empty */ { $$=NULL; }
615 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
616 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
619 acc_opt : /* Empty */ { $$=0; }
620 | acc_opt ',' NOINVERT { $$=$1 | WRC_AF_NOINVERT; }
621 | acc_opt ',' SHIFT { $$=$1 | WRC_AF_SHIFT; }
622 | acc_opt ',' CONTROL { $$=$1 | WRC_AF_CONTROL; }
623 | acc_opt ',' ALT { $$=$1 | WRC_AF_ALT; }
624 | acc_opt ',' ASCII { $$=$1 | WRC_AF_ASCII; }
625 | acc_opt ',' VIRTKEY { $$=$1 | WRC_AF_VIRTKEY; }
628 /* ------------------------------ Dialog ------------------------------ */
629 /* FIXME: Support EXSTYLE in the dialog line itself */
630 dialog : DIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
638 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
643 $10->controls = get_control_head($12);
647 $$->style = WS_POPUP;
651 $$->style |= WS_CAPTION;
653 $$->style |= DS_SETFONT;
655 if(!$$->lvc.language)
656 $$->lvc.language = dup_language(currentlanguage);
661 : /* Empty */ { $$=new_dialog(); }
662 | dlg_attributes STYLE expr { $$=dialog_style($3,$1); }
663 | dlg_attributes EXSTYLE expr { $$=dialog_exstyle($3,$1); }
664 | dlg_attributes CAPTION tSTRING { $$=dialog_caption($3,$1); }
665 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
666 | dlg_attributes CLASS nameid_s { $$=dialog_class($3,$1); }
667 | dlg_attributes MENU nameid { $$=dialog_menu($3,$1); }
668 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
669 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
670 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
673 ctrls : /* Empty */ { $$ = NULL; }
674 | ctrls CONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
675 | ctrls EDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
676 | ctrls LISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
677 | ctrls COMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
678 | ctrls SCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
679 | ctrls CHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
680 | ctrls DEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
681 | ctrls GROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
682 | ctrls PUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
683 /* | ctrls PUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
684 | ctrls RADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
685 | ctrls AUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
686 | ctrls STATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
687 | ctrls AUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
688 | ctrls AUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
689 | ctrls LTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
690 | ctrls CTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
691 | ctrls RTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
692 /* special treatment for icons, as the extent is optional */
693 | ctrls ICON nameid_s ',' expr ',' expr ',' expr iconinfo {
694 if($3->type == name_str)
696 $10->title = $3->name.s_name;
705 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
710 : tSTRING ',' expr ',' expr ',' expr ',' expr ',' expr optional_style {
728 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
744 iconinfo: /* Empty */
745 { $$ = new_control(); }
747 | ',' expr ',' expr {
752 | ',' expr ',' expr ',' expr {
759 | ',' expr ',' expr ',' expr ',' expr {
766 $$->gotexstyle = TRUE;
770 gen_ctrl: tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ',' expr ',' expr {
774 $$->ctlclass = convert_ctlclass($5);
782 $$->gotexstyle = TRUE;
784 | tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ',' expr {
788 $$->ctlclass = convert_ctlclass($5);
799 : FONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
802 optional_style /* Abbused once to get optional ExStyle */
803 : /* Empty */ { $$ = NULL; }
804 | ',' expr { $$ = new_int($2); }
811 $$->name.i_name = $1;
816 $$->name.s_name = $1;
820 /* ------------------------------ DialogEx ------------------------------ */
821 dialogex: DIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
822 tBEGIN exctrls tEND {
824 yywarning("DIALOGEX not supported in 16-bit mode");
831 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
838 $11->helpid = *($10);
839 $11->gothelpid = TRUE;
842 $11->controls = get_control_head($13);
846 $$->style = WS_POPUP;
850 $$->style |= WS_CAPTION;
852 $$->style |= DS_SETFONT;
854 if(!$$->lvc.language)
855 $$->lvc.language = dup_language(currentlanguage);
860 : /* Empty */ { $$=new_dialogex(); }
861 | dlgex_attribs STYLE expr { $$=dialogex_style($3,$1); }
862 | dlgex_attribs EXSTYLE expr { $$=dialogex_exstyle($3,$1); }
863 | dlgex_attribs CAPTION tSTRING { $$=dialogex_caption($3,$1); }
864 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
865 | dlgex_attribs CLASS nameid_s { $$=dialogex_class($3,$1); }
866 | dlgex_attribs MENU nameid { $$=dialogex_menu($3,$1); }
867 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
868 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
869 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
872 exctrls : /* Empty */ { $$ = NULL; }
873 | exctrls CONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
874 | exctrls EDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
875 | exctrls LISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
876 | exctrls COMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
877 | exctrls SCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
878 | exctrls CHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
879 | exctrls DEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
880 | exctrls GROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
881 | exctrls PUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
882 /* | exctrls PUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
883 | exctrls RADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
884 | exctrls AUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
885 | exctrls STATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
886 | exctrls AUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
887 | exctrls AUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
888 | exctrls LTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
889 | exctrls CTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
890 | exctrls RTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
891 /* special treatment for icons, as the extent is optional */
892 | exctrls ICON tSTRING ',' expr ',' expr ',' expr iconinfo {
897 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
902 : tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ','
903 expr ',' e_expr helpid opt_data {
907 $$->ctlclass = convert_ctlclass($5);
916 $$->exstyle = *($17);
917 $$->gotexstyle = TRUE;
923 $$->gothelpid = TRUE;
928 | tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ',' expr opt_data {
934 $$->ctlclass = convert_ctlclass($5);
944 : tSTRING ',' expr ',' expr ',' expr ',' expr ',' expr optional_style opt_data {
963 : expr ',' expr ',' expr ',' expr ',' expr optional_style opt_data {
980 opt_data: /* Empty */ { $$ = NULL; }
981 | raw_data { $$ = $1; }
984 helpid : /* Empty */ { $$ = NULL; }
985 | ',' expr { $$ = new_int($2); }
989 : FONT expr ',' tSTRING ',' expr ',' expr { $$ = new_font_id($2, $4, $6, $8); }
992 /* ------------------------------ Menu ------------------------------ */
993 menu : MENU loadmemopts opt_lvc menu_body {
995 yyerror("Menu must contain items");
1003 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1004 $$->items = get_item_head($4);
1010 if(!$$->lvc.language)
1011 $$->lvc.language = dup_language(currentlanguage);
1016 : tBEGIN item_definitions tEND { $$ = $2; }
1020 : /* Empty */ {$$ = NULL;}
1021 | item_definitions MENUITEM tSTRING ',' expr item_options {
1030 | item_definitions MENUITEM SEPARATOR {
1036 | item_definitions POPUP tSTRING item_options menu_body {
1037 $$ = new_menu_item();
1041 $$->popup = get_item_head($5);
1046 /* NOTE: item_options is right recursive because it would introduce
1047 * a shift/reduce conflict on ',' in itemex_options due to the
1048 * empty rule here. The parser is now forced to look beyond the ','
1049 * before reducing (force shift).
1050 * Right recursion here is not a problem because we cannot expect
1051 * more than 7 parserstack places to be occupied while parsing this
1052 * (who would want to specify a MF_x flag twice?).
1055 : /* Empty */ { $$ = 0; }
1056 | ',' CHECKED item_options { $$ = $3 | MF_CHECKED; }
1057 | ',' GRAYED item_options { $$ = $3 | MF_GRAYED; }
1058 | ',' HELP item_options { $$ = $3 | MF_HELP; }
1059 | ',' INACTIVE item_options { $$ = $3 | MF_DISABLED; }
1060 | ',' MENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1061 | ',' MENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1064 /* ------------------------------ MenuEx ------------------------------ */
1065 menuex : MENUEX loadmemopts opt_lvc menuex_body {
1067 yywarning("MENUEX not supported in 16-bit mode");
1069 yyerror("MenuEx must contain items");
1077 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1078 $$->items = get_itemex_head($4);
1084 if(!$$->lvc.language)
1085 $$->lvc.language = dup_language(currentlanguage);
1090 : tBEGIN itemex_definitions tEND { $$ = $2; }
1094 : /* Empty */ {$$ = NULL; }
1095 | itemex_definitions MENUITEM tSTRING itemex_options {
1096 $$ = new_menuex_item();
1102 $$->type = $4->type;
1103 $$->state = $4->state;
1104 $$->helpid = $4->helpid;
1105 $$->gotid = $4->gotid;
1106 $$->gottype = $4->gottype;
1107 $$->gotstate = $4->gotstate;
1108 $$->gothelpid = $4->gothelpid;
1111 | itemex_definitions MENUITEM SEPARATOR {
1112 $$ = new_menuex_item();
1117 | itemex_definitions POPUP tSTRING itemex_p_options menuex_body {
1118 $$ = new_menuex_item();
1122 $$->popup = get_itemex_head($5);
1125 $$->type = $4->type;
1126 $$->state = $4->state;
1127 $$->helpid = $4->helpid;
1128 $$->gotid = $4->gotid;
1129 $$->gottype = $4->gottype;
1130 $$->gotstate = $4->gotstate;
1131 $$->gothelpid = $4->gothelpid;
1137 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1139 $$ = new_itemex_opt($2, 0, 0, 0);
1142 | ',' e_expr ',' e_expr item_options {
1143 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1146 $$->gotstate = TRUE;
1150 | ',' e_expr ',' e_expr ',' expr {
1151 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1154 $$->gotstate = TRUE;
1161 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1163 $$ = new_itemex_opt($2, 0, 0, 0);
1166 | ',' e_expr ',' expr {
1167 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1172 | ',' e_expr ',' e_expr ',' expr {
1173 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1178 $$->gotstate = TRUE;
1180 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1181 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1187 $$->gotstate = TRUE;
1188 $$->gothelpid = TRUE;
1192 /* ------------------------------ StringTable ------------------------------ */
1193 /* Stringtables are parsed differently than other resources because their
1194 * layout is substantially different from other resources.
1195 * The table is parsed through a _global_ variable 'tagstt' which holds the
1196 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1197 * list of stringtables of different languages.
1200 : stt_head tBEGIN strings tEND {
1203 yyerror("Stringtable must have at least one entry");
1208 /* Check if we added to a language table or created
1211 for(stt = sttres; stt; stt = stt->next)
1218 /* It is a new one */
1221 sttres->prev = tagstt;
1222 tagstt->next = sttres;
1228 /* Else were done */
1232 free(tagstt_memopt);
1233 tagstt_memopt = NULL;
1240 /* This is to get the language of the currently parsed stringtable */
1241 stt_head: STRINGTABLE loadmemopts opt_lvc {
1242 if((tagstt = find_stringtable($3)) == NULL)
1243 tagstt = new_stringtable($3);
1245 tagstt_version = $3->version;
1246 tagstt_characts = $3->characts;
1252 strings : /* Empty */ { $$ = NULL; }
1253 | strings expr opt_comma tSTRING {
1255 assert(tagstt != NULL);
1256 /* Search for the ID */
1257 for(i = 0; i < tagstt->nentries; i++)
1259 if(tagstt->entries[i].id == $2)
1260 yyerror("Stringtable ID %d already in use", $2);
1262 /* If we get here, then we have a new unique entry */
1264 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1265 tagstt->entries[tagstt->nentries-1].id = $2;
1266 tagstt->entries[tagstt->nentries-1].str = $4;
1268 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1270 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1271 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1272 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1274 if(!win32 && $4->size > 254)
1275 yyerror("Stringtable entry more than 254 characters");
1276 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1277 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1282 opt_comma /* There seem to be two ways to specify a stringtable... */
1287 /* ------------------------------ VersionInfo ------------------------------ */
1289 : VERSIONINFO fix_version tBEGIN ver_blocks tEND {
1291 $2->blocks = get_ver_block_head($4);
1296 : /* Empty */ { $$ = new_versioninfo(); }
1297 | fix_version FILEVERSION expr ',' expr ',' expr ',' expr {
1299 yyerror("FILEVERSION already defined");
1301 $$->filever_maj1 = $3;
1302 $$->filever_maj2 = $5;
1303 $$->filever_min1 = $7;
1304 $$->filever_min2 = $9;
1307 | fix_version PRODUCTVERSION expr ',' expr ',' expr ',' expr {
1309 yyerror("PRODUCTVERSION already defined");
1311 $$->prodver_maj1 = $3;
1312 $$->prodver_maj2 = $5;
1313 $$->prodver_min1 = $7;
1314 $$->prodver_min2 = $9;
1317 | fix_version FILEFLAGS expr {
1319 yyerror("FILEFLAGS already defined");
1324 | fix_version FILEFLAGSMASK expr {
1326 yyerror("FILEFLAGSMASK already defined");
1328 $$->fileflagsmask = $3;
1331 | fix_version FILEOS expr {
1333 yyerror("FILEOS already defined");
1338 | fix_version FILETYPE expr {
1340 yyerror("FILETYPE already defined");
1345 | fix_version FILESUBTYPE expr {
1347 yyerror("FILESUBTYPE already defined");
1349 $$->filesubtype = $3;
1355 : /* Empty */ { $$ = NULL; }
1356 | ver_blocks ver_block {
1365 : BLOCK tSTRING tBEGIN ver_values tEND {
1366 $$ = new_ver_block();
1368 $$->values = get_ver_value_head($4);
1373 : /* Empty */ { $$ = NULL; }
1374 | ver_values ver_value {
1384 $$ = new_ver_value();
1385 $$->type = val_block;
1386 $$->value.block = $1;
1388 | VALUE tSTRING ',' tSTRING {
1389 $$ = new_ver_value();
1394 | VALUE tSTRING ',' ver_words {
1395 $$ = new_ver_value();
1396 $$->type = val_words;
1398 $$->value.words = $4;
1403 : expr { $$ = new_ver_words($1); }
1404 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1407 /* ------------------------------ Toolbar ------------------------------ */
1408 toolbar: TOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1410 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1411 $$ = new_toolbar($3, $5, items, nitems);
1419 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1426 if(!$$->lvc.language)
1428 $$->lvc.language = dup_language(currentlanguage);
1434 : /* Empty */ { $$ = NULL; }
1435 | toolbar_items BUTTON expr {
1436 toolbar_item_t *idrec = new_toolbar_item();
1438 $$ = ins_tlbr_button($1, idrec);
1440 | toolbar_items SEPARATOR {
1441 toolbar_item_t *idrec = new_toolbar_item();
1443 $$ = ins_tlbr_button($1, idrec);
1447 /* ------------------------------ Memory options ------------------------------ */
1449 : /* Empty */ { $$ = NULL; }
1450 | loadmemopts lamo {
1460 | loadmemopts lama {
1469 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1475 lamo : PRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1476 | MOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1477 | DISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1478 | tPURE { $$ = new_int(WRC_MO_PURE); }
1481 lama : LOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1482 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1483 | IMPURE { $$ = new_int(~WRC_MO_PURE); }
1486 /* ------------------------------ Win32 options ------------------------------ */
1487 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1488 | opt_lvc opt_language {
1490 yywarning("LANGUAGE not supported in 16-bit mode");
1492 yyerror("Language already defined");
1496 | opt_lvc opt_characts {
1498 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1500 yyerror("Characteristics already defined");
1504 | opt_lvc opt_version {
1506 yywarning("VERSION not supported in 16-bit mode");
1508 yyerror("Version already defined");
1515 : LANGUAGE expr ',' expr { $$ = new_language($2, $4); }
1519 : CHARACTERISTICS expr { $$ = new_characts($2); }
1523 : VERSION expr { $$ = new_version($2); }
1526 /* ------------------------------ Raw data handking ------------------------------ */
1527 raw_data: tBEGIN raw_elements tEND { $$ = $2; }
1531 : RAWDATA { $$ = $1; }
1532 | NUMBER { $$ = int2raw_data($1); }
1533 | tSTRING { $$ = str2raw_data($1); }
1534 | raw_elements opt_comma RAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1535 | raw_elements opt_comma NUMBER { $$ = merge_raw_data_int($1, $3); }
1536 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1539 /* ------------------------------ Win32 expressions ------------------------------ */
1540 /* All win16 numbers are also handled here. This is inconsistent with MS'
1541 * resource compiler, but what the heck, its just handy to have.
1543 e_expr : /* Empty */ { $$ = 0; }
1544 | expr { $$ = new_int($1); }
1546 expr : dummy xpr { $$ = ($2) & andmask; }
1549 dummy : /* Empty */ { $$ = 0; andmask = -1; }
1552 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1553 | xpr '-' xpr { $$ = ($1) - ($3); }
1554 | xpr '|' xpr { $$ = ($1) | ($3); }
1555 | xpr '&' xpr { $$ = ($1) & ($3); }
1556 | xpr '*' xpr { $$ = ($1) * ($3); }
1557 | xpr '/' xpr { $$ = ($1) / ($3); }
1558 | '~' xpr { $$ = ~($2); }
1559 | '-' xpr { $$ = -($2); } /* FIXME: shift/reduce conflict */
1560 /* | '+' xpr { $$ = $2; } */
1561 | '(' xpr ')' { $$ = $2; }
1562 | NUMBER { $$ = $1; want_rscname = 0; }
1563 | NOT NUMBER { $$ = 0; andmask &= ~($2); }
1566 /* Dialog specific functions */
1567 dialog_t *dialog_style(int st, dialog_t *dlg)
1570 assert(dlg != NULL);
1573 yywarning("Style already defined, or-ing together");
1576 dlg->style = st | s;
1577 dlg->gotstyle = TRUE;
1581 dialog_t *dialog_exstyle(int st, dialog_t *dlg)
1584 assert(dlg != NULL);
1587 yywarning("ExStyle already defined, or-ing together");
1590 dlg->exstyle = st | s;
1591 dlg->gotexstyle = TRUE;
1595 dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1597 assert(dlg != NULL);
1599 yyerror("Caption already defined");
1604 dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1606 assert(dlg != NULL);
1608 yyerror("Font already defined");
1613 dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1615 assert(dlg != NULL);
1617 yyerror("Class already defined");
1622 dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1624 assert(dlg != NULL);
1626 yyerror("Menu already defined");
1631 dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1633 assert(dlg != NULL);
1634 if(dlg->lvc.language)
1635 yyerror("Language already defined");
1636 dlg->lvc.language = l;
1640 dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1642 assert(dlg != NULL);
1643 if(dlg->lvc.characts)
1644 yyerror("Characteristics already defined");
1645 dlg->lvc.characts = c;
1649 dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1651 assert(dlg != NULL);
1652 if(dlg->lvc.version)
1653 yyerror("Version already defined");
1654 dlg->lvc.version = v;
1658 /* Controls specific functions */
1659 control_t *ins_ctrl(int type, int style, control_t *ctrl, control_t *prev)
1661 assert(ctrl != NULL);
1667 ctrl->ctlclass = new_name_id();
1668 ctrl->ctlclass->type = name_ord;
1669 ctrl->ctlclass->name.i_name = type;
1672 /* Hm... this seems to be jammed in at all time... */
1673 ctrl->style |= WS_CHILD | WS_VISIBLE;
1677 ctrl->style |= style;
1678 if(style != BS_GROUPBOX && style != BS_RADIOBUTTON)
1679 ctrl->style |= WS_TABSTOP;
1682 ctrl->style |= WS_TABSTOP | WS_BORDER;
1685 ctrl->style |= LBS_NOTIFY | WS_BORDER;
1688 ctrl->style |= CBS_SIMPLE;
1691 ctrl->style |= style;
1692 if(style == SS_CENTER || style == SS_LEFT || style == SS_RIGHT)
1693 ctrl->style |= WS_GROUP;
1697 if(!ctrl->gotstyle) /* Handle default style setting */
1702 ctrl->style |= ES_LEFT;
1705 ctrl->style |= LBS_NOTIFY;
1708 ctrl->style |= CBS_SIMPLE | WS_TABSTOP;
1711 ctrl->style |= SBS_HORZ;
1717 case BS_DEFPUSHBUTTON:
1720 /* case BS_PUSHBOX: */
1721 case BS_AUTORADIOBUTTON:
1724 case BS_AUTOCHECKBOX:
1725 ctrl->style |= WS_TABSTOP;
1728 yywarning("Unknown default button control-style 0x%08x", style);
1729 case BS_RADIOBUTTON:
1740 ctrl->style |= WS_GROUP;
1742 case SS_ICON: /* Special case */
1745 yywarning("Unknown default static control-style 0x%08x", style);
1749 case -1: /* Generic control */
1753 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
1757 /* The SS_ICON flag is always forced in for icon controls */
1758 if(type == CT_STATIC && style == SS_ICON)
1759 ctrl->style |= SS_ICON;
1761 ctrl->gotstyle = TRUE;
1766 name_id_t *convert_ctlclass(name_id_t *cls)
1771 if(cls->type == name_ord)
1773 assert(cls->type == name_str);
1774 if(cls->type == str_unicode)
1776 yyerror("Don't yet support unicode class comparison");
1779 cc = cls->name.s_name->str.cstr;
1781 if(!strcasecmp("BUTTON", cc))
1783 else if(!strcasecmp("COMBOBOX", cc))
1784 iclass = CT_COMBOBOX;
1785 else if(!strcasecmp("LISTBOX", cc))
1786 iclass = CT_LISTBOX;
1787 else if(!strcasecmp("EDIT", cc))
1789 else if(!strcasecmp("STATIC", cc))
1791 else if(!strcasecmp("SCROLLBAR", cc))
1792 iclass = CT_SCROLLBAR;
1794 return cls; /* No default, return user controlclass */
1796 free(cls->name.s_name->str.cstr);
1797 free(cls->name.s_name);
1798 cls->type = name_ord;
1799 cls->name.i_name = iclass;
1803 /* DialogEx specific functions */
1804 dialogex_t *dialogex_style(int st, dialogex_t *dlg)
1807 assert(dlg != NULL);
1810 yywarning("Style already defined, or-ing together");
1813 dlg->style = st | s;
1814 dlg->gotstyle = TRUE;
1818 dialogex_t *dialogex_exstyle(int st, dialogex_t *dlg)
1821 assert(dlg != NULL);
1824 yywarning("ExStyle already defined, or-ing together");
1827 dlg->exstyle = st | s;
1828 dlg->gotexstyle = TRUE;
1832 dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
1834 assert(dlg != NULL);
1836 yyerror("Caption already defined");
1841 dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
1843 assert(dlg != NULL);
1845 yyerror("Font already defined");
1850 dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
1852 assert(dlg != NULL);
1854 yyerror("Class already defined");
1859 dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
1861 assert(dlg != NULL);
1863 yyerror("Menu already defined");
1868 dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
1870 assert(dlg != NULL);
1871 if(dlg->lvc.language)
1872 yyerror("Language already defined");
1873 dlg->lvc.language = l;
1877 dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
1879 assert(dlg != NULL);
1880 if(dlg->lvc.characts)
1881 yyerror("Characteristics already defined");
1882 dlg->lvc.characts = c;
1886 dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
1888 assert(dlg != NULL);
1889 if(dlg->lvc.version)
1890 yyerror("Version already defined");
1891 dlg->lvc.version = v;
1895 /* Accelerator specific functions */
1896 event_t *add_event(int key, int id, int flags, event_t *prev)
1898 event_t *ev = new_event();
1900 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
1901 yyerror("Cannot use both ASCII and VIRTKEY");
1905 ev->flags = flags & ~WRC_AF_ASCII;
1912 event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
1915 event_t *ev = new_event();
1917 if(key->type != str_char)
1918 yyerror("Key code must be an ascii string");
1920 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0]) && !isdigit(key->str.cstr[0])))
1921 yyerror("VIRTKEY code is not equal to ascii value");
1923 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
1925 yyerror("Cannot use both '^' and CONTROL modifier");
1927 else if(key->str.cstr[0] == '^')
1929 keycode = toupper(key->str.cstr[1]) - '@';
1931 yyerror("Control-code out of range");
1934 keycode = key->str.cstr[0];
1937 ev->flags = flags & ~WRC_AF_ASCII;
1944 /* MenuEx specific functions */
1945 itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
1947 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
1951 opt->helpid = helpid;
1955 /* Raw data functions */
1956 raw_data_t *load_file(string_t *name)
1960 if(name->type != str_char)
1961 yyerror("Filename must be ASCII string");
1963 fp = open_include(name->str.cstr, 1);
1965 yyerror("Cannot open file %s", name->str.cstr);
1966 rd = new_raw_data();
1967 fseek(fp, 0, SEEK_END);
1968 rd->size = ftell(fp);
1969 fseek(fp, 0, SEEK_SET);
1970 rd->data = (char *)xmalloc(rd->size);
1971 fread(rd->data, rd->size, 1, fp);
1977 raw_data_t *int2raw_data(int i)
1980 rd = new_raw_data();
1981 rd->size = sizeof(short);
1982 rd->data = (char *)xmalloc(rd->size);
1983 *(short *)(rd->data) = (short)i;
1987 raw_data_t *str2raw_data(string_t *str)
1990 rd = new_raw_data();
1991 rd->size = str->size * (str->type == str_char ? 1 : 2);
1992 rd->data = (char *)xmalloc(rd->size);
1993 memcpy(rd->data, str->str.cstr, rd->size);
1997 raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
1999 r1->data = xrealloc(r1->data, r1->size + r2->size);
2000 memcpy(r1->data + r1->size, r2->data, r2->size);
2001 r1->size += r2->size;
2005 raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2007 raw_data_t *t = int2raw_data(i);
2008 merge_raw_data(r1, t);
2014 raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2016 raw_data_t *t = str2raw_data(str);
2017 merge_raw_data(r1, t);
2023 /* Function the go back in a list to get the head */
2024 menu_item_t *get_item_head(menu_item_t *p)
2033 menuex_item_t *get_itemex_head(menuex_item_t *p)
2042 resource_t *get_resource_head(resource_t *p)
2051 ver_block_t *get_ver_block_head(ver_block_t *p)
2060 ver_value_t *get_ver_value_head(ver_value_t *p)
2069 control_t *get_control_head(control_t *p)
2078 event_t *get_event_head(event_t *p)
2087 /* Find a stringtable with given language */
2088 stringtable_t *find_stringtable(lvc_t *lvc)
2092 assert(lvc != NULL);
2095 lvc->language = dup_language(currentlanguage);
2097 for(stt = sttres; stt; stt = stt->next)
2099 if(stt->lvc.language->id == lvc->language->id
2100 && stt->lvc.language->id == lvc->language->id)
2102 /* Found a table with the same language */
2103 /* The version and characteristics are now handled
2104 * in the generation of the individual stringtables.
2105 * This enables localized analysis.
2106 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2107 || (!stt->lvc.version && lvc->version)
2108 || (stt->lvc.version && !lvc->version))
2109 yywarning("Stringtable's versions are not the same, using first definition");
2111 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2112 || (!stt->lvc.characts && lvc->characts)
2113 || (stt->lvc.characts && !lvc->characts))
2114 yywarning("Stringtable's characteristics are not the same, using first definition");
2122 /* qsort sorting function for string table entries */
2123 #define STE(p) ((stt_entry_t *)(p))
2124 int sort_stt_entry(const void *e1, const void *e2)
2126 return STE(e1)->id - STE(e2)->id;
2130 resource_t *build_stt_resources(stringtable_t *stthead)
2133 stringtable_t *newstt;
2135 resource_t *rsclist = NULL;
2136 resource_t *rsctail = NULL;
2141 characts_t *characts;
2147 /* For all languages defined */
2148 for(stt = stthead; stt; stt = stt->next)
2150 assert(stt->nentries > 0);
2152 /* Sort the entries */
2153 if(stt->nentries > 1)
2154 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2156 for(i = 0; i < stt->nentries; )
2158 newstt = new_stringtable(&stt->lvc);
2159 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2160 newstt->nentries = 16;
2161 newstt->idbase = stt->entries[i].id & ~0xf;
2162 for(j = 0; j < 16 && i < stt->nentries; j++)
2164 if(stt->entries[i].id - newstt->idbase == j)
2166 newstt->entries[j] = stt->entries[i];
2174 /* Check individual memory options and get
2175 * the first characteristics/version
2177 for(j = 0; j < 16; j++)
2179 if(!newstt->entries[j].str)
2181 andsum &= newstt->entries[j].memopt;
2182 orsum |= newstt->entries[j].memopt;
2184 characts = newstt->entries[j].characts;
2186 version = newstt->entries[j].version;
2190 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2192 /* Check version and characteristics */
2193 for(j = 0; j < 16; j++)
2196 && newstt->entries[j].characts
2197 && *newstt->entries[j].characts != *characts)
2198 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2200 && newstt->entries[j].version
2201 && *newstt->entries[j].version != *version)
2202 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2204 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2205 rsc->name = new_name_id();
2206 rsc->name->type = name_ord;
2207 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2208 rsc->memopt = andsum; /* Set to least common denominator */
2209 newstt->memopt = andsum;
2210 newstt->lvc.characts = characts;
2211 newstt->lvc.version = version;
2219 rsctail->next = rsc;
2220 rsc->prev = rsctail;
2228 /* Cursor and icon splitter functions */
2234 static int get_new_id(id_alloc_t **list, int *n, language_t *lan)
2237 assert(lan != NULL);
2238 assert(list != NULL);
2243 *list = (id_alloc_t *)xmalloc(sizeof(id_alloc_t));
2245 (*list)[0].lan = *lan;
2250 for(i = 0; i < *n; i++)
2252 if((*list)[i].lan.id == lan->id && (*list)[i].lan.sub == lan->sub)
2253 return ++((*list)[i].id);
2256 *list = (id_alloc_t *)xrealloc(*list, sizeof(id_alloc_t) * (*n+1));
2257 (*list)[*n].lan = *lan;
2263 int alloc_icon_id(language_t *lan)
2265 static id_alloc_t *idlist = NULL;
2268 return get_new_id(&idlist, &nid, lan);
2271 int alloc_cursor_id(language_t *lan)
2273 static id_alloc_t *idlist = NULL;
2276 return get_new_id(&idlist, &nid, lan);
2279 #define BPTR(base) ((char *)(rd->data + (base)))
2280 #define WPTR(base) ((WORD *)(rd->data + (base)))
2281 #define DPTR(base) ((DWORD *)(rd->data + (base)))
2282 void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico)
2286 icon_dir_entry_t *ide;
2288 icon_t *list = NULL;
2290 /* FIXME: Distinguish between normal and animated icons (RIFF format) */
2292 yyerror("Icon resource data has invalid type id %d", WPTR(0)[1]);
2294 ide = (icon_dir_entry_t *)&(WPTR(0)[3]);
2295 for(i = 0; i < cnt; i++)
2298 ico->id = alloc_icon_id(icog->lvc.language);
2299 ico->lvc.language = dup_language(icog->lvc.language);
2300 if(ide[i].offset > rd->size
2301 || ide[i].offset + ide[i].ressize > rd->size)
2302 yyerror("Icon resource data corrupt");
2303 ico->width = ide[i].width;
2304 ico->height = ide[i].height;
2305 ico->nclr = ide[i].nclr;
2306 ico->planes = ide[i].planes;
2307 ico->bits = ide[i].bits;
2310 /* Argh! They did not fill out the resdir structure */
2311 ico->planes = ((BITMAPINFOHEADER *)BPTR(ide[i].offset))->biPlanes;
2315 /* Argh! They did not fill out the resdir structure */
2316 ico->bits = ((BITMAPINFOHEADER *)BPTR(ide[i].offset))->biBitCount;
2318 ico->data = new_raw_data();
2319 copy_raw_data(ico->data, rd, ide[i].offset, ide[i].ressize);
2331 icog->iconlist = list;
2335 void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur)
2339 cursor_dir_entry_t *cde;
2341 cursor_t *list = NULL;
2343 /* FIXME: Distinguish between normal and animated cursors (RIFF format)*/
2345 yyerror("Cursor resource data has invalid type id %d", WPTR(0)[1]);
2347 cde = (cursor_dir_entry_t *)&(WPTR(0)[3]);
2348 for(i = 0; i < cnt; i++)
2351 cur->id = alloc_cursor_id(curg->lvc.language);
2352 cur->lvc.language = dup_language(curg->lvc.language);
2353 if(cde[i].offset > rd->size
2354 || cde[i].offset + cde[i].ressize > rd->size)
2355 yyerror("Cursor resource data corrupt");
2356 cur->width = cde[i].width;
2357 cur->height = cde[i].height;
2358 cur->nclr = cde[i].nclr;
2359 /* The next two are to support color cursors */
2360 cur->planes = ((BITMAPINFOHEADER *)BPTR(cde[i].offset))->biPlanes;
2361 cur->bits = ((BITMAPINFOHEADER *)BPTR(cde[i].offset))->biBitCount;
2362 if(!win32 && (cur->planes != 1 || cur->bits != 1))
2363 yywarning("Win16 cursor contains colors");
2364 cur->xhot = cde[i].xhot;
2365 cur->yhot = cde[i].yhot;
2366 cur->data = new_raw_data();
2367 copy_raw_data(cur->data, rd, cde[i].offset, cde[i].ressize);
2379 curg->cursorlist = list;
2388 toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2397 toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)