Made the DLL version clash error message more verbose.
[wine.git] / tools / wrc / parser.y
blob1c6c97326005966880ea2cd0d7eec356d52afb24
1 %{
2 /*
3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * 21-May-2000 BS - Partial implementation of font resources.
8 * - Corrected language propagation for binary
9 * resources such as bitmaps, isons, cursors,
10 * userres and rcdata. The language is now
11 * correct in .res files.
12 * - Fixed reading the resource name as ident,
13 * so that it may overlap keywords.
14 * 20-May-2000 BS - Implemented animated cursors and icons
15 * resource types.
16 * 30-Apr-2000 BS - Reintegration into the wine-tree
17 * 14-Jan-2000 BS - Redid the usertype resources so that they
18 * are compatible.
19 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
20 * expect for the # command (line numbers).
22 * 06-Nov-1999 JS - see CHANGES
24 * 29-Dec-1998 AdH - Grammar and function extensions.
25 * grammar: TOOLBAR resources, Named ICONs in
26 * DIALOGS
27 * functions: semantic actions for the grammar
28 * changes, resource files can now be anywhere
29 * on the include path instead of just in the
30 * current directory
32 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
33 * printed out correctly.
35 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
36 * also accept a tSTRING as argument.
38 * 25-May-1998 BS - Found out that I need to support language, version
39 * and characteristics in inline resources (bitmap,
40 * cursor, etc) but they can also be specified with
41 * a filename. This renders my filename-scanning scheme
42 * worthless. Need to build newline parsing to solve
43 * this one.
44 * It will come with version 1.1.0 (sigh).
46 * 19-May-1998 BS - Started to build a builtin preprocessor
48 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
49 * ideas had some serious flaws.
51 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
52 * file.
54 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
55 * - This file is growing too big. It is time to strip
56 * things and put it in a support file.
58 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
59 * resource will be created. This because the table
60 * has a different layout than other resources. The
61 * table has to be sorted, and divided into smaller
62 * resource entries (see comment in source).
64 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
65 * as string_t which include unicode strings upon
66 * input.
67 * - Parser now emits a warning when compiling win32
68 * extensions in win16 mode.
70 * 16-Apr-1998 BS - Raw data elements are now *optionally* seperated
71 * by commas. Read the comments in file sq2dq.l.
72 * - FIXME: there are instances in the source that rely
73 * on the fact that int==32bit and pointers are int size.
74 * - Fixed the conflict in menuex by changing a rule
75 * back into right recursion. See note in source.
76 * - UserType resources cannot have an expression as its
77 * typeclass. See note in source.
79 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
80 * get reduction of the parsestack.
81 * This also helps communication between bison and flex.
82 * Main advantage is that the Empty rule gets reduced
83 * first, which is used to allocate/link things.
84 * It also added a shift/reduce conflict in the menuex
85 * handling, due to expression/option possibility,
86 * although not serious.
88 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
89 * about making it more efficient, but readable (for me)
90 * and slightly easier to expand/change.
91 * This is done primarily by using more reduce states
92 * with many (intuitive) types for the various resource
93 * statements.
94 * - Added expression handling for all resources where a
95 * number is accepted (not only for win32). Also added
96 * multiply and division (not MS compatible, but handy).
97 * Unary minus introduced a shift/reduce conflict, but
98 * it is not serious.
100 * 13-Apr-1998 BS - Reordered a lot of things
101 * - Made the source more readable
102 * - Added Win32 resource definitions
103 * - Corrected syntax problems with an old yacc (;)
104 * - Added extra comment about grammar
106 #include "config.h"
108 #include <stdio.h>
109 #include <stdlib.h>
110 #include <stdarg.h>
111 #include <assert.h>
112 #include <ctype.h>
113 #include <string.h>
114 #ifdef HAVE_ALLOCA_H
115 #include <alloca.h>
116 #endif
118 #include "wrc.h"
119 #include "utils.h"
120 #include "newstruc.h"
121 #include "dumpres.h"
122 #include "preproc.h"
123 #include "parser.h"
124 #include "windef.h"
125 #include "wingdi.h"
126 #include "winuser.h"
128 int want_nl = 0; /* Signal flex that we need the next newline */
129 int want_id = 0; /* Signal flex that we need the next identifier */
130 stringtable_t *tagstt; /* Stringtable tag.
131 * It is set while parsing a stringtable to one of
132 * the stringtables in the sttres list or a new one
133 * if the language was not parsed before.
135 stringtable_t *sttres; /* Stringtable resources. This holds the list of
136 * stringtables with different lanuages
138 /* Set to the current options of the currently scanning stringtable */
139 static int *tagstt_memopt;
140 static characts_t *tagstt_characts;
141 static version_t *tagstt_version;
143 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
145 /* Prototypes of here defined functions */
146 static event_t *get_event_head(event_t *p);
147 static control_t *get_control_head(control_t *p);
148 static ver_value_t *get_ver_value_head(ver_value_t *p);
149 static ver_block_t *get_ver_block_head(ver_block_t *p);
150 static resource_t *get_resource_head(resource_t *p);
151 static menuex_item_t *get_itemex_head(menuex_item_t *p);
152 static menu_item_t *get_item_head(menu_item_t *p);
153 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
154 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
155 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
156 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
157 static raw_data_t *str2raw_data(string_t *str);
158 static raw_data_t *int2raw_data(int i);
159 static raw_data_t *long2raw_data(int i);
160 static raw_data_t *load_file(string_t *name);
161 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
162 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
163 static event_t *add_event(int key, int id, int flags, event_t *prev);
164 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
165 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
166 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
167 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
168 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
169 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
170 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
171 static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
172 static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
173 static name_id_t *convert_ctlclass(name_id_t *cls);
174 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
175 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
176 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
177 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
178 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
179 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
180 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
181 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
182 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
183 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
184 static resource_t *build_stt_resources(stringtable_t *stthead);
185 static stringtable_t *find_stringtable(lvc_t *lvc);
186 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
187 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
188 static string_t *make_filename(string_t *s);
189 static resource_t *build_fontdirs(resource_t *tail);
190 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
193 %union{
194 string_t *str;
195 int num;
196 int *iptr;
197 char *cptr;
198 resource_t *res;
199 accelerator_t *acc;
200 bitmap_t *bmp;
201 dialog_t *dlg;
202 dialogex_t *dlgex;
203 font_t *fnt;
204 fontdir_t *fnd;
205 menu_t *men;
206 menuex_t *menex;
207 rcdata_t *rdt;
208 stringtable_t *stt;
209 stt_entry_t *stte;
210 user_t *usr;
211 messagetable_t *msg;
212 versioninfo_t *veri;
213 control_t *ctl;
214 name_id_t *nid;
215 font_id_t *fntid;
216 language_t *lan;
217 version_t *ver;
218 characts_t *chars;
219 event_t *event;
220 menu_item_t *menitm;
221 menuex_item_t *menexitm;
222 itemex_opt_t *exopt;
223 raw_data_t *raw;
224 lvc_t *lvc;
225 ver_value_t *val;
226 ver_block_t *blk;
227 ver_words_t *verw;
228 toolbar_t *tlbar;
229 toolbar_item_t *tlbarItems;
230 dlginit_t *dginit;
231 style_pair_t *styles;
232 style_t *style;
233 ani_any_t *ani;
236 %token tTYPEDEF tEXTERN tSTRUCT tENUM tCPPCLASS tINLINE tSTATIC tNL
237 %token <num> tNUMBER tLNUMBER
238 %token <str> tSTRING tIDENT tFILENAME
239 %token <raw> tRAWDATA
240 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
241 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
242 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
243 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
244 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
245 %token tCONTROL tEDITTEXT
246 %token tRTEXT tCTEXT tLTEXT
247 %token tBLOCK tVALUE
248 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
249 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
250 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
251 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
252 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
253 %token tHELP
254 %token tSTRING tIDENT tRAWDATA
255 %token tTOOLBAR tBUTTON
256 %token tBEGIN tEND
257 %token tDLGINIT
258 %left '|'
259 %left '^'
260 %left '&'
261 %left '+' '-'
262 %left '*' '/'
263 %right '~' tNOT
264 %left pUPM
266 %type <res> resource_file resource resources resource_definition
267 %type <stt> stringtable strings
268 %type <fnt> font
269 %type <fnd> fontdir
270 %type <acc> accelerators
271 %type <event> events
272 %type <bmp> bitmap
273 %type <ani> cursor icon
274 %type <dlg> dialog dlg_attributes
275 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
276 %type <iptr> helpid
277 %type <dlgex> dialogex dlgex_attribs
278 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
279 %type <rdt> rcdata
280 %type <raw> raw_data raw_elements opt_data file_raw
281 %type <veri> versioninfo fix_version
282 %type <verw> ver_words
283 %type <blk> ver_blocks ver_block
284 %type <val> ver_values ver_value
285 %type <men> menu
286 %type <menitm> item_definitions menu_body
287 %type <menex> menuex
288 %type <menexitm> itemex_definitions menuex_body
289 %type <exopt> itemex_p_options itemex_options
290 %type <msg> messagetable
291 %type <usr> userres
292 %type <num> item_options
293 %type <nid> nameid nameid_s ctlclass usertype
294 %type <num> acc_opt acc accs
295 %type <iptr> loadmemopts lamo lama
296 %type <fntid> opt_font opt_exfont opt_expr
297 %type <lvc> opt_lvc
298 %type <lan> opt_language
299 %type <chars> opt_characts
300 %type <ver> opt_version
301 %type <num> expr xpr
302 %type <iptr> e_expr
303 %type <tlbar> toolbar
304 %type <tlbarItems> toolbar_items
305 %type <dginit> dlginit
306 %type <styles> optional_style_pair
307 %type <num> any_num any_nums
308 %type <style> optional_style
309 %type <style> style
310 %type <str> filename
314 resource_file
315 : resources {
316 resource_t *rsc;
317 /* First add stringtables to the resource-list */
318 rsc = build_stt_resources(sttres);
319 /* 'build_stt_resources' returns a head and $1 is a tail */
320 if($1)
322 $1->next = rsc;
323 if(rsc)
324 rsc->prev = $1;
326 else
327 $1 = rsc;
328 /* Find the tail again */
329 while($1 && $1->next)
330 $1 = $1->next;
331 /* Now add any fontdirecory */
332 rsc = build_fontdirs($1);
333 /* 'build_fontdir' returns a head and $1 is a tail */
334 if($1)
336 $1->next = rsc;
337 if(rsc)
338 rsc->prev = $1;
340 else
341 $1 = rsc;
342 /* Final statement before were done */
343 resource_top = get_resource_head($1);
347 /* Resources are put into a linked list */
348 resources
349 : /* Empty */ { $$ = NULL; want_id = 1; }
350 | resources resource {
351 if($2)
353 resource_t *tail = $2;
354 resource_t *head = $2;
355 while(tail->next)
356 tail = tail->next;
357 while(head->prev)
358 head = head->prev;
359 head->prev = $1;
360 if($1)
361 $1->next = head;
362 $$ = tail;
363 /* Check for duplicate identifiers */
364 while($1 && head)
366 resource_t *rsc = $1;
367 while(rsc)
369 if(rsc->type == head->type
370 && rsc->lan->id == head->lan->id
371 && rsc->lan->sub == head->lan->sub
372 && !compare_name_id(rsc->name, head->name))
374 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
376 rsc = rsc->prev;
378 head = head->next;
381 else if($1)
383 resource_t *tail = $1;
384 while(tail->next)
385 tail = tail->next;
386 $$ = tail;
388 else
389 $$ = NULL;
390 want_id = 1;
392 | resources preprocessor { $$ = $1; want_id = 1; }
393 | resources cjunk { $$ = $1; want_id = 1; }
397 * The preprocessor generates line directives a la gcc
398 * in the format:
399 * # <linenum> "filename" <codes>
401 * Codes can be a sequence of:
402 * - 1 start of new file
403 * - 2 returning to previous
404 * - 3 system header
405 * - 4 interpret as C-code
407 * 4 is not used and 1 mutually excludes 2
408 * Anyhow, we are not really interested in these at all
409 * because we only want to know the linenumber and
410 * filename.
412 preprocessor
413 : '#' { want_nl = 1; } tNUMBER tSTRING any_nums tNL {
414 line_number = $3 - 1;
415 input_name = $4->str.cstr;
416 /* fprintf(stderr, "Now at %s:%d\n", input_name, line_number); */
420 any_nums: any_num
421 | any_nums any_num
424 /* C ignore stuff */
425 cjunk : tTYPEDEF { strip_til_semicolon(); }
426 | tSTRUCT { strip_til_semicolon(); }
427 | tEXTERN { strip_til_semicolon(); }
428 | tENUM { strip_til_semicolon(); }
429 | tCPPCLASS { strip_til_semicolon(); }
430 | tSTATIC { strip_til_semicolon(); }
431 | tINLINE { internal_error(__FILE__, __LINE__, "Don't yet know how to strip inline functions\n"); }
432 /* | tIDENT tIDENT { strip_til_semicolon(); } */
433 | tIDENT tIDENT '(' { strip_til_parenthesis(); }
434 /* | tIDENT '(' { strip_til_parenthesis(); } */
435 | tIDENT '*' { strip_til_semicolon(); }
438 /* Parse top level resource definitions etc. */
439 resource
440 : nameid resource_definition {
441 $$ = $2;
442 if($$)
444 $$->name = $1;
445 if($1->type == name_ord)
447 chat("Got %s (%d)",get_typename($2),$1->name.i_name);
449 else if($1->type == name_str)
451 chat("Got %s (%s)",get_typename($2),$1->name.s_name->str.cstr);
455 | stringtable {
456 /* Don't do anything, stringtables are converted to
457 * resource_t structures when we are finished parsing and
458 * the final rule of the parser is reduced (see above)
460 $$ = NULL;
461 chat("Got STRINGTABLE");
463 | tLANGUAGE {want_nl = 1; } expr ',' expr tNL {
464 /* We *NEED* the newline to delimit the expression.
465 * Otherwise, we would not be able to set the next
466 * want_id anymore because of the token-lookahead.
468 if(!win32)
469 yywarning("LANGUAGE not supported in 16-bit mode");
470 if(currentlanguage)
471 free(currentlanguage);
472 currentlanguage = new_language($3, $5);
473 $$ = NULL;
478 * Get a valid name/id
480 nameid : expr {
481 if($1 > 65535 || $1 < -32768)
482 yyerror("Resource's ID out of range (%d)", $1);
483 $$ = new_name_id();
484 $$->type = name_ord;
485 $$->name.i_name = $1;
487 | tIDENT {
488 $$ = new_name_id();
489 $$->type = name_str;
490 $$->name.s_name = $1;
495 * Extra string recognition for CLASS statement in dialogs
497 nameid_s: nameid { $$ = $1; }
498 | tSTRING {
499 $$ = new_name_id();
500 $$->type = name_str;
501 $$->name.s_name = $1;
505 /* get the value for a single resource*/
506 resource_definition
507 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
508 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
509 | cursor {
510 resource_t *rsc;
511 if($1->type == res_anicur)
513 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
515 else if($1->type == res_curg)
517 cursor_t *cur;
518 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
519 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
521 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
522 rsc->prev->next = rsc;
523 rsc = rsc->prev;
524 rsc->name = new_name_id();
525 rsc->name->type = name_ord;
526 rsc->name->name.i_name = cur->id;
529 else
530 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
531 free($1);
533 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
534 | dialogex {
535 if(win32)
536 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
537 else
538 $$ = NULL;
540 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
541 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
542 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
543 | icon {
544 resource_t *rsc;
545 if($1->type == res_aniico)
547 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
549 else if($1->type == res_icog)
551 icon_t *ico;
552 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
553 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
555 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
556 rsc->prev->next = rsc;
557 rsc = rsc->prev;
558 rsc->name = new_name_id();
559 rsc->name->type = name_ord;
560 rsc->name->name.i_name = ico->id;
563 else
564 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
565 free($1);
567 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
568 | menuex {
569 if(win32)
570 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
571 else
572 $$ = NULL;
574 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
575 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
576 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
577 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
578 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
582 filename: tFILENAME { $$ = make_filename($1); }
583 | tIDENT { $$ = make_filename($1); }
584 | tSTRING { $$ = make_filename($1); }
587 /* ------------------------------ Bitmap ------------------------------ */
588 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
591 /* ------------------------------ Cursor ------------------------------ */
592 cursor : tCURSOR loadmemopts file_raw {
593 $$ = new_ani_any();
594 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
596 $$->type = res_anicur;
597 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
599 else
601 $$->type = res_curg;
602 $$->u.curg = new_cursor_group($3, $2);
607 /* ------------------------------ Icon ------------------------------ */
608 icon : tICON loadmemopts file_raw {
609 $$ = new_ani_any();
610 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
612 $$->type = res_aniico;
613 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
615 else
617 $$->type = res_icog;
618 $$->u.icog = new_icon_group($3, $2);
623 /* ------------------------------ Font ------------------------------ */
625 * The reading of raw_data for fonts is a Borland BRC
626 * extension. MS generates an error. However, it is
627 * most logical to support this, considering how wine
628 * enters things in CVS (ascii).
630 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
634 * The fontdir is a Borland BRC extension which only
635 * reads the data as 'raw_data' from the file.
636 * I don't know whether it is interpreted.
637 * The fontdir is generated if it was not present and
638 * fonts are defined in the source.
640 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
643 /* ------------------------------ MessageTable ------------------------------ */
644 /* It might be interesting to implement the MS Message compiler here as well
645 * to get everything in one source. Might be a future project.
647 messagetable
648 : tMESSAGETABLE loadmemopts file_raw {
649 if(!win32)
650 yywarning("MESSAGETABLE not supported in 16-bit mode");
651 $$ = new_messagetable($3, $2);
655 /* ------------------------------ RCData ------------------------------ */
656 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
659 /* ------------------------------ DLGINIT ------------------------------ */
660 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
663 /* ------------------------------ UserType ------------------------------ */
664 userres : usertype loadmemopts file_raw {
665 if($1->type == name_ord)
667 switch($1->name.i_name)
669 case WRC_RT_CURSOR: /* Bad idea; cursors should generate directories */
670 case WRC_RT_ANICURSOR:
671 case WRC_RT_ICON:
672 case WRC_RT_ANIICON: /* Bad idea; icons should generate directories */
673 case WRC_RT_BITMAP:
674 case WRC_RT_FONT: /* Bad idea; fonts should generate directories */
675 case WRC_RT_FONTDIR:
676 case WRC_RT_RCDATA: /* This cannot be interpreted anyway */
677 case WRC_RT_MESSAGETABLE: /* This case is involked by mc.exe */
678 case WRC_RT_DLGINIT: /* No real layout available */
680 /* These should never be invoked because they have their own layout */
681 case WRC_RT_ACCELERATOR:
682 case WRC_RT_MENU:
683 case WRC_RT_DIALOG:
684 case WRC_RT_STRING:
685 case WRC_RT_TOOLBAR:
686 case WRC_RT_VERSION:
687 yywarning("Usertype uses special type-ID %d (wrc cannot yet re-interpret the data)", $1->name.i_name);
688 goto douser;
690 case WRC_RT_GROUP_CURSOR:
691 case WRC_RT_GROUP_ICON:
692 yywarning("Usertype uses reserved type-ID %d, which is auto-generated", $1->name.i_name);
693 goto douser;
695 case WRC_RT_DLGINCLUDE:
696 case WRC_RT_PLUGPLAY:
697 case WRC_RT_VXD:
698 case WRC_RT_HTML:
699 yywarning("Usertype uses reserved type-ID %d, which is not supported by wrc", $1->name.i_name);
700 default:
701 goto douser;
704 else
706 douser:
707 #ifdef WORDS_BIGENDIAN
708 if(pedantic && byteorder != WRC_BO_LITTLE)
709 #else
710 if(pedantic && byteorder == WRC_BO_BIG)
711 #endif
712 yywarning("Byteordering is not little-endian and type cannot be interpreted");
713 $$ = new_user($1, $3, $2);
718 usertype: tNUMBER {
719 $$ = new_name_id();
720 $$->type = name_ord;
721 $$->name.i_name = $1;
723 | tIDENT {
724 $$ = new_name_id();
725 $$->type = name_str;
726 $$->name.s_name = $1;
730 /* ------------------------------ Accelerator ------------------------------ */
731 accelerators
732 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
733 $$ = new_accelerator();
734 if($2)
736 $$->memopt = *($2);
737 free($2);
739 else
741 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
743 if(!$5)
744 yyerror("Accelerator table must have at least one entry");
745 $$->events = get_event_head($5);
746 if($3)
748 $$->lvc = *($3);
749 free($3);
751 if(!$$->lvc.language)
752 $$->lvc.language = dup_language(currentlanguage);
756 events : /* Empty */ { $$=NULL; }
757 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
758 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
762 * The empty rule generates a s/r conflict because of {bi,u}nary expr
763 * on - and +. It cannot be solved in any way because it is the same as
764 * the if/then/else problem (LALR(1) problem). The conflict is moved
765 * away by forcing it to be in the expression handling below.
767 acc_opt : /* Empty */ { $$ = 0; }
768 | ',' accs { $$ = $2; }
771 accs : acc { $$ = $1; }
772 | accs ',' acc { $$ = $1 | $3; }
775 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
776 | tSHIFT { $$ = WRC_AF_SHIFT; }
777 | tCONTROL { $$ = WRC_AF_CONTROL; }
778 | tALT { $$ = WRC_AF_ALT; }
779 | tASCII { $$ = WRC_AF_ASCII; }
780 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
783 /* ------------------------------ Dialog ------------------------------ */
784 /* FIXME: Support EXSTYLE in the dialog line itself */
785 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
786 tBEGIN ctrls tEND {
787 if($2)
789 $10->memopt = *($2);
790 free($2);
792 else
793 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
794 $10->x = $3;
795 $10->y = $5;
796 $10->width = $7;
797 $10->height = $9;
798 $10->controls = get_control_head($12);
799 $$ = $10;
800 if(!$$->gotstyle)
802 $$->style->or_mask = WS_POPUP;
803 $$->gotstyle = TRUE;
805 if($$->title)
806 $$->style->or_mask |= WS_CAPTION;
807 if($$->font)
808 $$->style->or_mask |= DS_SETFONT;
810 $$->style->or_mask &= ~($$->style->and_mask);
811 $$->style->and_mask = 0;
813 if(!$$->lvc.language)
814 $$->lvc.language = dup_language(currentlanguage);
818 dlg_attributes
819 : /* Empty */ { $$=new_dialog(); }
820 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
821 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
822 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
823 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
824 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
825 | dlg_attributes tCPPCLASS nameid_s { $$=dialog_class($3,$1); }
826 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
827 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
828 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
829 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
832 ctrls : /* Empty */ { $$ = NULL; }
833 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
834 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
835 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
836 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
837 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
838 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
839 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
840 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
841 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
842 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
843 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
844 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
845 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
846 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
847 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
848 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
849 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
850 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
851 /* special treatment for icons, as the extent is optional */
852 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
853 $10->title = $3;
854 $10->id = $5;
855 $10->x = $7;
856 $10->y = $9;
857 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
861 lab_ctrl
862 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style {
863 $$=new_control();
864 $$->title = new_name_id();
865 $$->title->type = name_str;
866 $$->title->name.s_name = $1;
867 $$->id = $3;
868 $$->x = $5;
869 $$->y = $7;
870 $$->width = $9;
871 $$->height = $11;
872 if($12)
874 $$->style = $12;
875 $$->gotstyle = TRUE;
880 ctrl_desc
881 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
882 $$ = new_control();
883 $$->id = $1;
884 $$->x = $3;
885 $$->y = $5;
886 $$->width = $7;
887 $$->height = $9;
888 if($10)
890 $$->style = $10;
891 $$->gotstyle = TRUE;
896 iconinfo: /* Empty */
897 { $$ = new_control(); }
899 | ',' expr ',' expr {
900 $$ = new_control();
901 $$->width = $2;
902 $$->height = $4;
904 | ',' expr ',' expr ',' style {
905 $$ = new_control();
906 $$->width = $2;
907 $$->height = $4;
908 $$->style = $6;
909 $$->gotstyle = TRUE;
911 | ',' expr ',' expr ',' style ',' style {
912 $$ = new_control();
913 $$->width = $2;
914 $$->height = $4;
915 $$->style = $6;
916 $$->gotstyle = TRUE;
917 $$->exstyle = $8;
918 $$->gotexstyle = TRUE;
922 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
923 $$=new_control();
924 $$->title = $1;
925 $$->id = $3;
926 $$->ctlclass = convert_ctlclass($5);
927 $$->style = $7;
928 $$->gotstyle = TRUE;
929 $$->x = $9;
930 $$->y = $11;
931 $$->width = $13;
932 $$->height = $15;
933 $$->exstyle = $17;
934 $$->gotexstyle = TRUE;
936 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
937 $$=new_control();
938 $$->title = $1;
939 $$->id = $3;
940 $$->ctlclass = convert_ctlclass($5);
941 $$->style = $7;
942 $$->gotstyle = TRUE;
943 $$->x = $9;
944 $$->y = $11;
945 $$->width = $13;
946 $$->height = $15;
950 opt_font
951 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
954 /* ------------------------------ style flags ------------------------------ */
955 optional_style /* Abbused once to get optional ExStyle */
956 : /* Empty */ { $$ = NULL; }
957 | ',' style { $$ = $2; }
960 optional_style_pair
961 : /* Empty */ { $$ = NULL; }
962 | ',' style { $$ = new_style_pair($2, 0); }
963 | ',' style ',' style { $$ = new_style_pair($2, $4); }
966 style
967 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
968 | '(' style ')' { $$ = $2; }
969 | any_num { $$ = new_style($1, 0); }
970 | tNOT any_num { $$ = new_style(0, $2); }
973 ctlclass
974 : expr {
975 $$ = new_name_id();
976 $$->type = name_ord;
977 $$->name.i_name = $1;
979 | tSTRING {
980 $$ = new_name_id();
981 $$->type = name_str;
982 $$->name.s_name = $1;
986 /* ------------------------------ DialogEx ------------------------------ */
987 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
988 tBEGIN exctrls tEND {
989 if(!win32)
990 yywarning("DIALOGEX not supported in 16-bit mode");
991 if($2)
993 $11->memopt = *($2);
994 free($2);
996 else
997 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
998 $11->x = $3;
999 $11->y = $5;
1000 $11->width = $7;
1001 $11->height = $9;
1002 if($10)
1004 $11->helpid = *($10);
1005 $11->gothelpid = TRUE;
1006 free($10);
1008 $11->controls = get_control_head($13);
1009 $$ = $11;
1011 assert($$->style != NULL);
1012 if(!$$->gotstyle)
1014 $$->style->or_mask = WS_POPUP;
1015 $$->gotstyle = TRUE;
1017 if($$->title)
1018 $$->style->or_mask |= WS_CAPTION;
1019 if($$->font)
1020 $$->style->or_mask |= DS_SETFONT;
1022 $$->style->or_mask &= ~($$->style->and_mask);
1023 $$->style->and_mask = 0;
1025 if(!$$->lvc.language)
1026 $$->lvc.language = dup_language(currentlanguage);
1030 dlgex_attribs
1031 : /* Empty */ { $$=new_dialogex(); }
1032 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
1033 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
1034 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1035 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1036 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1037 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1038 | dlgex_attribs tCPPCLASS nameid_s { $$=dialogex_class($3,$1); }
1039 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1040 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1041 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1042 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1045 exctrls : /* Empty */ { $$ = NULL; }
1046 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1047 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1048 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1049 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1050 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1051 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1052 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1053 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1054 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1055 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1056 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1057 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1058 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1059 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1060 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1061 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1062 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1063 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1064 /* special treatment for icons, as the extent is optional */
1065 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1066 $10->title = $3;
1067 $10->id = $5;
1068 $10->x = $7;
1069 $10->y = $9;
1070 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1074 gen_exctrl
1075 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1076 expr ',' style helpid opt_data {
1077 $$=new_control();
1078 $$->title = $1;
1079 $$->id = $3;
1080 $$->ctlclass = convert_ctlclass($5);
1081 $$->style = $7;
1082 $$->gotstyle = TRUE;
1083 $$->x = $9;
1084 $$->y = $11;
1085 $$->width = $13;
1086 $$->height = $15;
1087 if($17)
1089 $$->exstyle = $17;
1090 $$->gotexstyle = TRUE;
1092 if($18)
1094 $$->helpid = *($18);
1095 $$->gothelpid = TRUE;
1096 free($18);
1098 $$->extra = $19;
1100 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1101 $$=new_control();
1102 $$->title = $1;
1103 $$->id = $3;
1104 $$->style = $7;
1105 $$->gotstyle = TRUE;
1106 $$->ctlclass = convert_ctlclass($5);
1107 $$->x = $9;
1108 $$->y = $11;
1109 $$->width = $13;
1110 $$->height = $15;
1111 $$->extra = $16;
1115 lab_exctrl
1116 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1117 $$=new_control();
1118 $$->title = new_name_id();
1119 $$->title->type = name_str;
1120 $$->title->name.s_name = $1;
1121 $$->id = $3;
1122 $$->x = $5;
1123 $$->y = $7;
1124 $$->width = $9;
1125 $$->height = $11;
1126 if($12)
1128 $$->style = $12->style;
1129 $$->gotstyle = TRUE;
1131 if ($12->exstyle)
1133 $$->exstyle = $12->exstyle;
1134 $$->gotexstyle = TRUE;
1136 free($12);
1139 $$->extra = $13;
1143 exctrl_desc
1144 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1145 $$ = new_control();
1146 $$->id = $1;
1147 $$->x = $3;
1148 $$->y = $5;
1149 $$->width = $7;
1150 $$->height = $9;
1151 if($10)
1153 $$->style = $10->style;
1154 $$->gotstyle = TRUE;
1156 if ($10->exstyle)
1158 $$->exstyle = $10->exstyle;
1159 $$->gotexstyle = TRUE;
1161 free($10);
1163 $$->extra = $11;
1167 opt_data: /* Empty */ { $$ = NULL; }
1168 | raw_data { $$ = $1; }
1171 helpid : /* Empty */ { $$ = NULL; }
1172 | ',' expr { $$ = new_int($2); }
1175 opt_exfont
1176 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1180 * FIXME: This odd expression is here to nullify an extra token found
1181 * in some appstudio produced resources which appear to do nothing.
1183 opt_expr: /* Empty */ { $$ = NULL; }
1184 | ',' expr { $$ = NULL; }
1187 /* ------------------------------ Menu ------------------------------ */
1188 menu : tMENU loadmemopts opt_lvc menu_body {
1189 if(!$4)
1190 yyerror("Menu must contain items");
1191 $$ = new_menu();
1192 if($2)
1194 $$->memopt = *($2);
1195 free($2);
1197 else
1198 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1199 $$->items = get_item_head($4);
1200 if($3)
1202 $$->lvc = *($3);
1203 free($3);
1205 if(!$$->lvc.language)
1206 $$->lvc.language = dup_language(currentlanguage);
1210 menu_body
1211 : tBEGIN item_definitions tEND { $$ = $2; }
1214 item_definitions
1215 : /* Empty */ {$$ = NULL;}
1216 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1217 $$=new_menu_item();
1218 $$->prev = $1;
1219 if($1)
1220 $1->next = $$;
1221 $$->id = $5;
1222 $$->state = $6;
1223 $$->name = $3;
1225 | item_definitions tMENUITEM tSEPARATOR {
1226 $$=new_menu_item();
1227 $$->prev = $1;
1228 if($1)
1229 $1->next = $$;
1231 | item_definitions tPOPUP tSTRING item_options menu_body {
1232 $$ = new_menu_item();
1233 $$->prev = $1;
1234 if($1)
1235 $1->next = $$;
1236 $$->popup = get_item_head($5);
1237 $$->name = $3;
1241 /* NOTE: item_options is right recursive because it would introduce
1242 * a shift/reduce conflict on ',' in itemex_options due to the
1243 * empty rule here. The parser is now forced to look beyond the ','
1244 * before reducing (force shift).
1245 * Right recursion here is not a problem because we cannot expect
1246 * more than 7 parserstack places to be occupied while parsing this
1247 * (who would want to specify a MF_x flag twice?).
1249 item_options
1250 : /* Empty */ { $$ = 0; }
1251 | ',' tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1252 | ',' tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1253 | ',' tHELP item_options { $$ = $3 | MF_HELP; }
1254 | ',' tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1255 | ',' tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1256 | ',' tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1259 /* ------------------------------ MenuEx ------------------------------ */
1260 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1261 if(!win32)
1262 yywarning("MENUEX not supported in 16-bit mode");
1263 if(!$4)
1264 yyerror("MenuEx must contain items");
1265 $$ = new_menuex();
1266 if($2)
1268 $$->memopt = *($2);
1269 free($2);
1271 else
1272 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1273 $$->items = get_itemex_head($4);
1274 if($3)
1276 $$->lvc = *($3);
1277 free($3);
1279 if(!$$->lvc.language)
1280 $$->lvc.language = dup_language(currentlanguage);
1284 menuex_body
1285 : tBEGIN itemex_definitions tEND { $$ = $2; }
1288 itemex_definitions
1289 : /* Empty */ {$$ = NULL; }
1290 | itemex_definitions tMENUITEM tSTRING itemex_options {
1291 $$ = new_menuex_item();
1292 $$->prev = $1;
1293 if($1)
1294 $1->next = $$;
1295 $$->name = $3;
1296 $$->id = $4->id;
1297 $$->type = $4->type;
1298 $$->state = $4->state;
1299 $$->helpid = $4->helpid;
1300 $$->gotid = $4->gotid;
1301 $$->gottype = $4->gottype;
1302 $$->gotstate = $4->gotstate;
1303 $$->gothelpid = $4->gothelpid;
1304 free($4);
1306 | itemex_definitions tMENUITEM tSEPARATOR {
1307 $$ = new_menuex_item();
1308 $$->prev = $1;
1309 if($1)
1310 $1->next = $$;
1312 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1313 $$ = new_menuex_item();
1314 $$->prev = $1;
1315 if($1)
1316 $1->next = $$;
1317 $$->popup = get_itemex_head($5);
1318 $$->name = $3;
1319 $$->id = $4->id;
1320 $$->type = $4->type;
1321 $$->state = $4->state;
1322 $$->helpid = $4->helpid;
1323 $$->gotid = $4->gotid;
1324 $$->gottype = $4->gottype;
1325 $$->gotstate = $4->gotstate;
1326 $$->gothelpid = $4->gothelpid;
1327 free($4);
1331 itemex_options
1332 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1333 | ',' expr {
1334 $$ = new_itemex_opt($2, 0, 0, 0);
1335 $$->gotid = TRUE;
1337 | ',' e_expr ',' e_expr item_options {
1338 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1339 $$->gotid = TRUE;
1340 $$->gottype = TRUE;
1341 $$->gotstate = TRUE;
1342 if($2) free($2);
1343 if($4) free($4);
1345 | ',' e_expr ',' e_expr ',' expr {
1346 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1347 $$->gotid = TRUE;
1348 $$->gottype = TRUE;
1349 $$->gotstate = TRUE;
1350 if($2) free($2);
1351 if($4) free($4);
1355 itemex_p_options
1356 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1357 | ',' expr {
1358 $$ = new_itemex_opt($2, 0, 0, 0);
1359 $$->gotid = TRUE;
1361 | ',' e_expr ',' expr {
1362 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1363 if($2) free($2);
1364 $$->gotid = TRUE;
1365 $$->gottype = TRUE;
1367 | ',' e_expr ',' e_expr ',' expr {
1368 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1369 if($2) free($2);
1370 if($4) free($4);
1371 $$->gotid = TRUE;
1372 $$->gottype = TRUE;
1373 $$->gotstate = TRUE;
1375 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1376 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1377 if($2) free($2);
1378 if($4) free($4);
1379 if($6) free($6);
1380 $$->gotid = TRUE;
1381 $$->gottype = TRUE;
1382 $$->gotstate = TRUE;
1383 $$->gothelpid = TRUE;
1387 /* ------------------------------ StringTable ------------------------------ */
1388 /* Stringtables are parsed differently than other resources because their
1389 * layout is substantially different from other resources.
1390 * The table is parsed through a _global_ variable 'tagstt' which holds the
1391 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1392 * list of stringtables of different languages.
1394 stringtable
1395 : stt_head tBEGIN strings tEND {
1396 if(!$3)
1398 yyerror("Stringtable must have at least one entry");
1400 else
1402 stringtable_t *stt;
1403 /* Check if we added to a language table or created
1404 * a new one.
1406 for(stt = sttres; stt; stt = stt->next)
1408 if(stt == tagstt)
1409 break;
1411 if(!stt)
1413 /* It is a new one */
1414 if(sttres)
1416 sttres->prev = tagstt;
1417 tagstt->next = sttres;
1418 sttres = tagstt;
1420 else
1421 sttres = tagstt;
1423 /* Else were done */
1425 if(tagstt_memopt)
1427 free(tagstt_memopt);
1428 tagstt_memopt = NULL;
1431 $$ = tagstt;
1435 /* This is to get the language of the currently parsed stringtable */
1436 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1437 if((tagstt = find_stringtable($3)) == NULL)
1438 tagstt = new_stringtable($3);
1439 tagstt_memopt = $2;
1440 tagstt_version = $3->version;
1441 tagstt_characts = $3->characts;
1442 if($3)
1443 free($3);
1447 strings : /* Empty */ { $$ = NULL; }
1448 | strings expr opt_comma tSTRING {
1449 int i;
1450 assert(tagstt != NULL);
1451 if($2 > 65535 || $2 < -32768)
1452 yyerror("Stringtable entry's ID out of range (%d)", $2);
1453 /* Search for the ID */
1454 for(i = 0; i < tagstt->nentries; i++)
1456 if(tagstt->entries[i].id == $2)
1457 yyerror("Stringtable ID %d already in use", $2);
1459 /* If we get here, then we have a new unique entry */
1460 tagstt->nentries++;
1461 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1462 tagstt->entries[tagstt->nentries-1].id = $2;
1463 tagstt->entries[tagstt->nentries-1].str = $4;
1464 if(tagstt_memopt)
1465 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1466 else
1467 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1468 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1469 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1471 if(!win32 && $4->size > 254)
1472 yyerror("Stringtable entry more than 254 characters");
1473 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1474 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1475 $$ = tagstt;
1479 opt_comma /* There seem to be two ways to specify a stringtable... */
1480 : /* Empty */
1481 | ','
1484 /* ------------------------------ VersionInfo ------------------------------ */
1485 versioninfo
1486 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1487 $$ = $3;
1488 if($2)
1490 $$->memopt = *($2);
1491 free($2);
1493 else
1494 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1495 $$->blocks = get_ver_block_head($5);
1496 /* Set language; there is no version or characteristics */
1497 $$->lvc.language = dup_language(currentlanguage);
1501 fix_version
1502 : /* Empty */ { $$ = new_versioninfo(); }
1503 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1504 if($1->gotit.fv)
1505 yyerror("FILEVERSION already defined");
1506 $$ = $1;
1507 $$->filever_maj1 = $3;
1508 $$->filever_maj2 = $5;
1509 $$->filever_min1 = $7;
1510 $$->filever_min2 = $9;
1511 $$->gotit.fv = 1;
1513 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1514 if($1->gotit.pv)
1515 yyerror("PRODUCTVERSION already defined");
1516 $$ = $1;
1517 $$->prodver_maj1 = $3;
1518 $$->prodver_maj2 = $5;
1519 $$->prodver_min1 = $7;
1520 $$->prodver_min2 = $9;
1521 $$->gotit.pv = 1;
1523 | fix_version tFILEFLAGS expr {
1524 if($1->gotit.ff)
1525 yyerror("FILEFLAGS already defined");
1526 $$ = $1;
1527 $$->fileflags = $3;
1528 $$->gotit.ff = 1;
1530 | fix_version tFILEFLAGSMASK expr {
1531 if($1->gotit.ffm)
1532 yyerror("FILEFLAGSMASK already defined");
1533 $$ = $1;
1534 $$->fileflagsmask = $3;
1535 $$->gotit.ffm = 1;
1537 | fix_version tFILEOS expr {
1538 if($1->gotit.fo)
1539 yyerror("FILEOS already defined");
1540 $$ = $1;
1541 $$->fileos = $3;
1542 $$->gotit.fo = 1;
1544 | fix_version tFILETYPE expr {
1545 if($1->gotit.ft)
1546 yyerror("FILETYPE already defined");
1547 $$ = $1;
1548 $$->filetype = $3;
1549 $$->gotit.ft = 1;
1551 | fix_version tFILESUBTYPE expr {
1552 if($1->gotit.fst)
1553 yyerror("FILESUBTYPE already defined");
1554 $$ = $1;
1555 $$->filesubtype = $3;
1556 $$->gotit.fst = 1;
1560 ver_blocks
1561 : /* Empty */ { $$ = NULL; }
1562 | ver_blocks ver_block {
1563 $$ = $2;
1564 $$->prev = $1;
1565 if($1)
1566 $1->next = $$;
1570 ver_block
1571 : tBLOCK tSTRING tBEGIN ver_values tEND {
1572 $$ = new_ver_block();
1573 $$->name = $2;
1574 $$->values = get_ver_value_head($4);
1578 ver_values
1579 : /* Empty */ { $$ = NULL; }
1580 | ver_values ver_value {
1581 $$ = $2;
1582 $$->prev = $1;
1583 if($1)
1584 $1->next = $$;
1588 ver_value
1589 : ver_block {
1590 $$ = new_ver_value();
1591 $$->type = val_block;
1592 $$->value.block = $1;
1594 | tVALUE tSTRING ',' tSTRING {
1595 $$ = new_ver_value();
1596 $$->type = val_str;
1597 $$->key = $2;
1598 $$->value.str = $4;
1600 | tVALUE tSTRING ',' ver_words {
1601 $$ = new_ver_value();
1602 $$->type = val_words;
1603 $$->key = $2;
1604 $$->value.words = $4;
1608 ver_words
1609 : expr { $$ = new_ver_words($1); }
1610 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1613 /* ------------------------------ Toolbar ------------------------------ */
1614 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1615 int nitems;
1616 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1617 $$ = new_toolbar($3, $5, items, nitems);
1618 if($2)
1620 $$->memopt = *($2);
1621 free($2);
1623 else
1625 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1627 if($6)
1629 $$->lvc = *($6);
1630 free($6);
1632 if(!$$->lvc.language)
1634 $$->lvc.language = dup_language(currentlanguage);
1639 toolbar_items
1640 : /* Empty */ { $$ = NULL; }
1641 | toolbar_items tBUTTON expr {
1642 toolbar_item_t *idrec = new_toolbar_item();
1643 idrec->id = $3;
1644 $$ = ins_tlbr_button($1, idrec);
1646 | toolbar_items tSEPARATOR {
1647 toolbar_item_t *idrec = new_toolbar_item();
1648 idrec->id = 0;
1649 $$ = ins_tlbr_button($1, idrec);
1653 /* ------------------------------ Memory options ------------------------------ */
1654 loadmemopts
1655 : /* Empty */ { $$ = NULL; }
1656 | loadmemopts lamo {
1657 if($1)
1659 *($1) |= *($2);
1660 $$ = $1;
1661 free($2);
1663 else
1664 $$ = $2;
1666 | loadmemopts lama {
1667 if($1)
1669 *($1) &= *($2);
1670 $$ = $1;
1671 free($2);
1673 else
1675 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1676 $$ = $2;
1681 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1682 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1683 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1684 | tPURE { $$ = new_int(WRC_MO_PURE); }
1687 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1688 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1689 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1692 /* ------------------------------ Win32 options ------------------------------ */
1693 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1694 | opt_lvc opt_language {
1695 if(!win32)
1696 yywarning("LANGUAGE not supported in 16-bit mode");
1697 if($1->language)
1698 yyerror("Language already defined");
1699 $$ = $1;
1700 $1->language = $2;
1702 | opt_lvc opt_characts {
1703 if(!win32)
1704 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1705 if($1->characts)
1706 yyerror("Characteristics already defined");
1707 $$ = $1;
1708 $1->characts = $2;
1710 | opt_lvc opt_version {
1711 if(!win32)
1712 yywarning("VERSION not supported in 16-bit mode");
1713 if($1->version)
1714 yyerror("Version already defined");
1715 $$ = $1;
1716 $1->version = $2;
1721 * This here is another s/r conflict on {bi,u}nary + and -.
1722 * It is due to the look-ahead which must determine when the
1723 * rule opt_language ends. It could be solved with adding a
1724 * tNL at the end, but that seems unreasonable to do.
1725 * The conflict is now moved to the expression handling below.
1727 opt_language
1728 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4); }
1731 opt_characts
1732 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1735 opt_version
1736 : tVERSION expr { $$ = new_version($2); }
1739 /* ------------------------------ Raw data handling ------------------------------ */
1740 raw_data: opt_lvc tBEGIN raw_elements tEND {
1741 if($1)
1743 $3->lvc = *($1);
1744 free($1);
1747 if(!$3->lvc.language)
1748 $3->lvc.language = dup_language(currentlanguage);
1750 $$ = $3;
1754 raw_elements
1755 : tRAWDATA { $$ = $1; }
1756 | tNUMBER { $$ = int2raw_data($1); }
1757 | tLNUMBER { $$ = long2raw_data($1); }
1758 | tSTRING { $$ = str2raw_data($1); }
1759 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1760 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1761 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1762 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1765 /* File data or raw data */
1766 file_raw: filename {
1767 $$ = load_file($1);
1768 $$->lvc.language = dup_language(currentlanguage);
1770 | raw_data { $$ = $1; }
1773 /* ------------------------------ Win32 expressions ------------------------------ */
1774 /* All win16 numbers are also handled here. This is inconsistent with MS'
1775 * resource compiler, but what the heck, its just handy to have.
1777 e_expr : /* Empty */ { $$ = 0; }
1778 | expr { $$ = new_int($1); }
1781 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1782 expr : xpr { $$ = ($1); }
1785 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1786 | xpr '-' xpr { $$ = ($1) - ($3); }
1787 | xpr '|' xpr { $$ = ($1) | ($3); }
1788 | xpr '&' xpr { $$ = ($1) & ($3); }
1789 | xpr '*' xpr { $$ = ($1) * ($3); }
1790 | xpr '/' xpr { $$ = ($1) / ($3); }
1791 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1792 | '~' xpr { $$ = ~($2); }
1793 | '-' xpr %prec pUPM { $$ = -($2); }
1794 | '+' xpr %prec pUPM { $$ = $2; }
1795 | '(' xpr ')' { $$ = $2; }
1796 | any_num { $$ = $1; }
1797 | tNOT any_num { $$ = ~($2); }
1800 any_num : tNUMBER { $$ = $1; }
1801 | tLNUMBER { $$ = $1; }
1805 /* Dialog specific functions */
1806 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1808 assert(dlg != NULL);
1809 if(dlg->style == NULL)
1811 dlg->style = new_style(0,0);
1814 if(dlg->gotstyle)
1816 yywarning("Style already defined, or-ing together");
1818 else
1820 dlg->style->or_mask = 0;
1821 dlg->style->and_mask = 0;
1823 dlg->style->or_mask |= st->or_mask;
1824 dlg->style->and_mask |= st->and_mask;
1825 dlg->gotstyle = TRUE;
1826 free(st);
1827 return dlg;
1830 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1832 assert(dlg != NULL);
1833 if(dlg->exstyle == NULL)
1835 dlg->exstyle = new_style(0,0);
1838 if(dlg->gotexstyle)
1840 yywarning("ExStyle already defined, or-ing together");
1842 else
1844 dlg->exstyle->or_mask = 0;
1845 dlg->exstyle->and_mask = 0;
1847 dlg->exstyle->or_mask |= st->or_mask;
1848 dlg->exstyle->and_mask |= st->and_mask;
1849 dlg->gotexstyle = TRUE;
1850 free(st);
1851 return dlg;
1854 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1856 assert(dlg != NULL);
1857 if(dlg->title)
1858 yyerror("Caption already defined");
1859 dlg->title = s;
1860 return dlg;
1863 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1865 assert(dlg != NULL);
1866 if(dlg->font)
1867 yyerror("Font already defined");
1868 dlg->font = f;
1869 return dlg;
1872 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1874 assert(dlg != NULL);
1875 if(dlg->dlgclass)
1876 yyerror("Class already defined");
1877 dlg->dlgclass = n;
1878 return dlg;
1881 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1883 assert(dlg != NULL);
1884 if(dlg->menu)
1885 yyerror("Menu already defined");
1886 dlg->menu = m;
1887 return dlg;
1890 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1892 assert(dlg != NULL);
1893 if(dlg->lvc.language)
1894 yyerror("Language already defined");
1895 dlg->lvc.language = l;
1896 return dlg;
1899 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1901 assert(dlg != NULL);
1902 if(dlg->lvc.characts)
1903 yyerror("Characteristics already defined");
1904 dlg->lvc.characts = c;
1905 return dlg;
1908 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1910 assert(dlg != NULL);
1911 if(dlg->lvc.version)
1912 yyerror("Version already defined");
1913 dlg->lvc.version = v;
1914 return dlg;
1917 /* Controls specific functions */
1918 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1920 /* Hm... this seems to be jammed in at all time... */
1921 int defaultstyle = WS_CHILD | WS_VISIBLE;
1923 assert(ctrl != NULL);
1924 ctrl->prev = prev;
1926 if(prev)
1927 prev->next = ctrl;
1929 if(type != -1)
1931 ctrl->ctlclass = new_name_id();
1932 ctrl->ctlclass->type = name_ord;
1933 ctrl->ctlclass->name.i_name = type;
1936 switch(type)
1938 case CT_BUTTON:
1939 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1940 defaultstyle |= WS_TABSTOP;
1941 break;
1942 case CT_EDIT:
1943 defaultstyle |= WS_TABSTOP | WS_BORDER;
1944 break;
1945 case CT_LISTBOX:
1946 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1947 break;
1948 case CT_COMBOBOX:
1949 defaultstyle |= CBS_SIMPLE;
1950 break;
1951 case CT_STATIC:
1952 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1953 defaultstyle |= WS_GROUP;
1954 break;
1957 if(!ctrl->gotstyle) /* Handle default style setting */
1959 switch(type)
1961 case CT_EDIT:
1962 defaultstyle |= ES_LEFT;
1963 break;
1964 case CT_LISTBOX:
1965 defaultstyle |= LBS_NOTIFY;
1966 break;
1967 case CT_COMBOBOX:
1968 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1969 break;
1970 case CT_SCROLLBAR:
1971 defaultstyle |= SBS_HORZ;
1972 break;
1973 case CT_BUTTON:
1974 switch(special_style)
1976 case BS_CHECKBOX:
1977 case BS_DEFPUSHBUTTON:
1978 case BS_PUSHBUTTON:
1979 case BS_GROUPBOX:
1980 /* case BS_PUSHBOX: */
1981 case BS_AUTORADIOBUTTON:
1982 case BS_AUTO3STATE:
1983 case BS_3STATE:
1984 case BS_AUTOCHECKBOX:
1985 defaultstyle |= WS_TABSTOP;
1986 break;
1987 default:
1988 yywarning("Unknown default button control-style 0x%08x", special_style);
1989 case BS_RADIOBUTTON:
1990 break;
1992 break;
1994 case CT_STATIC:
1995 switch(special_style)
1997 case SS_LEFT:
1998 case SS_RIGHT:
1999 case SS_CENTER:
2000 defaultstyle |= WS_GROUP;
2001 break;
2002 case SS_ICON: /* Special case */
2003 break;
2004 default:
2005 yywarning("Unknown default static control-style 0x%08x", special_style);
2006 break;
2008 break;
2009 case -1: /* Generic control */
2010 goto byebye;
2012 default:
2013 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2017 /* The SS_ICON flag is always forced in for icon controls */
2018 if(type == CT_STATIC && special_style == SS_ICON)
2019 defaultstyle |= SS_ICON;
2021 if (!ctrl->gotstyle)
2022 ctrl->style = new_style(0,0);
2024 /* combine all styles */
2025 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2026 ctrl->gotstyle = TRUE;
2027 byebye:
2028 /* combine with NOT mask */
2029 if (ctrl->gotstyle)
2031 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2032 ctrl->style->and_mask = 0;
2034 if (ctrl->gotexstyle)
2036 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2037 ctrl->exstyle->and_mask = 0;
2039 return ctrl;
2042 static name_id_t *convert_ctlclass(name_id_t *cls)
2044 char *cc;
2045 int iclass;
2047 if(cls->type == name_ord)
2048 return cls;
2049 assert(cls->type == name_str);
2050 if(cls->type == str_unicode)
2052 yyerror("Don't yet support unicode class comparison");
2054 else
2055 cc = cls->name.s_name->str.cstr;
2057 if(!strcasecmp("BUTTON", cc))
2058 iclass = CT_BUTTON;
2059 else if(!strcasecmp("COMBOBOX", cc))
2060 iclass = CT_COMBOBOX;
2061 else if(!strcasecmp("LISTBOX", cc))
2062 iclass = CT_LISTBOX;
2063 else if(!strcasecmp("EDIT", cc))
2064 iclass = CT_EDIT;
2065 else if(!strcasecmp("STATIC", cc))
2066 iclass = CT_STATIC;
2067 else if(!strcasecmp("SCROLLBAR", cc))
2068 iclass = CT_SCROLLBAR;
2069 else
2070 return cls; /* No default, return user controlclass */
2072 free(cls->name.s_name->str.cstr);
2073 free(cls->name.s_name);
2074 cls->type = name_ord;
2075 cls->name.i_name = iclass;
2076 return cls;
2079 /* DialogEx specific functions */
2080 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2082 assert(dlg != NULL);
2083 if(dlg->style == NULL)
2085 dlg->style = new_style(0,0);
2088 if(dlg->gotstyle)
2090 yywarning("Style already defined, or-ing together");
2092 else
2094 dlg->style->or_mask = 0;
2095 dlg->style->and_mask = 0;
2097 dlg->style->or_mask |= st->or_mask;
2098 dlg->style->and_mask |= st->and_mask;
2099 dlg->gotstyle = TRUE;
2100 free(st);
2101 return dlg;
2104 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2106 assert(dlg != NULL);
2107 if(dlg->exstyle == NULL)
2109 dlg->exstyle = new_style(0,0);
2112 if(dlg->gotexstyle)
2114 yywarning("ExStyle already defined, or-ing together");
2116 else
2118 dlg->exstyle->or_mask = 0;
2119 dlg->exstyle->and_mask = 0;
2121 dlg->exstyle->or_mask |= st->or_mask;
2122 dlg->exstyle->and_mask |= st->and_mask;
2123 dlg->gotexstyle = TRUE;
2124 free(st);
2125 return dlg;
2128 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2130 assert(dlg != NULL);
2131 if(dlg->title)
2132 yyerror("Caption already defined");
2133 dlg->title = s;
2134 return dlg;
2137 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2139 assert(dlg != NULL);
2140 if(dlg->font)
2141 yyerror("Font already defined");
2142 dlg->font = f;
2143 return dlg;
2146 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2148 assert(dlg != NULL);
2149 if(dlg->dlgclass)
2150 yyerror("Class already defined");
2151 dlg->dlgclass = n;
2152 return dlg;
2155 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2157 assert(dlg != NULL);
2158 if(dlg->menu)
2159 yyerror("Menu already defined");
2160 dlg->menu = m;
2161 return dlg;
2164 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2166 assert(dlg != NULL);
2167 if(dlg->lvc.language)
2168 yyerror("Language already defined");
2169 dlg->lvc.language = l;
2170 return dlg;
2173 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2175 assert(dlg != NULL);
2176 if(dlg->lvc.characts)
2177 yyerror("Characteristics already defined");
2178 dlg->lvc.characts = c;
2179 return dlg;
2182 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2184 assert(dlg != NULL);
2185 if(dlg->lvc.version)
2186 yyerror("Version already defined");
2187 dlg->lvc.version = v;
2188 return dlg;
2191 /* Accelerator specific functions */
2192 static event_t *add_event(int key, int id, int flags, event_t *prev)
2194 event_t *ev = new_event();
2196 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2197 yyerror("Cannot use both ASCII and VIRTKEY");
2199 ev->key = key;
2200 ev->id = id;
2201 ev->flags = flags & ~WRC_AF_ASCII;
2202 ev->prev = prev;
2203 if(prev)
2204 prev->next = ev;
2205 return ev;
2208 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2210 int keycode = 0;
2211 event_t *ev = new_event();
2213 if(key->type != str_char)
2214 yyerror("Key code must be an ascii string");
2216 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0]) && !isdigit(key->str.cstr[0])))
2217 yyerror("VIRTKEY code is not equal to ascii value");
2219 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2221 yyerror("Cannot use both '^' and CONTROL modifier");
2223 else if(key->str.cstr[0] == '^')
2225 keycode = toupper(key->str.cstr[1]) - '@';
2226 if(keycode >= ' ')
2227 yyerror("Control-code out of range");
2229 else
2230 keycode = key->str.cstr[0];
2231 ev->key = keycode;
2232 ev->id = id;
2233 ev->flags = flags & ~WRC_AF_ASCII;
2234 ev->prev = prev;
2235 if(prev)
2236 prev->next = ev;
2237 return ev;
2240 /* MenuEx specific functions */
2241 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2243 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2244 opt->id = id;
2245 opt->type = type;
2246 opt->state = state;
2247 opt->helpid = helpid;
2248 return opt;
2251 /* Raw data functions */
2252 static raw_data_t *load_file(string_t *name)
2254 FILE *fp;
2255 raw_data_t *rd;
2256 if(name->type != str_char)
2257 yyerror("Filename must be ASCII string");
2259 fp = open_include(name->str.cstr, 1, NULL);
2260 if(!fp)
2261 yyerror("Cannot open file %s", name->str.cstr);
2262 rd = new_raw_data();
2263 fseek(fp, 0, SEEK_END);
2264 rd->size = ftell(fp);
2265 fseek(fp, 0, SEEK_SET);
2266 rd->data = (char *)xmalloc(rd->size);
2267 fread(rd->data, rd->size, 1, fp);
2268 fclose(fp);
2269 return rd;
2272 static raw_data_t *int2raw_data(int i)
2274 raw_data_t *rd;
2276 if((int)((short)i) != i)
2277 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2279 rd = new_raw_data();
2280 rd->size = sizeof(short);
2281 rd->data = (char *)xmalloc(rd->size);
2282 switch(byteorder)
2284 #ifndef WORDS_BIGENDIAN
2285 case WRC_BO_BIG:
2286 #else
2287 case WRC_BO_LITTLE:
2288 #endif
2289 *(WORD *)(rd->data) = BYTESWAP_WORD((WORD)i);
2290 break;
2291 default:
2292 *(WORD *)(rd->data) = (WORD)i;
2293 break;
2295 return rd;
2298 static raw_data_t *long2raw_data(int i)
2300 raw_data_t *rd;
2301 rd = new_raw_data();
2302 rd->size = sizeof(int);
2303 rd->data = (char *)xmalloc(rd->size);
2304 switch(byteorder)
2306 #ifndef WORDS_BIGENDIAN
2307 case WRC_BO_BIG:
2308 #else
2309 case WRC_BO_LITTLE:
2310 #endif
2311 *(DWORD *)(rd->data) = BYTESWAP_DWORD((DWORD)i);
2312 break;
2313 default:
2314 *(DWORD *)(rd->data) = (DWORD)i;
2315 break;
2317 return rd;
2320 static raw_data_t *str2raw_data(string_t *str)
2322 raw_data_t *rd;
2323 rd = new_raw_data();
2324 rd->size = str->size * (str->type == str_char ? 1 : 2);
2325 rd->data = (char *)xmalloc(rd->size);
2326 if(str->type == str_char)
2327 memcpy(rd->data, str->str.cstr, rd->size);
2328 else if(str->type == str_unicode)
2330 int i;
2331 switch(byteorder)
2333 #ifndef WORDS_BIGENDIAN
2334 case WRC_BO_BIG:
2335 #else
2336 case WRC_BO_LITTLE:
2337 #endif
2338 for(i = 0; i < str->size; i++)
2339 *(WORD *)&(rd->data[2*i]) = BYTESWAP_WORD((WORD)str->str.wstr[i]);
2340 break;
2341 default:
2342 for(i = 0; i < str->size; i++)
2343 *(WORD *)&(rd->data[2*i]) = (WORD)str->str.wstr[i];
2344 break;
2347 else
2348 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2349 return rd;
2352 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2354 r1->data = xrealloc(r1->data, r1->size + r2->size);
2355 memcpy(r1->data + r1->size, r2->data, r2->size);
2356 r1->size += r2->size;
2357 return r1;
2360 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2362 raw_data_t *t = int2raw_data(i);
2363 merge_raw_data(r1, t);
2364 free(t->data);
2365 free(t);
2366 return r1;
2369 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2371 raw_data_t *t = long2raw_data(i);
2372 merge_raw_data(r1, t);
2373 free(t->data);
2374 free(t);
2375 return r1;
2378 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2380 raw_data_t *t = str2raw_data(str);
2381 merge_raw_data(r1, t);
2382 free(t->data);
2383 free(t);
2384 return r1;
2387 /* Function the go back in a list to get the head */
2388 static menu_item_t *get_item_head(menu_item_t *p)
2390 if(!p)
2391 return NULL;
2392 while(p->prev)
2393 p = p->prev;
2394 return p;
2397 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2399 if(!p)
2400 return NULL;
2401 while(p->prev)
2402 p = p->prev;
2403 return p;
2406 static resource_t *get_resource_head(resource_t *p)
2408 if(!p)
2409 return NULL;
2410 while(p->prev)
2411 p = p->prev;
2412 return p;
2415 static ver_block_t *get_ver_block_head(ver_block_t *p)
2417 if(!p)
2418 return NULL;
2419 while(p->prev)
2420 p = p->prev;
2421 return p;
2424 static ver_value_t *get_ver_value_head(ver_value_t *p)
2426 if(!p)
2427 return NULL;
2428 while(p->prev)
2429 p = p->prev;
2430 return p;
2433 static control_t *get_control_head(control_t *p)
2435 if(!p)
2436 return NULL;
2437 while(p->prev)
2438 p = p->prev;
2439 return p;
2442 static event_t *get_event_head(event_t *p)
2444 if(!p)
2445 return NULL;
2446 while(p->prev)
2447 p = p->prev;
2448 return p;
2451 /* Find a stringtable with given language */
2452 static stringtable_t *find_stringtable(lvc_t *lvc)
2454 stringtable_t *stt;
2456 assert(lvc != NULL);
2458 if(!lvc->language)
2459 lvc->language = dup_language(currentlanguage);
2461 for(stt = sttres; stt; stt = stt->next)
2463 if(stt->lvc.language->id == lvc->language->id
2464 && stt->lvc.language->id == lvc->language->id)
2466 /* Found a table with the same language */
2467 /* The version and characteristics are now handled
2468 * in the generation of the individual stringtables.
2469 * This enables localized analysis.
2470 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2471 || (!stt->lvc.version && lvc->version)
2472 || (stt->lvc.version && !lvc->version))
2473 yywarning("Stringtable's versions are not the same, using first definition");
2475 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2476 || (!stt->lvc.characts && lvc->characts)
2477 || (stt->lvc.characts && !lvc->characts))
2478 yywarning("Stringtable's characteristics are not the same, using first definition");
2480 return stt;
2483 return NULL;
2486 /* qsort sorting function for string table entries */
2487 #define STE(p) ((stt_entry_t *)(p))
2488 static int sort_stt_entry(const void *e1, const void *e2)
2490 return STE(e1)->id - STE(e2)->id;
2492 #undef STE
2494 static resource_t *build_stt_resources(stringtable_t *stthead)
2496 stringtable_t *stt;
2497 stringtable_t *newstt;
2498 resource_t *rsc;
2499 resource_t *rsclist = NULL;
2500 resource_t *rsctail = NULL;
2501 int i;
2502 int j;
2503 DWORD andsum;
2504 DWORD orsum;
2505 characts_t *characts;
2506 version_t *version;
2508 if(!stthead)
2509 return NULL;
2511 /* For all languages defined */
2512 for(stt = stthead; stt; stt = stt->next)
2514 assert(stt->nentries > 0);
2516 /* Sort the entries */
2517 if(stt->nentries > 1)
2518 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2520 for(i = 0; i < stt->nentries; )
2522 newstt = new_stringtable(&stt->lvc);
2523 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2524 newstt->nentries = 16;
2525 newstt->idbase = stt->entries[i].id & ~0xf;
2526 for(j = 0; j < 16 && i < stt->nentries; j++)
2528 if(stt->entries[i].id - newstt->idbase == j)
2530 newstt->entries[j] = stt->entries[i];
2531 i++;
2534 andsum = ~0;
2535 orsum = 0;
2536 characts = NULL;
2537 version = NULL;
2538 /* Check individual memory options and get
2539 * the first characteristics/version
2541 for(j = 0; j < 16; j++)
2543 if(!newstt->entries[j].str)
2544 continue;
2545 andsum &= newstt->entries[j].memopt;
2546 orsum |= newstt->entries[j].memopt;
2547 if(!characts)
2548 characts = newstt->entries[j].characts;
2549 if(!version)
2550 version = newstt->entries[j].version;
2552 if(andsum != orsum)
2554 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2556 /* Check version and characteristics */
2557 for(j = 0; j < 16; j++)
2559 if(characts
2560 && newstt->entries[j].characts
2561 && *newstt->entries[j].characts != *characts)
2562 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2563 if(version
2564 && newstt->entries[j].version
2565 && *newstt->entries[j].version != *version)
2566 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2568 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2569 rsc->name = new_name_id();
2570 rsc->name->type = name_ord;
2571 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2572 rsc->memopt = andsum; /* Set to least common denominator */
2573 newstt->memopt = andsum;
2574 newstt->lvc.characts = characts;
2575 newstt->lvc.version = version;
2576 if(!rsclist)
2578 rsclist = rsc;
2579 rsctail = rsc;
2581 else
2583 rsctail->next = rsc;
2584 rsc->prev = rsctail;
2585 rsctail = rsc;
2589 return rsclist;
2593 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2595 idrec->prev = prev;
2596 if(prev)
2597 prev->next = idrec;
2599 return idrec;
2602 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2604 if(!p)
2606 *nitems = 0;
2607 return NULL;
2610 *nitems = 1;
2612 while(p->prev)
2614 (*nitems)++;
2615 p = p->prev;
2618 return p;
2621 static string_t *make_filename(string_t *str)
2623 char *cptr;
2625 if(str->type != str_char)
2626 yyerror("Cannot handle UNICODE filenames");
2628 /* Remove escaped backslash and convert to forward */
2629 cptr = str->str.cstr;
2630 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2632 if(cptr[1] == '\\')
2634 memmove(cptr, cptr+1, strlen(cptr));
2635 str->size--;
2637 *cptr = '/';
2640 /* Convert to lower case. Seems to be reasonable to do */
2641 for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
2643 *cptr = tolower(*cptr);
2645 return str;
2649 * Process all resources to extract fonts and build
2650 * a fontdir resource.
2652 * Note: MS' resource compiler (build 1472) does not
2653 * handle font resources with different languages.
2654 * The fontdir is generated in the last active language
2655 * and font identifiers must be unique across the entire
2656 * source.
2657 * This is not logical considering the localization
2658 * constraints of all other resource types. MS has,
2659 * most probably, never testet localized fonts. However,
2660 * using fontresources is rare, so it might not occur
2661 * in normal applications.
2662 * Wine does require better localization because a lot
2663 * of languages are coded into the same executable.
2664 * Therefore, I will generate fontdirs for *each*
2665 * localized set of fonts.
2667 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2669 static int once = 0;
2670 if(!once)
2672 warning("Need to parse fonts, not yet implemented");
2673 once++;
2675 return NULL;
2678 static resource_t *build_fontdirs(resource_t *tail)
2680 resource_t *rsc;
2681 resource_t *lst = NULL;
2682 resource_t **fnt = NULL; /* List of all fonts */
2683 int nfnt = 0;
2684 resource_t **fnd = NULL; /* List of all fontdirs */
2685 int nfnd = 0;
2686 resource_t **lanfnt = NULL;
2687 int nlanfnt = 0;
2688 int i;
2689 name_id_t nid;
2690 string_t str;
2691 int fntleft;
2693 nid.type = name_str;
2694 nid.name.s_name = &str;
2695 str.type = str_char;
2696 str.str.cstr = "FONTDIR";
2697 str.size = 7;
2699 /* Extract all fonts and fontdirs */
2700 for(rsc = tail; rsc; rsc = rsc->prev)
2702 if(rsc->type == res_fnt)
2704 nfnt++;
2705 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2706 fnt[nfnt-1] = rsc;
2708 else if(rsc->type == res_fntdir)
2710 nfnd++;
2711 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2712 fnd[nfnd-1] = rsc;
2716 /* Verify the name of the present fontdirs */
2717 for(i = 0; i < nfnd; i++)
2719 if(compare_name_id(&nid, fnd[i]->name))
2721 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2722 get_nameid_str(fnd[i]->name));
2723 fnd[i] = NULL;
2727 /* Sanity check */
2728 if(nfnt == 0)
2730 if(nfnd != 0)
2731 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2732 goto clean;
2735 /* Copy space */
2736 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2738 /* Get all fonts covered by fontdirs */
2739 for(i = 0; i < nfnd; i++)
2741 int j;
2742 WORD cnt;
2743 int isswapped = 0;
2745 if(!fnd[i])
2746 continue;
2747 for(j = 0; j < nfnt; j++)
2749 if(!fnt[j])
2750 continue;
2751 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2753 lanfnt[nlanfnt] = fnt[j];
2754 nlanfnt++;
2755 fnt[j] = NULL;
2759 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2760 if(nlanfnt == cnt)
2761 isswapped = 0;
2762 else if(nlanfnt == BYTESWAP_WORD(cnt))
2763 isswapped = 1;
2764 else
2765 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2766 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2767 #ifdef WORDS_BIGENDIAN
2768 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2769 #else
2770 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2771 #endif
2773 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2777 /* We now have fonts left where we need to make a fontdir resource */
2778 for(i = fntleft = 0; i < nfnt; i++)
2780 if(fnt[i])
2781 fntleft++;
2783 while(fntleft)
2785 /* Get fonts of same language in lanfnt[] */
2786 for(i = nlanfnt = 0; i < nfnt; i++)
2788 if(fnt[i])
2790 if(!nlanfnt)
2792 addlanfnt:
2793 lanfnt[nlanfnt] = fnt[i];
2794 nlanfnt++;
2795 fnt[i] = NULL;
2796 fntleft--;
2798 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2799 goto addlanfnt;
2802 /* and build a fontdir */
2803 rsc = build_fontdir(lanfnt, nlanfnt);
2804 if(rsc)
2806 if(lst)
2808 lst->next = rsc;
2809 rsc->prev = lst;
2811 lst = rsc;
2815 free(lanfnt);
2816 clean:
2817 if(fnt)
2818 free(fnt);
2819 if(fnd)
2820 free(fnd);
2821 return lst;