]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | %{ |
2 | /* | |
3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> | |
4 | * Released under the terms of the GNU GPL v2.0. | |
5 | */ | |
6 | ||
7 | #include <ctype.h> | |
8 | #include <stdarg.h> | |
9 | #include <stdio.h> | |
10 | #include <stdlib.h> | |
11 | #include <string.h> | |
12 | #include <stdbool.h> | |
13 | ||
7a88488b RZ |
14 | #define LKC_DIRECT_LINK |
15 | #include "lkc.h" | |
16 | ||
1da177e4 LT |
17 | #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) |
18 | ||
19 | #define PRINTD 0x0001 | |
20 | #define DEBUG_PARSE 0x0002 | |
21 | ||
22 | int cdebug = PRINTD; | |
23 | ||
24 | extern int zconflex(void); | |
25 | static void zconfprint(const char *err, ...); | |
a02f0570 | 26 | static void zconf_error(const char *err, ...); |
1da177e4 | 27 | static void zconferror(const char *err); |
a02f0570 | 28 | static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken); |
1da177e4 | 29 | |
e66f25d7 | 30 | struct symbol *symbol_hash[SYMBOL_HASHSIZE]; |
1da177e4 LT |
31 | |
32 | static struct menu *current_menu, *current_entry; | |
33 | ||
a02f0570 RZ |
34 | #define YYDEBUG 0 |
35 | #if YYDEBUG | |
1da177e4 | 36 | #define YYERROR_VERBOSE |
a02f0570 | 37 | #endif |
1da177e4 | 38 | %} |
8ea13e2c | 39 | %expect 28 |
1da177e4 LT |
40 | |
41 | %union | |
42 | { | |
1da177e4 | 43 | char *string; |
a02f0570 | 44 | struct file *file; |
1da177e4 LT |
45 | struct symbol *symbol; |
46 | struct expr *expr; | |
47 | struct menu *menu; | |
3370f9f0 | 48 | struct kconf_id *id; |
1da177e4 LT |
49 | } |
50 | ||
3370f9f0 RZ |
51 | %token <id>T_MAINMENU |
52 | %token <id>T_MENU | |
53 | %token <id>T_ENDMENU | |
54 | %token <id>T_SOURCE | |
55 | %token <id>T_CHOICE | |
56 | %token <id>T_ENDCHOICE | |
57 | %token <id>T_COMMENT | |
58 | %token <id>T_CONFIG | |
59 | %token <id>T_MENUCONFIG | |
60 | %token <id>T_HELP | |
1da177e4 | 61 | %token <string> T_HELPTEXT |
3370f9f0 RZ |
62 | %token <id>T_IF |
63 | %token <id>T_ENDIF | |
64 | %token <id>T_DEPENDS | |
3370f9f0 RZ |
65 | %token <id>T_OPTIONAL |
66 | %token <id>T_PROMPT | |
67 | %token <id>T_TYPE | |
68 | %token <id>T_DEFAULT | |
69 | %token <id>T_SELECT | |
70 | %token <id>T_RANGE | |
f6a88aa8 | 71 | %token <id>T_OPTION |
3370f9f0 | 72 | %token <id>T_ON |
1da177e4 LT |
73 | %token <string> T_WORD |
74 | %token <string> T_WORD_QUOTE | |
75 | %token T_UNEQUAL | |
1da177e4 LT |
76 | %token T_CLOSE_PAREN |
77 | %token T_OPEN_PAREN | |
3370f9f0 | 78 | %token T_EOL |
1da177e4 LT |
79 | |
80 | %left T_OR | |
81 | %left T_AND | |
82 | %left T_EQUAL T_UNEQUAL | |
83 | %nonassoc T_NOT | |
84 | ||
85 | %type <string> prompt | |
1da177e4 LT |
86 | %type <symbol> symbol |
87 | %type <expr> expr | |
88 | %type <expr> if_expr | |
a02f0570 RZ |
89 | %type <id> end |
90 | %type <id> option_name | |
91 | %type <menu> if_entry menu_entry choice_entry | |
5a1aa8a1 | 92 | %type <string> symbol_option_arg word_opt |
a02f0570 RZ |
93 | |
94 | %destructor { | |
95 | fprintf(stderr, "%s:%d: missing end statement for this entry\n", | |
96 | $$->file->name, $$->lineno); | |
97 | if (current_menu == $$) | |
98 | menu_end_menu(); | |
99 | } if_entry menu_entry choice_entry | |
1da177e4 | 100 | |
1456edbb JT |
101 | %{ |
102 | /* Include zconf.hash.c here so it can see the token constants. */ | |
103 | #include "zconf.hash.c" | |
104 | %} | |
105 | ||
1da177e4 | 106 | %% |
8ea13e2c AL |
107 | input: nl start | start; |
108 | ||
109 | start: mainmenu_stmt stmt_list | stmt_list; | |
a02f0570 RZ |
110 | |
111 | stmt_list: | |
112 | /* empty */ | |
113 | | stmt_list common_stmt | |
114 | | stmt_list choice_stmt | |
115 | | stmt_list menu_stmt | |
a02f0570 RZ |
116 | | stmt_list end { zconf_error("unexpected end statement"); } |
117 | | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); } | |
118 | | stmt_list option_name error T_EOL | |
119 | { | |
120 | zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name); | |
121 | } | |
122 | | stmt_list error T_EOL { zconf_error("invalid statement"); } | |
1da177e4 LT |
123 | ; |
124 | ||
a02f0570 RZ |
125 | option_name: |
126 | T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | |
1da177e4 LT |
127 | ; |
128 | ||
a02f0570 RZ |
129 | common_stmt: |
130 | T_EOL | |
131 | | if_stmt | |
1da177e4 LT |
132 | | comment_stmt |
133 | | config_stmt | |
134 | | menuconfig_stmt | |
135 | | source_stmt | |
a02f0570 RZ |
136 | ; |
137 | ||
138 | option_error: | |
139 | T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); } | |
140 | | error T_EOL { zconf_error("invalid option"); } | |
1da177e4 LT |
141 | ; |
142 | ||
143 | ||
144 | /* config/menuconfig entry */ | |
145 | ||
146 | config_entry_start: T_CONFIG T_WORD T_EOL | |
147 | { | |
148 | struct symbol *sym = sym_lookup($2, 0); | |
149 | sym->flags |= SYMBOL_OPTIONAL; | |
150 | menu_add_entry(sym); | |
151 | printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2); | |
152 | }; | |
153 | ||
154 | config_stmt: config_entry_start config_option_list | |
155 | { | |
156 | menu_end_entry(); | |
157 | printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); | |
158 | }; | |
159 | ||
160 | menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL | |
161 | { | |
162 | struct symbol *sym = sym_lookup($2, 0); | |
163 | sym->flags |= SYMBOL_OPTIONAL; | |
164 | menu_add_entry(sym); | |
165 | printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2); | |
166 | }; | |
167 | ||
168 | menuconfig_stmt: menuconfig_entry_start config_option_list | |
169 | { | |
170 | if (current_entry->prompt) | |
171 | current_entry->prompt->type = P_MENU; | |
172 | else | |
173 | zconfprint("warning: menuconfig statement without prompt"); | |
174 | menu_end_entry(); | |
175 | printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); | |
176 | }; | |
177 | ||
178 | config_option_list: | |
179 | /* empty */ | |
180 | | config_option_list config_option | |
f6a88aa8 | 181 | | config_option_list symbol_option |
1da177e4 LT |
182 | | config_option_list depends |
183 | | config_option_list help | |
a02f0570 | 184 | | config_option_list option_error |
1da177e4 LT |
185 | | config_option_list T_EOL |
186 | ; | |
187 | ||
3370f9f0 | 188 | config_option: T_TYPE prompt_stmt_opt T_EOL |
1da177e4 | 189 | { |
3370f9f0 RZ |
190 | menu_set_type($1->stype); |
191 | printd(DEBUG_PARSE, "%s:%d:type(%u)\n", | |
192 | zconf_curname(), zconf_lineno(), | |
193 | $1->stype); | |
1da177e4 LT |
194 | }; |
195 | ||
196 | config_option: T_PROMPT prompt if_expr T_EOL | |
197 | { | |
198 | menu_add_prompt(P_PROMPT, $2, $3); | |
199 | printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); | |
200 | }; | |
201 | ||
202 | config_option: T_DEFAULT expr if_expr T_EOL | |
203 | { | |
204 | menu_add_expr(P_DEFAULT, $2, $3); | |
3370f9f0 RZ |
205 | if ($1->stype != S_UNKNOWN) |
206 | menu_set_type($1->stype); | |
207 | printd(DEBUG_PARSE, "%s:%d:default(%u)\n", | |
208 | zconf_curname(), zconf_lineno(), | |
209 | $1->stype); | |
1da177e4 LT |
210 | }; |
211 | ||
212 | config_option: T_SELECT T_WORD if_expr T_EOL | |
213 | { | |
214 | menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3); | |
215 | printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno()); | |
216 | }; | |
217 | ||
218 | config_option: T_RANGE symbol symbol if_expr T_EOL | |
219 | { | |
220 | menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4); | |
221 | printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); | |
222 | }; | |
223 | ||
f6a88aa8 RZ |
224 | symbol_option: T_OPTION symbol_option_list T_EOL |
225 | ; | |
226 | ||
227 | symbol_option_list: | |
228 | /* empty */ | |
229 | | symbol_option_list T_WORD symbol_option_arg | |
230 | { | |
231 | struct kconf_id *id = kconf_id_lookup($2, strlen($2)); | |
232 | if (id && id->flags & TF_OPTION) | |
233 | menu_add_option(id->token, $3); | |
234 | else | |
235 | zconfprint("warning: ignoring unknown option %s", $2); | |
236 | free($2); | |
237 | }; | |
238 | ||
239 | symbol_option_arg: | |
240 | /* empty */ { $$ = NULL; } | |
241 | | T_EQUAL prompt { $$ = $2; } | |
242 | ; | |
243 | ||
1da177e4 LT |
244 | /* choice entry */ |
245 | ||
5a1aa8a1 | 246 | choice: T_CHOICE word_opt T_EOL |
1da177e4 | 247 | { |
5a1aa8a1 RZ |
248 | struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE); |
249 | sym->flags |= SYMBOL_AUTO; | |
1da177e4 LT |
250 | menu_add_entry(sym); |
251 | menu_add_expr(P_CHOICE, NULL, NULL); | |
252 | printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno()); | |
253 | }; | |
254 | ||
255 | choice_entry: choice choice_option_list | |
256 | { | |
a02f0570 | 257 | $$ = menu_add_menu(); |
1da177e4 LT |
258 | }; |
259 | ||
260 | choice_end: end | |
261 | { | |
262 | if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) { | |
263 | menu_end_menu(); | |
264 | printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno()); | |
265 | } | |
266 | }; | |
267 | ||
a02f0570 RZ |
268 | choice_stmt: choice_entry choice_block choice_end |
269 | ; | |
1da177e4 LT |
270 | |
271 | choice_option_list: | |
272 | /* empty */ | |
273 | | choice_option_list choice_option | |
274 | | choice_option_list depends | |
275 | | choice_option_list help | |
276 | | choice_option_list T_EOL | |
a02f0570 | 277 | | choice_option_list option_error |
1da177e4 LT |
278 | ; |
279 | ||
280 | choice_option: T_PROMPT prompt if_expr T_EOL | |
281 | { | |
282 | menu_add_prompt(P_PROMPT, $2, $3); | |
283 | printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); | |
284 | }; | |
285 | ||
3370f9f0 | 286 | choice_option: T_TYPE prompt_stmt_opt T_EOL |
1da177e4 | 287 | { |
3370f9f0 RZ |
288 | if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) { |
289 | menu_set_type($1->stype); | |
290 | printd(DEBUG_PARSE, "%s:%d:type(%u)\n", | |
291 | zconf_curname(), zconf_lineno(), | |
292 | $1->stype); | |
293 | } else | |
294 | YYERROR; | |
1da177e4 LT |
295 | }; |
296 | ||
297 | choice_option: T_OPTIONAL T_EOL | |
298 | { | |
299 | current_entry->sym->flags |= SYMBOL_OPTIONAL; | |
300 | printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno()); | |
301 | }; | |
302 | ||
303 | choice_option: T_DEFAULT T_WORD if_expr T_EOL | |
304 | { | |
3370f9f0 RZ |
305 | if ($1->stype == S_UNKNOWN) { |
306 | menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3); | |
307 | printd(DEBUG_PARSE, "%s:%d:default\n", | |
308 | zconf_curname(), zconf_lineno()); | |
309 | } else | |
310 | YYERROR; | |
1da177e4 LT |
311 | }; |
312 | ||
313 | choice_block: | |
314 | /* empty */ | |
a02f0570 | 315 | | choice_block common_stmt |
1da177e4 LT |
316 | ; |
317 | ||
318 | /* if entry */ | |
319 | ||
a02f0570 | 320 | if_entry: T_IF expr nl |
1da177e4 LT |
321 | { |
322 | printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); | |
323 | menu_add_entry(NULL); | |
324 | menu_add_dep($2); | |
a02f0570 | 325 | $$ = menu_add_menu(); |
1da177e4 LT |
326 | }; |
327 | ||
328 | if_end: end | |
329 | { | |
330 | if (zconf_endtoken($1, T_IF, T_ENDIF)) { | |
331 | menu_end_menu(); | |
332 | printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno()); | |
333 | } | |
334 | }; | |
335 | ||
a02f0570 RZ |
336 | if_stmt: if_entry if_block if_end |
337 | ; | |
1da177e4 LT |
338 | |
339 | if_block: | |
340 | /* empty */ | |
a02f0570 | 341 | | if_block common_stmt |
1da177e4 LT |
342 | | if_block menu_stmt |
343 | | if_block choice_stmt | |
344 | ; | |
345 | ||
8ea13e2c AL |
346 | /* mainmenu entry */ |
347 | ||
348 | mainmenu_stmt: T_MAINMENU prompt nl | |
349 | { | |
350 | menu_add_prompt(P_MENU, $2, NULL); | |
351 | }; | |
352 | ||
1da177e4 LT |
353 | /* menu entry */ |
354 | ||
355 | menu: T_MENU prompt T_EOL | |
356 | { | |
357 | menu_add_entry(NULL); | |
fb7f6ff6 | 358 | menu_add_prompt(P_MENU, $2, NULL); |
1da177e4 LT |
359 | printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); |
360 | }; | |
361 | ||
362 | menu_entry: menu depends_list | |
363 | { | |
a02f0570 | 364 | $$ = menu_add_menu(); |
1da177e4 LT |
365 | }; |
366 | ||
367 | menu_end: end | |
368 | { | |
369 | if (zconf_endtoken($1, T_MENU, T_ENDMENU)) { | |
370 | menu_end_menu(); | |
371 | printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno()); | |
372 | } | |
373 | }; | |
374 | ||
a02f0570 RZ |
375 | menu_stmt: menu_entry menu_block menu_end |
376 | ; | |
1da177e4 LT |
377 | |
378 | menu_block: | |
379 | /* empty */ | |
a02f0570 | 380 | | menu_block common_stmt |
1da177e4 LT |
381 | | menu_block menu_stmt |
382 | | menu_block choice_stmt | |
1da177e4 LT |
383 | ; |
384 | ||
a02f0570 | 385 | source_stmt: T_SOURCE prompt T_EOL |
1da177e4 | 386 | { |
1da177e4 | 387 | printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); |
a02f0570 | 388 | zconf_nextfile($2); |
1da177e4 LT |
389 | }; |
390 | ||
391 | /* comment entry */ | |
392 | ||
393 | comment: T_COMMENT prompt T_EOL | |
394 | { | |
395 | menu_add_entry(NULL); | |
fb7f6ff6 | 396 | menu_add_prompt(P_COMMENT, $2, NULL); |
1da177e4 LT |
397 | printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno()); |
398 | }; | |
399 | ||
400 | comment_stmt: comment depends_list | |
401 | { | |
402 | menu_end_entry(); | |
403 | }; | |
404 | ||
405 | /* help option */ | |
406 | ||
407 | help_start: T_HELP T_EOL | |
408 | { | |
409 | printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno()); | |
410 | zconf_starthelp(); | |
411 | }; | |
412 | ||
413 | help: help_start T_HELPTEXT | |
414 | { | |
03d29122 | 415 | current_entry->help = $2; |
1da177e4 LT |
416 | }; |
417 | ||
418 | /* depends option */ | |
419 | ||
a02f0570 RZ |
420 | depends_list: |
421 | /* empty */ | |
422 | | depends_list depends | |
423 | | depends_list T_EOL | |
424 | | depends_list option_error | |
1da177e4 LT |
425 | ; |
426 | ||
427 | depends: T_DEPENDS T_ON expr T_EOL | |
428 | { | |
429 | menu_add_dep($3); | |
430 | printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); | |
1da177e4 LT |
431 | }; |
432 | ||
433 | /* prompt statement */ | |
434 | ||
435 | prompt_stmt_opt: | |
436 | /* empty */ | |
437 | | prompt if_expr | |
438 | { | |
fb7f6ff6 | 439 | menu_add_prompt(P_PROMPT, $1, $2); |
1da177e4 LT |
440 | }; |
441 | ||
442 | prompt: T_WORD | |
443 | | T_WORD_QUOTE | |
444 | ; | |
445 | ||
a02f0570 RZ |
446 | end: T_ENDMENU T_EOL { $$ = $1; } |
447 | | T_ENDCHOICE T_EOL { $$ = $1; } | |
448 | | T_ENDIF T_EOL { $$ = $1; } | |
1da177e4 LT |
449 | ; |
450 | ||
a02f0570 RZ |
451 | nl: |
452 | T_EOL | |
453 | | nl T_EOL | |
454 | ; | |
1da177e4 LT |
455 | |
456 | if_expr: /* empty */ { $$ = NULL; } | |
457 | | T_IF expr { $$ = $2; } | |
458 | ; | |
459 | ||
460 | expr: symbol { $$ = expr_alloc_symbol($1); } | |
461 | | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); } | |
462 | | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); } | |
463 | | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; } | |
464 | | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); } | |
465 | | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); } | |
466 | | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); } | |
467 | ; | |
468 | ||
469 | symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); } | |
5a1aa8a1 | 470 | | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); } |
1da177e4 LT |
471 | ; |
472 | ||
5a1aa8a1 RZ |
473 | word_opt: /* empty */ { $$ = NULL; } |
474 | | T_WORD | |
475 | ||
1da177e4 LT |
476 | %% |
477 | ||
478 | void conf_parse(const char *name) | |
479 | { | |
480 | struct symbol *sym; | |
481 | int i; | |
482 | ||
483 | zconf_initscan(name); | |
484 | ||
485 | sym_init(); | |
692d97c3 | 486 | _menu_init(); |
face4374 RZ |
487 | modules_sym = sym_lookup(NULL, 0); |
488 | modules_sym->type = S_BOOLEAN; | |
489 | modules_sym->flags |= SYMBOL_AUTO; | |
fb7f6ff6 | 490 | rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL); |
1da177e4 | 491 | |
a02f0570 RZ |
492 | #if YYDEBUG |
493 | if (getenv("ZCONF_DEBUG")) | |
494 | zconfdebug = 1; | |
495 | #endif | |
1da177e4 LT |
496 | zconfparse(); |
497 | if (zconfnerrs) | |
498 | exit(1); | |
face4374 RZ |
499 | if (!modules_sym->prop) { |
500 | struct property *prop; | |
501 | ||
502 | prop = prop_alloc(P_DEFAULT, modules_sym); | |
503 | prop->expr = expr_alloc_symbol(sym_lookup("MODULES", 0)); | |
504 | } | |
f6ce00b8 AL |
505 | |
506 | rootmenu.prompt->text = _(rootmenu.prompt->text); | |
507 | rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text); | |
508 | ||
1da177e4 LT |
509 | menu_finalize(&rootmenu); |
510 | for_all_symbols(i, sym) { | |
5447d34b SR |
511 | if (sym_check_deps(sym)) |
512 | zconfnerrs++; | |
1da177e4 | 513 | } |
5447d34b SR |
514 | if (zconfnerrs) |
515 | exit(1); | |
bfc10001 | 516 | sym_set_change_count(1); |
1da177e4 LT |
517 | } |
518 | ||
65166571 | 519 | static const char *zconf_tokenname(int token) |
1da177e4 LT |
520 | { |
521 | switch (token) { | |
522 | case T_MENU: return "menu"; | |
523 | case T_ENDMENU: return "endmenu"; | |
524 | case T_CHOICE: return "choice"; | |
525 | case T_ENDCHOICE: return "endchoice"; | |
526 | case T_IF: return "if"; | |
527 | case T_ENDIF: return "endif"; | |
a02f0570 | 528 | case T_DEPENDS: return "depends"; |
1da177e4 LT |
529 | } |
530 | return "<token>"; | |
531 | } | |
532 | ||
a02f0570 | 533 | static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken) |
1da177e4 | 534 | { |
a02f0570 RZ |
535 | if (id->token != endtoken) { |
536 | zconf_error("unexpected '%s' within %s block", | |
537 | kconf_id_strings + id->name, zconf_tokenname(starttoken)); | |
1da177e4 LT |
538 | zconfnerrs++; |
539 | return false; | |
540 | } | |
541 | if (current_menu->file != current_file) { | |
a02f0570 RZ |
542 | zconf_error("'%s' in different file than '%s'", |
543 | kconf_id_strings + id->name, zconf_tokenname(starttoken)); | |
544 | fprintf(stderr, "%s:%d: location of the '%s'\n", | |
545 | current_menu->file->name, current_menu->lineno, | |
546 | zconf_tokenname(starttoken)); | |
1da177e4 LT |
547 | zconfnerrs++; |
548 | return false; | |
549 | } | |
550 | return true; | |
551 | } | |
552 | ||
553 | static void zconfprint(const char *err, ...) | |
554 | { | |
555 | va_list ap; | |
556 | ||
a02f0570 RZ |
557 | fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); |
558 | va_start(ap, err); | |
559 | vfprintf(stderr, err, ap); | |
560 | va_end(ap); | |
561 | fprintf(stderr, "\n"); | |
562 | } | |
563 | ||
564 | static void zconf_error(const char *err, ...) | |
565 | { | |
566 | va_list ap; | |
567 | ||
568 | zconfnerrs++; | |
569 | fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); | |
1da177e4 LT |
570 | va_start(ap, err); |
571 | vfprintf(stderr, err, ap); | |
572 | va_end(ap); | |
573 | fprintf(stderr, "\n"); | |
574 | } | |
575 | ||
576 | static void zconferror(const char *err) | |
577 | { | |
a02f0570 | 578 | #if YYDEBUG |
1da177e4 | 579 | fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err); |
a02f0570 | 580 | #endif |
1da177e4 LT |
581 | } |
582 | ||
65166571 | 583 | static void print_quoted_string(FILE *out, const char *str) |
1da177e4 LT |
584 | { |
585 | const char *p; | |
586 | int len; | |
587 | ||
588 | putc('"', out); | |
589 | while ((p = strchr(str, '"'))) { | |
590 | len = p - str; | |
591 | if (len) | |
592 | fprintf(out, "%.*s", len, str); | |
593 | fputs("\\\"", out); | |
594 | str = p + 1; | |
595 | } | |
596 | fputs(str, out); | |
597 | putc('"', out); | |
598 | } | |
599 | ||
65166571 | 600 | static void print_symbol(FILE *out, struct menu *menu) |
1da177e4 LT |
601 | { |
602 | struct symbol *sym = menu->sym; | |
603 | struct property *prop; | |
604 | ||
605 | if (sym_is_choice(sym)) | |
c6ccc30f | 606 | fprintf(out, "\nchoice\n"); |
1da177e4 | 607 | else |
c6ccc30f | 608 | fprintf(out, "\nconfig %s\n", sym->name); |
1da177e4 LT |
609 | switch (sym->type) { |
610 | case S_BOOLEAN: | |
611 | fputs(" boolean\n", out); | |
612 | break; | |
613 | case S_TRISTATE: | |
614 | fputs(" tristate\n", out); | |
615 | break; | |
616 | case S_STRING: | |
617 | fputs(" string\n", out); | |
618 | break; | |
619 | case S_INT: | |
620 | fputs(" integer\n", out); | |
621 | break; | |
622 | case S_HEX: | |
623 | fputs(" hex\n", out); | |
624 | break; | |
625 | default: | |
626 | fputs(" ???\n", out); | |
627 | break; | |
628 | } | |
629 | for (prop = sym->prop; prop; prop = prop->next) { | |
630 | if (prop->menu != menu) | |
631 | continue; | |
632 | switch (prop->type) { | |
633 | case P_PROMPT: | |
634 | fputs(" prompt ", out); | |
635 | print_quoted_string(out, prop->text); | |
636 | if (!expr_is_yes(prop->visible.expr)) { | |
637 | fputs(" if ", out); | |
638 | expr_fprint(prop->visible.expr, out); | |
639 | } | |
640 | fputc('\n', out); | |
641 | break; | |
642 | case P_DEFAULT: | |
643 | fputs( " default ", out); | |
644 | expr_fprint(prop->expr, out); | |
645 | if (!expr_is_yes(prop->visible.expr)) { | |
646 | fputs(" if ", out); | |
647 | expr_fprint(prop->visible.expr, out); | |
648 | } | |
649 | fputc('\n', out); | |
650 | break; | |
651 | case P_CHOICE: | |
652 | fputs(" #choice value\n", out); | |
653 | break; | |
c6ccc30f LZ |
654 | case P_SELECT: |
655 | fputs( " select ", out); | |
656 | expr_fprint(prop->expr, out); | |
657 | fputc('\n', out); | |
658 | break; | |
659 | case P_RANGE: | |
660 | fputs( " range ", out); | |
661 | expr_fprint(prop->expr, out); | |
662 | fputc('\n', out); | |
663 | break; | |
664 | case P_MENU: | |
665 | fputs( " menu ", out); | |
666 | print_quoted_string(out, prop->text); | |
667 | fputc('\n', out); | |
668 | break; | |
1da177e4 LT |
669 | default: |
670 | fprintf(out, " unknown prop %d!\n", prop->type); | |
671 | break; | |
672 | } | |
673 | } | |
03d29122 SR |
674 | if (menu->help) { |
675 | int len = strlen(menu->help); | |
676 | while (menu->help[--len] == '\n') | |
677 | menu->help[len] = 0; | |
678 | fprintf(out, " help\n%s\n", menu->help); | |
1da177e4 | 679 | } |
1da177e4 LT |
680 | } |
681 | ||
682 | void zconfdump(FILE *out) | |
683 | { | |
684 | struct property *prop; | |
685 | struct symbol *sym; | |
686 | struct menu *menu; | |
687 | ||
688 | menu = rootmenu.list; | |
689 | while (menu) { | |
690 | if ((sym = menu->sym)) | |
691 | print_symbol(out, menu); | |
692 | else if ((prop = menu->prompt)) { | |
693 | switch (prop->type) { | |
694 | case P_COMMENT: | |
695 | fputs("\ncomment ", out); | |
696 | print_quoted_string(out, prop->text); | |
697 | fputs("\n", out); | |
698 | break; | |
699 | case P_MENU: | |
700 | fputs("\nmenu ", out); | |
701 | print_quoted_string(out, prop->text); | |
702 | fputs("\n", out); | |
703 | break; | |
704 | default: | |
705 | ; | |
706 | } | |
707 | if (!expr_is_yes(prop->visible.expr)) { | |
708 | fputs(" depends ", out); | |
709 | expr_fprint(prop->visible.expr, out); | |
710 | fputc('\n', out); | |
711 | } | |
1da177e4 LT |
712 | } |
713 | ||
714 | if (menu->list) | |
715 | menu = menu->list; | |
716 | else if (menu->next) | |
717 | menu = menu->next; | |
718 | else while ((menu = menu->parent)) { | |
719 | if (menu->prompt && menu->prompt->type == P_MENU) | |
720 | fputs("\nendmenu\n", out); | |
721 | if (menu->next) { | |
722 | menu = menu->next; | |
723 | break; | |
724 | } | |
725 | } | |
726 | } | |
727 | } | |
728 | ||
729 | #include "lex.zconf.c" | |
730 | #include "util.c" | |
731 | #include "confdata.c" | |
732 | #include "expr.c" | |
733 | #include "symbol.c" | |
734 | #include "menu.c" |