3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * 24-Jul-2000 BS - Made a fix for broken Berkeley yacc on
8 * non-terminals (see cjunk rule).
9 * 21-May-2000 BS - Partial implementation of font resources.
10 * - Corrected language propagation for binary
11 * resources such as bitmaps, isons, cursors,
12 * userres and rcdata. The language is now
13 * correct in .res files.
14 * - Fixed reading the resource name as ident,
15 * so that it may overlap keywords.
16 * 20-May-2000 BS - Implemented animated cursors and icons
18 * 30-Apr-2000 BS - Reintegration into the wine-tree
19 * 14-Jan-2000 BS - Redid the usertype resources so that they
21 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
22 * expect for the # command (line numbers).
24 * 06-Nov-1999 JS - see CHANGES
26 * 29-Dec-1998 AdH - Grammar and function extensions.
27 * grammar: TOOLBAR resources, Named ICONs in
29 * functions: semantic actions for the grammar
30 * changes, resource files can now be anywhere
31 * on the include path instead of just in the
34 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
35 * printed out correctly.
37 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
38 * also accept a tSTRING as argument.
40 * 25-May-1998 BS - Found out that I need to support language, version
41 * and characteristics in inline resources (bitmap,
42 * cursor, etc) but they can also be specified with
43 * a filename. This renders my filename-scanning scheme
44 * worthless. Need to build newline parsing to solve
46 * It will come with version 1.1.0 (sigh).
48 * 19-May-1998 BS - Started to build a builtin preprocessor
50 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
51 * ideas had some serious flaws.
53 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
56 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
57 * - This file is growing too big. It is time to strip
58 * things and put it in a support file.
60 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
61 * resource will be created. This because the table
62 * has a different layout than other resources. The
63 * table has to be sorted, and divided into smaller
64 * resource entries (see comment in source).
66 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
67 * as string_t which include unicode strings upon
69 * - Parser now emits a warning when compiling win32
70 * extensions in win16 mode.
72 * 16-Apr-1998 BS - Raw data elements are now *optionally* seperated
73 * by commas. Read the comments in file sq2dq.l.
74 * - FIXME: there are instances in the source that rely
75 * on the fact that int==32bit and pointers are int size.
76 * - Fixed the conflict in menuex by changing a rule
77 * back into right recursion. See note in source.
78 * - UserType resources cannot have an expression as its
79 * typeclass. See note in source.
81 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
82 * get reduction of the parsestack.
83 * This also helps communication between bison and flex.
84 * Main advantage is that the Empty rule gets reduced
85 * first, which is used to allocate/link things.
86 * It also added a shift/reduce conflict in the menuex
87 * handling, due to expression/option possibility,
88 * although not serious.
90 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
91 * about making it more efficient, but readable (for me)
92 * and slightly easier to expand/change.
93 * This is done primarily by using more reduce states
94 * with many (intuitive) types for the various resource
96 * - Added expression handling for all resources where a
97 * number is accepted (not only for win32). Also added
98 * multiply and division (not MS compatible, but handy).
99 * Unary minus introduced a shift/reduce conflict, but
102 * 13-Apr-1998 BS - Reordered a lot of things
103 * - Made the source more readable
104 * - Added Win32 resource definitions
105 * - Corrected syntax problems with an old yacc (;)
106 * - Added extra comment about grammar
122 #include "newstruc.h"
132 /* Berkeley yacc (byacc) doesn't seem to know about these */
133 /* Some *BSD supplied versions do define these though */
135 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
138 # define YYLEX yylex()
141 #elif defined(YYBISON)
142 /* Bison was used for original development */
143 /* #define YYEMPTY -2 */
144 /* #define YYLEX yylex() */
147 /* No yacc we know yet */
148 # if !defined(YYEMPTY) || !defined(YYLEX)
149 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
150 # elif defined(__GNUC__) /* gcc defines the #warning directive */
151 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
152 /* #else we just take a chance that it works... */
156 int want_nl
= 0; /* Signal flex that we need the next newline */
157 int want_id
= 0; /* Signal flex that we need the next identifier */
158 stringtable_t
*tagstt
; /* Stringtable tag.
159 * It is set while parsing a stringtable to one of
160 * the stringtables in the sttres list or a new one
161 * if the language was not parsed before.
163 stringtable_t
*sttres
; /* Stringtable resources. This holds the list of
164 * stringtables with different lanuages
166 static int dont_want_id
= 0; /* See language parsing for details */
168 /* Set to the current options of the currently scanning stringtable */
169 static int *tagstt_memopt
;
170 static characts_t
*tagstt_characts
;
171 static version_t
*tagstt_version
;
173 static const char riff
[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
175 /* Prototypes of here defined functions */
176 static event_t
*get_event_head
(event_t
*p
);
177 static control_t
*get_control_head
(control_t
*p
);
178 static ver_value_t
*get_ver_value_head
(ver_value_t
*p
);
179 static ver_block_t
*get_ver_block_head
(ver_block_t
*p
);
180 static resource_t
*get_resource_head
(resource_t
*p
);
181 static menuex_item_t
*get_itemex_head
(menuex_item_t
*p
);
182 static menu_item_t
*get_item_head
(menu_item_t
*p
);
183 static raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
);
184 static raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
);
185 static raw_data_t
*merge_raw_data_long
(raw_data_t
*r1
, int i
);
186 static raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
);
187 static raw_data_t
*str2raw_data
(string_t
*str
);
188 static raw_data_t
*int2raw_data
(int i
);
189 static raw_data_t
*long2raw_data
(int i
);
190 static raw_data_t
*load_file
(string_t
*name
);
191 static itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
);
192 static event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
);
193 static event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
);
194 static dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
);
195 static dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
);
196 static dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
);
197 static dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
);
198 static dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
);
199 static dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
);
200 static dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
);
201 static dialogex_t
*dialogex_exstyle
(style_t
*st
, dialogex_t
*dlg
);
202 static dialogex_t
*dialogex_style
(style_t
*st
, dialogex_t
*dlg
);
203 static name_id_t
*convert_ctlclass
(name_id_t
*cls
);
204 static control_t
*ins_ctrl
(int type
, int special_style
, control_t
*ctrl
, control_t
*prev
);
205 static dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
);
206 static dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
);
207 static dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
);
208 static dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
);
209 static dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
);
210 static dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
);
211 static dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
);
212 static dialog_t
*dialog_exstyle
(style_t
* st
, dialog_t
*dlg
);
213 static dialog_t
*dialog_style
(style_t
* st
, dialog_t
*dlg
);
214 static resource_t
*build_stt_resources
(stringtable_t
*stthead
);
215 static stringtable_t
*find_stringtable
(lvc_t
*lvc
);
216 static toolbar_item_t
*ins_tlbr_button
(toolbar_item_t
*prev
, toolbar_item_t
*idrec
);
217 static toolbar_item_t
*get_tlbr_buttons_head
(toolbar_item_t
*p
, int *nitems
);
218 static string_t
*make_filename
(string_t
*s
);
219 static resource_t
*build_fontdirs
(resource_t
*tail
);
220 static resource_t
*build_fontdir
(resource_t
**fnt
, int nfnt
);
221 static int rsrcid_to_token
(int lookahead
);
252 menuex_item_t
*menexitm
;
260 toolbar_item_t
*tlbarItems
;
262 style_pair_t
*styles
;
267 %token tTYPEDEF tEXTERN tSTRUCT tENUM tCPPCLASS tINLINE tSTATIC tNL
268 %token
<num
> tNUMBER tLNUMBER
269 %token
<str
> tSTRING tIDENT tFILENAME
270 %token
<raw
> tRAWDATA
271 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
272 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
273 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
274 %token tPUSHBUTTON tRADIOBUTTON tSTATE3
/* PUSHBOX */
275 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
276 %token tCONTROL tEDITTEXT
277 %token tRTEXT tCTEXT tLTEXT
279 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
280 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
281 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
282 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
283 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
285 %token tSTRING tIDENT tRAWDATA
286 %token tTOOLBAR tBUTTON
297 %type
<res
> resource_file resource resources resource_definition
298 %type
<stt
> stringtable strings
301 %type
<acc
> accelerators
304 %type
<ani
> cursor icon
305 %type
<dlg
> dialog dlg_attributes
306 %type
<ctl
> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
308 %type
<dlgex
> dialogex dlgex_attribs
309 %type
<ctl
> exctrls gen_exctrl lab_exctrl exctrl_desc
311 %type
<raw
> raw_data raw_elements opt_data file_raw
312 %type
<veri
> versioninfo fix_version
313 %type
<verw
> ver_words
314 %type
<blk
> ver_blocks ver_block
315 %type
<val
> ver_values ver_value
317 %type
<menitm
> item_definitions menu_body
319 %type
<menexitm
> itemex_definitions menuex_body
320 %type
<exopt
> itemex_p_options itemex_options
321 %type
<msg
> messagetable
323 %type
<num
> item_options
324 %type
<nid
> nameid nameid_s ctlclass usertype
325 %type
<num
> acc_opt acc accs
326 %type
<iptr
> loadmemopts lamo lama
327 %type
<fntid
> opt_font opt_exfont opt_expr
329 %type
<lan
> opt_language
330 %type
<chars
> opt_characts
331 %type
<ver
> opt_version
334 %type
<tlbar
> toolbar
335 %type
<tlbarItems
> toolbar_items
336 %type
<dginit
> dlginit
337 %type
<styles
> optional_style_pair
339 %type
<style
> optional_style
348 /* First add stringtables to the resource-list */
349 rsc
= build_stt_resources
(sttres
);
350 /* 'build_stt_resources' returns a head and $1 is a tail */
359 /* Find the tail again */
360 while
($1 && $1->next
)
362 /* Now add any fontdirecory */
363 rsc
= build_fontdirs
($1);
364 /* 'build_fontdir' returns a head and $1 is a tail */
373 /* Final statement before were done */
374 resource_top
= get_resource_head
($1);
378 /* Resources are put into a linked list */
380 : /* Empty */ { $$
= NULL
; want_id
= 1; }
381 | resources resource
{
384 resource_t
*tail
= $2;
385 resource_t
*head
= $2;
394 /* Check for duplicate identifiers */
397 resource_t
*rsc
= $1;
400 if
(rsc
->type
== head
->type
401 && rsc
->lan
->id
== head
->lan
->id
402 && rsc
->lan
->sub
== head
->lan
->sub
403 && !compare_name_id
(rsc
->name
, head
->name
))
405 yyerror("Duplicate resource name '%s'", get_nameid_str
(rsc
->name
));
414 resource_t
*tail
= $1;
422 if
(!dont_want_id
) /* See comments in language parsing below */
426 | resources cjunk
{ $$
= $1; want_id
= 1; }
431 cjunk
: tTYPEDEF
{ strip_til_semicolon
(); }
432 | tSTRUCT
{ strip_til_semicolon
(); }
433 | tEXTERN
{ strip_til_semicolon
(); }
434 | tENUM
{ strip_til_semicolon
(); }
435 | tCPPCLASS
{ strip_til_semicolon
(); }
436 | tSTATIC
{ strip_til_semicolon
(); }
437 | tINLINE
{ internal_error
(__FILE__
, __LINE__
, "Don't yet know how to strip inline functions\n"); }
438 /* | tIDENT tIDENT { strip_til_semicolon(); } */
439 /* | tIDENT tIDENT '(' { strip_til_parenthesis(); } See comments in 'resource' below */
440 /* | tIDENT '(' { strip_til_parenthesis(); } */
441 | tIDENT
'*' { strip_til_semicolon
(); }
443 * This newline rule will never get reduced because we never
444 * get the tNL token, unless we explicitely set the 'want_nl'
445 * flag, which we don't.
446 * The *ONLY* reason for this to be here is because Berkeley
447 * yacc (byacc), at least version 1.9, has a bug.
448 * (identified in the generated parser on the second
450 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
452 * This extra rule fixes it.
453 * The problem is that the expression handling rule "expr: xpr"
454 * is not reduced on non-terminal tokens, defined above in the
455 * %token declarations. Token tNL is the only non-terminal that
456 * can occur. The error becomes visible in the language parsing
457 * rule below, which looks at the look-ahead token and tests it
458 * for tNL. However, byacc already generates an error upon reading
459 * the token instead of keeping it as a lookahead. The reason
460 * lies in the lack of a $default transition in the "expr : xpr . "
461 * state (currently state 25). It is probably ommitted because tNL
462 * is a non-terminal and the state contains 2 s/r conflicts. The
463 * state enumerates all possible transitions instead of using a
464 * $default transition.
465 * All in all, it is a bug in byacc. (period)
469 /* Parse top level resource definitions etc. */
471 : expr usrcvt resource_definition
{
475 if
($1 > 65535 ||
$1 < -32768)
476 yyerror("Resource's ID out of range (%d)", $1);
477 $$
->name
= new_name_id
();
478 $$
->name
->type
= name_ord
;
479 $$
->name
->name.i_name
= $1;
480 chat
("Got %s (%d)", get_typename
($3), $$
->name
->name.i_name
);
483 | tIDENT usrcvt resource_definition
{
487 $$
->name
= new_name_id
();
488 $$
->name
->type
= name_str
;
489 $$
->name
->name.s_name
= $1;
490 chat
("Got %s (%s)", get_typename
($3), $$
->name
->name.s_name
->str.cstr
);
493 | tIDENT usrcvt tIDENT
'(' { /* cjunk */ strip_til_parenthesis
(); $$
= NULL
; }
494 /* The above rule is inserted here with explicit tIDENT
495 * references to avoid a nasty LALR(2) problem when
496 * considering the 'cjunk' rules with respect to the usertype
498 * A usertype resource can have two leading identifiers before
499 * it qualifies as shift into usertype rules. However, the
500 * cjunk scanner also has a rule of two leading identifiers.
501 * The problem occurs because the second identifier is at the
502 * second lookahead (hence LALR(2)) seen from the recursion
504 * Thus, the scanner will pick *one* of the rules in preference
505 * of the other (in this case it was 'cjunk') and generates a
506 * syntax error if the trailing context wasn't seen. The
507 * correct action would have been to rollback the stack and
508 * decent into the 'userres' rule, but this cannot be done
509 * because yacc only parses LALR(1).
510 * The problem is prevented from happening by making the decent
511 * into the cjunk-scanning obsolete and explicitly force the
512 * scanner to require no more than 1 lookahead.
515 /* Don't do anything, stringtables are converted to
516 * resource_t structures when we are finished parsing and
517 * the final rule of the parser is reduced (see above)
520 chat
("Got STRINGTABLE");
522 | tLANGUAGE
{want_nl
= 1; } expr
',' expr
{
523 /* We *NEED* the newline to delimit the expression.
524 * Otherwise, we would not be able to set the next
525 * want_id anymore because of the token-lookahead.
527 * However, we can test the lookahead-token for
528 * being "non-expression" type, in which case we
529 * continue. Fortunately, tNL is the only token that
530 * will break expression parsing and is implicitely
531 * void, so we just remove it. This scheme makes it
532 * possible to do some (not all) fancy preprocessor
534 * BTW, we also need to make sure that the next
535 * reduction of 'resources' above will *not* set
536 * want_id because we already have a lookahead that
539 if
(yychar != YYEMPTY
&& yychar != tNL
)
543 yychar = YYEMPTY
; /* Could use 'yyclearin', but we already need the*/
544 /* direct access to yychar in rule 'usrcvt' below. */
545 else if
(yychar == tIDENT
)
546 yywarning
("LANGUAGE statement not delimited with newline; next identifier might be wrong");
548 want_nl
= 0; /* We don't want it anymore if we didn't get it */
551 yywarning
("LANGUAGE not supported in 16-bit mode");
553 free
(currentlanguage
);
554 currentlanguage
= new_language
($3, $5);
556 chat
("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
561 * Remapping of numerical resource types
562 * (see also comment of called function below)
564 usrcvt
: /* Empty */ { yychar = rsrcid_to_token
(yychar); }
568 * Get a valid name/id
571 if
($1 > 65535 ||
$1 < -32768)
572 yyerror("Resource's ID out of range (%d)", $1);
575 $$
->name.i_name
= $1;
580 $$
->name.s_name
= $1;
585 * Extra string recognition for CLASS statement in dialogs
587 nameid_s: nameid
{ $$
= $1; }
591 $$
->name.s_name
= $1;
595 /* get the value for a single resource*/
597 : accelerators
{ $$
= new_resource
(res_acc
, $1, $1->memopt
, $1->lvc.language
); }
598 | bitmap
{ $$
= new_resource
(res_bmp
, $1, $1->memopt
, $1->data
->lvc.language
); }
601 if
($1->type
== res_anicur
)
603 $$
= rsc
= new_resource
(res_anicur
, $1->u.ani
, $1->u.ani
->memopt
, $1->u.ani
->data
->lvc.language
);
605 else if
($1->type
== res_curg
)
608 $$
= rsc
= new_resource
(res_curg
, $1->u.curg
, $1->u.curg
->memopt
, $1->u.curg
->lvc.language
);
609 for
(cur
= $1->u.curg
->cursorlist
; cur
; cur
= cur
->next
)
611 rsc
->prev
= new_resource
(res_cur
, cur
, $1->u.curg
->memopt
, $1->u.curg
->lvc.language
);
612 rsc
->prev
->next
= rsc
;
614 rsc
->name
= new_name_id
();
615 rsc
->name
->type
= name_ord
;
616 rsc
->name
->name.i_name
= cur
->id
;
620 internal_error
(__FILE__
, __LINE__
, "Invalid top-level type %d in cursor resource", $1->type
);
623 | dialog
{ $$
= new_resource
(res_dlg
, $1, $1->memopt
, $1->lvc.language
); }
626 $$
= new_resource
(res_dlgex
, $1, $1->memopt
, $1->lvc.language
);
630 | dlginit
{ $$
= new_resource
(res_dlginit
, $1, $1->memopt
, $1->data
->lvc.language
); }
631 | font
{ $$
= new_resource
(res_fnt
, $1, $1->memopt
, $1->data
->lvc.language
); }
632 | fontdir
{ $$
= new_resource
(res_fntdir
, $1, $1->memopt
, $1->data
->lvc.language
); }
635 if
($1->type
== res_aniico
)
637 $$
= rsc
= new_resource
(res_aniico
, $1->u.ani
, $1->u.ani
->memopt
, $1->u.ani
->data
->lvc.language
);
639 else if
($1->type
== res_icog
)
642 $$
= rsc
= new_resource
(res_icog
, $1->u.icog
, $1->u.icog
->memopt
, $1->u.icog
->lvc.language
);
643 for
(ico
= $1->u.icog
->iconlist
; ico
; ico
= ico
->next
)
645 rsc
->prev
= new_resource
(res_ico
, ico
, $1->u.icog
->memopt
, $1->u.icog
->lvc.language
);
646 rsc
->prev
->next
= rsc
;
648 rsc
->name
= new_name_id
();
649 rsc
->name
->type
= name_ord
;
650 rsc
->name
->name.i_name
= ico
->id
;
654 internal_error
(__FILE__
, __LINE__
, "Invalid top-level type %d in icon resource", $1->type
);
657 | menu
{ $$
= new_resource
(res_men
, $1, $1->memopt
, $1->lvc.language
); }
660 $$
= new_resource
(res_menex
, $1, $1->memopt
, $1->lvc.language
);
664 | messagetable
{ $$
= new_resource
(res_msg
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, dup_language
(currentlanguage
)); }
665 | rcdata
{ $$
= new_resource
(res_rdt
, $1, $1->memopt
, $1->data
->lvc.language
); }
666 | toolbar
{ $$
= new_resource
(res_toolbar
, $1, $1->memopt
, $1->lvc.language
); }
667 | userres
{ $$
= new_resource
(res_usr
, $1, $1->memopt
, $1->data
->lvc.language
); }
668 | versioninfo
{ $$
= new_resource
(res_ver
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, $1->lvc.language
); }
672 filename: tFILENAME
{ $$
= make_filename
($1); }
673 | tIDENT
{ $$
= make_filename
($1); }
674 | tSTRING
{ $$
= make_filename
($1); }
677 /* ------------------------------ Bitmap ------------------------------ */
678 bitmap
: tBITMAP loadmemopts file_raw
{ $$
= new_bitmap
($3, $2); }
681 /* ------------------------------ Cursor ------------------------------ */
682 cursor
: tCURSOR loadmemopts file_raw
{
684 if
($3->size
> 4 && !memcmp
($3->data
, riff
, sizeof
(riff
)))
686 $$
->type
= res_anicur
;
687 $$
->u.ani
= new_ani_curico
(res_anicur
, $3, $2);
692 $$
->u.curg
= new_cursor_group
($3, $2);
697 /* ------------------------------ Icon ------------------------------ */
698 icon
: tICON loadmemopts file_raw
{
700 if
($3->size
> 4 && !memcmp
($3->data
, riff
, sizeof
(riff
)))
702 $$
->type
= res_aniico
;
703 $$
->u.ani
= new_ani_curico
(res_aniico
, $3, $2);
708 $$
->u.icog
= new_icon_group
($3, $2);
713 /* ------------------------------ Font ------------------------------ */
715 * The reading of raw_data for fonts is a Borland BRC
716 * extension. MS generates an error. However, it is
717 * most logical to support this, considering how wine
718 * enters things in CVS (ascii).
720 font
: tFONT loadmemopts file_raw
{ $$
= new_font
($3, $2); }
724 * The fontdir is a Borland BRC extension which only
725 * reads the data as 'raw_data' from the file.
726 * I don't know whether it is interpreted.
727 * The fontdir is generated if it was not present and
728 * fonts are defined in the source.
730 fontdir
: tFONTDIR loadmemopts file_raw
{ $$
= new_fontdir
($3, $2); }
733 /* ------------------------------ MessageTable ------------------------------ */
734 /* It might be interesting to implement the MS Message compiler here as well
735 * to get everything in one source. Might be a future project.
738 : tMESSAGETABLE loadmemopts file_raw
{
740 yywarning
("MESSAGETABLE not supported in 16-bit mode");
741 $$
= new_messagetable
($3, $2);
745 /* ------------------------------ RCData ------------------------------ */
746 rcdata
: tRCDATA loadmemopts file_raw
{ $$
= new_rcdata
($3, $2); }
749 /* ------------------------------ DLGINIT ------------------------------ */
750 dlginit
: tDLGINIT loadmemopts file_raw
{ $$
= new_dlginit
($3, $2); }
753 /* ------------------------------ UserType ------------------------------ */
754 userres
: usertype loadmemopts file_raw
{
755 #ifdef WORDS_BIGENDIAN
756 if
(pedantic
&& byteorder
!= WRC_BO_LITTLE
)
758 if
(pedantic
&& byteorder
== WRC_BO_BIG
)
760 yywarning
("Byteordering is not little-endian and type cannot be interpreted");
761 $$
= new_user
($1, $3, $2);
768 $$
->name.i_name
= $1;
773 $$
->name.s_name
= $1;
777 /* ------------------------------ Accelerator ------------------------------ */
779 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND
{
780 $$
= new_accelerator
();
788 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE
;
791 yyerror("Accelerator table must have at least one entry");
792 $$
->events
= get_event_head
($5);
798 if
(!$$
->lvc.language
)
799 $$
->lvc.language
= dup_language
(currentlanguage
);
803 events
: /* Empty */ { $$
=NULL
; }
804 | events tSTRING
',' expr acc_opt
{ $$
=add_string_event
($2, $4, $5, $1); }
805 | events expr
',' expr acc_opt
{ $$
=add_event
($2, $4, $5, $1); }
809 * The empty rule generates a s/r conflict because of {bi,u}nary expr
810 * on - and +. It cannot be solved in any way because it is the same as
811 * the if/then/else problem (LALR(1) problem). The conflict is moved
812 * away by forcing it to be in the expression handling below.
814 acc_opt
: /* Empty */ { $$
= 0; }
815 |
',' accs
{ $$
= $2; }
818 accs
: acc
{ $$
= $1; }
819 | accs
',' acc
{ $$
= $1 |
$3; }
822 acc
: tNOINVERT
{ $$
= WRC_AF_NOINVERT
; }
823 | tSHIFT
{ $$
= WRC_AF_SHIFT
; }
824 | tCONTROL
{ $$
= WRC_AF_CONTROL
; }
825 | tALT
{ $$
= WRC_AF_ALT
; }
826 | tASCII
{ $$
= WRC_AF_ASCII
; }
827 | tVIRTKEY
{ $$
= WRC_AF_VIRTKEY
; }
830 /* ------------------------------ Dialog ------------------------------ */
831 /* FIXME: Support EXSTYLE in the dialog line itself */
832 dialog
: tDIALOG loadmemopts expr
',' expr
',' expr
',' expr dlg_attributes
840 $10->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
845 $10->controls
= get_control_head
($12);
849 $$
->style
->or_mask
= WS_POPUP
;
853 $$
->style
->or_mask |
= WS_CAPTION
;
855 $$
->style
->or_mask |
= DS_SETFONT
;
857 $$
->style
->or_mask
&= ~
($$
->style
->and_mask
);
858 $$
->style
->and_mask
= 0;
860 if
(!$$
->lvc.language
)
861 $$
->lvc.language
= dup_language
(currentlanguage
);
866 : /* Empty */ { $$
=new_dialog
(); }
867 | dlg_attributes tSTYLE style
{ $$
=dialog_style
($3,$1); }
868 | dlg_attributes tEXSTYLE style
{ $$
=dialog_exstyle
($3,$1); }
869 | dlg_attributes tCAPTION tSTRING
{ $$
=dialog_caption
($3,$1); }
870 | dlg_attributes opt_font
{ $$
=dialog_font
($2,$1); }
871 | dlg_attributes tCLASS nameid_s
{ $$
=dialog_class
($3,$1); }
872 | dlg_attributes tCPPCLASS nameid_s
{ $$
=dialog_class
($3,$1); }
873 | dlg_attributes tMENU nameid
{ $$
=dialog_menu
($3,$1); }
874 | dlg_attributes opt_language
{ $$
=dialog_language
($2,$1); }
875 | dlg_attributes opt_characts
{ $$
=dialog_characteristics
($2,$1); }
876 | dlg_attributes opt_version
{ $$
=dialog_version
($2,$1); }
879 ctrls
: /* Empty */ { $$
= NULL
; }
880 | ctrls tCONTROL gen_ctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
881 | ctrls tEDITTEXT ctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
882 | ctrls tLISTBOX ctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
883 | ctrls tCOMBOBOX ctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
884 | ctrls tSCROLLBAR ctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
885 | ctrls tCHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
886 | ctrls tDEFPUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
887 | ctrls tGROUPBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
888 | ctrls tPUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
889 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
890 | ctrls tRADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
891 | ctrls tAUTO3STATE lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
892 | ctrls tSTATE3 lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
893 | ctrls tAUTOCHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
894 | ctrls tAUTORADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
895 | ctrls tLTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
896 | ctrls tCTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
897 | ctrls tRTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
898 /* special treatment for icons, as the extent is optional */
899 | ctrls tICON nameid_s opt_comma expr
',' expr
',' expr iconinfo
{
904 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
909 : tSTRING opt_comma expr
',' expr
',' expr
',' expr
',' expr optional_style
{
911 $$
->title
= new_name_id
();
912 $$
->title
->type
= name_str
;
913 $$
->title
->name.s_name
= $1;
928 : expr
',' expr
',' expr
',' expr
',' expr optional_style
{
943 iconinfo: /* Empty */
944 { $$
= new_control
(); }
946 |
',' expr
',' expr
{
951 |
',' expr
',' expr
',' style
{
958 |
',' expr
',' expr
',' style
',' style
{
965 $$
->gotexstyle
= TRUE
;
969 gen_ctrl: nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr
',' style
{
973 $$
->ctlclass
= convert_ctlclass
($5);
981 $$
->gotexstyle
= TRUE
;
983 | nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr
{
987 $$
->ctlclass
= convert_ctlclass
($5);
998 : tFONT expr
',' tSTRING
{ $$
= new_font_id
($2, $4, 0, 0); }
1001 /* ------------------------------ style flags ------------------------------ */
1002 optional_style
/* Abbused once to get optional ExStyle */
1003 : /* Empty */ { $$
= NULL
; }
1004 |
',' style
{ $$
= $2; }
1008 : /* Empty */ { $$
= NULL
; }
1009 |
',' style
{ $$
= new_style_pair
($2, 0); }
1010 |
',' style
',' style
{ $$
= new_style_pair
($2, $4); }
1014 : style
'|' style
{ $$
= new_style
($1->or_mask |
$3->or_mask
, $1->and_mask |
$3->and_mask
); free
($1); free
($3);}
1015 |
'(' style
')' { $$
= $2; }
1016 | any_num
{ $$
= new_style
($1, 0); }
1017 | tNOT any_num
{ $$
= new_style
(0, $2); }
1023 $$
->type
= name_ord
;
1024 $$
->name.i_name
= $1;
1028 $$
->type
= name_str
;
1029 $$
->name.s_name
= $1;
1033 /* ------------------------------ DialogEx ------------------------------ */
1034 dialogex: tDIALOGEX loadmemopts expr
',' expr
',' expr
',' expr helpid dlgex_attribs
1035 tBEGIN exctrls tEND
{
1037 yywarning
("DIALOGEX not supported in 16-bit mode");
1040 $11->memopt
= *($2);
1044 $11->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1051 $11->helpid
= *($10);
1052 $11->gothelpid
= TRUE
;
1055 $11->controls
= get_control_head
($13);
1058 assert
($$
->style
!= NULL
);
1061 $$
->style
->or_mask
= WS_POPUP
;
1062 $$
->gotstyle
= TRUE
;
1065 $$
->style
->or_mask |
= WS_CAPTION
;
1067 $$
->style
->or_mask |
= DS_SETFONT
;
1069 $$
->style
->or_mask
&= ~
($$
->style
->and_mask
);
1070 $$
->style
->and_mask
= 0;
1072 if
(!$$
->lvc.language
)
1073 $$
->lvc.language
= dup_language
(currentlanguage
);
1078 : /* Empty */ { $$
=new_dialogex
(); }
1079 | dlgex_attribs tSTYLE style
{ $$
=dialogex_style
($3,$1); }
1080 | dlgex_attribs tEXSTYLE style
{ $$
=dialogex_exstyle
($3,$1); }
1081 | dlgex_attribs tCAPTION tSTRING
{ $$
=dialogex_caption
($3,$1); }
1082 | dlgex_attribs opt_font
{ $$
=dialogex_font
($2,$1); }
1083 | dlgex_attribs opt_exfont
{ $$
=dialogex_font
($2,$1); }
1084 | dlgex_attribs tCLASS nameid_s
{ $$
=dialogex_class
($3,$1); }
1085 | dlgex_attribs tCPPCLASS nameid_s
{ $$
=dialogex_class
($3,$1); }
1086 | dlgex_attribs tMENU nameid
{ $$
=dialogex_menu
($3,$1); }
1087 | dlgex_attribs opt_language
{ $$
=dialogex_language
($2,$1); }
1088 | dlgex_attribs opt_characts
{ $$
=dialogex_characteristics
($2,$1); }
1089 | dlgex_attribs opt_version
{ $$
=dialogex_version
($2,$1); }
1092 exctrls
: /* Empty */ { $$
= NULL
; }
1093 | exctrls tCONTROL gen_exctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
1094 | exctrls tEDITTEXT exctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
1095 | exctrls tLISTBOX exctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
1096 | exctrls tCOMBOBOX exctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
1097 | exctrls tSCROLLBAR exctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
1098 | exctrls tCHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
1099 | exctrls tDEFPUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
1100 | exctrls tGROUPBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
1101 | exctrls tPUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
1102 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1103 | exctrls tRADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
1104 | exctrls tAUTO3STATE lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
1105 | exctrls tSTATE3 lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
1106 | exctrls tAUTOCHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
1107 | exctrls tAUTORADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
1108 | exctrls tLTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
1109 | exctrls tCTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
1110 | exctrls tRTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
1111 /* special treatment for icons, as the extent is optional */
1112 | exctrls tICON nameid_s opt_comma expr
',' expr
',' expr iconinfo
{
1117 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
1122 : nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
','
1123 expr
',' style helpid opt_data
{
1127 $$
->ctlclass
= convert_ctlclass
($5);
1129 $$
->gotstyle
= TRUE
;
1137 $$
->gotexstyle
= TRUE
;
1141 $$
->helpid
= *($18);
1142 $$
->gothelpid
= TRUE
;
1147 | nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr opt_data
{
1152 $$
->gotstyle
= TRUE
;
1153 $$
->ctlclass
= convert_ctlclass
($5);
1163 : tSTRING opt_comma expr
',' expr
',' expr
',' expr
',' expr optional_style_pair opt_data
{
1165 $$
->title
= new_name_id
();
1166 $$
->title
->type
= name_str
;
1167 $$
->title
->name.s_name
= $1;
1175 $$
->style
= $12->style
;
1176 $$
->gotstyle
= TRUE
;
1180 $$
->exstyle
= $12->exstyle
;
1181 $$
->gotexstyle
= TRUE
;
1191 : expr
',' expr
',' expr
',' expr
',' expr optional_style_pair opt_data
{
1200 $$
->style
= $10->style
;
1201 $$
->gotstyle
= TRUE
;
1205 $$
->exstyle
= $10->exstyle
;
1206 $$
->gotexstyle
= TRUE
;
1214 opt_data: /* Empty */ { $$
= NULL
; }
1215 | raw_data
{ $$
= $1; }
1218 helpid
: /* Empty */ { $$
= NULL
; }
1219 |
',' expr
{ $$
= new_int
($2); }
1223 : tFONT expr
',' tSTRING
',' expr
',' expr opt_expr
{ $$
= new_font_id
($2, $4, $6, $8); }
1227 * FIXME: This odd expression is here to nullify an extra token found
1228 * in some appstudio produced resources which appear to do nothing.
1230 opt_expr: /* Empty */ { $$
= NULL
; }
1231 |
',' expr
{ $$
= NULL
; }
1234 /* ------------------------------ Menu ------------------------------ */
1235 menu
: tMENU loadmemopts opt_lvc menu_body
{
1237 yyerror("Menu must contain items");
1245 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1246 $$
->items
= get_item_head
($4);
1252 if
(!$$
->lvc.language
)
1253 $$
->lvc.language
= dup_language
(currentlanguage
);
1258 : tBEGIN item_definitions tEND
{ $$
= $2; }
1262 : /* Empty */ {$$
= NULL
;}
1263 | item_definitions tMENUITEM tSTRING opt_comma expr item_options
{
1272 | item_definitions tMENUITEM tSEPARATOR
{
1278 | item_definitions tPOPUP tSTRING item_options menu_body
{
1279 $$
= new_menu_item
();
1283 $$
->popup
= get_item_head
($5);
1288 /* NOTE: item_options is right recursive because it would introduce
1289 * a shift/reduce conflict on ',' in itemex_options due to the
1290 * empty rule here. The parser is now forced to look beyond the ','
1291 * before reducing (force shift).
1292 * Right recursion here is not a problem because we cannot expect
1293 * more than 7 parserstack places to be occupied while parsing this
1294 * (who would want to specify a MF_x flag twice?).
1297 : /* Empty */ { $$
= 0; }
1298 |
',' tCHECKED item_options
{ $$
= $3 | MF_CHECKED
; }
1299 |
',' tGRAYED item_options
{ $$
= $3 | MF_GRAYED
; }
1300 |
',' tHELP item_options
{ $$
= $3 | MF_HELP
; }
1301 |
',' tINACTIVE item_options
{ $$
= $3 | MF_DISABLED
; }
1302 |
',' tMENUBARBREAK item_options
{ $$
= $3 | MF_MENUBARBREAK
; }
1303 |
',' tMENUBREAK item_options
{ $$
= $3 | MF_MENUBREAK
; }
1306 /* ------------------------------ MenuEx ------------------------------ */
1307 menuex
: tMENUEX loadmemopts opt_lvc menuex_body
{
1309 yywarning
("MENUEX not supported in 16-bit mode");
1311 yyerror("MenuEx must contain items");
1319 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1320 $$
->items
= get_itemex_head
($4);
1326 if
(!$$
->lvc.language
)
1327 $$
->lvc.language
= dup_language
(currentlanguage
);
1332 : tBEGIN itemex_definitions tEND
{ $$
= $2; }
1336 : /* Empty */ {$$
= NULL
; }
1337 | itemex_definitions tMENUITEM tSTRING itemex_options
{
1338 $$
= new_menuex_item
();
1344 $$
->type
= $4->type
;
1345 $$
->state
= $4->state
;
1346 $$
->helpid
= $4->helpid
;
1347 $$
->gotid
= $4->gotid
;
1348 $$
->gottype
= $4->gottype
;
1349 $$
->gotstate
= $4->gotstate
;
1350 $$
->gothelpid
= $4->gothelpid
;
1353 | itemex_definitions tMENUITEM tSEPARATOR
{
1354 $$
= new_menuex_item
();
1359 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body
{
1360 $$
= new_menuex_item
();
1364 $$
->popup
= get_itemex_head
($5);
1367 $$
->type
= $4->type
;
1368 $$
->state
= $4->state
;
1369 $$
->helpid
= $4->helpid
;
1370 $$
->gotid
= $4->gotid
;
1371 $$
->gottype
= $4->gottype
;
1372 $$
->gotstate
= $4->gotstate
;
1373 $$
->gothelpid
= $4->gothelpid
;
1379 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1381 $$
= new_itemex_opt
($2, 0, 0, 0);
1384 |
',' e_expr
',' e_expr item_options
{
1385 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $5, 0);
1388 $$
->gotstate
= TRUE
;
1392 |
',' e_expr
',' e_expr
',' expr
{
1393 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1396 $$
->gotstate
= TRUE
;
1403 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1405 $$
= new_itemex_opt
($2, 0, 0, 0);
1408 |
',' e_expr
',' expr
{
1409 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4, 0, 0);
1414 |
',' e_expr
',' e_expr
',' expr
{
1415 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1420 $$
->gotstate
= TRUE
;
1422 |
',' e_expr
',' e_expr
',' e_expr
',' expr
{
1423 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6 ?
*($6) : 0, $8);
1429 $$
->gotstate
= TRUE
;
1430 $$
->gothelpid
= TRUE
;
1434 /* ------------------------------ StringTable ------------------------------ */
1435 /* Stringtables are parsed differently than other resources because their
1436 * layout is substantially different from other resources.
1437 * The table is parsed through a _global_ variable 'tagstt' which holds the
1438 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1439 * list of stringtables of different languages.
1442 : stt_head tBEGIN strings tEND
{
1445 yyerror("Stringtable must have at least one entry");
1450 /* Check if we added to a language table or created
1453 for
(stt
= sttres
; stt
; stt
= stt
->next
)
1460 /* It is a new one */
1463 sttres
->prev
= tagstt
;
1464 tagstt
->next
= sttres
;
1470 /* Else were done */
1474 free
(tagstt_memopt
);
1475 tagstt_memopt
= NULL
;
1482 /* This is to get the language of the currently parsed stringtable */
1483 stt_head: tSTRINGTABLE loadmemopts opt_lvc
{
1484 if
((tagstt
= find_stringtable
($3)) == NULL
)
1485 tagstt
= new_stringtable
($3);
1487 tagstt_version
= $3->version
;
1488 tagstt_characts
= $3->characts
;
1494 strings
: /* Empty */ { $$
= NULL
; }
1495 | strings expr opt_comma tSTRING
{
1497 assert
(tagstt
!= NULL
);
1498 if
($2 > 65535 ||
$2 < -32768)
1499 yyerror("Stringtable entry's ID out of range (%d)", $2);
1500 /* Search for the ID */
1501 for
(i
= 0; i
< tagstt
->nentries
; i
++)
1503 if
(tagstt
->entries
[i
].id
== $2)
1504 yyerror("Stringtable ID %d already in use", $2);
1506 /* If we get here, then we have a new unique entry */
1508 tagstt
->entries
= xrealloc
(tagstt
->entries
, sizeof
(tagstt
->entries
[0]) * tagstt
->nentries
);
1509 tagstt
->entries
[tagstt
->nentries
-1].id
= $2;
1510 tagstt
->entries
[tagstt
->nentries
-1].str
= $4;
1512 tagstt
->entries
[tagstt
->nentries
-1].memopt
= *tagstt_memopt
;
1514 tagstt
->entries
[tagstt
->nentries
-1].memopt
= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1515 tagstt
->entries
[tagstt
->nentries
-1].version
= tagstt_version
;
1516 tagstt
->entries
[tagstt
->nentries
-1].characts
= tagstt_characts
;
1518 if
(pedantic
&& !$4->size
)
1519 yywarning
("Zero length strings make no sense");
1520 if
(!win32
&& $4->size
> 254)
1521 yyerror("Stringtable entry more than 254 characters");
1522 if
(win32
&& $4->size
> 65534) /* Hmm..., does this happen? */
1523 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1528 opt_comma
/* There seem to be two ways to specify a stringtable... */
1533 /* ------------------------------ VersionInfo ------------------------------ */
1535 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND
{
1543 $$
->memopt
= WRC_MO_MOVEABLE |
(win32 ? WRC_MO_PURE
: 0);
1544 $$
->blocks
= get_ver_block_head
($5);
1545 /* Set language; there is no version or characteristics */
1546 $$
->lvc.language
= dup_language
(currentlanguage
);
1551 : /* Empty */ { $$
= new_versioninfo
(); }
1552 | fix_version tFILEVERSION expr
',' expr
',' expr
',' expr
{
1554 yyerror("FILEVERSION already defined");
1556 $$
->filever_maj1
= $3;
1557 $$
->filever_maj2
= $5;
1558 $$
->filever_min1
= $7;
1559 $$
->filever_min2
= $9;
1562 | fix_version tPRODUCTVERSION expr
',' expr
',' expr
',' expr
{
1564 yyerror("PRODUCTVERSION already defined");
1566 $$
->prodver_maj1
= $3;
1567 $$
->prodver_maj2
= $5;
1568 $$
->prodver_min1
= $7;
1569 $$
->prodver_min2
= $9;
1572 | fix_version tFILEFLAGS expr
{
1574 yyerror("FILEFLAGS already defined");
1579 | fix_version tFILEFLAGSMASK expr
{
1581 yyerror("FILEFLAGSMASK already defined");
1583 $$
->fileflagsmask
= $3;
1586 | fix_version tFILEOS expr
{
1588 yyerror("FILEOS already defined");
1593 | fix_version tFILETYPE expr
{
1595 yyerror("FILETYPE already defined");
1600 | fix_version tFILESUBTYPE expr
{
1602 yyerror("FILESUBTYPE already defined");
1604 $$
->filesubtype
= $3;
1610 : /* Empty */ { $$
= NULL
; }
1611 | ver_blocks ver_block
{
1620 : tBLOCK tSTRING tBEGIN ver_values tEND
{
1621 $$
= new_ver_block
();
1623 $$
->values
= get_ver_value_head
($4);
1628 : /* Empty */ { $$
= NULL
; }
1629 | ver_values ver_value
{
1639 $$
= new_ver_value
();
1640 $$
->type
= val_block
;
1641 $$
->value.block
= $1;
1643 | tVALUE tSTRING
',' tSTRING
{
1644 $$
= new_ver_value
();
1649 | tVALUE tSTRING
',' ver_words
{
1650 $$
= new_ver_value
();
1651 $$
->type
= val_words
;
1653 $$
->value.words
= $4;
1658 : expr
{ $$
= new_ver_words
($1); }
1659 | ver_words
',' expr
{ $$
= add_ver_words
($1, $3); }
1662 /* ------------------------------ Toolbar ------------------------------ */
1663 toolbar: tTOOLBAR loadmemopts expr
',' expr opt_lvc tBEGIN toolbar_items tEND
{
1665 toolbar_item_t
*items
= get_tlbr_buttons_head
($8, &nitems
);
1666 $$
= new_toolbar
($3, $5, items
, nitems
);
1674 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE
;
1681 if
(!$$
->lvc.language
)
1683 $$
->lvc.language
= dup_language
(currentlanguage
);
1689 : /* Empty */ { $$
= NULL
; }
1690 | toolbar_items tBUTTON expr
{
1691 toolbar_item_t
*idrec
= new_toolbar_item
();
1693 $$
= ins_tlbr_button
($1, idrec
);
1695 | toolbar_items tSEPARATOR
{
1696 toolbar_item_t
*idrec
= new_toolbar_item
();
1698 $$
= ins_tlbr_button
($1, idrec
);
1702 /* ------------------------------ Memory options ------------------------------ */
1704 : /* Empty */ { $$
= NULL
; }
1705 | loadmemopts lamo
{
1715 | loadmemopts lama
{
1724 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1730 lamo
: tPRELOAD
{ $$
= new_int
(WRC_MO_PRELOAD
); }
1731 | tMOVEABLE
{ $$
= new_int
(WRC_MO_MOVEABLE
); }
1732 | tDISCARDABLE
{ $$
= new_int
(WRC_MO_DISCARDABLE
); }
1733 | tPURE
{ $$
= new_int
(WRC_MO_PURE
); }
1736 lama
: tLOADONCALL
{ $$
= new_int
(~WRC_MO_PRELOAD
); }
1737 | tFIXED
{ $$
= new_int
(~WRC_MO_MOVEABLE
); }
1738 | tIMPURE
{ $$
= new_int
(~WRC_MO_PURE
); }
1741 /* ------------------------------ Win32 options ------------------------------ */
1742 opt_lvc
: /* Empty */ { $$
= new_lvc
(); }
1743 | opt_lvc opt_language
{
1745 yywarning
("LANGUAGE not supported in 16-bit mode");
1747 yyerror("Language already defined");
1751 | opt_lvc opt_characts
{
1753 yywarning
("CHARACTERISTICS not supported in 16-bit mode");
1755 yyerror("Characteristics already defined");
1759 | opt_lvc opt_version
{
1761 yywarning
("VERSION not supported in 16-bit mode");
1763 yyerror("Version already defined");
1770 * This here is another s/r conflict on {bi,u}nary + and -.
1771 * It is due to the look-ahead which must determine when the
1772 * rule opt_language ends. It could be solved with adding a
1773 * tNL at the end, but that seems unreasonable to do.
1774 * The conflict is now moved to the expression handling below.
1777 : tLANGUAGE expr
',' expr
{ $$
= new_language
($2, $4); }
1781 : tCHARACTERISTICS expr
{ $$
= new_characts
($2); }
1785 : tVERSION expr
{ $$
= new_version
($2); }
1788 /* ------------------------------ Raw data handling ------------------------------ */
1789 raw_data: opt_lvc tBEGIN raw_elements tEND
{
1796 if
(!$3->lvc.language
)
1797 $3->lvc.language
= dup_language
(currentlanguage
);
1804 : tRAWDATA
{ $$
= $1; }
1805 | tNUMBER
{ $$
= int2raw_data
($1); }
1806 | tLNUMBER
{ $$
= long2raw_data
($1); }
1807 | tSTRING
{ $$
= str2raw_data
($1); }
1808 | raw_elements opt_comma tRAWDATA
{ $$
= merge_raw_data
($1, $3); free
($3->data
); free
($3); }
1809 | raw_elements opt_comma tNUMBER
{ $$
= merge_raw_data_int
($1, $3); }
1810 | raw_elements opt_comma tLNUMBER
{ $$
= merge_raw_data_long
($1, $3); }
1811 | raw_elements opt_comma tSTRING
{ $$
= merge_raw_data_str
($1, $3); }
1814 /* File data or raw data */
1815 file_raw: filename
{
1817 $$
->lvc.language
= dup_language
(currentlanguage
);
1819 | raw_data
{ $$
= $1; }
1822 /* ------------------------------ Win32 expressions ------------------------------ */
1823 /* All win16 numbers are also handled here. This is inconsistent with MS'
1824 * resource compiler, but what the heck, its just handy to have.
1826 e_expr
: /* Empty */ { $$
= 0; }
1827 | expr
{ $$
= new_int
($1); }
1830 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1831 expr
: xpr
{ $$
= ($1); }
1834 xpr
: xpr
'+' xpr
{ $$
= ($1) + ($3); }
1835 | xpr
'-' xpr
{ $$
= ($1) - ($3); }
1836 | xpr
'|' xpr
{ $$
= ($1) |
($3); }
1837 | xpr
'&' xpr
{ $$
= ($1) & ($3); }
1838 | xpr
'*' xpr
{ $$
= ($1) * ($3); }
1839 | xpr
'/' xpr
{ $$
= ($1) / ($3); }
1840 | xpr
'^' xpr
{ $$
= ($1) ^
($3); }
1841 |
'~' xpr
{ $$
= ~
($2); }
1842 |
'-' xpr %prec pUPM
{ $$
= -($2); }
1843 |
'+' xpr %prec pUPM
{ $$
= $2; }
1844 |
'(' xpr
')' { $$
= $2; }
1845 | any_num
{ $$
= $1; }
1846 | tNOT any_num
{ $$
= ~
($2); }
1849 any_num
: tNUMBER
{ $$
= $1; }
1850 | tLNUMBER
{ $$
= $1; }
1854 /* Dialog specific functions */
1855 static dialog_t
*dialog_style
(style_t
* st
, dialog_t
*dlg
)
1857 assert
(dlg
!= NULL
);
1858 if
(dlg
->style
== NULL
)
1860 dlg
->style
= new_style
(0,0);
1865 yywarning
("Style already defined, or-ing together");
1869 dlg
->style
->or_mask
= 0;
1870 dlg
->style
->and_mask
= 0;
1872 dlg
->style
->or_mask |
= st
->or_mask
;
1873 dlg
->style
->and_mask |
= st
->and_mask
;
1874 dlg
->gotstyle
= TRUE
;
1879 static dialog_t
*dialog_exstyle
(style_t
*st
, dialog_t
*dlg
)
1881 assert
(dlg
!= NULL
);
1882 if
(dlg
->exstyle
== NULL
)
1884 dlg
->exstyle
= new_style
(0,0);
1889 yywarning
("ExStyle already defined, or-ing together");
1893 dlg
->exstyle
->or_mask
= 0;
1894 dlg
->exstyle
->and_mask
= 0;
1896 dlg
->exstyle
->or_mask |
= st
->or_mask
;
1897 dlg
->exstyle
->and_mask |
= st
->and_mask
;
1898 dlg
->gotexstyle
= TRUE
;
1903 static dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
)
1905 assert
(dlg
!= NULL
);
1907 yyerror("Caption already defined");
1912 static dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
)
1914 assert
(dlg
!= NULL
);
1916 yyerror("Font already defined");
1921 static dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
)
1923 assert
(dlg
!= NULL
);
1925 yyerror("Class already defined");
1930 static dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
)
1932 assert
(dlg
!= NULL
);
1934 yyerror("Menu already defined");
1939 static dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
)
1941 assert
(dlg
!= NULL
);
1942 if
(dlg
->lvc.language
)
1943 yyerror("Language already defined");
1944 dlg
->lvc.language
= l
;
1948 static dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
)
1950 assert
(dlg
!= NULL
);
1951 if
(dlg
->lvc.characts
)
1952 yyerror("Characteristics already defined");
1953 dlg
->lvc.characts
= c
;
1957 static dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
)
1959 assert
(dlg
!= NULL
);
1960 if
(dlg
->lvc.version
)
1961 yyerror("Version already defined");
1962 dlg
->lvc.version
= v
;
1966 /* Controls specific functions */
1967 static control_t
*ins_ctrl
(int type
, int special_style
, control_t
*ctrl
, control_t
*prev
)
1969 /* Hm... this seems to be jammed in at all time... */
1970 int defaultstyle
= WS_CHILD | WS_VISIBLE
;
1972 assert
(ctrl
!= NULL
);
1980 ctrl
->ctlclass
= new_name_id
();
1981 ctrl
->ctlclass
->type
= name_ord
;
1982 ctrl
->ctlclass
->name.i_name
= type
;
1988 if
(special_style
!= BS_GROUPBOX
&& special_style
!= BS_RADIOBUTTON
)
1989 defaultstyle |
= WS_TABSTOP
;
1992 defaultstyle |
= WS_TABSTOP | WS_BORDER
;
1995 defaultstyle |
= LBS_NOTIFY | WS_BORDER
;
1998 defaultstyle |
= CBS_SIMPLE
;
2001 if
(special_style
== SS_CENTER || special_style
== SS_LEFT || special_style
== SS_RIGHT
)
2002 defaultstyle |
= WS_GROUP
;
2006 if
(!ctrl
->gotstyle
) /* Handle default style setting */
2011 defaultstyle |
= ES_LEFT
;
2014 defaultstyle |
= LBS_NOTIFY
;
2017 defaultstyle |
= CBS_SIMPLE | WS_TABSTOP
;
2020 defaultstyle |
= SBS_HORZ
;
2023 switch
(special_style
)
2026 case BS_DEFPUSHBUTTON
:
2029 /* case BS_PUSHBOX: */
2030 case BS_AUTORADIOBUTTON
:
2033 case BS_AUTOCHECKBOX
:
2034 defaultstyle |
= WS_TABSTOP
;
2037 yywarning
("Unknown default button control-style 0x%08x", special_style
);
2038 case BS_RADIOBUTTON
:
2044 switch
(special_style
)
2049 defaultstyle |
= WS_GROUP
;
2051 case SS_ICON
: /* Special case */
2054 yywarning
("Unknown default static control-style 0x%08x", special_style
);
2058 case
-1: /* Generic control */
2062 yyerror("Internal error (report this): Got weird control type 0x%08x", type
);
2066 /* The SS_ICON flag is always forced in for icon controls */
2067 if
(type
== CT_STATIC
&& special_style
== SS_ICON
)
2068 defaultstyle |
= SS_ICON
;
2070 if
(!ctrl
->gotstyle
)
2071 ctrl
->style
= new_style
(0,0);
2073 /* combine all styles */
2074 ctrl
->style
->or_mask
= ctrl
->style
->or_mask | defaultstyle | special_style
;
2075 ctrl
->gotstyle
= TRUE
;
2077 /* combine with NOT mask */
2080 ctrl
->style
->or_mask
&= ~
(ctrl
->style
->and_mask
);
2081 ctrl
->style
->and_mask
= 0;
2083 if
(ctrl
->gotexstyle
)
2085 ctrl
->exstyle
->or_mask
&= ~
(ctrl
->exstyle
->and_mask
);
2086 ctrl
->exstyle
->and_mask
= 0;
2091 static name_id_t
*convert_ctlclass
(name_id_t
*cls
)
2096 if
(cls
->type
== name_ord
)
2098 assert
(cls
->type
== name_str
);
2099 if
(cls
->type
== str_unicode
)
2101 yyerror("Don't yet support unicode class comparison");
2104 cc
= cls
->name.s_name
->str.cstr
;
2106 if
(!strcasecmp
("BUTTON", cc
))
2108 else if
(!strcasecmp
("COMBOBOX", cc
))
2109 iclass
= CT_COMBOBOX
;
2110 else if
(!strcasecmp
("LISTBOX", cc
))
2111 iclass
= CT_LISTBOX
;
2112 else if
(!strcasecmp
("EDIT", cc
))
2114 else if
(!strcasecmp
("STATIC", cc
))
2116 else if
(!strcasecmp
("SCROLLBAR", cc
))
2117 iclass
= CT_SCROLLBAR
;
2119 return cls
; /* No default, return user controlclass */
2121 free
(cls
->name.s_name
->str.cstr
);
2122 free
(cls
->name.s_name
);
2123 cls
->type
= name_ord
;
2124 cls
->name.i_name
= iclass
;
2128 /* DialogEx specific functions */
2129 static dialogex_t
*dialogex_style
(style_t
* st
, dialogex_t
*dlg
)
2131 assert
(dlg
!= NULL
);
2132 if
(dlg
->style
== NULL
)
2134 dlg
->style
= new_style
(0,0);
2139 yywarning
("Style already defined, or-ing together");
2143 dlg
->style
->or_mask
= 0;
2144 dlg
->style
->and_mask
= 0;
2146 dlg
->style
->or_mask |
= st
->or_mask
;
2147 dlg
->style
->and_mask |
= st
->and_mask
;
2148 dlg
->gotstyle
= TRUE
;
2153 static dialogex_t
*dialogex_exstyle
(style_t
* st
, dialogex_t
*dlg
)
2155 assert
(dlg
!= NULL
);
2156 if
(dlg
->exstyle
== NULL
)
2158 dlg
->exstyle
= new_style
(0,0);
2163 yywarning
("ExStyle already defined, or-ing together");
2167 dlg
->exstyle
->or_mask
= 0;
2168 dlg
->exstyle
->and_mask
= 0;
2170 dlg
->exstyle
->or_mask |
= st
->or_mask
;
2171 dlg
->exstyle
->and_mask |
= st
->and_mask
;
2172 dlg
->gotexstyle
= TRUE
;
2177 static dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
)
2179 assert
(dlg
!= NULL
);
2181 yyerror("Caption already defined");
2186 static dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
)
2188 assert
(dlg
!= NULL
);
2190 yyerror("Font already defined");
2195 static dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
)
2197 assert
(dlg
!= NULL
);
2199 yyerror("Class already defined");
2204 static dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
)
2206 assert
(dlg
!= NULL
);
2208 yyerror("Menu already defined");
2213 static dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
)
2215 assert
(dlg
!= NULL
);
2216 if
(dlg
->lvc.language
)
2217 yyerror("Language already defined");
2218 dlg
->lvc.language
= l
;
2222 static dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
)
2224 assert
(dlg
!= NULL
);
2225 if
(dlg
->lvc.characts
)
2226 yyerror("Characteristics already defined");
2227 dlg
->lvc.characts
= c
;
2231 static dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
)
2233 assert
(dlg
!= NULL
);
2234 if
(dlg
->lvc.version
)
2235 yyerror("Version already defined");
2236 dlg
->lvc.version
= v
;
2240 /* Accelerator specific functions */
2241 static event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
)
2243 event_t
*ev
= new_event
();
2245 if
((flags
& (WRC_AF_VIRTKEY | WRC_AF_ASCII
)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII
))
2246 yyerror("Cannot use both ASCII and VIRTKEY");
2250 ev
->flags
= flags
& ~WRC_AF_ASCII
;
2257 static event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
)
2260 event_t
*ev
= new_event
();
2262 if
(key
->type
!= str_char
)
2263 yyerror("Key code must be an ascii string");
2265 if
((flags
& WRC_AF_VIRTKEY
) && (!isupper
(key
->str.cstr
[0] & 0xff) && !isdigit
(key
->str.cstr
[0] & 0xff)))
2266 yyerror("VIRTKEY code is not equal to ascii value");
2268 if
(key
->str.cstr
[0] == '^' && (flags
& WRC_AF_CONTROL
) != 0)
2270 yyerror("Cannot use both '^' and CONTROL modifier");
2272 else if
(key
->str.cstr
[0] == '^')
2274 keycode
= toupper
(key
->str.cstr
[1]) - '@';
2276 yyerror("Control-code out of range");
2279 keycode
= key
->str.cstr
[0];
2282 ev
->flags
= flags
& ~WRC_AF_ASCII
;
2289 /* MenuEx specific functions */
2290 static itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
)
2292 itemex_opt_t
*opt
= (itemex_opt_t
*)xmalloc
(sizeof
(itemex_opt_t
));
2296 opt
->helpid
= helpid
;
2300 /* Raw data functions */
2301 static raw_data_t
*load_file
(string_t
*name
)
2305 if
(name
->type
!= str_char
)
2306 yyerror("Filename must be ASCII string");
2308 fp
= open_include
(name
->str.cstr
, 1, NULL
);
2310 yyerror("Cannot open file %s", name
->str.cstr
);
2311 rd
= new_raw_data
();
2312 fseek
(fp
, 0, SEEK_END
);
2313 rd
->size
= ftell
(fp
);
2314 fseek
(fp
, 0, SEEK_SET
);
2315 rd
->data
= (char *)xmalloc
(rd
->size
);
2316 fread
(rd
->data
, rd
->size
, 1, fp
);
2321 static raw_data_t
*int2raw_data
(int i
)
2325 if
((int)((short)i
) != i
)
2326 yywarning
("Integer constant out of 16bit range (%d), truncated to %d\n", i
, (short)i
);
2328 rd
= new_raw_data
();
2329 rd
->size
= sizeof
(short);
2330 rd
->data
= (char *)xmalloc
(rd
->size
);
2333 #ifdef WORDS_BIGENDIAN
2337 rd
->data
[0] = HIBYTE
(i
);
2338 rd
->data
[1] = LOBYTE
(i
);
2341 #ifndef WORDS_BIGENDIAN
2345 rd
->data
[1] = HIBYTE
(i
);
2346 rd
->data
[0] = LOBYTE
(i
);
2352 static raw_data_t
*long2raw_data
(int i
)
2355 rd
= new_raw_data
();
2356 rd
->size
= sizeof
(int);
2357 rd
->data
= (char *)xmalloc
(rd
->size
);
2360 #ifdef WORDS_BIGENDIAN
2364 rd
->data
[0] = HIBYTE
(HIWORD
(i
));
2365 rd
->data
[1] = LOBYTE
(HIWORD
(i
));
2366 rd
->data
[2] = HIBYTE
(LOWORD
(i
));
2367 rd
->data
[3] = LOBYTE
(LOWORD
(i
));
2370 #ifndef WORDS_BIGENDIAN
2374 rd
->data
[3] = HIBYTE
(HIWORD
(i
));
2375 rd
->data
[2] = LOBYTE
(HIWORD
(i
));
2376 rd
->data
[1] = HIBYTE
(LOWORD
(i
));
2377 rd
->data
[0] = LOBYTE
(LOWORD
(i
));
2383 static raw_data_t
*str2raw_data
(string_t
*str
)
2386 rd
= new_raw_data
();
2387 rd
->size
= str
->size
* (str
->type
== str_char ?
1 : 2);
2388 rd
->data
= (char *)xmalloc
(rd
->size
);
2389 if
(str
->type
== str_char
)
2390 memcpy
(rd
->data
, str
->str.cstr
, rd
->size
);
2391 else if
(str
->type
== str_unicode
)
2396 #ifdef WORDS_BIGENDIAN
2400 for
(i
= 0; i
< str
->size
; i
++)
2402 rd
->data
[2*i
+ 0] = HIBYTE
((WORD
)str
->str.wstr
[i
]);
2403 rd
->data
[2*i
+ 1] = LOBYTE
((WORD
)str
->str.wstr
[i
]);
2406 #ifndef WORDS_BIGENDIAN
2410 for
(i
= 0; i
< str
->size
; i
++)
2412 rd
->data
[2*i
+ 1] = HIBYTE
((WORD
)str
->str.wstr
[i
]);
2413 rd
->data
[2*i
+ 0] = LOBYTE
((WORD
)str
->str.wstr
[i
]);
2419 internal_error
(__FILE__
, __LINE__
, "Invalid stringtype");
2423 static raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
)
2425 r1
->data
= xrealloc
(r1
->data
, r1
->size
+ r2
->size
);
2426 memcpy
(r1
->data
+ r1
->size
, r2
->data
, r2
->size
);
2427 r1
->size
+= r2
->size
;
2431 static raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
)
2433 raw_data_t
*t
= int2raw_data
(i
);
2434 merge_raw_data
(r1
, t
);
2440 static raw_data_t
*merge_raw_data_long
(raw_data_t
*r1
, int i
)
2442 raw_data_t
*t
= long2raw_data
(i
);
2443 merge_raw_data
(r1
, t
);
2449 static raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
)
2451 raw_data_t
*t
= str2raw_data
(str
);
2452 merge_raw_data
(r1
, t
);
2458 /* Function the go back in a list to get the head */
2459 static menu_item_t
*get_item_head
(menu_item_t
*p
)
2468 static menuex_item_t
*get_itemex_head
(menuex_item_t
*p
)
2477 static resource_t
*get_resource_head
(resource_t
*p
)
2486 static ver_block_t
*get_ver_block_head
(ver_block_t
*p
)
2495 static ver_value_t
*get_ver_value_head
(ver_value_t
*p
)
2504 static control_t
*get_control_head
(control_t
*p
)
2513 static event_t
*get_event_head
(event_t
*p
)
2522 /* Find a stringtable with given language */
2523 static stringtable_t
*find_stringtable
(lvc_t
*lvc
)
2527 assert
(lvc
!= NULL
);
2530 lvc
->language
= dup_language
(currentlanguage
);
2532 for
(stt
= sttres
; stt
; stt
= stt
->next
)
2534 if
(stt
->lvc.language
->id
== lvc
->language
->id
2535 && stt
->lvc.language
->sub
== lvc
->language
->sub
)
2537 /* Found a table with the same language */
2538 /* The version and characteristics are now handled
2539 * in the generation of the individual stringtables.
2540 * This enables localized analysis.
2541 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2542 || (!stt->lvc.version && lvc->version)
2543 || (stt->lvc.version && !lvc->version))
2544 yywarning("Stringtable's versions are not the same, using first definition");
2546 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2547 || (!stt->lvc.characts && lvc->characts)
2548 || (stt->lvc.characts && !lvc->characts))
2549 yywarning("Stringtable's characteristics are not the same, using first definition");
2557 /* qsort sorting function for string table entries */
2558 #define STE(p) ((stt_entry_t *)(p))
2559 static int sort_stt_entry
(const void *e1
, const void *e2
)
2561 return STE
(e1
)->id
- STE
(e2
)->id
;
2565 static resource_t
*build_stt_resources
(stringtable_t
*stthead
)
2568 stringtable_t
*newstt
;
2570 resource_t
*rsclist
= NULL
;
2571 resource_t
*rsctail
= NULL
;
2576 characts_t
*characts
;
2582 /* For all languages defined */
2583 for
(stt
= stthead
; stt
; stt
= stt
->next
)
2585 assert
(stt
->nentries
> 0);
2587 /* Sort the entries */
2588 if
(stt
->nentries
> 1)
2589 qsort
(stt
->entries
, stt
->nentries
, sizeof
(stt
->entries
[0]), sort_stt_entry
);
2591 for
(i
= 0; i
< stt
->nentries
; )
2593 newstt
= new_stringtable
(&stt
->lvc
);
2594 newstt
->entries
= (stt_entry_t
*)xmalloc
(16 * sizeof
(stt_entry_t
));
2595 newstt
->nentries
= 16;
2596 newstt
->idbase
= stt
->entries
[i
].id
& ~
0xf;
2597 for
(j
= 0; j
< 16 && i
< stt
->nentries
; j
++)
2599 if
(stt
->entries
[i
].id
- newstt
->idbase
== j
)
2601 newstt
->entries
[j
] = stt
->entries
[i
];
2609 /* Check individual memory options and get
2610 * the first characteristics/version
2612 for
(j
= 0; j
< 16; j
++)
2614 if
(!newstt
->entries
[j
].str
)
2616 andsum
&= newstt
->entries
[j
].memopt
;
2617 orsum |
= newstt
->entries
[j
].memopt
;
2619 characts
= newstt
->entries
[j
].characts
;
2621 version
= newstt
->entries
[j
].version
;
2625 warning
("Stringtable's memory options are not equal (idbase: %d)", newstt
->idbase
);
2627 /* Check version and characteristics */
2628 for
(j
= 0; j
< 16; j
++)
2631 && newstt
->entries
[j
].characts
2632 && *newstt
->entries
[j
].characts
!= *characts
)
2633 warning
("Stringtable's characteristics are not the same (idbase: %d)", newstt
->idbase
);
2635 && newstt
->entries
[j
].version
2636 && *newstt
->entries
[j
].version
!= *version
)
2637 warning
("Stringtable's versions are not the same (idbase: %d)", newstt
->idbase
);
2639 rsc
= new_resource
(res_stt
, newstt
, newstt
->memopt
, newstt
->lvc.language
);
2640 rsc
->name
= new_name_id
();
2641 rsc
->name
->type
= name_ord
;
2642 rsc
->name
->name.i_name
= (newstt
->idbase
>> 4) + 1;
2643 rsc
->memopt
= andsum
; /* Set to least common denominator */
2644 newstt
->memopt
= andsum
;
2645 newstt
->lvc.characts
= characts
;
2646 newstt
->lvc.version
= version
;
2654 rsctail
->next
= rsc
;
2655 rsc
->prev
= rsctail
;
2664 static toolbar_item_t
*ins_tlbr_button
(toolbar_item_t
*prev
, toolbar_item_t
*idrec
)
2673 static toolbar_item_t
*get_tlbr_buttons_head
(toolbar_item_t
*p
, int *nitems
)
2692 static string_t
*make_filename
(string_t
*str
)
2696 if
(str
->type
!= str_char
)
2697 yyerror("Cannot handle UNICODE filenames");
2699 /* Remove escaped backslash and convert to forward */
2700 cptr
= str
->str.cstr
;
2701 for
(cptr
= str
->str.cstr
; (cptr
= strchr
(cptr
, '\\')) != NULL
; cptr
++)
2705 memmove
(cptr
, cptr
+1, strlen
(cptr
));
2711 /* Convert to lower case. Seems to be reasonable to do */
2712 for
(cptr
= str
->str.cstr
; !leave_case
&& *cptr
; cptr
++)
2714 *cptr
= tolower
(*cptr
);
2720 * Process all resources to extract fonts and build
2721 * a fontdir resource.
2723 * Note: MS' resource compiler (build 1472) does not
2724 * handle font resources with different languages.
2725 * The fontdir is generated in the last active language
2726 * and font identifiers must be unique across the entire
2728 * This is not logical considering the localization
2729 * constraints of all other resource types. MS has,
2730 * most probably, never testet localized fonts. However,
2731 * using fontresources is rare, so it might not occur
2732 * in normal applications.
2733 * Wine does require better localization because a lot
2734 * of languages are coded into the same executable.
2735 * Therefore, I will generate fontdirs for *each*
2736 * localized set of fonts.
2738 static resource_t
*build_fontdir
(resource_t
**fnt
, int nfnt
)
2740 static int once
= 0;
2743 warning
("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt
, nfnt
);
2749 static resource_t
*build_fontdirs
(resource_t
*tail
)
2752 resource_t
*lst
= NULL
;
2753 resource_t
**fnt
= NULL
; /* List of all fonts */
2755 resource_t
**fnd
= NULL
; /* List of all fontdirs */
2757 resource_t
**lanfnt
= NULL
;
2764 nid.type
= name_str
;
2765 nid.name.s_name
= &str
;
2766 str.type
= str_char
;
2767 str.str.cstr
= "FONTDIR";
2770 /* Extract all fonts and fontdirs */
2771 for
(rsc
= tail
; rsc
; rsc
= rsc
->prev
)
2773 if
(rsc
->type
== res_fnt
)
2776 fnt
= xrealloc
(fnt
, nfnt
* sizeof
(*fnt
));
2779 else if
(rsc
->type
== res_fntdir
)
2782 fnd
= xrealloc
(fnd
, nfnd
* sizeof
(*fnd
));
2787 /* Verify the name of the present fontdirs */
2788 for
(i
= 0; i
< nfnd
; i
++)
2790 if
(compare_name_id
(&nid
, fnd
[i
]->name
))
2792 warning
("User supplied FONTDIR entry has an invalid name '%s', ignored",
2793 get_nameid_str
(fnd
[i
]->name
));
2802 warning
("Found %d FONTDIR entries without any fonts present", nfnd
);
2807 lanfnt
= xmalloc
(nfnt
* sizeof
(*lanfnt
));
2809 /* Get all fonts covered by fontdirs */
2810 for
(i
= 0; i
< nfnd
; i
++)
2818 for
(j
= 0; j
< nfnt
; j
++)
2822 if
(fnt
[j
]->lan
->id
== fnd
[i
]->lan
->id
&& fnt
[j
]->lan
->sub
== fnd
[i
]->lan
->sub
)
2824 lanfnt
[nlanfnt
] = fnt
[j
];
2830 cnt
= *(WORD
*)fnd
[i
]->res.fnd
->data
->data
;
2833 else if
(nlanfnt
== BYTESWAP_WORD
(cnt
))
2836 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2837 fnd
[i
]->lan
->id
, fnd
[i
]->lan
->sub
, cnt
, nlanfnt
);
2838 #ifdef WORDS_BIGENDIAN
2839 if
((byteorder
== WRC_BO_LITTLE
&& !isswapped
) ||
(byteorder
!= WRC_BO_LITTLE
&& isswapped
))
2841 if
((byteorder
== WRC_BO_BIG
&& !isswapped
) ||
(byteorder
!= WRC_BO_BIG
&& isswapped
))
2844 internal_error
(__FILE__
, __LINE__
, "User supplied FONTDIR needs byteswapping");
2848 /* We now have fonts left where we need to make a fontdir resource */
2849 for
(i
= fntleft
= 0; i
< nfnt
; i
++)
2856 /* Get fonts of same language in lanfnt[] */
2857 for
(i
= nlanfnt
= 0; i
< nfnt
; i
++)
2864 lanfnt
[nlanfnt
] = fnt
[i
];
2869 else if
(fnt
[i
]->lan
->id
== lanfnt
[0]->lan
->id
&& fnt
[i
]->lan
->sub
== lanfnt
[0]->lan
->sub
)
2873 /* and build a fontdir */
2874 rsc
= build_fontdir
(lanfnt
, nlanfnt
);
2896 * This gets invoked to determine whether the next resource
2897 * is to be of a standard-type (e.g. bitmaps etc.), or should
2898 * be a user-type resource. This function is required because
2899 * there is the _possibility_ of a lookahead token in the
2900 * parser, which is generated from the "expr" state in the
2903 * The general resource format is:
2904 * <identifier> <type> <flags> <resourcebody>
2906 * The <identifier> can either be tIDENT or "expr". The latter
2907 * will always generate a lookahead, which is the <type> of the
2908 * resource to parse. Otherwise, we need to get a new token from
2909 * the scanner to determine the next step.
2911 * The problem arrises when <type> is numerical. This case should
2912 * map onto default resource-types and be parsed as such instead
2913 * of being mapped onto user-type resources.
2915 * The trick lies in the fact that yacc (bison) doesn't care about
2916 * intermediate changes of the lookahead while reducing a rule. We
2917 * simply replace the lookahead with a token that will result in
2918 * a shift to the appropriate rule for the specific resource-type.
2920 static int rsrcid_to_token
(int lookahead
)
2925 /* Get a token if we don't have one yet */
2926 if
(lookahead
== YYEMPTY
)
2929 /* Only numbers are possibly interesting */
2959 case WRC_RT_FONTDIR
:
2967 case WRC_RT_MESSAGETABLE
:
2968 type
= "MESSAGETABLE";
2969 token
= tMESSAGETABLE
;
2971 case WRC_RT_DLGINIT
:
2975 case WRC_RT_ACCELERATOR
:
2976 type
= "ACCELERATOR";
2977 token
= tACCELERATORS
;
2987 case WRC_RT_VERSION
:
2989 token
= tVERSIONINFO
;
2991 case WRC_RT_TOOLBAR
:
2997 type
= "STRINGTABLE";
3000 case WRC_RT_ANICURSOR
:
3001 case WRC_RT_ANIICON
:
3002 case WRC_RT_GROUP_CURSOR
:
3003 case WRC_RT_GROUP_ICON
:
3004 yywarning
("Usertype uses reserved type-ID %d, which is auto-generated", yylval.num
);
3007 case WRC_RT_DLGINCLUDE
:
3008 case WRC_RT_PLUGPLAY
:
3011 yywarning
("Usertype uses reserved type-ID %d, which is not supported by wrc", yylval.num
);
3019 yywarning
("Usertype uses reserved type-ID %d, which is used by %s", yylval.num
, type
);