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 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
20 #define DEBUG_PARSE 0x0002
24 extern
int zconflex
(void);
25 static void zconfprint
(const char *err
, ...
);
26 static void zconf_error
(const char *err
, ...
);
27 static void zconferror
(const char *err
);
28 static bool zconf_endtoken
(struct kconf_id
*id
, int starttoken
, int endtoken
);
30 struct symbol
*symbol_hash
[SYMBOL_HASHSIZE
];
32 static struct menu
*current_menu
, *current_entry
;
36 #define YYERROR_VERBOSE
45 struct symbol
*symbol
;
56 %token
<id
>T_ENDCHOICE
59 %token
<id
>T_MENUCONFIG
61 %token
<string> T_HELPTEXT
74 %token
<string> T_WORD
75 %token
<string> T_WORD_QUOTE
83 %left T_EQUAL T_UNEQUAL
91 %type
<id
> option_name
92 %type
<menu
> if_entry menu_entry choice_entry
93 %type
<string> symbol_option_arg word_opt
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
103 /* Include zconf.hash.c here so it can see the token constants. */
104 #include "zconf.hash.c"
108 input: nl start | start
;
110 start: mainmenu_stmt stmt_list | stmt_list
;
114 | stmt_list common_stmt
115 | stmt_list choice_stmt
116 | stmt_list menu_stmt
117 | stmt_list end
{ zconf_error
("unexpected end statement"); }
118 | stmt_list T_WORD
error T_EOL
{ zconf_error
("unknown statement \"%s\"", $2); }
119 | stmt_list option_name
error T_EOL
121 zconf_error
("unexpected option \"%s\"", kconf_id_strings
+ $2->name
);
123 | stmt_list
error T_EOL
{ zconf_error
("invalid statement"); }
127 T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
140 T_WORD
error T_EOL
{ zconf_error
("unknown option \"%s\"", $1); }
141 |
error T_EOL
{ zconf_error
("invalid option"); }
145 /* config/menuconfig entry */
147 config_entry_start: T_CONFIG T_WORD T_EOL
149 struct symbol
*sym
= sym_lookup
($2, 0);
150 sym
->flags |
= SYMBOL_OPTIONAL
;
152 printd
(DEBUG_PARSE
, "%s:%d:config %s\n", zconf_curname
(), zconf_lineno
(), $2);
155 config_stmt: config_entry_start config_option_list
158 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
161 menuconfig_entry_start: T_MENUCONFIG T_WORD T_EOL
163 struct symbol
*sym
= sym_lookup
($2, 0);
164 sym
->flags |
= SYMBOL_OPTIONAL
;
166 printd
(DEBUG_PARSE
, "%s:%d:menuconfig %s\n", zconf_curname
(), zconf_lineno
(), $2);
169 menuconfig_stmt: menuconfig_entry_start config_option_list
171 if
(current_entry
->prompt
)
172 current_entry
->prompt
->type
= P_MENU
;
174 zconfprint
("warning: menuconfig statement without prompt");
176 printd
(DEBUG_PARSE
, "%s:%d:endconfig\n", zconf_curname
(), zconf_lineno
());
181 | config_option_list config_option
182 | config_option_list symbol_option
183 | config_option_list depends
184 | config_option_list help
185 | config_option_list option_error
186 | config_option_list T_EOL
189 config_option: T_TYPE prompt_stmt_opt T_EOL
191 menu_set_type
($1->stype
);
192 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
193 zconf_curname
(), zconf_lineno
(),
197 config_option: T_PROMPT prompt if_expr T_EOL
199 menu_add_prompt
(P_PROMPT
, $2, $3);
200 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
203 config_option: T_DEFAULT expr if_expr T_EOL
205 menu_add_expr
(P_DEFAULT
, $2, $3);
206 if
($1->stype
!= S_UNKNOWN
)
207 menu_set_type
($1->stype
);
208 printd
(DEBUG_PARSE
, "%s:%d:default(%u)\n",
209 zconf_curname
(), zconf_lineno
(),
213 config_option: T_SELECT T_WORD if_expr T_EOL
215 menu_add_symbol
(P_SELECT
, sym_lookup
($2, 0), $3);
216 printd
(DEBUG_PARSE
, "%s:%d:select\n", zconf_curname
(), zconf_lineno
());
219 config_option: T_RANGE symbol symbol if_expr T_EOL
221 menu_add_expr
(P_RANGE
, expr_alloc_comp
(E_RANGE
,$2, $3), $4);
222 printd
(DEBUG_PARSE
, "%s:%d:range\n", zconf_curname
(), zconf_lineno
());
225 symbol_option: T_OPTION symbol_option_list T_EOL
230 | symbol_option_list T_WORD symbol_option_arg
232 struct kconf_id
*id
= kconf_id_lookup
($2, strlen
($2));
233 if
(id
&& id
->flags
& TF_OPTION
)
234 menu_add_option
(id
->token
, $3);
236 zconfprint
("warning: ignoring unknown option %s", $2);
241 /* empty */ { $$
= NULL
; }
242 | T_EQUAL prompt
{ $$
= $2; }
247 choice: T_CHOICE word_opt T_EOL
249 struct symbol
*sym
= sym_lookup
($2, SYMBOL_CHOICE
);
250 sym
->flags |
= SYMBOL_AUTO
;
252 menu_add_expr
(P_CHOICE
, NULL
, NULL
);
253 printd
(DEBUG_PARSE
, "%s:%d:choice\n", zconf_curname
(), zconf_lineno
());
256 choice_entry: choice choice_option_list
258 $$
= menu_add_menu
();
263 if
(zconf_endtoken
($1, T_CHOICE
, T_ENDCHOICE
)) {
265 printd
(DEBUG_PARSE
, "%s:%d:endchoice\n", zconf_curname
(), zconf_lineno
());
269 choice_stmt: choice_entry choice_block choice_end
274 | choice_option_list choice_option
275 | choice_option_list depends
276 | choice_option_list help
277 | choice_option_list T_EOL
278 | choice_option_list option_error
281 choice_option: T_PROMPT prompt if_expr T_EOL
283 menu_add_prompt
(P_PROMPT
, $2, $3);
284 printd
(DEBUG_PARSE
, "%s:%d:prompt\n", zconf_curname
(), zconf_lineno
());
287 choice_option: T_TYPE prompt_stmt_opt T_EOL
289 if
($1->stype
== S_BOOLEAN ||
$1->stype
== S_TRISTATE
) {
290 menu_set_type
($1->stype
);
291 printd
(DEBUG_PARSE
, "%s:%d:type(%u)\n",
292 zconf_curname
(), zconf_lineno
(),
298 choice_option: T_OPTIONAL T_EOL
300 current_entry
->sym
->flags |
= SYMBOL_OPTIONAL
;
301 printd
(DEBUG_PARSE
, "%s:%d:optional\n", zconf_curname
(), zconf_lineno
());
304 choice_option: T_DEFAULT T_WORD if_expr T_EOL
306 if
($1->stype
== S_UNKNOWN
) {
307 menu_add_symbol
(P_DEFAULT
, sym_lookup
($2, 0), $3);
308 printd
(DEBUG_PARSE
, "%s:%d:default\n",
309 zconf_curname
(), zconf_lineno
());
316 | choice_block common_stmt
321 if_entry: T_IF expr nl
323 printd
(DEBUG_PARSE
, "%s:%d:if\n", zconf_curname
(), zconf_lineno
());
324 menu_add_entry
(NULL
);
326 $$
= menu_add_menu
();
331 if
(zconf_endtoken
($1, T_IF
, T_ENDIF
)) {
333 printd
(DEBUG_PARSE
, "%s:%d:endif\n", zconf_curname
(), zconf_lineno
());
337 if_stmt: if_entry if_block if_end
342 | if_block common_stmt
344 | if_block choice_stmt
349 mainmenu_stmt: T_MAINMENU prompt nl
351 menu_add_prompt
(P_MENU
, $2, NULL
);
356 menu: T_MENU prompt T_EOL
358 menu_add_entry
(NULL
);
359 menu_add_prompt
(P_MENU
, $2, NULL
);
360 printd
(DEBUG_PARSE
, "%s:%d:menu\n", zconf_curname
(), zconf_lineno
());
363 menu_entry: menu visibility_list depends_list
365 $$
= menu_add_menu
();
370 if
(zconf_endtoken
($1, T_MENU
, T_ENDMENU
)) {
372 printd
(DEBUG_PARSE
, "%s:%d:endmenu\n", zconf_curname
(), zconf_lineno
());
376 menu_stmt: menu_entry menu_block menu_end
381 | menu_block common_stmt
382 | menu_block menu_stmt
383 | menu_block choice_stmt
386 source_stmt: T_SOURCE prompt T_EOL
388 printd
(DEBUG_PARSE
, "%s:%d:source %s\n", zconf_curname
(), zconf_lineno
(), $2);
394 comment: T_COMMENT prompt T_EOL
396 menu_add_entry
(NULL
);
397 menu_add_prompt
(P_COMMENT
, $2, NULL
);
398 printd
(DEBUG_PARSE
, "%s:%d:comment\n", zconf_curname
(), zconf_lineno
());
401 comment_stmt: comment depends_list
408 help_start: T_HELP T_EOL
410 printd
(DEBUG_PARSE
, "%s:%d:help\n", zconf_curname
(), zconf_lineno
());
414 help: help_start T_HELPTEXT
416 current_entry
->help
= $2;
423 | depends_list depends
425 | depends_list option_error
428 depends: T_DEPENDS T_ON expr T_EOL
431 printd
(DEBUG_PARSE
, "%s:%d:depends on\n", zconf_curname
(), zconf_lineno
());
434 /* visibility option */
438 | visibility_list visible
439 | visibility_list T_EOL
442 visible: T_VISIBLE if_expr
444 menu_add_visibility
($2);
447 /* prompt statement */
453 menu_add_prompt
(P_PROMPT
, $1, $2);
460 end: T_ENDMENU T_EOL
{ $$
= $1; }
461 | T_ENDCHOICE T_EOL
{ $$
= $1; }
462 | T_ENDIF T_EOL
{ $$
= $1; }
470 if_expr: /* empty */ { $$
= NULL
; }
471 | T_IF expr
{ $$
= $2; }
474 expr: symbol
{ $$
= expr_alloc_symbol
($1); }
475 | symbol T_EQUAL symbol
{ $$
= expr_alloc_comp
(E_EQUAL
, $1, $3); }
476 | symbol T_UNEQUAL symbol
{ $$
= expr_alloc_comp
(E_UNEQUAL
, $1, $3); }
477 | T_OPEN_PAREN expr T_CLOSE_PAREN
{ $$
= $2; }
478 | T_NOT expr
{ $$
= expr_alloc_one
(E_NOT
, $2); }
479 | expr T_OR expr
{ $$
= expr_alloc_two
(E_OR
, $1, $3); }
480 | expr T_AND expr
{ $$
= expr_alloc_two
(E_AND
, $1, $3); }
483 symbol: T_WORD
{ $$
= sym_lookup
($1, 0); free
($1); }
484 | T_WORD_QUOTE
{ $$
= sym_lookup
($1, SYMBOL_CONST
); free
($1); }
487 word_opt: /* empty */ { $$
= NULL
; }
492 void conf_parse
(const char *name
)
497 zconf_initscan
(name
);
501 modules_sym
= sym_lookup
(NULL
, 0);
502 modules_sym
->type
= S_BOOLEAN
;
503 modules_sym
->flags |
= SYMBOL_AUTO
;
504 rootmenu.prompt
= menu_add_prompt
(P_MENU
, "Linux Kernel Configuration", NULL
);
507 if
(getenv
("ZCONF_DEBUG"))
513 if
(!modules_sym
->prop
) {
514 struct property
*prop
;
516 prop
= prop_alloc
(P_DEFAULT
, modules_sym
);
517 prop
->expr
= expr_alloc_symbol
(sym_lookup
("MODULES", 0));
520 rootmenu.prompt
->text
= _
(rootmenu.prompt
->text
);
521 rootmenu.prompt
->text
= sym_expand_string_value
(rootmenu.prompt
->text
);
523 menu_finalize
(&rootmenu
);
524 for_all_symbols
(i
, sym
) {
525 if
(sym_check_deps
(sym
))
530 sym_set_change_count
(1);
533 static const char *zconf_tokenname
(int token
)
536 case T_MENU
: return
"menu";
537 case T_ENDMENU
: return
"endmenu";
538 case T_CHOICE
: return
"choice";
539 case T_ENDCHOICE
: return
"endchoice";
540 case T_IF
: return
"if";
541 case T_ENDIF
: return
"endif";
542 case T_DEPENDS
: return
"depends";
543 case T_VISIBLE
: return
"visible";
548 static bool zconf_endtoken
(struct kconf_id
*id
, int starttoken
, int endtoken
)
550 if
(id
->token
!= endtoken
) {
551 zconf_error
("unexpected '%s' within %s block",
552 kconf_id_strings
+ id
->name
, zconf_tokenname
(starttoken
));
556 if
(current_menu
->file
!= current_file
) {
557 zconf_error
("'%s' in different file than '%s'",
558 kconf_id_strings
+ id
->name
, zconf_tokenname
(starttoken
));
559 fprintf
(stderr
, "%s:%d: location of the '%s'\n",
560 current_menu
->file
->name
, current_menu
->lineno
,
561 zconf_tokenname
(starttoken
));
568 static void zconfprint
(const char *err
, ...
)
572 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
574 vfprintf
(stderr
, err
, ap
);
576 fprintf
(stderr
, "\n");
579 static void zconf_error
(const char *err
, ...
)
584 fprintf
(stderr
, "%s:%d: ", zconf_curname
(), zconf_lineno
());
586 vfprintf
(stderr
, err
, ap
);
588 fprintf
(stderr
, "\n");
591 static void zconferror
(const char *err
)
594 fprintf
(stderr
, "%s:%d: %s\n", zconf_curname
(), zconf_lineno
() + 1, err
);
598 static void print_quoted_string
(FILE *out
, const char *str
)
604 while
((p
= strchr
(str
, '"'))) {
607 fprintf
(out
, "%.*s", len
, str
);
615 static void print_symbol
(FILE *out
, struct menu
*menu
)
617 struct symbol
*sym
= menu
->sym
;
618 struct property
*prop
;
620 if
(sym_is_choice
(sym
))
621 fprintf
(out
, "\nchoice\n");
623 fprintf
(out
, "\nconfig %s\n", sym
->name
);
626 fputs
(" boolean\n", out
);
629 fputs
(" tristate\n", out
);
632 fputs
(" string\n", out
);
635 fputs
(" integer\n", out
);
638 fputs
(" hex\n", out
);
641 fputs
(" ???\n", out
);
644 for
(prop
= sym
->prop
; prop
; prop
= prop
->next
) {
645 if
(prop
->menu
!= menu
)
647 switch
(prop
->type
) {
649 fputs
(" prompt ", out
);
650 print_quoted_string
(out
, prop
->text
);
651 if
(!expr_is_yes
(prop
->visible.expr
)) {
653 expr_fprint
(prop
->visible.expr
, out
);
658 fputs
( " default ", out
);
659 expr_fprint
(prop
->expr
, out
);
660 if
(!expr_is_yes
(prop
->visible.expr
)) {
662 expr_fprint
(prop
->visible.expr
, out
);
667 fputs
(" #choice value\n", out
);
670 fputs
( " select ", out
);
671 expr_fprint
(prop
->expr
, out
);
675 fputs
( " range ", out
);
676 expr_fprint
(prop
->expr
, out
);
680 fputs
( " menu ", out
);
681 print_quoted_string
(out
, prop
->text
);
685 fprintf
(out
, " unknown prop %d!\n", prop
->type
);
690 int len
= strlen
(menu
->help
);
691 while
(menu
->help
[--len
] == '\n')
693 fprintf
(out
, " help\n%s\n", menu
->help
);
697 void zconfdump
(FILE *out
)
699 struct property
*prop
;
703 menu
= rootmenu.list
;
705 if
((sym
= menu
->sym
))
706 print_symbol
(out
, menu
);
707 else if
((prop
= menu
->prompt
)) {
708 switch
(prop
->type
) {
710 fputs
("\ncomment ", out
);
711 print_quoted_string
(out
, prop
->text
);
715 fputs
("\nmenu ", out
);
716 print_quoted_string
(out
, prop
->text
);
722 if
(!expr_is_yes
(prop
->visible.expr
)) {
723 fputs
(" depends ", out
);
724 expr_fprint
(prop
->visible.expr
, out
);
733 else while
((menu
= menu
->parent
)) {
734 if
(menu
->prompt
&& menu
->prompt
->type
== P_MENU
)
735 fputs
("\nendmenu\n", out
);
744 #include "lex.zconf.c"
746 #include "confdata.c"