1 %{ /* rclex.l -- lexer for Windows rc files parser */
2 /* Copyright 1997 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program 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
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 /* This is a lex input file which generates a lexer used by the
23 Windows rc file parser. It basically just recognized a bunch of
28 #include "libiberty.h"
35 /* Whether we are in rcdata mode, in which we returns the lengths of
38 static int rcdata_mode;
40 /* List of allocated strings. */
44 struct alloc_string *next;
48 static struct alloc_string *strings;
50 /* Local functions. */
52 static void cpp_line PARAMS ((const char *));
53 static char *handle_quotes PARAMS ((const char *, unsigned long *));
54 static char *get_string PARAMS ((int));
60 "BEGIN" { return BEG; }
62 "ACCELERATORS" { return ACCELERATORS; }
63 "VIRTKEY" { return VIRTKEY; }
64 "ASCII" { return ASCII; }
65 "NOINVERT" { return NOINVERT; }
66 "SHIFT" { return SHIFT; }
67 "CONTROL" { return CONTROL; }
69 "BITMAP" { return BITMAP; }
70 "CURSOR" { return CURSOR; }
71 "DIALOG" { return DIALOG; }
72 "DIALOGEX" { return DIALOGEX; }
73 "EXSTYLE" { return EXSTYLE; }
74 "CAPTION" { return CAPTION; }
75 "CLASS" { return CLASS; }
76 "STYLE" { return STYLE; }
77 "AUTO3STATE" { return AUTO3STATE; }
78 "AUTOCHECKBOX" { return AUTOCHECKBOX; }
79 "AUTORADIOBUTTON" { return AUTORADIOBUTTON; }
80 "CHECKBOX" { return CHECKBOX; }
81 "COMBOBOX" { return COMBOBOX; }
82 "CTEXT" { return CTEXT; }
83 "DEFPUSHBUTTON" { return DEFPUSHBUTTON; }
84 "EDITTEXT" { return EDITTEXT; }
85 "GROUPBOX" { return GROUPBOX; }
86 "LISTBOX" { return LISTBOX; }
87 "LTEXT" { return LTEXT; }
88 "PUSHBOX" { return PUSHBOX; }
89 "PUSHBUTTON" { return PUSHBUTTON; }
90 "RADIOBUTTON" { return RADIOBUTTON; }
91 "RTEXT" { return RTEXT; }
92 "SCROLLBAR" { return SCROLLBAR; }
93 "STATE3" { return STATE3; }
94 "USERBUTTON" { return USERBUTTON; }
95 "BEDIT" { return BEDIT; }
96 "HEDIT" { return HEDIT; }
97 "IEDIT" { return IEDIT; }
98 "FONT" { return FONT; }
99 "ICON" { return ICON; }
100 "LANGUAGE" { return LANGUAGE; }
101 "CHARACTERISTICS" { return CHARACTERISTICS; }
102 "VERSION" { return VERSIONK; }
103 "MENU" { return MENU; }
104 "MENUEX" { return MENUEX; }
105 "MENUITEM" { return MENUITEM; }
106 "SEPARATOR" { return SEPARATOR; }
107 "POPUP" { return POPUP; }
108 "CHECKED" { return CHECKED; }
109 "GRAYED" { return GRAYED; }
110 "HELP" { return HELP; }
111 "INACTIVE" { return INACTIVE; }
112 "MENUBARBREAK" { return MENUBARBREAK; }
113 "MENUBREAK" { return MENUBREAK; }
114 "MESSAGETABLE" { return MESSAGETABLE; }
115 "RCDATA" { return RCDATA; }
116 "STRINGTABLE" { return STRINGTABLE; }
117 "VERSIONINFO" { return VERSIONINFO; }
118 "FILEVERSION" { return FILEVERSION; }
119 "PRODUCTVERSION" { return PRODUCTVERSION; }
120 "FILEFLAGSMASK" { return FILEFLAGSMASK; }
121 "FILEFLAGS" { return FILEFLAGS; }
122 "FILEOS" { return FILEOS; }
123 "FILETYPE" { return FILETYPE; }
124 "FILESUBTYPE" { return FILESUBTYPE; }
125 "VALUE" { return VALUE; }
126 "MOVEABLE" { return MOVEABLE; }
127 "FIXED" { return FIXED; }
128 "PURE" { return PURE; }
129 "IMPURE" { return IMPURE; }
130 "PRELOAD" { return PRELOAD; }
131 "LOADONCALL" { return LOADONCALL; }
132 "DISCARDABLE" { return DISCARDABLE; }
133 "NOT" { return NOT; }
135 "BLOCK"[ \t\n]*"\""[^\#\n]*"\"" {
138 /* This is a hack to let us parse version
139 information easily. */
141 s = strchr (yytext, '"');
143 send = strchr (s, '"');
144 if (strncmp (s, "StringFileInfo",
145 sizeof "StringFileInfo" - 1) == 0
146 && s + sizeof "StringFileInfo" - 1 == send)
147 return BLOCKSTRINGFILEINFO;
148 else if (strncmp (s, "VarFileInfo",
149 sizeof "VarFileInfo" - 1) == 0
150 && s + sizeof "VarFileInfo" - 1 == send)
151 return BLOCKVARFILEINFO;
156 r = get_string (send - s + 1);
157 strncpy (r, s, send - s);
168 [0-9][x0-9A-Fa-f]*L {
169 yylval.i.val = strtoul (yytext, 0, 0);
175 yylval.i.val = strtoul (yytext, 0, 0);
180 ("\""[^\"\n]*"\""[ \t]*)+ {
182 unsigned long length;
184 s = handle_quotes (yytext, &length);
192 yylval.ss.length = length;
198 [A-Za-z][^ ,\t\r\n]* {
201 /* I rejected comma in a string in order to
202 handle VIRTKEY, CONTROL in an accelerator
203 resource. This means that an unquoted
204 file name can not contain a comma. I
205 don't know what rc permits. */
207 s = get_string (strlen (yytext) + 1);
213 [\n] { ++rc_lineno; }
214 [ \t\r]+ { /* ignore whitespace */ }
215 . { return *yytext; }
219 /* This is needed for some versions of lex. */
226 /* Handle a C preprocessor line. */
239 line = strtol (s, &send, 0);
240 if (*send != '\0' && ! isspace (*send))
243 /* Subtract 1 because we are about to count the newline. */
244 rc_lineno = line - 1;
254 send = strchr (s, '"');
258 fn = (char *) xmalloc (send - s + 1);
259 strncpy (fn, s, send - s);
266 /* Handle a quoted string. The quotes are stripped. A pair of quotes
267 in a string are turned into a single quote. Adjacent strings are
268 merged separated by whitespace are merged, as in C. */
271 handle_quotes (input, len)
279 ret = get_string (strlen (input) + 1);
293 rcparse_warning ("backslash at end of string");
297 rcparse_warning ("use \"\" to put \" in a string");
339 case '0': case '1': case '2': case '3':
340 case '4': case '5': case '6': case '7':
343 if (*t >= '0' && *t <= '7')
345 ch = (ch << 3) | (*t - '0');
347 if (*t >= '0' && *t <= '7')
349 ch = (ch << 3) | (*t - '0');
361 if (*t >= '0' && *t <= '9')
362 ch = (ch << 4) | (*t - '0');
363 else if (*t >= 'a' && *t <= 'f')
364 ch = (ch << 4) | (*t - 'a');
365 else if (*t >= 'A' && *t <= 'F')
366 ch = (ch << 4) | (*t - 'A');
375 rcparse_warning ("unrecognized escape sequence");
383 else if (t[1] == '\0')
385 else if (t[1] == '"')
393 assert (isspace (*t));
410 /* Allocate a string of a given length. */
416 struct alloc_string *as;
418 as = (struct alloc_string *) xmalloc (sizeof *as);
419 as->s = xmalloc (len);
427 /* Discard all the strings we have allocated. The parser calls this
428 when it no longer needs them. */
431 rcparse_discard_strings ()
433 struct alloc_string *as;
438 struct alloc_string *n;
449 /* Enter rcdata mode. */
457 /* Go back to normal mode from rcdata mode. */