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"
131 /* Berkeley yacc (byacc) doesn't seem to know about these */
132 /* Some *BSD supplied versions do define these though */
134 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
137 # define YYLEX yylex()
140 #elif defined(YYBISON)
141 /* Bison was used for original development */
142 /* #define YYEMPTY -2 */
143 /* #define YYLEX yylex() */
146 /* No yacc we know yet */
147 # if !defined(YYEMPTY) || !defined(YYLEX)
148 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
149 # elif defined(__GNUC__) /* gcc defines the #warning directive */
150 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
151 /* #else we just take a chance that it works... */
155 int want_nl
= 0; /* Signal flex that we need the next newline */
156 int want_id
= 0; /* Signal flex that we need the next identifier */
157 stringtable_t
*tagstt
; /* Stringtable tag.
158 * It is set while parsing a stringtable to one of
159 * the stringtables in the sttres list or a new one
160 * if the language was not parsed before.
162 stringtable_t
*sttres
; /* Stringtable resources. This holds the list of
163 * stringtables with different lanuages
165 static int dont_want_id
= 0; /* See language parsing for details */
167 /* Set to the current options of the currently scanning stringtable */
168 static int *tagstt_memopt
;
169 static characts_t
*tagstt_characts
;
170 static version_t
*tagstt_version
;
172 static const char riff
[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
174 /* Prototypes of here defined functions */
175 static event_t
*get_event_head
(event_t
*p
);
176 static control_t
*get_control_head
(control_t
*p
);
177 static ver_value_t
*get_ver_value_head
(ver_value_t
*p
);
178 static ver_block_t
*get_ver_block_head
(ver_block_t
*p
);
179 static resource_t
*get_resource_head
(resource_t
*p
);
180 static menuex_item_t
*get_itemex_head
(menuex_item_t
*p
);
181 static menu_item_t
*get_item_head
(menu_item_t
*p
);
182 static raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
);
183 static raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
);
184 static raw_data_t
*merge_raw_data_long
(raw_data_t
*r1
, int i
);
185 static raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
);
186 static raw_data_t
*str2raw_data
(string_t
*str
);
187 static raw_data_t
*int2raw_data
(int i
);
188 static raw_data_t
*long2raw_data
(int i
);
189 static raw_data_t
*load_file
(string_t
*name
);
190 static itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
);
191 static event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
);
192 static event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
);
193 static dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
);
194 static dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
);
195 static dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
);
196 static dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
);
197 static dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
);
198 static dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
);
199 static dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
);
200 static dialogex_t
*dialogex_exstyle
(style_t
*st
, dialogex_t
*dlg
);
201 static dialogex_t
*dialogex_style
(style_t
*st
, dialogex_t
*dlg
);
202 static name_id_t
*convert_ctlclass
(name_id_t
*cls
);
203 static control_t
*ins_ctrl
(int type
, int special_style
, control_t
*ctrl
, control_t
*prev
);
204 static dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
);
205 static dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
);
206 static dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
);
207 static dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
);
208 static dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
);
209 static dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
);
210 static dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
);
211 static dialog_t
*dialog_exstyle
(style_t
* st
, dialog_t
*dlg
);
212 static dialog_t
*dialog_style
(style_t
* st
, dialog_t
*dlg
);
213 static resource_t
*build_stt_resources
(stringtable_t
*stthead
);
214 static stringtable_t
*find_stringtable
(lvc_t
*lvc
);
215 static toolbar_item_t
*ins_tlbr_button
(toolbar_item_t
*prev
, toolbar_item_t
*idrec
);
216 static toolbar_item_t
*get_tlbr_buttons_head
(toolbar_item_t
*p
, int *nitems
);
217 static string_t
*make_filename
(string_t
*s
);
218 static resource_t
*build_fontdirs
(resource_t
*tail
);
219 static resource_t
*build_fontdir
(resource_t
**fnt
, int nfnt
);
220 static int rsrcid_to_token
(int lookahead
);
251 menuex_item_t
*menexitm
;
259 toolbar_item_t
*tlbarItems
;
261 style_pair_t
*styles
;
266 %token tTYPEDEF tEXTERN tSTRUCT tENUM tCPPCLASS tINLINE tSTATIC tNL
267 %token
<num
> tNUMBER tLNUMBER
268 %token
<str
> tSTRING tIDENT tFILENAME
269 %token
<raw
> tRAWDATA
270 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
271 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
272 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
273 %token tPUSHBUTTON tRADIOBUTTON tSTATE3
/* PUSHBOX */
274 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
275 %token tCONTROL tEDITTEXT
276 %token tRTEXT tCTEXT tLTEXT
278 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
279 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
280 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
281 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
282 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
284 %token tSTRING tIDENT tRAWDATA
285 %token tTOOLBAR tBUTTON
296 %type
<res
> resource_file resource resources resource_definition
297 %type
<stt
> stringtable strings
300 %type
<acc
> accelerators
303 %type
<ani
> cursor icon
304 %type
<dlg
> dialog dlg_attributes
305 %type
<ctl
> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
307 %type
<dlgex
> dialogex dlgex_attribs
308 %type
<ctl
> exctrls gen_exctrl lab_exctrl exctrl_desc
310 %type
<raw
> raw_data raw_elements opt_data file_raw
311 %type
<veri
> versioninfo fix_version
312 %type
<verw
> ver_words
313 %type
<blk
> ver_blocks ver_block
314 %type
<val
> ver_values ver_value
316 %type
<menitm
> item_definitions menu_body
318 %type
<menexitm
> itemex_definitions menuex_body
319 %type
<exopt
> itemex_p_options itemex_options
320 %type
<msg
> messagetable
322 %type
<num
> item_options
323 %type
<nid
> nameid nameid_s ctlclass usertype
324 %type
<num
> acc_opt acc accs
325 %type
<iptr
> loadmemopts lamo lama
326 %type
<fntid
> opt_font opt_exfont opt_expr
328 %type
<lan
> opt_language
329 %type
<chars
> opt_characts
330 %type
<ver
> opt_version
333 %type
<tlbar
> toolbar
334 %type
<tlbarItems
> toolbar_items
335 %type
<dginit
> dlginit
336 %type
<styles
> optional_style_pair
338 %type
<style
> optional_style
347 /* First add stringtables to the resource-list */
348 rsc
= build_stt_resources
(sttres
);
349 /* 'build_stt_resources' returns a head and $1 is a tail */
358 /* Find the tail again */
359 while
($1 && $1->next
)
361 /* Now add any fontdirecory */
362 rsc
= build_fontdirs
($1);
363 /* 'build_fontdir' returns a head and $1 is a tail */
372 /* Final statement before were done */
373 resource_top
= get_resource_head
($1);
377 /* Resources are put into a linked list */
379 : /* Empty */ { $$
= NULL
; want_id
= 1; }
380 | resources resource
{
383 resource_t
*tail
= $2;
384 resource_t
*head
= $2;
393 /* Check for duplicate identifiers */
396 resource_t
*rsc
= $1;
399 if
(rsc
->type
== head
->type
400 && rsc
->lan
->id
== head
->lan
->id
401 && rsc
->lan
->sub
== head
->lan
->sub
402 && !compare_name_id
(rsc
->name
, head
->name
))
404 yyerror("Duplicate resource name '%s'", get_nameid_str
(rsc
->name
));
413 resource_t
*tail
= $1;
421 if
(!dont_want_id
) /* See comments in language parsing below */
425 | resources cjunk
{ $$
= $1; want_id
= 1; }
430 cjunk
: tTYPEDEF
{ strip_til_semicolon
(); }
431 | tSTRUCT
{ strip_til_semicolon
(); }
432 | tEXTERN
{ strip_til_semicolon
(); }
433 | tENUM
{ strip_til_semicolon
(); }
434 | tCPPCLASS
{ strip_til_semicolon
(); }
435 | tSTATIC
{ strip_til_semicolon
(); }
436 | tINLINE
{ internal_error
(__FILE__
, __LINE__
, "Don't yet know how to strip inline functions\n"); }
437 /* | tIDENT tIDENT { strip_til_semicolon(); } */
438 /* | tIDENT tIDENT '(' { strip_til_parenthesis(); } See comments in 'resource' below */
439 /* | tIDENT '(' { strip_til_parenthesis(); } */
440 | tIDENT
'*' { strip_til_semicolon
(); }
442 * This newline rule will never get reduced because we never
443 * get the tNL token, unless we explicitely set the 'want_nl'
444 * flag, which we don't.
445 * The *ONLY* reason for this to be here is because Berkeley
446 * yacc (byacc), at least version 1.9, has a bug.
447 * (identified in the generated parser on the second
449 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
451 * This extra rule fixes it.
452 * The problem is that the expression handling rule "expr: xpr"
453 * is not reduced on non-terminal tokens, defined above in the
454 * %token declarations. Token tNL is the only non-terminal that
455 * can occur. The error becomes visible in the language parsing
456 * rule below, which looks at the look-ahead token and tests it
457 * for tNL. However, byacc already generates an error upon reading
458 * the token instead of keeping it as a lookahead. The reason
459 * lies in the lack of a $default transition in the "expr : xpr . "
460 * state (currently state 25). It is probably ommitted because tNL
461 * is a non-terminal and the state contains 2 s/r conflicts. The
462 * state enumerates all possible transitions instead of using a
463 * $default transition.
464 * All in all, it is a bug in byacc. (period)
468 /* Parse top level resource definitions etc. */
470 : expr usrcvt resource_definition
{
474 if
($1 > 65535 ||
$1 < -32768)
475 yyerror("Resource's ID out of range (%d)", $1);
476 $$
->name
= new_name_id
();
477 $$
->name
->type
= name_ord
;
478 $$
->name
->name.i_name
= $1;
479 chat
("Got %s (%d)", get_typename
($3), $$
->name
->name.i_name
);
482 | tIDENT usrcvt resource_definition
{
486 $$
->name
= new_name_id
();
487 $$
->name
->type
= name_str
;
488 $$
->name
->name.s_name
= $1;
489 chat
("Got %s (%s)", get_typename
($3), $$
->name
->name.s_name
->str.cstr
);
492 | tIDENT usrcvt tIDENT
'(' { /* cjunk */ strip_til_parenthesis
(); $$
= NULL
; }
493 /* The above rule is inserted here with explicit tIDENT
494 * references to avoid a nasty LALR(2) problem when
495 * considering the 'cjunk' rules with respect to the usertype
497 * A usertype resource can have two leading identifiers before
498 * it qualifies as shift into usertype rules. However, the
499 * cjunk scanner also has a rule of two leading identifiers.
500 * The problem occurs because the second identifier is at the
501 * second lookahead (hence LALR(2)) seen from the recursion
503 * Thus, the scanner will pick *one* of the rules in preference
504 * of the other (in this case it was 'cjunk') and generates a
505 * syntax error if the trailing context wasn't seen. The
506 * correct action would have been to rollback the stack and
507 * decent into the 'userres' rule, but this cannot be done
508 * because yacc only parses LALR(1).
509 * The problem is prevented from happening by making the decent
510 * into the cjunk-scanning obsolete and explicitly force the
511 * scanner to require no more than 1 lookahead.
514 /* Don't do anything, stringtables are converted to
515 * resource_t structures when we are finished parsing and
516 * the final rule of the parser is reduced (see above)
519 chat
("Got STRINGTABLE");
521 | tLANGUAGE
{want_nl
= 1; } expr
',' expr
{
522 /* We *NEED* the newline to delimit the expression.
523 * Otherwise, we would not be able to set the next
524 * want_id anymore because of the token-lookahead.
526 * However, we can test the lookahead-token for
527 * being "non-expression" type, in which case we
528 * continue. Fortunately, tNL is the only token that
529 * will break expression parsing and is implicitely
530 * void, so we just remove it. This scheme makes it
531 * possible to do some (not all) fancy preprocessor
533 * BTW, we also need to make sure that the next
534 * reduction of 'resources' above will *not* set
535 * want_id because we already have a lookahead that
538 if
(yychar != YYEMPTY
&& yychar != tNL
)
542 yychar = YYEMPTY
; /* Could use 'yyclearin', but we already need the*/
543 /* direct access to yychar in rule 'usrcvt' below. */
544 else if
(yychar == tIDENT
)
545 yywarning
("LANGUAGE statement not delimited with newline; next identifier might be wrong");
547 want_nl
= 0; /* We don't want it anymore if we didn't get it */
550 yywarning
("LANGUAGE not supported in 16-bit mode");
552 free
(currentlanguage
);
553 currentlanguage
= new_language
($3, $5);
555 chat
("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
560 * Remapping of numerical resource types
561 * (see also comment of called function below)
563 usrcvt
: /* Empty */ { yychar = rsrcid_to_token
(yychar); }
567 * Get a valid name/id
570 if
($1 > 65535 ||
$1 < -32768)
571 yyerror("Resource's ID out of range (%d)", $1);
574 $$
->name.i_name
= $1;
579 $$
->name.s_name
= $1;
584 * Extra string recognition for CLASS statement in dialogs
586 nameid_s: nameid
{ $$
= $1; }
590 $$
->name.s_name
= $1;
594 /* get the value for a single resource*/
596 : accelerators
{ $$
= new_resource
(res_acc
, $1, $1->memopt
, $1->lvc.language
); }
597 | bitmap
{ $$
= new_resource
(res_bmp
, $1, $1->memopt
, $1->data
->lvc.language
); }
600 if
($1->type
== res_anicur
)
602 $$
= rsc
= new_resource
(res_anicur
, $1->u.ani
, $1->u.ani
->memopt
, $1->u.ani
->data
->lvc.language
);
604 else if
($1->type
== res_curg
)
607 $$
= rsc
= new_resource
(res_curg
, $1->u.curg
, $1->u.curg
->memopt
, $1->u.curg
->lvc.language
);
608 for
(cur
= $1->u.curg
->cursorlist
; cur
; cur
= cur
->next
)
610 rsc
->prev
= new_resource
(res_cur
, cur
, $1->u.curg
->memopt
, $1->u.curg
->lvc.language
);
611 rsc
->prev
->next
= rsc
;
613 rsc
->name
= new_name_id
();
614 rsc
->name
->type
= name_ord
;
615 rsc
->name
->name.i_name
= cur
->id
;
619 internal_error
(__FILE__
, __LINE__
, "Invalid top-level type %d in cursor resource", $1->type
);
622 | dialog
{ $$
= new_resource
(res_dlg
, $1, $1->memopt
, $1->lvc.language
); }
625 $$
= new_resource
(res_dlgex
, $1, $1->memopt
, $1->lvc.language
);
629 | dlginit
{ $$
= new_resource
(res_dlginit
, $1, $1->memopt
, $1->data
->lvc.language
); }
630 | font
{ $$
= new_resource
(res_fnt
, $1, $1->memopt
, $1->data
->lvc.language
); }
631 | fontdir
{ $$
= new_resource
(res_fntdir
, $1, $1->memopt
, $1->data
->lvc.language
); }
634 if
($1->type
== res_aniico
)
636 $$
= rsc
= new_resource
(res_aniico
, $1->u.ani
, $1->u.ani
->memopt
, $1->u.ani
->data
->lvc.language
);
638 else if
($1->type
== res_icog
)
641 $$
= rsc
= new_resource
(res_icog
, $1->u.icog
, $1->u.icog
->memopt
, $1->u.icog
->lvc.language
);
642 for
(ico
= $1->u.icog
->iconlist
; ico
; ico
= ico
->next
)
644 rsc
->prev
= new_resource
(res_ico
, ico
, $1->u.icog
->memopt
, $1->u.icog
->lvc.language
);
645 rsc
->prev
->next
= rsc
;
647 rsc
->name
= new_name_id
();
648 rsc
->name
->type
= name_ord
;
649 rsc
->name
->name.i_name
= ico
->id
;
653 internal_error
(__FILE__
, __LINE__
, "Invalid top-level type %d in icon resource", $1->type
);
656 | menu
{ $$
= new_resource
(res_men
, $1, $1->memopt
, $1->lvc.language
); }
659 $$
= new_resource
(res_menex
, $1, $1->memopt
, $1->lvc.language
);
663 | messagetable
{ $$
= new_resource
(res_msg
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, dup_language
(currentlanguage
)); }
664 | rcdata
{ $$
= new_resource
(res_rdt
, $1, $1->memopt
, $1->data
->lvc.language
); }
665 | toolbar
{ $$
= new_resource
(res_toolbar
, $1, $1->memopt
, $1->lvc.language
); }
666 | userres
{ $$
= new_resource
(res_usr
, $1, $1->memopt
, $1->data
->lvc.language
); }
667 | versioninfo
{ $$
= new_resource
(res_ver
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, $1->lvc.language
); }
671 filename: tFILENAME
{ $$
= make_filename
($1); }
672 | tIDENT
{ $$
= make_filename
($1); }
673 | tSTRING
{ $$
= make_filename
($1); }
676 /* ------------------------------ Bitmap ------------------------------ */
677 bitmap
: tBITMAP loadmemopts file_raw
{ $$
= new_bitmap
($3, $2); }
680 /* ------------------------------ Cursor ------------------------------ */
681 cursor
: tCURSOR loadmemopts file_raw
{
683 if
($3->size
> 4 && !memcmp
($3->data
, riff
, sizeof
(riff
)))
685 $$
->type
= res_anicur
;
686 $$
->u.ani
= new_ani_curico
(res_anicur
, $3, $2);
691 $$
->u.curg
= new_cursor_group
($3, $2);
696 /* ------------------------------ Icon ------------------------------ */
697 icon
: tICON loadmemopts file_raw
{
699 if
($3->size
> 4 && !memcmp
($3->data
, riff
, sizeof
(riff
)))
701 $$
->type
= res_aniico
;
702 $$
->u.ani
= new_ani_curico
(res_aniico
, $3, $2);
707 $$
->u.icog
= new_icon_group
($3, $2);
712 /* ------------------------------ Font ------------------------------ */
714 * The reading of raw_data for fonts is a Borland BRC
715 * extension. MS generates an error. However, it is
716 * most logical to support this, considering how wine
717 * enters things in CVS (ascii).
719 font
: tFONT loadmemopts file_raw
{ $$
= new_font
($3, $2); }
723 * The fontdir is a Borland BRC extension which only
724 * reads the data as 'raw_data' from the file.
725 * I don't know whether it is interpreted.
726 * The fontdir is generated if it was not present and
727 * fonts are defined in the source.
729 fontdir
: tFONTDIR loadmemopts file_raw
{ $$
= new_fontdir
($3, $2); }
732 /* ------------------------------ MessageTable ------------------------------ */
733 /* It might be interesting to implement the MS Message compiler here as well
734 * to get everything in one source. Might be a future project.
737 : tMESSAGETABLE loadmemopts file_raw
{
739 yywarning
("MESSAGETABLE not supported in 16-bit mode");
740 $$
= new_messagetable
($3, $2);
744 /* ------------------------------ RCData ------------------------------ */
745 rcdata
: tRCDATA loadmemopts file_raw
{ $$
= new_rcdata
($3, $2); }
748 /* ------------------------------ DLGINIT ------------------------------ */
749 dlginit
: tDLGINIT loadmemopts file_raw
{ $$
= new_dlginit
($3, $2); }
752 /* ------------------------------ UserType ------------------------------ */
753 userres
: usertype loadmemopts file_raw
{
754 #ifdef WORDS_BIGENDIAN
755 if
(pedantic
&& byteorder
!= WRC_BO_LITTLE
)
757 if
(pedantic
&& byteorder
== WRC_BO_BIG
)
759 yywarning
("Byteordering is not little-endian and type cannot be interpreted");
760 $$
= new_user
($1, $3, $2);
767 $$
->name.i_name
= $1;
772 $$
->name.s_name
= $1;
776 /* ------------------------------ Accelerator ------------------------------ */
778 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND
{
779 $$
= new_accelerator
();
787 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE
;
790 yyerror("Accelerator table must have at least one entry");
791 $$
->events
= get_event_head
($5);
797 if
(!$$
->lvc.language
)
798 $$
->lvc.language
= dup_language
(currentlanguage
);
802 events
: /* Empty */ { $$
=NULL
; }
803 | events tSTRING
',' expr acc_opt
{ $$
=add_string_event
($2, $4, $5, $1); }
804 | events expr
',' expr acc_opt
{ $$
=add_event
($2, $4, $5, $1); }
808 * The empty rule generates a s/r conflict because of {bi,u}nary expr
809 * on - and +. It cannot be solved in any way because it is the same as
810 * the if/then/else problem (LALR(1) problem). The conflict is moved
811 * away by forcing it to be in the expression handling below.
813 acc_opt
: /* Empty */ { $$
= 0; }
814 |
',' accs
{ $$
= $2; }
817 accs
: acc
{ $$
= $1; }
818 | accs
',' acc
{ $$
= $1 |
$3; }
821 acc
: tNOINVERT
{ $$
= WRC_AF_NOINVERT
; }
822 | tSHIFT
{ $$
= WRC_AF_SHIFT
; }
823 | tCONTROL
{ $$
= WRC_AF_CONTROL
; }
824 | tALT
{ $$
= WRC_AF_ALT
; }
825 | tASCII
{ $$
= WRC_AF_ASCII
; }
826 | tVIRTKEY
{ $$
= WRC_AF_VIRTKEY
; }
829 /* ------------------------------ Dialog ------------------------------ */
830 /* FIXME: Support EXSTYLE in the dialog line itself */
831 dialog
: tDIALOG loadmemopts expr
',' expr
',' expr
',' expr dlg_attributes
839 $10->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
844 $10->controls
= get_control_head
($12);
848 $$
->style
->or_mask
= WS_POPUP
;
852 $$
->style
->or_mask |
= WS_CAPTION
;
854 $$
->style
->or_mask |
= DS_SETFONT
;
856 $$
->style
->or_mask
&= ~
($$
->style
->and_mask
);
857 $$
->style
->and_mask
= 0;
859 if
(!$$
->lvc.language
)
860 $$
->lvc.language
= dup_language
(currentlanguage
);
865 : /* Empty */ { $$
=new_dialog
(); }
866 | dlg_attributes tSTYLE style
{ $$
=dialog_style
($3,$1); }
867 | dlg_attributes tEXSTYLE style
{ $$
=dialog_exstyle
($3,$1); }
868 | dlg_attributes tCAPTION tSTRING
{ $$
=dialog_caption
($3,$1); }
869 | dlg_attributes opt_font
{ $$
=dialog_font
($2,$1); }
870 | dlg_attributes tCLASS nameid_s
{ $$
=dialog_class
($3,$1); }
871 | dlg_attributes tCPPCLASS nameid_s
{ $$
=dialog_class
($3,$1); }
872 | dlg_attributes tMENU nameid
{ $$
=dialog_menu
($3,$1); }
873 | dlg_attributes opt_language
{ $$
=dialog_language
($2,$1); }
874 | dlg_attributes opt_characts
{ $$
=dialog_characteristics
($2,$1); }
875 | dlg_attributes opt_version
{ $$
=dialog_version
($2,$1); }
878 ctrls
: /* Empty */ { $$
= NULL
; }
879 | ctrls tCONTROL gen_ctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
880 | ctrls tEDITTEXT ctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
881 | ctrls tLISTBOX ctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
882 | ctrls tCOMBOBOX ctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
883 | ctrls tSCROLLBAR ctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
884 | ctrls tCHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
885 | ctrls tDEFPUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
886 | ctrls tGROUPBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
887 | ctrls tPUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
888 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
889 | ctrls tRADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
890 | ctrls tAUTO3STATE lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
891 | ctrls tSTATE3 lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
892 | ctrls tAUTOCHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
893 | ctrls tAUTORADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
894 | ctrls tLTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
895 | ctrls tCTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
896 | ctrls tRTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
897 /* special treatment for icons, as the extent is optional */
898 | ctrls tICON nameid_s opt_comma expr
',' expr
',' expr iconinfo
{
903 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
908 : tSTRING opt_comma expr
',' expr
',' expr
',' expr
',' expr optional_style
{
910 $$
->title
= new_name_id
();
911 $$
->title
->type
= name_str
;
912 $$
->title
->name.s_name
= $1;
927 : expr
',' expr
',' expr
',' expr
',' expr optional_style
{
942 iconinfo: /* Empty */
943 { $$
= new_control
(); }
945 |
',' expr
',' expr
{
950 |
',' expr
',' expr
',' style
{
957 |
',' expr
',' expr
',' style
',' style
{
964 $$
->gotexstyle
= TRUE
;
968 gen_ctrl: nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr
',' style
{
972 $$
->ctlclass
= convert_ctlclass
($5);
980 $$
->gotexstyle
= TRUE
;
982 | nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr
{
986 $$
->ctlclass
= convert_ctlclass
($5);
997 : tFONT expr
',' tSTRING
{ $$
= new_font_id
($2, $4, 0, 0); }
1000 /* ------------------------------ style flags ------------------------------ */
1001 optional_style
/* Abbused once to get optional ExStyle */
1002 : /* Empty */ { $$
= NULL
; }
1003 |
',' style
{ $$
= $2; }
1007 : /* Empty */ { $$
= NULL
; }
1008 |
',' style
{ $$
= new_style_pair
($2, 0); }
1009 |
',' style
',' style
{ $$
= new_style_pair
($2, $4); }
1013 : style
'|' style
{ $$
= new_style
($1->or_mask |
$3->or_mask
, $1->and_mask |
$3->and_mask
); free
($1); free
($3);}
1014 |
'(' style
')' { $$
= $2; }
1015 | any_num
{ $$
= new_style
($1, 0); }
1016 | tNOT any_num
{ $$
= new_style
(0, $2); }
1022 $$
->type
= name_ord
;
1023 $$
->name.i_name
= $1;
1027 $$
->type
= name_str
;
1028 $$
->name.s_name
= $1;
1032 /* ------------------------------ DialogEx ------------------------------ */
1033 dialogex: tDIALOGEX loadmemopts expr
',' expr
',' expr
',' expr helpid dlgex_attribs
1034 tBEGIN exctrls tEND
{
1036 yywarning
("DIALOGEX not supported in 16-bit mode");
1039 $11->memopt
= *($2);
1043 $11->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1050 $11->helpid
= *($10);
1051 $11->gothelpid
= TRUE
;
1054 $11->controls
= get_control_head
($13);
1057 assert
($$
->style
!= NULL
);
1060 $$
->style
->or_mask
= WS_POPUP
;
1061 $$
->gotstyle
= TRUE
;
1064 $$
->style
->or_mask |
= WS_CAPTION
;
1066 $$
->style
->or_mask |
= DS_SETFONT
;
1068 $$
->style
->or_mask
&= ~
($$
->style
->and_mask
);
1069 $$
->style
->and_mask
= 0;
1071 if
(!$$
->lvc.language
)
1072 $$
->lvc.language
= dup_language
(currentlanguage
);
1077 : /* Empty */ { $$
=new_dialogex
(); }
1078 | dlgex_attribs tSTYLE style
{ $$
=dialogex_style
($3,$1); }
1079 | dlgex_attribs tEXSTYLE style
{ $$
=dialogex_exstyle
($3,$1); }
1080 | dlgex_attribs tCAPTION tSTRING
{ $$
=dialogex_caption
($3,$1); }
1081 | dlgex_attribs opt_font
{ $$
=dialogex_font
($2,$1); }
1082 | dlgex_attribs opt_exfont
{ $$
=dialogex_font
($2,$1); }
1083 | dlgex_attribs tCLASS nameid_s
{ $$
=dialogex_class
($3,$1); }
1084 | dlgex_attribs tCPPCLASS nameid_s
{ $$
=dialogex_class
($3,$1); }
1085 | dlgex_attribs tMENU nameid
{ $$
=dialogex_menu
($3,$1); }
1086 | dlgex_attribs opt_language
{ $$
=dialogex_language
($2,$1); }
1087 | dlgex_attribs opt_characts
{ $$
=dialogex_characteristics
($2,$1); }
1088 | dlgex_attribs opt_version
{ $$
=dialogex_version
($2,$1); }
1091 exctrls
: /* Empty */ { $$
= NULL
; }
1092 | exctrls tCONTROL gen_exctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
1093 | exctrls tEDITTEXT exctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
1094 | exctrls tLISTBOX exctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
1095 | exctrls tCOMBOBOX exctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
1096 | exctrls tSCROLLBAR exctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
1097 | exctrls tCHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
1098 | exctrls tDEFPUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
1099 | exctrls tGROUPBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
1100 | exctrls tPUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
1101 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1102 | exctrls tRADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
1103 | exctrls tAUTO3STATE lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
1104 | exctrls tSTATE3 lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
1105 | exctrls tAUTOCHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
1106 | exctrls tAUTORADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
1107 | exctrls tLTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
1108 | exctrls tCTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
1109 | exctrls tRTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
1110 /* special treatment for icons, as the extent is optional */
1111 | exctrls tICON nameid_s opt_comma expr
',' expr
',' expr iconinfo
{
1116 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
1121 : nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
','
1122 expr
',' style helpid opt_data
{
1126 $$
->ctlclass
= convert_ctlclass
($5);
1128 $$
->gotstyle
= TRUE
;
1136 $$
->gotexstyle
= TRUE
;
1140 $$
->helpid
= *($18);
1141 $$
->gothelpid
= TRUE
;
1146 | nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr opt_data
{
1151 $$
->gotstyle
= TRUE
;
1152 $$
->ctlclass
= convert_ctlclass
($5);
1162 : tSTRING opt_comma expr
',' expr
',' expr
',' expr
',' expr optional_style_pair opt_data
{
1164 $$
->title
= new_name_id
();
1165 $$
->title
->type
= name_str
;
1166 $$
->title
->name.s_name
= $1;
1174 $$
->style
= $12->style
;
1175 $$
->gotstyle
= TRUE
;
1179 $$
->exstyle
= $12->exstyle
;
1180 $$
->gotexstyle
= TRUE
;
1190 : expr
',' expr
',' expr
',' expr
',' expr optional_style_pair opt_data
{
1199 $$
->style
= $10->style
;
1200 $$
->gotstyle
= TRUE
;
1204 $$
->exstyle
= $10->exstyle
;
1205 $$
->gotexstyle
= TRUE
;
1213 opt_data: /* Empty */ { $$
= NULL
; }
1214 | raw_data
{ $$
= $1; }
1217 helpid
: /* Empty */ { $$
= NULL
; }
1218 |
',' expr
{ $$
= new_int
($2); }
1222 : tFONT expr
',' tSTRING
',' expr
',' expr opt_expr
{ $$
= new_font_id
($2, $4, $6, $8); }
1226 * FIXME: This odd expression is here to nullify an extra token found
1227 * in some appstudio produced resources which appear to do nothing.
1229 opt_expr: /* Empty */ { $$
= NULL
; }
1230 |
',' expr
{ $$
= NULL
; }
1233 /* ------------------------------ Menu ------------------------------ */
1234 menu
: tMENU loadmemopts opt_lvc menu_body
{
1236 yyerror("Menu must contain items");
1244 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1245 $$
->items
= get_item_head
($4);
1251 if
(!$$
->lvc.language
)
1252 $$
->lvc.language
= dup_language
(currentlanguage
);
1257 : tBEGIN item_definitions tEND
{ $$
= $2; }
1261 : /* Empty */ {$$
= NULL
;}
1262 | item_definitions tMENUITEM tSTRING opt_comma expr item_options
{
1271 | item_definitions tMENUITEM tSEPARATOR
{
1277 | item_definitions tPOPUP tSTRING item_options menu_body
{
1278 $$
= new_menu_item
();
1282 $$
->popup
= get_item_head
($5);
1287 /* NOTE: item_options is right recursive because it would introduce
1288 * a shift/reduce conflict on ',' in itemex_options due to the
1289 * empty rule here. The parser is now forced to look beyond the ','
1290 * before reducing (force shift).
1291 * Right recursion here is not a problem because we cannot expect
1292 * more than 7 parserstack places to be occupied while parsing this
1293 * (who would want to specify a MF_x flag twice?).
1296 : /* Empty */ { $$
= 0; }
1297 |
',' tCHECKED item_options
{ $$
= $3 | MF_CHECKED
; }
1298 |
',' tGRAYED item_options
{ $$
= $3 | MF_GRAYED
; }
1299 |
',' tHELP item_options
{ $$
= $3 | MF_HELP
; }
1300 |
',' tINACTIVE item_options
{ $$
= $3 | MF_DISABLED
; }
1301 |
',' tMENUBARBREAK item_options
{ $$
= $3 | MF_MENUBARBREAK
; }
1302 |
',' tMENUBREAK item_options
{ $$
= $3 | MF_MENUBREAK
; }
1305 /* ------------------------------ MenuEx ------------------------------ */
1306 menuex
: tMENUEX loadmemopts opt_lvc menuex_body
{
1308 yywarning
("MENUEX not supported in 16-bit mode");
1310 yyerror("MenuEx must contain items");
1318 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1319 $$
->items
= get_itemex_head
($4);
1325 if
(!$$
->lvc.language
)
1326 $$
->lvc.language
= dup_language
(currentlanguage
);
1331 : tBEGIN itemex_definitions tEND
{ $$
= $2; }
1335 : /* Empty */ {$$
= NULL
; }
1336 | itemex_definitions tMENUITEM tSTRING itemex_options
{
1337 $$
= new_menuex_item
();
1343 $$
->type
= $4->type
;
1344 $$
->state
= $4->state
;
1345 $$
->helpid
= $4->helpid
;
1346 $$
->gotid
= $4->gotid
;
1347 $$
->gottype
= $4->gottype
;
1348 $$
->gotstate
= $4->gotstate
;
1349 $$
->gothelpid
= $4->gothelpid
;
1352 | itemex_definitions tMENUITEM tSEPARATOR
{
1353 $$
= new_menuex_item
();
1358 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body
{
1359 $$
= new_menuex_item
();
1363 $$
->popup
= get_itemex_head
($5);
1366 $$
->type
= $4->type
;
1367 $$
->state
= $4->state
;
1368 $$
->helpid
= $4->helpid
;
1369 $$
->gotid
= $4->gotid
;
1370 $$
->gottype
= $4->gottype
;
1371 $$
->gotstate
= $4->gotstate
;
1372 $$
->gothelpid
= $4->gothelpid
;
1378 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1380 $$
= new_itemex_opt
($2, 0, 0, 0);
1383 |
',' e_expr
',' e_expr item_options
{
1384 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $5, 0);
1387 $$
->gotstate
= TRUE
;
1391 |
',' e_expr
',' e_expr
',' expr
{
1392 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1395 $$
->gotstate
= TRUE
;
1402 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1404 $$
= new_itemex_opt
($2, 0, 0, 0);
1407 |
',' e_expr
',' expr
{
1408 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4, 0, 0);
1413 |
',' e_expr
',' e_expr
',' expr
{
1414 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1419 $$
->gotstate
= TRUE
;
1421 |
',' e_expr
',' e_expr
',' e_expr
',' expr
{
1422 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6 ?
*($6) : 0, $8);
1428 $$
->gotstate
= TRUE
;
1429 $$
->gothelpid
= TRUE
;
1433 /* ------------------------------ StringTable ------------------------------ */
1434 /* Stringtables are parsed differently than other resources because their
1435 * layout is substantially different from other resources.
1436 * The table is parsed through a _global_ variable 'tagstt' which holds the
1437 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1438 * list of stringtables of different languages.
1441 : stt_head tBEGIN strings tEND
{
1444 yyerror("Stringtable must have at least one entry");
1449 /* Check if we added to a language table or created
1452 for
(stt
= sttres
; stt
; stt
= stt
->next
)
1459 /* It is a new one */
1462 sttres
->prev
= tagstt
;
1463 tagstt
->next
= sttres
;
1469 /* Else were done */
1473 free
(tagstt_memopt
);
1474 tagstt_memopt
= NULL
;
1481 /* This is to get the language of the currently parsed stringtable */
1482 stt_head: tSTRINGTABLE loadmemopts opt_lvc
{
1483 if
((tagstt
= find_stringtable
($3)) == NULL
)
1484 tagstt
= new_stringtable
($3);
1486 tagstt_version
= $3->version
;
1487 tagstt_characts
= $3->characts
;
1493 strings
: /* Empty */ { $$
= NULL
; }
1494 | strings expr opt_comma tSTRING
{
1496 assert
(tagstt
!= NULL
);
1497 if
($2 > 65535 ||
$2 < -32768)
1498 yyerror("Stringtable entry's ID out of range (%d)", $2);
1499 /* Search for the ID */
1500 for
(i
= 0; i
< tagstt
->nentries
; i
++)
1502 if
(tagstt
->entries
[i
].id
== $2)
1503 yyerror("Stringtable ID %d already in use", $2);
1505 /* If we get here, then we have a new unique entry */
1507 tagstt
->entries
= xrealloc
(tagstt
->entries
, sizeof
(tagstt
->entries
[0]) * tagstt
->nentries
);
1508 tagstt
->entries
[tagstt
->nentries
-1].id
= $2;
1509 tagstt
->entries
[tagstt
->nentries
-1].str
= $4;
1511 tagstt
->entries
[tagstt
->nentries
-1].memopt
= *tagstt_memopt
;
1513 tagstt
->entries
[tagstt
->nentries
-1].memopt
= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1514 tagstt
->entries
[tagstt
->nentries
-1].version
= tagstt_version
;
1515 tagstt
->entries
[tagstt
->nentries
-1].characts
= tagstt_characts
;
1517 if
(pedantic
&& !$4->size
)
1518 yywarning
("Zero length strings make no sense");
1519 if
(!win32
&& $4->size
> 254)
1520 yyerror("Stringtable entry more than 254 characters");
1521 if
(win32
&& $4->size
> 65534) /* Hmm..., does this happen? */
1522 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1527 opt_comma
/* There seem to be two ways to specify a stringtable... */
1532 /* ------------------------------ VersionInfo ------------------------------ */
1534 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND
{
1542 $$
->memopt
= WRC_MO_MOVEABLE |
(win32 ? WRC_MO_PURE
: 0);
1543 $$
->blocks
= get_ver_block_head
($5);
1544 /* Set language; there is no version or characteristics */
1545 $$
->lvc.language
= dup_language
(currentlanguage
);
1550 : /* Empty */ { $$
= new_versioninfo
(); }
1551 | fix_version tFILEVERSION expr
',' expr
',' expr
',' expr
{
1553 yyerror("FILEVERSION already defined");
1555 $$
->filever_maj1
= $3;
1556 $$
->filever_maj2
= $5;
1557 $$
->filever_min1
= $7;
1558 $$
->filever_min2
= $9;
1561 | fix_version tPRODUCTVERSION expr
',' expr
',' expr
',' expr
{
1563 yyerror("PRODUCTVERSION already defined");
1565 $$
->prodver_maj1
= $3;
1566 $$
->prodver_maj2
= $5;
1567 $$
->prodver_min1
= $7;
1568 $$
->prodver_min2
= $9;
1571 | fix_version tFILEFLAGS expr
{
1573 yyerror("FILEFLAGS already defined");
1578 | fix_version tFILEFLAGSMASK expr
{
1580 yyerror("FILEFLAGSMASK already defined");
1582 $$
->fileflagsmask
= $3;
1585 | fix_version tFILEOS expr
{
1587 yyerror("FILEOS already defined");
1592 | fix_version tFILETYPE expr
{
1594 yyerror("FILETYPE already defined");
1599 | fix_version tFILESUBTYPE expr
{
1601 yyerror("FILESUBTYPE already defined");
1603 $$
->filesubtype
= $3;
1609 : /* Empty */ { $$
= NULL
; }
1610 | ver_blocks ver_block
{
1619 : tBLOCK tSTRING tBEGIN ver_values tEND
{
1620 $$
= new_ver_block
();
1622 $$
->values
= get_ver_value_head
($4);
1627 : /* Empty */ { $$
= NULL
; }
1628 | ver_values ver_value
{
1638 $$
= new_ver_value
();
1639 $$
->type
= val_block
;
1640 $$
->value.block
= $1;
1642 | tVALUE tSTRING
',' tSTRING
{
1643 $$
= new_ver_value
();
1648 | tVALUE tSTRING
',' ver_words
{
1649 $$
= new_ver_value
();
1650 $$
->type
= val_words
;
1652 $$
->value.words
= $4;
1657 : expr
{ $$
= new_ver_words
($1); }
1658 | ver_words
',' expr
{ $$
= add_ver_words
($1, $3); }
1661 /* ------------------------------ Toolbar ------------------------------ */
1662 toolbar: tTOOLBAR loadmemopts expr
',' expr opt_lvc tBEGIN toolbar_items tEND
{
1664 toolbar_item_t
*items
= get_tlbr_buttons_head
($8, &nitems
);
1665 $$
= new_toolbar
($3, $5, items
, nitems
);
1673 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE
;
1680 if
(!$$
->lvc.language
)
1682 $$
->lvc.language
= dup_language
(currentlanguage
);
1688 : /* Empty */ { $$
= NULL
; }
1689 | toolbar_items tBUTTON expr
{
1690 toolbar_item_t
*idrec
= new_toolbar_item
();
1692 $$
= ins_tlbr_button
($1, idrec
);
1694 | toolbar_items tSEPARATOR
{
1695 toolbar_item_t
*idrec
= new_toolbar_item
();
1697 $$
= ins_tlbr_button
($1, idrec
);
1701 /* ------------------------------ Memory options ------------------------------ */
1703 : /* Empty */ { $$
= NULL
; }
1704 | loadmemopts lamo
{
1714 | loadmemopts lama
{
1723 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1729 lamo
: tPRELOAD
{ $$
= new_int
(WRC_MO_PRELOAD
); }
1730 | tMOVEABLE
{ $$
= new_int
(WRC_MO_MOVEABLE
); }
1731 | tDISCARDABLE
{ $$
= new_int
(WRC_MO_DISCARDABLE
); }
1732 | tPURE
{ $$
= new_int
(WRC_MO_PURE
); }
1735 lama
: tLOADONCALL
{ $$
= new_int
(~WRC_MO_PRELOAD
); }
1736 | tFIXED
{ $$
= new_int
(~WRC_MO_MOVEABLE
); }
1737 | tIMPURE
{ $$
= new_int
(~WRC_MO_PURE
); }
1740 /* ------------------------------ Win32 options ------------------------------ */
1741 opt_lvc
: /* Empty */ { $$
= new_lvc
(); }
1742 | opt_lvc opt_language
{
1744 yywarning
("LANGUAGE not supported in 16-bit mode");
1746 yyerror("Language already defined");
1750 | opt_lvc opt_characts
{
1752 yywarning
("CHARACTERISTICS not supported in 16-bit mode");
1754 yyerror("Characteristics already defined");
1758 | opt_lvc opt_version
{
1760 yywarning
("VERSION not supported in 16-bit mode");
1762 yyerror("Version already defined");
1769 * This here is another s/r conflict on {bi,u}nary + and -.
1770 * It is due to the look-ahead which must determine when the
1771 * rule opt_language ends. It could be solved with adding a
1772 * tNL at the end, but that seems unreasonable to do.
1773 * The conflict is now moved to the expression handling below.
1776 : tLANGUAGE expr
',' expr
{ $$
= new_language
($2, $4); }
1780 : tCHARACTERISTICS expr
{ $$
= new_characts
($2); }
1784 : tVERSION expr
{ $$
= new_version
($2); }
1787 /* ------------------------------ Raw data handling ------------------------------ */
1788 raw_data: opt_lvc tBEGIN raw_elements tEND
{
1795 if
(!$3->lvc.language
)
1796 $3->lvc.language
= dup_language
(currentlanguage
);
1803 : tRAWDATA
{ $$
= $1; }
1804 | tNUMBER
{ $$
= int2raw_data
($1); }
1805 | tLNUMBER
{ $$
= long2raw_data
($1); }
1806 | tSTRING
{ $$
= str2raw_data
($1); }
1807 | raw_elements opt_comma tRAWDATA
{ $$
= merge_raw_data
($1, $3); free
($3->data
); free
($3); }
1808 | raw_elements opt_comma tNUMBER
{ $$
= merge_raw_data_int
($1, $3); }
1809 | raw_elements opt_comma tLNUMBER
{ $$
= merge_raw_data_long
($1, $3); }
1810 | raw_elements opt_comma tSTRING
{ $$
= merge_raw_data_str
($1, $3); }
1813 /* File data or raw data */
1814 file_raw: filename
{
1816 $$
->lvc.language
= dup_language
(currentlanguage
);
1818 | raw_data
{ $$
= $1; }
1821 /* ------------------------------ Win32 expressions ------------------------------ */
1822 /* All win16 numbers are also handled here. This is inconsistent with MS'
1823 * resource compiler, but what the heck, its just handy to have.
1825 e_expr
: /* Empty */ { $$
= 0; }
1826 | expr
{ $$
= new_int
($1); }
1829 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1830 expr
: xpr
{ $$
= ($1); }
1833 xpr
: xpr
'+' xpr
{ $$
= ($1) + ($3); }
1834 | 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
{ $$
= ~
($2); }
1841 |
'-' xpr %prec pUPM
{ $$
= -($2); }
1842 |
'+' xpr %prec pUPM
{ $$
= $2; }
1843 |
'(' xpr
')' { $$
= $2; }
1844 | any_num
{ $$
= $1; }
1845 | tNOT any_num
{ $$
= ~
($2); }
1848 any_num
: tNUMBER
{ $$
= $1; }
1849 | tLNUMBER
{ $$
= $1; }
1853 /* Dialog specific functions */
1854 static dialog_t
*dialog_style
(style_t
* st
, dialog_t
*dlg
)
1856 assert
(dlg
!= NULL
);
1857 if
(dlg
->style
== NULL
)
1859 dlg
->style
= new_style
(0,0);
1864 yywarning
("Style already defined, or-ing together");
1868 dlg
->style
->or_mask
= 0;
1869 dlg
->style
->and_mask
= 0;
1871 dlg
->style
->or_mask |
= st
->or_mask
;
1872 dlg
->style
->and_mask |
= st
->and_mask
;
1873 dlg
->gotstyle
= TRUE
;
1878 static dialog_t
*dialog_exstyle
(style_t
*st
, dialog_t
*dlg
)
1880 assert
(dlg
!= NULL
);
1881 if
(dlg
->exstyle
== NULL
)
1883 dlg
->exstyle
= new_style
(0,0);
1888 yywarning
("ExStyle already defined, or-ing together");
1892 dlg
->exstyle
->or_mask
= 0;
1893 dlg
->exstyle
->and_mask
= 0;
1895 dlg
->exstyle
->or_mask |
= st
->or_mask
;
1896 dlg
->exstyle
->and_mask |
= st
->and_mask
;
1897 dlg
->gotexstyle
= TRUE
;
1902 static dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
)
1904 assert
(dlg
!= NULL
);
1906 yyerror("Caption already defined");
1911 static dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
)
1913 assert
(dlg
!= NULL
);
1915 yyerror("Font already defined");
1920 static dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
)
1922 assert
(dlg
!= NULL
);
1924 yyerror("Class already defined");
1929 static dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
)
1931 assert
(dlg
!= NULL
);
1933 yyerror("Menu already defined");
1938 static dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
)
1940 assert
(dlg
!= NULL
);
1941 if
(dlg
->lvc.language
)
1942 yyerror("Language already defined");
1943 dlg
->lvc.language
= l
;
1947 static dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
)
1949 assert
(dlg
!= NULL
);
1950 if
(dlg
->lvc.characts
)
1951 yyerror("Characteristics already defined");
1952 dlg
->lvc.characts
= c
;
1956 static dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
)
1958 assert
(dlg
!= NULL
);
1959 if
(dlg
->lvc.version
)
1960 yyerror("Version already defined");
1961 dlg
->lvc.version
= v
;
1965 /* Controls specific functions */
1966 static control_t
*ins_ctrl
(int type
, int special_style
, control_t
*ctrl
, control_t
*prev
)
1968 /* Hm... this seems to be jammed in at all time... */
1969 int defaultstyle
= WS_CHILD | WS_VISIBLE
;
1971 assert
(ctrl
!= NULL
);
1979 ctrl
->ctlclass
= new_name_id
();
1980 ctrl
->ctlclass
->type
= name_ord
;
1981 ctrl
->ctlclass
->name.i_name
= type
;
1987 if
(special_style
!= BS_GROUPBOX
&& special_style
!= BS_RADIOBUTTON
)
1988 defaultstyle |
= WS_TABSTOP
;
1991 defaultstyle |
= WS_TABSTOP | WS_BORDER
;
1994 defaultstyle |
= LBS_NOTIFY | WS_BORDER
;
1997 defaultstyle |
= CBS_SIMPLE
;
2000 if
(special_style
== SS_CENTER || special_style
== SS_LEFT || special_style
== SS_RIGHT
)
2001 defaultstyle |
= WS_GROUP
;
2005 if
(!ctrl
->gotstyle
) /* Handle default style setting */
2010 defaultstyle |
= ES_LEFT
;
2013 defaultstyle |
= LBS_NOTIFY
;
2016 defaultstyle |
= CBS_SIMPLE | WS_TABSTOP
;
2019 defaultstyle |
= SBS_HORZ
;
2022 switch
(special_style
)
2025 case BS_DEFPUSHBUTTON
:
2028 /* case BS_PUSHBOX: */
2029 case BS_AUTORADIOBUTTON
:
2032 case BS_AUTOCHECKBOX
:
2033 defaultstyle |
= WS_TABSTOP
;
2036 yywarning
("Unknown default button control-style 0x%08x", special_style
);
2037 case BS_RADIOBUTTON
:
2043 switch
(special_style
)
2048 defaultstyle |
= WS_GROUP
;
2050 case SS_ICON
: /* Special case */
2053 yywarning
("Unknown default static control-style 0x%08x", special_style
);
2057 case
-1: /* Generic control */
2061 yyerror("Internal error (report this): Got weird control type 0x%08x", type
);
2065 /* The SS_ICON flag is always forced in for icon controls */
2066 if
(type
== CT_STATIC
&& special_style
== SS_ICON
)
2067 defaultstyle |
= SS_ICON
;
2069 if
(!ctrl
->gotstyle
)
2070 ctrl
->style
= new_style
(0,0);
2072 /* combine all styles */
2073 ctrl
->style
->or_mask
= ctrl
->style
->or_mask | defaultstyle | special_style
;
2074 ctrl
->gotstyle
= TRUE
;
2076 /* combine with NOT mask */
2079 ctrl
->style
->or_mask
&= ~
(ctrl
->style
->and_mask
);
2080 ctrl
->style
->and_mask
= 0;
2082 if
(ctrl
->gotexstyle
)
2084 ctrl
->exstyle
->or_mask
&= ~
(ctrl
->exstyle
->and_mask
);
2085 ctrl
->exstyle
->and_mask
= 0;
2090 static name_id_t
*convert_ctlclass
(name_id_t
*cls
)
2095 if
(cls
->type
== name_ord
)
2097 assert
(cls
->type
== name_str
);
2098 if
(cls
->type
== str_unicode
)
2100 yyerror("Don't yet support unicode class comparison");
2103 cc
= cls
->name.s_name
->str.cstr
;
2105 if
(!strcasecmp
("BUTTON", cc
))
2107 else if
(!strcasecmp
("COMBOBOX", cc
))
2108 iclass
= CT_COMBOBOX
;
2109 else if
(!strcasecmp
("LISTBOX", cc
))
2110 iclass
= CT_LISTBOX
;
2111 else if
(!strcasecmp
("EDIT", cc
))
2113 else if
(!strcasecmp
("STATIC", cc
))
2115 else if
(!strcasecmp
("SCROLLBAR", cc
))
2116 iclass
= CT_SCROLLBAR
;
2118 return cls
; /* No default, return user controlclass */
2120 free
(cls
->name.s_name
->str.cstr
);
2121 free
(cls
->name.s_name
);
2122 cls
->type
= name_ord
;
2123 cls
->name.i_name
= iclass
;
2127 /* DialogEx specific functions */
2128 static dialogex_t
*dialogex_style
(style_t
* st
, dialogex_t
*dlg
)
2130 assert
(dlg
!= NULL
);
2131 if
(dlg
->style
== NULL
)
2133 dlg
->style
= new_style
(0,0);
2138 yywarning
("Style already defined, or-ing together");
2142 dlg
->style
->or_mask
= 0;
2143 dlg
->style
->and_mask
= 0;
2145 dlg
->style
->or_mask |
= st
->or_mask
;
2146 dlg
->style
->and_mask |
= st
->and_mask
;
2147 dlg
->gotstyle
= TRUE
;
2152 static dialogex_t
*dialogex_exstyle
(style_t
* st
, dialogex_t
*dlg
)
2154 assert
(dlg
!= NULL
);
2155 if
(dlg
->exstyle
== NULL
)
2157 dlg
->exstyle
= new_style
(0,0);
2162 yywarning
("ExStyle already defined, or-ing together");
2166 dlg
->exstyle
->or_mask
= 0;
2167 dlg
->exstyle
->and_mask
= 0;
2169 dlg
->exstyle
->or_mask |
= st
->or_mask
;
2170 dlg
->exstyle
->and_mask |
= st
->and_mask
;
2171 dlg
->gotexstyle
= TRUE
;
2176 static dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
)
2178 assert
(dlg
!= NULL
);
2180 yyerror("Caption already defined");
2185 static dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
)
2187 assert
(dlg
!= NULL
);
2189 yyerror("Font already defined");
2194 static dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
)
2196 assert
(dlg
!= NULL
);
2198 yyerror("Class already defined");
2203 static dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
)
2205 assert
(dlg
!= NULL
);
2207 yyerror("Menu already defined");
2212 static dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
)
2214 assert
(dlg
!= NULL
);
2215 if
(dlg
->lvc.language
)
2216 yyerror("Language already defined");
2217 dlg
->lvc.language
= l
;
2221 static dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
)
2223 assert
(dlg
!= NULL
);
2224 if
(dlg
->lvc.characts
)
2225 yyerror("Characteristics already defined");
2226 dlg
->lvc.characts
= c
;
2230 static dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
)
2232 assert
(dlg
!= NULL
);
2233 if
(dlg
->lvc.version
)
2234 yyerror("Version already defined");
2235 dlg
->lvc.version
= v
;
2239 /* Accelerator specific functions */
2240 static event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
)
2242 event_t
*ev
= new_event
();
2244 if
((flags
& (WRC_AF_VIRTKEY | WRC_AF_ASCII
)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII
))
2245 yyerror("Cannot use both ASCII and VIRTKEY");
2249 ev
->flags
= flags
& ~WRC_AF_ASCII
;
2256 static event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
)
2259 event_t
*ev
= new_event
();
2261 if
(key
->type
!= str_char
)
2262 yyerror("Key code must be an ascii string");
2264 if
((flags
& WRC_AF_VIRTKEY
) && (!isupper
(key
->str.cstr
[0] & 0xff) && !isdigit
(key
->str.cstr
[0] & 0xff)))
2265 yyerror("VIRTKEY code is not equal to ascii value");
2267 if
(key
->str.cstr
[0] == '^' && (flags
& WRC_AF_CONTROL
) != 0)
2269 yyerror("Cannot use both '^' and CONTROL modifier");
2271 else if
(key
->str.cstr
[0] == '^')
2273 keycode
= toupper
(key
->str.cstr
[1]) - '@';
2275 yyerror("Control-code out of range");
2278 keycode
= key
->str.cstr
[0];
2281 ev
->flags
= flags
& ~WRC_AF_ASCII
;
2288 /* MenuEx specific functions */
2289 static itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
)
2291 itemex_opt_t
*opt
= (itemex_opt_t
*)xmalloc
(sizeof
(itemex_opt_t
));
2295 opt
->helpid
= helpid
;
2299 /* Raw data functions */
2300 static raw_data_t
*load_file
(string_t
*name
)
2304 if
(name
->type
!= str_char
)
2305 yyerror("Filename must be ASCII string");
2307 fp
= open_include
(name
->str.cstr
, 1, NULL
);
2309 yyerror("Cannot open file %s", name
->str.cstr
);
2310 rd
= new_raw_data
();
2311 fseek
(fp
, 0, SEEK_END
);
2312 rd
->size
= ftell
(fp
);
2313 fseek
(fp
, 0, SEEK_SET
);
2314 rd
->data
= (char *)xmalloc
(rd
->size
);
2315 fread
(rd
->data
, rd
->size
, 1, fp
);
2320 static raw_data_t
*int2raw_data
(int i
)
2324 if
((int)((short)i
) != i
)
2325 yywarning
("Integer constant out of 16bit range (%d), truncated to %d\n", i
, (short)i
);
2327 rd
= new_raw_data
();
2328 rd
->size
= sizeof
(short);
2329 rd
->data
= (char *)xmalloc
(rd
->size
);
2332 #ifndef WORDS_BIGENDIAN
2337 *(WORD
*)(rd
->data
) = BYTESWAP_WORD
((WORD
)i
);
2340 *(WORD
*)(rd
->data
) = (WORD
)i
;
2346 static raw_data_t
*long2raw_data
(int i
)
2349 rd
= new_raw_data
();
2350 rd
->size
= sizeof
(int);
2351 rd
->data
= (char *)xmalloc
(rd
->size
);
2354 #ifndef WORDS_BIGENDIAN
2359 *(DWORD
*)(rd
->data
) = BYTESWAP_DWORD
((DWORD
)i
);
2362 *(DWORD
*)(rd
->data
) = (DWORD
)i
;
2368 static raw_data_t
*str2raw_data
(string_t
*str
)
2371 rd
= new_raw_data
();
2372 rd
->size
= str
->size
* (str
->type
== str_char ?
1 : 2);
2373 rd
->data
= (char *)xmalloc
(rd
->size
);
2374 if
(str
->type
== str_char
)
2375 memcpy
(rd
->data
, str
->str.cstr
, rd
->size
);
2376 else if
(str
->type
== str_unicode
)
2381 #ifndef WORDS_BIGENDIAN
2386 for
(i
= 0; i
< str
->size
; i
++)
2387 *(WORD
*)&(rd
->data
[2*i
]) = BYTESWAP_WORD
((WORD
)str
->str.wstr
[i
]);
2390 for
(i
= 0; i
< str
->size
; i
++)
2391 *(WORD
*)&(rd
->data
[2*i
]) = (WORD
)str
->str.wstr
[i
];
2396 internal_error
(__FILE__
, __LINE__
, "Invalid stringtype");
2400 static raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
)
2402 r1
->data
= xrealloc
(r1
->data
, r1
->size
+ r2
->size
);
2403 memcpy
(r1
->data
+ r1
->size
, r2
->data
, r2
->size
);
2404 r1
->size
+= r2
->size
;
2408 static raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
)
2410 raw_data_t
*t
= int2raw_data
(i
);
2411 merge_raw_data
(r1
, t
);
2417 static raw_data_t
*merge_raw_data_long
(raw_data_t
*r1
, int i
)
2419 raw_data_t
*t
= long2raw_data
(i
);
2420 merge_raw_data
(r1
, t
);
2426 static raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
)
2428 raw_data_t
*t
= str2raw_data
(str
);
2429 merge_raw_data
(r1
, t
);
2435 /* Function the go back in a list to get the head */
2436 static menu_item_t
*get_item_head
(menu_item_t
*p
)
2445 static menuex_item_t
*get_itemex_head
(menuex_item_t
*p
)
2454 static resource_t
*get_resource_head
(resource_t
*p
)
2463 static ver_block_t
*get_ver_block_head
(ver_block_t
*p
)
2472 static ver_value_t
*get_ver_value_head
(ver_value_t
*p
)
2481 static control_t
*get_control_head
(control_t
*p
)
2490 static event_t
*get_event_head
(event_t
*p
)
2499 /* Find a stringtable with given language */
2500 static stringtable_t
*find_stringtable
(lvc_t
*lvc
)
2504 assert
(lvc
!= NULL
);
2507 lvc
->language
= dup_language
(currentlanguage
);
2509 for
(stt
= sttres
; stt
; stt
= stt
->next
)
2511 if
(stt
->lvc.language
->id
== lvc
->language
->id
2512 && stt
->lvc.language
->sub
== lvc
->language
->sub
)
2514 /* Found a table with the same language */
2515 /* The version and characteristics are now handled
2516 * in the generation of the individual stringtables.
2517 * This enables localized analysis.
2518 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2519 || (!stt->lvc.version && lvc->version)
2520 || (stt->lvc.version && !lvc->version))
2521 yywarning("Stringtable's versions are not the same, using first definition");
2523 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2524 || (!stt->lvc.characts && lvc->characts)
2525 || (stt->lvc.characts && !lvc->characts))
2526 yywarning("Stringtable's characteristics are not the same, using first definition");
2534 /* qsort sorting function for string table entries */
2535 #define STE(p) ((stt_entry_t *)(p))
2536 static int sort_stt_entry
(const void *e1
, const void *e2
)
2538 return STE
(e1
)->id
- STE
(e2
)->id
;
2542 static resource_t
*build_stt_resources
(stringtable_t
*stthead
)
2545 stringtable_t
*newstt
;
2547 resource_t
*rsclist
= NULL
;
2548 resource_t
*rsctail
= NULL
;
2553 characts_t
*characts
;
2559 /* For all languages defined */
2560 for
(stt
= stthead
; stt
; stt
= stt
->next
)
2562 assert
(stt
->nentries
> 0);
2564 /* Sort the entries */
2565 if
(stt
->nentries
> 1)
2566 qsort
(stt
->entries
, stt
->nentries
, sizeof
(stt
->entries
[0]), sort_stt_entry
);
2568 for
(i
= 0; i
< stt
->nentries
; )
2570 newstt
= new_stringtable
(&stt
->lvc
);
2571 newstt
->entries
= (stt_entry_t
*)xmalloc
(16 * sizeof
(stt_entry_t
));
2572 newstt
->nentries
= 16;
2573 newstt
->idbase
= stt
->entries
[i
].id
& ~
0xf;
2574 for
(j
= 0; j
< 16 && i
< stt
->nentries
; j
++)
2576 if
(stt
->entries
[i
].id
- newstt
->idbase
== j
)
2578 newstt
->entries
[j
] = stt
->entries
[i
];
2586 /* Check individual memory options and get
2587 * the first characteristics/version
2589 for
(j
= 0; j
< 16; j
++)
2591 if
(!newstt
->entries
[j
].str
)
2593 andsum
&= newstt
->entries
[j
].memopt
;
2594 orsum |
= newstt
->entries
[j
].memopt
;
2596 characts
= newstt
->entries
[j
].characts
;
2598 version
= newstt
->entries
[j
].version
;
2602 warning
("Stringtable's memory options are not equal (idbase: %d)", newstt
->idbase
);
2604 /* Check version and characteristics */
2605 for
(j
= 0; j
< 16; j
++)
2608 && newstt
->entries
[j
].characts
2609 && *newstt
->entries
[j
].characts
!= *characts
)
2610 warning
("Stringtable's characteristics are not the same (idbase: %d)", newstt
->idbase
);
2612 && newstt
->entries
[j
].version
2613 && *newstt
->entries
[j
].version
!= *version
)
2614 warning
("Stringtable's versions are not the same (idbase: %d)", newstt
->idbase
);
2616 rsc
= new_resource
(res_stt
, newstt
, newstt
->memopt
, newstt
->lvc.language
);
2617 rsc
->name
= new_name_id
();
2618 rsc
->name
->type
= name_ord
;
2619 rsc
->name
->name.i_name
= (newstt
->idbase
>> 4) + 1;
2620 rsc
->memopt
= andsum
; /* Set to least common denominator */
2621 newstt
->memopt
= andsum
;
2622 newstt
->lvc.characts
= characts
;
2623 newstt
->lvc.version
= version
;
2631 rsctail
->next
= rsc
;
2632 rsc
->prev
= rsctail
;
2641 static toolbar_item_t
*ins_tlbr_button
(toolbar_item_t
*prev
, toolbar_item_t
*idrec
)
2650 static toolbar_item_t
*get_tlbr_buttons_head
(toolbar_item_t
*p
, int *nitems
)
2669 static string_t
*make_filename
(string_t
*str
)
2673 if
(str
->type
!= str_char
)
2674 yyerror("Cannot handle UNICODE filenames");
2676 /* Remove escaped backslash and convert to forward */
2677 cptr
= str
->str.cstr
;
2678 for
(cptr
= str
->str.cstr
; (cptr
= strchr
(cptr
, '\\')) != NULL
; cptr
++)
2682 memmove
(cptr
, cptr
+1, strlen
(cptr
));
2688 /* Convert to lower case. Seems to be reasonable to do */
2689 for
(cptr
= str
->str.cstr
; !leave_case
&& *cptr
; cptr
++)
2691 *cptr
= tolower
(*cptr
);
2697 * Process all resources to extract fonts and build
2698 * a fontdir resource.
2700 * Note: MS' resource compiler (build 1472) does not
2701 * handle font resources with different languages.
2702 * The fontdir is generated in the last active language
2703 * and font identifiers must be unique across the entire
2705 * This is not logical considering the localization
2706 * constraints of all other resource types. MS has,
2707 * most probably, never testet localized fonts. However,
2708 * using fontresources is rare, so it might not occur
2709 * in normal applications.
2710 * Wine does require better localization because a lot
2711 * of languages are coded into the same executable.
2712 * Therefore, I will generate fontdirs for *each*
2713 * localized set of fonts.
2715 static resource_t
*build_fontdir
(resource_t
**fnt
, int nfnt
)
2717 static int once
= 0;
2720 warning
("Need to parse fonts, not yet implemented");
2726 static resource_t
*build_fontdirs
(resource_t
*tail
)
2729 resource_t
*lst
= NULL
;
2730 resource_t
**fnt
= NULL
; /* List of all fonts */
2732 resource_t
**fnd
= NULL
; /* List of all fontdirs */
2734 resource_t
**lanfnt
= NULL
;
2741 nid.type
= name_str
;
2742 nid.name.s_name
= &str
;
2743 str.type
= str_char
;
2744 str.str.cstr
= "FONTDIR";
2747 /* Extract all fonts and fontdirs */
2748 for
(rsc
= tail
; rsc
; rsc
= rsc
->prev
)
2750 if
(rsc
->type
== res_fnt
)
2753 fnt
= xrealloc
(fnt
, nfnt
* sizeof
(*fnt
));
2756 else if
(rsc
->type
== res_fntdir
)
2759 fnd
= xrealloc
(fnd
, nfnd
* sizeof
(*fnd
));
2764 /* Verify the name of the present fontdirs */
2765 for
(i
= 0; i
< nfnd
; i
++)
2767 if
(compare_name_id
(&nid
, fnd
[i
]->name
))
2769 warning
("User supplied FONTDIR entry has an invalid name '%s', ignored",
2770 get_nameid_str
(fnd
[i
]->name
));
2779 warning
("Found %d FONTDIR entries without any fonts present", nfnd
);
2784 lanfnt
= xmalloc
(nfnt
* sizeof
(*lanfnt
));
2786 /* Get all fonts covered by fontdirs */
2787 for
(i
= 0; i
< nfnd
; i
++)
2795 for
(j
= 0; j
< nfnt
; j
++)
2799 if
(fnt
[j
]->lan
->id
== fnd
[i
]->lan
->id
&& fnt
[j
]->lan
->sub
== fnd
[i
]->lan
->sub
)
2801 lanfnt
[nlanfnt
] = fnt
[j
];
2807 cnt
= *(WORD
*)fnd
[i
]->res.fnd
->data
->data
;
2810 else if
(nlanfnt
== BYTESWAP_WORD
(cnt
))
2813 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2814 fnd
[i
]->lan
->id
, fnd
[i
]->lan
->sub
, cnt
, nlanfnt
);
2815 #ifdef WORDS_BIGENDIAN
2816 if
((byteorder
== WRC_BO_LITTLE
&& !isswapped
) ||
(byteorder
!= WRC_BO_LITTLE
&& isswapped
))
2818 if
((byteorder
== WRC_BO_BIG
&& !isswapped
) ||
(byteorder
!= WRC_BO_BIG
&& isswapped
))
2821 internal_error
(__FILE__
, __LINE__
, "User supplied FONTDIR needs byteswapping");
2825 /* We now have fonts left where we need to make a fontdir resource */
2826 for
(i
= fntleft
= 0; i
< nfnt
; i
++)
2833 /* Get fonts of same language in lanfnt[] */
2834 for
(i
= nlanfnt
= 0; i
< nfnt
; i
++)
2841 lanfnt
[nlanfnt
] = fnt
[i
];
2846 else if
(fnt
[i
]->lan
->id
== lanfnt
[0]->lan
->id
&& fnt
[i
]->lan
->sub
== lanfnt
[0]->lan
->sub
)
2850 /* and build a fontdir */
2851 rsc
= build_fontdir
(lanfnt
, nlanfnt
);
2873 * This gets invoked to determine whether the next resource
2874 * is to be of a standard-type (e.g. bitmaps etc.), or should
2875 * be a user-type resource. This function is required because
2876 * there is the _possibility_ of a lookahead token in the
2877 * parser, which is generated from the "expr" state in the
2880 * The general resource format is:
2881 * <identifier> <type> <flags> <resourcebody>
2883 * The <identifier> can either be tIDENT or "expr". The latter
2884 * will always generate a lookahead, which is the <type> of the
2885 * resource to parse. Otherwise, we need to get a new token from
2886 * the scanner to determine the next step.
2888 * The problem arrises when <type> is numerical. This case should
2889 * map onto default resource-types and be parsed as such instead
2890 * of being mapped onto user-type resources.
2892 * The trick lies in the fact that yacc (bison) doesn't care about
2893 * intermediate changes of the lookahead while reducing a rule. We
2894 * simply replace the lookahead with a token that will result in
2895 * a shift to the appropriate rule for the specific resource-type.
2897 static int rsrcid_to_token
(int lookahead
)
2902 /* Get a token if we don't have one yet */
2903 if
(lookahead
== YYEMPTY
)
2906 /* Only numbers are possibly interesting */
2936 case WRC_RT_FONTDIR
:
2944 case WRC_RT_MESSAGETABLE
:
2945 type
= "MESSAGETABLE";
2946 token
= tMESSAGETABLE
;
2948 case WRC_RT_DLGINIT
:
2952 case WRC_RT_ACCELERATOR
:
2953 type
= "ACCELERATOR";
2954 token
= tACCELERATORS
;
2964 case WRC_RT_VERSION
:
2966 token
= tVERSIONINFO
;
2968 case WRC_RT_TOOLBAR
:
2974 type
= "STRINGTABLE";
2977 case WRC_RT_ANICURSOR
:
2978 case WRC_RT_ANIICON
:
2979 case WRC_RT_GROUP_CURSOR
:
2980 case WRC_RT_GROUP_ICON
:
2981 yywarning
("Usertype uses reserved type-ID %d, which is auto-generated", yylval.num
);
2984 case WRC_RT_DLGINCLUDE
:
2985 case WRC_RT_PLUGPLAY
:
2988 yywarning
("Usertype uses reserved type-ID %d, which is not supported by wrc", yylval.num
);
2996 yywarning
("Usertype uses reserved type-ID %d, which is used by %s", yylval.num
, type
);