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
76 %token T_GREATER_EQUAL
83 %left T_EQUAL T_UNEQUAL
84 %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
92 %type
<id
> option_name
93 %type
<menu
> if_entry menu_entry choice_entry
94 %type
<string> symbol_option_arg word_opt
97 fprintf
(stderr
, "%s:%d: missing end statement for this entry\n",
98 $$
->file
->name
, $$
->lineno
);
99 if
(current_menu
== $$
)
101 } if_entry menu_entry choice_entry
104 /* Include zconf_id.c here so it can see the token constants. */
105 #include "kconf_id.c"
109 input: nl start | start
;
111 start: mainmenu_stmt stmt_list | no_mainmenu_stmt stmt_list
;
115 mainmenu_stmt: T_MAINMENU prompt T_EOL
117 menu_add_prompt
(P_MENU
, $2, NULL
);
120 /* Default main menu, if there's no mainmenu entry */
122 no_mainmenu_stmt: /* empty */
125 * Hack: Keep the main menu title on the heap so we can safely free it
126 * later regardless of whether it comes from the 'prompt' in
127 * mainmenu_stmt or here
129 menu_add_prompt
(P_MENU
, strdup
("Linux Kernel Configuration"), NULL
);
135 | stmt_list common_stmt
136 | stmt_list choice_stmt
137 | stmt_list menu_stmt
138 | stmt_list end
{ zconf_error
("unexpected end statement"); }
139 | stmt_list T_WORD
error T_EOL
{ zconf_error
("unknown statement \"%s\"", $2); }
140 | stmt_list option_name
error T_EOL
142 zconf_error
("unexpected option \"%s\"", $2->name
);
144 | stmt_list
error T_EOL
{ zconf_error
("invalid statement"); }
148 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_IMPLY | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
161 T_WORD
error T_EOL
{ zconf_error
("unknown option \"%s\"", $1); }
162 |
error T_EOL
{ zconf_error
("invalid option"); }
166 /* config/menuconfig entry */
168 config_entry_start: T_CONFIG T_WORD T_EOL
170 struct symbol
*sym
= sym_lookup
($2, 0);
171 sym
->flags |
= SYMBOL_OPTIONAL
;
173 printd
(DEBUG_PARSE
, "%s:%d:config %s\n", zconf_curname
(), zconf_lineno
(), $2);
176 config_stmt: config_entry_start config_option_list
179 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
182 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
184 struct symbol
*sym
= sym_lookup
($2, 0);
185 sym
->flags |
= SYMBOL_OPTIONAL
;
187 printd
(DEBUG_PARSE
, "%s:%d:menuconfig %s\n", zconf_curname
(), zconf_lineno
(), $2);
190 menuconfig_stmt: menuconfig_entry_start config_option_list
192 if
(current_entry
->prompt
)
193 current_entry
->prompt
->type
= P_MENU
;
195 zconfprint
("warning: menuconfig statement without prompt");
197 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
202 | config_option_list config_option
203 | config_option_list symbol_option
204 | config_option_list depends
205 | config_option_list help
206 | config_option_list option_error
207 | config_option_list T_EOL
210 config_option: T_TYPE prompt_stmt_opt T_EOL
212 menu_set_type
($1->stype
);
213 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
214 zconf_curname
(), zconf_lineno
(),
218 config_option: T_PROMPT prompt if_expr T_EOL
220 menu_add_prompt
(P_PROMPT
, $2, $3);
221 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
224 config_option: T_DEFAULT expr if_expr T_EOL
226 menu_add_expr
(P_DEFAULT
, $2, $3);
227 if
($1->stype
!= S_UNKNOWN
)
228 menu_set_type
($1->stype
);
229 printd
(DEBUG_PARSE
, "%s:%d:default(%u)\n",
230 zconf_curname
(), zconf_lineno
(),
234 config_option: T_SELECT T_WORD if_expr T_EOL
236 menu_add_symbol
(P_SELECT
, sym_lookup
($2, 0), $3);
237 printd
(DEBUG_PARSE
, "%s:%d:select\n", zconf_curname
(), zconf_lineno
());
240 config_option: T_IMPLY T_WORD if_expr T_EOL
242 menu_add_symbol
(P_IMPLY
, sym_lookup
($2, 0), $3);
243 printd
(DEBUG_PARSE
, "%s:%d:imply\n", zconf_curname
(), zconf_lineno
());
246 config_option: T_RANGE symbol symbol if_expr T_EOL
248 menu_add_expr
(P_RANGE
, expr_alloc_comp
(E_RANGE
,$2, $3), $4);
249 printd
(DEBUG_PARSE
, "%s:%d:range\n", zconf_curname
(), zconf_lineno
());
252 symbol_option: T_OPTION symbol_option_list T_EOL
257 | symbol_option_list T_WORD symbol_option_arg
259 const struct kconf_id
*id
= kconf_id_lookup
($2, strlen
($2));
260 if
(id
&& id
->flags
& TF_OPTION
)
261 menu_add_option
(id
->token
, $3);
263 zconfprint
("warning: ignoring unknown option %s", $2);
268 /* empty */ { $$
= NULL
; }
269 | T_EQUAL prompt
{ $$
= $2; }
274 choice: T_CHOICE word_opt T_EOL
276 struct symbol
*sym
= sym_lookup
($2, SYMBOL_CHOICE
);
277 sym
->flags |
= SYMBOL_AUTO
;
279 menu_add_expr
(P_CHOICE
, NULL
, NULL
);
280 printd
(DEBUG_PARSE
, "%s:%d:choice\n", zconf_curname
(), zconf_lineno
());
283 choice_entry: choice choice_option_list
285 $$
= menu_add_menu
();
290 if
(zconf_endtoken
($1, T_CHOICE
, T_ENDCHOICE
)) {
292 printd
(DEBUG_PARSE
, "%s:%d:endchoice\n", zconf_curname
(), zconf_lineno
());
296 choice_stmt: choice_entry choice_block choice_end
301 | choice_option_list choice_option
302 | choice_option_list depends
303 | choice_option_list help
304 | choice_option_list T_EOL
305 | choice_option_list option_error
308 choice_option: T_PROMPT prompt if_expr T_EOL
310 menu_add_prompt
(P_PROMPT
, $2, $3);
311 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
314 choice_option: T_TYPE prompt_stmt_opt T_EOL
316 if
($1->stype
== S_BOOLEAN ||
$1->stype
== S_TRISTATE
) {
317 menu_set_type
($1->stype
);
318 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
319 zconf_curname
(), zconf_lineno
(),
325 choice_option: T_OPTIONAL T_EOL
327 current_entry
->sym
->flags |
= SYMBOL_OPTIONAL
;
328 printd
(DEBUG_PARSE
, "%s:%d:optional\n", zconf_curname
(), zconf_lineno
());
331 choice_option: T_DEFAULT T_WORD if_expr T_EOL
333 if
($1->stype
== S_UNKNOWN
) {
334 menu_add_symbol
(P_DEFAULT
, sym_lookup
($2, 0), $3);
335 printd
(DEBUG_PARSE
, "%s:%d:default\n",
336 zconf_curname
(), zconf_lineno
());
343 | choice_block common_stmt
348 if_entry: T_IF expr T_EOL
350 printd
(DEBUG_PARSE
, "%s:%d:if\n", zconf_curname
(), zconf_lineno
());
351 menu_add_entry
(NULL
);
353 $$
= menu_add_menu
();
358 if
(zconf_endtoken
($1, T_IF
, T_ENDIF
)) {
360 printd
(DEBUG_PARSE
, "%s:%d:endif\n", zconf_curname
(), zconf_lineno
());
364 if_stmt: if_entry if_block if_end
369 | if_block common_stmt
371 | if_block choice_stmt
376 menu: T_MENU prompt T_EOL
378 menu_add_entry
(NULL
);
379 menu_add_prompt
(P_MENU
, $2, NULL
);
380 printd
(DEBUG_PARSE
, "%s:%d:menu\n", zconf_curname
(), zconf_lineno
());
383 menu_entry: menu visibility_list depends_list
385 $$
= menu_add_menu
();
390 if
(zconf_endtoken
($1, T_MENU
, T_ENDMENU
)) {
392 printd
(DEBUG_PARSE
, "%s:%d:endmenu\n", zconf_curname
(), zconf_lineno
());
396 menu_stmt: menu_entry menu_block menu_end
401 | menu_block common_stmt
402 | menu_block menu_stmt
403 | menu_block choice_stmt
406 source_stmt: T_SOURCE prompt T_EOL
408 printd
(DEBUG_PARSE
, "%s:%d:source %s\n", zconf_curname
(), zconf_lineno
(), $2);
414 comment: T_COMMENT prompt T_EOL
416 menu_add_entry
(NULL
);
417 menu_add_prompt
(P_COMMENT
, $2, NULL
);
418 printd
(DEBUG_PARSE
, "%s:%d:comment\n", zconf_curname
(), zconf_lineno
());
421 comment_stmt: comment depends_list
428 help_start: T_HELP T_EOL
430 printd
(DEBUG_PARSE
, "%s:%d:help\n", zconf_curname
(), zconf_lineno
());
434 help: help_start T_HELPTEXT
436 current_entry
->help
= $2;
443 | depends_list depends
445 | depends_list option_error
448 depends: T_DEPENDS T_ON expr T_EOL
451 printd
(DEBUG_PARSE
, "%s:%d:depends on\n", zconf_curname
(), zconf_lineno
());
454 /* visibility option */
458 | visibility_list visible
459 | visibility_list T_EOL
462 visible: T_VISIBLE if_expr
464 menu_add_visibility
($2);
467 /* prompt statement */
473 menu_add_prompt
(P_PROMPT
, $1, $2);
480 end: T_ENDMENU T_EOL
{ $$
= $1; }
481 | T_ENDCHOICE T_EOL
{ $$
= $1; }
482 | T_ENDIF T_EOL
{ $$
= $1; }
490 if_expr: /* empty */ { $$
= NULL
; }
491 | T_IF expr
{ $$
= $2; }
494 expr: symbol
{ $$
= expr_alloc_symbol
($1); }
495 | symbol T_LESS symbol
{ $$
= expr_alloc_comp
(E_LTH
, $1, $3); }
496 | symbol T_LESS_EQUAL symbol
{ $$
= expr_alloc_comp
(E_LEQ
, $1, $3); }
497 | symbol T_GREATER symbol
{ $$
= expr_alloc_comp
(E_GTH
, $1, $3); }
498 | symbol T_GREATER_EQUAL symbol
{ $$
= expr_alloc_comp
(E_GEQ
, $1, $3); }
499 | symbol T_EQUAL symbol
{ $$
= expr_alloc_comp
(E_EQUAL
, $1, $3); }
500 | symbol T_UNEQUAL symbol
{ $$
= expr_alloc_comp
(E_UNEQUAL
, $1, $3); }
501 | T_OPEN_PAREN expr T_CLOSE_PAREN
{ $$
= $2; }
502 | T_NOT expr
{ $$
= expr_alloc_one
(E_NOT
, $2); }
503 | expr T_OR expr
{ $$
= expr_alloc_two
(E_OR
, $1, $3); }
504 | expr T_AND expr
{ $$
= expr_alloc_two
(E_AND
, $1, $3); }
507 symbol: T_WORD
{ $$
= sym_lookup
($1, 0); free
($1); }
508 | T_WORD_QUOTE
{ $$
= sym_lookup
($1, SYMBOL_CONST
); free
($1); }
511 word_opt: /* empty */ { $$
= NULL
; }
516 void conf_parse
(const char *name
)
522 zconf_initscan
(name
);
527 if
(getenv
("ZCONF_DEBUG"))
533 modules_sym
= sym_find
( "n" );
535 tmp
= rootmenu.prompt
->text
;
536 rootmenu.prompt
->text
= _
(rootmenu.prompt
->text
);
537 rootmenu.prompt
->text
= sym_expand_string_value
(rootmenu.prompt
->text
);
540 menu_finalize
(&rootmenu
);
541 for_all_symbols
(i
, sym
) {
542 if
(sym_check_deps
(sym
))
547 sym_set_change_count
(1);
550 static const char *zconf_tokenname
(int token
)
553 case T_MENU
: return
"menu";
554 case T_ENDMENU
: return
"endmenu";
555 case T_CHOICE
: return
"choice";
556 case T_ENDCHOICE
: return
"endchoice";
557 case T_IF
: return
"if";
558 case T_ENDIF
: return
"endif";
559 case T_DEPENDS
: return
"depends";
560 case T_VISIBLE
: return
"visible";
565 static bool zconf_endtoken
(const struct kconf_id
*id
, int starttoken
, int endtoken
)
567 if
(id
->token
!= endtoken
) {
568 zconf_error
("unexpected '%s' within %s block",
569 id
->name
, zconf_tokenname
(starttoken
));
573 if
(current_menu
->file
!= current_file
) {
574 zconf_error
("'%s' in different file than '%s'",
575 id
->name
, zconf_tokenname
(starttoken
));
576 fprintf
(stderr
, "%s:%d: location of the '%s'\n",
577 current_menu
->file
->name
, current_menu
->lineno
,
578 zconf_tokenname
(starttoken
));
585 static void zconfprint
(const char *err
, ...
)
589 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
591 vfprintf
(stderr
, err
, ap
);
593 fprintf
(stderr
, "\n");
596 static void zconf_error
(const char *err
, ...
)
601 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
603 vfprintf
(stderr
, err
, ap
);
605 fprintf
(stderr
, "\n");
608 static void zconferror
(const char *err
)
610 fprintf
(stderr
, "%s:%d: %s\n", zconf_curname
(), zconf_lineno
() + 1, err
);
613 static void print_quoted_string
(FILE *out
, const char *str
)
619 while
((p
= strchr
(str
, '"'))) {
622 fprintf
(out
, "%.*s", len
, str
);
630 static void print_symbol
(FILE *out
, struct menu
*menu
)
632 struct symbol
*sym
= menu
->sym
;
633 struct property
*prop
;
635 if
(sym_is_choice
(sym
))
636 fprintf
(out
, "\nchoice\n");
638 fprintf
(out
, "\nconfig %s\n", sym
->name
);
641 fputs
(" boolean\n", out
);
644 fputs
(" tristate\n", out
);
647 fputs
(" string\n", out
);
650 fputs
(" integer\n", out
);
653 fputs
(" hex\n", out
);
656 fputs
(" ???\n", out
);
659 for
(prop
= sym
->prop
; prop
; prop
= prop
->next
) {
660 if
(prop
->menu
!= menu
)
662 switch
(prop
->type
) {
664 fputs
(" prompt ", out
);
665 print_quoted_string
(out
, prop
->text
);
666 if
(!expr_is_yes
(prop
->visible.expr
)) {
668 expr_fprint
(prop
->visible.expr
, out
);
673 fputs
( " default ", out
);
674 expr_fprint
(prop
->expr
, out
);
675 if
(!expr_is_yes
(prop
->visible.expr
)) {
677 expr_fprint
(prop
->visible.expr
, out
);
682 fputs
(" #choice value\n", out
);
685 fputs
( " select ", out
);
686 expr_fprint
(prop
->expr
, out
);
690 fputs
( " imply ", out
);
691 expr_fprint
(prop
->expr
, out
);
695 fputs
( " range ", out
);
696 expr_fprint
(prop
->expr
, out
);
700 fputs
( " menu ", out
);
701 print_quoted_string
(out
, prop
->text
);
705 fprintf
(out
, " unknown prop %d!\n", prop
->type
);
710 int len
= strlen
(menu
->help
);
711 while
(menu
->help
[--len
] == '\n')
713 fprintf
(out
, " help\n%s\n", menu
->help
);
717 void zconfdump
(FILE *out
)
719 struct property
*prop
;
723 menu
= rootmenu.list
;
725 if
((sym
= menu
->sym
))
726 print_symbol
(out
, menu
);
727 else if
((prop
= menu
->prompt
)) {
728 switch
(prop
->type
) {
730 fputs
("\ncomment ", out
);
731 print_quoted_string
(out
, prop
->text
);
735 fputs
("\nmenu ", out
);
736 print_quoted_string
(out
, prop
->text
);
742 if
(!expr_is_yes
(prop
->visible.expr
)) {
743 fputs
(" depends ", out
);
744 expr_fprint
(prop
->visible.expr
, out
);
753 else while
((menu
= menu
->parent
)) {
754 if
(menu
->prompt
&& menu
->prompt
->type
== P_MENU
)
755 fputs
("\nendmenu\n", out
);
764 #include "zconf.lex.c"
766 #include "confdata.c"