PageRenderTime 66ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/wine-1.5.9/tools/wrc/parser.y

#
Happy | 2919 lines | 2705 code | 214 blank | 0 comment | 0 complexity | e6b64cf0b29f7aaa3452c9887af5332e MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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. #include <stdio.h>
  126. #include <stdlib.h>
  127. #include <stdarg.h>
  128. #include <assert.h>
  129. #include <ctype.h>
  130. #include <string.h>
  131. #include "wrc.h"
  132. #include "utils.h"
  133. #include "newstruc.h"
  134. #include "dumpres.h"
  135. #include "wine/wpp.h"
  136. #include "wine/unicode.h"
  137. #include "parser.h"
  138. #include "windef.h"
  139. #include "winbase.h"
  140. #include "wingdi.h"
  141. #include "winuser.h"
  142. #if defined(YYBYACC)
  143. /* Berkeley yacc (byacc) doesn't seem to know about these */
  144. /* Some *BSD supplied versions do define these though */
  145. # ifndef YYEMPTY
  146. # define YYEMPTY (-1) /* Empty lookahead value of yychar */
  147. # endif
  148. # ifndef YYLEX
  149. # define YYLEX yylex()
  150. # endif
  151. #elif defined(YYBISON)
  152. /* Bison was used for original development */
  153. /* #define YYEMPTY -2 */
  154. /* #define YYLEX yylex() */
  155. #else
  156. /* No yacc we know yet */
  157. # if !defined(YYEMPTY) || !defined(YYLEX)
  158. # error Yacc version/type unknown. This version needs to be verified for settings of YYEMPTY and YYLEX.
  159. # elif defined(__GNUC__) /* gcc defines the #warning directive */
  160. # warning Yacc version/type unknown. It defines YYEMPTY and YYLEX, but is not tested
  161. /* #else we just take a chance that it works... */
  162. # endif
  163. #endif
  164. int want_nl = 0; /* Signal flex that we need the next newline */
  165. int want_id = 0; /* Signal flex that we need the next identifier */
  166. static stringtable_t *tagstt; /* Stringtable tag.
  167. * It is set while parsing a stringtable to one of
  168. * the stringtables in the sttres list or a new one
  169. * if the language was not parsed before.
  170. */
  171. static stringtable_t *sttres; /* Stringtable resources. This holds the list of
  172. * stringtables with different lanuages
  173. */
  174. static int dont_want_id = 0; /* See language parsing for details */
  175. /* Set to the current options of the currently scanning stringtable */
  176. static int *tagstt_memopt;
  177. static characts_t *tagstt_characts;
  178. static version_t *tagstt_version;
  179. static const char riff[4] = "RIFF"; /* RIFF file magic for animated cursor/icon */
  180. /* Prototypes of here defined functions */
  181. static event_t *get_event_head(event_t *p);
  182. static control_t *get_control_head(control_t *p);
  183. static ver_value_t *get_ver_value_head(ver_value_t *p);
  184. static ver_block_t *get_ver_block_head(ver_block_t *p);
  185. static resource_t *get_resource_head(resource_t *p);
  186. static menu_item_t *get_item_head(menu_item_t *p);
  187. static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str);
  188. static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i);
  189. static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i);
  190. static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2);
  191. static raw_data_t *str2raw_data(string_t *str);
  192. static raw_data_t *int2raw_data(int i);
  193. static raw_data_t *long2raw_data(int i);
  194. static raw_data_t *load_file(string_t *name, language_t *lang);
  195. static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid);
  196. static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev);
  197. static event_t *add_event(int key, int id, int flags, event_t *prev);
  198. static name_id_t *convert_ctlclass(name_id_t *cls);
  199. static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev);
  200. static dialog_t *dialog_version(version_t *v, dialog_t *dlg);
  201. static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg);
  202. static dialog_t *dialog_language(language_t *l, dialog_t *dlg);
  203. static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg);
  204. static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg);
  205. static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg);
  206. static dialog_t *dialog_caption(string_t *s, dialog_t *dlg);
  207. static dialog_t *dialog_exstyle(style_t * st, dialog_t *dlg);
  208. static dialog_t *dialog_style(style_t * st, dialog_t *dlg);
  209. static resource_t *build_stt_resources(stringtable_t *stthead);
  210. static stringtable_t *find_stringtable(lvc_t *lvc);
  211. static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec);
  212. static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems);
  213. static string_t *make_filename(string_t *s);
  214. static resource_t *build_fontdirs(resource_t *tail);
  215. static resource_t *build_fontdir(resource_t **fnt, int nfnt);
  216. static int rsrcid_to_token(int lookahead);
  217. %}
  218. %union{
  219. string_t *str;
  220. int num;
  221. int *iptr;
  222. char *cptr;
  223. resource_t *res;
  224. accelerator_t *acc;
  225. bitmap_t *bmp;
  226. dialog_t *dlg;
  227. font_t *fnt;
  228. fontdir_t *fnd;
  229. menu_t *men;
  230. html_t *html;
  231. rcdata_t *rdt;
  232. stringtable_t *stt;
  233. stt_entry_t *stte;
  234. user_t *usr;
  235. messagetable_t *msg;
  236. versioninfo_t *veri;
  237. control_t *ctl;
  238. name_id_t *nid;
  239. font_id_t *fntid;
  240. language_t *lan;
  241. version_t *ver;
  242. characts_t *chars;
  243. event_t *event;
  244. menu_item_t *menitm;
  245. itemex_opt_t *exopt;
  246. raw_data_t *raw;
  247. lvc_t *lvc;
  248. ver_value_t *val;
  249. ver_block_t *blk;
  250. ver_words_t *verw;
  251. toolbar_t *tlbar;
  252. toolbar_item_t *tlbarItems;
  253. dlginit_t *dginit;
  254. style_pair_t *styles;
  255. style_t *style;
  256. ani_any_t *ani;
  257. }
  258. %token tNL
  259. %token <num> tNUMBER tLNUMBER
  260. %token <str> tSTRING tIDENT tFILENAME
  261. %token <raw> tRAWDATA
  262. %token tACCELERATORS tBITMAP tCURSOR tDIALOG tDIALOGEX tMENU tMENUEX tMESSAGETABLE
  263. %token tRCDATA tVERSIONINFO tSTRINGTABLE tFONT tFONTDIR tICON tHTML
  264. %token tAUTO3STATE tAUTOCHECKBOX tAUTORADIOBUTTON tCHECKBOX tDEFPUSHBUTTON
  265. %token tPUSHBUTTON tRADIOBUTTON tSTATE3 /* PUSHBOX */
  266. %token tGROUPBOX tCOMBOBOX tLISTBOX tSCROLLBAR
  267. %token tCONTROL tEDITTEXT
  268. %token tRTEXT tCTEXT tLTEXT
  269. %token tBLOCK tVALUE
  270. %token tSHIFT tALT tASCII tVIRTKEY tGRAYED tCHECKED tINACTIVE tNOINVERT
  271. %token tPURE tIMPURE tDISCARDABLE tLOADONCALL tPRELOAD tFIXED tMOVEABLE
  272. %token tCLASS tCAPTION tCHARACTERISTICS tEXSTYLE tSTYLE tVERSION tLANGUAGE
  273. %token tFILEVERSION tPRODUCTVERSION tFILEFLAGSMASK tFILEOS tFILETYPE tFILEFLAGS tFILESUBTYPE
  274. %token tMENUBARBREAK tMENUBREAK tMENUITEM tPOPUP tSEPARATOR
  275. %token tHELP
  276. %token tTOOLBAR tBUTTON
  277. %token tBEGIN tEND
  278. %token tDLGINIT
  279. %left '|'
  280. %left '^'
  281. %left '&'
  282. %left '+' '-'
  283. %left '*' '/'
  284. %right '~' tNOT
  285. %left pUPM
  286. %type <res> resource_file resource resources resource_definition
  287. %type <stt> stringtable strings
  288. %type <fnt> font
  289. %type <fnd> fontdir
  290. %type <acc> accelerators
  291. %type <event> events
  292. %type <bmp> bitmap
  293. %type <ani> cursor icon
  294. %type <dlg> dialog dlg_attributes dialogex dlgex_attribs
  295. %type <ctl> ctrls gen_ctrl lab_ctrl ctrl_desc iconinfo
  296. %type <iptr> helpid
  297. %type <ctl> exctrls gen_exctrl lab_exctrl exctrl_desc
  298. %type <html> html
  299. %type <rdt> rcdata
  300. %type <raw> raw_data raw_elements opt_data file_raw
  301. %type <veri> versioninfo fix_version
  302. %type <verw> ver_words
  303. %type <blk> ver_blocks ver_block
  304. %type <val> ver_values ver_value
  305. %type <men> menu menuex
  306. %type <menitm> item_definitions menu_body itemex_definitions menuex_body
  307. %type <exopt> itemex_p_options itemex_options
  308. %type <msg> messagetable
  309. %type <usr> userres
  310. %type <num> item_options
  311. %type <nid> nameid nameid_s ctlclass usertype
  312. %type <num> acc_opt acc accs
  313. %type <iptr> loadmemopts lamo lama
  314. %type <fntid> opt_font opt_exfont opt_expr
  315. %type <lvc> opt_lvc
  316. %type <lan> opt_language
  317. %type <chars> opt_characts
  318. %type <ver> opt_version
  319. %type <num> expr xpr
  320. %type <iptr> e_expr
  321. %type <tlbar> toolbar
  322. %type <tlbarItems> toolbar_items
  323. %type <dginit> dlginit
  324. %type <styles> optional_style_pair
  325. %type <num> any_num
  326. %type <style> style
  327. %type <str> filename
  328. %%
  329. resource_file
  330. : resources {
  331. resource_t *rsc, *head;
  332. /* First add stringtables to the resource-list */
  333. rsc = build_stt_resources(sttres);
  334. /* 'build_stt_resources' returns a head and $1 is a tail */
  335. if($1)
  336. {
  337. $1->next = rsc;
  338. if(rsc)
  339. rsc->prev = $1;
  340. }
  341. else
  342. $1 = rsc;
  343. /* Find the tail again */
  344. while($1 && $1->next)
  345. $1 = $1->next;
  346. /* Now add any fontdirecory */
  347. rsc = build_fontdirs($1);
  348. /* 'build_fontdir' returns a head and $1 is a tail */
  349. if($1)
  350. {
  351. $1->next = rsc;
  352. if(rsc)
  353. rsc->prev = $1;
  354. }
  355. else
  356. $1 = rsc;
  357. /* Final statements before we're done */
  358. if ((head = get_resource_head($1)) != NULL)
  359. {
  360. if (resource_top) /* append to existing resources */
  361. {
  362. resource_t *tail = resource_top;
  363. while (tail->next) tail = tail->next;
  364. tail->next = head;
  365. head->prev = tail;
  366. }
  367. else resource_top = head;
  368. }
  369. sttres = NULL;
  370. }
  371. ;
  372. /* Resources are put into a linked list */
  373. resources
  374. : /* Empty */ { $$ = NULL; want_id = 1; }
  375. | resources resource {
  376. if($2)
  377. {
  378. resource_t *tail = $2;
  379. resource_t *head = $2;
  380. while(tail->next)
  381. tail = tail->next;
  382. while(head->prev)
  383. head = head->prev;
  384. head->prev = $1;
  385. if($1)
  386. $1->next = head;
  387. $$ = tail;
  388. /* Check for duplicate identifiers */
  389. while($1 && head)
  390. {
  391. resource_t *rsc = $1;
  392. while(rsc)
  393. {
  394. if(rsc->type == head->type
  395. && rsc->lan->id == head->lan->id
  396. && rsc->lan->sub == head->lan->sub
  397. && !compare_name_id(rsc->name, head->name)
  398. && (rsc->type != res_usr || !compare_name_id(rsc->res.usr->type,head->res.usr->type)))
  399. {
  400. yyerror("Duplicate resource name '%s'", get_nameid_str(rsc->name));
  401. }
  402. rsc = rsc->prev;
  403. }
  404. head = head->next;
  405. }
  406. }
  407. else if($1)
  408. {
  409. resource_t *tail = $1;
  410. while(tail->next)
  411. tail = tail->next;
  412. $$ = tail;
  413. }
  414. else
  415. $$ = NULL;
  416. if(!dont_want_id) /* See comments in language parsing below */
  417. want_id = 1;
  418. dont_want_id = 0;
  419. }
  420. /*
  421. * The following newline rule will never get reduced because we never
  422. * get the tNL token, unless we explicitly set the 'want_nl'
  423. * flag, which we don't.
  424. * The *ONLY* reason for this to be here is because Berkeley
  425. * yacc (byacc), at least version 1.9, has a bug.
  426. * (identified in the generated parser on the second
  427. * line with:
  428. * static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
  429. * )
  430. * This extra rule fixes it.
  431. * The problem is that the expression handling rule "expr: xpr"
  432. * is not reduced on non-terminal tokens, defined above in the
  433. * %token declarations. Token tNL is the only non-terminal that
  434. * can occur. The error becomes visible in the language parsing
  435. * rule below, which looks at the look-ahead token and tests it
  436. * for tNL. However, byacc already generates an error upon reading
  437. * the token instead of keeping it as a lookahead. The reason
  438. * lies in the lack of a $default transition in the "expr : xpr . "
  439. * state (currently state 25). It is probably omitted because tNL
  440. * is a non-terminal and the state contains 2 s/r conflicts. The
  441. * state enumerates all possible transitions instead of using a
  442. * $default transition.
  443. * All in all, it is a bug in byacc. (period)
  444. */
  445. | resources tNL
  446. ;
  447. /* Parse top level resource definitions etc. */
  448. resource
  449. : expr usrcvt resource_definition {
  450. $$ = $3;
  451. if($$)
  452. {
  453. if($1 > 65535 || $1 < -32768)
  454. yyerror("Resource's ID out of range (%d)", $1);
  455. $$->name = new_name_id();
  456. $$->name->type = name_ord;
  457. $$->name->name.i_name = $1;
  458. chat("Got %s (%d)\n", get_typename($3), $$->name->name.i_name);
  459. }
  460. }
  461. | tIDENT usrcvt resource_definition {
  462. $$ = $3;
  463. if($$)
  464. {
  465. $$->name = new_name_id();
  466. $$->name->type = name_str;
  467. $$->name->name.s_name = $1;
  468. chat("Got %s (%s)\n", get_typename($3), $$->name->name.s_name->str.cstr);
  469. }
  470. }
  471. | stringtable {
  472. /* Don't do anything, stringtables are converted to
  473. * resource_t structures when we are finished parsing and
  474. * the final rule of the parser is reduced (see above)
  475. */
  476. $$ = NULL;
  477. chat("Got STRINGTABLE\n");
  478. }
  479. | tLANGUAGE {want_nl = 1; } expr ',' expr {
  480. /* We *NEED* the newline to delimit the expression.
  481. * Otherwise, we would not be able to set the next
  482. * want_id anymore because of the token-lookahead.
  483. *
  484. * However, we can test the lookahead-token for
  485. * being "non-expression" type, in which case we
  486. * continue. Fortunately, tNL is the only token that
  487. * will break expression parsing and is implicitly
  488. * void, so we just remove it. This scheme makes it
  489. * possible to do some (not all) fancy preprocessor
  490. * stuff.
  491. * BTW, we also need to make sure that the next
  492. * reduction of 'resources' above will *not* set
  493. * want_id because we already have a lookahead that
  494. * cannot be undone.
  495. */
  496. if(yychar != YYEMPTY && yychar != tNL)
  497. dont_want_id = 1;
  498. if(yychar == tNL)
  499. yychar = YYEMPTY; /* Could use 'yyclearin', but we already need the*/
  500. /* direct access to yychar in rule 'usrcvt' below. */
  501. else if(yychar == tIDENT)
  502. parser_warning("LANGUAGE statement not delimited with newline; next identifier might be wrong\n");
  503. want_nl = 0; /* We don't want it anymore if we didn't get it */
  504. if(!win32)
  505. parser_warning("LANGUAGE not supported in 16-bit mode\n");
  506. free(currentlanguage);
  507. if (get_language_codepage($3, $5) == -1)
  508. yyerror( "Language %04x is not supported", ($5<<10) + $3);
  509. currentlanguage = new_language($3, $5);
  510. $$ = NULL;
  511. chat("Got LANGUAGE %d,%d (0x%04x)\n", $3, $5, ($5<<10) + $3);
  512. }
  513. ;
  514. /*
  515. * Remapping of numerical resource types
  516. * (see also comment of called function below)
  517. */
  518. usrcvt : /* Empty */ { yychar = rsrcid_to_token(yychar); }
  519. ;
  520. /*
  521. * Get a valid name/id
  522. */
  523. nameid : expr {
  524. if($1 > 65535 || $1 < -32768)
  525. yyerror("Resource's ID out of range (%d)", $1);
  526. $$ = new_name_id();
  527. $$->type = name_ord;
  528. $$->name.i_name = $1;
  529. }
  530. | tIDENT {
  531. $$ = new_name_id();
  532. $$->type = name_str;
  533. $$->name.s_name = $1;
  534. }
  535. ;
  536. /*
  537. * Extra string recognition for CLASS statement in dialogs
  538. */
  539. nameid_s: nameid { $$ = $1; }
  540. | tSTRING {
  541. $$ = new_name_id();
  542. $$->type = name_str;
  543. $$->name.s_name = $1;
  544. }
  545. ;
  546. /* get the value for a single resource*/
  547. resource_definition
  548. : accelerators { $$ = new_resource(res_acc, $1, $1->memopt, $1->lvc.language); }
  549. | bitmap { $$ = new_resource(res_bmp, $1, $1->memopt, $1->data->lvc.language); }
  550. | cursor {
  551. resource_t *rsc;
  552. if($1->type == res_anicur)
  553. {
  554. $$ = rsc = new_resource(res_anicur, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
  555. }
  556. else if($1->type == res_curg)
  557. {
  558. cursor_t *cur;
  559. $$ = rsc = new_resource(res_curg, $1->u.curg, $1->u.curg->memopt, $1->u.curg->lvc.language);
  560. for(cur = $1->u.curg->cursorlist; cur; cur = cur->next)
  561. {
  562. rsc->prev = new_resource(res_cur, cur, $1->u.curg->memopt, $1->u.curg->lvc.language);
  563. rsc->prev->next = rsc;
  564. rsc = rsc->prev;
  565. rsc->name = new_name_id();
  566. rsc->name->type = name_ord;
  567. rsc->name->name.i_name = cur->id;
  568. }
  569. }
  570. else
  571. internal_error(__FILE__, __LINE__, "Invalid top-level type %d in cursor resource\n", $1->type);
  572. free($1);
  573. }
  574. | dialog { $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language); }
  575. | dialogex {
  576. if(win32)
  577. $$ = new_resource(res_dlg, $1, $1->memopt, $1->lvc.language);
  578. else
  579. $$ = NULL;
  580. }
  581. | dlginit { $$ = new_resource(res_dlginit, $1, $1->memopt, $1->data->lvc.language); }
  582. | font { $$ = new_resource(res_fnt, $1, $1->memopt, $1->data->lvc.language); }
  583. | fontdir { $$ = new_resource(res_fntdir, $1, $1->memopt, $1->data->lvc.language); }
  584. | icon {
  585. resource_t *rsc;
  586. if($1->type == res_aniico)
  587. {
  588. $$ = rsc = new_resource(res_aniico, $1->u.ani, $1->u.ani->memopt, $1->u.ani->data->lvc.language);
  589. }
  590. else if($1->type == res_icog)
  591. {
  592. icon_t *ico;
  593. $$ = rsc = new_resource(res_icog, $1->u.icog, $1->u.icog->memopt, $1->u.icog->lvc.language);
  594. for(ico = $1->u.icog->iconlist; ico; ico = ico->next)
  595. {
  596. rsc->prev = new_resource(res_ico, ico, $1->u.icog->memopt, $1->u.icog->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 = ico->id;
  602. }
  603. }
  604. else
  605. internal_error(__FILE__, __LINE__, "Invalid top-level type %d in icon resource\n", $1->type);
  606. free($1);
  607. }
  608. | menu { $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language); }
  609. | menuex {
  610. if(win32)
  611. $$ = new_resource(res_men, $1, $1->memopt, $1->lvc.language);
  612. else
  613. $$ = NULL;
  614. }
  615. | messagetable { $$ = new_resource(res_msg, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->data->lvc.language); }
  616. | html { $$ = new_resource(res_html, $1, $1->memopt, $1->data->lvc.language); }
  617. | rcdata { $$ = new_resource(res_rdt, $1, $1->memopt, $1->data->lvc.language); }
  618. | toolbar { $$ = new_resource(res_toolbar, $1, $1->memopt, $1->lvc.language); }
  619. | userres { $$ = new_resource(res_usr, $1, $1->memopt, $1->data->lvc.language); }
  620. | versioninfo { $$ = new_resource(res_ver, $1, WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE, $1->lvc.language); }
  621. ;
  622. filename: tFILENAME { $$ = make_filename($1); }
  623. | tIDENT { $$ = make_filename($1); }
  624. | tSTRING { $$ = make_filename($1); }
  625. ;
  626. /* ------------------------------ Bitmap ------------------------------ */
  627. bitmap : tBITMAP loadmemopts file_raw { $$ = new_bitmap($3, $2); }
  628. ;
  629. /* ------------------------------ Cursor ------------------------------ */
  630. cursor : tCURSOR loadmemopts file_raw {
  631. $$ = new_ani_any();
  632. if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
  633. {
  634. $$->type = res_anicur;
  635. $$->u.ani = new_ani_curico(res_anicur, $3, $2);
  636. }
  637. else
  638. {
  639. $$->type = res_curg;
  640. $$->u.curg = new_cursor_group($3, $2);
  641. }
  642. }
  643. ;
  644. /* ------------------------------ Icon ------------------------------ */
  645. icon : tICON loadmemopts file_raw {
  646. $$ = new_ani_any();
  647. if($3->size > 4 && !memcmp($3->data, riff, sizeof(riff)))
  648. {
  649. $$->type = res_aniico;
  650. $$->u.ani = new_ani_curico(res_aniico, $3, $2);
  651. }
  652. else
  653. {
  654. $$->type = res_icog;
  655. $$->u.icog = new_icon_group($3, $2);
  656. }
  657. }
  658. ;
  659. /* ------------------------------ Font ------------------------------ */
  660. /*
  661. * The reading of raw_data for fonts is a Borland BRC
  662. * extension. MS generates an error. However, it is
  663. * most logical to support this, considering how wine
  664. * enters things in CVS (ascii).
  665. */
  666. font : tFONT loadmemopts file_raw { $$ = new_font($3, $2); }
  667. ;
  668. /*
  669. * The fontdir is a Borland BRC extension which only
  670. * reads the data as 'raw_data' from the file.
  671. * I don't know whether it is interpreted.
  672. * The fontdir is generated if it was not present and
  673. * fonts are defined in the source.
  674. */
  675. fontdir : tFONTDIR loadmemopts file_raw { $$ = new_fontdir($3, $2); }
  676. ;
  677. /* ------------------------------ MessageTable ------------------------------ */
  678. /* It might be interesting to implement the MS Message compiler here as well
  679. * to get everything in one source. Might be a future project.
  680. */
  681. messagetable
  682. : tMESSAGETABLE loadmemopts file_raw {
  683. if(!win32)
  684. parser_warning("MESSAGETABLE not supported in 16-bit mode\n");
  685. $$ = new_messagetable($3, $2);
  686. }
  687. ;
  688. /* ------------------------------ HTML ------------------------------ */
  689. html : tHTML loadmemopts file_raw { $$ = new_html($3, $2); }
  690. ;
  691. /* ------------------------------ RCData ------------------------------ */
  692. rcdata : tRCDATA loadmemopts file_raw { $$ = new_rcdata($3, $2); }
  693. ;
  694. /* ------------------------------ DLGINIT ------------------------------ */
  695. dlginit : tDLGINIT loadmemopts file_raw { $$ = new_dlginit($3, $2); }
  696. ;
  697. /* ------------------------------ UserType ------------------------------ */
  698. userres : usertype loadmemopts file_raw {
  699. #ifdef WORDS_BIGENDIAN
  700. if(pedantic && byteorder != WRC_BO_LITTLE)
  701. #else
  702. if(pedantic && byteorder == WRC_BO_BIG)
  703. #endif
  704. parser_warning("Byteordering is not little-endian and type cannot be interpreted\n");
  705. $$ = new_user($1, $3, $2);
  706. }
  707. ;
  708. usertype: tNUMBER {
  709. $$ = new_name_id();
  710. $$->type = name_ord;
  711. $$->name.i_name = $1;
  712. }
  713. | tIDENT {
  714. $$ = new_name_id();
  715. $$->type = name_str;
  716. $$->name.s_name = $1;
  717. }
  718. ;
  719. /* ------------------------------ Accelerator ------------------------------ */
  720. accelerators
  721. : tACCELERATORS loadmemopts opt_lvc tBEGIN events tEND {
  722. $$ = new_accelerator();
  723. if($2)
  724. {
  725. $$->memopt = *($2);
  726. free($2);
  727. }
  728. else
  729. {
  730. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
  731. }
  732. if(!$5)
  733. yyerror("Accelerator table must have at least one entry");
  734. $$->events = get_event_head($5);
  735. if($3)
  736. {
  737. $$->lvc = *($3);
  738. free($3);
  739. }
  740. if(!$$->lvc.language)
  741. $$->lvc.language = dup_language(currentlanguage);
  742. }
  743. ;
  744. events : /* Empty */ { $$=NULL; }
  745. | events tSTRING ',' expr acc_opt { $$=add_string_event($2, $4, $5, $1); }
  746. | events expr ',' expr acc_opt { $$=add_event($2, $4, $5, $1); }
  747. ;
  748. /*
  749. * The empty rule generates a s/r conflict because of {bi,u}nary expr
  750. * on - and +. It cannot be solved in any way because it is the same as
  751. * the if/then/else problem (LALR(1) problem). The conflict is moved
  752. * away by forcing it to be in the expression handling below.
  753. */
  754. acc_opt : /* Empty */ { $$ = 0; }
  755. | ',' accs { $$ = $2; }
  756. ;
  757. accs : acc { $$ = $1; }
  758. | accs ',' acc { $$ = $1 | $3; }
  759. ;
  760. acc : tNOINVERT { $$ = WRC_AF_NOINVERT; }
  761. | tSHIFT { $$ = WRC_AF_SHIFT; }
  762. | tCONTROL { $$ = WRC_AF_CONTROL; }
  763. | tALT { $$ = WRC_AF_ALT; }
  764. | tASCII { $$ = WRC_AF_ASCII; }
  765. | tVIRTKEY { $$ = WRC_AF_VIRTKEY; }
  766. ;
  767. /* ------------------------------ Dialog ------------------------------ */
  768. /* FIXME: Support EXSTYLE in the dialog line itself */
  769. dialog : tDIALOG loadmemopts expr ',' expr ',' expr ',' expr dlg_attributes
  770. tBEGIN ctrls tEND {
  771. if($2)
  772. {
  773. $10->memopt = *($2);
  774. free($2);
  775. }
  776. else
  777. $10->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  778. $10->x = $3;
  779. $10->y = $5;
  780. $10->width = $7;
  781. $10->height = $9;
  782. $10->controls = get_control_head($12);
  783. $$ = $10;
  784. if(!$$->gotstyle)
  785. {
  786. $$->style = new_style(0,0);
  787. $$->style->or_mask = WS_POPUP;
  788. $$->gotstyle = TRUE;
  789. }
  790. if($$->title)
  791. $$->style->or_mask |= WS_CAPTION;
  792. if($$->font)
  793. $$->style->or_mask |= DS_SETFONT;
  794. $$->style->or_mask &= ~($$->style->and_mask);
  795. $$->style->and_mask = 0;
  796. if(!$$->lvc.language)
  797. $$->lvc.language = dup_language(currentlanguage);
  798. }
  799. ;
  800. dlg_attributes
  801. : /* Empty */ { $$=new_dialog(); }
  802. | dlg_attributes tSTYLE style { $$=dialog_style($3,$1); }
  803. | dlg_attributes tEXSTYLE style { $$=dialog_exstyle($3,$1); }
  804. | dlg_attributes tCAPTION tSTRING { $$=dialog_caption($3,$1); }
  805. | dlg_attributes opt_font { $$=dialog_font($2,$1); }
  806. | dlg_attributes tCLASS nameid_s { $$=dialog_class($3,$1); }
  807. | dlg_attributes tMENU nameid { $$=dialog_menu($3,$1); }
  808. | dlg_attributes opt_language { $$=dialog_language($2,$1); }
  809. | dlg_attributes opt_characts { $$=dialog_characteristics($2,$1); }
  810. | dlg_attributes opt_version { $$=dialog_version($2,$1); }
  811. ;
  812. ctrls : /* Empty */ { $$ = NULL; }
  813. | ctrls tCONTROL gen_ctrl { $$=ins_ctrl(-1, 0, $3, $1); }
  814. | ctrls tEDITTEXT ctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
  815. | ctrls tLISTBOX ctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
  816. | ctrls tCOMBOBOX ctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
  817. | ctrls tSCROLLBAR ctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
  818. | ctrls tCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
  819. | ctrls tDEFPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
  820. | ctrls tGROUPBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
  821. | ctrls tPUSHBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
  822. /* | ctrls tPUSHBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
  823. | ctrls tRADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
  824. | ctrls tAUTO3STATE lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
  825. | ctrls tSTATE3 lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
  826. | ctrls tAUTOCHECKBOX lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
  827. | ctrls tAUTORADIOBUTTON lab_ctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
  828. | ctrls tLTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
  829. | ctrls tCTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
  830. | ctrls tRTEXT lab_ctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
  831. /* special treatment for icons, as the extent is optional */
  832. | ctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
  833. $10->title = $3;
  834. $10->id = $5;
  835. $10->x = $7;
  836. $10->y = $9;
  837. $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
  838. }
  839. ;
  840. lab_ctrl
  841. : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
  842. $$=new_control();
  843. $$->title = $1;
  844. $$->id = $3;
  845. $$->x = $5;
  846. $$->y = $7;
  847. $$->width = $9;
  848. $$->height = $11;
  849. if($12)
  850. {
  851. $$->style = $12->style;
  852. $$->gotstyle = TRUE;
  853. if ($12->exstyle)
  854. {
  855. $$->exstyle = $12->exstyle;
  856. $$->gotexstyle = TRUE;
  857. }
  858. free($12);
  859. }
  860. }
  861. ;
  862. ctrl_desc
  863. : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair {
  864. $$ = new_control();
  865. $$->id = $1;
  866. $$->x = $3;
  867. $$->y = $5;
  868. $$->width = $7;
  869. $$->height = $9;
  870. if($10)
  871. {
  872. $$->style = $10->style;
  873. $$->gotstyle = TRUE;
  874. if ($10->exstyle)
  875. {
  876. $$->exstyle = $10->exstyle;
  877. $$->gotexstyle = TRUE;
  878. }
  879. free($10);
  880. }
  881. }
  882. ;
  883. iconinfo: /* Empty */
  884. { $$ = new_control(); }
  885. | ',' expr ',' expr {
  886. $$ = new_control();
  887. $$->width = $2;
  888. $$->height = $4;
  889. }
  890. | ',' expr ',' expr ',' style {
  891. $$ = new_control();
  892. $$->width = $2;
  893. $$->height = $4;
  894. $$->style = $6;
  895. $$->gotstyle = TRUE;
  896. }
  897. | ',' expr ',' expr ',' style ',' style {
  898. $$ = new_control();
  899. $$->width = $2;
  900. $$->height = $4;
  901. $$->style = $6;
  902. $$->gotstyle = TRUE;
  903. $$->exstyle = $8;
  904. $$->gotexstyle = TRUE;
  905. }
  906. ;
  907. gen_ctrl: nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr ',' style {
  908. $$=new_control();
  909. $$->title = $1;
  910. $$->id = $3;
  911. $$->ctlclass = convert_ctlclass($5);
  912. $$->style = $7;
  913. $$->gotstyle = TRUE;
  914. $$->x = $9;
  915. $$->y = $11;
  916. $$->width = $13;
  917. $$->height = $15;
  918. $$->exstyle = $17;
  919. $$->gotexstyle = TRUE;
  920. }
  921. | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr {
  922. $$=new_control();
  923. $$->title = $1;
  924. $$->id = $3;
  925. $$->ctlclass = convert_ctlclass($5);
  926. $$->style = $7;
  927. $$->gotstyle = TRUE;
  928. $$->x = $9;
  929. $$->y = $11;
  930. $$->width = $13;
  931. $$->height = $15;
  932. }
  933. ;
  934. opt_font
  935. : tFONT expr ',' tSTRING { $$ = new_font_id($2, $4, 0, 0); }
  936. ;
  937. /* ------------------------------ style flags ------------------------------ */
  938. optional_style_pair
  939. : /* Empty */ { $$ = NULL; }
  940. | ',' style { $$ = new_style_pair($2, 0); }
  941. | ',' style ',' style { $$ = new_style_pair($2, $4); }
  942. ;
  943. style
  944. : style '|' style { $$ = new_style($1->or_mask | $3->or_mask, $1->and_mask | $3->and_mask); free($1); free($3);}
  945. | '(' style ')' { $$ = $2; }
  946. | any_num { $$ = new_style($1, 0); }
  947. | tNOT any_num { $$ = new_style(0, $2); }
  948. ;
  949. ctlclass
  950. : expr {
  951. $$ = new_name_id();
  952. $$->type = name_ord;
  953. $$->name.i_name = $1;
  954. }
  955. | tSTRING {
  956. $$ = new_name_id();
  957. $$->type = name_str;
  958. $$->name.s_name = $1;
  959. }
  960. ;
  961. /* ------------------------------ DialogEx ------------------------------ */
  962. dialogex: tDIALOGEX loadmemopts expr ',' expr ',' expr ',' expr helpid dlgex_attribs
  963. tBEGIN exctrls tEND {
  964. if(!win32)
  965. parser_warning("DIALOGEX not supported in 16-bit mode\n");
  966. if($2)
  967. {
  968. $11->memopt = *($2);
  969. free($2);
  970. }
  971. else
  972. $11->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  973. $11->x = $3;
  974. $11->y = $5;
  975. $11->width = $7;
  976. $11->height = $9;
  977. if($10)
  978. {
  979. $11->helpid = *($10);
  980. $11->gothelpid = TRUE;
  981. free($10);
  982. }
  983. $11->controls = get_control_head($13);
  984. $$ = $11;
  985. assert($$->style != NULL);
  986. if(!$$->gotstyle)
  987. {
  988. $$->style->or_mask = WS_POPUP;
  989. $$->gotstyle = TRUE;
  990. }
  991. if($$->title)
  992. $$->style->or_mask |= WS_CAPTION;
  993. if($$->font)
  994. $$->style->or_mask |= DS_SETFONT;
  995. $$->style->or_mask &= ~($$->style->and_mask);
  996. $$->style->and_mask = 0;
  997. if(!$$->lvc.language)
  998. $$->lvc.language = dup_language(currentlanguage);
  999. }
  1000. ;
  1001. dlgex_attribs
  1002. : /* Empty */ { $$=new_dialog(); $$->is_ex = TRUE; }
  1003. | dlgex_attribs tSTYLE style { $$=dialog_style($3,$1); }
  1004. | dlgex_attribs tEXSTYLE style { $$=dialog_exstyle($3,$1); }
  1005. | dlgex_attribs tCAPTION tSTRING { $$=dialog_caption($3,$1); }
  1006. | dlgex_attribs opt_font { $$=dialog_font($2,$1); }
  1007. | dlgex_attribs opt_exfont { $$=dialog_font($2,$1); }
  1008. | dlgex_attribs tCLASS nameid_s { $$=dialog_class($3,$1); }
  1009. | dlgex_attribs tMENU nameid { $$=dialog_menu($3,$1); }
  1010. | dlgex_attribs opt_language { $$=dialog_language($2,$1); }
  1011. | dlgex_attribs opt_characts { $$=dialog_characteristics($2,$1); }
  1012. | dlgex_attribs opt_version { $$=dialog_version($2,$1); }
  1013. ;
  1014. exctrls : /* Empty */ { $$ = NULL; }
  1015. | exctrls tCONTROL gen_exctrl { $$=ins_ctrl(-1, 0, $3, $1); }
  1016. | exctrls tEDITTEXT exctrl_desc { $$=ins_ctrl(CT_EDIT, 0, $3, $1); }
  1017. | exctrls tLISTBOX exctrl_desc { $$=ins_ctrl(CT_LISTBOX, 0, $3, $1); }
  1018. | exctrls tCOMBOBOX exctrl_desc { $$=ins_ctrl(CT_COMBOBOX, 0, $3, $1); }
  1019. | exctrls tSCROLLBAR exctrl_desc { $$=ins_ctrl(CT_SCROLLBAR, 0, $3, $1); }
  1020. | exctrls tCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_CHECKBOX, $3, $1); }
  1021. | exctrls tDEFPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_DEFPUSHBUTTON, $3, $1); }
  1022. | exctrls tGROUPBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_GROUPBOX, $3, $1);}
  1023. | exctrls tPUSHBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBUTTON, $3, $1); }
  1024. /* | exctrls tPUSHBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_PUSHBOX, $3, $1); } */
  1025. | exctrls tRADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_RADIOBUTTON, $3, $1); }
  1026. | exctrls tAUTO3STATE lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTO3STATE, $3, $1); }
  1027. | exctrls tSTATE3 lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_3STATE, $3, $1); }
  1028. | exctrls tAUTOCHECKBOX lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTOCHECKBOX, $3, $1); }
  1029. | exctrls tAUTORADIOBUTTON lab_exctrl { $$=ins_ctrl(CT_BUTTON, BS_AUTORADIOBUTTON, $3, $1); }
  1030. | exctrls tLTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_LEFT, $3, $1); }
  1031. | exctrls tCTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_CENTER, $3, $1); }
  1032. | exctrls tRTEXT lab_exctrl { $$=ins_ctrl(CT_STATIC, SS_RIGHT, $3, $1); }
  1033. /* special treatment for icons, as the extent is optional */
  1034. | exctrls tICON nameid_s opt_comma expr ',' expr ',' expr iconinfo {
  1035. $10->title = $3;
  1036. $10->id = $5;
  1037. $10->x = $7;
  1038. $10->y = $9;
  1039. $$ = ins_ctrl(CT_STATIC, SS_ICON, $10, $1);
  1040. }
  1041. ;
  1042. gen_exctrl
  1043. : nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ','
  1044. expr ',' style helpid opt_data {
  1045. $$=new_control();
  1046. $$->title = $1;
  1047. $$->id = $3;
  1048. $$->ctlclass = convert_ctlclass($5);
  1049. $$->style = $7;
  1050. $$->gotstyle = TRUE;
  1051. $$->x = $9;
  1052. $$->y = $11;
  1053. $$->width = $13;
  1054. $$->height = $15;
  1055. if($17)
  1056. {
  1057. $$->exstyle = $17;
  1058. $$->gotexstyle = TRUE;
  1059. }
  1060. if($18)
  1061. {
  1062. $$->helpid = *($18);
  1063. $$->gothelpid = TRUE;
  1064. free($18);
  1065. }
  1066. $$->extra = $19;
  1067. }
  1068. | nameid_s opt_comma expr ',' ctlclass ',' style ',' expr ',' expr ',' expr ',' expr opt_data {
  1069. $$=new_control();
  1070. $$->title = $1;
  1071. $$->id = $3;
  1072. $$->style = $7;
  1073. $$->gotstyle = TRUE;
  1074. $$->ctlclass = convert_ctlclass($5);
  1075. $$->x = $9;
  1076. $$->y = $11;
  1077. $$->width = $13;
  1078. $$->height = $15;
  1079. $$->extra = $16;
  1080. }
  1081. ;
  1082. lab_exctrl
  1083. : nameid_s opt_comma expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
  1084. $$=new_control();
  1085. $$->title = $1;
  1086. $$->id = $3;
  1087. $$->x = $5;
  1088. $$->y = $7;
  1089. $$->width = $9;
  1090. $$->height = $11;
  1091. if($12)
  1092. {
  1093. $$->style = $12->style;
  1094. $$->gotstyle = TRUE;
  1095. if ($12->exstyle)
  1096. {
  1097. $$->exstyle = $12->exstyle;
  1098. $$->gotexstyle = TRUE;
  1099. }
  1100. free($12);
  1101. }
  1102. $$->extra = $14;
  1103. }
  1104. ;
  1105. exctrl_desc
  1106. : expr ',' expr ',' expr ',' expr ',' expr optional_style_pair helpid opt_data {
  1107. $$ = new_control();
  1108. $$->id = $1;
  1109. $$->x = $3;
  1110. $$->y = $5;
  1111. $$->width = $7;
  1112. $$->height = $9;
  1113. if($10)
  1114. {
  1115. $$->style = $10->style;
  1116. $$->gotstyle = TRUE;
  1117. if ($10->exstyle)
  1118. {
  1119. $$->exstyle = $10->exstyle;
  1120. $$->gotexstyle = TRUE;
  1121. }
  1122. free($10);
  1123. }
  1124. $$->extra = $12;
  1125. }
  1126. ;
  1127. opt_data: /* Empty */ { $$ = NULL; }
  1128. | raw_data { $$ = $1; }
  1129. ;
  1130. helpid : /* Empty */ { $$ = NULL; }
  1131. | ',' expr { $$ = new_int($2); }
  1132. ;
  1133. opt_exfont
  1134. : tFONT expr ',' tSTRING ',' expr ',' expr opt_expr { $$ = new_font_id($2, $4, $6, $8); }
  1135. ;
  1136. /*
  1137. * FIXME: This odd expression is here to nullify an extra token found
  1138. * in some appstudio produced resources which appear to do nothing.
  1139. */
  1140. opt_expr: /* Empty */ { $$ = NULL; }
  1141. | ',' expr { $$ = NULL; }
  1142. ;
  1143. /* ------------------------------ Menu ------------------------------ */
  1144. menu : tMENU loadmemopts opt_lvc menu_body {
  1145. if(!$4)
  1146. yyerror("Menu must contain items");
  1147. $$ = new_menu();
  1148. if($2)
  1149. {
  1150. $$->memopt = *($2);
  1151. free($2);
  1152. }
  1153. else
  1154. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  1155. $$->items = get_item_head($4);
  1156. if($3)
  1157. {
  1158. $$->lvc = *($3);
  1159. free($3);
  1160. }
  1161. if(!$$->lvc.language)
  1162. $$->lvc.language = dup_language(currentlanguage);
  1163. }
  1164. ;
  1165. menu_body
  1166. : tBEGIN item_definitions tEND { $$ = $2; }
  1167. ;
  1168. item_definitions
  1169. : /* Empty */ {$$ = NULL;}
  1170. | item_definitions tMENUITEM tSTRING opt_comma expr item_options {
  1171. $$=new_menu_item();
  1172. $$->prev = $1;
  1173. if($1)
  1174. $1->next = $$;
  1175. $$->id = $5;
  1176. $$->state = $6;
  1177. $$->name = $3;
  1178. }
  1179. | item_definitions tMENUITEM tSEPARATOR {
  1180. $$=new_menu_item();
  1181. $$->prev = $1;
  1182. if($1)
  1183. $1->next = $$;
  1184. }
  1185. | item_definitions tPOPUP tSTRING item_options menu_body {
  1186. $$ = new_menu_item();
  1187. $$->prev = $1;
  1188. if($1)
  1189. $1->next = $$;
  1190. $$->popup = get_item_head($5);
  1191. $$->name = $3;
  1192. }
  1193. ;
  1194. /* NOTE: item_options is right recursive because it would introduce
  1195. * a shift/reduce conflict on ',' in itemex_options due to the
  1196. * empty rule here. The parser is now forced to look beyond the ','
  1197. * before reducing (force shift).
  1198. * Right recursion here is not a problem because we cannot expect
  1199. * more than 7 parserstack places to be occupied while parsing this
  1200. * (who would want to specify a MF_x flag twice?).
  1201. */
  1202. item_options
  1203. : /* Empty */ { $$ = 0; }
  1204. | ',' item_options { $$ = $2; }
  1205. | tCHECKED item_options { $$ = $2 | MF_CHECKED; }
  1206. | tGRAYED item_options { $$ = $2 | MF_GRAYED; }
  1207. | tHELP item_options { $$ = $2 | MF_HELP; }
  1208. | tINACTIVE item_options { $$ = $2 | MF_DISABLED; }
  1209. | tMENUBARBREAK item_options { $$ = $2 | MF_MENUBARBREAK; }
  1210. | tMENUBREAK item_options { $$ = $2 | MF_MENUBREAK; }
  1211. ;
  1212. /* ------------------------------ MenuEx ------------------------------ */
  1213. menuex : tMENUEX loadmemopts opt_lvc menuex_body {
  1214. if(!win32)
  1215. parser_warning("MENUEX not supported in 16-bit mode\n");
  1216. if(!$4)
  1217. yyerror("MenuEx must contain items");
  1218. $$ = new_menu();
  1219. $$->is_ex = TRUE;
  1220. if($2)
  1221. {
  1222. $$->memopt = *($2);
  1223. free($2);
  1224. }
  1225. else
  1226. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE | WRC_MO_DISCARDABLE;
  1227. $$->items = get_item_head($4);
  1228. if($3)
  1229. {
  1230. $$->lvc = *($3);
  1231. free($3);
  1232. }
  1233. if(!$$->lvc.language)
  1234. $$->lvc.language = dup_language(currentlanguage);
  1235. }
  1236. ;
  1237. menuex_body
  1238. : tBEGIN itemex_definitions tEND { $$ = $2; }
  1239. ;
  1240. itemex_definitions
  1241. : /* Empty */ {$$ = NULL; }
  1242. | itemex_definitions tMENUITEM tSTRING itemex_options {
  1243. $$ = new_menu_item();
  1244. $$->prev = $1;
  1245. if($1)
  1246. $1->next = $$;
  1247. $$->name = $3;
  1248. $$->id = $4->id;
  1249. $$->type = $4->type;
  1250. $$->state = $4->state;
  1251. $$->helpid = $4->helpid;
  1252. $$->gotid = $4->gotid;
  1253. $$->gottype = $4->gottype;
  1254. $$->gotstate = $4->gotstate;
  1255. $$->gothelpid = $4->gothelpid;
  1256. free($4);
  1257. }
  1258. | itemex_definitions tMENUITEM tSEPARATOR {
  1259. $$ = new_menu_item();
  1260. $$->prev = $1;
  1261. if($1)
  1262. $1->next = $$;
  1263. }
  1264. | itemex_definitions tPOPUP tSTRING itemex_p_options menuex_body {
  1265. $$ = new_menu_item();
  1266. $$->prev = $1;
  1267. if($1)
  1268. $1->next = $$;
  1269. $$->popup = get_item_head($5);
  1270. $$->name = $3;
  1271. $$->id = $4->id;
  1272. $$->type = $4->type;
  1273. $$->state = $4->state;
  1274. $$->helpid = $4->helpid;
  1275. $$->gotid = $4->gotid;
  1276. $$->gottype = $4->gottype;
  1277. $$->gotstate = $4->gotstate;
  1278. $$->gothelpid = $4->gothelpid;
  1279. free($4);
  1280. }
  1281. ;
  1282. itemex_options
  1283. : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
  1284. | ',' expr {
  1285. $$ = new_itemex_opt($2, 0, 0, 0);
  1286. $$->gotid = TRUE;
  1287. }
  1288. | ',' e_expr ',' e_expr item_options {
  1289. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $5, 0);
  1290. $$->gotid = TRUE;
  1291. $$->gottype = TRUE;
  1292. $$->gotstate = TRUE;
  1293. free($2);
  1294. free($4);
  1295. }
  1296. | ',' e_expr ',' e_expr ',' expr {
  1297. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
  1298. $$->gotid = TRUE;
  1299. $$->gottype = TRUE;
  1300. $$->gotstate = TRUE;
  1301. free($2);
  1302. free($4);
  1303. }
  1304. ;
  1305. itemex_p_options
  1306. : /* Empty */ { $$ = new_itemex_opt(0, 0, 0, 0); }
  1307. | ',' expr {
  1308. $$ = new_itemex_opt($2, 0, 0, 0);
  1309. $$->gotid = TRUE;
  1310. }
  1311. | ',' e_expr ',' expr {
  1312. $$ = new_itemex_opt($2 ? *($2) : 0, $4, 0, 0);
  1313. free($2);
  1314. $$->gotid = TRUE;
  1315. $$->gottype = TRUE;
  1316. }
  1317. | ',' e_expr ',' e_expr ',' expr {
  1318. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6, 0);
  1319. free($2);
  1320. free($4);
  1321. $$->gotid = TRUE;
  1322. $$->gottype = TRUE;
  1323. $$->gotstate = TRUE;
  1324. }
  1325. | ',' e_expr ',' e_expr ',' e_expr ',' expr {
  1326. $$ = new_itemex_opt($2 ? *($2) : 0, $4 ? *($4) : 0, $6 ? *($6) : 0, $8);
  1327. free($2);
  1328. free($4);
  1329. free($6);
  1330. $$->gotid = TRUE;
  1331. $$->gottype = TRUE;
  1332. $$->gotstate = TRUE;
  1333. $$->gothelpid = TRUE;
  1334. }
  1335. ;
  1336. /* ------------------------------ StringTable ------------------------------ */
  1337. /* Stringtables are parsed differently than other resources because their
  1338. * layout is substantially different from other resources.
  1339. * The table is parsed through a _global_ variable 'tagstt' which holds the
  1340. * current stringtable descriptor (stringtable_t *) and 'sttres' that holds a
  1341. * list of stringtables of different languages.
  1342. */
  1343. stringtable
  1344. : stt_head tBEGIN strings tEND {
  1345. if(!$3)
  1346. {
  1347. yyerror("Stringtable must have at least one entry");
  1348. }
  1349. else
  1350. {
  1351. stringtable_t *stt;
  1352. /* Check if we added to a language table or created
  1353. * a new one.
  1354. */
  1355. for(stt = sttres; stt; stt = stt->next)
  1356. {
  1357. if(stt == tagstt)
  1358. break;
  1359. }
  1360. if(!stt)
  1361. {
  1362. /* It is a new one */
  1363. if(sttres)
  1364. {
  1365. sttres->prev = tagstt;
  1366. tagstt->next = sttres;
  1367. sttres = tagstt;
  1368. }
  1369. else
  1370. sttres = tagstt;
  1371. }
  1372. /* Else were done */
  1373. }
  1374. free(tagstt_memopt);
  1375. tagstt_memopt = NULL;
  1376. $$ = tagstt;
  1377. }
  1378. ;
  1379. /* This is to get the language of the currently parsed stringtable */
  1380. stt_head: tSTRINGTABLE loadmemopts opt_lvc {
  1381. if((tagstt = find_stringtable($3)) == NULL)
  1382. tagstt = new_stringtable($3);
  1383. tagstt_memopt = $2;
  1384. tagstt_version = $3->version;
  1385. tagstt_characts = $3->characts;
  1386. free($3);
  1387. }
  1388. ;
  1389. strings : /* Empty */ { $$ = NULL; }
  1390. | strings expr opt_comma tSTRING {
  1391. int i;
  1392. assert(tagstt != NULL);
  1393. if($2 > 65535 || $2 < -32768)
  1394. yyerror("Stringtable entry's ID out of range (%d)", $2);
  1395. /* Search for the ID */
  1396. for(i = 0; i < tagstt->nentries; i++)
  1397. {
  1398. if(tagstt->entries[i].id == $2)
  1399. yyerror("Stringtable ID %d already in use", $2);
  1400. }
  1401. /* If we get here, then we have a new unique entry */
  1402. tagstt->nentries++;
  1403. tagstt->entries = xrealloc(tagstt->entries, sizeof(tagstt->entries[0]) * tagstt->nentries);
  1404. tagstt->entries[tagstt->nentries-1].id = $2;
  1405. tagstt->entries[tagstt->nentries-1].str = $4;
  1406. if(tagstt_memopt)
  1407. tagstt->entries[tagstt->nentries-1].memopt = *tagstt_memopt;
  1408. else
  1409. tagstt->entries[tagstt->nentries-1].memopt = WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
  1410. tagstt->entries[tagstt->nentries-1].version = tagstt_version;
  1411. tagstt->entries[tagstt->nentries-1].characts = tagstt_characts;
  1412. if(pedantic && !$4->size)
  1413. parser_warning("Zero length strings make no sense\n");
  1414. if(!win32 && $4->size > 254)
  1415. yyerror("Stringtable entry more than 254 characters");
  1416. if(win32 && $4->size > 65534) /* Hmm..., does this happen? */
  1417. yyerror("Stringtable entry more than 65534 characters (probably something else that went wrong)");
  1418. $$ = tagstt;
  1419. }
  1420. ;
  1421. opt_comma /* There seem to be two ways to specify a stringtable... */
  1422. : /* Empty */
  1423. | ','
  1424. ;
  1425. /* ------------------------------ VersionInfo ------------------------------ */
  1426. versioninfo
  1427. : tVERSIONINFO loadmemopts fix_version tBEGIN ver_blocks tEND {
  1428. $$ = $3;
  1429. if($2)
  1430. {
  1431. $$->memopt = *($2);
  1432. free($2);
  1433. }
  1434. else
  1435. $$->memopt = WRC_MO_MOVEABLE | (win32 ? WRC_MO_PURE : 0);
  1436. $$->blocks = get_ver_block_head($5);
  1437. /* Set language; there is no version or characteristics */
  1438. $$->lvc.language = dup_language(currentlanguage);
  1439. }
  1440. ;
  1441. fix_version
  1442. : /* Empty */ { $$ = new_versioninfo(); }
  1443. | fix_version tFILEVERSION expr ',' expr ',' expr ',' expr {
  1444. if($1->gotit.fv)
  1445. yyerror("FILEVERSION already defined");
  1446. $$ = $1;
  1447. $$->filever_maj1 = $3;
  1448. $$->filever_maj2 = $5;
  1449. $$->filever_min1 = $7;
  1450. $$->filever_min2 = $9;
  1451. $$->gotit.fv = 1;
  1452. }
  1453. | fix_version tPRODUCTVERSION expr ',' expr ',' expr ',' expr {
  1454. if($1->gotit.pv)
  1455. yyerror("PRODUCTVERSION already defined");
  1456. $$ = $1;
  1457. $$->prodver_maj1 = $3;
  1458. $$->prodver_maj2 = $5;
  1459. $$->prodver_min1 = $7;
  1460. $$->prodver_min2 = $9;
  1461. $$->gotit.pv = 1;
  1462. }
  1463. | fix_version tFILEFLAGS expr {
  1464. if($1->gotit.ff)
  1465. yyerror("FILEFLAGS already defined");
  1466. $$ = $1;
  1467. $$->fileflags = $3;
  1468. $$->gotit.ff = 1;
  1469. }
  1470. | fix_version tFILEFLAGSMASK expr {
  1471. if($1->gotit.ffm)
  1472. yyerror("FILEFLAGSMASK already defined");
  1473. $$ = $1;
  1474. $$->fileflagsmask = $3;
  1475. $$->gotit.ffm = 1;
  1476. }
  1477. | fix_version tFILEOS expr {
  1478. if($1->gotit.fo)
  1479. yyerror("FILEOS already defined");
  1480. $$ = $1;
  1481. $$->fileos = $3;
  1482. $$->gotit.fo = 1;
  1483. }
  1484. | fix_version tFILETYPE expr {
  1485. if($1->gotit.ft)
  1486. yyerror("FILETYPE already defined");
  1487. $$ = $1;
  1488. $$->filetype = $3;
  1489. $$->gotit.ft = 1;
  1490. }
  1491. | fix_version tFILESUBTYPE expr {
  1492. if($1->gotit.fst)
  1493. yyerror("FILESUBTYPE already defined");
  1494. $$ = $1;
  1495. $$->filesubtype = $3;
  1496. $$->gotit.fst = 1;
  1497. }
  1498. ;
  1499. ver_blocks
  1500. : /* Empty */ { $$ = NULL; }
  1501. | ver_blocks ver_block {
  1502. $$ = $2;
  1503. $$->prev = $1;
  1504. if($1)
  1505. $1->next = $$;
  1506. }
  1507. ;
  1508. ver_block
  1509. : tBLOCK tSTRING tBEGIN ver_values tEND {
  1510. $$ = new_ver_block();
  1511. $$->name = $2;
  1512. $$->values = get_ver_value_head($4);
  1513. }
  1514. ;
  1515. ver_values
  1516. : /* Empty */ { $$ = NULL; }
  1517. | ver_values ver_value {
  1518. $$ = $2;
  1519. $$->prev = $1;
  1520. if($1)
  1521. $1->next = $$;
  1522. }
  1523. ;
  1524. ver_value
  1525. : ver_block {
  1526. $$ = new_ver_value();
  1527. $$->type = val_block;
  1528. $$->value.block = $1;
  1529. }
  1530. | tVALUE tSTRING ',' tSTRING {
  1531. $$ = new_ver_value();
  1532. $$->type = val_str;
  1533. $$->key = $2;
  1534. $$->value.str = $4;
  1535. }
  1536. | tVALUE tSTRING ',' ver_words {
  1537. $$ = new_ver_value();
  1538. $$->type = val_words;
  1539. $$->key = $2;
  1540. $$->value.words = $4;
  1541. }
  1542. ;
  1543. ver_words
  1544. : expr { $$ = new_ver_words($1); }
  1545. | ver_words ',' expr { $$ = add_ver_words($1, $3); }
  1546. ;
  1547. /* ------------------------------ Toolbar ------------------------------ */
  1548. toolbar: tTOOLBAR loadmemopts expr ',' expr opt_lvc tBEGIN toolbar_items tEND {
  1549. int nitems;
  1550. toolbar_item_t *items = get_tlbr_buttons_head($8, &nitems);
  1551. $$ = new_toolbar($3, $5, items, nitems);
  1552. if($2)
  1553. {
  1554. $$->memopt = *($2);
  1555. free($2);
  1556. }
  1557. else
  1558. {
  1559. $$->memopt = WRC_MO_MOVEABLE | WRC_MO_PURE;
  1560. }
  1561. if($6)
  1562. {
  1563. $$->lvc = *($6);
  1564. free($6);
  1565. }
  1566. if(!$$->lvc.language)
  1567. {
  1568. $$->lvc.language = dup_language(currentlanguage);
  1569. }
  1570. }
  1571. ;
  1572. toolbar_items
  1573. : /* Empty */ { $$ = NULL; }
  1574. | toolbar_items tBUTTON expr {
  1575. toolbar_item_t *idrec = new_toolbar_item();
  1576. idrec->id = $3;
  1577. $$ = ins_tlbr_button($1, idrec);
  1578. }
  1579. | toolbar_items tSEPARATOR {
  1580. toolbar_item_t *idrec = new_toolbar_item();
  1581. idrec->id = 0;
  1582. $$ = ins_tlbr_button($1, idrec);
  1583. }
  1584. ;
  1585. /* ------------------------------ Memory options ------------------------------ */
  1586. loadmemopts
  1587. : /* Empty */ { $$ = NULL; }
  1588. | loadmemopts lamo {
  1589. if($1)
  1590. {
  1591. *($1) |= *($2);
  1592. $$ = $1;
  1593. free($2);
  1594. }
  1595. else
  1596. $$ = $2;
  1597. }
  1598. | loadmemopts lama {
  1599. if($1)
  1600. {
  1601. *($1) &= *($2);
  1602. $$ = $1;
  1603. free($2);
  1604. }
  1605. else
  1606. {
  1607. *$2 &= WRC_MO_MOVEABLE | WRC_MO_DISCARDABLE | WRC_MO_PURE;
  1608. $$ = $2;
  1609. }
  1610. }
  1611. ;
  1612. lamo : tPRELOAD { $$ = new_int(WRC_MO_PRELOAD);
  1613. if (win32 && pedantic) parser_warning("PRELOAD is ignored in 32-bit mode\n"); }
  1614. | tMOVEABLE { $$ = new_int(WRC_MO_MOVEABLE);
  1615. if (win32 && pedantic) parser_warning("MOVEABLE is ignored in 32-bit mode\n"); }
  1616. | tDISCARDABLE { $$ = new_int(WRC_MO_DISCARDABLE);
  1617. if (win32 && pedantic) parser_warning("DISCARDABLE is ignored in 32-bit mode\n"); }
  1618. | tPURE { $$ = new_int(WRC_MO_PURE);
  1619. if (win32 && pedantic) parser_warning("PURE is ignored in 32-bit mode\n"); }
  1620. ;
  1621. lama : tLOADONCALL { $$ = new_int(~WRC_MO_PRELOAD);
  1622. if (win32 && pedantic) parser_warning("LOADONCALL is ignored in 32-bit mode\n"); }
  1623. | tFIXED { $$ = new_int(~WRC_MO_MOVEABLE);
  1624. if (win32 && pedantic) parser_warning("FIXED is ignored in 32-bit mode\n"); }
  1625. | tIMPURE { $$ = new_int(~WRC_MO_PURE);
  1626. if (win32 && pedantic) parser_warning("IMPURE is ignored in 32-bit mode\n"); }
  1627. ;
  1628. /* ------------------------------ Win32 options ------------------------------ */
  1629. opt_lvc : /* Empty */ { $$ = new_lvc(); }
  1630. | opt_lvc opt_langu

Large files files are truncated, but you can click here to view the full file