rclex.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. /* rclex.c -- lexer for Windows rc files parser */
  2. /* Copyright (C) 1997-2015 Free Software Foundation, Inc.
  3. Written by Kai Tietz, Onevision.
  4. This file is part of GNU Binutils.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
  16. 02110-1301, USA. */
  17. /* This is a lexer used by the Windows rc file parser. It basically
  18. just recognized a bunch of keywords. */
  19. #include "sysdep.h"
  20. #include "bfd.h"
  21. #include "bucomm.h"
  22. #include "libiberty.h"
  23. #include "safe-ctype.h"
  24. #include "windres.h"
  25. #include "rcparse.h"
  26. #include <assert.h>
  27. /* Whether we are in rcdata mode, in which we returns the lengths of
  28. strings. */
  29. static int rcdata_mode;
  30. /* Whether we are supressing lines from cpp (including windows.h or
  31. headers from your C sources may bring in externs and typedefs).
  32. When active, we return IGNORED_TOKEN, which lets us ignore these
  33. outside of resource constructs. Thus, it isn't required to protect
  34. all the non-preprocessor lines in your header files with #ifdef
  35. RC_INVOKED. It also means your RC file can't include other RC
  36. files if they're named "*.h". Sorry. Name them *.rch or whatever. */
  37. static int suppress_cpp_data;
  38. #define IGNORE_CPP(x) (suppress_cpp_data ? IGNORED_TOKEN : (x))
  39. /* The first filename we detect in the cpp output. We use this to
  40. tell included files from the original file. */
  41. static char *initial_fn;
  42. /* List of allocated strings. */
  43. struct alloc_string
  44. {
  45. struct alloc_string *next;
  46. char *s;
  47. };
  48. static struct alloc_string *strings;
  49. struct rclex_keywords
  50. {
  51. const char *name;
  52. int tok;
  53. };
  54. #define K(KEY) { #KEY, KEY }
  55. #define KRT(KEY) { #KEY, RT_##KEY }
  56. static const struct rclex_keywords keywds[] =
  57. {
  58. K(ACCELERATORS), K(ALT), K(ANICURSOR), K(ANIICON), K(ASCII),
  59. K(AUTO3STATE), K(AUTOCHECKBOX), K(AUTORADIOBUTTON),
  60. K(BEDIT), { "BEGIN", BEG }, K(BITMAP), K(BLOCK), K(BUTTON),
  61. K(CAPTION), K(CHARACTERISTICS), K(CHECKBOX), K(CHECKED),
  62. K(CLASS), K(COMBOBOX), K(CONTROL), K(CTEXT), K(CURSOR),
  63. K(DEFPUSHBUTTON), K(DIALOG), K(DIALOGEX), K(DISCARDABLE),
  64. K(DLGINCLUDE), K(DLGINIT),
  65. K(EDITTEXT), K(END), K(EXSTYLE),
  66. K(FILEFLAGS), K(FILEFLAGSMASK), K(FILEOS), K(FILESUBTYPE),
  67. K(FILETYPE), K(FILEVERSION), K(FIXED), K(FONT), K(FONTDIR),
  68. K(GRAYED), KRT(GROUP_CURSOR), KRT(GROUP_ICON), K(GROUPBOX),
  69. K(HEDIT), K(HELP), K(HTML),
  70. K(ICON), K(IEDIT), K(IMPURE), K(INACTIVE),
  71. K(LANGUAGE), K(LISTBOX), K(LOADONCALL), K(LTEXT),
  72. K(MANIFEST), K(MENU), K(MENUBARBREAK), K(MENUBREAK),
  73. K(MENUEX), K(MENUITEM), K(MESSAGETABLE), K(MOVEABLE),
  74. K(NOINVERT), K(NOT),
  75. K(PLUGPLAY), K(POPUP), K(PRELOAD), K(PRODUCTVERSION),
  76. K(PURE), K(PUSHBOX), K(PUSHBUTTON),
  77. K(RADIOBUTTON), K(RCDATA), K(RTEXT),
  78. K(SCROLLBAR), K(SEPARATOR), K(SHIFT), K(STATE3),
  79. K(STRINGTABLE), K(STYLE),
  80. K(TOOLBAR),
  81. K(USERBUTTON),
  82. K(VALUE), { "VERSION", VERSIONK }, K(VERSIONINFO),
  83. K(VIRTKEY), K(VXD),
  84. { NULL, 0 },
  85. };
  86. /* External input stream from resrc */
  87. extern FILE *cpp_pipe;
  88. /* Lexical scanner helpers. */
  89. static int rclex_lastch = -1;
  90. static size_t rclex_tok_max = 0;
  91. static size_t rclex_tok_pos = 0;
  92. static char *rclex_tok = NULL;
  93. static int
  94. rclex_translatekeyword (const char *key)
  95. {
  96. if (key && ISUPPER (key[0]))
  97. {
  98. const struct rclex_keywords *kw = &keywds[0];
  99. do
  100. {
  101. if (! strcmp (kw->name, key))
  102. return kw->tok;
  103. ++kw;
  104. }
  105. while (kw->name != NULL);
  106. }
  107. return STRING;
  108. }
  109. /* Handle a C preprocessor line. */
  110. static void
  111. cpp_line (void)
  112. {
  113. const char *s = rclex_tok;
  114. int line;
  115. char *send, *fn;
  116. size_t len, mlen;
  117. ++s;
  118. while (ISSPACE (*s))
  119. ++s;
  120. /* Check for #pragma code_page ( DEFAULT | <nr>). */
  121. len = strlen (s);
  122. mlen = strlen ("pragma");
  123. if (len > mlen && memcmp (s, "pragma", mlen) == 0 && ISSPACE (s[mlen]))
  124. {
  125. const char *end;
  126. s += mlen + 1;
  127. while (ISSPACE (*s))
  128. ++s;
  129. len = strlen (s);
  130. mlen = strlen ("code_page");
  131. if (len <= mlen || memcmp (s, "code_page", mlen) != 0)
  132. /* FIXME: We ought to issue a warning message about an unrecognised pragma. */
  133. return;
  134. s += mlen;
  135. while (ISSPACE (*s))
  136. ++s;
  137. if (*s != '(')
  138. /* FIXME: We ought to issue an error message about a malformed pragma. */
  139. return;
  140. ++s;
  141. while (ISSPACE (*s))
  142. ++s;
  143. if (*s == 0 || (end = strchr (s, ')')) == NULL)
  144. /* FIXME: We ought to issue an error message about a malformed pragma. */
  145. return;
  146. len = (size_t) (end - s);
  147. fn = xmalloc (len + 1);
  148. if (len)
  149. memcpy (fn, s, len);
  150. fn[len] = 0;
  151. while (len > 0 && (fn[len - 1] > 0 && fn[len - 1] <= 0x20))
  152. fn[--len] = 0;
  153. if (! len || (len == strlen ("DEFAULT") && strcasecmp (fn, "DEFAULT") == 0))
  154. wind_current_codepage = wind_default_codepage;
  155. else if (len > 0)
  156. {
  157. rc_uint_type ncp;
  158. if (fn[0] == '0' && (fn[1] == 'x' || fn[1] == 'X'))
  159. ncp = (rc_uint_type) strtol (fn + 2, NULL, 16);
  160. else
  161. ncp = (rc_uint_type) strtol (fn, NULL, 10);
  162. if (ncp == CP_UTF16 || ! unicode_is_valid_codepage (ncp))
  163. fatal (_("invalid value specified for pragma code_page.\n"));
  164. wind_current_codepage = ncp;
  165. }
  166. free (fn);
  167. return;
  168. }
  169. line = strtol (s, &send, 0);
  170. if (*send != '\0' && ! ISSPACE (*send))
  171. return;
  172. /* Subtract 1 because we are about to count the newline. */
  173. rc_lineno = line - 1;
  174. s = send;
  175. while (ISSPACE (*s))
  176. ++s;
  177. if (*s != '"')
  178. return;
  179. ++s;
  180. send = strchr (s, '"');
  181. if (send == NULL)
  182. return;
  183. fn = xmalloc (send - s + 1);
  184. strncpy (fn, s, send - s);
  185. fn[send - s] = '\0';
  186. free (rc_filename);
  187. rc_filename = fn;
  188. if (! initial_fn)
  189. {
  190. initial_fn = xmalloc (strlen (fn) + 1);
  191. strcpy (initial_fn, fn);
  192. }
  193. /* Allow the initial file, regardless of name. Suppress all other
  194. files if they end in ".h" (this allows included "*.rc"). */
  195. if (strcmp (initial_fn, fn) == 0
  196. || strcmp (fn + strlen (fn) - 2, ".h") != 0)
  197. suppress_cpp_data = 0;
  198. else
  199. suppress_cpp_data = 1;
  200. }
  201. /* Allocate a string of a given length. */
  202. static char *
  203. get_string (int len)
  204. {
  205. struct alloc_string *as;
  206. as = xmalloc (sizeof *as);
  207. as->s = xmalloc (len);
  208. as->next = strings;
  209. strings = as;
  210. return as->s;
  211. }
  212. /* Handle a quoted string. The quotes are stripped. A pair of quotes
  213. in a string are turned into a single quote. Adjacent strings are
  214. merged separated by whitespace are merged, as in C. */
  215. static char *
  216. handle_quotes (rc_uint_type *len)
  217. {
  218. const char *input = rclex_tok;
  219. char *ret, *s;
  220. const char *t;
  221. int ch;
  222. int num_xdigits;
  223. ret = get_string (strlen (input) + 1);
  224. s = ret;
  225. t = input;
  226. if (*t == '"')
  227. ++t;
  228. while (*t != '\0')
  229. {
  230. if (*t == '\\')
  231. {
  232. ++t;
  233. switch (*t)
  234. {
  235. case '\0':
  236. rcparse_warning ("backslash at end of string");
  237. break;
  238. case '\"':
  239. rcparse_warning ("use \"\" to put \" in a string");
  240. *s++ = '"';
  241. ++t;
  242. break;
  243. case 'a':
  244. *s++ = ESCAPE_B; /* Strange, but true... */
  245. ++t;
  246. break;
  247. case 'b':
  248. *s++ = ESCAPE_B;
  249. ++t;
  250. break;
  251. case 'f':
  252. *s++ = ESCAPE_F;
  253. ++t;
  254. break;
  255. case 'n':
  256. *s++ = ESCAPE_N;
  257. ++t;
  258. break;
  259. case 'r':
  260. *s++ = ESCAPE_R;
  261. ++t;
  262. break;
  263. case 't':
  264. *s++ = ESCAPE_T;
  265. ++t;
  266. break;
  267. case 'v':
  268. *s++ = ESCAPE_V;
  269. ++t;
  270. break;
  271. case '\\':
  272. *s++ = *t++;
  273. break;
  274. case '0': case '1': case '2': case '3':
  275. case '4': case '5': case '6': case '7':
  276. ch = *t - '0';
  277. ++t;
  278. if (*t >= '0' && *t <= '7')
  279. {
  280. ch = (ch << 3) | (*t - '0');
  281. ++t;
  282. if (*t >= '0' && *t <= '7')
  283. {
  284. ch = (ch << 3) | (*t - '0');
  285. ++t;
  286. }
  287. }
  288. *s++ = ch;
  289. break;
  290. case 'x': case 'X':
  291. ++t;
  292. ch = 0;
  293. /* We only handle single byte chars here. Make sure
  294. we finish an escape sequence like "/xB0ABC" after
  295. the first two digits. */
  296. num_xdigits = 2;
  297. while (num_xdigits--)
  298. {
  299. if (*t >= '0' && *t <= '9')
  300. ch = (ch << 4) | (*t - '0');
  301. else if (*t >= 'a' && *t <= 'f')
  302. ch = (ch << 4) | (*t - 'a' + 10);
  303. else if (*t >= 'A' && *t <= 'F')
  304. ch = (ch << 4) | (*t - 'A' + 10);
  305. else
  306. break;
  307. ++t;
  308. }
  309. *s++ = ch;
  310. break;
  311. default:
  312. rcparse_warning ("unrecognized escape sequence");
  313. *s++ = '\\';
  314. *s++ = *t++;
  315. break;
  316. }
  317. }
  318. else if (*t != '"')
  319. *s++ = *t++;
  320. else if (t[1] == '\0')
  321. break;
  322. else if (t[1] == '"')
  323. {
  324. *s++ = '"';
  325. t += 2;
  326. }
  327. else
  328. {
  329. ++t;
  330. if (! ISSPACE (*t))
  331. rcparse_warning ("unexpected character after '\"'");
  332. while (ISSPACE (*t))
  333. {
  334. if ((*t) == '\n')
  335. ++rc_lineno;
  336. ++t;
  337. }
  338. if (*t == '\0')
  339. break;
  340. assert (*t == '"');
  341. ++t;
  342. }
  343. }
  344. *s = '\0';
  345. *len = s - ret;
  346. return ret;
  347. }
  348. /* Allocate a unicode string of a given length. */
  349. static unichar *
  350. get_unistring (int len)
  351. {
  352. return (unichar *) get_string (len * sizeof (unichar));
  353. }
  354. /* Handle a quoted unicode string. The quotes are stripped. A pair of quotes
  355. in a string are turned into a single quote. Adjacent strings are
  356. merged separated by whitespace are merged, as in C. */
  357. static unichar *
  358. handle_uniquotes (rc_uint_type *len)
  359. {
  360. const char *input = rclex_tok;
  361. unichar *ret, *s;
  362. const char *t;
  363. int ch;
  364. int num_xdigits;
  365. ret = get_unistring (strlen (input) + 1);
  366. s = ret;
  367. t = input;
  368. if ((*t == 'L' || *t == 'l') && t[1] == '"')
  369. t += 2;
  370. else if (*t == '"')
  371. ++t;
  372. while (*t != '\0')
  373. {
  374. if (*t == '\\')
  375. {
  376. ++t;
  377. switch (*t)
  378. {
  379. case '\0':
  380. rcparse_warning ("backslash at end of string");
  381. break;
  382. case '\"':
  383. rcparse_warning ("use \"\" to put \" in a string");
  384. break;
  385. case 'a':
  386. *s++ = ESCAPE_B; /* Strange, but true... */
  387. ++t;
  388. break;
  389. case 'b':
  390. *s++ = ESCAPE_B;
  391. ++t;
  392. break;
  393. case 'f':
  394. *s++ = ESCAPE_F;
  395. ++t;
  396. break;
  397. case 'n':
  398. *s++ = ESCAPE_N;
  399. ++t;
  400. break;
  401. case 'r':
  402. *s++ = ESCAPE_R;
  403. ++t;
  404. break;
  405. case 't':
  406. *s++ = ESCAPE_T;
  407. ++t;
  408. break;
  409. case 'v':
  410. *s++ = ESCAPE_V;
  411. ++t;
  412. break;
  413. case '\\':
  414. *s++ = (unichar) *t++;
  415. break;
  416. case '0': case '1': case '2': case '3':
  417. case '4': case '5': case '6': case '7':
  418. ch = *t - '0';
  419. ++t;
  420. if (*t >= '0' && *t <= '7')
  421. {
  422. ch = (ch << 3) | (*t - '0');
  423. ++t;
  424. if (*t >= '0' && *t <= '7')
  425. {
  426. ch = (ch << 3) | (*t - '0');
  427. ++t;
  428. }
  429. }
  430. *s++ = (unichar) ch;
  431. break;
  432. case 'x': case 'X':
  433. ++t;
  434. ch = 0;
  435. /* We only handle two byte chars here. Make sure
  436. we finish an escape sequence like "/xB0ABC" after
  437. the first two digits. */
  438. num_xdigits = 4;
  439. while (num_xdigits--)
  440. {
  441. if (*t >= '0' && *t <= '9')
  442. ch = (ch << 4) | (*t - '0');
  443. else if (*t >= 'a' && *t <= 'f')
  444. ch = (ch << 4) | (*t - 'a' + 10);
  445. else if (*t >= 'A' && *t <= 'F')
  446. ch = (ch << 4) | (*t - 'A' + 10);
  447. else
  448. break;
  449. ++t;
  450. }
  451. *s++ = (unichar) ch;
  452. break;
  453. default:
  454. rcparse_warning ("unrecognized escape sequence");
  455. *s++ = '\\';
  456. *s++ = (unichar) *t++;
  457. break;
  458. }
  459. }
  460. else if (*t != '"')
  461. *s++ = (unichar) *t++;
  462. else if (t[1] == '\0')
  463. break;
  464. else if (t[1] == '"')
  465. {
  466. *s++ = '"';
  467. t += 2;
  468. }
  469. else
  470. {
  471. ++t;
  472. assert (ISSPACE (*t));
  473. while (ISSPACE (*t))
  474. {
  475. if ((*t) == '\n')
  476. ++rc_lineno;
  477. ++t;
  478. }
  479. if (*t == '\0')
  480. break;
  481. assert (*t == '"');
  482. ++t;
  483. }
  484. }
  485. *s = '\0';
  486. *len = s - ret;
  487. return ret;
  488. }
  489. /* Discard all the strings we have allocated. The parser calls this
  490. when it no longer needs them. */
  491. void
  492. rcparse_discard_strings (void)
  493. {
  494. struct alloc_string *as;
  495. as = strings;
  496. while (as != NULL)
  497. {
  498. struct alloc_string *n;
  499. free (as->s);
  500. n = as->next;
  501. free (as);
  502. as = n;
  503. }
  504. strings = NULL;
  505. }
  506. /* Enter rcdata mode. */
  507. void
  508. rcparse_rcdata (void)
  509. {
  510. rcdata_mode = 1;
  511. }
  512. /* Go back to normal mode from rcdata mode. */
  513. void
  514. rcparse_normal (void)
  515. {
  516. rcdata_mode = 0;
  517. }
  518. static void
  519. rclex_tok_add_char (int ch)
  520. {
  521. if (! rclex_tok || rclex_tok_max <= rclex_tok_pos)
  522. {
  523. char *h = xmalloc (rclex_tok_max + 9);
  524. if (! h)
  525. abort ();
  526. if (rclex_tok)
  527. {
  528. memcpy (h, rclex_tok, rclex_tok_pos + 1);
  529. free (rclex_tok);
  530. }
  531. else
  532. rclex_tok_pos = 0;
  533. rclex_tok_max += 8;
  534. rclex_tok = h;
  535. }
  536. if (ch != -1)
  537. rclex_tok[rclex_tok_pos++] = (char) ch;
  538. rclex_tok[rclex_tok_pos] = 0;
  539. }
  540. static int
  541. rclex_readch (void)
  542. {
  543. int r = -1;
  544. if ((r = rclex_lastch) != -1)
  545. rclex_lastch = -1;
  546. else
  547. {
  548. char ch;
  549. do
  550. {
  551. if (! cpp_pipe || feof (cpp_pipe)
  552. || fread (&ch, 1, 1,cpp_pipe) != 1)
  553. break;
  554. r = ((int) ch) & 0xff;
  555. }
  556. while (r == 0 || r == '\r');
  557. }
  558. rclex_tok_add_char (r);
  559. return r;
  560. }
  561. static int
  562. rclex_peekch (void)
  563. {
  564. int r;
  565. if ((r = rclex_lastch) == -1)
  566. {
  567. if ((r = rclex_readch ()) != -1)
  568. {
  569. rclex_lastch = r;
  570. if (rclex_tok_pos > 0)
  571. rclex_tok[--rclex_tok_pos] = 0;
  572. }
  573. }
  574. return r;
  575. }
  576. static void
  577. rclex_string (void)
  578. {
  579. int c;
  580. while ((c = rclex_peekch ()) != -1)
  581. {
  582. if (c == '\n')
  583. break;
  584. if (c == '\\')
  585. {
  586. rclex_readch ();
  587. if ((c = rclex_peekch ()) == -1 || c == '\n')
  588. break;
  589. rclex_readch ();
  590. }
  591. else if (rclex_readch () == '"')
  592. {
  593. /* PR 6714
  594. Skip any whitespace after the end of the double quotes. */
  595. do
  596. {
  597. c = rclex_peekch ();
  598. if (ISSPACE (c))
  599. rclex_readch ();
  600. else
  601. c = -1;
  602. }
  603. while (c != -1);
  604. if (rclex_peekch () == '"')
  605. rclex_readch ();
  606. else
  607. break;
  608. }
  609. }
  610. }
  611. static rc_uint_type
  612. read_digit (int ch)
  613. {
  614. rc_uint_type base = 10;
  615. rc_uint_type ret, val;
  616. int warned = 0;
  617. ret = 0;
  618. if (ch == '0')
  619. {
  620. base = 8;
  621. switch (rclex_peekch ())
  622. {
  623. case 'o': case 'O':
  624. rclex_readch ();
  625. base = 8;
  626. break;
  627. case 'x': case 'X':
  628. rclex_readch ();
  629. base = 16;
  630. break;
  631. }
  632. }
  633. else
  634. ret = (rc_uint_type) (ch - '0');
  635. while ((ch = rclex_peekch ()) != -1)
  636. {
  637. if (ISDIGIT (ch))
  638. val = (rc_uint_type) (ch - '0');
  639. else if (ch >= 'a' && ch <= 'f')
  640. val = (rc_uint_type) ((ch - 'a') + 10);
  641. else if (ch >= 'A' && ch <= 'F')
  642. val = (rc_uint_type) ((ch - 'A') + 10);
  643. else
  644. break;
  645. rclex_readch ();
  646. if (! warned && val >= base)
  647. {
  648. warned = 1;
  649. rcparse_warning ("digit exceeds base");
  650. }
  651. ret *= base;
  652. ret += val;
  653. }
  654. return ret;
  655. }
  656. /* yyparser entry method. */
  657. int
  658. yylex (void)
  659. {
  660. char *s;
  661. unichar *us;
  662. rc_uint_type length;
  663. int ch;
  664. /* Make sure that rclex_tok is initialized. */
  665. if (! rclex_tok)
  666. rclex_tok_add_char (-1);
  667. do
  668. {
  669. do
  670. {
  671. /* Clear token. */
  672. rclex_tok_pos = 0;
  673. rclex_tok[0] = 0;
  674. if ((ch = rclex_readch ()) == -1)
  675. return -1;
  676. if (ch == '\n')
  677. ++rc_lineno;
  678. }
  679. while (ch <= 0x20);
  680. switch (ch)
  681. {
  682. case '#':
  683. while ((ch = rclex_peekch ()) != -1 && ch != '\n')
  684. rclex_readch ();
  685. cpp_line ();
  686. ch = IGNORED_TOKEN;
  687. break;
  688. case '{':
  689. ch = IGNORE_CPP (BEG);
  690. break;
  691. case '}':
  692. ch = IGNORE_CPP (END);
  693. break;
  694. case '0': case '1': case '2': case '3': case '4':
  695. case '5': case '6': case '7': case '8': case '9':
  696. yylval.i.val = read_digit (ch);
  697. yylval.i.dword = 0;
  698. switch (rclex_peekch ())
  699. {
  700. case 'l': case 'L':
  701. rclex_readch ();
  702. yylval.i.dword = 1;
  703. break;
  704. }
  705. ch = IGNORE_CPP (NUMBER);
  706. break;
  707. case '"':
  708. rclex_string ();
  709. ch = IGNORE_CPP ((! rcdata_mode ? QUOTEDSTRING : SIZEDSTRING));
  710. if (ch == IGNORED_TOKEN)
  711. break;
  712. s = handle_quotes (&length);
  713. if (! rcdata_mode)
  714. yylval.s = s;
  715. else
  716. {
  717. yylval.ss.length = length;
  718. yylval.ss.s = s;
  719. }
  720. break;
  721. case 'L': case 'l':
  722. if (rclex_peekch () == '"')
  723. {
  724. rclex_readch ();
  725. rclex_string ();
  726. ch = IGNORE_CPP ((! rcdata_mode ? QUOTEDUNISTRING : SIZEDUNISTRING));
  727. if (ch == IGNORED_TOKEN)
  728. break;
  729. us = handle_uniquotes (&length);
  730. if (! rcdata_mode)
  731. yylval.uni = us;
  732. else
  733. {
  734. yylval.suni.length = length;
  735. yylval.suni.s = us;
  736. }
  737. break;
  738. }
  739. /* Fall through. */
  740. default:
  741. if (ISIDST (ch) || ch=='$')
  742. {
  743. while ((ch = rclex_peekch ()) != -1
  744. && (ISIDNUM (ch) || ch == '$' || ch == '.'
  745. || ch == ':' || ch == '\\' || ch == '/'
  746. || ch == '_' || ch == '-')
  747. )
  748. rclex_readch ();
  749. ch = IGNORE_CPP (rclex_translatekeyword (rclex_tok));
  750. if (ch == STRING)
  751. {
  752. s = get_string (strlen (rclex_tok) + 1);
  753. strcpy (s, rclex_tok);
  754. yylval.s = s;
  755. }
  756. else if (ch == BLOCK)
  757. {
  758. const char *hs = NULL;
  759. switch (yylex ())
  760. {
  761. case STRING:
  762. case QUOTEDSTRING:
  763. hs = yylval.s;
  764. break;
  765. case SIZEDSTRING:
  766. hs = yylval.s = yylval.ss.s;
  767. break;
  768. }
  769. if (! hs)
  770. {
  771. rcparse_warning ("BLOCK expects a string as argument.");
  772. ch = IGNORED_TOKEN;
  773. }
  774. else if (! strcmp (hs, "StringFileInfo"))
  775. ch = BLOCKSTRINGFILEINFO;
  776. else if (! strcmp (hs, "VarFileInfo"))
  777. ch = BLOCKVARFILEINFO;
  778. }
  779. break;
  780. }
  781. ch = IGNORE_CPP (ch);
  782. break;
  783. }
  784. }
  785. while (ch == IGNORED_TOKEN);
  786. return ch;
  787. }