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
108 DWORD andmask; /* Used to parse 'NOT NUMBER' expressions */
109 int indialog = 0; /* Signal flex that we're parsing a dialog */
110 int want_rscname = 0; /* Set when a resource's name is required */
111 stringtable_t *tagstt; /* Stringtable tag.
112 * It is set while parsing a stringtable to one of
113 * the stringtables in the sttres list or a new one
114 * if the language was not parsed before.
116 stringtable_t *sttres; /* Stringtable resources. This holds the list of
117 * stringtables with different lanuages
119 /* Set to the current options of the currently scanning stringtable */
120 static int *tagstt_memopt;
121 static characts_t *tagstt_characts;
122 static version_t *tagstt_version;
124 /* Prototypes of here defined functions */
125 void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur);
126 void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico);
127 int alloc_cursor_id(language_t *);
128 int alloc_icon_id(language_t *);
129 void ins_stt_entry(stt_entry_t *ste);
130 int check_stt_entry(stringtable_t *tabs, stt_entry_t *ste);
131 event_t *get_event_head(event_t *p);
132 control_t *get_control_head(control_t *p);
133 ver_value_t *get_ver_value_head(ver_value_t *p);
134 ver_block_t *get_ver_block_head(ver_block_t *p);
135 resource_t *get_resource_head(resource_t *p);
136 menuex_item_t *get_itemex_head(menuex_item_t *p);
137 menu_item_t *get_item_head(menu_item_t *p);
138 raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
139 raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
140 raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
141 raw_data_t *str2raw_data(string_t *str);
142 raw_data_t *int2raw_data(int i);
143 raw_data_t *load_file(string_t *name);
144 itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
145 event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
146 event_t *add_event(int key, int id, int flags, event_t *prev);
147 dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
148 dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
149 dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
150 dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
151 dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
152 dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
153 dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
154 dialogex_t *dialogex_exstyle(int st, dialogex_t *dlg);
155 dialogex_t *dialogex_style(int st, dialogex_t *dlg);
156 name_id_t *convert_ctlclass(name_id_t *cls);
157 control_t *ins_ctrl(int type, int style, control_t *ctrl, control_t *prev);
158 dialog_t *dialog_version(version_t *v, dialog_t *dlg);
159 dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
160 dialog_t *dialog_language(language_t *l, dialog_t *dlg);
161 dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
162 dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
163 dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
164 dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
165 dialog_t *dialog_exstyle(int st, dialog_t *dlg);
166 dialog_t *dialog_style(int st, dialog_t *dlg);
167 resource_t *build_stt_resources(stringtable_t *stthead);
168 stringtable_t *find_stringtable(lvc_t *lvc);
169 toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
170 toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
181 cursor_group_t *curg;
203 menuex_item_t *menexitm;
211 toolbar_item_t *tlbarItems;
214 %token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
215 %token tTYPEDEF tEXTERN
217 %token <str> tSTRING IDENT FILENAME
219 %token ACCELERATORS tBITMAP CURSOR DIALOG DIALOGEX MENU MENUEX MESSAGETABLE
220 %token RCDATA VERSIONINFO STRINGTABLE FONT ICON
221 %token AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON CHECKBOX DEFPUSHBUTTON
222 %token PUSHBUTTON RADIOBUTTON STATE3 /* PUSHBOX */
223 %token GROUPBOX COMBOBOX LISTBOX SCROLLBAR
224 %token CONTROL EDITTEXT
225 %token RTEXT CTEXT LTEXT
227 %token SHIFT ALT ASCII VIRTKEY GRAYED CHECKED INACTIVE NOINVERT
228 %token tPURE IMPURE DISCARDABLE LOADONCALL PRELOAD tFIXED MOVEABLE
229 %token CLASS CAPTION CHARACTERISTICS EXSTYLE STYLE VERSION LANGUAGE
230 %token FILEVERSION PRODUCTVERSION FILEFLAGSMASK FILEOS FILETYPE FILEFLAGS FILESUBTYPE
231 %token MENUBARBREAK MENUBREAK MENUITEM POPUP SEPARATOR
233 %token tSTRING IDENT RAWDATA
234 %token TOOLBAR BUTTON
242 %left '<' LTE '>' GTE
247 %type <res> resource_file resource resources resource_definition
248 %type <stt> stringtable strings
251 %type <acc> accelerators
255 %type <dlg> dialog dlg_attributes
256 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
257 %type <iptr> optional_style helpid
258 %type <dlgex> dialogex dlgex_attribs
259 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
261 %type <raw> raw_data raw_elements opt_data
262 %type <veri> versioninfo fix_version
263 %type <verw> ver_words
264 %type <blk> ver_blocks ver_block
265 %type <val> ver_values ver_value
267 %type <menitm> item_definitions menu_body
269 %type <menexitm> itemex_definitions menuex_body
270 %type <exopt> itemex_p_options itemex_options
271 %type <msg> messagetable
273 %type <num> item_options
274 %type <nid> nameid nameid_s ctlclass usertype
276 %type <iptr> loadmemopts lamo lama
277 %type <fntid> opt_font opt_exfont
279 %type <lan> opt_language
280 %type <chars> opt_characts
281 %type <ver> opt_version
282 %type <num> expr xpr dummy
284 %type <iptr> pp_expr pp_constant
285 %type <tlbar> toolbar
286 %type <tlbarItems> toolbar_items
293 /* First add stringtables to the resource-list */
294 rsc = build_stt_resources(sttres);
295 /* 'build_stt_resources' returns a head and $1 is a tail */
304 /* Final statement before were done */
305 resource_top = get_resource_head($1);
309 /* Resources are put into a linked list */
311 : /* Empty */ { $$ = NULL; want_rscname = 1; }
312 | resources resource {
315 resource_t *tail = $2;
316 resource_t *head = $2;
328 resource_t *tail = $1;
337 | resources preprocessor { $$ = $1; want_rscname = 1; }
338 | resources cjunk { $$ = $1; want_rscname = 1; }
341 /* The buildin preprocessor */
343 : tIF pp_expr tNL { pop_start(); push_if($2 ? *($2) : 0, 0, 0); if($2) free($2);}
344 | tIFDEF IDENT tNL { pop_start(); push_if(pp_lookup($2->str.cstr) != NULL, 0, 0); }
345 | tIFNDEF IDENT tNL { pop_start(); push_if(pp_lookup($2->str.cstr) == NULL, 0, 0); }
346 | tELIF pp_expr tNL { pop_start(); push_if($2 ? *($2) : 0, pop_if(), 0); if($2) free($2); }
347 | tELSE tNL { pop_start(); push_if(1, pop_if(), 0); }
348 | tENDIF tNL { pop_if(); }
351 pp_expr : pp_constant { $$ = $1; }
352 | pp_expr LOGOR pp_expr { $$ = new_int($1 && $3 ? (*$1 || *$3) : 0); if($1) free($1); if($3) free($3); }
353 | pp_expr LOGAND 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 '^' pp_expr { $$ = new_int($1 && $3 ? (*$1 ^ *$3) : 0); if($1) free($1); if($3) free($3); }
357 | pp_expr EQ pp_expr { $$ = new_int($1 && $3 ? (*$1 == *$3) : 0); if($1) free($1); if($3) free($3); }
358 | pp_expr NE 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 '>' pp_expr { $$ = new_int($1 && $3 ? (*$1 > *$3) : 0); if($1) free($1); if($3) free($3); }
361 | pp_expr LTE pp_expr { $$ = new_int($1 && $3 ? (*$1 <= *$3) : 0); if($1) free($1); if($3) free($3); }
362 | pp_expr GTE pp_expr { $$ = new_int($1 && $3 ? (*$1 >= *$3) : 0); if($1) free($1); if($3) free($3); }
363 | '~' pp_expr { $$ = $2; if($2) *$2 = ~(*$2); }
364 | '+' pp_expr { $$ = $2; }
365 | '-' pp_expr { $$ = $2; if($2) *$2 = -(*$2); }
366 | '!' pp_expr { $$ = $2; if($2) *$2 = !(*$2); }
367 | '(' pp_expr ')' { $$ = $2; }
371 : NUMBER { $$ = new_int($1); }
372 | IDENT { $$ = NULL; }
373 | tDEFINED IDENT { $$ = new_int(pp_lookup($2->str.cstr) != NULL); }
374 | tDEFINED '(' IDENT ')' { $$ = new_int(pp_lookup($3->str.cstr) != NULL); }
378 cjunk : tTYPEDEF { strip_til_semicolon(); }
379 | tEXTERN { strip_til_semicolon(); }
380 | IDENT IDENT { strip_til_semicolon(); }
381 | IDENT '(' { strip_til_parenthesis(); }
382 | IDENT '*' { strip_til_semicolon(); }
385 /* Parse top level resource definitions etc. */
387 : nameid resource_definition {
392 if($1->type == name_ord)
394 chat("Got %s (%d)",get_typename($2),$1->name.i_name);
396 else if($1->type == name_str)
398 chat("Got %s (%s)",get_typename($2),$1->name.s_name->str.cstr);
403 /* Don't do anything, stringtables are converted to
404 * resource_t structures when we are finished parsing and
405 * the final rule of the parser is reduced (see above)
408 chat("Got STRINGTABLE");
412 yywarning("LANGUAGE not supported in 16-bit mode");
414 free(currentlanguage);
415 currentlanguage = $1;
421 * Get a valid name/id
426 $$->name.i_name = $1;
432 $$->name.s_name = $1;
438 * Extra string recognition for CLASS statement in dialogs
440 nameid_s: nameid { $$ = $1; }
444 $$->name.s_name = $1;
449 /* get the value for a single resource*/
451 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
452 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, dup_language(currentlanguage)); }
456 $$ = rsc = new_resource(res_curg, $1, $1->memopt, dup_language(currentlanguage));
457 for(cur = $1->cursorlist; cur; cur = cur->next)
459 rsc->prev = new_resource(res_cur, cur, $1->memopt, dup_language(currentlanguage));
460 rsc->prev->next = rsc;
462 rsc->name = new_name_id();
463 rsc->name->type = name_ord;
464 rsc->name->name.i_name = cur->id;
467 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
470 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
474 | font { $$=new_resource(res_fnt, $1, $1->memopt, dup_language(currentlanguage)); }
478 $$ = rsc = new_resource(res_icog, $1, $1->memopt, dup_language(currentlanguage));
479 for(ico = $1->iconlist; ico; ico = ico->next)
481 rsc->prev = new_resource(res_ico, ico, $1->memopt, dup_language(currentlanguage));
482 rsc->prev->next = rsc;
484 rsc->name = new_name_id();
485 rsc->name->type = name_ord;
486 rsc->name->name.i_name = ico->id;
489 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
492 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
496 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
497 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->lvc.language); }
498 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
499 | userres { $$ = new_resource(res_usr, $1, $1->memopt, dup_language(currentlanguage)); }
500 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
503 /* ------------------------------ Bitmap ------------------------------ */
504 bitmap : tBITMAP loadmemopts FILENAME { $$ = new_bitmap(load_file($3), $2); }
505 | tBITMAP loadmemopts raw_data { $$ = new_bitmap($3, $2); }
508 /* ------------------------------ Cursor ------------------------------ */
509 cursor : CURSOR loadmemopts FILENAME { $$ = new_cursor_group(load_file($3), $2); }
510 | CURSOR loadmemopts raw_data { $$ = new_cursor_group($3, $2); }
513 /* ------------------------------ Font ------------------------------ */
514 /* FIXME: Should we allow raw_data here? */
515 font : FONT loadmemopts FILENAME { $$ = new_font(load_file($3), $2); }
518 /* ------------------------------ Icon ------------------------------ */
519 icon : ICON loadmemopts FILENAME { $$ = new_icon_group(load_file($3), $2); }
520 | ICON loadmemopts raw_data { $$ = new_icon_group($3, $2); }
523 /* ------------------------------ MessageTable ------------------------------ */
524 /* It might be interesting to implement the MS Message compiler here as well
525 * to get everything in one source. Might be a future project.
528 : MESSAGETABLE FILENAME {
530 yywarning("MESSAGETABLE not supported in 16-bit mode");
531 $$ = new_messagetable(load_file($2));
535 /* ------------------------------ RCData ------------------------------ */
536 rcdata : RCDATA loadmemopts opt_lvc raw_data {
537 $$ = new_rcdata($4, $2);
543 if(!$$->lvc.language)
544 $$->lvc.language = dup_language(currentlanguage);
548 /* ------------------------------ UserType ------------------------------ */
549 userres : usertype loadmemopts FILENAME { $$ = new_user($1, load_file($3), $2); }
550 | usertype loadmemopts raw_data { $$ = new_user($1, $3, $2); }
553 /* NOTE: This here is an exception where I do not allow an expression.
554 * Reason for this is that it is not possible to set the 'yywf' condition
555 * for flex if loadmemopts is empty. Reading an expression requires a
556 * lookahead to determine its end. In this case here, that would mean that
557 * the filename has been read as IDENT or tSTRING, which is incorrect.
558 * Note also that IDENT cannot be used as a file-name because it is lacking
562 /* I also allow string identifiers as classtypes. Not MS implemented, but
563 * seems to be reasonable to implement.
565 /* Allowing anything else than NUMBER makes it very hard to get rid of
566 * prototypes. So, I remove IDENT to be able to get prototypes out of the
572 $$->name.i_name = $1;
578 $$->name.s_name = $1;
584 $$->name.s_name = $1;
589 /* ------------------------------ Accelerator ------------------------------ */
591 : ACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
592 $$ = new_accelerator();
600 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
603 yyerror("Accelerator table must have at least one entry");
604 $$->events = get_event_head($5);
610 if(!$$->lvc.language)
611 $$->lvc.language = dup_language(currentlanguage);
615 events : /* Empty */ { $$=NULL; }
616 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
617 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
620 acc_opt : /* Empty */ { $$=0; }
621 | acc_opt ',' NOINVERT { $$=$1 | WRC_AF_NOINVERT; }
622 | acc_opt ',' SHIFT { $$=$1 | WRC_AF_SHIFT; }
623 | acc_opt ',' CONTROL { $$=$1 | WRC_AF_CONTROL; }
624 | acc_opt ',' ALT { $$=$1 | WRC_AF_ALT; }
625 | acc_opt ',' ASCII { $$=$1 | WRC_AF_ASCII; }
626 | acc_opt ',' VIRTKEY { $$=$1 | WRC_AF_VIRTKEY; }
629 /* ------------------------------ Dialog ------------------------------ */
630 /* FIXME: Support EXSTYLE in the dialog line itself */
631 dialog : DIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
639 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
644 $10->controls = get_control_head($12);
648 $$->style = WS_POPUP;
652 $$->style |= WS_CAPTION;
654 $$->style |= DS_SETFONT;
656 if(!$$->lvc.language)
657 $$->lvc.language = dup_language(currentlanguage);
662 : /* Empty */ { $$=new_dialog(); }
663 | dlg_attributes STYLE expr { $$=dialog_style($3,$1); }
664 | dlg_attributes EXSTYLE expr { $$=dialog_exstyle($3,$1); }
665 | dlg_attributes CAPTION tSTRING { $$=dialog_caption($3,$1); }
666 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
667 | dlg_attributes CLASS nameid_s { $$=dialog_class($3,$1); }
668 | dlg_attributes MENU nameid { $$=dialog_menu($3,$1); }
669 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
670 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
671 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
674 ctrls : /* Empty */ { $$ = NULL; }
675 | ctrls CONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
676 | ctrls EDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
677 | ctrls LISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
678 | ctrls COMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
679 | ctrls SCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
680 | ctrls CHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
681 | ctrls DEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
682 | ctrls GROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
683 | ctrls PUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
684 /* | ctrls PUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
685 | ctrls RADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
686 | ctrls AUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
687 | ctrls STATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
688 | ctrls AUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
689 | ctrls AUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
690 | ctrls LTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
691 | ctrls CTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
692 | ctrls RTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
693 /* special treatment for icons, as the extent is optional */
694 | ctrls ICON nameid_s ',' expr ',' expr ',' expr iconinfo {
695 if($3->type == name_str)
697 $10->title = $3->name.s_name;
706 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
711 : tSTRING ',' expr ',' expr ',' expr ',' expr ',' expr optional_style {
729 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
745 iconinfo: /* Empty */
746 { $$ = new_control(); }
748 | ',' expr ',' expr {
753 | ',' expr ',' expr ',' expr {
760 | ',' expr ',' expr ',' expr ',' expr {
767 $$->gotexstyle = TRUE;
771 gen_ctrl: tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ',' expr ',' expr {
775 $$->ctlclass = convert_ctlclass($5);
783 $$->gotexstyle = TRUE;
785 | tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ',' expr {
789 $$->ctlclass = convert_ctlclass($5);
800 : FONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
803 optional_style /* Abbused once to get optional ExStyle */
804 : /* Empty */ { $$ = NULL; }
805 | ',' expr { $$ = new_int($2); }
812 $$->name.i_name = $1;
817 $$->name.s_name = $1;
821 /* ------------------------------ DialogEx ------------------------------ */
822 dialogex: DIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
823 tBEGIN exctrls tEND {
825 yywarning("DIALOGEX not supported in 16-bit mode");
832 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
839 $11->helpid = *($10);
840 $11->gothelpid = TRUE;
843 $11->controls = get_control_head($13);
847 $$->style = WS_POPUP;
851 $$->style |= WS_CAPTION;
853 $$->style |= DS_SETFONT;
855 if(!$$->lvc.language)
856 $$->lvc.language = dup_language(currentlanguage);
861 : /* Empty */ { $$=new_dialogex(); }
862 | dlgex_attribs STYLE expr { $$=dialogex_style($3,$1); }
863 | dlgex_attribs EXSTYLE expr { $$=dialogex_exstyle($3,$1); }
864 | dlgex_attribs CAPTION tSTRING { $$=dialogex_caption($3,$1); }
865 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
866 | dlgex_attribs CLASS nameid_s { $$=dialogex_class($3,$1); }
867 | dlgex_attribs MENU nameid { $$=dialogex_menu($3,$1); }
868 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
869 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
870 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
873 exctrls : /* Empty */ { $$ = NULL; }
874 | exctrls CONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
875 | exctrls EDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
876 | exctrls LISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
877 | exctrls COMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
878 | exctrls SCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
879 | exctrls CHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
880 | exctrls DEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
881 | exctrls GROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
882 | exctrls PUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
883 /* | exctrls PUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
884 | exctrls RADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
885 | exctrls AUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
886 | exctrls STATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
887 | exctrls AUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
888 | exctrls AUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
889 | exctrls LTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
890 | exctrls CTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
891 | exctrls RTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
892 /* special treatment for icons, as the extent is optional */
893 | exctrls ICON tSTRING ',' expr ',' expr ',' expr iconinfo {
898 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
903 : tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ','
904 expr ',' e_expr helpid opt_data {
908 $$->ctlclass = convert_ctlclass($5);
917 $$->exstyle = *($17);
918 $$->gotexstyle = TRUE;
924 $$->gothelpid = TRUE;
929 | tSTRING ',' expr ',' ctlclass ',' expr ',' expr ',' expr ',' expr ',' expr opt_data {
935 $$->ctlclass = convert_ctlclass($5);
945 : tSTRING ',' expr ',' expr ',' expr ',' expr ',' expr optional_style opt_data {
964 : expr ',' expr ',' expr ',' expr ',' expr optional_style opt_data {
981 opt_data: /* Empty */ { $$ = NULL; }
982 | raw_data { $$ = $1; }
985 helpid : /* Empty */ { $$ = NULL; }
986 | ',' expr { $$ = new_int($2); }
990 : FONT expr ',' tSTRING ',' expr ',' expr { $$ = new_font_id($2, $4, $6, $8); }
993 /* ------------------------------ Menu ------------------------------ */
994 menu : MENU loadmemopts opt_lvc menu_body {
996 yyerror("Menu must contain items");
1004 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1005 $$->items = get_item_head($4);
1011 if(!$$->lvc.language)
1012 $$->lvc.language = dup_language(currentlanguage);
1017 : tBEGIN item_definitions tEND { $$ = $2; }
1021 : /* Empty */ {$$ = NULL;}
1022 | item_definitions MENUITEM tSTRING ',' expr item_options {
1031 | item_definitions MENUITEM SEPARATOR {
1037 | item_definitions POPUP tSTRING item_options menu_body {
1038 $$ = new_menu_item();
1042 $$->popup = get_item_head($5);
1047 /* NOTE: item_options is right recursive because it would introduce
1048 * a shift/reduce conflict on ',' in itemex_options due to the
1049 * empty rule here. The parser is now forced to look beyond the ','
1050 * before reducing (force shift).
1051 * Right recursion here is not a problem because we cannot expect
1052 * more than 7 parserstack places to be occupied while parsing this
1053 * (who would want to specify a MF_x flag twice?).
1056 : /* Empty */ { $$ = 0; }
1057 | ',' CHECKED item_options { $$ = $3 | MF_CHECKED; }
1058 | ',' GRAYED item_options { $$ = $3 | MF_GRAYED; }
1059 | ',' HELP item_options { $$ = $3 | MF_HELP; }
1060 | ',' INACTIVE item_options { $$ = $3 | MF_DISABLED; }
1061 | ',' MENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1062 | ',' MENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1065 /* ------------------------------ MenuEx ------------------------------ */
1066 menuex : MENUEX loadmemopts opt_lvc menuex_body {
1068 yywarning("MENUEX not supported in 16-bit mode");
1070 yyerror("MenuEx must contain items");
1078 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1079 $$->items = get_itemex_head($4);
1085 if(!$$->lvc.language)
1086 $$->lvc.language = dup_language(currentlanguage);
1091 : tBEGIN itemex_definitions tEND { $$ = $2; }
1095 : /* Empty */ {$$ = NULL; }
1096 | itemex_definitions MENUITEM tSTRING itemex_options {
1097 $$ = new_menuex_item();
1103 $$->type = $4->type;
1104 $$->state = $4->state;
1105 $$->helpid = $4->helpid;
1106 $$->gotid = $4->gotid;
1107 $$->gottype = $4->gottype;
1108 $$->gotstate = $4->gotstate;
1109 $$->gothelpid = $4->gothelpid;
1112 | itemex_definitions MENUITEM SEPARATOR {
1113 $$ = new_menuex_item();
1118 | itemex_definitions POPUP tSTRING itemex_p_options menuex_body {
1119 $$ = new_menuex_item();
1123 $$->popup = get_itemex_head($5);
1126 $$->type = $4->type;
1127 $$->state = $4->state;
1128 $$->helpid = $4->helpid;
1129 $$->gotid = $4->gotid;
1130 $$->gottype = $4->gottype;
1131 $$->gotstate = $4->gotstate;
1132 $$->gothelpid = $4->gothelpid;
1138 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1140 $$ = new_itemex_opt($2, 0, 0, 0);
1143 | ',' e_expr ',' e_expr item_options {
1144 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1147 $$->gotstate = TRUE;
1151 | ',' e_expr ',' e_expr ',' expr {
1152 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1155 $$->gotstate = TRUE;
1162 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1164 $$ = new_itemex_opt($2, 0, 0, 0);
1167 | ',' e_expr ',' expr {
1168 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1173 | ',' e_expr ',' e_expr ',' expr {
1174 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1179 $$->gotstate = TRUE;
1181 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1182 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1188 $$->gotstate = TRUE;
1189 $$->gothelpid = TRUE;
1193 /* ------------------------------ StringTable ------------------------------ */
1194 /* Stringtables are parsed differently than other resources because their
1195 * layout is substantially different from other resources.
1196 * The table is parsed through a _global_ variable 'tagstt' which holds the
1197 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1198 * list of stringtables of different languages.
1201 : stt_head tBEGIN strings tEND {
1204 yyerror("Stringtable must have at least one entry");
1209 /* Check if we added to a language table or created
1212 for(stt = sttres; stt; stt = stt->next)
1219 /* It is a new one */
1222 sttres->prev = tagstt;
1223 tagstt->next = sttres;
1229 /* Else were done */
1233 free(tagstt_memopt);
1234 tagstt_memopt = NULL;
1241 /* This is to get the language of the currently parsed stringtable */
1242 stt_head: STRINGTABLE loadmemopts opt_lvc {
1243 if((tagstt = find_stringtable($3)) == NULL)
1244 tagstt = new_stringtable($3);
1246 tagstt_version = $3->version;
1247 tagstt_characts = $3->characts;
1253 strings : /* Empty */ { $$ = NULL; }
1254 | strings expr opt_comma tSTRING {
1256 assert(tagstt != NULL);
1257 /* Search for the ID */
1258 for(i = 0; i < tagstt->nentries; i++)
1260 if(tagstt->entries[i].id == $2)
1261 yyerror("Stringtable ID %d already in use", $2);
1263 /* If we get here, then we have a new unique entry */
1265 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1266 tagstt->entries[tagstt->nentries-1].id = $2;
1267 tagstt->entries[tagstt->nentries-1].str = $4;
1269 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1271 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1272 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1273 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1275 if(!win32 && $4->size > 254)
1276 yyerror("Stringtable entry more than 254 characters");
1277 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1278 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1283 opt_comma /* There seem to be two ways to specify a stringtable... */
1288 /* ------------------------------ VersionInfo ------------------------------ */
1290 : VERSIONINFO fix_version tBEGIN ver_blocks tEND {
1292 $2->blocks = get_ver_block_head($4);
1297 : /* Empty */ { $$ = new_versioninfo(); }
1298 | fix_version FILEVERSION expr ',' expr ',' expr ',' expr {
1300 yyerror("FILEVERSION already defined");
1302 $$->filever_maj1 = $3;
1303 $$->filever_maj2 = $5;
1304 $$->filever_min1 = $7;
1305 $$->filever_min2 = $9;
1308 | fix_version PRODUCTVERSION expr ',' expr ',' expr ',' expr {
1310 yyerror("PRODUCTVERSION already defined");
1312 $$->prodver_maj1 = $3;
1313 $$->prodver_maj2 = $5;
1314 $$->prodver_min1 = $7;
1315 $$->prodver_min2 = $9;
1318 | fix_version FILEFLAGS expr {
1320 yyerror("FILEFLAGS already defined");
1325 | fix_version FILEFLAGSMASK expr {
1327 yyerror("FILEFLAGSMASK already defined");
1329 $$->fileflagsmask = $3;
1332 | fix_version FILEOS expr {
1334 yyerror("FILEOS already defined");
1339 | fix_version FILETYPE expr {
1341 yyerror("FILETYPE already defined");
1346 | fix_version FILESUBTYPE expr {
1348 yyerror("FILESUBTYPE already defined");
1350 $$->filesubtype = $3;
1356 : /* Empty */ { $$ = NULL; }
1357 | ver_blocks ver_block {
1366 : BLOCK tSTRING tBEGIN ver_values tEND {
1367 $$ = new_ver_block();
1369 $$->values = get_ver_value_head($4);
1374 : /* Empty */ { $$ = NULL; }
1375 | ver_values ver_value {
1385 $$ = new_ver_value();
1386 $$->type = val_block;
1387 $$->value.block = $1;
1389 | VALUE tSTRING ',' tSTRING {
1390 $$ = new_ver_value();
1395 | VALUE tSTRING ',' ver_words {
1396 $$ = new_ver_value();
1397 $$->type = val_words;
1399 $$->value.words = $4;
1404 : expr { $$ = new_ver_words($1); }
1405 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1408 /* ------------------------------ Toolbar ------------------------------ */
1409 toolbar: TOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1411 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1412 $$ = new_toolbar($3, $5, items, nitems);
1420 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1427 if(!$$->lvc.language)
1429 $$->lvc.language = dup_language(currentlanguage);
1435 : /* Empty */ { $$ = NULL; }
1436 | toolbar_items BUTTON expr {
1437 toolbar_item_t *idrec = new_toolbar_item();
1439 $$ = ins_tlbr_button($1, idrec);
1441 | toolbar_items SEPARATOR {
1442 toolbar_item_t *idrec = new_toolbar_item();
1444 $$ = ins_tlbr_button($1, idrec);
1448 /* ------------------------------ Memory options ------------------------------ */
1450 : /* Empty */ { $$ = NULL; }
1451 | loadmemopts lamo {
1461 | loadmemopts lama {
1470 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1476 lamo : PRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1477 | MOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1478 | DISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1479 | tPURE { $$ = new_int(WRC_MO_PURE); }
1482 lama : LOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1483 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1484 | IMPURE { $$ = new_int(~WRC_MO_PURE); }
1487 /* ------------------------------ Win32 options ------------------------------ */
1488 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1489 | opt_lvc opt_language {
1491 yywarning("LANGUAGE not supported in 16-bit mode");
1493 yyerror("Language already defined");
1497 | opt_lvc opt_characts {
1499 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1501 yyerror("Characteristics already defined");
1505 | opt_lvc opt_version {
1507 yywarning("VERSION not supported in 16-bit mode");
1509 yyerror("Version already defined");
1516 : LANGUAGE expr ',' expr { $$ = new_language($2, $4); }
1520 : CHARACTERISTICS expr { $$ = new_characts($2); }
1524 : VERSION expr { $$ = new_version($2); }
1527 /* ------------------------------ Raw data handking ------------------------------ */
1528 raw_data: tBEGIN raw_elements tEND { $$ = $2; }
1532 : RAWDATA { $$ = $1; }
1533 | NUMBER { $$ = int2raw_data($1); }
1534 | tSTRING { $$ = str2raw_data($1); }
1535 | raw_elements opt_comma RAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1536 | raw_elements opt_comma NUMBER { $$ = merge_raw_data_int($1, $3); }
1537 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1540 /* ------------------------------ Win32 expressions ------------------------------ */
1541 /* All win16 numbers are also handled here. This is inconsistent with MS'
1542 * resource compiler, but what the heck, its just handy to have.
1544 e_expr : /* Empty */ { $$ = 0; }
1545 | expr { $$ = new_int($1); }
1547 expr : dummy xpr { $$ = ($2) & andmask; }
1550 dummy : /* Empty */ { $$ = 0; andmask = -1; }
1553 xpr : 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 '/' xpr { $$ = ($1) / ($3); }
1559 | '~' xpr { $$ = ~($2); }
1560 | '-' xpr { $$ = -($2); } /* FIXME: shift/reduce conflict */
1561 /* | '+' xpr { $$ = $2; } */
1562 | '(' xpr ')' { $$ = $2; }
1563 | NUMBER { $$ = $1; want_rscname = 0; }
1564 | NOT NUMBER { $$ = 0; andmask &= ~($2); }
1567 /* Dialog specific functions */
1568 dialog_t *dialog_style(int st, dialog_t *dlg)
1571 assert(dlg != NULL);
1574 yywarning("Style already defined, or-ing together");
1577 dlg->style = st | s;
1578 dlg->gotstyle = TRUE;
1582 dialog_t *dialog_exstyle(int st, dialog_t *dlg)
1585 assert(dlg != NULL);
1588 yywarning("ExStyle already defined, or-ing together");
1591 dlg->exstyle = st | s;
1592 dlg->gotexstyle = TRUE;
1596 dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1598 assert(dlg != NULL);
1600 yyerror("Caption already defined");
1605 dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1607 assert(dlg != NULL);
1609 yyerror("Font already defined");
1614 dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1616 assert(dlg != NULL);
1618 yyerror("Class already defined");
1623 dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1625 assert(dlg != NULL);
1627 yyerror("Menu already defined");
1632 dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1634 assert(dlg != NULL);
1635 if(dlg->lvc.language)
1636 yyerror("Language already defined");
1637 dlg->lvc.language = l;
1641 dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1643 assert(dlg != NULL);
1644 if(dlg->lvc.characts)
1645 yyerror("Characteristics already defined");
1646 dlg->lvc.characts = c;
1650 dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1652 assert(dlg != NULL);
1653 if(dlg->lvc.version)
1654 yyerror("Version already defined");
1655 dlg->lvc.version = v;
1659 /* Controls specific functions */
1660 control_t *ins_ctrl(int type, int style, control_t *ctrl, control_t *prev)
1662 assert(ctrl != NULL);
1668 ctrl->ctlclass = new_name_id();
1669 ctrl->ctlclass->type = name_ord;
1670 ctrl->ctlclass->name.i_name = type;
1673 /* Hm... this seems to be jammed in at all time... */
1674 ctrl->style |= WS_CHILD | WS_VISIBLE;
1678 ctrl->style |= style;
1679 if(style != BS_GROUPBOX && style != BS_RADIOBUTTON)
1680 ctrl->style |= WS_TABSTOP;
1683 ctrl->style |= WS_TABSTOP | WS_BORDER;
1686 ctrl->style |= LBS_NOTIFY | WS_BORDER;
1689 ctrl->style |= CBS_SIMPLE;
1692 ctrl->style |= style;
1693 if(style == SS_CENTER || style == SS_LEFT || style == SS_RIGHT)
1694 ctrl->style |= WS_GROUP;
1698 if(!ctrl->gotstyle) /* Handle default style setting */
1703 ctrl->style |= ES_LEFT;
1706 ctrl->style |= LBS_NOTIFY;
1709 ctrl->style |= CBS_SIMPLE | WS_TABSTOP;
1712 ctrl->style |= SBS_HORZ;
1718 case BS_DEFPUSHBUTTON:
1721 /* case BS_PUSHBOX: */
1722 case BS_AUTORADIOBUTTON:
1725 case BS_AUTOCHECKBOX:
1726 ctrl->style |= WS_TABSTOP;
1729 yywarning("Unknown default button control-style 0x%08x", style);
1730 case BS_RADIOBUTTON:
1741 ctrl->style |= WS_GROUP;
1743 case SS_ICON: /* Special case */
1746 yywarning("Unknown default static control-style 0x%08x", style);
1750 case -1: /* Generic control */
1754 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
1758 /* The SS_ICON flag is always forced in for icon controls */
1759 if(type == CT_STATIC && style == SS_ICON)
1760 ctrl->style |= SS_ICON;
1762 ctrl->gotstyle = TRUE;
1767 name_id_t *convert_ctlclass(name_id_t *cls)
1772 if(cls->type == name_ord)
1774 assert(cls->type == name_str);
1775 if(cls->type == str_unicode)
1777 yyerror("Don't yet support unicode class comparison");
1780 cc = cls->name.s_name->str.cstr;
1782 if(!strcasecmp("BUTTON", cc))
1784 else if(!strcasecmp("COMBOBOX", cc))
1785 iclass = CT_COMBOBOX;
1786 else if(!strcasecmp("LISTBOX", cc))
1787 iclass = CT_LISTBOX;
1788 else if(!strcasecmp("EDIT", cc))
1790 else if(!strcasecmp("STATIC", cc))
1792 else if(!strcasecmp("SCROLLBAR", cc))
1793 iclass = CT_SCROLLBAR;
1795 return cls; /* No default, return user controlclass */
1797 free(cls->name.s_name->str.cstr);
1798 free(cls->name.s_name);
1799 cls->type = name_ord;
1800 cls->name.i_name = iclass;
1804 /* DialogEx specific functions */
1805 dialogex_t *dialogex_style(int st, dialogex_t *dlg)
1808 assert(dlg != NULL);
1811 yywarning("Style already defined, or-ing together");
1814 dlg->style = st | s;
1815 dlg->gotstyle = TRUE;
1819 dialogex_t *dialogex_exstyle(int st, dialogex_t *dlg)
1822 assert(dlg != NULL);
1825 yywarning("ExStyle already defined, or-ing together");
1828 dlg->exstyle = st | s;
1829 dlg->gotexstyle = TRUE;
1833 dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
1835 assert(dlg != NULL);
1837 yyerror("Caption already defined");
1842 dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
1844 assert(dlg != NULL);
1846 yyerror("Font already defined");
1851 dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
1853 assert(dlg != NULL);
1855 yyerror("Class already defined");
1860 dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
1862 assert(dlg != NULL);
1864 yyerror("Menu already defined");
1869 dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
1871 assert(dlg != NULL);
1872 if(dlg->lvc.language)
1873 yyerror("Language already defined");
1874 dlg->lvc.language = l;
1878 dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
1880 assert(dlg != NULL);
1881 if(dlg->lvc.characts)
1882 yyerror("Characteristics already defined");
1883 dlg->lvc.characts = c;
1887 dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
1889 assert(dlg != NULL);
1890 if(dlg->lvc.version)
1891 yyerror("Version already defined");
1892 dlg->lvc.version = v;
1896 /* Accelerator specific functions */
1897 event_t *add_event(int key, int id, int flags, event_t *prev)
1899 event_t *ev = new_event();
1901 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
1902 yyerror("Cannot use both ASCII and VIRTKEY");
1906 ev->flags = flags & ~WRC_AF_ASCII;
1913 event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
1916 event_t *ev = new_event();
1918 if(key->type != str_char)
1919 yyerror("Key code must be an ascii string");
1921 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0]) && !isdigit(key->str.cstr[0])))
1922 yyerror("VIRTKEY code is not equal to ascii value");
1924 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
1926 yyerror("Cannot use both '^' and CONTROL modifier");
1928 else if(key->str.cstr[0] == '^')
1930 keycode = toupper(key->str.cstr[1]) - '@';
1932 yyerror("Control-code out of range");
1935 keycode = key->str.cstr[0];
1938 ev->flags = flags & ~WRC_AF_ASCII;
1945 /* MenuEx specific functions */
1946 itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
1948 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
1952 opt->helpid = helpid;
1956 /* Raw data functions */
1957 raw_data_t *load_file(string_t *name)
1961 if(name->type != str_char)
1962 yyerror("Filename must be ASCII string");
1964 fp = open_include(name->str.cstr, 1);
1966 yyerror("Cannot open file %s", name->str.cstr);
1967 rd = new_raw_data();
1968 fseek(fp, 0, SEEK_END);
1969 rd->size = ftell(fp);
1970 fseek(fp, 0, SEEK_SET);
1971 rd->data = (char *)xmalloc(rd->size);
1972 fread(rd->data, rd->size, 1, fp);
1978 raw_data_t *int2raw_data(int i)
1981 rd = new_raw_data();
1982 rd->size = sizeof(short);
1983 rd->data = (char *)xmalloc(rd->size);
1984 *(short *)(rd->data) = (short)i;
1988 raw_data_t *str2raw_data(string_t *str)
1991 rd = new_raw_data();
1992 rd->size = str->size * (str->type == str_char ? 1 : 2);
1993 rd->data = (char *)xmalloc(rd->size);
1994 memcpy(rd->data, str->str.cstr, rd->size);
1998 raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2000 r1->data = xrealloc(r1->data, r1->size + r2->size);
2001 memcpy(r1->data + r1->size, r2->data, r2->size);
2002 r1->size += r2->size;
2006 raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2008 raw_data_t *t = int2raw_data(i);
2009 merge_raw_data(r1, t);
2015 raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2017 raw_data_t *t = str2raw_data(str);
2018 merge_raw_data(r1, t);
2024 /* Function the go back in a list to get the head */
2025 menu_item_t *get_item_head(menu_item_t *p)
2034 menuex_item_t *get_itemex_head(menuex_item_t *p)
2043 resource_t *get_resource_head(resource_t *p)
2052 ver_block_t *get_ver_block_head(ver_block_t *p)
2061 ver_value_t *get_ver_value_head(ver_value_t *p)
2070 control_t *get_control_head(control_t *p)
2079 event_t *get_event_head(event_t *p)
2088 /* Find a stringtable with given language */
2089 stringtable_t *find_stringtable(lvc_t *lvc)
2093 assert(lvc != NULL);
2096 lvc->language = dup_language(currentlanguage);
2098 for(stt = sttres; stt; stt = stt->next)
2100 if(stt->lvc.language->id == lvc->language->id
2101 && stt->lvc.language->id == lvc->language->id)
2103 /* Found a table with the same language */
2104 /* The version and characteristics are now handled
2105 * in the generation of the individual stringtables.
2106 * This enables localized analysis.
2107 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2108 || (!stt->lvc.version && lvc->version)
2109 || (stt->lvc.version && !lvc->version))
2110 yywarning("Stringtable's versions are not the same, using first definition");
2112 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2113 || (!stt->lvc.characts && lvc->characts)
2114 || (stt->lvc.characts && !lvc->characts))
2115 yywarning("Stringtable's characteristics are not the same, using first definition");
2123 /* qsort sorting function for string table entries */
2124 #define STE(p) ((stt_entry_t *)(p))
2125 int sort_stt_entry(const void *e1, const void *e2)
2127 return STE(e1)->id - STE(e2)->id;
2131 resource_t *build_stt_resources(stringtable_t *stthead)
2134 stringtable_t *newstt;
2136 resource_t *rsclist = NULL;
2137 resource_t *rsctail = NULL;
2142 characts_t *characts;
2148 /* For all languages defined */
2149 for(stt = stthead; stt; stt = stt->next)
2151 assert(stt->nentries > 0);
2153 /* Sort the entries */
2154 if(stt->nentries > 1)
2155 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2157 for(i = 0; i < stt->nentries; )
2159 newstt = new_stringtable(&stt->lvc);
2160 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2161 newstt->nentries = 16;
2162 newstt->idbase = stt->entries[i].id & ~0xf;
2163 for(j = 0; j < 16 && i < stt->nentries; j++)
2165 if(stt->entries[i].id - newstt->idbase == j)
2167 newstt->entries[j] = stt->entries[i];
2175 /* Check individual memory options and get
2176 * the first characteristics/version
2178 for(j = 0; j < 16; j++)
2180 if(!newstt->entries[j].str)
2182 andsum &= newstt->entries[j].memopt;
2183 orsum |= newstt->entries[j].memopt;
2185 characts = newstt->entries[j].characts;
2187 version = newstt->entries[j].version;
2191 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2193 /* Check version and characteristics */
2194 for(j = 0; j < 16; j++)
2197 && newstt->entries[j].characts
2198 && *newstt->entries[j].characts != *characts)
2199 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2201 && newstt->entries[j].version
2202 && *newstt->entries[j].version != *version)
2203 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2205 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2206 rsc->name = new_name_id();
2207 rsc->name->type = name_ord;
2208 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2209 rsc->memopt = andsum; /* Set to least common denominator */
2210 newstt->memopt = andsum;
2211 newstt->lvc.characts = characts;
2212 newstt->lvc.version = version;
2220 rsctail->next = rsc;
2221 rsc->prev = rsctail;
2229 /* Cursor and icon splitter functions */
2235 static int get_new_id(id_alloc_t **list, int *n, language_t *lan)
2238 assert(lan != NULL);
2239 assert(list != NULL);
2244 *list = (id_alloc_t *)xmalloc(sizeof(id_alloc_t));
2246 (*list)[0].lan = *lan;
2251 for(i = 0; i < *n; i++)
2253 if((*list)[i].lan.id == lan->id && (*list)[i].lan.sub == lan->sub)
2254 return ++((*list)[i].id);
2257 *list = (id_alloc_t *)xrealloc(*list, sizeof(id_alloc_t) * (*n+1));
2258 (*list)[*n].lan = *lan;
2264 int alloc_icon_id(language_t *lan)
2266 static id_alloc_t *idlist = NULL;
2269 return get_new_id(&idlist, &nid, lan);
2272 int alloc_cursor_id(language_t *lan)
2274 static id_alloc_t *idlist = NULL;
2277 return get_new_id(&idlist, &nid, lan);
2280 #define BPTR(base) ((char *)(rd->data + (base)))
2281 #define WPTR(base) ((WORD *)(rd->data + (base)))
2282 #define DPTR(base) ((DWORD *)(rd->data + (base)))
2283 void split_icons(raw_data_t *rd, icon_group_t *icog, int *nico)
2287 icon_dir_entry_t *ide;
2289 icon_t *list = NULL;
2291 /* FIXME: Distinguish between normal and animated icons (RIFF format) */
2293 yyerror("Icon resource data has invalid type id %d", WPTR(0)[1]);
2295 ide = (icon_dir_entry_t *)&(WPTR(0)[3]);
2296 for(i = 0; i < cnt; i++)
2299 ico->id = alloc_icon_id(icog->lvc.language);
2300 ico->lvc.language = dup_language(icog->lvc.language);
2301 if(ide[i].offset > rd->size
2302 || ide[i].offset + ide[i].ressize > rd->size)
2303 yyerror("Icon resource data corrupt");
2304 ico->width = ide[i].width;
2305 ico->height = ide[i].height;
2306 ico->nclr = ide[i].nclr;
2307 ico->planes = ide[i].planes;
2308 ico->bits = ide[i].bits;
2311 /* Argh! They did not fill out the resdir structure */
2312 ico->planes = ((BITMAPINFOHEADER *)BPTR(ide[i].offset))->biPlanes;
2316 /* Argh! They did not fill out the resdir structure */
2317 ico->bits = ((BITMAPINFOHEADER *)BPTR(ide[i].offset))->biBitCount;
2319 ico->data = new_raw_data();
2320 copy_raw_data(ico->data, rd, ide[i].offset, ide[i].ressize);
2332 icog->iconlist = list;
2336 void split_cursors(raw_data_t *rd, cursor_group_t *curg, int *ncur)
2340 cursor_dir_entry_t *cde;
2342 cursor_t *list = NULL;
2344 /* FIXME: Distinguish between normal and animated cursors (RIFF format)*/
2346 yyerror("Cursor resource data has invalid type id %d", WPTR(0)[1]);
2348 cde = (cursor_dir_entry_t *)&(WPTR(0)[3]);
2349 for(i = 0; i < cnt; i++)
2352 cur->id = alloc_cursor_id(curg->lvc.language);
2353 cur->lvc.language = dup_language(curg->lvc.language);
2354 if(cde[i].offset > rd->size
2355 || cde[i].offset + cde[i].ressize > rd->size)
2356 yyerror("Cursor resource data corrupt");
2357 cur->width = cde[i].width;
2358 cur->height = cde[i].height;
2359 cur->nclr = cde[i].nclr;
2360 /* The next two are to support color cursors */
2361 cur->planes = ((BITMAPINFOHEADER *)BPTR(cde[i].offset))->biPlanes;
2362 cur->bits = ((BITMAPINFOHEADER *)BPTR(cde[i].offset))->biBitCount;
2363 if(!win32 && (cur->planes != 1 || cur->bits != 1))
2364 yywarning("Win16 cursor contains colors");
2365 cur->xhot = cde[i].xhot;
2366 cur->yhot = cde[i].yhot;
2367 cur->data = new_raw_data();
2368 copy_raw_data(cur->data, rd, cde[i].offset, cde[i].ressize);
2380 curg->cursorlist = list;
2389 toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2398 toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)