xref: /linux/scripts/kconfig/parser.y (revision 42d37fc0c819b81f6f6afd108b55d04ba9d32d0f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
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_set_type(S_BOOLEAN);
245 	INIT_LIST_HEAD(&current_entry->choice_members);
246 
247 	printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno);
248 };
249 
250 choice_entry: choice choice_option_list
251 {
252 	if (!current_entry->prompt) {
253 		fprintf(stderr, "%s:%d: error: choice must have a prompt\n",
254 			current_entry->filename, current_entry->lineno);
255 		yynerrs++;
256 	}
257 
258 	$$ = menu_add_menu();
259 
260 	current_choice = current_entry;
261 };
262 
263 choice_end: end
264 {
265 	current_choice = NULL;
266 
267 	if (zconf_endtoken($1, "choice")) {
268 		menu_end_menu();
269 		printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno);
270 	}
271 };
272 
273 choice_stmt: choice_entry stmt_list_in_choice choice_end
274 ;
275 
276 choice_option_list:
277 	  /* empty */
278 	| choice_option_list choice_option
279 	| choice_option_list depends
280 	| choice_option_list help
281 ;
282 
283 choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL
284 {
285 	menu_add_prompt(P_PROMPT, $2, $3);
286 	printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno);
287 };
288 
289 choice_option: T_BOOL T_WORD_QUOTE if_expr T_EOL
290 {
291 	menu_add_prompt(P_PROMPT, $2, $3);
292 	printd(DEBUG_PARSE, "%s:%d:bool\n", cur_filename, cur_lineno);
293 };
294 
295 choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL
296 {
297 	menu_add_symbol(P_DEFAULT, $2, $3);
298 	printd(DEBUG_PARSE, "%s:%d:default\n", cur_filename, cur_lineno);
299 };
300 
301 type:
302 	  T_BOOL		{ $$ = S_BOOLEAN; }
303 	| T_TRISTATE		{ $$ = S_TRISTATE; }
304 	| T_INT			{ $$ = S_INT; }
305 	| T_HEX			{ $$ = S_HEX; }
306 	| T_STRING		{ $$ = S_STRING; }
307 
308 default:
309 	  T_DEFAULT		{ $$ = S_UNKNOWN; }
310 	| T_DEF_BOOL		{ $$ = S_BOOLEAN; }
311 	| T_DEF_TRISTATE	{ $$ = S_TRISTATE; }
312 
313 /* if entry */
314 
315 if_entry: T_IF expr T_EOL
316 {
317 	printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno);
318 	menu_add_entry(NULL);
319 	menu_add_dep($2);
320 	$$ = menu_add_menu();
321 };
322 
323 if_end: end
324 {
325 	if (zconf_endtoken($1, "if")) {
326 		menu_end_menu();
327 		printd(DEBUG_PARSE, "%s:%d:endif\n", cur_filename, cur_lineno);
328 	}
329 };
330 
331 if_stmt: if_entry stmt_list if_end
332 ;
333 
334 if_stmt_in_choice: if_entry stmt_list_in_choice if_end
335 ;
336 
337 /* menu entry */
338 
339 menu: T_MENU T_WORD_QUOTE T_EOL
340 {
341 	menu_add_entry(NULL);
342 	menu_add_prompt(P_MENU, $2, NULL);
343 	printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno);
344 };
345 
346 menu_entry: menu menu_option_list
347 {
348 	$$ = menu_add_menu();
349 };
350 
351 menu_end: end
352 {
353 	if (zconf_endtoken($1, "menu")) {
354 		menu_end_menu();
355 		printd(DEBUG_PARSE, "%s:%d:endmenu\n", cur_filename, cur_lineno);
356 	}
357 };
358 
359 menu_stmt: menu_entry stmt_list menu_end
360 ;
361 
362 menu_option_list:
363 	  /* empty */
364 	| menu_option_list visible
365 	| menu_option_list depends
366 ;
367 
368 source_stmt: T_SOURCE T_WORD_QUOTE T_EOL
369 {
370 	printd(DEBUG_PARSE, "%s:%d:source %s\n", cur_filename, cur_lineno, $2);
371 	zconf_nextfile($2);
372 	free($2);
373 };
374 
375 /* comment entry */
376 
377 comment: T_COMMENT T_WORD_QUOTE T_EOL
378 {
379 	menu_add_entry(NULL);
380 	menu_add_prompt(P_COMMENT, $2, NULL);
381 	printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno);
382 };
383 
384 comment_stmt: comment comment_option_list
385 ;
386 
387 comment_option_list:
388 	  /* empty */
389 	| comment_option_list depends
390 ;
391 
392 /* help option */
393 
394 help_start: T_HELP T_EOL
395 {
396 	printd(DEBUG_PARSE, "%s:%d:help\n", cur_filename, cur_lineno);
397 	zconf_starthelp();
398 };
399 
400 help: help_start T_HELPTEXT
401 {
402 	if (current_entry->help) {
403 		free(current_entry->help);
404 		zconfprint("warning: '%s' defined with more than one help text -- only the last one will be used",
405 			   current_entry->sym->name ?: "<choice>");
406 	}
407 
408 	/* Is the help text empty or all whitespace? */
409 	if ($2[strspn($2, " \f\n\r\t\v")] == '\0')
410 		zconfprint("warning: '%s' defined with blank help text",
411 			   current_entry->sym->name ?: "<choice>");
412 
413 	current_entry->help = $2;
414 };
415 
416 /* depends option */
417 
418 depends: T_DEPENDS T_ON expr T_EOL
419 {
420 	menu_add_dep($3);
421 	printd(DEBUG_PARSE, "%s:%d:depends on\n", cur_filename, cur_lineno);
422 };
423 
424 /* visibility option */
425 visible: T_VISIBLE if_expr T_EOL
426 {
427 	menu_add_visibility($2);
428 };
429 
430 /* prompt statement */
431 
432 prompt_stmt_opt:
433 	  /* empty */
434 	| T_WORD_QUOTE if_expr
435 {
436 	menu_add_prompt(P_PROMPT, $1, $2);
437 };
438 
439 end:	  T_ENDMENU T_EOL	{ $$ = "menu"; }
440 	| T_ENDCHOICE T_EOL	{ $$ = "choice"; }
441 	| T_ENDIF T_EOL		{ $$ = "if"; }
442 ;
443 
444 if_expr:  /* empty */			{ $$ = NULL; }
445 	| T_IF expr			{ $$ = $2; }
446 ;
447 
448 expr:	  symbol				{ $$ = expr_alloc_symbol($1); }
449 	| symbol T_LESS symbol			{ $$ = expr_alloc_comp(E_LTH, $1, $3); }
450 	| symbol T_LESS_EQUAL symbol		{ $$ = expr_alloc_comp(E_LEQ, $1, $3); }
451 	| symbol T_GREATER symbol		{ $$ = expr_alloc_comp(E_GTH, $1, $3); }
452 	| symbol T_GREATER_EQUAL symbol		{ $$ = expr_alloc_comp(E_GEQ, $1, $3); }
453 	| symbol T_EQUAL symbol			{ $$ = expr_alloc_comp(E_EQUAL, $1, $3); }
454 	| symbol T_UNEQUAL symbol		{ $$ = expr_alloc_comp(E_UNEQUAL, $1, $3); }
455 	| T_OPEN_PAREN expr T_CLOSE_PAREN	{ $$ = $2; }
456 	| T_NOT expr				{ $$ = expr_alloc_one(E_NOT, $2); }
457 	| expr T_OR expr			{ $$ = expr_alloc_two(E_OR, $1, $3); }
458 	| expr T_AND expr			{ $$ = expr_alloc_two(E_AND, $1, $3); }
459 ;
460 
461 /* For symbol definitions, selects, etc., where quotes are not accepted */
462 nonconst_symbol: T_WORD { $$ = sym_lookup($1, 0); free($1); };
463 
464 symbol:	  nonconst_symbol
465 	| T_WORD_QUOTE	{ $$ = sym_lookup($1, SYMBOL_CONST); free($1); }
466 ;
467 
468 /* assignment statement */
469 
470 assignment_stmt:  T_WORD assign_op assign_val T_EOL	{ variable_add($1, $3, $2); free($1); free($3); }
471 
472 assign_op:
473 	  T_EQUAL	{ $$ = VAR_RECURSIVE; }
474 	| T_COLON_EQUAL	{ $$ = VAR_SIMPLE; }
475 	| T_PLUS_EQUAL	{ $$ = VAR_APPEND; }
476 ;
477 
478 assign_val:
479 	/* empty */		{ $$ = xstrdup(""); };
480 	| T_ASSIGN_VAL
481 ;
482 
483 %%
484 
485 /**
486  * choice_check_sanity - check sanity of a choice member
487  *
488  * @menu: menu of the choice member
489  *
490  * Return: -1 if an error is found, 0 otherwise.
491  */
492 static int choice_check_sanity(const struct menu *menu)
493 {
494 	struct property *prop;
495 	int ret = 0;
496 
497 	for (prop = menu->sym->prop; prop; prop = prop->next) {
498 		if (prop->type == P_DEFAULT) {
499 			fprintf(stderr, "%s:%d: error: %s",
500 				prop->filename, prop->lineno,
501 				"defaults for choice values not supported\n");
502 			ret = -1;
503 		}
504 
505 		if (prop->menu != menu && prop->type == P_PROMPT &&
506 		    prop->menu->parent != menu->parent) {
507 			fprintf(stderr, "%s:%d: error: %s",
508 				prop->filename, prop->lineno,
509 				"choice value has a prompt outside its choice group\n");
510 			ret = -1;
511 		}
512 	}
513 
514 	return ret;
515 }
516 
517 void conf_parse(const char *name)
518 {
519 	struct menu *menu;
520 
521 	autoconf_cmd = str_new();
522 
523 	str_printf(&autoconf_cmd, "\ndeps_config := \\\n");
524 
525 	zconf_initscan(name);
526 
527 	_menu_init();
528 
529 	if (getenv("ZCONF_DEBUG"))
530 		yydebug = 1;
531 	yyparse();
532 
533 	/*
534 	 * FIXME:
535 	 * cur_filename and cur_lineno are used even after yyparse();
536 	 * menu_finalize() calls menu_add_symbol(). This should be fixed.
537 	 */
538 	cur_filename = "<none>";
539 	cur_lineno = 0;
540 
541 	str_printf(&autoconf_cmd,
542 		   "\n"
543 		   "$(autoconfig): $(deps_config)\n"
544 		   "$(deps_config): ;\n");
545 
546 	env_write_dep(&autoconf_cmd);
547 
548 	/* Variables are expanded in the parse phase. We can free them here. */
549 	variable_all_del();
550 
551 	if (yynerrs)
552 		exit(1);
553 	if (!modules_sym)
554 		modules_sym = &symbol_no;
555 
556 	if (!menu_has_prompt(&rootmenu)) {
557 		current_entry = &rootmenu;
558 		menu_add_prompt(P_MENU, "Main menu", NULL);
559 	}
560 
561 	menu_finalize();
562 
563 	menu_for_each_entry(menu) {
564 		struct menu *child;
565 
566 		if (menu->sym && sym_check_deps(menu->sym))
567 			yynerrs++;
568 
569 		if (menu->sym && sym_is_choice(menu->sym)) {
570 			menu_for_each_sub_entry(child, menu)
571 				if (child->sym && choice_check_sanity(child))
572 					yynerrs++;
573 		}
574 	}
575 
576 	if (yynerrs)
577 		exit(1);
578 	conf_set_changed(true);
579 }
580 
581 static bool zconf_endtoken(const char *tokenname,
582 			   const char *expected_tokenname)
583 {
584 	if (strcmp(tokenname, expected_tokenname)) {
585 		zconf_error("unexpected '%s' within %s block",
586 			    tokenname, expected_tokenname);
587 		yynerrs++;
588 		return false;
589 	}
590 	if (strcmp(current_menu->filename, cur_filename)) {
591 		zconf_error("'%s' in different file than '%s'",
592 			    tokenname, expected_tokenname);
593 		fprintf(stderr, "%s:%d: location of the '%s'\n",
594 			current_menu->filename, current_menu->lineno,
595 			expected_tokenname);
596 		yynerrs++;
597 		return false;
598 	}
599 	return true;
600 }
601 
602 static void zconfprint(const char *err, ...)
603 {
604 	va_list ap;
605 
606 	fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno);
607 	va_start(ap, err);
608 	vfprintf(stderr, err, ap);
609 	va_end(ap);
610 	fprintf(stderr, "\n");
611 }
612 
613 static void zconf_error(const char *err, ...)
614 {
615 	va_list ap;
616 
617 	yynerrs++;
618 	fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno);
619 	va_start(ap, err);
620 	vfprintf(stderr, err, ap);
621 	va_end(ap);
622 	fprintf(stderr, "\n");
623 }
624 
625 static void yyerror(const char *err)
626 {
627 	fprintf(stderr, "%s:%d: %s\n", cur_filename, cur_lineno, err);
628 }
629 
630 static void print_quoted_string(FILE *out, const char *str)
631 {
632 	const char *p;
633 	int len;
634 
635 	putc('"', out);
636 	while ((p = strchr(str, '"'))) {
637 		len = p - str;
638 		if (len)
639 			fprintf(out, "%.*s", len, str);
640 		fputs("\\\"", out);
641 		str = p + 1;
642 	}
643 	fputs(str, out);
644 	putc('"', out);
645 }
646 
647 static void print_symbol(FILE *out, const struct menu *menu)
648 {
649 	struct symbol *sym = menu->sym;
650 	struct property *prop;
651 
652 	if (sym_is_choice(sym))
653 		fprintf(out, "\nchoice\n");
654 	else
655 		fprintf(out, "\nconfig %s\n", sym->name);
656 	switch (sym->type) {
657 	case S_BOOLEAN:
658 		fputs("  bool\n", out);
659 		break;
660 	case S_TRISTATE:
661 		fputs("  tristate\n", out);
662 		break;
663 	case S_STRING:
664 		fputs("  string\n", out);
665 		break;
666 	case S_INT:
667 		fputs("  integer\n", out);
668 		break;
669 	case S_HEX:
670 		fputs("  hex\n", out);
671 		break;
672 	default:
673 		fputs("  ???\n", out);
674 		break;
675 	}
676 	for (prop = sym->prop; prop; prop = prop->next) {
677 		if (prop->menu != menu)
678 			continue;
679 		switch (prop->type) {
680 		case P_PROMPT:
681 			fputs("  prompt ", out);
682 			print_quoted_string(out, prop->text);
683 			if (!expr_is_yes(prop->visible.expr)) {
684 				fputs(" if ", out);
685 				expr_fprint(prop->visible.expr, out);
686 			}
687 			fputc('\n', out);
688 			break;
689 		case P_DEFAULT:
690 			fputs( "  default ", out);
691 			expr_fprint(prop->expr, out);
692 			if (!expr_is_yes(prop->visible.expr)) {
693 				fputs(" if ", out);
694 				expr_fprint(prop->visible.expr, out);
695 			}
696 			fputc('\n', out);
697 			break;
698 		case P_SELECT:
699 			fputs( "  select ", out);
700 			expr_fprint(prop->expr, out);
701 			fputc('\n', out);
702 			break;
703 		case P_IMPLY:
704 			fputs( "  imply ", out);
705 			expr_fprint(prop->expr, out);
706 			fputc('\n', out);
707 			break;
708 		case P_RANGE:
709 			fputs( "  range ", out);
710 			expr_fprint(prop->expr, out);
711 			fputc('\n', out);
712 			break;
713 		case P_MENU:
714 			fputs( "  menu ", out);
715 			print_quoted_string(out, prop->text);
716 			fputc('\n', out);
717 			break;
718 		case P_SYMBOL:
719 			fputs( "  symbol ", out);
720 			fprintf(out, "%s\n", prop->menu->sym->name);
721 			break;
722 		default:
723 			fprintf(out, "  unknown prop %d!\n", prop->type);
724 			break;
725 		}
726 	}
727 	if (menu->help) {
728 		int len = strlen(menu->help);
729 		while (menu->help[--len] == '\n')
730 			menu->help[len] = 0;
731 		fprintf(out, "  help\n%s\n", menu->help);
732 	}
733 }
734 
735 void zconfdump(FILE *out)
736 {
737 	struct property *prop;
738 	struct symbol *sym;
739 	struct menu *menu;
740 
741 	menu = rootmenu.list;
742 	while (menu) {
743 		if ((sym = menu->sym))
744 			print_symbol(out, menu);
745 		else if ((prop = menu->prompt)) {
746 			switch (prop->type) {
747 			case P_COMMENT:
748 				fputs("\ncomment ", out);
749 				print_quoted_string(out, prop->text);
750 				fputs("\n", out);
751 				break;
752 			case P_MENU:
753 				fputs("\nmenu ", out);
754 				print_quoted_string(out, prop->text);
755 				fputs("\n", out);
756 				break;
757 			default:
758 				;
759 			}
760 			if (!expr_is_yes(prop->visible.expr)) {
761 				fputs("  depends ", out);
762 				expr_fprint(prop->visible.expr, out);
763 				fputc('\n', out);
764 			}
765 		}
766 
767 		if (menu->list)
768 			menu = menu->list;
769 		else if (menu->next)
770 			menu = menu->next;
771 		else while ((menu = menu->parent)) {
772 			if (menu->prompt && menu->prompt->type == P_MENU)
773 				fputs("\nendmenu\n", out);
774 			if (menu->next) {
775 				menu = menu->next;
776 				break;
777 			}
778 		}
779 	}
780 }
781