3 * Copyright Martin von Loewis, 1994
4 * Copyright 1998 Bertho A. Stultiens (BS)
6 * 25-May-1998 BS - Found out that I need to support language, version
7 * and characteristics in inline resources (bitmap,
8 * cursor, etc) but they can also be specified with
9 * a filename. This renders my filename-scanning scheme
10 * worthless. Need to build newline parsing to solve
12 * It will come with version 1.1.0 (sigh).
14 * 19-May-1998 BS - Started to build a builtin preprocessor
16 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
17 * ideas had some serious flaws.
19 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
22 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
23 * - This file is growing too big. It is time to strip
24 * things and put it in a support file.
26 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
27 * resource will be created. This because the table
28 * has a different layout than other resources. The
29 * table has to be sorted, and divided into smaller
30 * resource entries (see comment in source).
32 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
33 * as string_t which include unicode strings upon
35 * - Parser now emits a warning when compiling win32
36 * extensions in win16 mode.
38 * 16-Apr-1998 BS - Raw data elements are now *optionally* seperated
39 * by commas. Read the comments in file sq2dq.l.
40 * - FIXME: there are instances in the source that rely
41 * on the fact that int==32bit and pointers are int size.
42 * - Fixed the conflict in menuex by changing a rule
43 * back into right recursion. See note in source.
44 * - UserType resources cannot have an expression as its
45 * typeclass. See note in source.
47 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
48 * get reduction of the parsestack.
49 * This also helps communication between bison and flex.
50 * Main advantage is that the Empty rule gets reduced
51 * first, which is used to allocate/link things.
52 * It also added a shift/reduce conflict in the menuex
53 * handling, due to expression/option possibility,
54 * although not serious.
56 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
57 * about making it more efficient, but readable (for me)
58 * and slightly easier to expand/change.
59 * This is done primarily by using more reduce states
60 * with many (intuitive) types for the various resource
62 * - Added expression handling for all resources where a
63 * number is accepted (not only for win32). Also added
64 * multiply and division (not MS compatible, but handy).
65 * Unary minus introduced a shift/reduce conflict, but
68 * 13-Apr-1998 BS - Reordered a lot of things
69 * - Made the source more readable
70 * - Added Win32 resource definitions
71 * - Corrected syntax problems with an old yacc (;)
72 * - Added extra comment about grammar
92 DWORD andmask
; /* Used to parse 'NOT NUMBER' expressions */
93 int indialog
= 0; /* Signal flex that we're parsing a dialog */
94 int want_rscname
= 0; /* Set when a resource's name is required */
95 stringtable_t
*tagstt
; /* Stringtable tag.
96 * It is set while parsing a stringtable to one of
97 * the stringtables in the sttres list or a new one
98 * if the language was not parsed before.
100 stringtable_t
*sttres
; /* Stringtable resources. This holds the list of
101 * stringtables with different lanuages
103 /* Set to the current options of the currently scanning stringtable */
104 static int *tagstt_memopt
;
105 static characts_t
*tagstt_characts
;
106 static version_t
*tagstt_version
;
108 /* Prototypes of here defined functions */
109 void split_cursors
(raw_data_t
*rd
, cursor_group_t
*curg
, int *ncur
);
110 void split_icons
(raw_data_t
*rd
, icon_group_t
*icog
, int *nico
);
111 int alloc_cursor_id
(void);
112 int alloc_icon_id
(void);
113 void ins_stt_entry
(stt_entry_t
*ste
);
114 int check_stt_entry
(stringtable_t
*tabs
, stt_entry_t
*ste
);
115 event_t
*get_event_head
(event_t
*p
);
116 control_t
*get_control_head
(control_t
*p
);
117 ver_value_t
*get_ver_value_head
(ver_value_t
*p
);
118 ver_block_t
*get_ver_block_head
(ver_block_t
*p
);
119 resource_t
*get_resource_head
(resource_t
*p
);
120 menuex_item_t
*get_itemex_head
(menuex_item_t
*p
);
121 menu_item_t
*get_item_head
(menu_item_t
*p
);
122 raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
);
123 raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
);
124 raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
);
125 raw_data_t
*str2raw_data
(string_t
*str
);
126 raw_data_t
*int2raw_data
(int i
);
127 raw_data_t
*load_file
(string_t
*name
);
128 itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
);
129 event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
);
130 event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
);
131 dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
);
132 dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
);
133 dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
);
134 dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
);
135 dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
);
136 dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
);
137 dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
);
138 dialogex_t
*dialogex_exstyle
(int st
, dialogex_t
*dlg
);
139 dialogex_t
*dialogex_style
(int st
, dialogex_t
*dlg
);
140 name_id_t
*convert_ctlclass
(name_id_t
*cls
);
141 control_t
*ins_ctrl
(int type
, int style
, control_t
*ctrl
, control_t
*prev
);
142 dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
);
143 dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
);
144 dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
);
145 dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
);
146 dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
);
147 dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
);
148 dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
);
149 dialog_t
*dialog_exstyle
(int st
, dialog_t
*dlg
);
150 dialog_t
*dialog_style
(int st
, dialog_t
*dlg
);
151 resource_t
*build_stt_resources
(stringtable_t
*stthead
);
152 stringtable_t
*find_stringtable
(lvc_t
*lvc
);
163 cursor_group_t
*curg
;
185 menuex_item_t
*menexitm
;
194 %token tIF tIFDEF tIFNDEF tELSE tELIF tENDIF tDEFINED tNL
195 %token tTYPEDEF tEXTERN
197 %token
<str
> tSTRING IDENT FILENAME
199 %token ACCELERATORS tBITMAP CURSOR DIALOG DIALOGEX MENU MENUEX MESSAGETABLE
200 %token RCDATA VERSIONINFO STRINGTABLE FONT ICON
201 %token AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON CHECKBOX DEFPUSHBUTTON
202 %token PUSHBUTTON RADIOBUTTON STATE3
/* PUSHBOX */
203 %token GROUPBOX COMBOBOX LISTBOX SCROLLBAR
204 %token CONTROL EDITTEXT
205 %token RTEXT CTEXT LTEXT
207 %token SHIFT ALT ASCII VIRTKEY GRAYED CHECKED INACTIVE NOINVERT
208 %token tPURE IMPURE DISCARDABLE LOADONCALL PRELOAD tFIXED MOVEABLE
209 %token CLASS CAPTION CHARACTERISTICS EXSTYLE STYLE VERSION LANGUAGE
210 %token FILEVERSION PRODUCTVERSION FILEFLAGSMASK FILEOS FILETYPE FILEFLAGS FILESUBTYPE
211 %token MENUBARBREAK MENUBREAK MENUITEM POPUP SEPARATOR
213 %token tSTRING IDENT RAWDATA
221 %left
'<' LTE
'>' GTE
226 %type
<res
> resource_file resource resources resource_definition
227 %type
<stt
> stringtable strings
230 %type
<acc
> accelerators
234 %type
<dlg
> dialog dlg_attributes
235 %type
<ctl
> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
236 %type
<iptr
> optional_style helpid
237 %type
<dlgex
> dialogex dlgex_attribs
238 %type
<ctl
> exctrls gen_exctrl lab_exctrl exctrl_desc
240 %type
<raw
> raw_data raw_elements opt_data
241 %type
<veri
> versioninfo fix_version
242 %type
<verw
> ver_words
243 %type
<blk
> ver_blocks ver_block
244 %type
<val
> ver_values ver_value
246 %type
<menitm
> item_definitions menu_body
248 %type
<menexitm
> itemex_definitions menuex_body
249 %type
<exopt
> itemex_p_options itemex_options
250 %type
<msg
> messagetable
252 %type
<num
> item_options
253 %type
<nid
> nameid ctlclass usertype
255 %type
<iptr
> loadmemopts lamo lama
256 %type
<fntid
> opt_font opt_exfont
258 %type
<lan
> opt_language
259 %type
<chars
> opt_characts
260 %type
<ver
> opt_version
261 %type
<num
> expr xpr dummy
263 %type
<iptr
> pp_expr pp_constant
270 /* First add stringtables to the resource-list */
271 rsc
= build_stt_resources
(sttres
);
272 /* 'build_stt_resources' returns a head and $1 is a tail */
281 /* Final statement before were done */
282 resource_top
= get_resource_head
($1);
286 /* Resources are put into a linked list */
288 : /* Empty */ { $$
= NULL
; want_rscname
= 1; }
289 | resources resource
{
292 resource_t
*tail
= $2;
293 resource_t
*head
= $2;
305 resource_t
*tail
= $1;
314 | resources preprocessor
{ $$
= $1; want_rscname
= 1; }
315 | resources cjunk
{ $$
= $1; want_rscname
= 1; }
318 /* The buildin preprocessor */
320 : tIF pp_expr tNL
{ pop_start
(); push_if
($2 ?
*($2) : 0, 0, 0); if
($2) free
($2);}
321 | tIFDEF IDENT tNL
{ pop_start
(); push_if
(pp_lookup
($2->str.cstr
) != NULL
, 0, 0); }
322 | tIFNDEF IDENT tNL
{ pop_start
(); push_if
(pp_lookup
($2->str.cstr
) == NULL
, 0, 0); }
323 | tELIF pp_expr tNL
{ pop_start
(); push_if
($2 ?
*($2) : 0, pop_if
(), 0); if
($2) free
($2); }
324 | tELSE tNL
{ pop_start
(); push_if
(1, pop_if
(), 0); }
325 | tENDIF tNL
{ pop_if
(); }
328 pp_expr
: pp_constant
{ $$
= $1; }
329 | pp_expr LOGOR pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 ||
*$3) : 0); if
($1) free
($1); if
($3) free
($3); }
330 | pp_expr LOGAND pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 && *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
331 | pp_expr
'+' pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 + *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
332 | pp_expr
'-' pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 - *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
333 | pp_expr
'^' pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 ^
*$3) : 0); if
($1) free
($1); if
($3) free
($3); }
334 | pp_expr EQ pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 == *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
335 | pp_expr NE pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 != *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
336 | pp_expr
'<' pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 < *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
337 | pp_expr
'>' pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 > *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
338 | pp_expr LTE pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 <= *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
339 | pp_expr GTE pp_expr
{ $$
= new_int
($1 && $3 ?
(*$1 >= *$3) : 0); if
($1) free
($1); if
($3) free
($3); }
340 |
'~' pp_expr
{ $$
= $2; if
($2) *$2 = ~
(*$2); }
341 |
'+' pp_expr
{ $$
= $2; }
342 |
'-' pp_expr
{ $$
= $2; if
($2) *$2 = -(*$2); }
343 |
'!' pp_expr
{ $$
= $2; if
($2) *$2 = !(*$2); }
344 |
'(' pp_expr
')' { $$
= $2; }
348 : NUMBER
{ $$
= new_int
($1); }
349 | IDENT
{ $$
= NULL
; }
350 | tDEFINED IDENT
{ $$
= new_int
(pp_lookup
($2->str.cstr
) != NULL
); }
351 | tDEFINED
'(' IDENT
')' { $$
= new_int
(pp_lookup
($3->str.cstr
) != NULL
); }
355 cjunk
: tTYPEDEF
{ strip_til_semicolon
(); }
356 | tEXTERN
{ strip_til_semicolon
(); }
357 | IDENT IDENT
{ strip_til_semicolon
(); }
358 | IDENT
'(' { strip_til_parenthesis
(); }
359 | IDENT
'*' { strip_til_semicolon
(); }
362 /* Parse top level resource definitions etc. */
364 : nameid resource_definition
{
369 if
($1->type
== name_ord
)
371 chat
("Got %s (%d)",get_typename
($2),$1->name.i_name
);
373 else if
($1->type
== name_str
)
375 chat
("Got %s (%s)",get_typename
($2),$1->name.s_name
->str.cstr
);
380 /* Don't do anything, stringtables are converted to
381 * resource_t structures when we are finished parsing and
382 * the final rule of the parser is reduced (see above)
385 chat
("Got STRINGTABLE");
389 yywarning
("LANGUAGE not supported in 16-bit mode");
391 free
(currentlanguage
);
392 currentlanguage
= $1;
398 * The problem here is that MENU MENU {...} is a valid (!) resource.
399 * The name-identifier is "MENU". We cannot parse this without generating
400 * an error. It would mean that a list of keywords must be added here
401 * and converted into a valid name_id_t structure.
406 $$
->name.i_name
= $1;
412 $$
->name.s_name
= $1;
417 /* get the value for a single resource*/
419 : accelerators
{ $$
= new_resource
(res_acc
, $1, $1->memopt
, $1->lvc.language
); }
420 | bitmap
{ $$
= new_resource
(res_bmp
, $1, $1->memopt
, currentlanguage
); }
424 $$
= rsc
= new_resource
(res_curg
, $1, $1->memopt
, currentlanguage
);
425 for
(cur
= $1->cursorlist
; cur
; cur
= cur
->next
)
427 rsc
->prev
= new_resource
(res_cur
, cur
, $1->memopt
, currentlanguage
);
428 rsc
->prev
->next
= rsc
;
430 rsc
->name
= new_name_id
();
431 rsc
->name
->type
= name_ord
;
432 rsc
->name
->name.i_name
= cur
->id
;
435 | dialog
{ $$
= new_resource
(res_dlg
, $1, $1->memopt
, $1->lvc.language
); }
438 $$
= new_resource
(res_dlgex
, $1, $1->memopt
, $1->lvc.language
);
442 | font
{ $$
=new_resource
(res_fnt
, $1, $1->memopt
, currentlanguage
); }
446 $$
= rsc
= new_resource
(res_icog
, $1, $1->memopt
, currentlanguage
);
447 for
(ico
= $1->iconlist
; ico
; ico
= ico
->next
)
449 rsc
->prev
= new_resource
(res_ico
, ico
, $1->memopt
, currentlanguage
);
450 rsc
->prev
->next
= rsc
;
452 rsc
->name
= new_name_id
();
453 rsc
->name
->type
= name_ord
;
454 rsc
->name
->name.i_name
= ico
->id
;
457 | menu
{ $$
= new_resource
(res_men
, $1, $1->memopt
, $1->lvc.language
); }
460 $$
= new_resource
(res_menex
, $1, $1->memopt
, $1->lvc.language
);
464 | messagetable
{ $$
= new_resource
(res_msg
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, currentlanguage
); }
465 | rcdata
{ $$
= new_resource
(res_rdt
, $1, $1->memopt
, $1->lvc.language
); }
466 | userres
{ $$
= new_resource
(res_usr
, $1, $1->memopt
, currentlanguage
); }
467 | versioninfo
{ $$
= new_resource
(res_ver
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, currentlanguage
); }
470 /* ------------------------------ Bitmap ------------------------------ */
471 bitmap
: tBITMAP loadmemopts FILENAME
{ $$
= new_bitmap
(load_file
($3), $2); }
472 | tBITMAP loadmemopts raw_data
{ $$
= new_bitmap
($3, $2); }
475 /* ------------------------------ Cursor ------------------------------ */
476 cursor
: CURSOR loadmemopts FILENAME
{ $$
= new_cursor_group
(load_file
($3), $2); }
477 | CURSOR loadmemopts raw_data
{ $$
= new_cursor_group
($3, $2); }
480 /* ------------------------------ Font ------------------------------ */
481 /* FIXME: Should we allow raw_data here? */
482 font
: FONT loadmemopts FILENAME
{ $$
= new_font
(load_file
($3), $2); }
485 /* ------------------------------ Icon ------------------------------ */
486 icon
: ICON loadmemopts FILENAME
{ $$
= new_icon_group
(load_file
($3), $2); }
487 | ICON loadmemopts raw_data
{ $$
= new_icon_group
($3, $2); }
490 /* ------------------------------ MessageTable ------------------------------ */
491 /* It might be interesting to implement the MS Message compiler here as well
492 * to get everything in one source. Might be a future project.
495 : MESSAGETABLE FILENAME
{
497 yywarning
("MESSAGETABLE not supported in 16-bit mode");
498 $$
= new_messagetable
(load_file
($2));
502 /* ------------------------------ RCData ------------------------------ */
503 rcdata
: RCDATA loadmemopts opt_lvc raw_data
{
504 $$
= new_rcdata
($4, $2);
510 if
(!$$
->lvc.language
)
511 $$
->lvc.language
= dup_language
(currentlanguage
);
515 /* ------------------------------ UserType ------------------------------ */
516 userres
: usertype loadmemopts FILENAME
{ $$
= new_user
($1, load_file
($3), $2); }
517 | usertype loadmemopts raw_data
{ $$
= new_user
($1, $3, $2); }
520 /* NOTE: This here is an exception where I do not allow an expression.
521 * Reason for this is that it is not possible to set the 'yywf' condition
522 * for flex if loadmemopts is empty. Reading an expression requires a
523 * lookahead to determine its end. In this case here, that would mean that
524 * the filename has been read as IDENT or tSTRING, which is incorrect.
525 * Note also that IDENT cannot be used as a file-name because it is lacking
529 /* I also allow string identifiers as classtypes. Not MS implemented, but
530 * seems to be reasonable to implement.
532 /* Allowing anything else than NUMBER makes it very hard to get rid of
533 * prototypes. So, I remove IDENT to be able to get prototypes out of the
539 $$
->name.i_name
= $1;
545 $$->name.s_name = $1;
551 $$
->name.s_name
= $1;
556 /* ------------------------------ Accelerator ------------------------------ */
558 : ACCELERATORS loadmemopts opt_lvc tBEGIN events tEND
{
559 $$
= new_accelerator
();
567 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE
;
570 yyerror("Accelerator table must have at least one entry");
571 $$
->events
= get_event_head
($5);
577 if
(!$$
->lvc.language
)
578 $$
->lvc.language
= dup_language
(currentlanguage
);
582 events
: /* Empty */ { $$
=NULL
; }
583 | events tSTRING
',' expr acc_opt
{ $$
=add_string_event
($2, $4, $5, $1); }
584 | events expr
',' expr acc_opt
{ $$
=add_event
($2, $4, $5, $1); }
587 acc_opt
: /* Empty */ { $$
=0; }
588 | acc_opt
',' NOINVERT
{ $$
=$1 | WRC_AF_NOINVERT
; }
589 | acc_opt
',' SHIFT
{ $$
=$1 | WRC_AF_SHIFT
; }
590 | acc_opt
',' CONTROL
{ $$
=$1 | WRC_AF_CONTROL
; }
591 | acc_opt
',' ALT
{ $$
=$1 | WRC_AF_ALT
; }
592 | acc_opt
',' ASCII
{ $$
=$1 | WRC_AF_ASCII
; }
593 | acc_opt
',' VIRTKEY
{ $$
=$1 | WRC_AF_VIRTKEY
; }
596 /* ------------------------------ Dialog ------------------------------ */
597 /* FIXME: Support EXSTYLE in the dialog line itself */
598 dialog
: DIALOG loadmemopts expr
',' expr
',' expr
',' expr dlg_attributes
606 $10->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
611 $10->controls
= get_control_head
($12);
615 $$
->style
= WS_POPUP
;
619 $$
->style |
= WS_CAPTION
;
621 $$
->style |
= DS_SETFONT
;
623 if
(!$$
->lvc.language
)
624 $$
->lvc.language
= dup_language
(currentlanguage
);
629 : /* Empty */ { $$
=new_dialog
(); }
630 | dlg_attributes STYLE expr
{ $$
=dialog_style
($3,$1); }
631 | dlg_attributes EXSTYLE expr
{ $$
=dialog_exstyle
($3,$1); }
632 | dlg_attributes CAPTION tSTRING
{ $$
=dialog_caption
($3,$1); }
633 | dlg_attributes opt_font
{ $$
=dialog_font
($2,$1); }
634 | dlg_attributes CLASS nameid
{ $$
=dialog_class
($3,$1); }
635 | dlg_attributes MENU nameid
{ $$
=dialog_menu
($3,$1); }
636 | dlg_attributes opt_language
{ $$
=dialog_language
($2,$1); }
637 | dlg_attributes opt_characts
{ $$
=dialog_characteristics
($2,$1); }
638 | dlg_attributes opt_version
{ $$
=dialog_version
($2,$1); }
641 ctrls
: /* Empty */ { $$
= NULL
; }
642 | ctrls CONTROL gen_ctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
643 | ctrls EDITTEXT ctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
644 | ctrls LISTBOX ctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
645 | ctrls COMBOBOX ctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
646 | ctrls SCROLLBAR ctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
647 | ctrls CHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
648 | ctrls DEFPUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
649 | ctrls GROUPBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
650 | ctrls PUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
651 /* | ctrls PUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
652 | ctrls RADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
653 | ctrls AUTO3STATE lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
654 | ctrls STATE3 lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
655 | ctrls AUTOCHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
656 | ctrls AUTORADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
657 | ctrls LTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
658 | ctrls CTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
659 | ctrls RTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
660 /* special treatment for icons, as the extent is optional */
661 | ctrls ICON tSTRING
',' expr
',' expr
',' expr iconinfo
{
666 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
671 : tSTRING
',' expr
',' expr
',' expr
',' expr
',' expr optional_style
{
689 : expr
',' expr
',' expr
',' expr
',' expr optional_style
{
705 iconinfo: /* Empty */
706 { $$
= new_control
(); }
708 |
',' expr
',' expr
{
713 |
',' expr
',' expr
',' expr
{
720 |
',' expr
',' expr
',' expr
',' expr
{
727 $$
->gotexstyle
= TRUE
;
731 gen_ctrl: tSTRING
',' expr
',' ctlclass
',' expr
',' expr
',' expr
',' expr
',' expr
',' expr
{
735 $$
->ctlclass
= convert_ctlclass
($5);
743 $$
->gotexstyle
= TRUE
;
745 | tSTRING
',' expr
',' ctlclass
',' expr
',' expr
',' expr
',' expr
',' expr
{
749 $$
->ctlclass
= convert_ctlclass
($5);
760 : FONT expr
',' tSTRING
{ $$
= new_font_id
($2, $4, 0, 0); }
763 optional_style
/* Abbused once to get optional ExStyle */
764 : /* Empty */ { $$
= NULL
; }
765 |
',' expr
{ $$
= new_int
($2); }
772 $$
->name.i_name
= $1;
777 $$
->name.s_name
= $1;
781 /* ------------------------------ DialogEx ------------------------------ */
782 dialogex: DIALOGEX loadmemopts expr
',' expr
',' expr
',' expr helpid dlgex_attribs
783 tBEGIN exctrls tEND
{
785 yywarning
("DIALOGEX not supported in 16-bit mode");
792 $11->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
799 $11->helpid
= *($10);
800 $11->gothelpid
= TRUE
;
803 $11->controls
= get_control_head
($13);
807 $$
->style
= WS_POPUP
;
811 $$
->style |
= WS_CAPTION
;
813 $$
->style |
= DS_SETFONT
;
815 if
(!$$
->lvc.language
)
816 $$
->lvc.language
= dup_language
(currentlanguage
);
821 : /* Empty */ { $$
=new_dialogex
(); }
822 | dlgex_attribs STYLE expr
{ $$
=dialogex_style
($3,$1); }
823 | dlgex_attribs EXSTYLE expr
{ $$
=dialogex_exstyle
($3,$1); }
824 | dlgex_attribs CAPTION tSTRING
{ $$
=dialogex_caption
($3,$1); }
825 | dlgex_attribs opt_exfont
{ $$
=dialogex_font
($2,$1); }
826 | dlgex_attribs CLASS nameid
{ $$
=dialogex_class
($3,$1); }
827 | dlgex_attribs MENU nameid
{ $$
=dialogex_menu
($3,$1); }
828 | dlgex_attribs opt_language
{ $$
=dialogex_language
($2,$1); }
829 | dlgex_attribs opt_characts
{ $$
=dialogex_characteristics
($2,$1); }
830 | dlgex_attribs opt_version
{ $$
=dialogex_version
($2,$1); }
833 exctrls
: /* Empty */ { $$
= NULL
; }
834 | exctrls CONTROL gen_exctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
835 | exctrls EDITTEXT exctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
836 | exctrls LISTBOX exctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
837 | exctrls COMBOBOX exctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
838 | exctrls SCROLLBAR exctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
839 | exctrls CHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
840 | exctrls DEFPUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
841 | exctrls GROUPBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
842 | exctrls PUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
843 /* | exctrls PUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
844 | exctrls RADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
845 | exctrls AUTO3STATE lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
846 | exctrls STATE3 lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
847 | exctrls AUTOCHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
848 | exctrls AUTORADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
849 | exctrls LTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
850 | exctrls CTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
851 | exctrls RTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
852 /* special treatment for icons, as the extent is optional */
853 | exctrls ICON tSTRING
',' expr
',' expr
',' expr iconinfo
{
858 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
863 : tSTRING
',' expr
',' ctlclass
',' expr
',' expr
',' expr
',' expr
','
864 expr
',' e_expr helpid opt_data
{
868 $$
->ctlclass
= convert_ctlclass
($5);
877 $$
->exstyle
= *($17);
878 $$
->gotexstyle
= TRUE
;
884 $$
->gothelpid
= TRUE
;
889 | tSTRING
',' expr
',' ctlclass
',' expr
',' expr
',' expr
',' expr
',' expr opt_data
{
895 $$
->ctlclass
= convert_ctlclass
($5);
905 : tSTRING
',' expr
',' expr
',' expr
',' expr
',' expr optional_style opt_data
{
924 : expr
',' expr
',' expr
',' expr
',' expr optional_style opt_data
{
941 opt_data: /* Empty */ { $$
= NULL
; }
942 | raw_data
{ $$
= $1; }
945 helpid
: /* Empty */ { $$
= NULL
; }
946 |
',' expr
{ $$
= new_int
($2); }
950 : FONT expr
',' tSTRING
',' expr
',' expr
{ $$
= new_font_id
($2, $4, $6, $8); }
953 /* ------------------------------ Menu ------------------------------ */
954 menu
: MENU loadmemopts opt_lvc menu_body
{
956 yyerror("Menu must contain items");
964 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
965 $$
->items
= get_item_head
($4);
971 if
(!$$
->lvc.language
)
972 $$
->lvc.language
= dup_language
(currentlanguage
);
977 : tBEGIN item_definitions tEND
{ $$
= $2; }
981 : /* Empty */ {$$
= NULL
;}
982 | item_definitions MENUITEM tSTRING
',' expr item_options
{
991 | item_definitions MENUITEM SEPARATOR
{
997 | item_definitions POPUP tSTRING item_options menu_body
{
998 $$
= new_menu_item
();
1002 $$
->popup
= get_item_head
($5);
1007 /* NOTE: item_options is right recursive because it would introduce
1008 * a shift/reduce conflict on ',' in itemex_options due to the
1009 * empty rule here. The parser is now forced to look beyond the ','
1010 * before reducing (force shift).
1011 * Right recursion here is not a problem because we cannot expect
1012 * more than 7 parserstack places to be occupied while parsing this
1013 * (who would want to specify a MF_x flag twice?).
1016 : /* Empty */ { $$
= 0; }
1017 |
',' CHECKED item_options
{ $$
= $3 | MF_CHECKED
; }
1018 |
',' GRAYED item_options
{ $$
= $3 | MF_GRAYED
; }
1019 |
',' HELP item_options
{ $$
= $3 | MF_HELP
; }
1020 |
',' INACTIVE item_options
{ $$
= $3 | MF_DISABLED
; }
1021 |
',' MENUBARBREAK item_options
{ $$
= $3 | MF_MENUBARBREAK
; }
1022 |
',' MENUBREAK item_options
{ $$
= $3 | MF_MENUBREAK
; }
1025 /* ------------------------------ MenuEx ------------------------------ */
1026 menuex
: MENUEX loadmemopts opt_lvc menuex_body
{
1028 yywarning
("MENUEX not supported in 16-bit mode");
1030 yyerror("MenuEx must contain items");
1038 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1039 $$
->items
= get_itemex_head
($4);
1045 if
(!$$
->lvc.language
)
1046 $$
->lvc.language
= dup_language
(currentlanguage
);
1051 : tBEGIN itemex_definitions tEND
{ $$
= $2; }
1055 : /* Empty */ {$$
= NULL
; }
1056 | itemex_definitions MENUITEM tSTRING itemex_options
{
1057 $$
= new_menuex_item
();
1063 $$
->type
= $4->type
;
1064 $$
->state
= $4->state
;
1065 $$
->helpid
= $4->helpid
;
1066 $$
->gotid
= $4->gotid
;
1067 $$
->gottype
= $4->gottype
;
1068 $$
->gotstate
= $4->gotstate
;
1069 $$
->gothelpid
= $4->gothelpid
;
1072 | itemex_definitions MENUITEM SEPARATOR
{
1073 $$
= new_menuex_item
();
1078 | itemex_definitions POPUP tSTRING itemex_p_options menuex_body
{
1079 $$
= new_menuex_item
();
1083 $$
->popup
= get_itemex_head
($5);
1086 $$
->type
= $4->type
;
1087 $$
->state
= $4->state
;
1088 $$
->helpid
= $4->helpid
;
1089 $$
->gotid
= $4->gotid
;
1090 $$
->gottype
= $4->gottype
;
1091 $$
->gotstate
= $4->gotstate
;
1092 $$
->gothelpid
= $4->gothelpid
;
1098 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1100 $$
= new_itemex_opt
($2, 0, 0, 0);
1103 |
',' e_expr
',' e_expr item_options
{
1104 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $5, 0);
1107 $$
->gotstate
= TRUE
;
1111 |
',' e_expr
',' e_expr
',' expr
{
1112 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1115 $$
->gotstate
= TRUE
;
1122 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1124 $$
= new_itemex_opt
($2, 0, 0, 0);
1127 |
',' e_expr
',' expr
{
1128 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4, 0, 0);
1133 |
',' e_expr
',' e_expr
',' expr
{
1134 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1139 $$
->gotstate
= TRUE
;
1141 |
',' e_expr
',' e_expr
',' e_expr
',' expr
{
1142 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6 ?
*($6) : 0, $8);
1148 $$
->gotstate
= TRUE
;
1149 $$
->gothelpid
= TRUE
;
1153 /* ------------------------------ StringTable ------------------------------ */
1154 /* Stringtables are parsed differently than other resources because their
1155 * layout is substantially different from other resources.
1156 * The table is parsed through a _global_ variable 'tagstt' which holds the
1157 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1158 * list of stringtables of different languages.
1161 : stt_head tBEGIN strings tEND
{
1164 yyerror("Stringtable must have at least one entry");
1169 /* Check if we added to a language table or created
1172 for
(stt
= sttres
; stt
; stt
= stt
->next
)
1179 /* It is a new one */
1182 sttres
->prev
= tagstt
;
1183 tagstt
->next
= sttres
;
1189 /* Else were done */
1193 free
(tagstt_memopt
);
1194 tagstt_memopt
= NULL
;
1201 /* This is to get the language of the currently parsed stringtable */
1202 stt_head: STRINGTABLE loadmemopts opt_lvc
{
1203 if
((tagstt
= find_stringtable
($3)) == NULL
)
1204 tagstt
= new_stringtable
($3);
1206 tagstt_version
= $3->version
;
1207 tagstt_characts
= $3->characts
;
1213 strings
: /* Empty */ { $$
= NULL
; }
1214 | strings expr opt_comma tSTRING
{
1216 assert
(tagstt
!= NULL
);
1217 /* Search for the ID */
1218 for
(i
= 0; i
< tagstt
->nentries
; i
++)
1220 if
(tagstt
->entries
[i
].id
== $2)
1221 yyerror("Stringtable ID %d already in use", $2);
1223 /* If we get here, then we have a new unique entry */
1225 tagstt
->entries
= xrealloc
(tagstt
->entries
, sizeof
(tagstt
->entries
[0]) * tagstt
->nentries
);
1226 tagstt
->entries
[tagstt
->nentries
-1].id
= $2;
1227 tagstt
->entries
[tagstt
->nentries
-1].str
= $4;
1229 tagstt
->entries
[tagstt
->nentries
-1].memopt
= *tagstt_memopt
;
1231 tagstt
->entries
[tagstt
->nentries
-1].memopt
= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1232 tagstt
->entries
[tagstt
->nentries
-1].version
= tagstt_version
;
1233 tagstt
->entries
[tagstt
->nentries
-1].characts
= tagstt_characts
;
1235 if
(!win32
&& $4->size
> 254)
1236 yyerror("Stringtable entry more than 254 characters");
1237 if
(win32
&& $4->size
> 65534) /* Hmm..., does this happen? */
1238 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1243 opt_comma
/* There seem to be two ways to specify a stringtable... */
1248 /* ------------------------------ VersionInfo ------------------------------ */
1250 : VERSIONINFO fix_version tBEGIN ver_blocks tEND
{
1252 $2->blocks
= get_ver_block_head
($4);
1257 : /* Empty */ { $$
= new_versioninfo
(); }
1258 | fix_version FILEVERSION expr
',' expr
',' expr
',' expr
{
1260 yyerror("FILEVERSION already defined");
1262 $$
->filever_maj1
= $3;
1263 $$
->filever_maj2
= $5;
1264 $$
->filever_min1
= $7;
1265 $$
->filever_min2
= $9;
1268 | fix_version PRODUCTVERSION expr
',' expr
',' expr
',' expr
{
1270 yyerror("PRODUCTVERSION already defined");
1272 $$
->prodver_maj1
= $3;
1273 $$
->prodver_maj2
= $5;
1274 $$
->prodver_min1
= $7;
1275 $$
->prodver_min2
= $9;
1278 | fix_version FILEFLAGS expr
{
1280 yyerror("FILEFLAGS already defined");
1285 | fix_version FILEFLAGSMASK expr
{
1287 yyerror("FILEFLAGSMASK already defined");
1289 $$
->fileflagsmask
= $3;
1292 | fix_version FILEOS expr
{
1294 yyerror("FILEOS already defined");
1299 | fix_version FILETYPE expr
{
1301 yyerror("FILETYPE already defined");
1306 | fix_version FILESUBTYPE expr
{
1308 yyerror("FILESUBTYPE already defined");
1310 $$
->filesubtype
= $3;
1316 : /* Empty */ { $$
= NULL
; }
1317 | ver_blocks ver_block
{
1326 : BLOCK tSTRING tBEGIN ver_values tEND
{
1327 $$
= new_ver_block
();
1329 $$
->values
= get_ver_value_head
($4);
1334 : /* Empty */ { $$
= NULL
; }
1335 | ver_values ver_value
{
1345 $$
= new_ver_value
();
1346 $$
->type
= val_block
;
1347 $$
->value.block
= $1;
1349 | VALUE tSTRING
',' tSTRING
{
1350 $$
= new_ver_value
();
1355 | VALUE tSTRING
',' ver_words
{
1356 $$
= new_ver_value
();
1357 $$
->type
= val_words
;
1359 $$
->value.words
= $4;
1364 : expr
{ $$
= new_ver_words
($1); }
1365 | ver_words
',' expr
{ $$
= add_ver_words
($1, $3); }
1368 /* ------------------------------ Memory options ------------------------------ */
1370 : /* Empty */ { $$
= NULL
; }
1371 | loadmemopts lamo
{
1381 | loadmemopts lama
{
1390 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1396 lamo
: PRELOAD
{ $$
= new_int
(WRC_MO_PRELOAD
); }
1397 | MOVEABLE
{ $$
= new_int
(WRC_MO_MOVEABLE
); }
1398 | DISCARDABLE
{ $$
= new_int
(WRC_MO_DISCARDABLE
); }
1399 | tPURE
{ $$
= new_int
(WRC_MO_PURE
); }
1402 lama
: LOADONCALL
{ $$
= new_int
(~WRC_MO_PRELOAD
); }
1403 | tFIXED
{ $$
= new_int
(~WRC_MO_MOVEABLE
); }
1404 | IMPURE
{ $$
= new_int
(~WRC_MO_PURE
); }
1407 /* ------------------------------ Win32 options ------------------------------ */
1408 opt_lvc
: /* Empty */ { $$
= new_lvc
(); }
1409 | opt_lvc opt_language
{
1411 yywarning
("LANGUAGE not supported in 16-bit mode");
1413 yyerror("Language already defined");
1417 | opt_lvc opt_characts
{
1419 yywarning
("CHARACTERISTICS not supported in 16-bit mode");
1421 yyerror("Characteristics already defined");
1425 | opt_lvc opt_version
{
1427 yywarning
("VERSION not supported in 16-bit mode");
1429 yyerror("Version already defined");
1436 : LANGUAGE expr
',' expr
{ $$
= new_language
($2, $4); }
1440 : CHARACTERISTICS expr
{ $$
= new_characts
($2); }
1444 : VERSION expr
{ $$
= new_version
($2); }
1447 /* ------------------------------ Raw data handking ------------------------------ */
1448 raw_data: tBEGIN raw_elements tEND
{ $$
= $2; }
1452 : RAWDATA
{ $$
= $1; }
1453 | NUMBER
{ $$
= int2raw_data
($1); }
1454 | tSTRING
{ $$
= str2raw_data
($1); }
1455 | raw_elements opt_comma RAWDATA
{ $$
= merge_raw_data
($1, $3); free
($3->data
); free
($3); }
1456 | raw_elements opt_comma NUMBER
{ $$
= merge_raw_data_int
($1, $3); }
1457 | raw_elements opt_comma tSTRING
{ $$
= merge_raw_data_str
($1, $3); }
1460 /* ------------------------------ Win32 expressions ------------------------------ */
1461 /* All win16 numbers are also handled here. This is inconsistent with MS'
1462 * resource compiler, but what the heck, its just handy to have.
1464 e_expr
: /* Empty */ { $$
= 0; }
1465 | expr
{ $$
= new_int
($1); }
1467 expr
: dummy xpr
{ $$
= ($2) & andmask
; }
1470 dummy
: /* Empty */ { $$
= 0; andmask
= -1; }
1473 xpr
: xpr
'+' xpr
{ $$
= ($1) + ($3); }
1474 | xpr
'-' xpr
{ $$
= ($1) - ($3); }
1475 | xpr
'|' xpr
{ $$
= ($1) |
($3); }
1476 | xpr
'&' xpr
{ $$
= ($1) & ($3); }
1477 | xpr
'*' xpr
{ $$
= ($1) * ($3); }
1478 | xpr
'/' xpr
{ $$
= ($1) / ($3); }
1479 |
'~' xpr
{ $$
= ~
($2); }
1480 |
'-' xpr
{ $$
= -($2); } /* FIXME: shift/reduce conflict */
1481 /* | '+' xpr { $$ = $2; } */
1482 |
'(' xpr
')' { $$
= $2; }
1483 | NUMBER
{ $$
= $1; want_rscname
= 0; }
1484 | NOT NUMBER
{ $$
= 0; andmask
&= ~
($2); }
1487 /* Dialog specific functions */
1488 dialog_t
*dialog_style
(int st
, dialog_t
*dlg
)
1491 assert
(dlg
!= NULL
);
1494 yywarning
("Style already defined, or-ing together");
1497 dlg
->style
= st | s
;
1498 dlg
->gotstyle
= TRUE
;
1502 dialog_t
*dialog_exstyle
(int st
, dialog_t
*dlg
)
1505 assert
(dlg
!= NULL
);
1508 yywarning
("ExStyle already defined, or-ing together");
1511 dlg
->exstyle
= st | s
;
1512 dlg
->gotexstyle
= TRUE
;
1516 dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
)
1518 assert
(dlg
!= NULL
);
1520 yyerror("Caption already defined");
1525 dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
)
1527 assert
(dlg
!= NULL
);
1529 yyerror("Font already defined");
1534 dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
)
1536 assert
(dlg
!= NULL
);
1538 yyerror("Class already defined");
1543 dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
)
1545 assert
(dlg
!= NULL
);
1547 yyerror("Menu already defined");
1552 dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
)
1554 assert
(dlg
!= NULL
);
1555 if
(dlg
->lvc.language
)
1556 yyerror("Language already defined");
1557 dlg
->lvc.language
= l
;
1561 dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
)
1563 assert
(dlg
!= NULL
);
1564 if
(dlg
->lvc.characts
)
1565 yyerror("Characteristics already defined");
1566 dlg
->lvc.characts
= c
;
1570 dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
)
1572 assert
(dlg
!= NULL
);
1573 if
(dlg
->lvc.version
)
1574 yyerror("Version already defined");
1575 dlg
->lvc.version
= v
;
1579 /* Controls specific functions */
1580 control_t
*ins_ctrl
(int type
, int style
, control_t
*ctrl
, control_t
*prev
)
1582 assert
(ctrl
!= NULL
);
1588 ctrl
->ctlclass
= new_name_id
();
1589 ctrl
->ctlclass
->type
= name_ord
;
1590 ctrl
->ctlclass
->name.i_name
= type
;
1593 /* Hm... this seems to be jammed in at all time... */
1594 ctrl
->style |
= WS_CHILD | WS_VISIBLE
;
1598 ctrl
->style |
= style
;
1599 if
(style
!= BS_GROUPBOX
&& style
!= BS_RADIOBUTTON
)
1600 ctrl
->style |
= WS_TABSTOP
;
1603 ctrl
->style |
= WS_TABSTOP | WS_BORDER
;
1606 ctrl
->style |
= LBS_NOTIFY | WS_BORDER
;
1609 ctrl
->style |
= CBS_SIMPLE
;
1612 ctrl
->style |
= style
;
1613 if
(style
== SS_CENTER || style
== SS_LEFT || style
== SS_RIGHT
)
1614 ctrl
->style |
= WS_GROUP
;
1618 if
(!ctrl
->gotstyle
) /* Handle default style setting */
1623 ctrl
->style |
= ES_LEFT
;
1626 ctrl
->style |
= LBS_NOTIFY
;
1629 ctrl
->style |
= CBS_SIMPLE | WS_TABSTOP
;
1632 ctrl
->style |
= SBS_HORZ
;
1638 case BS_DEFPUSHBUTTON
:
1641 /* case BS_PUSHBOX: */
1642 case BS_AUTORADIOBUTTON
:
1645 case BS_AUTOCHECKBOX
:
1646 ctrl
->style |
= WS_TABSTOP
;
1649 yywarning
("Unknown default button control-style 0x%08x", style
);
1650 case BS_RADIOBUTTON
:
1661 ctrl
->style |
= WS_GROUP
;
1663 case SS_ICON
: /* Special case */
1666 yywarning
("Unknown default static control-style 0x%08x", style
);
1670 case
-1: /* Generic control */
1674 yyerror("Internal error (report this): Got weird control type 0x%08x", type
);
1678 /* The SS_ICON flag is always forced in for icon controls */
1679 if
(type
== CT_STATIC
&& style
== SS_ICON
)
1680 ctrl
->style |
= SS_ICON
;
1682 ctrl
->gotstyle
= TRUE
;
1687 name_id_t
*convert_ctlclass
(name_id_t
*cls
)
1692 if
(cls
->type
== name_ord
)
1694 assert
(cls
->type
== name_str
);
1695 if
(cls
->type
== str_unicode
)
1697 yyerror("Don't yet support unicode class comparison");
1700 cc
= cls
->name.s_name
->str.cstr
;
1702 if
(!stricmp
("BUTTON", cc
))
1704 else if
(!stricmp
("COMBOBOX", cc
))
1705 iclass
= CT_COMBOBOX
;
1706 else if
(!stricmp
("LISTBOX", cc
))
1707 iclass
= CT_LISTBOX
;
1708 else if
(!stricmp
("EDIT", cc
))
1710 else if
(!stricmp
("STATIC", cc
))
1712 else if
(!stricmp
("SCROLLBAR", cc
))
1713 iclass
= CT_SCROLLBAR
;
1715 return cls
; /* No default, return user controlclass */
1717 free
(cls
->name.s_name
->str.cstr
);
1718 free
(cls
->name.s_name
);
1719 cls
->type
= name_ord
;
1720 cls
->name.i_name
= iclass
;
1724 /* DialogEx specific functions */
1725 dialogex_t
*dialogex_style
(int st
, dialogex_t
*dlg
)
1728 assert
(dlg
!= NULL
);
1731 yywarning
("Style already defined, or-ing together");
1734 dlg
->style
= st | s
;
1735 dlg
->gotstyle
= TRUE
;
1739 dialogex_t
*dialogex_exstyle
(int st
, dialogex_t
*dlg
)
1742 assert
(dlg
!= NULL
);
1745 yywarning
("ExStyle already defined, or-ing together");
1748 dlg
->exstyle
= st | s
;
1749 dlg
->gotexstyle
= TRUE
;
1753 dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
)
1755 assert
(dlg
!= NULL
);
1757 yyerror("Caption already defined");
1762 dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
)
1764 assert
(dlg
!= NULL
);
1766 yyerror("Font already defined");
1771 dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
)
1773 assert
(dlg
!= NULL
);
1775 yyerror("Class already defined");
1780 dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
)
1782 assert
(dlg
!= NULL
);
1784 yyerror("Menu already defined");
1789 dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
)
1791 assert
(dlg
!= NULL
);
1792 if
(dlg
->lvc.language
)
1793 yyerror("Language already defined");
1794 dlg
->lvc.language
= l
;
1798 dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
)
1800 assert
(dlg
!= NULL
);
1801 if
(dlg
->lvc.characts
)
1802 yyerror("Characteristics already defined");
1803 dlg
->lvc.characts
= c
;
1807 dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
)
1809 assert
(dlg
!= NULL
);
1810 if
(dlg
->lvc.version
)
1811 yyerror("Version already defined");
1812 dlg
->lvc.version
= v
;
1816 /* Accelerator specific functions */
1817 event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
)
1819 event_t
*ev
= new_event
();
1821 if
((flags
& (WRC_AF_VIRTKEY | WRC_AF_ASCII
)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII
))
1822 yyerror("Cannot use both ASCII and VIRTKEY");
1826 ev
->flags
= flags
& ~WRC_AF_ASCII
;
1833 event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
)
1836 event_t
*ev
= new_event
();
1838 if
(key
->type
!= str_char
)
1839 yyerror("Key code must be an ascii string");
1841 if
((flags
& WRC_AF_VIRTKEY
) && (!isupper
(key
->str.cstr
[0]) ||
!isdigit
(key
->str.cstr
[0])))
1842 yyerror("VIRTKEY code is not equal to ascii value");
1844 if
(key
->str.cstr
[0] == '^')
1846 keycode
= toupper
(key
->str.cstr
[1]) - '@';
1848 yyerror("Control-code out of range");
1851 keycode
= key
->str.cstr
[0];
1854 ev
->flags
= flags
& ~WRC_AF_ASCII
;
1861 /* MenuEx specific functions */
1862 itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
)
1864 itemex_opt_t
*opt
= (itemex_opt_t
*)xmalloc
(sizeof
(itemex_opt_t
));
1868 opt
->helpid
= helpid
;
1872 /* Raw data functions */
1873 raw_data_t
*load_file
(string_t
*name
)
1877 if
(name
->type
!= str_char
)
1878 yyerror("Filename must be ASCII string");
1880 fp
= fopen
(name
->str.cstr
, "rb");
1882 yyerror("Cannot open file %s", name
);
1883 rd
= new_raw_data
();
1884 fseek
(fp
, 0, SEEK_END
);
1885 rd
->size
= ftell
(fp
);
1886 fseek
(fp
, 0, SEEK_SET
);
1887 rd
->data
= (char *)xmalloc
(rd
->size
);
1888 fread
(rd
->data
, rd
->size
, 1, fp
);
1894 raw_data_t
*int2raw_data
(int i
)
1897 rd
= new_raw_data
();
1898 rd
->size
= sizeof
(short);
1899 rd
->data
= (char *)xmalloc
(rd
->size
);
1900 *(short *)(rd
->data
) = (short)i
;
1904 raw_data_t
*str2raw_data
(string_t
*str
)
1907 rd
= new_raw_data
();
1908 rd
->size
= str
->size
* (str
->type
== str_char ?
1 : 2);
1909 rd
->data
= (char *)xmalloc
(rd
->size
);
1910 memcpy
(rd
->data
, str
->str.cstr
, rd
->size
);
1914 raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
)
1916 r1
->data
= xrealloc
(r1
->data
, r1
->size
+ r2
->size
);
1917 memcpy
(r1
->data
+ r1
->size
, r2
->data
, r2
->size
);
1918 r1
->size
+= r2
->size
;
1922 raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
)
1924 raw_data_t
*t
= int2raw_data
(i
);
1925 merge_raw_data
(r1
, t
);
1931 raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
)
1933 raw_data_t
*t
= str2raw_data
(str
);
1934 merge_raw_data
(r1
, t
);
1940 /* Function the go back in a list to get the head */
1941 menu_item_t
*get_item_head
(menu_item_t
*p
)
1950 menuex_item_t
*get_itemex_head
(menuex_item_t
*p
)
1959 resource_t
*get_resource_head
(resource_t
*p
)
1968 ver_block_t
*get_ver_block_head
(ver_block_t
*p
)
1977 ver_value_t
*get_ver_value_head
(ver_value_t
*p
)
1986 control_t
*get_control_head
(control_t
*p
)
1995 event_t
*get_event_head
(event_t
*p
)
2004 /* Find a stringtable with given language */
2005 stringtable_t
*find_stringtable
(lvc_t
*lvc
)
2009 assert
(lvc
!= NULL
);
2012 lvc
->language
= currentlanguage
;
2014 for
(stt
= sttres
; stt
; stt
= stt
->next
)
2016 if
(stt
->lvc.language
->id
== lvc
->language
->id
2017 && stt
->lvc.language
->id
== lvc
->language
->id
)
2019 /* Found a table with the same language */
2020 /* The version and characteristics are now handled
2021 * in the generation of the individual stringtables.
2022 * This enables localized analysis.
2023 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2024 || (!stt->lvc.version && lvc->version)
2025 || (stt->lvc.version && !lvc->version))
2026 yywarning("Stringtable's versions are not the same, using first definition");
2028 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2029 || (!stt->lvc.characts && lvc->characts)
2030 || (stt->lvc.characts && !lvc->characts))
2031 yywarning("Stringtable's characteristics are not the same, using first definition");
2039 /* qsort sorting function for string table entries */
2040 #define STE(p) ((stt_entry_t *)(p))
2041 int sort_stt_entry
(const void *e1
, const void *e2
)
2043 return STE
(e1
)->id
- STE
(e2
)->id
;
2047 resource_t
*build_stt_resources
(stringtable_t
*stthead
)
2050 stringtable_t
*newstt
;
2052 resource_t
*rsclist
= NULL
;
2053 resource_t
*rsctail
= NULL
;
2058 characts_t
*characts
;
2064 /* For all languages defined */
2065 for
(stt
= stthead
; stt
; stt
= stt
->next
)
2067 assert
(stt
->nentries
> 0);
2069 /* Sort the entries */
2070 if
(stt
->nentries
> 1)
2071 qsort
(stt
->entries
, stt
->nentries
, sizeof
(stt
->entries
[0]), sort_stt_entry
);
2073 for
(i
= 0; i
< stt
->nentries
; )
2075 newstt
= new_stringtable
(&stt
->lvc
);
2076 newstt
->entries
= (stt_entry_t
*)xmalloc
(16 * sizeof
(stt_entry_t
));
2077 newstt
->nentries
= 16;
2078 newstt
->idbase
= stt
->entries
[i
].id
& ~
0xf;
2079 for
(j
= 0; j
< 16 && i
< stt
->nentries
; j
++)
2081 if
(stt
->entries
[i
].id
- newstt
->idbase
== j
)
2083 newstt
->entries
[j
] = stt
->entries
[i
];
2091 /* Check individual memory options and get
2092 * the first characteristics/version
2094 for
(j
= 0; j
< 16; j
++)
2096 if
(!newstt
->entries
[j
].str
)
2098 andsum
&= newstt
->entries
[j
].memopt
;
2099 orsum |
= newstt
->entries
[j
].memopt
;
2101 characts
= newstt
->entries
[j
].characts
;
2103 version
= newstt
->entries
[j
].version
;
2107 warning
("Stringtable's memory options are not equal (idbase: %d)", newstt
->idbase
);
2109 /* Check version and characteristics */
2110 for
(j
= 0; j
< 16; j
++)
2113 && newstt
->entries
[j
].characts
2114 && *newstt
->entries
[j
].characts
!= *characts
)
2115 warning
("Stringtable's characteristics are not the same (idbase: %d)", newstt
->idbase
);
2117 && newstt
->entries
[j
].version
2118 && *newstt
->entries
[j
].version
!= *version
)
2119 warning
("Stringtable's versions are not the same (idbase: %d)", newstt
->idbase
);
2121 rsc
= new_resource
(res_stt
, newstt
, newstt
->memopt
, newstt
->lvc.language
);
2122 rsc
->name
= new_name_id
();
2123 rsc
->name
->type
= name_ord
;
2124 rsc
->name
->name.i_name
= (newstt
->idbase
>> 4) + 1;
2125 rsc
->memopt
= andsum
; /* Set to least common denominator */
2126 newstt
->memopt
= andsum
;
2127 newstt
->lvc.characts
= characts
;
2128 newstt
->lvc.version
= version
;
2136 rsctail
->next
= rsc
;
2137 rsc
->prev
= rsctail
;
2145 /* Cursor and icon splitter functions */
2146 int alloc_icon_id
(void)
2148 static int icon_id
= 1;
2152 int alloc_cursor_id
(void)
2154 static int cursor_id
= 1;
2158 #define BPTR(base) ((char *)(rd->data + (base)))
2159 #define WPTR(base) ((WORD *)(rd->data + (base)))
2160 #define DPTR(base) ((DWORD *)(rd->data + (base)))
2161 void split_icons
(raw_data_t
*rd
, icon_group_t
*icog
, int *nico
)
2165 icon_dir_entry_t
*ide
;
2167 icon_t
*list
= NULL
;
2169 /* FIXME: Distinguish between normal and animated icons (RIFF format) */
2171 yyerror("Icon resource data has invalid type id %d", WPTR
(0)[1]);
2173 ide
= (icon_dir_entry_t
*)&(WPTR
(0)[3]);
2174 for
(i
= 0; i
< cnt
; i
++)
2177 ico
->id
= alloc_icon_id
();
2178 if
(ide
[i
].offset
> rd
->size
2179 || ide
[i
].offset
+ ide
[i
].ressize
> rd
->size
)
2180 yyerror("Icon resource data corrupt");
2181 ico
->width
= ide
[i
].width
;
2182 ico
->height
= ide
[i
].height
;
2183 ico
->nclr
= ide
[i
].nclr
;
2184 ico
->planes
= ide
[i
].planes
;
2185 ico
->bits
= ide
[i
].bits
;
2188 /* Argh! They did not fill out the resdir structure */
2189 ico
->planes
= ((BITMAPINFOHEADER
*)BPTR
(ide
[i
].offset
))->biPlanes
;
2193 /* Argh! They did not fill out the resdir structure */
2194 ico
->bits
= ((BITMAPINFOHEADER
*)BPTR
(ide
[i
].offset
))->biBitCount
;
2196 ico
->data
= new_raw_data
();
2197 copy_raw_data
(ico
->data
, rd
, ide
[i
].offset
, ide
[i
].ressize
);
2209 icog
->iconlist
= list
;
2213 void split_cursors
(raw_data_t
*rd
, cursor_group_t
*curg
, int *ncur
)
2217 cursor_dir_entry_t
*cde
;
2219 cursor_t
*list
= NULL
;
2221 /* FIXME: Distinguish between normal and animated cursors (RIFF format)*/
2223 yyerror("Cursor resource data has invalid type id %d", WPTR
(0)[1]);
2225 cde
= (cursor_dir_entry_t
*)&(WPTR
(0)[3]);
2226 for
(i
= 0; i
< cnt
; i
++)
2229 cur
->id
= alloc_cursor_id
();
2230 if
(cde
[i
].offset
> rd
->size
2231 || cde
[i
].offset
+ cde
[i
].ressize
> rd
->size
)
2232 yyerror("Cursor resource data corrupt");
2233 cur
->width
= cde
[i
].width
;
2234 cur
->height
= cde
[i
].height
;
2235 cur
->nclr
= cde
[i
].nclr
;
2236 /* The next two are to support color cursors */
2237 cur
->planes
= ((BITMAPINFOHEADER
*)BPTR
(cde
[i
].offset
))->biPlanes
;
2238 cur
->bits
= ((BITMAPINFOHEADER
*)BPTR
(cde
[i
].offset
))->biBitCount
;
2239 if
(!win32
&& (cur
->planes
!= 1 || cur
->bits
!= 1))
2240 yywarning
("Win16 cursor contains colors");
2241 cur
->xhot
= cde
[i
].xhot
;
2242 cur
->yhot
= cde
[i
].yhot
;
2243 cur
->data
= new_raw_data
();
2244 copy_raw_data
(cur
->data
, rd
, cde
[i
].offset
, cde
[i
].ressize
);
2256 curg
->cursorlist
= list
;