xref: /linux-6.15/scripts/kconfig/parser.y (revision f79dc03f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2002 Roman Zippel <[email protected]>
4  */
5 %{
6 
7 #include <ctype.h>
8 #include <stdarg.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdbool.h>
13 
14 #include "lkc.h"
15 #include "internal.h"
16 #include "preprocess.h"
17 
18 #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt)
19 
20 #define PRINTD		0x0001
21 #define DEBUG_PARSE	0x0002
22 
23 int cdebug = PRINTD;
24 
25 static void yyerror(const char *err);
26 static void zconfprint(const char *err, ...);
27 static void zconf_error(const char *err, ...);
28 static bool zconf_endtoken(const char *tokenname,
29 			   const char *expected_tokenname);
30 
31 struct menu *current_menu, *current_entry, *current_choice;
32 
33 %}
34 
35 %union
36 {
37 	char *string;
38 	struct symbol *symbol;
39 	struct expr *expr;
40 	struct menu *menu;
41 	enum symbol_type type;
42 	enum variable_flavor flavor;
43 }
44 
45 %token <string> T_HELPTEXT
46 %token <string> T_WORD
47 %token <string> T_WORD_QUOTE
48 %token T_BOOL
49 %token T_CHOICE
50 %token T_CLOSE_PAREN
51 %token T_COLON_EQUAL
52 %token T_COMMENT
53 %token T_CONFIG
54 %token T_DEFAULT
55 %token T_DEF_BOOL
56 %token T_DEF_TRISTATE
57 %token T_DEPENDS
58 %token T_ENDCHOICE
59 %token T_ENDIF
60 %token T_ENDMENU
61 %token T_HELP
62 %token T_HEX
63 %token T_IF
64 %token T_IMPLY
65 %token T_INT
66 %token T_MAINMENU
67 %token T_MENU
68 %token T_MENUCONFIG
69 %token T_MODULES
70 %token T_ON
71 %token T_OPEN_PAREN
72 %token T_PLUS_EQUAL
73 %token T_PROMPT
74 %token T_RANGE
75 %token T_SELECT
76 %token T_SOURCE
77 %token T_STRING
78 %token T_TRISTATE
79 %token T_VISIBLE
80 %token T_EOL
81 %token <string> T_ASSIGN_VAL
82 
83 %left T_OR
84 %left T_AND
85 %left T_EQUAL T_UNEQUAL
86 %left T_LESS T_LESS_EQUAL T_GREATER T_GREATER_EQUAL
87 %nonassoc T_NOT
88 
89 %type <symbol> nonconst_symbol
90 %type <symbol> symbol
91 %type <type> type default
92 %type <expr> expr
93 %type <expr> if_expr
94 %type <string> end
95 %type <menu> if_entry menu_entry choice_entry
96 %type <string> assign_val
97 %type <flavor> assign_op
98 
99 %destructor {
100 	fprintf(stderr, "%s:%d: missing end statement for this entry\n",
101 		$$->filename, $$->lineno);
102 	if (current_menu == $$)
103 		menu_end_menu();
104 } if_entry menu_entry choice_entry
105 
106 %%
107 input: mainmenu_stmt stmt_list | stmt_list;
108 
109 /* mainmenu entry */
110 
111 mainmenu_stmt: T_MAINMENU T_WORD_QUOTE T_EOL
112 {
113 	menu_add_prompt(P_MENU, $2, NULL);
114 };
115 
116 stmt_list:
117 	  /* empty */
118 	| stmt_list assignment_stmt
119 	| stmt_list choice_stmt
120 	| stmt_list comment_stmt
121 	| stmt_list config_stmt
122 	| stmt_list if_stmt
123 	| stmt_list menu_stmt
124 	| stmt_list menuconfig_stmt
125 	| stmt_list source_stmt
126 	| stmt_list T_WORD error T_EOL	{ zconf_error("unknown statement \"%s\"", $2); }
127 	| stmt_list error T_EOL		{ zconf_error("invalid statement"); }
128 ;
129 
130 stmt_list_in_choice:
131 	  /* empty */
132 	| stmt_list_in_choice comment_stmt
133 	| stmt_list_in_choice config_stmt
134 	| stmt_list_in_choice if_stmt_in_choice
135 	| stmt_list_in_choice error T_EOL	{ zconf_error("invalid statement"); }
136 ;
137 
138 /* config/menuconfig entry */
139 
140 config_entry_start: T_CONFIG nonconst_symbol T_EOL
141 {
142 	menu_add_entry($2);
143 	printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name);
144 };
145 
146 config_stmt: config_entry_start config_option_list
147 {
148 	if (current_choice) {
149 		if (!current_entry->prompt) {
150 			fprintf(stderr, "%s:%d: error: choice member must have a prompt\n",
151 				current_entry->filename, current_entry->lineno);
152 			yynerrs++;
153 		}
154 
155 		if (current_entry->sym->type != S_BOOLEAN) {
156 			fprintf(stderr, "%s:%d: error: choice member must be bool\n",
157 				current_entry->filename, current_entry->lineno);
158 			yynerrs++;
159 		}
160 
161 		list_add_tail(&current_entry->sym->choice_link,
162 			      &current_choice->choice_members);
163 	}
164 
165 	printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno);
166 };
167 
168 menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL
169 {
170 	menu_add_entry($2);
171 	printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name);
172 };
173 
174 menuconfig_stmt: menuconfig_entry_start config_option_list
175 {
176 	if (current_entry->prompt)
177 		current_entry->prompt->type = P_MENU;
178 	else
179 		zconfprint("warning: menuconfig statement without prompt");
180 	printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno);
181 };
182 
183 config_option_list:
184 	  /* empty */
185 	| config_option_list config_option
186 	| config_option_list depends
187 	| config_option_list help
188 ;
189 
190 config_option: type prompt_stmt_opt T_EOL
191 {
192 	menu_set_type($1);
193 	printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1);
194 };
195 
196 config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
197 {
198 	menu_add_prompt(P_PROMPT, $2, $3);
199 	printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno);
200 };
201 
202 config_option: default expr if_expr T_EOL
203 {
204 	menu_add_expr(P_DEFAULT, $2, $3);
205 	if ($1 != S_UNKNOWN)
206 		menu_set_type($1);
207 	printd(DEBUG_PARSE, "%s:%d:default(%u)\n", cur_filename, cur_lineno,
208 		$1);
209 };
210 
211 config_option: T_SELECT nonconst_symbol if_expr T_EOL
212 {
213 	menu_add_symbol(P_SELECT, $2, $3);
214 	printd(DEBUG_PARSE, "%s:%d:select\n", cur_filename, cur_lineno);
215 };
216 
217 config_option: T_IMPLY nonconst_symbol if_expr T_EOL
218 {
219 	menu_add_symbol(P_IMPLY, $2, $3);
220 	printd(DEBUG_PARSE, "%s:%d:imply\n", cur_filename, cur_lineno);
221 };
222 
223 config_option: T_RANGE symbol symbol if_expr T_EOL
224 {
225 	menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4);
226 	printd(DEBUG_PARSE, "%s:%d:range\n", cur_filename, cur_lineno);
227 };
228 
229 config_option: T_MODULES T_EOL
230 {
231 	if (modules_sym)
232 		zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'",
233 			    current_entry->sym->name, modules_sym->name);
234 	modules_sym = current_entry->sym;
235 };
236 
237 /* choice entry */
238 
239 choice: T_CHOICE T_EOL
240 {
241 	struct symbol *sym = sym_lookup(NULL, 0);
242 
243 	menu_add_entry(sym);
244 	menu_add_expr(P_CHOICE, NULL, NULL);
245 	menu_set_type(S_BOOLEAN);
246 	INIT_LIST_HEAD(&current_entry->choice_members);
247 
248 	printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno);
249 };
250 
251 choice_entry: choice choice_option_list
252 {
253 	if (!current_entry->prompt) {
254 		fprintf(stderr, "%s:%d: error: choice must have a prompt\n",
255 			current_entry->filename, current_entry->lineno);
256 		yynerrs++;
257 	}
258 
259 	$$ = menu_add_menu();
260 
261 	current_choice = current_entry;
262 };
263 
264 choice_end: end
265 {
266 	current_choice = NULL;
267 
268 	if (zconf_endtoken($1, "choice")) {
269 		menu_end_menu();
270 		printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno);
271 	}
272 };
273 
274 choice_stmt: choice_entry stmt_list_in_choice choice_end
275 ;
276 
277 choice_option_list:
278 	  /* empty */
279 	| choice_option_list choice_option
280 	| choice_option_list depends
281 	| choice_option_list help
282 ;
283 
284 choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
285 {
286 	menu_add_prompt(P_PROMPT, $2, $3);
287 	printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno);
288 };
289 
290 choice_option: T_BOOL T_WORD_QUOTE if_expr T_EOL
291 {
292 	menu_add_prompt(P_PROMPT, $2, $3);
293 	printd(DEBUG_PARSE, "%s:%d:bool\n", cur_filename, cur_lineno);
294 };
295 
296 choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
297 {
298 	menu_add_symbol(P_DEFAULT, $2, $3);
299 	printd(DEBUG_PARSE, "%s:%d:default\n", cur_filename, cur_lineno);
300 };
301 
302 type:
303 	  T_BOOL		{ $$ = S_BOOLEAN; }
304 	| T_TRISTATE		{ $$ = S_TRISTATE; }
305 	| T_INT			{ $$ = S_INT; }
306 	| T_HEX			{ $$ = S_HEX; }
307 	| T_STRING		{ $$ = S_STRING; }
308 
309 default:
310 	  T_DEFAULT		{ $$ = S_UNKNOWN; }
311 	| T_DEF_BOOL		{ $$ = S_BOOLEAN; }
312 	| T_DEF_TRISTATE	{ $$ = S_TRISTATE; }
313 
314 /* if entry */
315 
316 if_entry: T_IF expr T_EOL
317 {
318 	printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno);
319 	menu_add_entry(NULL);
320 	menu_add_dep($2);
321 	$$ = menu_add_menu();
322 };
323 
324 if_end: end
325 {
326 	if (zconf_endtoken($1, "if")) {
327 		menu_end_menu();
328 		printd(DEBUG_PARSE, "%s:%d:endif\n", cur_filename, cur_lineno);
329 	}
330 };
331 
332 if_stmt: if_entry stmt_list if_end
333 ;
334 
335 if_stmt_in_choice: if_entry stmt_list_in_choice if_end
336 ;
337 
338 /* menu entry */
339 
340 menu: T_MENU T_WORD_QUOTE T_EOL
341 {
342 	menu_add_entry(NULL);
343 	menu_add_prompt(P_MENU, $2, NULL);
344 	printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno);
345 };
346 
347 menu_entry: menu menu_option_list
348 {
349 	$$ = menu_add_menu();
350 };
351 
352 menu_end: end
353 {
354 	if (zconf_endtoken($1, "menu")) {
355 		menu_end_menu();
356 		printd(DEBUG_PARSE, "%s:%d:endmenu\n", cur_filename, cur_lineno);
357 	}
358 };
359 
360 menu_stmt: menu_entry stmt_list menu_end
361 ;
362 
363 menu_option_list:
364 	  /* empty */
365 	| menu_option_list visible
366 	| menu_option_list depends
367 ;
368 
369 source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
370 {
371 	printd(DEBUG_PARSE, "%s:%d:source %s\n", cur_filename, cur_lineno, $2);
372 	zconf_nextfile($2);
373 	free($2);
374 };
375 
376 /* comment entry */
377 
378 comment: T_COMMENT T_WORD_QUOTE T_EOL
379 {
380 	menu_add_entry(NULL);
381 	menu_add_prompt(P_COMMENT, $2, NULL);
382 	printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno);
383 };
384 
385 comment_stmt: comment comment_option_list
386 ;
387 
388 comment_option_list:
389 	  /* empty */
390 	| comment_option_list depends
391 ;
392 
393 /* help option */
394 
395 help_start: T_HELP T_EOL
396 {
397 	printd(DEBUG_PARSE, "%s:%d:help\n", cur_filename, cur_lineno);
398 	zconf_starthelp();
399 };
400 
401 help: help_start T_HELPTEXT
402 {
403 	if (current_entry->help) {
404 		free(current_entry->help);
405 		zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
406 			   current_entry->sym->name ?: "<choice>");
407 	}
408 
409 	/* Is the help text empty or all whitespace? */
410 	if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
411 		zconfprint("warning: '%s' defined with blank help text",
412 			   current_entry->sym->name ?: "<choice>");
413 
414 	current_entry->help = $2;
415 };
416 
417 /* depends option */
418 
419 depends: T_DEPENDS T_ON expr T_EOL
420 {
421 	menu_add_dep($3);
422 	printd(DEBUG_PARSE, "%s:%d:depends on\n", cur_filename, cur_lineno);
423 };
424 
425 /* visibility option */
426 visible: T_VISIBLE if_expr T_EOL
427 {
428 	menu_add_visibility($2);
429 };
430 
431 /* prompt statement */
432 
433 prompt_stmt_opt:
434 	  /* empty */
435 	| T_WORD_QUOTE if_expr
436 {
437 	menu_add_prompt(P_PROMPT, $1, $2);
438 };
439 
440 end:	  T_ENDMENU T_EOL	{ $$ = "menu"; }
441 	| T_ENDCHOICE T_EOL	{ $$ = "choice"; }
442 	| T_ENDIF T_EOL		{ $$ = "if"; }
443 ;
444 
445 if_expr:  /* empty */			{ $$ = NULL; }
446 	| T_IF expr			{ $$ = $2; }
447 ;
448 
449 expr:	  symbol				{ $$ = expr_alloc_symbol($1); }
450 	| symbol T_LESS symbol			{ $$ = expr_alloc_comp(E_LTH, $1, $3); }
451 	| symbol T_LESS_EQUAL symbol		{ $$ = expr_alloc_comp(E_LEQ, $1, $3); }
452 	| symbol T_GREATER symbol		{ $$ = expr_alloc_comp(E_GTH, $1, $3); }
453 	| symbol T_GREATER_EQUAL symbol		{ $$ = expr_alloc_comp(E_GEQ, $1, $3); }
454 	| symbol T_EQUAL symbol			{ $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
455 	| symbol T_UNEQUAL symbol		{ $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
456 	| T_OPEN_PAREN expr T_CLOSE_PAREN	{ $$ = $2; }
457 	| T_NOT expr				{ $$ = expr_alloc_one(E_NOT, $2); }
458 	| expr T_OR expr			{ $$ = expr_alloc_two(E_OR, $1, $3); }
459 	| expr T_AND expr			{ $$ = expr_alloc_two(E_AND, $1, $3); }
460 ;
461 
462 /* For symbol definitions, selects, etc., where quotes are not accepted */
463 nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
464 
465 symbol:	  nonconst_symbol
466 	| T_WORD_QUOTE	{ $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
467 ;
468 
469 /* assignment statement */
470 
471 assignment_stmt:  T_WORD assign_op assign_val T_EOL	{ variable_add($1, $3, $2); free($1); free($3); }
472 
473 assign_op:
474 	  T_EQUAL	{ $$ = VAR_RECURSIVE; }
475 	| T_COLON_EQUAL	{ $$ = VAR_SIMPLE; }
476 	| T_PLUS_EQUAL	{ $$ = VAR_APPEND; }
477 ;
478 
479 assign_val:
480 	/* empty */		{ $$ = xstrdup(""); };
481 	| T_ASSIGN_VAL
482 ;
483 
484 %%
485 
486 /**
487  * choice_check_sanity - check sanity of a choice member
488  *
489  * @menu: menu of the choice member
490  *
491  * Return: -1 if an error is found, 0 otherwise.
492  */
493 static int choice_check_sanity(struct menu *menu)
494 {
495 	struct property *prop;
496 	int ret = 0;
497 
498 	for (prop = menu->sym->prop; prop; prop = prop->next) {
499 		if (prop->type == P_DEFAULT) {
500 			fprintf(stderr, "%s:%d: error: %s",
501 				prop->filename, prop->lineno,
502 				"defaults for choice values not supported\n");
503 			ret = -1;
504 		}
505 
506 		if (prop->menu != menu && prop->type == P_PROMPT &&
507 		    prop->menu->parent != menu->parent) {
508 			fprintf(stderr, "%s:%d: error: %s",
509 				prop->filename, prop->lineno,
510 				"choice value has a prompt outside its choice group\n");
511 			ret = -1;
512 		}
513 	}
514 
515 	return ret;
516 }
517 
518 void conf_parse(const char *name)
519 {
520 	struct menu *menu;
521 
522 	autoconf_cmd = str_new();
523 
524 	str_printf(&autoconf_cmd, "\ndeps_config := \\\n");
525 
526 	zconf_initscan(name);
527 
528 	_menu_init();
529 
530 	if (getenv("ZCONF_DEBUG"))
531 		yydebug = 1;
532 	yyparse();
533 
534 	/*
535 	 * FIXME:
536 	 * cur_filename and cur_lineno are used even after yyparse();
537 	 * menu_finalize() calls menu_add_symbol(). This should be fixed.
538 	 */
539 	cur_filename = "<none>";
540 	cur_lineno = 0;
541 
542 	str_printf(&autoconf_cmd,
543 		   "\n"
544 		   "$(autoconfig): $(deps_config)\n"
545 		   "$(deps_config): ;\n");
546 
547 	env_write_dep(&autoconf_cmd);
548 
549 	/* Variables are expanded in the parse phase. We can free them here. */
550 	variable_all_del();
551 
552 	if (yynerrs)
553 		exit(1);
554 	if (!modules_sym)
555 		modules_sym = &symbol_no;
556 
557 	if (!menu_has_prompt(&rootmenu)) {
558 		current_entry = &rootmenu;
559 		menu_add_prompt(P_MENU, "Main menu", NULL);
560 	}
561 
562 	menu_finalize();
563 
564 	menu_for_each_entry(menu) {
565 		struct menu *child;
566 
567 		if (menu->sym && sym_check_deps(menu->sym))
568 			yynerrs++;
569 
570 		if (menu->sym && sym_is_choice(menu->sym)) {
571 			menu_for_each_sub_entry(child, menu)
572 				if (child->sym && choice_check_sanity(child))
573 					yynerrs++;
574 		}
575 	}
576 
577 	if (yynerrs)
578 		exit(1);
579 	conf_set_changed(true);
580 }
581 
582 static bool zconf_endtoken(const char *tokenname,
583 			   const char *expected_tokenname)
584 {
585 	if (strcmp(tokenname, expected_tokenname)) {
586 		zconf_error("unexpected '%s' within %s block",
587 			    tokenname, expected_tokenname);
588 		yynerrs++;
589 		return false;
590 	}
591 	if (strcmp(current_menu->filename, cur_filename)) {
592 		zconf_error("'%s' in different file than '%s'",
593 			    tokenname, expected_tokenname);
594 		fprintf(stderr, "%s:%d: location of the '%s'\n",
595 			current_menu->filename, current_menu->lineno,
596 			expected_tokenname);
597 		yynerrs++;
598 		return false;
599 	}
600 	return true;
601 }
602 
603 static void zconfprint(const char *err, ...)
604 {
605 	va_list ap;
606 
607 	fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno);
608 	va_start(ap, err);
609 	vfprintf(stderr, err, ap);
610 	va_end(ap);
611 	fprintf(stderr, "\n");
612 }
613 
614 static void zconf_error(const char *err, ...)
615 {
616 	va_list ap;
617 
618 	yynerrs++;
619 	fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno);
620 	va_start(ap, err);
621 	vfprintf(stderr, err, ap);
622 	va_end(ap);
623 	fprintf(stderr, "\n");
624 }
625 
626 static void yyerror(const char *err)
627 {
628 	fprintf(stderr, "%s:%d: %s\n", cur_filename, cur_lineno, err);
629 }
630 
631 static void print_quoted_string(FILE *out, const char *str)
632 {
633 	const char *p;
634 	int len;
635 
636 	putc('"', out);
637 	while ((p = strchr(str, '"'))) {
638 		len = p - str;
639 		if (len)
640 			fprintf(out, "%.*s", len, str);
641 		fputs("\\\"", out);
642 		str = p + 1;
643 	}
644 	fputs(str, out);
645 	putc('"', out);
646 }
647 
648 static void print_symbol(FILE *out, struct menu *menu)
649 {
650 	struct symbol *sym = menu->sym;
651 	struct property *prop;
652 
653 	if (sym_is_choice(sym))
654 		fprintf(out, "\nchoice\n");
655 	else
656 		fprintf(out, "\nconfig %s\n", sym->name);
657 	switch (sym->type) {
658 	case S_BOOLEAN:
659 		fputs("  bool\n", out);
660 		break;
661 	case S_TRISTATE:
662 		fputs("  tristate\n", out);
663 		break;
664 	case S_STRING:
665 		fputs("  string\n", out);
666 		break;
667 	case S_INT:
668 		fputs("  integer\n", out);
669 		break;
670 	case S_HEX:
671 		fputs("  hex\n", out);
672 		break;
673 	default:
674 		fputs("  ???\n", out);
675 		break;
676 	}
677 	for (prop = sym->prop; prop; prop = prop->next) {
678 		if (prop->menu != menu)
679 			continue;
680 		switch (prop->type) {
681 		case P_PROMPT:
682 			fputs("  prompt ", out);
683 			print_quoted_string(out, prop->text);
684 			if (!expr_is_yes(prop->visible.expr)) {
685 				fputs(" if ", out);
686 				expr_fprint(prop->visible.expr, out);
687 			}
688 			fputc('\n', out);
689 			break;
690 		case P_DEFAULT:
691 			fputs( "  default ", out);
692 			expr_fprint(prop->expr, out);
693 			if (!expr_is_yes(prop->visible.expr)) {
694 				fputs(" if ", out);
695 				expr_fprint(prop->visible.expr, out);
696 			}
697 			fputc('\n', out);
698 			break;
699 		case P_CHOICE:
700 			fputs("  #choice value\n", out);
701 			break;
702 		case P_SELECT:
703 			fputs( "  select ", out);
704 			expr_fprint(prop->expr, out);
705 			fputc('\n', out);
706 			break;
707 		case P_IMPLY:
708 			fputs( "  imply ", out);
709 			expr_fprint(prop->expr, out);
710 			fputc('\n', out);
711 			break;
712 		case P_RANGE:
713 			fputs( "  range ", out);
714 			expr_fprint(prop->expr, out);
715 			fputc('\n', out);
716 			break;
717 		case P_MENU:
718 			fputs( "  menu ", out);
719 			print_quoted_string(out, prop->text);
720 			fputc('\n', out);
721 			break;
722 		case P_SYMBOL:
723 			fputs( "  symbol ", out);
724 			fprintf(out, "%s\n", prop->menu->sym->name);
725 			break;
726 		default:
727 			fprintf(out, "  unknown prop %d!\n", prop->type);
728 			break;
729 		}
730 	}
731 	if (menu->help) {
732 		int len = strlen(menu->help);
733 		while (menu->help[--len] == '\n')
734 			menu->help[len] = 0;
735 		fprintf(out, "  help\n%s\n", menu->help);
736 	}
737 }
738 
739 void zconfdump(FILE *out)
740 {
741 	struct property *prop;
742 	struct symbol *sym;
743 	struct menu *menu;
744 
745 	menu = rootmenu.list;
746 	while (menu) {
747 		if ((sym = menu->sym))
748 			print_symbol(out, menu);
749 		else if ((prop = menu->prompt)) {
750 			switch (prop->type) {
751 			case P_COMMENT:
752 				fputs("\ncomment ", out);
753 				print_quoted_string(out, prop->text);
754 				fputs("\n", out);
755 				break;
756 			case P_MENU:
757 				fputs("\nmenu ", out);
758 				print_quoted_string(out, prop->text);
759 				fputs("\n", out);
760 				break;
761 			default:
762 				;
763 			}
764 			if (!expr_is_yes(prop->visible.expr)) {
765 				fputs("  depends ", out);
766 				expr_fprint(prop->visible.expr, out);
767 				fputc('\n', out);
768 			}
769 		}
770 
771 		if (menu->list)
772 			menu = menu->list;
773 		else if (menu->next)
774 			menu = menu->next;
775 		else while ((menu = menu->parent)) {
776 			if (menu->prompt && menu->prompt->type == P_MENU)
777 				fputs("\nendmenu\n", out);
778 			if (menu->next) {
779 				menu = menu->next;
780 				break;
781 			}
782 		}
783 	}
784 }
785