PageRenderTime 60ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/wrc/parser.y

https://bitbucket.org/arty/arty-newcc-reactos
Happy | 2961 lines | 2744 code | 217 blank | 0 comment | 0 complexity | 1ad3d74dea63c63f35a0e2a7ce468089 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-3.0, CC-BY-SA-3.0, AGPL-3.0, GPL-3.0, CPL-1.0
  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_language {
  1631. if(!win32)
  1632. parser_warning("LANGUAGE not supported in 16-bit mode\n");
  1633. if($1->language)
  1634. yyerror("Language already defined");
  1635. $$ = $1;
  1636. $1->language = $2;
  1637. }
  1638. | opt_lvc opt_characts {
  1639. if(!win32)
  1640. parser_warning("CHARACTERISTICS not supported in 16-bit mode\n");
  1641. if($1->characts)
  1642. yyerror("Characteristics already defined");
  1643. $$ = $1;
  1644. $1->characts = $2;
  1645. }
  1646. | opt_lvc opt_version {
  1647. if(!win32)
  1648. parser_warning("VERSION not supported in 16-bit mode\n");
  1649. if($1->version)
  1650. yyerror("Version already defined");
  1651. $$ = $1;
  1652. $1->version = $2;
  1653. }
  1654. ;
  1655. /*
  1656. * This here is another s/r conflict on {bi,u}nary + and -.
  1657. * It is due to the look-ahead which must determine when the
  1658. * rule opt_language ends. It could be solved with adding a
  1659. * tNL at the end, but that seems unreasonable to do.
  1660. * The conflict is now moved to the expression handling below.
  1661. */
  1662. opt_language
  1663. : tLANGUAGE expr ',' expr { $$ = new_language($2, $4);
  1664. if (get_language_codepage($2, $4) == -1)
  1665. yyerror( "Language %04x is not supported", ($4<<10) + $2);
  1666. }
  1667. ;
  1668. opt_characts
  1669. : tCHARACTERISTICS expr { $$ = new_characts($2); }
  1670. ;
  1671. opt_version
  1672. : tVERSION expr { $$ = new_version($2); }
  1673. ;
  1674. /* ------------------------------ Raw data handling ------------------------------ */
  1675. raw_data: opt_lvc tBEGIN raw_elements tEND {
  1676. if($1)
  1677. {
  1678. $3->lvc = *($1);
  1679. free($1);
  1680. }
  1681. if(!$3->lvc.language)
  1682. $3->lvc.language = dup_language(currentlanguage);
  1683. $$ = $3;
  1684. }
  1685. ;
  1686. raw_elements
  1687. : tRAWDATA { $$ = $1; }
  1688. | tNUMBER { $$ = int2raw_data($1); }
  1689. | '-' tNUMBER { $$ = int2raw_data(-($2)); }
  1690. | tLNUMBER { $$ = long2raw_data($1); }
  1691. | '-' tLNUMBER { $$ = long2raw_data(-($2)); }
  1692. | tSTRING { $$ = str2raw_data($1); }
  1693. | raw_elements opt_comma tRAWDATA { $$ = merge_raw_data($1, $3); free($3->data); free($3); }
  1694. | raw_elements opt_comma tNUMBER { $$ = merge_raw_data_int($1, $3); }
  1695. | raw_elements opt_comma '-' tNUMBER { $$ = merge_raw_data_int($1, -($4)); }
  1696. | raw_elements opt_comma tLNUMBER { $$ = merge_raw_data_long($1, $3); }
  1697. | raw_elements opt_comma '-' tLNUMBER { $$ = merge_raw_data_long($1, -($4)); }
  1698. | raw_elements opt_comma tSTRING { $$ = merge_raw_data_str($1, $3); }
  1699. ;
  1700. /* File data or raw data */
  1701. file_raw: filename { $$ = load_file($1,dup_language(currentlanguage)); }
  1702. | raw_data { $$ = $1; }
  1703. ;
  1704. /* ------------------------------ Win32 expressions ------------------------------ */
  1705. /* All win16 numbers are also handled here. This is inconsistent with MS'
  1706. * resource compiler, but what the heck, its just handy to have.
  1707. */
  1708. e_expr : /* Empty */ { $$ = 0; }
  1709. | expr { $$ = new_int($1); }
  1710. ;
  1711. /* This rule moves ALL s/r conflicts on {bi,u}nary - and + to here */
  1712. expr : xpr { $$ = ($1); }
  1713. ;
  1714. xpr : xpr '+' xpr { $$ = ($1) + ($3); }
  1715. | xpr '-' xpr { $$ = ($1) - ($3); }
  1716. | xpr '|' xpr { $$ = ($1) | ($3); }
  1717. | xpr '&' xpr { $$ = ($1) & ($3); }
  1718. | xpr '*' xpr { $$ = ($1) * ($3); }
  1719. | xpr '/' xpr { $$ = ($1) / ($3); }
  1720. | xpr '^' xpr { $$ = ($1) ^ ($3); }
  1721. | '~' xpr { $$ = ~($2); }
  1722. | '-' xpr %prec pUPM { $$ = -($2); }
  1723. | '+' xpr %prec pUPM { $$ = $2; }
  1724. | '(' xpr ')' { $$ = $2; }
  1725. | any_num { $$ = $1; }
  1726. | tNOT any_num { $$ = ~($2); }
  1727. ;
  1728. any_num : tNUMBER { $$ = $1; }
  1729. | tLNUMBER { $$ = $1; }
  1730. ;
  1731. %%
  1732. /* Dialog specific functions */
  1733. static dialog_t *dialog_style(style_t * st, dialog_t *dlg)
  1734. {
  1735. assert(dlg != NULL);
  1736. if(dlg->style == NULL)
  1737. {
  1738. dlg->style = new_style(0,0);
  1739. }
  1740. if(dlg->gotstyle)
  1741. {
  1742. parser_warning("Style already defined, or-ing together\n");
  1743. }
  1744. else
  1745. {
  1746. dlg->style->or_mask = 0;
  1747. dlg->style->and_mask = 0;
  1748. }
  1749. dlg->style->or_mask |= st->or_mask;
  1750. dlg->style->and_mask |= st->and_mask;
  1751. dlg->gotstyle = TRUE;
  1752. free(st);
  1753. return dlg;
  1754. }
  1755. static dialog_t *dialog_exstyle(style_t *st, dialog_t *dlg)
  1756. {
  1757. assert(dlg != NULL);
  1758. if(dlg->exstyle == NULL)
  1759. {
  1760. dlg->exstyle = new_style(0,0);
  1761. }
  1762. if(dlg->gotexstyle)
  1763. {
  1764. parser_warning("ExStyle already defined, or-ing together\n");
  1765. }
  1766. else
  1767. {
  1768. dlg->exstyle->or_mask = 0;
  1769. dlg->exstyle->and_mask = 0;
  1770. }
  1771. dlg->exstyle->or_mask |= st->or_mask;
  1772. dlg->exstyle->and_mask |= st->and_mask;
  1773. dlg->gotexstyle = TRUE;
  1774. free(st);
  1775. return dlg;
  1776. }
  1777. static dialog_t *dialog_caption(string_t *s, dialog_t *dlg)
  1778. {
  1779. assert(dlg != NULL);
  1780. if(dlg->title)
  1781. yyerror("Caption already defined");
  1782. dlg->title = s;
  1783. return dlg;
  1784. }
  1785. static dialog_t *dialog_font(font_id_t *f, dialog_t *dlg)
  1786. {
  1787. assert(dlg != NULL);
  1788. if(dlg->font)
  1789. yyerror("Font already defined");
  1790. dlg->font = f;
  1791. return dlg;
  1792. }
  1793. static dialog_t *dialog_class(name_id_t *n, dialog_t *dlg)
  1794. {
  1795. assert(dlg != NULL);
  1796. if(dlg->dlgclass)
  1797. yyerror("Class already defined");
  1798. dlg->dlgclass = n;
  1799. return dlg;
  1800. }
  1801. static dialog_t *dialog_menu(name_id_t *m, dialog_t *dlg)
  1802. {
  1803. assert(dlg != NULL);
  1804. if(dlg->menu)
  1805. yyerror("Menu already defined");
  1806. dlg->menu = m;
  1807. return dlg;
  1808. }
  1809. static dialog_t *dialog_language(language_t *l, dialog_t *dlg)
  1810. {
  1811. assert(dlg != NULL);
  1812. if(dlg->lvc.language)
  1813. yyerror("Language already defined");
  1814. dlg->lvc.language = l;
  1815. return dlg;
  1816. }
  1817. static dialog_t *dialog_characteristics(characts_t *c, dialog_t *dlg)
  1818. {
  1819. assert(dlg != NULL);
  1820. if(dlg->lvc.characts)
  1821. yyerror("Characteristics already defined");
  1822. dlg->lvc.characts = c;
  1823. return dlg;
  1824. }
  1825. static dialog_t *dialog_version(version_t *v, dialog_t *dlg)
  1826. {
  1827. assert(dlg != NULL);
  1828. if(dlg->lvc.version)
  1829. yyerror("Version already defined");
  1830. dlg->lvc.version = v;
  1831. return dlg;
  1832. }
  1833. /* Controls specific functions */
  1834. static control_t *ins_ctrl(int type, int special_style, control_t *ctrl, control_t *prev)
  1835. {
  1836. /* Hm... this seems to be jammed in at all time... */
  1837. int defaultstyle = WS_CHILD | WS_VISIBLE;
  1838. assert(ctrl != NULL);
  1839. ctrl->prev = prev;
  1840. if(prev)
  1841. prev->next = ctrl;
  1842. /* Check for duplicate identifiers */
  1843. while (prev)
  1844. {
  1845. if (ctrl->id != -1 && ctrl->id == prev->id)
  1846. parser_warning("Duplicate dialog control id %d\n", ctrl->id);
  1847. prev = prev->prev;
  1848. }
  1849. if(type != -1)
  1850. {
  1851. ctrl->ctlclass = new_name_id();
  1852. ctrl->ctlclass->type = name_ord;
  1853. ctrl->ctlclass->name.i_name = type;
  1854. }
  1855. switch(type)
  1856. {
  1857. case CT_BUTTON:
  1858. if(special_style != BS_GROUPBOX && special_style != BS_RADIOBUTTON)
  1859. defaultstyle |= WS_TABSTOP;
  1860. break;
  1861. case CT_EDIT:
  1862. defaultstyle |= WS_TABSTOP | WS_BORDER;
  1863. break;
  1864. case CT_LISTBOX:
  1865. defaultstyle |= LBS_NOTIFY | WS_BORDER;
  1866. break;
  1867. case CT_COMBOBOX:
  1868. if (!(ctrl->style->or_mask & (CBS_SIMPLE | CBS_DROPDOWN | CBS_DROPDOWNLIST)))
  1869. defaultstyle |= CBS_SIMPLE;
  1870. break;
  1871. case CT_STATIC:
  1872. if(special_style == SS_CENTER || special_style == SS_LEFT || special_style == SS_RIGHT)
  1873. defaultstyle |= WS_GROUP;
  1874. break;
  1875. }
  1876. if(!ctrl->gotstyle) /* Handle default style setting */
  1877. {
  1878. switch(type)
  1879. {
  1880. case CT_EDIT:
  1881. defaultstyle |= ES_LEFT;
  1882. break;
  1883. case CT_LISTBOX:
  1884. defaultstyle |= LBS_NOTIFY;
  1885. break;
  1886. case CT_COMBOBOX:
  1887. defaultstyle |= CBS_SIMPLE | WS_TABSTOP;
  1888. break;
  1889. case CT_SCROLLBAR:
  1890. defaultstyle |= SBS_HORZ;
  1891. break;
  1892. case CT_BUTTON:
  1893. switch(special_style)
  1894. {
  1895. case BS_CHECKBOX:
  1896. case BS_DEFPUSHBUTTON:
  1897. case BS_PUSHBUTTON:
  1898. /* case BS_PUSHBOX: */
  1899. case BS_AUTORADIOBUTTON:
  1900. case BS_AUTO3STATE:
  1901. case BS_3STATE:
  1902. case BS_AUTOCHECKBOX:
  1903. defaultstyle |= WS_TABSTOP;
  1904. break;
  1905. default:
  1906. parser_warning("Unknown default button control-style 0x%08x\n", special_style);
  1907. case BS_GROUPBOX:
  1908. case BS_RADIOBUTTON:
  1909. break;
  1910. }
  1911. break;
  1912. case CT_STATIC:
  1913. switch(special_style)
  1914. {
  1915. case SS_LEFT:
  1916. case SS_RIGHT:
  1917. case SS_CENTER:
  1918. defaultstyle |= WS_GROUP;
  1919. break;
  1920. case SS_ICON: /* Special case */
  1921. break;
  1922. default:
  1923. parser_warning("Unknown default static control-style 0x%08x\n", special_style);
  1924. break;
  1925. }
  1926. break;
  1927. case -1: /* Generic control */
  1928. goto byebye;
  1929. default:
  1930. yyerror("Internal error (report this): Got weird control type 0x%08x", type);
  1931. }
  1932. }
  1933. /* The SS_ICON flag is always forced in for icon controls */
  1934. if(type == CT_STATIC && special_style == SS_ICON)
  1935. defaultstyle |= SS_ICON;
  1936. if (!ctrl->gotstyle)
  1937. ctrl->style = new_style(0,0);
  1938. /* combine all styles */
  1939. ctrl->style->or_mask = ctrl->style->or_mask | defaultstyle | special_style;
  1940. ctrl->gotstyle = TRUE;
  1941. byebye:
  1942. /* combine with NOT mask */
  1943. if (ctrl->gotstyle)
  1944. {
  1945. ctrl->style->or_mask &= ~(ctrl->style->and_mask);
  1946. ctrl->style->and_mask = 0;
  1947. }
  1948. if (ctrl->gotexstyle)
  1949. {
  1950. ctrl->exstyle->or_mask &= ~(ctrl->exstyle->and_mask);
  1951. ctrl->exstyle->and_mask = 0;
  1952. }
  1953. return ctrl;
  1954. }
  1955. static int get_class_idW(const WCHAR *cc)
  1956. {
  1957. static const WCHAR szBUTTON[] = {'B','U','T','T','O','N',0};
  1958. static const WCHAR szCOMBOBOX[] = {'C','O','M','B','O','B','O','X',0};
  1959. static const WCHAR szLISTBOX[] = {'L','I','S','T','B','O','X',0};
  1960. static const WCHAR szEDIT[] = {'E','D','I','T',0};
  1961. static const WCHAR szSTATIC[] = {'S','T','A','T','I','C',0};
  1962. static const WCHAR szSCROLLBAR[] = {'S','C','R','O','L','L','B','A','R',0};
  1963. if(!strcmpiW(szBUTTON, cc))
  1964. return CT_BUTTON;
  1965. if(!strcmpiW(szCOMBOBOX, cc))
  1966. return CT_COMBOBOX;
  1967. if(!strcmpiW(szLISTBOX, cc))
  1968. return CT_LISTBOX;
  1969. if(!strcmpiW(szEDIT, cc))
  1970. return CT_EDIT;
  1971. if(!strcmpiW(szSTATIC, cc))
  1972. return CT_STATIC;
  1973. if(!strcmpiW(szSCROLLBAR, cc))
  1974. return CT_SCROLLBAR;
  1975. return -1;
  1976. }
  1977. static int get_class_idA(const char *cc)
  1978. {
  1979. if(!strcasecmp("BUTTON", cc))
  1980. return CT_BUTTON;
  1981. if(!strcasecmp("COMBOBOX", cc))
  1982. return CT_COMBOBOX;
  1983. if(!strcasecmp("LISTBOX", cc))
  1984. return CT_LISTBOX;
  1985. if(!strcasecmp("EDIT", cc))
  1986. return CT_EDIT;
  1987. if(!strcasecmp("STATIC", cc))
  1988. return CT_STATIC;
  1989. if(!strcasecmp("SCROLLBAR", cc))
  1990. return CT_SCROLLBAR;
  1991. return -1;
  1992. }
  1993. static name_id_t *convert_ctlclass(name_id_t *cls)
  1994. {
  1995. int iclass;
  1996. if(cls->type == name_ord)
  1997. return cls;
  1998. assert(cls->type == name_str);
  1999. if(cls->name.s_name->type == str_unicode)
  2000. iclass = get_class_idW(cls->name.s_name->str.wstr);
  2001. else
  2002. iclass = get_class_idA(cls->name.s_name->str.cstr);
  2003. if (iclass == -1)
  2004. return cls; /* No default, return user controlclass */
  2005. free(cls->name.s_name->str.cstr);
  2006. free(cls->name.s_name);
  2007. cls->type = name_ord;
  2008. cls->name.i_name = iclass;
  2009. return cls;
  2010. }
  2011. /* Accelerator specific functions */
  2012. static event_t *add_event(int key, int id, int flags, event_t *prev)
  2013. {
  2014. event_t *ev = new_event();
  2015. if((flags & (WRC_AF_VIRTKEY | WRC_AF_ASCII)) == (WRC_AF_VIRTKEY | WRC_AF_ASCII))
  2016. yyerror("Cannot use both ASCII and VIRTKEY");
  2017. ev->key = key;
  2018. ev->id = id;
  2019. ev->flags = flags & ~WRC_AF_ASCII;
  2020. ev->prev = prev;
  2021. if(prev)
  2022. prev->next = ev;
  2023. return ev;
  2024. }
  2025. static event_t *add_string_event(string_t *key, int id, int flags, event_t *prev)
  2026. {
  2027. int keycode = 0;
  2028. event_t *ev = new_event();
  2029. if(key->type == str_char)
  2030. {
  2031. if((flags & WRC_AF_VIRTKEY) &&
  2032. !((key->str.cstr[0] >= 'A' && key->str.cstr[0] <= 'Z') ||
  2033. (key->str.cstr[0] >= '0' && key->str.cstr[0] <= '9')))
  2034. yyerror("VIRTKEY code is not equal to ascii value");
  2035. if(key->str.cstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
  2036. {
  2037. yyerror("Cannot use both '^' and CONTROL modifier");
  2038. }
  2039. else if(key->str.cstr[0] == '^')
  2040. {
  2041. keycode = toupper((unsigned char)key->str.cstr[1]) - '@';
  2042. if(keycode >= ' ')
  2043. yyerror("Control-code out of range");
  2044. }
  2045. else
  2046. keycode = key->str.cstr[0];
  2047. }
  2048. else
  2049. {
  2050. if((flags & WRC_AF_VIRTKEY) &&
  2051. !((key->str.wstr[0] >= 'A' && key->str.wstr[0] <= 'Z') ||
  2052. (key->str.wstr[0] >= '0' && key->str.wstr[0] <= '9')))
  2053. yyerror("VIRTKEY code is not equal to ascii value");
  2054. if(key->str.wstr[0] == '^' && (flags & WRC_AF_CONTROL) != 0)
  2055. {
  2056. yyerror("Cannot use both '^' and CONTROL modifier");
  2057. }
  2058. else if(key->str.wstr[0] == '^')
  2059. {
  2060. keycode = toupperW(key->str.wstr[1]) - '@';
  2061. if(keycode >= ' ')
  2062. yyerror("Control-code out of range");
  2063. }
  2064. else
  2065. keycode = key->str.wstr[0];
  2066. }
  2067. ev->key = keycode;
  2068. ev->id = id;
  2069. ev->flags = flags & ~WRC_AF_ASCII;
  2070. ev->prev = prev;
  2071. if(prev)
  2072. prev->next = ev;
  2073. return ev;
  2074. }
  2075. /* MenuEx specific functions */
  2076. static itemex_opt_t *new_itemex_opt(int id, int type, int state, int helpid)
  2077. {
  2078. itemex_opt_t *opt = xmalloc(sizeof(itemex_opt_t));
  2079. memset( opt, 0, sizeof(*opt) );
  2080. opt->id = id;
  2081. opt->type = type;
  2082. opt->state = state;
  2083. opt->helpid = helpid;
  2084. return opt;
  2085. }
  2086. /* Raw data functions */
  2087. static raw_data_t *load_file(string_t *filename, language_t *lang)
  2088. {
  2089. FILE *fp = NULL;
  2090. char *path;
  2091. raw_data_t *rd;
  2092. string_t *name;
  2093. int codepage = get_language_codepage(lang->id, lang->sub);
  2094. /* FIXME: we may want to use utf-8 here */
  2095. if (codepage <= 0 && filename->type != str_char)
  2096. yyerror("Cannot convert filename to ASCII string");
  2097. name = convert_string( filename, str_char, codepage );
  2098. if (!(path = wpp_find_include(name->str.cstr, input_name)))
  2099. yyerror("Cannot open file %s", name->str.cstr);
  2100. if (!(fp = fopen( path, "rb" )))
  2101. yyerror("Cannot open file %s", name->str.cstr);
  2102. free( path );
  2103. rd = new_raw_data();
  2104. fseek(fp, 0, SEEK_END);
  2105. rd->size = ftell(fp);
  2106. fseek(fp, 0, SEEK_SET);
  2107. if (rd->size)
  2108. {
  2109. rd->data = xmalloc(rd->size);
  2110. fread(rd->data, rd->size, 1, fp);
  2111. }
  2112. else rd->data = NULL;
  2113. fclose(fp);
  2114. rd->lvc.language = lang;
  2115. free_string(name);
  2116. return rd;
  2117. }
  2118. static raw_data_t *int2raw_data(int i)
  2119. {
  2120. raw_data_t *rd;
  2121. if( ( i >= 0 && (int)((unsigned short)i) != i) ||
  2122. ( i < 0 && (int)((short)i) != i) )
  2123. parser_warning("Integer constant out of 16bit range (%d), truncated to %d\n", i, (short)i);
  2124. rd = new_raw_data();
  2125. rd->size = sizeof(short);
  2126. rd->data = xmalloc(rd->size);
  2127. switch(byteorder)
  2128. {
  2129. #ifdef WORDS_BIGENDIAN
  2130. default:
  2131. #endif
  2132. case WRC_BO_BIG:
  2133. rd->data[0] = HIBYTE(i);
  2134. rd->data[1] = LOBYTE(i);
  2135. break;
  2136. #ifndef WORDS_BIGENDIAN
  2137. default:
  2138. #endif
  2139. case WRC_BO_LITTLE:
  2140. rd->data[1] = HIBYTE(i);
  2141. rd->data[0] = LOBYTE(i);
  2142. break;
  2143. }
  2144. return rd;
  2145. }
  2146. static raw_data_t *long2raw_data(int i)
  2147. {
  2148. raw_data_t *rd;
  2149. rd = new_raw_data();
  2150. rd->size = sizeof(int);
  2151. rd->data = xmalloc(rd->size);
  2152. switch(byteorder)
  2153. {
  2154. #ifdef WORDS_BIGENDIAN
  2155. default:
  2156. #endif
  2157. case WRC_BO_BIG:
  2158. rd->data[0] = HIBYTE(HIWORD(i));
  2159. rd->data[1] = LOBYTE(HIWORD(i));
  2160. rd->data[2] = HIBYTE(LOWORD(i));
  2161. rd->data[3] = LOBYTE(LOWORD(i));
  2162. break;
  2163. #ifndef WORDS_BIGENDIAN
  2164. default:
  2165. #endif
  2166. case WRC_BO_LITTLE:
  2167. rd->data[3] = HIBYTE(HIWORD(i));
  2168. rd->data[2] = LOBYTE(HIWORD(i));
  2169. rd->data[1] = HIBYTE(LOWORD(i));
  2170. rd->data[0] = LOBYTE(LOWORD(i));
  2171. break;
  2172. }
  2173. return rd;
  2174. }
  2175. static raw_data_t *str2raw_data(string_t *str)
  2176. {
  2177. raw_data_t *rd;
  2178. rd = new_raw_data();
  2179. rd->size = str->size * (str->type == str_char ? 1 : 2);
  2180. rd->data = xmalloc(rd->size);
  2181. if(str->type == str_char)
  2182. memcpy(rd->data, str->str.cstr, rd->size);
  2183. else if(str->type == str_unicode)
  2184. {
  2185. int i;
  2186. switch(byteorder)
  2187. {
  2188. #ifdef WORDS_BIGENDIAN
  2189. default:
  2190. #endif
  2191. case WRC_BO_BIG:
  2192. for(i = 0; i < str->size; i++)
  2193. {
  2194. rd->data[2*i + 0] = HIBYTE((WORD)str->str.wstr[i]);
  2195. rd->data[2*i + 1] = LOBYTE((WORD)str->str.wstr[i]);
  2196. }
  2197. break;
  2198. #ifndef WORDS_BIGENDIAN
  2199. default:
  2200. #endif
  2201. case WRC_BO_LITTLE:
  2202. for(i = 0; i < str->size; i++)
  2203. {
  2204. rd->data[2*i + 1] = HIBYTE((WORD)str->str.wstr[i]);
  2205. rd->data[2*i + 0] = LOBYTE((WORD)str->str.wstr[i]);
  2206. }
  2207. break;
  2208. }
  2209. }
  2210. else
  2211. internal_error(__FILE__, __LINE__, "Invalid stringtype\n");
  2212. return rd;
  2213. }
  2214. static raw_data_t *merge_raw_data(raw_data_t *r1, raw_data_t *r2)
  2215. {
  2216. r1->data = xrealloc(r1->data, r1->size + r2->size);
  2217. memcpy(r1->data + r1->size, r2->data, r2->size);
  2218. r1->size += r2->size;
  2219. return r1;
  2220. }
  2221. static raw_data_t *merge_raw_data_int(raw_data_t *r1, int i)
  2222. {
  2223. raw_data_t *t = int2raw_data(i);
  2224. merge_raw_data(r1, t);
  2225. free(t->data);
  2226. free(t);
  2227. return r1;
  2228. }
  2229. static raw_data_t *merge_raw_data_long(raw_data_t *r1, int i)
  2230. {
  2231. raw_data_t *t = long2raw_data(i);
  2232. merge_raw_data(r1, t);
  2233. free(t->data);
  2234. free(t);
  2235. return r1;
  2236. }
  2237. static raw_data_t *merge_raw_data_str(raw_data_t *r1, string_t *str)
  2238. {
  2239. raw_data_t *t = str2raw_data(str);
  2240. merge_raw_data(r1, t);
  2241. free(t->data);
  2242. free(t);
  2243. return r1;
  2244. }
  2245. /* Function the go back in a list to get the head */
  2246. static menu_item_t *get_item_head(menu_item_t *p)
  2247. {
  2248. if(!p)
  2249. return NULL;
  2250. while(p->prev)
  2251. p = p->prev;
  2252. return p;
  2253. }
  2254. static resource_t *get_resource_head(resource_t *p)
  2255. {
  2256. if(!p)
  2257. return NULL;
  2258. while(p->prev)
  2259. p = p->prev;
  2260. return p;
  2261. }
  2262. static ver_block_t *get_ver_block_head(ver_block_t *p)
  2263. {
  2264. if(!p)
  2265. return NULL;
  2266. while(p->prev)
  2267. p = p->prev;
  2268. return p;
  2269. }
  2270. static ver_value_t *get_ver_value_head(ver_value_t *p)
  2271. {
  2272. if(!p)
  2273. return NULL;
  2274. while(p->prev)
  2275. p = p->prev;
  2276. return p;
  2277. }
  2278. static control_t *get_control_head(control_t *p)
  2279. {
  2280. if(!p)
  2281. return NULL;
  2282. while(p->prev)
  2283. p = p->prev;
  2284. return p;
  2285. }
  2286. static event_t *get_event_head(event_t *p)
  2287. {
  2288. if(!p)
  2289. return NULL;
  2290. while(p->prev)
  2291. p = p->prev;
  2292. return p;
  2293. }
  2294. /* Find a stringtable with given language */
  2295. static stringtable_t *find_stringtable(lvc_t *lvc)
  2296. {
  2297. stringtable_t *stt;
  2298. assert(lvc != NULL);
  2299. if(!lvc->language)
  2300. lvc->language = dup_language(currentlanguage);
  2301. for(stt = sttres; stt; stt = stt->next)
  2302. {
  2303. if(stt->lvc.language->id == lvc->language->id
  2304. && stt->lvc.language->sub == lvc->language->sub)
  2305. {
  2306. /* Found a table with the same language */
  2307. /* The version and characteristics are now handled
  2308. * in the generation of the individual stringtables.
  2309. * This enables localized analysis.
  2310. if((stt->lvc.version && lvc->version && *(stt->lvc.version) != *(lvc->version))
  2311. || (!stt->lvc.version && lvc->version)
  2312. || (stt->lvc.version && !lvc->version))
  2313. parser_warning("Stringtable's versions are not the same, using first definition\n");
  2314. if((stt->lvc.characts && lvc->characts && *(stt->lvc.characts) != *(lvc->characts))
  2315. || (!stt->lvc.characts && lvc->characts)
  2316. || (stt->lvc.characts && !lvc->characts))
  2317. parser_warning("Stringtable's characteristics are not the same, using first definition\n");
  2318. */
  2319. return stt;
  2320. }
  2321. }
  2322. return NULL;
  2323. }
  2324. /* qsort sorting function for string table entries */
  2325. #define STE(p) ((const stt_entry_t *)(p))
  2326. static int sort_stt_entry(const void *e1, const void *e2)
  2327. {
  2328. return STE(e1)->id - STE(e2)->id;
  2329. }
  2330. #undef STE
  2331. static resource_t *build_stt_resources(stringtable_t *stthead)
  2332. {
  2333. stringtable_t *stt;
  2334. stringtable_t *newstt;
  2335. resource_t *rsc;
  2336. resource_t *rsclist = NULL;
  2337. resource_t *rsctail = NULL;
  2338. int i;
  2339. int j;
  2340. DWORD andsum;
  2341. DWORD orsum;
  2342. characts_t *characts;
  2343. version_t *version;
  2344. if(!stthead)
  2345. return NULL;
  2346. /* For all languages defined */
  2347. for(stt = stthead; stt; stt = stt->next)
  2348. {
  2349. assert(stt->nentries > 0);
  2350. /* Sort the entries */
  2351. if(stt->nentries > 1)
  2352. qsort(stt->entries, stt->nentries, sizeof(stt->entries[0]), sort_stt_entry);
  2353. for(i = 0; i < stt->nentries; )
  2354. {
  2355. newstt = new_stringtable(&stt->lvc);
  2356. newstt->entries = xmalloc(16 * sizeof(stt_entry_t));
  2357. memset( newstt->entries, 0, 16 * sizeof(stt_entry_t) );
  2358. newstt->nentries = 16;
  2359. newstt->idbase = stt->entries[i].id & ~0xf;
  2360. for(j = 0; j < 16 && i < stt->nentries; j++)
  2361. {
  2362. if(stt->entries[i].id - newstt->idbase == j)
  2363. {
  2364. newstt->entries[j] = stt->entries[i];
  2365. i++;
  2366. }
  2367. }
  2368. andsum = ~0;
  2369. orsum = 0;
  2370. characts = NULL;
  2371. version = NULL;
  2372. /* Check individual memory options and get
  2373. * the first characteristics/version
  2374. */
  2375. for(j = 0; j < 16; j++)
  2376. {
  2377. if(!newstt->entries[j].str)
  2378. continue;
  2379. andsum &= newstt->entries[j].memopt;
  2380. orsum |= newstt->entries[j].memopt;
  2381. if(!characts)
  2382. characts = newstt->entries[j].characts;
  2383. if(!version)
  2384. version = newstt->entries[j].version;
  2385. }
  2386. if(andsum != orsum)
  2387. {
  2388. warning("Stringtable's memory options are not equal (idbase: %d)\n", newstt->idbase);
  2389. }
  2390. /* Check version and characteristics */
  2391. for(j = 0; j < 16; j++)
  2392. {
  2393. if(characts
  2394. && newstt->entries[j].characts
  2395. && *newstt->entries[j].characts != *characts)
  2396. warning("Stringtable's characteristics are not the same (idbase: %d)\n", newstt->idbase);
  2397. if(version
  2398. && newstt->entries[j].version
  2399. && *newstt->entries[j].version != *version)
  2400. warning("Stringtable's versions are not the same (idbase: %d)\n", newstt->idbase);
  2401. }
  2402. rsc = new_resource(res_stt, newstt, newstt->memopt, newstt->lvc.language);
  2403. rsc->name = new_name_id();
  2404. rsc->name->type = name_ord;
  2405. rsc->name->name.i_name = (newstt->idbase >> 4) + 1;
  2406. rsc->memopt = andsum; /* Set to least common denominator */
  2407. newstt->memopt = andsum;
  2408. newstt->lvc.characts = characts;
  2409. newstt->lvc.version = version;
  2410. if(!rsclist)
  2411. {
  2412. rsclist = rsc;
  2413. rsctail = rsc;
  2414. }
  2415. else
  2416. {
  2417. rsctail->next = rsc;
  2418. rsc->prev = rsctail;
  2419. rsctail = rsc;
  2420. }
  2421. }
  2422. }
  2423. return rsclist;
  2424. }
  2425. static toolbar_item_t *ins_tlbr_button(toolbar_item_t *prev, toolbar_item_t *idrec)
  2426. {
  2427. idrec->prev = prev;
  2428. if(prev)
  2429. prev->next = idrec;
  2430. return idrec;
  2431. }
  2432. static toolbar_item_t *get_tlbr_buttons_head(toolbar_item_t *p, int *nitems)
  2433. {
  2434. if(!p)
  2435. {
  2436. *nitems = 0;
  2437. return NULL;
  2438. }
  2439. *nitems = 1;
  2440. while(p->prev)
  2441. {
  2442. (*nitems)++;
  2443. p = p->prev;
  2444. }
  2445. return p;
  2446. }
  2447. static string_t *make_filename(string_t *str)
  2448. {
  2449. if(str->type == str_char)
  2450. {
  2451. char *cptr;
  2452. /* Remove escaped backslash and convert to forward */
  2453. for(cptr = str->str.cstr; (cptr = strchr(cptr, '\\')) != NULL; cptr++)
  2454. {
  2455. if(cptr[1] == '\\')
  2456. {
  2457. memmove(cptr, cptr+1, strlen(cptr));
  2458. str->size--;
  2459. }
  2460. *cptr = '/';
  2461. }
  2462. }
  2463. else
  2464. {
  2465. WCHAR *wptr;
  2466. /* Remove escaped backslash and convert to forward */
  2467. for(wptr = str->str.wstr; (wptr = strchrW(wptr, '\\')) != NULL; wptr++)
  2468. {
  2469. if(wptr[1] == '\\')
  2470. {
  2471. memmove(wptr, wptr+1, strlenW(wptr));
  2472. str->size--;
  2473. }
  2474. *wptr = '/';
  2475. }
  2476. }
  2477. return str;
  2478. }
  2479. /*
  2480. * Process all resources to extract fonts and build
  2481. * a fontdir resource.
  2482. *
  2483. * Note: MS' resource compiler (build 1472) does not
  2484. * handle font resources with different languages.
  2485. * The fontdir is generated in the last active language
  2486. * and font identifiers must be unique across the entire
  2487. * source.
  2488. * This is not logical considering the localization
  2489. * constraints of all other resource types. MS has,
  2490. * most probably, never testet localized fonts. However,
  2491. * using fontresources is rare, so it might not occur
  2492. * in normal applications.
  2493. * Wine does require better localization because a lot
  2494. * of languages are coded into the same executable.
  2495. * Therefore, I will generate fontdirs for *each*
  2496. * localized set of fonts.
  2497. */
  2498. static resource_t *build_fontdir(resource_t **fnt, int nfnt)
  2499. {
  2500. static int once = 0;
  2501. if(!once)
  2502. {
  2503. warning("Need to parse fonts, not yet implemented (fnt: %p, nfnt: %d)\n", fnt, nfnt);
  2504. once++;
  2505. }
  2506. return NULL;
  2507. }
  2508. static resource_t *build_fontdirs(resource_t *tail)
  2509. {
  2510. resource_t *rsc;
  2511. resource_t *lst = NULL;
  2512. resource_t **fnt = NULL; /* List of all fonts */
  2513. int nfnt = 0;
  2514. resource_t **fnd = NULL; /* List of all fontdirs */
  2515. int nfnd = 0;
  2516. resource_t **lanfnt = NULL;
  2517. int nlanfnt = 0;
  2518. int i;
  2519. name_id_t nid;
  2520. string_t str;
  2521. int fntleft;
  2522. nid.type = name_str;
  2523. nid.name.s_name = &str;
  2524. str.type = str_char;
  2525. str.str.cstr = xstrdup("FONTDIR");
  2526. str.size = 7;
  2527. /* Extract all fonts and fontdirs */
  2528. for(rsc = tail; rsc; rsc = rsc->prev)
  2529. {
  2530. if(rsc->type == res_fnt)
  2531. {
  2532. nfnt++;
  2533. fnt = xrealloc(fnt, nfnt * sizeof(*fnt));
  2534. fnt[nfnt-1] = rsc;
  2535. }
  2536. else if(rsc->type == res_fntdir)
  2537. {
  2538. nfnd++;
  2539. fnd = xrealloc(fnd, nfnd * sizeof(*fnd));
  2540. fnd[nfnd-1] = rsc;
  2541. }
  2542. }
  2543. /* Verify the name of the present fontdirs */
  2544. for(i = 0; i < nfnd; i++)
  2545. {
  2546. if(compare_name_id(&nid, fnd[i]->name))
  2547. {
  2548. warning("User supplied FONTDIR entry has an invalid name '%s', ignored\n",
  2549. get_nameid_str(fnd[i]->name));
  2550. fnd[i] = NULL;
  2551. }
  2552. }
  2553. /* Sanity check */
  2554. if(nfnt == 0)
  2555. {
  2556. if(nfnd != 0)
  2557. warning("Found %d FONTDIR entries without any fonts present\n", nfnd);
  2558. goto clean;
  2559. }
  2560. /* Copy space */
  2561. lanfnt = xmalloc(nfnt * sizeof(*lanfnt));
  2562. memset( lanfnt, 0, nfnt * sizeof(*lanfnt));
  2563. /* Get all fonts covered by fontdirs */
  2564. for(i = 0; i < nfnd; i++)
  2565. {
  2566. int j;
  2567. WORD cnt;
  2568. int isswapped = 0;
  2569. if(!fnd[i])
  2570. continue;
  2571. for(j = 0; j < nfnt; j++)
  2572. {
  2573. if(!fnt[j])
  2574. continue;
  2575. if(fnt[j]->lan->id == fnd[i]->lan->id && fnt[j]->lan->sub == fnd[i]->lan->sub)
  2576. {
  2577. lanfnt[nlanfnt] = fnt[j];
  2578. nlanfnt++;
  2579. fnt[j] = NULL;
  2580. }
  2581. }
  2582. cnt = *(WORD *)fnd[i]->res.fnd->data->data;
  2583. if(nlanfnt == cnt)
  2584. isswapped = 0;
  2585. else if(nlanfnt == BYTESWAP_WORD(cnt))
  2586. isswapped = 1;
  2587. else
  2588. error("FONTDIR for language %d,%d has wrong count (%d, expected %d)\n",
  2589. fnd[i]->lan->id, fnd[i]->lan->sub, cnt, nlanfnt);
  2590. #ifdef WORDS_BIGENDIAN
  2591. if((byteorder == WRC_BO_LITTLE && !isswapped) || (byteorder != WRC_BO_LITTLE && isswapped))
  2592. #else
  2593. if((byteorder == WRC_BO_BIG && !isswapped) || (byteorder != WRC_BO_BIG && isswapped))
  2594. #endif
  2595. {
  2596. internal_error(__FILE__, __LINE__, "User supplied FONTDIR needs byteswapping\n");
  2597. }
  2598. }
  2599. /* We now have fonts left where we need to make a fontdir resource */
  2600. for(i = fntleft = 0; i < nfnt; i++)
  2601. {
  2602. if(fnt[i])
  2603. fntleft++;
  2604. }
  2605. while(fntleft)
  2606. {
  2607. /* Get fonts of same language in lanfnt[] */
  2608. for(i = nlanfnt = 0; i < nfnt; i++)
  2609. {
  2610. if(fnt[i])
  2611. {
  2612. if(!nlanfnt)
  2613. {
  2614. addlanfnt:
  2615. lanfnt[nlanfnt] = fnt[i];
  2616. nlanfnt++;
  2617. fnt[i] = NULL;
  2618. fntleft--;
  2619. }
  2620. else if(fnt[i]->lan->id == lanfnt[0]->lan->id && fnt[i]->lan->sub == lanfnt[0]->lan->sub)
  2621. goto addlanfnt;
  2622. }
  2623. }
  2624. /* and build a fontdir */
  2625. rsc = build_fontdir(lanfnt, nlanfnt);
  2626. if(rsc)
  2627. {
  2628. if(lst)
  2629. {
  2630. lst->next = rsc;
  2631. rsc->prev = lst;
  2632. }
  2633. lst = rsc;
  2634. }
  2635. }
  2636. free(lanfnt);
  2637. clean:
  2638. free(fnt);
  2639. free(fnd);
  2640. free(str.str.cstr);
  2641. return lst;
  2642. }
  2643. /*
  2644. * This gets invoked to determine whether the next resource
  2645. * is to be of a standard-type (e.g. bitmaps etc.), or should
  2646. * be a user-type resource. This function is required because
  2647. * there is the _possibility_ of a lookahead token in the
  2648. * parser, which is generated from the "expr" state in the
  2649. * "nameid" parsing.
  2650. *
  2651. * The general resource format is:
  2652. * <identifier> <type> <flags> <resourcebody>
  2653. *
  2654. * The <identifier> can either be tIDENT or "expr". The latter
  2655. * will always generate a lookahead, which is the <type> of the
  2656. * resource to parse. Otherwise, we need to get a new token from
  2657. * the scanner to determine the next step.
  2658. *
  2659. * The problem arrises when <type> is numerical. This case should
  2660. * map onto default resource-types and be parsed as such instead
  2661. * of being mapped onto user-type resources.
  2662. *
  2663. * The trick lies in the fact that yacc (bison) doesn't care about
  2664. * intermediate changes of the lookahead while reducing a rule. We
  2665. * simply replace the lookahead with a token that will result in
  2666. * a shift to the appropriate rule for the specific resource-type.
  2667. */
  2668. static int rsrcid_to_token(int lookahead)
  2669. {
  2670. int token;
  2671. /* Get a token if we don't have one yet */
  2672. if(lookahead == YYEMPTY)
  2673. lookahead = YYLEX;
  2674. /* Only numbers are possibly interesting */
  2675. switch(lookahead)
  2676. {
  2677. case tNUMBER:
  2678. case tLNUMBER:
  2679. break;
  2680. default:
  2681. return lookahead;
  2682. }
  2683. token = lookahead;
  2684. switch(yylval.num)
  2685. {
  2686. case WRC_RT_CURSOR:
  2687. token = tCURSOR;
  2688. break;
  2689. case WRC_RT_ICON:
  2690. token = tICON;
  2691. break;
  2692. case WRC_RT_BITMAP:
  2693. token = tBITMAP;
  2694. break;
  2695. case WRC_RT_FONT:
  2696. token = tFONT;
  2697. break;
  2698. case WRC_RT_FONTDIR:
  2699. token = tFONTDIR;
  2700. break;
  2701. case WRC_RT_RCDATA:
  2702. token = tRCDATA;
  2703. break;
  2704. case WRC_RT_MESSAGETABLE:
  2705. token = tMESSAGETABLE;
  2706. break;
  2707. case WRC_RT_DLGINIT:
  2708. token = tDLGINIT;
  2709. break;
  2710. case WRC_RT_ACCELERATOR:
  2711. token = tACCELERATORS;
  2712. break;
  2713. case WRC_RT_MENU:
  2714. token = tMENU;
  2715. break;
  2716. case WRC_RT_DIALOG:
  2717. token = tDIALOG;
  2718. break;
  2719. case WRC_RT_VERSION:
  2720. token = tVERSIONINFO;
  2721. break;
  2722. case WRC_RT_TOOLBAR:
  2723. token = tTOOLBAR;
  2724. break;
  2725. case WRC_RT_HTML:
  2726. token = tHTML;
  2727. break;
  2728. case WRC_RT_STRING:
  2729. break;
  2730. case WRC_RT_ANICURSOR:
  2731. case WRC_RT_ANIICON:
  2732. case WRC_RT_GROUP_CURSOR:
  2733. case WRC_RT_GROUP_ICON:
  2734. parser_warning("Usertype uses reserved type ID %d, which is auto-generated\n", yylval.num);
  2735. return lookahead;
  2736. case WRC_RT_DLGINCLUDE:
  2737. case WRC_RT_PLUGPLAY:
  2738. case WRC_RT_VXD:
  2739. parser_warning("Usertype uses reserved type ID %d, which is not supported by wrc yet\n", yylval.num);
  2740. default:
  2741. return lookahead;
  2742. }
  2743. return token;
  2744. }