blob: 377d04d832d1bc27caec4d311b07a64e18d13b21 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001%{
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
Roman Zippel7a884882005-11-08 21:34:51 -080014#define LKC_DIRECT_LINK
15#include "lkc.h"
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
18
19#define PRINTD 0x0001
20#define DEBUG_PARSE 0x0002
21
22int cdebug = PRINTD;
23
24extern int zconflex(void);
25static void zconfprint(const char *err, ...);
Roman Zippela02f0572005-11-08 21:34:53 -080026static void zconf_error(const char *err, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static void zconferror(const char *err);
Arnaud Lacombe61f956f2011-05-04 21:14:44 -040028static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Andi Kleene66f25d2010-01-13 17:02:44 +010030struct symbol *symbol_hash[SYMBOL_HASHSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32static struct menu *current_menu, *current_entry;
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034%}
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030035%expect 30
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37%union
38{
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 char *string;
Roman Zippela02f0572005-11-08 21:34:53 -080040 struct file *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 struct symbol *symbol;
42 struct expr *expr;
43 struct menu *menu;
Arnaud Lacombe61f956f2011-05-04 21:14:44 -040044 const struct kconf_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
Roman Zippel3370f9f2005-11-08 21:34:52 -080047%token <id>T_MAINMENU
48%token <id>T_MENU
49%token <id>T_ENDMENU
50%token <id>T_SOURCE
51%token <id>T_CHOICE
52%token <id>T_ENDCHOICE
53%token <id>T_COMMENT
54%token <id>T_CONFIG
55%token <id>T_MENUCONFIG
56%token <id>T_HELP
Linus Torvalds1da177e2005-04-16 15:20:36 -070057%token <string> T_HELPTEXT
Roman Zippel3370f9f2005-11-08 21:34:52 -080058%token <id>T_IF
59%token <id>T_ENDIF
60%token <id>T_DEPENDS
Roman Zippel3370f9f2005-11-08 21:34:52 -080061%token <id>T_OPTIONAL
62%token <id>T_PROMPT
63%token <id>T_TYPE
64%token <id>T_DEFAULT
65%token <id>T_SELECT
66%token <id>T_RANGE
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030067%token <id>T_VISIBLE
Roman Zippelf6a88aa2006-06-08 22:12:44 -070068%token <id>T_OPTION
Roman Zippel3370f9f2005-11-08 21:34:52 -080069%token <id>T_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -070070%token <string> T_WORD
71%token <string> T_WORD_QUOTE
72%token T_UNEQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070073%token T_CLOSE_PAREN
74%token T_OPEN_PAREN
Roman Zippel3370f9f2005-11-08 21:34:52 -080075%token T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77%left T_OR
78%left T_AND
79%left T_EQUAL T_UNEQUAL
80%nonassoc T_NOT
81
82%type <string> prompt
Linus Torvalds1da177e2005-04-16 15:20:36 -070083%type <symbol> symbol
84%type <expr> expr
85%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080086%type <id> end
87%type <id> option_name
88%type <menu> if_entry menu_entry choice_entry
Roman Zippel5a1aa8a2008-02-29 05:11:50 +010089%type <string> symbol_option_arg word_opt
Roman Zippela02f0572005-11-08 21:34:53 -080090
91%destructor {
92 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
93 $$->file->name, $$->lineno);
94 if (current_menu == $$)
95 menu_end_menu();
96} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Josh Triplett1456edb2009-10-15 11:03:20 -070098%{
99/* Include zconf.hash.c here so it can see the token constants. */
100#include "zconf.hash.c"
101%}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103%%
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400104input: nl start | start;
105
106start: mainmenu_stmt stmt_list | stmt_list;
Roman Zippela02f0572005-11-08 21:34:53 -0800107
108stmt_list:
109 /* empty */
110 | stmt_list common_stmt
111 | stmt_list choice_stmt
112 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800113 | stmt_list end { zconf_error("unexpected end statement"); }
114 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
115 | stmt_list option_name error T_EOL
116{
117 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
118}
119 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120;
121
Roman Zippela02f0572005-11-08 21:34:53 -0800122option_name:
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300123 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124;
125
Roman Zippela02f0572005-11-08 21:34:53 -0800126common_stmt:
127 T_EOL
128 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 | comment_stmt
130 | config_stmt
131 | menuconfig_stmt
132 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800133;
134
135option_error:
136 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
137 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138;
139
140
141/* config/menuconfig entry */
142
143config_entry_start: T_CONFIG T_WORD T_EOL
144{
145 struct symbol *sym = sym_lookup($2, 0);
146 sym->flags |= SYMBOL_OPTIONAL;
147 menu_add_entry(sym);
148 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
149};
150
151config_stmt: config_entry_start config_option_list
152{
153 menu_end_entry();
154 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
155};
156
157menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
158{
159 struct symbol *sym = sym_lookup($2, 0);
160 sym->flags |= SYMBOL_OPTIONAL;
161 menu_add_entry(sym);
162 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
163};
164
165menuconfig_stmt: menuconfig_entry_start config_option_list
166{
167 if (current_entry->prompt)
168 current_entry->prompt->type = P_MENU;
169 else
170 zconfprint("warning: menuconfig statement without prompt");
171 menu_end_entry();
172 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
173};
174
175config_option_list:
176 /* empty */
177 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700178 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 | config_option_list depends
180 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800181 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 | config_option_list T_EOL
183;
184
Roman Zippel3370f9f2005-11-08 21:34:52 -0800185config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800187 menu_set_type($1->stype);
188 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
189 zconf_curname(), zconf_lineno(),
190 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191};
192
193config_option: T_PROMPT prompt if_expr T_EOL
194{
195 menu_add_prompt(P_PROMPT, $2, $3);
196 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
197};
198
199config_option: T_DEFAULT expr if_expr T_EOL
200{
201 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800202 if ($1->stype != S_UNKNOWN)
203 menu_set_type($1->stype);
204 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
205 zconf_curname(), zconf_lineno(),
206 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207};
208
209config_option: T_SELECT T_WORD if_expr T_EOL
210{
211 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
212 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
213};
214
215config_option: T_RANGE symbol symbol if_expr T_EOL
216{
217 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
218 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
219};
220
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700221symbol_option: T_OPTION symbol_option_list T_EOL
222;
223
224symbol_option_list:
225 /* empty */
226 | symbol_option_list T_WORD symbol_option_arg
227{
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400228 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700229 if (id && id->flags & TF_OPTION)
230 menu_add_option(id->token, $3);
231 else
232 zconfprint("warning: ignoring unknown option %s", $2);
233 free($2);
234};
235
236symbol_option_arg:
237 /* empty */ { $$ = NULL; }
238 | T_EQUAL prompt { $$ = $2; }
239;
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241/* choice entry */
242
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100243choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100245 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
246 sym->flags |= SYMBOL_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 menu_add_entry(sym);
248 menu_add_expr(P_CHOICE, NULL, NULL);
249 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
250};
251
252choice_entry: choice choice_option_list
253{
Roman Zippela02f0572005-11-08 21:34:53 -0800254 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255};
256
257choice_end: end
258{
259 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
260 menu_end_menu();
261 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
262 }
263};
264
Roman Zippela02f0572005-11-08 21:34:53 -0800265choice_stmt: choice_entry choice_block choice_end
266;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268choice_option_list:
269 /* empty */
270 | choice_option_list choice_option
271 | choice_option_list depends
272 | choice_option_list help
273 | choice_option_list T_EOL
Roman Zippela02f0572005-11-08 21:34:53 -0800274 | choice_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275;
276
277choice_option: T_PROMPT prompt if_expr T_EOL
278{
279 menu_add_prompt(P_PROMPT, $2, $3);
280 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
281};
282
Roman Zippel3370f9f2005-11-08 21:34:52 -0800283choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800285 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
286 menu_set_type($1->stype);
287 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
288 zconf_curname(), zconf_lineno(),
289 $1->stype);
290 } else
291 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292};
293
294choice_option: T_OPTIONAL T_EOL
295{
296 current_entry->sym->flags |= SYMBOL_OPTIONAL;
297 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
298};
299
300choice_option: T_DEFAULT T_WORD if_expr T_EOL
301{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800302 if ($1->stype == S_UNKNOWN) {
303 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
304 printd(DEBUG_PARSE, "%s:%d:default\n",
305 zconf_curname(), zconf_lineno());
306 } else
307 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308};
309
310choice_block:
311 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800312 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313;
314
315/* if entry */
316
Roman Zippela02f0572005-11-08 21:34:53 -0800317if_entry: T_IF expr nl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
319 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
320 menu_add_entry(NULL);
321 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800322 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323};
324
325if_end: end
326{
327 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
328 menu_end_menu();
329 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
330 }
331};
332
Roman Zippela02f0572005-11-08 21:34:53 -0800333if_stmt: if_entry if_block if_end
334;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
336if_block:
337 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800338 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 | if_block menu_stmt
340 | if_block choice_stmt
341;
342
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400343/* mainmenu entry */
344
345mainmenu_stmt: T_MAINMENU prompt nl
346{
347 menu_add_prompt(P_MENU, $2, NULL);
348};
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350/* menu entry */
351
352menu: T_MENU prompt T_EOL
353{
354 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200355 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
357};
358
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300359menu_entry: menu visibility_list depends_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Roman Zippela02f0572005-11-08 21:34:53 -0800361 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362};
363
364menu_end: end
365{
366 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
367 menu_end_menu();
368 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
369 }
370};
371
Roman Zippela02f0572005-11-08 21:34:53 -0800372menu_stmt: menu_entry menu_block menu_end
373;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375menu_block:
376 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800377 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 | menu_block menu_stmt
379 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380;
381
Roman Zippela02f0572005-11-08 21:34:53 -0800382source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800385 zconf_nextfile($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386};
387
388/* comment entry */
389
390comment: T_COMMENT prompt T_EOL
391{
392 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200393 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
395};
396
397comment_stmt: comment depends_list
398{
399 menu_end_entry();
400};
401
402/* help option */
403
404help_start: T_HELP T_EOL
405{
406 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
407 zconf_starthelp();
408};
409
410help: help_start T_HELPTEXT
411{
Sam Ravnborg03d29122007-07-21 00:00:36 +0200412 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413};
414
415/* depends option */
416
Roman Zippela02f0572005-11-08 21:34:53 -0800417depends_list:
418 /* empty */
419 | depends_list depends
420 | depends_list T_EOL
421 | depends_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422;
423
424depends: T_DEPENDS T_ON expr T_EOL
425{
426 menu_add_dep($3);
427 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428};
429
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300430/* visibility option */
431
432visibility_list:
433 /* empty */
434 | visibility_list visible
435 | visibility_list T_EOL
436;
437
438visible: T_VISIBLE if_expr
439{
440 menu_add_visibility($2);
441};
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443/* prompt statement */
444
445prompt_stmt_opt:
446 /* empty */
447 | prompt if_expr
448{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200449 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450};
451
452prompt: T_WORD
453 | T_WORD_QUOTE
454;
455
Roman Zippela02f0572005-11-08 21:34:53 -0800456end: T_ENDMENU T_EOL { $$ = $1; }
457 | T_ENDCHOICE T_EOL { $$ = $1; }
458 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459;
460
Roman Zippela02f0572005-11-08 21:34:53 -0800461nl:
462 T_EOL
463 | nl T_EOL
464;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466if_expr: /* empty */ { $$ = NULL; }
467 | T_IF expr { $$ = $2; }
468;
469
470expr: symbol { $$ = expr_alloc_symbol($1); }
471 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
472 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
473 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
474 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
475 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
476 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
477;
478
479symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100480 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481;
482
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100483word_opt: /* empty */ { $$ = NULL; }
484 | T_WORD
485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486%%
487
488void conf_parse(const char *name)
489{
490 struct symbol *sym;
491 int i;
492
493 zconf_initscan(name);
494
495 sym_init();
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200496 _menu_init();
Roman Zippelface4372006-06-08 22:12:45 -0700497 modules_sym = sym_lookup(NULL, 0);
498 modules_sym->type = S_BOOLEAN;
499 modules_sym->flags |= SYMBOL_AUTO;
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200500 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Roman Zippela02f0572005-11-08 21:34:53 -0800502 if (getenv("ZCONF_DEBUG"))
503 zconfdebug = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 zconfparse();
505 if (zconfnerrs)
506 exit(1);
Roman Zippelface4372006-06-08 22:12:45 -0700507 if (!modules_sym->prop) {
508 struct property *prop;
509
510 prop = prop_alloc(P_DEFAULT, modules_sym);
511 prop->expr = expr_alloc_symbol(sym_lookup("MODULES", 0));
512 }
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400513
514 rootmenu.prompt->text = _(rootmenu.prompt->text);
515 rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 menu_finalize(&rootmenu);
518 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200519 if (sym_check_deps(sym))
520 zconfnerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
Sam Ravnborg5447d342007-05-06 09:20:10 +0200522 if (zconfnerrs)
523 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800524 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525}
526
Josh Triplett65166572009-10-15 12:13:36 -0700527static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
529 switch (token) {
530 case T_MENU: return "menu";
531 case T_ENDMENU: return "endmenu";
532 case T_CHOICE: return "choice";
533 case T_ENDCHOICE: return "endchoice";
534 case T_IF: return "if";
535 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800536 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300537 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 }
539 return "<token>";
540}
541
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400542static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Roman Zippela02f0572005-11-08 21:34:53 -0800544 if (id->token != endtoken) {
545 zconf_error("unexpected '%s' within %s block",
546 kconf_id_strings + id->name, zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 zconfnerrs++;
548 return false;
549 }
550 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800551 zconf_error("'%s' in different file than '%s'",
552 kconf_id_strings + id->name, zconf_tokenname(starttoken));
553 fprintf(stderr, "%s:%d: location of the '%s'\n",
554 current_menu->file->name, current_menu->lineno,
555 zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 zconfnerrs++;
557 return false;
558 }
559 return true;
560}
561
562static void zconfprint(const char *err, ...)
563{
564 va_list ap;
565
Roman Zippela02f0572005-11-08 21:34:53 -0800566 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
567 va_start(ap, err);
568 vfprintf(stderr, err, ap);
569 va_end(ap);
570 fprintf(stderr, "\n");
571}
572
573static void zconf_error(const char *err, ...)
574{
575 va_list ap;
576
577 zconfnerrs++;
578 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 va_start(ap, err);
580 vfprintf(stderr, err, ap);
581 va_end(ap);
582 fprintf(stderr, "\n");
583}
584
585static void zconferror(const char *err)
586{
587 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
Josh Triplett65166572009-10-15 12:13:36 -0700590static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
592 const char *p;
593 int len;
594
595 putc('"', out);
596 while ((p = strchr(str, '"'))) {
597 len = p - str;
598 if (len)
599 fprintf(out, "%.*s", len, str);
600 fputs("\\\"", out);
601 str = p + 1;
602 }
603 fputs(str, out);
604 putc('"', out);
605}
606
Josh Triplett65166572009-10-15 12:13:36 -0700607static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608{
609 struct symbol *sym = menu->sym;
610 struct property *prop;
611
612 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800613 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800615 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 switch (sym->type) {
617 case S_BOOLEAN:
618 fputs(" boolean\n", out);
619 break;
620 case S_TRISTATE:
621 fputs(" tristate\n", out);
622 break;
623 case S_STRING:
624 fputs(" string\n", out);
625 break;
626 case S_INT:
627 fputs(" integer\n", out);
628 break;
629 case S_HEX:
630 fputs(" hex\n", out);
631 break;
632 default:
633 fputs(" ???\n", out);
634 break;
635 }
636 for (prop = sym->prop; prop; prop = prop->next) {
637 if (prop->menu != menu)
638 continue;
639 switch (prop->type) {
640 case P_PROMPT:
641 fputs(" prompt ", out);
642 print_quoted_string(out, prop->text);
643 if (!expr_is_yes(prop->visible.expr)) {
644 fputs(" if ", out);
645 expr_fprint(prop->visible.expr, out);
646 }
647 fputc('\n', out);
648 break;
649 case P_DEFAULT:
650 fputs( " default ", out);
651 expr_fprint(prop->expr, out);
652 if (!expr_is_yes(prop->visible.expr)) {
653 fputs(" if ", out);
654 expr_fprint(prop->visible.expr, out);
655 }
656 fputc('\n', out);
657 break;
658 case P_CHOICE:
659 fputs(" #choice value\n", out);
660 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800661 case P_SELECT:
662 fputs( " select ", out);
663 expr_fprint(prop->expr, out);
664 fputc('\n', out);
665 break;
666 case P_RANGE:
667 fputs( " range ", out);
668 expr_fprint(prop->expr, out);
669 fputc('\n', out);
670 break;
671 case P_MENU:
672 fputs( " menu ", out);
673 print_quoted_string(out, prop->text);
674 fputc('\n', out);
675 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 default:
677 fprintf(out, " unknown prop %d!\n", prop->type);
678 break;
679 }
680 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200681 if (menu->help) {
682 int len = strlen(menu->help);
683 while (menu->help[--len] == '\n')
684 menu->help[len] = 0;
685 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687}
688
689void zconfdump(FILE *out)
690{
691 struct property *prop;
692 struct symbol *sym;
693 struct menu *menu;
694
695 menu = rootmenu.list;
696 while (menu) {
697 if ((sym = menu->sym))
698 print_symbol(out, menu);
699 else if ((prop = menu->prompt)) {
700 switch (prop->type) {
701 case P_COMMENT:
702 fputs("\ncomment ", out);
703 print_quoted_string(out, prop->text);
704 fputs("\n", out);
705 break;
706 case P_MENU:
707 fputs("\nmenu ", out);
708 print_quoted_string(out, prop->text);
709 fputs("\n", out);
710 break;
711 default:
712 ;
713 }
714 if (!expr_is_yes(prop->visible.expr)) {
715 fputs(" depends ", out);
716 expr_fprint(prop->visible.expr, out);
717 fputc('\n', out);
718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 }
720
721 if (menu->list)
722 menu = menu->list;
723 else if (menu->next)
724 menu = menu->next;
725 else while ((menu = menu->parent)) {
726 if (menu->prompt && menu->prompt->type == P_MENU)
727 fputs("\nendmenu\n", out);
728 if (menu->next) {
729 menu = menu->next;
730 break;
731 }
732 }
733 }
734}
735
736#include "lex.zconf.c"
737#include "util.c"
738#include "confdata.c"
739#include "expr.c"
740#include "symbol.c"
741#include "menu.c"