bfd/
[binutils.git] / binutils / rcparse.y
blobfbc5bef6f8ae190642f3202681c8fa35df1a5d1e
1 %{ /* rcparse.y -- parser for Windows rc files
2 Copyright 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
3 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GNU Binutils.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
23 /* This is a parser for Windows rc files. It is based on the parser
24 by Gunther Ebert <gunther.ebert@ixos-leipzig.de>. */
26 #include "bfd.h"
27 #include "bucomm.h"
28 #include "libiberty.h"
29 #include "windres.h"
30 #include "safe-ctype.h"
32 /* The current language. */
34 static unsigned short language;
36 /* The resource information during a sub statement. */
38 static struct res_res_info sub_res_info;
40 /* Dialog information. This is built by the nonterminals styles and
41 controls. */
43 static struct dialog dialog;
45 /* This is used when building a style. It is modified by the
46 nonterminal styleexpr. */
48 static unsigned long style;
50 /* These are used when building a control. They are set before using
51 control_params. */
53 static unsigned long base_style;
54 static unsigned long default_style;
55 static unsigned long class;
56 static struct res_id res_text_field;
57 static unichar null_unichar;
59 /* This is used for COMBOBOX, LISTBOX and EDITTEXT which
60 do not allow resource 'text' field in control definition. */
61 static const struct res_id res_null_text = { 1, {{0, &null_unichar}}};
65 %union
67 struct accelerator acc;
68 struct accelerator *pacc;
69 struct dialog_control *dialog_control;
70 struct menuitem *menuitem;
71 struct
73 struct rcdata_item *first;
74 struct rcdata_item *last;
75 } rcdata;
76 struct rcdata_item *rcdata_item;
77 struct stringtable_data *stringtable;
78 struct fixed_versioninfo *fixver;
79 struct ver_info *verinfo;
80 struct ver_stringinfo *verstring;
81 struct ver_varinfo *vervar;
82 struct res_id id;
83 struct res_res_info res_info;
84 struct
86 unsigned short on;
87 unsigned short off;
88 } memflags;
89 struct
91 unsigned long val;
92 /* Nonzero if this number was explicitly specified as long. */
93 int dword;
94 } i;
95 unsigned long il;
96 unsigned short is;
97 const char *s;
98 struct
100 unsigned long length;
101 const char *s;
102 } ss;
105 %token BEG END
106 %token ACCELERATORS VIRTKEY ASCII NOINVERT SHIFT CONTROL ALT
107 %token BITMAP
108 %token CURSOR
109 %token DIALOG DIALOGEX EXSTYLE CAPTION CLASS STYLE
110 %token AUTO3STATE AUTOCHECKBOX AUTORADIOBUTTON CHECKBOX COMBOBOX CTEXT
111 %token DEFPUSHBUTTON EDITTEXT GROUPBOX LISTBOX LTEXT PUSHBOX PUSHBUTTON
112 %token RADIOBUTTON RTEXT SCROLLBAR STATE3 USERBUTTON
113 %token BEDIT HEDIT IEDIT
114 %token FONT
115 %token ICON
116 %token LANGUAGE CHARACTERISTICS VERSIONK
117 %token MENU MENUEX MENUITEM SEPARATOR POPUP CHECKED GRAYED HELP INACTIVE
118 %token MENUBARBREAK MENUBREAK
119 %token MESSAGETABLE
120 %token RCDATA
121 %token STRINGTABLE
122 %token VERSIONINFO FILEVERSION PRODUCTVERSION FILEFLAGSMASK FILEFLAGS
123 %token FILEOS FILETYPE FILESUBTYPE BLOCKSTRINGFILEINFO BLOCKVARFILEINFO
124 %token VALUE
125 %token <s> BLOCK
126 %token MOVEABLE FIXED PURE IMPURE PRELOAD LOADONCALL DISCARDABLE
127 %token NOT
128 %token <s> QUOTEDSTRING STRING
129 %token <i> NUMBER
130 %token <ss> SIZEDSTRING
131 %token IGNORED_TOKEN
133 %type <pacc> acc_entries
134 %type <acc> acc_entry acc_event
135 %type <dialog_control> control control_params
136 %type <menuitem> menuitems menuitem menuexitems menuexitem
137 %type <rcdata> optrcdata_data optrcdata_data_int rcdata_data
138 %type <rcdata_item> opt_control_data
139 %type <fixver> fixedverinfo
140 %type <verinfo> verblocks
141 %type <verstring> vervals
142 %type <vervar> vertrans
143 %type <res_info> suboptions memflags_move_discard memflags_move
144 %type <memflags> memflag
145 %type <id> id optresidc resref
146 %type <il> exstyle parennumber
147 %type <il> numexpr posnumexpr cnumexpr optcnumexpr cposnumexpr
148 %type <is> acc_options acc_option menuitem_flags menuitem_flag
149 %type <s> file_name resname
150 %type <i> sizednumexpr sizedposnumexpr
152 %left '|'
153 %left '^'
154 %left '&'
155 %left '+' '-'
156 %left '*' '/' '%'
157 %right '~' NEG
161 input:
162 /* empty */
163 | input accelerator
164 | input bitmap
165 | input cursor
166 | input dialog
167 | input font
168 | input icon
169 | input language
170 | input menu
171 | input menuex
172 | input messagetable
173 | input rcdata
174 | input stringtable
175 | input user
176 | input versioninfo
177 | input IGNORED_TOKEN
180 /* Accelerator resources. */
182 accelerator:
183 id ACCELERATORS suboptions BEG acc_entries END
185 define_accelerator ($1, &$3, $5);
186 if (yychar != YYEMPTY)
187 YYERROR;
188 rcparse_discard_strings ();
192 acc_entries:
193 /* empty */
195 $$ = NULL;
197 | acc_entries acc_entry
199 struct accelerator *a;
201 a = (struct accelerator *) res_alloc (sizeof *a);
202 *a = $2;
203 if ($1 == NULL)
204 $$ = a;
205 else
207 struct accelerator **pp;
209 for (pp = &$1->next; *pp != NULL; pp = &(*pp)->next)
211 *pp = a;
212 $$ = $1;
217 acc_entry:
218 acc_event cposnumexpr
220 $$ = $1;
221 $$.id = $2;
223 | acc_event cposnumexpr ',' acc_options
225 $$ = $1;
226 $$.id = $2;
227 $$.flags |= $4;
228 if (($$.flags & ACC_VIRTKEY) == 0
229 && ($$.flags & (ACC_SHIFT | ACC_CONTROL)) != 0)
230 rcparse_warning (_("inappropriate modifiers for non-VIRTKEY"));
234 acc_event:
235 QUOTEDSTRING
237 const char *s = $1;
238 char ch;
240 $$.next = NULL;
241 $$.id = 0;
242 ch = *s;
243 if (ch != '^')
244 $$.flags = 0;
245 else
247 $$.flags = ACC_CONTROL | ACC_VIRTKEY;
248 ++s;
249 ch = *s;
250 ch = TOUPPER (ch);
252 $$.key = ch;
253 if (s[1] != '\0')
254 rcparse_warning (_("accelerator should only be one character"));
256 | posnumexpr
258 $$.next = NULL;
259 $$.flags = 0;
260 $$.id = 0;
261 $$.key = $1;
265 acc_options:
266 acc_option
268 $$ = $1;
270 | acc_options ',' acc_option
272 $$ = $1 | $3;
274 /* I've had one report that the comma is optional. */
275 | acc_options acc_option
277 $$ = $1 | $2;
281 acc_option:
282 VIRTKEY
284 $$ = ACC_VIRTKEY;
286 | ASCII
288 /* This is just the absence of VIRTKEY. */
289 $$ = 0;
291 | NOINVERT
293 $$ = ACC_NOINVERT;
295 | SHIFT
297 $$ = ACC_SHIFT;
299 | CONTROL
301 $$ = ACC_CONTROL;
303 | ALT
305 $$ = ACC_ALT;
309 /* Bitmap resources. */
311 bitmap:
312 id BITMAP memflags_move file_name
314 define_bitmap ($1, &$3, $4);
315 if (yychar != YYEMPTY)
316 YYERROR;
317 rcparse_discard_strings ();
321 /* Cursor resources. */
323 cursor:
324 id CURSOR memflags_move_discard file_name
326 define_cursor ($1, &$3, $4);
327 if (yychar != YYEMPTY)
328 YYERROR;
329 rcparse_discard_strings ();
333 /* Dialog resources. */
335 dialog:
336 id DIALOG memflags_move exstyle posnumexpr cnumexpr cnumexpr
337 cnumexpr
339 memset (&dialog, 0, sizeof dialog);
340 dialog.x = $5;
341 dialog.y = $6;
342 dialog.width = $7;
343 dialog.height = $8;
344 dialog.style = WS_POPUP | WS_BORDER | WS_SYSMENU;
345 dialog.exstyle = $4;
346 dialog.menu.named = 1;
347 dialog.class.named = 1;
348 dialog.font = NULL;
349 dialog.ex = NULL;
350 dialog.controls = NULL;
351 sub_res_info = $3;
352 style = 0;
354 styles BEG controls END
356 define_dialog ($1, &sub_res_info, &dialog);
357 if (yychar != YYEMPTY)
358 YYERROR;
359 rcparse_discard_strings ();
361 | id DIALOGEX memflags_move exstyle posnumexpr cnumexpr cnumexpr
362 cnumexpr
364 memset (&dialog, 0, sizeof dialog);
365 dialog.x = $5;
366 dialog.y = $6;
367 dialog.width = $7;
368 dialog.height = $8;
369 dialog.style = WS_POPUP | WS_BORDER | WS_SYSMENU;
370 dialog.exstyle = $4;
371 dialog.menu.named = 1;
372 dialog.class.named = 1;
373 dialog.font = NULL;
374 dialog.ex = ((struct dialog_ex *)
375 res_alloc (sizeof (struct dialog_ex)));
376 memset (dialog.ex, 0, sizeof (struct dialog_ex));
377 dialog.controls = NULL;
378 sub_res_info = $3;
379 style = 0;
381 styles BEG controls END
383 define_dialog ($1, &sub_res_info, &dialog);
384 if (yychar != YYEMPTY)
385 YYERROR;
386 rcparse_discard_strings ();
388 | id DIALOGEX memflags_move exstyle posnumexpr cnumexpr cnumexpr
389 cnumexpr cnumexpr
391 memset (&dialog, 0, sizeof dialog);
392 dialog.x = $5;
393 dialog.y = $6;
394 dialog.width = $7;
395 dialog.height = $8;
396 dialog.style = WS_POPUP | WS_BORDER | WS_SYSMENU;
397 dialog.exstyle = $4;
398 dialog.menu.named = 1;
399 dialog.class.named = 1;
400 dialog.font = NULL;
401 dialog.ex = ((struct dialog_ex *)
402 res_alloc (sizeof (struct dialog_ex)));
403 memset (dialog.ex, 0, sizeof (struct dialog_ex));
404 dialog.ex->help = $9;
405 dialog.controls = NULL;
406 sub_res_info = $3;
407 style = 0;
409 styles BEG controls END
411 define_dialog ($1, &sub_res_info, &dialog);
412 if (yychar != YYEMPTY)
413 YYERROR;
414 rcparse_discard_strings ();
418 exstyle:
419 /* empty */
421 $$ = 0;
423 | EXSTYLE '=' numexpr
425 $$ = $3;
429 styles:
430 /* empty */
431 | styles CAPTION QUOTEDSTRING
433 dialog.style |= WS_CAPTION;
434 style |= WS_CAPTION;
435 unicode_from_ascii ((int *) NULL, &dialog.caption, $3);
437 | styles CLASS id
439 dialog.class = $3;
441 | styles STYLE
442 styleexpr
444 dialog.style = style;
446 | styles EXSTYLE numexpr
448 dialog.exstyle = $3;
450 | styles CLASS QUOTEDSTRING
452 res_string_to_id (& dialog.class, $3);
454 | styles FONT numexpr ',' QUOTEDSTRING
456 dialog.style |= DS_SETFONT;
457 style |= DS_SETFONT;
458 dialog.pointsize = $3;
459 unicode_from_ascii ((int *) NULL, &dialog.font, $5);
460 if (dialog.ex != NULL)
462 dialog.ex->weight = 0;
463 dialog.ex->italic = 0;
464 dialog.ex->charset = 1;
467 | styles FONT numexpr ',' QUOTEDSTRING cnumexpr
469 dialog.style |= DS_SETFONT;
470 style |= DS_SETFONT;
471 dialog.pointsize = $3;
472 unicode_from_ascii ((int *) NULL, &dialog.font, $5);
473 if (dialog.ex == NULL)
474 rcparse_warning (_("extended FONT requires DIALOGEX"));
475 else
477 dialog.ex->weight = $6;
478 dialog.ex->italic = 0;
479 dialog.ex->charset = 1;
482 | styles FONT numexpr ',' QUOTEDSTRING cnumexpr cnumexpr
484 dialog.style |= DS_SETFONT;
485 style |= DS_SETFONT;
486 dialog.pointsize = $3;
487 unicode_from_ascii ((int *) NULL, &dialog.font, $5);
488 if (dialog.ex == NULL)
489 rcparse_warning (_("extended FONT requires DIALOGEX"));
490 else
492 dialog.ex->weight = $6;
493 dialog.ex->italic = $7;
494 dialog.ex->charset = 1;
497 | styles FONT numexpr ',' QUOTEDSTRING cnumexpr cnumexpr cnumexpr
499 dialog.style |= DS_SETFONT;
500 style |= DS_SETFONT;
501 dialog.pointsize = $3;
502 unicode_from_ascii ((int *) NULL, &dialog.font, $5);
503 if (dialog.ex == NULL)
504 rcparse_warning (_("extended FONT requires DIALOGEX"));
505 else
507 dialog.ex->weight = $6;
508 dialog.ex->italic = $7;
509 dialog.ex->charset = $8;
512 | styles MENU id
514 dialog.menu = $3;
516 | styles CHARACTERISTICS numexpr
518 sub_res_info.characteristics = $3;
520 | styles LANGUAGE numexpr cnumexpr
522 sub_res_info.language = $3 | ($4 << SUBLANG_SHIFT);
524 | styles VERSIONK numexpr
526 sub_res_info.version = $3;
530 controls:
531 /* empty */
532 | controls control
534 struct dialog_control **pp;
536 for (pp = &dialog.controls; *pp != NULL; pp = &(*pp)->next)
538 *pp = $2;
542 control:
543 AUTO3STATE optresidc
545 default_style = BS_AUTO3STATE | WS_TABSTOP;
546 base_style = BS_AUTO3STATE;
547 class = CTL_BUTTON;
548 res_text_field = $2;
550 control_params
552 $$ = $4;
554 | AUTOCHECKBOX optresidc
556 default_style = BS_AUTOCHECKBOX | WS_TABSTOP;
557 base_style = BS_AUTOCHECKBOX;
558 class = CTL_BUTTON;
559 res_text_field = $2;
561 control_params
563 $$ = $4;
565 | AUTORADIOBUTTON optresidc
567 default_style = BS_AUTORADIOBUTTON | WS_TABSTOP;
568 base_style = BS_AUTORADIOBUTTON;
569 class = CTL_BUTTON;
570 res_text_field = $2;
572 control_params
574 $$ = $4;
576 | BEDIT optresidc
578 default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
579 base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
580 class = CTL_EDIT;
581 res_text_field = $2;
583 control_params
585 $$ = $4;
586 if (dialog.ex == NULL)
587 rcparse_warning (_("BEDIT requires DIALOGEX"));
588 res_string_to_id (&$$->class, "BEDIT");
590 | CHECKBOX optresidc
592 default_style = BS_CHECKBOX | WS_TABSTOP;
593 base_style = BS_CHECKBOX | WS_TABSTOP;
594 class = CTL_BUTTON;
595 res_text_field = $2;
597 control_params
599 $$ = $4;
601 | COMBOBOX
603 /* This is as per MSDN documentation. With some (???)
604 versions of MS rc.exe their is no default style. */
605 default_style = CBS_SIMPLE | WS_TABSTOP;
606 base_style = 0;
607 class = CTL_COMBOBOX;
608 res_text_field = res_null_text;
610 control_params
612 $$ = $3;
614 | CONTROL optresidc numexpr cnumexpr control_styleexpr cnumexpr
615 cnumexpr cnumexpr cnumexpr optcnumexpr opt_control_data
617 $$ = define_control ($2, $3, $6, $7, $8, $9, $4, style, $10);
618 if ($11 != NULL)
620 if (dialog.ex == NULL)
621 rcparse_warning (_("control data requires DIALOGEX"));
622 $$->data = $11;
625 | CONTROL optresidc numexpr cnumexpr control_styleexpr cnumexpr
626 cnumexpr cnumexpr cnumexpr cnumexpr cnumexpr opt_control_data
628 $$ = define_control ($2, $3, $6, $7, $8, $9, $4, style, $10);
629 if (dialog.ex == NULL)
630 rcparse_warning (_("help ID requires DIALOGEX"));
631 $$->help = $11;
632 $$->data = $12;
634 | CONTROL optresidc numexpr ',' QUOTEDSTRING control_styleexpr
635 cnumexpr cnumexpr cnumexpr cnumexpr optcnumexpr opt_control_data
637 $$ = define_control ($2, $3, $7, $8, $9, $10, 0, style, $11);
638 if ($12 != NULL)
640 if (dialog.ex == NULL)
641 rcparse_warning ("control data requires DIALOGEX");
642 $$->data = $12;
644 $$->class.named = 1;
645 unicode_from_ascii (&$$->class.u.n.length, &$$->class.u.n.name, $5);
647 | CONTROL optresidc numexpr ',' QUOTEDSTRING control_styleexpr
648 cnumexpr cnumexpr cnumexpr cnumexpr cnumexpr cnumexpr opt_control_data
650 $$ = define_control ($2, $3, $7, $8, $9, $10, 0, style, $11);
651 if (dialog.ex == NULL)
652 rcparse_warning ("help ID requires DIALOGEX");
653 $$->help = $12;
654 $$->data = $13;
655 $$->class.named = 1;
656 unicode_from_ascii (&$$->class.u.n.length, &$$->class.u.n.name, $5);
658 | CTEXT optresidc
660 default_style = SS_CENTER | WS_GROUP;
661 base_style = SS_CENTER;
662 class = CTL_STATIC;
663 res_text_field = $2;
665 control_params
667 $$ = $4;
669 | DEFPUSHBUTTON optresidc
671 default_style = BS_DEFPUSHBUTTON | WS_TABSTOP;
672 base_style = BS_DEFPUSHBUTTON | WS_TABSTOP;
673 class = CTL_BUTTON;
674 res_text_field = $2;
676 control_params
678 $$ = $4;
680 | EDITTEXT
682 default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
683 base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
684 class = CTL_EDIT;
685 res_text_field = res_null_text;
687 control_params
689 $$ = $3;
691 | GROUPBOX optresidc
693 default_style = BS_GROUPBOX;
694 base_style = BS_GROUPBOX;
695 class = CTL_BUTTON;
696 res_text_field = $2;
698 control_params
700 $$ = $4;
702 | HEDIT optresidc
704 default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
705 base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
706 class = CTL_EDIT;
707 res_text_field = $2;
709 control_params
711 $$ = $4;
712 if (dialog.ex == NULL)
713 rcparse_warning (_("IEDIT requires DIALOGEX"));
714 res_string_to_id (&$$->class, "HEDIT");
716 | ICON resref numexpr cnumexpr cnumexpr opt_control_data
718 $$ = define_icon_control ($2, $3, $4, $5, 0, 0, 0, $6,
719 dialog.ex);
721 | ICON resref numexpr cnumexpr cnumexpr cnumexpr cnumexpr
722 opt_control_data
724 $$ = define_icon_control ($2, $3, $4, $5, 0, 0, 0, $8,
725 dialog.ex);
727 | ICON resref numexpr cnumexpr cnumexpr cnumexpr cnumexpr
728 icon_styleexpr optcnumexpr opt_control_data
730 $$ = define_icon_control ($2, $3, $4, $5, style, $9, 0, $10,
731 dialog.ex);
733 | ICON resref numexpr cnumexpr cnumexpr cnumexpr cnumexpr
734 icon_styleexpr cnumexpr cnumexpr opt_control_data
736 $$ = define_icon_control ($2, $3, $4, $5, style, $9, $10, $11,
737 dialog.ex);
739 | IEDIT optresidc
741 default_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
742 base_style = ES_LEFT | WS_BORDER | WS_TABSTOP;
743 class = CTL_EDIT;
744 res_text_field = $2;
746 control_params
748 $$ = $4;
749 if (dialog.ex == NULL)
750 rcparse_warning (_("IEDIT requires DIALOGEX"));
751 res_string_to_id (&$$->class, "IEDIT");
753 | LISTBOX
755 default_style = LBS_NOTIFY | WS_BORDER;
756 base_style = LBS_NOTIFY | WS_BORDER;
757 class = CTL_LISTBOX;
758 res_text_field = res_null_text;
760 control_params
762 $$ = $3;
764 | LTEXT optresidc
766 default_style = SS_LEFT | WS_GROUP;
767 base_style = SS_LEFT;
768 class = CTL_STATIC;
769 res_text_field = $2;
771 control_params
773 $$ = $4;
775 | PUSHBOX optresidc
777 default_style = BS_PUSHBOX | WS_TABSTOP;
778 base_style = BS_PUSHBOX;
779 class = CTL_BUTTON;
781 control_params
783 $$ = $4;
785 | PUSHBUTTON optresidc
787 default_style = BS_PUSHBUTTON | WS_TABSTOP;
788 base_style = BS_PUSHBUTTON | WS_TABSTOP;
789 class = CTL_BUTTON;
790 res_text_field = $2;
792 control_params
794 $$ = $4;
796 | RADIOBUTTON optresidc
798 default_style = BS_RADIOBUTTON | WS_TABSTOP;
799 base_style = BS_RADIOBUTTON;
800 class = CTL_BUTTON;
801 res_text_field = $2;
803 control_params
805 $$ = $4;
807 | RTEXT optresidc
809 default_style = SS_RIGHT | WS_GROUP;
810 base_style = SS_RIGHT;
811 class = CTL_STATIC;
812 res_text_field = $2;
814 control_params
816 $$ = $4;
818 | SCROLLBAR
820 default_style = SBS_HORZ;
821 base_style = 0;
822 class = CTL_SCROLLBAR;
823 res_text_field = res_null_text;
825 control_params
827 $$ = $3;
829 | STATE3 optresidc
831 default_style = BS_3STATE | WS_TABSTOP;
832 base_style = BS_3STATE;
833 class = CTL_BUTTON;
834 res_text_field = $2;
836 control_params
838 $$ = $4;
840 | USERBUTTON resref numexpr ',' numexpr ',' numexpr ','
841 numexpr ',' numexpr ','
842 { style = WS_CHILD | WS_VISIBLE; }
843 styleexpr optcnumexpr
845 $$ = define_control ($2, $3, $5, $7, $9, $11, CTL_BUTTON,
846 style, $15);
850 /* Parameters for a control. The static variables DEFAULT_STYLE,
851 BASE_STYLE, and CLASS must be initialized before this nonterminal
852 is used. DEFAULT_STYLE is the style to use if no style expression
853 is specified. BASE_STYLE is the base style to use if a style
854 expression is specified; the style expression modifies the base
855 style. CLASS is the class of the control. */
857 control_params:
858 numexpr cnumexpr cnumexpr cnumexpr cnumexpr opt_control_data
860 $$ = define_control (res_text_field, $1, $2, $3, $4, $5, class,
861 default_style | WS_CHILD | WS_VISIBLE, 0);
862 if ($6 != NULL)
864 if (dialog.ex == NULL)
865 rcparse_warning (_("control data requires DIALOGEX"));
866 $$->data = $6;
869 | numexpr cnumexpr cnumexpr cnumexpr cnumexpr
870 control_params_styleexpr optcnumexpr opt_control_data
872 $$ = define_control (res_text_field, $1, $2, $3, $4, $5, class, style, $7);
873 if ($8 != NULL)
875 if (dialog.ex == NULL)
876 rcparse_warning (_("control data requires DIALOGEX"));
877 $$->data = $8;
880 | numexpr cnumexpr cnumexpr cnumexpr cnumexpr
881 control_params_styleexpr cnumexpr cnumexpr opt_control_data
883 $$ = define_control (res_text_field, $1, $2, $3, $4, $5, class, style, $7);
884 if (dialog.ex == NULL)
885 rcparse_warning (_("help ID requires DIALOGEX"));
886 $$->help = $8;
887 $$->data = $9;
891 optresidc:
892 /* empty */
894 res_string_to_id (&$$, "");
896 | posnumexpr ','
898 $$.named = 0;
899 $$.u.id = $1;
901 | QUOTEDSTRING
903 res_string_to_id (&$$, $1);
905 | QUOTEDSTRING ','
907 res_string_to_id (&$$, $1);
911 opt_control_data:
912 /* empty */
914 $$ = NULL;
916 | BEG optrcdata_data END
918 $$ = $2.first;
922 /* These only exist to parse a reduction out of a common case. */
924 control_styleexpr:
926 { style = WS_CHILD | WS_VISIBLE; }
927 styleexpr
930 icon_styleexpr:
932 { style = SS_ICON | WS_CHILD | WS_VISIBLE; }
933 styleexpr
936 control_params_styleexpr:
938 { style = base_style | WS_CHILD | WS_VISIBLE; }
939 styleexpr
942 /* Font resources. */
944 font:
945 id FONT memflags_move_discard file_name
947 define_font ($1, &$3, $4);
948 if (yychar != YYEMPTY)
949 YYERROR;
950 rcparse_discard_strings ();
954 /* Icon resources. */
956 icon:
957 id ICON memflags_move_discard file_name
959 define_icon ($1, &$3, $4);
960 if (yychar != YYEMPTY)
961 YYERROR;
962 rcparse_discard_strings ();
966 /* Language command. This changes the static variable language, which
967 affects all subsequent resources. */
969 language:
970 LANGUAGE numexpr cnumexpr
972 language = $2 | ($3 << SUBLANG_SHIFT);
976 /* Menu resources. */
978 menu:
979 id MENU suboptions BEG menuitems END
981 define_menu ($1, &$3, $5);
982 if (yychar != YYEMPTY)
983 YYERROR;
984 rcparse_discard_strings ();
988 menuitems:
989 /* empty */
991 $$ = NULL;
993 | menuitems menuitem
995 if ($1 == NULL)
996 $$ = $2;
997 else
999 struct menuitem **pp;
1001 for (pp = &$1->next; *pp != NULL; pp = &(*pp)->next)
1003 *pp = $2;
1004 $$ = $1;
1009 menuitem:
1010 MENUITEM QUOTEDSTRING cnumexpr menuitem_flags
1012 $$ = define_menuitem ($2, $3, $4, 0, 0, NULL);
1014 | MENUITEM SEPARATOR
1016 $$ = define_menuitem (NULL, 0, 0, 0, 0, NULL);
1018 | POPUP QUOTEDSTRING menuitem_flags BEG menuitems END
1020 $$ = define_menuitem ($2, 0, $3, 0, 0, $5);
1024 menuitem_flags:
1025 /* empty */
1027 $$ = 0;
1029 | menuitem_flags ',' menuitem_flag
1031 $$ = $1 | $3;
1033 | menuitem_flags menuitem_flag
1035 $$ = $1 | $2;
1039 menuitem_flag:
1040 CHECKED
1042 $$ = MENUITEM_CHECKED;
1044 | GRAYED
1046 $$ = MENUITEM_GRAYED;
1048 | HELP
1050 $$ = MENUITEM_HELP;
1052 | INACTIVE
1054 $$ = MENUITEM_INACTIVE;
1056 | MENUBARBREAK
1058 $$ = MENUITEM_MENUBARBREAK;
1060 | MENUBREAK
1062 $$ = MENUITEM_MENUBREAK;
1066 /* Menuex resources. */
1068 menuex:
1069 id MENUEX suboptions BEG menuexitems END
1071 define_menu ($1, &$3, $5);
1072 if (yychar != YYEMPTY)
1073 YYERROR;
1074 rcparse_discard_strings ();
1078 menuexitems:
1079 /* empty */
1081 $$ = NULL;
1083 | menuexitems menuexitem
1085 if ($1 == NULL)
1086 $$ = $2;
1087 else
1089 struct menuitem **pp;
1091 for (pp = &$1->next; *pp != NULL; pp = &(*pp)->next)
1093 *pp = $2;
1094 $$ = $1;
1099 menuexitem:
1100 MENUITEM QUOTEDSTRING
1102 $$ = define_menuitem ($2, 0, 0, 0, 0, NULL);
1104 | MENUITEM QUOTEDSTRING cnumexpr
1106 $$ = define_menuitem ($2, $3, 0, 0, 0, NULL);
1108 | MENUITEM QUOTEDSTRING cnumexpr cnumexpr optcnumexpr
1110 $$ = define_menuitem ($2, $3, $4, $5, 0, NULL);
1112 | MENUITEM SEPARATOR
1114 $$ = define_menuitem (NULL, 0, 0, 0, 0, NULL);
1116 | POPUP QUOTEDSTRING BEG menuexitems END
1118 $$ = define_menuitem ($2, 0, 0, 0, 0, $4);
1120 | POPUP QUOTEDSTRING cnumexpr BEG menuexitems END
1122 $$ = define_menuitem ($2, $3, 0, 0, 0, $5);
1124 | POPUP QUOTEDSTRING cnumexpr cnumexpr BEG menuexitems END
1126 $$ = define_menuitem ($2, $3, $4, 0, 0, $6);
1128 | POPUP QUOTEDSTRING cnumexpr cnumexpr cnumexpr optcnumexpr
1129 BEG menuexitems END
1131 $$ = define_menuitem ($2, $3, $4, $5, $6, $8);
1135 /* Messagetable resources. */
1137 messagetable:
1138 id MESSAGETABLE memflags_move file_name
1140 define_messagetable ($1, &$3, $4);
1141 if (yychar != YYEMPTY)
1142 YYERROR;
1143 rcparse_discard_strings ();
1147 /* Rcdata resources. */
1149 rcdata:
1150 id RCDATA suboptions BEG optrcdata_data END
1152 define_rcdata ($1, &$3, $5.first);
1153 if (yychar != YYEMPTY)
1154 YYERROR;
1155 rcparse_discard_strings ();
1157 | id RCDATA suboptions file_name
1159 define_rcdata_file ($1, &$3, $4);
1160 if (yychar != YYEMPTY)
1161 YYERROR;
1162 rcparse_discard_strings ();
1166 /* We use a different lexing algorithm, because rcdata strings may
1167 contain embedded null bytes, and we need to know the length to use. */
1169 optrcdata_data:
1171 rcparse_rcdata ();
1173 optrcdata_data_int
1175 rcparse_normal ();
1176 $$ = $2;
1180 optrcdata_data_int:
1181 /* empty */
1183 $$.first = NULL;
1184 $$.last = NULL;
1186 | rcdata_data
1188 $$ = $1;
1192 rcdata_data:
1193 SIZEDSTRING
1195 struct rcdata_item *ri;
1197 ri = define_rcdata_string ($1.s, $1.length);
1198 $$.first = ri;
1199 $$.last = ri;
1201 | sizednumexpr
1203 struct rcdata_item *ri;
1205 ri = define_rcdata_number ($1.val, $1.dword);
1206 $$.first = ri;
1207 $$.last = ri;
1209 | rcdata_data ',' SIZEDSTRING
1211 struct rcdata_item *ri;
1213 ri = define_rcdata_string ($3.s, $3.length);
1214 $$.first = $1.first;
1215 $1.last->next = ri;
1216 $$.last = ri;
1218 | rcdata_data ',' sizednumexpr
1220 struct rcdata_item *ri;
1222 ri = define_rcdata_number ($3.val, $3.dword);
1223 $$.first = $1.first;
1224 $1.last->next = ri;
1225 $$.last = ri;
1229 /* Stringtable resources. */
1231 stringtable:
1232 STRINGTABLE suboptions BEG
1233 { sub_res_info = $2; }
1234 string_data END
1237 string_data:
1238 /* empty */
1239 | string_data numexpr QUOTEDSTRING
1241 define_stringtable (&sub_res_info, $2, $3);
1242 if (yychar != YYEMPTY)
1243 YYERROR;
1244 rcparse_discard_strings ();
1246 | string_data numexpr ',' QUOTEDSTRING
1248 define_stringtable (&sub_res_info, $2, $4);
1249 if (yychar != YYEMPTY)
1250 YYERROR;
1251 rcparse_discard_strings ();
1255 /* User defined resources. We accept general suboptions in the
1256 file_name case to keep the parser happy. */
1258 user:
1259 id id suboptions BEG optrcdata_data END
1261 define_user_data ($1, $2, &$3, $5.first);
1262 if (yychar != YYEMPTY)
1263 YYERROR;
1264 rcparse_discard_strings ();
1266 | id id suboptions file_name
1268 define_user_file ($1, $2, &$3, $4);
1269 if (yychar != YYEMPTY)
1270 YYERROR;
1271 rcparse_discard_strings ();
1275 /* Versioninfo resources. */
1277 versioninfo:
1278 id VERSIONINFO fixedverinfo BEG verblocks END
1280 define_versioninfo ($1, language, $3, $5);
1281 if (yychar != YYEMPTY)
1282 YYERROR;
1283 rcparse_discard_strings ();
1287 fixedverinfo:
1288 /* empty */
1290 $$ = ((struct fixed_versioninfo *)
1291 res_alloc (sizeof (struct fixed_versioninfo)));
1292 memset ($$, 0, sizeof (struct fixed_versioninfo));
1294 | fixedverinfo FILEVERSION numexpr cnumexpr cnumexpr cnumexpr
1296 $1->file_version_ms = ($3 << 16) | $4;
1297 $1->file_version_ls = ($5 << 16) | $6;
1298 $$ = $1;
1300 | fixedverinfo PRODUCTVERSION numexpr cnumexpr cnumexpr cnumexpr
1302 $1->product_version_ms = ($3 << 16) | $4;
1303 $1->product_version_ls = ($5 << 16) | $6;
1304 $$ = $1;
1306 | fixedverinfo FILEFLAGSMASK numexpr
1308 $1->file_flags_mask = $3;
1309 $$ = $1;
1311 | fixedverinfo FILEFLAGS numexpr
1313 $1->file_flags = $3;
1314 $$ = $1;
1316 | fixedverinfo FILEOS numexpr
1318 $1->file_os = $3;
1319 $$ = $1;
1321 | fixedverinfo FILETYPE numexpr
1323 $1->file_type = $3;
1324 $$ = $1;
1326 | fixedverinfo FILESUBTYPE numexpr
1328 $1->file_subtype = $3;
1329 $$ = $1;
1333 /* To handle verblocks successfully, the lexer handles BLOCK
1334 specially. A BLOCK "StringFileInfo" is returned as
1335 BLOCKSTRINGFILEINFO. A BLOCK "VarFileInfo" is returned as
1336 BLOCKVARFILEINFO. A BLOCK with some other string returns BLOCK
1337 with the string as the value. */
1339 verblocks:
1340 /* empty */
1342 $$ = NULL;
1344 | verblocks BLOCKSTRINGFILEINFO BEG BLOCK BEG vervals END END
1346 $$ = append_ver_stringfileinfo ($1, $4, $6);
1348 | verblocks BLOCKVARFILEINFO BEG VALUE QUOTEDSTRING vertrans END
1350 $$ = append_ver_varfileinfo ($1, $5, $6);
1354 vervals:
1355 /* empty */
1357 $$ = NULL;
1359 | vervals VALUE QUOTEDSTRING ',' QUOTEDSTRING
1361 $$ = append_verval ($1, $3, $5);
1365 vertrans:
1366 /* empty */
1368 $$ = NULL;
1370 | vertrans cnumexpr cnumexpr
1372 $$ = append_vertrans ($1, $2, $3);
1376 /* A resource ID. */
1379 posnumexpr
1381 $$.named = 0;
1382 $$.u.id = $1;
1384 | STRING
1386 char *copy, *s;
1388 /* It seems that resource ID's are forced to upper case. */
1389 copy = xstrdup ($1);
1390 for (s = copy; *s != '\0'; s++)
1391 *s = TOUPPER (*s);
1392 res_string_to_id (&$$, copy);
1393 free (copy);
1397 /* A resource reference. */
1399 resname:
1400 QUOTEDSTRING
1402 $$ = $1;
1404 | QUOTEDSTRING ','
1406 $$ = $1;
1408 | STRING ','
1410 $$ = $1;
1415 resref:
1416 posnumexpr ','
1418 $$.named = 0;
1419 $$.u.id = $1;
1421 | resname
1423 char *copy, *s;
1425 /* It seems that resource ID's are forced to upper case. */
1426 copy = xstrdup ($1);
1427 for (s = copy; *s != '\0'; s++)
1428 *s = TOUPPER (*s);
1429 res_string_to_id (&$$, copy);
1430 free (copy);
1434 /* Generic suboptions. These may appear before the BEGIN in any
1435 multiline statement. */
1437 suboptions:
1438 /* empty */
1440 memset (&$$, 0, sizeof (struct res_res_info));
1441 $$.language = language;
1442 /* FIXME: Is this the right default? */
1443 $$.memflags = MEMFLAG_MOVEABLE | MEMFLAG_PURE | MEMFLAG_DISCARDABLE;
1445 | suboptions memflag
1447 $$ = $1;
1448 $$.memflags |= $2.on;
1449 $$.memflags &=~ $2.off;
1451 | suboptions CHARACTERISTICS numexpr
1453 $$ = $1;
1454 $$.characteristics = $3;
1456 | suboptions LANGUAGE numexpr cnumexpr
1458 $$ = $1;
1459 $$.language = $3 | ($4 << SUBLANG_SHIFT);
1461 | suboptions VERSIONK numexpr
1463 $$ = $1;
1464 $$.version = $3;
1468 /* Memory flags which default to MOVEABLE and DISCARDABLE. */
1470 memflags_move_discard:
1471 /* empty */
1473 memset (&$$, 0, sizeof (struct res_res_info));
1474 $$.language = language;
1475 $$.memflags = MEMFLAG_MOVEABLE | MEMFLAG_DISCARDABLE;
1477 | memflags_move_discard memflag
1479 $$ = $1;
1480 $$.memflags |= $2.on;
1481 $$.memflags &=~ $2.off;
1485 /* Memory flags which default to MOVEABLE. */
1487 memflags_move:
1488 /* empty */
1490 memset (&$$, 0, sizeof (struct res_res_info));
1491 $$.language = language;
1492 $$.memflags = MEMFLAG_MOVEABLE | MEMFLAG_PURE | MEMFLAG_DISCARDABLE;
1494 | memflags_move memflag
1496 $$ = $1;
1497 $$.memflags |= $2.on;
1498 $$.memflags &=~ $2.off;
1502 /* Memory flags. This returns a struct with two integers, because we
1503 sometimes want to set bits and we sometimes want to clear them. */
1505 memflag:
1506 MOVEABLE
1508 $$.on = MEMFLAG_MOVEABLE;
1509 $$.off = 0;
1511 | FIXED
1513 $$.on = 0;
1514 $$.off = MEMFLAG_MOVEABLE;
1516 | PURE
1518 $$.on = MEMFLAG_PURE;
1519 $$.off = 0;
1521 | IMPURE
1523 $$.on = 0;
1524 $$.off = MEMFLAG_PURE;
1526 | PRELOAD
1528 $$.on = MEMFLAG_PRELOAD;
1529 $$.off = 0;
1531 | LOADONCALL
1533 $$.on = 0;
1534 $$.off = MEMFLAG_PRELOAD;
1536 | DISCARDABLE
1538 $$.on = MEMFLAG_DISCARDABLE;
1539 $$.off = 0;
1543 /* A file name. */
1545 file_name:
1546 QUOTEDSTRING
1548 $$ = $1;
1550 | STRING
1552 $$ = $1;
1556 /* A style expression. This changes the static variable STYLE. We do
1557 it this way because rc appears to permit a style to be set to
1558 something like
1559 WS_GROUP | NOT WS_TABSTOP
1560 to mean that a default of WS_TABSTOP should be removed. Anything
1561 which wants to accept a style must first set STYLE to the default
1562 value. The styleexpr nonterminal will change STYLE as specified by
1563 the user. Note that we do not accept arbitrary expressions here,
1564 just numbers separated by '|'. */
1566 styleexpr:
1567 parennumber
1569 style |= $1;
1571 | NOT parennumber
1573 style &=~ $2;
1575 | styleexpr '|' parennumber
1577 style |= $3;
1579 | styleexpr '|' NOT parennumber
1581 style &=~ $4;
1585 parennumber:
1586 NUMBER
1588 $$ = $1.val;
1590 | '(' numexpr ')'
1592 $$ = $2;
1596 /* An optional expression with a leading comma. */
1598 optcnumexpr:
1599 /* empty */
1601 $$ = 0;
1603 | cnumexpr
1605 $$ = $1;
1609 /* An expression with a leading comma. */
1611 cnumexpr:
1612 ',' numexpr
1614 $$ = $2;
1618 /* A possibly negated numeric expression. */
1620 numexpr:
1621 sizednumexpr
1623 $$ = $1.val;
1627 /* A possibly negated expression with a size. */
1629 sizednumexpr:
1630 NUMBER
1632 $$ = $1;
1634 | '(' sizednumexpr ')'
1636 $$ = $2;
1638 | '~' sizednumexpr %prec '~'
1640 $$.val = ~ $2.val;
1641 $$.dword = $2.dword;
1643 | '-' sizednumexpr %prec NEG
1645 $$.val = - $2.val;
1646 $$.dword = $2.dword;
1648 | sizednumexpr '*' sizednumexpr
1650 $$.val = $1.val * $3.val;
1651 $$.dword = $1.dword || $3.dword;
1653 | sizednumexpr '/' sizednumexpr
1655 $$.val = $1.val / $3.val;
1656 $$.dword = $1.dword || $3.dword;
1658 | sizednumexpr '%' sizednumexpr
1660 $$.val = $1.val % $3.val;
1661 $$.dword = $1.dword || $3.dword;
1663 | sizednumexpr '+' sizednumexpr
1665 $$.val = $1.val + $3.val;
1666 $$.dword = $1.dword || $3.dword;
1668 | sizednumexpr '-' sizednumexpr
1670 $$.val = $1.val - $3.val;
1671 $$.dword = $1.dword || $3.dword;
1673 | sizednumexpr '&' sizednumexpr
1675 $$.val = $1.val & $3.val;
1676 $$.dword = $1.dword || $3.dword;
1678 | sizednumexpr '^' sizednumexpr
1680 $$.val = $1.val ^ $3.val;
1681 $$.dword = $1.dword || $3.dword;
1683 | sizednumexpr '|' sizednumexpr
1685 $$.val = $1.val | $3.val;
1686 $$.dword = $1.dword || $3.dword;
1690 /* An expression with a leading comma which does not use unary
1691 negation. */
1693 cposnumexpr:
1694 ',' posnumexpr
1696 $$ = $2;
1700 /* An expression which does not use unary negation. */
1702 posnumexpr:
1703 sizedposnumexpr
1705 $$ = $1.val;
1709 /* An expression which does not use unary negation. We separate unary
1710 negation to avoid parsing conflicts when two numeric expressions
1711 appear consecutively. */
1713 sizedposnumexpr:
1714 NUMBER
1716 $$ = $1;
1718 | '(' sizednumexpr ')'
1720 $$ = $2;
1722 | '~' sizednumexpr %prec '~'
1724 $$.val = ~ $2.val;
1725 $$.dword = $2.dword;
1727 | sizedposnumexpr '*' sizednumexpr
1729 $$.val = $1.val * $3.val;
1730 $$.dword = $1.dword || $3.dword;
1732 | sizedposnumexpr '/' sizednumexpr
1734 $$.val = $1.val / $3.val;
1735 $$.dword = $1.dword || $3.dword;
1737 | sizedposnumexpr '%' sizednumexpr
1739 $$.val = $1.val % $3.val;
1740 $$.dword = $1.dword || $3.dword;
1742 | sizedposnumexpr '+' sizednumexpr
1744 $$.val = $1.val + $3.val;
1745 $$.dword = $1.dword || $3.dword;
1747 | sizedposnumexpr '-' sizednumexpr
1749 $$.val = $1.val - $3.val;
1750 $$.dword = $1.dword || $3.dword;
1752 | sizedposnumexpr '&' sizednumexpr
1754 $$.val = $1.val & $3.val;
1755 $$.dword = $1.dword || $3.dword;
1757 | sizedposnumexpr '^' sizednumexpr
1759 $$.val = $1.val ^ $3.val;
1760 $$.dword = $1.dword || $3.dword;
1762 | sizedposnumexpr '|' sizednumexpr
1764 $$.val = $1.val | $3.val;
1765 $$.dword = $1.dword || $3.dword;
1771 /* Set the language from the command line. */
1773 void
1774 rcparse_set_language (int lang)
1776 language = lang;