3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
16 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
19 #define DEBUG_PARSE 0x0002
23 extern int zconflex(void);
24 static void zconfprint(const char *err, ...);
25 static void zconf_error(const char *err, ...);
26 static void zconferror(const char *err);
27 static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken);
29 struct symbol *symbol_hash[SYMBOL_HASHSIZE];
31 static struct menu *current_menu, *current_entry;
40 struct symbol *symbol;
43 const struct kconf_id *id;
51 %token <id>T_ENDCHOICE
54 %token <id>T_MENUCONFIG
56 %token <string> T_HELPTEXT
70 %token <string> T_WORD
71 %token <string> T_WORD_QUOTE
79 %left T_EQUAL T_UNEQUAL
87 %type <id> option_name
88 %type <menu> if_entry menu_entry choice_entry
89 %type <string> symbol_option_arg word_opt
92 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
93 $$->file->name, $$->lineno);
94 if (current_menu == $$)
96 } if_entry menu_entry choice_entry
99 /* Include zconf.hash.c here so it can see the token constants. */
100 #include "zconf.hash.c"
104 input: nl start | start;
106 start: mainmenu_stmt stmt_list | stmt_list;
110 | stmt_list common_stmt
111 | stmt_list choice_stmt
112 | stmt_list menu_stmt
113 | stmt_list end { zconf_error("unexpected end statement"); }
114 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
115 | stmt_list option_name error T_EOL
117 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
119 | stmt_list error T_EOL { zconf_error("invalid statement"); }
123 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE | T_RESET
136 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
137 | error T_EOL { zconf_error("invalid option"); }
141 /* config/menuconfig entry */
143 config_entry_start: T_CONFIG T_WORD T_EOL
145 struct symbol *sym = sym_lookup($2, 0);
146 sym->flags |= SYMBOL_OPTIONAL;
148 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
151 config_stmt: config_entry_start config_option_list
154 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
157 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
159 struct symbol *sym = sym_lookup($2, 0);
160 sym->flags |= SYMBOL_OPTIONAL;
162 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
165 menuconfig_stmt: menuconfig_entry_start config_option_list
167 if (current_entry->prompt)
168 current_entry->prompt->type = P_MENU;
170 zconfprint("warning: menuconfig statement without prompt");
172 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
177 | config_option_list config_option
178 | config_option_list symbol_option
179 | config_option_list depends
180 | config_option_list help
181 | config_option_list option_error
182 | config_option_list T_EOL
185 config_option: T_TYPE prompt_stmt_opt T_EOL
187 menu_set_type($1->stype);
188 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
189 zconf_curname(), zconf_lineno(),
193 config_option: T_PROMPT prompt if_expr T_EOL
195 menu_add_prompt(P_PROMPT, $2, $3);
196 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
199 config_option: T_DEFAULT expr if_expr T_EOL
201 menu_add_expr(P_DEFAULT, $2, $3);
202 if ($1->stype != S_UNKNOWN)
203 menu_set_type($1->stype);
204 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
205 zconf_curname(), zconf_lineno(),
209 config_option: T_SELECT T_WORD if_expr T_EOL
211 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
212 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
215 config_option: T_RANGE symbol symbol if_expr T_EOL
217 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
218 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
221 symbol_option: T_OPTION symbol_option_list T_EOL
226 | symbol_option_list T_WORD symbol_option_arg
228 const struct kconf_id *id = kconf_id_lookup($2, strlen($2));
229 if (id && id->flags & TF_OPTION)
230 menu_add_option(id->token, $3);
232 zconfprint("warning: ignoring unknown option %s", $2);
237 /* empty */ { $$ = NULL; }
238 | T_EQUAL prompt { $$ = $2; }
243 choice: T_CHOICE word_opt T_EOL
245 struct symbol *sym = sym_lookup($2, SYMBOL_CHOICE);
246 sym->flags |= SYMBOL_AUTO;
248 menu_add_expr(P_CHOICE, NULL, NULL);
249 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
252 choice_entry: choice choice_option_list
254 $$ = menu_add_menu();
259 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
261 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
265 choice_stmt: choice_entry choice_block choice_end
270 | choice_option_list choice_option
271 | choice_option_list depends
272 | choice_option_list help
273 | choice_option_list T_EOL
274 | choice_option_list option_error
277 choice_option: T_PROMPT prompt if_expr T_EOL
279 menu_add_prompt(P_PROMPT, $2, $3);
280 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
283 choice_option: T_TYPE prompt_stmt_opt T_EOL
285 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
286 menu_set_type($1->stype);
287 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
288 zconf_curname(), zconf_lineno(),
294 choice_option: T_OPTIONAL T_EOL
296 current_entry->sym->flags |= SYMBOL_OPTIONAL;
297 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
300 choice_option: T_RESET if_expr T_EOL
302 menu_add_prop(P_RESET, NULL, NULL, $2);
305 choice_option: T_DEFAULT T_WORD if_expr T_EOL
307 if ($1->stype == S_UNKNOWN) {
308 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
309 printd(DEBUG_PARSE, "%s:%d:default\n",
310 zconf_curname(), zconf_lineno());
317 | choice_block common_stmt
322 if_entry: T_IF expr nl
324 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
325 menu_add_entry(NULL);
327 $$ = menu_add_menu();
332 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
334 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
338 if_stmt: if_entry if_block if_end
343 | if_block common_stmt
345 | if_block choice_stmt
350 mainmenu_stmt: T_MAINMENU prompt nl
352 menu_add_prompt(P_MENU, $2, NULL);
357 menu: T_MENU prompt T_EOL
359 menu_add_entry(NULL);
360 menu_add_prompt(P_MENU, $2, NULL);
361 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
364 menu_entry: menu visibility_list depends_list
366 $$ = menu_add_menu();
371 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
373 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
377 menu_stmt: menu_entry menu_block menu_end
382 | menu_block common_stmt
383 | menu_block menu_stmt
384 | menu_block choice_stmt
387 source_stmt: T_SOURCE prompt T_EOL
389 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
395 comment: T_COMMENT prompt T_EOL
397 menu_add_entry(NULL);
398 menu_add_prompt(P_COMMENT, $2, NULL);
399 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
402 comment_stmt: comment depends_list
409 help_start: T_HELP T_EOL
411 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
415 help: help_start T_HELPTEXT
417 current_entry->help = $2;
424 | depends_list depends
426 | depends_list option_error
429 depends: T_DEPENDS T_ON expr T_EOL
432 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
433 } | T_DEPENDS expr T_EOL
436 zconfprint("warning: deprecated 'depends' syntax, use 'depends on' instead.");
439 /* visibility option */
443 | visibility_list visible
444 | visibility_list T_EOL
447 visible: T_VISIBLE if_expr
449 menu_add_visibility($2);
452 /* prompt statement */
458 menu_add_prompt(P_PROMPT, $1, $2);
465 end: T_ENDMENU T_EOL { $$ = $1; }
466 | T_ENDCHOICE T_EOL { $$ = $1; }
467 | T_ENDIF T_EOL { $$ = $1; }
475 if_expr: /* empty */ { $$ = NULL; }
476 | T_IF expr { $$ = $2; }
479 expr: symbol { $$ = expr_alloc_symbol($1); }
480 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
481 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
482 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
483 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
484 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
485 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
488 symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
489 | T_WORD_QUOTE { $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
492 word_opt: /* empty */ { $$ = NULL; }
497 void conf_parse(const char *name)
502 zconf_initscan(name);
506 rootmenu.prompt = menu_add_prompt(P_MENU, "Linux Kernel Configuration", NULL);
509 if (getenv("ZCONF_DEBUG"))
516 modules_sym = sym_find( "n" );
518 rootmenu.prompt->text = _(rootmenu.prompt->text);
519 rootmenu.prompt->text = sym_expand_string_value(rootmenu.prompt->text);
521 menu_finalize(&rootmenu);
522 for_all_symbols(i, sym) {
523 if (sym_check_deps(sym))
528 sym_set_change_count(1);
531 static const char *zconf_tokenname(int token)
534 case T_MENU: return "menu";
535 case T_ENDMENU: return "endmenu";
536 case T_CHOICE: return "choice";
537 case T_ENDCHOICE: return "endchoice";
538 case T_IF: return "if";
539 case T_ENDIF: return "endif";
540 case T_DEPENDS: return "depends";
541 case T_VISIBLE: return "visible";
546 static bool zconf_endtoken(const struct kconf_id *id, int starttoken, int endtoken)
548 if (id->token != endtoken) {
549 zconf_error("unexpected '%s' within %s block",
550 kconf_id_strings + id->name, zconf_tokenname(starttoken));
554 if (current_menu->file != current_file) {
555 zconf_error("'%s' in different file than '%s'",
556 kconf_id_strings + id->name, zconf_tokenname(starttoken));
557 fprintf(stderr, "%s:%d: location of the '%s'\n",
558 current_menu->file->name, current_menu->lineno,
559 zconf_tokenname(starttoken));
566 static void zconfprint(const char *err, ...)
570 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
572 vfprintf(stderr, err, ap);
574 fprintf(stderr, "\n");
577 static void zconf_error(const char *err, ...)
582 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
584 vfprintf(stderr, err, ap);
586 fprintf(stderr, "\n");
589 static void zconferror(const char *err)
591 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
594 static void print_quoted_string(FILE *out, const char *str)
600 while ((p = strchr(str, '"'))) {
603 fprintf(out, "%.*s", len, str);
611 static void print_symbol(FILE *out, struct menu *menu)
613 struct symbol *sym = menu->sym;
614 struct property *prop;
616 if (sym_is_choice(sym))
617 fprintf(out, "\nchoice\n");
619 fprintf(out, "\nconfig %s\n", sym->name);
622 fputs(" boolean\n", out);
625 fputs(" tristate\n", out);
628 fputs(" string\n", out);
631 fputs(" integer\n", out);
634 fputs(" hex\n", out);
637 fputs(" ???\n", out);
640 for (prop = sym->prop; prop; prop = prop->next) {
641 if (prop->menu != menu)
643 switch (prop->type) {
645 fputs(" prompt ", out);
646 print_quoted_string(out, prop->text);
647 if (!expr_is_yes(prop->visible.expr)) {
649 expr_fprint(prop->visible.expr, out);
654 fputs( " default ", out);
655 expr_fprint(prop->expr, out);
656 if (!expr_is_yes(prop->visible.expr)) {
658 expr_fprint(prop->visible.expr, out);
663 fputs(" #choice value\n", out);
666 fputs( " select ", out);
667 expr_fprint(prop->expr, out);
671 fputs( " range ", out);
672 expr_fprint(prop->expr, out);
676 fputs( " menu ", out);
677 print_quoted_string(out, prop->text);
681 fprintf(out, " unknown prop %d!\n", prop->type);
686 int len = strlen(menu->help);
687 while (menu->help[--len] == '\n')
689 fprintf(out, " help\n%s\n", menu->help);
693 void zconfdump(FILE *out)
695 struct property *prop;
699 menu = rootmenu.list;
701 if ((sym = menu->sym))
702 print_symbol(out, menu);
703 else if ((prop = menu->prompt)) {
704 switch (prop->type) {
706 fputs("\ncomment ", out);
707 print_quoted_string(out, prop->text);
711 fputs("\nmenu ", out);
712 print_quoted_string(out, prop->text);
718 if (!expr_is_yes(prop->visible.expr)) {
719 fputs(" depends ", out);
720 expr_fprint(prop->visible.expr, out);
729 else while ((menu = menu->parent)) {
730 if (menu->prompt && menu->prompt->type == P_MENU)
731 fputs("\nendmenu\n", out);
740 #include "zconf.lex.c"
742 #include "confdata.c"