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 s = get_string (strlen (yytext) + 1);
207 [\n] { ++rc_lineno; }
208 [ \t\r]+ { /* ignore whitespace */ }
209 . { return *yytext; }
213 /* This is needed for some versions of lex. */
220 /* Handle a C preprocessor line. */
233 line = strtol (s, &send, 0);
234 if (*send != '\0' && ! isspace (*send))
237 /* Subtract 1 because we are about to count the newline. */
238 rc_lineno = line - 1;
248 send = strchr (s, '"');
252 fn = (char *) xmalloc (send - s + 1);
253 strncpy (fn, s, send - s);
260 /* Handle a quoted string. The quotes are stripped. A pair of quotes
261 in a string are turned into a single quote. Adjacent strings are
262 merged separated by whitespace are merged, as in C. */
265 handle_quotes (input, len)
273 ret = get_string (strlen (input) + 1);
287 rcparse_warning ("backslash at end of string");
291 rcparse_warning ("use \"\" to put \" in a string");
298 case '0': case '1': case '2': case '3':
299 case '4': case '5': case '6': case '7':
302 if (*t >= '0' && *t <= '7')
304 ch = (ch << 3) | (*t - '0');
306 if (*t >= '0' && *t <= '7')
308 ch = (ch << 3) | (*t - '0');
320 if (*t >= '0' && *t <= '9')
321 ch = (ch << 4) | (*t - '0');
322 else if (*t >= 'a' && *t <= 'f')
323 ch = (ch << 4) | (*t - 'a');
324 else if (*t >= 'A' && *t <= 'F')
325 ch = (ch << 4) | (*t - 'A');
336 else if (t[1] == '\0')
338 else if (t[1] == '"')
346 assert (isspace (*t));
363 /* Allocate a string of a given length. */
369 struct alloc_string *as;
371 as = (struct alloc_string *) xmalloc (sizeof *as);
372 as->s = xmalloc (len);
380 /* Discard all the strings we have allocated. The parser calls this
381 when it no longer needs them. */
384 rcparse_discard_strings ()
386 struct alloc_string *as;
391 struct alloc_string *n;
402 /* Enter rcdata mode. */
410 /* Go back to normal mode from rcdata mode. */