-rw-r--r-- | scripts/kconfig/zconf.l | 72 |
1 files changed, 54 insertions, 18 deletions
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l index 6d81e5e..1471630 100644 --- a/scripts/kconfig/zconf.l +++ b/scripts/kconfig/zconf.l | |||
@@ -1,29 +1,29 @@ | |||
1 | %option backup nostdinit noyywrap full ecs | 1 | %option backup nostdinit noyywrap never-interactive full ecs |
2 | %option 8bit backup nodefault perf-report perf-report | 2 | %option 8bit backup nodefault perf-report perf-report |
3 | %x COMMAND HELP STRING PARAM | 3 | %x COMMAND HELP STRING PARAM |
4 | %{ | 4 | %{ |
5 | /* | 5 | /* |
6 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> | 6 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
7 | * Released under the terms of the GNU GPL v2.0. | 7 | * Released under the terms of the GNU GPL v2.0. |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <limits.h> | ||
10 | #include <stdio.h> | 11 | #include <stdio.h> |
11 | #include <stdlib.h> | 12 | #include <stdlib.h> |
12 | #include <string.h> | 13 | #include <string.h> |
13 | #include <unistd.h> | 14 | #include <unistd.h> |
14 | 15 | ||
15 | #define LKC_DIRECT_LINK | 16 | #define LKC_DIRECT_LINK |
16 | #include "lkc.h" | 17 | #include "lkc.h" |
17 | #include "zconf.tab.h" | ||
18 | 18 | ||
19 | #define START_STRSIZE16 | 19 | #define START_STRSIZE16 |
20 | 20 | ||
21 | char *text; | 21 | char *text; |
22 | static char *text_ptr; | 22 | static char *text_ptr; |
23 | static int text_size, text_asize; | 23 | static int text_size, text_asize; |
24 | 24 | ||
25 | struct buffer { | 25 | struct buffer { |
26 | struct buffer *parent; | 26 | struct buffer *parent; |
27 | YY_BUFFER_STATE state; | 27 | YY_BUFFER_STATE state; |
28 | }; | 28 | }; |
29 | 29 | ||
@@ -74,26 +74,24 @@ n [A-Za-z0-9_] | |||
74 | 74 | ||
75 | [ \t]*#.*\ncurrent_file->lineno++; | 75 | [ \t]*#.*\ncurrent_file->lineno++; |
76 | [ \t]*#.* | 76 | [ \t]*#.* |
77 | 77 | ||
78 | [ \t]*\ncurrent_file->lineno++; return T_EOL; | 78 | [ \t]*\ncurrent_file->lineno++; return T_EOL; |
79 | 79 | ||
80 | [ \t]+{ | 80 | [ \t]+{ |
81 | BEGIN(COMMAND); | 81 | BEGIN(COMMAND); |
82 | } | 82 | } |
83 | 83 | ||
84 | .{ | 84 | .{ |
85 | unput(yytext[0]); | 85 | unput(yytext[0]); |
86 | //printf("new config: "); | ||
87 | //symbol_end(NULL); | ||
88 | BEGIN(COMMAND); | 86 | BEGIN(COMMAND); |
89 | } | 87 | } |
90 | 88 | ||
91 | 89 | ||
92 | <COMMAND>{ | 90 | <COMMAND>{ |
93 | "mainmenu" BEGIN(PARAM); return T_MAINMENU; | 91 | "mainmenu" BEGIN(PARAM); return T_MAINMENU; |
94 | "menu" BEGIN(PARAM); return T_MENU; | 92 | "menu" BEGIN(PARAM); return T_MENU; |
95 | "endmenu" BEGIN(PARAM); return T_ENDMENU; | 93 | "endmenu" BEGIN(PARAM); return T_ENDMENU; |
96 | "source" BEGIN(PARAM); return T_SOURCE; | 94 | "source" BEGIN(PARAM); return T_SOURCE; |
97 | "choice" BEGIN(PARAM); return T_CHOICE; | 95 | "choice" BEGIN(PARAM); return T_CHOICE; |
98 | "endchoice" BEGIN(PARAM); return T_ENDCHOICE; | 96 | "endchoice" BEGIN(PARAM); return T_ENDCHOICE; |
99 | "comment" BEGIN(PARAM); return T_COMMENT; | 97 | "comment" BEGIN(PARAM); return T_COMMENT; |
@@ -134,50 +132,64 @@ n [A-Za-z0-9_] | |||
134 | \"|\'{ | 132 | \"|\'{ |
135 | str = yytext[0]; | 133 | str = yytext[0]; |
136 | new_string(); | 134 | new_string(); |
137 | BEGIN(STRING); | 135 | BEGIN(STRING); |
138 | } | 136 | } |
139 | \nBEGIN(INITIAL); current_file->lineno++; return T_EOL; | 137 | \nBEGIN(INITIAL); current_file->lineno++; return T_EOL; |
140 | ---/* ignore */ | 138 | ---/* ignore */ |
141 | ({n}|[-/.])+{ | 139 | ({n}|[-/.])+{ |
142 | alloc_string(yytext, yyleng); | 140 | alloc_string(yytext, yyleng); |
143 | zconflval.string = text; | 141 | zconflval.string = text; |
144 | return T_WORD; | 142 | return T_WORD; |
145 | } | 143 | } |
144 | \\\ncurrent_file->lineno++; | ||
146 | . | 145 | . |
146 | <<EOF>> { | ||
147 | BEGIN(INITIAL); | ||
148 | } | ||
147 | } | 149 | } |
148 | 150 | ||
149 | <STRING>{ | 151 | <STRING>{ |
150 | [^'"\n\\]+{ | 152 | [^'"\\\n]+/\n{ |
153 | append_string(yytext, yyleng); | ||
154 | zconflval.string = text; | ||
155 | return T_STRING; | ||
156 | } | ||
157 | [^'"\\\n]+{ | ||
151 | append_string(yytext, yyleng); | 158 | append_string(yytext, yyleng); |
152 | } | 159 | } |
160 | \\.?/\n{ | ||
161 | append_string(yytext + 1, yyleng - 1); | ||
162 | zconflval.string = text; | ||
163 | return T_STRING; | ||
164 | } | ||
165 | \\.?{ | ||
166 | append_string(yytext + 1, yyleng - 1); | ||
167 | } | ||
153 | \'|\"{ | 168 | \'|\"{ |
154 | if (str == yytext[0]) { | 169 | if (str == yytext[0]) { |
155 | BEGIN(PARAM); | 170 | BEGIN(PARAM); |
156 | zconflval.string = text; | 171 | zconflval.string = text; |
157 | //printf("s:%s\n", text); | ||
158 | return T_STRING; | 172 | return T_STRING; |
159 | } else | 173 | } else |
160 | append_string(yytext, 1); | 174 | append_string(yytext, 1); |
161 | } | 175 | } |
162 | \\[ \t]*\nappend_string(yytext+yyleng-1, 1); current_file->lineno++; | ||
163 | \\[ \t]*append_string(yytext+1, yyleng-1); | ||
164 | \\. append_string(yytext+1, 1); | ||
165 | \n{ | 176 | \n{ |
166 | //printf(":%d: open string!\n", current_file->lineno+1); | 177 | printf("%s:%d:warning: multi-line strings not supported\n", zconf_curname(), zconf_lineno()); |
167 | exit(0); | 178 | current_file->lineno++; |
179 | BEGIN(INITIAL); | ||
180 | return T_EOL; | ||
168 | } | 181 | } |
169 | <<EOF>>{ | 182 | <<EOF>>{ |
170 | //printf(":%d: open string!\n", current_file->lineno+1); | 183 | BEGIN(INITIAL); |
171 | exit(0); | ||
172 | } | 184 | } |
173 | } | 185 | } |
174 | 186 | ||
175 | <HELP>{ | 187 | <HELP>{ |
176 | [ \t]+{ | 188 | [ \t]+{ |
177 | ts = 0; | 189 | ts = 0; |
178 | for (i = 0; i < yyleng; i++) { | 190 | for (i = 0; i < yyleng; i++) { |
179 | if (yytext[i] == '\t') | 191 | if (yytext[i] == '\t') |
180 | ts = (ts & ~7) + 8; | 192 | ts = (ts & ~7) + 8; |
181 | else | 193 | else |
182 | ts++; | 194 | ts++; |
183 | } | 195 | } |
@@ -212,100 +224,124 @@ n [A-Za-z0-9_] | |||
212 | } | 224 | } |
213 | <<EOF>>{ | 225 | <<EOF>>{ |
214 | zconf_endhelp(); | 226 | zconf_endhelp(); |
215 | return T_HELPTEXT; | 227 | return T_HELPTEXT; |
216 | } | 228 | } |
217 | } | 229 | } |
218 | 230 | ||
219 | <<EOF>>{ | 231 | <<EOF>>{ |
220 | if (current_buf) { | 232 | if (current_buf) { |
221 | zconf_endfile(); | 233 | zconf_endfile(); |
222 | return T_EOF; | 234 | return T_EOF; |
223 | } | 235 | } |
236 | fclose(yyin); | ||
224 | yyterminate(); | 237 | yyterminate(); |
225 | } | 238 | } |
226 | 239 | ||
227 | %% | 240 | %% |
228 | void zconf_starthelp(void) | 241 | void zconf_starthelp(void) |
229 | { | 242 | { |
230 | new_string(); | 243 | new_string(); |
231 | last_ts = first_ts = 0; | 244 | last_ts = first_ts = 0; |
232 | BEGIN(HELP); | 245 | BEGIN(HELP); |
233 | } | 246 | } |
234 | 247 | ||
235 | static void zconf_endhelp(void) | 248 | static void zconf_endhelp(void) |
236 | { | 249 | { |
237 | zconflval.string = text; | 250 | zconflval.string = text; |
238 | BEGIN(INITIAL); | 251 | BEGIN(INITIAL); |
239 | } | 252 | } |
240 | 253 | ||
254 | |||
255 | /* | ||
256 | * Try to open specified file with following names: | ||
257 | * ./name | ||
258 | * $(srctree)/name | ||
259 | * The latter is used when srctree is separate from objtree | ||
260 | * when compiling the kernel. | ||
261 | * Return NULL if file is not found. | ||
262 | */ | ||
263 | FILE *zconf_fopen(const char *name) | ||
264 | { | ||
265 | char *env, fullname[PATH_MAX+1]; | ||
266 | FILE *f; | ||
267 | |||
268 | f = fopen(name, "r"); | ||
269 | if (!f && name[0] != '/') { | ||
270 | env = getenv(SRCTREE); | ||
271 | if (env) { | ||
272 | sprintf(fullname, "%s/%s", env, name); | ||
273 | f = fopen(fullname, "r"); | ||
274 | } | ||
275 | } | ||
276 | return f; | ||
277 | } | ||
278 | |||
241 | void zconf_initscan(const char *name) | 279 | void zconf_initscan(const char *name) |
242 | { | 280 | { |
243 | yyin = fopen(name, "r"); | 281 | yyin = zconf_fopen(name); |
244 | if (!yyin) { | 282 | if (!yyin) { |
245 | printf("can't find file %s\n", name); | 283 | printf("can't find file %s\n", name); |
246 | exit(1); | 284 | exit(1); |
247 | } | 285 | } |
248 | //fprintf(stderr, "zconf_initscan: %s\n", name); | ||
249 | 286 | ||
250 | current_buf = malloc(sizeof(*current_buf)); | 287 | current_buf = malloc(sizeof(*current_buf)); |
251 | memset(current_buf, 0, sizeof(*current_buf)); | 288 | memset(current_buf, 0, sizeof(*current_buf)); |
252 | 289 | ||
253 | current_file = file_lookup(name); | 290 | current_file = file_lookup(name); |
254 | current_file->lineno = 1; | 291 | current_file->lineno = 1; |
255 | current_file->flags = FILE_BUSY; | 292 | current_file->flags = FILE_BUSY; |
256 | } | 293 | } |
257 | 294 | ||
258 | void zconf_nextfile(const char *name) | 295 | void zconf_nextfile(const char *name) |
259 | { | 296 | { |
260 | struct file *file = file_lookup(name); | 297 | struct file *file = file_lookup(name); |
261 | struct buffer *buf = malloc(sizeof(*buf)); | 298 | struct buffer *buf = malloc(sizeof(*buf)); |
262 | memset(buf, 0, sizeof(*buf)); | 299 | memset(buf, 0, sizeof(*buf)); |
263 | 300 | ||
264 | current_buf->state = YY_CURRENT_BUFFER; | 301 | current_buf->state = YY_CURRENT_BUFFER; |
265 | yyin = fopen(name, "r"); | 302 | yyin = zconf_fopen(name); |
266 | if (!yyin) { | 303 | if (!yyin) { |
267 | printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); | 304 | printf("%s:%d: can't open file \"%s\"\n", zconf_curname(), zconf_lineno(), name); |
268 | exit(1); | 305 | exit(1); |
269 | } | 306 | } |
270 | yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); | 307 | yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); |
271 | buf->parent = current_buf; | 308 | buf->parent = current_buf; |
272 | current_buf = buf; | 309 | current_buf = buf; |
273 | 310 | ||
274 | //fprintf(stderr, "zconf_nextfile: %s\n", name); | ||
275 | |||
276 | if (file->flags & FILE_BUSY) { | 311 | if (file->flags & FILE_BUSY) { |
277 | printf("recursive scan (%s)?\n", name); | 312 | printf("recursive scan (%s)?\n", name); |
278 | exit(1); | 313 | exit(1); |
279 | } | 314 | } |
280 | if (file->flags & FILE_SCANNED) { | 315 | if (file->flags & FILE_SCANNED) { |
281 | printf("file %s already scanned?\n", name); | 316 | printf("file %s already scanned?\n", name); |
282 | exit(1); | 317 | exit(1); |
283 | } | 318 | } |
284 | file->flags |= FILE_BUSY; | 319 | file->flags |= FILE_BUSY; |
285 | file->lineno = 1; | 320 | file->lineno = 1; |
286 | file->parent = current_file; | 321 | file->parent = current_file; |
287 | current_file = file; | 322 | current_file = file; |
288 | } | 323 | } |
289 | 324 | ||
290 | static struct buffer *zconf_endfile(void) | 325 | static struct buffer *zconf_endfile(void) |
291 | { | 326 | { |
292 | struct buffer *parent; | 327 | struct buffer *parent; |
293 | 328 | ||
294 | current_file->flags |= FILE_SCANNED; | 329 | current_file->flags |= FILE_SCANNED; |
295 | current_file->flags &= ~FILE_BUSY; | 330 | current_file->flags &= ~FILE_BUSY; |
296 | current_file = current_file->parent; | 331 | current_file = current_file->parent; |
297 | 332 | ||
298 | parent = current_buf->parent; | 333 | parent = current_buf->parent; |
299 | if (parent) { | 334 | if (parent) { |
335 | fclose(yyin); | ||
300 | yy_delete_buffer(YY_CURRENT_BUFFER); | 336 | yy_delete_buffer(YY_CURRENT_BUFFER); |
301 | yy_switch_to_buffer(parent->state); | 337 | yy_switch_to_buffer(parent->state); |
302 | } | 338 | } |
303 | free(current_buf); | 339 | free(current_buf); |
304 | current_buf = parent; | 340 | current_buf = parent; |
305 | 341 | ||
306 | return parent; | 342 | return parent; |
307 | } | 343 | } |
308 | 344 | ||
309 | int zconf_lineno(void) | 345 | int zconf_lineno(void) |
310 | { | 346 | { |
311 | if (current_buf) | 347 | if (current_buf) |