blob: 71bf8bff696a41ff3f3ff8cdfe46149e4e11506d [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#include "lkc.h"
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
17
18#define PRINTD 0x0001
19#define DEBUG_PARSE 0x0002
20
21int cdebug = PRINTD;
22
23extern int zconflex(void);
24static void zconfprint(const char *err, ...);
Roman Zippela02f0572005-11-08 21:34:53 -080025static void zconf_error(const char *err, ...);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026static void zconferror(const char *err);
Arnaud Lacombe61f956f2011-05-04 21:14:44 -040027static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Andi Kleene66f25d2010-01-13 17:02:44 +010029struct symbol *symbol_hash[SYMBOL_HASHSIZE];
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31static struct menu *current_menu, *current_entry;
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033%}
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030034%expect 30
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36%union
37{
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 char *string;
Roman Zippela02f0572005-11-08 21:34:53 -080039 struct file *file;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 struct symbol *symbol;
41 struct expr *expr;
42 struct menu *menu;
Arnaud Lacombe61f956f2011-05-04 21:14:44 -040043 const struct kconf_id *id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
Roman Zippel3370f9f2005-11-08 21:34:52 -080046%token <id>T_MAINMENU
47%token <id>T_MENU
48%token <id>T_ENDMENU
49%token <id>T_SOURCE
50%token <id>T_CHOICE
51%token <id>T_ENDCHOICE
52%token <id>T_COMMENT
53%token <id>T_CONFIG
54%token <id>T_MENUCONFIG
55%token <id>T_HELP
Linus Torvalds1da177e2005-04-16 15:20:36 -070056%token <string> T_HELPTEXT
Roman Zippel3370f9f2005-11-08 21:34:52 -080057%token <id>T_IF
58%token <id>T_ENDIF
59%token <id>T_DEPENDS
Roman Zippel3370f9f2005-11-08 21:34:52 -080060%token <id>T_OPTIONAL
61%token <id>T_PROMPT
62%token <id>T_TYPE
63%token <id>T_DEFAULT
64%token <id>T_SELECT
65%token <id>T_RANGE
Arnaud Lacombe86e187f2010-11-06 18:30:23 -030066%token <id>T_VISIBLE
Roman Zippelf6a88aa2006-06-08 22:12:44 -070067%token <id>T_OPTION
Roman Zippel3370f9f2005-11-08 21:34:52 -080068%token <id>T_ON
Linus Torvalds1da177e2005-04-16 15:20:36 -070069%token <string> T_WORD
70%token <string> T_WORD_QUOTE
71%token T_UNEQUAL
Jan Beulich31847b62015-06-15 13:00:21 +010072%token T_LESS
73%token T_LESS_EQUAL
74%token T_GREATER
75%token T_GREATER_EQUAL
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
Jan Beulich31847b62015-06-15 13:00:21 +010083%left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
Linus Torvalds1da177e2005-04-16 15:20:36 -070084%nonassoc T_NOT
85
86%type <string> prompt
Linus Torvalds1da177e2005-04-16 15:20:36 -070087%type <symbol> symbol
88%type <expr> expr
89%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080090%type <id> end
91%type <id> option_name
92%type <menu> if_entry menu_entry choice_entry
Roman Zippel5a1aa8a2008-02-29 05:11:50 +010093%type <string> symbol_option_arg word_opt
Roman Zippela02f0572005-11-08 21:34:53 -080094
95%destructor {
96 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
97 $$->file->name, $$->lineno);
98 if (current_menu == $$)
99 menu_end_menu();
100} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Josh Triplett1456edb2009-10-15 11:03:20 -0700102%{
103/* Include zconf.hash.c here so it can see the token constants. */
104#include "zconf.hash.c"
105%}
106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107%%
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400108input: nl start | start;
109
110start: mainmenu_stmt stmt_list | stmt_list;
Roman Zippela02f0572005-11-08 21:34:53 -0800111
112stmt_list:
113 /* empty */
114 | stmt_list common_stmt
115 | stmt_list choice_stmt
116 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800117 | stmt_list end { zconf_error("unexpected end statement"); }
118 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
119 | stmt_list option_name error T_EOL
120{
121 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
122}
123 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124;
125
Roman Zippela02f0572005-11-08 21:34:53 -0800126option_name:
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300127 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128;
129
Roman Zippela02f0572005-11-08 21:34:53 -0800130common_stmt:
131 T_EOL
132 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 | comment_stmt
134 | config_stmt
135 | menuconfig_stmt
136 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800137;
138
139option_error:
140 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
141 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142;
143
144
145/* config/menuconfig entry */
146
147config_entry_start: T_CONFIG T_WORD T_EOL
148{
149 struct symbol *sym = sym_lookup($2, 0);
150 sym->flags |= SYMBOL_OPTIONAL;
151 menu_add_entry(sym);
152 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
153};
154
155config_stmt: config_entry_start config_option_list
156{
157 menu_end_entry();
158 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
159};
160
161menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
162{
163 struct symbol *sym = sym_lookup($2, 0);
164 sym->flags |= SYMBOL_OPTIONAL;
165 menu_add_entry(sym);
166 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
167};
168
169menuconfig_stmt: menuconfig_entry_start config_option_list
170{
171 if (current_entry->prompt)
172 current_entry->prompt->type = P_MENU;
173 else
174 zconfprint("warning: menuconfig statement without prompt");
175 menu_end_entry();
176 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
177};
178
179config_option_list:
180 /* empty */
181 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700182 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 | config_option_list depends
184 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800185 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 | config_option_list T_EOL
187;
188
Roman Zippel3370f9f2005-11-08 21:34:52 -0800189config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800191 menu_set_type($1->stype);
192 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
193 zconf_curname(), zconf_lineno(),
194 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195};
196
197config_option: T_PROMPT prompt if_expr T_EOL
198{
199 menu_add_prompt(P_PROMPT, $2, $3);
200 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
201};
202
203config_option: T_DEFAULT expr if_expr T_EOL
204{
205 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800206 if ($1->stype != S_UNKNOWN)
207 menu_set_type($1->stype);
208 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
209 zconf_curname(), zconf_lineno(),
210 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211};
212
213config_option: T_SELECT T_WORD if_expr T_EOL
214{
215 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
216 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
217};
218
219config_option: T_RANGE symbol symbol if_expr T_EOL
220{
221 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
222 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
223};
224
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700225symbol_option: T_OPTION symbol_option_list T_EOL
226;
227
228symbol_option_list:
229 /* empty */
230 | symbol_option_list T_WORD symbol_option_arg
231{
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400232 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700233 if (id && id->flags & TF_OPTION)
234 menu_add_option(id->token, $3);
235 else
236 zconfprint("warning: ignoring unknown option %s", $2);
237 free($2);
238};
239
240symbol_option_arg:
241 /* empty */ { $$ = NULL; }
242 | T_EQUAL prompt { $$ = $2; }
243;
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245/* choice entry */
246
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100247choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100249 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
250 sym->flags |= SYMBOL_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 menu_add_entry(sym);
252 menu_add_expr(P_CHOICE, NULL, NULL);
253 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
254};
255
256choice_entry: choice choice_option_list
257{
Roman Zippela02f0572005-11-08 21:34:53 -0800258 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259};
260
261choice_end: end
262{
263 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
264 menu_end_menu();
265 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
266 }
267};
268
Roman Zippela02f0572005-11-08 21:34:53 -0800269choice_stmt: choice_entry choice_block choice_end
270;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
272choice_option_list:
273 /* empty */
274 | choice_option_list choice_option
275 | choice_option_list depends
276 | choice_option_list help
277 | choice_option_list T_EOL
Roman Zippela02f0572005-11-08 21:34:53 -0800278 | choice_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279;
280
281choice_option: T_PROMPT prompt if_expr T_EOL
282{
283 menu_add_prompt(P_PROMPT, $2, $3);
284 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
285};
286
Roman Zippel3370f9f2005-11-08 21:34:52 -0800287choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800289 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
290 menu_set_type($1->stype);
291 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
292 zconf_curname(), zconf_lineno(),
293 $1->stype);
294 } else
295 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296};
297
298choice_option: T_OPTIONAL T_EOL
299{
300 current_entry->sym->flags |= SYMBOL_OPTIONAL;
301 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
302};
303
304choice_option: T_DEFAULT T_WORD if_expr T_EOL
305{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800306 if ($1->stype == S_UNKNOWN) {
307 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
308 printd(DEBUG_PARSE, "%s:%d:default\n",
309 zconf_curname(), zconf_lineno());
310 } else
311 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312};
313
314choice_block:
315 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800316 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317;
318
319/* if entry */
320
Roman Zippela02f0572005-11-08 21:34:53 -0800321if_entry: T_IF expr nl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
323 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
324 menu_add_entry(NULL);
325 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800326 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327};
328
329if_end: end
330{
331 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
332 menu_end_menu();
333 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
334 }
335};
336
Roman Zippela02f0572005-11-08 21:34:53 -0800337if_stmt: if_entry if_block if_end
338;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340if_block:
341 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800342 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 | if_block menu_stmt
344 | if_block choice_stmt
345;
346
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400347/* mainmenu entry */
348
349mainmenu_stmt: T_MAINMENU prompt nl
350{
351 menu_add_prompt(P_MENU, $2, NULL);
352};
353
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354/* menu entry */
355
356menu: T_MENU prompt T_EOL
357{
358 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200359 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
361};
362
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300363menu_entry: menu visibility_list depends_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Roman Zippela02f0572005-11-08 21:34:53 -0800365 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366};
367
368menu_end: end
369{
370 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
371 menu_end_menu();
372 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
373 }
374};
375
Roman Zippela02f0572005-11-08 21:34:53 -0800376menu_stmt: menu_entry menu_block menu_end
377;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379menu_block:
380 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800381 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 | menu_block menu_stmt
383 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384;
385
Roman Zippela02f0572005-11-08 21:34:53 -0800386source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800389 zconf_nextfile($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390};
391
392/* comment entry */
393
394comment: T_COMMENT prompt T_EOL
395{
396 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200397 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
399};
400
401comment_stmt: comment depends_list
402{
403 menu_end_entry();
404};
405
406/* help option */
407
408help_start: T_HELP T_EOL
409{
410 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
411 zconf_starthelp();
412};
413
414help: help_start T_HELPTEXT
415{
Sam Ravnborg03d29122007-07-21 00:00:36 +0200416 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417};
418
419/* depends option */
420
Roman Zippela02f0572005-11-08 21:34:53 -0800421depends_list:
422 /* empty */
423 | depends_list depends
424 | depends_list T_EOL
425 | depends_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426;
427
428depends: T_DEPENDS T_ON expr T_EOL
429{
430 menu_add_dep($3);
431 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432};
433
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300434/* visibility option */
435
436visibility_list:
437 /* empty */
438 | visibility_list visible
439 | visibility_list T_EOL
440;
441
442visible: T_VISIBLE if_expr
443{
444 menu_add_visibility($2);
445};
446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447/* prompt statement */
448
449prompt_stmt_opt:
450 /* empty */
451 | prompt if_expr
452{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200453 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454};
455
456prompt: T_WORD
457 | T_WORD_QUOTE
458;
459
Roman Zippela02f0572005-11-08 21:34:53 -0800460end: T_ENDMENU T_EOL { $$ = $1; }
461 | T_ENDCHOICE T_EOL { $$ = $1; }
462 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463;
464
Roman Zippela02f0572005-11-08 21:34:53 -0800465nl:
466 T_EOL
467 | nl T_EOL
468;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
470if_expr: /* empty */ { $$ = NULL; }
471 | T_IF expr { $$ = $2; }
472;
473
474expr: symbol { $$ = expr_alloc_symbol($1); }
Jan Beulich31847b62015-06-15 13:00:21 +0100475 | symbol T_LESS symbol { $$ = expr_alloc_comp(E_LTH, $1, $3); }
476 | symbol T_LESS_EQUAL symbol { $$ = expr_alloc_comp(E_LEQ, $1, $3); }
477 | symbol T_GREATER symbol { $$ = expr_alloc_comp(E_GTH, $1, $3); }
478 | symbol T_GREATER_EQUAL symbol { $$ = expr_alloc_comp(E_GEQ, $1, $3); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
480 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
481 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
482 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
483 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
484 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
485;
486
487symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100488 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489;
490
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100491word_opt: /* empty */ { $$ = NULL; }
492 | T_WORD
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494%%
495
496void conf_parse(const char *name)
497{
498 struct symbol *sym;
499 int i;
500
501 zconf_initscan(name);
502
503 sym_init();
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200504 _menu_init();
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200505 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Roman Zippela02f0572005-11-08 21:34:53 -0800507 if (getenv("ZCONF_DEBUG"))
508 zconfdebug = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 zconfparse();
510 if (zconfnerrs)
511 exit(1);
Yann E. MORIN6902dcc2013-09-03 17:07:18 +0200512 if (!modules_sym)
513 modules_sym = sym_find( "n" );
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400514
515 rootmenu.prompt->text = _(rootmenu.prompt->text);
516 rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 menu_finalize(&rootmenu);
519 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200520 if (sym_check_deps(sym))
521 zconfnerrs++;
Masahiro Yamadabb66fc62014-06-10 19:08:13 +0900522 }
Sam Ravnborg5447d342007-05-06 09:20:10 +0200523 if (zconfnerrs)
524 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800525 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526}
527
Josh Triplett65166572009-10-15 12:13:36 -0700528static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
530 switch (token) {
531 case T_MENU: return "menu";
532 case T_ENDMENU: return "endmenu";
533 case T_CHOICE: return "choice";
534 case T_ENDCHOICE: return "endchoice";
535 case T_IF: return "if";
536 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800537 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300538 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 }
540 return "<token>";
541}
542
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400543static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Roman Zippela02f0572005-11-08 21:34:53 -0800545 if (id->token != endtoken) {
546 zconf_error("unexpected '%s' within %s block",
547 kconf_id_strings + id->name, zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 zconfnerrs++;
549 return false;
550 }
551 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800552 zconf_error("'%s' in different file than '%s'",
553 kconf_id_strings + id->name, zconf_tokenname(starttoken));
554 fprintf(stderr, "%s:%d: location of the '%s'\n",
555 current_menu->file->name, current_menu->lineno,
556 zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 zconfnerrs++;
558 return false;
559 }
560 return true;
561}
562
563static void zconfprint(const char *err, ...)
564{
565 va_list ap;
566
Roman Zippela02f0572005-11-08 21:34:53 -0800567 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
568 va_start(ap, err);
569 vfprintf(stderr, err, ap);
570 va_end(ap);
571 fprintf(stderr, "\n");
572}
573
574static void zconf_error(const char *err, ...)
575{
576 va_list ap;
577
578 zconfnerrs++;
579 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 va_start(ap, err);
581 vfprintf(stderr, err, ap);
582 va_end(ap);
583 fprintf(stderr, "\n");
584}
585
586static void zconferror(const char *err)
587{
588 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589}
590
Josh Triplett65166572009-10-15 12:13:36 -0700591static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592{
593 const char *p;
594 int len;
595
596 putc('"', out);
597 while ((p = strchr(str, '"'))) {
598 len = p - str;
599 if (len)
600 fprintf(out, "%.*s", len, str);
601 fputs("\\\"", out);
602 str = p + 1;
603 }
604 fputs(str, out);
605 putc('"', out);
606}
607
Josh Triplett65166572009-10-15 12:13:36 -0700608static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
610 struct symbol *sym = menu->sym;
611 struct property *prop;
612
613 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800614 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800616 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 switch (sym->type) {
618 case S_BOOLEAN:
619 fputs(" boolean\n", out);
620 break;
621 case S_TRISTATE:
622 fputs(" tristate\n", out);
623 break;
624 case S_STRING:
625 fputs(" string\n", out);
626 break;
627 case S_INT:
628 fputs(" integer\n", out);
629 break;
630 case S_HEX:
631 fputs(" hex\n", out);
632 break;
633 default:
634 fputs(" ???\n", out);
635 break;
636 }
637 for (prop = sym->prop; prop; prop = prop->next) {
638 if (prop->menu != menu)
639 continue;
640 switch (prop->type) {
641 case P_PROMPT:
642 fputs(" prompt ", out);
643 print_quoted_string(out, prop->text);
644 if (!expr_is_yes(prop->visible.expr)) {
645 fputs(" if ", out);
646 expr_fprint(prop->visible.expr, out);
647 }
648 fputc('\n', out);
649 break;
650 case P_DEFAULT:
651 fputs( " default ", out);
652 expr_fprint(prop->expr, out);
653 if (!expr_is_yes(prop->visible.expr)) {
654 fputs(" if ", out);
655 expr_fprint(prop->visible.expr, out);
656 }
657 fputc('\n', out);
658 break;
659 case P_CHOICE:
660 fputs(" #choice value\n", out);
661 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800662 case P_SELECT:
663 fputs( " select ", out);
664 expr_fprint(prop->expr, out);
665 fputc('\n', out);
666 break;
667 case P_RANGE:
668 fputs( " range ", out);
669 expr_fprint(prop->expr, out);
670 fputc('\n', out);
671 break;
672 case P_MENU:
673 fputs( " menu ", out);
674 print_quoted_string(out, prop->text);
675 fputc('\n', out);
676 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 default:
678 fprintf(out, " unknown prop %d!\n", prop->type);
679 break;
680 }
681 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200682 if (menu->help) {
683 int len = strlen(menu->help);
684 while (menu->help[--len] == '\n')
685 menu->help[len] = 0;
686 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688}
689
690void zconfdump(FILE *out)
691{
692 struct property *prop;
693 struct symbol *sym;
694 struct menu *menu;
695
696 menu = rootmenu.list;
697 while (menu) {
698 if ((sym = menu->sym))
699 print_symbol(out, menu);
700 else if ((prop = menu->prompt)) {
701 switch (prop->type) {
702 case P_COMMENT:
703 fputs("\ncomment ", out);
704 print_quoted_string(out, prop->text);
705 fputs("\n", out);
706 break;
707 case P_MENU:
708 fputs("\nmenu ", out);
709 print_quoted_string(out, prop->text);
710 fputs("\n", out);
711 break;
712 default:
713 ;
714 }
715 if (!expr_is_yes(prop->visible.expr)) {
716 fputs(" depends ", out);
717 expr_fprint(prop->visible.expr, out);
718 fputc('\n', out);
719 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721
722 if (menu->list)
723 menu = menu->list;
724 else if (menu->next)
725 menu = menu->next;
726 else while ((menu = menu->parent)) {
727 if (menu->prompt && menu->prompt->type == P_MENU)
728 fputs("\nendmenu\n", out);
729 if (menu->next) {
730 menu = menu->next;
731 break;
732 }
733 }
734 }
735}
736
Arnaud Lacombe378dbb22011-05-23 02:08:52 -0400737#include "zconf.lex.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738#include "util.c"
739#include "confdata.c"
740#include "expr.c"
741#include "symbol.c"
742#include "menu.c"