mshtml: Implement MarkupServices_ParseString.
[wine.git] / tools / wrc / parser.y
blob6b362b06b6b3741de5656883c5344a2209415789
1 %{
2 /*
3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * History:
22 * 24-Jul-2000 BS - Made a fix for broken Berkeley yacc on
23 * non-terminals (see cjunk rule).
24 * 21-May-2000 BS - Partial implementation of font resources.
25 * - Corrected language propagation for binary
26 * resources such as bitmaps, icons, cursors,
27 * userres and rcdata. The language is now
28 * correct in .res files.
29 * - Fixed reading the resource name as ident,
30 * so that it may overlap keywords.
31 * 20-May-2000 BS - Implemented animated cursors and icons
32 * resource types.
33 * 30-Apr-2000 BS - Reintegration into the wine-tree
34 * 14-Jan-2000 BS - Redid the usertype resources so that they
35 * are compatible.
36 * 02-Jan-2000 BS - Removed the preprocessor from the grammar
37 * except for the # command (line numbers).
39 * 06-Nov-1999 JS - see CHANGES
41 * 29-Dec-1998 AdH - Grammar and function extensions.
42 * grammar: TOOLBAR resources, Named ICONs in
43 * DIALOGS
44 * functions: semantic actions for the grammar
45 * changes, resource files can now be anywhere
46 * on the include path instead of just in the
47 * current directory
49 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
50 * printed out correctly.
52 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
53 * also accept a tSTRING as argument.
55 * 25-May-1998 BS - Found out that I need to support language, version
56 * and characteristics in inline resources (bitmap,
57 * cursor, etc) but they can also be specified with
58 * a filename. This renders my filename-scanning scheme
59 * worthless. Need to build newline parsing to solve
60 * this one.
61 * It will come with version 1.1.0 (sigh).
63 * 19-May-1998 BS - Started to build a builtin preprocessor
65 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
66 * ideas had some serious flaws.
68 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
69 * file.
71 * 21-Apr-1998 BS - Added correct behavior for cursors and icons.
72 * - This file is growing too big. It is time to strip
73 * things and put it in a support file.
75 * 19-Apr-1998 BS - Tagged the stringtable resource so that only one
76 * resource will be created. This because the table
77 * has a different layout than other resources. The
78 * table has to be sorted, and divided into smaller
79 * resource entries (see comment in source).
81 * 17-Apr-1998 BS - Almost all strings, including identifiers, are parsed
82 * as string_t which include unicode strings upon
83 * input.
84 * - Parser now emits a warning when compiling win32
85 * extensions in win16 mode.
87 * 16-Apr-1998 BS - Raw data elements are now *optionally* separated
88 * by commas. Read the comments in file sq2dq.l.
89 * - FIXME: there are instances in the source that rely
90 * on the fact that int==32bit and pointers are int size.
91 * - Fixed the conflict in menuex by changing a rule
92 * back into right recursion. See note in source.
93 * - UserType resources cannot have an expression as its
94 * typeclass. See note in source.
96 * 15-Apr-1998 BS - Changed all right recursion into left recursion to
97 * get reduction of the parsestack.
98 * This also helps communication between bison and flex.
99 * Main advantage is that the Empty rule gets reduced
100 * first, which is used to allocate/link things.
101 * It also added a shift/reduce conflict in the menuex
102 * handling, due to expression/option possibility,
103 * although not serious.
105 * 14-Apr-1998 BS - Redone almost the entire parser. We're not talking
106 * about making it more efficient, but readable (for me)
107 * and slightly easier to expand/change.
108 * This is done primarily by using more reduce states
109 * with many (intuitive) types for the various resource
110 * statements.
111 * - Added expression handling for all resources where a
112 * number is accepted (not only for win32). Also added
113 * multiply and division (not MS compatible, but handy).
114 * Unary minus introduced a shift/reduce conflict, but
115 * it is not serious.
117 * 13-Apr-1998 BS - Reordered a lot of things
118 * - Made the source more readable
119 * - Added Win32 resource definitions
120 * - Corrected syntax problems with an old yacc (;)
121 * - Added extra comment about grammar
124 #include "config.h"
126 #include <stdio.h>
127 #include <stdlib.h>
128 #include <stdarg.h>
129 #include <assert.h>
130 #include <ctype.h>
131 #include <string.h>
133 #include "../tools.h"
134 #include "wrc.h"
135 #include "utils.h"
136 #include "newstruc.h"
137 #include "wpp_private.h"
138 #include "parser.h"
139 #include "windef.h"
140 #include "winbase.h"
141 #include "wingdi.h"
142 #include "winuser.h"
144 int want_nl = 0; /* Signal flex that we need the next newline */
145 int want_id = 0; /* Signal flex that we need the next identifier */
146 static stringtable_t *tagstt; /* Stringtable tag.
147 * It is set while parsing a stringtable to one of
148 * the stringtables in the sttres list or a new one
149 * if the language was not parsed before.
151 static stringtable_t *sttres; /* Stringtable resources. This holds the list of
152 * stringtables with different lanuages
154 static int dont_want_id = 0; /* See language parsing for details */
156 /* Set to the current options of the currently scanning stringtable */
157 static int *tagstt_memopt;
158 static characts_t tagstt_characts;
159 static version_t tagstt_version;
161 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
163 /* Prototypes of here defined functions */
164 static event_t *get_event_head(event_t *p);
165 static control_t *get_control_head(control_t *p);
166 static ver_value_t *get_ver_value_head(ver_value_t *p);
167 static ver_block_t *get_ver_block_head(ver_block_t *p);
168 static resource_t *get_resource_head(resource_t *p);
169 static menu_item_t *get_item_head(menu_item_t *p);
170 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
171 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
172 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
173 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
174 static raw_data_t *str2raw_data(string_t *str);
175 static raw_data_t *int2raw_data(int i);
176 static raw_data_t *long2raw_data(int i);
177 static raw_data_t *load_file(string_t *name, language_t lang);
178 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
179 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
180 static event_t *add_event(int key, int id, int flags, event_t *prev);
181 static name_id_t *convert_ctlclass(name_id_t *cls);
182 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
183 static dialog_t *dialog_version(version_t v, dialog_t *dlg);
184 static dialog_t *dialog_characteristics(characts_t c, dialog_t *dlg);
185 static dialog_t *dialog_language(language_t l, dialog_t *dlg);
186 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
187 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
188 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
189 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
190 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
191 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
192 static resource_t *build_stt_resources(stringtable_t *stthead);
193 static stringtable_t *find_stringtable(lvc_t *lvc);
194 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
195 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
196 static string_t *make_filename(string_t *s);
197 static resource_t *build_fontdirs(resource_t *tail);
198 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
199 static int rsrcid_to_token(int lookahead);
201 /* bison >= 3.6 applies api.prefix also to YYEMPTY */
202 #define YYEMPTY (-2)
206 %define api.prefix {parser_}
208 %union{
209 string_t *str;
210 int num;
211 int *iptr;
212 char *cptr;
213 resource_t *res;
214 accelerator_t *acc;
215 bitmap_t *bmp;
216 dialog_t *dlg;
217 font_t *fnt;
218 fontdir_t *fnd;
219 menu_t *men;
220 html_t *html;
221 rcdata_t *rdt;
222 stringtable_t *stt;
223 stt_entry_t *stte;
224 user_t *usr;
225 messagetable_t *msg;
226 versioninfo_t *veri;
227 control_t *ctl;
228 name_id_t *nid;
229 font_id_t *fntid;
230 language_t lan;
231 version_t ver;
232 characts_t chars;
233 event_t *event;
234 menu_item_t *menitm;
235 itemex_opt_t *exopt;
236 raw_data_t *raw;
237 lvc_t *lvc;
238 ver_value_t *val;
239 ver_block_t *blk;
240 ver_words_t *verw;
241 toolbar_t *tlbar;
242 toolbar_item_t *tlbarItems;
243 dlginit_t *dginit;
244 style_pair_t *styles;
245 style_t *style;
246 ani_any_t *ani;
249 %token tNL
250 %token <num> tNUMBER tLNUMBER
251 %token <str> tSTRING tIDENT
252 %token <raw> tRAWDATA
253 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
254 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
255 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
256 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
257 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
258 %token tCONTROL tEDITTEXT
259 %token tRTEXT tCTEXT tLTEXT
260 %token tBLOCK tVALUE
261 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
262 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
263 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
264 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
265 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
266 %token tHELP
267 %token tTOOLBAR tBUTTON
268 %token tBEGIN tEND
269 %token tDLGINIT
270 %left '|'
271 %left '^'
272 %left '&'
273 %left '+' '-'
274 %left '*' '/'
275 %right '~' tNOT
276 %left pUPM
278 %type <res> resource_file resource resources resource_definition
279 %type <stt> stringtable strings
280 %type <fnt> font
281 %type <fnd> fontdir
282 %type <acc> accelerators
283 %type <event> events
284 %type <bmp> bitmap
285 %type <ani> cursor icon
286 %type <dlg> dialog dlg_attributes dialogex dlgex_attribs
287 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
288 %type <iptr> helpid
289 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
290 %type <html> html
291 %type <rdt> rcdata
292 %type <raw> raw_data raw_elements opt_data file_raw
293 %type <veri> versioninfo fix_version
294 %type <verw> ver_words
295 %type <blk> ver_blocks ver_block
296 %type <val> ver_values ver_value
297 %type <men> menu menuex
298 %type <menitm> item_definitions menu_body itemex_definitions menuex_body
299 %type <exopt> itemex_p_options itemex_options
300 %type <msg> messagetable
301 %type <usr> userres
302 %type <num> item_options
303 %type <nid> nameid nameid_s ctlclass usertype
304 %type <num> acc_opt acc accs
305 %type <iptr> loadmemopts lamo lama
306 %type <fntid> opt_font opt_exfont opt_expr
307 %type <lvc> opt_lvc
308 %type <lan> opt_language
309 %type <chars> opt_characts
310 %type <ver> opt_version
311 %type <num> expr xpr
312 %type <iptr> e_expr
313 %type <tlbar> toolbar
314 %type <tlbarItems> toolbar_items
315 %type <dginit> dlginit
316 %type <styles> optional_style_pair
317 %type <num> any_num
318 %type <style> style
319 %type <str> filename
323 resource_file
324 : resources {
325 resource_t *rsc, *head;
326 /* First add stringtables to the resource-list */
327 rsc = build_stt_resources(sttres);
328 /* 'build_stt_resources' returns a head and $1 is a tail */
329 if($1)
331 $1->next = rsc;
332 if(rsc)
333 rsc->prev = $1;
335 else
336 $1 = rsc;
337 /* Find the tail again */
338 while($1 && $1->next)
339 $1 = $1->next;
340 /* Now add any fontdirectory */
341 rsc = build_fontdirs($1);
342 /* 'build_fontdir' returns a head and $1 is a tail */
343 if($1)
345 $1->next = rsc;
346 if(rsc)
347 rsc->prev = $1;
349 else
350 $1 = rsc;
352 /* Final statements before we're done */
353 if ((head = get_resource_head($1)) != NULL)
355 if (resource_top) /* append to existing resources */
357 resource_t *tail = resource_top;
358 while (tail->next) tail = tail->next;
359 tail->next = head;
360 head->prev = tail;
362 else resource_top = head;
364 sttres = NULL;
368 /* Resources are put into a linked list */
369 resources
370 : /* Empty */ { $$ = NULL; want_id = 1; }
371 | resources resource {
372 if($2)
374 resource_t *tail = $2;
375 resource_t *head = $2;
376 while(tail->next)
377 tail = tail->next;
378 while(head->prev)
379 head = head->prev;
380 head->prev = $1;
381 if($1)
382 $1->next = head;
383 $$ = tail;
384 /* Check for duplicate identifiers */
385 while($1 && head)
387 resource_t *rsc = $1;
388 while(rsc)
390 if(rsc->type == head->type
391 && rsc->lan == head->lan
392 && !compare_name_id(rsc->name, head->name)
393 && (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
395 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
397 rsc = rsc->prev;
399 head = head->next;
402 else if($1)
404 resource_t *tail = $1;
405 while(tail->next)
406 tail = tail->next;
407 $$ = tail;
409 else
410 $$ = NULL;
412 if(!dont_want_id) /* See comments in language parsing below */
413 want_id = 1;
414 dont_want_id = 0;
417 * The following newline rule will never get reduced because we never
418 * get the tNL token, unless we explicitly set the 'want_nl'
419 * flag, which we don't.
420 * The *ONLY* reason for this to be here is because Berkeley
421 * yacc (byacc), at least version 1.9, has a bug.
422 * (identified in the generated parser on the second
423 * line with:
424 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
426 * This extra rule fixes it.
427 * The problem is that the expression handling rule "expr: xpr"
428 * is not reduced on non-terminal tokens, defined above in the
429 * %token declarations. Token tNL is the only non-terminal that
430 * can occur. The error becomes visible in the language parsing
431 * rule below, which looks at the look-ahead token and tests it
432 * for tNL. However, byacc already generates an error upon reading
433 * the token instead of keeping it as a lookahead. The reason
434 * lies in the lack of a $default transition in the "expr : xpr . "
435 * state (currently state 25). It is probably omitted because tNL
436 * is a non-terminal and the state contains 2 s/r conflicts. The
437 * state enumerates all possible transitions instead of using a
438 * $default transition.
439 * All in all, it is a bug in byacc. (period)
441 | resources tNL
445 /* Parse top level resource definitions etc. */
446 resource
447 : expr usrcvt resource_definition {
448 $$ = $3;
449 if($$)
451 if($1 > 65535 || $1 < -32768)
452 yyerror("Resource's ID out of range (%d)", $1);
453 $$->name = new_name_id();
454 $$->name->type = name_ord;
455 $$->name->name.i_name = $1;
458 | tIDENT usrcvt resource_definition {
459 $$ = $3;
460 if($$)
462 $$->name = new_name_id();
463 $$->name->type = name_str;
464 $$->name->name.s_name = $1;
467 | stringtable {
468 /* Don't do anything, stringtables are converted to
469 * resource_t structures when we are finished parsing and
470 * the final rule of the parser is reduced (see above)
472 $$ = NULL;
473 chat("Got STRINGTABLE\n");
475 | tLANGUAGE {want_nl = 1; } expr ',' expr {
476 /* We *NEED* the newline to delimit the expression.
477 * Otherwise, we would not be able to set the next
478 * want_id anymore because of the token-lookahead.
480 * However, we can test the lookahead-token for
481 * being "non-expression" type, in which case we
482 * continue. Fortunately, tNL is the only token that
483 * will break expression parsing and is implicitly
484 * void, so we just remove it. This scheme makes it
485 * possible to do some (not all) fancy preprocessor
486 * stuff.
487 * BTW, we also need to make sure that the next
488 * reduction of 'resources' above will *not* set
489 * want_id because we already have a lookahead that
490 * cannot be undone.
492 if(yychar != YYEMPTY && yychar != tNL)
493 dont_want_id = 1;
495 if(yychar == tNL)
496 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
497 /* direct access to yychar in rule 'usrcvt' below. */
498 else if(yychar == tIDENT)
499 parser_warning("LANGUAGE statement not delimited with newline; next identifier might be wrong\n");
501 want_nl = 0; /* We don't want it anymore if we didn't get it */
503 if(!win32)
504 parser_warning("LANGUAGE not supported in 16-bit mode\n");
505 currentlanguage = MAKELANGID($3, $5);
506 if (get_language_codepage(currentlanguage) == -1)
507 yyerror( "Language %04x is not supported", currentlanguage);
508 $$ = NULL;
509 chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, currentlanguage);
514 * Remapping of numerical resource types
515 * (see also comment of called function below)
517 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
521 * Get a valid name/id
523 nameid : expr {
524 if($1 > 65535 || $1 < -32768)
525 yyerror("Resource's ID out of range (%d)", $1);
526 $$ = new_name_id();
527 $$->type = name_ord;
528 $$->name.i_name = $1;
530 | tIDENT {
531 $$ = new_name_id();
532 $$->type = name_str;
533 $$->name.s_name = $1;
538 * Extra string recognition for CLASS statement in dialogs
540 nameid_s: nameid { $$ = $1; }
541 | tSTRING {
542 $$ = new_name_id();
543 $$->type = name_str;
544 $$->name.s_name = $1;
548 /* get the value for a single resource*/
549 resource_definition
550 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
551 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
552 | cursor {
553 resource_t *rsc;
554 if($1->type == res_anicur)
556 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
558 else /* res_curg */
560 cursor_t *cur;
561 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
562 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
564 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
565 rsc->prev->next = rsc;
566 rsc = rsc->prev;
567 rsc->name = new_name_id();
568 rsc->name->type = name_ord;
569 rsc->name->name.i_name = cur->id;
572 free($1);
574 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
575 | dialogex {
576 if(win32)
577 $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language);
578 else
579 $$ = NULL;
581 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
582 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
583 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
584 | icon {
585 resource_t *rsc;
586 if($1->type == res_aniico)
588 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
590 else /* res_icog */
592 icon_t *ico;
593 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
594 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
596 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
597 rsc->prev->next = rsc;
598 rsc = rsc->prev;
599 rsc->name = new_name_id();
600 rsc->name->type = name_ord;
601 rsc->name->name.i_name = ico->id;
604 free($1);
606 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
607 | menuex {
608 if(win32)
609 $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language);
610 else
611 $$ = NULL;
613 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
614 | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
615 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
616 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
617 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
618 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
622 filename: tIDENT { $$ = make_filename($1); }
623 | tSTRING { $$ = make_filename($1); }
626 /* ------------------------------ Bitmap ------------------------------ */
627 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
630 /* ------------------------------ Cursor ------------------------------ */
631 cursor : tCURSOR loadmemopts file_raw {
632 $$ = new_ani_any();
633 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
635 $$->type = res_anicur;
636 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
638 else
640 $$->type = res_curg;
641 $$->u.curg = new_cursor_group($3, $2);
646 /* ------------------------------ Icon ------------------------------ */
647 icon : tICON loadmemopts file_raw {
648 $$ = new_ani_any();
649 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
651 $$->type = res_aniico;
652 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
654 else
656 $$->type = res_icog;
657 $$->u.icog = new_icon_group($3, $2);
662 /* ------------------------------ Font ------------------------------ */
664 * The reading of raw_data for fonts is a Borland BRC
665 * extension. MS generates an error. However, it is
666 * most logical to support this, considering how wine
667 * enters things in CVS (ascii).
669 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
673 * The fontdir is a Borland BRC extension which only
674 * reads the data as 'raw_data' from the file.
675 * I don't know whether it is interpreted.
676 * The fontdir is generated if it was not present and
677 * fonts are defined in the source.
679 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
682 /* ------------------------------ MessageTable ------------------------------ */
683 /* It might be interesting to implement the MS Message compiler here as well
684 * to get everything in one source. Might be a future project.
686 messagetable
687 : tMESSAGETABLE loadmemopts file_raw {
688 if(!win32)
689 parser_warning("MESSAGETABLE not supported in 16-bit mode\n");
690 $$ = new_messagetable($3, $2);
694 /* ------------------------------ HTML ------------------------------ */
695 html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
698 /* ------------------------------ RCData ------------------------------ */
699 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
702 /* ------------------------------ DLGINIT ------------------------------ */
703 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
706 /* ------------------------------ UserType ------------------------------ */
707 userres : usertype loadmemopts file_raw {
708 $$ = new_user($1, $3, $2);
712 usertype: tNUMBER {
713 $$ = new_name_id();
714 $$->type = name_ord;
715 $$->name.i_name = $1;
717 | tIDENT {
718 $$ = new_name_id();
719 $$->type = name_str;
720 $$->name.s_name = $1;
724 /* ------------------------------ Accelerator ------------------------------ */
725 accelerators
726 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
727 $$ = new_accelerator();
728 if($2)
730 $$->memopt = *($2);
731 free($2);
733 else
735 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
737 if(!$5)
738 yyerror("Accelerator table must have at least one entry");
739 $$->events = get_event_head($5);
740 if($3)
742 $$->lvc = *($3);
743 free($3);
745 if(!$$->lvc.language) $$->lvc.language = currentlanguage;
749 events : /* Empty */ { $$=NULL; }
750 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
751 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
755 * The empty rule generates a s/r conflict because of {bi,u}nary expr
756 * on - and +. It cannot be solved in any way because it is the same as
757 * the if/then/else problem (LALR(1) problem). The conflict is moved
758 * away by forcing it to be in the expression handling below.
760 acc_opt : /* Empty */ { $$ = 0; }
761 | ',' accs { $$ = $2; }
764 accs : acc { $$ = $1; }
765 | accs ',' acc { $$ = $1 | $3; }
768 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
769 | tSHIFT { $$ = WRC_AF_SHIFT; }
770 | tCONTROL { $$ = WRC_AF_CONTROL; }
771 | tALT { $$ = WRC_AF_ALT; }
772 | tASCII { $$ = WRC_AF_ASCII; }
773 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
776 /* ------------------------------ Dialog ------------------------------ */
777 /* FIXME: Support EXSTYLE in the dialog line itself */
778 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
779 tBEGIN ctrls tEND {
780 if($2)
782 $10->memopt = *($2);
783 free($2);
785 else
786 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
787 $10->x = $3;
788 $10->y = $5;
789 $10->width = $7;
790 $10->height = $9;
791 $10->controls = get_control_head($12);
792 $$ = $10;
793 if(!$$->gotstyle)
795 $$->style = new_style(0,0);
796 $$->style->or_mask = WS_POPUP;
797 $$->gotstyle = TRUE;
799 if($$->title)
800 $$->style->or_mask |= WS_CAPTION;
801 if($$->font)
802 $$->style->or_mask |= DS_SETFONT;
804 $$->style->or_mask &= ~($$->style->and_mask);
805 $$->style->and_mask = 0;
807 if(!$$->lvc.language) $$->lvc.language = currentlanguage;
811 dlg_attributes
812 : /* Empty */ { $$=new_dialog(); }
813 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
814 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
815 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
816 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
817 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
818 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
819 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
820 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
821 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
824 ctrls : /* Empty */ { $$ = NULL; }
825 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
826 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
827 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
828 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
829 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
830 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
831 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
832 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
833 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
834 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
835 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
836 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
837 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
838 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
839 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
840 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
841 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
842 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
843 /* special treatment for icons, as the extent is optional */
844 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
845 $10->title = $3;
846 $10->id = $5;
847 $10->x = $7;
848 $10->y = $9;
849 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
853 lab_ctrl
854 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
855 $$=new_control();
856 $$->title = $1;
857 $$->id = $3;
858 $$->x = $5;
859 $$->y = $7;
860 $$->width = $9;
861 $$->height = $11;
862 if($12)
864 $$->style = $12->style;
865 $$->gotstyle = TRUE;
866 if ($12->exstyle)
868 $$->exstyle = $12->exstyle;
869 $$->gotexstyle = TRUE;
871 free($12);
876 ctrl_desc
877 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
878 $$ = new_control();
879 $$->id = $1;
880 $$->x = $3;
881 $$->y = $5;
882 $$->width = $7;
883 $$->height = $9;
884 if($10)
886 $$->style = $10->style;
887 $$->gotstyle = TRUE;
888 if ($10->exstyle)
890 $$->exstyle = $10->exstyle;
891 $$->gotexstyle = TRUE;
893 free($10);
898 iconinfo: /* Empty */
899 { $$ = new_control(); }
901 | ',' expr ',' expr {
902 $$ = new_control();
903 $$->width = $2;
904 $$->height = $4;
906 | ',' expr ',' expr ',' style {
907 $$ = new_control();
908 $$->width = $2;
909 $$->height = $4;
910 $$->style = $6;
911 $$->gotstyle = TRUE;
913 | ',' expr ',' expr ',' style ',' style {
914 $$ = new_control();
915 $$->width = $2;
916 $$->height = $4;
917 $$->style = $6;
918 $$->gotstyle = TRUE;
919 $$->exstyle = $8;
920 $$->gotexstyle = TRUE;
924 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
925 $$=new_control();
926 $$->title = $1;
927 $$->id = $3;
928 $$->ctlclass = convert_ctlclass($5);
929 $$->style = $7;
930 $$->gotstyle = TRUE;
931 $$->x = $9;
932 $$->y = $11;
933 $$->width = $13;
934 $$->height = $15;
935 $$->exstyle = $17;
936 $$->gotexstyle = TRUE;
938 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
939 $$=new_control();
940 $$->title = $1;
941 $$->id = $3;
942 $$->ctlclass = convert_ctlclass($5);
943 $$->style = $7;
944 $$->gotstyle = TRUE;
945 $$->x = $9;
946 $$->y = $11;
947 $$->width = $13;
948 $$->height = $15;
952 opt_font
953 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
956 /* ------------------------------ style flags ------------------------------ */
957 optional_style_pair
958 : /* Empty */ { $$ = NULL; }
959 | ',' style { $$ = new_style_pair($2, 0); }
960 | ',' style ',' style { $$ = new_style_pair($2, $4); }
963 style
964 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
965 | '(' style ')' { $$ = $2; }
966 | any_num { $$ = new_style($1, 0); }
967 | tNOT any_num { $$ = new_style(0, $2); }
970 ctlclass
971 : expr {
972 $$ = new_name_id();
973 $$->type = name_ord;
974 $$->name.i_name = $1;
976 | tSTRING {
977 $$ = new_name_id();
978 $$->type = name_str;
979 $$->name.s_name = $1;
983 /* ------------------------------ DialogEx ------------------------------ */
984 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
985 tBEGIN exctrls tEND {
986 if(!win32)
987 parser_warning("DIALOGEX not supported in 16-bit mode\n");
988 if($2)
990 $11->memopt = *($2);
991 free($2);
993 else
994 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
995 $11->x = $3;
996 $11->y = $5;
997 $11->width = $7;
998 $11->height = $9;
999 if($10)
1001 $11->helpid = *($10);
1002 $11->gothelpid = TRUE;
1003 free($10);
1005 $11->controls = get_control_head($13);
1006 $$ = $11;
1008 assert($$->style != NULL);
1009 if(!$$->gotstyle)
1011 $$->style->or_mask = WS_POPUP;
1012 $$->gotstyle = TRUE;
1014 if($$->title)
1015 $$->style->or_mask |= WS_CAPTION;
1016 if($$->font)
1017 $$->style->or_mask |= DS_SETFONT;
1019 $$->style->or_mask &= ~($$->style->and_mask);
1020 $$->style->and_mask = 0;
1022 if(!$$->lvc.language) $$->lvc.language = currentlanguage;
1026 dlgex_attribs
1027 : /* Empty */ { $$=new_dialog(); $$->is_ex = TRUE; }
1028 | dlgex_attribs tSTYLE style { $$=dialog_style($3,$1); }
1029 | dlgex_attribs tEXSTYLE style { $$=dialog_exstyle($3,$1); }
1030 | dlgex_attribs tCAPTION tSTRING { $$=dialog_caption($3,$1); }
1031 | dlgex_attribs opt_font { $$=dialog_font($2,$1); }
1032 | dlgex_attribs opt_exfont { $$=dialog_font($2,$1); }
1033 | dlgex_attribs tCLASS nameid_s { $$=dialog_class($3,$1); }
1034 | dlgex_attribs tMENU nameid { $$=dialog_menu($3,$1); }
1035 | dlgex_attribs opt_language { $$=dialog_language($2,$1); }
1036 | dlgex_attribs opt_characts { $$=dialog_characteristics($2,$1); }
1037 | dlgex_attribs opt_version { $$=dialog_version($2,$1); }
1040 exctrls : /* Empty */ { $$ = NULL; }
1041 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1042 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1043 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1044 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1045 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1046 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1047 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1048 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1049 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1050 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1051 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1052 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1053 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1054 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1055 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1056 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1057 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1058 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1059 /* special treatment for icons, as the extent is optional */
1060 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1061 $10->title = $3;
1062 $10->id = $5;
1063 $10->x = $7;
1064 $10->y = $9;
1065 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1069 gen_exctrl
1070 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1071 expr ',' style helpid opt_data {
1072 $$=new_control();
1073 $$->title = $1;
1074 $$->id = $3;
1075 $$->ctlclass = convert_ctlclass($5);
1076 $$->style = $7;
1077 $$->gotstyle = TRUE;
1078 $$->x = $9;
1079 $$->y = $11;
1080 $$->width = $13;
1081 $$->height = $15;
1082 if($17)
1084 $$->exstyle = $17;
1085 $$->gotexstyle = TRUE;
1087 if($18)
1089 $$->helpid = *($18);
1090 $$->gothelpid = TRUE;
1091 free($18);
1093 $$->extra = $19;
1095 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1096 $$=new_control();
1097 $$->title = $1;
1098 $$->id = $3;
1099 $$->style = $7;
1100 $$->gotstyle = TRUE;
1101 $$->ctlclass = convert_ctlclass($5);
1102 $$->x = $9;
1103 $$->y = $11;
1104 $$->width = $13;
1105 $$->height = $15;
1106 $$->extra = $16;
1110 lab_exctrl
1111 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1112 $$=new_control();
1113 $$->title = $1;
1114 $$->id = $3;
1115 $$->x = $5;
1116 $$->y = $7;
1117 $$->width = $9;
1118 $$->height = $11;
1119 if($12)
1121 $$->style = $12->style;
1122 $$->gotstyle = TRUE;
1124 if ($12->exstyle)
1126 $$->exstyle = $12->exstyle;
1127 $$->gotexstyle = TRUE;
1129 free($12);
1132 $$->extra = $14;
1136 exctrl_desc
1137 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1138 $$ = new_control();
1139 $$->id = $1;
1140 $$->x = $3;
1141 $$->y = $5;
1142 $$->width = $7;
1143 $$->height = $9;
1144 if($10)
1146 $$->style = $10->style;
1147 $$->gotstyle = TRUE;
1149 if ($10->exstyle)
1151 $$->exstyle = $10->exstyle;
1152 $$->gotexstyle = TRUE;
1154 free($10);
1156 $$->extra = $12;
1160 opt_data: /* Empty */ { $$ = NULL; }
1161 | raw_data { $$ = $1; }
1164 helpid : /* Empty */ { $$ = NULL; }
1165 | ',' expr { $$ = new_int($2); }
1168 opt_exfont
1169 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1173 * FIXME: This odd expression is here to nullify an extra token found
1174 * in some appstudio produced resources which appear to do nothing.
1176 opt_expr: /* Empty */ { $$ = NULL; }
1177 | ',' expr { $$ = NULL; }
1180 /* ------------------------------ Menu ------------------------------ */
1181 menu : tMENU loadmemopts opt_lvc menu_body {
1182 if(!$4)
1183 yyerror("Menu must contain items");
1184 $$ = new_menu();
1185 if($2)
1187 $$->memopt = *($2);
1188 free($2);
1190 else
1191 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1192 $$->items = get_item_head($4);
1193 if($3)
1195 $$->lvc = *($3);
1196 free($3);
1198 if(!$$->lvc.language) $$->lvc.language = currentlanguage;
1202 menu_body
1203 : tBEGIN item_definitions tEND { $$ = $2; }
1206 item_definitions
1207 : /* Empty */ {$$ = NULL;}
1208 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1209 $$=new_menu_item();
1210 $$->prev = $1;
1211 if($1)
1212 $1->next = $$;
1213 $$->id = $5;
1214 $$->state = $6;
1215 $$->name = $3;
1217 | item_definitions tMENUITEM tSEPARATOR {
1218 $$=new_menu_item();
1219 $$->prev = $1;
1220 if($1)
1221 $1->next = $$;
1223 | item_definitions tPOPUP tSTRING item_options menu_body {
1224 $$ = new_menu_item();
1225 $$->prev = $1;
1226 if($1)
1227 $1->next = $$;
1228 $$->popup = get_item_head($5);
1229 $$->name = $3;
1233 /* NOTE: item_options is right recursive because it would introduce
1234 * a shift/reduce conflict on ',' in itemex_options due to the
1235 * empty rule here. The parser is now forced to look beyond the ','
1236 * before reducing (force shift).
1237 * Right recursion here is not a problem because we cannot expect
1238 * more than 7 parserstack places to be occupied while parsing this
1239 * (who would want to specify a MF_x flag twice?).
1241 item_options
1242 : /* Empty */ { $$ = 0; }
1243 | ',' item_options { $$ = $2; }
1244 | tCHECKED item_options { $$ = $2 | MF_CHECKED; }
1245 | tGRAYED item_options { $$ = $2 | MF_GRAYED; }
1246 | tHELP item_options { $$ = $2 | MF_HELP; }
1247 | tINACTIVE item_options { $$ = $2 | MF_DISABLED; }
1248 | tMENUBARBREAK item_options { $$ = $2 | MF_MENUBARBREAK; }
1249 | tMENUBREAK item_options { $$ = $2 | MF_MENUBREAK; }
1252 /* ------------------------------ MenuEx ------------------------------ */
1253 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1254 if(!win32)
1255 parser_warning("MENUEX not supported in 16-bit mode\n");
1256 if(!$4)
1257 yyerror("MenuEx must contain items");
1258 $$ = new_menu();
1259 $$->is_ex = TRUE;
1260 if($2)
1262 $$->memopt = *($2);
1263 free($2);
1265 else
1266 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1267 $$->items = get_item_head($4);
1268 if($3)
1270 $$->lvc = *($3);
1271 free($3);
1273 if(!$$->lvc.language) $$->lvc.language = currentlanguage;
1277 menuex_body
1278 : tBEGIN itemex_definitions tEND { $$ = $2; }
1281 itemex_definitions
1282 : /* Empty */ {$$ = NULL; }
1283 | itemex_definitions tMENUITEM tSTRING itemex_options {
1284 $$ = new_menu_item();
1285 $$->prev = $1;
1286 if($1)
1287 $1->next = $$;
1288 $$->name = $3;
1289 $$->id = $4->id;
1290 $$->type = $4->type;
1291 $$->state = $4->state;
1292 $$->helpid = $4->helpid;
1293 $$->gotid = $4->gotid;
1294 $$->gottype = $4->gottype;
1295 $$->gotstate = $4->gotstate;
1296 $$->gothelpid = $4->gothelpid;
1297 free($4);
1299 | itemex_definitions tMENUITEM tSEPARATOR {
1300 $$ = new_menu_item();
1301 $$->prev = $1;
1302 if($1)
1303 $1->next = $$;
1305 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1306 $$ = new_menu_item();
1307 $$->prev = $1;
1308 if($1)
1309 $1->next = $$;
1310 $$->popup = get_item_head($5);
1311 $$->name = $3;
1312 $$->id = $4->id;
1313 $$->type = $4->type;
1314 $$->state = $4->state;
1315 $$->helpid = $4->helpid;
1316 $$->gotid = $4->gotid;
1317 $$->gottype = $4->gottype;
1318 $$->gotstate = $4->gotstate;
1319 $$->gothelpid = $4->gothelpid;
1320 free($4);
1324 itemex_options
1325 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1326 | ',' expr {
1327 $$ = new_itemex_opt($2, 0, 0, 0);
1328 $$->gotid = TRUE;
1330 | ',' e_expr ',' e_expr item_options {
1331 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1332 $$->gotid = TRUE;
1333 $$->gottype = TRUE;
1334 $$->gotstate = TRUE;
1335 free($2);
1336 free($4);
1338 | ',' e_expr ',' e_expr ',' expr {
1339 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1340 $$->gotid = TRUE;
1341 $$->gottype = TRUE;
1342 $$->gotstate = TRUE;
1343 free($2);
1344 free($4);
1348 itemex_p_options
1349 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1350 | ',' expr {
1351 $$ = new_itemex_opt($2, 0, 0, 0);
1352 $$->gotid = TRUE;
1354 | ',' e_expr ',' expr {
1355 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1356 free($2);
1357 $$->gotid = TRUE;
1358 $$->gottype = TRUE;
1360 | ',' e_expr ',' e_expr ',' expr {
1361 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1362 free($2);
1363 free($4);
1364 $$->gotid = TRUE;
1365 $$->gottype = TRUE;
1366 $$->gotstate = TRUE;
1368 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1369 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1370 free($2);
1371 free($4);
1372 free($6);
1373 $$->gotid = TRUE;
1374 $$->gottype = TRUE;
1375 $$->gotstate = TRUE;
1376 $$->gothelpid = TRUE;
1380 /* ------------------------------ StringTable ------------------------------ */
1381 /* Stringtables are parsed differently than other resources because their
1382 * layout is substantially different from other resources.
1383 * The table is parsed through a _global_ variable 'tagstt' which holds the
1384 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1385 * list of stringtables of different languages.
1387 stringtable
1388 : stt_head tBEGIN strings tEND {
1389 if(!$3)
1391 yyerror("Stringtable must have at least one entry");
1393 else
1395 stringtable_t *stt;
1396 /* Check if we added to a language table or created
1397 * a new one.
1399 for(stt = sttres; stt; stt = stt->next)
1401 if(stt == tagstt)
1402 break;
1404 if(!stt)
1406 /* It is a new one */
1407 if(sttres)
1409 sttres->prev = tagstt;
1410 tagstt->next = sttres;
1411 sttres = tagstt;
1413 else
1414 sttres = tagstt;
1416 /* Else, we're done */
1418 free(tagstt_memopt);
1419 tagstt_memopt = NULL;
1421 $$ = tagstt;
1425 /* This is to get the language of the currently parsed stringtable */
1426 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1427 if((tagstt = find_stringtable($3)) == NULL)
1428 tagstt = new_stringtable($3);
1429 tagstt_memopt = $2;
1430 tagstt_version = $3->version;
1431 tagstt_characts = $3->characts;
1432 free($3);
1436 strings : /* Empty */ { $$ = NULL; }
1437 | strings expr opt_comma tSTRING {
1438 int i;
1439 assert(tagstt != NULL);
1440 if($2 > 65535 || $2 < -32768)
1441 yyerror("Stringtable entry's ID out of range (%d)", $2);
1442 /* Search for the ID */
1443 for(i = 0; i < tagstt->nentries; i++)
1445 if(tagstt->entries[i].id == $2)
1446 yyerror("Stringtable ID %d already in use", $2);
1448 /* If we get here, then we have a new unique entry */
1449 tagstt->nentries++;
1450 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1451 tagstt->entries[tagstt->nentries-1].id = $2;
1452 tagstt->entries[tagstt->nentries-1].str = $4;
1453 if(tagstt_memopt)
1454 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1455 else
1456 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1457 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1458 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1460 if(pedantic && !$4->size)
1461 parser_warning("Zero length strings make no sense\n");
1462 if(!win32 && $4->size > 254)
1463 yyerror("Stringtable entry more than 254 characters");
1464 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1465 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1466 $$ = tagstt;
1470 opt_comma /* There seem to be two ways to specify a stringtable... */
1471 : /* Empty */
1472 | ','
1475 /* ------------------------------ VersionInfo ------------------------------ */
1476 versioninfo
1477 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1478 $$ = $3;
1479 if($2)
1481 $$->memopt = *($2);
1482 free($2);
1484 else
1485 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1486 $$->blocks = get_ver_block_head($5);
1487 /* Set language; there is no version or characteristics */
1488 $$->lvc.language = currentlanguage;
1492 fix_version
1493 : /* Empty */ { $$ = new_versioninfo(); }
1494 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1495 if($1->gotit.fv)
1496 yyerror("FILEVERSION already defined");
1497 $$ = $1;
1498 $$->filever_maj1 = $3;
1499 $$->filever_maj2 = $5;
1500 $$->filever_min1 = $7;
1501 $$->filever_min2 = $9;
1502 $$->gotit.fv = 1;
1504 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1505 if($1->gotit.pv)
1506 yyerror("PRODUCTVERSION already defined");
1507 $$ = $1;
1508 $$->prodver_maj1 = $3;
1509 $$->prodver_maj2 = $5;
1510 $$->prodver_min1 = $7;
1511 $$->prodver_min2 = $9;
1512 $$->gotit.pv = 1;
1514 | fix_version tFILEFLAGS expr {
1515 if($1->gotit.ff)
1516 yyerror("FILEFLAGS already defined");
1517 $$ = $1;
1518 $$->fileflags = $3;
1519 $$->gotit.ff = 1;
1521 | fix_version tFILEFLAGSMASK expr {
1522 if($1->gotit.ffm)
1523 yyerror("FILEFLAGSMASK already defined");
1524 $$ = $1;
1525 $$->fileflagsmask = $3;
1526 $$->gotit.ffm = 1;
1528 | fix_version tFILEOS expr {
1529 if($1->gotit.fo)
1530 yyerror("FILEOS already defined");
1531 $$ = $1;
1532 $$->fileos = $3;
1533 $$->gotit.fo = 1;
1535 | fix_version tFILETYPE expr {
1536 if($1->gotit.ft)
1537 yyerror("FILETYPE already defined");
1538 $$ = $1;
1539 $$->filetype = $3;
1540 $$->gotit.ft = 1;
1542 | fix_version tFILESUBTYPE expr {
1543 if($1->gotit.fst)
1544 yyerror("FILESUBTYPE already defined");
1545 $$ = $1;
1546 $$->filesubtype = $3;
1547 $$->gotit.fst = 1;
1551 ver_blocks
1552 : /* Empty */ { $$ = NULL; }
1553 | ver_blocks ver_block {
1554 $$ = $2;
1555 $$->prev = $1;
1556 if($1)
1557 $1->next = $$;
1561 ver_block
1562 : tBLOCK tSTRING tBEGIN ver_values tEND {
1563 $$ = new_ver_block();
1564 $$->name = $2;
1565 $$->values = get_ver_value_head($4);
1569 ver_values
1570 : /* Empty */ { $$ = NULL; }
1571 | ver_values ver_value {
1572 $$ = $2;
1573 $$->prev = $1;
1574 if($1)
1575 $1->next = $$;
1579 ver_value
1580 : ver_block {
1581 $$ = new_ver_value();
1582 $$->type = val_block;
1583 $$->value.block = $1;
1585 | tVALUE tSTRING ',' tSTRING {
1586 $$ = new_ver_value();
1587 $$->type = val_str;
1588 $$->key = $2;
1589 $$->value.str = $4;
1591 | tVALUE tSTRING ',' ver_words {
1592 $$ = new_ver_value();
1593 $$->type = val_words;
1594 $$->key = $2;
1595 $$->value.words = $4;
1599 ver_words
1600 : expr { $$ = new_ver_words($1); }
1601 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1604 /* ------------------------------ Toolbar ------------------------------ */
1605 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1606 int nitems;
1607 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1608 $$ = new_toolbar($3, $5, items, nitems);
1609 if($2)
1611 $$->memopt = *($2);
1612 free($2);
1614 else
1616 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1618 if($6)
1620 $$->lvc = *($6);
1621 free($6);
1623 if(!$$->lvc.language) $$->lvc.language = currentlanguage;
1627 toolbar_items
1628 : /* Empty */ { $$ = NULL; }
1629 | toolbar_items tBUTTON expr {
1630 toolbar_item_t *idrec = new_toolbar_item();
1631 idrec->id = $3;
1632 $$ = ins_tlbr_button($1, idrec);
1634 | toolbar_items tSEPARATOR {
1635 toolbar_item_t *idrec = new_toolbar_item();
1636 idrec->id = 0;
1637 $$ = ins_tlbr_button($1, idrec);
1641 /* ------------------------------ Memory options ------------------------------ */
1642 loadmemopts
1643 : /* Empty */ { $$ = NULL; }
1644 | loadmemopts lamo {
1645 if($1)
1647 *($1) |= *($2);
1648 $$ = $1;
1649 free($2);
1651 else
1652 $$ = $2;
1654 | loadmemopts lama {
1655 if($1)
1657 *($1) &= *($2);
1658 $$ = $1;
1659 free($2);
1661 else
1663 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1664 $$ = $2;
1669 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD);
1670 if (win32 && pedantic) parser_warning("PRELOAD is ignored in 32-bit mode\n"); }
1671 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE);
1672 if (win32 && pedantic) parser_warning("MOVEABLE is ignored in 32-bit mode\n"); }
1673 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE);
1674 if (win32 && pedantic) parser_warning("DISCARDABLE is ignored in 32-bit mode\n"); }
1675 | tPURE { $$ = new_int(WRC_MO_PURE);
1676 if (win32 && pedantic) parser_warning("PURE is ignored in 32-bit mode\n"); }
1679 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD);
1680 if (win32 && pedantic) parser_warning("LOADONCALL is ignored in 32-bit mode\n"); }
1681 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE);
1682 if (win32 && pedantic) parser_warning("FIXED is ignored in 32-bit mode\n"); }
1683 | tIMPURE { $$ = new_int(~WRC_MO_PURE);
1684 if (win32 && pedantic) parser_warning("IMPURE is ignored in 32-bit mode\n"); }
1687 /* ------------------------------ Win32 options ------------------------------ */
1688 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1689 | opt_lvc opt_language {
1690 if(!win32)
1691 parser_warning("LANGUAGE not supported in 16-bit mode\n");
1692 if($1->language)
1693 yyerror("Language already defined");
1694 $$ = $1;
1695 $1->language = $2;
1697 | opt_lvc opt_characts {
1698 if(!win32)
1699 parser_warning("CHARACTERISTICS not supported in 16-bit mode\n");
1700 if($1->characts)
1701 yyerror("Characteristics already defined");
1702 $$ = $1;
1703 $1->characts = $2;
1705 | opt_lvc opt_version {
1706 if(!win32)
1707 parser_warning("VERSION not supported in 16-bit mode\n");
1708 if($1->version)
1709 yyerror("Version already defined");
1710 $$ = $1;
1711 $1->version = $2;
1716 * This here is another s/r conflict on {bi,u}nary + and -.
1717 * It is due to the look-ahead which must determine when the
1718 * rule opt_language ends. It could be solved with adding a
1719 * tNL at the end, but that seems unreasonable to do.
1720 * The conflict is now moved to the expression handling below.
1722 opt_language
1723 : tLANGUAGE expr ',' expr { $$ = MAKELANGID($2, $4);
1724 if (get_language_codepage($$) == -1)
1725 yyerror( "Language %04x is not supported", $$);
1729 opt_characts
1730 : tCHARACTERISTICS expr { $$ = $2; }
1733 opt_version
1734 : tVERSION expr { $$ = $2; }
1737 /* ------------------------------ Raw data handling ------------------------------ */
1738 raw_data: opt_lvc tBEGIN raw_elements tEND {
1739 if($1)
1741 $3->lvc = *($1);
1742 free($1);
1745 if(!$3->lvc.language)
1746 $3->lvc.language = currentlanguage;
1748 $$ = $3;
1752 raw_elements
1753 : tRAWDATA { $$ = $1; }
1754 | tNUMBER { $$ = int2raw_data($1); }
1755 | '-' tNUMBER { $$ = int2raw_data(-($2)); }
1756 | tLNUMBER { $$ = long2raw_data($1); }
1757 | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
1758 | tSTRING { $$ = str2raw_data($1); }
1759 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1760 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1761 | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
1762 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1763 | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
1764 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1767 /* File data or raw data */
1768 file_raw: filename { $$ = load_file($1,currentlanguage); }
1769 | raw_data { $$ = $1; }
1772 /* ------------------------------ Win32 expressions ------------------------------ */
1773 /* All win16 numbers are also handled here. This is inconsistent with MS
1774 * resource compiler, but what the heck, it's just handy to have.
1776 e_expr : /* Empty */ { $$ = 0; }
1777 | expr { $$ = new_int($1); }
1780 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1781 expr : xpr { $$ = ($1); }
1784 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1785 | xpr '-' xpr { $$ = ($1) - ($3); }
1786 | xpr '|' xpr { $$ = ($1) | ($3); }
1787 | xpr '&' xpr { $$ = ($1) & ($3); }
1788 | xpr '*' xpr { $$ = ($1) * ($3); }
1789 | xpr '/' xpr { $$ = ($1) / ($3); }
1790 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1791 | '~' xpr { $$ = ~($2); }
1792 | '-' xpr %prec pUPM { $$ = -($2); }
1793 | '+' xpr %prec pUPM { $$ = $2; }
1794 | '(' xpr ')' { $$ = $2; }
1795 | any_num { $$ = $1; }
1796 | tNOT any_num { $$ = ~($2); }
1799 any_num : tNUMBER { $$ = $1; }
1800 | tLNUMBER { $$ = $1; }
1804 /* Dialog specific functions */
1805 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1807 assert(dlg != NULL);
1808 if(dlg->style == NULL)
1810 dlg->style = new_style(0,0);
1813 if(dlg->gotstyle)
1815 parser_warning("Style already defined, or-ing together\n");
1817 else
1819 dlg->style->or_mask = 0;
1820 dlg->style->and_mask = 0;
1822 dlg->style->or_mask |= st->or_mask;
1823 dlg->style->and_mask |= st->and_mask;
1824 dlg->gotstyle = TRUE;
1825 free(st);
1826 return dlg;
1829 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1831 assert(dlg != NULL);
1832 if(dlg->exstyle == NULL)
1834 dlg->exstyle = new_style(0,0);
1837 if(dlg->gotexstyle)
1839 parser_warning("ExStyle already defined, or-ing together\n");
1841 else
1843 dlg->exstyle->or_mask = 0;
1844 dlg->exstyle->and_mask = 0;
1846 dlg->exstyle->or_mask |= st->or_mask;
1847 dlg->exstyle->and_mask |= st->and_mask;
1848 dlg->gotexstyle = TRUE;
1849 free(st);
1850 return dlg;
1853 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1855 assert(dlg != NULL);
1856 if(dlg->title)
1857 yyerror("Caption already defined");
1858 dlg->title = s;
1859 return dlg;
1862 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1864 assert(dlg != NULL);
1865 if(dlg->font)
1866 yyerror("Font already defined");
1867 dlg->font = f;
1868 return dlg;
1871 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1873 assert(dlg != NULL);
1874 if(dlg->dlgclass)
1875 yyerror("Class already defined");
1876 dlg->dlgclass = n;
1877 return dlg;
1880 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1882 assert(dlg != NULL);
1883 if(dlg->menu)
1884 yyerror("Menu already defined");
1885 dlg->menu = m;
1886 return dlg;
1889 static dialog_t *dialog_language(language_t l, dialog_t *dlg)
1891 assert(dlg != NULL);
1892 if(dlg->lvc.language)
1893 yyerror("Language already defined");
1894 dlg->lvc.language = l;
1895 return dlg;
1898 static dialog_t *dialog_characteristics(characts_t c, dialog_t *dlg)
1900 assert(dlg != NULL);
1901 if(dlg->lvc.characts)
1902 yyerror("Characteristics already defined");
1903 dlg->lvc.characts = c;
1904 return dlg;
1907 static dialog_t *dialog_version(version_t v, dialog_t *dlg)
1909 assert(dlg != NULL);
1910 if(dlg->lvc.version)
1911 yyerror("Version already defined");
1912 dlg->lvc.version = v;
1913 return dlg;
1916 /* Controls specific functions */
1917 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1919 /* Hm... this seems to be jammed in at all time... */
1920 int defaultstyle = WS_CHILD | WS_VISIBLE;
1922 assert(ctrl != NULL);
1923 ctrl->prev = prev;
1925 if(prev)
1926 prev->next = ctrl;
1928 /* Check for duplicate identifiers */
1929 while (prev)
1931 if (ctrl->id != -1 && ctrl->id == prev->id)
1932 parser_warning("Duplicate dialog control id %d\n", ctrl->id);
1933 prev = prev->prev;
1936 if(type != -1)
1938 ctrl->ctlclass = new_name_id();
1939 ctrl->ctlclass->type = name_ord;
1940 ctrl->ctlclass->name.i_name = type;
1943 switch(type)
1945 case CT_BUTTON:
1946 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1947 defaultstyle |= WS_TABSTOP;
1948 break;
1949 case CT_EDIT:
1950 defaultstyle |= WS_TABSTOP | WS_BORDER;
1951 break;
1952 case CT_LISTBOX:
1953 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1954 break;
1955 case CT_COMBOBOX:
1956 if (!ctrl->gotstyle || !(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
1957 defaultstyle |= CBS_SIMPLE;
1958 break;
1959 case CT_STATIC:
1960 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1961 defaultstyle |= WS_GROUP;
1962 break;
1965 if(!ctrl->gotstyle) /* Handle default style setting */
1967 switch(type)
1969 case CT_EDIT:
1970 defaultstyle |= ES_LEFT;
1971 break;
1972 case CT_LISTBOX:
1973 defaultstyle |= LBS_NOTIFY;
1974 break;
1975 case CT_COMBOBOX:
1976 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
1977 break;
1978 case CT_SCROLLBAR:
1979 defaultstyle |= SBS_HORZ;
1980 break;
1981 case CT_BUTTON:
1982 switch(special_style)
1984 case BS_CHECKBOX:
1985 case BS_DEFPUSHBUTTON:
1986 case BS_PUSHBUTTON:
1987 /* case BS_PUSHBOX: */
1988 case BS_AUTORADIOBUTTON:
1989 case BS_AUTO3STATE:
1990 case BS_3STATE:
1991 case BS_AUTOCHECKBOX:
1992 defaultstyle |= WS_TABSTOP;
1993 break;
1994 default:
1995 parser_warning("Unknown default button control-style 0x%08x\n", special_style);
1996 case BS_GROUPBOX:
1997 case BS_RADIOBUTTON:
1998 break;
2000 break;
2002 case CT_STATIC:
2003 switch(special_style)
2005 case SS_LEFT:
2006 case SS_RIGHT:
2007 case SS_CENTER:
2008 defaultstyle |= WS_GROUP;
2009 break;
2010 case SS_ICON: /* Special case */
2011 break;
2012 default:
2013 parser_warning("Unknown default static control-style 0x%08x\n", special_style);
2014 break;
2016 break;
2017 case -1: /* Generic control */
2018 goto byebye;
2020 default:
2021 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2025 /* The SS_ICON flag is always forced in for icon controls */
2026 if(type == CT_STATIC && special_style == SS_ICON)
2027 defaultstyle |= SS_ICON;
2029 if (!ctrl->gotstyle)
2030 ctrl->style = new_style(0,0);
2032 /* combine all styles */
2033 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2034 ctrl->gotstyle = TRUE;
2035 byebye:
2036 /* combine with NOT mask */
2037 if (ctrl->gotstyle)
2039 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2040 ctrl->style->and_mask = 0;
2042 if (ctrl->gotexstyle)
2044 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2045 ctrl->exstyle->and_mask = 0;
2047 return ctrl;
2050 static int get_class_idW(const WCHAR *cc)
2052 static const WCHAR szBUTTON[] = {'B','U','T','T','O','N',0};
2053 static const WCHAR szCOMBOBOX[] = {'C','O','M','B','O','B','O','X',0};
2054 static const WCHAR szLISTBOX[] = {'L','I','S','T','B','O','X',0};
2055 static const WCHAR szEDIT[] = {'E','D','I','T',0};
2056 static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0};
2057 static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0};
2059 if(!compare_striW(szBUTTON, cc)) return CT_BUTTON;
2060 if(!compare_striW(szCOMBOBOX, cc)) return CT_COMBOBOX;
2061 if(!compare_striW(szLISTBOX, cc)) return CT_LISTBOX;
2062 if(!compare_striW(szEDIT, cc)) return CT_EDIT;
2063 if(!compare_striW(szSTATIC, cc)) return CT_STATIC;
2064 if(!compare_striW(szSCROLLBAR, cc)) return CT_SCROLLBAR;
2065 return -1;
2068 static int get_class_idA(const char *cc)
2070 if(!compare_striA("BUTTON", cc)) return CT_BUTTON;
2071 if(!compare_striA("COMBOBOX", cc)) return CT_COMBOBOX;
2072 if(!compare_striA("LISTBOX", cc)) return CT_LISTBOX;
2073 if(!compare_striA("EDIT", cc)) return CT_EDIT;
2074 if(!compare_striA("STATIC", cc)) return CT_STATIC;
2075 if(!compare_striA("SCROLLBAR", cc)) return CT_SCROLLBAR;
2076 return -1;
2080 static name_id_t *convert_ctlclass(name_id_t *cls)
2082 int iclass;
2084 if(cls->type == name_ord)
2085 return cls;
2086 assert(cls->type == name_str);
2087 if(cls->name.s_name->type == str_unicode)
2088 iclass = get_class_idW(cls->name.s_name->str.wstr);
2089 else
2090 iclass = get_class_idA(cls->name.s_name->str.cstr);
2092 if (iclass == -1)
2093 return cls; /* No default, return user controlclass */
2095 free(cls->name.s_name->str.cstr);
2096 free(cls->name.s_name);
2097 cls->type = name_ord;
2098 cls->name.i_name = iclass;
2099 return cls;
2102 /* Accelerator specific functions */
2103 static event_t *add_event(int key, int id, int flags, event_t *prev)
2105 event_t *ev = new_event();
2107 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2108 yyerror("Cannot use both ASCII and VIRTKEY");
2110 ev->key = key;
2111 ev->id = id;
2112 ev->flags = flags & ~WRC_AF_ASCII;
2113 ev->prev = prev;
2114 if(prev)
2115 prev->next = ev;
2116 return ev;
2119 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2121 event_t *ev = new_event();
2123 ev->str = 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 /* MenuEx specific functions */
2133 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2135 itemex_opt_t *opt = xmalloc(sizeof(itemex_opt_t));
2136 memset( opt, 0, sizeof(*opt) );
2137 opt->id = id;
2138 opt->type = type;
2139 opt->state = state;
2140 opt->helpid = helpid;
2141 return opt;
2144 /* Raw data functions */
2145 static raw_data_t *load_file(string_t *filename, language_t lang)
2147 FILE *fp = NULL;
2148 char *path, *name;
2149 raw_data_t *rd;
2151 if (filename->type == str_unicode)
2152 name = convert_string_utf8( filename, 0 );
2153 else
2154 name = xstrdup( filename->str.cstr );
2155 if (!(path = wpp_find_include(name, input_name)))
2156 yyerror("Cannot open file %s", name);
2157 if (!(fp = fopen( path, "rb" )))
2158 yyerror("Cannot open file %s", name);
2159 free( path );
2160 rd = new_raw_data();
2161 fseek(fp, 0, SEEK_END);
2162 rd->size = ftell(fp);
2163 fseek(fp, 0, SEEK_SET);
2164 if (rd->size)
2166 rd->data = xmalloc(rd->size);
2167 fread(rd->data, rd->size, 1, fp);
2169 else rd->data = NULL;
2170 fclose(fp);
2171 rd->lvc.language = lang;
2172 free(name);
2173 return rd;
2176 static raw_data_t *int2raw_data(int i)
2178 raw_data_t *rd;
2180 if( ( i >= 0 && (int)((unsigned short)i) != i) ||
2181 ( i < 0 && (int)((short)i) != i) )
2182 parser_warning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2184 rd = new_raw_data();
2185 rd->size = sizeof(short);
2186 rd->data = xmalloc(rd->size);
2187 rd->data[0] = i;
2188 rd->data[1] = i >> 8;
2189 return rd;
2192 static raw_data_t *long2raw_data(int i)
2194 raw_data_t *rd;
2195 rd = new_raw_data();
2196 rd->size = sizeof(int);
2197 rd->data = xmalloc(rd->size);
2198 rd->data[0] = i;
2199 rd->data[1] = i >> 8;
2200 rd->data[2] = i >> 16;
2201 rd->data[3] = i >> 24;
2202 return rd;
2205 static raw_data_t *str2raw_data(string_t *str)
2207 raw_data_t *rd;
2208 rd = new_raw_data();
2209 rd->size = str->size * (str->type == str_char ? 1 : 2);
2210 rd->data = xmalloc(rd->size);
2211 switch (str->type)
2213 case str_char:
2214 memcpy(rd->data, str->str.cstr, rd->size);
2215 break;
2216 case str_unicode:
2218 int i;
2219 for(i = 0; i < str->size; i++)
2221 rd->data[2*i + 0] = str->str.wstr[i];
2222 rd->data[2*i + 1] = str->str.wstr[i] >> 8;
2226 return rd;
2229 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2231 r1->data = xrealloc(r1->data, r1->size + r2->size);
2232 memcpy(r1->data + r1->size, r2->data, r2->size);
2233 r1->size += r2->size;
2234 return r1;
2237 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2239 raw_data_t *t = int2raw_data(i);
2240 merge_raw_data(r1, t);
2241 free(t->data);
2242 free(t);
2243 return r1;
2246 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2248 raw_data_t *t = long2raw_data(i);
2249 merge_raw_data(r1, t);
2250 free(t->data);
2251 free(t);
2252 return r1;
2255 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2257 raw_data_t *t = str2raw_data(str);
2258 merge_raw_data(r1, t);
2259 free(t->data);
2260 free(t);
2261 return r1;
2264 /* Function the go back in a list to get the head */
2265 static menu_item_t *get_item_head(menu_item_t *p)
2267 if(!p)
2268 return NULL;
2269 while(p->prev)
2270 p = p->prev;
2271 return p;
2274 static resource_t *get_resource_head(resource_t *p)
2276 if(!p)
2277 return NULL;
2278 while(p->prev)
2279 p = p->prev;
2280 return p;
2283 static ver_block_t *get_ver_block_head(ver_block_t *p)
2285 if(!p)
2286 return NULL;
2287 while(p->prev)
2288 p = p->prev;
2289 return p;
2292 static ver_value_t *get_ver_value_head(ver_value_t *p)
2294 if(!p)
2295 return NULL;
2296 while(p->prev)
2297 p = p->prev;
2298 return p;
2301 static control_t *get_control_head(control_t *p)
2303 if(!p)
2304 return NULL;
2305 while(p->prev)
2306 p = p->prev;
2307 return p;
2310 static event_t *get_event_head(event_t *p)
2312 if(!p)
2313 return NULL;
2314 while(p->prev)
2315 p = p->prev;
2316 return p;
2319 /* Find a stringtable with given language */
2320 static stringtable_t *find_stringtable(lvc_t *lvc)
2322 stringtable_t *stt;
2324 assert(lvc != NULL);
2326 if(!lvc->language)
2327 lvc->language = currentlanguage;
2329 for(stt = sttres; stt; stt = stt->next)
2331 if(stt->lvc.language == lvc->language)
2333 /* Found a table with the same language */
2334 /* The version and characteristics are now handled
2335 * in the generation of the individual stringtables.
2336 * This enables localized analysis.
2337 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2338 || (!stt->lvc.version && lvc->version)
2339 || (stt->lvc.version && !lvc->version))
2340 parser_warning("Stringtable's versions are not the same, using first definition\n");
2342 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2343 || (!stt->lvc.characts && lvc->characts)
2344 || (stt->lvc.characts && !lvc->characts))
2345 parser_warning("Stringtable's characteristics are not the same, using first definition\n");
2347 return stt;
2350 return NULL;
2353 /* qsort sorting function for string table entries */
2354 #define STE(p) ((const stt_entry_t *)(p))
2355 static int sort_stt_entry(const void *e1, const void *e2)
2357 return STE(e1)->id - STE(e2)->id;
2359 #undef STE
2361 static resource_t *build_stt_resources(stringtable_t *stthead)
2363 stringtable_t *stt;
2364 stringtable_t *newstt;
2365 resource_t *rsc;
2366 resource_t *rsclist = NULL;
2367 resource_t *rsctail = NULL;
2368 int i;
2369 int j;
2370 unsigned int andsum;
2371 unsigned int orsum;
2372 characts_t characts;
2373 version_t version;
2375 if(!stthead)
2376 return NULL;
2378 /* For all languages defined */
2379 for(stt = stthead; stt; stt = stt->next)
2381 assert(stt->nentries > 0);
2383 /* Sort the entries */
2384 if(stt->nentries > 1)
2385 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2387 for(i = 0; i < stt->nentries; )
2389 newstt = new_stringtable(&stt->lvc);
2390 newstt->entries = xmalloc(16 * sizeof(stt_entry_t));
2391 memset( newstt->entries, 0, 16 * sizeof(stt_entry_t) );
2392 newstt->nentries = 16;
2393 newstt->idbase = stt->entries[i].id & ~0xf;
2394 for(j = 0; j < 16 && i < stt->nentries; j++)
2396 if(stt->entries[i].id - newstt->idbase == j)
2398 newstt->entries[j] = stt->entries[i];
2399 i++;
2402 andsum = ~0;
2403 orsum = 0;
2404 characts = 0;
2405 version = 0;
2406 /* Check individual memory options and get
2407 * the first characteristics/version
2409 for(j = 0; j < 16; j++)
2411 if(!newstt->entries[j].str)
2412 continue;
2413 andsum &= newstt->entries[j].memopt;
2414 orsum |= newstt->entries[j].memopt;
2415 if(!characts)
2416 characts = newstt->entries[j].characts;
2417 if(!version)
2418 version = newstt->entries[j].version;
2420 if(andsum != orsum)
2422 warning("Stringtable's memory options are not equal (idbase: %d)\n", newstt->idbase);
2424 /* Check version and characteristics */
2425 for(j = 0; j < 16; j++)
2427 if(characts
2428 && newstt->entries[j].characts
2429 && newstt->entries[j].characts != characts)
2430 warning("Stringtable's characteristics are not the same (idbase: %d)\n", newstt->idbase);
2431 if(version
2432 && newstt->entries[j].version
2433 && newstt->entries[j].version != version)
2434 warning("Stringtable's versions are not the same (idbase: %d)\n", newstt->idbase);
2436 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2437 rsc->name = new_name_id();
2438 rsc->name->type = name_ord;
2439 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2440 rsc->memopt = andsum; /* Set to least common denominator */
2441 newstt->memopt = andsum;
2442 newstt->lvc.characts = characts;
2443 newstt->lvc.version = version;
2444 if(!rsclist)
2446 rsclist = rsc;
2447 rsctail = rsc;
2449 else
2451 rsctail->next = rsc;
2452 rsc->prev = rsctail;
2453 rsctail = rsc;
2457 return rsclist;
2461 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2463 idrec->prev = prev;
2464 if(prev)
2465 prev->next = idrec;
2467 return idrec;
2470 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2472 if(!p)
2474 *nitems = 0;
2475 return NULL;
2478 *nitems = 1;
2480 while(p->prev)
2482 (*nitems)++;
2483 p = p->prev;
2486 return p;
2489 static string_t *make_filename(string_t *str)
2491 int i;
2493 if(str->type == str_char)
2495 char *dst = str->str.cstr;
2497 /* Remove escaped backslash and convert to forward */
2498 for (i = 0; i < str->size; i++)
2500 if (str->str.cstr[i] == '\\')
2502 if (i < str->size - 1 && str->str.cstr[i + 1] == '\\') i++;
2503 *dst++ = '/';
2505 else *dst++ = str->str.cstr[i];
2507 *dst = 0;
2508 str->size = dst - str->str.cstr;
2510 else
2512 WCHAR *dst = str->str.wstr;
2514 /* Remove escaped backslash and convert to forward */
2515 for (i = 0; i < str->size; i++)
2517 if (str->str.wstr[i] == '\\')
2519 if (i < str->size - 1 && str->str.wstr[i + 1] == '\\') i++;
2520 *dst++ = '/';
2522 else *dst++ = str->str.wstr[i];
2524 *dst = 0;
2525 str->size = dst - str->str.wstr;
2527 return str;
2531 * Process all resources to extract fonts and build
2532 * a fontdir resource.
2534 * Note: MS' resource compiler (build 1472) does not
2535 * handle font resources with different languages.
2536 * The fontdir is generated in the last active language
2537 * and font identifiers must be unique across the entire
2538 * source.
2539 * This is not logical considering the localization
2540 * constraints of all other resource types. MS has,
2541 * most probably, never testet localized fonts. However,
2542 * using fontresources is rare, so it might not occur
2543 * in normal applications.
2544 * Wine does require better localization because a lot
2545 * of languages are coded into the same executable.
2546 * Therefore, I will generate fontdirs for *each*
2547 * localized set of fonts.
2549 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2551 static int once = 0;
2552 if(!once)
2554 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)\n", fnt, nfnt);
2555 once++;
2557 return NULL;
2560 static resource_t *build_fontdirs(resource_t *tail)
2562 resource_t *rsc;
2563 resource_t *lst = NULL;
2564 resource_t **fnt = NULL; /* List of all fonts */
2565 int nfnt = 0;
2566 resource_t **fnd = NULL; /* List of all fontdirs */
2567 int nfnd = 0;
2568 resource_t **lanfnt = NULL;
2569 int nlanfnt = 0;
2570 int i;
2571 name_id_t nid;
2572 string_t str;
2573 int fntleft;
2575 nid.type = name_str;
2576 nid.name.s_name = &str;
2577 str.type = str_char;
2578 str.str.cstr = xstrdup("FONTDIR");
2579 str.size = 7;
2581 /* Extract all fonts and fontdirs */
2582 for(rsc = tail; rsc; rsc = rsc->prev)
2584 if(rsc->type == res_fnt)
2586 nfnt++;
2587 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2588 fnt[nfnt-1] = rsc;
2590 else if(rsc->type == res_fntdir)
2592 nfnd++;
2593 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2594 fnd[nfnd-1] = rsc;
2598 /* Verify the name of the present fontdirs */
2599 for(i = 0; i < nfnd; i++)
2601 if(compare_name_id(&nid, fnd[i]->name))
2603 warning("User supplied FONTDIR entry has an invalid name '%s', ignored\n",
2604 get_nameid_str(fnd[i]->name));
2605 fnd[i] = NULL;
2609 /* Sanity check */
2610 if(nfnt == 0)
2612 if(nfnd != 0)
2613 warning("Found %d FONTDIR entries without any fonts present\n", nfnd);
2614 goto clean;
2617 /* Copy space */
2618 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2619 memset( lanfnt, 0, nfnt * sizeof(*lanfnt));
2621 /* Get all fonts covered by fontdirs */
2622 for(i = 0; i < nfnd; i++)
2624 int j;
2626 if(!fnd[i])
2627 continue;
2628 for(j = 0; j < nfnt; j++)
2630 if(!fnt[j])
2631 continue;
2632 if(fnt[j]->lan == fnd[i]->lan)
2634 lanfnt[nlanfnt] = fnt[j];
2635 nlanfnt++;
2636 fnt[j] = NULL;
2641 /* We now have fonts left where we need to make a fontdir resource */
2642 for(i = fntleft = 0; i < nfnt; i++)
2644 if(fnt[i])
2645 fntleft++;
2647 while(fntleft)
2649 /* Get fonts of same language in lanfnt[] */
2650 for(i = nlanfnt = 0; i < nfnt; i++)
2652 if(fnt[i])
2654 if(!nlanfnt)
2656 addlanfnt:
2657 lanfnt[nlanfnt] = fnt[i];
2658 nlanfnt++;
2659 fnt[i] = NULL;
2660 fntleft--;
2662 else if(fnt[i]->lan == lanfnt[0]->lan)
2663 goto addlanfnt;
2666 /* and build a fontdir */
2667 rsc = build_fontdir(lanfnt, nlanfnt);
2668 if(rsc)
2670 if(lst)
2672 lst->next = rsc;
2673 rsc->prev = lst;
2675 lst = rsc;
2679 free(lanfnt);
2680 clean:
2681 free(fnt);
2682 free(fnd);
2683 free(str.str.cstr);
2684 return lst;
2688 * This gets invoked to determine whether the next resource
2689 * is to be of a standard-type (e.g. bitmaps etc.), or should
2690 * be a user-type resource. This function is required because
2691 * there is the _possibility_ of a lookahead token in the
2692 * parser, which is generated from the "expr" state in the
2693 * "nameid" parsing.
2695 * The general resource format is:
2696 * <identifier> <type> <flags> <resourcebody>
2698 * The <identifier> can either be tIDENT or "expr". The latter
2699 * will always generate a lookahead, which is the <type> of the
2700 * resource to parse. Otherwise, we need to get a new token from
2701 * the scanner to determine the next step.
2703 * The problem arrises when <type> is numerical. This case should
2704 * map onto default resource-types and be parsed as such instead
2705 * of being mapped onto user-type resources.
2707 * The trick lies in the fact that yacc (bison) doesn't care about
2708 * intermediate changes of the lookahead while reducing a rule. We
2709 * simply replace the lookahead with a token that will result in
2710 * a shift to the appropriate rule for the specific resource-type.
2712 static int rsrcid_to_token(int lookahead)
2714 int token;
2716 /* Get a token if we don't have one yet */
2717 if(lookahead == YYEMPTY)
2718 lookahead = yylex();
2720 /* Only numbers are possibly interesting */
2721 switch(lookahead)
2723 case tNUMBER:
2724 case tLNUMBER:
2725 break;
2726 default:
2727 return lookahead;
2730 token = lookahead;
2732 switch(yylval.num)
2734 case WRC_RT_CURSOR:
2735 token = tCURSOR;
2736 break;
2737 case WRC_RT_ICON:
2738 token = tICON;
2739 break;
2740 case WRC_RT_BITMAP:
2741 token = tBITMAP;
2742 break;
2743 case WRC_RT_FONT:
2744 token = tFONT;
2745 break;
2746 case WRC_RT_FONTDIR:
2747 token = tFONTDIR;
2748 break;
2749 case WRC_RT_RCDATA:
2750 token = tRCDATA;
2751 break;
2752 case WRC_RT_MESSAGETABLE:
2753 token = tMESSAGETABLE;
2754 break;
2755 case WRC_RT_DLGINIT:
2756 token = tDLGINIT;
2757 break;
2758 case WRC_RT_ACCELERATOR:
2759 token = tACCELERATORS;
2760 break;
2761 case WRC_RT_MENU:
2762 token = tMENU;
2763 break;
2764 case WRC_RT_DIALOG:
2765 token = tDIALOG;
2766 break;
2767 case WRC_RT_VERSION:
2768 token = tVERSIONINFO;
2769 break;
2770 case WRC_RT_TOOLBAR:
2771 token = tTOOLBAR;
2772 break;
2773 case WRC_RT_HTML:
2774 token = tHTML;
2775 break;
2777 case WRC_RT_STRING:
2778 break;
2780 case WRC_RT_ANICURSOR:
2781 case WRC_RT_ANIICON:
2782 case WRC_RT_GROUP_CURSOR:
2783 case WRC_RT_GROUP_ICON:
2784 parser_warning("Usertype uses reserved type ID %d, which is auto-generated\n", yylval.num);
2785 return lookahead;
2787 case WRC_RT_DLGINCLUDE:
2788 case WRC_RT_PLUGPLAY:
2789 case WRC_RT_VXD:
2790 parser_warning("Usertype uses reserved type ID %d, which is not supported by wrc yet\n", yylval.num);
2791 default:
2792 return lookahead;
2795 return token;