blob: e9b14efd74147509728a85943371dd00e131e5f8 [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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 menu_finalize(&rootmenu);
506 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200507 if (sym_check_deps(sym))
508 zconfnerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
Sam Ravnborg5447d342007-05-06 09:20:10 +0200510 if (zconfnerrs)
511 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800512 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513}
514
Josh Triplett65166572009-10-15 12:13:36 -0700515static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
517 switch (token) {
518 case T_MENU: return "menu";
519 case T_ENDMENU: return "endmenu";
520 case T_CHOICE: return "choice";
521 case T_ENDCHOICE: return "endchoice";
522 case T_IF: return "if";
523 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800524 case T_DEPENDS: return "depends";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 }
526 return "<token>";
527}
528
Roman Zippela02f0572005-11-08 21:34:53 -0800529static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530{
Roman Zippela02f0572005-11-08 21:34:53 -0800531 if (id->token != endtoken) {
532 zconf_error("unexpected '%s' within %s block",
533 kconf_id_strings + id->name, zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 zconfnerrs++;
535 return false;
536 }
537 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800538 zconf_error("'%s' in different file than '%s'",
539 kconf_id_strings + id->name, zconf_tokenname(starttoken));
540 fprintf(stderr, "%s:%d: location of the '%s'\n",
541 current_menu->file->name, current_menu->lineno,
542 zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 zconfnerrs++;
544 return false;
545 }
546 return true;
547}
548
549static void zconfprint(const char *err, ...)
550{
551 va_list ap;
552
Roman Zippela02f0572005-11-08 21:34:53 -0800553 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
554 va_start(ap, err);
555 vfprintf(stderr, err, ap);
556 va_end(ap);
557 fprintf(stderr, "\n");
558}
559
560static void zconf_error(const char *err, ...)
561{
562 va_list ap;
563
564 zconfnerrs++;
565 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 va_start(ap, err);
567 vfprintf(stderr, err, ap);
568 va_end(ap);
569 fprintf(stderr, "\n");
570}
571
572static void zconferror(const char *err)
573{
Roman Zippela02f0572005-11-08 21:34:53 -0800574#if YYDEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Roman Zippela02f0572005-11-08 21:34:53 -0800576#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
Josh Triplett65166572009-10-15 12:13:36 -0700579static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
581 const char *p;
582 int len;
583
584 putc('"', out);
585 while ((p = strchr(str, '"'))) {
586 len = p - str;
587 if (len)
588 fprintf(out, "%.*s", len, str);
589 fputs("\\\"", out);
590 str = p + 1;
591 }
592 fputs(str, out);
593 putc('"', out);
594}
595
Josh Triplett65166572009-10-15 12:13:36 -0700596static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
598 struct symbol *sym = menu->sym;
599 struct property *prop;
600
601 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800602 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800604 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 switch (sym->type) {
606 case S_BOOLEAN:
607 fputs(" boolean\n", out);
608 break;
609 case S_TRISTATE:
610 fputs(" tristate\n", out);
611 break;
612 case S_STRING:
613 fputs(" string\n", out);
614 break;
615 case S_INT:
616 fputs(" integer\n", out);
617 break;
618 case S_HEX:
619 fputs(" hex\n", out);
620 break;
621 default:
622 fputs(" ???\n", out);
623 break;
624 }
625 for (prop = sym->prop; prop; prop = prop->next) {
626 if (prop->menu != menu)
627 continue;
628 switch (prop->type) {
629 case P_PROMPT:
630 fputs(" prompt ", out);
631 print_quoted_string(out, prop->text);
632 if (!expr_is_yes(prop->visible.expr)) {
633 fputs(" if ", out);
634 expr_fprint(prop->visible.expr, out);
635 }
636 fputc('\n', out);
637 break;
638 case P_DEFAULT:
639 fputs( " default ", out);
640 expr_fprint(prop->expr, out);
641 if (!expr_is_yes(prop->visible.expr)) {
642 fputs(" if ", out);
643 expr_fprint(prop->visible.expr, out);
644 }
645 fputc('\n', out);
646 break;
647 case P_CHOICE:
648 fputs(" #choice value\n", out);
649 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800650 case P_SELECT:
651 fputs( " select ", out);
652 expr_fprint(prop->expr, out);
653 fputc('\n', out);
654 break;
655 case P_RANGE:
656 fputs( " range ", out);
657 expr_fprint(prop->expr, out);
658 fputc('\n', out);
659 break;
660 case P_MENU:
661 fputs( " menu ", out);
662 print_quoted_string(out, prop->text);
663 fputc('\n', out);
664 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 default:
666 fprintf(out, " unknown prop %d!\n", prop->type);
667 break;
668 }
669 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200670 if (menu->help) {
671 int len = strlen(menu->help);
672 while (menu->help[--len] == '\n')
673 menu->help[len] = 0;
674 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676}
677
678void zconfdump(FILE *out)
679{
680 struct property *prop;
681 struct symbol *sym;
682 struct menu *menu;
683
684 menu = rootmenu.list;
685 while (menu) {
686 if ((sym = menu->sym))
687 print_symbol(out, menu);
688 else if ((prop = menu->prompt)) {
689 switch (prop->type) {
690 case P_COMMENT:
691 fputs("\ncomment ", out);
692 print_quoted_string(out, prop->text);
693 fputs("\n", out);
694 break;
695 case P_MENU:
696 fputs("\nmenu ", out);
697 print_quoted_string(out, prop->text);
698 fputs("\n", out);
699 break;
700 default:
701 ;
702 }
703 if (!expr_is_yes(prop->visible.expr)) {
704 fputs(" depends ", out);
705 expr_fprint(prop->visible.expr, out);
706 fputc('\n', out);
707 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 }
709
710 if (menu->list)
711 menu = menu->list;
712 else if (menu->next)
713 menu = menu->next;
714 else while ((menu = menu->parent)) {
715 if (menu->prompt && menu->prompt->type == P_MENU)
716 fputs("\nendmenu\n", out);
717 if (menu->next) {
718 menu = menu->next;
719 break;
720 }
721 }
722 }
723}
724
725#include "lex.zconf.c"
726#include "util.c"
727#include "confdata.c"
728#include "expr.c"
729#include "symbol.c"
730#include "menu.c"