Alexandre Julliard <julliard@winehq.org>
[reactos.git] / reactos / tools / wrc / parser.y
1 %{
2 /*
3 * Copyright 1994 Martin von Loewis
4 * Copyright 1998-2000 Bertho A. Stultiens (BS)
5 * 1999 Juergen Schmied (JS)
6 *
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.
11 *
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.
16 *
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
20 *
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).
38 *
39 * 06-Nov-1999 JS - see CHANGES
40 *
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
48 *
49 * 20-Jun-1998 BS - Fixed a bug in load_file() where the name was not
50 * printed out correctly.
51 *
52 * 17-Jun-1998 BS - Fixed a bug in CLASS statement parsing which should
53 * also accept a tSTRING as argument.
54 *
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).
62 *
63 * 19-May-1998 BS - Started to build a builtin preprocessor
64 *
65 * 30-Apr-1998 BS - Redid the stringtable parsing/handling. My previous
66 * ideas had some serious flaws.
67 *
68 * 27-Apr-1998 BS - Removed a lot of dead comments and put it in a doc
69 * file.
70 *
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.
74 *
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).
80 *
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.
86 *
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.
95 *
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.
104 *
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.
116 *
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
122 */
123 #include "config.h"
124 #include "wine/port.h"
125
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
135
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"
147
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
157
158 #elif defined(YYBISON)
159 /* Bison was used for original development */
160 /* #define YYEMPTY -2 */
161 /* #define YYLEX yylex() */
162
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
172
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.
179 */
180 stringtable_t *sttres; /* Stringtable resources. This holds the list of
181 * stringtables with different lanuages
182 */
183 static int dont_want_id = 0; /* See language parsing for details */
184
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;
189
190 static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
191
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);
239
240 %}
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;
283 }
284
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 tSTRING tIDENT tRAWDATA
304 %token tTOOLBAR tBUTTON
305 %token tBEGIN tEND
306 %token tDLGINIT
307 %left '|'
308 %left '^'
309 %left '&'
310 %left '+' '-'
311 %left '*' '/'
312 %right '~' tNOT
313 %left pUPM
314
315 %type <res> resource_file resource resources resource_definition
316 %type <stt> stringtable strings
317 %type <fnt> font
318 %type <fnd> fontdir
319 %type <acc> accelerators
320 %type <event> events
321 %type <bmp> bitmap
322 %type <ani> cursor icon
323 %type <dlg> dialog dlg_attributes
324 %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
325 %type <iptr> helpid
326 %type <dlgex> dialogex dlgex_attribs
327 %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
328 %type <html> html
329 %type <rdt> rcdata
330 %type <raw> raw_data raw_elements opt_data file_raw
331 %type <veri> versioninfo fix_version
332 %type <verw> ver_words
333 %type <blk> ver_blocks ver_block
334 %type <val> ver_values ver_value
335 %type <men> menu
336 %type <menitm> item_definitions menu_body
337 %type <menex> menuex
338 %type <menexitm> itemex_definitions menuex_body
339 %type <exopt> itemex_p_options itemex_options
340 %type <msg> messagetable
341 %type <usr> userres
342 %type <num> item_options
343 %type <nid> nameid nameid_s ctlclass usertype
344 %type <num> acc_opt acc accs
345 %type <iptr> loadmemopts lamo lama
346 %type <fntid> opt_font opt_exfont opt_expr
347 %type <lvc> opt_lvc
348 %type <lan> opt_language
349 %type <chars> opt_characts
350 %type <ver> opt_version
351 %type <num> expr xpr xpr_no_not
352 %type <iptr> e_expr
353 %type <tlbar> toolbar
354 %type <tlbarItems> toolbar_items
355 %type <dginit> dlginit
356 %type <styles> optional_style_pair
357 %type <num> any_num
358 %type <style> style
359 %type <str> filename
360
361 %%
362
363 resource_file
364 : resources {
365 resource_t *rsc;
366 /* First add stringtables to the resource-list */
367 rsc = build_stt_resources(sttres);
368 /* 'build_stt_resources' returns a head and $1 is a tail */
369 if($1)
370 {
371 $1->next = rsc;
372 if(rsc)
373 rsc->prev = $1;
374 }
375 else
376 $1 = rsc;
377 /* Find the tail again */
378 while($1 && $1->next)
379 $1 = $1->next;
380 /* Now add any fontdirecory */
381 rsc = build_fontdirs($1);
382 /* 'build_fontdir' returns a head and $1 is a tail */
383 if($1)
384 {
385 $1->next = rsc;
386 if(rsc)
387 rsc->prev = $1;
388 }
389 else
390 $1 = rsc;
391 /* Final statement before were done */
392 resource_top = get_resource_head($1);
393 }
394 ;
395
396 /* Resources are put into a linked list */
397 resources
398 : /* Empty */ { $$ = NULL; want_id = 1; }
399 | resources resource {
400 if($2)
401 {
402 resource_t *tail = $2;
403 resource_t *head = $2;
404 while(tail->next)
405 tail = tail->next;
406 while(head->prev)
407 head = head->prev;
408 head->prev = $1;
409 if($1)
410 $1->next = head;
411 $$ = tail;
412 /* Check for duplicate identifiers */
413 while($1 && head)
414 {
415 resource_t *rsc = $1;
416 while(rsc)
417 {
418 if(rsc->type == head->type
419 && rsc->lan->id == head->lan->id
420 && rsc->lan->sub == head->lan->sub
421 && !compare_name_id(rsc->name, head->name))
422 {
423 yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
424 }
425 rsc = rsc->prev;
426 }
427 head = head->next;
428 }
429 }
430 else if($1)
431 {
432 resource_t *tail = $1;
433 while(tail->next)
434 tail = tail->next;
435 $$ = tail;
436 }
437 else
438 $$ = NULL;
439
440 if(!dont_want_id) /* See comments in language parsing below */
441 want_id = 1;
442 dont_want_id = 0;
443 }
444 /*
445 * The following newline rule will never get reduced because we never
446 * get the tNL token, unless we explicitely set the 'want_nl'
447 * flag, which we don't.
448 * The *ONLY* reason for this to be here is because Berkeley
449 * yacc (byacc), at least version 1.9, has a bug.
450 * (identified in the generated parser on the second
451 * line with:
452 * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
453 * )
454 * This extra rule fixes it.
455 * The problem is that the expression handling rule "expr: xpr"
456 * is not reduced on non-terminal tokens, defined above in the
457 * %token declarations. Token tNL is the only non-terminal that
458 * can occur. The error becomes visible in the language parsing
459 * rule below, which looks at the look-ahead token and tests it
460 * for tNL. However, byacc already generates an error upon reading
461 * the token instead of keeping it as a lookahead. The reason
462 * lies in the lack of a $default transition in the "expr : xpr . "
463 * state (currently state 25). It is probably omitted because tNL
464 * is a non-terminal and the state contains 2 s/r conflicts. The
465 * state enumerates all possible transitions instead of using a
466 * $default transition.
467 * All in all, it is a bug in byacc. (period)
468 */
469 | resources tNL
470 ;
471
472
473 /* Parse top level resource definitions etc. */
474 resource
475 : expr usrcvt resource_definition {
476 $$ = $3;
477 if($$)
478 {
479 if($1 > 65535 || $1 < -32768)
480 yyerror("Resource's ID out of range (%d)", $1);
481 $$->name = new_name_id();
482 $$->name->type = name_ord;
483 $$->name->name.i_name = $1;
484 chat("Got %s (%d)", get_typename($3), $$->name->name.i_name);
485 }
486 }
487 | tIDENT usrcvt resource_definition {
488 $$ = $3;
489 if($$)
490 {
491 $$->name = new_name_id();
492 $$->name->type = name_str;
493 $$->name->name.s_name = $1;
494 chat("Got %s (%s)", get_typename($3), $$->name->name.s_name->str.cstr);
495 }
496 }
497 | stringtable {
498 /* Don't do anything, stringtables are converted to
499 * resource_t structures when we are finished parsing and
500 * the final rule of the parser is reduced (see above)
501 */
502 $$ = NULL;
503 chat("Got STRINGTABLE");
504 }
505 | tLANGUAGE {want_nl = 1; } expr ',' expr {
506 /* We *NEED* the newline to delimit the expression.
507 * Otherwise, we would not be able to set the next
508 * want_id anymore because of the token-lookahead.
509 *
510 * However, we can test the lookahead-token for
511 * being "non-expression" type, in which case we
512 * continue. Fortunately, tNL is the only token that
513 * will break expression parsing and is implicitely
514 * void, so we just remove it. This scheme makes it
515 * possible to do some (not all) fancy preprocessor
516 * stuff.
517 * BTW, we also need to make sure that the next
518 * reduction of 'resources' above will *not* set
519 * want_id because we already have a lookahead that
520 * cannot be undone.
521 */
522 if(yychar != YYEMPTY && yychar != tNL)
523 dont_want_id = 1;
524
525 if(yychar == tNL)
526 yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
527 /* direct access to yychar in rule 'usrcvt' below. */
528 else if(yychar == tIDENT)
529 yywarning("LANGUAGE statement not delimited with newline; next identifier might be wrong");
530
531 want_nl = 0; /* We don't want it anymore if we didn't get it */
532
533 if(!win32)
534 yywarning("LANGUAGE not supported in 16-bit mode");
535 if(currentlanguage)
536 free(currentlanguage);
537 if (get_language_codepage($3, $5) == -1)
538 yyerror( "Language %04x is not supported", ($5<<10) + $3);
539 currentlanguage = new_language($3, $5);
540 $$ = NULL;
541 chat("Got LANGUAGE %d,%d (0x%04x)", $3, $5, ($5<<10) + $3);
542 }
543 ;
544
545 /*
546 * Remapping of numerical resource types
547 * (see also comment of called function below)
548 */
549 usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
550 ;
551
552 /*
553 * Get a valid name/id
554 */
555 nameid : expr {
556 if($1 > 65535 || $1 < -32768)
557 yyerror("Resource's ID out of range (%d)", $1);
558 $$ = new_name_id();
559 $$->type = name_ord;
560 $$->name.i_name = $1;
561 }
562 | tIDENT {
563 $$ = new_name_id();
564 $$->type = name_str;
565 $$->name.s_name = $1;
566 }
567 ;
568
569 /*
570 * Extra string recognition for CLASS statement in dialogs
571 */
572 nameid_s: nameid { $$ = $1; }
573 | tSTRING {
574 $$ = new_name_id();
575 $$->type = name_str;
576 $$->name.s_name = $1;
577 }
578 ;
579
580 /* get the value for a single resource*/
581 resource_definition
582 : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
583 | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
584 | cursor {
585 resource_t *rsc;
586 if($1->type == res_anicur)
587 {
588 $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
589 }
590 else if($1->type == res_curg)
591 {
592 cursor_t *cur;
593 $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
594 for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
595 {
596 rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
597 rsc->prev->next = rsc;
598 rsc = rsc->prev;
599 rsc->name = new_name_id();
600 rsc->name->type = name_ord;
601 rsc->name->name.i_name = cur->id;
602 }
603 }
604 else
605 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource", $1->type);
606 free($1);
607 }
608 | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
609 | dialogex {
610 if(win32)
611 $$ = new_resource(res_dlgex, $1, $1->memopt, $1->lvc.language);
612 else
613 $$ = NULL;
614 }
615 | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
616 | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
617 | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
618 | icon {
619 resource_t *rsc;
620 if($1->type == res_aniico)
621 {
622 $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
623 }
624 else if($1->type == res_icog)
625 {
626 icon_t *ico;
627 $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
628 for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
629 {
630 rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->lvc.language);
631 rsc->prev->next = rsc;
632 rsc = rsc->prev;
633 rsc->name = new_name_id();
634 rsc->name->type = name_ord;
635 rsc->name->name.i_name = ico->id;
636 }
637 }
638 else
639 internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource", $1->type);
640 free($1);
641 }
642 | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
643 | menuex {
644 if(win32)
645 $$ = new_resource(res_menex, $1, $1->memopt, $1->lvc.language);
646 else
647 $$ = NULL;
648 }
649 | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
650 | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
651 | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
652 | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
653 | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
654 | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
655 ;
656
657
658 filename: tFILENAME { $$ = make_filename($1); }
659 | tIDENT { $$ = make_filename($1); }
660 | tSTRING { $$ = make_filename($1); }
661 ;
662
663 /* ------------------------------ Bitmap ------------------------------ */
664 bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
665 ;
666
667 /* ------------------------------ Cursor ------------------------------ */
668 cursor : tCURSOR loadmemopts file_raw {
669 $$ = new_ani_any();
670 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
671 {
672 $$->type = res_anicur;
673 $$->u.ani = new_ani_curico(res_anicur, $3, $2);
674 }
675 else
676 {
677 $$->type = res_curg;
678 $$->u.curg = new_cursor_group($3, $2);
679 }
680 }
681 ;
682
683 /* ------------------------------ Icon ------------------------------ */
684 icon : tICON loadmemopts file_raw {
685 $$ = new_ani_any();
686 if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
687 {
688 $$->type = res_aniico;
689 $$->u.ani = new_ani_curico(res_aniico, $3, $2);
690 }
691 else
692 {
693 $$->type = res_icog;
694 $$->u.icog = new_icon_group($3, $2);
695 }
696 }
697 ;
698
699 /* ------------------------------ Font ------------------------------ */
700 /*
701 * The reading of raw_data for fonts is a Borland BRC
702 * extension. MS generates an error. However, it is
703 * most logical to support this, considering how wine
704 * enters things in CVS (ascii).
705 */
706 font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
707 ;
708
709 /*
710 * The fontdir is a Borland BRC extension which only
711 * reads the data as 'raw_data' from the file.
712 * I don't know whether it is interpreted.
713 * The fontdir is generated if it was not present and
714 * fonts are defined in the source.
715 */
716 fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
717 ;
718
719 /* ------------------------------ MessageTable ------------------------------ */
720 /* It might be interesting to implement the MS Message compiler here as well
721 * to get everything in one source. Might be a future project.
722 */
723 messagetable
724 : tMESSAGETABLE loadmemopts file_raw {
725 if(!win32)
726 yywarning("MESSAGETABLE not supported in 16-bit mode");
727 $$ = new_messagetable($3, $2);
728 }
729 ;
730
731 /* ------------------------------ HTML ------------------------------ */
732 html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
733 ;
734
735 /* ------------------------------ RCData ------------------------------ */
736 rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
737 ;
738
739 /* ------------------------------ DLGINIT ------------------------------ */
740 dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
741 ;
742
743 /* ------------------------------ UserType ------------------------------ */
744 userres : usertype loadmemopts file_raw {
745 #ifdef WORDS_BIGENDIAN
746 if(pedantic && byteorder != WRC_BO_LITTLE)
747 #else
748 if(pedantic && byteorder == WRC_BO_BIG)
749 #endif
750 yywarning("Byteordering is not little-endian and type cannot be interpreted");
751 $$ = new_user($1, $3, $2);
752 }
753 ;
754
755 usertype: tNUMBER {
756 $$ = new_name_id();
757 $$->type = name_ord;
758 $$->name.i_name = $1;
759 }
760 | tIDENT {
761 $$ = new_name_id();
762 $$->type = name_str;
763 $$->name.s_name = $1;
764 }
765 ;
766
767 /* ------------------------------ Accelerator ------------------------------ */
768 accelerators
769 : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
770 $$ = new_accelerator();
771 if($2)
772 {
773 $$->memopt = *($2);
774 free($2);
775 }
776 else
777 {
778 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
779 }
780 if(!$5)
781 yyerror("Accelerator table must have at least one entry");
782 $$->events = get_event_head($5);
783 if($3)
784 {
785 $$->lvc = *($3);
786 free($3);
787 }
788 if(!$$->lvc.language)
789 $$->lvc.language = dup_language(currentlanguage);
790 }
791 ;
792
793 events : /* Empty */ { $$=NULL; }
794 | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
795 | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
796 ;
797
798 /*
799 * The empty rule generates a s/r conflict because of {bi,u}nary expr
800 * on - and +. It cannot be solved in any way because it is the same as
801 * the if/then/else problem (LALR(1) problem). The conflict is moved
802 * away by forcing it to be in the expression handling below.
803 */
804 acc_opt : /* Empty */ { $$ = 0; }
805 | ',' accs { $$ = $2; }
806 ;
807
808 accs : acc { $$ = $1; }
809 | accs ',' acc { $$ = $1 | $3; }
810 ;
811
812 acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
813 | tSHIFT { $$ = WRC_AF_SHIFT; }
814 | tCONTROL { $$ = WRC_AF_CONTROL; }
815 | tALT { $$ = WRC_AF_ALT; }
816 | tASCII { $$ = WRC_AF_ASCII; }
817 | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
818 ;
819
820 /* ------------------------------ Dialog ------------------------------ */
821 /* FIXME: Support EXSTYLE in the dialog line itself */
822 dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
823 tBEGIN ctrls tEND {
824 if($2)
825 {
826 $10->memopt = *($2);
827 free($2);
828 }
829 else
830 $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
831 $10->x = $3;
832 $10->y = $5;
833 $10->width = $7;
834 $10->height = $9;
835 $10->controls = get_control_head($12);
836 $$ = $10;
837 if(!$$->gotstyle)
838 {
839 $$->style = new_style(0,0);
840 $$->style->or_mask = WS_POPUP;
841 $$->gotstyle = TRUE;
842 }
843 if($$->title)
844 $$->style->or_mask |= WS_CAPTION;
845 if($$->font)
846 $$->style->or_mask |= DS_SETFONT;
847
848 $$->style->or_mask &= ~($$->style->and_mask);
849 $$->style->and_mask = 0;
850
851 if(!$$->lvc.language)
852 $$->lvc.language = dup_language(currentlanguage);
853 }
854 ;
855
856 dlg_attributes
857 : /* Empty */ { $$=new_dialog(); }
858 | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
859 | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
860 | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
861 | dlg_attributes opt_font { $$=dialog_font($2,$1); }
862 | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
863 | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
864 | dlg_attributes opt_language { $$=dialog_language($2,$1); }
865 | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
866 | dlg_attributes opt_version { $$=dialog_version($2,$1); }
867 ;
868
869 ctrls : /* Empty */ { $$ = NULL; }
870 | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
871 | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
872 | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
873 | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
874 | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
875 | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
876 | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
877 | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
878 | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
879 /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
880 | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
881 | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
882 | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
883 | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
884 | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
885 | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
886 | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
887 | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
888 /* special treatment for icons, as the extent is optional */
889 | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
890 $10->title = $3;
891 $10->id = $5;
892 $10->x = $7;
893 $10->y = $9;
894 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
895 }
896 ;
897
898 lab_ctrl
899 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
900 $$=new_control();
901 $$->title = new_name_id();
902 $$->title->type = name_str;
903 $$->title->name.s_name = $1;
904 $$->id = $3;
905 $$->x = $5;
906 $$->y = $7;
907 $$->width = $9;
908 $$->height = $11;
909 if($12)
910 {
911 $$->style = $12->style;
912 $$->gotstyle = TRUE;
913 if ($12->exstyle)
914 {
915 $$->exstyle = $12->exstyle;
916 $$->gotexstyle = TRUE;
917 }
918 free($12);
919 }
920 }
921 ;
922
923 ctrl_desc
924 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
925 $$ = new_control();
926 $$->id = $1;
927 $$->x = $3;
928 $$->y = $5;
929 $$->width = $7;
930 $$->height = $9;
931 if($10)
932 {
933 $$->style = $10->style;
934 $$->gotstyle = TRUE;
935 if ($10->exstyle)
936 {
937 $$->exstyle = $10->exstyle;
938 $$->gotexstyle = TRUE;
939 }
940 free($10);
941 }
942 }
943 ;
944
945 iconinfo: /* Empty */
946 { $$ = new_control(); }
947
948 | ',' expr ',' expr {
949 $$ = new_control();
950 $$->width = $2;
951 $$->height = $4;
952 }
953 | ',' expr ',' expr ',' style {
954 $$ = new_control();
955 $$->width = $2;
956 $$->height = $4;
957 $$->style = $6;
958 $$->gotstyle = TRUE;
959 }
960 | ',' expr ',' expr ',' style ',' style {
961 $$ = new_control();
962 $$->width = $2;
963 $$->height = $4;
964 $$->style = $6;
965 $$->gotstyle = TRUE;
966 $$->exstyle = $8;
967 $$->gotexstyle = TRUE;
968 }
969 ;
970
971 gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
972 $$=new_control();
973 $$->title = $1;
974 $$->id = $3;
975 $$->ctlclass = convert_ctlclass($5);
976 $$->style = $7;
977 $$->gotstyle = TRUE;
978 $$->x = $9;
979 $$->y = $11;
980 $$->width = $13;
981 $$->height = $15;
982 $$->exstyle = $17;
983 $$->gotexstyle = TRUE;
984 }
985 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
986 $$=new_control();
987 $$->title = $1;
988 $$->id = $3;
989 $$->ctlclass = convert_ctlclass($5);
990 $$->style = $7;
991 $$->gotstyle = TRUE;
992 $$->x = $9;
993 $$->y = $11;
994 $$->width = $13;
995 $$->height = $15;
996 }
997 ;
998
999 opt_font
1000 : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
1001 ;
1002
1003 /* ------------------------------ style flags ------------------------------ */
1004 optional_style_pair
1005 : /* Empty */ { $$ = NULL; }
1006 | ',' style { $$ = new_style_pair($2, 0); }
1007 | ',' style ',' style { $$ = new_style_pair($2, $4); }
1008 ;
1009
1010 style
1011 : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
1012 | '(' style ')' { $$ = $2; }
1013 | xpr_no_not { $$ = new_style($1, 0); }
1014 | tNOT xpr_no_not { $$ = new_style(0, $2); }
1015 ;
1016
1017 ctlclass
1018 : expr {
1019 $$ = new_name_id();
1020 $$->type = name_ord;
1021 $$->name.i_name = $1;
1022 }
1023 | tSTRING {
1024 $$ = new_name_id();
1025 $$->type = name_str;
1026 $$->name.s_name = $1;
1027 }
1028 ;
1029
1030 /* ------------------------------ DialogEx ------------------------------ */
1031 dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
1032 tBEGIN exctrls tEND {
1033 if(!win32)
1034 yywarning("DIALOGEX not supported in 16-bit mode");
1035 if($2)
1036 {
1037 $11->memopt = *($2);
1038 free($2);
1039 }
1040 else
1041 $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1042 $11->x = $3;
1043 $11->y = $5;
1044 $11->width = $7;
1045 $11->height = $9;
1046 if($10)
1047 {
1048 $11->helpid = *($10);
1049 $11->gothelpid = TRUE;
1050 free($10);
1051 }
1052 $11->controls = get_control_head($13);
1053 $$ = $11;
1054
1055 assert($$->style != NULL);
1056 if(!$$->gotstyle)
1057 {
1058 $$->style->or_mask = WS_POPUP;
1059 $$->gotstyle = TRUE;
1060 }
1061 if($$->title)
1062 $$->style->or_mask |= WS_CAPTION;
1063 if($$->font)
1064 $$->style->or_mask |= DS_SETFONT;
1065
1066 $$->style->or_mask &= ~($$->style->and_mask);
1067 $$->style->and_mask = 0;
1068
1069 if(!$$->lvc.language)
1070 $$->lvc.language = dup_language(currentlanguage);
1071 }
1072 ;
1073
1074 dlgex_attribs
1075 : /* Empty */ { $$=new_dialogex(); }
1076 | dlgex_attribs tSTYLE style { $$=dialogex_style($3,$1); }
1077 | dlgex_attribs tEXSTYLE style { $$=dialogex_exstyle($3,$1); }
1078 | dlgex_attribs tCAPTION tSTRING { $$=dialogex_caption($3,$1); }
1079 | dlgex_attribs opt_font { $$=dialogex_font($2,$1); }
1080 | dlgex_attribs opt_exfont { $$=dialogex_font($2,$1); }
1081 | dlgex_attribs tCLASS nameid_s { $$=dialogex_class($3,$1); }
1082 | dlgex_attribs tMENU nameid { $$=dialogex_menu($3,$1); }
1083 | dlgex_attribs opt_language { $$=dialogex_language($2,$1); }
1084 | dlgex_attribs opt_characts { $$=dialogex_characteristics($2,$1); }
1085 | dlgex_attribs opt_version { $$=dialogex_version($2,$1); }
1086 ;
1087
1088 exctrls : /* Empty */ { $$ = NULL; }
1089 | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
1090 | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
1091 | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
1092 | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
1093 | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
1094 | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
1095 | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
1096 | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
1097 | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
1098 /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
1099 | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
1100 | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
1101 | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
1102 | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
1103 | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
1104 | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
1105 | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
1106 | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
1107 /* special treatment for icons, as the extent is optional */
1108 | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
1109 $10->title = $3;
1110 $10->id = $5;
1111 $10->x = $7;
1112 $10->y = $9;
1113 $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
1114 }
1115 ;
1116
1117 gen_exctrl
1118 : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
1119 expr ',' style helpid opt_data {
1120 $$=new_control();
1121 $$->title = $1;
1122 $$->id = $3;
1123 $$->ctlclass = convert_ctlclass($5);
1124 $$->style = $7;
1125 $$->gotstyle = TRUE;
1126 $$->x = $9;
1127 $$->y = $11;
1128 $$->width = $13;
1129 $$->height = $15;
1130 if($17)
1131 {
1132 $$->exstyle = $17;
1133 $$->gotexstyle = TRUE;
1134 }
1135 if($18)
1136 {
1137 $$->helpid = *($18);
1138 $$->gothelpid = TRUE;
1139 free($18);
1140 }
1141 $$->extra = $19;
1142 }
1143 | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
1144 $$=new_control();
1145 $$->title = $1;
1146 $$->id = $3;
1147 $$->style = $7;
1148 $$->gotstyle = TRUE;
1149 $$->ctlclass = convert_ctlclass($5);
1150 $$->x = $9;
1151 $$->y = $11;
1152 $$->width = $13;
1153 $$->height = $15;
1154 $$->extra = $16;
1155 }
1156 ;
1157
1158 lab_exctrl
1159 : tSTRING opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1160 $$=new_control();
1161 $$->title = new_name_id();
1162 $$->title->type = name_str;
1163 $$->title->name.s_name = $1;
1164 $$->id = $3;
1165 $$->x = $5;
1166 $$->y = $7;
1167 $$->width = $9;
1168 $$->height = $11;
1169 if($12)
1170 {
1171 $$->style = $12->style;
1172 $$->gotstyle = TRUE;
1173
1174 if ($12->exstyle)
1175 {
1176 $$->exstyle = $12->exstyle;
1177 $$->gotexstyle = TRUE;
1178 }
1179 free($12);
1180 }
1181
1182 $$->extra = $14;
1183 }
1184 ;
1185
1186 exctrl_desc
1187 : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
1188 $$ = new_control();
1189 $$->id = $1;
1190 $$->x = $3;
1191 $$->y = $5;
1192 $$->width = $7;
1193 $$->height = $9;
1194 if($10)
1195 {
1196 $$->style = $10->style;
1197 $$->gotstyle = TRUE;
1198
1199 if ($10->exstyle)
1200 {
1201 $$->exstyle = $10->exstyle;
1202 $$->gotexstyle = TRUE;
1203 }
1204 free($10);
1205 }
1206 $$->extra = $12;
1207 }
1208 ;
1209
1210 opt_data: /* Empty */ { $$ = NULL; }
1211 | raw_data { $$ = $1; }
1212 ;
1213
1214 helpid : /* Empty */ { $$ = NULL; }
1215 | ',' expr { $$ = new_int($2); }
1216 ;
1217
1218 opt_exfont
1219 : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
1220 ;
1221
1222 /*
1223 * FIXME: This odd expression is here to nullify an extra token found
1224 * in some appstudio produced resources which appear to do nothing.
1225 */
1226 opt_expr: /* Empty */ { $$ = NULL; }
1227 | ',' expr { $$ = NULL; }
1228 ;
1229
1230 /* ------------------------------ Menu ------------------------------ */
1231 menu : tMENU loadmemopts opt_lvc menu_body {
1232 if(!$4)
1233 yyerror("Menu must contain items");
1234 $$ = new_menu();
1235 if($2)
1236 {
1237 $$->memopt = *($2);
1238 free($2);
1239 }
1240 else
1241 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1242 $$->items = get_item_head($4);
1243 if($3)
1244 {
1245 $$->lvc = *($3);
1246 free($3);
1247 }
1248 if(!$$->lvc.language)
1249 $$->lvc.language = dup_language(currentlanguage);
1250 }
1251 ;
1252
1253 menu_body
1254 : tBEGIN item_definitions tEND { $$ = $2; }
1255 ;
1256
1257 item_definitions
1258 : /* Empty */ {$$ = NULL;}
1259 | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
1260 $$=new_menu_item();
1261 $$->prev = $1;
1262 if($1)
1263 $1->next = $$;
1264 $$->id = $5;
1265 $$->state = $6;
1266 $$->name = $3;
1267 }
1268 | item_definitions tMENUITEM tSEPARATOR {
1269 $$=new_menu_item();
1270 $$->prev = $1;
1271 if($1)
1272 $1->next = $$;
1273 }
1274 | item_definitions tPOPUP tSTRING item_options menu_body {
1275 $$ = new_menu_item();
1276 $$->prev = $1;
1277 if($1)
1278 $1->next = $$;
1279 $$->popup = get_item_head($5);
1280 $$->name = $3;
1281 }
1282 ;
1283
1284 /* NOTE: item_options is right recursive because it would introduce
1285 * a shift/reduce conflict on ',' in itemex_options due to the
1286 * empty rule here. The parser is now forced to look beyond the ','
1287 * before reducing (force shift).
1288 * Right recursion here is not a problem because we cannot expect
1289 * more than 7 parserstack places to be occupied while parsing this
1290 * (who would want to specify a MF_x flag twice?).
1291 */
1292 item_options
1293 : /* Empty */ { $$ = 0; }
1294 | opt_comma tCHECKED item_options { $$ = $3 | MF_CHECKED; }
1295 | opt_comma tGRAYED item_options { $$ = $3 | MF_GRAYED; }
1296 | opt_comma tHELP item_options { $$ = $3 | MF_HELP; }
1297 | opt_comma tINACTIVE item_options { $$ = $3 | MF_DISABLED; }
1298 | opt_comma tMENUBARBREAK item_options { $$ = $3 | MF_MENUBARBREAK; }
1299 | opt_comma tMENUBREAK item_options { $$ = $3 | MF_MENUBREAK; }
1300 ;
1301
1302 /* ------------------------------ MenuEx ------------------------------ */
1303 menuex : tMENUEX loadmemopts opt_lvc menuex_body {
1304 if(!win32)
1305 yywarning("MENUEX not supported in 16-bit mode");
1306 if(!$4)
1307 yyerror("MenuEx must contain items");
1308 $$ = new_menuex();
1309 if($2)
1310 {
1311 $$->memopt = *($2);
1312 free($2);
1313 }
1314 else
1315 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
1316 $$->items = get_itemex_head($4);
1317 if($3)
1318 {
1319 $$->lvc = *($3);
1320 free($3);
1321 }
1322 if(!$$->lvc.language)
1323 $$->lvc.language = dup_language(currentlanguage);
1324 }
1325 ;
1326
1327 menuex_body
1328 : tBEGIN itemex_definitions tEND { $$ = $2; }
1329 ;
1330
1331 itemex_definitions
1332 : /* Empty */ {$$ = NULL; }
1333 | itemex_definitions tMENUITEM tSTRING itemex_options {
1334 $$ = new_menuex_item();
1335 $$->prev = $1;
1336 if($1)
1337 $1->next = $$;
1338 $$->name = $3;
1339 $$->id = $4->id;
1340 $$->type = $4->type;
1341 $$->state = $4->state;
1342 $$->helpid = $4->helpid;
1343 $$->gotid = $4->gotid;
1344 $$->gottype = $4->gottype;
1345 $$->gotstate = $4->gotstate;
1346 $$->gothelpid = $4->gothelpid;
1347 free($4);
1348 }
1349 | itemex_definitions tMENUITEM tSEPARATOR {
1350 $$ = new_menuex_item();
1351 $$->prev = $1;
1352 if($1)
1353 $1->next = $$;
1354 }
1355 | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
1356 $$ = new_menuex_item();
1357 $$->prev = $1;
1358 if($1)
1359 $1->next = $$;
1360 $$->popup = get_itemex_head($5);
1361 $$->name = $3;
1362 $$->id = $4->id;
1363 $$->type = $4->type;
1364 $$->state = $4->state;
1365 $$->helpid = $4->helpid;
1366 $$->gotid = $4->gotid;
1367 $$->gottype = $4->gottype;
1368 $$->gotstate = $4->gotstate;
1369 $$->gothelpid = $4->gothelpid;
1370 free($4);
1371 }
1372 ;
1373
1374 itemex_options
1375 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1376 | ',' expr {
1377 $$ = new_itemex_opt($2, 0, 0, 0);
1378 $$->gotid = TRUE;
1379 }
1380 | ',' e_expr ',' e_expr item_options {
1381 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
1382 $$->gotid = TRUE;
1383 $$->gottype = TRUE;
1384 $$->gotstate = TRUE;
1385 if($2) free($2);
1386 if($4) free($4);
1387 }
1388 | ',' e_expr ',' e_expr ',' expr {
1389 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1390 $$->gotid = TRUE;
1391 $$->gottype = TRUE;
1392 $$->gotstate = TRUE;
1393 if($2) free($2);
1394 if($4) free($4);
1395 }
1396 ;
1397
1398 itemex_p_options
1399 : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
1400 | ',' expr {
1401 $$ = new_itemex_opt($2, 0, 0, 0);
1402 $$->gotid = TRUE;
1403 }
1404 | ',' e_expr ',' expr {
1405 $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
1406 if($2) free($2);
1407 $$->gotid = TRUE;
1408 $$->gottype = TRUE;
1409 }
1410 | ',' e_expr ',' e_expr ',' expr {
1411 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
1412 if($2) free($2);
1413 if($4) free($4);
1414 $$->gotid = TRUE;
1415 $$->gottype = TRUE;
1416 $$->gotstate = TRUE;
1417 }
1418 | ',' e_expr ',' e_expr ',' e_expr ',' expr {
1419 $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
1420 if($2) free($2);
1421 if($4) free($4);
1422 if($6) free($6);
1423 $$->gotid = TRUE;
1424 $$->gottype = TRUE;
1425 $$->gotstate = TRUE;
1426 $$->gothelpid = TRUE;
1427 }
1428 ;
1429
1430 /* ------------------------------ StringTable ------------------------------ */
1431 /* Stringtables are parsed differently than other resources because their
1432 * layout is substantially different from other resources.
1433 * The table is parsed through a _global_ variable 'tagstt' which holds the
1434 * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
1435 * list of stringtables of different languages.
1436 */
1437 stringtable
1438 : stt_head tBEGIN strings tEND {
1439 if(!$3)
1440 {
1441 yyerror("Stringtable must have at least one entry");
1442 }
1443 else
1444 {
1445 stringtable_t *stt;
1446 /* Check if we added to a language table or created
1447 * a new one.
1448 */
1449 for(stt = sttres; stt; stt = stt->next)
1450 {
1451 if(stt == tagstt)
1452 break;
1453 }
1454 if(!stt)
1455 {
1456 /* It is a new one */
1457 if(sttres)
1458 {
1459 sttres->prev = tagstt;
1460 tagstt->next = sttres;
1461 sttres = tagstt;
1462 }
1463 else
1464 sttres = tagstt;
1465 }
1466 /* Else were done */
1467 }
1468 if(tagstt_memopt)
1469 {
1470 free(tagstt_memopt);
1471 tagstt_memopt = NULL;
1472 }
1473
1474 $$ = tagstt;
1475 }
1476 ;
1477
1478 /* This is to get the language of the currently parsed stringtable */
1479 stt_head: tSTRINGTABLE loadmemopts opt_lvc {
1480 if((tagstt = find_stringtable($3)) == NULL)
1481 tagstt = new_stringtable($3);
1482 tagstt_memopt = $2;
1483 tagstt_version = $3->version;
1484 tagstt_characts = $3->characts;
1485 if($3)
1486 free($3);
1487 }
1488 ;
1489
1490 strings : /* Empty */ { $$ = NULL; }
1491 | strings expr opt_comma tSTRING {
1492 int i;
1493 assert(tagstt != NULL);
1494 if($2 > 65535 || $2 < -32768)
1495 yyerror("Stringtable entry's ID out of range (%d)", $2);
1496 /* Search for the ID */
1497 for(i = 0; i < tagstt->nentries; i++)
1498 {
1499 if(tagstt->entries[i].id == $2)
1500 yyerror("Stringtable ID %d already in use", $2);
1501 }
1502 /* If we get here, then we have a new unique entry */
1503 tagstt->nentries++;
1504 tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
1505 tagstt->entries[tagstt->nentries-1].id = $2;
1506 tagstt->entries[tagstt->nentries-1].str = $4;
1507 if(tagstt_memopt)
1508 tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
1509 else
1510 tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1511 tagstt->entries[tagstt->nentries-1].version = tagstt_version;
1512 tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
1513
1514 if(pedantic && !$4->size)
1515 yywarning("Zero length strings make no sense");
1516 if(!win32 && $4->size > 254)
1517 yyerror("Stringtable entry more than 254 characters");
1518 if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
1519 yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
1520 $$ = tagstt;
1521 }
1522 ;
1523
1524 opt_comma /* There seem to be two ways to specify a stringtable... */
1525 : /* Empty */
1526 | ','
1527 ;
1528
1529 /* ------------------------------ VersionInfo ------------------------------ */
1530 versioninfo
1531 : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
1532 $$ = $3;
1533 if($2)
1534 {
1535 $$->memopt = *($2);
1536 free($2);
1537 }
1538 else
1539 $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
1540 $$->blocks = get_ver_block_head($5);
1541 /* Set language; there is no version or characteristics */
1542 $$->lvc.language = dup_language(currentlanguage);
1543 }
1544 ;
1545
1546 fix_version
1547 : /* Empty */ { $$ = new_versioninfo(); }
1548 | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
1549 if($1->gotit.fv)
1550 yyerror("FILEVERSION already defined");
1551 $$ = $1;
1552 $$->filever_maj1 = $3;
1553 $$->filever_maj2 = $5;
1554 $$->filever_min1 = $7;
1555 $$->filever_min2 = $9;
1556 $$->gotit.fv = 1;
1557 }
1558 | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
1559 if($1->gotit.pv)
1560 yyerror("PRODUCTVERSION already defined");
1561 $$ = $1;
1562 $$->prodver_maj1 = $3;
1563 $$->prodver_maj2 = $5;
1564 $$->prodver_min1 = $7;
1565 $$->prodver_min2 = $9;
1566 $$->gotit.pv = 1;
1567 }
1568 | fix_version tFILEFLAGS expr {
1569 if($1->gotit.ff)
1570 yyerror("FILEFLAGS already defined");
1571 $$ = $1;
1572 $$->fileflags = $3;
1573 $$->gotit.ff = 1;
1574 }
1575 | fix_version tFILEFLAGSMASK expr {
1576 if($1->gotit.ffm)
1577 yyerror("FILEFLAGSMASK already defined");
1578 $$ = $1;
1579 $$->fileflagsmask = $3;
1580 $$->gotit.ffm = 1;
1581 }
1582 | fix_version tFILEOS expr {
1583 if($1->gotit.fo)
1584 yyerror("FILEOS already defined");
1585 $$ = $1;
1586 $$->fileos = $3;
1587 $$->gotit.fo = 1;
1588 }
1589 | fix_version tFILETYPE expr {
1590 if($1->gotit.ft)
1591 yyerror("FILETYPE already defined");
1592 $$ = $1;
1593 $$->filetype = $3;
1594 $$->gotit.ft = 1;
1595 }
1596 | fix_version tFILESUBTYPE expr {
1597 if($1->gotit.fst)
1598 yyerror("FILESUBTYPE already defined");
1599 $$ = $1;
1600 $$->filesubtype = $3;
1601 $$->gotit.fst = 1;
1602 }
1603 ;
1604
1605 ver_blocks
1606 : /* Empty */ { $$ = NULL; }
1607 | ver_blocks ver_block {
1608 $$ = $2;
1609 $$->prev = $1;
1610 if($1)
1611 $1->next = $$;
1612 }
1613 ;
1614
1615 ver_block
1616 : tBLOCK tSTRING tBEGIN ver_values tEND {
1617 $$ = new_ver_block();
1618 $$->name = $2;
1619 $$->values = get_ver_value_head($4);
1620 }
1621 ;
1622
1623 ver_values
1624 : /* Empty */ { $$ = NULL; }
1625 | ver_values ver_value {
1626 $$ = $2;
1627 $$->prev = $1;
1628 if($1)
1629 $1->next = $$;
1630 }
1631 ;
1632
1633 ver_value
1634 : ver_block {
1635 $$ = new_ver_value();
1636 $$->type = val_block;
1637 $$->value.block = $1;
1638 }
1639 | tVALUE tSTRING ',' tSTRING {
1640 $$ = new_ver_value();
1641 $$->type = val_str;
1642 $$->key = $2;
1643 $$->value.str = $4;
1644 }
1645 | tVALUE tSTRING ',' ver_words {
1646 $$ = new_ver_value();
1647 $$->type = val_words;
1648 $$->key = $2;
1649 $$->value.words = $4;
1650 }
1651 ;
1652
1653 ver_words
1654 : expr { $$ = new_ver_words($1); }
1655 | ver_words ',' expr { $$ = add_ver_words($1, $3); }
1656 ;
1657
1658 /* ------------------------------ Toolbar ------------------------------ */
1659 toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
1660 int nitems;
1661 toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
1662 $$ = new_toolbar($3, $5, items, nitems);
1663 if($2)
1664 {
1665 $$->memopt = *($2);
1666 free($2);
1667 }
1668 else
1669 {
1670 $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
1671 }
1672 if($6)
1673 {
1674 $$->lvc = *($6);
1675 free($6);
1676 }
1677 if(!$$->lvc.language)
1678 {
1679 $$->lvc.language = dup_language(currentlanguage);
1680 }
1681 }
1682 ;
1683
1684 toolbar_items
1685 : /* Empty */ { $$ = NULL; }
1686 | toolbar_items tBUTTON expr {
1687 toolbar_item_t *idrec = new_toolbar_item();
1688 idrec->id = $3;
1689 $$ = ins_tlbr_button($1, idrec);
1690 }
1691 | toolbar_items tSEPARATOR {
1692 toolbar_item_t *idrec = new_toolbar_item();
1693 idrec->id = 0;
1694 $$ = ins_tlbr_button($1, idrec);
1695 }
1696 ;
1697
1698 /* ------------------------------ Memory options ------------------------------ */
1699 loadmemopts
1700 : /* Empty */ { $$ = NULL; }
1701 | loadmemopts lamo {
1702 if($1)
1703 {
1704 *($1) |= *($2);
1705 $$ = $1;
1706 free($2);
1707 }
1708 else
1709 $$ = $2;
1710 }
1711 | loadmemopts lama {
1712 if($1)
1713 {
1714 *($1) &= *($2);
1715 $$ = $1;
1716 free($2);
1717 }
1718 else
1719 {
1720 *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
1721 $$ = $2;
1722 }
1723 }
1724 ;
1725
1726 lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD); }
1727 | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE); }
1728 | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE); }
1729 | tPURE { $$ = new_int(WRC_MO_PURE); }
1730 ;
1731
1732 lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD); }
1733 | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE); }
1734 | tIMPURE { $$ = new_int(~WRC_MO_PURE); }
1735 ;
1736
1737 /* ------------------------------ Win32 options ------------------------------ */
1738 opt_lvc : /* Empty */ { $$ = new_lvc(); }
1739 | opt_lvc opt_language {
1740 if(!win32)
1741 yywarning("LANGUAGE not supported in 16-bit mode");
1742 if($1->language)
1743 yyerror("Language already defined");
1744 $$ = $1;
1745 $1->language = $2;
1746 }
1747 | opt_lvc opt_characts {
1748 if(!win32)
1749 yywarning("CHARACTERISTICS not supported in 16-bit mode");
1750 if($1->characts)
1751 yyerror("Characteristics already defined");
1752 $$ = $1;
1753 $1->characts = $2;
1754 }
1755 | opt_lvc opt_version {
1756 if(!win32)
1757 yywarning("VERSION not supported in 16-bit mode");
1758 if($1->version)
1759 yyerror("Version already defined");
1760 $$ = $1;
1761 $1->version = $2;
1762 }
1763 ;
1764
1765 /*
1766 * This here is another s/r conflict on {bi,u}nary + and -.
1767 * It is due to the look-ahead which must determine when the
1768 * rule opt_language ends. It could be solved with adding a
1769 * tNL at the end, but that seems unreasonable to do.
1770 * The conflict is now moved to the expression handling below.
1771 */
1772 opt_language
1773 : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
1774 if (get_language_codepage($2, $4) == -1)
1775 yyerror( "Language %04x is not supported", ($4<<10) + $2);
1776 }
1777 ;
1778
1779 opt_characts
1780 : tCHARACTERISTICS expr { $$ = new_characts($2); }
1781 ;
1782
1783 opt_version
1784 : tVERSION expr { $$ = new_version($2); }
1785 ;
1786
1787 /* ------------------------------ Raw data handling ------------------------------ */
1788 raw_data: opt_lvc tBEGIN raw_elements tEND {
1789 if($1)
1790 {
1791 $3->lvc = *($1);
1792 free($1);
1793 }
1794
1795 if(!$3->lvc.language)
1796 $3->lvc.language = dup_language(currentlanguage);
1797
1798 $$ = $3;
1799 }
1800 ;
1801
1802 raw_elements
1803 : tRAWDATA { $$ = $1; }
1804 | tNUMBER { $$ = int2raw_data($1); }
1805 | '-' tNUMBER { $$ = int2raw_data(-($2)); }
1806 | tLNUMBER { $$ = long2raw_data($1); }
1807 | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
1808 | tSTRING { $$ = str2raw_data($1); }
1809 | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
1810 | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
1811 | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
1812 | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
1813 | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
1814 | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
1815 ;
1816
1817 /* File data or raw data */
1818 file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
1819 | raw_data { $$ = $1; }
1820 ;
1821
1822 /* ------------------------------ Win32 expressions ------------------------------ */
1823 /* All win16 numbers are also handled here. This is inconsistent with MS'
1824 * resource compiler, but what the heck, its just handy to have.
1825 */
1826 e_expr : /* Empty */ { $$ = 0; }
1827 | expr { $$ = new_int($1); }
1828 ;
1829
1830 /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
1831 expr : xpr { $$ = ($1); }
1832 ;
1833
1834 xpr_no_not : xpr '+' xpr { $$ = ($1) + ($3); }
1835 | xpr '-' xpr { $$ = ($1) - ($3); }
1836 | xpr '|' xpr { $$ = ($1) | ($3); }
1837 | xpr '&' xpr { $$ = ($1) & ($3); }
1838 | xpr '*' xpr { $$ = ($1) * ($3); }
1839 | xpr '/' xpr { $$ = ($1) / ($3); }
1840 | xpr '^' xpr { $$ = ($1) ^ ($3); }
1841 | '~' xpr { $$ = ~($2); }
1842 | '-' xpr %prec pUPM { $$ = -($2); }
1843 | '+' xpr %prec pUPM { $$ = $2; }
1844 | '(' xpr ')' { $$ = $2; }
1845 | any_num { $$ = $1; }
1846 ;
1847
1848
1849 xpr : xpr_no_not { $$ = ($1); }
1850 | tNOT any_num { $$ = ~($2); }
1851 ;
1852
1853 any_num : tNUMBER { $$ = $1; }
1854 | tLNUMBER { $$ = $1; }
1855 ;
1856
1857 %%
1858 /* Dialog specific functions */
1859 static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
1860 {
1861 assert(dlg != NULL);
1862 if(dlg->style == NULL)
1863 {
1864 dlg->style = new_style(0,0);
1865 }
1866
1867 if(dlg->gotstyle)
1868 {
1869 yywarning("Style already defined, or-ing together");
1870 }
1871 else
1872 {
1873 dlg->style->or_mask = 0;
1874 dlg->style->and_mask = 0;
1875 }
1876 dlg->style->or_mask |= st->or_mask;
1877 dlg->style->and_mask |= st->and_mask;
1878 dlg->gotstyle = TRUE;
1879 free(st);
1880 return dlg;
1881 }
1882
1883 static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
1884 {
1885 assert(dlg != NULL);
1886 if(dlg->exstyle == NULL)
1887 {
1888 dlg->exstyle = new_style(0,0);
1889 }
1890
1891 if(dlg->gotexstyle)
1892 {
1893 yywarning("ExStyle already defined, or-ing together");
1894 }
1895 else
1896 {
1897 dlg->exstyle->or_mask = 0;
1898 dlg->exstyle->and_mask = 0;
1899 }
1900 dlg->exstyle->or_mask |= st->or_mask;
1901 dlg->exstyle->and_mask |= st->and_mask;
1902 dlg->gotexstyle = TRUE;
1903 free(st);
1904 return dlg;
1905 }
1906
1907 static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
1908 {
1909 assert(dlg != NULL);
1910 if(dlg->title)
1911 yyerror("Caption already defined");
1912 dlg->title = s;
1913 return dlg;
1914 }
1915
1916 static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
1917 {
1918 assert(dlg != NULL);
1919 if(dlg->font)
1920 yyerror("Font already defined");
1921 dlg->font = f;
1922 return dlg;
1923 }
1924
1925 static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
1926 {
1927 assert(dlg != NULL);
1928 if(dlg->dlgclass)
1929 yyerror("Class already defined");
1930 dlg->dlgclass = n;
1931 return dlg;
1932 }
1933
1934 static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
1935 {
1936 assert(dlg != NULL);
1937 if(dlg->menu)
1938 yyerror("Menu already defined");
1939 dlg->menu = m;
1940 return dlg;
1941 }
1942
1943 static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
1944 {
1945 assert(dlg != NULL);
1946 if(dlg->lvc.language)
1947 yyerror("Language already defined");
1948 dlg->lvc.language = l;
1949 return dlg;
1950 }
1951
1952 static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
1953 {
1954 assert(dlg != NULL);
1955 if(dlg->lvc.characts)
1956 yyerror("Characteristics already defined");
1957 dlg->lvc.characts = c;
1958 return dlg;
1959 }
1960
1961 static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
1962 {
1963 assert(dlg != NULL);
1964 if(dlg->lvc.version)
1965 yyerror("Version already defined");
1966 dlg->lvc.version = v;
1967 return dlg;
1968 }
1969
1970 /* Controls specific functions */
1971 static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
1972 {
1973 /* Hm... this seems to be jammed in at all time... */
1974 int defaultstyle = WS_CHILD | WS_VISIBLE;
1975
1976 assert(ctrl != NULL);
1977 ctrl->prev = prev;
1978
1979 if(prev)
1980 prev->next = ctrl;
1981
1982 if(type != -1)
1983 {
1984 ctrl->ctlclass = new_name_id();
1985 ctrl->ctlclass->type = name_ord;
1986 ctrl->ctlclass->name.i_name = type;
1987 }
1988
1989 switch(type)
1990 {
1991 case CT_BUTTON:
1992 if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
1993 defaultstyle |= WS_TABSTOP;
1994 break;
1995 case CT_EDIT:
1996 defaultstyle |= WS_TABSTOP | WS_BORDER;
1997 break;
1998 case CT_LISTBOX:
1999 defaultstyle |= LBS_NOTIFY | WS_BORDER;
2000 break;
2001 case CT_COMBOBOX:
2002 if (!(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
2003 defaultstyle |= CBS_SIMPLE;
2004 break;
2005 case CT_STATIC:
2006 if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
2007 defaultstyle |= WS_GROUP;
2008 break;
2009 }
2010
2011 if(!ctrl->gotstyle) /* Handle default style setting */
2012 {
2013 switch(type)
2014 {
2015 case CT_EDIT:
2016 defaultstyle |= ES_LEFT;
2017 break;
2018 case CT_LISTBOX:
2019 defaultstyle |= LBS_NOTIFY;
2020 break;
2021 case CT_COMBOBOX:
2022 defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
2023 break;
2024 case CT_SCROLLBAR:
2025 defaultstyle |= SBS_HORZ;
2026 break;
2027 case CT_BUTTON:
2028 switch(special_style)
2029 {
2030 case BS_CHECKBOX:
2031 case BS_DEFPUSHBUTTON:
2032 case BS_PUSHBUTTON:
2033 /* case BS_PUSHBOX: */
2034 case BS_AUTORADIOBUTTON:
2035 case BS_AUTO3STATE:
2036 case BS_3STATE:
2037 case BS_AUTOCHECKBOX:
2038 defaultstyle |= WS_TABSTOP;
2039 break;
2040 default:
2041 yywarning("Unknown default button control-style 0x%08x", special_style);
2042 case BS_GROUPBOX:
2043 case BS_RADIOBUTTON:
2044 break;
2045 }
2046 break;
2047
2048 case CT_STATIC:
2049 switch(special_style)
2050 {
2051 case SS_LEFT:
2052 case SS_RIGHT:
2053 case SS_CENTER:
2054 defaultstyle |= WS_GROUP;
2055 break;
2056 case SS_ICON: /* Special case */
2057 break;
2058 default:
2059 yywarning("Unknown default static control-style 0x%08x", special_style);
2060 break;
2061 }
2062 break;
2063 case -1: /* Generic control */
2064 goto byebye;
2065
2066 default:
2067 yyerror("Internal error (report this): Got weird control type 0x%08x", type);
2068 }
2069 }
2070
2071 /* The SS_ICON flag is always forced in for icon controls */
2072 if(type == CT_STATIC && special_style == SS_ICON)
2073 defaultstyle |= SS_ICON;
2074
2075 if (!ctrl->gotstyle)
2076 ctrl->style = new_style(0,0);
2077
2078 /* combine all styles */
2079 ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
2080 ctrl->gotstyle = TRUE;
2081 byebye:
2082 /* combine with NOT mask */
2083 if (ctrl->gotstyle)
2084 {
2085 ctrl->style->or_mask &= ~(ctrl->style->and_mask);
2086 ctrl->style->and_mask = 0;
2087 }
2088 if (ctrl->gotexstyle)
2089 {
2090 ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
2091 ctrl->exstyle->and_mask = 0;
2092 }
2093 return ctrl;
2094 }
2095
2096 static name_id_t *convert_ctlclass(name_id_t *cls)
2097 {
2098 char *cc = NULL;
2099 int iclass;
2100
2101 if(cls->type == name_ord)
2102 return cls;
2103 assert(cls->type == name_str);
2104 if(cls->type == str_unicode)
2105 {
2106 yyerror("Don't yet support unicode class comparison");
2107 }
2108 else
2109 cc = cls->name.s_name->str.cstr;
2110
2111 if(!strcasecmp("BUTTON", cc))
2112 iclass = CT_BUTTON;
2113 else if(!strcasecmp("COMBOBOX", cc))
2114 iclass = CT_COMBOBOX;
2115 else if(!strcasecmp("LISTBOX", cc))
2116 iclass = CT_LISTBOX;
2117 else if(!strcasecmp("EDIT", cc))
2118 iclass = CT_EDIT;
2119 else if(!strcasecmp("STATIC", cc))
2120 iclass = CT_STATIC;
2121 else if(!strcasecmp("SCROLLBAR", cc))
2122 iclass = CT_SCROLLBAR;
2123 else
2124 return cls; /* No default, return user controlclass */
2125
2126 free(cls->name.s_name->str.cstr);
2127 free(cls->name.s_name);
2128 cls->type = name_ord;
2129 cls->name.i_name = iclass;
2130 return cls;
2131 }
2132
2133 /* DialogEx specific functions */
2134 static dialogex_t *dialogex_style(style_t * st, dialogex_t *dlg)
2135 {
2136 assert(dlg != NULL);
2137 if(dlg->style == NULL)
2138 {
2139 dlg->style = new_style(0,0);
2140 }
2141
2142 if(dlg->gotstyle)
2143 {
2144 yywarning("Style already defined, or-ing together");
2145 }
2146 else
2147 {
2148 dlg->style->or_mask = 0;
2149 dlg->style->and_mask = 0;
2150 }
2151 dlg->style->or_mask |= st->or_mask;
2152 dlg->style->and_mask |= st->and_mask;
2153 dlg->gotstyle = TRUE;
2154 free(st);
2155 return dlg;
2156 }
2157
2158 static dialogex_t *dialogex_exstyle(style_t * st, dialogex_t *dlg)
2159 {
2160 assert(dlg != NULL);
2161 if(dlg->exstyle == NULL)
2162 {
2163 dlg->exstyle = new_style(0,0);
2164 }
2165
2166 if(dlg->gotexstyle)
2167 {
2168 yywarning("ExStyle already defined, or-ing together");
2169 }
2170 else
2171 {
2172 dlg->exstyle->or_mask = 0;
2173 dlg->exstyle->and_mask = 0;
2174 }
2175 dlg->exstyle->or_mask |= st->or_mask;
2176 dlg->exstyle->and_mask |= st->and_mask;
2177 dlg->gotexstyle = TRUE;
2178 free(st);
2179 return dlg;
2180 }
2181
2182 static dialogex_t *dialogex_caption(string_t *s, dialogex_t *dlg)
2183 {
2184 assert(dlg != NULL);
2185 if(dlg->title)
2186 yyerror("Caption already defined");
2187 dlg->title = s;
2188 return dlg;
2189 }
2190
2191 static dialogex_t *dialogex_font(font_id_t *f, dialogex_t *dlg)
2192 {
2193 assert(dlg != NULL);
2194 if(dlg->font)
2195 yyerror("Font already defined");
2196 dlg->font = f;
2197 return dlg;
2198 }
2199
2200 static dialogex_t *dialogex_class(name_id_t *n, dialogex_t *dlg)
2201 {
2202 assert(dlg != NULL);
2203 if(dlg->dlgclass)
2204 yyerror("Class already defined");
2205 dlg->dlgclass = n;
2206 return dlg;
2207 }
2208
2209 static dialogex_t *dialogex_menu(name_id_t *m, dialogex_t *dlg)
2210 {
2211 assert(dlg != NULL);
2212 if(dlg->menu)
2213 yyerror("Menu already defined");
2214 dlg->menu = m;
2215 return dlg;
2216 }
2217
2218 static dialogex_t *dialogex_language(language_t *l, dialogex_t *dlg)
2219 {
2220 assert(dlg != NULL);
2221 if(dlg->lvc.language)
2222 yyerror("Language already defined");
2223 dlg->lvc.language = l;
2224 return dlg;
2225 }
2226
2227 static dialogex_t *dialogex_characteristics(characts_t *c, dialogex_t *dlg)
2228 {
2229 assert(dlg != NULL);
2230 if(dlg->lvc.characts)
2231 yyerror("Characteristics already defined");
2232 dlg->lvc.characts = c;
2233 return dlg;
2234 }
2235
2236 static dialogex_t *dialogex_version(version_t *v, dialogex_t *dlg)
2237 {
2238 assert(dlg != NULL);
2239 if(dlg->lvc.version)
2240 yyerror("Version already defined");
2241 dlg->lvc.version = v;
2242 return dlg;
2243 }
2244
2245 /* Accelerator specific functions */
2246 static event_t *add_event(int key, int id, int flags, event_t *prev)
2247 {
2248 event_t *ev = new_event();
2249
2250 if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
2251 yyerror("Cannot use both ASCII and VIRTKEY");
2252
2253 ev->key = key;
2254 ev->id = id;
2255 ev->flags = flags & ~WRC_AF_ASCII;
2256 ev->prev = prev;
2257 if(prev)
2258 prev->next = ev;
2259 return ev;
2260 }
2261
2262 static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
2263 {
2264 int keycode = 0, keysym = 0;
2265 event_t *ev = new_event();
2266
2267 if(key->type == str_char)
2268 keysym = key->str.cstr[0];
2269 else
2270 keysym = key->str.wstr[0];
2271
2272 if((flags & WRC_AF_VIRTKEY) && (!isupper(keysym & 0xff) && !isdigit(keysym & 0xff)))
2273 yyerror("VIRTKEY code is not equal to ascii value");
2274
2275 if(keysym == '^' && (flags & WRC_AF_CONTROL) != 0)
2276 {
2277 yyerror("Cannot use both '^' and CONTROL modifier");
2278 }
2279 else if(keysym == '^')
2280 {
2281 if(key->type == str_char)
2282 keycode = toupper(key->str.cstr[1]) - '@';
2283 else
2284 keycode = toupper(key->str.wstr[1]) - '@';
2285 if(keycode >= ' ')
2286 yyerror("Control-code out of range");
2287 }
2288 else
2289 keycode = keysym;
2290 ev->key = keycode;
2291 ev->id = id;
2292 ev->flags = flags & ~WRC_AF_ASCII;
2293 ev->prev = prev;
2294 if(prev)
2295 prev->next = ev;
2296 return ev;
2297 }
2298
2299 /* MenuEx specific functions */
2300 static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
2301 {
2302 itemex_opt_t *opt = (itemex_opt_t *)xmalloc(sizeof(itemex_opt_t));
2303 opt->id = id;
2304 opt->type = type;
2305 opt->state = state;
2306 opt->helpid = helpid;
2307 return opt;
2308 }
2309
2310 /* Raw data functions */
2311 static raw_data_t *load_file(string_t *filename, language_t *lang)
2312 {
2313 FILE *fp = NULL;
2314 char *path;
2315 raw_data_t *rd;
2316 string_t *name;
2317 int codepage = get_language_codepage(lang->id, lang->sub);
2318
2319 /* FIXME: we may want to use utf-8 here */
2320 if (codepage <= 0 && filename->type != str_char)
2321 yyerror("Cannot convert filename to ASCII string");
2322 name = convert_string( filename, str_char, codepage );
2323 if (!(path = wpp_find_include(name->str.cstr, 1)))
2324 yyerror("Cannot open file %s", name->str.cstr);
2325 if (!(fp = fopen( path, "rb" )))
2326 yyerror("Cannot open file %s", name->str.cstr);
2327 free( path );
2328 rd = new_raw_data();
2329 fseek(fp, 0, SEEK_END);
2330 rd->size = ftell(fp);
2331 fseek(fp, 0, SEEK_SET);
2332 if (rd->size)
2333 {
2334 rd->data = (char *)xmalloc(rd->size);
2335 fread(rd->data, rd->size, 1, fp);
2336 }
2337 else rd->data = NULL;
2338 fclose(fp);
2339 rd->lvc.language = lang;
2340 free_string(name);
2341 return rd;
2342 }
2343
2344 static raw_data_t *int2raw_data(int i)
2345 {
2346 raw_data_t *rd;
2347
2348 if( ( i >= 0 && (int)((unsigned short)i) != i) ||
2349 ( i < 0 && (int)((short)i) != i) )
2350 yywarning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
2351
2352 rd = new_raw_data();
2353 rd->size = sizeof(short);
2354 rd->data = (char *)xmalloc(rd->size);
2355 switch(byteorder)
2356 {
2357 #ifdef WORDS_BIGENDIAN
2358 default:
2359 #endif
2360 case WRC_BO_BIG:
2361 rd->data[0] = HIBYTE(i);
2362 rd->data[1] = LOBYTE(i);
2363 break;
2364
2365 #ifndef WORDS_BIGENDIAN
2366 default:
2367 #endif
2368 case WRC_BO_LITTLE:
2369 rd->data[1] = HIBYTE(i);
2370 rd->data[0] = LOBYTE(i);
2371 break;
2372 }
2373 return rd;
2374 }
2375
2376 static raw_data_t *long2raw_data(int i)
2377 {
2378 raw_data_t *rd;
2379 rd = new_raw_data();
2380 rd->size = sizeof(int);
2381 rd->data = (char *)xmalloc(rd->size);
2382 switch(byteorder)
2383 {
2384 #ifdef WORDS_BIGENDIAN
2385 default:
2386 #endif
2387 case WRC_BO_BIG:
2388 rd->data[0] = HIBYTE(HIWORD(i));
2389 rd->data[1] = LOBYTE(HIWORD(i));
2390 rd->data[2] = HIBYTE(LOWORD(i));
2391 rd->data[3] = LOBYTE(LOWORD(i));
2392 break;
2393
2394 #ifndef WORDS_BIGENDIAN
2395 default:
2396 #endif
2397 case WRC_BO_LITTLE:
2398 rd->data[3] = HIBYTE(HIWORD(i));
2399 rd->data[2] = LOBYTE(HIWORD(i));
2400 rd->data[1] = HIBYTE(LOWORD(i));
2401 rd->data[0] = LOBYTE(LOWORD(i));
2402 break;
2403 }
2404 return rd;
2405 }
2406
2407 static raw_data_t *str2raw_data(string_t *str)
2408 {
2409 raw_data_t *rd;
2410 rd = new_raw_data();
2411 rd->size = str->size * (str->type == str_char ? 1 : 2);
2412 rd->data = (char *)xmalloc(rd->size);
2413 if(str->type == str_char)
2414 memcpy(rd->data, str->str.cstr, rd->size);
2415 else if(str->type == str_unicode)
2416 {
2417 int i;
2418 switch(byteorder)
2419 {
2420 #ifdef WORDS_BIGENDIAN
2421 default:
2422 #endif
2423 case WRC_BO_BIG:
2424 for(i = 0; i < str->size; i++)
2425 {
2426 rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
2427 rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
2428 }
2429 break;
2430 #ifndef WORDS_BIGENDIAN
2431 default:
2432 #endif
2433 case WRC_BO_LITTLE:
2434 for(i = 0; i < str->size; i++)
2435 {
2436 rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
2437 rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
2438 }
2439 break;
2440 }
2441 }
2442 else
2443 internal_error(__FILE__, __LINE__, "Invalid stringtype");
2444 return rd;
2445 }
2446
2447 static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
2448 {
2449 r1->data = xrealloc(r1->data, r1->size + r2->size);
2450 memcpy(r1->data + r1->size, r2->data, r2->size);
2451 r1->size += r2->size;
2452 return r1;
2453 }
2454
2455 static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
2456 {
2457 raw_data_t *t = int2raw_data(i);
2458 merge_raw_data(r1, t);
2459 free(t->data);
2460 free(t);
2461 return r1;
2462 }
2463
2464 static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
2465 {
2466 raw_data_t *t = long2raw_data(i);
2467 merge_raw_data(r1, t);
2468 free(t->data);
2469 free(t);
2470 return r1;
2471 }
2472
2473 static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
2474 {
2475 raw_data_t *t = str2raw_data(str);
2476 merge_raw_data(r1, t);
2477 free(t->data);
2478 free(t);
2479 return r1;
2480 }
2481
2482 /* Function the go back in a list to get the head */
2483 static menu_item_t *get_item_head(menu_item_t *p)
2484 {
2485 if(!p)
2486 return NULL;
2487 while(p->prev)
2488 p = p->prev;
2489 return p;
2490 }
2491
2492 static menuex_item_t *get_itemex_head(menuex_item_t *p)
2493 {
2494 if(!p)
2495 return NULL;
2496 while(p->prev)
2497 p = p->prev;
2498 return p;
2499 }
2500
2501 static resource_t *get_resource_head(resource_t *p)
2502 {
2503 if(!p)
2504 return NULL;
2505 while(p->prev)
2506 p = p->prev;
2507 return p;
2508 }
2509
2510 static ver_block_t *get_ver_block_head(ver_block_t *p)
2511 {
2512 if(!p)
2513 return NULL;
2514 while(p->prev)
2515 p = p->prev;
2516 return p;
2517 }
2518
2519 static ver_value_t *get_ver_value_head(ver_value_t *p)
2520 {
2521 if(!p)
2522 return NULL;
2523 while(p->prev)
2524 p = p->prev;
2525 return p;
2526 }
2527
2528 static control_t *get_control_head(control_t *p)
2529 {
2530 if(!p)
2531 return NULL;
2532 while(p->prev)
2533 p = p->prev;
2534 return p;
2535 }
2536
2537 static event_t *get_event_head(event_t *p)
2538 {
2539 if(!p)
2540 return NULL;
2541 while(p->prev)
2542 p = p->prev;
2543 return p;
2544 }
2545
2546 /* Find a stringtable with given language */
2547 static stringtable_t *find_stringtable(lvc_t *lvc)
2548 {
2549 stringtable_t *stt;
2550
2551 assert(lvc != NULL);
2552
2553 if(!lvc->language)
2554 lvc->language = dup_language(currentlanguage);
2555
2556 for(stt = sttres; stt; stt = stt->next)
2557 {
2558 if(stt->lvc.language->id == lvc->language->id
2559 && stt->lvc.language->sub == lvc->language->sub)
2560 {
2561 /* Found a table with the same language */
2562 /* The version and characteristics are now handled
2563 * in the generation of the individual stringtables.
2564 * This enables localized analysis.
2565 if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
2566 || (!stt->lvc.version && lvc->version)
2567 || (stt->lvc.version && !lvc->version))
2568 yywarning("Stringtable's versions are not the same, using first definition");
2569
2570 if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
2571 || (!stt->lvc.characts && lvc->characts)
2572 || (stt->lvc.characts && !lvc->characts))
2573 yywarning("Stringtable's characteristics are not the same, using first definition");
2574 */
2575 return stt;
2576 }
2577 }
2578 return NULL;
2579 }
2580
2581 /* qsort sorting function for string table entries */
2582 #define STE(p) ((const stt_entry_t *)(p))
2583 static int sort_stt_entry(const void *e1, const void *e2)
2584 {
2585 return STE(e1)->id - STE(e2)->id;
2586 }
2587 #undef STE
2588
2589 static resource_t *build_stt_resources(stringtable_t *stthead)
2590 {
2591 stringtable_t *stt;
2592 stringtable_t *newstt;
2593 resource_t *rsc;
2594 resource_t *rsclist = NULL;
2595 resource_t *rsctail = NULL;
2596 int i;
2597 int j;
2598 DWORD andsum;
2599 DWORD orsum;
2600 characts_t *characts;
2601 version_t *version;
2602
2603 if(!stthead)
2604 return NULL;
2605
2606 /* For all languages defined */
2607 for(stt = stthead; stt; stt = stt->next)
2608 {
2609 assert(stt->nentries > 0);
2610
2611 /* Sort the entries */
2612 if(stt->nentries > 1)
2613 qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
2614
2615 for(i = 0; i < stt->nentries; )
2616 {
2617 newstt = new_stringtable(&stt->lvc);
2618 newstt->entries = (stt_entry_t *)xmalloc(16 * sizeof(stt_entry_t));
2619 newstt->nentries = 16;
2620 newstt->idbase = stt->entries[i].id & ~0xf;
2621 for(j = 0; j < 16 && i < stt->nentries; j++)
2622 {
2623 if(stt->entries[i].id - newstt->idbase == j)
2624 {
2625 newstt->entries[j] = stt->entries[i];
2626 i++;
2627 }
2628 }
2629 andsum = ~0;
2630 orsum = 0;
2631 characts = NULL;
2632 version = NULL;
2633 /* Check individual memory options and get
2634 * the first characteristics/version
2635 */
2636 for(j = 0; j < 16; j++)
2637 {
2638 if(!newstt->entries[j].str)
2639 continue;
2640 andsum &= newstt->entries[j].memopt;
2641 orsum |= newstt->entries[j].memopt;
2642 if(!characts)
2643 characts = newstt->entries[j].characts;
2644 if(!version)
2645 version = newstt->entries[j].version;
2646 }
2647 if(andsum != orsum)
2648 {
2649 warning("Stringtable's memory options are not equal (idbase: %d)", newstt->idbase);
2650 }
2651 /* Check version and characteristics */
2652 for(j = 0; j < 16; j++)
2653 {
2654 if(characts
2655 && newstt->entries[j].characts
2656 && *newstt->entries[j].characts != *characts)
2657 warning("Stringtable's characteristics are not the same (idbase: %d)", newstt->idbase);
2658 if(version
2659 && newstt->entries[j].version
2660 && *newstt->entries[j].version != *version)
2661 warning("Stringtable's versions are not the same (idbase: %d)", newstt->idbase);
2662 }
2663 rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
2664 rsc->name = new_name_id();
2665 rsc->name->type = name_ord;
2666 rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
2667 rsc->memopt = andsum; /* Set to least common denominator */
2668 newstt->memopt = andsum;
2669 newstt->lvc.characts = characts;
2670 newstt->lvc.version = version;
2671 if(!rsclist)
2672 {
2673 rsclist = rsc;
2674 rsctail = rsc;
2675 }
2676 else
2677 {
2678 rsctail->next = rsc;
2679 rsc->prev = rsctail;
2680 rsctail = rsc;
2681 }
2682 }
2683 }
2684 return rsclist;
2685 }
2686
2687
2688 static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
2689 {
2690 idrec->prev = prev;
2691 if(prev)
2692 prev->next = idrec;
2693
2694 return idrec;
2695 }
2696
2697 static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
2698 {
2699 if(!p)
2700 {
2701 *nitems = 0;
2702 return NULL;
2703 }
2704
2705 *nitems = 1;
2706
2707 while(p->prev)
2708 {
2709 (*nitems)++;
2710 p = p->prev;
2711 }
2712
2713 return p;
2714 }
2715
2716 static string_t *make_filename(string_t *str)
2717 {
2718 if(str->type == str_char)
2719 {
2720 char *cptr;
2721
2722 /* Remove escaped backslash and convert to forward */
2723 for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
2724 {
2725 if(cptr[1] == '\\')
2726 {
2727 memmove(cptr, cptr+1, strlen(cptr));
2728 str->size--;
2729 }
2730 *cptr = '/';
2731 }
2732 }
2733 else
2734 {
2735 WCHAR *wptr;
2736
2737 /* Remove escaped backslash and convert to forward */
2738 for(wptr = str->str.wstr; (wptr = strchrW(wptr, '\\')) != NULL; wptr++)
2739 {
2740 if(wptr[1] == '\\')
2741 {
2742 memmove(wptr, wptr+1, strlenW(wptr));
2743 str->size--;
2744 }
2745 *wptr = '/';
2746 }
2747 }
2748 return str;
2749 }
2750
2751 /*
2752 * Process all resources to extract fonts and build
2753 * a fontdir resource.
2754 *
2755 * Note: MS' resource compiler (build 1472) does not
2756 * handle font resources with different languages.
2757 * The fontdir is generated in the last active language
2758 * and font identifiers must be unique across the entire
2759 * source.
2760 * This is not logical considering the localization
2761 * constraints of all other resource types. MS has,
2762 * most probably, never testet localized fonts. However,
2763 * using fontresources is rare, so it might not occur
2764 * in normal applications.
2765 * Wine does require better localization because a lot
2766 * of languages are coded into the same executable.
2767 * Therefore, I will generate fontdirs for *each*
2768 * localized set of fonts.
2769 */
2770 static resource_t *build_fontdir(resource_t **fnt, int nfnt)
2771 {
2772 static int once = 0;
2773 if(!once)
2774 {
2775 warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)", fnt, nfnt);
2776 once++;
2777 }
2778 return NULL;
2779 }
2780
2781 static resource_t *build_fontdirs(resource_t *tail)
2782 {
2783 resource_t *rsc;
2784 resource_t *lst = NULL;
2785 resource_t **fnt = NULL; /* List of all fonts */
2786 int nfnt = 0;
2787 resource_t **fnd = NULL; /* List of all fontdirs */
2788 int nfnd = 0;
2789 resource_t **lanfnt = NULL;
2790 int nlanfnt = 0;
2791 int i;
2792 name_id_t nid;
2793 string_t str;
2794 int fntleft;
2795
2796 nid.type = name_str;
2797 nid.name.s_name = &str;
2798 str.type = str_char;
2799 str.str.cstr = xstrdup("FONTDIR");
2800 str.size = 7;
2801
2802 /* Extract all fonts and fontdirs */
2803 for(rsc = tail; rsc; rsc = rsc->prev)
2804 {
2805 if(rsc->type == res_fnt)
2806 {
2807 nfnt++;
2808 fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
2809 fnt[nfnt-1] = rsc;
2810 }
2811 else if(rsc->type == res_fntdir)
2812 {
2813 nfnd++;
2814 fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
2815 fnd[nfnd-1] = rsc;
2816 }
2817 }
2818
2819 /* Verify the name of the present fontdirs */
2820 for(i = 0; i < nfnd; i++)
2821 {
2822 if(compare_name_id(&nid, fnd[i]->name))
2823 {
2824 warning("User supplied FONTDIR entry has an invalid name '%s', ignored",
2825 get_nameid_str(fnd[i]->name));
2826 fnd[i] = NULL;
2827 }
2828 }
2829
2830 /* Sanity check */
2831 if(nfnt == 0)
2832 {
2833 if(nfnd != 0)
2834 warning("Found %d FONTDIR entries without any fonts present", nfnd);
2835 goto clean;
2836 }
2837
2838 /* Copy space */
2839 lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
2840
2841 /* Get all fonts covered by fontdirs */
2842 for(i = 0; i < nfnd; i++)
2843 {
2844 int j;
2845 WORD cnt;
2846 int isswapped = 0;
2847
2848 if(!fnd[i])
2849 continue;
2850 for(j = 0; j < nfnt; j++)
2851 {
2852 if(!fnt[j])
2853 continue;
2854 if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
2855 {
2856 lanfnt[nlanfnt] = fnt[j];
2857 nlanfnt++;
2858 fnt[j] = NULL;
2859 }
2860 }
2861
2862 cnt = *(WORD *)fnd[i]->res.fnd->data->data;
2863 if(nlanfnt == cnt)
2864 isswapped = 0;
2865 else if(nlanfnt == BYTESWAP_WORD(cnt))
2866 isswapped = 1;
2867 else
2868 error("FONTDIR for language %d,%d has wrong count (%d, expected %d)",
2869 fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
2870 #ifdef WORDS_BIGENDIAN
2871 if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
2872 #else
2873 if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
2874 #endif
2875 {
2876 internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping");
2877 }
2878 }
2879
2880 /* We now have fonts left where we need to make a fontdir resource */
2881 for(i = fntleft = 0; i < nfnt; i++)
2882 {
2883 if(fnt[i])
2884 fntleft++;
2885 }
2886 while(fntleft)
2887 {
2888 /* Get fonts of same language in lanfnt[] */
2889 for(i = nlanfnt = 0; i < nfnt; i++)
2890 {
2891 if(fnt[i])
2892 {
2893 if(!nlanfnt)
2894 {
2895 addlanfnt:
2896 lanfnt[nlanfnt] = fnt[i];
2897 nlanfnt++;
2898 fnt[i] = NULL;
2899 fntleft--;
2900 }
2901 else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
2902 goto addlanfnt;
2903 }
2904 }
2905 /* and build a fontdir */
2906 rsc = build_fontdir(lanfnt, nlanfnt);
2907 if(rsc)
2908 {
2909 if(lst)
2910 {
2911 lst->next = rsc;
2912 rsc->prev = lst;
2913 }
2914 lst = rsc;
2915 }
2916 }
2917
2918 free(lanfnt);
2919 clean:
2920 if(fnt)
2921 free(fnt);
2922 if(fnd)
2923 free(fnd);
2924 free(str.str.cstr);
2925 return lst;
2926 }
2927
2928 /*
2929 * This gets invoked to determine whether the next resource
2930 * is to be of a standard-type (e.g. bitmaps etc.), or should
2931 * be a user-type resource. This function is required because
2932 * there is the _possibility_ of a lookahead token in the
2933 * parser, which is generated from the "expr" state in the
2934 * "nameid" parsing.
2935 *
2936 * The general resource format is:
2937 * <identifier> <type> <flags> <resourcebody>
2938 *
2939 * The <identifier> can either be tIDENT or "expr". The latter
2940 * will always generate a lookahead, which is the <type> of the
2941 * resource to parse. Otherwise, we need to get a new token from
2942 * the scanner to determine the next step.
2943 *
2944 * The problem arrises when <type> is numerical. This case should
2945 * map onto default resource-types and be parsed as such instead
2946 * of being mapped onto user-type resources.
2947 *
2948 * The trick lies in the fact that yacc (bison) doesn't care about
2949 * intermediate changes of the lookahead while reducing a rule. We
2950 * simply replace the lookahead with a token that will result in
2951 * a shift to the appropriate rule for the specific resource-type.
2952 */
2953 static int rsrcid_to_token(int lookahead)
2954 {
2955 int token;
2956 const char *type = "?";
2957
2958 /* Get a token if we don't have one yet */
2959 if(lookahead == YYEMPTY)
2960 lookahead = YYLEX;
2961
2962 /* Only numbers are possibly interesting */
2963 switch(lookahead)
2964 {
2965 case tNUMBER:
2966 case tLNUMBER:
2967 break;
2968 default:
2969 return lookahead;
2970 }
2971
2972 token = lookahead;
2973
2974 switch(yylval.num)
2975 {
2976 case WRC_RT_CURSOR:
2977 type = "CURSOR";
2978 token = tCURSOR;
2979 break;
2980 case WRC_RT_ICON:
2981 type = "ICON";
2982 token = tICON;
2983 break;
2984 case WRC_RT_BITMAP:
2985 type = "BITMAP";
2986 token = tBITMAP;
2987 break;
2988 case WRC_RT_FONT:
2989 type = "FONT";
2990 token = tFONT;
2991 break;
2992 case WRC_RT_FONTDIR:
2993 type = "FONTDIR";
2994 token = tFONTDIR;
2995 break;
2996 case WRC_RT_RCDATA:
2997 type = "RCDATA";
2998 token = tRCDATA;
2999 break;
3000 case WRC_RT_MESSAGETABLE:
3001 type = "MESSAGETABLE";
3002 token = tMESSAGETABLE;
3003 break;
3004 case WRC_RT_DLGINIT:
3005 type = "DLGINIT";
3006 token = tDLGINIT;
3007 break;
3008 case WRC_RT_ACCELERATOR:
3009 type = "ACCELERATOR";
3010 token = tACCELERATORS;
3011 break;
3012 case WRC_RT_MENU:
3013 type = "MENU";
3014 token = tMENU;
3015 break;
3016 case WRC_RT_DIALOG:
3017 type = "DIALOG";
3018 token = tDIALOG;
3019 break;
3020 case WRC_RT_VERSION:
3021 type = "VERSION";
3022 token = tVERSIONINFO;
3023 break;
3024 case WRC_RT_TOOLBAR:
3025 type = "TOOLBAR";
3026 token = tTOOLBAR;
3027 break;
3028 case WRC_RT_HTML:
3029 type = "HTML";
3030 token = tHTML;
3031 break;
3032
3033 case WRC_RT_STRING:
3034 type = "STRINGTABLE";
3035 break;
3036
3037 case WRC_RT_ANICURSOR:
3038 case WRC_RT_ANIICON:
3039 case WRC_RT_GROUP_CURSOR:
3040 case WRC_RT_GROUP_ICON:
3041 yywarning("Usertype uses reserved type ID %d, which is auto-generated", yylval.num);
3042 return lookahead;
3043
3044 case WRC_RT_DLGINCLUDE:
3045 case WRC_RT_PLUGPLAY:
3046 case WRC_RT_VXD:
3047 yywarning("Usertype uses reserved type ID %d, which is not supported by wrc yet", yylval.num);
3048 default:
3049 return lookahead;
3050 }
3051
3052 return token;
3053 }