combase/tests: Build without -DWINE_NO_LONG_TYPES.
[wine.git] / tools / wrc / parser.y
blobe9a19905949cb95e02a344bf8579aefc4738c3ef
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 "dumpres.h"
138 #include "wpp_private.h"
139 #include "parser.h"
140 #include "windef.h"
141 #include "winbase.h"
142 #include "wingdi.h"
143 #include "winuser.h"
145 int want_nl = 0; /* Signal flex that we need the next newline */
146 int want_id = 0; /* Signal flex that we need the next identifier */
147 static stringtable_t *tagstt; /* Stringtable tag.
148 * It is set while parsing a stringtable to one of
149 * the stringtables in the sttres list or a new one
150 * if the language was not parsed before.
152 static stringtable_t *sttres; /* Stringtable resources. This holds the list of
153 * stringtables with different lanuages
155 static int dont_want_id = 0; /* See language parsing for details */
157 /* Set to the current options of the currently scanning stringtable */
158 static int *tagstt_memopt;
159 static characts_t *tagstt_characts;
160 static version_t *tagstt_version;
162 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
164 /* Prototypes of here defined functions */
165 static event_t *get_event_head(event_t *p);
166 static control_t *get_control_head(control_t *p);
167 static ver_value_t *get_ver_value_head(ver_value_t *p);
168 static ver_block_t *get_ver_block_head(ver_block_t *p);
169 static resource_t *get_resource_head(resource_t *p);
170 static menu_item_t *get_item_head(menu_item_t *p);
171 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
172 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
173 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
174 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
175 static raw_data_t *str2raw_data(string_t *str);
176 static raw_data_t *int2raw_data(int i);
177 static raw_data_t *long2raw_data(int i);
178 static raw_data_t *load_file(string_t *name, language_t *lang);
179 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
180 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
181 static event_t *add_event(int key, int id, int flags, event_t *prev);
182 static name_id_t *convert_ctlclass(name_id_t *cls);
183 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
184 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
185 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
186 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
187 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
188 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
189 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
190 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
191 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
192 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
193 static resource_t *build_stt_resources(stringtable_t *stthead);
194 static stringtable_t *find_stringtable(lvc_t *lvc);
195 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
196 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
197 static string_t *make_filename(string_t *s);
198 static resource_t *build_fontdirs(resource_t *tail);
199 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
200 static int rsrcid_to_token(int lookahead);
202 /* bison >= 3.6 applies api.prefix also to YYEMPTY */
203 #define YYEMPTY (-2)
207 %define api.prefix {parser_}
209 %union{
210 string_t *str;
211 int num;
212 int *iptr;
213 char *cptr;
214 resource_t *res;
215 accelerator_t *acc;
216 bitmap_t *bmp;
217 dialog_t *dlg;
218 font_t *fnt;
219 fontdir_t *fnd;
220 menu_t *men;
221 html_t *html;
222 rcdata_t *rdt;
223 stringtable_t *stt;
224 stt_entry_t *stte;
225 user_t *usr;
226 messagetable_t *msg;
227 versioninfo_t *veri;
228 control_t *ctl;
229 name_id_t *nid;
230 font_id_t *fntid;
231 language_t *lan;
232 version_t *ver;
233 characts_t *chars;
234 event_t *event;
235 menu_item_t *menitm;
236 itemex_opt_t *exopt;
237 raw_data_t *raw;
238 lvc_t *lvc;
239 ver_value_t *val;
240 ver_block_t *blk;
241 ver_words_t *verw;
242 toolbar_t *tlbar;
243 toolbar_item_t *tlbarItems;
244 dlginit_t *dginit;
245 style_pair_t *styles;
246 style_t *style;
247 ani_any_t *ani;
250 %token tNL
251 %token <num> tNUMBER tLNUMBER
252 %token <str> tSTRING tIDENT
253 %token <raw> tRAWDATA
254 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
255 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
256 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
257 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
258 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
259 %token tCONTROL tEDITTEXT
260 %token tRTEXT tCTEXT tLTEXT
261 %token tBLOCK tVALUE
262 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
263 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
264 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
265 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
266 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
267 %token tHELP
268 %token tTOOLBAR tBUTTON
269 %token tBEGIN tEND
270 %token tDLGINIT
271 %left '|'
272 %left '^'
273 %left '&'
274 %left '+' '-'
275 %left '*' '/'
276 %right '~' tNOT
277 %left pUPM
279 %type <res> resource_file resource resources resource_definition
280 %type <stt> stringtable strings
281 %type <fnt> font
282 %type <fnd> fontdir
283 %type <acc> accelerators
284 %type <event> events
285 %type <bmp> bitmap
286 %type <ani> cursor icon
287 %type <dlg> dialog dlg_attributes dialogex dlgex_attribs
288 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
289 %type <iptr> helpid
290 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
291 %type <html> html
292 %type <rdt> rcdata
293 %type <raw> raw_data raw_elements opt_data file_raw
294 %type <veri> versioninfo fix_version
295 %type <verw> ver_words
296 %type <blk> ver_blocks ver_block
297 %type <val> ver_values ver_value
298 %type <men> menu menuex
299 %type <menitm> item_definitions menu_body itemex_definitions menuex_body
300 %type <exopt> itemex_p_options itemex_options
301 %type <msg> messagetable
302 %type <usr> userres
303 %type <num> item_options
304 %type <nid> nameid nameid_s ctlclass usertype
305 %type <num> acc_opt acc accs
306 %type <iptr> loadmemopts lamo lama
307 %type <fntid> opt_font opt_exfont opt_expr
308 %type <lvc> opt_lvc
309 %type <lan> opt_language
310 %type <chars> opt_characts
311 %type <ver> opt_version
312 %type <num> expr xpr
313 %type <iptr> e_expr
314 %type <tlbar> toolbar
315 %type <tlbarItems> toolbar_items
316 %type <dginit> dlginit
317 %type <styles> optional_style_pair
318 %type <num> any_num
319 %type <style> style
320 %type <str> filename
324 resource_file
325 : resources {
326 resource_t *rsc, *head;
327 /* First add stringtables to the resource-list */
328 rsc = build_stt_resources(sttres);
329 /* 'build_stt_resources' returns a head and $1 is a tail */
330 if($1)
332 $1->next = rsc;
333 if(rsc)
334 rsc->prev = $1;
336 else
337 $1 = rsc;
338 /* Find the tail again */
339 while($1 && $1->next)
340 $1 = $1->next;
341 /* Now add any fontdirectory */
342 rsc = build_fontdirs($1);
343 /* 'build_fontdir' returns a head and $1 is a tail */
344 if($1)
346 $1->next = rsc;
347 if(rsc)
348 rsc->prev = $1;
350 else
351 $1 = rsc;
353 /* Final statements before we're done */
354 if ((head = get_resource_head($1)) != NULL)
356 if (resource_top) /* append to existing resources */
358 resource_t *tail = resource_top;
359 while (tail->next) tail = tail->next;
360 tail->next = head;
361 head->prev = tail;
363 else resource_top = head;
365 sttres = NULL;
369 /* Resources are put into a linked list */
370 resources
371 : /* Empty */ { $$ = NULL; want_id = 1; }
372 | resources resource {
373 if($2)
375 resource_t *tail = $2;
376 resource_t *head = $2;
377 while(tail->next)
378 tail = tail->next;
379 while(head->prev)
380 head = head->prev;
381 head->prev = $1;
382 if($1)
383 $1->next = head;
384 $$ = tail;
385 /* Check for duplicate identifiers */
386 while($1 && head)
388 resource_t *rsc = $1;
389 while(rsc)
391 if(rsc->type == head->type
392 && rsc->lan->id == head->lan->id
393 && rsc->lan->sub == head->lan->sub
394 && !compare_name_id(rsc->name, head->name)
395 && (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
397 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
399 rsc = rsc->prev;
401 head = head->next;
404 else if($1)
406 resource_t *tail = $1;
407 while(tail->next)
408 tail = tail->next;
409 $$ = tail;
411 else
412 $$ = NULL;
414 if(!dont_want_id) /* See comments in language parsing below */
415 want_id = 1;
416 dont_want_id = 0;
419 * The following newline rule will never get reduced because we never
420 * get the tNL token, unless we explicitly set the 'want_nl'
421 * flag, which we don't.
422 * The *ONLY* reason for this to be here is because Berkeley
423 * yacc (byacc), at least version 1.9, has a bug.
424 * (identified in the generated parser on the second
425 * line with:
426 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
428 * This extra rule fixes it.
429 * The problem is that the expression handling rule "expr: xpr"
430 * is not reduced on non-terminal tokens, defined above in the
431 * %token declarations. Token tNL is the only non-terminal that
432 * can occur. The error becomes visible in the language parsing
433 * rule below, which looks at the look-ahead token and tests it
434 * for tNL. However, byacc already generates an error upon reading
435 * the token instead of keeping it as a lookahead. The reason
436 * lies in the lack of a $default transition in the "expr : xpr . "
437 * state (currently state 25). It is probably omitted because tNL
438 * is a non-terminal and the state contains 2 s/r conflicts. The
439 * state enumerates all possible transitions instead of using a
440 * $default transition.
441 * All in all, it is a bug in byacc. (period)
443 | resources tNL
447 /* Parse top level resource definitions etc. */
448 resource
449 : expr usrcvt resource_definition {
450 $$ = $3;
451 if($$)
453 if($1 > 65535 || $1 < -32768)
454 yyerror("Resource's ID out of range (%d)", $1);
455 $$->name = new_name_id();
456 $$->name->type = name_ord;
457 $$->name->name.i_name = $1;
458 chat("Got %s (%d)\n", get_typename($3), $$->name->name.i_name);
461 | tIDENT usrcvt resource_definition {
462 $$ = $3;
463 if($$)
465 $$->name = new_name_id();
466 $$->name->type = name_str;
467 $$->name->name.s_name = $1;
468 chat("Got %s (%s)\n", get_typename($3), $$->name->name.s_name->str.cstr);
471 | stringtable {
472 /* Don't do anything, stringtables are converted to
473 * resource_t structures when we are finished parsing and
474 * the final rule of the parser is reduced (see above)
476 $$ = NULL;
477 chat("Got STRINGTABLE\n");
479 | tLANGUAGE {want_nl = 1; } expr ',' expr {
480 /* We *NEED* the newline to delimit the expression.
481 * Otherwise, we would not be able to set the next
482 * want_id anymore because of the token-lookahead.
484 * However, we can test the lookahead-token for
485 * being "non-expression" type, in which case we
486 * continue. Fortunately, tNL is the only token that
487 * will break expression parsing and is implicitly
488 * void, so we just remove it. This scheme makes it
489 * possible to do some (not all) fancy preprocessor
490 * stuff.
491 * BTW, we also need to make sure that the next
492 * reduction of 'resources' above will *not* set
493 * want_id because we already have a lookahead that
494 * cannot be undone.
496 if(yychar != YYEMPTY && yychar != tNL)
497 dont_want_id = 1;
499 if(yychar == tNL)
500 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
501 /* direct access to yychar in rule 'usrcvt' below. */
502 else if(yychar == tIDENT)
503 parser_warning("LANGUAGE statement not delimited with newline; next identifier might be wrong\n");
505 want_nl = 0; /* We don't want it anymore if we didn't get it */
507 if(!win32)
508 parser_warning("LANGUAGE not supported in 16-bit mode\n");
509 free(currentlanguage);
510 if (get_language_codepage($3, $5) == -1)
511 yyerror( "Language %04x is not supported", ($5<<10) + $3);
512 currentlanguage = new_language($3, $5);
513 $$ = NULL;
514 chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, ($5<<10) + $3);
519 * Remapping of numerical resource types
520 * (see also comment of called function below)
522 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
526 * Get a valid name/id
528 nameid : expr {
529 if($1 > 65535 || $1 < -32768)
530 yyerror("Resource's ID out of range (%d)", $1);
531 $$ = new_name_id();
532 $$->type = name_ord;
533 $$->name.i_name = $1;
535 | tIDENT {
536 $$ = new_name_id();
537 $$->type = name_str;
538 $$->name.s_name = $1;
543 * Extra string recognition for CLASS statement in dialogs
545 nameid_s: nameid { $$ = $1; }
546 | tSTRING {
547 $$ = new_name_id();
548 $$->type = name_str;
549 $$->name.s_name = $1;
553 /* get the value for a single resource*/
554 resource_definition
555 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
556 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
557 | cursor {
558 resource_t *rsc;
559 if($1->type == res_anicur)
561 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
563 else /* res_curg */
565 cursor_t *cur;
566 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
567 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
569 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
570 rsc->prev->next = rsc;
571 rsc = rsc->prev;
572 rsc->name = new_name_id();
573 rsc->name->type = name_ord;
574 rsc->name->name.i_name = cur->id;
577 free($1);
579 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
580 | dialogex {
581 if(win32)
582 $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language);
583 else
584 $$ = NULL;
586 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
587 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
588 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
589 | icon {
590 resource_t *rsc;
591 if($1->type == res_aniico)
593 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
595 else /* res_icog */
597 icon_t *ico;
598 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
599 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
601 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
602 rsc->prev->next = rsc;
603 rsc = rsc->prev;
604 rsc->name = new_name_id();
605 rsc->name->type = name_ord;
606 rsc->name->name.i_name = ico->id;
609 free($1);
611 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
612 | menuex {
613 if(win32)
614 $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language);
615 else
616 $$ = NULL;
618 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
619 | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
620 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
621 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
622 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
623 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
627 filename: tIDENT { $$ = make_filename($1); }
628 | tSTRING { $$ = make_filename($1); }
631 /* ------------------------------ Bitmap ------------------------------ */
632 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
635 /* ------------------------------ Cursor ------------------------------ */
636 cursor : tCURSOR loadmemopts file_raw {
637 $$ = new_ani_any();
638 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
640 $$->type = res_anicur;
641 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
643 else
645 $$->type = res_curg;
646 $$->u.curg = new_cursor_group($3, $2);
651 /* ------------------------------ Icon ------------------------------ */
652 icon : tICON loadmemopts file_raw {
653 $$ = new_ani_any();
654 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
656 $$->type = res_aniico;
657 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
659 else
661 $$->type = res_icog;
662 $$->u.icog = new_icon_group($3, $2);
667 /* ------------------------------ Font ------------------------------ */
669 * The reading of raw_data for fonts is a Borland BRC
670 * extension. MS generates an error. However, it is
671 * most logical to support this, considering how wine
672 * enters things in CVS (ascii).
674 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
678 * The fontdir is a Borland BRC extension which only
679 * reads the data as 'raw_data' from the file.
680 * I don't know whether it is interpreted.
681 * The fontdir is generated if it was not present and
682 * fonts are defined in the source.
684 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
687 /* ------------------------------ MessageTable ------------------------------ */
688 /* It might be interesting to implement the MS Message compiler here as well
689 * to get everything in one source. Might be a future project.
691 messagetable
692 : tMESSAGETABLE loadmemopts file_raw {
693 if(!win32)
694 parser_warning("MESSAGETABLE not supported in 16-bit mode\n");
695 $$ = new_messagetable($3, $2);
699 /* ------------------------------ HTML ------------------------------ */
700 html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
703 /* ------------------------------ RCData ------------------------------ */
704 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
707 /* ------------------------------ DLGINIT ------------------------------ */
708 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
711 /* ------------------------------ UserType ------------------------------ */
712 userres : usertype loadmemopts file_raw {
713 $$ = new_user($1, $3, $2);
717 usertype: tNUMBER {
718 $$ = new_name_id();
719 $$->type = name_ord;
720 $$->name.i_name = $1;
722 | tIDENT {
723 $$ = new_name_id();
724 $$->type = name_str;
725 $$->name.s_name = $1;
729 /* ------------------------------ Accelerator ------------------------------ */
730 accelerators
731 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
732 $$ = new_accelerator();
733 if($2)
735 $$->memopt = *($2);
736 free($2);
738 else
740 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
742 if(!$5)
743 yyerror("Accelerator table must have at least one entry");
744 $$->events = get_event_head($5);
745 if($3)
747 $$->lvc = *($3);
748 free($3);
750 if(!$$->lvc.language)
751 $$->lvc.language = dup_language(currentlanguage);
755 events : /* Empty */ { $$=NULL; }
756 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
757 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
761 * The empty rule generates a s/r conflict because of {bi,u}nary expr
762 * on - and +. It cannot be solved in any way because it is the same as
763 * the if/then/else problem (LALR(1) problem). The conflict is moved
764 * away by forcing it to be in the expression handling below.
766 acc_opt : /* Empty */ { $$ = 0; }
767 | ',' accs { $$ = $2; }
770 accs : acc { $$ = $1; }
771 | accs ',' acc { $$ = $1 | $3; }
774 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
775 | tSHIFT { $$ = WRC_AF_SHIFT; }
776 | tCONTROL { $$ = WRC_AF_CONTROL; }
777 | tALT { $$ = WRC_AF_ALT; }
778 | tASCII { $$ = WRC_AF_ASCII; }
779 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
782 /* ------------------------------ Dialog ------------------------------ */
783 /* FIXME: Support EXSTYLE in the dialog line itself */
784 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
785 tBEGIN ctrls tEND {
786 if($2)
788 $10->memopt = *($2);
789 free($2);
791 else
792 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
793 $10->x = $3;
794 $10->y = $5;
795 $10->width = $7;
796 $10->height = $9;
797 $10->controls = get_control_head($12);
798 $$ = $10;
799 if(!$$->gotstyle)
801 $$->style = new_style(0,0);
802 $$->style->or_mask = WS_POPUP;
803 $$->gotstyle = TRUE;
805 if($$->title)
806 $$->style->or_mask |= WS_CAPTION;
807 if($$->font)
808 $$->style->or_mask |= DS_SETFONT;
810 $$->style->or_mask &= ~($$->style->and_mask);
811 $$->style->and_mask = 0;
813 if(!$$->lvc.language)
814 $$->lvc.language = dup_language(currentlanguage);
818 dlg_attributes
819 : /* Empty */ { $$=new_dialog(); }
820 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
821 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
822 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
823 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
824 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
825 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
826 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
827 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
828 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
831 ctrls : /* Empty */ { $$ = NULL; }
832 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
833 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
834 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
835 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
836 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
837 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
838 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
839 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
840 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
841 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
842 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
843 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
844 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
845 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
846 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
847 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
848 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
849 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
850 /* special treatment for icons, as the extent is optional */
851 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
852 $10->title = $3;
853 $10->id = $5;
854 $10->x = $7;
855 $10->y = $9;
856 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
860 lab_ctrl
861 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
862 $$=new_control();
863 $$->title = $1;
864 $$->id = $3;
865 $$->x = $5;
866 $$->y = $7;
867 $$->width = $9;
868 $$->height = $11;
869 if($12)
871 $$->style = $12->style;
872 $$->gotstyle = TRUE;
873 if ($12->exstyle)
875 $$->exstyle = $12->exstyle;
876 $$->gotexstyle = TRUE;
878 free($12);
883 ctrl_desc
884 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
885 $$ = new_control();
886 $$->id = $1;
887 $$->x = $3;
888 $$->y = $5;
889 $$->width = $7;
890 $$->height = $9;
891 if($10)
893 $$->style = $10->style;
894 $$->gotstyle = TRUE;
895 if ($10->exstyle)
897 $$->exstyle = $10->exstyle;
898 $$->gotexstyle = TRUE;
900 free($10);
905 iconinfo: /* Empty */
906 { $$ = new_control(); }
908 | ',' expr ',' expr {
909 $$ = new_control();
910 $$->width = $2;
911 $$->height = $4;
913 | ',' expr ',' expr ',' style {
914 $$ = new_control();
915 $$->width = $2;
916 $$->height = $4;
917 $$->style = $6;
918 $$->gotstyle = TRUE;
920 | ',' expr ',' expr ',' style ',' style {
921 $$ = new_control();
922 $$->width = $2;
923 $$->height = $4;
924 $$->style = $6;
925 $$->gotstyle = TRUE;
926 $$->exstyle = $8;
927 $$->gotexstyle = TRUE;
931 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
932 $$=new_control();
933 $$->title = $1;
934 $$->id = $3;
935 $$->ctlclass = convert_ctlclass($5);
936 $$->style = $7;
937 $$->gotstyle = TRUE;
938 $$->x = $9;
939 $$->y = $11;
940 $$->width = $13;
941 $$->height = $15;
942 $$->exstyle = $17;
943 $$->gotexstyle = TRUE;
945 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
946 $$=new_control();
947 $$->title = $1;
948 $$->id = $3;
949 $$->ctlclass = convert_ctlclass($5);
950 $$->style = $7;
951 $$->gotstyle = TRUE;
952 $$->x = $9;
953 $$->y = $11;
954 $$->width = $13;
955 $$->height = $15;
959 opt_font
960 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
963 /* ------------------------------ style flags ------------------------------ */
964 optional_style_pair
965 : /* Empty */ { $$ = NULL; }
966 | ',' style { $$ = new_style_pair($2, 0); }
967 | ',' style ',' style { $$ = new_style_pair($2, $4); }
970 style
971 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
972 | '(' style ')' { $$ = $2; }
973 | any_num { $$ = new_style($1, 0); }
974 | tNOT any_num { $$ = new_style(0, $2); }
977 ctlclass
978 : expr {
979 $$ = new_name_id();
980 $$->type = name_ord;
981 $$->name.i_name = $1;
983 | tSTRING {
984 $$ = new_name_id();
985 $$->type = name_str;
986 $$->name.s_name = $1;
990 /* ------------------------------ DialogEx ------------------------------ */
991 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
992 tBEGIN exctrls tEND {
993 if(!win32)
994 parser_warning("DIALOGEX not supported in 16-bit mode\n");
995 if($2)
997 $11->memopt = *($2);
998 free($2);
1000 else
1001 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1002 $11->x = $3;
1003 $11->y = $5;
1004 $11->width = $7;
1005 $11->height = $9;
1006 if($10)
1008 $11->helpid = *($10);
1009 $11->gothelpid = TRUE;
1010 free($10);
1012 $11->controls = get_control_head($13);
1013 $$ = $11;
1015 assert($$->style != NULL);
1016 if(!$$->gotstyle)
1018 $$->style->or_mask = WS_POPUP;
1019 $$->gotstyle = TRUE;
1021 if($$->title)
1022 $$->style->or_mask |= WS_CAPTION;
1023 if($$->font)
1024 $$->style->or_mask |= DS_SETFONT;
1026 $$->style->or_mask &= ~($$->style->and_mask);
1027 $$->style->and_mask = 0;
1029 if(!$$->lvc.language)
1030 $$->lvc.language = dup_language(currentlanguage);
1034 dlgex_attribs
1035 : /* Empty */ { $$=new_dialog(); $$->is_ex = TRUE; }
1036 | dlgex_attribs tSTYLE style { $$=dialog_style($3,$1); }
1037 | dlgex_attribs tEXSTYLE style { $$=dialog_exstyle($3,$1); }
1038 | dlgex_attribs tCAPTION tSTRING { $$=dialog_caption($3,$1); }
1039 | dlgex_attribs opt_font { $$=dialog_font($2,$1); }
1040 | dlgex_attribs opt_exfont { $$=dialog_font($2,$1); }
1041 | dlgex_attribs tCLASS nameid_s { $$=dialog_class($3,$1); }
1042 | dlgex_attribs tMENU nameid { $$=dialog_menu($3,$1); }
1043 | dlgex_attribs opt_language { $$=dialog_language($2,$1); }
1044 | dlgex_attribs opt_characts { $$=dialog_characteristics($2,$1); }
1045 | dlgex_attribs opt_version { $$=dialog_version($2,$1); }
1048 exctrls : /* Empty */ { $$ = NULL; }
1049 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1050 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1051 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1052 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1053 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1054 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1055 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1056 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1057 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1058 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1059 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1060 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1061 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1062 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1063 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1064 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1065 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1066 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1067 /* special treatment for icons, as the extent is optional */
1068 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1069 $10->title = $3;
1070 $10->id = $5;
1071 $10->x = $7;
1072 $10->y = $9;
1073 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1077 gen_exctrl
1078 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1079 expr ',' style helpid opt_data {
1080 $$=new_control();
1081 $$->title = $1;
1082 $$->id = $3;
1083 $$->ctlclass = convert_ctlclass($5);
1084 $$->style = $7;
1085 $$->gotstyle = TRUE;
1086 $$->x = $9;
1087 $$->y = $11;
1088 $$->width = $13;
1089 $$->height = $15;
1090 if($17)
1092 $$->exstyle = $17;
1093 $$->gotexstyle = TRUE;
1095 if($18)
1097 $$->helpid = *($18);
1098 $$->gothelpid = TRUE;
1099 free($18);
1101 $$->extra = $19;
1103 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1104 $$=new_control();
1105 $$->title = $1;
1106 $$->id = $3;
1107 $$->style = $7;
1108 $$->gotstyle = TRUE;
1109 $$->ctlclass = convert_ctlclass($5);
1110 $$->x = $9;
1111 $$->y = $11;
1112 $$->width = $13;
1113 $$->height = $15;
1114 $$->extra = $16;
1118 lab_exctrl
1119 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1120 $$=new_control();
1121 $$->title = $1;
1122 $$->id = $3;
1123 $$->x = $5;
1124 $$->y = $7;
1125 $$->width = $9;
1126 $$->height = $11;
1127 if($12)
1129 $$->style = $12->style;
1130 $$->gotstyle = TRUE;
1132 if ($12->exstyle)
1134 $$->exstyle = $12->exstyle;
1135 $$->gotexstyle = TRUE;
1137 free($12);
1140 $$->extra = $14;
1144 exctrl_desc
1145 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1146 $$ = new_control();
1147 $$->id = $1;
1148 $$->x = $3;
1149 $$->y = $5;
1150 $$->width = $7;
1151 $$->height = $9;
1152 if($10)
1154 $$->style = $10->style;
1155 $$->gotstyle = TRUE;
1157 if ($10->exstyle)
1159 $$->exstyle = $10->exstyle;
1160 $$->gotexstyle = TRUE;
1162 free($10);
1164 $$->extra = $12;
1168 opt_data: /* Empty */ { $$ = NULL; }
1169 | raw_data { $$ = $1; }
1172 helpid : /* Empty */ { $$ = NULL; }
1173 | ',' expr { $$ = new_int($2); }
1176 opt_exfont
1177 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1181 * FIXME: This odd expression is here to nullify an extra token found
1182 * in some appstudio produced resources which appear to do nothing.
1184 opt_expr: /* Empty */ { $$ = NULL; }
1185 | ',' expr { $$ = NULL; }
1188 /* ------------------------------ Menu ------------------------------ */
1189 menu : tMENU loadmemopts opt_lvc menu_body {
1190 if(!$4)
1191 yyerror("Menu must contain items");
1192 $$ = new_menu();
1193 if($2)
1195 $$->memopt = *($2);
1196 free($2);
1198 else
1199 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1200 $$->items = get_item_head($4);
1201 if($3)
1203 $$->lvc = *($3);
1204 free($3);
1206 if(!$$->lvc.language)
1207 $$->lvc.language = dup_language(currentlanguage);
1211 menu_body
1212 : tBEGIN item_definitions tEND { $$ = $2; }
1215 item_definitions
1216 : /* Empty */ {$$ = NULL;}
1217 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1218 $$=new_menu_item();
1219 $$->prev = $1;
1220 if($1)
1221 $1->next = $$;
1222 $$->id = $5;
1223 $$->state = $6;
1224 $$->name = $3;
1226 | item_definitions tMENUITEM tSEPARATOR {
1227 $$=new_menu_item();
1228 $$->prev = $1;
1229 if($1)
1230 $1->next = $$;
1232 | item_definitions tPOPUP tSTRING item_options menu_body {
1233 $$ = new_menu_item();
1234 $$->prev = $1;
1235 if($1)
1236 $1->next = $$;
1237 $$->popup = get_item_head($5);
1238 $$->name = $3;
1242 /* NOTE: item_options is right recursive because it would introduce
1243 * a shift/reduce conflict on ',' in itemex_options due to the
1244 * empty rule here. The parser is now forced to look beyond the ','
1245 * before reducing (force shift).
1246 * Right recursion here is not a problem because we cannot expect
1247 * more than 7 parserstack places to be occupied while parsing this
1248 * (who would want to specify a MF_x flag twice?).
1250 item_options
1251 : /* Empty */ { $$ = 0; }
1252 | ',' item_options { $$ = $2; }
1253 | tCHECKED item_options { $$ = $2 | MF_CHECKED; }
1254 | tGRAYED item_options { $$ = $2 | MF_GRAYED; }
1255 | tHELP item_options { $$ = $2 | MF_HELP; }
1256 | tINACTIVE item_options { $$ = $2 | MF_DISABLED; }
1257 | tMENUBARBREAK item_options { $$ = $2 | MF_MENUBARBREAK; }
1258 | tMENUBREAK item_options { $$ = $2 | MF_MENUBREAK; }
1261 /* ------------------------------ MenuEx ------------------------------ */
1262 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1263 if(!win32)
1264 parser_warning("MENUEX not supported in 16-bit mode\n");
1265 if(!$4)
1266 yyerror("MenuEx must contain items");
1267 $$ = new_menu();
1268 $$->is_ex = TRUE;
1269 if($2)
1271 $$->memopt = *($2);
1272 free($2);
1274 else
1275 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1276 $$->items = get_item_head($4);
1277 if($3)
1279 $$->lvc = *($3);
1280 free($3);
1282 if(!$$->lvc.language)
1283 $$->lvc.language = dup_language(currentlanguage);
1287 menuex_body
1288 : tBEGIN itemex_definitions tEND { $$ = $2; }
1291 itemex_definitions
1292 : /* Empty */ {$$ = NULL; }
1293 | itemex_definitions tMENUITEM tSTRING itemex_options {
1294 $$ = new_menu_item();
1295 $$->prev = $1;
1296 if($1)
1297 $1->next = $$;
1298 $$->name = $3;
1299 $$->id = $4->id;
1300 $$->type = $4->type;
1301 $$->state = $4->state;
1302 $$->helpid = $4->helpid;
1303 $$->gotid = $4->gotid;
1304 $$->gottype = $4->gottype;
1305 $$->gotstate = $4->gotstate;
1306 $$->gothelpid = $4->gothelpid;
1307 free($4);
1309 | itemex_definitions tMENUITEM tSEPARATOR {
1310 $$ = new_menu_item();
1311 $$->prev = $1;
1312 if($1)
1313 $1->next = $$;
1315 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1316 $$ = new_menu_item();
1317 $$->prev = $1;
1318 if($1)
1319 $1->next = $$;
1320 $$->popup = get_item_head($5);
1321 $$->name = $3;
1322 $$->id = $4->id;
1323 $$->type = $4->type;
1324 $$->state = $4->state;
1325 $$->helpid = $4->helpid;
1326 $$->gotid = $4->gotid;
1327 $$->gottype = $4->gottype;
1328 $$->gotstate = $4->gotstate;
1329 $$->gothelpid = $4->gothelpid;
1330 free($4);
1334 itemex_options
1335 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1336 | ',' expr {
1337 $$ = new_itemex_opt($2, 0, 0, 0);
1338 $$->gotid = TRUE;
1340 | ',' e_expr ',' e_expr item_options {
1341 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1342 $$->gotid = TRUE;
1343 $$->gottype = TRUE;
1344 $$->gotstate = TRUE;
1345 free($2);
1346 free($4);
1348 | ',' e_expr ',' e_expr ',' expr {
1349 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1350 $$->gotid = TRUE;
1351 $$->gottype = TRUE;
1352 $$->gotstate = TRUE;
1353 free($2);
1354 free($4);
1358 itemex_p_options
1359 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1360 | ',' expr {
1361 $$ = new_itemex_opt($2, 0, 0, 0);
1362 $$->gotid = TRUE;
1364 | ',' e_expr ',' expr {
1365 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1366 free($2);
1367 $$->gotid = TRUE;
1368 $$->gottype = TRUE;
1370 | ',' e_expr ',' e_expr ',' expr {
1371 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1372 free($2);
1373 free($4);
1374 $$->gotid = TRUE;
1375 $$->gottype = TRUE;
1376 $$->gotstate = TRUE;
1378 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1379 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1380 free($2);
1381 free($4);
1382 free($6);
1383 $$->gotid = TRUE;
1384 $$->gottype = TRUE;
1385 $$->gotstate = TRUE;
1386 $$->gothelpid = TRUE;
1390 /* ------------------------------ StringTable ------------------------------ */
1391 /* Stringtables are parsed differently than other resources because their
1392 * layout is substantially different from other resources.
1393 * The table is parsed through a _global_ variable 'tagstt' which holds the
1394 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1395 * list of stringtables of different languages.
1397 stringtable
1398 : stt_head tBEGIN strings tEND {
1399 if(!$3)
1401 yyerror("Stringtable must have at least one entry");
1403 else
1405 stringtable_t *stt;
1406 /* Check if we added to a language table or created
1407 * a new one.
1409 for(stt = sttres; stt; stt = stt->next)
1411 if(stt == tagstt)
1412 break;
1414 if(!stt)
1416 /* It is a new one */
1417 if(sttres)
1419 sttres->prev = tagstt;
1420 tagstt->next = sttres;
1421 sttres = tagstt;
1423 else
1424 sttres = tagstt;
1426 /* Else, we're done */
1428 free(tagstt_memopt);
1429 tagstt_memopt = NULL;
1431 $$ = tagstt;
1435 /* This is to get the language of the currently parsed stringtable */
1436 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1437 if((tagstt = find_stringtable($3)) == NULL)
1438 tagstt = new_stringtable($3);
1439 tagstt_memopt = $2;
1440 tagstt_version = $3->version;
1441 tagstt_characts = $3->characts;
1442 free($3);
1446 strings : /* Empty */ { $$ = NULL; }
1447 | strings expr opt_comma tSTRING {
1448 int i;
1449 assert(tagstt != NULL);
1450 if($2 > 65535 || $2 < -32768)
1451 yyerror("Stringtable entry's ID out of range (%d)", $2);
1452 /* Search for the ID */
1453 for(i = 0; i < tagstt->nentries; i++)
1455 if(tagstt->entries[i].id == $2)
1456 yyerror("Stringtable ID %d already in use", $2);
1458 /* If we get here, then we have a new unique entry */
1459 tagstt->nentries++;
1460 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1461 tagstt->entries[tagstt->nentries-1].id = $2;
1462 tagstt->entries[tagstt->nentries-1].str = $4;
1463 if(tagstt_memopt)
1464 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1465 else
1466 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1467 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1468 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1470 if(pedantic && !$4->size)
1471 parser_warning("Zero length strings make no sense\n");
1472 if(!win32 && $4->size > 254)
1473 yyerror("Stringtable entry more than 254 characters");
1474 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1475 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1476 $$ = tagstt;
1480 opt_comma /* There seem to be two ways to specify a stringtable... */
1481 : /* Empty */
1482 | ','
1485 /* ------------------------------ VersionInfo ------------------------------ */
1486 versioninfo
1487 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1488 $$ = $3;
1489 if($2)
1491 $$->memopt = *($2);
1492 free($2);
1494 else
1495 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1496 $$->blocks = get_ver_block_head($5);
1497 /* Set language; there is no version or characteristics */
1498 $$->lvc.language = dup_language(currentlanguage);
1502 fix_version
1503 : /* Empty */ { $$ = new_versioninfo(); }
1504 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1505 if($1->gotit.fv)
1506 yyerror("FILEVERSION already defined");
1507 $$ = $1;
1508 $$->filever_maj1 = $3;
1509 $$->filever_maj2 = $5;
1510 $$->filever_min1 = $7;
1511 $$->filever_min2 = $9;
1512 $$->gotit.fv = 1;
1514 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1515 if($1->gotit.pv)
1516 yyerror("PRODUCTVERSION already defined");
1517 $$ = $1;
1518 $$->prodver_maj1 = $3;
1519 $$->prodver_maj2 = $5;
1520 $$->prodver_min1 = $7;
1521 $$->prodver_min2 = $9;
1522 $$->gotit.pv = 1;
1524 | fix_version tFILEFLAGS expr {
1525 if($1->gotit.ff)
1526 yyerror("FILEFLAGS already defined");
1527 $$ = $1;
1528 $$->fileflags = $3;
1529 $$->gotit.ff = 1;
1531 | fix_version tFILEFLAGSMASK expr {
1532 if($1->gotit.ffm)
1533 yyerror("FILEFLAGSMASK already defined");
1534 $$ = $1;
1535 $$->fileflagsmask = $3;
1536 $$->gotit.ffm = 1;
1538 | fix_version tFILEOS expr {
1539 if($1->gotit.fo)
1540 yyerror("FILEOS already defined");
1541 $$ = $1;
1542 $$->fileos = $3;
1543 $$->gotit.fo = 1;
1545 | fix_version tFILETYPE expr {
1546 if($1->gotit.ft)
1547 yyerror("FILETYPE already defined");
1548 $$ = $1;
1549 $$->filetype = $3;
1550 $$->gotit.ft = 1;
1552 | fix_version tFILESUBTYPE expr {
1553 if($1->gotit.fst)
1554 yyerror("FILESUBTYPE already defined");
1555 $$ = $1;
1556 $$->filesubtype = $3;
1557 $$->gotit.fst = 1;
1561 ver_blocks
1562 : /* Empty */ { $$ = NULL; }
1563 | ver_blocks ver_block {
1564 $$ = $2;
1565 $$->prev = $1;
1566 if($1)
1567 $1->next = $$;
1571 ver_block
1572 : tBLOCK tSTRING tBEGIN ver_values tEND {
1573 $$ = new_ver_block();
1574 $$->name = $2;
1575 $$->values = get_ver_value_head($4);
1579 ver_values
1580 : /* Empty */ { $$ = NULL; }
1581 | ver_values ver_value {
1582 $$ = $2;
1583 $$->prev = $1;
1584 if($1)
1585 $1->next = $$;
1589 ver_value
1590 : ver_block {
1591 $$ = new_ver_value();
1592 $$->type = val_block;
1593 $$->value.block = $1;
1595 | tVALUE tSTRING ',' tSTRING {
1596 $$ = new_ver_value();
1597 $$->type = val_str;
1598 $$->key = $2;
1599 $$->value.str = $4;
1601 | tVALUE tSTRING ',' ver_words {
1602 $$ = new_ver_value();
1603 $$->type = val_words;
1604 $$->key = $2;
1605 $$->value.words = $4;
1609 ver_words
1610 : expr { $$ = new_ver_words($1); }
1611 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1614 /* ------------------------------ Toolbar ------------------------------ */
1615 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1616 int nitems;
1617 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1618 $$ = new_toolbar($3, $5, items, nitems);
1619 if($2)
1621 $$->memopt = *($2);
1622 free($2);
1624 else
1626 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1628 if($6)
1630 $$->lvc = *($6);
1631 free($6);
1633 if(!$$->lvc.language)
1635 $$->lvc.language = dup_language(currentlanguage);
1640 toolbar_items
1641 : /* Empty */ { $$ = NULL; }
1642 | toolbar_items tBUTTON expr {
1643 toolbar_item_t *idrec = new_toolbar_item();
1644 idrec->id = $3;
1645 $$ = ins_tlbr_button($1, idrec);
1647 | toolbar_items tSEPARATOR {
1648 toolbar_item_t *idrec = new_toolbar_item();
1649 idrec->id = 0;
1650 $$ = ins_tlbr_button($1, idrec);
1654 /* ------------------------------ Memory options ------------------------------ */
1655 loadmemopts
1656 : /* Empty */ { $$ = NULL; }
1657 | loadmemopts lamo {
1658 if($1)
1660 *($1) |= *($2);
1661 $$ = $1;
1662 free($2);
1664 else
1665 $$ = $2;
1667 | loadmemopts lama {
1668 if($1)
1670 *($1) &= *($2);
1671 $$ = $1;
1672 free($2);
1674 else
1676 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1677 $$ = $2;
1682 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD);
1683 if (win32 && pedantic) parser_warning("PRELOAD is ignored in 32-bit mode\n"); }
1684 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE);
1685 if (win32 && pedantic) parser_warning("MOVEABLE is ignored in 32-bit mode\n"); }
1686 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE);
1687 if (win32 && pedantic) parser_warning("DISCARDABLE is ignored in 32-bit mode\n"); }
1688 | tPURE { $$ = new_int(WRC_MO_PURE);
1689 if (win32 && pedantic) parser_warning("PURE is ignored in 32-bit mode\n"); }
1692 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD);
1693 if (win32 && pedantic) parser_warning("LOADONCALL is ignored in 32-bit mode\n"); }
1694 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE);
1695 if (win32 && pedantic) parser_warning("FIXED is ignored in 32-bit mode\n"); }
1696 | tIMPURE { $$ = new_int(~WRC_MO_PURE);
1697 if (win32 && pedantic) parser_warning("IMPURE is ignored in 32-bit mode\n"); }
1700 /* ------------------------------ Win32 options ------------------------------ */
1701 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1702 | opt_lvc opt_language {
1703 if(!win32)
1704 parser_warning("LANGUAGE not supported in 16-bit mode\n");
1705 if($1->language)
1706 yyerror("Language already defined");
1707 $$ = $1;
1708 $1->language = $2;
1710 | opt_lvc opt_characts {
1711 if(!win32)
1712 parser_warning("CHARACTERISTICS not supported in 16-bit mode\n");
1713 if($1->characts)
1714 yyerror("Characteristics already defined");
1715 $$ = $1;
1716 $1->characts = $2;
1718 | opt_lvc opt_version {
1719 if(!win32)
1720 parser_warning("VERSION not supported in 16-bit mode\n");
1721 if($1->version)
1722 yyerror("Version already defined");
1723 $$ = $1;
1724 $1->version = $2;
1729 * This here is another s/r conflict on {bi,u}nary + and -.
1730 * It is due to the look-ahead which must determine when the
1731 * rule opt_language ends. It could be solved with adding a
1732 * tNL at the end, but that seems unreasonable to do.
1733 * The conflict is now moved to the expression handling below.
1735 opt_language
1736 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
1737 if (get_language_codepage($2, $4) == -1)
1738 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1742 opt_characts
1743 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1746 opt_version
1747 : tVERSION expr { $$ = new_version($2); }
1750 /* ------------------------------ Raw data handling ------------------------------ */
1751 raw_data: opt_lvc tBEGIN raw_elements tEND {
1752 if($1)
1754 $3->lvc = *($1);
1755 free($1);
1758 if(!$3->lvc.language)
1759 $3->lvc.language = dup_language(currentlanguage);
1761 $$ = $3;
1765 raw_elements
1766 : tRAWDATA { $$ = $1; }
1767 | tNUMBER { $$ = int2raw_data($1); }
1768 | '-' tNUMBER { $$ = int2raw_data(-($2)); }
1769 | tLNUMBER { $$ = long2raw_data($1); }
1770 | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
1771 | tSTRING { $$ = str2raw_data($1); }
1772 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1773 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1774 | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
1775 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1776 | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
1777 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1780 /* File data or raw data */
1781 file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
1782 | raw_data { $$ = $1; }
1785 /* ------------------------------ Win32 expressions ------------------------------ */
1786 /* All win16 numbers are also handled here. This is inconsistent with MS
1787 * resource compiler, but what the heck, it's just handy to have.
1789 e_expr : /* Empty */ { $$ = 0; }
1790 | expr { $$ = new_int($1); }
1793 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1794 expr : xpr { $$ = ($1); }
1797 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1798 | xpr '-' xpr { $$ = ($1) - ($3); }
1799 | xpr '|' xpr { $$ = ($1) | ($3); }
1800 | xpr '&' xpr { $$ = ($1) & ($3); }
1801 | xpr '*' xpr { $$ = ($1) * ($3); }
1802 | xpr '/' xpr { $$ = ($1) / ($3); }
1803 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1804 | '~' xpr { $$ = ~($2); }
1805 | '-' xpr %prec pUPM { $$ = -($2); }
1806 | '+' xpr %prec pUPM { $$ = $2; }
1807 | '(' xpr ')' { $$ = $2; }
1808 | any_num { $$ = $1; }
1809 | tNOT any_num { $$ = ~($2); }
1812 any_num : tNUMBER { $$ = $1; }
1813 | tLNUMBER { $$ = $1; }
1817 /* Dialog specific functions */
1818 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1820 assert(dlg != NULL);
1821 if(dlg->style == NULL)
1823 dlg->style = new_style(0,0);
1826 if(dlg->gotstyle)
1828 parser_warning("Style already defined, or-ing together\n");
1830 else
1832 dlg->style->or_mask = 0;
1833 dlg->style->and_mask = 0;
1835 dlg->style->or_mask |= st->or_mask;
1836 dlg->style->and_mask |= st->and_mask;
1837 dlg->gotstyle = TRUE;
1838 free(st);
1839 return dlg;
1842 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1844 assert(dlg != NULL);
1845 if(dlg->exstyle == NULL)
1847 dlg->exstyle = new_style(0,0);
1850 if(dlg->gotexstyle)
1852 parser_warning("ExStyle already defined, or-ing together\n");
1854 else
1856 dlg->exstyle->or_mask = 0;
1857 dlg->exstyle->and_mask = 0;
1859 dlg->exstyle->or_mask |= st->or_mask;
1860 dlg->exstyle->and_mask |= st->and_mask;
1861 dlg->gotexstyle = TRUE;
1862 free(st);
1863 return dlg;
1866 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1868 assert(dlg != NULL);
1869 if(dlg->title)
1870 yyerror("Caption already defined");
1871 dlg->title = s;
1872 return dlg;
1875 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1877 assert(dlg != NULL);
1878 if(dlg->font)
1879 yyerror("Font already defined");
1880 dlg->font = f;
1881 return dlg;
1884 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1886 assert(dlg != NULL);
1887 if(dlg->dlgclass)
1888 yyerror("Class already defined");
1889 dlg->dlgclass = n;
1890 return dlg;
1893 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1895 assert(dlg != NULL);
1896 if(dlg->menu)
1897 yyerror("Menu already defined");
1898 dlg->menu = m;
1899 return dlg;
1902 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1904 assert(dlg != NULL);
1905 if(dlg->lvc.language)
1906 yyerror("Language already defined");
1907 dlg->lvc.language = l;
1908 return dlg;
1911 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1913 assert(dlg != NULL);
1914 if(dlg->lvc.characts)
1915 yyerror("Characteristics already defined");
1916 dlg->lvc.characts = c;
1917 return dlg;
1920 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1922 assert(dlg != NULL);
1923 if(dlg->lvc.version)
1924 yyerror("Version already defined");
1925 dlg->lvc.version = v;
1926 return dlg;
1929 /* Controls specific functions */
1930 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1932 /* Hm... this seems to be jammed in at all time... */
1933 int defaultstyle = WS_CHILD | WS_VISIBLE;
1935 assert(ctrl != NULL);
1936 ctrl->prev = prev;
1938 if(prev)
1939 prev->next = ctrl;
1941 /* Check for duplicate identifiers */
1942 while (prev)
1944 if (ctrl->id != -1 && ctrl->id == prev->id)
1945 parser_warning("Duplicate dialog control id %d\n", ctrl->id);
1946 prev = prev->prev;
1949 if(type != -1)
1951 ctrl->ctlclass = new_name_id();
1952 ctrl->ctlclass->type = name_ord;
1953 ctrl->ctlclass->name.i_name = type;
1956 switch(type)
1958 case CT_BUTTON:
1959 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1960 defaultstyle |= WS_TABSTOP;
1961 break;
1962 case CT_EDIT:
1963 defaultstyle |= WS_TABSTOP | WS_BORDER;
1964 break;
1965 case CT_LISTBOX:
1966 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1967 break;
1968 case CT_COMBOBOX:
1969 if (!ctrl->gotstyle || !(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
1970 defaultstyle |= CBS_SIMPLE;
1971 break;
1972 case CT_STATIC:
1973 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1974 defaultstyle |= WS_GROUP;
1975 break;
1978 if(!ctrl->gotstyle) /* Handle default style setting */
1980 switch(type)
1982 case CT_EDIT:
1983 defaultstyle |= ES_LEFT;
1984 break;
1985 case CT_LISTBOX:
1986 defaultstyle |= LBS_NOTIFY;
1987 break;
1988 case CT_COMBOBOX:
1989 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1990 break;
1991 case CT_SCROLLBAR:
1992 defaultstyle |= SBS_HORZ;
1993 break;
1994 case CT_BUTTON:
1995 switch(special_style)
1997 case BS_CHECKBOX:
1998 case BS_DEFPUSHBUTTON:
1999 case BS_PUSHBUTTON:
2000 /* case BS_PUSHBOX: */
2001 case BS_AUTORADIOBUTTON:
2002 case BS_AUTO3STATE:
2003 case BS_3STATE:
2004 case BS_AUTOCHECKBOX:
2005 defaultstyle |= WS_TABSTOP;
2006 break;
2007 default:
2008 parser_warning("Unknown default button control-style 0x%08x\n", special_style);
2009 case BS_GROUPBOX:
2010 case BS_RADIOBUTTON:
2011 break;
2013 break;
2015 case CT_STATIC:
2016 switch(special_style)
2018 case SS_LEFT:
2019 case SS_RIGHT:
2020 case SS_CENTER:
2021 defaultstyle |= WS_GROUP;
2022 break;
2023 case SS_ICON: /* Special case */
2024 break;
2025 default:
2026 parser_warning("Unknown default static control-style 0x%08x\n", special_style);
2027 break;
2029 break;
2030 case -1: /* Generic control */
2031 goto byebye;
2033 default:
2034 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2038 /* The SS_ICON flag is always forced in for icon controls */
2039 if(type == CT_STATIC && special_style == SS_ICON)
2040 defaultstyle |= SS_ICON;
2042 if (!ctrl->gotstyle)
2043 ctrl->style = new_style(0,0);
2045 /* combine all styles */
2046 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2047 ctrl->gotstyle = TRUE;
2048 byebye:
2049 /* combine with NOT mask */
2050 if (ctrl->gotstyle)
2052 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2053 ctrl->style->and_mask = 0;
2055 if (ctrl->gotexstyle)
2057 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2058 ctrl->exstyle->and_mask = 0;
2060 return ctrl;
2063 static int get_class_idW(const WCHAR *cc)
2065 static const WCHAR szBUTTON[] = {'B','U','T','T','O','N',0};
2066 static const WCHAR szCOMBOBOX[] = {'C','O','M','B','O','B','O','X',0};
2067 static const WCHAR szLISTBOX[] = {'L','I','S','T','B','O','X',0};
2068 static const WCHAR szEDIT[] = {'E','D','I','T',0};
2069 static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0};
2070 static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0};
2072 if(!compare_striW(szBUTTON, cc)) return CT_BUTTON;
2073 if(!compare_striW(szCOMBOBOX, cc)) return CT_COMBOBOX;
2074 if(!compare_striW(szLISTBOX, cc)) return CT_LISTBOX;
2075 if(!compare_striW(szEDIT, cc)) return CT_EDIT;
2076 if(!compare_striW(szSTATIC, cc)) return CT_STATIC;
2077 if(!compare_striW(szSCROLLBAR, cc)) return CT_SCROLLBAR;
2078 return -1;
2081 static int get_class_idA(const char *cc)
2083 if(!compare_striA("BUTTON", cc)) return CT_BUTTON;
2084 if(!compare_striA("COMBOBOX", cc)) return CT_COMBOBOX;
2085 if(!compare_striA("LISTBOX", cc)) return CT_LISTBOX;
2086 if(!compare_striA("EDIT", cc)) return CT_EDIT;
2087 if(!compare_striA("STATIC", cc)) return CT_STATIC;
2088 if(!compare_striA("SCROLLBAR", cc)) return CT_SCROLLBAR;
2089 return -1;
2093 static name_id_t *convert_ctlclass(name_id_t *cls)
2095 int iclass;
2097 if(cls->type == name_ord)
2098 return cls;
2099 assert(cls->type == name_str);
2100 if(cls->name.s_name->type == str_unicode)
2101 iclass = get_class_idW(cls->name.s_name->str.wstr);
2102 else
2103 iclass = get_class_idA(cls->name.s_name->str.cstr);
2105 if (iclass == -1)
2106 return cls; /* No default, return user controlclass */
2108 free(cls->name.s_name->str.cstr);
2109 free(cls->name.s_name);
2110 cls->type = name_ord;
2111 cls->name.i_name = iclass;
2112 return cls;
2115 /* Accelerator specific functions */
2116 static event_t *add_event(int key, int id, int flags, event_t *prev)
2118 event_t *ev = new_event();
2120 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2121 yyerror("Cannot use both ASCII and VIRTKEY");
2123 ev->key = key;
2124 ev->id = id;
2125 ev->flags = flags & ~WRC_AF_ASCII;
2126 ev->prev = prev;
2127 if(prev)
2128 prev->next = ev;
2129 return ev;
2132 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2134 event_t *ev = new_event();
2136 ev->str = key;
2137 ev->id = id;
2138 ev->flags = flags & ~WRC_AF_ASCII;
2139 ev->prev = prev;
2140 if(prev)
2141 prev->next = ev;
2142 return ev;
2145 /* MenuEx specific functions */
2146 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2148 itemex_opt_t *opt = xmalloc(sizeof(itemex_opt_t));
2149 memset( opt, 0, sizeof(*opt) );
2150 opt->id = id;
2151 opt->type = type;
2152 opt->state = state;
2153 opt->helpid = helpid;
2154 return opt;
2157 /* Raw data functions */
2158 static raw_data_t *load_file(string_t *filename, language_t *lang)
2160 FILE *fp = NULL;
2161 char *path, *name;
2162 raw_data_t *rd;
2164 if (filename->type == str_unicode)
2165 name = convert_string_utf8( filename, 0 );
2166 else
2167 name = xstrdup( filename->str.cstr );
2168 if (!(path = wpp_find_include(name, input_name)))
2169 yyerror("Cannot open file %s", name);
2170 if (!(fp = fopen( path, "rb" )))
2171 yyerror("Cannot open file %s", name);
2172 free( path );
2173 rd = new_raw_data();
2174 fseek(fp, 0, SEEK_END);
2175 rd->size = ftell(fp);
2176 fseek(fp, 0, SEEK_SET);
2177 if (rd->size)
2179 rd->data = xmalloc(rd->size);
2180 fread(rd->data, rd->size, 1, fp);
2182 else rd->data = NULL;
2183 fclose(fp);
2184 rd->lvc.language = lang;
2185 free(name);
2186 return rd;
2189 static raw_data_t *int2raw_data(int i)
2191 raw_data_t *rd;
2193 if( ( i >= 0 && (int)((unsigned short)i) != i) ||
2194 ( i < 0 && (int)((short)i) != i) )
2195 parser_warning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2197 rd = new_raw_data();
2198 rd->size = sizeof(short);
2199 rd->data = xmalloc(rd->size);
2200 rd->data[0] = i;
2201 rd->data[1] = i >> 8;
2202 return rd;
2205 static raw_data_t *long2raw_data(int i)
2207 raw_data_t *rd;
2208 rd = new_raw_data();
2209 rd->size = sizeof(int);
2210 rd->data = xmalloc(rd->size);
2211 rd->data[0] = i;
2212 rd->data[1] = i >> 8;
2213 rd->data[2] = i >> 16;
2214 rd->data[3] = i >> 24;
2215 return rd;
2218 static raw_data_t *str2raw_data(string_t *str)
2220 raw_data_t *rd;
2221 rd = new_raw_data();
2222 rd->size = str->size * (str->type == str_char ? 1 : 2);
2223 rd->data = xmalloc(rd->size);
2224 switch (str->type)
2226 case str_char:
2227 memcpy(rd->data, str->str.cstr, rd->size);
2228 break;
2229 case str_unicode:
2231 int i;
2232 for(i = 0; i < str->size; i++)
2234 rd->data[2*i + 0] = str->str.wstr[i];
2235 rd->data[2*i + 1] = str->str.wstr[i] >> 8;
2239 return rd;
2242 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2244 r1->data = xrealloc(r1->data, r1->size + r2->size);
2245 memcpy(r1->data + r1->size, r2->data, r2->size);
2246 r1->size += r2->size;
2247 return r1;
2250 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2252 raw_data_t *t = int2raw_data(i);
2253 merge_raw_data(r1, t);
2254 free(t->data);
2255 free(t);
2256 return r1;
2259 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2261 raw_data_t *t = long2raw_data(i);
2262 merge_raw_data(r1, t);
2263 free(t->data);
2264 free(t);
2265 return r1;
2268 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2270 raw_data_t *t = str2raw_data(str);
2271 merge_raw_data(r1, t);
2272 free(t->data);
2273 free(t);
2274 return r1;
2277 /* Function the go back in a list to get the head */
2278 static menu_item_t *get_item_head(menu_item_t *p)
2280 if(!p)
2281 return NULL;
2282 while(p->prev)
2283 p = p->prev;
2284 return p;
2287 static resource_t *get_resource_head(resource_t *p)
2289 if(!p)
2290 return NULL;
2291 while(p->prev)
2292 p = p->prev;
2293 return p;
2296 static ver_block_t *get_ver_block_head(ver_block_t *p)
2298 if(!p)
2299 return NULL;
2300 while(p->prev)
2301 p = p->prev;
2302 return p;
2305 static ver_value_t *get_ver_value_head(ver_value_t *p)
2307 if(!p)
2308 return NULL;
2309 while(p->prev)
2310 p = p->prev;
2311 return p;
2314 static control_t *get_control_head(control_t *p)
2316 if(!p)
2317 return NULL;
2318 while(p->prev)
2319 p = p->prev;
2320 return p;
2323 static event_t *get_event_head(event_t *p)
2325 if(!p)
2326 return NULL;
2327 while(p->prev)
2328 p = p->prev;
2329 return p;
2332 /* Find a stringtable with given language */
2333 static stringtable_t *find_stringtable(lvc_t *lvc)
2335 stringtable_t *stt;
2337 assert(lvc != NULL);
2339 if(!lvc->language)
2340 lvc->language = dup_language(currentlanguage);
2342 for(stt = sttres; stt; stt = stt->next)
2344 if(stt->lvc.language->id == lvc->language->id
2345 && stt->lvc.language->sub == lvc->language->sub)
2347 /* Found a table with the same language */
2348 /* The version and characteristics are now handled
2349 * in the generation of the individual stringtables.
2350 * This enables localized analysis.
2351 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2352 || (!stt->lvc.version && lvc->version)
2353 || (stt->lvc.version && !lvc->version))
2354 parser_warning("Stringtable's versions are not the same, using first definition\n");
2356 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2357 || (!stt->lvc.characts && lvc->characts)
2358 || (stt->lvc.characts && !lvc->characts))
2359 parser_warning("Stringtable's characteristics are not the same, using first definition\n");
2361 return stt;
2364 return NULL;
2367 /* qsort sorting function for string table entries */
2368 #define STE(p) ((const stt_entry_t *)(p))
2369 static int sort_stt_entry(const void *e1, const void *e2)
2371 return STE(e1)->id - STE(e2)->id;
2373 #undef STE
2375 static resource_t *build_stt_resources(stringtable_t *stthead)
2377 stringtable_t *stt;
2378 stringtable_t *newstt;
2379 resource_t *rsc;
2380 resource_t *rsclist = NULL;
2381 resource_t *rsctail = NULL;
2382 int i;
2383 int j;
2384 unsigned int andsum;
2385 unsigned int orsum;
2386 characts_t *characts;
2387 version_t *version;
2389 if(!stthead)
2390 return NULL;
2392 /* For all languages defined */
2393 for(stt = stthead; stt; stt = stt->next)
2395 assert(stt->nentries > 0);
2397 /* Sort the entries */
2398 if(stt->nentries > 1)
2399 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2401 for(i = 0; i < stt->nentries; )
2403 newstt = new_stringtable(&stt->lvc);
2404 newstt->entries = xmalloc(16 * sizeof(stt_entry_t));
2405 memset( newstt->entries, 0, 16 * sizeof(stt_entry_t) );
2406 newstt->nentries = 16;
2407 newstt->idbase = stt->entries[i].id & ~0xf;
2408 for(j = 0; j < 16 && i < stt->nentries; j++)
2410 if(stt->entries[i].id - newstt->idbase == j)
2412 newstt->entries[j] = stt->entries[i];
2413 i++;
2416 andsum = ~0;
2417 orsum = 0;
2418 characts = NULL;
2419 version = NULL;
2420 /* Check individual memory options and get
2421 * the first characteristics/version
2423 for(j = 0; j < 16; j++)
2425 if(!newstt->entries[j].str)
2426 continue;
2427 andsum &= newstt->entries[j].memopt;
2428 orsum |= newstt->entries[j].memopt;
2429 if(!characts)
2430 characts = newstt->entries[j].characts;
2431 if(!version)
2432 version = newstt->entries[j].version;
2434 if(andsum != orsum)
2436 warning("Stringtable's memory options are not equal (idbase: %d)\n", newstt->idbase);
2438 /* Check version and characteristics */
2439 for(j = 0; j < 16; j++)
2441 if(characts
2442 && newstt->entries[j].characts
2443 && *newstt->entries[j].characts != *characts)
2444 warning("Stringtable's characteristics are not the same (idbase: %d)\n", newstt->idbase);
2445 if(version
2446 && newstt->entries[j].version
2447 && *newstt->entries[j].version != *version)
2448 warning("Stringtable's versions are not the same (idbase: %d)\n", newstt->idbase);
2450 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2451 rsc->name = new_name_id();
2452 rsc->name->type = name_ord;
2453 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2454 rsc->memopt = andsum; /* Set to least common denominator */
2455 newstt->memopt = andsum;
2456 newstt->lvc.characts = characts;
2457 newstt->lvc.version = version;
2458 if(!rsclist)
2460 rsclist = rsc;
2461 rsctail = rsc;
2463 else
2465 rsctail->next = rsc;
2466 rsc->prev = rsctail;
2467 rsctail = rsc;
2471 return rsclist;
2475 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2477 idrec->prev = prev;
2478 if(prev)
2479 prev->next = idrec;
2481 return idrec;
2484 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2486 if(!p)
2488 *nitems = 0;
2489 return NULL;
2492 *nitems = 1;
2494 while(p->prev)
2496 (*nitems)++;
2497 p = p->prev;
2500 return p;
2503 static string_t *make_filename(string_t *str)
2505 int i;
2507 if(str->type == str_char)
2509 char *dst = str->str.cstr;
2511 /* Remove escaped backslash and convert to forward */
2512 for (i = 0; i < str->size; i++)
2514 if (str->str.cstr[i] == '\\')
2516 if (i < str->size - 1 && str->str.cstr[i + 1] == '\\') i++;
2517 *dst++ = '/';
2519 else *dst++ = str->str.cstr[i];
2521 *dst = 0;
2522 str->size = dst - str->str.cstr;
2524 else
2526 WCHAR *dst = str->str.wstr;
2528 /* Remove escaped backslash and convert to forward */
2529 for (i = 0; i < str->size; i++)
2531 if (str->str.wstr[i] == '\\')
2533 if (i < str->size - 1 && str->str.wstr[i + 1] == '\\') i++;
2534 *dst++ = '/';
2536 else *dst++ = str->str.wstr[i];
2538 *dst = 0;
2539 str->size = dst - str->str.wstr;
2541 return str;
2545 * Process all resources to extract fonts and build
2546 * a fontdir resource.
2548 * Note: MS' resource compiler (build 1472) does not
2549 * handle font resources with different languages.
2550 * The fontdir is generated in the last active language
2551 * and font identifiers must be unique across the entire
2552 * source.
2553 * This is not logical considering the localization
2554 * constraints of all other resource types. MS has,
2555 * most probably, never testet localized fonts. However,
2556 * using fontresources is rare, so it might not occur
2557 * in normal applications.
2558 * Wine does require better localization because a lot
2559 * of languages are coded into the same executable.
2560 * Therefore, I will generate fontdirs for *each*
2561 * localized set of fonts.
2563 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2565 static int once = 0;
2566 if(!once)
2568 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)\n", fnt, nfnt);
2569 once++;
2571 return NULL;
2574 static resource_t *build_fontdirs(resource_t *tail)
2576 resource_t *rsc;
2577 resource_t *lst = NULL;
2578 resource_t **fnt = NULL; /* List of all fonts */
2579 int nfnt = 0;
2580 resource_t **fnd = NULL; /* List of all fontdirs */
2581 int nfnd = 0;
2582 resource_t **lanfnt = NULL;
2583 int nlanfnt = 0;
2584 int i;
2585 name_id_t nid;
2586 string_t str;
2587 int fntleft;
2589 nid.type = name_str;
2590 nid.name.s_name = &str;
2591 str.type = str_char;
2592 str.str.cstr = xstrdup("FONTDIR");
2593 str.size = 7;
2595 /* Extract all fonts and fontdirs */
2596 for(rsc = tail; rsc; rsc = rsc->prev)
2598 if(rsc->type == res_fnt)
2600 nfnt++;
2601 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2602 fnt[nfnt-1] = rsc;
2604 else if(rsc->type == res_fntdir)
2606 nfnd++;
2607 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2608 fnd[nfnd-1] = rsc;
2612 /* Verify the name of the present fontdirs */
2613 for(i = 0; i < nfnd; i++)
2615 if(compare_name_id(&nid, fnd[i]->name))
2617 warning("User supplied FONTDIR entry has an invalid name '%s', ignored\n",
2618 get_nameid_str(fnd[i]->name));
2619 fnd[i] = NULL;
2623 /* Sanity check */
2624 if(nfnt == 0)
2626 if(nfnd != 0)
2627 warning("Found %d FONTDIR entries without any fonts present\n", nfnd);
2628 goto clean;
2631 /* Copy space */
2632 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2633 memset( lanfnt, 0, nfnt * sizeof(*lanfnt));
2635 /* Get all fonts covered by fontdirs */
2636 for(i = 0; i < nfnd; i++)
2638 int j;
2640 if(!fnd[i])
2641 continue;
2642 for(j = 0; j < nfnt; j++)
2644 if(!fnt[j])
2645 continue;
2646 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2648 lanfnt[nlanfnt] = fnt[j];
2649 nlanfnt++;
2650 fnt[j] = NULL;
2655 /* We now have fonts left where we need to make a fontdir resource */
2656 for(i = fntleft = 0; i < nfnt; i++)
2658 if(fnt[i])
2659 fntleft++;
2661 while(fntleft)
2663 /* Get fonts of same language in lanfnt[] */
2664 for(i = nlanfnt = 0; i < nfnt; i++)
2666 if(fnt[i])
2668 if(!nlanfnt)
2670 addlanfnt:
2671 lanfnt[nlanfnt] = fnt[i];
2672 nlanfnt++;
2673 fnt[i] = NULL;
2674 fntleft--;
2676 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2677 goto addlanfnt;
2680 /* and build a fontdir */
2681 rsc = build_fontdir(lanfnt, nlanfnt);
2682 if(rsc)
2684 if(lst)
2686 lst->next = rsc;
2687 rsc->prev = lst;
2689 lst = rsc;
2693 free(lanfnt);
2694 clean:
2695 free(fnt);
2696 free(fnd);
2697 free(str.str.cstr);
2698 return lst;
2702 * This gets invoked to determine whether the next resource
2703 * is to be of a standard-type (e.g. bitmaps etc.), or should
2704 * be a user-type resource. This function is required because
2705 * there is the _possibility_ of a lookahead token in the
2706 * parser, which is generated from the "expr" state in the
2707 * "nameid" parsing.
2709 * The general resource format is:
2710 * <identifier> <type> <flags> <resourcebody>
2712 * The <identifier> can either be tIDENT or "expr". The latter
2713 * will always generate a lookahead, which is the <type> of the
2714 * resource to parse. Otherwise, we need to get a new token from
2715 * the scanner to determine the next step.
2717 * The problem arrises when <type> is numerical. This case should
2718 * map onto default resource-types and be parsed as such instead
2719 * of being mapped onto user-type resources.
2721 * The trick lies in the fact that yacc (bison) doesn't care about
2722 * intermediate changes of the lookahead while reducing a rule. We
2723 * simply replace the lookahead with a token that will result in
2724 * a shift to the appropriate rule for the specific resource-type.
2726 static int rsrcid_to_token(int lookahead)
2728 int token;
2730 /* Get a token if we don't have one yet */
2731 if(lookahead == YYEMPTY)
2732 lookahead = yylex();
2734 /* Only numbers are possibly interesting */
2735 switch(lookahead)
2737 case tNUMBER:
2738 case tLNUMBER:
2739 break;
2740 default:
2741 return lookahead;
2744 token = lookahead;
2746 switch(yylval.num)
2748 case WRC_RT_CURSOR:
2749 token = tCURSOR;
2750 break;
2751 case WRC_RT_ICON:
2752 token = tICON;
2753 break;
2754 case WRC_RT_BITMAP:
2755 token = tBITMAP;
2756 break;
2757 case WRC_RT_FONT:
2758 token = tFONT;
2759 break;
2760 case WRC_RT_FONTDIR:
2761 token = tFONTDIR;
2762 break;
2763 case WRC_RT_RCDATA:
2764 token = tRCDATA;
2765 break;
2766 case WRC_RT_MESSAGETABLE:
2767 token = tMESSAGETABLE;
2768 break;
2769 case WRC_RT_DLGINIT:
2770 token = tDLGINIT;
2771 break;
2772 case WRC_RT_ACCELERATOR:
2773 token = tACCELERATORS;
2774 break;
2775 case WRC_RT_MENU:
2776 token = tMENU;
2777 break;
2778 case WRC_RT_DIALOG:
2779 token = tDIALOG;
2780 break;
2781 case WRC_RT_VERSION:
2782 token = tVERSIONINFO;
2783 break;
2784 case WRC_RT_TOOLBAR:
2785 token = tTOOLBAR;
2786 break;
2787 case WRC_RT_HTML:
2788 token = tHTML;
2789 break;
2791 case WRC_RT_STRING:
2792 break;
2794 case WRC_RT_ANICURSOR:
2795 case WRC_RT_ANIICON:
2796 case WRC_RT_GROUP_CURSOR:
2797 case WRC_RT_GROUP_ICON:
2798 parser_warning("Usertype uses reserved type ID %d, which is auto-generated\n", yylval.num);
2799 return lookahead;
2801 case WRC_RT_DLGINCLUDE:
2802 case WRC_RT_PLUGPLAY:
2803 case WRC_RT_VXD:
2804 parser_warning("Usertype uses reserved type ID %d, which is not supported by wrc yet\n", yylval.num);
2805 default:
2806 return lookahead;
2809 return token;