3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * 24-Jul-2000 BS - Made a fix for broken Berkeley yacc on
23 * non-terminals (see cjunk rule).
24 * 21-May-2000 BS - Partial implementation of font resources.
25 * - Corrected language propagation for binary
26 * resources such as bitmaps, icons, cursors,
27 * userres and rcdata. The language is now
28 * correct in .res files.
29 * - Fixed reading the resource name as ident,
30 * so that it may overlap keywords.
31 * 20-May-2000 BS - Implemented animated cursors and icons
33 * 30-Apr-2000 BS - Reintegration into the wine-tree
34 * 14-Jan-2000 BS - Redid the usertype resources so that they
36 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
37 * except for the # command (line numbers).
39 * 06-Nov-1999 JS - see CHANGES
41 * 29-Dec-1998 AdH - Grammar and function extensions.
42 * grammar: TOOLBAR resources, Named ICONs in
44 * functions: semantic actions for the grammar
45 * changes, resource files can now be anywhere
46 * on the include path instead of just in the
49 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
50 * printed out correctly.
52 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
53 * also accept a tSTRING as argument.
55 * 25-May-1998 BS - Found out that I need to support language, version
56 * and characteristics in inline resources (bitmap,
57 * cursor, etc) but they can also be specified with
58 * a filename. This renders my filename-scanning scheme
59 * worthless. Need to build newline parsing to solve
61 * It will come with version 1.1.0 (sigh).
63 * 19-May-1998 BS - Started to build a builtin preprocessor
65 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
66 * ideas had some serious flaws.
68 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
71 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
72 * - This file is growing too big. It is time to strip
73 * things and put it in a support file.
75 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
76 * resource will be created. This because the table
77 * has a different layout than other resources. The
78 * table has to be sorted, and divided into smaller
79 * resource entries (see comment in source).
81 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
82 * as string_t which include unicode strings upon
84 * - Parser now emits a warning when compiling win32
85 * extensions in win16 mode.
87 * 16-Apr-1998 BS - Raw data elements are now *optionally* separated
88 * by commas. Read the comments in file sq2dq.l.
89 * - FIXME: there are instances in the source that rely
90 * on the fact that int==32bit and pointers are int size.
91 * - Fixed the conflict in menuex by changing a rule
92 * back into right recursion. See note in source.
93 * - UserType resources cannot have an expression as its
94 * typeclass. See note in source.
96 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
97 * get reduction of the parsestack.
98 * This also helps communication between bison and flex.
99 * Main advantage is that the Empty rule gets reduced
100 * first, which is used to allocate/link things.
101 * It also added a shift/reduce conflict in the menuex
102 * handling, due to expression/option possibility,
103 * although not serious.
105 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
106 * about making it more efficient, but readable (for me)
107 * and slightly easier to expand/change.
108 * This is done primarily by using more reduce states
109 * with many (intuitive) types for the various resource
111 * - Added expression handling for all resources where a
112 * number is accepted (not only for win32). Also added
113 * multiply and division (not MS compatible, but handy).
114 * Unary minus introduced a shift/reduce conflict, but
117 * 13-Apr-1998 BS - Reordered a lot of things
118 * - Made the source more readable
119 * - Added Win32 resource definitions
120 * - Corrected syntax problems with an old yacc (;)
121 * - Added extra comment about grammar
137 #include "newstruc.h"
139 #include "wine/wpp.h"
140 #include "wine/unicode.h"
148 /* Berkeley yacc (byacc) doesn't seem to know about these */
149 /* Some *BSD supplied versions do define these though */
151 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
154 # define YYLEX yylex()
157 #elif defined(YYBISON)
158 /* Bison was used for original development */
159 /* #define YYEMPTY -2 */
160 /* #define YYLEX yylex() */
163 /* No yacc we know yet */
164 # if !defined(YYEMPTY) || !defined(YYLEX)
165 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
166 # elif defined(__GNUC__) /* gcc defines the #warning directive */
167 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
168 /* #else we just take a chance that it works... */
172 int want_nl
= 0; /* Signal flex that we need the next newline */
173 int want_id
= 0; /* Signal flex that we need the next identifier */
174 stringtable_t
*tagstt
; /* Stringtable tag.
175 * It is set while parsing a stringtable to one of
176 * the stringtables in the sttres list or a new one
177 * if the language was not parsed before.
179 stringtable_t
*sttres
; /* Stringtable resources. This holds the list of
180 * stringtables with different lanuages
182 static int dont_want_id
= 0; /* See language parsing for details */
184 /* Set to the current options of the currently scanning stringtable */
185 static int *tagstt_memopt
;
186 static characts_t
*tagstt_characts
;
187 static version_t
*tagstt_version
;
189 static const char riff
[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
191 /* Prototypes of here defined functions */
192 static event_t
*get_event_head
(event_t
*p
);
193 static control_t
*get_control_head
(control_t
*p
);
194 static ver_value_t
*get_ver_value_head
(ver_value_t
*p
);
195 static ver_block_t
*get_ver_block_head
(ver_block_t
*p
);
196 static resource_t
*get_resource_head
(resource_t
*p
);
197 static menuex_item_t
*get_itemex_head
(menuex_item_t
*p
);
198 static menu_item_t
*get_item_head
(menu_item_t
*p
);
199 static raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
);
200 static raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
);
201 static raw_data_t
*merge_raw_data_long
(raw_data_t
*r1
, int i
);
202 static raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
);
203 static raw_data_t
*str2raw_data
(string_t
*str
);
204 static raw_data_t
*int2raw_data
(int i
);
205 static raw_data_t
*long2raw_data
(int i
);
206 static raw_data_t
*load_file
(string_t
*name
, language_t
*lang
);
207 static itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
);
208 static event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
);
209 static event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
);
210 static dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
);
211 static dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
);
212 static dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
);
213 static dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
);
214 static dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
);
215 static dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
);
216 static dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
);
217 static dialogex_t
*dialogex_exstyle
(style_t
*st
, dialogex_t
*dlg
);
218 static dialogex_t
*dialogex_style
(style_t
*st
, dialogex_t
*dlg
);
219 static name_id_t
*convert_ctlclass
(name_id_t
*cls
);
220 static control_t
*ins_ctrl
(int type
, int special_style
, control_t
*ctrl
, control_t
*prev
);
221 static dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
);
222 static dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
);
223 static dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
);
224 static dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
);
225 static dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
);
226 static dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
);
227 static dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
);
228 static dialog_t
*dialog_exstyle
(style_t
* st
, dialog_t
*dlg
);
229 static dialog_t
*dialog_style
(style_t
* st
, dialog_t
*dlg
);
230 static resource_t
*build_stt_resources
(stringtable_t
*stthead
);
231 static stringtable_t
*find_stringtable
(lvc_t
*lvc
);
232 static toolbar_item_t
*ins_tlbr_button
(toolbar_item_t
*prev
, toolbar_item_t
*idrec
);
233 static toolbar_item_t
*get_tlbr_buttons_head
(toolbar_item_t
*p
, int *nitems
);
234 static string_t
*make_filename
(string_t
*s
);
235 static resource_t
*build_fontdirs
(resource_t
*tail
);
236 static resource_t
*build_fontdir
(resource_t
**fnt
, int nfnt
);
237 static int rsrcid_to_token
(int lookahead
);
268 menuex_item_t
*menexitm
;
276 toolbar_item_t
*tlbarItems
;
278 style_pair_t
*styles
;
284 %token
<num
> tNUMBER tLNUMBER
285 %token
<str
> tSTRING tIDENT tFILENAME
286 %token
<raw
> tRAWDATA
287 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
288 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
289 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
290 %token tPUSHBUTTON tRADIOBUTTON tSTATE3
/* PUSHBOX */
291 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
292 %token tCONTROL tEDITTEXT
293 %token tRTEXT tCTEXT tLTEXT
295 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
296 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
297 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
298 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
299 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
301 %token tSTRING tIDENT tRAWDATA
302 %token tTOOLBAR tBUTTON
313 %type
<res
> resource_file resource resources resource_definition
314 %type
<stt
> stringtable strings
317 %type
<acc
> accelerators
320 %type
<ani
> cursor icon
321 %type
<dlg
> dialog dlg_attributes
322 %type
<ctl
> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
324 %type
<dlgex
> dialogex dlgex_attribs
325 %type
<ctl
> exctrls gen_exctrl lab_exctrl exctrl_desc
327 %type
<raw
> raw_data raw_elements opt_data file_raw
328 %type
<veri
> versioninfo fix_version
329 %type
<verw
> ver_words
330 %type
<blk
> ver_blocks ver_block
331 %type
<val
> ver_values ver_value
333 %type
<menitm
> item_definitions menu_body
335 %type
<menexitm
> itemex_definitions menuex_body
336 %type
<exopt
> itemex_p_options itemex_options
337 %type
<msg
> messagetable
339 %type
<num
> item_options
340 %type
<nid
> nameid nameid_s ctlclass usertype
341 %type
<num
> acc_opt acc accs
342 %type
<iptr
> loadmemopts lamo lama
343 %type
<fntid
> opt_font opt_exfont opt_expr
345 %type
<lan
> opt_language
346 %type
<chars
> opt_characts
347 %type
<ver
> opt_version
350 %type
<tlbar
> toolbar
351 %type
<tlbarItems
> toolbar_items
352 %type
<dginit
> dlginit
353 %type
<styles
> optional_style_pair
355 %type
<style
> optional_style
364 /* First add stringtables to the resource-list */
365 rsc
= build_stt_resources
(sttres
);
366 /* 'build_stt_resources' returns a head and $1 is a tail */
375 /* Find the tail again */
376 while
($1 && $1->next
)
378 /* Now add any fontdirecory */
379 rsc
= build_fontdirs
($1);
380 /* 'build_fontdir' returns a head and $1 is a tail */
389 /* Final statement before were done */
390 resource_top
= get_resource_head
($1);
394 /* Resources are put into a linked list */
396 : /* Empty */ { $$
= NULL
; want_id
= 1; }
397 | resources resource
{
400 resource_t
*tail
= $2;
401 resource_t
*head
= $2;
410 /* Check for duplicate identifiers */
413 resource_t
*rsc
= $1;
416 if
(rsc
->type
== head
->type
417 && rsc
->lan
->id
== head
->lan
->id
418 && rsc
->lan
->sub
== head
->lan
->sub
419 && !compare_name_id
(rsc
->name
, head
->name
))
421 yyerror("Duplicate resource name '%s'", get_nameid_str
(rsc
->name
));
430 resource_t
*tail
= $1;
438 if
(!dont_want_id
) /* See comments in language parsing below */
443 * The following 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)
471 /* Parse top level resource definitions etc. */
473 : expr usrcvt resource_definition
{
477 if
($1 > 65535 ||
$1 < -32768)
478 yyerror("Resource's ID out of range (%d)", $1);
479 $$
->name
= new_name_id
();
480 $$
->name
->type
= name_ord
;
481 $$
->name
->name.i_name
= $1;
482 chat
("Got %s (%d)", get_typename
($3), $$
->name
->name.i_name
);
485 | tIDENT usrcvt resource_definition
{
489 $$
->name
= new_name_id
();
490 $$
->name
->type
= name_str
;
491 $$
->name
->name.s_name
= $1;
492 chat
("Got %s (%s)", get_typename
($3), $$
->name
->name.s_name
->str.cstr
);
496 /* Don't do anything, stringtables are converted to
497 * resource_t structures when we are finished parsing and
498 * the final rule of the parser is reduced (see above)
501 chat
("Got STRINGTABLE");
503 | tLANGUAGE
{want_nl
= 1; } expr
',' expr
{
504 /* We *NEED* the newline to delimit the expression.
505 * Otherwise, we would not be able to set the next
506 * want_id anymore because of the token-lookahead.
508 * However, we can test the lookahead-token for
509 * being "non-expression" type, in which case we
510 * continue. Fortunately, tNL is the only token that
511 * will break expression parsing and is implicitely
512 * void, so we just remove it. This scheme makes it
513 * possible to do some (not all) fancy preprocessor
515 * BTW, we also need to make sure that the next
516 * reduction of 'resources' above will *not* set
517 * want_id because we already have a lookahead that
520 if
(yychar != YYEMPTY
&& yychar != tNL
)
524 yychar = YYEMPTY
; /* Could use 'yyclearin', but we already need the*/
525 /* direct access to yychar in rule 'usrcvt' below. */
526 else if
(yychar == tIDENT
)
527 yywarning
("LANGUAGE statement not delimited with newline; next identifier might be wrong");
529 want_nl
= 0; /* We don't want it anymore if we didn't get it */
532 yywarning
("LANGUAGE not supported in 16-bit mode");
534 free
(currentlanguage
);
535 if
(get_language_codepage
($3, $5) == -1)
536 yyerror( "Language %04x is not supported", ($5<<10) + $3);
537 currentlanguage
= new_language
($3, $5);
539 chat
("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
544 * Remapping of numerical resource types
545 * (see also comment of called function below)
547 usrcvt
: /* Empty */ { yychar = rsrcid_to_token
(yychar); }
551 * Get a valid name/id
554 if
($1 > 65535 ||
$1 < -32768)
555 yyerror("Resource's ID out of range (%d)", $1);
558 $$
->name.i_name
= $1;
563 $$
->name.s_name
= $1;
568 * Extra string recognition for CLASS statement in dialogs
570 nameid_s: nameid
{ $$
= $1; }
574 $$
->name.s_name
= $1;
578 /* get the value for a single resource*/
580 : accelerators
{ $$
= new_resource
(res_acc
, $1, $1->memopt
, $1->lvc.language
); }
581 | bitmap
{ $$
= new_resource
(res_bmp
, $1, $1->memopt
, $1->data
->lvc.language
); }
584 if
($1->type
== res_anicur
)
586 $$
= rsc
= new_resource
(res_anicur
, $1->u.ani
, $1->u.ani
->memopt
, $1->u.ani
->data
->lvc.language
);
588 else if
($1->type
== res_curg
)
591 $$
= rsc
= new_resource
(res_curg
, $1->u.curg
, $1->u.curg
->memopt
, $1->u.curg
->lvc.language
);
592 for
(cur
= $1->u.curg
->cursorlist
; cur
; cur
= cur
->next
)
594 rsc
->prev
= new_resource
(res_cur
, cur
, $1->u.curg
->memopt
, $1->u.curg
->lvc.language
);
595 rsc
->prev
->next
= rsc
;
597 rsc
->name
= new_name_id
();
598 rsc
->name
->type
= name_ord
;
599 rsc
->name
->name.i_name
= cur
->id
;
603 internal_error
(__FILE__
, __LINE__
, "Invalid top-level type %d in cursor resource", $1->type
);
606 | dialog
{ $$
= new_resource
(res_dlg
, $1, $1->memopt
, $1->lvc.language
); }
609 $$
= new_resource
(res_dlgex
, $1, $1->memopt
, $1->lvc.language
);
613 | dlginit
{ $$
= new_resource
(res_dlginit
, $1, $1->memopt
, $1->data
->lvc.language
); }
614 | font
{ $$
= new_resource
(res_fnt
, $1, $1->memopt
, $1->data
->lvc.language
); }
615 | fontdir
{ $$
= new_resource
(res_fntdir
, $1, $1->memopt
, $1->data
->lvc.language
); }
618 if
($1->type
== res_aniico
)
620 $$
= rsc
= new_resource
(res_aniico
, $1->u.ani
, $1->u.ani
->memopt
, $1->u.ani
->data
->lvc.language
);
622 else if
($1->type
== res_icog
)
625 $$
= rsc
= new_resource
(res_icog
, $1->u.icog
, $1->u.icog
->memopt
, $1->u.icog
->lvc.language
);
626 for
(ico
= $1->u.icog
->iconlist
; ico
; ico
= ico
->next
)
628 rsc
->prev
= new_resource
(res_ico
, ico
, $1->u.icog
->memopt
, $1->u.icog
->lvc.language
);
629 rsc
->prev
->next
= rsc
;
631 rsc
->name
= new_name_id
();
632 rsc
->name
->type
= name_ord
;
633 rsc
->name
->name.i_name
= ico
->id
;
637 internal_error
(__FILE__
, __LINE__
, "Invalid top-level type %d in icon resource", $1->type
);
640 | menu
{ $$
= new_resource
(res_men
, $1, $1->memopt
, $1->lvc.language
); }
643 $$
= new_resource
(res_menex
, $1, $1->memopt
, $1->lvc.language
);
647 | messagetable
{ $$
= new_resource
(res_msg
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, $1->data
->lvc.language
); }
648 | rcdata
{ $$
= new_resource
(res_rdt
, $1, $1->memopt
, $1->data
->lvc.language
); }
649 | toolbar
{ $$
= new_resource
(res_toolbar
, $1, $1->memopt
, $1->lvc.language
); }
650 | userres
{ $$
= new_resource
(res_usr
, $1, $1->memopt
, $1->data
->lvc.language
); }
651 | versioninfo
{ $$
= new_resource
(res_ver
, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE
, $1->lvc.language
); }
655 filename: tFILENAME
{ $$
= make_filename
($1); }
656 | tIDENT
{ $$
= make_filename
($1); }
657 | tSTRING
{ $$
= make_filename
($1); }
660 /* ------------------------------ Bitmap ------------------------------ */
661 bitmap
: tBITMAP loadmemopts file_raw
{ $$
= new_bitmap
($3, $2); }
664 /* ------------------------------ Cursor ------------------------------ */
665 cursor
: tCURSOR loadmemopts file_raw
{
667 if
($3->size
> 4 && !memcmp
($3->data
, riff
, sizeof
(riff
)))
669 $$
->type
= res_anicur
;
670 $$
->u.ani
= new_ani_curico
(res_anicur
, $3, $2);
675 $$
->u.curg
= new_cursor_group
($3, $2);
680 /* ------------------------------ Icon ------------------------------ */
681 icon
: tICON loadmemopts file_raw
{
683 if
($3->size
> 4 && !memcmp
($3->data
, riff
, sizeof
(riff
)))
685 $$
->type
= res_aniico
;
686 $$
->u.ani
= new_ani_curico
(res_aniico
, $3, $2);
691 $$
->u.icog
= new_icon_group
($3, $2);
696 /* ------------------------------ Font ------------------------------ */
698 * The reading of raw_data for fonts is a Borland BRC
699 * extension. MS generates an error. However, it is
700 * most logical to support this, considering how wine
701 * enters things in CVS (ascii).
703 font
: tFONT loadmemopts file_raw
{ $$
= new_font
($3, $2); }
707 * The fontdir is a Borland BRC extension which only
708 * reads the data as 'raw_data' from the file.
709 * I don't know whether it is interpreted.
710 * The fontdir is generated if it was not present and
711 * fonts are defined in the source.
713 fontdir
: tFONTDIR loadmemopts file_raw
{ $$
= new_fontdir
($3, $2); }
716 /* ------------------------------ MessageTable ------------------------------ */
717 /* It might be interesting to implement the MS Message compiler here as well
718 * to get everything in one source. Might be a future project.
721 : tMESSAGETABLE loadmemopts file_raw
{
723 yywarning
("MESSAGETABLE not supported in 16-bit mode");
724 $$
= new_messagetable
($3, $2);
728 /* ------------------------------ RCData ------------------------------ */
729 rcdata
: tRCDATA loadmemopts file_raw
{ $$
= new_rcdata
($3, $2); }
732 /* ------------------------------ DLGINIT ------------------------------ */
733 dlginit
: tDLGINIT loadmemopts file_raw
{ $$
= new_dlginit
($3, $2); }
736 /* ------------------------------ UserType ------------------------------ */
737 userres
: usertype loadmemopts file_raw
{
738 #ifdef WORDS_BIGENDIAN
739 if
(pedantic
&& byteorder
!= WRC_BO_LITTLE
)
741 if
(pedantic
&& byteorder
== WRC_BO_BIG
)
743 yywarning
("Byteordering is not little-endian and type cannot be interpreted");
744 $$
= new_user
($1, $3, $2);
751 $$
->name.i_name
= $1;
756 $$
->name.s_name
= $1;
760 /* ------------------------------ Accelerator ------------------------------ */
762 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND
{
763 $$
= new_accelerator
();
771 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE
;
774 yyerror("Accelerator table must have at least one entry");
775 $$
->events
= get_event_head
($5);
781 if
(!$$
->lvc.language
)
782 $$
->lvc.language
= dup_language
(currentlanguage
);
786 events
: /* Empty */ { $$
=NULL
; }
787 | events tSTRING
',' expr acc_opt
{ $$
=add_string_event
($2, $4, $5, $1); }
788 | events expr
',' expr acc_opt
{ $$
=add_event
($2, $4, $5, $1); }
792 * The empty rule generates a s/r conflict because of {bi,u}nary expr
793 * on - and +. It cannot be solved in any way because it is the same as
794 * the if/then/else problem (LALR(1) problem). The conflict is moved
795 * away by forcing it to be in the expression handling below.
797 acc_opt
: /* Empty */ { $$
= 0; }
798 |
',' accs
{ $$
= $2; }
801 accs
: acc
{ $$
= $1; }
802 | accs
',' acc
{ $$
= $1 |
$3; }
805 acc
: tNOINVERT
{ $$
= WRC_AF_NOINVERT
; }
806 | tSHIFT
{ $$
= WRC_AF_SHIFT
; }
807 | tCONTROL
{ $$
= WRC_AF_CONTROL
; }
808 | tALT
{ $$
= WRC_AF_ALT
; }
809 | tASCII
{ $$
= WRC_AF_ASCII
; }
810 | tVIRTKEY
{ $$
= WRC_AF_VIRTKEY
; }
813 /* ------------------------------ Dialog ------------------------------ */
814 /* FIXME: Support EXSTYLE in the dialog line itself */
815 dialog
: tDIALOG loadmemopts expr
',' expr
',' expr
',' expr dlg_attributes
823 $10->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
828 $10->controls
= get_control_head
($12);
832 $$
->style
= new_style
(0,0);
833 $$
->style
->or_mask
= WS_POPUP
;
837 $$
->style
->or_mask |
= WS_CAPTION
;
839 $$
->style
->or_mask |
= DS_SETFONT
;
841 $$
->style
->or_mask
&= ~
($$
->style
->and_mask
);
842 $$
->style
->and_mask
= 0;
844 if
(!$$
->lvc.language
)
845 $$
->lvc.language
= dup_language
(currentlanguage
);
850 : /* Empty */ { $$
=new_dialog
(); }
851 | dlg_attributes tSTYLE style
{ $$
=dialog_style
($3,$1); }
852 | dlg_attributes tEXSTYLE style
{ $$
=dialog_exstyle
($3,$1); }
853 | dlg_attributes tCAPTION tSTRING
{ $$
=dialog_caption
($3,$1); }
854 | dlg_attributes opt_font
{ $$
=dialog_font
($2,$1); }
855 | dlg_attributes tCLASS nameid_s
{ $$
=dialog_class
($3,$1); }
856 | dlg_attributes tMENU nameid
{ $$
=dialog_menu
($3,$1); }
857 | dlg_attributes opt_language
{ $$
=dialog_language
($2,$1); }
858 | dlg_attributes opt_characts
{ $$
=dialog_characteristics
($2,$1); }
859 | dlg_attributes opt_version
{ $$
=dialog_version
($2,$1); }
862 ctrls
: /* Empty */ { $$
= NULL
; }
863 | ctrls tCONTROL gen_ctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
864 | ctrls tEDITTEXT ctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
865 | ctrls tLISTBOX ctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
866 | ctrls tCOMBOBOX ctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
867 | ctrls tSCROLLBAR ctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
868 | ctrls tCHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
869 | ctrls tDEFPUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
870 | ctrls tGROUPBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
871 | ctrls tPUSHBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
872 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
873 | ctrls tRADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
874 | ctrls tAUTO3STATE lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
875 | ctrls tSTATE3 lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
876 | ctrls tAUTOCHECKBOX lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
877 | ctrls tAUTORADIOBUTTON lab_ctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
878 | ctrls tLTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
879 | ctrls tCTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
880 | ctrls tRTEXT lab_ctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
881 /* special treatment for icons, as the extent is optional */
882 | ctrls tICON nameid_s opt_comma expr
',' expr
',' expr iconinfo
{
887 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
892 : tSTRING opt_comma expr
',' expr
',' expr
',' expr
',' expr optional_style
{
894 $$
->title
= new_name_id
();
895 $$
->title
->type
= name_str
;
896 $$
->title
->name.s_name
= $1;
911 : expr
',' expr
',' expr
',' expr
',' expr optional_style
{
926 iconinfo: /* Empty */
927 { $$
= new_control
(); }
929 |
',' expr
',' expr
{
934 |
',' expr
',' expr
',' style
{
941 |
',' expr
',' expr
',' style
',' style
{
948 $$
->gotexstyle
= TRUE
;
952 gen_ctrl: nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr
',' style
{
956 $$
->ctlclass
= convert_ctlclass
($5);
964 $$
->gotexstyle
= TRUE
;
966 | nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr
{
970 $$
->ctlclass
= convert_ctlclass
($5);
981 : tFONT expr
',' tSTRING
{ $$
= new_font_id
($2, $4, 0, 0); }
984 /* ------------------------------ style flags ------------------------------ */
985 optional_style
/* Abbused once to get optional ExStyle */
986 : /* Empty */ { $$
= NULL
; }
987 |
',' style
{ $$
= $2; }
991 : /* Empty */ { $$
= NULL
; }
992 |
',' style
{ $$
= new_style_pair
($2, 0); }
993 |
',' style
',' style
{ $$
= new_style_pair
($2, $4); }
997 : style
'|' style
{ $$
= new_style
($1->or_mask |
$3->or_mask
, $1->and_mask |
$3->and_mask
); free
($1); free
($3);}
998 |
'(' style
')' { $$
= $2; }
999 | any_num
{ $$
= new_style
($1, 0); }
1000 | tNOT any_num
{ $$
= new_style
(0, $2); }
1006 $$
->type
= name_ord
;
1007 $$
->name.i_name
= $1;
1011 $$
->type
= name_str
;
1012 $$
->name.s_name
= $1;
1016 /* ------------------------------ DialogEx ------------------------------ */
1017 dialogex: tDIALOGEX loadmemopts expr
',' expr
',' expr
',' expr helpid dlgex_attribs
1018 tBEGIN exctrls tEND
{
1020 yywarning
("DIALOGEX not supported in 16-bit mode");
1023 $11->memopt
= *($2);
1027 $11->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1034 $11->helpid
= *($10);
1035 $11->gothelpid
= TRUE
;
1038 $11->controls
= get_control_head
($13);
1041 assert
($$
->style
!= NULL
);
1044 $$
->style
->or_mask
= WS_POPUP
;
1045 $$
->gotstyle
= TRUE
;
1048 $$
->style
->or_mask |
= WS_CAPTION
;
1050 $$
->style
->or_mask |
= DS_SETFONT
;
1052 $$
->style
->or_mask
&= ~
($$
->style
->and_mask
);
1053 $$
->style
->and_mask
= 0;
1055 if
(!$$
->lvc.language
)
1056 $$
->lvc.language
= dup_language
(currentlanguage
);
1061 : /* Empty */ { $$
=new_dialogex
(); }
1062 | dlgex_attribs tSTYLE style
{ $$
=dialogex_style
($3,$1); }
1063 | dlgex_attribs tEXSTYLE style
{ $$
=dialogex_exstyle
($3,$1); }
1064 | dlgex_attribs tCAPTION tSTRING
{ $$
=dialogex_caption
($3,$1); }
1065 | dlgex_attribs opt_font
{ $$
=dialogex_font
($2,$1); }
1066 | dlgex_attribs opt_exfont
{ $$
=dialogex_font
($2,$1); }
1067 | dlgex_attribs tCLASS nameid_s
{ $$
=dialogex_class
($3,$1); }
1068 | dlgex_attribs tMENU nameid
{ $$
=dialogex_menu
($3,$1); }
1069 | dlgex_attribs opt_language
{ $$
=dialogex_language
($2,$1); }
1070 | dlgex_attribs opt_characts
{ $$
=dialogex_characteristics
($2,$1); }
1071 | dlgex_attribs opt_version
{ $$
=dialogex_version
($2,$1); }
1074 exctrls
: /* Empty */ { $$
= NULL
; }
1075 | exctrls tCONTROL gen_exctrl
{ $$
=ins_ctrl
(-1, 0, $3, $1); }
1076 | exctrls tEDITTEXT exctrl_desc
{ $$
=ins_ctrl
(CT_EDIT
, 0, $3, $1); }
1077 | exctrls tLISTBOX exctrl_desc
{ $$
=ins_ctrl
(CT_LISTBOX
, 0, $3, $1); }
1078 | exctrls tCOMBOBOX exctrl_desc
{ $$
=ins_ctrl
(CT_COMBOBOX
, 0, $3, $1); }
1079 | exctrls tSCROLLBAR exctrl_desc
{ $$
=ins_ctrl
(CT_SCROLLBAR
, 0, $3, $1); }
1080 | exctrls tCHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_CHECKBOX
, $3, $1); }
1081 | exctrls tDEFPUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_DEFPUSHBUTTON
, $3, $1); }
1082 | exctrls tGROUPBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_GROUPBOX
, $3, $1);}
1083 | exctrls tPUSHBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_PUSHBUTTON
, $3, $1); }
1084 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1085 | exctrls tRADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_RADIOBUTTON
, $3, $1); }
1086 | exctrls tAUTO3STATE lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTO3STATE
, $3, $1); }
1087 | exctrls tSTATE3 lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_3STATE
, $3, $1); }
1088 | exctrls tAUTOCHECKBOX lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTOCHECKBOX
, $3, $1); }
1089 | exctrls tAUTORADIOBUTTON lab_exctrl
{ $$
=ins_ctrl
(CT_BUTTON
, BS_AUTORADIOBUTTON
, $3, $1); }
1090 | exctrls tLTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_LEFT
, $3, $1); }
1091 | exctrls tCTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_CENTER
, $3, $1); }
1092 | exctrls tRTEXT lab_exctrl
{ $$
=ins_ctrl
(CT_STATIC
, SS_RIGHT
, $3, $1); }
1093 /* special treatment for icons, as the extent is optional */
1094 | exctrls tICON nameid_s opt_comma expr
',' expr
',' expr iconinfo
{
1099 $$
= ins_ctrl
(CT_STATIC
, SS_ICON
, $10, $1);
1104 : nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
','
1105 expr
',' style helpid opt_data
{
1109 $$
->ctlclass
= convert_ctlclass
($5);
1111 $$
->gotstyle
= TRUE
;
1119 $$
->gotexstyle
= TRUE
;
1123 $$
->helpid
= *($18);
1124 $$
->gothelpid
= TRUE
;
1129 | nameid_s opt_comma expr
',' ctlclass
',' style
',' expr
',' expr
',' expr
',' expr opt_data
{
1134 $$
->gotstyle
= TRUE
;
1135 $$
->ctlclass
= convert_ctlclass
($5);
1145 : tSTRING opt_comma expr
',' expr
',' expr
',' expr
',' expr optional_style_pair helpid opt_data
{
1147 $$
->title
= new_name_id
();
1148 $$
->title
->type
= name_str
;
1149 $$
->title
->name.s_name
= $1;
1157 $$
->style
= $12->style
;
1158 $$
->gotstyle
= TRUE
;
1162 $$
->exstyle
= $12->exstyle
;
1163 $$
->gotexstyle
= TRUE
;
1173 : expr
',' expr
',' expr
',' expr
',' expr optional_style_pair helpid opt_data
{
1182 $$
->style
= $10->style
;
1183 $$
->gotstyle
= TRUE
;
1187 $$
->exstyle
= $10->exstyle
;
1188 $$
->gotexstyle
= TRUE
;
1196 opt_data: /* Empty */ { $$
= NULL
; }
1197 | raw_data
{ $$
= $1; }
1200 helpid
: /* Empty */ { $$
= NULL
; }
1201 |
',' expr
{ $$
= new_int
($2); }
1205 : tFONT expr
',' tSTRING
',' expr
',' expr opt_expr
{ $$
= new_font_id
($2, $4, $6, $8); }
1209 * FIXME: This odd expression is here to nullify an extra token found
1210 * in some appstudio produced resources which appear to do nothing.
1212 opt_expr: /* Empty */ { $$
= NULL
; }
1213 |
',' expr
{ $$
= NULL
; }
1216 /* ------------------------------ Menu ------------------------------ */
1217 menu
: tMENU loadmemopts opt_lvc menu_body
{
1219 yyerror("Menu must contain items");
1227 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1228 $$
->items
= get_item_head
($4);
1234 if
(!$$
->lvc.language
)
1235 $$
->lvc.language
= dup_language
(currentlanguage
);
1240 : tBEGIN item_definitions tEND
{ $$
= $2; }
1244 : /* Empty */ {$$
= NULL
;}
1245 | item_definitions tMENUITEM tSTRING opt_comma expr item_options
{
1254 | item_definitions tMENUITEM tSEPARATOR
{
1260 | item_definitions tPOPUP tSTRING item_options menu_body
{
1261 $$
= new_menu_item
();
1265 $$
->popup
= get_item_head
($5);
1270 /* NOTE: item_options is right recursive because it would introduce
1271 * a shift/reduce conflict on ',' in itemex_options due to the
1272 * empty rule here. The parser is now forced to look beyond the ','
1273 * before reducing (force shift).
1274 * Right recursion here is not a problem because we cannot expect
1275 * more than 7 parserstack places to be occupied while parsing this
1276 * (who would want to specify a MF_x flag twice?).
1279 : /* Empty */ { $$
= 0; }
1280 |
',' tCHECKED item_options
{ $$
= $3 | MF_CHECKED
; }
1281 |
',' tGRAYED item_options
{ $$
= $3 | MF_GRAYED
; }
1282 |
',' tHELP item_options
{ $$
= $3 | MF_HELP
; }
1283 |
',' tINACTIVE item_options
{ $$
= $3 | MF_DISABLED
; }
1284 |
',' tMENUBARBREAK item_options
{ $$
= $3 | MF_MENUBARBREAK
; }
1285 |
',' tMENUBREAK item_options
{ $$
= $3 | MF_MENUBREAK
; }
1288 /* ------------------------------ MenuEx ------------------------------ */
1289 menuex
: tMENUEX loadmemopts opt_lvc menuex_body
{
1291 yywarning
("MENUEX not supported in 16-bit mode");
1293 yyerror("MenuEx must contain items");
1301 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE
;
1302 $$
->items
= get_itemex_head
($4);
1308 if
(!$$
->lvc.language
)
1309 $$
->lvc.language
= dup_language
(currentlanguage
);
1314 : tBEGIN itemex_definitions tEND
{ $$
= $2; }
1318 : /* Empty */ {$$
= NULL
; }
1319 | itemex_definitions tMENUITEM tSTRING itemex_options
{
1320 $$
= new_menuex_item
();
1326 $$
->type
= $4->type
;
1327 $$
->state
= $4->state
;
1328 $$
->helpid
= $4->helpid
;
1329 $$
->gotid
= $4->gotid
;
1330 $$
->gottype
= $4->gottype
;
1331 $$
->gotstate
= $4->gotstate
;
1332 $$
->gothelpid
= $4->gothelpid
;
1335 | itemex_definitions tMENUITEM tSEPARATOR
{
1336 $$
= new_menuex_item
();
1341 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body
{
1342 $$
= new_menuex_item
();
1346 $$
->popup
= get_itemex_head
($5);
1349 $$
->type
= $4->type
;
1350 $$
->state
= $4->state
;
1351 $$
->helpid
= $4->helpid
;
1352 $$
->gotid
= $4->gotid
;
1353 $$
->gottype
= $4->gottype
;
1354 $$
->gotstate
= $4->gotstate
;
1355 $$
->gothelpid
= $4->gothelpid
;
1361 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1363 $$
= new_itemex_opt
($2, 0, 0, 0);
1366 |
',' e_expr
',' e_expr item_options
{
1367 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $5, 0);
1370 $$
->gotstate
= TRUE
;
1374 |
',' e_expr
',' e_expr
',' expr
{
1375 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1378 $$
->gotstate
= TRUE
;
1385 : /* Empty */ { $$
= new_itemex_opt
(0, 0, 0, 0); }
1387 $$
= new_itemex_opt
($2, 0, 0, 0);
1390 |
',' e_expr
',' expr
{
1391 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4, 0, 0);
1396 |
',' e_expr
',' e_expr
',' expr
{
1397 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6, 0);
1402 $$
->gotstate
= TRUE
;
1404 |
',' e_expr
',' e_expr
',' e_expr
',' expr
{
1405 $$
= new_itemex_opt
($2 ?
*($2) : 0, $4 ?
*($4) : 0, $6 ?
*($6) : 0, $8);
1411 $$
->gotstate
= TRUE
;
1412 $$
->gothelpid
= TRUE
;
1416 /* ------------------------------ StringTable ------------------------------ */
1417 /* Stringtables are parsed differently than other resources because their
1418 * layout is substantially different from other resources.
1419 * The table is parsed through a _global_ variable 'tagstt' which holds the
1420 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1421 * list of stringtables of different languages.
1424 : stt_head tBEGIN strings tEND
{
1427 yyerror("Stringtable must have at least one entry");
1432 /* Check if we added to a language table or created
1435 for
(stt
= sttres
; stt
; stt
= stt
->next
)
1442 /* It is a new one */
1445 sttres
->prev
= tagstt
;
1446 tagstt
->next
= sttres
;
1452 /* Else were done */
1456 free
(tagstt_memopt
);
1457 tagstt_memopt
= NULL
;
1464 /* This is to get the language of the currently parsed stringtable */
1465 stt_head: tSTRINGTABLE loadmemopts opt_lvc
{
1466 if
((tagstt
= find_stringtable
($3)) == NULL
)
1467 tagstt
= new_stringtable
($3);
1469 tagstt_version
= $3->version
;
1470 tagstt_characts
= $3->characts
;
1476 strings
: /* Empty */ { $$
= NULL
; }
1477 | strings expr opt_comma tSTRING
{
1479 assert
(tagstt
!= NULL
);
1480 if
($2 > 65535 ||
$2 < -32768)
1481 yyerror("Stringtable entry's ID out of range (%d)", $2);
1482 /* Search for the ID */
1483 for
(i
= 0; i
< tagstt
->nentries
; i
++)
1485 if
(tagstt
->entries
[i
].id
== $2)
1486 yyerror("Stringtable ID %d already in use", $2);
1488 /* If we get here, then we have a new unique entry */
1490 tagstt
->entries
= xrealloc
(tagstt
->entries
, sizeof
(tagstt
->entries
[0]) * tagstt
->nentries
);
1491 tagstt
->entries
[tagstt
->nentries
-1].id
= $2;
1492 tagstt
->entries
[tagstt
->nentries
-1].str
= $4;
1494 tagstt
->entries
[tagstt
->nentries
-1].memopt
= *tagstt_memopt
;
1496 tagstt
->entries
[tagstt
->nentries
-1].memopt
= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1497 tagstt
->entries
[tagstt
->nentries
-1].version
= tagstt_version
;
1498 tagstt
->entries
[tagstt
->nentries
-1].characts
= tagstt_characts
;
1500 if
(pedantic
&& !$4->size
)
1501 yywarning
("Zero length strings make no sense");
1502 if
(!win32
&& $4->size
> 254)
1503 yyerror("Stringtable entry more than 254 characters");
1504 if
(win32
&& $4->size
> 65534) /* Hmm..., does this happen? */
1505 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1510 opt_comma
/* There seem to be two ways to specify a stringtable... */
1515 /* ------------------------------ VersionInfo ------------------------------ */
1517 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND
{
1525 $$
->memopt
= WRC_MO_MOVEABLE |
(win32 ? WRC_MO_PURE
: 0);
1526 $$
->blocks
= get_ver_block_head
($5);
1527 /* Set language; there is no version or characteristics */
1528 $$
->lvc.language
= dup_language
(currentlanguage
);
1533 : /* Empty */ { $$
= new_versioninfo
(); }
1534 | fix_version tFILEVERSION expr
',' expr
',' expr
',' expr
{
1536 yyerror("FILEVERSION already defined");
1538 $$
->filever_maj1
= $3;
1539 $$
->filever_maj2
= $5;
1540 $$
->filever_min1
= $7;
1541 $$
->filever_min2
= $9;
1544 | fix_version tPRODUCTVERSION expr
',' expr
',' expr
',' expr
{
1546 yyerror("PRODUCTVERSION already defined");
1548 $$
->prodver_maj1
= $3;
1549 $$
->prodver_maj2
= $5;
1550 $$
->prodver_min1
= $7;
1551 $$
->prodver_min2
= $9;
1554 | fix_version tFILEFLAGS expr
{
1556 yyerror("FILEFLAGS already defined");
1561 | fix_version tFILEFLAGSMASK expr
{
1563 yyerror("FILEFLAGSMASK already defined");
1565 $$
->fileflagsmask
= $3;
1568 | fix_version tFILEOS expr
{
1570 yyerror("FILEOS already defined");
1575 | fix_version tFILETYPE expr
{
1577 yyerror("FILETYPE already defined");
1582 | fix_version tFILESUBTYPE expr
{
1584 yyerror("FILESUBTYPE already defined");
1586 $$
->filesubtype
= $3;
1592 : /* Empty */ { $$
= NULL
; }
1593 | ver_blocks ver_block
{
1602 : tBLOCK tSTRING tBEGIN ver_values tEND
{
1603 $$
= new_ver_block
();
1605 $$
->values
= get_ver_value_head
($4);
1610 : /* Empty */ { $$
= NULL
; }
1611 | ver_values ver_value
{
1621 $$
= new_ver_value
();
1622 $$
->type
= val_block
;
1623 $$
->value.block
= $1;
1625 | tVALUE tSTRING
',' tSTRING
{
1626 $$
= new_ver_value
();
1631 | tVALUE tSTRING
',' ver_words
{
1632 $$
= new_ver_value
();
1633 $$
->type
= val_words
;
1635 $$
->value.words
= $4;
1640 : expr
{ $$
= new_ver_words
($1); }
1641 | ver_words
',' expr
{ $$
= add_ver_words
($1, $3); }
1644 /* ------------------------------ Toolbar ------------------------------ */
1645 toolbar: tTOOLBAR loadmemopts expr
',' expr opt_lvc tBEGIN toolbar_items tEND
{
1647 toolbar_item_t
*items
= get_tlbr_buttons_head
($8, &nitems
);
1648 $$
= new_toolbar
($3, $5, items
, nitems
);
1656 $$
->memopt
= WRC_MO_MOVEABLE | WRC_MO_PURE
;
1663 if
(!$$
->lvc.language
)
1665 $$
->lvc.language
= dup_language
(currentlanguage
);
1671 : /* Empty */ { $$
= NULL
; }
1672 | toolbar_items tBUTTON expr
{
1673 toolbar_item_t
*idrec
= new_toolbar_item
();
1675 $$
= ins_tlbr_button
($1, idrec
);
1677 | toolbar_items tSEPARATOR
{
1678 toolbar_item_t
*idrec
= new_toolbar_item
();
1680 $$
= ins_tlbr_button
($1, idrec
);
1684 /* ------------------------------ Memory options ------------------------------ */
1686 : /* Empty */ { $$
= NULL
; }
1687 | loadmemopts lamo
{
1697 | loadmemopts lama
{
1706 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE
;
1712 lamo
: tPRELOAD
{ $$
= new_int
(WRC_MO_PRELOAD
); }
1713 | tMOVEABLE
{ $$
= new_int
(WRC_MO_MOVEABLE
); }
1714 | tDISCARDABLE
{ $$
= new_int
(WRC_MO_DISCARDABLE
); }
1715 | tPURE
{ $$
= new_int
(WRC_MO_PURE
); }
1718 lama
: tLOADONCALL
{ $$
= new_int
(~WRC_MO_PRELOAD
); }
1719 | tFIXED
{ $$
= new_int
(~WRC_MO_MOVEABLE
); }
1720 | tIMPURE
{ $$
= new_int
(~WRC_MO_PURE
); }
1723 /* ------------------------------ Win32 options ------------------------------ */
1724 opt_lvc
: /* Empty */ { $$
= new_lvc
(); }
1725 | opt_lvc opt_language
{
1727 yywarning
("LANGUAGE not supported in 16-bit mode");
1729 yyerror("Language already defined");
1733 | opt_lvc opt_characts
{
1735 yywarning
("CHARACTERISTICS not supported in 16-bit mode");
1737 yyerror("Characteristics already defined");
1741 | opt_lvc opt_version
{
1743 yywarning
("VERSION not supported in 16-bit mode");
1745 yyerror("Version already defined");
1752 * This here is another s/r conflict on {bi,u}nary + and -.
1753 * It is due to the look-ahead which must determine when the
1754 * rule opt_language ends. It could be solved with adding a
1755 * tNL at the end, but that seems unreasonable to do.
1756 * The conflict is now moved to the expression handling below.
1759 : tLANGUAGE expr
',' expr
{ $$
= new_language
($2, $4);
1760 if
(get_language_codepage
($2, $4) == -1)
1761 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1766 : tCHARACTERISTICS expr
{ $$
= new_characts
($2); }
1770 : tVERSION expr
{ $$
= new_version
($2); }
1773 /* ------------------------------ Raw data handling ------------------------------ */
1774 raw_data: opt_lvc tBEGIN raw_elements tEND
{
1781 if
(!$3->lvc.language
)
1782 $3->lvc.language
= dup_language
(currentlanguage
);
1789 : tRAWDATA
{ $$
= $1; }
1790 | tNUMBER
{ $$
= int2raw_data
($1); }
1791 | tLNUMBER
{ $$
= long2raw_data
($1); }
1792 | tSTRING
{ $$
= str2raw_data
($1); }
1793 | raw_elements opt_comma tRAWDATA
{ $$
= merge_raw_data
($1, $3); free
($3->data
); free
($3); }
1794 | raw_elements opt_comma tNUMBER
{ $$
= merge_raw_data_int
($1, $3); }
1795 | raw_elements opt_comma tLNUMBER
{ $$
= merge_raw_data_long
($1, $3); }
1796 | raw_elements opt_comma tSTRING
{ $$
= merge_raw_data_str
($1, $3); }
1799 /* File data or raw data */
1800 file_raw: filename
{ $$
= load_file
($1,dup_language
(currentlanguage
)); }
1801 | raw_data
{ $$
= $1; }
1804 /* ------------------------------ Win32 expressions ------------------------------ */
1805 /* All win16 numbers are also handled here. This is inconsistent with MS'
1806 * resource compiler, but what the heck, its just handy to have.
1808 e_expr
: /* Empty */ { $$
= 0; }
1809 | expr
{ $$
= new_int
($1); }
1812 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1813 expr
: xpr
{ $$
= ($1); }
1816 xpr
: xpr
'+' xpr
{ $$
= ($1) + ($3); }
1817 | xpr
'-' xpr
{ $$
= ($1) - ($3); }
1818 | xpr
'|' xpr
{ $$
= ($1) |
($3); }
1819 | xpr
'&' xpr
{ $$
= ($1) & ($3); }
1820 | xpr
'*' xpr
{ $$
= ($1) * ($3); }
1821 | xpr
'/' xpr
{ $$
= ($1) / ($3); }
1822 | xpr
'^' xpr
{ $$
= ($1) ^
($3); }
1823 |
'~' xpr
{ $$
= ~
($2); }
1824 |
'-' xpr %prec pUPM
{ $$
= -($2); }
1825 |
'+' xpr %prec pUPM
{ $$
= $2; }
1826 |
'(' xpr
')' { $$
= $2; }
1827 | any_num
{ $$
= $1; }
1828 | tNOT any_num
{ $$
= ~
($2); }
1831 any_num
: tNUMBER
{ $$
= $1; }
1832 | tLNUMBER
{ $$
= $1; }
1836 /* Dialog specific functions */
1837 static dialog_t
*dialog_style
(style_t
* st
, dialog_t
*dlg
)
1839 assert
(dlg
!= NULL
);
1840 if
(dlg
->style
== NULL
)
1842 dlg
->style
= new_style
(0,0);
1847 yywarning
("Style already defined, or-ing together");
1851 dlg
->style
->or_mask
= 0;
1852 dlg
->style
->and_mask
= 0;
1854 dlg
->style
->or_mask |
= st
->or_mask
;
1855 dlg
->style
->and_mask |
= st
->and_mask
;
1856 dlg
->gotstyle
= TRUE
;
1861 static dialog_t
*dialog_exstyle
(style_t
*st
, dialog_t
*dlg
)
1863 assert
(dlg
!= NULL
);
1864 if
(dlg
->exstyle
== NULL
)
1866 dlg
->exstyle
= new_style
(0,0);
1871 yywarning
("ExStyle already defined, or-ing together");
1875 dlg
->exstyle
->or_mask
= 0;
1876 dlg
->exstyle
->and_mask
= 0;
1878 dlg
->exstyle
->or_mask |
= st
->or_mask
;
1879 dlg
->exstyle
->and_mask |
= st
->and_mask
;
1880 dlg
->gotexstyle
= TRUE
;
1885 static dialog_t
*dialog_caption
(string_t
*s
, dialog_t
*dlg
)
1887 assert
(dlg
!= NULL
);
1889 yyerror("Caption already defined");
1894 static dialog_t
*dialog_font
(font_id_t
*f
, dialog_t
*dlg
)
1896 assert
(dlg
!= NULL
);
1898 yyerror("Font already defined");
1903 static dialog_t
*dialog_class
(name_id_t
*n
, dialog_t
*dlg
)
1905 assert
(dlg
!= NULL
);
1907 yyerror("Class already defined");
1912 static dialog_t
*dialog_menu
(name_id_t
*m
, dialog_t
*dlg
)
1914 assert
(dlg
!= NULL
);
1916 yyerror("Menu already defined");
1921 static dialog_t
*dialog_language
(language_t
*l
, dialog_t
*dlg
)
1923 assert
(dlg
!= NULL
);
1924 if
(dlg
->lvc.language
)
1925 yyerror("Language already defined");
1926 dlg
->lvc.language
= l
;
1930 static dialog_t
*dialog_characteristics
(characts_t
*c
, dialog_t
*dlg
)
1932 assert
(dlg
!= NULL
);
1933 if
(dlg
->lvc.characts
)
1934 yyerror("Characteristics already defined");
1935 dlg
->lvc.characts
= c
;
1939 static dialog_t
*dialog_version
(version_t
*v
, dialog_t
*dlg
)
1941 assert
(dlg
!= NULL
);
1942 if
(dlg
->lvc.version
)
1943 yyerror("Version already defined");
1944 dlg
->lvc.version
= v
;
1948 /* Controls specific functions */
1949 static control_t
*ins_ctrl
(int type
, int special_style
, control_t
*ctrl
, control_t
*prev
)
1951 /* Hm... this seems to be jammed in at all time... */
1952 int defaultstyle
= WS_CHILD | WS_VISIBLE
;
1954 assert
(ctrl
!= NULL
);
1962 ctrl
->ctlclass
= new_name_id
();
1963 ctrl
->ctlclass
->type
= name_ord
;
1964 ctrl
->ctlclass
->name.i_name
= type
;
1970 if
(special_style
!= BS_GROUPBOX
&& special_style
!= BS_RADIOBUTTON
)
1971 defaultstyle |
= WS_TABSTOP
;
1974 defaultstyle |
= WS_TABSTOP | WS_BORDER
;
1977 defaultstyle |
= LBS_NOTIFY | WS_BORDER
;
1980 if
(!(ctrl
->style
->or_mask
& (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST
)))
1981 defaultstyle |
= CBS_SIMPLE
;
1984 if
(special_style
== SS_CENTER || special_style
== SS_LEFT || special_style
== SS_RIGHT
)
1985 defaultstyle |
= WS_GROUP
;
1989 if
(!ctrl
->gotstyle
) /* Handle default style setting */
1994 defaultstyle |
= ES_LEFT
;
1997 defaultstyle |
= LBS_NOTIFY
;
2000 defaultstyle |
= CBS_SIMPLE | WS_TABSTOP
;
2003 defaultstyle |
= SBS_HORZ
;
2006 switch
(special_style
)
2009 case BS_DEFPUSHBUTTON
:
2011 /* case BS_PUSHBOX: */
2012 case BS_AUTORADIOBUTTON
:
2015 case BS_AUTOCHECKBOX
:
2016 defaultstyle |
= WS_TABSTOP
;
2019 yywarning
("Unknown default button control-style 0x%08x", special_style
);
2021 case BS_RADIOBUTTON
:
2027 switch
(special_style
)
2032 defaultstyle |
= WS_GROUP
;
2034 case SS_ICON
: /* Special case */
2037 yywarning
("Unknown default static control-style 0x%08x", special_style
);
2041 case
-1: /* Generic control */
2045 yyerror("Internal error (report this): Got weird control type 0x%08x", type
);
2049 /* The SS_ICON flag is always forced in for icon controls */
2050 if
(type
== CT_STATIC
&& special_style
== SS_ICON
)
2051 defaultstyle |
= SS_ICON
;
2053 if
(!ctrl
->gotstyle
)
2054 ctrl
->style
= new_style
(0,0);
2056 /* combine all styles */
2057 ctrl
->style
->or_mask
= ctrl
->style
->or_mask | defaultstyle | special_style
;
2058 ctrl
->gotstyle
= TRUE
;
2060 /* combine with NOT mask */
2063 ctrl
->style
->or_mask
&= ~
(ctrl
->style
->and_mask
);
2064 ctrl
->style
->and_mask
= 0;
2066 if
(ctrl
->gotexstyle
)
2068 ctrl
->exstyle
->or_mask
&= ~
(ctrl
->exstyle
->and_mask
);
2069 ctrl
->exstyle
->and_mask
= 0;
2074 static name_id_t
*convert_ctlclass
(name_id_t
*cls
)
2079 if
(cls
->type
== name_ord
)
2081 assert
(cls
->type
== name_str
);
2082 if
(cls
->type
== str_unicode
)
2084 yyerror("Don't yet support unicode class comparison");
2087 cc
= cls
->name.s_name
->str.cstr
;
2089 if
(!strcasecmp
("BUTTON", cc
))
2091 else if
(!strcasecmp
("COMBOBOX", cc
))
2092 iclass
= CT_COMBOBOX
;
2093 else if
(!strcasecmp
("LISTBOX", cc
))
2094 iclass
= CT_LISTBOX
;
2095 else if
(!strcasecmp
("EDIT", cc
))
2097 else if
(!strcasecmp
("STATIC", cc
))
2099 else if
(!strcasecmp
("SCROLLBAR", cc
))
2100 iclass
= CT_SCROLLBAR
;
2102 return cls
; /* No default, return user controlclass */
2104 free
(cls
->name.s_name
->str.cstr
);
2105 free
(cls
->name.s_name
);
2106 cls
->type
= name_ord
;
2107 cls
->name.i_name
= iclass
;
2111 /* DialogEx specific functions */
2112 static dialogex_t
*dialogex_style
(style_t
* st
, dialogex_t
*dlg
)
2114 assert
(dlg
!= NULL
);
2115 if
(dlg
->style
== NULL
)
2117 dlg
->style
= new_style
(0,0);
2122 yywarning
("Style already defined, or-ing together");
2126 dlg
->style
->or_mask
= 0;
2127 dlg
->style
->and_mask
= 0;
2129 dlg
->style
->or_mask |
= st
->or_mask
;
2130 dlg
->style
->and_mask |
= st
->and_mask
;
2131 dlg
->gotstyle
= TRUE
;
2136 static dialogex_t
*dialogex_exstyle
(style_t
* st
, dialogex_t
*dlg
)
2138 assert
(dlg
!= NULL
);
2139 if
(dlg
->exstyle
== NULL
)
2141 dlg
->exstyle
= new_style
(0,0);
2146 yywarning
("ExStyle already defined, or-ing together");
2150 dlg
->exstyle
->or_mask
= 0;
2151 dlg
->exstyle
->and_mask
= 0;
2153 dlg
->exstyle
->or_mask |
= st
->or_mask
;
2154 dlg
->exstyle
->and_mask |
= st
->and_mask
;
2155 dlg
->gotexstyle
= TRUE
;
2160 static dialogex_t
*dialogex_caption
(string_t
*s
, dialogex_t
*dlg
)
2162 assert
(dlg
!= NULL
);
2164 yyerror("Caption already defined");
2169 static dialogex_t
*dialogex_font
(font_id_t
*f
, dialogex_t
*dlg
)
2171 assert
(dlg
!= NULL
);
2173 yyerror("Font already defined");
2178 static dialogex_t
*dialogex_class
(name_id_t
*n
, dialogex_t
*dlg
)
2180 assert
(dlg
!= NULL
);
2182 yyerror("Class already defined");
2187 static dialogex_t
*dialogex_menu
(name_id_t
*m
, dialogex_t
*dlg
)
2189 assert
(dlg
!= NULL
);
2191 yyerror("Menu already defined");
2196 static dialogex_t
*dialogex_language
(language_t
*l
, dialogex_t
*dlg
)
2198 assert
(dlg
!= NULL
);
2199 if
(dlg
->lvc.language
)
2200 yyerror("Language already defined");
2201 dlg
->lvc.language
= l
;
2205 static dialogex_t
*dialogex_characteristics
(characts_t
*c
, dialogex_t
*dlg
)
2207 assert
(dlg
!= NULL
);
2208 if
(dlg
->lvc.characts
)
2209 yyerror("Characteristics already defined");
2210 dlg
->lvc.characts
= c
;
2214 static dialogex_t
*dialogex_version
(version_t
*v
, dialogex_t
*dlg
)
2216 assert
(dlg
!= NULL
);
2217 if
(dlg
->lvc.version
)
2218 yyerror("Version already defined");
2219 dlg
->lvc.version
= v
;
2223 /* Accelerator specific functions */
2224 static event_t
*add_event
(int key
, int id
, int flags
, event_t
*prev
)
2226 event_t
*ev
= new_event
();
2228 if
((flags
& (WRC_AF_VIRTKEY | WRC_AF_ASCII
)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII
))
2229 yyerror("Cannot use both ASCII and VIRTKEY");
2233 ev
->flags
= flags
& ~WRC_AF_ASCII
;
2240 static event_t
*add_string_event
(string_t
*key
, int id
, int flags
, event_t
*prev
)
2243 event_t
*ev
= new_event
();
2245 if
(key
->type
!= str_char
)
2246 yyerror("Key code must be an ascii string");
2248 if
((flags
& WRC_AF_VIRTKEY
) && (!isupper
(key
->str.cstr
[0] & 0xff) && !isdigit
(key
->str.cstr
[0] & 0xff)))
2249 yyerror("VIRTKEY code is not equal to ascii value");
2251 if
(key
->str.cstr
[0] == '^' && (flags
& WRC_AF_CONTROL
) != 0)
2253 yyerror("Cannot use both '^' and CONTROL modifier");
2255 else if
(key
->str.cstr
[0] == '^')
2257 keycode
= toupper
(key
->str.cstr
[1]) - '@';
2259 yyerror("Control-code out of range");
2262 keycode
= key
->str.cstr
[0];
2265 ev
->flags
= flags
& ~WRC_AF_ASCII
;
2272 /* MenuEx specific functions */
2273 static itemex_opt_t
*new_itemex_opt
(int id
, int type
, int state
, int helpid
)
2275 itemex_opt_t
*opt
= (itemex_opt_t
*)xmalloc
(sizeof
(itemex_opt_t
));
2279 opt
->helpid
= helpid
;
2283 /* Raw data functions */
2284 static raw_data_t
*load_file
(string_t
*filename
, language_t
*lang
)
2290 int codepage
= get_language_codepage
(lang
->id
, lang
->sub
);
2292 /* FIXME: we may want to use utf-8 here */
2293 if
(codepage
<= 0 && filename
->type
!= str_char
)
2294 yyerror("Cannot convert filename to ASCII string");
2295 name
= convert_string
( filename
, str_char
, codepage
);
2296 if
(!(path
= wpp_find_include
(name
->str.cstr
, 1)))
2297 yyerror("Cannot open file %s", name
->str.cstr
);
2298 if
(!(fp
= fopen
( path
, "rb" )))
2299 yyerror("Cannot open file %s", name
->str.cstr
);
2301 rd
= new_raw_data
();
2302 fseek
(fp
, 0, SEEK_END
);
2303 rd
->size
= ftell
(fp
);
2304 fseek
(fp
, 0, SEEK_SET
);
2305 rd
->data
= (char *)xmalloc
(rd
->size
);
2306 fread
(rd
->data
, rd
->size
, 1, fp
);
2308 rd
->lvc.language
= lang
;
2313 static raw_data_t
*int2raw_data
(int i
)
2317 if
((int)((short)i
) != i
)
2318 yywarning
("Integer constant out of 16bit range (%d), truncated to %d\n", i
, (short)i
);
2320 rd
= new_raw_data
();
2321 rd
->size
= sizeof
(short);
2322 rd
->data
= (char *)xmalloc
(rd
->size
);
2325 #ifdef WORDS_BIGENDIAN
2329 rd
->data
[0] = HIBYTE
(i
);
2330 rd
->data
[1] = LOBYTE
(i
);
2333 #ifndef WORDS_BIGENDIAN
2337 rd
->data
[1] = HIBYTE
(i
);
2338 rd
->data
[0] = LOBYTE
(i
);
2344 static raw_data_t
*long2raw_data
(int i
)
2347 rd
= new_raw_data
();
2348 rd
->size
= sizeof
(int);
2349 rd
->data
= (char *)xmalloc
(rd
->size
);
2352 #ifdef WORDS_BIGENDIAN
2356 rd
->data
[0] = HIBYTE
(HIWORD
(i
));
2357 rd
->data
[1] = LOBYTE
(HIWORD
(i
));
2358 rd
->data
[2] = HIBYTE
(LOWORD
(i
));
2359 rd
->data
[3] = LOBYTE
(LOWORD
(i
));
2362 #ifndef WORDS_BIGENDIAN
2366 rd
->data
[3] = HIBYTE
(HIWORD
(i
));
2367 rd
->data
[2] = LOBYTE
(HIWORD
(i
));
2368 rd
->data
[1] = HIBYTE
(LOWORD
(i
));
2369 rd
->data
[0] = LOBYTE
(LOWORD
(i
));
2375 static raw_data_t
*str2raw_data
(string_t
*str
)
2378 rd
= new_raw_data
();
2379 rd
->size
= str
->size
* (str
->type
== str_char ?
1 : 2);
2380 rd
->data
= (char *)xmalloc
(rd
->size
);
2381 if
(str
->type
== str_char
)
2382 memcpy
(rd
->data
, str
->str.cstr
, rd
->size
);
2383 else if
(str
->type
== str_unicode
)
2388 #ifdef WORDS_BIGENDIAN
2392 for
(i
= 0; i
< str
->size
; i
++)
2394 rd
->data
[2*i
+ 0] = HIBYTE
((WORD
)str
->str.wstr
[i
]);
2395 rd
->data
[2*i
+ 1] = LOBYTE
((WORD
)str
->str.wstr
[i
]);
2398 #ifndef WORDS_BIGENDIAN
2402 for
(i
= 0; i
< str
->size
; i
++)
2404 rd
->data
[2*i
+ 1] = HIBYTE
((WORD
)str
->str.wstr
[i
]);
2405 rd
->data
[2*i
+ 0] = LOBYTE
((WORD
)str
->str.wstr
[i
]);
2411 internal_error
(__FILE__
, __LINE__
, "Invalid stringtype");
2415 static raw_data_t
*merge_raw_data
(raw_data_t
*r1
, raw_data_t
*r2
)
2417 r1
->data
= xrealloc
(r1
->data
, r1
->size
+ r2
->size
);
2418 memcpy
(r1
->data
+ r1
->size
, r2
->data
, r2
->size
);
2419 r1
->size
+= r2
->size
;
2423 static raw_data_t
*merge_raw_data_int
(raw_data_t
*r1
, int i
)
2425 raw_data_t
*t
= int2raw_data
(i
);
2426 merge_raw_data
(r1
, t
);
2432 static raw_data_t
*merge_raw_data_long
(raw_data_t
*r1
, int i
)
2434 raw_data_t
*t
= long2raw_data
(i
);
2435 merge_raw_data
(r1
, t
);
2441 static raw_data_t
*merge_raw_data_str
(raw_data_t
*r1
, string_t
*str
)
2443 raw_data_t
*t
= str2raw_data
(str
);
2444 merge_raw_data
(r1
, t
);
2450 /* Function the go back in a list to get the head */
2451 static menu_item_t
*get_item_head
(menu_item_t
*p
)
2460 static menuex_item_t
*get_itemex_head
(menuex_item_t
*p
)
2469 static resource_t
*get_resource_head
(resource_t
*p
)
2478 static ver_block_t
*get_ver_block_head
(ver_block_t
*p
)
2487 static ver_value_t
*get_ver_value_head
(ver_value_t
*p
)
2496 static control_t
*get_control_head
(control_t
*p
)
2505 static event_t
*get_event_head
(event_t
*p
)
2514 /* Find a stringtable with given language */
2515 static stringtable_t
*find_stringtable
(lvc_t
*lvc
)
2519 assert
(lvc
!= NULL
);
2522 lvc
->language
= dup_language
(currentlanguage
);
2524 for
(stt
= sttres
; stt
; stt
= stt
->next
)
2526 if
(stt
->lvc.language
->id
== lvc
->language
->id
2527 && stt
->lvc.language
->sub
== lvc
->language
->sub
)
2529 /* Found a table with the same language */
2530 /* The version and characteristics are now handled
2531 * in the generation of the individual stringtables.
2532 * This enables localized analysis.
2533 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2534 || (!stt->lvc.version && lvc->version)
2535 || (stt->lvc.version && !lvc->version))
2536 yywarning("Stringtable's versions are not the same, using first definition");
2538 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2539 || (!stt->lvc.characts && lvc->characts)
2540 || (stt->lvc.characts && !lvc->characts))
2541 yywarning("Stringtable's characteristics are not the same, using first definition");
2549 /* qsort sorting function for string table entries */
2550 #define STE(p) ((stt_entry_t *)(p))
2551 static int sort_stt_entry
(const void *e1
, const void *e2
)
2553 return STE
(e1
)->id
- STE
(e2
)->id
;
2557 static resource_t
*build_stt_resources
(stringtable_t
*stthead
)
2560 stringtable_t
*newstt
;
2562 resource_t
*rsclist
= NULL
;
2563 resource_t
*rsctail
= NULL
;
2568 characts_t
*characts
;
2574 /* For all languages defined */
2575 for
(stt
= stthead
; stt
; stt
= stt
->next
)
2577 assert
(stt
->nentries
> 0);
2579 /* Sort the entries */
2580 if
(stt
->nentries
> 1)
2581 qsort
(stt
->entries
, stt
->nentries
, sizeof
(stt
->entries
[0]), sort_stt_entry
);
2583 for
(i
= 0; i
< stt
->nentries
; )
2585 newstt
= new_stringtable
(&stt
->lvc
);
2586 newstt
->entries
= (stt_entry_t
*)xmalloc
(16 * sizeof
(stt_entry_t
));
2587 newstt
->nentries
= 16;
2588 newstt
->idbase
= stt
->entries
[i
].id
& ~
0xf;
2589 for
(j
= 0; j
< 16 && i
< stt
->nentries
; j
++)
2591 if
(stt
->entries
[i
].id
- newstt
->idbase
== j
)
2593 newstt
->entries
[j
] = stt
->entries
[i
];
2601 /* Check individual memory options and get
2602 * the first characteristics/version
2604 for
(j
= 0; j
< 16; j
++)
2606 if
(!newstt
->entries
[j
].str
)
2608 andsum
&= newstt
->entries
[j
].memopt
;
2609 orsum |
= newstt
->entries
[j
].memopt
;
2611 characts
= newstt
->entries
[j
].characts
;
2613 version
= newstt
->entries
[j
].version
;
2617 warning
("Stringtable's memory options are not equal (idbase: %d)", newstt
->idbase
);
2619 /* Check version and characteristics */
2620 for
(j
= 0; j
< 16; j
++)
2623 && newstt
->entries
[j
].characts
2624 && *newstt
->entries
[j
].characts
!= *characts
)
2625 warning
("Stringtable's characteristics are not the same (idbase: %d)", newstt
->idbase
);
2627 && newstt
->entries
[j
].version
2628 && *newstt
->entries
[j
].version
!= *version
)
2629 warning
("Stringtable's versions are not the same (idbase: %d)", newstt
->idbase
);
2631 rsc
= new_resource
(res_stt
, newstt
, newstt
->memopt
, newstt
->lvc.language
);
2632 rsc
->name
= new_name_id
();
2633 rsc
->name
->type
= name_ord
;
2634 rsc
->name
->name.i_name
= (newstt
->idbase
>> 4) + 1;
2635 rsc
->memopt
= andsum
; /* Set to least common denominator */
2636 newstt
->memopt
= andsum
;
2637 newstt
->lvc.characts
= characts
;
2638 newstt
->lvc.version
= version
;
2646 rsctail
->next
= rsc
;
2647 rsc
->prev
= rsctail
;
2656 static toolbar_item_t
*ins_tlbr_button
(toolbar_item_t
*prev
, toolbar_item_t
*idrec
)
2665 static toolbar_item_t
*get_tlbr_buttons_head
(toolbar_item_t
*p
, int *nitems
)
2684 static string_t
*make_filename
(string_t
*str
)
2686 if
(str
->type
== str_char
)
2690 /* Remove escaped backslash and convert to forward */
2691 for
(cptr
= str
->str.cstr
; (cptr
= strchr
(cptr
, '\\')) != NULL
; cptr
++)
2695 memmove
(cptr
, cptr
+1, strlen
(cptr
));
2705 /* Remove escaped backslash and convert to forward */
2706 for
(wptr
= str
->str.wstr
; (wptr
= strchrW
(wptr
, '\\')) != NULL
; wptr
++)
2710 memmove
(wptr
, wptr
+1, strlenW
(wptr
));
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
= xstrdup
("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
);
2897 * This gets invoked to determine whether the next resource
2898 * is to be of a standard-type (e.g. bitmaps etc.), or should
2899 * be a user-type resource. This function is required because
2900 * there is the _possibility_ of a lookahead token in the
2901 * parser, which is generated from the "expr" state in the
2904 * The general resource format is:
2905 * <identifier> <type> <flags> <resourcebody>
2907 * The <identifier> can either be tIDENT or "expr". The latter
2908 * will always generate a lookahead, which is the <type> of the
2909 * resource to parse. Otherwise, we need to get a new token from
2910 * the scanner to determine the next step.
2912 * The problem arrises when <type> is numerical. This case should
2913 * map onto default resource-types and be parsed as such instead
2914 * of being mapped onto user-type resources.
2916 * The trick lies in the fact that yacc (bison) doesn't care about
2917 * intermediate changes of the lookahead while reducing a rule. We
2918 * simply replace the lookahead with a token that will result in
2919 * a shift to the appropriate rule for the specific resource-type.
2921 static int rsrcid_to_token
(int lookahead
)
2924 const char *type
= "?";
2926 /* Get a token if we don't have one yet */
2927 if
(lookahead
== YYEMPTY
)
2930 /* Only numbers are possibly interesting */
2960 case WRC_RT_FONTDIR
:
2968 case WRC_RT_MESSAGETABLE
:
2969 type
= "MESSAGETABLE";
2970 token
= tMESSAGETABLE
;
2972 case WRC_RT_DLGINIT
:
2976 case WRC_RT_ACCELERATOR
:
2977 type
= "ACCELERATOR";
2978 token
= tACCELERATORS
;
2988 case WRC_RT_VERSION
:
2990 token
= tVERSIONINFO
;
2992 case WRC_RT_TOOLBAR
:
2998 type
= "STRINGTABLE";
3001 case WRC_RT_ANICURSOR
:
3002 case WRC_RT_ANIICON
:
3003 case WRC_RT_GROUP_CURSOR
:
3004 case WRC_RT_GROUP_ICON
:
3005 yywarning
("Usertype uses reserved type ID %d, which is auto-generated", yylval.num
);
3008 case WRC_RT_DLGINCLUDE
:
3009 case WRC_RT_PLUGPLAY
:
3012 yywarning
("Usertype uses reserved type ID %d, which is not supported by wrc yet", yylval.num
);