msi: Add some registry reading macro functions.
[wine/wine-kai.git] / tools / wrc / parser.y
blob252606cd64f0ad5fd23e93b99fade3c7e5629f8f
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>
132 #ifdef HAVE_ALLOCA_H
133 #include <alloca.h>
134 #endif
136 #include "wrc.h"
137 #include "utils.h"
138 #include "newstruc.h"
139 #include "dumpres.h"
140 #include "wine/wpp.h"
141 #include "wine/unicode.h"
142 #include "parser.h"
143 #include "windef.h"
144 #include "winbase.h"
145 #include "wingdi.h"
146 #include "winuser.h"
148 #if defined(YYBYACC)
149 /* Berkeley yacc (byacc) doesn't seem to know about these */
150 /* Some *BSD supplied versions do define these though */
151 # ifndef YYEMPTY
152 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
153 # endif
154 # ifndef YYLEX
155 # define YYLEX yylex()
156 # endif
158 #elif defined(YYBISON)
159 /* Bison was used for original development */
160 /* #define YYEMPTY -2 */
161 /* #define YYLEX yylex() */
163 #else
164 /* No yacc we know yet */
165 # if !defined(YYEMPTY) || !defined(YYLEX)
166 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
167 # elif defined(__GNUC__) /* gcc defines the #warning directive */
168 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
169 /* #else we just take a chance that it works... */
170 # endif
171 #endif
173 int want_nl = 0; /* Signal flex that we need the next newline */
174 int want_id = 0; /* Signal flex that we need the next identifier */
175 stringtable_t *tagstt; /* Stringtable tag.
176 * It is set while parsing a stringtable to one of
177 * the stringtables in the sttres list or a new one
178 * if the language was not parsed before.
180 stringtable_t *sttres; /* Stringtable resources. This holds the list of
181 * stringtables with different lanuages
183 static int dont_want_id = 0; /* See language parsing for details */
185 /* Set to the current options of the currently scanning stringtable */
186 static int *tagstt_memopt;
187 static characts_t *tagstt_characts;
188 static version_t *tagstt_version;
190 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
192 /* Prototypes of here defined functions */
193 static event_t *get_event_head(event_t *p);
194 static control_t *get_control_head(control_t *p);
195 static ver_value_t *get_ver_value_head(ver_value_t *p);
196 static ver_block_t *get_ver_block_head(ver_block_t *p);
197 static resource_t *get_resource_head(resource_t *p);
198 static menuex_item_t *get_itemex_head(menuex_item_t *p);
199 static menu_item_t *get_item_head(menu_item_t *p);
200 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
201 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
202 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
203 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
204 static raw_data_t *str2raw_data(string_t *str);
205 static raw_data_t *int2raw_data(int i);
206 static raw_data_t *long2raw_data(int i);
207 static raw_data_t *load_file(string_t *name, language_t *lang);
208 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
209 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
210 static event_t *add_event(int key, int id, int flags, event_t *prev);
211 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
212 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
213 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
214 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
215 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
216 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
217 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
218 static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
219 static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
220 static name_id_t *convert_ctlclass(name_id_t *cls);
221 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
222 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
223 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
224 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
225 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
226 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
227 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
228 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
229 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
230 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
231 static resource_t *build_stt_resources(stringtable_t *stthead);
232 static stringtable_t *find_stringtable(lvc_t *lvc);
233 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
234 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
235 static string_t *make_filename(string_t *s);
236 static resource_t *build_fontdirs(resource_t *tail);
237 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
238 static int rsrcid_to_token(int lookahead);
241 %union{
242 string_t *str;
243 int num;
244 int *iptr;
245 char *cptr;
246 resource_t *res;
247 accelerator_t *acc;
248 bitmap_t *bmp;
249 dialog_t *dlg;
250 dialogex_t *dlgex;
251 font_t *fnt;
252 fontdir_t *fnd;
253 menu_t *men;
254 menuex_t *menex;
255 html_t *html;
256 rcdata_t *rdt;
257 stringtable_t *stt;
258 stt_entry_t *stte;
259 user_t *usr;
260 messagetable_t *msg;
261 versioninfo_t *veri;
262 control_t *ctl;
263 name_id_t *nid;
264 font_id_t *fntid;
265 language_t *lan;
266 version_t *ver;
267 characts_t *chars;
268 event_t *event;
269 menu_item_t *menitm;
270 menuex_item_t *menexitm;
271 itemex_opt_t *exopt;
272 raw_data_t *raw;
273 lvc_t *lvc;
274 ver_value_t *val;
275 ver_block_t *blk;
276 ver_words_t *verw;
277 toolbar_t *tlbar;
278 toolbar_item_t *tlbarItems;
279 dlginit_t *dginit;
280 style_pair_t *styles;
281 style_t *style;
282 ani_any_t *ani;
285 %token tNL
286 %token <num> tNUMBER tLNUMBER
287 %token <str> tSTRING tIDENT tFILENAME
288 %token <raw> tRAWDATA
289 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
290 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
291 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
292 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
293 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
294 %token tCONTROL tEDITTEXT
295 %token tRTEXT tCTEXT tLTEXT
296 %token tBLOCK tVALUE
297 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
298 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
299 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
300 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
301 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
302 %token tHELP
303 %token tTOOLBAR tBUTTON
304 %token tBEGIN tEND
305 %token tDLGINIT
306 %left '|'
307 %left '^'
308 %left '&'
309 %left '+' '-'
310 %left '*' '/'
311 %right '~' tNOT
312 %left pUPM
314 %type <res> resource_file resource resources resource_definition
315 %type <stt> stringtable strings
316 %type <fnt> font
317 %type <fnd> fontdir
318 %type <acc> accelerators
319 %type <event> events
320 %type <bmp> bitmap
321 %type <ani> cursor icon
322 %type <dlg> dialog dlg_attributes
323 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
324 %type <iptr> helpid
325 %type <dlgex> dialogex dlgex_attribs
326 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
327 %type <html> html
328 %type <rdt> rcdata
329 %type <raw> raw_data raw_elements opt_data file_raw
330 %type <veri> versioninfo fix_version
331 %type <verw> ver_words
332 %type <blk> ver_blocks ver_block
333 %type <val> ver_values ver_value
334 %type <men> menu
335 %type <menitm> item_definitions menu_body
336 %type <menex> menuex
337 %type <menexitm> itemex_definitions menuex_body
338 %type <exopt> itemex_p_options itemex_options
339 %type <msg> messagetable
340 %type <usr> userres
341 %type <num> item_options
342 %type <nid> nameid nameid_s ctlclass usertype
343 %type <num> acc_opt acc accs
344 %type <iptr> loadmemopts lamo lama
345 %type <fntid> opt_font opt_exfont opt_expr
346 %type <lvc> opt_lvc
347 %type <lan> opt_language
348 %type <chars> opt_characts
349 %type <ver> opt_version
350 %type <num> expr xpr
351 %type <iptr> e_expr
352 %type <tlbar> toolbar
353 %type <tlbarItems> toolbar_items
354 %type <dginit> dlginit
355 %type <styles> optional_style_pair
356 %type <num> any_num
357 %type <style> style
358 %type <str> filename
362 resource_file
363 : resources {
364 resource_t *rsc;
365 /* First add stringtables to the resource-list */
366 rsc = build_stt_resources(sttres);
367 /* 'build_stt_resources' returns a head and $1 is a tail */
368 if($1)
370 $1->next = rsc;
371 if(rsc)
372 rsc->prev = $1;
374 else
375 $1 = rsc;
376 /* Find the tail again */
377 while($1 && $1->next)
378 $1 = $1->next;
379 /* Now add any fontdirecory */
380 rsc = build_fontdirs($1);
381 /* 'build_fontdir' returns a head and $1 is a tail */
382 if($1)
384 $1->next = rsc;
385 if(rsc)
386 rsc->prev = $1;
388 else
389 $1 = rsc;
390 /* Final statement before were done */
391 resource_top = get_resource_head($1);
395 /* Resources are put into a linked list */
396 resources
397 : /* Empty */ { $$ = NULL; want_id = 1; }
398 | resources resource {
399 if($2)
401 resource_t *tail = $2;
402 resource_t *head = $2;
403 while(tail->next)
404 tail = tail->next;
405 while(head->prev)
406 head = head->prev;
407 head->prev = $1;
408 if($1)
409 $1->next = head;
410 $$ = tail;
411 /* Check for duplicate identifiers */
412 while($1 && head)
414 resource_t *rsc = $1;
415 while(rsc)
417 if(rsc->type == head->type
418 && rsc->lan->id == head->lan->id
419 && rsc->lan->sub == head->lan->sub
420 && !compare_name_id(rsc->name, head->name))
422 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
424 rsc = rsc->prev;
426 head = head->next;
429 else if($1)
431 resource_t *tail = $1;
432 while(tail->next)
433 tail = tail->next;
434 $$ = tail;
436 else
437 $$ = NULL;
439 if(!dont_want_id) /* See comments in language parsing below */
440 want_id = 1;
441 dont_want_id = 0;
444 * The following newline rule will never get reduced because we never
445 * get the tNL token, unless we explicitely set the 'want_nl'
446 * flag, which we don't.
447 * The *ONLY* reason for this to be here is because Berkeley
448 * yacc (byacc), at least version 1.9, has a bug.
449 * (identified in the generated parser on the second
450 * line with:
451 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
453 * This extra rule fixes it.
454 * The problem is that the expression handling rule "expr: xpr"
455 * is not reduced on non-terminal tokens, defined above in the
456 * %token declarations. Token tNL is the only non-terminal that
457 * can occur. The error becomes visible in the language parsing
458 * rule below, which looks at the look-ahead token and tests it
459 * for tNL. However, byacc already generates an error upon reading
460 * the token instead of keeping it as a lookahead. The reason
461 * lies in the lack of a $default transition in the "expr : xpr . "
462 * state (currently state 25). It is probably omitted because tNL
463 * is a non-terminal and the state contains 2 s/r conflicts. The
464 * state enumerates all possible transitions instead of using a
465 * $default transition.
466 * All in all, it is a bug in byacc. (period)
468 | resources tNL
472 /* Parse top level resource definitions etc. */
473 resource
474 : expr usrcvt resource_definition {
475 $$ = $3;
476 if($$)
478 if($1 > 65535 || $1 < -32768)
479 yyerror("Resource's ID out of range (%d)", $1);
480 $$->name = new_name_id();
481 $$->name->type = name_ord;
482 $$->name->name.i_name = $1;
483 chat("Got %s (%d)", get_typename($3), $$->name->name.i_name);
486 | tIDENT usrcvt resource_definition {
487 $$ = $3;
488 if($$)
490 $$->name = new_name_id();
491 $$->name->type = name_str;
492 $$->name->name.s_name = $1;
493 chat("Got %s (%s)", get_typename($3), $$->name->name.s_name->str.cstr);
496 | stringtable {
497 /* Don't do anything, stringtables are converted to
498 * resource_t structures when we are finished parsing and
499 * the final rule of the parser is reduced (see above)
501 $$ = NULL;
502 chat("Got STRINGTABLE");
504 | tLANGUAGE {want_nl = 1; } expr ',' expr {
505 /* We *NEED* the newline to delimit the expression.
506 * Otherwise, we would not be able to set the next
507 * want_id anymore because of the token-lookahead.
509 * However, we can test the lookahead-token for
510 * being "non-expression" type, in which case we
511 * continue. Fortunately, tNL is the only token that
512 * will break expression parsing and is implicitely
513 * void, so we just remove it. This scheme makes it
514 * possible to do some (not all) fancy preprocessor
515 * stuff.
516 * BTW, we also need to make sure that the next
517 * reduction of 'resources' above will *not* set
518 * want_id because we already have a lookahead that
519 * cannot be undone.
521 if(yychar != YYEMPTY && yychar != tNL)
522 dont_want_id = 1;
524 if(yychar == tNL)
525 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
526 /* direct access to yychar in rule 'usrcvt' below. */
527 else if(yychar == tIDENT)
528 yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
530 want_nl = 0; /* We don't want it anymore if we didn't get it */
532 if(!win32)
533 yywarning("LANGUAGE not supported in 16-bit mode");
534 if(currentlanguage)
535 free(currentlanguage);
536 if (get_language_codepage($3, $5) == -1)
537 yyerror( "Language %04x is not supported", ($5<<10) + $3);
538 currentlanguage = new_language($3, $5);
539 $$ = NULL;
540 chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
545 * Remapping of numerical resource types
546 * (see also comment of called function below)
548 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
552 * Get a valid name/id
554 nameid : expr {
555 if($1 > 65535 || $1 < -32768)
556 yyerror("Resource's ID out of range (%d)", $1);
557 $$ = new_name_id();
558 $$->type = name_ord;
559 $$->name.i_name = $1;
561 | tIDENT {
562 $$ = new_name_id();
563 $$->type = name_str;
564 $$->name.s_name = $1;
569 * Extra string recognition for CLASS statement in dialogs
571 nameid_s: nameid { $$ = $1; }
572 | tSTRING {
573 $$ = new_name_id();
574 $$->type = name_str;
575 $$->name.s_name = $1;
579 /* get the value for a single resource*/
580 resource_definition
581 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
582 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
583 | cursor {
584 resource_t *rsc;
585 if($1->type == res_anicur)
587 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
589 else if($1->type == res_curg)
591 cursor_t *cur;
592 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
593 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
595 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
596 rsc->prev->next = rsc;
597 rsc = rsc->prev;
598 rsc->name = new_name_id();
599 rsc->name->type = name_ord;
600 rsc->name->name.i_name = cur->id;
603 else
604 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
605 free($1);
607 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
608 | dialogex {
609 if(win32)
610 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
611 else
612 $$ = NULL;
614 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
615 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
616 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
617 | icon {
618 resource_t *rsc;
619 if($1->type == res_aniico)
621 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
623 else if($1->type == res_icog)
625 icon_t *ico;
626 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
627 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
629 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
630 rsc->prev->next = rsc;
631 rsc = rsc->prev;
632 rsc->name = new_name_id();
633 rsc->name->type = name_ord;
634 rsc->name->name.i_name = ico->id;
637 else
638 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
639 free($1);
641 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
642 | menuex {
643 if(win32)
644 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
645 else
646 $$ = NULL;
648 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
649 | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
650 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
651 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
652 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
653 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
657 filename: tFILENAME { $$ = make_filename($1); }
658 | tIDENT { $$ = make_filename($1); }
659 | tSTRING { $$ = make_filename($1); }
662 /* ------------------------------ Bitmap ------------------------------ */
663 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
666 /* ------------------------------ Cursor ------------------------------ */
667 cursor : tCURSOR loadmemopts file_raw {
668 $$ = new_ani_any();
669 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
671 $$->type = res_anicur;
672 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
674 else
676 $$->type = res_curg;
677 $$->u.curg = new_cursor_group($3, $2);
682 /* ------------------------------ Icon ------------------------------ */
683 icon : tICON loadmemopts file_raw {
684 $$ = new_ani_any();
685 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
687 $$->type = res_aniico;
688 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
690 else
692 $$->type = res_icog;
693 $$->u.icog = new_icon_group($3, $2);
698 /* ------------------------------ Font ------------------------------ */
700 * The reading of raw_data for fonts is a Borland BRC
701 * extension. MS generates an error. However, it is
702 * most logical to support this, considering how wine
703 * enters things in CVS (ascii).
705 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
709 * The fontdir is a Borland BRC extension which only
710 * reads the data as 'raw_data' from the file.
711 * I don't know whether it is interpreted.
712 * The fontdir is generated if it was not present and
713 * fonts are defined in the source.
715 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
718 /* ------------------------------ MessageTable ------------------------------ */
719 /* It might be interesting to implement the MS Message compiler here as well
720 * to get everything in one source. Might be a future project.
722 messagetable
723 : tMESSAGETABLE loadmemopts file_raw {
724 if(!win32)
725 yywarning("MESSAGETABLE not supported in 16-bit mode");
726 $$ = new_messagetable($3, $2);
730 /* ------------------------------ HTML ------------------------------ */
731 html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
734 /* ------------------------------ RCData ------------------------------ */
735 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
738 /* ------------------------------ DLGINIT ------------------------------ */
739 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
742 /* ------------------------------ UserType ------------------------------ */
743 userres : usertype loadmemopts file_raw {
744 #ifdef WORDS_BIGENDIAN
745 if(pedantic && byteorder != WRC_BO_LITTLE)
746 #else
747 if(pedantic && byteorder == WRC_BO_BIG)
748 #endif
749 yywarning("Byteordering is not little-endian and type cannot be interpreted");
750 $$ = new_user($1, $3, $2);
754 usertype: tNUMBER {
755 $$ = new_name_id();
756 $$->type = name_ord;
757 $$->name.i_name = $1;
759 | tIDENT {
760 $$ = new_name_id();
761 $$->type = name_str;
762 $$->name.s_name = $1;
766 /* ------------------------------ Accelerator ------------------------------ */
767 accelerators
768 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
769 $$ = new_accelerator();
770 if($2)
772 $$->memopt = *($2);
773 free($2);
775 else
777 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
779 if(!$5)
780 yyerror("Accelerator table must have at least one entry");
781 $$->events = get_event_head($5);
782 if($3)
784 $$->lvc = *($3);
785 free($3);
787 if(!$$->lvc.language)
788 $$->lvc.language = dup_language(currentlanguage);
792 events : /* Empty */ { $$=NULL; }
793 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
794 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
798 * The empty rule generates a s/r conflict because of {bi,u}nary expr
799 * on - and +. It cannot be solved in any way because it is the same as
800 * the if/then/else problem (LALR(1) problem). The conflict is moved
801 * away by forcing it to be in the expression handling below.
803 acc_opt : /* Empty */ { $$ = 0; }
804 | ',' accs { $$ = $2; }
807 accs : acc { $$ = $1; }
808 | accs ',' acc { $$ = $1 | $3; }
811 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
812 | tSHIFT { $$ = WRC_AF_SHIFT; }
813 | tCONTROL { $$ = WRC_AF_CONTROL; }
814 | tALT { $$ = WRC_AF_ALT; }
815 | tASCII { $$ = WRC_AF_ASCII; }
816 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
819 /* ------------------------------ Dialog ------------------------------ */
820 /* FIXME: Support EXSTYLE in the dialog line itself */
821 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
822 tBEGIN ctrls tEND {
823 if($2)
825 $10->memopt = *($2);
826 free($2);
828 else
829 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
830 $10->x = $3;
831 $10->y = $5;
832 $10->width = $7;
833 $10->height = $9;
834 $10->controls = get_control_head($12);
835 $$ = $10;
836 if(!$$->gotstyle)
838 $$->style = new_style(0,0);
839 $$->style->or_mask = WS_POPUP;
840 $$->gotstyle = TRUE;
842 if($$->title)
843 $$->style->or_mask |= WS_CAPTION;
844 if($$->font)
845 $$->style->or_mask |= DS_SETFONT;
847 $$->style->or_mask &= ~($$->style->and_mask);
848 $$->style->and_mask = 0;
850 if(!$$->lvc.language)
851 $$->lvc.language = dup_language(currentlanguage);
855 dlg_attributes
856 : /* Empty */ { $$=new_dialog(); }
857 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
858 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
859 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
860 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
861 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
862 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
863 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
864 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
865 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
868 ctrls : /* Empty */ { $$ = NULL; }
869 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
870 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
871 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
872 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
873 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
874 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
875 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
876 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
877 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
878 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
879 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
880 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
881 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
882 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
883 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
884 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
885 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
886 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
887 /* special treatment for icons, as the extent is optional */
888 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
889 $10->title = $3;
890 $10->id = $5;
891 $10->x = $7;
892 $10->y = $9;
893 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
897 lab_ctrl
898 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
899 $$=new_control();
900 $$->title = $1;
901 $$->id = $3;
902 $$->x = $5;
903 $$->y = $7;
904 $$->width = $9;
905 $$->height = $11;
906 if($12)
908 $$->style = $12->style;
909 $$->gotstyle = TRUE;
910 if ($12->exstyle)
912 $$->exstyle = $12->exstyle;
913 $$->gotexstyle = TRUE;
915 free($12);
920 ctrl_desc
921 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
922 $$ = new_control();
923 $$->id = $1;
924 $$->x = $3;
925 $$->y = $5;
926 $$->width = $7;
927 $$->height = $9;
928 if($10)
930 $$->style = $10->style;
931 $$->gotstyle = TRUE;
932 if ($10->exstyle)
934 $$->exstyle = $10->exstyle;
935 $$->gotexstyle = TRUE;
937 free($10);
942 iconinfo: /* Empty */
943 { $$ = new_control(); }
945 | ',' expr ',' expr {
946 $$ = new_control();
947 $$->width = $2;
948 $$->height = $4;
950 | ',' expr ',' expr ',' style {
951 $$ = new_control();
952 $$->width = $2;
953 $$->height = $4;
954 $$->style = $6;
955 $$->gotstyle = TRUE;
957 | ',' expr ',' expr ',' style ',' style {
958 $$ = new_control();
959 $$->width = $2;
960 $$->height = $4;
961 $$->style = $6;
962 $$->gotstyle = TRUE;
963 $$->exstyle = $8;
964 $$->gotexstyle = TRUE;
968 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
969 $$=new_control();
970 $$->title = $1;
971 $$->id = $3;
972 $$->ctlclass = convert_ctlclass($5);
973 $$->style = $7;
974 $$->gotstyle = TRUE;
975 $$->x = $9;
976 $$->y = $11;
977 $$->width = $13;
978 $$->height = $15;
979 $$->exstyle = $17;
980 $$->gotexstyle = TRUE;
982 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
983 $$=new_control();
984 $$->title = $1;
985 $$->id = $3;
986 $$->ctlclass = convert_ctlclass($5);
987 $$->style = $7;
988 $$->gotstyle = TRUE;
989 $$->x = $9;
990 $$->y = $11;
991 $$->width = $13;
992 $$->height = $15;
996 opt_font
997 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
1000 /* ------------------------------ style flags ------------------------------ */
1001 optional_style_pair
1002 : /* Empty */ { $$ = NULL; }
1003 | ',' style { $$ = new_style_pair($2, 0); }
1004 | ',' style ',' style { $$ = new_style_pair($2, $4); }
1007 style
1008 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
1009 | '(' style ')' { $$ = $2; }
1010 | any_num { $$ = new_style($1, 0); }
1011 | tNOT any_num { $$ = new_style(0, $2); }
1014 ctlclass
1015 : expr {
1016 $$ = new_name_id();
1017 $$->type = name_ord;
1018 $$->name.i_name = $1;
1020 | tSTRING {
1021 $$ = new_name_id();
1022 $$->type = name_str;
1023 $$->name.s_name = $1;
1027 /* ------------------------------ DialogEx ------------------------------ */
1028 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
1029 tBEGIN exctrls tEND {
1030 if(!win32)
1031 yywarning("DIALOGEX not supported in 16-bit mode");
1032 if($2)
1034 $11->memopt = *($2);
1035 free($2);
1037 else
1038 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1039 $11->x = $3;
1040 $11->y = $5;
1041 $11->width = $7;
1042 $11->height = $9;
1043 if($10)
1045 $11->helpid = *($10);
1046 $11->gothelpid = TRUE;
1047 free($10);
1049 $11->controls = get_control_head($13);
1050 $$ = $11;
1052 assert($$->style != NULL);
1053 if(!$$->gotstyle)
1055 $$->style->or_mask = WS_POPUP;
1056 $$->gotstyle = TRUE;
1058 if($$->title)
1059 $$->style->or_mask |= WS_CAPTION;
1060 if($$->font)
1061 $$->style->or_mask |= DS_SETFONT;
1063 $$->style->or_mask &= ~($$->style->and_mask);
1064 $$->style->and_mask = 0;
1066 if(!$$->lvc.language)
1067 $$->lvc.language = dup_language(currentlanguage);
1071 dlgex_attribs
1072 : /* Empty */ { $$=new_dialogex(); }
1073 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
1074 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
1075 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1076 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1077 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1078 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1079 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1080 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1081 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1082 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1085 exctrls : /* Empty */ { $$ = NULL; }
1086 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1087 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1088 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1089 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1090 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1091 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1092 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1093 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1094 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1095 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1096 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1097 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1098 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1099 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1100 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1101 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1102 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1103 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1104 /* special treatment for icons, as the extent is optional */
1105 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1106 $10->title = $3;
1107 $10->id = $5;
1108 $10->x = $7;
1109 $10->y = $9;
1110 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1114 gen_exctrl
1115 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1116 expr ',' style helpid opt_data {
1117 $$=new_control();
1118 $$->title = $1;
1119 $$->id = $3;
1120 $$->ctlclass = convert_ctlclass($5);
1121 $$->style = $7;
1122 $$->gotstyle = TRUE;
1123 $$->x = $9;
1124 $$->y = $11;
1125 $$->width = $13;
1126 $$->height = $15;
1127 if($17)
1129 $$->exstyle = $17;
1130 $$->gotexstyle = TRUE;
1132 if($18)
1134 $$->helpid = *($18);
1135 $$->gothelpid = TRUE;
1136 free($18);
1138 $$->extra = $19;
1140 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1141 $$=new_control();
1142 $$->title = $1;
1143 $$->id = $3;
1144 $$->style = $7;
1145 $$->gotstyle = TRUE;
1146 $$->ctlclass = convert_ctlclass($5);
1147 $$->x = $9;
1148 $$->y = $11;
1149 $$->width = $13;
1150 $$->height = $15;
1151 $$->extra = $16;
1155 lab_exctrl
1156 : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1157 $$=new_control();
1158 $$->title = $1;
1159 $$->id = $3;
1160 $$->x = $5;
1161 $$->y = $7;
1162 $$->width = $9;
1163 $$->height = $11;
1164 if($12)
1166 $$->style = $12->style;
1167 $$->gotstyle = TRUE;
1169 if ($12->exstyle)
1171 $$->exstyle = $12->exstyle;
1172 $$->gotexstyle = TRUE;
1174 free($12);
1177 $$->extra = $14;
1181 exctrl_desc
1182 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1183 $$ = new_control();
1184 $$->id = $1;
1185 $$->x = $3;
1186 $$->y = $5;
1187 $$->width = $7;
1188 $$->height = $9;
1189 if($10)
1191 $$->style = $10->style;
1192 $$->gotstyle = TRUE;
1194 if ($10->exstyle)
1196 $$->exstyle = $10->exstyle;
1197 $$->gotexstyle = TRUE;
1199 free($10);
1201 $$->extra = $12;
1205 opt_data: /* Empty */ { $$ = NULL; }
1206 | raw_data { $$ = $1; }
1209 helpid : /* Empty */ { $$ = NULL; }
1210 | ',' expr { $$ = new_int($2); }
1213 opt_exfont
1214 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1218 * FIXME: This odd expression is here to nullify an extra token found
1219 * in some appstudio produced resources which appear to do nothing.
1221 opt_expr: /* Empty */ { $$ = NULL; }
1222 | ',' expr { $$ = NULL; }
1225 /* ------------------------------ Menu ------------------------------ */
1226 menu : tMENU loadmemopts opt_lvc menu_body {
1227 if(!$4)
1228 yyerror("Menu must contain items");
1229 $$ = new_menu();
1230 if($2)
1232 $$->memopt = *($2);
1233 free($2);
1235 else
1236 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1237 $$->items = get_item_head($4);
1238 if($3)
1240 $$->lvc = *($3);
1241 free($3);
1243 if(!$$->lvc.language)
1244 $$->lvc.language = dup_language(currentlanguage);
1248 menu_body
1249 : tBEGIN item_definitions tEND { $$ = $2; }
1252 item_definitions
1253 : /* Empty */ {$$ = NULL;}
1254 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1255 $$=new_menu_item();
1256 $$->prev = $1;
1257 if($1)
1258 $1->next = $$;
1259 $$->id = $5;
1260 $$->state = $6;
1261 $$->name = $3;
1263 | item_definitions tMENUITEM tSEPARATOR {
1264 $$=new_menu_item();
1265 $$->prev = $1;
1266 if($1)
1267 $1->next = $$;
1269 | item_definitions tPOPUP tSTRING item_options menu_body {
1270 $$ = new_menu_item();
1271 $$->prev = $1;
1272 if($1)
1273 $1->next = $$;
1274 $$->popup = get_item_head($5);
1275 $$->name = $3;
1279 /* NOTE: item_options is right recursive because it would introduce
1280 * a shift/reduce conflict on ',' in itemex_options due to the
1281 * empty rule here. The parser is now forced to look beyond the ','
1282 * before reducing (force shift).
1283 * Right recursion here is not a problem because we cannot expect
1284 * more than 7 parserstack places to be occupied while parsing this
1285 * (who would want to specify a MF_x flag twice?).
1287 item_options
1288 : /* Empty */ { $$ = 0; }
1289 | opt_comma tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1290 | opt_comma tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1291 | opt_comma tHELP item_options { $$ = $3 | MF_HELP; }
1292 | opt_comma tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1293 | opt_comma tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1294 | opt_comma tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1297 /* ------------------------------ MenuEx ------------------------------ */
1298 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1299 if(!win32)
1300 yywarning("MENUEX not supported in 16-bit mode");
1301 if(!$4)
1302 yyerror("MenuEx must contain items");
1303 $$ = new_menuex();
1304 if($2)
1306 $$->memopt = *($2);
1307 free($2);
1309 else
1310 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1311 $$->items = get_itemex_head($4);
1312 if($3)
1314 $$->lvc = *($3);
1315 free($3);
1317 if(!$$->lvc.language)
1318 $$->lvc.language = dup_language(currentlanguage);
1322 menuex_body
1323 : tBEGIN itemex_definitions tEND { $$ = $2; }
1326 itemex_definitions
1327 : /* Empty */ {$$ = NULL; }
1328 | itemex_definitions tMENUITEM tSTRING itemex_options {
1329 $$ = new_menuex_item();
1330 $$->prev = $1;
1331 if($1)
1332 $1->next = $$;
1333 $$->name = $3;
1334 $$->id = $4->id;
1335 $$->type = $4->type;
1336 $$->state = $4->state;
1337 $$->helpid = $4->helpid;
1338 $$->gotid = $4->gotid;
1339 $$->gottype = $4->gottype;
1340 $$->gotstate = $4->gotstate;
1341 $$->gothelpid = $4->gothelpid;
1342 free($4);
1344 | itemex_definitions tMENUITEM tSEPARATOR {
1345 $$ = new_menuex_item();
1346 $$->prev = $1;
1347 if($1)
1348 $1->next = $$;
1350 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1351 $$ = new_menuex_item();
1352 $$->prev = $1;
1353 if($1)
1354 $1->next = $$;
1355 $$->popup = get_itemex_head($5);
1356 $$->name = $3;
1357 $$->id = $4->id;
1358 $$->type = $4->type;
1359 $$->state = $4->state;
1360 $$->helpid = $4->helpid;
1361 $$->gotid = $4->gotid;
1362 $$->gottype = $4->gottype;
1363 $$->gotstate = $4->gotstate;
1364 $$->gothelpid = $4->gothelpid;
1365 free($4);
1369 itemex_options
1370 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1371 | ',' expr {
1372 $$ = new_itemex_opt($2, 0, 0, 0);
1373 $$->gotid = TRUE;
1375 | ',' e_expr ',' e_expr item_options {
1376 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1377 $$->gotid = TRUE;
1378 $$->gottype = TRUE;
1379 $$->gotstate = TRUE;
1380 if($2) free($2);
1381 if($4) free($4);
1383 | ',' e_expr ',' e_expr ',' expr {
1384 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1385 $$->gotid = TRUE;
1386 $$->gottype = TRUE;
1387 $$->gotstate = TRUE;
1388 if($2) free($2);
1389 if($4) free($4);
1393 itemex_p_options
1394 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1395 | ',' expr {
1396 $$ = new_itemex_opt($2, 0, 0, 0);
1397 $$->gotid = TRUE;
1399 | ',' e_expr ',' expr {
1400 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1401 if($2) free($2);
1402 $$->gotid = TRUE;
1403 $$->gottype = TRUE;
1405 | ',' e_expr ',' e_expr ',' expr {
1406 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1407 if($2) free($2);
1408 if($4) free($4);
1409 $$->gotid = TRUE;
1410 $$->gottype = TRUE;
1411 $$->gotstate = TRUE;
1413 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1414 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1415 if($2) free($2);
1416 if($4) free($4);
1417 if($6) free($6);
1418 $$->gotid = TRUE;
1419 $$->gottype = TRUE;
1420 $$->gotstate = TRUE;
1421 $$->gothelpid = TRUE;
1425 /* ------------------------------ StringTable ------------------------------ */
1426 /* Stringtables are parsed differently than other resources because their
1427 * layout is substantially different from other resources.
1428 * The table is parsed through a _global_ variable 'tagstt' which holds the
1429 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1430 * list of stringtables of different languages.
1432 stringtable
1433 : stt_head tBEGIN strings tEND {
1434 if(!$3)
1436 yyerror("Stringtable must have at least one entry");
1438 else
1440 stringtable_t *stt;
1441 /* Check if we added to a language table or created
1442 * a new one.
1444 for(stt = sttres; stt; stt = stt->next)
1446 if(stt == tagstt)
1447 break;
1449 if(!stt)
1451 /* It is a new one */
1452 if(sttres)
1454 sttres->prev = tagstt;
1455 tagstt->next = sttres;
1456 sttres = tagstt;
1458 else
1459 sttres = tagstt;
1461 /* Else were done */
1463 if(tagstt_memopt)
1465 free(tagstt_memopt);
1466 tagstt_memopt = NULL;
1469 $$ = tagstt;
1473 /* This is to get the language of the currently parsed stringtable */
1474 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1475 if((tagstt = find_stringtable($3)) == NULL)
1476 tagstt = new_stringtable($3);
1477 tagstt_memopt = $2;
1478 tagstt_version = $3->version;
1479 tagstt_characts = $3->characts;
1480 if($3)
1481 free($3);
1485 strings : /* Empty */ { $$ = NULL; }
1486 | strings expr opt_comma tSTRING {
1487 int i;
1488 assert(tagstt != NULL);
1489 if($2 > 65535 || $2 < -32768)
1490 yyerror("Stringtable entry's ID out of range (%d)", $2);
1491 /* Search for the ID */
1492 for(i = 0; i < tagstt->nentries; i++)
1494 if(tagstt->entries[i].id == $2)
1495 yyerror("Stringtable ID %d already in use", $2);
1497 /* If we get here, then we have a new unique entry */
1498 tagstt->nentries++;
1499 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1500 tagstt->entries[tagstt->nentries-1].id = $2;
1501 tagstt->entries[tagstt->nentries-1].str = $4;
1502 if(tagstt_memopt)
1503 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1504 else
1505 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1506 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1507 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1509 if(pedantic && !$4->size)
1510 yywarning("Zero length strings make no sense");
1511 if(!win32 && $4->size > 254)
1512 yyerror("Stringtable entry more than 254 characters");
1513 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1514 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1515 $$ = tagstt;
1519 opt_comma /* There seem to be two ways to specify a stringtable... */
1520 : /* Empty */
1521 | ','
1524 /* ------------------------------ VersionInfo ------------------------------ */
1525 versioninfo
1526 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1527 $$ = $3;
1528 if($2)
1530 $$->memopt = *($2);
1531 free($2);
1533 else
1534 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1535 $$->blocks = get_ver_block_head($5);
1536 /* Set language; there is no version or characteristics */
1537 $$->lvc.language = dup_language(currentlanguage);
1541 fix_version
1542 : /* Empty */ { $$ = new_versioninfo(); }
1543 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1544 if($1->gotit.fv)
1545 yyerror("FILEVERSION already defined");
1546 $$ = $1;
1547 $$->filever_maj1 = $3;
1548 $$->filever_maj2 = $5;
1549 $$->filever_min1 = $7;
1550 $$->filever_min2 = $9;
1551 $$->gotit.fv = 1;
1553 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1554 if($1->gotit.pv)
1555 yyerror("PRODUCTVERSION already defined");
1556 $$ = $1;
1557 $$->prodver_maj1 = $3;
1558 $$->prodver_maj2 = $5;
1559 $$->prodver_min1 = $7;
1560 $$->prodver_min2 = $9;
1561 $$->gotit.pv = 1;
1563 | fix_version tFILEFLAGS expr {
1564 if($1->gotit.ff)
1565 yyerror("FILEFLAGS already defined");
1566 $$ = $1;
1567 $$->fileflags = $3;
1568 $$->gotit.ff = 1;
1570 | fix_version tFILEFLAGSMASK expr {
1571 if($1->gotit.ffm)
1572 yyerror("FILEFLAGSMASK already defined");
1573 $$ = $1;
1574 $$->fileflagsmask = $3;
1575 $$->gotit.ffm = 1;
1577 | fix_version tFILEOS expr {
1578 if($1->gotit.fo)
1579 yyerror("FILEOS already defined");
1580 $$ = $1;
1581 $$->fileos = $3;
1582 $$->gotit.fo = 1;
1584 | fix_version tFILETYPE expr {
1585 if($1->gotit.ft)
1586 yyerror("FILETYPE already defined");
1587 $$ = $1;
1588 $$->filetype = $3;
1589 $$->gotit.ft = 1;
1591 | fix_version tFILESUBTYPE expr {
1592 if($1->gotit.fst)
1593 yyerror("FILESUBTYPE already defined");
1594 $$ = $1;
1595 $$->filesubtype = $3;
1596 $$->gotit.fst = 1;
1600 ver_blocks
1601 : /* Empty */ { $$ = NULL; }
1602 | ver_blocks ver_block {
1603 $$ = $2;
1604 $$->prev = $1;
1605 if($1)
1606 $1->next = $$;
1610 ver_block
1611 : tBLOCK tSTRING tBEGIN ver_values tEND {
1612 $$ = new_ver_block();
1613 $$->name = $2;
1614 $$->values = get_ver_value_head($4);
1618 ver_values
1619 : /* Empty */ { $$ = NULL; }
1620 | ver_values ver_value {
1621 $$ = $2;
1622 $$->prev = $1;
1623 if($1)
1624 $1->next = $$;
1628 ver_value
1629 : ver_block {
1630 $$ = new_ver_value();
1631 $$->type = val_block;
1632 $$->value.block = $1;
1634 | tVALUE tSTRING ',' tSTRING {
1635 $$ = new_ver_value();
1636 $$->type = val_str;
1637 $$->key = $2;
1638 $$->value.str = $4;
1640 | tVALUE tSTRING ',' ver_words {
1641 $$ = new_ver_value();
1642 $$->type = val_words;
1643 $$->key = $2;
1644 $$->value.words = $4;
1648 ver_words
1649 : expr { $$ = new_ver_words($1); }
1650 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1653 /* ------------------------------ Toolbar ------------------------------ */
1654 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1655 int nitems;
1656 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1657 $$ = new_toolbar($3, $5, items, nitems);
1658 if($2)
1660 $$->memopt = *($2);
1661 free($2);
1663 else
1665 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1667 if($6)
1669 $$->lvc = *($6);
1670 free($6);
1672 if(!$$->lvc.language)
1674 $$->lvc.language = dup_language(currentlanguage);
1679 toolbar_items
1680 : /* Empty */ { $$ = NULL; }
1681 | toolbar_items tBUTTON expr {
1682 toolbar_item_t *idrec = new_toolbar_item();
1683 idrec->id = $3;
1684 $$ = ins_tlbr_button($1, idrec);
1686 | toolbar_items tSEPARATOR {
1687 toolbar_item_t *idrec = new_toolbar_item();
1688 idrec->id = 0;
1689 $$ = ins_tlbr_button($1, idrec);
1693 /* ------------------------------ Memory options ------------------------------ */
1694 loadmemopts
1695 : /* Empty */ { $$ = NULL; }
1696 | loadmemopts lamo {
1697 if($1)
1699 *($1) |= *($2);
1700 $$ = $1;
1701 free($2);
1703 else
1704 $$ = $2;
1706 | loadmemopts lama {
1707 if($1)
1709 *($1) &= *($2);
1710 $$ = $1;
1711 free($2);
1713 else
1715 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1716 $$ = $2;
1721 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1722 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1723 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1724 | tPURE { $$ = new_int(WRC_MO_PURE); }
1727 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1728 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1729 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1732 /* ------------------------------ Win32 options ------------------------------ */
1733 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1734 | opt_lvc opt_language {
1735 if(!win32)
1736 yywarning("LANGUAGE not supported in 16-bit mode");
1737 if($1->language)
1738 yyerror("Language already defined");
1739 $$ = $1;
1740 $1->language = $2;
1742 | opt_lvc opt_characts {
1743 if(!win32)
1744 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1745 if($1->characts)
1746 yyerror("Characteristics already defined");
1747 $$ = $1;
1748 $1->characts = $2;
1750 | opt_lvc opt_version {
1751 if(!win32)
1752 yywarning("VERSION not supported in 16-bit mode");
1753 if($1->version)
1754 yyerror("Version already defined");
1755 $$ = $1;
1756 $1->version = $2;
1761 * This here is another s/r conflict on {bi,u}nary + and -.
1762 * It is due to the look-ahead which must determine when the
1763 * rule opt_language ends. It could be solved with adding a
1764 * tNL at the end, but that seems unreasonable to do.
1765 * The conflict is now moved to the expression handling below.
1767 opt_language
1768 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
1769 if (get_language_codepage($2, $4) == -1)
1770 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1774 opt_characts
1775 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1778 opt_version
1779 : tVERSION expr { $$ = new_version($2); }
1782 /* ------------------------------ Raw data handling ------------------------------ */
1783 raw_data: opt_lvc tBEGIN raw_elements tEND {
1784 if($1)
1786 $3->lvc = *($1);
1787 free($1);
1790 if(!$3->lvc.language)
1791 $3->lvc.language = dup_language(currentlanguage);
1793 $$ = $3;
1797 raw_elements
1798 : tRAWDATA { $$ = $1; }
1799 | tNUMBER { $$ = int2raw_data($1); }
1800 | '-' tNUMBER { $$ = int2raw_data(-($2)); }
1801 | tLNUMBER { $$ = long2raw_data($1); }
1802 | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
1803 | tSTRING { $$ = str2raw_data($1); }
1804 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1805 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1806 | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
1807 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1808 | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
1809 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1812 /* File data or raw data */
1813 file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
1814 | raw_data { $$ = $1; }
1817 /* ------------------------------ Win32 expressions ------------------------------ */
1818 /* All win16 numbers are also handled here. This is inconsistent with MS'
1819 * resource compiler, but what the heck, its just handy to have.
1821 e_expr : /* Empty */ { $$ = 0; }
1822 | expr { $$ = new_int($1); }
1825 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1826 expr : xpr { $$ = ($1); }
1829 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1830 | xpr '-' xpr { $$ = ($1) - ($3); }
1831 | xpr '|' xpr { $$ = ($1) | ($3); }
1832 | xpr '&' xpr { $$ = ($1) & ($3); }
1833 | xpr '*' xpr { $$ = ($1) * ($3); }
1834 | xpr '/' xpr { $$ = ($1) / ($3); }
1835 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1836 | '~' xpr { $$ = ~($2); }
1837 | '-' xpr %prec pUPM { $$ = -($2); }
1838 | '+' xpr %prec pUPM { $$ = $2; }
1839 | '(' xpr ')' { $$ = $2; }
1840 | any_num { $$ = $1; }
1841 | tNOT any_num { $$ = ~($2); }
1844 any_num : tNUMBER { $$ = $1; }
1845 | tLNUMBER { $$ = $1; }
1849 /* Dialog specific functions */
1850 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1852 assert(dlg != NULL);
1853 if(dlg->style == NULL)
1855 dlg->style = new_style(0,0);
1858 if(dlg->gotstyle)
1860 yywarning("Style already defined, or-ing together");
1862 else
1864 dlg->style->or_mask = 0;
1865 dlg->style->and_mask = 0;
1867 dlg->style->or_mask |= st->or_mask;
1868 dlg->style->and_mask |= st->and_mask;
1869 dlg->gotstyle = TRUE;
1870 free(st);
1871 return dlg;
1874 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1876 assert(dlg != NULL);
1877 if(dlg->exstyle == NULL)
1879 dlg->exstyle = new_style(0,0);
1882 if(dlg->gotexstyle)
1884 yywarning("ExStyle already defined, or-ing together");
1886 else
1888 dlg->exstyle->or_mask = 0;
1889 dlg->exstyle->and_mask = 0;
1891 dlg->exstyle->or_mask |= st->or_mask;
1892 dlg->exstyle->and_mask |= st->and_mask;
1893 dlg->gotexstyle = TRUE;
1894 free(st);
1895 return dlg;
1898 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1900 assert(dlg != NULL);
1901 if(dlg->title)
1902 yyerror("Caption already defined");
1903 dlg->title = s;
1904 return dlg;
1907 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1909 assert(dlg != NULL);
1910 if(dlg->font)
1911 yyerror("Font already defined");
1912 dlg->font = f;
1913 return dlg;
1916 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1918 assert(dlg != NULL);
1919 if(dlg->dlgclass)
1920 yyerror("Class already defined");
1921 dlg->dlgclass = n;
1922 return dlg;
1925 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1927 assert(dlg != NULL);
1928 if(dlg->menu)
1929 yyerror("Menu already defined");
1930 dlg->menu = m;
1931 return dlg;
1934 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1936 assert(dlg != NULL);
1937 if(dlg->lvc.language)
1938 yyerror("Language already defined");
1939 dlg->lvc.language = l;
1940 return dlg;
1943 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1945 assert(dlg != NULL);
1946 if(dlg->lvc.characts)
1947 yyerror("Characteristics already defined");
1948 dlg->lvc.characts = c;
1949 return dlg;
1952 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1954 assert(dlg != NULL);
1955 if(dlg->lvc.version)
1956 yyerror("Version already defined");
1957 dlg->lvc.version = v;
1958 return dlg;
1961 /* Controls specific functions */
1962 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1964 /* Hm... this seems to be jammed in at all time... */
1965 int defaultstyle = WS_CHILD | WS_VISIBLE;
1967 assert(ctrl != NULL);
1968 ctrl->prev = prev;
1970 if(prev)
1971 prev->next = ctrl;
1973 if(type != -1)
1975 ctrl->ctlclass = new_name_id();
1976 ctrl->ctlclass->type = name_ord;
1977 ctrl->ctlclass->name.i_name = type;
1980 switch(type)
1982 case CT_BUTTON:
1983 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1984 defaultstyle |= WS_TABSTOP;
1985 break;
1986 case CT_EDIT:
1987 defaultstyle |= WS_TABSTOP | WS_BORDER;
1988 break;
1989 case CT_LISTBOX:
1990 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1991 break;
1992 case CT_COMBOBOX:
1993 if (!(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
1994 defaultstyle |= CBS_SIMPLE;
1995 break;
1996 case CT_STATIC:
1997 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1998 defaultstyle |= WS_GROUP;
1999 break;
2002 if(!ctrl->gotstyle) /* Handle default style setting */
2004 switch(type)
2006 case CT_EDIT:
2007 defaultstyle |= ES_LEFT;
2008 break;
2009 case CT_LISTBOX:
2010 defaultstyle |= LBS_NOTIFY;
2011 break;
2012 case CT_COMBOBOX:
2013 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
2014 break;
2015 case CT_SCROLLBAR:
2016 defaultstyle |= SBS_HORZ;
2017 break;
2018 case CT_BUTTON:
2019 switch(special_style)
2021 case BS_CHECKBOX:
2022 case BS_DEFPUSHBUTTON:
2023 case BS_PUSHBUTTON:
2024 /* case BS_PUSHBOX: */
2025 case BS_AUTORADIOBUTTON:
2026 case BS_AUTO3STATE:
2027 case BS_3STATE:
2028 case BS_AUTOCHECKBOX:
2029 defaultstyle |= WS_TABSTOP;
2030 break;
2031 default:
2032 yywarning("Unknown default button control-style 0x%08x", special_style);
2033 case BS_GROUPBOX:
2034 case BS_RADIOBUTTON:
2035 break;
2037 break;
2039 case CT_STATIC:
2040 switch(special_style)
2042 case SS_LEFT:
2043 case SS_RIGHT:
2044 case SS_CENTER:
2045 defaultstyle |= WS_GROUP;
2046 break;
2047 case SS_ICON: /* Special case */
2048 break;
2049 default:
2050 yywarning("Unknown default static control-style 0x%08x", special_style);
2051 break;
2053 break;
2054 case -1: /* Generic control */
2055 goto byebye;
2057 default:
2058 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2062 /* The SS_ICON flag is always forced in for icon controls */
2063 if(type == CT_STATIC && special_style == SS_ICON)
2064 defaultstyle |= SS_ICON;
2066 if (!ctrl->gotstyle)
2067 ctrl->style = new_style(0,0);
2069 /* combine all styles */
2070 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2071 ctrl->gotstyle = TRUE;
2072 byebye:
2073 /* combine with NOT mask */
2074 if (ctrl->gotstyle)
2076 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2077 ctrl->style->and_mask = 0;
2079 if (ctrl->gotexstyle)
2081 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2082 ctrl->exstyle->and_mask = 0;
2084 return ctrl;
2087 static name_id_t *convert_ctlclass(name_id_t *cls)
2089 char *cc = NULL;
2090 int iclass;
2092 if(cls->type == name_ord)
2093 return cls;
2094 assert(cls->type == name_str);
2095 if(cls->type == str_unicode)
2097 yyerror("Don't yet support unicode class comparison");
2099 else
2100 cc = cls->name.s_name->str.cstr;
2102 if(!strcasecmp("BUTTON", cc))
2103 iclass = CT_BUTTON;
2104 else if(!strcasecmp("COMBOBOX", cc))
2105 iclass = CT_COMBOBOX;
2106 else if(!strcasecmp("LISTBOX", cc))
2107 iclass = CT_LISTBOX;
2108 else if(!strcasecmp("EDIT", cc))
2109 iclass = CT_EDIT;
2110 else if(!strcasecmp("STATIC", cc))
2111 iclass = CT_STATIC;
2112 else if(!strcasecmp("SCROLLBAR", cc))
2113 iclass = CT_SCROLLBAR;
2114 else
2115 return cls; /* No default, return user controlclass */
2117 free(cls->name.s_name->str.cstr);
2118 free(cls->name.s_name);
2119 cls->type = name_ord;
2120 cls->name.i_name = iclass;
2121 return cls;
2124 /* DialogEx specific functions */
2125 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2127 assert(dlg != NULL);
2128 if(dlg->style == NULL)
2130 dlg->style = new_style(0,0);
2133 if(dlg->gotstyle)
2135 yywarning("Style already defined, or-ing together");
2137 else
2139 dlg->style->or_mask = 0;
2140 dlg->style->and_mask = 0;
2142 dlg->style->or_mask |= st->or_mask;
2143 dlg->style->and_mask |= st->and_mask;
2144 dlg->gotstyle = TRUE;
2145 free(st);
2146 return dlg;
2149 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2151 assert(dlg != NULL);
2152 if(dlg->exstyle == NULL)
2154 dlg->exstyle = new_style(0,0);
2157 if(dlg->gotexstyle)
2159 yywarning("ExStyle already defined, or-ing together");
2161 else
2163 dlg->exstyle->or_mask = 0;
2164 dlg->exstyle->and_mask = 0;
2166 dlg->exstyle->or_mask |= st->or_mask;
2167 dlg->exstyle->and_mask |= st->and_mask;
2168 dlg->gotexstyle = TRUE;
2169 free(st);
2170 return dlg;
2173 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2175 assert(dlg != NULL);
2176 if(dlg->title)
2177 yyerror("Caption already defined");
2178 dlg->title = s;
2179 return dlg;
2182 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2184 assert(dlg != NULL);
2185 if(dlg->font)
2186 yyerror("Font already defined");
2187 dlg->font = f;
2188 return dlg;
2191 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2193 assert(dlg != NULL);
2194 if(dlg->dlgclass)
2195 yyerror("Class already defined");
2196 dlg->dlgclass = n;
2197 return dlg;
2200 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2202 assert(dlg != NULL);
2203 if(dlg->menu)
2204 yyerror("Menu already defined");
2205 dlg->menu = m;
2206 return dlg;
2209 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2211 assert(dlg != NULL);
2212 if(dlg->lvc.language)
2213 yyerror("Language already defined");
2214 dlg->lvc.language = l;
2215 return dlg;
2218 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2220 assert(dlg != NULL);
2221 if(dlg->lvc.characts)
2222 yyerror("Characteristics already defined");
2223 dlg->lvc.characts = c;
2224 return dlg;
2227 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2229 assert(dlg != NULL);
2230 if(dlg->lvc.version)
2231 yyerror("Version already defined");
2232 dlg->lvc.version = v;
2233 return dlg;
2236 /* Accelerator specific functions */
2237 static event_t *add_event(int key, int id, int flags, event_t *prev)
2239 event_t *ev = new_event();
2241 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2242 yyerror("Cannot use both ASCII and VIRTKEY");
2244 ev->key = key;
2245 ev->id = id;
2246 ev->flags = flags & ~WRC_AF_ASCII;
2247 ev->prev = prev;
2248 if(prev)
2249 prev->next = ev;
2250 return ev;
2253 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2255 int keycode = 0;
2256 event_t *ev = new_event();
2258 if(key->type != str_char)
2259 yyerror("Key code must be an ascii string");
2261 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
2262 yyerror("VIRTKEY code is not equal to ascii value");
2264 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2266 yyerror("Cannot use both '^' and CONTROL modifier");
2268 else if(key->str.cstr[0] == '^')
2270 keycode = toupper(key->str.cstr[1]) - '@';
2271 if(keycode >= ' ')
2272 yyerror("Control-code out of range");
2274 else
2275 keycode = key->str.cstr[0];
2276 ev->key = keycode;
2277 ev->id = id;
2278 ev->flags = flags & ~WRC_AF_ASCII;
2279 ev->prev = prev;
2280 if(prev)
2281 prev->next = ev;
2282 return ev;
2285 /* MenuEx specific functions */
2286 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2288 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2289 opt->id = id;
2290 opt->type = type;
2291 opt->state = state;
2292 opt->helpid = helpid;
2293 return opt;
2296 /* Raw data functions */
2297 static raw_data_t *load_file(string_t *filename, language_t *lang)
2299 FILE *fp = NULL;
2300 char *path;
2301 raw_data_t *rd;
2302 string_t *name;
2303 int codepage = get_language_codepage(lang->id, lang->sub);
2305 /* FIXME: we may want to use utf-8 here */
2306 if (codepage <= 0 && filename->type != str_char)
2307 yyerror("Cannot convert filename to ASCII string");
2308 name = convert_string( filename, str_char, codepage );
2309 if (!(path = wpp_find_include(name->str.cstr, input_name)))
2310 yyerror("Cannot open file %s", name->str.cstr);
2311 if (!(fp = fopen( path, "rb" )))
2312 yyerror("Cannot open file %s", name->str.cstr);
2313 free( path );
2314 rd = new_raw_data();
2315 fseek(fp, 0, SEEK_END);
2316 rd->size = ftell(fp);
2317 fseek(fp, 0, SEEK_SET);
2318 if (rd->size)
2320 rd->data = (char *)xmalloc(rd->size);
2321 fread(rd->data, rd->size, 1, fp);
2323 else rd->data = NULL;
2324 fclose(fp);
2325 rd->lvc.language = lang;
2326 free_string(name);
2327 return rd;
2330 static raw_data_t *int2raw_data(int i)
2332 raw_data_t *rd;
2334 if( ( i >= 0 && (int)((unsigned short)i) != i) ||
2335 ( i < 0 && (int)((short)i) != i) )
2336 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2338 rd = new_raw_data();
2339 rd->size = sizeof(short);
2340 rd->data = (char *)xmalloc(rd->size);
2341 switch(byteorder)
2343 #ifdef WORDS_BIGENDIAN
2344 default:
2345 #endif
2346 case WRC_BO_BIG:
2347 rd->data[0] = HIBYTE(i);
2348 rd->data[1] = LOBYTE(i);
2349 break;
2351 #ifndef WORDS_BIGENDIAN
2352 default:
2353 #endif
2354 case WRC_BO_LITTLE:
2355 rd->data[1] = HIBYTE(i);
2356 rd->data[0] = LOBYTE(i);
2357 break;
2359 return rd;
2362 static raw_data_t *long2raw_data(int i)
2364 raw_data_t *rd;
2365 rd = new_raw_data();
2366 rd->size = sizeof(int);
2367 rd->data = (char *)xmalloc(rd->size);
2368 switch(byteorder)
2370 #ifdef WORDS_BIGENDIAN
2371 default:
2372 #endif
2373 case WRC_BO_BIG:
2374 rd->data[0] = HIBYTE(HIWORD(i));
2375 rd->data[1] = LOBYTE(HIWORD(i));
2376 rd->data[2] = HIBYTE(LOWORD(i));
2377 rd->data[3] = LOBYTE(LOWORD(i));
2378 break;
2380 #ifndef WORDS_BIGENDIAN
2381 default:
2382 #endif
2383 case WRC_BO_LITTLE:
2384 rd->data[3] = HIBYTE(HIWORD(i));
2385 rd->data[2] = LOBYTE(HIWORD(i));
2386 rd->data[1] = HIBYTE(LOWORD(i));
2387 rd->data[0] = LOBYTE(LOWORD(i));
2388 break;
2390 return rd;
2393 static raw_data_t *str2raw_data(string_t *str)
2395 raw_data_t *rd;
2396 rd = new_raw_data();
2397 rd->size = str->size * (str->type == str_char ? 1 : 2);
2398 rd->data = (char *)xmalloc(rd->size);
2399 if(str->type == str_char)
2400 memcpy(rd->data, str->str.cstr, rd->size);
2401 else if(str->type == str_unicode)
2403 int i;
2404 switch(byteorder)
2406 #ifdef WORDS_BIGENDIAN
2407 default:
2408 #endif
2409 case WRC_BO_BIG:
2410 for(i = 0; i < str->size; i++)
2412 rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
2413 rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
2415 break;
2416 #ifndef WORDS_BIGENDIAN
2417 default:
2418 #endif
2419 case WRC_BO_LITTLE:
2420 for(i = 0; i < str->size; i++)
2422 rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
2423 rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
2425 break;
2428 else
2429 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2430 return rd;
2433 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2435 r1->data = xrealloc(r1->data, r1->size + r2->size);
2436 memcpy(r1->data + r1->size, r2->data, r2->size);
2437 r1->size += r2->size;
2438 return r1;
2441 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2443 raw_data_t *t = int2raw_data(i);
2444 merge_raw_data(r1, t);
2445 free(t->data);
2446 free(t);
2447 return r1;
2450 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2452 raw_data_t *t = long2raw_data(i);
2453 merge_raw_data(r1, t);
2454 free(t->data);
2455 free(t);
2456 return r1;
2459 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2461 raw_data_t *t = str2raw_data(str);
2462 merge_raw_data(r1, t);
2463 free(t->data);
2464 free(t);
2465 return r1;
2468 /* Function the go back in a list to get the head */
2469 static menu_item_t *get_item_head(menu_item_t *p)
2471 if(!p)
2472 return NULL;
2473 while(p->prev)
2474 p = p->prev;
2475 return p;
2478 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2480 if(!p)
2481 return NULL;
2482 while(p->prev)
2483 p = p->prev;
2484 return p;
2487 static resource_t *get_resource_head(resource_t *p)
2489 if(!p)
2490 return NULL;
2491 while(p->prev)
2492 p = p->prev;
2493 return p;
2496 static ver_block_t *get_ver_block_head(ver_block_t *p)
2498 if(!p)
2499 return NULL;
2500 while(p->prev)
2501 p = p->prev;
2502 return p;
2505 static ver_value_t *get_ver_value_head(ver_value_t *p)
2507 if(!p)
2508 return NULL;
2509 while(p->prev)
2510 p = p->prev;
2511 return p;
2514 static control_t *get_control_head(control_t *p)
2516 if(!p)
2517 return NULL;
2518 while(p->prev)
2519 p = p->prev;
2520 return p;
2523 static event_t *get_event_head(event_t *p)
2525 if(!p)
2526 return NULL;
2527 while(p->prev)
2528 p = p->prev;
2529 return p;
2532 /* Find a stringtable with given language */
2533 static stringtable_t *find_stringtable(lvc_t *lvc)
2535 stringtable_t *stt;
2537 assert(lvc != NULL);
2539 if(!lvc->language)
2540 lvc->language = dup_language(currentlanguage);
2542 for(stt = sttres; stt; stt = stt->next)
2544 if(stt->lvc.language->id == lvc->language->id
2545 && stt->lvc.language->sub == lvc->language->sub)
2547 /* Found a table with the same language */
2548 /* The version and characteristics are now handled
2549 * in the generation of the individual stringtables.
2550 * This enables localized analysis.
2551 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2552 || (!stt->lvc.version && lvc->version)
2553 || (stt->lvc.version && !lvc->version))
2554 yywarning("Stringtable's versions are not the same, using first definition");
2556 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2557 || (!stt->lvc.characts && lvc->characts)
2558 || (stt->lvc.characts && !lvc->characts))
2559 yywarning("Stringtable's characteristics are not the same, using first definition");
2561 return stt;
2564 return NULL;
2567 /* qsort sorting function for string table entries */
2568 #define STE(p) ((const stt_entry_t *)(p))
2569 static int sort_stt_entry(const void *e1, const void *e2)
2571 return STE(e1)->id - STE(e2)->id;
2573 #undef STE
2575 static resource_t *build_stt_resources(stringtable_t *stthead)
2577 stringtable_t *stt;
2578 stringtable_t *newstt;
2579 resource_t *rsc;
2580 resource_t *rsclist = NULL;
2581 resource_t *rsctail = NULL;
2582 int i;
2583 int j;
2584 DWORD andsum;
2585 DWORD orsum;
2586 characts_t *characts;
2587 version_t *version;
2589 if(!stthead)
2590 return NULL;
2592 /* For all languages defined */
2593 for(stt = stthead; stt; stt = stt->next)
2595 assert(stt->nentries > 0);
2597 /* Sort the entries */
2598 if(stt->nentries > 1)
2599 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2601 for(i = 0; i < stt->nentries; )
2603 newstt = new_stringtable(&stt->lvc);
2604 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2605 newstt->nentries = 16;
2606 newstt->idbase = stt->entries[i].id & ~0xf;
2607 for(j = 0; j < 16 && i < stt->nentries; j++)
2609 if(stt->entries[i].id - newstt->idbase == j)
2611 newstt->entries[j] = stt->entries[i];
2612 i++;
2615 andsum = ~0;
2616 orsum = 0;
2617 characts = NULL;
2618 version = NULL;
2619 /* Check individual memory options and get
2620 * the first characteristics/version
2622 for(j = 0; j < 16; j++)
2624 if(!newstt->entries[j].str)
2625 continue;
2626 andsum &= newstt->entries[j].memopt;
2627 orsum |= newstt->entries[j].memopt;
2628 if(!characts)
2629 characts = newstt->entries[j].characts;
2630 if(!version)
2631 version = newstt->entries[j].version;
2633 if(andsum != orsum)
2635 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2637 /* Check version and characteristics */
2638 for(j = 0; j < 16; j++)
2640 if(characts
2641 && newstt->entries[j].characts
2642 && *newstt->entries[j].characts != *characts)
2643 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2644 if(version
2645 && newstt->entries[j].version
2646 && *newstt->entries[j].version != *version)
2647 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2649 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2650 rsc->name = new_name_id();
2651 rsc->name->type = name_ord;
2652 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2653 rsc->memopt = andsum; /* Set to least common denominator */
2654 newstt->memopt = andsum;
2655 newstt->lvc.characts = characts;
2656 newstt->lvc.version = version;
2657 if(!rsclist)
2659 rsclist = rsc;
2660 rsctail = rsc;
2662 else
2664 rsctail->next = rsc;
2665 rsc->prev = rsctail;
2666 rsctail = rsc;
2670 return rsclist;
2674 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2676 idrec->prev = prev;
2677 if(prev)
2678 prev->next = idrec;
2680 return idrec;
2683 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2685 if(!p)
2687 *nitems = 0;
2688 return NULL;
2691 *nitems = 1;
2693 while(p->prev)
2695 (*nitems)++;
2696 p = p->prev;
2699 return p;
2702 static string_t *make_filename(string_t *str)
2704 if(str->type == str_char)
2706 char *cptr;
2708 /* Remove escaped backslash and convert to forward */
2709 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2711 if(cptr[1] == '\\')
2713 memmove(cptr, cptr+1, strlen(cptr));
2714 str->size--;
2716 *cptr = '/';
2719 else
2721 WCHAR *wptr;
2723 /* Remove escaped backslash and convert to forward */
2724 for(wptr = str->str.wstr; (wptr = strchrW(wptr, '\\')) != NULL; wptr++)
2726 if(wptr[1] == '\\')
2728 memmove(wptr, wptr+1, strlenW(wptr));
2729 str->size--;
2731 *wptr = '/';
2734 return str;
2738 * Process all resources to extract fonts and build
2739 * a fontdir resource.
2741 * Note: MS' resource compiler (build 1472) does not
2742 * handle font resources with different languages.
2743 * The fontdir is generated in the last active language
2744 * and font identifiers must be unique across the entire
2745 * source.
2746 * This is not logical considering the localization
2747 * constraints of all other resource types. MS has,
2748 * most probably, never testet localized fonts. However,
2749 * using fontresources is rare, so it might not occur
2750 * in normal applications.
2751 * Wine does require better localization because a lot
2752 * of languages are coded into the same executable.
2753 * Therefore, I will generate fontdirs for *each*
2754 * localized set of fonts.
2756 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2758 static int once = 0;
2759 if(!once)
2761 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
2762 once++;
2764 return NULL;
2767 static resource_t *build_fontdirs(resource_t *tail)
2769 resource_t *rsc;
2770 resource_t *lst = NULL;
2771 resource_t **fnt = NULL; /* List of all fonts */
2772 int nfnt = 0;
2773 resource_t **fnd = NULL; /* List of all fontdirs */
2774 int nfnd = 0;
2775 resource_t **lanfnt = NULL;
2776 int nlanfnt = 0;
2777 int i;
2778 name_id_t nid;
2779 string_t str;
2780 int fntleft;
2782 nid.type = name_str;
2783 nid.name.s_name = &str;
2784 str.type = str_char;
2785 str.str.cstr = xstrdup("FONTDIR");
2786 str.size = 7;
2788 /* Extract all fonts and fontdirs */
2789 for(rsc = tail; rsc; rsc = rsc->prev)
2791 if(rsc->type == res_fnt)
2793 nfnt++;
2794 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2795 fnt[nfnt-1] = rsc;
2797 else if(rsc->type == res_fntdir)
2799 nfnd++;
2800 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2801 fnd[nfnd-1] = rsc;
2805 /* Verify the name of the present fontdirs */
2806 for(i = 0; i < nfnd; i++)
2808 if(compare_name_id(&nid, fnd[i]->name))
2810 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2811 get_nameid_str(fnd[i]->name));
2812 fnd[i] = NULL;
2816 /* Sanity check */
2817 if(nfnt == 0)
2819 if(nfnd != 0)
2820 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2821 goto clean;
2824 /* Copy space */
2825 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2827 /* Get all fonts covered by fontdirs */
2828 for(i = 0; i < nfnd; i++)
2830 int j;
2831 WORD cnt;
2832 int isswapped = 0;
2834 if(!fnd[i])
2835 continue;
2836 for(j = 0; j < nfnt; j++)
2838 if(!fnt[j])
2839 continue;
2840 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2842 lanfnt[nlanfnt] = fnt[j];
2843 nlanfnt++;
2844 fnt[j] = NULL;
2848 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2849 if(nlanfnt == cnt)
2850 isswapped = 0;
2851 else if(nlanfnt == BYTESWAP_WORD(cnt))
2852 isswapped = 1;
2853 else
2854 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2855 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2856 #ifdef WORDS_BIGENDIAN
2857 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2858 #else
2859 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2860 #endif
2862 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2866 /* We now have fonts left where we need to make a fontdir resource */
2867 for(i = fntleft = 0; i < nfnt; i++)
2869 if(fnt[i])
2870 fntleft++;
2872 while(fntleft)
2874 /* Get fonts of same language in lanfnt[] */
2875 for(i = nlanfnt = 0; i < nfnt; i++)
2877 if(fnt[i])
2879 if(!nlanfnt)
2881 addlanfnt:
2882 lanfnt[nlanfnt] = fnt[i];
2883 nlanfnt++;
2884 fnt[i] = NULL;
2885 fntleft--;
2887 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2888 goto addlanfnt;
2891 /* and build a fontdir */
2892 rsc = build_fontdir(lanfnt, nlanfnt);
2893 if(rsc)
2895 if(lst)
2897 lst->next = rsc;
2898 rsc->prev = lst;
2900 lst = rsc;
2904 free(lanfnt);
2905 clean:
2906 if(fnt)
2907 free(fnt);
2908 if(fnd)
2909 free(fnd);
2910 free(str.str.cstr);
2911 return lst;
2915 * This gets invoked to determine whether the next resource
2916 * is to be of a standard-type (e.g. bitmaps etc.), or should
2917 * be a user-type resource. This function is required because
2918 * there is the _possibility_ of a lookahead token in the
2919 * parser, which is generated from the "expr" state in the
2920 * "nameid" parsing.
2922 * The general resource format is:
2923 * <identifier> <type> <flags> <resourcebody>
2925 * The <identifier> can either be tIDENT or "expr". The latter
2926 * will always generate a lookahead, which is the <type> of the
2927 * resource to parse. Otherwise, we need to get a new token from
2928 * the scanner to determine the next step.
2930 * The problem arrises when <type> is numerical. This case should
2931 * map onto default resource-types and be parsed as such instead
2932 * of being mapped onto user-type resources.
2934 * The trick lies in the fact that yacc (bison) doesn't care about
2935 * intermediate changes of the lookahead while reducing a rule. We
2936 * simply replace the lookahead with a token that will result in
2937 * a shift to the appropriate rule for the specific resource-type.
2939 static int rsrcid_to_token(int lookahead)
2941 int token;
2942 const char *type = "?";
2944 /* Get a token if we don't have one yet */
2945 if(lookahead == YYEMPTY)
2946 lookahead = YYLEX;
2948 /* Only numbers are possibly interesting */
2949 switch(lookahead)
2951 case tNUMBER:
2952 case tLNUMBER:
2953 break;
2954 default:
2955 return lookahead;
2958 token = lookahead;
2960 switch(yylval.num)
2962 case WRC_RT_CURSOR:
2963 type = "CURSOR";
2964 token = tCURSOR;
2965 break;
2966 case WRC_RT_ICON:
2967 type = "ICON";
2968 token = tICON;
2969 break;
2970 case WRC_RT_BITMAP:
2971 type = "BITMAP";
2972 token = tBITMAP;
2973 break;
2974 case WRC_RT_FONT:
2975 type = "FONT";
2976 token = tFONT;
2977 break;
2978 case WRC_RT_FONTDIR:
2979 type = "FONTDIR";
2980 token = tFONTDIR;
2981 break;
2982 case WRC_RT_RCDATA:
2983 type = "RCDATA";
2984 token = tRCDATA;
2985 break;
2986 case WRC_RT_MESSAGETABLE:
2987 type = "MESSAGETABLE";
2988 token = tMESSAGETABLE;
2989 break;
2990 case WRC_RT_DLGINIT:
2991 type = "DLGINIT";
2992 token = tDLGINIT;
2993 break;
2994 case WRC_RT_ACCELERATOR:
2995 type = "ACCELERATOR";
2996 token = tACCELERATORS;
2997 break;
2998 case WRC_RT_MENU:
2999 type = "MENU";
3000 token = tMENU;
3001 break;
3002 case WRC_RT_DIALOG:
3003 type = "DIALOG";
3004 token = tDIALOG;
3005 break;
3006 case WRC_RT_VERSION:
3007 type = "VERSION";
3008 token = tVERSIONINFO;
3009 break;
3010 case WRC_RT_TOOLBAR:
3011 type = "TOOLBAR";
3012 token = tTOOLBAR;
3013 break;
3014 case WRC_RT_HTML:
3015 type = "HTML";
3016 token = tHTML;
3017 break;
3019 case WRC_RT_STRING:
3020 type = "STRINGTABLE";
3021 break;
3023 case WRC_RT_ANICURSOR:
3024 case WRC_RT_ANIICON:
3025 case WRC_RT_GROUP_CURSOR:
3026 case WRC_RT_GROUP_ICON:
3027 yywarning("Usertype uses reserved type ID %d, which is auto-generated", yylval.num);
3028 return lookahead;
3030 case WRC_RT_DLGINCLUDE:
3031 case WRC_RT_PLUGPLAY:
3032 case WRC_RT_VXD:
3033 yywarning("Usertype uses reserved type ID %d, which is not supported by wrc yet", yylval.num);
3034 default:
3035 return lookahead;
3038 return token;