3 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4 * Released under the terms of the GNU GPL v2.0.
14 #define LKC_DIRECT_LINK
17 #include "zconf.hash.c"
19 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
22 #define DEBUG_PARSE 0x0002
26 extern int zconflex(void);
27 static void zconfprint(const char *err, ...);
28 static void zconf_error(const char *err, ...);
29 static void zconferror(const char *err);
30 static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken);
32 struct symbol *symbol_hash[257];
34 static struct menu *current_menu, *current_entry;
38 #define YYERROR_VERBOSE
47 struct symbol *symbol;
58 %token <id>T_ENDCHOICE
61 %token <id>T_MENUCONFIG
63 %token <string> T_HELPTEXT
75 %token <string> T_WORD
76 %token <string> T_WORD_QUOTE
84 %left T_EQUAL T_UNEQUAL
92 %type <id> option_name
93 %type <menu> if_entry menu_entry choice_entry
96 fprintf(stderr, "%s:%d: missing end statement for this entry\n",
97 $$->file->name, $$->lineno);
98 if (current_menu == $$)
100 } if_entry menu_entry choice_entry
107 | stmt_list common_stmt
108 | stmt_list choice_stmt
109 | stmt_list menu_stmt
110 | stmt_list T_MAINMENU prompt nl
111 | stmt_list end { zconf_error("unexpected end statement"); }
112 | stmt_list T_WORD error T_EOL { zconf_error("unknown statement \"%s\"", $2); }
113 | stmt_list option_name error T_EOL
115 zconf_error("unexpected option \"%s\"", kconf_id_strings + $2->name);
117 | stmt_list error T_EOL { zconf_error("invalid statement"); }
121 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT
134 T_WORD error T_EOL { zconf_error("unknown option \"%s\"", $1); }
135 | error T_EOL { zconf_error("invalid option"); }
139 /* config/menuconfig entry */
141 config_entry_start: T_CONFIG T_WORD T_EOL
143 struct symbol *sym = sym_lookup($2, 0);
144 sym->flags |= SYMBOL_OPTIONAL;
146 printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2);
149 config_stmt: config_entry_start config_option_list
152 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
155 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
157 struct symbol *sym = sym_lookup($2, 0);
158 sym->flags |= SYMBOL_OPTIONAL;
160 printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2);
163 menuconfig_stmt: menuconfig_entry_start config_option_list
165 if (current_entry->prompt)
166 current_entry->prompt->type = P_MENU;
168 zconfprint("warning: menuconfig statement without prompt");
170 printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno());
175 | config_option_list config_option
176 | config_option_list depends
177 | config_option_list help
178 | config_option_list option_error
179 | config_option_list T_EOL
182 config_option: T_TYPE prompt_stmt_opt T_EOL
184 menu_set_type($1->stype);
185 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
186 zconf_curname(), zconf_lineno(),
190 config_option: T_PROMPT prompt if_expr T_EOL
192 menu_add_prompt(P_PROMPT, $2, $3);
193 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
196 config_option: T_DEFAULT expr if_expr T_EOL
198 menu_add_expr(P_DEFAULT, $2, $3);
199 if ($1->stype != S_UNKNOWN)
200 menu_set_type($1->stype);
201 printd(DEBUG_PARSE, "%s:%d:default(%u)\n",
202 zconf_curname(), zconf_lineno(),
206 config_option: T_SELECT T_WORD if_expr T_EOL
208 menu_add_symbol(P_SELECT, sym_lookup($2, 0), $3);
209 printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno());
212 config_option: T_RANGE symbol symbol if_expr T_EOL
214 menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
215 printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno());
220 choice: T_CHOICE T_EOL
222 struct symbol *sym = sym_lookup(NULL, 0);
223 sym->flags |= SYMBOL_CHOICE;
225 menu_add_expr(P_CHOICE, NULL, NULL);
226 printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno());
229 choice_entry: choice choice_option_list
231 $$ = menu_add_menu();
236 if (zconf_endtoken($1, T_CHOICE, T_ENDCHOICE)) {
238 printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno());
242 choice_stmt: choice_entry choice_block choice_end
247 | choice_option_list choice_option
248 | choice_option_list depends
249 | choice_option_list help
250 | choice_option_list T_EOL
251 | choice_option_list option_error
254 choice_option: T_PROMPT prompt if_expr T_EOL
256 menu_add_prompt(P_PROMPT, $2, $3);
257 printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno());
260 choice_option: T_TYPE prompt_stmt_opt T_EOL
262 if ($1->stype == S_BOOLEAN || $1->stype == S_TRISTATE) {
263 menu_set_type($1->stype);
264 printd(DEBUG_PARSE, "%s:%d:type(%u)\n",
265 zconf_curname(), zconf_lineno(),
271 choice_option: T_OPTIONAL T_EOL
273 current_entry->sym->flags |= SYMBOL_OPTIONAL;
274 printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno());
277 choice_option: T_DEFAULT T_WORD if_expr T_EOL
279 if ($1->stype == S_UNKNOWN) {
280 menu_add_symbol(P_DEFAULT, sym_lookup($2, 0), $3);
281 printd(DEBUG_PARSE, "%s:%d:default\n",
282 zconf_curname(), zconf_lineno());
289 | choice_block common_stmt
294 if_entry: T_IF expr nl
296 printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno());
297 menu_add_entry(NULL);
299 $$ = menu_add_menu();
304 if (zconf_endtoken($1, T_IF, T_ENDIF)) {
306 printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno());
310 if_stmt: if_entry if_block if_end
315 | if_block common_stmt
317 | if_block choice_stmt
322 menu: T_MENU prompt T_EOL
324 menu_add_entry(NULL);
325 menu_add_prompt(P_MENU, $2, NULL);
326 printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
329 menu_entry: menu depends_list
331 $$ = menu_add_menu();
336 if (zconf_endtoken($1, T_MENU, T_ENDMENU)) {
338 printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno());
342 menu_stmt: menu_entry menu_block menu_end
347 | menu_block common_stmt
348 | menu_block menu_stmt
349 | menu_block choice_stmt
352 source_stmt: T_SOURCE prompt T_EOL
354 printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2);
360 comment: T_COMMENT prompt T_EOL
362 menu_add_entry(NULL);
363 menu_add_prompt(P_COMMENT, $2, NULL);
364 printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno());
367 comment_stmt: comment depends_list
374 help_start: T_HELP T_EOL
376 printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno());
380 help: help_start T_HELPTEXT
382 current_entry->sym->help = $2;
389 | depends_list depends
391 | depends_list option_error
394 depends: T_DEPENDS T_ON expr T_EOL
397 printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
399 | T_DEPENDS expr T_EOL
402 printd(DEBUG_PARSE, "%s:%d:depends\n", zconf_curname(), zconf_lineno());
404 | T_REQUIRES expr T_EOL
407 printd(DEBUG_PARSE, "%s:%d:requires\n", zconf_curname(), zconf_lineno());
410 /* prompt statement */
416 menu_add_prompt(P_PROMPT, $1, $2);
423 end: T_ENDMENU T_EOL { $$ = $1; }
424 | T_ENDCHOICE T_EOL { $$ = $1; }
425 | T_ENDIF T_EOL { $$ = $1; }
433 if_expr: /* empty */ { $$ = NULL; }
434 | T_IF expr { $$ = $2; }
437 expr: symbol { $$ = expr_alloc_symbol($1); }
438 | symbol T_EQUAL symbol { $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
439 | symbol T_UNEQUAL symbol { $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
440 | T_OPEN_PAREN expr T_CLOSE_PAREN { $$ = $2; }
441 | T_NOT expr { $$ = expr_alloc_one(E_NOT, $2); }
442 | expr T_OR expr { $$ = expr_alloc_two(E_OR, $1, $3); }
443 | expr T_AND expr { $$ = expr_alloc_two(E_AND, $1, $3); }
446 symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); }
447 | T_WORD_QUOTE { $$ = sym_lookup($1, 1); free($1); }
452 void conf_parse(const char *name)
457 zconf_initscan(name);
461 modules_sym = sym_lookup("MODULES", 0);
462 rootmenu.prompt = menu_add_prompt(P_MENU, "Palacios VMM Configuration", NULL);
465 if (getenv("ZCONF_DEBUG"))
471 menu_finalize(&rootmenu);
472 for_all_symbols(i, sym) {
476 sym_change_count = 1;
479 const char *zconf_tokenname(int token)
482 case T_MENU: return "menu";
483 case T_ENDMENU: return "endmenu";
484 case T_CHOICE: return "choice";
485 case T_ENDCHOICE: return "endchoice";
486 case T_IF: return "if";
487 case T_ENDIF: return "endif";
488 case T_DEPENDS: return "depends";
493 static bool zconf_endtoken(struct kconf_id *id, int starttoken, int endtoken)
495 if (id->token != endtoken) {
496 zconf_error("unexpected '%s' within %s block",
497 kconf_id_strings + id->name, zconf_tokenname(starttoken));
501 if (current_menu->file != current_file) {
502 zconf_error("'%s' in different file than '%s'",
503 kconf_id_strings + id->name, zconf_tokenname(starttoken));
504 fprintf(stderr, "%s:%d: location of the '%s'\n",
505 current_menu->file->name, current_menu->lineno,
506 zconf_tokenname(starttoken));
513 static void zconfprint(const char *err, ...)
517 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
519 vfprintf(stderr, err, ap);
521 fprintf(stderr, "\n");
524 static void zconf_error(const char *err, ...)
529 fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno());
531 vfprintf(stderr, err, ap);
533 fprintf(stderr, "\n");
536 static void zconferror(const char *err)
539 fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err);
543 void print_quoted_string(FILE *out, const char *str)
549 while ((p = strchr(str, '"'))) {
552 fprintf(out, "%.*s", len, str);
560 void print_symbol(FILE *out, struct menu *menu)
562 struct symbol *sym = menu->sym;
563 struct property *prop;
565 if (sym_is_choice(sym))
566 fprintf(out, "choice\n");
568 fprintf(out, "config %s\n", sym->name);
571 fputs(" boolean\n", out);
574 fputs(" tristate\n", out);
577 fputs(" string\n", out);
580 fputs(" integer\n", out);
583 fputs(" hex\n", out);
586 fputs(" ???\n", out);
589 for (prop = sym->prop; prop; prop = prop->next) {
590 if (prop->menu != menu)
592 switch (prop->type) {
594 fputs(" prompt ", out);
595 print_quoted_string(out, prop->text);
596 if (!expr_is_yes(prop->visible.expr)) {
598 expr_fprint(prop->visible.expr, out);
603 fputs( " default ", out);
604 expr_fprint(prop->expr, out);
605 if (!expr_is_yes(prop->visible.expr)) {
607 expr_fprint(prop->visible.expr, out);
612 fputs(" #choice value\n", out);
615 fprintf(out, " unknown prop %d!\n", prop->type);
620 int len = strlen(sym->help);
621 while (sym->help[--len] == '\n')
623 fprintf(out, " help\n%s\n", sym->help);
628 void zconfdump(FILE *out)
630 struct property *prop;
634 menu = rootmenu.list;
636 if ((sym = menu->sym))
637 print_symbol(out, menu);
638 else if ((prop = menu->prompt)) {
639 switch (prop->type) {
641 fputs("\ncomment ", out);
642 print_quoted_string(out, prop->text);
646 fputs("\nmenu ", out);
647 print_quoted_string(out, prop->text);
653 if (!expr_is_yes(prop->visible.expr)) {
654 fputs(" depends ", out);
655 expr_fprint(prop->visible.expr, out);
665 else while ((menu = menu->parent)) {
666 if (menu->prompt && menu->prompt->type == P_MENU)
667 fputs("\nendmenu\n", out);
676 #include "lex.zconf.c"
678 #include "confdata.c"