Add include for LoadLibrary.
[wine.git] / tools / wrc / parser.y
blob3cd1d1ca5fb65428ae05457c15051b1f166b4e09
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 raw_data { $$ = 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 filename {
649 if(!win32)
650 yywarning("MESSAGETABLE not supported in 16-bit mode");
651 $$ = new_messagetable(load_file($2));
655 /* ------------------------------ RCData ------------------------------ */
656 rcdata : tRCDATA loadmemopts raw_data { $$ = new_rcdata($3, $2); }
659 /* ------------------------------ DLGINIT ------------------------------ */
660 dlginit : tDLGINIT loadmemopts raw_data { $$ = new_dlginit($3, $2); }
663 /* ------------------------------ UserType ------------------------------ */
664 userres : usertype loadmemopts file_raw { $$ = new_user($1, $3, $2); }
667 usertype: tNUMBER {
668 $$ = new_name_id();
669 $$->type = name_ord;
670 $$->name.i_name = $1;
672 | tIDENT {
673 $$ = new_name_id();
674 $$->type = name_str;
675 $$->name.s_name = $1;
679 /* ------------------------------ Accelerator ------------------------------ */
680 accelerators
681 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
682 $$ = new_accelerator();
683 if($2)
685 $$->memopt = *($2);
686 free($2);
688 else
690 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
692 if(!$5)
693 yyerror("Accelerator table must have at least one entry");
694 $$->events = get_event_head($5);
695 if($3)
697 $$->lvc = *($3);
698 free($3);
700 if(!$$->lvc.language)
701 $$->lvc.language = dup_language(currentlanguage);
705 events : /* Empty */ { $$=NULL; }
706 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
707 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
711 * The empty rule generates a s/r conflict because of {bi,u}nary expr
712 * on - and +. It cannot be solved in any way because it is the same as
713 * the if/then/else problem (LALR(1) problem). The conflict is moved
714 * away by forcing it to be in the expression handling below.
716 acc_opt : /* Empty */ { $$ = 0; }
717 | ',' accs { $$ = $2; }
720 accs : acc { $$ = $1; }
721 | accs ',' acc { $$ = $1 | $3; }
724 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
725 | tSHIFT { $$ = WRC_AF_SHIFT; }
726 | tCONTROL { $$ = WRC_AF_CONTROL; }
727 | tALT { $$ = WRC_AF_ALT; }
728 | tASCII { $$ = WRC_AF_ASCII; }
729 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
732 /* ------------------------------ Dialog ------------------------------ */
733 /* FIXME: Support EXSTYLE in the dialog line itself */
734 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
735 tBEGIN ctrls tEND {
736 if($2)
738 $10->memopt = *($2);
739 free($2);
741 else
742 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
743 $10->x = $3;
744 $10->y = $5;
745 $10->width = $7;
746 $10->height = $9;
747 $10->controls = get_control_head($12);
748 $$ = $10;
749 if(!$$->gotstyle)
751 $$->style->or_mask = WS_POPUP;
752 $$->gotstyle = TRUE;
754 if($$->title)
755 $$->style->or_mask |= WS_CAPTION;
756 if($$->font)
757 $$->style->or_mask |= DS_SETFONT;
759 $$->style->or_mask &= ~($$->style->and_mask);
760 $$->style->and_mask = 0;
762 if(!$$->lvc.language)
763 $$->lvc.language = dup_language(currentlanguage);
767 dlg_attributes
768 : /* Empty */ { $$=new_dialog(); }
769 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
770 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
771 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
772 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
773 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
774 | dlg_attributes tCPPCLASS nameid_s { $$=dialog_class($3,$1); }
775 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
776 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
777 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
778 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
781 ctrls : /* Empty */ { $$ = NULL; }
782 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
783 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
784 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
785 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
786 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
787 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
788 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
789 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
790 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
791 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
792 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
793 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
794 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
795 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
796 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
797 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
798 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
799 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
800 /* special treatment for icons, as the extent is optional */
801 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
802 $10->title = $3;
803 $10->id = $5;
804 $10->x = $7;
805 $10->y = $9;
806 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
810 lab_ctrl
811 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style {
812 $$=new_control();
813 $$->title = new_name_id();
814 $$->title->type = name_str;
815 $$->title->name.s_name = $1;
816 $$->id = $3;
817 $$->x = $5;
818 $$->y = $7;
819 $$->width = $9;
820 $$->height = $11;
821 if($12)
823 $$->style = $12;
824 $$->gotstyle = TRUE;
829 ctrl_desc
830 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
831 $$ = new_control();
832 $$->id = $1;
833 $$->x = $3;
834 $$->y = $5;
835 $$->width = $7;
836 $$->height = $9;
837 if($10)
839 $$->style = $10;
840 $$->gotstyle = TRUE;
845 iconinfo: /* Empty */
846 { $$ = new_control(); }
848 | ',' expr ',' expr {
849 $$ = new_control();
850 $$->width = $2;
851 $$->height = $4;
853 | ',' expr ',' expr ',' style {
854 $$ = new_control();
855 $$->width = $2;
856 $$->height = $4;
857 $$->style = $6;
858 $$->gotstyle = TRUE;
860 | ',' expr ',' expr ',' style ',' style {
861 $$ = new_control();
862 $$->width = $2;
863 $$->height = $4;
864 $$->style = $6;
865 $$->gotstyle = TRUE;
866 $$->exstyle = $8;
867 $$->gotexstyle = TRUE;
871 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
872 $$=new_control();
873 $$->title = $1;
874 $$->id = $3;
875 $$->ctlclass = convert_ctlclass($5);
876 $$->style = $7;
877 $$->gotstyle = TRUE;
878 $$->x = $9;
879 $$->y = $11;
880 $$->width = $13;
881 $$->height = $15;
882 $$->exstyle = $17;
883 $$->gotexstyle = TRUE;
885 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
886 $$=new_control();
887 $$->title = $1;
888 $$->id = $3;
889 $$->ctlclass = convert_ctlclass($5);
890 $$->style = $7;
891 $$->gotstyle = TRUE;
892 $$->x = $9;
893 $$->y = $11;
894 $$->width = $13;
895 $$->height = $15;
899 opt_font
900 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
903 /* ------------------------------ style flags ------------------------------ */
904 optional_style /* Abbused once to get optional ExStyle */
905 : /* Empty */ { $$ = NULL; }
906 | ',' style { $$ = $2; }
909 optional_style_pair
910 : /* Empty */ { $$ = NULL; }
911 | ',' style { $$ = new_style_pair($2, 0); }
912 | ',' style ',' style { $$ = new_style_pair($2, $4); }
915 style
916 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
917 | '(' style ')' { $$ = $2; }
918 | any_num { $$ = new_style($1, 0); }
919 | tNOT any_num { $$ = new_style(0, $2); }
922 ctlclass
923 : expr {
924 $$ = new_name_id();
925 $$->type = name_ord;
926 $$->name.i_name = $1;
928 | tSTRING {
929 $$ = new_name_id();
930 $$->type = name_str;
931 $$->name.s_name = $1;
935 /* ------------------------------ DialogEx ------------------------------ */
936 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
937 tBEGIN exctrls tEND {
938 if(!win32)
939 yywarning("DIALOGEX not supported in 16-bit mode");
940 if($2)
942 $11->memopt = *($2);
943 free($2);
945 else
946 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
947 $11->x = $3;
948 $11->y = $5;
949 $11->width = $7;
950 $11->height = $9;
951 if($10)
953 $11->helpid = *($10);
954 $11->gothelpid = TRUE;
955 free($10);
957 $11->controls = get_control_head($13);
958 $$ = $11;
960 assert($$->style != NULL);
961 if(!$$->gotstyle)
963 $$->style->or_mask = WS_POPUP;
964 $$->gotstyle = TRUE;
966 if($$->title)
967 $$->style->or_mask |= WS_CAPTION;
968 if($$->font)
969 $$->style->or_mask |= DS_SETFONT;
971 $$->style->or_mask &= ~($$->style->and_mask);
972 $$->style->and_mask = 0;
974 if(!$$->lvc.language)
975 $$->lvc.language = dup_language(currentlanguage);
979 dlgex_attribs
980 : /* Empty */ { $$=new_dialogex(); }
981 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
982 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
983 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
984 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
985 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
986 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
987 | dlgex_attribs tCPPCLASS nameid_s { $$=dialogex_class($3,$1); }
988 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
989 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
990 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
991 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
994 exctrls : /* Empty */ { $$ = NULL; }
995 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
996 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
997 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
998 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
999 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1000 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1001 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1002 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1003 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1004 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1005 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1006 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1007 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1008 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1009 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1010 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1011 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1012 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1013 /* special treatment for icons, as the extent is optional */
1014 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1015 $10->title = $3;
1016 $10->id = $5;
1017 $10->x = $7;
1018 $10->y = $9;
1019 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1023 gen_exctrl
1024 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1025 expr ',' style helpid opt_data {
1026 $$=new_control();
1027 $$->title = $1;
1028 $$->id = $3;
1029 $$->ctlclass = convert_ctlclass($5);
1030 $$->style = $7;
1031 $$->gotstyle = TRUE;
1032 $$->x = $9;
1033 $$->y = $11;
1034 $$->width = $13;
1035 $$->height = $15;
1036 if($17)
1038 $$->exstyle = $17;
1039 $$->gotexstyle = TRUE;
1041 if($18)
1043 $$->helpid = *($18);
1044 $$->gothelpid = TRUE;
1045 free($18);
1047 $$->extra = $19;
1049 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1050 $$=new_control();
1051 $$->title = $1;
1052 $$->id = $3;
1053 $$->style = $7;
1054 $$->gotstyle = TRUE;
1055 $$->ctlclass = convert_ctlclass($5);
1056 $$->x = $9;
1057 $$->y = $11;
1058 $$->width = $13;
1059 $$->height = $15;
1060 $$->extra = $16;
1064 lab_exctrl
1065 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1066 $$=new_control();
1067 $$->title = new_name_id();
1068 $$->title->type = name_str;
1069 $$->title->name.s_name = $1;
1070 $$->id = $3;
1071 $$->x = $5;
1072 $$->y = $7;
1073 $$->width = $9;
1074 $$->height = $11;
1075 if($12)
1077 $$->style = $12->style;
1078 $$->gotstyle = TRUE;
1080 if ($12->exstyle)
1082 $$->exstyle = $12->exstyle;
1083 $$->gotexstyle = TRUE;
1085 free($12);
1088 $$->extra = $13;
1092 exctrl_desc
1093 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1094 $$ = new_control();
1095 $$->id = $1;
1096 $$->x = $3;
1097 $$->y = $5;
1098 $$->width = $7;
1099 $$->height = $9;
1100 if($10)
1102 $$->style = $10->style;
1103 $$->gotstyle = TRUE;
1105 if ($10->exstyle)
1107 $$->exstyle = $10->exstyle;
1108 $$->gotexstyle = TRUE;
1110 free($10);
1112 $$->extra = $11;
1116 opt_data: /* Empty */ { $$ = NULL; }
1117 | raw_data { $$ = $1; }
1120 helpid : /* Empty */ { $$ = NULL; }
1121 | ',' expr { $$ = new_int($2); }
1124 opt_exfont
1125 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1129 * FIXME: This odd expression is here to nullify an extra token found
1130 * in some appstudio produced resources which appear to do nothing.
1132 opt_expr: /* Empty */ { $$ = NULL; }
1133 | ',' expr { $$ = NULL; }
1136 /* ------------------------------ Menu ------------------------------ */
1137 menu : tMENU loadmemopts opt_lvc menu_body {
1138 if(!$4)
1139 yyerror("Menu must contain items");
1140 $$ = new_menu();
1141 if($2)
1143 $$->memopt = *($2);
1144 free($2);
1146 else
1147 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1148 $$->items = get_item_head($4);
1149 if($3)
1151 $$->lvc = *($3);
1152 free($3);
1154 if(!$$->lvc.language)
1155 $$->lvc.language = dup_language(currentlanguage);
1159 menu_body
1160 : tBEGIN item_definitions tEND { $$ = $2; }
1163 item_definitions
1164 : /* Empty */ {$$ = NULL;}
1165 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1166 $$=new_menu_item();
1167 $$->prev = $1;
1168 if($1)
1169 $1->next = $$;
1170 $$->id = $5;
1171 $$->state = $6;
1172 $$->name = $3;
1174 | item_definitions tMENUITEM tSEPARATOR {
1175 $$=new_menu_item();
1176 $$->prev = $1;
1177 if($1)
1178 $1->next = $$;
1180 | item_definitions tPOPUP tSTRING item_options menu_body {
1181 $$ = new_menu_item();
1182 $$->prev = $1;
1183 if($1)
1184 $1->next = $$;
1185 $$->popup = get_item_head($5);
1186 $$->name = $3;
1190 /* NOTE: item_options is right recursive because it would introduce
1191 * a shift/reduce conflict on ',' in itemex_options due to the
1192 * empty rule here. The parser is now forced to look beyond the ','
1193 * before reducing (force shift).
1194 * Right recursion here is not a problem because we cannot expect
1195 * more than 7 parserstack places to be occupied while parsing this
1196 * (who would want to specify a MF_x flag twice?).
1198 item_options
1199 : /* Empty */ { $$ = 0; }
1200 | ',' tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1201 | ',' tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1202 | ',' tHELP item_options { $$ = $3 | MF_HELP; }
1203 | ',' tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1204 | ',' tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1205 | ',' tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1208 /* ------------------------------ MenuEx ------------------------------ */
1209 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1210 if(!win32)
1211 yywarning("MENUEX not supported in 16-bit mode");
1212 if(!$4)
1213 yyerror("MenuEx must contain items");
1214 $$ = new_menuex();
1215 if($2)
1217 $$->memopt = *($2);
1218 free($2);
1220 else
1221 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1222 $$->items = get_itemex_head($4);
1223 if($3)
1225 $$->lvc = *($3);
1226 free($3);
1228 if(!$$->lvc.language)
1229 $$->lvc.language = dup_language(currentlanguage);
1233 menuex_body
1234 : tBEGIN itemex_definitions tEND { $$ = $2; }
1237 itemex_definitions
1238 : /* Empty */ {$$ = NULL; }
1239 | itemex_definitions tMENUITEM tSTRING itemex_options {
1240 $$ = new_menuex_item();
1241 $$->prev = $1;
1242 if($1)
1243 $1->next = $$;
1244 $$->name = $3;
1245 $$->id = $4->id;
1246 $$->type = $4->type;
1247 $$->state = $4->state;
1248 $$->helpid = $4->helpid;
1249 $$->gotid = $4->gotid;
1250 $$->gottype = $4->gottype;
1251 $$->gotstate = $4->gotstate;
1252 $$->gothelpid = $4->gothelpid;
1253 free($4);
1255 | itemex_definitions tMENUITEM tSEPARATOR {
1256 $$ = new_menuex_item();
1257 $$->prev = $1;
1258 if($1)
1259 $1->next = $$;
1261 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1262 $$ = new_menuex_item();
1263 $$->prev = $1;
1264 if($1)
1265 $1->next = $$;
1266 $$->popup = get_itemex_head($5);
1267 $$->name = $3;
1268 $$->id = $4->id;
1269 $$->type = $4->type;
1270 $$->state = $4->state;
1271 $$->helpid = $4->helpid;
1272 $$->gotid = $4->gotid;
1273 $$->gottype = $4->gottype;
1274 $$->gotstate = $4->gotstate;
1275 $$->gothelpid = $4->gothelpid;
1276 free($4);
1280 itemex_options
1281 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1282 | ',' expr {
1283 $$ = new_itemex_opt($2, 0, 0, 0);
1284 $$->gotid = TRUE;
1286 | ',' e_expr ',' e_expr item_options {
1287 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1288 $$->gotid = TRUE;
1289 $$->gottype = TRUE;
1290 $$->gotstate = TRUE;
1291 if($2) free($2);
1292 if($4) free($4);
1294 | ',' e_expr ',' e_expr ',' expr {
1295 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1296 $$->gotid = TRUE;
1297 $$->gottype = TRUE;
1298 $$->gotstate = TRUE;
1299 if($2) free($2);
1300 if($4) free($4);
1304 itemex_p_options
1305 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1306 | ',' expr {
1307 $$ = new_itemex_opt($2, 0, 0, 0);
1308 $$->gotid = TRUE;
1310 | ',' e_expr ',' expr {
1311 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1312 if($2) free($2);
1313 $$->gotid = TRUE;
1314 $$->gottype = TRUE;
1316 | ',' e_expr ',' e_expr ',' expr {
1317 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1318 if($2) free($2);
1319 if($4) free($4);
1320 $$->gotid = TRUE;
1321 $$->gottype = TRUE;
1322 $$->gotstate = TRUE;
1324 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1325 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1326 if($2) free($2);
1327 if($4) free($4);
1328 if($6) free($6);
1329 $$->gotid = TRUE;
1330 $$->gottype = TRUE;
1331 $$->gotstate = TRUE;
1332 $$->gothelpid = TRUE;
1336 /* ------------------------------ StringTable ------------------------------ */
1337 /* Stringtables are parsed differently than other resources because their
1338 * layout is substantially different from other resources.
1339 * The table is parsed through a _global_ variable 'tagstt' which holds the
1340 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1341 * list of stringtables of different languages.
1343 stringtable
1344 : stt_head tBEGIN strings tEND {
1345 if(!$3)
1347 yyerror("Stringtable must have at least one entry");
1349 else
1351 stringtable_t *stt;
1352 /* Check if we added to a language table or created
1353 * a new one.
1355 for(stt = sttres; stt; stt = stt->next)
1357 if(stt == tagstt)
1358 break;
1360 if(!stt)
1362 /* It is a new one */
1363 if(sttres)
1365 sttres->prev = tagstt;
1366 tagstt->next = sttres;
1367 sttres = tagstt;
1369 else
1370 sttres = tagstt;
1372 /* Else were done */
1374 if(tagstt_memopt)
1376 free(tagstt_memopt);
1377 tagstt_memopt = NULL;
1380 $$ = tagstt;
1384 /* This is to get the language of the currently parsed stringtable */
1385 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1386 if((tagstt = find_stringtable($3)) == NULL)
1387 tagstt = new_stringtable($3);
1388 tagstt_memopt = $2;
1389 tagstt_version = $3->version;
1390 tagstt_characts = $3->characts;
1391 if($3)
1392 free($3);
1396 strings : /* Empty */ { $$ = NULL; }
1397 | strings expr opt_comma tSTRING {
1398 int i;
1399 assert(tagstt != NULL);
1400 if($2 > 65535 || $2 < -32768)
1401 yyerror("Stringtable entry's ID out of range (%d)", $2);
1402 /* Search for the ID */
1403 for(i = 0; i < tagstt->nentries; i++)
1405 if(tagstt->entries[i].id == $2)
1406 yyerror("Stringtable ID %d already in use", $2);
1408 /* If we get here, then we have a new unique entry */
1409 tagstt->nentries++;
1410 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1411 tagstt->entries[tagstt->nentries-1].id = $2;
1412 tagstt->entries[tagstt->nentries-1].str = $4;
1413 if(tagstt_memopt)
1414 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1415 else
1416 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1417 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1418 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1420 if(!win32 && $4->size > 254)
1421 yyerror("Stringtable entry more than 254 characters");
1422 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1423 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1424 $$ = tagstt;
1428 opt_comma /* There seem to be two ways to specify a stringtable... */
1429 : /* Empty */
1430 | ','
1433 /* ------------------------------ VersionInfo ------------------------------ */
1434 versioninfo
1435 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1436 $$ = $3;
1437 if($2)
1439 $$->memopt = *($2);
1440 free($2);
1442 else
1443 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1444 $$->blocks = get_ver_block_head($5);
1445 /* Set language; there is no version or characteristics */
1446 $$->lvc.language = dup_language(currentlanguage);
1450 fix_version
1451 : /* Empty */ { $$ = new_versioninfo(); }
1452 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1453 if($1->gotit.fv)
1454 yyerror("FILEVERSION already defined");
1455 $$ = $1;
1456 $$->filever_maj1 = $3;
1457 $$->filever_maj2 = $5;
1458 $$->filever_min1 = $7;
1459 $$->filever_min2 = $9;
1460 $$->gotit.fv = 1;
1462 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1463 if($1->gotit.pv)
1464 yyerror("PRODUCTVERSION already defined");
1465 $$ = $1;
1466 $$->prodver_maj1 = $3;
1467 $$->prodver_maj2 = $5;
1468 $$->prodver_min1 = $7;
1469 $$->prodver_min2 = $9;
1470 $$->gotit.pv = 1;
1472 | fix_version tFILEFLAGS expr {
1473 if($1->gotit.ff)
1474 yyerror("FILEFLAGS already defined");
1475 $$ = $1;
1476 $$->fileflags = $3;
1477 $$->gotit.ff = 1;
1479 | fix_version tFILEFLAGSMASK expr {
1480 if($1->gotit.ffm)
1481 yyerror("FILEFLAGSMASK already defined");
1482 $$ = $1;
1483 $$->fileflagsmask = $3;
1484 $$->gotit.ffm = 1;
1486 | fix_version tFILEOS expr {
1487 if($1->gotit.fo)
1488 yyerror("FILEOS already defined");
1489 $$ = $1;
1490 $$->fileos = $3;
1491 $$->gotit.fo = 1;
1493 | fix_version tFILETYPE expr {
1494 if($1->gotit.ft)
1495 yyerror("FILETYPE already defined");
1496 $$ = $1;
1497 $$->filetype = $3;
1498 $$->gotit.ft = 1;
1500 | fix_version tFILESUBTYPE expr {
1501 if($1->gotit.fst)
1502 yyerror("FILESUBTYPE already defined");
1503 $$ = $1;
1504 $$->filesubtype = $3;
1505 $$->gotit.fst = 1;
1509 ver_blocks
1510 : /* Empty */ { $$ = NULL; }
1511 | ver_blocks ver_block {
1512 $$ = $2;
1513 $$->prev = $1;
1514 if($1)
1515 $1->next = $$;
1519 ver_block
1520 : tBLOCK tSTRING tBEGIN ver_values tEND {
1521 $$ = new_ver_block();
1522 $$->name = $2;
1523 $$->values = get_ver_value_head($4);
1527 ver_values
1528 : /* Empty */ { $$ = NULL; }
1529 | ver_values ver_value {
1530 $$ = $2;
1531 $$->prev = $1;
1532 if($1)
1533 $1->next = $$;
1537 ver_value
1538 : ver_block {
1539 $$ = new_ver_value();
1540 $$->type = val_block;
1541 $$->value.block = $1;
1543 | tVALUE tSTRING ',' tSTRING {
1544 $$ = new_ver_value();
1545 $$->type = val_str;
1546 $$->key = $2;
1547 $$->value.str = $4;
1549 | tVALUE tSTRING ',' ver_words {
1550 $$ = new_ver_value();
1551 $$->type = val_words;
1552 $$->key = $2;
1553 $$->value.words = $4;
1557 ver_words
1558 : expr { $$ = new_ver_words($1); }
1559 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1562 /* ------------------------------ Toolbar ------------------------------ */
1563 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1564 int nitems;
1565 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1566 $$ = new_toolbar($3, $5, items, nitems);
1567 if($2)
1569 $$->memopt = *($2);
1570 free($2);
1572 else
1574 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1576 if($6)
1578 $$->lvc = *($6);
1579 free($6);
1581 if(!$$->lvc.language)
1583 $$->lvc.language = dup_language(currentlanguage);
1588 toolbar_items
1589 : /* Empty */ { $$ = NULL; }
1590 | toolbar_items tBUTTON expr {
1591 toolbar_item_t *idrec = new_toolbar_item();
1592 idrec->id = $3;
1593 $$ = ins_tlbr_button($1, idrec);
1595 | toolbar_items tSEPARATOR {
1596 toolbar_item_t *idrec = new_toolbar_item();
1597 idrec->id = 0;
1598 $$ = ins_tlbr_button($1, idrec);
1602 /* ------------------------------ Memory options ------------------------------ */
1603 loadmemopts
1604 : /* Empty */ { $$ = NULL; }
1605 | loadmemopts lamo {
1606 if($1)
1608 *($1) |= *($2);
1609 $$ = $1;
1610 free($2);
1612 else
1613 $$ = $2;
1615 | loadmemopts lama {
1616 if($1)
1618 *($1) &= *($2);
1619 $$ = $1;
1620 free($2);
1622 else
1624 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1625 $$ = $2;
1630 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1631 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1632 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1633 | tPURE { $$ = new_int(WRC_MO_PURE); }
1636 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1637 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1638 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1641 /* ------------------------------ Win32 options ------------------------------ */
1642 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1643 | opt_lvc opt_language {
1644 if(!win32)
1645 yywarning("LANGUAGE not supported in 16-bit mode");
1646 if($1->language)
1647 yyerror("Language already defined");
1648 $$ = $1;
1649 $1->language = $2;
1651 | opt_lvc opt_characts {
1652 if(!win32)
1653 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1654 if($1->characts)
1655 yyerror("Characteristics already defined");
1656 $$ = $1;
1657 $1->characts = $2;
1659 | opt_lvc opt_version {
1660 if(!win32)
1661 yywarning("VERSION not supported in 16-bit mode");
1662 if($1->version)
1663 yyerror("Version already defined");
1664 $$ = $1;
1665 $1->version = $2;
1670 * This here is another s/r conflict on {bi,u}nary + and -.
1671 * It is due to the look-ahead which must determine when the
1672 * rule opt_language ends. It could be solved with adding a
1673 * tNL at the end, but that seems unreasonable to do.
1674 * The conflict is now moved to the expression handling below.
1676 opt_language
1677 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4); }
1680 opt_characts
1681 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1684 opt_version
1685 : tVERSION expr { $$ = new_version($2); }
1688 /* ------------------------------ Raw data handling ------------------------------ */
1689 raw_data: opt_lvc tBEGIN raw_elements tEND {
1690 if($1)
1692 $3->lvc = *($1);
1693 free($1);
1696 if(!$3->lvc.language)
1697 $3->lvc.language = dup_language(currentlanguage);
1699 $$ = $3;
1703 raw_elements
1704 : tRAWDATA { $$ = $1; }
1705 | tNUMBER { $$ = int2raw_data($1); }
1706 | tLNUMBER { $$ = long2raw_data($1); }
1707 | tSTRING { $$ = str2raw_data($1); }
1708 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1709 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1710 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1711 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1714 /* File data or raw data */
1715 file_raw: filename {
1716 $$ = load_file($1);
1717 $$->lvc.language = dup_language(currentlanguage);
1719 | raw_data { $$ = $1; }
1722 /* ------------------------------ Win32 expressions ------------------------------ */
1723 /* All win16 numbers are also handled here. This is inconsistent with MS'
1724 * resource compiler, but what the heck, its just handy to have.
1726 e_expr : /* Empty */ { $$ = 0; }
1727 | expr { $$ = new_int($1); }
1730 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1731 expr : xpr { $$ = ($1); }
1734 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1735 | xpr '-' xpr { $$ = ($1) - ($3); }
1736 | xpr '|' xpr { $$ = ($1) | ($3); }
1737 | xpr '&' xpr { $$ = ($1) & ($3); }
1738 | xpr '*' xpr { $$ = ($1) * ($3); }
1739 | xpr '/' xpr { $$ = ($1) / ($3); }
1740 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1741 | '~' xpr { $$ = ~($2); }
1742 | '-' xpr %prec pUPM { $$ = -($2); }
1743 | '+' xpr %prec pUPM { $$ = $2; }
1744 | '(' xpr ')' { $$ = $2; }
1745 | any_num { $$ = $1; }
1746 | tNOT any_num { $$ = ~($2); }
1749 any_num : tNUMBER { $$ = $1; }
1750 | tLNUMBER { $$ = $1; }
1754 /* Dialog specific functions */
1755 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1757 assert(dlg != NULL);
1758 if(dlg->style == NULL)
1760 dlg->style = new_style(0,0);
1763 if(dlg->gotstyle)
1765 yywarning("Style already defined, or-ing together");
1767 else
1769 dlg->style->or_mask = 0;
1770 dlg->style->and_mask = 0;
1772 dlg->style->or_mask |= st->or_mask;
1773 dlg->style->and_mask |= st->and_mask;
1774 dlg->gotstyle = TRUE;
1775 free(st);
1776 return dlg;
1779 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1781 assert(dlg != NULL);
1782 if(dlg->exstyle == NULL)
1784 dlg->exstyle = new_style(0,0);
1787 if(dlg->gotexstyle)
1789 yywarning("ExStyle already defined, or-ing together");
1791 else
1793 dlg->exstyle->or_mask = 0;
1794 dlg->exstyle->and_mask = 0;
1796 dlg->exstyle->or_mask |= st->or_mask;
1797 dlg->exstyle->and_mask |= st->and_mask;
1798 dlg->gotexstyle = TRUE;
1799 free(st);
1800 return dlg;
1803 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1805 assert(dlg != NULL);
1806 if(dlg->title)
1807 yyerror("Caption already defined");
1808 dlg->title = s;
1809 return dlg;
1812 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1814 assert(dlg != NULL);
1815 if(dlg->font)
1816 yyerror("Font already defined");
1817 dlg->font = f;
1818 return dlg;
1821 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1823 assert(dlg != NULL);
1824 if(dlg->dlgclass)
1825 yyerror("Class already defined");
1826 dlg->dlgclass = n;
1827 return dlg;
1830 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1832 assert(dlg != NULL);
1833 if(dlg->menu)
1834 yyerror("Menu already defined");
1835 dlg->menu = m;
1836 return dlg;
1839 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1841 assert(dlg != NULL);
1842 if(dlg->lvc.language)
1843 yyerror("Language already defined");
1844 dlg->lvc.language = l;
1845 return dlg;
1848 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1850 assert(dlg != NULL);
1851 if(dlg->lvc.characts)
1852 yyerror("Characteristics already defined");
1853 dlg->lvc.characts = c;
1854 return dlg;
1857 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1859 assert(dlg != NULL);
1860 if(dlg->lvc.version)
1861 yyerror("Version already defined");
1862 dlg->lvc.version = v;
1863 return dlg;
1866 /* Controls specific functions */
1867 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1869 /* Hm... this seems to be jammed in at all time... */
1870 int defaultstyle = WS_CHILD | WS_VISIBLE;
1872 assert(ctrl != NULL);
1873 ctrl->prev = prev;
1875 if(prev)
1876 prev->next = ctrl;
1878 if(type != -1)
1880 ctrl->ctlclass = new_name_id();
1881 ctrl->ctlclass->type = name_ord;
1882 ctrl->ctlclass->name.i_name = type;
1885 switch(type)
1887 case CT_BUTTON:
1888 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1889 defaultstyle |= WS_TABSTOP;
1890 break;
1891 case CT_EDIT:
1892 defaultstyle |= WS_TABSTOP | WS_BORDER;
1893 break;
1894 case CT_LISTBOX:
1895 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1896 break;
1897 case CT_COMBOBOX:
1898 defaultstyle |= CBS_SIMPLE;
1899 break;
1900 case CT_STATIC:
1901 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1902 defaultstyle |= WS_GROUP;
1903 break;
1906 if(!ctrl->gotstyle) /* Handle default style setting */
1908 switch(type)
1910 case CT_EDIT:
1911 defaultstyle |= ES_LEFT;
1912 break;
1913 case CT_LISTBOX:
1914 defaultstyle |= LBS_NOTIFY;
1915 break;
1916 case CT_COMBOBOX:
1917 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1918 break;
1919 case CT_SCROLLBAR:
1920 defaultstyle |= SBS_HORZ;
1921 break;
1922 case CT_BUTTON:
1923 switch(special_style)
1925 case BS_CHECKBOX:
1926 case BS_DEFPUSHBUTTON:
1927 case BS_PUSHBUTTON:
1928 case BS_GROUPBOX:
1929 /* case BS_PUSHBOX: */
1930 case BS_AUTORADIOBUTTON:
1931 case BS_AUTO3STATE:
1932 case BS_3STATE:
1933 case BS_AUTOCHECKBOX:
1934 defaultstyle |= WS_TABSTOP;
1935 break;
1936 default:
1937 yywarning("Unknown default button control-style 0x%08x", special_style);
1938 case BS_RADIOBUTTON:
1939 break;
1941 break;
1943 case CT_STATIC:
1944 switch(special_style)
1946 case SS_LEFT:
1947 case SS_RIGHT:
1948 case SS_CENTER:
1949 defaultstyle |= WS_GROUP;
1950 break;
1951 case SS_ICON: /* Special case */
1952 break;
1953 default:
1954 yywarning("Unknown default static control-style 0x%08x", special_style);
1955 break;
1957 break;
1958 case -1: /* Generic control */
1959 goto byebye;
1961 default:
1962 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
1966 /* The SS_ICON flag is always forced in for icon controls */
1967 if(type == CT_STATIC && special_style == SS_ICON)
1968 defaultstyle |= SS_ICON;
1970 if (!ctrl->gotstyle)
1971 ctrl->style = new_style(0,0);
1973 /* combine all styles */
1974 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
1975 ctrl->gotstyle = TRUE;
1976 byebye:
1977 /* combine with NOT mask */
1978 if (ctrl->gotstyle)
1980 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
1981 ctrl->style->and_mask = 0;
1983 if (ctrl->gotexstyle)
1985 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
1986 ctrl->exstyle->and_mask = 0;
1988 return ctrl;
1991 static name_id_t *convert_ctlclass(name_id_t *cls)
1993 char *cc;
1994 int iclass;
1996 if(cls->type == name_ord)
1997 return cls;
1998 assert(cls->type == name_str);
1999 if(cls->type == str_unicode)
2001 yyerror("Don't yet support unicode class comparison");
2003 else
2004 cc = cls->name.s_name->str.cstr;
2006 if(!strcasecmp("BUTTON", cc))
2007 iclass = CT_BUTTON;
2008 else if(!strcasecmp("COMBOBOX", cc))
2009 iclass = CT_COMBOBOX;
2010 else if(!strcasecmp("LISTBOX", cc))
2011 iclass = CT_LISTBOX;
2012 else if(!strcasecmp("EDIT", cc))
2013 iclass = CT_EDIT;
2014 else if(!strcasecmp("STATIC", cc))
2015 iclass = CT_STATIC;
2016 else if(!strcasecmp("SCROLLBAR", cc))
2017 iclass = CT_SCROLLBAR;
2018 else
2019 return cls; /* No default, return user controlclass */
2021 free(cls->name.s_name->str.cstr);
2022 free(cls->name.s_name);
2023 cls->type = name_ord;
2024 cls->name.i_name = iclass;
2025 return cls;
2028 /* DialogEx specific functions */
2029 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2031 assert(dlg != NULL);
2032 if(dlg->style == NULL)
2034 dlg->style = new_style(0,0);
2037 if(dlg->gotstyle)
2039 yywarning("Style already defined, or-ing together");
2041 else
2043 dlg->style->or_mask = 0;
2044 dlg->style->and_mask = 0;
2046 dlg->style->or_mask |= st->or_mask;
2047 dlg->style->and_mask |= st->and_mask;
2048 dlg->gotstyle = TRUE;
2049 free(st);
2050 return dlg;
2053 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2055 assert(dlg != NULL);
2056 if(dlg->exstyle == NULL)
2058 dlg->exstyle = new_style(0,0);
2061 if(dlg->gotexstyle)
2063 yywarning("ExStyle already defined, or-ing together");
2065 else
2067 dlg->exstyle->or_mask = 0;
2068 dlg->exstyle->and_mask = 0;
2070 dlg->exstyle->or_mask |= st->or_mask;
2071 dlg->exstyle->and_mask |= st->and_mask;
2072 dlg->gotexstyle = TRUE;
2073 free(st);
2074 return dlg;
2077 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2079 assert(dlg != NULL);
2080 if(dlg->title)
2081 yyerror("Caption already defined");
2082 dlg->title = s;
2083 return dlg;
2086 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2088 assert(dlg != NULL);
2089 if(dlg->font)
2090 yyerror("Font already defined");
2091 dlg->font = f;
2092 return dlg;
2095 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2097 assert(dlg != NULL);
2098 if(dlg->dlgclass)
2099 yyerror("Class already defined");
2100 dlg->dlgclass = n;
2101 return dlg;
2104 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2106 assert(dlg != NULL);
2107 if(dlg->menu)
2108 yyerror("Menu already defined");
2109 dlg->menu = m;
2110 return dlg;
2113 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2115 assert(dlg != NULL);
2116 if(dlg->lvc.language)
2117 yyerror("Language already defined");
2118 dlg->lvc.language = l;
2119 return dlg;
2122 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2124 assert(dlg != NULL);
2125 if(dlg->lvc.characts)
2126 yyerror("Characteristics already defined");
2127 dlg->lvc.characts = c;
2128 return dlg;
2131 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2133 assert(dlg != NULL);
2134 if(dlg->lvc.version)
2135 yyerror("Version already defined");
2136 dlg->lvc.version = v;
2137 return dlg;
2140 /* Accelerator specific functions */
2141 static event_t *add_event(int key, int id, int flags, event_t *prev)
2143 event_t *ev = new_event();
2145 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2146 yyerror("Cannot use both ASCII and VIRTKEY");
2148 ev->key = key;
2149 ev->id = id;
2150 ev->flags = flags & ~WRC_AF_ASCII;
2151 ev->prev = prev;
2152 if(prev)
2153 prev->next = ev;
2154 return ev;
2157 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2159 int keycode = 0;
2160 event_t *ev = new_event();
2162 if(key->type != str_char)
2163 yyerror("Key code must be an ascii string");
2165 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0]) && !isdigit(key->str.cstr[0])))
2166 yyerror("VIRTKEY code is not equal to ascii value");
2168 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2170 yyerror("Cannot use both '^' and CONTROL modifier");
2172 else if(key->str.cstr[0] == '^')
2174 keycode = toupper(key->str.cstr[1]) - '@';
2175 if(keycode >= ' ')
2176 yyerror("Control-code out of range");
2178 else
2179 keycode = key->str.cstr[0];
2180 ev->key = keycode;
2181 ev->id = id;
2182 ev->flags = flags & ~WRC_AF_ASCII;
2183 ev->prev = prev;
2184 if(prev)
2185 prev->next = ev;
2186 return ev;
2189 /* MenuEx specific functions */
2190 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2192 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2193 opt->id = id;
2194 opt->type = type;
2195 opt->state = state;
2196 opt->helpid = helpid;
2197 return opt;
2200 /* Raw data functions */
2201 static raw_data_t *load_file(string_t *name)
2203 FILE *fp;
2204 raw_data_t *rd;
2205 if(name->type != str_char)
2206 yyerror("Filename must be ASCII string");
2208 fp = open_include(name->str.cstr, 1, NULL);
2209 if(!fp)
2210 yyerror("Cannot open file %s", name->str.cstr);
2211 rd = new_raw_data();
2212 fseek(fp, 0, SEEK_END);
2213 rd->size = ftell(fp);
2214 fseek(fp, 0, SEEK_SET);
2215 rd->data = (char *)xmalloc(rd->size);
2216 fread(rd->data, rd->size, 1, fp);
2217 fclose(fp);
2218 return rd;
2221 static raw_data_t *int2raw_data(int i)
2223 raw_data_t *rd;
2225 if((int)((short)i) != i)
2226 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2228 rd = new_raw_data();
2229 rd->size = sizeof(short);
2230 rd->data = (char *)xmalloc(rd->size);
2231 switch(byteorder)
2233 #ifndef WORDS_BIGENDIAN
2234 case WRC_BO_BIG:
2235 #else
2236 case WRC_BO_LITTLE:
2237 #endif
2238 *(WORD *)(rd->data) = BYTESWAP_WORD((WORD)i);
2239 break;
2240 default:
2241 *(WORD *)(rd->data) = (WORD)i;
2242 break;
2244 return rd;
2247 static raw_data_t *long2raw_data(int i)
2249 raw_data_t *rd;
2250 rd = new_raw_data();
2251 rd->size = sizeof(int);
2252 rd->data = (char *)xmalloc(rd->size);
2253 switch(byteorder)
2255 #ifndef WORDS_BIGENDIAN
2256 case WRC_BO_BIG:
2257 #else
2258 case WRC_BO_LITTLE:
2259 #endif
2260 *(DWORD *)(rd->data) = BYTESWAP_DWORD((DWORD)i);
2261 break;
2262 default:
2263 *(DWORD *)(rd->data) = (DWORD)i;
2264 break;
2266 return rd;
2269 static raw_data_t *str2raw_data(string_t *str)
2271 raw_data_t *rd;
2272 rd = new_raw_data();
2273 rd->size = str->size * (str->type == str_char ? 1 : 2);
2274 rd->data = (char *)xmalloc(rd->size);
2275 if(str->type == str_char)
2276 memcpy(rd->data, str->str.cstr, rd->size);
2277 else if(str->type == str_unicode)
2279 int i;
2280 switch(byteorder)
2282 #ifndef WORDS_BIGENDIAN
2283 case WRC_BO_BIG:
2284 #else
2285 case WRC_BO_LITTLE:
2286 #endif
2287 for(i = 0; i < str->size; i++)
2288 *(WORD *)&(rd->data[2*i]) = BYTESWAP_WORD((WORD)str->str.wstr[i]);
2289 break;
2290 default:
2291 for(i = 0; i < str->size; i++)
2292 *(WORD *)&(rd->data[2*i]) = (WORD)str->str.wstr[i];
2293 break;
2296 else
2297 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2298 return rd;
2301 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2303 r1->data = xrealloc(r1->data, r1->size + r2->size);
2304 memcpy(r1->data + r1->size, r2->data, r2->size);
2305 r1->size += r2->size;
2306 return r1;
2309 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2311 raw_data_t *t = int2raw_data(i);
2312 merge_raw_data(r1, t);
2313 free(t->data);
2314 free(t);
2315 return r1;
2318 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2320 raw_data_t *t = long2raw_data(i);
2321 merge_raw_data(r1, t);
2322 free(t->data);
2323 free(t);
2324 return r1;
2327 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2329 raw_data_t *t = str2raw_data(str);
2330 merge_raw_data(r1, t);
2331 free(t->data);
2332 free(t);
2333 return r1;
2336 /* Function the go back in a list to get the head */
2337 static menu_item_t *get_item_head(menu_item_t *p)
2339 if(!p)
2340 return NULL;
2341 while(p->prev)
2342 p = p->prev;
2343 return p;
2346 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2348 if(!p)
2349 return NULL;
2350 while(p->prev)
2351 p = p->prev;
2352 return p;
2355 static resource_t *get_resource_head(resource_t *p)
2357 if(!p)
2358 return NULL;
2359 while(p->prev)
2360 p = p->prev;
2361 return p;
2364 static ver_block_t *get_ver_block_head(ver_block_t *p)
2366 if(!p)
2367 return NULL;
2368 while(p->prev)
2369 p = p->prev;
2370 return p;
2373 static ver_value_t *get_ver_value_head(ver_value_t *p)
2375 if(!p)
2376 return NULL;
2377 while(p->prev)
2378 p = p->prev;
2379 return p;
2382 static control_t *get_control_head(control_t *p)
2384 if(!p)
2385 return NULL;
2386 while(p->prev)
2387 p = p->prev;
2388 return p;
2391 static event_t *get_event_head(event_t *p)
2393 if(!p)
2394 return NULL;
2395 while(p->prev)
2396 p = p->prev;
2397 return p;
2400 /* Find a stringtable with given language */
2401 static stringtable_t *find_stringtable(lvc_t *lvc)
2403 stringtable_t *stt;
2405 assert(lvc != NULL);
2407 if(!lvc->language)
2408 lvc->language = dup_language(currentlanguage);
2410 for(stt = sttres; stt; stt = stt->next)
2412 if(stt->lvc.language->id == lvc->language->id
2413 && stt->lvc.language->id == lvc->language->id)
2415 /* Found a table with the same language */
2416 /* The version and characteristics are now handled
2417 * in the generation of the individual stringtables.
2418 * This enables localized analysis.
2419 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2420 || (!stt->lvc.version && lvc->version)
2421 || (stt->lvc.version && !lvc->version))
2422 yywarning("Stringtable's versions are not the same, using first definition");
2424 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2425 || (!stt->lvc.characts && lvc->characts)
2426 || (stt->lvc.characts && !lvc->characts))
2427 yywarning("Stringtable's characteristics are not the same, using first definition");
2429 return stt;
2432 return NULL;
2435 /* qsort sorting function for string table entries */
2436 #define STE(p) ((stt_entry_t *)(p))
2437 static int sort_stt_entry(const void *e1, const void *e2)
2439 return STE(e1)->id - STE(e2)->id;
2441 #undef STE
2443 static resource_t *build_stt_resources(stringtable_t *stthead)
2445 stringtable_t *stt;
2446 stringtable_t *newstt;
2447 resource_t *rsc;
2448 resource_t *rsclist = NULL;
2449 resource_t *rsctail = NULL;
2450 int i;
2451 int j;
2452 DWORD andsum;
2453 DWORD orsum;
2454 characts_t *characts;
2455 version_t *version;
2457 if(!stthead)
2458 return NULL;
2460 /* For all languages defined */
2461 for(stt = stthead; stt; stt = stt->next)
2463 assert(stt->nentries > 0);
2465 /* Sort the entries */
2466 if(stt->nentries > 1)
2467 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2469 for(i = 0; i < stt->nentries; )
2471 newstt = new_stringtable(&stt->lvc);
2472 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2473 newstt->nentries = 16;
2474 newstt->idbase = stt->entries[i].id & ~0xf;
2475 for(j = 0; j < 16 && i < stt->nentries; j++)
2477 if(stt->entries[i].id - newstt->idbase == j)
2479 newstt->entries[j] = stt->entries[i];
2480 i++;
2483 andsum = ~0;
2484 orsum = 0;
2485 characts = NULL;
2486 version = NULL;
2487 /* Check individual memory options and get
2488 * the first characteristics/version
2490 for(j = 0; j < 16; j++)
2492 if(!newstt->entries[j].str)
2493 continue;
2494 andsum &= newstt->entries[j].memopt;
2495 orsum |= newstt->entries[j].memopt;
2496 if(!characts)
2497 characts = newstt->entries[j].characts;
2498 if(!version)
2499 version = newstt->entries[j].version;
2501 if(andsum != orsum)
2503 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2505 /* Check version and characteristics */
2506 for(j = 0; j < 16; j++)
2508 if(characts
2509 && newstt->entries[j].characts
2510 && *newstt->entries[j].characts != *characts)
2511 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2512 if(version
2513 && newstt->entries[j].version
2514 && *newstt->entries[j].version != *version)
2515 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2517 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2518 rsc->name = new_name_id();
2519 rsc->name->type = name_ord;
2520 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2521 rsc->memopt = andsum; /* Set to least common denominator */
2522 newstt->memopt = andsum;
2523 newstt->lvc.characts = characts;
2524 newstt->lvc.version = version;
2525 if(!rsclist)
2527 rsclist = rsc;
2528 rsctail = rsc;
2530 else
2532 rsctail->next = rsc;
2533 rsc->prev = rsctail;
2534 rsctail = rsc;
2538 return rsclist;
2542 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2544 idrec->prev = prev;
2545 if(prev)
2546 prev->next = idrec;
2548 return idrec;
2551 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2553 if(!p)
2555 *nitems = 0;
2556 return NULL;
2559 *nitems = 1;
2561 while(p->prev)
2563 (*nitems)++;
2564 p = p->prev;
2567 return p;
2570 static string_t *make_filename(string_t *str)
2572 char *cptr;
2574 if(str->type != str_char)
2575 yyerror("Cannot handle UNICODE filenames");
2577 /* Remove escaped backslash and convert to forward */
2578 cptr = str->str.cstr;
2579 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2581 if(cptr[1] == '\\')
2583 memmove(cptr, cptr+1, strlen(cptr));
2584 str->size--;
2586 *cptr = '/';
2589 /* Convert to lower case. Seems to be reasonable to do */
2590 for(cptr = str->str.cstr; !leave_case && *cptr; cptr++)
2592 *cptr = tolower(*cptr);
2594 return str;
2598 * Process all resources to extract fonts and build
2599 * a fontdir resource.
2601 * Note: MS' resource compiler (build 1472) does not
2602 * handle font resources with different languages.
2603 * The fontdir is generated in the last active language
2604 * and font identifiers must be unique across the entire
2605 * source.
2606 * This is not logical considering the localization
2607 * constraints of all other resource types. MS has,
2608 * most probably, never testet localized fonts. However,
2609 * using fontresources is rare, so it might not occur
2610 * in normal applications.
2611 * Wine does require better localization because a lot
2612 * of languages are coded into the same executable.
2613 * Therefore, I will generate fontdirs for *each*
2614 * localized set of fonts.
2616 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2618 static int once = 0;
2619 if(!once)
2621 warning("Need to parse fonts, not yet implemented");
2622 once++;
2624 return NULL;
2627 static resource_t *build_fontdirs(resource_t *tail)
2629 resource_t *rsc;
2630 resource_t *lst = NULL;
2631 resource_t **fnt = NULL; /* List of all fonts */
2632 int nfnt = 0;
2633 resource_t **fnd = NULL; /* List of all fontdirs */
2634 int nfnd = 0;
2635 resource_t **lanfnt = NULL;
2636 int nlanfnt = 0;
2637 int i;
2638 name_id_t nid;
2639 string_t str;
2640 int fntleft;
2642 nid.type = name_str;
2643 nid.name.s_name = &str;
2644 str.type = str_char;
2645 str.str.cstr = "FONTDIR";
2646 str.size = 7;
2648 /* Extract all fonts and fontdirs */
2649 for(rsc = tail; rsc; rsc = rsc->prev)
2651 if(rsc->type == res_fnt)
2653 nfnt++;
2654 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2655 fnt[nfnt-1] = rsc;
2657 else if(rsc->type == res_fntdir)
2659 nfnd++;
2660 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2661 fnd[nfnd-1] = rsc;
2665 /* Verify the name of the present fontdirs */
2666 for(i = 0; i < nfnd; i++)
2668 if(compare_name_id(&nid, fnd[i]->name))
2670 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2671 get_nameid_str(fnd[i]->name));
2672 fnd[i] = NULL;
2676 /* Sanity check */
2677 if(nfnt == 0)
2679 if(nfnd != 0)
2680 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2681 goto clean;
2684 /* Copy space */
2685 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2687 /* Get all fonts covered by fontdirs */
2688 for(i = 0; i < nfnd; i++)
2690 int j;
2691 WORD cnt;
2692 int isswapped = 0;
2694 if(!fnd[i])
2695 continue;
2696 for(j = 0; j < nfnt; j++)
2698 if(!fnt[j])
2699 continue;
2700 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2702 lanfnt[nlanfnt] = fnt[j];
2703 nlanfnt++;
2704 fnt[j] = NULL;
2708 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2709 if(nlanfnt == cnt)
2710 isswapped = 0;
2711 else if(nlanfnt == BYTESWAP_WORD(cnt))
2712 isswapped = 1;
2713 else
2714 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2715 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2716 #ifdef WORDS_BIGENDIAN
2717 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2718 #else
2719 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2720 #endif
2722 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2726 /* We now have fonts left where we need to make a fontdir resource */
2727 for(i = fntleft = 0; i < nfnt; i++)
2729 if(fnt[i])
2730 fntleft++;
2732 while(fntleft)
2734 /* Get fonts of same language in lanfnt[] */
2735 for(i = nlanfnt = 0; i < nfnt; i++)
2737 if(fnt[i])
2739 if(!nlanfnt)
2741 addlanfnt:
2742 lanfnt[nlanfnt] = fnt[i];
2743 nlanfnt++;
2744 fnt[i] = NULL;
2745 fntleft--;
2747 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2748 goto addlanfnt;
2751 /* and build a fontdir */
2752 rsc = build_fontdir(lanfnt, nlanfnt);
2753 if(rsc)
2755 if(lst)
2757 lst->next = rsc;
2758 rsc->prev = lst;
2760 lst = rsc;
2764 free(lanfnt);
2765 clean:
2766 if(fnt)
2767 free(fnt);
2768 if(fnd)
2769 free(fnd);
2770 return lst;