blob: 2abd3c7ff15d91d25679a4cec6f1ff21da38fb23 [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);
Roman Zippela02f0572005-11-08 21:34:53 -080028static bool zconf_endtoken(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
Roman Zippela02f0572005-11-08 21:34:53 -080034#define YYDEBUG 0
35#if YYDEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#define YYERROR_VERBOSE
Roman Zippela02f0572005-11-08 21:34:53 -080037#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070038%}
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -040039%expect 28
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41%union
42{
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 char *string;
Roman Zippela02f0572005-11-08 21:34:53 -080044 struct file *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 struct symbol *symbol;
46 struct expr *expr;
47 struct menu *menu;
Roman Zippel3370f9f2005-11-08 21:34:52 -080048 struct kconf_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049}
50
Roman Zippel3370f9f2005-11-08 21:34:52 -080051%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
Linus Torvalds1da177e2005-04-16 15:20:36 -070061%token <string> T_HELPTEXT
Roman Zippel3370f9f2005-11-08 21:34:52 -080062%token <id>T_IF
63%token <id>T_ENDIF
64%token <id>T_DEPENDS
Roman Zippel3370f9f2005-11-08 21:34:52 -080065%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
Roman Zippelf6a88aa2006-06-08 22:12:44 -070071%token <id>T_OPTION
Roman Zippel3370f9f2005-11-08 21:34:52 -080072%token <id>T_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -070073%token <string> T_WORD
74%token <string> T_WORD_QUOTE
75%token T_UNEQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070076%token T_CLOSE_PAREN
77%token T_OPEN_PAREN
Roman Zippel3370f9f2005-11-08 21:34:52 -080078%token T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80%left T_OR
81%left T_AND
82%left T_EQUAL T_UNEQUAL
83%nonassoc T_NOT
84
85%type <string> prompt
Linus Torvalds1da177e2005-04-16 15:20:36 -070086%type <symbol> symbol
87%type <expr> expr
88%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080089%type <id> end
90%type <id> option_name
91%type <menu> if_entry menu_entry choice_entry
Roman Zippel5a1aa8a2008-02-29 05:11:50 +010092%type <string> symbol_option_arg word_opt
Roman Zippela02f0572005-11-08 21:34:53 -080093
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Josh Triplett1456edb2009-10-15 11:03:20 -0700101%{
102/* Include zconf.hash.c here so it can see the token constants. */
103#include "zconf.hash.c"
104%}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106%%
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400107input: nl start | start;
108
109start: mainmenu_stmt stmt_list | stmt_list;
Roman Zippela02f0572005-11-08 21:34:53 -0800110
111stmt_list:
112 /* empty */
113 | stmt_list common_stmt
114 | stmt_list choice_stmt
115 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800116 | 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"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123;
124
Roman Zippela02f0572005-11-08 21:34:53 -0800125option_name:
126 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127;
128
Roman Zippela02f0572005-11-08 21:34:53 -0800129common_stmt:
130 T_EOL
131 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 | comment_stmt
133 | config_stmt
134 | menuconfig_stmt
135 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800136;
137
138option_error:
139 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
140 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141;
142
143
144/* config/menuconfig entry */
145
146config_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
154config_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
160menuconfig_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
168menuconfig_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
178config_option_list:
179 /* empty */
180 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700181 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 | config_option_list depends
183 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800184 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 | config_option_list T_EOL
186;
187
Roman Zippel3370f9f2005-11-08 21:34:52 -0800188config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800190 menu_set_type($1->stype);
191 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
192 zconf_curname(), zconf_lineno(),
193 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194};
195
196config_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
202config_option: T_DEFAULT expr if_expr T_EOL
203{
204 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800205 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210};
211
212config_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
218config_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
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700224symbol_option: T_OPTION symbol_option_list T_EOL
225;
226
227symbol_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
239symbol_option_arg:
240 /* empty */ { $$ = NULL; }
241 | T_EQUAL prompt { $$ = $2; }
242;
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244/* choice entry */
245
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100246choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100248 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
249 sym->flags |= SYMBOL_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 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
255choice_entry: choice choice_option_list
256{
Roman Zippela02f0572005-11-08 21:34:53 -0800257 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258};
259
260choice_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
Roman Zippela02f0572005-11-08 21:34:53 -0800268choice_stmt: choice_entry choice_block choice_end
269;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271choice_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
Roman Zippela02f0572005-11-08 21:34:53 -0800277 | choice_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278;
279
280choice_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
Roman Zippel3370f9f2005-11-08 21:34:52 -0800286choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800288 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295};
296
297choice_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
303choice_option: T_DEFAULT T_WORD if_expr T_EOL
304{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800305 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311};
312
313choice_block:
314 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800315 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316;
317
318/* if entry */
319
Roman Zippela02f0572005-11-08 21:34:53 -0800320if_entry: T_IF expr nl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
322 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
323 menu_add_entry(NULL);
324 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800325 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326};
327
328if_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
Roman Zippela02f0572005-11-08 21:34:53 -0800336if_stmt: if_entry if_block if_end
337;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339if_block:
340 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800341 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 | if_block menu_stmt
343 | if_block choice_stmt
344;
345
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400346/* mainmenu entry */
347
348mainmenu_stmt: T_MAINMENU prompt nl
349{
350 menu_add_prompt(P_MENU, $2, NULL);
351};
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353/* menu entry */
354
355menu: T_MENU prompt T_EOL
356{
357 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200358 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
360};
361
362menu_entry: menu depends_list
363{
Roman Zippela02f0572005-11-08 21:34:53 -0800364 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365};
366
367menu_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
Roman Zippela02f0572005-11-08 21:34:53 -0800375menu_stmt: menu_entry menu_block menu_end
376;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378menu_block:
379 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800380 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 | menu_block menu_stmt
382 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383;
384
Roman Zippela02f0572005-11-08 21:34:53 -0800385source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800388 zconf_nextfile($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389};
390
391/* comment entry */
392
393comment: T_COMMENT prompt T_EOL
394{
395 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200396 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
398};
399
400comment_stmt: comment depends_list
401{
402 menu_end_entry();
403};
404
405/* help option */
406
407help_start: T_HELP T_EOL
408{
409 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
410 zconf_starthelp();
411};
412
413help: help_start T_HELPTEXT
414{
Sam Ravnborg03d29122007-07-21 00:00:36 +0200415 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416};
417
418/* depends option */
419
Roman Zippela02f0572005-11-08 21:34:53 -0800420depends_list:
421 /* empty */
422 | depends_list depends
423 | depends_list T_EOL
424 | depends_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425;
426
427depends: 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());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431};
432
433/* prompt statement */
434
435prompt_stmt_opt:
436 /* empty */
437 | prompt if_expr
438{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200439 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440};
441
442prompt: T_WORD
443 | T_WORD_QUOTE
444;
445
Roman Zippela02f0572005-11-08 21:34:53 -0800446end: T_ENDMENU T_EOL { $$ = $1; }
447 | T_ENDCHOICE T_EOL { $$ = $1; }
448 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449;
450
Roman Zippela02f0572005-11-08 21:34:53 -0800451nl:
452 T_EOL
453 | nl T_EOL
454;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456if_expr: /* empty */ { $$ = NULL; }
457 | T_IF expr { $$ = $2; }
458;
459
460expr: 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
469symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100470 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471;
472
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100473word_opt: /* empty */ { $$ = NULL; }
474 | T_WORD
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476%%
477
478void conf_parse(const char *name)
479{
480 struct symbol *sym;
481 int i;
482
483 zconf_initscan(name);
484
485 sym_init();
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200486 _menu_init();
Roman Zippelface4372006-06-08 22:12:45 -0700487 modules_sym = sym_lookup(NULL, 0);
488 modules_sym->type = S_BOOLEAN;
489 modules_sym->flags |= SYMBOL_AUTO;
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200490 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Roman Zippela02f0572005-11-08 21:34:53 -0800492#if YYDEBUG
493 if (getenv("ZCONF_DEBUG"))
494 zconfdebug = 1;
495#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 zconfparse();
497 if (zconfnerrs)
498 exit(1);
Roman Zippelface4372006-06-08 22:12:45 -0700499 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 }
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400505
506 rootmenu.prompt->text = _(rootmenu.prompt->text);
507 rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 menu_finalize(&rootmenu);
510 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200511 if (sym_check_deps(sym))
512 zconfnerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
Sam Ravnborg5447d342007-05-06 09:20:10 +0200514 if (zconfnerrs)
515 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800516 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517}
518
Josh Triplett65166572009-10-15 12:13:36 -0700519static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
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";
Roman Zippela02f0572005-11-08 21:34:53 -0800528 case T_DEPENDS: return "depends";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 }
530 return "<token>";
531}
532
Roman Zippela02f0572005-11-08 21:34:53 -0800533static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534{
Roman Zippela02f0572005-11-08 21:34:53 -0800535 if (id->token != endtoken) {
536 zconf_error("unexpected '%s' within %s block",
537 kconf_id_strings + id->name, zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 zconfnerrs++;
539 return false;
540 }
541 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800542 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 zconfnerrs++;
548 return false;
549 }
550 return true;
551}
552
553static void zconfprint(const char *err, ...)
554{
555 va_list ap;
556
Roman Zippela02f0572005-11-08 21:34:53 -0800557 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
564static void zconf_error(const char *err, ...)
565{
566 va_list ap;
567
568 zconfnerrs++;
569 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 va_start(ap, err);
571 vfprintf(stderr, err, ap);
572 va_end(ap);
573 fprintf(stderr, "\n");
574}
575
576static void zconferror(const char *err)
577{
Roman Zippela02f0572005-11-08 21:34:53 -0800578#if YYDEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Roman Zippela02f0572005-11-08 21:34:53 -0800580#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
Josh Triplett65166572009-10-15 12:13:36 -0700583static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
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
Josh Triplett65166572009-10-15 12:13:36 -0700600static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
602 struct symbol *sym = menu->sym;
603 struct property *prop;
604
605 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800606 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800608 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 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;
Li Zefanc6ccc302010-04-14 11:44:20 +0800654 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 default:
670 fprintf(out, " unknown prop %d!\n", prop->type);
671 break;
672 }
673 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200674 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680}
681
682void 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
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"