blob: 864da07ba4aadc02a71a0e4b8414ef330f570674 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070072%token T_CLOSE_PAREN
73%token T_OPEN_PAREN
Roman Zippel3370f9f2005-11-08 21:34:52 -080074%token T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76%left T_OR
77%left T_AND
78%left T_EQUAL T_UNEQUAL
79%nonassoc T_NOT
80
81%type <string> prompt
Linus Torvalds1da177e2005-04-16 15:20:36 -070082%type <symbol> symbol
83%type <expr> expr
84%type <expr> if_expr
Roman Zippela02f0572005-11-08 21:34:53 -080085%type <id> end
86%type <id> option_name
87%type <menu> if_entry menu_entry choice_entry
Roman Zippel5a1aa8a2008-02-29 05:11:50 +010088%type <string> symbol_option_arg word_opt
Roman Zippela02f0572005-11-08 21:34:53 -080089
90%destructor {
91 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
92 $$->file->name, $$->lineno);
93 if (current_menu == $$)
94 menu_end_menu();
95} if_entry menu_entry choice_entry
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Josh Triplett1456edb2009-10-15 11:03:20 -070097%{
98/* Include zconf.hash.c here so it can see the token constants. */
99#include "zconf.hash.c"
100%}
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102%%
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400103input: nl start | start;
104
105start: mainmenu_stmt stmt_list | stmt_list;
Roman Zippela02f0572005-11-08 21:34:53 -0800106
107stmt_list:
108 /* empty */
109 | stmt_list common_stmt
110 | stmt_list choice_stmt
111 | stmt_list menu_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800112 | stmt_list end { zconf_error("unexpected end statement"); }
113 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
114 | stmt_list option_name error T_EOL
115{
116 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
117}
118 | stmt_list error T_EOL { zconf_error("invalid statement"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119;
120
Roman Zippela02f0572005-11-08 21:34:53 -0800121option_name:
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300122 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123;
124
Roman Zippela02f0572005-11-08 21:34:53 -0800125common_stmt:
126 T_EOL
127 | if_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 | comment_stmt
129 | config_stmt
130 | menuconfig_stmt
131 | source_stmt
Roman Zippela02f0572005-11-08 21:34:53 -0800132;
133
134option_error:
135 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
136 | error T_EOL { zconf_error("invalid option"); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137;
138
139
140/* config/menuconfig entry */
141
142config_entry_start: T_CONFIG T_WORD T_EOL
143{
144 struct symbol *sym = sym_lookup($2, 0);
145 sym->flags |= SYMBOL_OPTIONAL;
146 menu_add_entry(sym);
147 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
148};
149
150config_stmt: config_entry_start config_option_list
151{
152 menu_end_entry();
153 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
154};
155
156menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
157{
158 struct symbol *sym = sym_lookup($2, 0);
159 sym->flags |= SYMBOL_OPTIONAL;
160 menu_add_entry(sym);
161 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
162};
163
164menuconfig_stmt: menuconfig_entry_start config_option_list
165{
166 if (current_entry->prompt)
167 current_entry->prompt->type = P_MENU;
168 else
169 zconfprint("warning: menuconfig statement without prompt");
170 menu_end_entry();
171 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
172};
173
174config_option_list:
175 /* empty */
176 | config_option_list config_option
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700177 | config_option_list symbol_option
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 | config_option_list depends
179 | config_option_list help
Roman Zippela02f0572005-11-08 21:34:53 -0800180 | config_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 | config_option_list T_EOL
182;
183
Roman Zippel3370f9f2005-11-08 21:34:52 -0800184config_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800186 menu_set_type($1->stype);
187 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
188 zconf_curname(), zconf_lineno(),
189 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190};
191
192config_option: T_PROMPT prompt if_expr T_EOL
193{
194 menu_add_prompt(P_PROMPT, $2, $3);
195 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
196};
197
198config_option: T_DEFAULT expr if_expr T_EOL
199{
200 menu_add_expr(P_DEFAULT, $2, $3);
Roman Zippel3370f9f2005-11-08 21:34:52 -0800201 if ($1->stype != S_UNKNOWN)
202 menu_set_type($1->stype);
203 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
204 zconf_curname(), zconf_lineno(),
205 $1->stype);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206};
207
208config_option: T_SELECT T_WORD if_expr T_EOL
209{
210 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
211 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
212};
213
214config_option: T_RANGE symbol symbol if_expr T_EOL
215{
216 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
217 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
218};
219
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700220symbol_option: T_OPTION symbol_option_list T_EOL
221;
222
223symbol_option_list:
224 /* empty */
225 | symbol_option_list T_WORD symbol_option_arg
226{
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400227 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
Roman Zippelf6a88aa2006-06-08 22:12:44 -0700228 if (id && id->flags & TF_OPTION)
229 menu_add_option(id->token, $3);
230 else
231 zconfprint("warning: ignoring unknown option %s", $2);
232 free($2);
233};
234
235symbol_option_arg:
236 /* empty */ { $$ = NULL; }
237 | T_EQUAL prompt { $$ = $2; }
238;
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/* choice entry */
241
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100242choice: T_CHOICE word_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100244 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
245 sym->flags |= SYMBOL_AUTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 menu_add_entry(sym);
247 menu_add_expr(P_CHOICE, NULL, NULL);
248 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
249};
250
251choice_entry: choice choice_option_list
252{
Roman Zippela02f0572005-11-08 21:34:53 -0800253 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254};
255
256choice_end: end
257{
258 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
259 menu_end_menu();
260 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
261 }
262};
263
Roman Zippela02f0572005-11-08 21:34:53 -0800264choice_stmt: choice_entry choice_block choice_end
265;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267choice_option_list:
268 /* empty */
269 | choice_option_list choice_option
270 | choice_option_list depends
271 | choice_option_list help
272 | choice_option_list T_EOL
Roman Zippela02f0572005-11-08 21:34:53 -0800273 | choice_option_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274;
275
276choice_option: T_PROMPT prompt if_expr T_EOL
277{
278 menu_add_prompt(P_PROMPT, $2, $3);
279 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
280};
281
Roman Zippel3370f9f2005-11-08 21:34:52 -0800282choice_option: T_TYPE prompt_stmt_opt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800284 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
285 menu_set_type($1->stype);
286 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
287 zconf_curname(), zconf_lineno(),
288 $1->stype);
289 } else
290 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291};
292
293choice_option: T_OPTIONAL T_EOL
294{
295 current_entry->sym->flags |= SYMBOL_OPTIONAL;
296 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
297};
298
299choice_option: T_DEFAULT T_WORD if_expr T_EOL
300{
Roman Zippel3370f9f2005-11-08 21:34:52 -0800301 if ($1->stype == S_UNKNOWN) {
302 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
303 printd(DEBUG_PARSE, "%s:%d:default\n",
304 zconf_curname(), zconf_lineno());
305 } else
306 YYERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307};
308
309choice_block:
310 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800311 | choice_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312;
313
314/* if entry */
315
Roman Zippela02f0572005-11-08 21:34:53 -0800316if_entry: T_IF expr nl
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
319 menu_add_entry(NULL);
320 menu_add_dep($2);
Roman Zippela02f0572005-11-08 21:34:53 -0800321 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322};
323
324if_end: end
325{
326 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
327 menu_end_menu();
328 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
329 }
330};
331
Roman Zippela02f0572005-11-08 21:34:53 -0800332if_stmt: if_entry if_block if_end
333;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335if_block:
336 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800337 | if_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 | if_block menu_stmt
339 | if_block choice_stmt
340;
341
Arnaud Lacombe8ea13e22010-08-16 22:55:31 -0400342/* mainmenu entry */
343
344mainmenu_stmt: T_MAINMENU prompt nl
345{
346 menu_add_prompt(P_MENU, $2, NULL);
347};
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349/* menu entry */
350
351menu: T_MENU prompt T_EOL
352{
353 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200354 menu_add_prompt(P_MENU, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
356};
357
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300358menu_entry: menu visibility_list depends_list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Roman Zippela02f0572005-11-08 21:34:53 -0800360 $$ = menu_add_menu();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361};
362
363menu_end: end
364{
365 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
366 menu_end_menu();
367 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
368 }
369};
370
Roman Zippela02f0572005-11-08 21:34:53 -0800371menu_stmt: menu_entry menu_block menu_end
372;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374menu_block:
375 /* empty */
Roman Zippela02f0572005-11-08 21:34:53 -0800376 | menu_block common_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 | menu_block menu_stmt
378 | menu_block choice_stmt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379;
380
Roman Zippela02f0572005-11-08 21:34:53 -0800381source_stmt: T_SOURCE prompt T_EOL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
Roman Zippela02f0572005-11-08 21:34:53 -0800384 zconf_nextfile($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385};
386
387/* comment entry */
388
389comment: T_COMMENT prompt T_EOL
390{
391 menu_add_entry(NULL);
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200392 menu_add_prompt(P_COMMENT, $2, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
394};
395
396comment_stmt: comment depends_list
397{
398 menu_end_entry();
399};
400
401/* help option */
402
403help_start: T_HELP T_EOL
404{
405 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
406 zconf_starthelp();
407};
408
409help: help_start T_HELPTEXT
410{
Sam Ravnborg03d29122007-07-21 00:00:36 +0200411 current_entry->help = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412};
413
414/* depends option */
415
Roman Zippela02f0572005-11-08 21:34:53 -0800416depends_list:
417 /* empty */
418 | depends_list depends
419 | depends_list T_EOL
420 | depends_list option_error
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421;
422
423depends: T_DEPENDS T_ON expr T_EOL
424{
425 menu_add_dep($3);
426 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427};
428
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300429/* visibility option */
430
431visibility_list:
432 /* empty */
433 | visibility_list visible
434 | visibility_list T_EOL
435;
436
437visible: T_VISIBLE if_expr
438{
439 menu_add_visibility($2);
440};
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442/* prompt statement */
443
444prompt_stmt_opt:
445 /* empty */
446 | prompt if_expr
447{
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200448 menu_add_prompt(P_PROMPT, $1, $2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449};
450
451prompt: T_WORD
452 | T_WORD_QUOTE
453;
454
Roman Zippela02f0572005-11-08 21:34:53 -0800455end: T_ENDMENU T_EOL { $$ = $1; }
456 | T_ENDCHOICE T_EOL { $$ = $1; }
457 | T_ENDIF T_EOL { $$ = $1; }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458;
459
Roman Zippela02f0572005-11-08 21:34:53 -0800460nl:
461 T_EOL
462 | nl T_EOL
463;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
465if_expr: /* empty */ { $$ = NULL; }
466 | T_IF expr { $$ = $2; }
467;
468
469expr: symbol { $$ = expr_alloc_symbol($1); }
470 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
471 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
472 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
473 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
474 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
475 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
476;
477
478symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100479 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480;
481
Roman Zippel5a1aa8a2008-02-29 05:11:50 +0100482word_opt: /* empty */ { $$ = NULL; }
483 | T_WORD
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485%%
486
487void conf_parse(const char *name)
488{
489 struct symbol *sym;
490 int i;
491
492 zconf_initscan(name);
493
494 sym_init();
nir.tzachar@gmail.com692d97c2009-11-25 12:28:43 +0200495 _menu_init();
Roman Zippelface4372006-06-08 22:12:45 -0700496 modules_sym = sym_lookup(NULL, 0);
497 modules_sym->type = S_BOOLEAN;
498 modules_sym->flags |= SYMBOL_AUTO;
blaisorblade@yahoo.itfb7f6ff2005-07-28 17:56:25 +0200499 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Roman Zippela02f0572005-11-08 21:34:53 -0800501 if (getenv("ZCONF_DEBUG"))
502 zconfdebug = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 zconfparse();
504 if (zconfnerrs)
505 exit(1);
Roman Zippelface4372006-06-08 22:12:45 -0700506 if (!modules_sym->prop) {
507 struct property *prop;
508
509 prop = prop_alloc(P_DEFAULT, modules_sym);
510 prop->expr = expr_alloc_symbol(sym_lookup("MODULES", 0));
511 }
Arnaud Lacombef6ce00b2010-09-09 21:17:26 -0400512
513 rootmenu.prompt->text = _(rootmenu.prompt->text);
514 rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
515
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 menu_finalize(&rootmenu);
517 for_all_symbols(i, sym) {
Sam Ravnborg5447d342007-05-06 09:20:10 +0200518 if (sym_check_deps(sym))
519 zconfnerrs++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
Sam Ravnborg5447d342007-05-06 09:20:10 +0200521 if (zconfnerrs)
522 exit(1);
Karsten Wiesebfc10002006-12-13 00:34:07 -0800523 sym_set_change_count(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524}
525
Josh Triplett65166572009-10-15 12:13:36 -0700526static const char *zconf_tokenname(int token)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
528 switch (token) {
529 case T_MENU: return "menu";
530 case T_ENDMENU: return "endmenu";
531 case T_CHOICE: return "choice";
532 case T_ENDCHOICE: return "endchoice";
533 case T_IF: return "if";
534 case T_ENDIF: return "endif";
Roman Zippela02f0572005-11-08 21:34:53 -0800535 case T_DEPENDS: return "depends";
Arnaud Lacombe86e187f2010-11-06 18:30:23 -0300536 case T_VISIBLE: return "visible";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 }
538 return "<token>";
539}
540
Arnaud Lacombe61f956f2011-05-04 21:14:44 -0400541static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Roman Zippela02f0572005-11-08 21:34:53 -0800543 if (id->token != endtoken) {
544 zconf_error("unexpected '%s' within %s block",
545 kconf_id_strings + id->name, zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 zconfnerrs++;
547 return false;
548 }
549 if (current_menu->file != current_file) {
Roman Zippela02f0572005-11-08 21:34:53 -0800550 zconf_error("'%s' in different file than '%s'",
551 kconf_id_strings + id->name, zconf_tokenname(starttoken));
552 fprintf(stderr, "%s:%d: location of the '%s'\n",
553 current_menu->file->name, current_menu->lineno,
554 zconf_tokenname(starttoken));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 zconfnerrs++;
556 return false;
557 }
558 return true;
559}
560
561static void zconfprint(const char *err, ...)
562{
563 va_list ap;
564
Roman Zippela02f0572005-11-08 21:34:53 -0800565 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
566 va_start(ap, err);
567 vfprintf(stderr, err, ap);
568 va_end(ap);
569 fprintf(stderr, "\n");
570}
571
572static void zconf_error(const char *err, ...)
573{
574 va_list ap;
575
576 zconfnerrs++;
577 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 va_start(ap, err);
579 vfprintf(stderr, err, ap);
580 va_end(ap);
581 fprintf(stderr, "\n");
582}
583
584static void zconferror(const char *err)
585{
586 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587}
588
Josh Triplett65166572009-10-15 12:13:36 -0700589static void print_quoted_string(FILE *out, const char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
591 const char *p;
592 int len;
593
594 putc('"', out);
595 while ((p = strchr(str, '"'))) {
596 len = p - str;
597 if (len)
598 fprintf(out, "%.*s", len, str);
599 fputs("\\\"", out);
600 str = p + 1;
601 }
602 fputs(str, out);
603 putc('"', out);
604}
605
Josh Triplett65166572009-10-15 12:13:36 -0700606static void print_symbol(FILE *out, struct menu *menu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607{
608 struct symbol *sym = menu->sym;
609 struct property *prop;
610
611 if (sym_is_choice(sym))
Li Zefanc6ccc302010-04-14 11:44:20 +0800612 fprintf(out, "\nchoice\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 else
Li Zefanc6ccc302010-04-14 11:44:20 +0800614 fprintf(out, "\nconfig %s\n", sym->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 switch (sym->type) {
616 case S_BOOLEAN:
617 fputs(" boolean\n", out);
618 break;
619 case S_TRISTATE:
620 fputs(" tristate\n", out);
621 break;
622 case S_STRING:
623 fputs(" string\n", out);
624 break;
625 case S_INT:
626 fputs(" integer\n", out);
627 break;
628 case S_HEX:
629 fputs(" hex\n", out);
630 break;
631 default:
632 fputs(" ???\n", out);
633 break;
634 }
635 for (prop = sym->prop; prop; prop = prop->next) {
636 if (prop->menu != menu)
637 continue;
638 switch (prop->type) {
639 case P_PROMPT:
640 fputs(" prompt ", out);
641 print_quoted_string(out, prop->text);
642 if (!expr_is_yes(prop->visible.expr)) {
643 fputs(" if ", out);
644 expr_fprint(prop->visible.expr, out);
645 }
646 fputc('\n', out);
647 break;
648 case P_DEFAULT:
649 fputs( " default ", out);
650 expr_fprint(prop->expr, out);
651 if (!expr_is_yes(prop->visible.expr)) {
652 fputs(" if ", out);
653 expr_fprint(prop->visible.expr, out);
654 }
655 fputc('\n', out);
656 break;
657 case P_CHOICE:
658 fputs(" #choice value\n", out);
659 break;
Li Zefanc6ccc302010-04-14 11:44:20 +0800660 case P_SELECT:
661 fputs( " select ", out);
662 expr_fprint(prop->expr, out);
663 fputc('\n', out);
664 break;
665 case P_RANGE:
666 fputs( " range ", out);
667 expr_fprint(prop->expr, out);
668 fputc('\n', out);
669 break;
670 case P_MENU:
671 fputs( " menu ", out);
672 print_quoted_string(out, prop->text);
673 fputc('\n', out);
674 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 default:
676 fprintf(out, " unknown prop %d!\n", prop->type);
677 break;
678 }
679 }
Sam Ravnborg03d29122007-07-21 00:00:36 +0200680 if (menu->help) {
681 int len = strlen(menu->help);
682 while (menu->help[--len] == '\n')
683 menu->help[len] = 0;
684 fprintf(out, " help\n%s\n", menu->help);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686}
687
688void zconfdump(FILE *out)
689{
690 struct property *prop;
691 struct symbol *sym;
692 struct menu *menu;
693
694 menu = rootmenu.list;
695 while (menu) {
696 if ((sym = menu->sym))
697 print_symbol(out, menu);
698 else if ((prop = menu->prompt)) {
699 switch (prop->type) {
700 case P_COMMENT:
701 fputs("\ncomment ", out);
702 print_quoted_string(out, prop->text);
703 fputs("\n", out);
704 break;
705 case P_MENU:
706 fputs("\nmenu ", out);
707 print_quoted_string(out, prop->text);
708 fputs("\n", out);
709 break;
710 default:
711 ;
712 }
713 if (!expr_is_yes(prop->visible.expr)) {
714 fputs(" depends ", out);
715 expr_fprint(prop->visible.expr, out);
716 fputc('\n', out);
717 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
719
720 if (menu->list)
721 menu = menu->list;
722 else if (menu->next)
723 menu = menu->next;
724 else while ((menu = menu->parent)) {
725 if (menu->prompt && menu->prompt->type == P_MENU)
726 fputs("\nendmenu\n", out);
727 if (menu->next) {
728 menu = menu->next;
729 break;
730 }
731 }
732 }
733}
734
Arnaud Lacombe378dbb22011-05-23 02:08:52 -0400735#include "zconf.lex.c"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736#include "util.c"
737#include "confdata.c"
738#include "expr.c"
739#include "symbol.c"
740#include "menu.c"