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
69 %token
<string> T_WORD
70 %token
<string> T_WORD_QUOTE
78 %left T_EQUAL T_UNEQUAL
86 %type
<id
> option_name
87 %type
<menu
> if_entry menu_entry choice_entry
88 %type
<string> symbol_option_arg word_opt
91 fprintf
(stderr
, "%s:%d: missing end statement for this entry\n",
92 $$
->file
->name
, $$
->lineno
);
93 if
(current_menu
== $$
)
95 } if_entry menu_entry choice_entry
98 /* Include zconf.hash.c here so it can see the token constants. */
99 #include "zconf.hash.c"
103 input: nl start | start
;
105 start: mainmenu_stmt stmt_list | stmt_list
;
109 | stmt_list common_stmt
110 | stmt_list choice_stmt
111 | stmt_list menu_stmt
112 | 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
116 zconf_error
("unexpected option \"%s\"", kconf_id_strings
+ $2->name
);
118 | stmt_list
error T_EOL
{ zconf_error
("invalid statement"); }
122 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
135 T_WORD
error T_EOL
{ zconf_error
("unknown option \"%s\"", $1); }
136 |
error T_EOL
{ zconf_error
("invalid option"); }
140 /* config/menuconfig entry */
142 config_entry_start: T_CONFIG T_WORD T_EOL
144 struct symbol
*sym
= sym_lookup
($2, 0);
145 sym
->flags |
= SYMBOL_OPTIONAL
;
147 printd
(DEBUG_PARSE
, "%s:%d:config %s\n", zconf_curname
(), zconf_lineno
(), $2);
150 config_stmt: config_entry_start config_option_list
153 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
156 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
158 struct symbol
*sym
= sym_lookup
($2, 0);
159 sym
->flags |
= SYMBOL_OPTIONAL
;
161 printd
(DEBUG_PARSE
, "%s:%d:menuconfig %s\n", zconf_curname
(), zconf_lineno
(), $2);
164 menuconfig_stmt: menuconfig_entry_start config_option_list
166 if
(current_entry
->prompt
)
167 current_entry
->prompt
->type
= P_MENU
;
169 zconfprint
("warning: menuconfig statement without prompt");
171 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
176 | config_option_list config_option
177 | config_option_list symbol_option
178 | config_option_list depends
179 | config_option_list help
180 | config_option_list option_error
181 | config_option_list T_EOL
184 config_option: T_TYPE prompt_stmt_opt T_EOL
186 menu_set_type
($1->stype
);
187 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
188 zconf_curname
(), zconf_lineno
(),
192 config_option: T_PROMPT prompt if_expr T_EOL
194 menu_add_prompt
(P_PROMPT
, $2, $3);
195 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
198 config_option: T_DEFAULT expr if_expr T_EOL
200 menu_add_expr
(P_DEFAULT
, $2, $3);
201 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
(),
208 config_option: T_SELECT T_WORD if_expr T_EOL
210 menu_add_symbol
(P_SELECT
, sym_lookup
($2, 0), $3);
211 printd
(DEBUG_PARSE
, "%s:%d:select\n", zconf_curname
(), zconf_lineno
());
214 config_option: T_RANGE symbol symbol if_expr T_EOL
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
());
220 symbol_option: T_OPTION symbol_option_list T_EOL
225 | symbol_option_list T_WORD symbol_option_arg
227 const struct kconf_id
*id
= kconf_id_lookup
($2, strlen
($2));
228 if
(id
&& id
->flags
& TF_OPTION
)
229 menu_add_option
(id
->token
, $3);
231 zconfprint
("warning: ignoring unknown option %s", $2);
236 /* empty */ { $$
= NULL
; }
237 | T_EQUAL prompt
{ $$
= $2; }
242 choice: T_CHOICE word_opt T_EOL
244 struct symbol
*sym
= sym_lookup
($2, SYMBOL_CHOICE
);
245 sym
->flags |
= SYMBOL_AUTO
;
247 menu_add_expr
(P_CHOICE
, NULL
, NULL
);
248 printd
(DEBUG_PARSE
, "%s:%d:choice\n", zconf_curname
(), zconf_lineno
());
251 choice_entry: choice choice_option_list
253 $$
= menu_add_menu
();
258 if
(zconf_endtoken
($1, T_CHOICE
, T_ENDCHOICE
)) {
260 printd
(DEBUG_PARSE
, "%s:%d:endchoice\n", zconf_curname
(), zconf_lineno
());
264 choice_stmt: choice_entry choice_block choice_end
269 | choice_option_list choice_option
270 | choice_option_list depends
271 | choice_option_list help
272 | choice_option_list T_EOL
273 | choice_option_list option_error
276 choice_option: T_PROMPT prompt if_expr T_EOL
278 menu_add_prompt
(P_PROMPT
, $2, $3);
279 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
282 choice_option: T_TYPE prompt_stmt_opt T_EOL
284 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
(),
293 choice_option: T_OPTIONAL T_EOL
295 current_entry
->sym
->flags |
= SYMBOL_OPTIONAL
;
296 printd
(DEBUG_PARSE
, "%s:%d:optional\n", zconf_curname
(), zconf_lineno
());
299 choice_option: T_DEFAULT T_WORD if_expr T_EOL
301 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
());
311 | choice_block common_stmt
316 if_entry: T_IF expr nl
318 printd
(DEBUG_PARSE
, "%s:%d:if\n", zconf_curname
(), zconf_lineno
());
319 menu_add_entry
(NULL
);
321 $$
= menu_add_menu
();
326 if
(zconf_endtoken
($1, T_IF
, T_ENDIF
)) {
328 printd
(DEBUG_PARSE
, "%s:%d:endif\n", zconf_curname
(), zconf_lineno
());
332 if_stmt: if_entry if_block if_end
337 | if_block common_stmt
339 | if_block choice_stmt
344 mainmenu_stmt: T_MAINMENU prompt nl
346 menu_add_prompt
(P_MENU
, $2, NULL
);
351 menu: T_MENU prompt T_EOL
353 menu_add_entry
(NULL
);
354 menu_add_prompt
(P_MENU
, $2, NULL
);
355 printd
(DEBUG_PARSE
, "%s:%d:menu\n", zconf_curname
(), zconf_lineno
());
358 menu_entry: menu visibility_list depends_list
360 $$
= menu_add_menu
();
365 if
(zconf_endtoken
($1, T_MENU
, T_ENDMENU
)) {
367 printd
(DEBUG_PARSE
, "%s:%d:endmenu\n", zconf_curname
(), zconf_lineno
());
371 menu_stmt: menu_entry menu_block menu_end
376 | menu_block common_stmt
377 | menu_block menu_stmt
378 | menu_block choice_stmt
381 source_stmt: T_SOURCE prompt T_EOL
383 printd
(DEBUG_PARSE
, "%s:%d:source %s\n", zconf_curname
(), zconf_lineno
(), $2);
389 comment: T_COMMENT prompt T_EOL
391 menu_add_entry
(NULL
);
392 menu_add_prompt
(P_COMMENT
, $2, NULL
);
393 printd
(DEBUG_PARSE
, "%s:%d:comment\n", zconf_curname
(), zconf_lineno
());
396 comment_stmt: comment depends_list
403 help_start: T_HELP T_EOL
405 printd
(DEBUG_PARSE
, "%s:%d:help\n", zconf_curname
(), zconf_lineno
());
409 help: help_start T_HELPTEXT
411 current_entry
->help
= $2;
418 | depends_list depends
420 | depends_list option_error
423 depends: T_DEPENDS T_ON expr T_EOL
426 printd
(DEBUG_PARSE
, "%s:%d:depends on\n", zconf_curname
(), zconf_lineno
());
429 /* visibility option */
433 | visibility_list visible
434 | visibility_list T_EOL
437 visible: T_VISIBLE if_expr
439 menu_add_visibility
($2);
442 /* prompt statement */
448 menu_add_prompt
(P_PROMPT
, $1, $2);
455 end: T_ENDMENU T_EOL
{ $$
= $1; }
456 | T_ENDCHOICE T_EOL
{ $$
= $1; }
457 | T_ENDIF T_EOL
{ $$
= $1; }
465 if_expr: /* empty */ { $$
= NULL
; }
466 | T_IF expr
{ $$
= $2; }
469 expr: 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); }
478 symbol: T_WORD
{ $$
= sym_lookup
($1, 0); free
($1); }
479 | T_WORD_QUOTE
{ $$
= sym_lookup
($1, SYMBOL_CONST
); free
($1); }
482 word_opt: /* empty */ { $$
= NULL
; }
487 void conf_parse
(const char *name
)
492 zconf_initscan
(name
);
496 modules_sym
= sym_lookup
(NULL
, 0);
497 modules_sym
->type
= S_BOOLEAN
;
498 modules_sym
->flags |
= SYMBOL_AUTO
;
499 rootmenu.prompt
= menu_add_prompt
(P_MENU
, "Linux Kernel Configuration", NULL
);
501 if
(getenv
("ZCONF_DEBUG"))
506 if
(!modules_sym
->prop
) {
507 struct property
*prop
;
509 prop
= prop_alloc
(P_DEFAULT
, modules_sym
);
510 prop
->expr
= expr_alloc_symbol
(sym_lookup
("MODULES", 0));
513 rootmenu.prompt
->text
= _
(rootmenu.prompt
->text
);
514 rootmenu.prompt
->text
= sym_expand_string_value
(rootmenu.prompt
->text
);
516 menu_finalize
(&rootmenu
);
517 for_all_symbols
(i
, sym
) {
518 if
(sym_check_deps
(sym
))
523 sym_set_change_count
(1);
526 static const char *zconf_tokenname
(int 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";
535 case T_DEPENDS
: return
"depends";
536 case T_VISIBLE
: return
"visible";
541 static bool zconf_endtoken
(const struct kconf_id
*id
, int starttoken
, int endtoken
)
543 if
(id
->token
!= endtoken
) {
544 zconf_error
("unexpected '%s' within %s block",
545 kconf_id_strings
+ id
->name
, zconf_tokenname
(starttoken
));
549 if
(current_menu
->file
!= current_file
) {
550 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
));
561 static void zconfprint
(const char *err
, ...
)
565 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
567 vfprintf
(stderr
, err
, ap
);
569 fprintf
(stderr
, "\n");
572 static void zconf_error
(const char *err
, ...
)
577 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
579 vfprintf
(stderr
, err
, ap
);
581 fprintf
(stderr
, "\n");
584 static void zconferror
(const char *err
)
586 fprintf
(stderr
, "%s:%d: %s\n", zconf_curname
(), zconf_lineno
() + 1, err
);
589 static void print_quoted_string
(FILE *out
, const char *str
)
595 while
((p
= strchr
(str
, '"'))) {
598 fprintf
(out
, "%.*s", len
, str
);
606 static void print_symbol
(FILE *out
, struct menu
*menu
)
608 struct symbol
*sym
= menu
->sym
;
609 struct property
*prop
;
611 if
(sym_is_choice
(sym
))
612 fprintf
(out
, "\nchoice\n");
614 fprintf
(out
, "\nconfig %s\n", sym
->name
);
617 fputs
(" boolean\n", out
);
620 fputs
(" tristate\n", out
);
623 fputs
(" string\n", out
);
626 fputs
(" integer\n", out
);
629 fputs
(" hex\n", out
);
632 fputs
(" ???\n", out
);
635 for
(prop
= sym
->prop
; prop
; prop
= prop
->next
) {
636 if
(prop
->menu
!= menu
)
638 switch
(prop
->type
) {
640 fputs
(" prompt ", out
);
641 print_quoted_string
(out
, prop
->text
);
642 if
(!expr_is_yes
(prop
->visible.expr
)) {
644 expr_fprint
(prop
->visible.expr
, out
);
649 fputs
( " default ", out
);
650 expr_fprint
(prop
->expr
, out
);
651 if
(!expr_is_yes
(prop
->visible.expr
)) {
653 expr_fprint
(prop
->visible.expr
, out
);
658 fputs
(" #choice value\n", out
);
661 fputs
( " select ", out
);
662 expr_fprint
(prop
->expr
, out
);
666 fputs
( " range ", out
);
667 expr_fprint
(prop
->expr
, out
);
671 fputs
( " menu ", out
);
672 print_quoted_string
(out
, prop
->text
);
676 fprintf
(out
, " unknown prop %d!\n", prop
->type
);
681 int len
= strlen
(menu
->help
);
682 while
(menu
->help
[--len
] == '\n')
684 fprintf
(out
, " help\n%s\n", menu
->help
);
688 void zconfdump
(FILE *out
)
690 struct property
*prop
;
694 menu
= rootmenu.list
;
696 if
((sym
= menu
->sym
))
697 print_symbol
(out
, menu
);
698 else if
((prop
= menu
->prompt
)) {
699 switch
(prop
->type
) {
701 fputs
("\ncomment ", out
);
702 print_quoted_string
(out
, prop
->text
);
706 fputs
("\nmenu ", out
);
707 print_quoted_string
(out
, prop
->text
);
713 if
(!expr_is_yes
(prop
->visible.expr
)) {
714 fputs
(" depends ", out
);
715 expr_fprint
(prop
->visible.expr
, out
);
724 else while
((menu
= menu
->parent
)) {
725 if
(menu
->prompt
&& menu
->prompt
->type
== P_MENU
)
726 fputs
("\nendmenu\n", out
);
735 #include "zconf.lex.c"
737 #include "confdata.c"