Release 970305
[wine/multimedia.git] / rc / parser.y
blobbbf38fa7979681ca892153163fd14981c5e54244
1 %{
2 /*
4 * Copyright Martin von Loewis, 1994
5 */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include "parser.h"
10 #include "windows.h"
12 int yylex(void);
13 int yyerror(const char *s);
16 %union{
17 gen_res *res;
18 char *str;
19 int num;
20 struct rc_style *style;
22 %token <num> NUMBER
23 %token <str> tSTRING SINGLE_QUOTED IDENT
24 %token ACCELERATORS ALT ASCII tBEGIN tBITMAP CAPTION CHECKBOX CHECKED
25 %token CLASS COMBOBOX CONTROL CTEXT CURSOR DEFPUSHBUTTON DIALOG
26 %token DISCARDABLE EDITTEXT tEND tFIXED FONT GRAYED GROUPBOX HELP ICON
27 %token IDENT INACTIVE LISTBOX LTEXT MENU MENUBARBREAK MENUBREAK MENUITEM
28 %token MOVEABLE LOADONCALL NOINVERT NOT NOT_SUPPORTED POPUP PRELOAD
29 %token PURE PUSHBUTTON RADIOBUTTON RCDATA RTEXT SCROLLBAR SHIFT SEPARATOR
30 %token SINGLE_QUOTED tSTRING STRINGTABLE STYLE VERSIONINFO VIRTKEY
31 %type <res> resource_file resource resources resource_definition accelerators
32 %type <res> events bitmap cursor dialog dlg_attributes controls
33 %type <res> generic_control labeled_control control_desc font icon
34 %type <res> iconinfo menu menu_body item_definitions rcdata raw_data raw_elements
35 %type <res> stringtable strings versioninfo
36 %type <num> acc_options item_options
37 %type <style> style style_elm optional_style
40 resource_file: resources {create_output($1);}
42 /*resources are put into a linked list*/
43 resources: {$$=0;}
44 |resource resources {$$=add_resource($1,$2);}
47 /* get the name for a single resource*/
48 resource: NUMBER resource_definition
49 {$$=$2;$$->n.i_name=$1;$$->n_type=0;
50 if(verbose)fprintf(stderr,"Got %s %d\n",get_typename($2),$1);
52 | IDENT resource_definition
53 {$$=$2;$$->n.s_name=$1;$$->n_type=1;
54 if(verbose)fprintf(stderr,"Got %s %s\n",get_typename($2),$1);
56 | stringtable
57 {$$=$1; /* <-- should be NULL */
58 if(verbose)fprintf(stderr,"Got STRINGTABLE\n");
62 /* get the value for a single resource*/
63 resource_definition: accelerators {$$=$1;}
64 | bitmap {$$=$1;}
65 | cursor {$$=$1;}
66 | dialog {$$=$1;}
67 | font {$$=$1;}
68 | icon {$$=$1;}
69 | menu {$$=$1;}
70 | rcdata {$$=$1;}
71 | versioninfo {$$=$1;}
74 /* have to use tBEGIN because BEGIN is predefined */
75 accelerators: ACCELERATORS tBEGIN events tEND {$$=$3;$$->type=acc;}
76 /* the events are collected in a gen_res, as the accelerator resource is just
77 an array of events */
78 events: {$$=new_res();}
79 | tSTRING ',' NUMBER acc_options events
80 {$$=add_string_accelerator($1,$3,$4,$5);}
81 | NUMBER ',' NUMBER ',' ASCII acc_options events
82 {$$=add_ascii_accelerator($1,$3,$6,$7);}
83 | NUMBER ',' NUMBER ',' VIRTKEY acc_options events
84 {$$=add_vk_accelerator($1,$3,$6,$7);}
85 acc_options: {$$=0;}
86 | ',' NOINVERT acc_options {$$=$3|2;}
87 | ',' ALT acc_options {$$=$3|16;}
88 | ',' SHIFT acc_options {$$=$3|4;}
89 | ',' CONTROL acc_options {$$=$3|8;}
91 bitmap: tBITMAP load_and_memoption tSTRING {$$=make_bitmap(load_file($3));}
92 | tBITMAP load_and_memoption raw_data {$$=make_bitmap($3);}
94 /* load and memory options are ignored */
95 load_and_memoption: | lamo load_and_memoption
96 lamo: PRELOAD | LOADONCALL | tFIXED | MOVEABLE | DISCARDABLE | PURE
98 cursor: CURSOR load_and_memoption tSTRING {$$=make_cursor(load_file($3));}
99 |CURSOR load_and_memoption raw_data {$$=make_cursor($3);}
101 dialog: DIALOG load_and_memoption NUMBER ',' NUMBER ',' NUMBER ',' NUMBER
102 dlg_attributes
103 tBEGIN controls tEND
104 {$$=make_dialog($10,$3,$5,$7,$9,$12);}
106 dlg_attributes: {$$=new_dialog();}
107 | STYLE style dlg_attributes
108 {$$=dialog_style($2,$3);}
109 | CAPTION tSTRING dlg_attributes
110 {$$=dialog_caption($2,$3);}
111 | FONT NUMBER ',' tSTRING dlg_attributes
112 {$$=dialog_font($2,$4,$5);}
113 | CLASS tSTRING dlg_attributes
114 {$$=dialog_class($2,$3);}
115 | MENU tSTRING dlg_attributes
116 {$$=dialog_menu($2,$3);}
118 /* the controls are collected into a gen_res, and finally the dialog header
119 is put at the beginning */
120 controls: {$$=new_res();}
121 | CHECKBOX labeled_control controls
122 {$$=add_control(CT_BUTTON, BS_CHECKBOX, $2, $3);}
123 | COMBOBOX control_desc controls
124 {$$=add_control(CT_COMBOBOX, 0, $2, $3);}
125 | CONTROL generic_control controls
126 {$$=add_generic_control($2, $3);}
127 | CTEXT labeled_control controls
128 {$$=add_control(CT_STATIC, SS_CENTER, $2, $3);}
129 | DEFPUSHBUTTON labeled_control controls
130 {$$=add_control(CT_BUTTON, BS_DEFPUSHBUTTON, $2, $3);}
131 | EDITTEXT control_desc controls
132 {$$=add_control(CT_EDIT, 0, $2, $3);}
133 | GROUPBOX labeled_control controls
134 {$$=add_control(CT_BUTTON, BS_GROUPBOX, $2, $3);}
135 /*special treatment for icons, as the extent is optional*/
136 | ICON tSTRING ',' NUMBER ',' NUMBER ',' NUMBER iconinfo controls
137 {$$=add_icon($2, $4, $6, $8, $9, $10);}
138 | LISTBOX control_desc controls
139 {$$=add_control(CT_LISTBOX, 0, $2, $3);}
140 | LTEXT labeled_control controls
141 {$$=add_control(CT_STATIC, SS_LEFT, $2, $3);}
142 | PUSHBUTTON labeled_control controls
143 {$$=add_control(CT_BUTTON, BS_PUSHBUTTON, $2, $3);}
144 | RADIOBUTTON labeled_control controls
145 {$$=add_control(CT_BUTTON, BS_RADIOBUTTON, $2, $3);}
146 | RTEXT labeled_control controls
147 {$$=add_control(CT_STATIC, SS_RIGHT, $2, $3);}
148 | SCROLLBAR control_desc controls
149 {$$=add_control(CT_SCROLLBAR, 0, $2, $3);}
152 labeled_control: tSTRING ',' control_desc {$$=label_control_desc($1,$3);}
153 control_desc: NUMBER ',' NUMBER ',' NUMBER ',' NUMBER ',' NUMBER optional_style
154 {$$=create_control_desc($1,$3,$5,$7,$9,$10);}
156 optional_style: {$$=0;}|
157 ',' style {$$=$2;}
159 iconinfo: /*set extent and style to 0 if they are not provided */
160 {$$=create_control_desc(0,0,0,0,0,0);}
161 /* x and y are overwritten later */
162 | ',' NUMBER ',' NUMBER optional_style
163 {$$=create_control_desc(0,0,0,$2,$4,$5);}
165 generic_control: tSTRING ',' NUMBER ',' tSTRING ',' style ',' NUMBER
166 ',' NUMBER ',' NUMBER ',' NUMBER
167 {$$=create_generic_control($1,$3,$5,$7,$9,$11,$13,$15);}
169 font: FONT load_and_memoption tSTRING {$$=make_font(load_file($3));}
171 icon: ICON load_and_memoption tSTRING {$$=make_icon(load_file($3));}
172 | ICON load_and_memoption raw_data {$$=make_icon($3);}
174 menu: MENU load_and_memoption menu_body {$$=make_menu($3);}
175 /* menu items are collected in a gen_res and prefixed with the menu header*/
176 menu_body: tBEGIN item_definitions tEND {$$=$2;}
177 item_definitions: {$$=new_res();}
178 | MENUITEM tSTRING ',' NUMBER item_options item_definitions
179 {$$=add_menuitem($2,$4,$5,$6);}
180 | MENUITEM SEPARATOR item_definitions
181 {$$=add_menuitem("",0,0,$3);}
182 | POPUP tSTRING item_options menu_body item_definitions
183 {$$=add_popup($2,$3,$4,$5);}
184 item_options: {$$=0;}
185 | ',' CHECKED item_options {$$=$3|MF_CHECKED;}
186 | ',' GRAYED item_options {$$=$3|MF_GRAYED;}
187 | ',' HELP item_options {$$=$3|MF_HELP;}
188 | ',' INACTIVE item_options {$$=$3|MF_DISABLED;}
189 | ',' MENUBARBREAK item_options {$$=$3|MF_MENUBARBREAK;}
190 | ',' MENUBREAK item_options {$$=$3|MF_MENUBREAK;}
192 rcdata: RCDATA load_and_memoption raw_data {$$=make_raw($3);}
194 raw_data: tBEGIN raw_elements tEND {$$=$2;}
195 raw_elements: SINGLE_QUOTED {$$=hex_to_raw($1,new_res());}
196 | NUMBER {$$=int_to_raw($1,new_res());}
197 | SINGLE_QUOTED raw_elements {$$=hex_to_raw($1,$2);}
198 | NUMBER ',' raw_elements {$$=int_to_raw($1,$3);}
200 stringtable: STRINGTABLE load_and_memoption tBEGIN strings tEND
201 {$$=$4;}
202 strings: {$$=0;}|
203 NUMBER tSTRING strings {$$=0;add_str_tbl_elm($1,$2);}
205 versioninfo: VERSIONINFO NOT_SUPPORTED {$$=0;}
207 /* NOT x | NOT y | a | b means (a|b)& ~x & ~y
208 NOT is used to disable default styles */
209 style: {$$=new_style();}
210 | style_elm {$$=$1;}
211 | style_elm '|' style
212 {$$=$1;$$->or|=$3->or;$$->and&=$3->and;free($3);}
214 style_elm: NUMBER {$$=new_style();$$->or=$1;}
215 | NOT NUMBER {$$=new_style();$$->and=~($2);}
216 | '(' style ')' {$$=$2;}
218 extern int line_number;
219 extern char* yytext;
221 int yyerror( const char *s )
223 fprintf(stderr,"stdin:%d: %s before '%s'\n",line_number,s,yytext);
224 return 0;