wrc: Remove resource dumping support.
[wine.git] / tools / wrc / parser.y
blob9b680f2f5a0483866fe95bb7f81be0838553fb3d
1 %{
2 /*
3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * History:
22 * 24-Jul-2000 BS - Made a fix for broken Berkeley yacc on
23 * non-terminals (see cjunk rule).
24 * 21-May-2000 BS - Partial implementation of font resources.
25 * - Corrected language propagation for binary
26 * resources such as bitmaps, icons, cursors,
27 * userres and rcdata. The language is now
28 * correct in .res files.
29 * - Fixed reading the resource name as ident,
30 * so that it may overlap keywords.
31 * 20-May-2000 BS - Implemented animated cursors and icons
32 * resource types.
33 * 30-Apr-2000 BS - Reintegration into the wine-tree
34 * 14-Jan-2000 BS - Redid the usertype resources so that they
35 * are compatible.
36 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
37 * except for the # command (line numbers).
39 * 06-Nov-1999 JS - see CHANGES
41 * 29-Dec-1998 AdH - Grammar and function extensions.
42 * grammar: TOOLBAR resources, Named ICONs in
43 * DIALOGS
44 * functions: semantic actions for the grammar
45 * changes, resource files can now be anywhere
46 * on the include path instead of just in the
47 * current directory
49 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
50 * printed out correctly.
52 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
53 * also accept a tSTRING as argument.
55 * 25-May-1998 BS - Found out that I need to support language, version
56 * and characteristics in inline resources (bitmap,
57 * cursor, etc) but they can also be specified with
58 * a filename. This renders my filename-scanning scheme
59 * worthless. Need to build newline parsing to solve
60 * this one.
61 * It will come with version 1.1.0 (sigh).
63 * 19-May-1998 BS - Started to build a builtin preprocessor
65 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
66 * ideas had some serious flaws.
68 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
69 * file.
71 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
72 * - This file is growing too big. It is time to strip
73 * things and put it in a support file.
75 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
76 * resource will be created. This because the table
77 * has a different layout than other resources. The
78 * table has to be sorted, and divided into smaller
79 * resource entries (see comment in source).
81 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
82 * as string_t which include unicode strings upon
83 * input.
84 * - Parser now emits a warning when compiling win32
85 * extensions in win16 mode.
87 * 16-Apr-1998 BS - Raw data elements are now *optionally* separated
88 * by commas. Read the comments in file sq2dq.l.
89 * - FIXME: there are instances in the source that rely
90 * on the fact that int==32bit and pointers are int size.
91 * - Fixed the conflict in menuex by changing a rule
92 * back into right recursion. See note in source.
93 * - UserType resources cannot have an expression as its
94 * typeclass. See note in source.
96 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
97 * get reduction of the parsestack.
98 * This also helps communication between bison and flex.
99 * Main advantage is that the Empty rule gets reduced
100 * first, which is used to allocate/link things.
101 * It also added a shift/reduce conflict in the menuex
102 * handling, due to expression/option possibility,
103 * although not serious.
105 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
106 * about making it more efficient, but readable (for me)
107 * and slightly easier to expand/change.
108 * This is done primarily by using more reduce states
109 * with many (intuitive) types for the various resource
110 * statements.
111 * - Added expression handling for all resources where a
112 * number is accepted (not only for win32). Also added
113 * multiply and division (not MS compatible, but handy).
114 * Unary minus introduced a shift/reduce conflict, but
115 * it is not serious.
117 * 13-Apr-1998 BS - Reordered a lot of things
118 * - Made the source more readable
119 * - Added Win32 resource definitions
120 * - Corrected syntax problems with an old yacc (;)
121 * - Added extra comment about grammar
124 #include "config.h"
126 #include <stdio.h>
127 #include <stdlib.h>
128 #include <stdarg.h>
129 #include <assert.h>
130 #include <ctype.h>
131 #include <string.h>
133 #include "../tools.h"
134 #include "wrc.h"
135 #include "utils.h"
136 #include "newstruc.h"
137 #include "wpp_private.h"
138 #include "parser.h"
139 #include "windef.h"
140 #include "winbase.h"
141 #include "wingdi.h"
142 #include "winuser.h"
144 int want_nl = 0; /* Signal flex that we need the next newline */
145 int want_id = 0; /* Signal flex that we need the next identifier */
146 static stringtable_t *tagstt; /* Stringtable tag.
147 * It is set while parsing a stringtable to one of
148 * the stringtables in the sttres list or a new one
149 * if the language was not parsed before.
151 static stringtable_t *sttres; /* Stringtable resources. This holds the list of
152 * stringtables with different lanuages
154 static int dont_want_id = 0; /* See language parsing for details */
156 /* Set to the current options of the currently scanning stringtable */
157 static int *tagstt_memopt;
158 static characts_t *tagstt_characts;
159 static version_t *tagstt_version;
161 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
163 /* Prototypes of here defined functions */
164 static event_t *get_event_head(event_t *p);
165 static control_t *get_control_head(control_t *p);
166 static ver_value_t *get_ver_value_head(ver_value_t *p);
167 static ver_block_t *get_ver_block_head(ver_block_t *p);
168 static resource_t *get_resource_head(resource_t *p);
169 static menu_item_t *get_item_head(menu_item_t *p);
170 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
171 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
172 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
173 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
174 static raw_data_t *str2raw_data(string_t *str);
175 static raw_data_t *int2raw_data(int i);
176 static raw_data_t *long2raw_data(int i);
177 static raw_data_t *load_file(string_t *name, language_t *lang);
178 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
179 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
180 static event_t *add_event(int key, int id, int flags, event_t *prev);
181 static name_id_t *convert_ctlclass(name_id_t *cls);
182 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
183 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
184 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
185 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
186 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
187 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
188 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
189 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
190 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
191 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
192 static resource_t *build_stt_resources(stringtable_t *stthead);
193 static stringtable_t *find_stringtable(lvc_t *lvc);
194 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
195 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
196 static string_t *make_filename(string_t *s);
197 static resource_t *build_fontdirs(resource_t *tail);
198 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
199 static int rsrcid_to_token(int lookahead);
201 /* bison >= 3.6 applies api.prefix also to YYEMPTY */
202 #define YYEMPTY (-2)
206 %define api.prefix {parser_}
208 %union{
209 string_t *str;
210 int num;
211 int *iptr;
212 char *cptr;
213 resource_t *res;
214 accelerator_t *acc;
215 bitmap_t *bmp;
216 dialog_t *dlg;
217 font_t *fnt;
218 fontdir_t *fnd;
219 menu_t *men;
220 html_t *html;
221 rcdata_t *rdt;
222 stringtable_t *stt;
223 stt_entry_t *stte;
224 user_t *usr;
225 messagetable_t *msg;
226 versioninfo_t *veri;
227 control_t *ctl;
228 name_id_t *nid;
229 font_id_t *fntid;
230 language_t *lan;
231 version_t *ver;
232 characts_t *chars;
233 event_t *event;
234 menu_item_t *menitm;
235 itemex_opt_t *exopt;
236 raw_data_t *raw;
237 lvc_t *lvc;
238 ver_value_t *val;
239 ver_block_t *blk;
240 ver_words_t *verw;
241 toolbar_t *tlbar;
242 toolbar_item_t *tlbarItems;
243 dlginit_t *dginit;
244 style_pair_t *styles;
245 style_t *style;
246 ani_any_t *ani;
249 %token tNL
250 %token <num> tNUMBER tLNUMBER
251 %token <str> tSTRING tIDENT
252 %token <raw> tRAWDATA
253 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
254 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
255 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
256 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
257 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
258 %token tCONTROL tEDITTEXT
259 %token tRTEXT tCTEXT tLTEXT
260 %token tBLOCK tVALUE
261 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
262 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
263 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
264 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
265 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
266 %token tHELP
267 %token tTOOLBAR tBUTTON
268 %token tBEGIN tEND
269 %token tDLGINIT
270 %left '|'
271 %left '^'
272 %left '&'
273 %left '+' '-'
274 %left '*' '/'
275 %right '~' tNOT
276 %left pUPM
278 %type <res> resource_file resource resources resource_definition
279 %type <stt> stringtable strings
280 %type <fnt> font
281 %type <fnd> fontdir
282 %type <acc> accelerators
283 %type <event> events
284 %type <bmp> bitmap
285 %type <ani> cursor icon
286 %type <dlg> dialog dlg_attributes dialogex dlgex_attribs
287 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
288 %type <iptr> helpid
289 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
290 %type <html> html
291 %type <rdt> rcdata
292 %type <raw> raw_data raw_elements opt_data file_raw
293 %type <veri> versioninfo fix_version
294 %type <verw> ver_words
295 %type <blk> ver_blocks ver_block
296 %type <val> ver_values ver_value
297 %type <men> menu menuex
298 %type <menitm> item_definitions menu_body itemex_definitions menuex_body
299 %type <exopt> itemex_p_options itemex_options
300 %type <msg> messagetable
301 %type <usr> userres
302 %type <num> item_options
303 %type <nid> nameid nameid_s ctlclass usertype
304 %type <num> acc_opt acc accs
305 %type <iptr> loadmemopts lamo lama
306 %type <fntid> opt_font opt_exfont opt_expr
307 %type <lvc> opt_lvc
308 %type <lan> opt_language
309 %type <chars> opt_characts
310 %type <ver> opt_version
311 %type <num> expr xpr
312 %type <iptr> e_expr
313 %type <tlbar> toolbar
314 %type <tlbarItems> toolbar_items
315 %type <dginit> dlginit
316 %type <styles> optional_style_pair
317 %type <num> any_num
318 %type <style> style
319 %type <str> filename
323 resource_file
324 : resources {
325 resource_t *rsc, *head;
326 /* First add stringtables to the resource-list */
327 rsc = build_stt_resources(sttres);
328 /* 'build_stt_resources' returns a head and $1 is a tail */
329 if($1)
331 $1->next = rsc;
332 if(rsc)
333 rsc->prev = $1;
335 else
336 $1 = rsc;
337 /* Find the tail again */
338 while($1 && $1->next)
339 $1 = $1->next;
340 /* Now add any fontdirectory */
341 rsc = build_fontdirs($1);
342 /* 'build_fontdir' returns a head and $1 is a tail */
343 if($1)
345 $1->next = rsc;
346 if(rsc)
347 rsc->prev = $1;
349 else
350 $1 = rsc;
352 /* Final statements before we're done */
353 if ((head = get_resource_head($1)) != NULL)
355 if (resource_top) /* append to existing resources */
357 resource_t *tail = resource_top;
358 while (tail->next) tail = tail->next;
359 tail->next = head;
360 head->prev = tail;
362 else resource_top = head;
364 sttres = NULL;
368 /* Resources are put into a linked list */
369 resources
370 : /* Empty */ { $$ = NULL; want_id = 1; }
371 | resources resource {
372 if($2)
374 resource_t *tail = $2;
375 resource_t *head = $2;
376 while(tail->next)
377 tail = tail->next;
378 while(head->prev)
379 head = head->prev;
380 head->prev = $1;
381 if($1)
382 $1->next = head;
383 $$ = tail;
384 /* Check for duplicate identifiers */
385 while($1 && head)
387 resource_t *rsc = $1;
388 while(rsc)
390 if(rsc->type == head->type
391 && rsc->lan->id == head->lan->id
392 && rsc->lan->sub == head->lan->sub
393 && !compare_name_id(rsc->name, head->name)
394 && (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
396 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
398 rsc = rsc->prev;
400 head = head->next;
403 else if($1)
405 resource_t *tail = $1;
406 while(tail->next)
407 tail = tail->next;
408 $$ = tail;
410 else
411 $$ = NULL;
413 if(!dont_want_id) /* See comments in language parsing below */
414 want_id = 1;
415 dont_want_id = 0;
418 * The following newline rule will never get reduced because we never
419 * get the tNL token, unless we explicitly set the 'want_nl'
420 * flag, which we don't.
421 * The *ONLY* reason for this to be here is because Berkeley
422 * yacc (byacc), at least version 1.9, has a bug.
423 * (identified in the generated parser on the second
424 * line with:
425 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
427 * This extra rule fixes it.
428 * The problem is that the expression handling rule "expr: xpr"
429 * is not reduced on non-terminal tokens, defined above in the
430 * %token declarations. Token tNL is the only non-terminal that
431 * can occur. The error becomes visible in the language parsing
432 * rule below, which looks at the look-ahead token and tests it
433 * for tNL. However, byacc already generates an error upon reading
434 * the token instead of keeping it as a lookahead. The reason
435 * lies in the lack of a $default transition in the "expr : xpr . "
436 * state (currently state 25). It is probably omitted because tNL
437 * is a non-terminal and the state contains 2 s/r conflicts. The
438 * state enumerates all possible transitions instead of using a
439 * $default transition.
440 * All in all, it is a bug in byacc. (period)
442 | resources tNL
446 /* Parse top level resource definitions etc. */
447 resource
448 : expr usrcvt resource_definition {
449 $$ = $3;
450 if($$)
452 if($1 > 65535 || $1 < -32768)
453 yyerror("Resource's ID out of range (%d)", $1);
454 $$->name = new_name_id();
455 $$->name->type = name_ord;
456 $$->name->name.i_name = $1;
459 | tIDENT usrcvt resource_definition {
460 $$ = $3;
461 if($$)
463 $$->name = new_name_id();
464 $$->name->type = name_str;
465 $$->name->name.s_name = $1;
468 | stringtable {
469 /* Don't do anything, stringtables are converted to
470 * resource_t structures when we are finished parsing and
471 * the final rule of the parser is reduced (see above)
473 $$ = NULL;
474 chat("Got STRINGTABLE\n");
476 | tLANGUAGE {want_nl = 1; } expr ',' expr {
477 /* We *NEED* the newline to delimit the expression.
478 * Otherwise, we would not be able to set the next
479 * want_id anymore because of the token-lookahead.
481 * However, we can test the lookahead-token for
482 * being "non-expression" type, in which case we
483 * continue. Fortunately, tNL is the only token that
484 * will break expression parsing and is implicitly
485 * void, so we just remove it. This scheme makes it
486 * possible to do some (not all) fancy preprocessor
487 * stuff.
488 * BTW, we also need to make sure that the next
489 * reduction of 'resources' above will *not* set
490 * want_id because we already have a lookahead that
491 * cannot be undone.
493 if(yychar != YYEMPTY && yychar != tNL)
494 dont_want_id = 1;
496 if(yychar == tNL)
497 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
498 /* direct access to yychar in rule 'usrcvt' below. */
499 else if(yychar == tIDENT)
500 parser_warning("LANGUAGE statement not delimited with newline; next identifier might be wrong\n");
502 want_nl = 0; /* We don't want it anymore if we didn't get it */
504 if(!win32)
505 parser_warning("LANGUAGE not supported in 16-bit mode\n");
506 free(currentlanguage);
507 if (get_language_codepage($3, $5) == -1)
508 yyerror( "Language %04x is not supported", ($5<<10) + $3);
509 currentlanguage = new_language($3, $5);
510 $$ = NULL;
511 chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, ($5<<10) + $3);
516 * Remapping of numerical resource types
517 * (see also comment of called function below)
519 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
523 * Get a valid name/id
525 nameid : expr {
526 if($1 > 65535 || $1 < -32768)
527 yyerror("Resource's ID out of range (%d)", $1);
528 $$ = new_name_id();
529 $$->type = name_ord;
530 $$->name.i_name = $1;
532 | tIDENT {
533 $$ = new_name_id();
534 $$->type = name_str;
535 $$->name.s_name = $1;
540 * Extra string recognition for CLASS statement in dialogs
542 nameid_s: nameid { $$ = $1; }
543 | tSTRING {
544 $$ = new_name_id();
545 $$->type = name_str;
546 $$->name.s_name = $1;
550 /* get the value for a single resource*/
551 resource_definition
552 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
553 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
554 | cursor {
555 resource_t *rsc;
556 if($1->type == res_anicur)
558 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
560 else /* res_curg */
562 cursor_t *cur;
563 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
564 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
566 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
567 rsc->prev->next = rsc;
568 rsc = rsc->prev;
569 rsc->name = new_name_id();
570 rsc->name->type = name_ord;
571 rsc->name->name.i_name = cur->id;
574 free($1);
576 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
577 | dialogex {
578 if(win32)
579 $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language);
580 else
581 $$ = NULL;
583 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
584 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
585 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
586 | icon {
587 resource_t *rsc;
588 if($1->type == res_aniico)
590 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
592 else /* res_icog */
594 icon_t *ico;
595 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
596 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
598 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
599 rsc->prev->next = rsc;
600 rsc = rsc->prev;
601 rsc->name = new_name_id();
602 rsc->name->type = name_ord;
603 rsc->name->name.i_name = ico->id;
606 free($1);
608 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
609 | menuex {
610 if(win32)
611 $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language);
612 else
613 $$ = NULL;
615 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
616 | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
617 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
618 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
619 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
620 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
624 filename: tIDENT { $$ = make_filename($1); }
625 | tSTRING { $$ = make_filename($1); }
628 /* ------------------------------ Bitmap ------------------------------ */
629 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
632 /* ------------------------------ Cursor ------------------------------ */
633 cursor : tCURSOR loadmemopts file_raw {
634 $$ = new_ani_any();
635 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
637 $$->type = res_anicur;
638 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
640 else
642 $$->type = res_curg;
643 $$->u.curg = new_cursor_group($3, $2);
648 /* ------------------------------ Icon ------------------------------ */
649 icon : tICON loadmemopts file_raw {
650 $$ = new_ani_any();
651 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
653 $$->type = res_aniico;
654 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
656 else
658 $$->type = res_icog;
659 $$->u.icog = new_icon_group($3, $2);
664 /* ------------------------------ Font ------------------------------ */
666 * The reading of raw_data for fonts is a Borland BRC
667 * extension. MS generates an error. However, it is
668 * most logical to support this, considering how wine
669 * enters things in CVS (ascii).
671 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
675 * The fontdir is a Borland BRC extension which only
676 * reads the data as 'raw_data' from the file.
677 * I don't know whether it is interpreted.
678 * The fontdir is generated if it was not present and
679 * fonts are defined in the source.
681 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
684 /* ------------------------------ MessageTable ------------------------------ */
685 /* It might be interesting to implement the MS Message compiler here as well
686 * to get everything in one source. Might be a future project.
688 messagetable
689 : tMESSAGETABLE loadmemopts file_raw {
690 if(!win32)
691 parser_warning("MESSAGETABLE not supported in 16-bit mode\n");
692 $$ = new_messagetable($3, $2);
696 /* ------------------------------ HTML ------------------------------ */
697 html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
700 /* ------------------------------ RCData ------------------------------ */
701 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
704 /* ------------------------------ DLGINIT ------------------------------ */
705 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
708 /* ------------------------------ UserType ------------------------------ */
709 userres : usertype loadmemopts file_raw {
710 $$ = new_user($1, $3, $2);
714 usertype: tNUMBER {
715 $$ = new_name_id();
716 $$->type = name_ord;
717 $$->name.i_name = $1;
719 | tIDENT {
720 $$ = new_name_id();
721 $$->type = name_str;
722 $$->name.s_name = $1;
726 /* ------------------------------ Accelerator ------------------------------ */
727 accelerators
728 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
729 $$ = new_accelerator();
730 if($2)
732 $$->memopt = *($2);
733 free($2);
735 else
737 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
739 if(!$5)
740 yyerror("Accelerator table must have at least one entry");
741 $$->events = get_event_head($5);
742 if($3)
744 $$->lvc = *($3);
745 free($3);
747 if(!$$->lvc.language)
748 $$->lvc.language = dup_language(currentlanguage);
752 events : /* Empty */ { $$=NULL; }
753 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
754 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
758 * The empty rule generates a s/r conflict because of {bi,u}nary expr
759 * on - and +. It cannot be solved in any way because it is the same as
760 * the if/then/else problem (LALR(1) problem). The conflict is moved
761 * away by forcing it to be in the expression handling below.
763 acc_opt : /* Empty */ { $$ = 0; }
764 | ',' accs { $$ = $2; }
767 accs : acc { $$ = $1; }
768 | accs ',' acc { $$ = $1 | $3; }
771 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
772 | tSHIFT { $$ = WRC_AF_SHIFT; }
773 | tCONTROL { $$ = WRC_AF_CONTROL; }
774 | tALT { $$ = WRC_AF_ALT; }
775 | tASCII { $$ = WRC_AF_ASCII; }
776 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
779 /* ------------------------------ Dialog ------------------------------ */
780 /* FIXME: Support EXSTYLE in the dialog line itself */
781 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
782 tBEGIN ctrls tEND {
783 if($2)
785 $10->memopt = *($2);
786 free($2);
788 else
789 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
790 $10->x = $3;
791 $10->y = $5;
792 $10->width = $7;
793 $10->height = $9;
794 $10->controls = get_control_head($12);
795 $$ = $10;
796 if(!$$->gotstyle)
798 $$->style = new_style(0,0);
799 $$->style->or_mask = WS_POPUP;
800 $$->gotstyle = TRUE;
802 if($$->title)
803 $$->style->or_mask |= WS_CAPTION;
804 if($$->font)
805 $$->style->or_mask |= DS_SETFONT;
807 $$->style->or_mask &= ~($$->style->and_mask);
808 $$->style->and_mask = 0;
810 if(!$$->lvc.language)
811 $$->lvc.language = dup_language(currentlanguage);
815 dlg_attributes
816 : /* Empty */ { $$=new_dialog(); }
817 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
818 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
819 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
820 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
821 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
822 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
823 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
824 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
825 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
828 ctrls : /* Empty */ { $$ = NULL; }
829 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
830 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
831 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
832 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
833 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
834 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
835 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
836 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
837 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
838 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
839 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
840 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
841 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
842 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
843 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
844 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
845 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
846 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
847 /* special treatment for icons, as the extent is optional */
848 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
849 $10->title = $3;
850 $10->id = $5;
851 $10->x = $7;
852 $10->y = $9;
853 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
857 lab_ctrl
858 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
859 $$=new_control();
860 $$->title = $1;
861 $$->id = $3;
862 $$->x = $5;
863 $$->y = $7;
864 $$->width = $9;
865 $$->height = $11;
866 if($12)
868 $$->style = $12->style;
869 $$->gotstyle = TRUE;
870 if ($12->exstyle)
872 $$->exstyle = $12->exstyle;
873 $$->gotexstyle = TRUE;
875 free($12);
880 ctrl_desc
881 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
882 $$ = new_control();
883 $$->id = $1;
884 $$->x = $3;
885 $$->y = $5;
886 $$->width = $7;
887 $$->height = $9;
888 if($10)
890 $$->style = $10->style;
891 $$->gotstyle = TRUE;
892 if ($10->exstyle)
894 $$->exstyle = $10->exstyle;
895 $$->gotexstyle = TRUE;
897 free($10);
902 iconinfo: /* Empty */
903 { $$ = new_control(); }
905 | ',' expr ',' expr {
906 $$ = new_control();
907 $$->width = $2;
908 $$->height = $4;
910 | ',' expr ',' expr ',' style {
911 $$ = new_control();
912 $$->width = $2;
913 $$->height = $4;
914 $$->style = $6;
915 $$->gotstyle = TRUE;
917 | ',' expr ',' expr ',' style ',' style {
918 $$ = new_control();
919 $$->width = $2;
920 $$->height = $4;
921 $$->style = $6;
922 $$->gotstyle = TRUE;
923 $$->exstyle = $8;
924 $$->gotexstyle = TRUE;
928 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
929 $$=new_control();
930 $$->title = $1;
931 $$->id = $3;
932 $$->ctlclass = convert_ctlclass($5);
933 $$->style = $7;
934 $$->gotstyle = TRUE;
935 $$->x = $9;
936 $$->y = $11;
937 $$->width = $13;
938 $$->height = $15;
939 $$->exstyle = $17;
940 $$->gotexstyle = TRUE;
942 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
943 $$=new_control();
944 $$->title = $1;
945 $$->id = $3;
946 $$->ctlclass = convert_ctlclass($5);
947 $$->style = $7;
948 $$->gotstyle = TRUE;
949 $$->x = $9;
950 $$->y = $11;
951 $$->width = $13;
952 $$->height = $15;
956 opt_font
957 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
960 /* ------------------------------ style flags ------------------------------ */
961 optional_style_pair
962 : /* Empty */ { $$ = NULL; }
963 | ',' style { $$ = new_style_pair($2, 0); }
964 | ',' style ',' style { $$ = new_style_pair($2, $4); }
967 style
968 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
969 | '(' style ')' { $$ = $2; }
970 | any_num { $$ = new_style($1, 0); }
971 | tNOT any_num { $$ = new_style(0, $2); }
974 ctlclass
975 : expr {
976 $$ = new_name_id();
977 $$->type = name_ord;
978 $$->name.i_name = $1;
980 | tSTRING {
981 $$ = new_name_id();
982 $$->type = name_str;
983 $$->name.s_name = $1;
987 /* ------------------------------ DialogEx ------------------------------ */
988 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
989 tBEGIN exctrls tEND {
990 if(!win32)
991 parser_warning("DIALOGEX not supported in 16-bit mode\n");
992 if($2)
994 $11->memopt = *($2);
995 free($2);
997 else
998 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
999 $11->x = $3;
1000 $11->y = $5;
1001 $11->width = $7;
1002 $11->height = $9;
1003 if($10)
1005 $11->helpid = *($10);
1006 $11->gothelpid = TRUE;
1007 free($10);
1009 $11->controls = get_control_head($13);
1010 $$ = $11;
1012 assert($$->style != NULL);
1013 if(!$$->gotstyle)
1015 $$->style->or_mask = WS_POPUP;
1016 $$->gotstyle = TRUE;
1018 if($$->title)
1019 $$->style->or_mask |= WS_CAPTION;
1020 if($$->font)
1021 $$->style->or_mask |= DS_SETFONT;
1023 $$->style->or_mask &= ~($$->style->and_mask);
1024 $$->style->and_mask = 0;
1026 if(!$$->lvc.language)
1027 $$->lvc.language = dup_language(currentlanguage);
1031 dlgex_attribs
1032 : /* Empty */ { $$=new_dialog(); $$->is_ex = TRUE; }
1033 | dlgex_attribs tSTYLE style { $$=dialog_style($3,$1); }
1034 | dlgex_attribs tEXSTYLE style { $$=dialog_exstyle($3,$1); }
1035 | dlgex_attribs tCAPTION tSTRING { $$=dialog_caption($3,$1); }
1036 | dlgex_attribs opt_font { $$=dialog_font($2,$1); }
1037 | dlgex_attribs opt_exfont { $$=dialog_font($2,$1); }
1038 | dlgex_attribs tCLASS nameid_s { $$=dialog_class($3,$1); }
1039 | dlgex_attribs tMENU nameid { $$=dialog_menu($3,$1); }
1040 | dlgex_attribs opt_language { $$=dialog_language($2,$1); }
1041 | dlgex_attribs opt_characts { $$=dialog_characteristics($2,$1); }
1042 | dlgex_attribs opt_version { $$=dialog_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 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1117 $$=new_control();
1118 $$->title = $1;
1119 $$->id = $3;
1120 $$->x = $5;
1121 $$->y = $7;
1122 $$->width = $9;
1123 $$->height = $11;
1124 if($12)
1126 $$->style = $12->style;
1127 $$->gotstyle = TRUE;
1129 if ($12->exstyle)
1131 $$->exstyle = $12->exstyle;
1132 $$->gotexstyle = TRUE;
1134 free($12);
1137 $$->extra = $14;
1141 exctrl_desc
1142 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1143 $$ = new_control();
1144 $$->id = $1;
1145 $$->x = $3;
1146 $$->y = $5;
1147 $$->width = $7;
1148 $$->height = $9;
1149 if($10)
1151 $$->style = $10->style;
1152 $$->gotstyle = TRUE;
1154 if ($10->exstyle)
1156 $$->exstyle = $10->exstyle;
1157 $$->gotexstyle = TRUE;
1159 free($10);
1161 $$->extra = $12;
1165 opt_data: /* Empty */ { $$ = NULL; }
1166 | raw_data { $$ = $1; }
1169 helpid : /* Empty */ { $$ = NULL; }
1170 | ',' expr { $$ = new_int($2); }
1173 opt_exfont
1174 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1178 * FIXME: This odd expression is here to nullify an extra token found
1179 * in some appstudio produced resources which appear to do nothing.
1181 opt_expr: /* Empty */ { $$ = NULL; }
1182 | ',' expr { $$ = NULL; }
1185 /* ------------------------------ Menu ------------------------------ */
1186 menu : tMENU loadmemopts opt_lvc menu_body {
1187 if(!$4)
1188 yyerror("Menu must contain items");
1189 $$ = new_menu();
1190 if($2)
1192 $$->memopt = *($2);
1193 free($2);
1195 else
1196 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1197 $$->items = get_item_head($4);
1198 if($3)
1200 $$->lvc = *($3);
1201 free($3);
1203 if(!$$->lvc.language)
1204 $$->lvc.language = dup_language(currentlanguage);
1208 menu_body
1209 : tBEGIN item_definitions tEND { $$ = $2; }
1212 item_definitions
1213 : /* Empty */ {$$ = NULL;}
1214 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1215 $$=new_menu_item();
1216 $$->prev = $1;
1217 if($1)
1218 $1->next = $$;
1219 $$->id = $5;
1220 $$->state = $6;
1221 $$->name = $3;
1223 | item_definitions tMENUITEM tSEPARATOR {
1224 $$=new_menu_item();
1225 $$->prev = $1;
1226 if($1)
1227 $1->next = $$;
1229 | item_definitions tPOPUP tSTRING item_options menu_body {
1230 $$ = new_menu_item();
1231 $$->prev = $1;
1232 if($1)
1233 $1->next = $$;
1234 $$->popup = get_item_head($5);
1235 $$->name = $3;
1239 /* NOTE: item_options is right recursive because it would introduce
1240 * a shift/reduce conflict on ',' in itemex_options due to the
1241 * empty rule here. The parser is now forced to look beyond the ','
1242 * before reducing (force shift).
1243 * Right recursion here is not a problem because we cannot expect
1244 * more than 7 parserstack places to be occupied while parsing this
1245 * (who would want to specify a MF_x flag twice?).
1247 item_options
1248 : /* Empty */ { $$ = 0; }
1249 | ',' item_options { $$ = $2; }
1250 | tCHECKED item_options { $$ = $2 | MF_CHECKED; }
1251 | tGRAYED item_options { $$ = $2 | MF_GRAYED; }
1252 | tHELP item_options { $$ = $2 | MF_HELP; }
1253 | tINACTIVE item_options { $$ = $2 | MF_DISABLED; }
1254 | tMENUBARBREAK item_options { $$ = $2 | MF_MENUBARBREAK; }
1255 | tMENUBREAK item_options { $$ = $2 | MF_MENUBREAK; }
1258 /* ------------------------------ MenuEx ------------------------------ */
1259 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1260 if(!win32)
1261 parser_warning("MENUEX not supported in 16-bit mode\n");
1262 if(!$4)
1263 yyerror("MenuEx must contain items");
1264 $$ = new_menu();
1265 $$->is_ex = TRUE;
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_item_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_menu_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_menu_item();
1308 $$->prev = $1;
1309 if($1)
1310 $1->next = $$;
1312 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1313 $$ = new_menu_item();
1314 $$->prev = $1;
1315 if($1)
1316 $1->next = $$;
1317 $$->popup = get_item_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 free($2);
1343 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 free($2);
1351 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 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 free($2);
1370 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 free($2);
1378 free($4);
1379 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, we're done */
1425 free(tagstt_memopt);
1426 tagstt_memopt = NULL;
1428 $$ = tagstt;
1432 /* This is to get the language of the currently parsed stringtable */
1433 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1434 if((tagstt = find_stringtable($3)) == NULL)
1435 tagstt = new_stringtable($3);
1436 tagstt_memopt = $2;
1437 tagstt_version = $3->version;
1438 tagstt_characts = $3->characts;
1439 free($3);
1443 strings : /* Empty */ { $$ = NULL; }
1444 | strings expr opt_comma tSTRING {
1445 int i;
1446 assert(tagstt != NULL);
1447 if($2 > 65535 || $2 < -32768)
1448 yyerror("Stringtable entry's ID out of range (%d)", $2);
1449 /* Search for the ID */
1450 for(i = 0; i < tagstt->nentries; i++)
1452 if(tagstt->entries[i].id == $2)
1453 yyerror("Stringtable ID %d already in use", $2);
1455 /* If we get here, then we have a new unique entry */
1456 tagstt->nentries++;
1457 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1458 tagstt->entries[tagstt->nentries-1].id = $2;
1459 tagstt->entries[tagstt->nentries-1].str = $4;
1460 if(tagstt_memopt)
1461 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1462 else
1463 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1464 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1465 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1467 if(pedantic && !$4->size)
1468 parser_warning("Zero length strings make no sense\n");
1469 if(!win32 && $4->size > 254)
1470 yyerror("Stringtable entry more than 254 characters");
1471 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1472 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1473 $$ = tagstt;
1477 opt_comma /* There seem to be two ways to specify a stringtable... */
1478 : /* Empty */
1479 | ','
1482 /* ------------------------------ VersionInfo ------------------------------ */
1483 versioninfo
1484 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1485 $$ = $3;
1486 if($2)
1488 $$->memopt = *($2);
1489 free($2);
1491 else
1492 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1493 $$->blocks = get_ver_block_head($5);
1494 /* Set language; there is no version or characteristics */
1495 $$->lvc.language = dup_language(currentlanguage);
1499 fix_version
1500 : /* Empty */ { $$ = new_versioninfo(); }
1501 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1502 if($1->gotit.fv)
1503 yyerror("FILEVERSION already defined");
1504 $$ = $1;
1505 $$->filever_maj1 = $3;
1506 $$->filever_maj2 = $5;
1507 $$->filever_min1 = $7;
1508 $$->filever_min2 = $9;
1509 $$->gotit.fv = 1;
1511 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1512 if($1->gotit.pv)
1513 yyerror("PRODUCTVERSION already defined");
1514 $$ = $1;
1515 $$->prodver_maj1 = $3;
1516 $$->prodver_maj2 = $5;
1517 $$->prodver_min1 = $7;
1518 $$->prodver_min2 = $9;
1519 $$->gotit.pv = 1;
1521 | fix_version tFILEFLAGS expr {
1522 if($1->gotit.ff)
1523 yyerror("FILEFLAGS already defined");
1524 $$ = $1;
1525 $$->fileflags = $3;
1526 $$->gotit.ff = 1;
1528 | fix_version tFILEFLAGSMASK expr {
1529 if($1->gotit.ffm)
1530 yyerror("FILEFLAGSMASK already defined");
1531 $$ = $1;
1532 $$->fileflagsmask = $3;
1533 $$->gotit.ffm = 1;
1535 | fix_version tFILEOS expr {
1536 if($1->gotit.fo)
1537 yyerror("FILEOS already defined");
1538 $$ = $1;
1539 $$->fileos = $3;
1540 $$->gotit.fo = 1;
1542 | fix_version tFILETYPE expr {
1543 if($1->gotit.ft)
1544 yyerror("FILETYPE already defined");
1545 $$ = $1;
1546 $$->filetype = $3;
1547 $$->gotit.ft = 1;
1549 | fix_version tFILESUBTYPE expr {
1550 if($1->gotit.fst)
1551 yyerror("FILESUBTYPE already defined");
1552 $$ = $1;
1553 $$->filesubtype = $3;
1554 $$->gotit.fst = 1;
1558 ver_blocks
1559 : /* Empty */ { $$ = NULL; }
1560 | ver_blocks ver_block {
1561 $$ = $2;
1562 $$->prev = $1;
1563 if($1)
1564 $1->next = $$;
1568 ver_block
1569 : tBLOCK tSTRING tBEGIN ver_values tEND {
1570 $$ = new_ver_block();
1571 $$->name = $2;
1572 $$->values = get_ver_value_head($4);
1576 ver_values
1577 : /* Empty */ { $$ = NULL; }
1578 | ver_values ver_value {
1579 $$ = $2;
1580 $$->prev = $1;
1581 if($1)
1582 $1->next = $$;
1586 ver_value
1587 : ver_block {
1588 $$ = new_ver_value();
1589 $$->type = val_block;
1590 $$->value.block = $1;
1592 | tVALUE tSTRING ',' tSTRING {
1593 $$ = new_ver_value();
1594 $$->type = val_str;
1595 $$->key = $2;
1596 $$->value.str = $4;
1598 | tVALUE tSTRING ',' ver_words {
1599 $$ = new_ver_value();
1600 $$->type = val_words;
1601 $$->key = $2;
1602 $$->value.words = $4;
1606 ver_words
1607 : expr { $$ = new_ver_words($1); }
1608 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1611 /* ------------------------------ Toolbar ------------------------------ */
1612 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1613 int nitems;
1614 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1615 $$ = new_toolbar($3, $5, items, nitems);
1616 if($2)
1618 $$->memopt = *($2);
1619 free($2);
1621 else
1623 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1625 if($6)
1627 $$->lvc = *($6);
1628 free($6);
1630 if(!$$->lvc.language)
1632 $$->lvc.language = dup_language(currentlanguage);
1637 toolbar_items
1638 : /* Empty */ { $$ = NULL; }
1639 | toolbar_items tBUTTON expr {
1640 toolbar_item_t *idrec = new_toolbar_item();
1641 idrec->id = $3;
1642 $$ = ins_tlbr_button($1, idrec);
1644 | toolbar_items tSEPARATOR {
1645 toolbar_item_t *idrec = new_toolbar_item();
1646 idrec->id = 0;
1647 $$ = ins_tlbr_button($1, idrec);
1651 /* ------------------------------ Memory options ------------------------------ */
1652 loadmemopts
1653 : /* Empty */ { $$ = NULL; }
1654 | loadmemopts lamo {
1655 if($1)
1657 *($1) |= *($2);
1658 $$ = $1;
1659 free($2);
1661 else
1662 $$ = $2;
1664 | loadmemopts lama {
1665 if($1)
1667 *($1) &= *($2);
1668 $$ = $1;
1669 free($2);
1671 else
1673 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1674 $$ = $2;
1679 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD);
1680 if (win32 && pedantic) parser_warning("PRELOAD is ignored in 32-bit mode\n"); }
1681 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE);
1682 if (win32 && pedantic) parser_warning("MOVEABLE is ignored in 32-bit mode\n"); }
1683 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE);
1684 if (win32 && pedantic) parser_warning("DISCARDABLE is ignored in 32-bit mode\n"); }
1685 | tPURE { $$ = new_int(WRC_MO_PURE);
1686 if (win32 && pedantic) parser_warning("PURE is ignored in 32-bit mode\n"); }
1689 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD);
1690 if (win32 && pedantic) parser_warning("LOADONCALL is ignored in 32-bit mode\n"); }
1691 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE);
1692 if (win32 && pedantic) parser_warning("FIXED is ignored in 32-bit mode\n"); }
1693 | tIMPURE { $$ = new_int(~WRC_MO_PURE);
1694 if (win32 && pedantic) parser_warning("IMPURE is ignored in 32-bit mode\n"); }
1697 /* ------------------------------ Win32 options ------------------------------ */
1698 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1699 | opt_lvc opt_language {
1700 if(!win32)
1701 parser_warning("LANGUAGE not supported in 16-bit mode\n");
1702 if($1->language)
1703 yyerror("Language already defined");
1704 $$ = $1;
1705 $1->language = $2;
1707 | opt_lvc opt_characts {
1708 if(!win32)
1709 parser_warning("CHARACTERISTICS not supported in 16-bit mode\n");
1710 if($1->characts)
1711 yyerror("Characteristics already defined");
1712 $$ = $1;
1713 $1->characts = $2;
1715 | opt_lvc opt_version {
1716 if(!win32)
1717 parser_warning("VERSION not supported in 16-bit mode\n");
1718 if($1->version)
1719 yyerror("Version already defined");
1720 $$ = $1;
1721 $1->version = $2;
1726 * This here is another s/r conflict on {bi,u}nary + and -.
1727 * It is due to the look-ahead which must determine when the
1728 * rule opt_language ends. It could be solved with adding a
1729 * tNL at the end, but that seems unreasonable to do.
1730 * The conflict is now moved to the expression handling below.
1732 opt_language
1733 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
1734 if (get_language_codepage($2, $4) == -1)
1735 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1739 opt_characts
1740 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1743 opt_version
1744 : tVERSION expr { $$ = new_version($2); }
1747 /* ------------------------------ Raw data handling ------------------------------ */
1748 raw_data: opt_lvc tBEGIN raw_elements tEND {
1749 if($1)
1751 $3->lvc = *($1);
1752 free($1);
1755 if(!$3->lvc.language)
1756 $3->lvc.language = dup_language(currentlanguage);
1758 $$ = $3;
1762 raw_elements
1763 : tRAWDATA { $$ = $1; }
1764 | tNUMBER { $$ = int2raw_data($1); }
1765 | '-' tNUMBER { $$ = int2raw_data(-($2)); }
1766 | tLNUMBER { $$ = long2raw_data($1); }
1767 | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
1768 | tSTRING { $$ = str2raw_data($1); }
1769 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1770 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1771 | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
1772 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1773 | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
1774 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1777 /* File data or raw data */
1778 file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
1779 | raw_data { $$ = $1; }
1782 /* ------------------------------ Win32 expressions ------------------------------ */
1783 /* All win16 numbers are also handled here. This is inconsistent with MS
1784 * resource compiler, but what the heck, it's just handy to have.
1786 e_expr : /* Empty */ { $$ = 0; }
1787 | expr { $$ = new_int($1); }
1790 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1791 expr : xpr { $$ = ($1); }
1794 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1795 | xpr '-' xpr { $$ = ($1) - ($3); }
1796 | xpr '|' xpr { $$ = ($1) | ($3); }
1797 | xpr '&' xpr { $$ = ($1) & ($3); }
1798 | xpr '*' xpr { $$ = ($1) * ($3); }
1799 | xpr '/' xpr { $$ = ($1) / ($3); }
1800 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1801 | '~' xpr { $$ = ~($2); }
1802 | '-' xpr %prec pUPM { $$ = -($2); }
1803 | '+' xpr %prec pUPM { $$ = $2; }
1804 | '(' xpr ')' { $$ = $2; }
1805 | any_num { $$ = $1; }
1806 | tNOT any_num { $$ = ~($2); }
1809 any_num : tNUMBER { $$ = $1; }
1810 | tLNUMBER { $$ = $1; }
1814 /* Dialog specific functions */
1815 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1817 assert(dlg != NULL);
1818 if(dlg->style == NULL)
1820 dlg->style = new_style(0,0);
1823 if(dlg->gotstyle)
1825 parser_warning("Style already defined, or-ing together\n");
1827 else
1829 dlg->style->or_mask = 0;
1830 dlg->style->and_mask = 0;
1832 dlg->style->or_mask |= st->or_mask;
1833 dlg->style->and_mask |= st->and_mask;
1834 dlg->gotstyle = TRUE;
1835 free(st);
1836 return dlg;
1839 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1841 assert(dlg != NULL);
1842 if(dlg->exstyle == NULL)
1844 dlg->exstyle = new_style(0,0);
1847 if(dlg->gotexstyle)
1849 parser_warning("ExStyle already defined, or-ing together\n");
1851 else
1853 dlg->exstyle->or_mask = 0;
1854 dlg->exstyle->and_mask = 0;
1856 dlg->exstyle->or_mask |= st->or_mask;
1857 dlg->exstyle->and_mask |= st->and_mask;
1858 dlg->gotexstyle = TRUE;
1859 free(st);
1860 return dlg;
1863 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1865 assert(dlg != NULL);
1866 if(dlg->title)
1867 yyerror("Caption already defined");
1868 dlg->title = s;
1869 return dlg;
1872 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1874 assert(dlg != NULL);
1875 if(dlg->font)
1876 yyerror("Font already defined");
1877 dlg->font = f;
1878 return dlg;
1881 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1883 assert(dlg != NULL);
1884 if(dlg->dlgclass)
1885 yyerror("Class already defined");
1886 dlg->dlgclass = n;
1887 return dlg;
1890 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1892 assert(dlg != NULL);
1893 if(dlg->menu)
1894 yyerror("Menu already defined");
1895 dlg->menu = m;
1896 return dlg;
1899 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1901 assert(dlg != NULL);
1902 if(dlg->lvc.language)
1903 yyerror("Language already defined");
1904 dlg->lvc.language = l;
1905 return dlg;
1908 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1910 assert(dlg != NULL);
1911 if(dlg->lvc.characts)
1912 yyerror("Characteristics already defined");
1913 dlg->lvc.characts = c;
1914 return dlg;
1917 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1919 assert(dlg != NULL);
1920 if(dlg->lvc.version)
1921 yyerror("Version already defined");
1922 dlg->lvc.version = v;
1923 return dlg;
1926 /* Controls specific functions */
1927 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1929 /* Hm... this seems to be jammed in at all time... */
1930 int defaultstyle = WS_CHILD | WS_VISIBLE;
1932 assert(ctrl != NULL);
1933 ctrl->prev = prev;
1935 if(prev)
1936 prev->next = ctrl;
1938 /* Check for duplicate identifiers */
1939 while (prev)
1941 if (ctrl->id != -1 && ctrl->id == prev->id)
1942 parser_warning("Duplicate dialog control id %d\n", ctrl->id);
1943 prev = prev->prev;
1946 if(type != -1)
1948 ctrl->ctlclass = new_name_id();
1949 ctrl->ctlclass->type = name_ord;
1950 ctrl->ctlclass->name.i_name = type;
1953 switch(type)
1955 case CT_BUTTON:
1956 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1957 defaultstyle |= WS_TABSTOP;
1958 break;
1959 case CT_EDIT:
1960 defaultstyle |= WS_TABSTOP | WS_BORDER;
1961 break;
1962 case CT_LISTBOX:
1963 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1964 break;
1965 case CT_COMBOBOX:
1966 if (!ctrl->gotstyle || !(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
1967 defaultstyle |= CBS_SIMPLE;
1968 break;
1969 case CT_STATIC:
1970 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1971 defaultstyle |= WS_GROUP;
1972 break;
1975 if(!ctrl->gotstyle) /* Handle default style setting */
1977 switch(type)
1979 case CT_EDIT:
1980 defaultstyle |= ES_LEFT;
1981 break;
1982 case CT_LISTBOX:
1983 defaultstyle |= LBS_NOTIFY;
1984 break;
1985 case CT_COMBOBOX:
1986 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1987 break;
1988 case CT_SCROLLBAR:
1989 defaultstyle |= SBS_HORZ;
1990 break;
1991 case CT_BUTTON:
1992 switch(special_style)
1994 case BS_CHECKBOX:
1995 case BS_DEFPUSHBUTTON:
1996 case BS_PUSHBUTTON:
1997 /* case BS_PUSHBOX: */
1998 case BS_AUTORADIOBUTTON:
1999 case BS_AUTO3STATE:
2000 case BS_3STATE:
2001 case BS_AUTOCHECKBOX:
2002 defaultstyle |= WS_TABSTOP;
2003 break;
2004 default:
2005 parser_warning("Unknown default button control-style 0x%08x\n", special_style);
2006 case BS_GROUPBOX:
2007 case BS_RADIOBUTTON:
2008 break;
2010 break;
2012 case CT_STATIC:
2013 switch(special_style)
2015 case SS_LEFT:
2016 case SS_RIGHT:
2017 case SS_CENTER:
2018 defaultstyle |= WS_GROUP;
2019 break;
2020 case SS_ICON: /* Special case */
2021 break;
2022 default:
2023 parser_warning("Unknown default static control-style 0x%08x\n", special_style);
2024 break;
2026 break;
2027 case -1: /* Generic control */
2028 goto byebye;
2030 default:
2031 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2035 /* The SS_ICON flag is always forced in for icon controls */
2036 if(type == CT_STATIC && special_style == SS_ICON)
2037 defaultstyle |= SS_ICON;
2039 if (!ctrl->gotstyle)
2040 ctrl->style = new_style(0,0);
2042 /* combine all styles */
2043 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2044 ctrl->gotstyle = TRUE;
2045 byebye:
2046 /* combine with NOT mask */
2047 if (ctrl->gotstyle)
2049 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2050 ctrl->style->and_mask = 0;
2052 if (ctrl->gotexstyle)
2054 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2055 ctrl->exstyle->and_mask = 0;
2057 return ctrl;
2060 static int get_class_idW(const WCHAR *cc)
2062 static const WCHAR szBUTTON[] = {'B','U','T','T','O','N',0};
2063 static const WCHAR szCOMBOBOX[] = {'C','O','M','B','O','B','O','X',0};
2064 static const WCHAR szLISTBOX[] = {'L','I','S','T','B','O','X',0};
2065 static const WCHAR szEDIT[] = {'E','D','I','T',0};
2066 static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0};
2067 static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0};
2069 if(!compare_striW(szBUTTON, cc)) return CT_BUTTON;
2070 if(!compare_striW(szCOMBOBOX, cc)) return CT_COMBOBOX;
2071 if(!compare_striW(szLISTBOX, cc)) return CT_LISTBOX;
2072 if(!compare_striW(szEDIT, cc)) return CT_EDIT;
2073 if(!compare_striW(szSTATIC, cc)) return CT_STATIC;
2074 if(!compare_striW(szSCROLLBAR, cc)) return CT_SCROLLBAR;
2075 return -1;
2078 static int get_class_idA(const char *cc)
2080 if(!compare_striA("BUTTON", cc)) return CT_BUTTON;
2081 if(!compare_striA("COMBOBOX", cc)) return CT_COMBOBOX;
2082 if(!compare_striA("LISTBOX", cc)) return CT_LISTBOX;
2083 if(!compare_striA("EDIT", cc)) return CT_EDIT;
2084 if(!compare_striA("STATIC", cc)) return CT_STATIC;
2085 if(!compare_striA("SCROLLBAR", cc)) return CT_SCROLLBAR;
2086 return -1;
2090 static name_id_t *convert_ctlclass(name_id_t *cls)
2092 int iclass;
2094 if(cls->type == name_ord)
2095 return cls;
2096 assert(cls->type == name_str);
2097 if(cls->name.s_name->type == str_unicode)
2098 iclass = get_class_idW(cls->name.s_name->str.wstr);
2099 else
2100 iclass = get_class_idA(cls->name.s_name->str.cstr);
2102 if (iclass == -1)
2103 return cls; /* No default, return user controlclass */
2105 free(cls->name.s_name->str.cstr);
2106 free(cls->name.s_name);
2107 cls->type = name_ord;
2108 cls->name.i_name = iclass;
2109 return cls;
2112 /* Accelerator specific functions */
2113 static event_t *add_event(int key, int id, int flags, event_t *prev)
2115 event_t *ev = new_event();
2117 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2118 yyerror("Cannot use both ASCII and VIRTKEY");
2120 ev->key = key;
2121 ev->id = id;
2122 ev->flags = flags & ~WRC_AF_ASCII;
2123 ev->prev = prev;
2124 if(prev)
2125 prev->next = ev;
2126 return ev;
2129 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2131 event_t *ev = new_event();
2133 ev->str = key;
2134 ev->id = id;
2135 ev->flags = flags & ~WRC_AF_ASCII;
2136 ev->prev = prev;
2137 if(prev)
2138 prev->next = ev;
2139 return ev;
2142 /* MenuEx specific functions */
2143 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2145 itemex_opt_t *opt = xmalloc(sizeof(itemex_opt_t));
2146 memset( opt, 0, sizeof(*opt) );
2147 opt->id = id;
2148 opt->type = type;
2149 opt->state = state;
2150 opt->helpid = helpid;
2151 return opt;
2154 /* Raw data functions */
2155 static raw_data_t *load_file(string_t *filename, language_t *lang)
2157 FILE *fp = NULL;
2158 char *path, *name;
2159 raw_data_t *rd;
2161 if (filename->type == str_unicode)
2162 name = convert_string_utf8( filename, 0 );
2163 else
2164 name = xstrdup( filename->str.cstr );
2165 if (!(path = wpp_find_include(name, input_name)))
2166 yyerror("Cannot open file %s", name);
2167 if (!(fp = fopen( path, "rb" )))
2168 yyerror("Cannot open file %s", name);
2169 free( path );
2170 rd = new_raw_data();
2171 fseek(fp, 0, SEEK_END);
2172 rd->size = ftell(fp);
2173 fseek(fp, 0, SEEK_SET);
2174 if (rd->size)
2176 rd->data = xmalloc(rd->size);
2177 fread(rd->data, rd->size, 1, fp);
2179 else rd->data = NULL;
2180 fclose(fp);
2181 rd->lvc.language = lang;
2182 free(name);
2183 return rd;
2186 static raw_data_t *int2raw_data(int i)
2188 raw_data_t *rd;
2190 if( ( i >= 0 && (int)((unsigned short)i) != i) ||
2191 ( i < 0 && (int)((short)i) != i) )
2192 parser_warning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2194 rd = new_raw_data();
2195 rd->size = sizeof(short);
2196 rd->data = xmalloc(rd->size);
2197 rd->data[0] = i;
2198 rd->data[1] = i >> 8;
2199 return rd;
2202 static raw_data_t *long2raw_data(int i)
2204 raw_data_t *rd;
2205 rd = new_raw_data();
2206 rd->size = sizeof(int);
2207 rd->data = xmalloc(rd->size);
2208 rd->data[0] = i;
2209 rd->data[1] = i >> 8;
2210 rd->data[2] = i >> 16;
2211 rd->data[3] = i >> 24;
2212 return rd;
2215 static raw_data_t *str2raw_data(string_t *str)
2217 raw_data_t *rd;
2218 rd = new_raw_data();
2219 rd->size = str->size * (str->type == str_char ? 1 : 2);
2220 rd->data = xmalloc(rd->size);
2221 switch (str->type)
2223 case str_char:
2224 memcpy(rd->data, str->str.cstr, rd->size);
2225 break;
2226 case str_unicode:
2228 int i;
2229 for(i = 0; i < str->size; i++)
2231 rd->data[2*i + 0] = str->str.wstr[i];
2232 rd->data[2*i + 1] = str->str.wstr[i] >> 8;
2236 return rd;
2239 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2241 r1->data = xrealloc(r1->data, r1->size + r2->size);
2242 memcpy(r1->data + r1->size, r2->data, r2->size);
2243 r1->size += r2->size;
2244 return r1;
2247 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2249 raw_data_t *t = int2raw_data(i);
2250 merge_raw_data(r1, t);
2251 free(t->data);
2252 free(t);
2253 return r1;
2256 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2258 raw_data_t *t = long2raw_data(i);
2259 merge_raw_data(r1, t);
2260 free(t->data);
2261 free(t);
2262 return r1;
2265 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2267 raw_data_t *t = str2raw_data(str);
2268 merge_raw_data(r1, t);
2269 free(t->data);
2270 free(t);
2271 return r1;
2274 /* Function the go back in a list to get the head */
2275 static menu_item_t *get_item_head(menu_item_t *p)
2277 if(!p)
2278 return NULL;
2279 while(p->prev)
2280 p = p->prev;
2281 return p;
2284 static resource_t *get_resource_head(resource_t *p)
2286 if(!p)
2287 return NULL;
2288 while(p->prev)
2289 p = p->prev;
2290 return p;
2293 static ver_block_t *get_ver_block_head(ver_block_t *p)
2295 if(!p)
2296 return NULL;
2297 while(p->prev)
2298 p = p->prev;
2299 return p;
2302 static ver_value_t *get_ver_value_head(ver_value_t *p)
2304 if(!p)
2305 return NULL;
2306 while(p->prev)
2307 p = p->prev;
2308 return p;
2311 static control_t *get_control_head(control_t *p)
2313 if(!p)
2314 return NULL;
2315 while(p->prev)
2316 p = p->prev;
2317 return p;
2320 static event_t *get_event_head(event_t *p)
2322 if(!p)
2323 return NULL;
2324 while(p->prev)
2325 p = p->prev;
2326 return p;
2329 /* Find a stringtable with given language */
2330 static stringtable_t *find_stringtable(lvc_t *lvc)
2332 stringtable_t *stt;
2334 assert(lvc != NULL);
2336 if(!lvc->language)
2337 lvc->language = dup_language(currentlanguage);
2339 for(stt = sttres; stt; stt = stt->next)
2341 if(stt->lvc.language->id == lvc->language->id
2342 && stt->lvc.language->sub == lvc->language->sub)
2344 /* Found a table with the same language */
2345 /* The version and characteristics are now handled
2346 * in the generation of the individual stringtables.
2347 * This enables localized analysis.
2348 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2349 || (!stt->lvc.version && lvc->version)
2350 || (stt->lvc.version && !lvc->version))
2351 parser_warning("Stringtable's versions are not the same, using first definition\n");
2353 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2354 || (!stt->lvc.characts && lvc->characts)
2355 || (stt->lvc.characts && !lvc->characts))
2356 parser_warning("Stringtable's characteristics are not the same, using first definition\n");
2358 return stt;
2361 return NULL;
2364 /* qsort sorting function for string table entries */
2365 #define STE(p) ((const stt_entry_t *)(p))
2366 static int sort_stt_entry(const void *e1, const void *e2)
2368 return STE(e1)->id - STE(e2)->id;
2370 #undef STE
2372 static resource_t *build_stt_resources(stringtable_t *stthead)
2374 stringtable_t *stt;
2375 stringtable_t *newstt;
2376 resource_t *rsc;
2377 resource_t *rsclist = NULL;
2378 resource_t *rsctail = NULL;
2379 int i;
2380 int j;
2381 unsigned int andsum;
2382 unsigned int orsum;
2383 characts_t *characts;
2384 version_t *version;
2386 if(!stthead)
2387 return NULL;
2389 /* For all languages defined */
2390 for(stt = stthead; stt; stt = stt->next)
2392 assert(stt->nentries > 0);
2394 /* Sort the entries */
2395 if(stt->nentries > 1)
2396 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2398 for(i = 0; i < stt->nentries; )
2400 newstt = new_stringtable(&stt->lvc);
2401 newstt->entries = xmalloc(16 * sizeof(stt_entry_t));
2402 memset( newstt->entries, 0, 16 * sizeof(stt_entry_t) );
2403 newstt->nentries = 16;
2404 newstt->idbase = stt->entries[i].id & ~0xf;
2405 for(j = 0; j < 16 && i < stt->nentries; j++)
2407 if(stt->entries[i].id - newstt->idbase == j)
2409 newstt->entries[j] = stt->entries[i];
2410 i++;
2413 andsum = ~0;
2414 orsum = 0;
2415 characts = NULL;
2416 version = NULL;
2417 /* Check individual memory options and get
2418 * the first characteristics/version
2420 for(j = 0; j < 16; j++)
2422 if(!newstt->entries[j].str)
2423 continue;
2424 andsum &= newstt->entries[j].memopt;
2425 orsum |= newstt->entries[j].memopt;
2426 if(!characts)
2427 characts = newstt->entries[j].characts;
2428 if(!version)
2429 version = newstt->entries[j].version;
2431 if(andsum != orsum)
2433 warning("Stringtable's memory options are not equal (idbase: %d)\n", newstt->idbase);
2435 /* Check version and characteristics */
2436 for(j = 0; j < 16; j++)
2438 if(characts
2439 && newstt->entries[j].characts
2440 && *newstt->entries[j].characts != *characts)
2441 warning("Stringtable's characteristics are not the same (idbase: %d)\n", newstt->idbase);
2442 if(version
2443 && newstt->entries[j].version
2444 && *newstt->entries[j].version != *version)
2445 warning("Stringtable's versions are not the same (idbase: %d)\n", newstt->idbase);
2447 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2448 rsc->name = new_name_id();
2449 rsc->name->type = name_ord;
2450 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2451 rsc->memopt = andsum; /* Set to least common denominator */
2452 newstt->memopt = andsum;
2453 newstt->lvc.characts = characts;
2454 newstt->lvc.version = version;
2455 if(!rsclist)
2457 rsclist = rsc;
2458 rsctail = rsc;
2460 else
2462 rsctail->next = rsc;
2463 rsc->prev = rsctail;
2464 rsctail = rsc;
2468 return rsclist;
2472 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2474 idrec->prev = prev;
2475 if(prev)
2476 prev->next = idrec;
2478 return idrec;
2481 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2483 if(!p)
2485 *nitems = 0;
2486 return NULL;
2489 *nitems = 1;
2491 while(p->prev)
2493 (*nitems)++;
2494 p = p->prev;
2497 return p;
2500 static string_t *make_filename(string_t *str)
2502 int i;
2504 if(str->type == str_char)
2506 char *dst = str->str.cstr;
2508 /* Remove escaped backslash and convert to forward */
2509 for (i = 0; i < str->size; i++)
2511 if (str->str.cstr[i] == '\\')
2513 if (i < str->size - 1 && str->str.cstr[i + 1] == '\\') i++;
2514 *dst++ = '/';
2516 else *dst++ = str->str.cstr[i];
2518 *dst = 0;
2519 str->size = dst - str->str.cstr;
2521 else
2523 WCHAR *dst = str->str.wstr;
2525 /* Remove escaped backslash and convert to forward */
2526 for (i = 0; i < str->size; i++)
2528 if (str->str.wstr[i] == '\\')
2530 if (i < str->size - 1 && str->str.wstr[i + 1] == '\\') i++;
2531 *dst++ = '/';
2533 else *dst++ = str->str.wstr[i];
2535 *dst = 0;
2536 str->size = dst - str->str.wstr;
2538 return str;
2542 * Process all resources to extract fonts and build
2543 * a fontdir resource.
2545 * Note: MS' resource compiler (build 1472) does not
2546 * handle font resources with different languages.
2547 * The fontdir is generated in the last active language
2548 * and font identifiers must be unique across the entire
2549 * source.
2550 * This is not logical considering the localization
2551 * constraints of all other resource types. MS has,
2552 * most probably, never testet localized fonts. However,
2553 * using fontresources is rare, so it might not occur
2554 * in normal applications.
2555 * Wine does require better localization because a lot
2556 * of languages are coded into the same executable.
2557 * Therefore, I will generate fontdirs for *each*
2558 * localized set of fonts.
2560 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2562 static int once = 0;
2563 if(!once)
2565 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)\n", fnt, nfnt);
2566 once++;
2568 return NULL;
2571 static resource_t *build_fontdirs(resource_t *tail)
2573 resource_t *rsc;
2574 resource_t *lst = NULL;
2575 resource_t **fnt = NULL; /* List of all fonts */
2576 int nfnt = 0;
2577 resource_t **fnd = NULL; /* List of all fontdirs */
2578 int nfnd = 0;
2579 resource_t **lanfnt = NULL;
2580 int nlanfnt = 0;
2581 int i;
2582 name_id_t nid;
2583 string_t str;
2584 int fntleft;
2586 nid.type = name_str;
2587 nid.name.s_name = &str;
2588 str.type = str_char;
2589 str.str.cstr = xstrdup("FONTDIR");
2590 str.size = 7;
2592 /* Extract all fonts and fontdirs */
2593 for(rsc = tail; rsc; rsc = rsc->prev)
2595 if(rsc->type == res_fnt)
2597 nfnt++;
2598 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2599 fnt[nfnt-1] = rsc;
2601 else if(rsc->type == res_fntdir)
2603 nfnd++;
2604 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2605 fnd[nfnd-1] = rsc;
2609 /* Verify the name of the present fontdirs */
2610 for(i = 0; i < nfnd; i++)
2612 if(compare_name_id(&nid, fnd[i]->name))
2614 warning("User supplied FONTDIR entry has an invalid name '%s', ignored\n",
2615 get_nameid_str(fnd[i]->name));
2616 fnd[i] = NULL;
2620 /* Sanity check */
2621 if(nfnt == 0)
2623 if(nfnd != 0)
2624 warning("Found %d FONTDIR entries without any fonts present\n", nfnd);
2625 goto clean;
2628 /* Copy space */
2629 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2630 memset( lanfnt, 0, nfnt * sizeof(*lanfnt));
2632 /* Get all fonts covered by fontdirs */
2633 for(i = 0; i < nfnd; i++)
2635 int j;
2637 if(!fnd[i])
2638 continue;
2639 for(j = 0; j < nfnt; j++)
2641 if(!fnt[j])
2642 continue;
2643 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2645 lanfnt[nlanfnt] = fnt[j];
2646 nlanfnt++;
2647 fnt[j] = NULL;
2652 /* We now have fonts left where we need to make a fontdir resource */
2653 for(i = fntleft = 0; i < nfnt; i++)
2655 if(fnt[i])
2656 fntleft++;
2658 while(fntleft)
2660 /* Get fonts of same language in lanfnt[] */
2661 for(i = nlanfnt = 0; i < nfnt; i++)
2663 if(fnt[i])
2665 if(!nlanfnt)
2667 addlanfnt:
2668 lanfnt[nlanfnt] = fnt[i];
2669 nlanfnt++;
2670 fnt[i] = NULL;
2671 fntleft--;
2673 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2674 goto addlanfnt;
2677 /* and build a fontdir */
2678 rsc = build_fontdir(lanfnt, nlanfnt);
2679 if(rsc)
2681 if(lst)
2683 lst->next = rsc;
2684 rsc->prev = lst;
2686 lst = rsc;
2690 free(lanfnt);
2691 clean:
2692 free(fnt);
2693 free(fnd);
2694 free(str.str.cstr);
2695 return lst;
2699 * This gets invoked to determine whether the next resource
2700 * is to be of a standard-type (e.g. bitmaps etc.), or should
2701 * be a user-type resource. This function is required because
2702 * there is the _possibility_ of a lookahead token in the
2703 * parser, which is generated from the "expr" state in the
2704 * "nameid" parsing.
2706 * The general resource format is:
2707 * <identifier> <type> <flags> <resourcebody>
2709 * The <identifier> can either be tIDENT or "expr". The latter
2710 * will always generate a lookahead, which is the <type> of the
2711 * resource to parse. Otherwise, we need to get a new token from
2712 * the scanner to determine the next step.
2714 * The problem arrises when <type> is numerical. This case should
2715 * map onto default resource-types and be parsed as such instead
2716 * of being mapped onto user-type resources.
2718 * The trick lies in the fact that yacc (bison) doesn't care about
2719 * intermediate changes of the lookahead while reducing a rule. We
2720 * simply replace the lookahead with a token that will result in
2721 * a shift to the appropriate rule for the specific resource-type.
2723 static int rsrcid_to_token(int lookahead)
2725 int token;
2727 /* Get a token if we don't have one yet */
2728 if(lookahead == YYEMPTY)
2729 lookahead = yylex();
2731 /* Only numbers are possibly interesting */
2732 switch(lookahead)
2734 case tNUMBER:
2735 case tLNUMBER:
2736 break;
2737 default:
2738 return lookahead;
2741 token = lookahead;
2743 switch(yylval.num)
2745 case WRC_RT_CURSOR:
2746 token = tCURSOR;
2747 break;
2748 case WRC_RT_ICON:
2749 token = tICON;
2750 break;
2751 case WRC_RT_BITMAP:
2752 token = tBITMAP;
2753 break;
2754 case WRC_RT_FONT:
2755 token = tFONT;
2756 break;
2757 case WRC_RT_FONTDIR:
2758 token = tFONTDIR;
2759 break;
2760 case WRC_RT_RCDATA:
2761 token = tRCDATA;
2762 break;
2763 case WRC_RT_MESSAGETABLE:
2764 token = tMESSAGETABLE;
2765 break;
2766 case WRC_RT_DLGINIT:
2767 token = tDLGINIT;
2768 break;
2769 case WRC_RT_ACCELERATOR:
2770 token = tACCELERATORS;
2771 break;
2772 case WRC_RT_MENU:
2773 token = tMENU;
2774 break;
2775 case WRC_RT_DIALOG:
2776 token = tDIALOG;
2777 break;
2778 case WRC_RT_VERSION:
2779 token = tVERSIONINFO;
2780 break;
2781 case WRC_RT_TOOLBAR:
2782 token = tTOOLBAR;
2783 break;
2784 case WRC_RT_HTML:
2785 token = tHTML;
2786 break;
2788 case WRC_RT_STRING:
2789 break;
2791 case WRC_RT_ANICURSOR:
2792 case WRC_RT_ANIICON:
2793 case WRC_RT_GROUP_CURSOR:
2794 case WRC_RT_GROUP_ICON:
2795 parser_warning("Usertype uses reserved type ID %d, which is auto-generated\n", yylval.num);
2796 return lookahead;
2798 case WRC_RT_DLGINCLUDE:
2799 case WRC_RT_PLUGPLAY:
2800 case WRC_RT_VXD:
2801 parser_warning("Usertype uses reserved type ID %d, which is not supported by wrc yet\n", yylval.num);
2802 default:
2803 return lookahead;
2806 return token;