Updated directory info in DEVELOPERS-HINTS, and IRC info in several
[wine/multimedia.git] / tools / wrc / parser.y
blobf5d847d52e15c9eac24a5e1464e7635aadcd79d4
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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* seperated
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"
125 #include <stdio.h>
126 #include <stdlib.h>
127 #include <stdarg.h>
128 #include <assert.h>
129 #include <ctype.h>
130 #include <string.h>
131 #ifdef HAVE_ALLOCA_H
132 #include <alloca.h>
133 #endif
135 #include "wrc.h"
136 #include "utils.h"
137 #include "newstruc.h"
138 #include "dumpres.h"
139 #include "../wpp/wpp.h"
140 #include "parser.h"
141 #include "windef.h"
142 #include "winbase.h"
143 #include "wingdi.h"
144 #include "winuser.h"
146 #if defined(YYBYACC)
147 /* Berkeley yacc (byacc) doesn't seem to know about these */
148 /* Some *BSD supplied versions do define these though */
149 # ifndef YYEMPTY
150 # define YYEMPTY (-1) /* Empty lookahead value of yychar */
151 # endif
152 # ifndef YYLEX
153 # define YYLEX yylex()
154 # endif
156 #elif defined(YYBISON)
157 /* Bison was used for original development */
158 /* #define YYEMPTY -2 */
159 /* #define YYLEX yylex() */
161 #else
162 /* No yacc we know yet */
163 # if !defined(YYEMPTY) || !defined(YYLEX)
164 # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
165 # elif defined(__GNUC__) /* gcc defines the #warning directive */
166 # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
167 /* #else we just take a chance that it works... */
168 # endif
169 #endif
171 int want_nl = 0; /* Signal flex that we need the next newline */
172 int want_id = 0; /* Signal flex that we need the next identifier */
173 stringtable_t *tagstt; /* Stringtable tag.
174 * It is set while parsing a stringtable to one of
175 * the stringtables in the sttres list or a new one
176 * if the language was not parsed before.
178 stringtable_t *sttres; /* Stringtable resources. This holds the list of
179 * stringtables with different lanuages
181 static int dont_want_id = 0; /* See language parsing for details */
183 /* Set to the current options of the currently scanning stringtable */
184 static int *tagstt_memopt;
185 static characts_t *tagstt_characts;
186 static version_t *tagstt_version;
188 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
190 /* Prototypes of here defined functions */
191 static event_t *get_event_head(event_t *p);
192 static control_t *get_control_head(control_t *p);
193 static ver_value_t *get_ver_value_head(ver_value_t *p);
194 static ver_block_t *get_ver_block_head(ver_block_t *p);
195 static resource_t *get_resource_head(resource_t *p);
196 static menuex_item_t *get_itemex_head(menuex_item_t *p);
197 static menu_item_t *get_item_head(menu_item_t *p);
198 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
199 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
200 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
201 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
202 static raw_data_t *str2raw_data(string_t *str);
203 static raw_data_t *int2raw_data(int i);
204 static raw_data_t *long2raw_data(int i);
205 static raw_data_t *load_file(string_t *name);
206 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
207 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
208 static event_t *add_event(int key, int id, int flags, event_t *prev);
209 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg);
210 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg);
211 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg);
212 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg);
213 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg);
214 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg);
215 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg);
216 static dialogex_t *dialogex_exstyle(style_t *st, dialogex_t *dlg);
217 static dialogex_t *dialogex_style(style_t *st, dialogex_t *dlg);
218 static name_id_t *convert_ctlclass(name_id_t *cls);
219 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
220 static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
221 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
222 static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
223 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
224 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
225 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
226 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
227 static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
228 static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
229 static resource_t *build_stt_resources(stringtable_t *stthead);
230 static stringtable_t *find_stringtable(lvc_t *lvc);
231 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
232 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
233 static string_t *make_filename(string_t *s);
234 static resource_t *build_fontdirs(resource_t *tail);
235 static resource_t *build_fontdir(resource_t **fnt, int nfnt);
236 static int rsrcid_to_token(int lookahead);
239 %union{
240 string_t *str;
241 int num;
242 int *iptr;
243 char *cptr;
244 resource_t *res;
245 accelerator_t *acc;
246 bitmap_t *bmp;
247 dialog_t *dlg;
248 dialogex_t *dlgex;
249 font_t *fnt;
250 fontdir_t *fnd;
251 menu_t *men;
252 menuex_t *menex;
253 rcdata_t *rdt;
254 stringtable_t *stt;
255 stt_entry_t *stte;
256 user_t *usr;
257 messagetable_t *msg;
258 versioninfo_t *veri;
259 control_t *ctl;
260 name_id_t *nid;
261 font_id_t *fntid;
262 language_t *lan;
263 version_t *ver;
264 characts_t *chars;
265 event_t *event;
266 menu_item_t *menitm;
267 menuex_item_t *menexitm;
268 itemex_opt_t *exopt;
269 raw_data_t *raw;
270 lvc_t *lvc;
271 ver_value_t *val;
272 ver_block_t *blk;
273 ver_words_t *verw;
274 toolbar_t *tlbar;
275 toolbar_item_t *tlbarItems;
276 dlginit_t *dginit;
277 style_pair_t *styles;
278 style_t *style;
279 ani_any_t *ani;
282 %token tNL
283 %token <num> tNUMBER tLNUMBER
284 %token <str> tSTRING tIDENT tFILENAME
285 %token <raw> tRAWDATA
286 %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
287 %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON
288 %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
289 %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
290 %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
291 %token tCONTROL tEDITTEXT
292 %token tRTEXT tCTEXT tLTEXT
293 %token tBLOCK tVALUE
294 %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
295 %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
296 %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
297 %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
298 %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
299 %token tHELP
300 %token tSTRING tIDENT tRAWDATA
301 %token tTOOLBAR tBUTTON
302 %token tBEGIN tEND
303 %token tDLGINIT
304 %left '|'
305 %left '^'
306 %left '&'
307 %left '+' '-'
308 %left '*' '/'
309 %right '~' tNOT
310 %left pUPM
312 %type <res> resource_file resource resources resource_definition
313 %type <stt> stringtable strings
314 %type <fnt> font
315 %type <fnd> fontdir
316 %type <acc> accelerators
317 %type <event> events
318 %type <bmp> bitmap
319 %type <ani> cursor icon
320 %type <dlg> dialog dlg_attributes
321 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
322 %type <iptr> helpid
323 %type <dlgex> dialogex dlgex_attribs
324 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
325 %type <rdt> rcdata
326 %type <raw> raw_data raw_elements opt_data file_raw
327 %type <veri> versioninfo fix_version
328 %type <verw> ver_words
329 %type <blk> ver_blocks ver_block
330 %type <val> ver_values ver_value
331 %type <men> menu
332 %type <menitm> item_definitions menu_body
333 %type <menex> menuex
334 %type <menexitm> itemex_definitions menuex_body
335 %type <exopt> itemex_p_options itemex_options
336 %type <msg> messagetable
337 %type <usr> userres
338 %type <num> item_options
339 %type <nid> nameid nameid_s ctlclass usertype
340 %type <num> acc_opt acc accs
341 %type <iptr> loadmemopts lamo lama
342 %type <fntid> opt_font opt_exfont opt_expr
343 %type <lvc> opt_lvc
344 %type <lan> opt_language
345 %type <chars> opt_characts
346 %type <ver> opt_version
347 %type <num> expr xpr
348 %type <iptr> e_expr
349 %type <tlbar> toolbar
350 %type <tlbarItems> toolbar_items
351 %type <dginit> dlginit
352 %type <styles> optional_style_pair
353 %type <num> any_num
354 %type <style> optional_style
355 %type <style> style
356 %type <str> filename
360 resource_file
361 : resources {
362 resource_t *rsc;
363 /* First add stringtables to the resource-list */
364 rsc = build_stt_resources(sttres);
365 /* 'build_stt_resources' returns a head and $1 is a tail */
366 if($1)
368 $1->next = rsc;
369 if(rsc)
370 rsc->prev = $1;
372 else
373 $1 = rsc;
374 /* Find the tail again */
375 while($1 && $1->next)
376 $1 = $1->next;
377 /* Now add any fontdirecory */
378 rsc = build_fontdirs($1);
379 /* 'build_fontdir' returns a head and $1 is a tail */
380 if($1)
382 $1->next = rsc;
383 if(rsc)
384 rsc->prev = $1;
386 else
387 $1 = rsc;
388 /* Final statement before were done */
389 resource_top = get_resource_head($1);
393 /* Resources are put into a linked list */
394 resources
395 : /* Empty */ { $$ = NULL; want_id = 1; }
396 | resources resource {
397 if($2)
399 resource_t *tail = $2;
400 resource_t *head = $2;
401 while(tail->next)
402 tail = tail->next;
403 while(head->prev)
404 head = head->prev;
405 head->prev = $1;
406 if($1)
407 $1->next = head;
408 $$ = tail;
409 /* Check for duplicate identifiers */
410 while($1 && head)
412 resource_t *rsc = $1;
413 while(rsc)
415 if(rsc->type == head->type
416 && rsc->lan->id == head->lan->id
417 && rsc->lan->sub == head->lan->sub
418 && !compare_name_id(rsc->name, head->name))
420 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
422 rsc = rsc->prev;
424 head = head->next;
427 else if($1)
429 resource_t *tail = $1;
430 while(tail->next)
431 tail = tail->next;
432 $$ = tail;
434 else
435 $$ = NULL;
437 if(!dont_want_id) /* See comments in language parsing below */
438 want_id = 1;
439 dont_want_id = 0;
442 * The following newline rule will never get reduced because we never
443 * get the tNL token, unless we explicitely set the 'want_nl'
444 * flag, which we don't.
445 * The *ONLY* reason for this to be here is because Berkeley
446 * yacc (byacc), at least version 1.9, has a bug.
447 * (identified in the generated parser on the second
448 * line with:
449 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
451 * This extra rule fixes it.
452 * The problem is that the expression handling rule "expr: xpr"
453 * is not reduced on non-terminal tokens, defined above in the
454 * %token declarations. Token tNL is the only non-terminal that
455 * can occur. The error becomes visible in the language parsing
456 * rule below, which looks at the look-ahead token and tests it
457 * for tNL. However, byacc already generates an error upon reading
458 * the token instead of keeping it as a lookahead. The reason
459 * lies in the lack of a $default transition in the "expr : xpr . "
460 * state (currently state 25). It is probably ommitted because tNL
461 * is a non-terminal and the state contains 2 s/r conflicts. The
462 * state enumerates all possible transitions instead of using a
463 * $default transition.
464 * All in all, it is a bug in byacc. (period)
466 | resources tNL
470 /* Parse top level resource definitions etc. */
471 resource
472 : expr usrcvt resource_definition {
473 $$ = $3;
474 if($$)
476 if($1 > 65535 || $1 < -32768)
477 yyerror("Resource's ID out of range (%d)", $1);
478 $$->name = new_name_id();
479 $$->name->type = name_ord;
480 $$->name->name.i_name = $1;
481 chat("Got %s (%d)", get_typename($3), $$->name->name.i_name);
484 | tIDENT usrcvt resource_definition {
485 $$ = $3;
486 if($$)
488 $$->name = new_name_id();
489 $$->name->type = name_str;
490 $$->name->name.s_name = $1;
491 chat("Got %s (%s)", get_typename($3), $$->name->name.s_name->str.cstr);
494 | stringtable {
495 /* Don't do anything, stringtables are converted to
496 * resource_t structures when we are finished parsing and
497 * the final rule of the parser is reduced (see above)
499 $$ = NULL;
500 chat("Got STRINGTABLE");
502 | tLANGUAGE {want_nl = 1; } expr ',' expr {
503 /* We *NEED* the newline to delimit the expression.
504 * Otherwise, we would not be able to set the next
505 * want_id anymore because of the token-lookahead.
507 * However, we can test the lookahead-token for
508 * being "non-expression" type, in which case we
509 * continue. Fortunately, tNL is the only token that
510 * will break expression parsing and is implicitely
511 * void, so we just remove it. This scheme makes it
512 * possible to do some (not all) fancy preprocessor
513 * stuff.
514 * BTW, we also need to make sure that the next
515 * reduction of 'resources' above will *not* set
516 * want_id because we already have a lookahead that
517 * cannot be undone.
519 if(yychar != YYEMPTY && yychar != tNL)
520 dont_want_id = 1;
522 if(yychar == tNL)
523 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
524 /* direct access to yychar in rule 'usrcvt' below. */
525 else if(yychar == tIDENT)
526 yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
528 want_nl = 0; /* We don't want it anymore if we didn't get it */
530 if(!win32)
531 yywarning("LANGUAGE not supported in 16-bit mode");
532 if(currentlanguage)
533 free(currentlanguage);
534 if (get_language_codepage($3, $5) == -1)
535 yyerror( "Language %04x is not supported", ($5<<10) + $3);
536 currentlanguage = new_language($3, $5);
537 $$ = NULL;
538 chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
543 * Remapping of numerical resource types
544 * (see also comment of called function below)
546 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
550 * Get a valid name/id
552 nameid : expr {
553 if($1 > 65535 || $1 < -32768)
554 yyerror("Resource's ID out of range (%d)", $1);
555 $$ = new_name_id();
556 $$->type = name_ord;
557 $$->name.i_name = $1;
559 | tIDENT {
560 $$ = new_name_id();
561 $$->type = name_str;
562 $$->name.s_name = $1;
567 * Extra string recognition for CLASS statement in dialogs
569 nameid_s: nameid { $$ = $1; }
570 | tSTRING {
571 $$ = new_name_id();
572 $$->type = name_str;
573 $$->name.s_name = $1;
577 /* get the value for a single resource*/
578 resource_definition
579 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
580 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
581 | cursor {
582 resource_t *rsc;
583 if($1->type == res_anicur)
585 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
587 else if($1->type == res_curg)
589 cursor_t *cur;
590 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
591 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
593 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
594 rsc->prev->next = rsc;
595 rsc = rsc->prev;
596 rsc->name = new_name_id();
597 rsc->name->type = name_ord;
598 rsc->name->name.i_name = cur->id;
601 else
602 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
603 free($1);
605 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
606 | dialogex {
607 if(win32)
608 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
609 else
610 $$ = NULL;
612 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
613 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
614 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
615 | icon {
616 resource_t *rsc;
617 if($1->type == res_aniico)
619 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
621 else if($1->type == res_icog)
623 icon_t *ico;
624 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
625 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
627 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
628 rsc->prev->next = rsc;
629 rsc = rsc->prev;
630 rsc->name = new_name_id();
631 rsc->name->type = name_ord;
632 rsc->name->name.i_name = ico->id;
635 else
636 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
637 free($1);
639 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
640 | menuex {
641 if(win32)
642 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
643 else
644 $$ = NULL;
646 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, dup_language(currentlanguage)); }
647 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
648 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
649 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
650 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
654 filename: tFILENAME { $$ = make_filename($1); }
655 | tIDENT { $$ = make_filename($1); }
656 | tSTRING { $$ = make_filename($1); }
659 /* ------------------------------ Bitmap ------------------------------ */
660 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
663 /* ------------------------------ Cursor ------------------------------ */
664 cursor : tCURSOR loadmemopts file_raw {
665 $$ = new_ani_any();
666 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
668 $$->type = res_anicur;
669 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
671 else
673 $$->type = res_curg;
674 $$->u.curg = new_cursor_group($3, $2);
679 /* ------------------------------ Icon ------------------------------ */
680 icon : tICON loadmemopts file_raw {
681 $$ = new_ani_any();
682 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
684 $$->type = res_aniico;
685 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
687 else
689 $$->type = res_icog;
690 $$->u.icog = new_icon_group($3, $2);
695 /* ------------------------------ Font ------------------------------ */
697 * The reading of raw_data for fonts is a Borland BRC
698 * extension. MS generates an error. However, it is
699 * most logical to support this, considering how wine
700 * enters things in CVS (ascii).
702 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
706 * The fontdir is a Borland BRC extension which only
707 * reads the data as 'raw_data' from the file.
708 * I don't know whether it is interpreted.
709 * The fontdir is generated if it was not present and
710 * fonts are defined in the source.
712 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
715 /* ------------------------------ MessageTable ------------------------------ */
716 /* It might be interesting to implement the MS Message compiler here as well
717 * to get everything in one source. Might be a future project.
719 messagetable
720 : tMESSAGETABLE loadmemopts file_raw {
721 if(!win32)
722 yywarning("MESSAGETABLE not supported in 16-bit mode");
723 $$ = new_messagetable($3, $2);
727 /* ------------------------------ RCData ------------------------------ */
728 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
731 /* ------------------------------ DLGINIT ------------------------------ */
732 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
735 /* ------------------------------ UserType ------------------------------ */
736 userres : usertype loadmemopts file_raw {
737 #ifdef WORDS_BIGENDIAN
738 if(pedantic && byteorder != WRC_BO_LITTLE)
739 #else
740 if(pedantic && byteorder == WRC_BO_BIG)
741 #endif
742 yywarning("Byteordering is not little-endian and type cannot be interpreted");
743 $$ = new_user($1, $3, $2);
747 usertype: tNUMBER {
748 $$ = new_name_id();
749 $$->type = name_ord;
750 $$->name.i_name = $1;
752 | tIDENT {
753 $$ = new_name_id();
754 $$->type = name_str;
755 $$->name.s_name = $1;
759 /* ------------------------------ Accelerator ------------------------------ */
760 accelerators
761 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
762 $$ = new_accelerator();
763 if($2)
765 $$->memopt = *($2);
766 free($2);
768 else
770 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
772 if(!$5)
773 yyerror("Accelerator table must have at least one entry");
774 $$->events = get_event_head($5);
775 if($3)
777 $$->lvc = *($3);
778 free($3);
780 if(!$$->lvc.language)
781 $$->lvc.language = dup_language(currentlanguage);
785 events : /* Empty */ { $$=NULL; }
786 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
787 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
791 * The empty rule generates a s/r conflict because of {bi,u}nary expr
792 * on - and +. It cannot be solved in any way because it is the same as
793 * the if/then/else problem (LALR(1) problem). The conflict is moved
794 * away by forcing it to be in the expression handling below.
796 acc_opt : /* Empty */ { $$ = 0; }
797 | ',' accs { $$ = $2; }
800 accs : acc { $$ = $1; }
801 | accs ',' acc { $$ = $1 | $3; }
804 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
805 | tSHIFT { $$ = WRC_AF_SHIFT; }
806 | tCONTROL { $$ = WRC_AF_CONTROL; }
807 | tALT { $$ = WRC_AF_ALT; }
808 | tASCII { $$ = WRC_AF_ASCII; }
809 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
812 /* ------------------------------ Dialog ------------------------------ */
813 /* FIXME: Support EXSTYLE in the dialog line itself */
814 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
815 tBEGIN ctrls tEND {
816 if($2)
818 $10->memopt = *($2);
819 free($2);
821 else
822 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
823 $10->x = $3;
824 $10->y = $5;
825 $10->width = $7;
826 $10->height = $9;
827 $10->controls = get_control_head($12);
828 $$ = $10;
829 if(!$$->gotstyle)
831 $$->style->or_mask = WS_POPUP;
832 $$->gotstyle = TRUE;
834 if($$->title)
835 $$->style->or_mask |= WS_CAPTION;
836 if($$->font)
837 $$->style->or_mask |= DS_SETFONT;
839 $$->style->or_mask &= ~($$->style->and_mask);
840 $$->style->and_mask = 0;
842 if(!$$->lvc.language)
843 $$->lvc.language = dup_language(currentlanguage);
847 dlg_attributes
848 : /* Empty */ { $$=new_dialog(); }
849 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
850 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
851 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
852 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
853 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
854 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
855 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
856 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
857 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
860 ctrls : /* Empty */ { $$ = NULL; }
861 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
862 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
863 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
864 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
865 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
866 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
867 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
868 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
869 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
870 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
871 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
872 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
873 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
874 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
875 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
876 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
877 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
878 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
879 /* special treatment for icons, as the extent is optional */
880 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
881 $10->title = $3;
882 $10->id = $5;
883 $10->x = $7;
884 $10->y = $9;
885 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
889 lab_ctrl
890 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style {
891 $$=new_control();
892 $$->title = new_name_id();
893 $$->title->type = name_str;
894 $$->title->name.s_name = $1;
895 $$->id = $3;
896 $$->x = $5;
897 $$->y = $7;
898 $$->width = $9;
899 $$->height = $11;
900 if($12)
902 $$->style = $12;
903 $$->gotstyle = TRUE;
908 ctrl_desc
909 : expr ',' expr ',' expr ',' expr ',' expr optional_style {
910 $$ = new_control();
911 $$->id = $1;
912 $$->x = $3;
913 $$->y = $5;
914 $$->width = $7;
915 $$->height = $9;
916 if($10)
918 $$->style = $10;
919 $$->gotstyle = TRUE;
924 iconinfo: /* Empty */
925 { $$ = new_control(); }
927 | ',' expr ',' expr {
928 $$ = new_control();
929 $$->width = $2;
930 $$->height = $4;
932 | ',' expr ',' expr ',' style {
933 $$ = new_control();
934 $$->width = $2;
935 $$->height = $4;
936 $$->style = $6;
937 $$->gotstyle = TRUE;
939 | ',' expr ',' expr ',' style ',' style {
940 $$ = new_control();
941 $$->width = $2;
942 $$->height = $4;
943 $$->style = $6;
944 $$->gotstyle = TRUE;
945 $$->exstyle = $8;
946 $$->gotexstyle = TRUE;
950 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
951 $$=new_control();
952 $$->title = $1;
953 $$->id = $3;
954 $$->ctlclass = convert_ctlclass($5);
955 $$->style = $7;
956 $$->gotstyle = TRUE;
957 $$->x = $9;
958 $$->y = $11;
959 $$->width = $13;
960 $$->height = $15;
961 $$->exstyle = $17;
962 $$->gotexstyle = TRUE;
964 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
965 $$=new_control();
966 $$->title = $1;
967 $$->id = $3;
968 $$->ctlclass = convert_ctlclass($5);
969 $$->style = $7;
970 $$->gotstyle = TRUE;
971 $$->x = $9;
972 $$->y = $11;
973 $$->width = $13;
974 $$->height = $15;
978 opt_font
979 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
982 /* ------------------------------ style flags ------------------------------ */
983 optional_style /* Abbused once to get optional ExStyle */
984 : /* Empty */ { $$ = NULL; }
985 | ',' style { $$ = $2; }
988 optional_style_pair
989 : /* Empty */ { $$ = NULL; }
990 | ',' style { $$ = new_style_pair($2, 0); }
991 | ',' style ',' style { $$ = new_style_pair($2, $4); }
994 style
995 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
996 | '(' style ')' { $$ = $2; }
997 | any_num { $$ = new_style($1, 0); }
998 | tNOT any_num { $$ = new_style(0, $2); }
1001 ctlclass
1002 : expr {
1003 $$ = new_name_id();
1004 $$->type = name_ord;
1005 $$->name.i_name = $1;
1007 | tSTRING {
1008 $$ = new_name_id();
1009 $$->type = name_str;
1010 $$->name.s_name = $1;
1014 /* ------------------------------ DialogEx ------------------------------ */
1015 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
1016 tBEGIN exctrls tEND {
1017 if(!win32)
1018 yywarning("DIALOGEX not supported in 16-bit mode");
1019 if($2)
1021 $11->memopt = *($2);
1022 free($2);
1024 else
1025 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1026 $11->x = $3;
1027 $11->y = $5;
1028 $11->width = $7;
1029 $11->height = $9;
1030 if($10)
1032 $11->helpid = *($10);
1033 $11->gothelpid = TRUE;
1034 free($10);
1036 $11->controls = get_control_head($13);
1037 $$ = $11;
1039 assert($$->style != NULL);
1040 if(!$$->gotstyle)
1042 $$->style->or_mask = WS_POPUP;
1043 $$->gotstyle = TRUE;
1045 if($$->title)
1046 $$->style->or_mask |= WS_CAPTION;
1047 if($$->font)
1048 $$->style->or_mask |= DS_SETFONT;
1050 $$->style->or_mask &= ~($$->style->and_mask);
1051 $$->style->and_mask = 0;
1053 if(!$$->lvc.language)
1054 $$->lvc.language = dup_language(currentlanguage);
1058 dlgex_attribs
1059 : /* Empty */ { $$=new_dialogex(); }
1060 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
1061 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
1062 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1063 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1064 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1065 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1066 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1067 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1068 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1069 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1072 exctrls : /* Empty */ { $$ = NULL; }
1073 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1074 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1075 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1076 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1077 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1078 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1079 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1080 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1081 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1082 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1083 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1084 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1085 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1086 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1087 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1088 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1089 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1090 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1091 /* special treatment for icons, as the extent is optional */
1092 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1093 $10->title = $3;
1094 $10->id = $5;
1095 $10->x = $7;
1096 $10->y = $9;
1097 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1101 gen_exctrl
1102 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1103 expr ',' style helpid opt_data {
1104 $$=new_control();
1105 $$->title = $1;
1106 $$->id = $3;
1107 $$->ctlclass = convert_ctlclass($5);
1108 $$->style = $7;
1109 $$->gotstyle = TRUE;
1110 $$->x = $9;
1111 $$->y = $11;
1112 $$->width = $13;
1113 $$->height = $15;
1114 if($17)
1116 $$->exstyle = $17;
1117 $$->gotexstyle = TRUE;
1119 if($18)
1121 $$->helpid = *($18);
1122 $$->gothelpid = TRUE;
1123 free($18);
1125 $$->extra = $19;
1127 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1128 $$=new_control();
1129 $$->title = $1;
1130 $$->id = $3;
1131 $$->style = $7;
1132 $$->gotstyle = TRUE;
1133 $$->ctlclass = convert_ctlclass($5);
1134 $$->x = $9;
1135 $$->y = $11;
1136 $$->width = $13;
1137 $$->height = $15;
1138 $$->extra = $16;
1142 lab_exctrl
1143 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1144 $$=new_control();
1145 $$->title = new_name_id();
1146 $$->title->type = name_str;
1147 $$->title->name.s_name = $1;
1148 $$->id = $3;
1149 $$->x = $5;
1150 $$->y = $7;
1151 $$->width = $9;
1152 $$->height = $11;
1153 if($12)
1155 $$->style = $12->style;
1156 $$->gotstyle = TRUE;
1158 if ($12->exstyle)
1160 $$->exstyle = $12->exstyle;
1161 $$->gotexstyle = TRUE;
1163 free($12);
1166 $$->extra = $13;
1170 exctrl_desc
1171 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair opt_data {
1172 $$ = new_control();
1173 $$->id = $1;
1174 $$->x = $3;
1175 $$->y = $5;
1176 $$->width = $7;
1177 $$->height = $9;
1178 if($10)
1180 $$->style = $10->style;
1181 $$->gotstyle = TRUE;
1183 if ($10->exstyle)
1185 $$->exstyle = $10->exstyle;
1186 $$->gotexstyle = TRUE;
1188 free($10);
1190 $$->extra = $11;
1194 opt_data: /* Empty */ { $$ = NULL; }
1195 | raw_data { $$ = $1; }
1198 helpid : /* Empty */ { $$ = NULL; }
1199 | ',' expr { $$ = new_int($2); }
1202 opt_exfont
1203 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1207 * FIXME: This odd expression is here to nullify an extra token found
1208 * in some appstudio produced resources which appear to do nothing.
1210 opt_expr: /* Empty */ { $$ = NULL; }
1211 | ',' expr { $$ = NULL; }
1214 /* ------------------------------ Menu ------------------------------ */
1215 menu : tMENU loadmemopts opt_lvc menu_body {
1216 if(!$4)
1217 yyerror("Menu must contain items");
1218 $$ = new_menu();
1219 if($2)
1221 $$->memopt = *($2);
1222 free($2);
1224 else
1225 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1226 $$->items = get_item_head($4);
1227 if($3)
1229 $$->lvc = *($3);
1230 free($3);
1232 if(!$$->lvc.language)
1233 $$->lvc.language = dup_language(currentlanguage);
1237 menu_body
1238 : tBEGIN item_definitions tEND { $$ = $2; }
1241 item_definitions
1242 : /* Empty */ {$$ = NULL;}
1243 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1244 $$=new_menu_item();
1245 $$->prev = $1;
1246 if($1)
1247 $1->next = $$;
1248 $$->id = $5;
1249 $$->state = $6;
1250 $$->name = $3;
1252 | item_definitions tMENUITEM tSEPARATOR {
1253 $$=new_menu_item();
1254 $$->prev = $1;
1255 if($1)
1256 $1->next = $$;
1258 | item_definitions tPOPUP tSTRING item_options menu_body {
1259 $$ = new_menu_item();
1260 $$->prev = $1;
1261 if($1)
1262 $1->next = $$;
1263 $$->popup = get_item_head($5);
1264 $$->name = $3;
1268 /* NOTE: item_options is right recursive because it would introduce
1269 * a shift/reduce conflict on ',' in itemex_options due to the
1270 * empty rule here. The parser is now forced to look beyond the ','
1271 * before reducing (force shift).
1272 * Right recursion here is not a problem because we cannot expect
1273 * more than 7 parserstack places to be occupied while parsing this
1274 * (who would want to specify a MF_x flag twice?).
1276 item_options
1277 : /* Empty */ { $$ = 0; }
1278 | ',' tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1279 | ',' tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1280 | ',' tHELP item_options { $$ = $3 | MF_HELP; }
1281 | ',' tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1282 | ',' tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1283 | ',' tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1286 /* ------------------------------ MenuEx ------------------------------ */
1287 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1288 if(!win32)
1289 yywarning("MENUEX not supported in 16-bit mode");
1290 if(!$4)
1291 yyerror("MenuEx must contain items");
1292 $$ = new_menuex();
1293 if($2)
1295 $$->memopt = *($2);
1296 free($2);
1298 else
1299 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1300 $$->items = get_itemex_head($4);
1301 if($3)
1303 $$->lvc = *($3);
1304 free($3);
1306 if(!$$->lvc.language)
1307 $$->lvc.language = dup_language(currentlanguage);
1311 menuex_body
1312 : tBEGIN itemex_definitions tEND { $$ = $2; }
1315 itemex_definitions
1316 : /* Empty */ {$$ = NULL; }
1317 | itemex_definitions tMENUITEM tSTRING itemex_options {
1318 $$ = new_menuex_item();
1319 $$->prev = $1;
1320 if($1)
1321 $1->next = $$;
1322 $$->name = $3;
1323 $$->id = $4->id;
1324 $$->type = $4->type;
1325 $$->state = $4->state;
1326 $$->helpid = $4->helpid;
1327 $$->gotid = $4->gotid;
1328 $$->gottype = $4->gottype;
1329 $$->gotstate = $4->gotstate;
1330 $$->gothelpid = $4->gothelpid;
1331 free($4);
1333 | itemex_definitions tMENUITEM tSEPARATOR {
1334 $$ = new_menuex_item();
1335 $$->prev = $1;
1336 if($1)
1337 $1->next = $$;
1339 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1340 $$ = new_menuex_item();
1341 $$->prev = $1;
1342 if($1)
1343 $1->next = $$;
1344 $$->popup = get_itemex_head($5);
1345 $$->name = $3;
1346 $$->id = $4->id;
1347 $$->type = $4->type;
1348 $$->state = $4->state;
1349 $$->helpid = $4->helpid;
1350 $$->gotid = $4->gotid;
1351 $$->gottype = $4->gottype;
1352 $$->gotstate = $4->gotstate;
1353 $$->gothelpid = $4->gothelpid;
1354 free($4);
1358 itemex_options
1359 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1360 | ',' expr {
1361 $$ = new_itemex_opt($2, 0, 0, 0);
1362 $$->gotid = TRUE;
1364 | ',' e_expr ',' e_expr item_options {
1365 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1366 $$->gotid = TRUE;
1367 $$->gottype = TRUE;
1368 $$->gotstate = TRUE;
1369 if($2) free($2);
1370 if($4) free($4);
1372 | ',' e_expr ',' e_expr ',' expr {
1373 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1374 $$->gotid = TRUE;
1375 $$->gottype = TRUE;
1376 $$->gotstate = TRUE;
1377 if($2) free($2);
1378 if($4) free($4);
1382 itemex_p_options
1383 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1384 | ',' expr {
1385 $$ = new_itemex_opt($2, 0, 0, 0);
1386 $$->gotid = TRUE;
1388 | ',' e_expr ',' expr {
1389 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1390 if($2) free($2);
1391 $$->gotid = TRUE;
1392 $$->gottype = TRUE;
1394 | ',' e_expr ',' e_expr ',' expr {
1395 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1396 if($2) free($2);
1397 if($4) free($4);
1398 $$->gotid = TRUE;
1399 $$->gottype = TRUE;
1400 $$->gotstate = TRUE;
1402 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1403 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1404 if($2) free($2);
1405 if($4) free($4);
1406 if($6) free($6);
1407 $$->gotid = TRUE;
1408 $$->gottype = TRUE;
1409 $$->gotstate = TRUE;
1410 $$->gothelpid = TRUE;
1414 /* ------------------------------ StringTable ------------------------------ */
1415 /* Stringtables are parsed differently than other resources because their
1416 * layout is substantially different from other resources.
1417 * The table is parsed through a _global_ variable 'tagstt' which holds the
1418 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1419 * list of stringtables of different languages.
1421 stringtable
1422 : stt_head tBEGIN strings tEND {
1423 if(!$3)
1425 yyerror("Stringtable must have at least one entry");
1427 else
1429 stringtable_t *stt;
1430 /* Check if we added to a language table or created
1431 * a new one.
1433 for(stt = sttres; stt; stt = stt->next)
1435 if(stt == tagstt)
1436 break;
1438 if(!stt)
1440 /* It is a new one */
1441 if(sttres)
1443 sttres->prev = tagstt;
1444 tagstt->next = sttres;
1445 sttres = tagstt;
1447 else
1448 sttres = tagstt;
1450 /* Else were done */
1452 if(tagstt_memopt)
1454 free(tagstt_memopt);
1455 tagstt_memopt = NULL;
1458 $$ = tagstt;
1462 /* This is to get the language of the currently parsed stringtable */
1463 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1464 if((tagstt = find_stringtable($3)) == NULL)
1465 tagstt = new_stringtable($3);
1466 tagstt_memopt = $2;
1467 tagstt_version = $3->version;
1468 tagstt_characts = $3->characts;
1469 if($3)
1470 free($3);
1474 strings : /* Empty */ { $$ = NULL; }
1475 | strings expr opt_comma tSTRING {
1476 int i;
1477 assert(tagstt != NULL);
1478 if($2 > 65535 || $2 < -32768)
1479 yyerror("Stringtable entry's ID out of range (%d)", $2);
1480 /* Search for the ID */
1481 for(i = 0; i < tagstt->nentries; i++)
1483 if(tagstt->entries[i].id == $2)
1484 yyerror("Stringtable ID %d already in use", $2);
1486 /* If we get here, then we have a new unique entry */
1487 tagstt->nentries++;
1488 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1489 tagstt->entries[tagstt->nentries-1].id = $2;
1490 tagstt->entries[tagstt->nentries-1].str = $4;
1491 if(tagstt_memopt)
1492 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1493 else
1494 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1495 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1496 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1498 if(pedantic && !$4->size)
1499 yywarning("Zero length strings make no sense");
1500 if(!win32 && $4->size > 254)
1501 yyerror("Stringtable entry more than 254 characters");
1502 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1503 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1504 $$ = tagstt;
1508 opt_comma /* There seem to be two ways to specify a stringtable... */
1509 : /* Empty */
1510 | ','
1513 /* ------------------------------ VersionInfo ------------------------------ */
1514 versioninfo
1515 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1516 $$ = $3;
1517 if($2)
1519 $$->memopt = *($2);
1520 free($2);
1522 else
1523 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1524 $$->blocks = get_ver_block_head($5);
1525 /* Set language; there is no version or characteristics */
1526 $$->lvc.language = dup_language(currentlanguage);
1530 fix_version
1531 : /* Empty */ { $$ = new_versioninfo(); }
1532 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1533 if($1->gotit.fv)
1534 yyerror("FILEVERSION already defined");
1535 $$ = $1;
1536 $$->filever_maj1 = $3;
1537 $$->filever_maj2 = $5;
1538 $$->filever_min1 = $7;
1539 $$->filever_min2 = $9;
1540 $$->gotit.fv = 1;
1542 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1543 if($1->gotit.pv)
1544 yyerror("PRODUCTVERSION already defined");
1545 $$ = $1;
1546 $$->prodver_maj1 = $3;
1547 $$->prodver_maj2 = $5;
1548 $$->prodver_min1 = $7;
1549 $$->prodver_min2 = $9;
1550 $$->gotit.pv = 1;
1552 | fix_version tFILEFLAGS expr {
1553 if($1->gotit.ff)
1554 yyerror("FILEFLAGS already defined");
1555 $$ = $1;
1556 $$->fileflags = $3;
1557 $$->gotit.ff = 1;
1559 | fix_version tFILEFLAGSMASK expr {
1560 if($1->gotit.ffm)
1561 yyerror("FILEFLAGSMASK already defined");
1562 $$ = $1;
1563 $$->fileflagsmask = $3;
1564 $$->gotit.ffm = 1;
1566 | fix_version tFILEOS expr {
1567 if($1->gotit.fo)
1568 yyerror("FILEOS already defined");
1569 $$ = $1;
1570 $$->fileos = $3;
1571 $$->gotit.fo = 1;
1573 | fix_version tFILETYPE expr {
1574 if($1->gotit.ft)
1575 yyerror("FILETYPE already defined");
1576 $$ = $1;
1577 $$->filetype = $3;
1578 $$->gotit.ft = 1;
1580 | fix_version tFILESUBTYPE expr {
1581 if($1->gotit.fst)
1582 yyerror("FILESUBTYPE already defined");
1583 $$ = $1;
1584 $$->filesubtype = $3;
1585 $$->gotit.fst = 1;
1589 ver_blocks
1590 : /* Empty */ { $$ = NULL; }
1591 | ver_blocks ver_block {
1592 $$ = $2;
1593 $$->prev = $1;
1594 if($1)
1595 $1->next = $$;
1599 ver_block
1600 : tBLOCK tSTRING tBEGIN ver_values tEND {
1601 $$ = new_ver_block();
1602 $$->name = $2;
1603 $$->values = get_ver_value_head($4);
1607 ver_values
1608 : /* Empty */ { $$ = NULL; }
1609 | ver_values ver_value {
1610 $$ = $2;
1611 $$->prev = $1;
1612 if($1)
1613 $1->next = $$;
1617 ver_value
1618 : ver_block {
1619 $$ = new_ver_value();
1620 $$->type = val_block;
1621 $$->value.block = $1;
1623 | tVALUE tSTRING ',' tSTRING {
1624 $$ = new_ver_value();
1625 $$->type = val_str;
1626 $$->key = $2;
1627 $$->value.str = $4;
1629 | tVALUE tSTRING ',' ver_words {
1630 $$ = new_ver_value();
1631 $$->type = val_words;
1632 $$->key = $2;
1633 $$->value.words = $4;
1637 ver_words
1638 : expr { $$ = new_ver_words($1); }
1639 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1642 /* ------------------------------ Toolbar ------------------------------ */
1643 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1644 int nitems;
1645 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1646 $$ = new_toolbar($3, $5, items, nitems);
1647 if($2)
1649 $$->memopt = *($2);
1650 free($2);
1652 else
1654 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1656 if($6)
1658 $$->lvc = *($6);
1659 free($6);
1661 if(!$$->lvc.language)
1663 $$->lvc.language = dup_language(currentlanguage);
1668 toolbar_items
1669 : /* Empty */ { $$ = NULL; }
1670 | toolbar_items tBUTTON expr {
1671 toolbar_item_t *idrec = new_toolbar_item();
1672 idrec->id = $3;
1673 $$ = ins_tlbr_button($1, idrec);
1675 | toolbar_items tSEPARATOR {
1676 toolbar_item_t *idrec = new_toolbar_item();
1677 idrec->id = 0;
1678 $$ = ins_tlbr_button($1, idrec);
1682 /* ------------------------------ Memory options ------------------------------ */
1683 loadmemopts
1684 : /* Empty */ { $$ = NULL; }
1685 | loadmemopts lamo {
1686 if($1)
1688 *($1) |= *($2);
1689 $$ = $1;
1690 free($2);
1692 else
1693 $$ = $2;
1695 | loadmemopts lama {
1696 if($1)
1698 *($1) &= *($2);
1699 $$ = $1;
1700 free($2);
1702 else
1704 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1705 $$ = $2;
1710 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1711 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1712 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1713 | tPURE { $$ = new_int(WRC_MO_PURE); }
1716 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1717 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1718 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1721 /* ------------------------------ Win32 options ------------------------------ */
1722 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1723 | opt_lvc opt_language {
1724 if(!win32)
1725 yywarning("LANGUAGE not supported in 16-bit mode");
1726 if($1->language)
1727 yyerror("Language already defined");
1728 $$ = $1;
1729 $1->language = $2;
1731 | opt_lvc opt_characts {
1732 if(!win32)
1733 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1734 if($1->characts)
1735 yyerror("Characteristics already defined");
1736 $$ = $1;
1737 $1->characts = $2;
1739 | opt_lvc opt_version {
1740 if(!win32)
1741 yywarning("VERSION not supported in 16-bit mode");
1742 if($1->version)
1743 yyerror("Version already defined");
1744 $$ = $1;
1745 $1->version = $2;
1750 * This here is another s/r conflict on {bi,u}nary + and -.
1751 * It is due to the look-ahead which must determine when the
1752 * rule opt_language ends. It could be solved with adding a
1753 * tNL at the end, but that seems unreasonable to do.
1754 * The conflict is now moved to the expression handling below.
1756 opt_language
1757 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
1758 if (get_language_codepage($2, $4) == -1)
1759 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1763 opt_characts
1764 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1767 opt_version
1768 : tVERSION expr { $$ = new_version($2); }
1771 /* ------------------------------ Raw data handling ------------------------------ */
1772 raw_data: opt_lvc tBEGIN raw_elements tEND {
1773 if($1)
1775 $3->lvc = *($1);
1776 free($1);
1779 if(!$3->lvc.language)
1780 $3->lvc.language = dup_language(currentlanguage);
1782 $$ = $3;
1786 raw_elements
1787 : tRAWDATA { $$ = $1; }
1788 | tNUMBER { $$ = int2raw_data($1); }
1789 | tLNUMBER { $$ = long2raw_data($1); }
1790 | tSTRING { $$ = str2raw_data($1); }
1791 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1792 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1793 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1794 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1797 /* File data or raw data */
1798 file_raw: filename {
1799 $$ = load_file($1);
1800 $$->lvc.language = dup_language(currentlanguage);
1802 | raw_data { $$ = $1; }
1805 /* ------------------------------ Win32 expressions ------------------------------ */
1806 /* All win16 numbers are also handled here. This is inconsistent with MS'
1807 * resource compiler, but what the heck, its just handy to have.
1809 e_expr : /* Empty */ { $$ = 0; }
1810 | expr { $$ = new_int($1); }
1813 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1814 expr : xpr { $$ = ($1); }
1817 xpr : xpr '+' xpr { $$ = ($1) + ($3); }
1818 | xpr '-' xpr { $$ = ($1) - ($3); }
1819 | xpr '|' xpr { $$ = ($1) | ($3); }
1820 | xpr '&' xpr { $$ = ($1) & ($3); }
1821 | xpr '*' xpr { $$ = ($1) * ($3); }
1822 | xpr '/' xpr { $$ = ($1) / ($3); }
1823 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1824 | '~' xpr { $$ = ~($2); }
1825 | '-' xpr %prec pUPM { $$ = -($2); }
1826 | '+' xpr %prec pUPM { $$ = $2; }
1827 | '(' xpr ')' { $$ = $2; }
1828 | any_num { $$ = $1; }
1829 | tNOT any_num { $$ = ~($2); }
1832 any_num : tNUMBER { $$ = $1; }
1833 | tLNUMBER { $$ = $1; }
1837 /* Dialog specific functions */
1838 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1840 assert(dlg != NULL);
1841 if(dlg->style == NULL)
1843 dlg->style = new_style(0,0);
1846 if(dlg->gotstyle)
1848 yywarning("Style already defined, or-ing together");
1850 else
1852 dlg->style->or_mask = 0;
1853 dlg->style->and_mask = 0;
1855 dlg->style->or_mask |= st->or_mask;
1856 dlg->style->and_mask |= st->and_mask;
1857 dlg->gotstyle = TRUE;
1858 free(st);
1859 return dlg;
1862 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1864 assert(dlg != NULL);
1865 if(dlg->exstyle == NULL)
1867 dlg->exstyle = new_style(0,0);
1870 if(dlg->gotexstyle)
1872 yywarning("ExStyle already defined, or-ing together");
1874 else
1876 dlg->exstyle->or_mask = 0;
1877 dlg->exstyle->and_mask = 0;
1879 dlg->exstyle->or_mask |= st->or_mask;
1880 dlg->exstyle->and_mask |= st->and_mask;
1881 dlg->gotexstyle = TRUE;
1882 free(st);
1883 return dlg;
1886 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1888 assert(dlg != NULL);
1889 if(dlg->title)
1890 yyerror("Caption already defined");
1891 dlg->title = s;
1892 return dlg;
1895 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1897 assert(dlg != NULL);
1898 if(dlg->font)
1899 yyerror("Font already defined");
1900 dlg->font = f;
1901 return dlg;
1904 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1906 assert(dlg != NULL);
1907 if(dlg->dlgclass)
1908 yyerror("Class already defined");
1909 dlg->dlgclass = n;
1910 return dlg;
1913 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1915 assert(dlg != NULL);
1916 if(dlg->menu)
1917 yyerror("Menu already defined");
1918 dlg->menu = m;
1919 return dlg;
1922 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1924 assert(dlg != NULL);
1925 if(dlg->lvc.language)
1926 yyerror("Language already defined");
1927 dlg->lvc.language = l;
1928 return dlg;
1931 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1933 assert(dlg != NULL);
1934 if(dlg->lvc.characts)
1935 yyerror("Characteristics already defined");
1936 dlg->lvc.characts = c;
1937 return dlg;
1940 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1942 assert(dlg != NULL);
1943 if(dlg->lvc.version)
1944 yyerror("Version already defined");
1945 dlg->lvc.version = v;
1946 return dlg;
1949 /* Controls specific functions */
1950 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1952 /* Hm... this seems to be jammed in at all time... */
1953 int defaultstyle = WS_CHILD | WS_VISIBLE;
1955 assert(ctrl != NULL);
1956 ctrl->prev = prev;
1958 if(prev)
1959 prev->next = ctrl;
1961 if(type != -1)
1963 ctrl->ctlclass = new_name_id();
1964 ctrl->ctlclass->type = name_ord;
1965 ctrl->ctlclass->name.i_name = type;
1968 switch(type)
1970 case CT_BUTTON:
1971 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1972 defaultstyle |= WS_TABSTOP;
1973 break;
1974 case CT_EDIT:
1975 defaultstyle |= WS_TABSTOP | WS_BORDER;
1976 break;
1977 case CT_LISTBOX:
1978 defaultstyle |= LBS_NOTIFY | WS_BORDER;
1979 break;
1980 case CT_COMBOBOX:
1981 defaultstyle |= CBS_SIMPLE;
1982 break;
1983 case CT_STATIC:
1984 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
1985 defaultstyle |= WS_GROUP;
1986 break;
1989 if(!ctrl->gotstyle) /* Handle default style setting */
1991 switch(type)
1993 case CT_EDIT:
1994 defaultstyle |= ES_LEFT;
1995 break;
1996 case CT_LISTBOX:
1997 defaultstyle |= LBS_NOTIFY;
1998 break;
1999 case CT_COMBOBOX:
2000 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
2001 break;
2002 case CT_SCROLLBAR:
2003 defaultstyle |= SBS_HORZ;
2004 break;
2005 case CT_BUTTON:
2006 switch(special_style)
2008 case BS_CHECKBOX:
2009 case BS_DEFPUSHBUTTON:
2010 case BS_PUSHBUTTON:
2011 case BS_GROUPBOX:
2012 /* case BS_PUSHBOX: */
2013 case BS_AUTORADIOBUTTON:
2014 case BS_AUTO3STATE:
2015 case BS_3STATE:
2016 case BS_AUTOCHECKBOX:
2017 defaultstyle |= WS_TABSTOP;
2018 break;
2019 default:
2020 yywarning("Unknown default button control-style 0x%08x", special_style);
2021 case BS_RADIOBUTTON:
2022 break;
2024 break;
2026 case CT_STATIC:
2027 switch(special_style)
2029 case SS_LEFT:
2030 case SS_RIGHT:
2031 case SS_CENTER:
2032 defaultstyle |= WS_GROUP;
2033 break;
2034 case SS_ICON: /* Special case */
2035 break;
2036 default:
2037 yywarning("Unknown default static control-style 0x%08x", special_style);
2038 break;
2040 break;
2041 case -1: /* Generic control */
2042 goto byebye;
2044 default:
2045 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2049 /* The SS_ICON flag is always forced in for icon controls */
2050 if(type == CT_STATIC && special_style == SS_ICON)
2051 defaultstyle |= SS_ICON;
2053 if (!ctrl->gotstyle)
2054 ctrl->style = new_style(0,0);
2056 /* combine all styles */
2057 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2058 ctrl->gotstyle = TRUE;
2059 byebye:
2060 /* combine with NOT mask */
2061 if (ctrl->gotstyle)
2063 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2064 ctrl->style->and_mask = 0;
2066 if (ctrl->gotexstyle)
2068 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2069 ctrl->exstyle->and_mask = 0;
2071 return ctrl;
2074 static name_id_t *convert_ctlclass(name_id_t *cls)
2076 char *cc = NULL;
2077 int iclass;
2079 if(cls->type == name_ord)
2080 return cls;
2081 assert(cls->type == name_str);
2082 if(cls->type == str_unicode)
2084 yyerror("Don't yet support unicode class comparison");
2086 else
2087 cc = cls->name.s_name->str.cstr;
2089 if(!strcasecmp("BUTTON", cc))
2090 iclass = CT_BUTTON;
2091 else if(!strcasecmp("COMBOBOX", cc))
2092 iclass = CT_COMBOBOX;
2093 else if(!strcasecmp("LISTBOX", cc))
2094 iclass = CT_LISTBOX;
2095 else if(!strcasecmp("EDIT", cc))
2096 iclass = CT_EDIT;
2097 else if(!strcasecmp("STATIC", cc))
2098 iclass = CT_STATIC;
2099 else if(!strcasecmp("SCROLLBAR", cc))
2100 iclass = CT_SCROLLBAR;
2101 else
2102 return cls; /* No default, return user controlclass */
2104 free(cls->name.s_name->str.cstr);
2105 free(cls->name.s_name);
2106 cls->type = name_ord;
2107 cls->name.i_name = iclass;
2108 return cls;
2111 /* DialogEx specific functions */
2112 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2114 assert(dlg != NULL);
2115 if(dlg->style == NULL)
2117 dlg->style = new_style(0,0);
2120 if(dlg->gotstyle)
2122 yywarning("Style already defined, or-ing together");
2124 else
2126 dlg->style->or_mask = 0;
2127 dlg->style->and_mask = 0;
2129 dlg->style->or_mask |= st->or_mask;
2130 dlg->style->and_mask |= st->and_mask;
2131 dlg->gotstyle = TRUE;
2132 free(st);
2133 return dlg;
2136 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2138 assert(dlg != NULL);
2139 if(dlg->exstyle == NULL)
2141 dlg->exstyle = new_style(0,0);
2144 if(dlg->gotexstyle)
2146 yywarning("ExStyle already defined, or-ing together");
2148 else
2150 dlg->exstyle->or_mask = 0;
2151 dlg->exstyle->and_mask = 0;
2153 dlg->exstyle->or_mask |= st->or_mask;
2154 dlg->exstyle->and_mask |= st->and_mask;
2155 dlg->gotexstyle = TRUE;
2156 free(st);
2157 return dlg;
2160 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2162 assert(dlg != NULL);
2163 if(dlg->title)
2164 yyerror("Caption already defined");
2165 dlg->title = s;
2166 return dlg;
2169 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2171 assert(dlg != NULL);
2172 if(dlg->font)
2173 yyerror("Font already defined");
2174 dlg->font = f;
2175 return dlg;
2178 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2180 assert(dlg != NULL);
2181 if(dlg->dlgclass)
2182 yyerror("Class already defined");
2183 dlg->dlgclass = n;
2184 return dlg;
2187 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2189 assert(dlg != NULL);
2190 if(dlg->menu)
2191 yyerror("Menu already defined");
2192 dlg->menu = m;
2193 return dlg;
2196 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2198 assert(dlg != NULL);
2199 if(dlg->lvc.language)
2200 yyerror("Language already defined");
2201 dlg->lvc.language = l;
2202 return dlg;
2205 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2207 assert(dlg != NULL);
2208 if(dlg->lvc.characts)
2209 yyerror("Characteristics already defined");
2210 dlg->lvc.characts = c;
2211 return dlg;
2214 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2216 assert(dlg != NULL);
2217 if(dlg->lvc.version)
2218 yyerror("Version already defined");
2219 dlg->lvc.version = v;
2220 return dlg;
2223 /* Accelerator specific functions */
2224 static event_t *add_event(int key, int id, int flags, event_t *prev)
2226 event_t *ev = new_event();
2228 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2229 yyerror("Cannot use both ASCII and VIRTKEY");
2231 ev->key = key;
2232 ev->id = id;
2233 ev->flags = flags & ~WRC_AF_ASCII;
2234 ev->prev = prev;
2235 if(prev)
2236 prev->next = ev;
2237 return ev;
2240 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2242 int keycode = 0;
2243 event_t *ev = new_event();
2245 if(key->type != str_char)
2246 yyerror("Key code must be an ascii string");
2248 if((flags & WRC_AF_VIRTKEY) && (!isupper(key->str.cstr[0] & 0xff) && !isdigit(key->str.cstr[0] & 0xff)))
2249 yyerror("VIRTKEY code is not equal to ascii value");
2251 if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
2253 yyerror("Cannot use both '^' and CONTROL modifier");
2255 else if(key->str.cstr[0] == '^')
2257 keycode = toupper(key->str.cstr[1]) - '@';
2258 if(keycode >= ' ')
2259 yyerror("Control-code out of range");
2261 else
2262 keycode = key->str.cstr[0];
2263 ev->key = keycode;
2264 ev->id = id;
2265 ev->flags = flags & ~WRC_AF_ASCII;
2266 ev->prev = prev;
2267 if(prev)
2268 prev->next = ev;
2269 return ev;
2272 /* MenuEx specific functions */
2273 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2275 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2276 opt->id = id;
2277 opt->type = type;
2278 opt->state = state;
2279 opt->helpid = helpid;
2280 return opt;
2283 /* Raw data functions */
2284 static raw_data_t *load_file(string_t *name)
2286 FILE *fp = NULL;
2287 char *path;
2288 raw_data_t *rd;
2289 if(name->type != str_char)
2290 yyerror("Filename must be ASCII string");
2292 if (!(path = wpp_find_include(name->str.cstr, 1)))
2293 yyerror("Cannot open file %s", name->str.cstr);
2294 if (!(fp = fopen( path, "rb" )))
2295 yyerror("Cannot open file %s", name->str.cstr);
2296 free( path );
2297 rd = new_raw_data();
2298 fseek(fp, 0, SEEK_END);
2299 rd->size = ftell(fp);
2300 fseek(fp, 0, SEEK_SET);
2301 rd->data = (char *)xmalloc(rd->size);
2302 fread(rd->data, rd->size, 1, fp);
2303 fclose(fp);
2304 return rd;
2307 static raw_data_t *int2raw_data(int i)
2309 raw_data_t *rd;
2311 if((int)((short)i) != i)
2312 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2314 rd = new_raw_data();
2315 rd->size = sizeof(short);
2316 rd->data = (char *)xmalloc(rd->size);
2317 switch(byteorder)
2319 #ifdef WORDS_BIGENDIAN
2320 default:
2321 #endif
2322 case WRC_BO_BIG:
2323 rd->data[0] = HIBYTE(i);
2324 rd->data[1] = LOBYTE(i);
2325 break;
2327 #ifndef WORDS_BIGENDIAN
2328 default:
2329 #endif
2330 case WRC_BO_LITTLE:
2331 rd->data[1] = HIBYTE(i);
2332 rd->data[0] = LOBYTE(i);
2333 break;
2335 return rd;
2338 static raw_data_t *long2raw_data(int i)
2340 raw_data_t *rd;
2341 rd = new_raw_data();
2342 rd->size = sizeof(int);
2343 rd->data = (char *)xmalloc(rd->size);
2344 switch(byteorder)
2346 #ifdef WORDS_BIGENDIAN
2347 default:
2348 #endif
2349 case WRC_BO_BIG:
2350 rd->data[0] = HIBYTE(HIWORD(i));
2351 rd->data[1] = LOBYTE(HIWORD(i));
2352 rd->data[2] = HIBYTE(LOWORD(i));
2353 rd->data[3] = LOBYTE(LOWORD(i));
2354 break;
2356 #ifndef WORDS_BIGENDIAN
2357 default:
2358 #endif
2359 case WRC_BO_LITTLE:
2360 rd->data[3] = HIBYTE(HIWORD(i));
2361 rd->data[2] = LOBYTE(HIWORD(i));
2362 rd->data[1] = HIBYTE(LOWORD(i));
2363 rd->data[0] = LOBYTE(LOWORD(i));
2364 break;
2366 return rd;
2369 static raw_data_t *str2raw_data(string_t *str)
2371 raw_data_t *rd;
2372 rd = new_raw_data();
2373 rd->size = str->size * (str->type == str_char ? 1 : 2);
2374 rd->data = (char *)xmalloc(rd->size);
2375 if(str->type == str_char)
2376 memcpy(rd->data, str->str.cstr, rd->size);
2377 else if(str->type == str_unicode)
2379 int i;
2380 switch(byteorder)
2382 #ifdef WORDS_BIGENDIAN
2383 default:
2384 #endif
2385 case WRC_BO_BIG:
2386 for(i = 0; i < str->size; i++)
2388 rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
2389 rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
2391 break;
2392 #ifndef WORDS_BIGENDIAN
2393 default:
2394 #endif
2395 case WRC_BO_LITTLE:
2396 for(i = 0; i < str->size; i++)
2398 rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
2399 rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
2401 break;
2404 else
2405 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2406 return rd;
2409 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2411 r1->data = xrealloc(r1->data, r1->size + r2->size);
2412 memcpy(r1->data + r1->size, r2->data, r2->size);
2413 r1->size += r2->size;
2414 return r1;
2417 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2419 raw_data_t *t = int2raw_data(i);
2420 merge_raw_data(r1, t);
2421 free(t->data);
2422 free(t);
2423 return r1;
2426 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2428 raw_data_t *t = long2raw_data(i);
2429 merge_raw_data(r1, t);
2430 free(t->data);
2431 free(t);
2432 return r1;
2435 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2437 raw_data_t *t = str2raw_data(str);
2438 merge_raw_data(r1, t);
2439 free(t->data);
2440 free(t);
2441 return r1;
2444 /* Function the go back in a list to get the head */
2445 static menu_item_t *get_item_head(menu_item_t *p)
2447 if(!p)
2448 return NULL;
2449 while(p->prev)
2450 p = p->prev;
2451 return p;
2454 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2456 if(!p)
2457 return NULL;
2458 while(p->prev)
2459 p = p->prev;
2460 return p;
2463 static resource_t *get_resource_head(resource_t *p)
2465 if(!p)
2466 return NULL;
2467 while(p->prev)
2468 p = p->prev;
2469 return p;
2472 static ver_block_t *get_ver_block_head(ver_block_t *p)
2474 if(!p)
2475 return NULL;
2476 while(p->prev)
2477 p = p->prev;
2478 return p;
2481 static ver_value_t *get_ver_value_head(ver_value_t *p)
2483 if(!p)
2484 return NULL;
2485 while(p->prev)
2486 p = p->prev;
2487 return p;
2490 static control_t *get_control_head(control_t *p)
2492 if(!p)
2493 return NULL;
2494 while(p->prev)
2495 p = p->prev;
2496 return p;
2499 static event_t *get_event_head(event_t *p)
2501 if(!p)
2502 return NULL;
2503 while(p->prev)
2504 p = p->prev;
2505 return p;
2508 /* Find a stringtable with given language */
2509 static stringtable_t *find_stringtable(lvc_t *lvc)
2511 stringtable_t *stt;
2513 assert(lvc != NULL);
2515 if(!lvc->language)
2516 lvc->language = dup_language(currentlanguage);
2518 for(stt = sttres; stt; stt = stt->next)
2520 if(stt->lvc.language->id == lvc->language->id
2521 && stt->lvc.language->sub == lvc->language->sub)
2523 /* Found a table with the same language */
2524 /* The version and characteristics are now handled
2525 * in the generation of the individual stringtables.
2526 * This enables localized analysis.
2527 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2528 || (!stt->lvc.version && lvc->version)
2529 || (stt->lvc.version && !lvc->version))
2530 yywarning("Stringtable's versions are not the same, using first definition");
2532 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2533 || (!stt->lvc.characts && lvc->characts)
2534 || (stt->lvc.characts && !lvc->characts))
2535 yywarning("Stringtable's characteristics are not the same, using first definition");
2537 return stt;
2540 return NULL;
2543 /* qsort sorting function for string table entries */
2544 #define STE(p) ((stt_entry_t *)(p))
2545 static int sort_stt_entry(const void *e1, const void *e2)
2547 return STE(e1)->id - STE(e2)->id;
2549 #undef STE
2551 static resource_t *build_stt_resources(stringtable_t *stthead)
2553 stringtable_t *stt;
2554 stringtable_t *newstt;
2555 resource_t *rsc;
2556 resource_t *rsclist = NULL;
2557 resource_t *rsctail = NULL;
2558 int i;
2559 int j;
2560 DWORD andsum;
2561 DWORD orsum;
2562 characts_t *characts;
2563 version_t *version;
2565 if(!stthead)
2566 return NULL;
2568 /* For all languages defined */
2569 for(stt = stthead; stt; stt = stt->next)
2571 assert(stt->nentries > 0);
2573 /* Sort the entries */
2574 if(stt->nentries > 1)
2575 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2577 for(i = 0; i < stt->nentries; )
2579 newstt = new_stringtable(&stt->lvc);
2580 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2581 newstt->nentries = 16;
2582 newstt->idbase = stt->entries[i].id & ~0xf;
2583 for(j = 0; j < 16 && i < stt->nentries; j++)
2585 if(stt->entries[i].id - newstt->idbase == j)
2587 newstt->entries[j] = stt->entries[i];
2588 i++;
2591 andsum = ~0;
2592 orsum = 0;
2593 characts = NULL;
2594 version = NULL;
2595 /* Check individual memory options and get
2596 * the first characteristics/version
2598 for(j = 0; j < 16; j++)
2600 if(!newstt->entries[j].str)
2601 continue;
2602 andsum &= newstt->entries[j].memopt;
2603 orsum |= newstt->entries[j].memopt;
2604 if(!characts)
2605 characts = newstt->entries[j].characts;
2606 if(!version)
2607 version = newstt->entries[j].version;
2609 if(andsum != orsum)
2611 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2613 /* Check version and characteristics */
2614 for(j = 0; j < 16; j++)
2616 if(characts
2617 && newstt->entries[j].characts
2618 && *newstt->entries[j].characts != *characts)
2619 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2620 if(version
2621 && newstt->entries[j].version
2622 && *newstt->entries[j].version != *version)
2623 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2625 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2626 rsc->name = new_name_id();
2627 rsc->name->type = name_ord;
2628 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2629 rsc->memopt = andsum; /* Set to least common denominator */
2630 newstt->memopt = andsum;
2631 newstt->lvc.characts = characts;
2632 newstt->lvc.version = version;
2633 if(!rsclist)
2635 rsclist = rsc;
2636 rsctail = rsc;
2638 else
2640 rsctail->next = rsc;
2641 rsc->prev = rsctail;
2642 rsctail = rsc;
2646 return rsclist;
2650 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2652 idrec->prev = prev;
2653 if(prev)
2654 prev->next = idrec;
2656 return idrec;
2659 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2661 if(!p)
2663 *nitems = 0;
2664 return NULL;
2667 *nitems = 1;
2669 while(p->prev)
2671 (*nitems)++;
2672 p = p->prev;
2675 return p;
2678 static string_t *make_filename(string_t *str)
2680 char *cptr;
2682 if(str->type != str_char)
2683 yyerror("Cannot handle UNICODE filenames");
2685 /* Remove escaped backslash and convert to forward */
2686 cptr = str->str.cstr;
2687 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2689 if(cptr[1] == '\\')
2691 memmove(cptr, cptr+1, strlen(cptr));
2692 str->size--;
2694 *cptr = '/';
2697 return str;
2701 * Process all resources to extract fonts and build
2702 * a fontdir resource.
2704 * Note: MS' resource compiler (build 1472) does not
2705 * handle font resources with different languages.
2706 * The fontdir is generated in the last active language
2707 * and font identifiers must be unique across the entire
2708 * source.
2709 * This is not logical considering the localization
2710 * constraints of all other resource types. MS has,
2711 * most probably, never testet localized fonts. However,
2712 * using fontresources is rare, so it might not occur
2713 * in normal applications.
2714 * Wine does require better localization because a lot
2715 * of languages are coded into the same executable.
2716 * Therefore, I will generate fontdirs for *each*
2717 * localized set of fonts.
2719 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2721 static int once = 0;
2722 if(!once)
2724 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
2725 once++;
2727 return NULL;
2730 static resource_t *build_fontdirs(resource_t *tail)
2732 resource_t *rsc;
2733 resource_t *lst = NULL;
2734 resource_t **fnt = NULL; /* List of all fonts */
2735 int nfnt = 0;
2736 resource_t **fnd = NULL; /* List of all fontdirs */
2737 int nfnd = 0;
2738 resource_t **lanfnt = NULL;
2739 int nlanfnt = 0;
2740 int i;
2741 name_id_t nid;
2742 string_t str;
2743 int fntleft;
2745 nid.type = name_str;
2746 nid.name.s_name = &str;
2747 str.type = str_char;
2748 str.str.cstr = "FONTDIR";
2749 str.size = 7;
2751 /* Extract all fonts and fontdirs */
2752 for(rsc = tail; rsc; rsc = rsc->prev)
2754 if(rsc->type == res_fnt)
2756 nfnt++;
2757 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2758 fnt[nfnt-1] = rsc;
2760 else if(rsc->type == res_fntdir)
2762 nfnd++;
2763 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2764 fnd[nfnd-1] = rsc;
2768 /* Verify the name of the present fontdirs */
2769 for(i = 0; i < nfnd; i++)
2771 if(compare_name_id(&nid, fnd[i]->name))
2773 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2774 get_nameid_str(fnd[i]->name));
2775 fnd[i] = NULL;
2779 /* Sanity check */
2780 if(nfnt == 0)
2782 if(nfnd != 0)
2783 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2784 goto clean;
2787 /* Copy space */
2788 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2790 /* Get all fonts covered by fontdirs */
2791 for(i = 0; i < nfnd; i++)
2793 int j;
2794 WORD cnt;
2795 int isswapped = 0;
2797 if(!fnd[i])
2798 continue;
2799 for(j = 0; j < nfnt; j++)
2801 if(!fnt[j])
2802 continue;
2803 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2805 lanfnt[nlanfnt] = fnt[j];
2806 nlanfnt++;
2807 fnt[j] = NULL;
2811 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2812 if(nlanfnt == cnt)
2813 isswapped = 0;
2814 else if(nlanfnt == BYTESWAP_WORD(cnt))
2815 isswapped = 1;
2816 else
2817 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2818 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2819 #ifdef WORDS_BIGENDIAN
2820 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2821 #else
2822 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2823 #endif
2825 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2829 /* We now have fonts left where we need to make a fontdir resource */
2830 for(i = fntleft = 0; i < nfnt; i++)
2832 if(fnt[i])
2833 fntleft++;
2835 while(fntleft)
2837 /* Get fonts of same language in lanfnt[] */
2838 for(i = nlanfnt = 0; i < nfnt; i++)
2840 if(fnt[i])
2842 if(!nlanfnt)
2844 addlanfnt:
2845 lanfnt[nlanfnt] = fnt[i];
2846 nlanfnt++;
2847 fnt[i] = NULL;
2848 fntleft--;
2850 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2851 goto addlanfnt;
2854 /* and build a fontdir */
2855 rsc = build_fontdir(lanfnt, nlanfnt);
2856 if(rsc)
2858 if(lst)
2860 lst->next = rsc;
2861 rsc->prev = lst;
2863 lst = rsc;
2867 free(lanfnt);
2868 clean:
2869 if(fnt)
2870 free(fnt);
2871 if(fnd)
2872 free(fnd);
2873 return lst;
2877 * This gets invoked to determine whether the next resource
2878 * is to be of a standard-type (e.g. bitmaps etc.), or should
2879 * be a user-type resource. This function is required because
2880 * there is the _possibility_ of a lookahead token in the
2881 * parser, which is generated from the "expr" state in the
2882 * "nameid" parsing.
2884 * The general resource format is:
2885 * <identifier> <type> <flags> <resourcebody>
2887 * The <identifier> can either be tIDENT or "expr". The latter
2888 * will always generate a lookahead, which is the <type> of the
2889 * resource to parse. Otherwise, we need to get a new token from
2890 * the scanner to determine the next step.
2892 * The problem arrises when <type> is numerical. This case should
2893 * map onto default resource-types and be parsed as such instead
2894 * of being mapped onto user-type resources.
2896 * The trick lies in the fact that yacc (bison) doesn't care about
2897 * intermediate changes of the lookahead while reducing a rule. We
2898 * simply replace the lookahead with a token that will result in
2899 * a shift to the appropriate rule for the specific resource-type.
2901 static int rsrcid_to_token(int lookahead)
2903 int token;
2904 char *type = "?";
2906 /* Get a token if we don't have one yet */
2907 if(lookahead == YYEMPTY)
2908 lookahead = YYLEX;
2910 /* Only numbers are possibly interesting */
2911 switch(lookahead)
2913 case tNUMBER:
2914 case tLNUMBER:
2915 break;
2916 default:
2917 return lookahead;
2920 token = lookahead;
2922 switch(yylval.num)
2924 case WRC_RT_CURSOR:
2925 type = "CURSOR";
2926 token = tCURSOR;
2927 break;
2928 case WRC_RT_ICON:
2929 type = "ICON";
2930 token = tICON;
2931 break;
2932 case WRC_RT_BITMAP:
2933 type = "BITMAP";
2934 token = tBITMAP;
2935 break;
2936 case WRC_RT_FONT:
2937 type = "FONT";
2938 token = tFONT;
2939 break;
2940 case WRC_RT_FONTDIR:
2941 type = "FONTDIR";
2942 token = tFONTDIR;
2943 break;
2944 case WRC_RT_RCDATA:
2945 type = "RCDATA";
2946 token = tRCDATA;
2947 break;
2948 case WRC_RT_MESSAGETABLE:
2949 type = "MESSAGETABLE";
2950 token = tMESSAGETABLE;
2951 break;
2952 case WRC_RT_DLGINIT:
2953 type = "DLGINIT";
2954 token = tDLGINIT;
2955 break;
2956 case WRC_RT_ACCELERATOR:
2957 type = "ACCELERATOR";
2958 token = tACCELERATORS;
2959 break;
2960 case WRC_RT_MENU:
2961 type = "MENU";
2962 token = tMENU;
2963 break;
2964 case WRC_RT_DIALOG:
2965 type = "DIALOG";
2966 token = tDIALOG;
2967 break;
2968 case WRC_RT_VERSION:
2969 type = "VERSION";
2970 token = tVERSIONINFO;
2971 break;
2972 case WRC_RT_TOOLBAR:
2973 type = "TOOLBAR";
2974 token = tTOOLBAR;
2975 break;
2977 case WRC_RT_STRING:
2978 type = "STRINGTABLE";
2979 break;
2981 case WRC_RT_ANICURSOR:
2982 case WRC_RT_ANIICON:
2983 case WRC_RT_GROUP_CURSOR:
2984 case WRC_RT_GROUP_ICON:
2985 yywarning("Usertype uses reserved type ID %d, which is auto-generated", yylval.num);
2986 return lookahead;
2988 case WRC_RT_DLGINCLUDE:
2989 case WRC_RT_PLUGPLAY:
2990 case WRC_RT_VXD:
2991 case WRC_RT_HTML:
2992 yywarning("Usertype uses reserved type ID %d, which is not supported by wrc yet", yylval.num);
2993 default:
2994 return lookahead;
2997 if(remap)
2998 return token;
2999 else
3000 yywarning("Usertype uses reserved type ID %d, which is used by %s", yylval.num, type);
3001 return lookahead;