ntdll: Simplify detach sequence now that there is no possible race on process exit.
[wine.git] / tools / wrc / parser.y
blobad5fb9872de6d1eea5d0fca7a68720ee5764fc7b
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
123 #include "config.h"
124 #include "wine/port.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 "wrc.h"
134 #include "utils.h"
135 #include "newstruc.h"
136 #include "dumpres.h"
137 #include "wine/wpp.h"
138 #include "wine/unicode.h"
139 #include "parser.h"
140 #include "windef.h"
141 #include "winbase.h"
142 #include "wingdi.h"
143 #include "winuser.h"
145 #if defined(YYBYACC)
146 /* Berkeley yacc (byacc) doesn't seem to know about these */
147 /* Some *BSD supplied versions do define these though */
148 # ifndef YYEMPTY
149 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
150 # endif
151 # ifndef YYLEX
152 # define YYLEX yylex()
153 # endif
155 #elif defined(YYBISON)
156 /* Bison was used for original development */
157 /* #define YYEMPTY -2 */
158 /* #define YYLEX yylex() */
160 #else
161 /* No yacc we know yet */
162 # if !defined(YYEMPTY) || !defined(YYLEX)
163 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
164 # elif defined(__GNUC__) /* gcc defines the #warning directive */
165 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
166 /* #else we just take a chance that it works... */
167 # endif
168 #endif
170 int want_nl = 0; /* Signal flex that we need the next newline */
171 int want_id = 0; /* Signal flex that we need the next identifier */
172 static stringtable_t *tagstt; /* Stringtable tag.
173 * It is set while parsing a stringtable to one of
174 * the stringtables in the sttres list or a new one
175 * if the language was not parsed before.
177 static stringtable_t *sttres; /* Stringtable resources. This holds the list of
178 * stringtables with different lanuages
180 static int dont_want_id = 0; /* See language parsing for details */
182 /* Set to the current options of the currently scanning stringtable */
183 static int *tagstt_memopt;
184 static characts_t *tagstt_characts;
185 static version_t *tagstt_version;
187 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
189 /* Prototypes of here defined functions */
190 static event_t *get_event_head(event_t *p);
191 static control_t *get_control_head(control_t *p);
192 static ver_value_t *get_ver_value_head(ver_value_t *p);
193 static ver_block_t *get_ver_block_head(ver_block_t *p);
194 static resource_t *get_resource_head(resource_t *p);
195 static menu_item_t *get_item_head(menu_item_t *p);
196 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
197 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
198 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
199 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
200 static raw_data_t *str2raw_data(string_t *str);
201 static raw_data_t *int2raw_data(int i);
202 static raw_data_t *long2raw_data(int i);
203 static raw_data_t *load_file(string_t *name, language_t *lang);
204 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
205 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
206 static event_t *add_event(int key, int id, int flags, event_t *prev);
207 static name_id_t *convert_ctlclass(name_id_t *cls);
208 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
209 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
210 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
211 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
212 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
213 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
214 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
215 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
216 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
217 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
218 static resource_t *build_stt_resources(stringtable_t *stthead);
219 static stringtable_t *find_stringtable(lvc_t *lvc);
220 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
221 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
222 static string_t *make_filename(string_t *s);
223 static resource_t *build_fontdirs(resource_t *tail);
224 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
225 static int rsrcid_to_token(int lookahead);
228 %union{
229 string_t *str;
230 int num;
231 int *iptr;
232 char *cptr;
233 resource_t *res;
234 accelerator_t *acc;
235 bitmap_t *bmp;
236 dialog_t *dlg;
237 font_t *fnt;
238 fontdir_t *fnd;
239 menu_t *men;
240 html_t *html;
241 rcdata_t *rdt;
242 stringtable_t *stt;
243 stt_entry_t *stte;
244 user_t *usr;
245 messagetable_t *msg;
246 versioninfo_t *veri;
247 control_t *ctl;
248 name_id_t *nid;
249 font_id_t *fntid;
250 language_t *lan;
251 version_t *ver;
252 characts_t *chars;
253 event_t *event;
254 menu_item_t *menitm;
255 itemex_opt_t *exopt;
256 raw_data_t *raw;
257 lvc_t *lvc;
258 ver_value_t *val;
259 ver_block_t *blk;
260 ver_words_t *verw;
261 toolbar_t *tlbar;
262 toolbar_item_t *tlbarItems;
263 dlginit_t *dginit;
264 style_pair_t *styles;
265 style_t *style;
266 ani_any_t *ani;
269 %token tNL
270 %token <num> tNUMBER tLNUMBER
271 %token <str> tSTRING tIDENT
272 %token <raw> tRAWDATA
273 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
274 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
275 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
276 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
277 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
278 %token tCONTROL tEDITTEXT
279 %token tRTEXT tCTEXT tLTEXT
280 %token tBLOCK tVALUE
281 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
282 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
283 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
284 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
285 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
286 %token tHELP
287 %token tTOOLBAR tBUTTON
288 %token tBEGIN tEND
289 %token tDLGINIT
290 %left '|'
291 %left '^'
292 %left '&'
293 %left '+' '-'
294 %left '*' '/'
295 %right '~' tNOT
296 %left pUPM
298 %type <res> resource_file resource resources resource_definition
299 %type <stt> stringtable strings
300 %type <fnt> font
301 %type <fnd> fontdir
302 %type <acc> accelerators
303 %type <event> events
304 %type <bmp> bitmap
305 %type <ani> cursor icon
306 %type <dlg> dialog dlg_attributes dialogex dlgex_attribs
307 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
308 %type <iptr> helpid
309 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
310 %type <html> html
311 %type <rdt> rcdata
312 %type <raw> raw_data raw_elements opt_data file_raw
313 %type <veri> versioninfo fix_version
314 %type <verw> ver_words
315 %type <blk> ver_blocks ver_block
316 %type <val> ver_values ver_value
317 %type <men> menu menuex
318 %type <menitm> item_definitions menu_body itemex_definitions menuex_body
319 %type <exopt> itemex_p_options itemex_options
320 %type <msg> messagetable
321 %type <usr> userres
322 %type <num> item_options
323 %type <nid> nameid nameid_s ctlclass usertype
324 %type <num> acc_opt acc accs
325 %type <iptr> loadmemopts lamo lama
326 %type <fntid> opt_font opt_exfont opt_expr
327 %type <lvc> opt_lvc
328 %type <lan> opt_language
329 %type <chars> opt_characts
330 %type <ver> opt_version
331 %type <num> expr xpr
332 %type <iptr> e_expr
333 %type <tlbar> toolbar
334 %type <tlbarItems> toolbar_items
335 %type <dginit> dlginit
336 %type <styles> optional_style_pair
337 %type <num> any_num
338 %type <style> style
339 %type <str> filename
343 resource_file
344 : resources {
345 resource_t *rsc, *head;
346 /* First add stringtables to the resource-list */
347 rsc = build_stt_resources(sttres);
348 /* 'build_stt_resources' returns a head and $1 is a tail */
349 if($1)
351 $1->next = rsc;
352 if(rsc)
353 rsc->prev = $1;
355 else
356 $1 = rsc;
357 /* Find the tail again */
358 while($1 && $1->next)
359 $1 = $1->next;
360 /* Now add any fontdirecory */
361 rsc = build_fontdirs($1);
362 /* 'build_fontdir' returns a head and $1 is a tail */
363 if($1)
365 $1->next = rsc;
366 if(rsc)
367 rsc->prev = $1;
369 else
370 $1 = rsc;
372 /* Final statements before we're done */
373 if ((head = get_resource_head($1)) != NULL)
375 if (resource_top) /* append to existing resources */
377 resource_t *tail = resource_top;
378 while (tail->next) tail = tail->next;
379 tail->next = head;
380 head->prev = tail;
382 else resource_top = head;
384 sttres = NULL;
388 /* Resources are put into a linked list */
389 resources
390 : /* Empty */ { $$ = NULL; want_id = 1; }
391 | resources resource {
392 if($2)
394 resource_t *tail = $2;
395 resource_t *head = $2;
396 while(tail->next)
397 tail = tail->next;
398 while(head->prev)
399 head = head->prev;
400 head->prev = $1;
401 if($1)
402 $1->next = head;
403 $$ = tail;
404 /* Check for duplicate identifiers */
405 while($1 && head)
407 resource_t *rsc = $1;
408 while(rsc)
410 if(rsc->type == head->type
411 && rsc->lan->id == head->lan->id
412 && rsc->lan->sub == head->lan->sub
413 && !compare_name_id(rsc->name, head->name)
414 && (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
416 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
418 rsc = rsc->prev;
420 head = head->next;
423 else if($1)
425 resource_t *tail = $1;
426 while(tail->next)
427 tail = tail->next;
428 $$ = tail;
430 else
431 $$ = NULL;
433 if(!dont_want_id) /* See comments in language parsing below */
434 want_id = 1;
435 dont_want_id = 0;
438 * The following newline rule will never get reduced because we never
439 * get the tNL token, unless we explicitly set the 'want_nl'
440 * flag, which we don't.
441 * The *ONLY* reason for this to be here is because Berkeley
442 * yacc (byacc), at least version 1.9, has a bug.
443 * (identified in the generated parser on the second
444 * line with:
445 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
447 * This extra rule fixes it.
448 * The problem is that the expression handling rule "expr: xpr"
449 * is not reduced on non-terminal tokens, defined above in the
450 * %token declarations. Token tNL is the only non-terminal that
451 * can occur. The error becomes visible in the language parsing
452 * rule below, which looks at the look-ahead token and tests it
453 * for tNL. However, byacc already generates an error upon reading
454 * the token instead of keeping it as a lookahead. The reason
455 * lies in the lack of a $default transition in the "expr : xpr . "
456 * state (currently state 25). It is probably omitted because tNL
457 * is a non-terminal and the state contains 2 s/r conflicts. The
458 * state enumerates all possible transitions instead of using a
459 * $default transition.
460 * All in all, it is a bug in byacc. (period)
462 | resources tNL
466 /* Parse top level resource definitions etc. */
467 resource
468 : expr usrcvt resource_definition {
469 $$ = $3;
470 if($$)
472 if($1 > 65535 || $1 < -32768)
473 yyerror("Resource's ID out of range (%d)", $1);
474 $$->name = new_name_id();
475 $$->name->type = name_ord;
476 $$->name->name.i_name = $1;
477 chat("Got %s (%d)\n", get_typename($3), $$->name->name.i_name);
480 | tIDENT usrcvt resource_definition {
481 $$ = $3;
482 if($$)
484 $$->name = new_name_id();
485 $$->name->type = name_str;
486 $$->name->name.s_name = $1;
487 chat("Got %s (%s)\n", get_typename($3), $$->name->name.s_name->str.cstr);
490 | stringtable {
491 /* Don't do anything, stringtables are converted to
492 * resource_t structures when we are finished parsing and
493 * the final rule of the parser is reduced (see above)
495 $$ = NULL;
496 chat("Got STRINGTABLE\n");
498 | tLANGUAGE {want_nl = 1; } expr ',' expr {
499 /* We *NEED* the newline to delimit the expression.
500 * Otherwise, we would not be able to set the next
501 * want_id anymore because of the token-lookahead.
503 * However, we can test the lookahead-token for
504 * being "non-expression" type, in which case we
505 * continue. Fortunately, tNL is the only token that
506 * will break expression parsing and is implicitly
507 * void, so we just remove it. This scheme makes it
508 * possible to do some (not all) fancy preprocessor
509 * stuff.
510 * BTW, we also need to make sure that the next
511 * reduction of 'resources' above will *not* set
512 * want_id because we already have a lookahead that
513 * cannot be undone.
515 if(yychar != YYEMPTY && yychar != tNL)
516 dont_want_id = 1;
518 if(yychar == tNL)
519 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
520 /* direct access to yychar in rule 'usrcvt' below. */
521 else if(yychar == tIDENT)
522 parser_warning("LANGUAGE statement not delimited with newline; next identifier might be wrong\n");
524 want_nl = 0; /* We don't want it anymore if we didn't get it */
526 if(!win32)
527 parser_warning("LANGUAGE not supported in 16-bit mode\n");
528 free(currentlanguage);
529 if (get_language_codepage($3, $5) == -1)
530 yyerror( "Language %04x is not supported", ($5<<10) + $3);
531 currentlanguage = new_language($3, $5);
532 $$ = NULL;
533 chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, ($5<<10) + $3);
538 * Remapping of numerical resource types
539 * (see also comment of called function below)
541 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
545 * Get a valid name/id
547 nameid : expr {
548 if($1 > 65535 || $1 < -32768)
549 yyerror("Resource's ID out of range (%d)", $1);
550 $$ = new_name_id();
551 $$->type = name_ord;
552 $$->name.i_name = $1;
554 | tIDENT {
555 $$ = new_name_id();
556 $$->type = name_str;
557 $$->name.s_name = $1;
562 * Extra string recognition for CLASS statement in dialogs
564 nameid_s: nameid { $$ = $1; }
565 | tSTRING {
566 $$ = new_name_id();
567 $$->type = name_str;
568 $$->name.s_name = $1;
572 /* get the value for a single resource*/
573 resource_definition
574 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
575 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
576 | cursor {
577 resource_t *rsc;
578 if($1->type == res_anicur)
580 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
582 else if($1->type == res_curg)
584 cursor_t *cur;
585 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
586 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
588 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
589 rsc->prev->next = rsc;
590 rsc = rsc->prev;
591 rsc->name = new_name_id();
592 rsc->name->type = name_ord;
593 rsc->name->name.i_name = cur->id;
596 else
597 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource\n", $1->type);
598 free($1);
600 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
601 | dialogex {
602 if(win32)
603 $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language);
604 else
605 $$ = NULL;
607 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
608 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
609 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
610 | icon {
611 resource_t *rsc;
612 if($1->type == res_aniico)
614 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
616 else if($1->type == res_icog)
618 icon_t *ico;
619 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
620 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
622 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
623 rsc->prev->next = rsc;
624 rsc = rsc->prev;
625 rsc->name = new_name_id();
626 rsc->name->type = name_ord;
627 rsc->name->name.i_name = ico->id;
630 else
631 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource\n", $1->type);
632 free($1);
634 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
635 | menuex {
636 if(win32)
637 $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language);
638 else
639 $$ = NULL;
641 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
642 | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
643 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
644 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
645 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
646 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
650 filename: tIDENT { $$ = make_filename($1); }
651 | tSTRING { $$ = make_filename($1); }
654 /* ------------------------------ Bitmap ------------------------------ */
655 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
658 /* ------------------------------ Cursor ------------------------------ */
659 cursor : tCURSOR loadmemopts file_raw {
660 $$ = new_ani_any();
661 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
663 $$->type = res_anicur;
664 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
666 else
668 $$->type = res_curg;
669 $$->u.curg = new_cursor_group($3, $2);
674 /* ------------------------------ Icon ------------------------------ */
675 icon : tICON loadmemopts file_raw {
676 $$ = new_ani_any();
677 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
679 $$->type = res_aniico;
680 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
682 else
684 $$->type = res_icog;
685 $$->u.icog = new_icon_group($3, $2);
690 /* ------------------------------ Font ------------------------------ */
692 * The reading of raw_data for fonts is a Borland BRC
693 * extension. MS generates an error. However, it is
694 * most logical to support this, considering how wine
695 * enters things in CVS (ascii).
697 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
701 * The fontdir is a Borland BRC extension which only
702 * reads the data as 'raw_data' from the file.
703 * I don't know whether it is interpreted.
704 * The fontdir is generated if it was not present and
705 * fonts are defined in the source.
707 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
710 /* ------------------------------ MessageTable ------------------------------ */
711 /* It might be interesting to implement the MS Message compiler here as well
712 * to get everything in one source. Might be a future project.
714 messagetable
715 : tMESSAGETABLE loadmemopts file_raw {
716 if(!win32)
717 parser_warning("MESSAGETABLE not supported in 16-bit mode\n");
718 $$ = new_messagetable($3, $2);
722 /* ------------------------------ HTML ------------------------------ */
723 html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
726 /* ------------------------------ RCData ------------------------------ */
727 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
730 /* ------------------------------ DLGINIT ------------------------------ */
731 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
734 /* ------------------------------ UserType ------------------------------ */
735 userres : usertype loadmemopts file_raw {
736 #ifdef WORDS_BIGENDIAN
737 if(pedantic && byteorder != WRC_BO_LITTLE)
738 #else
739 if(pedantic && byteorder == WRC_BO_BIG)
740 #endif
741 parser_warning("Byteordering is not little-endian and type cannot be interpreted\n");
742 $$ = new_user($1, $3, $2);
746 usertype: tNUMBER {
747 $$ = new_name_id();
748 $$->type = name_ord;
749 $$->name.i_name = $1;
751 | tIDENT {
752 $$ = new_name_id();
753 $$->type = name_str;
754 $$->name.s_name = $1;
758 /* ------------------------------ Accelerator ------------------------------ */
759 accelerators
760 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
761 $$ = new_accelerator();
762 if($2)
764 $$->memopt = *($2);
765 free($2);
767 else
769 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
771 if(!$5)
772 yyerror("Accelerator table must have at least one entry");
773 $$->events = get_event_head($5);
774 if($3)
776 $$->lvc = *($3);
777 free($3);
779 if(!$$->lvc.language)
780 $$->lvc.language = dup_language(currentlanguage);
784 events : /* Empty */ { $$=NULL; }
785 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
786 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
790 * The empty rule generates a s/r conflict because of {bi,u}nary expr
791 * on - and +. It cannot be solved in any way because it is the same as
792 * the if/then/else problem (LALR(1) problem). The conflict is moved
793 * away by forcing it to be in the expression handling below.
795 acc_opt : /* Empty */ { $$ = 0; }
796 | ',' accs { $$ = $2; }
799 accs : acc { $$ = $1; }
800 | accs ',' acc { $$ = $1 | $3; }
803 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
804 | tSHIFT { $$ = WRC_AF_SHIFT; }
805 | tCONTROL { $$ = WRC_AF_CONTROL; }
806 | tALT { $$ = WRC_AF_ALT; }
807 | tASCII { $$ = WRC_AF_ASCII; }
808 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
811 /* ------------------------------ Dialog ------------------------------ */
812 /* FIXME: Support EXSTYLE in the dialog line itself */
813 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
814 tBEGIN ctrls tEND {
815 if($2)
817 $10->memopt = *($2);
818 free($2);
820 else
821 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
822 $10->x = $3;
823 $10->y = $5;
824 $10->width = $7;
825 $10->height = $9;
826 $10->controls = get_control_head($12);
827 $$ = $10;
828 if(!$$->gotstyle)
830 $$->style = new_style(0,0);
831 $$->style->or_mask = WS_POPUP;
832 $$->gotstyle = TRUE;
834 if($$->title)
835 $$->style->or_mask |= WS_CAPTION;
836 if($$->font)
837 $$->style->or_mask |= DS_SETFONT;
839 $$->style->or_mask &= ~($$->style->and_mask);
840 $$->style->and_mask = 0;
842 if(!$$->lvc.language)
843 $$->lvc.language = dup_language(currentlanguage);
847 dlg_attributes
848 : /* Empty */ { $$=new_dialog(); }
849 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
850 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
851 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
852 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
853 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
854 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
855 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
856 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
857 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
860 ctrls : /* Empty */ { $$ = NULL; }
861 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
862 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
863 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
864 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
865 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
866 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
867 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
868 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
869 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
870 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
871 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
872 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
873 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
874 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
875 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
876 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
877 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
878 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
879 /* special treatment for icons, as the extent is optional */
880 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
881 $10->title = $3;
882 $10->id = $5;
883 $10->x = $7;
884 $10->y = $9;
885 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
889 lab_ctrl
890 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
891 $$=new_control();
892 $$->title = $1;
893 $$->id = $3;
894 $$->x = $5;
895 $$->y = $7;
896 $$->width = $9;
897 $$->height = $11;
898 if($12)
900 $$->style = $12->style;
901 $$->gotstyle = TRUE;
902 if ($12->exstyle)
904 $$->exstyle = $12->exstyle;
905 $$->gotexstyle = TRUE;
907 free($12);
912 ctrl_desc
913 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
914 $$ = new_control();
915 $$->id = $1;
916 $$->x = $3;
917 $$->y = $5;
918 $$->width = $7;
919 $$->height = $9;
920 if($10)
922 $$->style = $10->style;
923 $$->gotstyle = TRUE;
924 if ($10->exstyle)
926 $$->exstyle = $10->exstyle;
927 $$->gotexstyle = TRUE;
929 free($10);
934 iconinfo: /* Empty */
935 { $$ = new_control(); }
937 | ',' expr ',' expr {
938 $$ = new_control();
939 $$->width = $2;
940 $$->height = $4;
942 | ',' expr ',' expr ',' style {
943 $$ = new_control();
944 $$->width = $2;
945 $$->height = $4;
946 $$->style = $6;
947 $$->gotstyle = TRUE;
949 | ',' expr ',' expr ',' style ',' style {
950 $$ = new_control();
951 $$->width = $2;
952 $$->height = $4;
953 $$->style = $6;
954 $$->gotstyle = TRUE;
955 $$->exstyle = $8;
956 $$->gotexstyle = TRUE;
960 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
961 $$=new_control();
962 $$->title = $1;
963 $$->id = $3;
964 $$->ctlclass = convert_ctlclass($5);
965 $$->style = $7;
966 $$->gotstyle = TRUE;
967 $$->x = $9;
968 $$->y = $11;
969 $$->width = $13;
970 $$->height = $15;
971 $$->exstyle = $17;
972 $$->gotexstyle = TRUE;
974 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
975 $$=new_control();
976 $$->title = $1;
977 $$->id = $3;
978 $$->ctlclass = convert_ctlclass($5);
979 $$->style = $7;
980 $$->gotstyle = TRUE;
981 $$->x = $9;
982 $$->y = $11;
983 $$->width = $13;
984 $$->height = $15;
988 opt_font
989 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
992 /* ------------------------------ style flags ------------------------------ */
993 optional_style_pair
994 : /* Empty */ { $$ = NULL; }
995 | ',' style { $$ = new_style_pair($2, 0); }
996 | ',' style ',' style { $$ = new_style_pair($2, $4); }
999 style
1000 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
1001 | '(' style ')' { $$ = $2; }
1002 | any_num { $$ = new_style($1, 0); }
1003 | tNOT any_num { $$ = new_style(0, $2); }
1006 ctlclass
1007 : expr {
1008 $$ = new_name_id();
1009 $$->type = name_ord;
1010 $$->name.i_name = $1;
1012 | tSTRING {
1013 $$ = new_name_id();
1014 $$->type = name_str;
1015 $$->name.s_name = $1;
1019 /* ------------------------------ DialogEx ------------------------------ */
1020 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
1021 tBEGIN exctrls tEND {
1022 if(!win32)
1023 parser_warning("DIALOGEX not supported in 16-bit mode\n");
1024 if($2)
1026 $11->memopt = *($2);
1027 free($2);
1029 else
1030 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1031 $11->x = $3;
1032 $11->y = $5;
1033 $11->width = $7;
1034 $11->height = $9;
1035 if($10)
1037 $11->helpid = *($10);
1038 $11->gothelpid = TRUE;
1039 free($10);
1041 $11->controls = get_control_head($13);
1042 $$ = $11;
1044 assert($$->style != NULL);
1045 if(!$$->gotstyle)
1047 $$->style->or_mask = WS_POPUP;
1048 $$->gotstyle = TRUE;
1050 if($$->title)
1051 $$->style->or_mask |= WS_CAPTION;
1052 if($$->font)
1053 $$->style->or_mask |= DS_SETFONT;
1055 $$->style->or_mask &= ~($$->style->and_mask);
1056 $$->style->and_mask = 0;
1058 if(!$$->lvc.language)
1059 $$->lvc.language = dup_language(currentlanguage);
1063 dlgex_attribs
1064 : /* Empty */ { $$=new_dialog(); $$->is_ex = TRUE; }
1065 | dlgex_attribs tSTYLE style { $$=dialog_style($3,$1); }
1066 | dlgex_attribs tEXSTYLE style { $$=dialog_exstyle($3,$1); }
1067 | dlgex_attribs tCAPTION tSTRING { $$=dialog_caption($3,$1); }
1068 | dlgex_attribs opt_font { $$=dialog_font($2,$1); }
1069 | dlgex_attribs opt_exfont { $$=dialog_font($2,$1); }
1070 | dlgex_attribs tCLASS nameid_s { $$=dialog_class($3,$1); }
1071 | dlgex_attribs tMENU nameid { $$=dialog_menu($3,$1); }
1072 | dlgex_attribs opt_language { $$=dialog_language($2,$1); }
1073 | dlgex_attribs opt_characts { $$=dialog_characteristics($2,$1); }
1074 | dlgex_attribs opt_version { $$=dialog_version($2,$1); }
1077 exctrls : /* Empty */ { $$ = NULL; }
1078 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1079 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1080 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1081 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1082 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1083 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1084 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1085 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1086 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1087 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1088 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1089 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1090 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1091 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1092 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1093 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1094 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1095 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1096 /* special treatment for icons, as the extent is optional */
1097 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1098 $10->title = $3;
1099 $10->id = $5;
1100 $10->x = $7;
1101 $10->y = $9;
1102 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1106 gen_exctrl
1107 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1108 expr ',' style helpid opt_data {
1109 $$=new_control();
1110 $$->title = $1;
1111 $$->id = $3;
1112 $$->ctlclass = convert_ctlclass($5);
1113 $$->style = $7;
1114 $$->gotstyle = TRUE;
1115 $$->x = $9;
1116 $$->y = $11;
1117 $$->width = $13;
1118 $$->height = $15;
1119 if($17)
1121 $$->exstyle = $17;
1122 $$->gotexstyle = TRUE;
1124 if($18)
1126 $$->helpid = *($18);
1127 $$->gothelpid = TRUE;
1128 free($18);
1130 $$->extra = $19;
1132 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1133 $$=new_control();
1134 $$->title = $1;
1135 $$->id = $3;
1136 $$->style = $7;
1137 $$->gotstyle = TRUE;
1138 $$->ctlclass = convert_ctlclass($5);
1139 $$->x = $9;
1140 $$->y = $11;
1141 $$->width = $13;
1142 $$->height = $15;
1143 $$->extra = $16;
1147 lab_exctrl
1148 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1149 $$=new_control();
1150 $$->title = $1;
1151 $$->id = $3;
1152 $$->x = $5;
1153 $$->y = $7;
1154 $$->width = $9;
1155 $$->height = $11;
1156 if($12)
1158 $$->style = $12->style;
1159 $$->gotstyle = TRUE;
1161 if ($12->exstyle)
1163 $$->exstyle = $12->exstyle;
1164 $$->gotexstyle = TRUE;
1166 free($12);
1169 $$->extra = $14;
1173 exctrl_desc
1174 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1175 $$ = new_control();
1176 $$->id = $1;
1177 $$->x = $3;
1178 $$->y = $5;
1179 $$->width = $7;
1180 $$->height = $9;
1181 if($10)
1183 $$->style = $10->style;
1184 $$->gotstyle = TRUE;
1186 if ($10->exstyle)
1188 $$->exstyle = $10->exstyle;
1189 $$->gotexstyle = TRUE;
1191 free($10);
1193 $$->extra = $12;
1197 opt_data: /* Empty */ { $$ = NULL; }
1198 | raw_data { $$ = $1; }
1201 helpid : /* Empty */ { $$ = NULL; }
1202 | ',' expr { $$ = new_int($2); }
1205 opt_exfont
1206 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1210 * FIXME: This odd expression is here to nullify an extra token found
1211 * in some appstudio produced resources which appear to do nothing.
1213 opt_expr: /* Empty */ { $$ = NULL; }
1214 | ',' expr { $$ = NULL; }
1217 /* ------------------------------ Menu ------------------------------ */
1218 menu : tMENU loadmemopts opt_lvc menu_body {
1219 if(!$4)
1220 yyerror("Menu must contain items");
1221 $$ = new_menu();
1222 if($2)
1224 $$->memopt = *($2);
1225 free($2);
1227 else
1228 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1229 $$->items = get_item_head($4);
1230 if($3)
1232 $$->lvc = *($3);
1233 free($3);
1235 if(!$$->lvc.language)
1236 $$->lvc.language = dup_language(currentlanguage);
1240 menu_body
1241 : tBEGIN item_definitions tEND { $$ = $2; }
1244 item_definitions
1245 : /* Empty */ {$$ = NULL;}
1246 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1247 $$=new_menu_item();
1248 $$->prev = $1;
1249 if($1)
1250 $1->next = $$;
1251 $$->id = $5;
1252 $$->state = $6;
1253 $$->name = $3;
1255 | item_definitions tMENUITEM tSEPARATOR {
1256 $$=new_menu_item();
1257 $$->prev = $1;
1258 if($1)
1259 $1->next = $$;
1261 | item_definitions tPOPUP tSTRING item_options menu_body {
1262 $$ = new_menu_item();
1263 $$->prev = $1;
1264 if($1)
1265 $1->next = $$;
1266 $$->popup = get_item_head($5);
1267 $$->name = $3;
1271 /* NOTE: item_options is right recursive because it would introduce
1272 * a shift/reduce conflict on ',' in itemex_options due to the
1273 * empty rule here. The parser is now forced to look beyond the ','
1274 * before reducing (force shift).
1275 * Right recursion here is not a problem because we cannot expect
1276 * more than 7 parserstack places to be occupied while parsing this
1277 * (who would want to specify a MF_x flag twice?).
1279 item_options
1280 : /* Empty */ { $$ = 0; }
1281 | ',' item_options { $$ = $2; }
1282 | tCHECKED item_options { $$ = $2 | MF_CHECKED; }
1283 | tGRAYED item_options { $$ = $2 | MF_GRAYED; }
1284 | tHELP item_options { $$ = $2 | MF_HELP; }
1285 | tINACTIVE item_options { $$ = $2 | MF_DISABLED; }
1286 | tMENUBARBREAK item_options { $$ = $2 | MF_MENUBARBREAK; }
1287 | tMENUBREAK item_options { $$ = $2 | MF_MENUBREAK; }
1290 /* ------------------------------ MenuEx ------------------------------ */
1291 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1292 if(!win32)
1293 parser_warning("MENUEX not supported in 16-bit mode\n");
1294 if(!$4)
1295 yyerror("MenuEx must contain items");
1296 $$ = new_menu();
1297 $$->is_ex = TRUE;
1298 if($2)
1300 $$->memopt = *($2);
1301 free($2);
1303 else
1304 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1305 $$->items = get_item_head($4);
1306 if($3)
1308 $$->lvc = *($3);
1309 free($3);
1311 if(!$$->lvc.language)
1312 $$->lvc.language = dup_language(currentlanguage);
1316 menuex_body
1317 : tBEGIN itemex_definitions tEND { $$ = $2; }
1320 itemex_definitions
1321 : /* Empty */ {$$ = NULL; }
1322 | itemex_definitions tMENUITEM tSTRING itemex_options {
1323 $$ = new_menu_item();
1324 $$->prev = $1;
1325 if($1)
1326 $1->next = $$;
1327 $$->name = $3;
1328 $$->id = $4->id;
1329 $$->type = $4->type;
1330 $$->state = $4->state;
1331 $$->helpid = $4->helpid;
1332 $$->gotid = $4->gotid;
1333 $$->gottype = $4->gottype;
1334 $$->gotstate = $4->gotstate;
1335 $$->gothelpid = $4->gothelpid;
1336 free($4);
1338 | itemex_definitions tMENUITEM tSEPARATOR {
1339 $$ = new_menu_item();
1340 $$->prev = $1;
1341 if($1)
1342 $1->next = $$;
1344 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1345 $$ = new_menu_item();
1346 $$->prev = $1;
1347 if($1)
1348 $1->next = $$;
1349 $$->popup = get_item_head($5);
1350 $$->name = $3;
1351 $$->id = $4->id;
1352 $$->type = $4->type;
1353 $$->state = $4->state;
1354 $$->helpid = $4->helpid;
1355 $$->gotid = $4->gotid;
1356 $$->gottype = $4->gottype;
1357 $$->gotstate = $4->gotstate;
1358 $$->gothelpid = $4->gothelpid;
1359 free($4);
1363 itemex_options
1364 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1365 | ',' expr {
1366 $$ = new_itemex_opt($2, 0, 0, 0);
1367 $$->gotid = TRUE;
1369 | ',' e_expr ',' e_expr item_options {
1370 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1371 $$->gotid = TRUE;
1372 $$->gottype = TRUE;
1373 $$->gotstate = TRUE;
1374 free($2);
1375 free($4);
1377 | ',' e_expr ',' e_expr ',' expr {
1378 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1379 $$->gotid = TRUE;
1380 $$->gottype = TRUE;
1381 $$->gotstate = TRUE;
1382 free($2);
1383 free($4);
1387 itemex_p_options
1388 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1389 | ',' expr {
1390 $$ = new_itemex_opt($2, 0, 0, 0);
1391 $$->gotid = TRUE;
1393 | ',' e_expr ',' expr {
1394 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1395 free($2);
1396 $$->gotid = TRUE;
1397 $$->gottype = TRUE;
1399 | ',' e_expr ',' e_expr ',' expr {
1400 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1401 free($2);
1402 free($4);
1403 $$->gotid = TRUE;
1404 $$->gottype = TRUE;
1405 $$->gotstate = TRUE;
1407 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1408 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1409 free($2);
1410 free($4);
1411 free($6);
1412 $$->gotid = TRUE;
1413 $$->gottype = TRUE;
1414 $$->gotstate = TRUE;
1415 $$->gothelpid = TRUE;
1419 /* ------------------------------ StringTable ------------------------------ */
1420 /* Stringtables are parsed differently than other resources because their
1421 * layout is substantially different from other resources.
1422 * The table is parsed through a _global_ variable 'tagstt' which holds the
1423 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1424 * list of stringtables of different languages.
1426 stringtable
1427 : stt_head tBEGIN strings tEND {
1428 if(!$3)
1430 yyerror("Stringtable must have at least one entry");
1432 else
1434 stringtable_t *stt;
1435 /* Check if we added to a language table or created
1436 * a new one.
1438 for(stt = sttres; stt; stt = stt->next)
1440 if(stt == tagstt)
1441 break;
1443 if(!stt)
1445 /* It is a new one */
1446 if(sttres)
1448 sttres->prev = tagstt;
1449 tagstt->next = sttres;
1450 sttres = tagstt;
1452 else
1453 sttres = tagstt;
1455 /* Else were done */
1457 free(tagstt_memopt);
1458 tagstt_memopt = NULL;
1460 $$ = tagstt;
1464 /* This is to get the language of the currently parsed stringtable */
1465 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1466 if((tagstt = find_stringtable($3)) == NULL)
1467 tagstt = new_stringtable($3);
1468 tagstt_memopt = $2;
1469 tagstt_version = $3->version;
1470 tagstt_characts = $3->characts;
1471 free($3);
1475 strings : /* Empty */ { $$ = NULL; }
1476 | strings expr opt_comma tSTRING {
1477 int i;
1478 assert(tagstt != NULL);
1479 if($2 > 65535 || $2 < -32768)
1480 yyerror("Stringtable entry's ID out of range (%d)", $2);
1481 /* Search for the ID */
1482 for(i = 0; i < tagstt->nentries; i++)
1484 if(tagstt->entries[i].id == $2)
1485 yyerror("Stringtable ID %d already in use", $2);
1487 /* If we get here, then we have a new unique entry */
1488 tagstt->nentries++;
1489 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1490 tagstt->entries[tagstt->nentries-1].id = $2;
1491 tagstt->entries[tagstt->nentries-1].str = $4;
1492 if(tagstt_memopt)
1493 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1494 else
1495 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1496 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1497 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1499 if(pedantic && !$4->size)
1500 parser_warning("Zero length strings make no sense\n");
1501 if(!win32 && $4->size > 254)
1502 yyerror("Stringtable entry more than 254 characters");
1503 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1504 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1505 $$ = tagstt;
1509 opt_comma /* There seem to be two ways to specify a stringtable... */
1510 : /* Empty */
1511 | ','
1514 /* ------------------------------ VersionInfo ------------------------------ */
1515 versioninfo
1516 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1517 $$ = $3;
1518 if($2)
1520 $$->memopt = *($2);
1521 free($2);
1523 else
1524 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1525 $$->blocks = get_ver_block_head($5);
1526 /* Set language; there is no version or characteristics */
1527 $$->lvc.language = dup_language(currentlanguage);
1531 fix_version
1532 : /* Empty */ { $$ = new_versioninfo(); }
1533 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1534 if($1->gotit.fv)
1535 yyerror("FILEVERSION already defined");
1536 $$ = $1;
1537 $$->filever_maj1 = $3;
1538 $$->filever_maj2 = $5;
1539 $$->filever_min1 = $7;
1540 $$->filever_min2 = $9;
1541 $$->gotit.fv = 1;
1543 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1544 if($1->gotit.pv)
1545 yyerror("PRODUCTVERSION already defined");
1546 $$ = $1;
1547 $$->prodver_maj1 = $3;
1548 $$->prodver_maj2 = $5;
1549 $$->prodver_min1 = $7;
1550 $$->prodver_min2 = $9;
1551 $$->gotit.pv = 1;
1553 | fix_version tFILEFLAGS expr {
1554 if($1->gotit.ff)
1555 yyerror("FILEFLAGS already defined");
1556 $$ = $1;
1557 $$->fileflags = $3;
1558 $$->gotit.ff = 1;
1560 | fix_version tFILEFLAGSMASK expr {
1561 if($1->gotit.ffm)
1562 yyerror("FILEFLAGSMASK already defined");
1563 $$ = $1;
1564 $$->fileflagsmask = $3;
1565 $$->gotit.ffm = 1;
1567 | fix_version tFILEOS expr {
1568 if($1->gotit.fo)
1569 yyerror("FILEOS already defined");
1570 $$ = $1;
1571 $$->fileos = $3;
1572 $$->gotit.fo = 1;
1574 | fix_version tFILETYPE expr {
1575 if($1->gotit.ft)
1576 yyerror("FILETYPE already defined");
1577 $$ = $1;
1578 $$->filetype = $3;
1579 $$->gotit.ft = 1;
1581 | fix_version tFILESUBTYPE expr {
1582 if($1->gotit.fst)
1583 yyerror("FILESUBTYPE already defined");
1584 $$ = $1;
1585 $$->filesubtype = $3;
1586 $$->gotit.fst = 1;
1590 ver_blocks
1591 : /* Empty */ { $$ = NULL; }
1592 | ver_blocks ver_block {
1593 $$ = $2;
1594 $$->prev = $1;
1595 if($1)
1596 $1->next = $$;
1600 ver_block
1601 : tBLOCK tSTRING tBEGIN ver_values tEND {
1602 $$ = new_ver_block();
1603 $$->name = $2;
1604 $$->values = get_ver_value_head($4);
1608 ver_values
1609 : /* Empty */ { $$ = NULL; }
1610 | ver_values ver_value {
1611 $$ = $2;
1612 $$->prev = $1;
1613 if($1)
1614 $1->next = $$;
1618 ver_value
1619 : ver_block {
1620 $$ = new_ver_value();
1621 $$->type = val_block;
1622 $$->value.block = $1;
1624 | tVALUE tSTRING ',' tSTRING {
1625 $$ = new_ver_value();
1626 $$->type = val_str;
1627 $$->key = $2;
1628 $$->value.str = $4;
1630 | tVALUE tSTRING ',' ver_words {
1631 $$ = new_ver_value();
1632 $$->type = val_words;
1633 $$->key = $2;
1634 $$->value.words = $4;
1638 ver_words
1639 : expr { $$ = new_ver_words($1); }
1640 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1643 /* ------------------------------ Toolbar ------------------------------ */
1644 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1645 int nitems;
1646 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1647 $$ = new_toolbar($3, $5, items, nitems);
1648 if($2)
1650 $$->memopt = *($2);
1651 free($2);
1653 else
1655 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1657 if($6)
1659 $$->lvc = *($6);
1660 free($6);
1662 if(!$$->lvc.language)
1664 $$->lvc.language = dup_language(currentlanguage);
1669 toolbar_items
1670 : /* Empty */ { $$ = NULL; }
1671 | toolbar_items tBUTTON expr {
1672 toolbar_item_t *idrec = new_toolbar_item();
1673 idrec->id = $3;
1674 $$ = ins_tlbr_button($1, idrec);
1676 | toolbar_items tSEPARATOR {
1677 toolbar_item_t *idrec = new_toolbar_item();
1678 idrec->id = 0;
1679 $$ = ins_tlbr_button($1, idrec);
1683 /* ------------------------------ Memory options ------------------------------ */
1684 loadmemopts
1685 : /* Empty */ { $$ = NULL; }
1686 | loadmemopts lamo {
1687 if($1)
1689 *($1) |= *($2);
1690 $$ = $1;
1691 free($2);
1693 else
1694 $$ = $2;
1696 | loadmemopts lama {
1697 if($1)
1699 *($1) &= *($2);
1700 $$ = $1;
1701 free($2);
1703 else
1705 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1706 $$ = $2;
1711 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD);
1712 if (win32 && pedantic) parser_warning("PRELOAD is ignored in 32-bit mode\n"); }
1713 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE);
1714 if (win32 && pedantic) parser_warning("MOVEABLE is ignored in 32-bit mode\n"); }
1715 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE);
1716 if (win32 && pedantic) parser_warning("DISCARDABLE is ignored in 32-bit mode\n"); }
1717 | tPURE { $$ = new_int(WRC_MO_PURE);
1718 if (win32 && pedantic) parser_warning("PURE is ignored in 32-bit mode\n"); }
1721 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD);
1722 if (win32 && pedantic) parser_warning("LOADONCALL is ignored in 32-bit mode\n"); }
1723 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE);
1724 if (win32 && pedantic) parser_warning("FIXED is ignored in 32-bit mode\n"); }
1725 | tIMPURE { $$ = new_int(~WRC_MO_PURE);
1726 if (win32 && pedantic) parser_warning("IMPURE is ignored in 32-bit mode\n"); }
1729 /* ------------------------------ Win32 options ------------------------------ */
1730 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1731 | opt_lvc opt_language {
1732 if(!win32)
1733 parser_warning("LANGUAGE not supported in 16-bit mode\n");
1734 if($1->language)
1735 yyerror("Language already defined");
1736 $$ = $1;
1737 $1->language = $2;
1739 | opt_lvc opt_characts {
1740 if(!win32)
1741 parser_warning("CHARACTERISTICS not supported in 16-bit mode\n");
1742 if($1->characts)
1743 yyerror("Characteristics already defined");
1744 $$ = $1;
1745 $1->characts = $2;
1747 | opt_lvc opt_version {
1748 if(!win32)
1749 parser_warning("VERSION not supported in 16-bit mode\n");
1750 if($1->version)
1751 yyerror("Version already defined");
1752 $$ = $1;
1753 $1->version = $2;
1758 * This here is another s/r conflict on {bi,u}nary + and -.
1759 * It is due to the look-ahead which must determine when the
1760 * rule opt_language ends. It could be solved with adding a
1761 * tNL at the end, but that seems unreasonable to do.
1762 * The conflict is now moved to the expression handling below.
1764 opt_language
1765 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
1766 if (get_language_codepage($2, $4) == -1)
1767 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1771 opt_characts
1772 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1775 opt_version
1776 : tVERSION expr { $$ = new_version($2); }
1779 /* ------------------------------ Raw data handling ------------------------------ */
1780 raw_data: opt_lvc tBEGIN raw_elements tEND {
1781 if($1)
1783 $3->lvc = *($1);
1784 free($1);
1787 if(!$3->lvc.language)
1788 $3->lvc.language = dup_language(currentlanguage);
1790 $$ = $3;
1794 raw_elements
1795 : tRAWDATA { $$ = $1; }
1796 | tNUMBER { $$ = int2raw_data($1); }
1797 | '-' tNUMBER { $$ = int2raw_data(-($2)); }
1798 | tLNUMBER { $$ = long2raw_data($1); }
1799 | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
1800 | tSTRING { $$ = str2raw_data($1); }
1801 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1802 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1803 | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
1804 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1805 | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
1806 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1809 /* File data or raw data */
1810 file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
1811 | raw_data { $$ = $1; }
1814 /* ------------------------------ Win32 expressions ------------------------------ */
1815 /* All win16 numbers are also handled here. This is inconsistent with MS'
1816 * resource compiler, but what the heck, its just handy to have.
1818 e_expr : /* Empty */ { $$ = 0; }
1819 | expr { $$ = new_int($1); }
1822 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1823 expr : xpr { $$ = ($1); }
1826 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1827 | xpr '-' xpr { $$ = ($1) - ($3); }
1828 | xpr '|' xpr { $$ = ($1) | ($3); }
1829 | xpr '&' xpr { $$ = ($1) & ($3); }
1830 | xpr '*' xpr { $$ = ($1) * ($3); }
1831 | xpr '/' xpr { $$ = ($1) / ($3); }
1832 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1833 | '~' xpr { $$ = ~($2); }
1834 | '-' xpr %prec pUPM { $$ = -($2); }
1835 | '+' xpr %prec pUPM { $$ = $2; }
1836 | '(' xpr ')' { $$ = $2; }
1837 | any_num { $$ = $1; }
1838 | tNOT any_num { $$ = ~($2); }
1841 any_num : tNUMBER { $$ = $1; }
1842 | tLNUMBER { $$ = $1; }
1846 /* Dialog specific functions */
1847 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1849 assert(dlg != NULL);
1850 if(dlg->style == NULL)
1852 dlg->style = new_style(0,0);
1855 if(dlg->gotstyle)
1857 parser_warning("Style already defined, or-ing together\n");
1859 else
1861 dlg->style->or_mask = 0;
1862 dlg->style->and_mask = 0;
1864 dlg->style->or_mask |= st->or_mask;
1865 dlg->style->and_mask |= st->and_mask;
1866 dlg->gotstyle = TRUE;
1867 free(st);
1868 return dlg;
1871 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1873 assert(dlg != NULL);
1874 if(dlg->exstyle == NULL)
1876 dlg->exstyle = new_style(0,0);
1879 if(dlg->gotexstyle)
1881 parser_warning("ExStyle already defined, or-ing together\n");
1883 else
1885 dlg->exstyle->or_mask = 0;
1886 dlg->exstyle->and_mask = 0;
1888 dlg->exstyle->or_mask |= st->or_mask;
1889 dlg->exstyle->and_mask |= st->and_mask;
1890 dlg->gotexstyle = TRUE;
1891 free(st);
1892 return dlg;
1895 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1897 assert(dlg != NULL);
1898 if(dlg->title)
1899 yyerror("Caption already defined");
1900 dlg->title = s;
1901 return dlg;
1904 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1906 assert(dlg != NULL);
1907 if(dlg->font)
1908 yyerror("Font already defined");
1909 dlg->font = f;
1910 return dlg;
1913 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1915 assert(dlg != NULL);
1916 if(dlg->dlgclass)
1917 yyerror("Class already defined");
1918 dlg->dlgclass = n;
1919 return dlg;
1922 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1924 assert(dlg != NULL);
1925 if(dlg->menu)
1926 yyerror("Menu already defined");
1927 dlg->menu = m;
1928 return dlg;
1931 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1933 assert(dlg != NULL);
1934 if(dlg->lvc.language)
1935 yyerror("Language already defined");
1936 dlg->lvc.language = l;
1937 return dlg;
1940 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1942 assert(dlg != NULL);
1943 if(dlg->lvc.characts)
1944 yyerror("Characteristics already defined");
1945 dlg->lvc.characts = c;
1946 return dlg;
1949 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1951 assert(dlg != NULL);
1952 if(dlg->lvc.version)
1953 yyerror("Version already defined");
1954 dlg->lvc.version = v;
1955 return dlg;
1958 /* Controls specific functions */
1959 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1961 /* Hm... this seems to be jammed in at all time... */
1962 int defaultstyle = WS_CHILD | WS_VISIBLE;
1964 assert(ctrl != NULL);
1965 ctrl->prev = prev;
1967 if(prev)
1968 prev->next = ctrl;
1970 /* Check for duplicate identifiers */
1971 while (prev)
1973 if (ctrl->id != -1 && ctrl->id == prev->id)
1974 parser_warning("Duplicate dialog control id %d\n", ctrl->id);
1975 prev = prev->prev;
1978 if(type != -1)
1980 ctrl->ctlclass = new_name_id();
1981 ctrl->ctlclass->type = name_ord;
1982 ctrl->ctlclass->name.i_name = type;
1985 switch(type)
1987 case CT_BUTTON:
1988 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1989 defaultstyle |= WS_TABSTOP;
1990 break;
1991 case CT_EDIT:
1992 defaultstyle |= WS_TABSTOP | WS_BORDER;
1993 break;
1994 case CT_LISTBOX:
1995 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1996 break;
1997 case CT_COMBOBOX:
1998 if (!(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
1999 defaultstyle |= CBS_SIMPLE;
2000 break;
2001 case CT_STATIC:
2002 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
2003 defaultstyle |= WS_GROUP;
2004 break;
2007 if(!ctrl->gotstyle) /* Handle default style setting */
2009 switch(type)
2011 case CT_EDIT:
2012 defaultstyle |= ES_LEFT;
2013 break;
2014 case CT_LISTBOX:
2015 defaultstyle |= LBS_NOTIFY;
2016 break;
2017 case CT_COMBOBOX:
2018 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
2019 break;
2020 case CT_SCROLLBAR:
2021 defaultstyle |= SBS_HORZ;
2022 break;
2023 case CT_BUTTON:
2024 switch(special_style)
2026 case BS_CHECKBOX:
2027 case BS_DEFPUSHBUTTON:
2028 case BS_PUSHBUTTON:
2029 /* case BS_PUSHBOX: */
2030 case BS_AUTORADIOBUTTON:
2031 case BS_AUTO3STATE:
2032 case BS_3STATE:
2033 case BS_AUTOCHECKBOX:
2034 defaultstyle |= WS_TABSTOP;
2035 break;
2036 default:
2037 parser_warning("Unknown default button control-style 0x%08x\n", special_style);
2038 case BS_GROUPBOX:
2039 case BS_RADIOBUTTON:
2040 break;
2042 break;
2044 case CT_STATIC:
2045 switch(special_style)
2047 case SS_LEFT:
2048 case SS_RIGHT:
2049 case SS_CENTER:
2050 defaultstyle |= WS_GROUP;
2051 break;
2052 case SS_ICON: /* Special case */
2053 break;
2054 default:
2055 parser_warning("Unknown default static control-style 0x%08x\n", special_style);
2056 break;
2058 break;
2059 case -1: /* Generic control */
2060 goto byebye;
2062 default:
2063 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2067 /* The SS_ICON flag is always forced in for icon controls */
2068 if(type == CT_STATIC && special_style == SS_ICON)
2069 defaultstyle |= SS_ICON;
2071 if (!ctrl->gotstyle)
2072 ctrl->style = new_style(0,0);
2074 /* combine all styles */
2075 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2076 ctrl->gotstyle = TRUE;
2077 byebye:
2078 /* combine with NOT mask */
2079 if (ctrl->gotstyle)
2081 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2082 ctrl->style->and_mask = 0;
2084 if (ctrl->gotexstyle)
2086 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2087 ctrl->exstyle->and_mask = 0;
2089 return ctrl;
2092 static int get_class_idW(const WCHAR *cc)
2094 static const WCHAR szBUTTON[] = {'B','U','T','T','O','N',0};
2095 static const WCHAR szCOMBOBOX[] = {'C','O','M','B','O','B','O','X',0};
2096 static const WCHAR szLISTBOX[] = {'L','I','S','T','B','O','X',0};
2097 static const WCHAR szEDIT[] = {'E','D','I','T',0};
2098 static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0};
2099 static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0};
2101 if(!strcmpiW(szBUTTON, cc))
2102 return CT_BUTTON;
2103 if(!strcmpiW(szCOMBOBOX, cc))
2104 return CT_COMBOBOX;
2105 if(!strcmpiW(szLISTBOX, cc))
2106 return CT_LISTBOX;
2107 if(!strcmpiW(szEDIT, cc))
2108 return CT_EDIT;
2109 if(!strcmpiW(szSTATIC, cc))
2110 return CT_STATIC;
2111 if(!strcmpiW(szSCROLLBAR, cc))
2112 return CT_SCROLLBAR;
2114 return -1;
2117 static int get_class_idA(const char *cc)
2119 if(!strcasecmp("BUTTON", cc))
2120 return CT_BUTTON;
2121 if(!strcasecmp("COMBOBOX", cc))
2122 return CT_COMBOBOX;
2123 if(!strcasecmp("LISTBOX", cc))
2124 return CT_LISTBOX;
2125 if(!strcasecmp("EDIT", cc))
2126 return CT_EDIT;
2127 if(!strcasecmp("STATIC", cc))
2128 return CT_STATIC;
2129 if(!strcasecmp("SCROLLBAR", cc))
2130 return CT_SCROLLBAR;
2132 return -1;
2136 static name_id_t *convert_ctlclass(name_id_t *cls)
2138 int iclass;
2140 if(cls->type == name_ord)
2141 return cls;
2142 assert(cls->type == name_str);
2143 if(cls->name.s_name->type == str_unicode)
2144 iclass = get_class_idW(cls->name.s_name->str.wstr);
2145 else
2146 iclass = get_class_idA(cls->name.s_name->str.cstr);
2148 if (iclass == -1)
2149 return cls; /* No default, return user controlclass */
2151 free(cls->name.s_name->str.cstr);
2152 free(cls->name.s_name);
2153 cls->type = name_ord;
2154 cls->name.i_name = iclass;
2155 return cls;
2158 /* Accelerator specific functions */
2159 static event_t *add_event(int key, int id, int flags, event_t *prev)
2161 event_t *ev = new_event();
2163 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2164 yyerror("Cannot use both ASCII and VIRTKEY");
2166 ev->key = key;
2167 ev->id = id;
2168 ev->flags = flags & ~WRC_AF_ASCII;
2169 ev->prev = prev;
2170 if(prev)
2171 prev->next = ev;
2172 return ev;
2175 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2177 event_t *ev = new_event();
2179 ev->str = key;
2180 ev->id = id;
2181 ev->flags = flags & ~WRC_AF_ASCII;
2182 ev->prev = prev;
2183 if(prev)
2184 prev->next = ev;
2185 return ev;
2188 /* MenuEx specific functions */
2189 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2191 itemex_opt_t *opt = xmalloc(sizeof(itemex_opt_t));
2192 memset( opt, 0, sizeof(*opt) );
2193 opt->id = id;
2194 opt->type = type;
2195 opt->state = state;
2196 opt->helpid = helpid;
2197 return opt;
2200 /* Raw data functions */
2201 static raw_data_t *load_file(string_t *filename, language_t *lang)
2203 FILE *fp = NULL;
2204 char *path;
2205 raw_data_t *rd;
2206 string_t *name;
2207 int codepage = get_language_codepage(lang->id, lang->sub);
2209 /* FIXME: we may want to use utf-8 here */
2210 if (codepage <= 0 && filename->type != str_char)
2211 yyerror("Cannot convert filename to ASCII string");
2212 name = convert_string( filename, str_char, codepage );
2213 if (!(path = wpp_find_include(name->str.cstr, input_name)))
2214 yyerror("Cannot open file %s", name->str.cstr);
2215 if (!(fp = fopen( path, "rb" )))
2216 yyerror("Cannot open file %s", name->str.cstr);
2217 free( path );
2218 rd = new_raw_data();
2219 fseek(fp, 0, SEEK_END);
2220 rd->size = ftell(fp);
2221 fseek(fp, 0, SEEK_SET);
2222 if (rd->size)
2224 rd->data = xmalloc(rd->size);
2225 fread(rd->data, rd->size, 1, fp);
2227 else rd->data = NULL;
2228 fclose(fp);
2229 rd->lvc.language = lang;
2230 free_string(name);
2231 return rd;
2234 static raw_data_t *int2raw_data(int i)
2236 raw_data_t *rd;
2238 if( ( i >= 0 && (int)((unsigned short)i) != i) ||
2239 ( i < 0 && (int)((short)i) != i) )
2240 parser_warning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2242 rd = new_raw_data();
2243 rd->size = sizeof(short);
2244 rd->data = xmalloc(rd->size);
2245 switch(byteorder)
2247 #ifdef WORDS_BIGENDIAN
2248 default:
2249 #endif
2250 case WRC_BO_BIG:
2251 rd->data[0] = HIBYTE(i);
2252 rd->data[1] = LOBYTE(i);
2253 break;
2255 #ifndef WORDS_BIGENDIAN
2256 default:
2257 #endif
2258 case WRC_BO_LITTLE:
2259 rd->data[1] = HIBYTE(i);
2260 rd->data[0] = LOBYTE(i);
2261 break;
2263 return rd;
2266 static raw_data_t *long2raw_data(int i)
2268 raw_data_t *rd;
2269 rd = new_raw_data();
2270 rd->size = sizeof(int);
2271 rd->data = xmalloc(rd->size);
2272 switch(byteorder)
2274 #ifdef WORDS_BIGENDIAN
2275 default:
2276 #endif
2277 case WRC_BO_BIG:
2278 rd->data[0] = HIBYTE(HIWORD(i));
2279 rd->data[1] = LOBYTE(HIWORD(i));
2280 rd->data[2] = HIBYTE(LOWORD(i));
2281 rd->data[3] = LOBYTE(LOWORD(i));
2282 break;
2284 #ifndef WORDS_BIGENDIAN
2285 default:
2286 #endif
2287 case WRC_BO_LITTLE:
2288 rd->data[3] = HIBYTE(HIWORD(i));
2289 rd->data[2] = LOBYTE(HIWORD(i));
2290 rd->data[1] = HIBYTE(LOWORD(i));
2291 rd->data[0] = LOBYTE(LOWORD(i));
2292 break;
2294 return rd;
2297 static raw_data_t *str2raw_data(string_t *str)
2299 raw_data_t *rd;
2300 rd = new_raw_data();
2301 rd->size = str->size * (str->type == str_char ? 1 : 2);
2302 rd->data = xmalloc(rd->size);
2303 if(str->type == str_char)
2304 memcpy(rd->data, str->str.cstr, rd->size);
2305 else if(str->type == str_unicode)
2307 int i;
2308 switch(byteorder)
2310 #ifdef WORDS_BIGENDIAN
2311 default:
2312 #endif
2313 case WRC_BO_BIG:
2314 for(i = 0; i < str->size; i++)
2316 rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
2317 rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
2319 break;
2320 #ifndef WORDS_BIGENDIAN
2321 default:
2322 #endif
2323 case WRC_BO_LITTLE:
2324 for(i = 0; i < str->size; i++)
2326 rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
2327 rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
2329 break;
2332 else
2333 internal_error(__FILE__, __LINE__, "Invalid stringtype\n");
2334 return rd;
2337 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2339 r1->data = xrealloc(r1->data, r1->size + r2->size);
2340 memcpy(r1->data + r1->size, r2->data, r2->size);
2341 r1->size += r2->size;
2342 return r1;
2345 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2347 raw_data_t *t = int2raw_data(i);
2348 merge_raw_data(r1, t);
2349 free(t->data);
2350 free(t);
2351 return r1;
2354 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2356 raw_data_t *t = long2raw_data(i);
2357 merge_raw_data(r1, t);
2358 free(t->data);
2359 free(t);
2360 return r1;
2363 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2365 raw_data_t *t = str2raw_data(str);
2366 merge_raw_data(r1, t);
2367 free(t->data);
2368 free(t);
2369 return r1;
2372 /* Function the go back in a list to get the head */
2373 static menu_item_t *get_item_head(menu_item_t *p)
2375 if(!p)
2376 return NULL;
2377 while(p->prev)
2378 p = p->prev;
2379 return p;
2382 static resource_t *get_resource_head(resource_t *p)
2384 if(!p)
2385 return NULL;
2386 while(p->prev)
2387 p = p->prev;
2388 return p;
2391 static ver_block_t *get_ver_block_head(ver_block_t *p)
2393 if(!p)
2394 return NULL;
2395 while(p->prev)
2396 p = p->prev;
2397 return p;
2400 static ver_value_t *get_ver_value_head(ver_value_t *p)
2402 if(!p)
2403 return NULL;
2404 while(p->prev)
2405 p = p->prev;
2406 return p;
2409 static control_t *get_control_head(control_t *p)
2411 if(!p)
2412 return NULL;
2413 while(p->prev)
2414 p = p->prev;
2415 return p;
2418 static event_t *get_event_head(event_t *p)
2420 if(!p)
2421 return NULL;
2422 while(p->prev)
2423 p = p->prev;
2424 return p;
2427 /* Find a stringtable with given language */
2428 static stringtable_t *find_stringtable(lvc_t *lvc)
2430 stringtable_t *stt;
2432 assert(lvc != NULL);
2434 if(!lvc->language)
2435 lvc->language = dup_language(currentlanguage);
2437 for(stt = sttres; stt; stt = stt->next)
2439 if(stt->lvc.language->id == lvc->language->id
2440 && stt->lvc.language->sub == lvc->language->sub)
2442 /* Found a table with the same language */
2443 /* The version and characteristics are now handled
2444 * in the generation of the individual stringtables.
2445 * This enables localized analysis.
2446 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2447 || (!stt->lvc.version && lvc->version)
2448 || (stt->lvc.version && !lvc->version))
2449 parser_warning("Stringtable's versions are not the same, using first definition\n");
2451 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2452 || (!stt->lvc.characts && lvc->characts)
2453 || (stt->lvc.characts && !lvc->characts))
2454 parser_warning("Stringtable's characteristics are not the same, using first definition\n");
2456 return stt;
2459 return NULL;
2462 /* qsort sorting function for string table entries */
2463 #define STE(p) ((const stt_entry_t *)(p))
2464 static int sort_stt_entry(const void *e1, const void *e2)
2466 return STE(e1)->id - STE(e2)->id;
2468 #undef STE
2470 static resource_t *build_stt_resources(stringtable_t *stthead)
2472 stringtable_t *stt;
2473 stringtable_t *newstt;
2474 resource_t *rsc;
2475 resource_t *rsclist = NULL;
2476 resource_t *rsctail = NULL;
2477 int i;
2478 int j;
2479 DWORD andsum;
2480 DWORD orsum;
2481 characts_t *characts;
2482 version_t *version;
2484 if(!stthead)
2485 return NULL;
2487 /* For all languages defined */
2488 for(stt = stthead; stt; stt = stt->next)
2490 assert(stt->nentries > 0);
2492 /* Sort the entries */
2493 if(stt->nentries > 1)
2494 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2496 for(i = 0; i < stt->nentries; )
2498 newstt = new_stringtable(&stt->lvc);
2499 newstt->entries = xmalloc(16 * sizeof(stt_entry_t));
2500 memset( newstt->entries, 0, 16 * sizeof(stt_entry_t) );
2501 newstt->nentries = 16;
2502 newstt->idbase = stt->entries[i].id & ~0xf;
2503 for(j = 0; j < 16 && i < stt->nentries; j++)
2505 if(stt->entries[i].id - newstt->idbase == j)
2507 newstt->entries[j] = stt->entries[i];
2508 i++;
2511 andsum = ~0;
2512 orsum = 0;
2513 characts = NULL;
2514 version = NULL;
2515 /* Check individual memory options and get
2516 * the first characteristics/version
2518 for(j = 0; j < 16; j++)
2520 if(!newstt->entries[j].str)
2521 continue;
2522 andsum &= newstt->entries[j].memopt;
2523 orsum |= newstt->entries[j].memopt;
2524 if(!characts)
2525 characts = newstt->entries[j].characts;
2526 if(!version)
2527 version = newstt->entries[j].version;
2529 if(andsum != orsum)
2531 warning("Stringtable's memory options are not equal (idbase: %d)\n", newstt->idbase);
2533 /* Check version and characteristics */
2534 for(j = 0; j < 16; j++)
2536 if(characts
2537 && newstt->entries[j].characts
2538 && *newstt->entries[j].characts != *characts)
2539 warning("Stringtable's characteristics are not the same (idbase: %d)\n", newstt->idbase);
2540 if(version
2541 && newstt->entries[j].version
2542 && *newstt->entries[j].version != *version)
2543 warning("Stringtable's versions are not the same (idbase: %d)\n", newstt->idbase);
2545 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2546 rsc->name = new_name_id();
2547 rsc->name->type = name_ord;
2548 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2549 rsc->memopt = andsum; /* Set to least common denominator */
2550 newstt->memopt = andsum;
2551 newstt->lvc.characts = characts;
2552 newstt->lvc.version = version;
2553 if(!rsclist)
2555 rsclist = rsc;
2556 rsctail = rsc;
2558 else
2560 rsctail->next = rsc;
2561 rsc->prev = rsctail;
2562 rsctail = rsc;
2566 return rsclist;
2570 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2572 idrec->prev = prev;
2573 if(prev)
2574 prev->next = idrec;
2576 return idrec;
2579 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2581 if(!p)
2583 *nitems = 0;
2584 return NULL;
2587 *nitems = 1;
2589 while(p->prev)
2591 (*nitems)++;
2592 p = p->prev;
2595 return p;
2598 static string_t *make_filename(string_t *str)
2600 if(str->type == str_char)
2602 char *cptr;
2604 /* Remove escaped backslash and convert to forward */
2605 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2607 if(cptr[1] == '\\')
2609 memmove(cptr, cptr+1, strlen(cptr));
2610 str->size--;
2612 *cptr = '/';
2615 else
2617 WCHAR *wptr;
2619 /* Remove escaped backslash and convert to forward */
2620 for(wptr = str->str.wstr; (wptr = strchrW(wptr, '\\')) != NULL; wptr++)
2622 if(wptr[1] == '\\')
2624 memmove(wptr, wptr+1, strlenW(wptr));
2625 str->size--;
2627 *wptr = '/';
2630 return str;
2634 * Process all resources to extract fonts and build
2635 * a fontdir resource.
2637 * Note: MS' resource compiler (build 1472) does not
2638 * handle font resources with different languages.
2639 * The fontdir is generated in the last active language
2640 * and font identifiers must be unique across the entire
2641 * source.
2642 * This is not logical considering the localization
2643 * constraints of all other resource types. MS has,
2644 * most probably, never testet localized fonts. However,
2645 * using fontresources is rare, so it might not occur
2646 * in normal applications.
2647 * Wine does require better localization because a lot
2648 * of languages are coded into the same executable.
2649 * Therefore, I will generate fontdirs for *each*
2650 * localized set of fonts.
2652 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2654 static int once = 0;
2655 if(!once)
2657 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)\n", fnt, nfnt);
2658 once++;
2660 return NULL;
2663 static resource_t *build_fontdirs(resource_t *tail)
2665 resource_t *rsc;
2666 resource_t *lst = NULL;
2667 resource_t **fnt = NULL; /* List of all fonts */
2668 int nfnt = 0;
2669 resource_t **fnd = NULL; /* List of all fontdirs */
2670 int nfnd = 0;
2671 resource_t **lanfnt = NULL;
2672 int nlanfnt = 0;
2673 int i;
2674 name_id_t nid;
2675 string_t str;
2676 int fntleft;
2678 nid.type = name_str;
2679 nid.name.s_name = &str;
2680 str.type = str_char;
2681 str.str.cstr = xstrdup("FONTDIR");
2682 str.size = 7;
2684 /* Extract all fonts and fontdirs */
2685 for(rsc = tail; rsc; rsc = rsc->prev)
2687 if(rsc->type == res_fnt)
2689 nfnt++;
2690 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2691 fnt[nfnt-1] = rsc;
2693 else if(rsc->type == res_fntdir)
2695 nfnd++;
2696 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2697 fnd[nfnd-1] = rsc;
2701 /* Verify the name of the present fontdirs */
2702 for(i = 0; i < nfnd; i++)
2704 if(compare_name_id(&nid, fnd[i]->name))
2706 warning("User supplied FONTDIR entry has an invalid name '%s', ignored\n",
2707 get_nameid_str(fnd[i]->name));
2708 fnd[i] = NULL;
2712 /* Sanity check */
2713 if(nfnt == 0)
2715 if(nfnd != 0)
2716 warning("Found %d FONTDIR entries without any fonts present\n", nfnd);
2717 goto clean;
2720 /* Copy space */
2721 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2722 memset( lanfnt, 0, nfnt * sizeof(*lanfnt));
2724 /* Get all fonts covered by fontdirs */
2725 for(i = 0; i < nfnd; i++)
2727 int j;
2728 WORD cnt;
2729 int isswapped = 0;
2731 if(!fnd[i])
2732 continue;
2733 for(j = 0; j < nfnt; j++)
2735 if(!fnt[j])
2736 continue;
2737 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2739 lanfnt[nlanfnt] = fnt[j];
2740 nlanfnt++;
2741 fnt[j] = NULL;
2745 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2746 if(nlanfnt == cnt)
2747 isswapped = 0;
2748 else if(nlanfnt == BYTESWAP_WORD(cnt))
2749 isswapped = 1;
2750 else
2751 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)\n",
2752 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2753 #ifdef WORDS_BIGENDIAN
2754 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2755 #else
2756 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2757 #endif
2759 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping\n");
2763 /* We now have fonts left where we need to make a fontdir resource */
2764 for(i = fntleft = 0; i < nfnt; i++)
2766 if(fnt[i])
2767 fntleft++;
2769 while(fntleft)
2771 /* Get fonts of same language in lanfnt[] */
2772 for(i = nlanfnt = 0; i < nfnt; i++)
2774 if(fnt[i])
2776 if(!nlanfnt)
2778 addlanfnt:
2779 lanfnt[nlanfnt] = fnt[i];
2780 nlanfnt++;
2781 fnt[i] = NULL;
2782 fntleft--;
2784 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2785 goto addlanfnt;
2788 /* and build a fontdir */
2789 rsc = build_fontdir(lanfnt, nlanfnt);
2790 if(rsc)
2792 if(lst)
2794 lst->next = rsc;
2795 rsc->prev = lst;
2797 lst = rsc;
2801 free(lanfnt);
2802 clean:
2803 free(fnt);
2804 free(fnd);
2805 free(str.str.cstr);
2806 return lst;
2810 * This gets invoked to determine whether the next resource
2811 * is to be of a standard-type (e.g. bitmaps etc.), or should
2812 * be a user-type resource. This function is required because
2813 * there is the _possibility_ of a lookahead token in the
2814 * parser, which is generated from the "expr" state in the
2815 * "nameid" parsing.
2817 * The general resource format is:
2818 * <identifier> <type> <flags> <resourcebody>
2820 * The <identifier> can either be tIDENT or "expr". The latter
2821 * will always generate a lookahead, which is the <type> of the
2822 * resource to parse. Otherwise, we need to get a new token from
2823 * the scanner to determine the next step.
2825 * The problem arrises when <type> is numerical. This case should
2826 * map onto default resource-types and be parsed as such instead
2827 * of being mapped onto user-type resources.
2829 * The trick lies in the fact that yacc (bison) doesn't care about
2830 * intermediate changes of the lookahead while reducing a rule. We
2831 * simply replace the lookahead with a token that will result in
2832 * a shift to the appropriate rule for the specific resource-type.
2834 static int rsrcid_to_token(int lookahead)
2836 int token;
2838 /* Get a token if we don't have one yet */
2839 if(lookahead == YYEMPTY)
2840 lookahead = YYLEX;
2842 /* Only numbers are possibly interesting */
2843 switch(lookahead)
2845 case tNUMBER:
2846 case tLNUMBER:
2847 break;
2848 default:
2849 return lookahead;
2852 token = lookahead;
2854 switch(yylval.num)
2856 case WRC_RT_CURSOR:
2857 token = tCURSOR;
2858 break;
2859 case WRC_RT_ICON:
2860 token = tICON;
2861 break;
2862 case WRC_RT_BITMAP:
2863 token = tBITMAP;
2864 break;
2865 case WRC_RT_FONT:
2866 token = tFONT;
2867 break;
2868 case WRC_RT_FONTDIR:
2869 token = tFONTDIR;
2870 break;
2871 case WRC_RT_RCDATA:
2872 token = tRCDATA;
2873 break;
2874 case WRC_RT_MESSAGETABLE:
2875 token = tMESSAGETABLE;
2876 break;
2877 case WRC_RT_DLGINIT:
2878 token = tDLGINIT;
2879 break;
2880 case WRC_RT_ACCELERATOR:
2881 token = tACCELERATORS;
2882 break;
2883 case WRC_RT_MENU:
2884 token = tMENU;
2885 break;
2886 case WRC_RT_DIALOG:
2887 token = tDIALOG;
2888 break;
2889 case WRC_RT_VERSION:
2890 token = tVERSIONINFO;
2891 break;
2892 case WRC_RT_TOOLBAR:
2893 token = tTOOLBAR;
2894 break;
2895 case WRC_RT_HTML:
2896 token = tHTML;
2897 break;
2899 case WRC_RT_STRING:
2900 break;
2902 case WRC_RT_ANICURSOR:
2903 case WRC_RT_ANIICON:
2904 case WRC_RT_GROUP_CURSOR:
2905 case WRC_RT_GROUP_ICON:
2906 parser_warning("Usertype uses reserved type ID %d, which is auto-generated\n", yylval.num);
2907 return lookahead;
2909 case WRC_RT_DLGINCLUDE:
2910 case WRC_RT_PLUGPLAY:
2911 case WRC_RT_VXD:
2912 parser_warning("Usertype uses reserved type ID %d, which is not supported by wrc yet\n", yylval.num);
2913 default:
2914 return lookahead;
2917 return token;