xref: /linux/scripts/kconfig/menu.c (revision 76df6815dab76d7890936dc5f6d91cf7e7f88358)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
4  */
5 
6 #include <ctype.h>
7 #include <stdarg.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include <list.h>
12 #include <xalloc.h>
13 #include "lkc.h"
14 #include "internal.h"
15 
16 static const char nohelp_text[] = "There is no help available for this option.";
17 
18 struct menu rootmenu = { .type = M_MENU };
19 static struct menu **last_entry_ptr;
20 
21 /**
22  * menu_next - return the next menu entry with depth-first traversal
23  * @menu: pointer to the current menu
24  * @root: root of the sub-tree to traverse. If NULL is given, the traveral
25  *        continues until it reaches the end of the entire menu tree.
26  * return: the menu to visit next, or NULL when it reaches the end.
27  */
28 struct menu *menu_next(struct menu *menu, struct menu *root)
29 {
30 	if (menu->list)
31 		return menu->list;
32 
33 	while (menu != root && !menu->next)
34 		menu = menu->parent;
35 
36 	if (menu == root)
37 		return NULL;
38 
39 	return menu->next;
40 }
41 
42 void menu_warn(const struct menu *menu, const char *fmt, ...)
43 {
44 	va_list ap;
45 	va_start(ap, fmt);
46 	fprintf(stderr, "%s:%d:warning: ", menu->filename, menu->lineno);
47 	vfprintf(stderr, fmt, ap);
48 	fprintf(stderr, "\n");
49 	va_end(ap);
50 }
51 
52 static void prop_warn(const struct property *prop, const char *fmt, ...)
53 {
54 	va_list ap;
55 	va_start(ap, fmt);
56 	fprintf(stderr, "%s:%d:warning: ", prop->filename, prop->lineno);
57 	vfprintf(stderr, fmt, ap);
58 	fprintf(stderr, "\n");
59 	va_end(ap);
60 }
61 
62 void _menu_init(void)
63 {
64 	current_entry = current_menu = &rootmenu;
65 	last_entry_ptr = &rootmenu.list;
66 }
67 
68 void menu_add_entry(struct symbol *sym, enum menu_type type)
69 {
70 	struct menu *menu;
71 
72 	menu = xmalloc(sizeof(*menu));
73 	memset(menu, 0, sizeof(*menu));
74 	menu->type = type;
75 	menu->sym = sym;
76 	menu->parent = current_menu;
77 	menu->filename = cur_filename;
78 	menu->lineno = cur_lineno;
79 
80 	*last_entry_ptr = menu;
81 	last_entry_ptr = &menu->next;
82 	current_entry = menu;
83 	if (sym)
84 		list_add_tail(&menu->link, &sym->menus);
85 }
86 
87 struct menu *menu_add_menu(void)
88 {
89 	last_entry_ptr = &current_entry->list;
90 	current_menu = current_entry;
91 	return current_menu;
92 }
93 
94 void menu_end_menu(void)
95 {
96 	last_entry_ptr = &current_menu->next;
97 	current_menu = current_menu->parent;
98 }
99 
100 /*
101  * Rewrites 'm' to 'm' && MODULES, so that it evaluates to 'n' when running
102  * without modules
103  */
104 static struct expr *rewrite_m(struct expr *e)
105 {
106 	if (!e)
107 		return e;
108 
109 	switch (e->type) {
110 	case E_NOT:
111 		e = expr_alloc_one(E_NOT, rewrite_m(e->left.expr));
112 		break;
113 	case E_OR:
114 	case E_AND:
115 		e = expr_alloc_two(e->type,
116 				   rewrite_m(e->left.expr),
117 				   rewrite_m(e->right.expr));
118 		break;
119 	case E_SYMBOL:
120 		/* change 'm' into 'm' && MODULES */
121 		if (e->left.sym == &symbol_mod)
122 			return expr_alloc_and(e, expr_alloc_symbol(modules_sym));
123 		break;
124 	default:
125 		break;
126 	}
127 	return e;
128 }
129 
130 void menu_add_dep(struct expr *dep, struct expr *cond)
131 {
132 	if (cond) {
133 		/*
134 		 * We have "depends on X if Y" and we want:
135 		 *	Y != n --> X
136 		 *	Y == n --> y
137 		 * That simplifies to: (X || (Y == n))
138 		 */
139 		dep = expr_alloc_or(dep,
140 				expr_trans_compare(cond, E_EQUAL, &symbol_no));
141 	}
142 	current_entry->dep = expr_alloc_and(current_entry->dep, dep);
143 }
144 
145 void menu_set_type(int type)
146 {
147 	struct symbol *sym = current_entry->sym;
148 
149 	if (sym->type == type)
150 		return;
151 	if (sym->type == S_UNKNOWN) {
152 		sym->type = type;
153 		return;
154 	}
155 	menu_warn(current_entry,
156 		"ignoring type redefinition of '%s' from '%s' to '%s'",
157 		sym->name ? sym->name : "<choice>",
158 		sym_type_name(sym->type), sym_type_name(type));
159 }
160 
161 static struct property *menu_add_prop(enum prop_type type, struct expr *expr,
162 				      struct expr *dep)
163 {
164 	struct property *prop;
165 
166 	prop = xmalloc(sizeof(*prop));
167 	memset(prop, 0, sizeof(*prop));
168 	prop->type = type;
169 	prop->filename = cur_filename;
170 	prop->lineno = cur_lineno;
171 	prop->menu = current_entry;
172 	prop->expr = expr;
173 	prop->visible.expr = dep;
174 
175 	/* append property to the prop list of symbol */
176 	if (current_entry->sym) {
177 		struct property **propp;
178 
179 		for (propp = &current_entry->sym->prop;
180 		     *propp;
181 		     propp = &(*propp)->next)
182 			;
183 		*propp = prop;
184 	}
185 
186 	return prop;
187 }
188 
189 struct property *menu_add_prompt(enum prop_type type, const char *prompt,
190 				 struct expr *dep)
191 {
192 	struct property *prop = menu_add_prop(type, NULL, dep);
193 
194 	if (isspace(*prompt)) {
195 		prop_warn(prop, "leading whitespace ignored");
196 		while (isspace(*prompt))
197 			prompt++;
198 	}
199 	if (current_entry->prompt)
200 		prop_warn(prop, "prompt redefined");
201 
202 	/* Apply all upper menus' visibilities to actual prompts. */
203 	if (type == P_PROMPT) {
204 		struct menu *menu = current_entry;
205 
206 		while ((menu = menu->parent) != NULL) {
207 
208 			if (!menu->visibility)
209 				continue;
210 			prop->visible.expr = expr_alloc_and(prop->visible.expr,
211 							    menu->visibility);
212 		}
213 	}
214 
215 	current_entry->prompt = prop;
216 	prop->text = prompt;
217 
218 	return prop;
219 }
220 
221 void menu_add_visibility(struct expr *expr)
222 {
223 	current_entry->visibility = expr_alloc_and(current_entry->visibility,
224 	    expr);
225 }
226 
227 void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
228 {
229 	menu_add_prop(type, expr, dep);
230 }
231 
232 void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
233 {
234 	menu_add_prop(type, expr_alloc_symbol(sym), dep);
235 }
236 
237 static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
238 {
239 	return sym2->type == S_INT || sym2->type == S_HEX ||
240 	       (sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name));
241 }
242 
243 static void sym_check_prop(struct symbol *sym)
244 {
245 	struct property *prop;
246 	struct symbol *sym2;
247 	char *use;
248 
249 	for (prop = sym->prop; prop; prop = prop->next) {
250 		switch (prop->type) {
251 		case P_DEFAULT:
252 			if ((sym->type == S_STRING || sym->type == S_INT || sym->type == S_HEX) &&
253 			    prop->expr->type != E_SYMBOL)
254 				prop_warn(prop,
255 				    "default for config symbol '%s'"
256 				    " must be a single symbol", sym->name);
257 			if (prop->expr->type != E_SYMBOL)
258 				break;
259 			sym2 = prop_get_symbol(prop);
260 			if (sym->type == S_HEX || sym->type == S_INT) {
261 				if (!menu_validate_number(sym, sym2))
262 					prop_warn(prop,
263 					    "'%s': number is invalid",
264 					    sym->name);
265 			}
266 			if (sym_is_choice(sym)) {
267 				struct menu *choice = sym_get_choice_menu(sym2);
268 
269 				if (!choice || choice->sym != sym)
270 					prop_warn(prop,
271 						  "choice default symbol '%s' is not contained in the choice",
272 						  sym2->name);
273 			}
274 			break;
275 		case P_SELECT:
276 		case P_IMPLY:
277 			use = prop->type == P_SELECT ? "select" : "imply";
278 			sym2 = prop_get_symbol(prop);
279 			if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE)
280 				prop_warn(prop,
281 				    "config symbol '%s' uses %s, but is "
282 				    "not bool or tristate", sym->name, use);
283 			else if (sym2->type != S_UNKNOWN &&
284 				 sym2->type != S_BOOLEAN &&
285 				 sym2->type != S_TRISTATE)
286 				prop_warn(prop,
287 				    "'%s' has wrong type. '%s' only "
288 				    "accept arguments of bool and "
289 				    "tristate type", sym2->name, use);
290 			break;
291 		case P_RANGE:
292 			if (sym->type != S_INT && sym->type != S_HEX)
293 				prop_warn(prop, "range is only allowed "
294 						"for int or hex symbols");
295 			if (!menu_validate_number(sym, prop->expr->left.sym) ||
296 			    !menu_validate_number(sym, prop->expr->right.sym))
297 				prop_warn(prop, "range is invalid");
298 			break;
299 		default:
300 			;
301 		}
302 	}
303 }
304 
305 static void _menu_finalize(struct menu *parent, bool inside_choice)
306 {
307 	struct menu *menu, *last_menu;
308 	struct symbol *sym;
309 	struct property *prop;
310 	struct expr *basedep, *dep, *dep2;
311 
312 	sym = parent->sym;
313 	if (parent->list) {
314 		/*
315 		 * This menu node has children. We (recursively) process them
316 		 * and propagate parent dependencies before moving on.
317 		 */
318 
319 		/* For each child menu node... */
320 		for (menu = parent->list; menu; menu = menu->next) {
321 			/*
322 			 * Propagate parent dependencies to the child menu
323 			 * node, also rewriting and simplifying expressions
324 			 */
325 			basedep = rewrite_m(menu->dep);
326 			basedep = expr_transform(basedep);
327 			basedep = expr_alloc_and(parent->dep, basedep);
328 			basedep = expr_eliminate_dups(basedep);
329 			menu->dep = basedep;
330 
331 			if (menu->sym)
332 				/*
333 				 * Note: For symbols, all prompts are included
334 				 * too in the symbol's own property list
335 				 */
336 				prop = menu->sym->prop;
337 			else
338 				/*
339 				 * For non-symbol menu nodes, we just need to
340 				 * handle the prompt
341 				 */
342 				prop = menu->prompt;
343 
344 			/* For each property... */
345 			for (; prop; prop = prop->next) {
346 				if (prop->menu != menu)
347 					/*
348 					 * Two possibilities:
349 					 *
350 					 * 1. The property lacks dependencies
351 					 *    and so isn't location-specific,
352 					 *    e.g. an 'option'
353 					 *
354 					 * 2. The property belongs to a symbol
355 					 *    defined in multiple locations and
356 					 *    is from some other location. It
357 					 *    will be handled there in that
358 					 *    case.
359 					 *
360 					 * Skip the property.
361 					 */
362 					continue;
363 
364 				/*
365 				 * Propagate parent dependencies to the
366 				 * property's condition, rewriting and
367 				 * simplifying expressions at the same time
368 				 */
369 				dep = rewrite_m(prop->visible.expr);
370 				dep = expr_transform(dep);
371 				dep = expr_alloc_and(basedep, dep);
372 				dep = expr_eliminate_dups(dep);
373 				prop->visible.expr = dep;
374 
375 				/*
376 				 * Handle selects and implies, which modify the
377 				 * dependencies of the selected/implied symbol
378 				 */
379 				if (prop->type == P_SELECT) {
380 					struct symbol *es = prop_get_symbol(prop);
381 					es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr,
382 							expr_alloc_and(expr_alloc_symbol(menu->sym), dep));
383 				} else if (prop->type == P_IMPLY) {
384 					struct symbol *es = prop_get_symbol(prop);
385 					es->implied.expr = expr_alloc_or(es->implied.expr,
386 							expr_alloc_and(expr_alloc_symbol(menu->sym), dep));
387 				}
388 			}
389 		}
390 
391 		/*
392 		 * Recursively process children in the same fashion before
393 		 * moving on
394 		 */
395 		for (menu = parent->list; menu; menu = menu->next)
396 			_menu_finalize(menu, sym && sym_is_choice(sym));
397 	} else if (!inside_choice && sym) {
398 		/*
399 		 * Automatic submenu creation. If sym is a symbol and A, B, C,
400 		 * ... are consecutive items (symbols, menus, ifs, etc.) that
401 		 * all depend on sym, then the following menu structure is
402 		 * created:
403 		 *
404 		 *	sym
405 		 *	 +-A
406 		 *	 +-B
407 		 *	 +-C
408 		 *	 ...
409 		 *
410 		 * This also works recursively, giving the following structure
411 		 * if A is a symbol and B depends on A:
412 		 *
413 		 *	sym
414 		 *	 +-A
415 		 *	 | +-B
416 		 *	 +-C
417 		 *	 ...
418 		 */
419 
420 		basedep = parent->prompt ? parent->prompt->visible.expr : NULL;
421 		basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no);
422 		basedep = expr_eliminate_dups(expr_transform(basedep));
423 
424 		/* Examine consecutive elements after sym */
425 		last_menu = NULL;
426 		for (menu = parent->next; menu; menu = menu->next) {
427 			dep = menu->prompt ? menu->prompt->visible.expr : menu->dep;
428 			if (!expr_contains_symbol(dep, sym))
429 				/* No dependency, quit */
430 				break;
431 			if (expr_depends_symbol(dep, sym))
432 				/* Absolute dependency, put in submenu */
433 				goto next;
434 
435 			/*
436 			 * Also consider it a dependency on sym if our
437 			 * dependencies contain sym and are a "superset" of
438 			 * sym's dependencies, e.g. '(sym || Q) && R' when sym
439 			 * depends on R.
440 			 *
441 			 * Note that 'R' might be from an enclosing menu or if,
442 			 * making this a more common case than it might seem.
443 			 */
444 			dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no);
445 			dep = expr_eliminate_dups(expr_transform(dep));
446 			dep2 = basedep;
447 			expr_eliminate_eq(&dep, &dep2);
448 			if (!expr_is_yes(dep2)) {
449 				/* Not superset, quit */
450 				break;
451 			}
452 			/* Superset, put in submenu */
453 		next:
454 			_menu_finalize(menu, false);
455 			menu->parent = parent;
456 			last_menu = menu;
457 		}
458 		if (last_menu) {
459 			parent->list = parent->next;
460 			parent->next = last_menu->next;
461 			last_menu->next = NULL;
462 		}
463 
464 		sym->dir_dep.expr = expr_alloc_or(sym->dir_dep.expr, parent->dep);
465 	}
466 	for (menu = parent->list; menu; menu = menu->next) {
467 		/*
468 		 * This code serves two purposes:
469 		 *
470 		 * (1) Flattening 'if' blocks, which do not specify a submenu
471 		 *     and only add dependencies.
472 		 *
473 		 *     (Automatic submenu creation might still create a submenu
474 		 *     from an 'if' before this code runs.)
475 		 *
476 		 * (2) "Undoing" any automatic submenus created earlier below
477 		 *     promptless symbols.
478 		 *
479 		 * Before:
480 		 *
481 		 *	A
482 		 *	if ... (or promptless symbol)
483 		 *	 +-B
484 		 *	 +-C
485 		 *	D
486 		 *
487 		 * After:
488 		 *
489 		 *	A
490 		 *	if ... (or promptless symbol)
491 		 *	B
492 		 *	C
493 		 *	D
494 		 */
495 		if (menu->list && (!menu->prompt || !menu->prompt->text)) {
496 			for (last_menu = menu->list; ; last_menu = last_menu->next) {
497 				last_menu->parent = parent;
498 				if (!last_menu->next)
499 					break;
500 			}
501 			last_menu->next = menu->next;
502 			menu->next = menu->list;
503 			menu->list = NULL;
504 		}
505 	}
506 
507 	if (sym && !(sym->flags & SYMBOL_WARNED)) {
508 		if (sym->type == S_UNKNOWN)
509 			menu_warn(parent, "config symbol defined without type");
510 
511 		/* Check properties connected to this symbol */
512 		sym_check_prop(sym);
513 		sym->flags |= SYMBOL_WARNED;
514 	}
515 }
516 
517 void menu_finalize(void)
518 {
519 	_menu_finalize(&rootmenu, false);
520 }
521 
522 bool menu_has_prompt(const struct menu *menu)
523 {
524 	if (!menu->prompt)
525 		return false;
526 	return true;
527 }
528 
529 /*
530  * Determine if a menu is empty.
531  * A menu is considered empty if it contains no or only
532  * invisible entries.
533  */
534 bool menu_is_empty(struct menu *menu)
535 {
536 	struct menu *child;
537 
538 	for (child = menu->list; child; child = child->next) {
539 		if (menu_is_visible(child))
540 			return(false);
541 	}
542 	return(true);
543 }
544 
545 bool menu_is_visible(struct menu *menu)
546 {
547 	struct menu *child;
548 	struct symbol *sym;
549 	tristate visible;
550 
551 	if (!menu->prompt)
552 		return false;
553 
554 	if (menu->visibility) {
555 		if (expr_calc_value(menu->visibility) == no)
556 			return false;
557 	}
558 
559 	sym = menu->sym;
560 	if (sym) {
561 		sym_calc_value(sym);
562 		visible = menu->prompt->visible.tri;
563 	} else
564 		visible = menu->prompt->visible.tri = expr_calc_value(menu->prompt->visible.expr);
565 
566 	if (visible != no)
567 		return true;
568 
569 	if (!sym || sym_get_tristate_value(menu->sym) == no)
570 		return false;
571 
572 	for (child = menu->list; child; child = child->next)
573 		if (menu_is_visible(child))
574 			return true;
575 
576 	return false;
577 }
578 
579 const char *menu_get_prompt(const struct menu *menu)
580 {
581 	if (menu->prompt)
582 		return menu->prompt->text;
583 	else if (menu->sym)
584 		return menu->sym->name;
585 	return NULL;
586 }
587 
588 /**
589  * menu_get_parent_menu - return the parent menu or NULL
590  * @menu: pointer to the menu
591  * return: the parent menu, or NULL if there is no parent.
592  */
593 struct menu *menu_get_parent_menu(struct menu *menu)
594 {
595 	for (menu = menu->parent; menu; menu = menu->parent)
596 		if (menu->type == M_MENU)
597 			return menu;
598 
599 	return NULL;
600 }
601 
602 /**
603  * menu_get_menu_or_parent_menu - return the parent menu or the menu itself
604  * @menu: pointer to the menu
605  * return: the parent menu. If the given argument is already a menu, return
606  *         itself.
607  */
608 struct menu *menu_get_menu_or_parent_menu(struct menu *menu)
609 {
610 	enum prop_type type;
611 
612 	for (; menu != &rootmenu; menu = menu->parent) {
613 		type = menu->prompt ? menu->prompt->type : 0;
614 		if (type == P_MENU)
615 			break;
616 	}
617 	return menu;
618 }
619 
620 static void get_def_str(struct gstr *r, const struct menu *menu)
621 {
622 	str_printf(r, "Defined at %s:%d\n",
623 		   menu->filename, menu->lineno);
624 }
625 
626 static void get_dep_str(struct gstr *r, const struct expr *expr,
627 			const char *prefix)
628 {
629 	if (!expr_is_yes(expr)) {
630 		str_append(r, prefix);
631 		expr_gstr_print(expr, r);
632 		str_append(r, "\n");
633 	}
634 }
635 
636 int __attribute__((weak)) get_jump_key_char(void)
637 {
638 	return -1;
639 }
640 
641 static void get_prompt_str(struct gstr *r, struct property *prop,
642 			   struct list_head *head)
643 {
644 	int i, j;
645 	struct menu *submenu[8], *menu, *location = NULL;
646 	struct jump_key *jump = NULL;
647 
648 	str_printf(r, "  Prompt: %s\n", prop->text);
649 
650 	get_dep_str(r, prop->menu->dep, "  Depends on: ");
651 	/*
652 	 * Most prompts in Linux have visibility that exactly matches their
653 	 * dependencies. For these, we print only the dependencies to improve
654 	 * readability. However, prompts with inline "if" expressions and
655 	 * prompts with a parent that has a "visible if" expression have
656 	 * differing dependencies and visibility. In these rare cases, we
657 	 * print both.
658 	 */
659 	if (!expr_eq(prop->menu->dep, prop->visible.expr))
660 		get_dep_str(r, prop->visible.expr, "  Visible if: ");
661 
662 	menu = prop->menu;
663 	for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) {
664 		submenu[i++] = menu;
665 		if (location == NULL && menu_is_visible(menu))
666 			location = menu;
667 	}
668 	if (head && location) {
669 		jump = xmalloc(sizeof(struct jump_key));
670 		jump->target = location;
671 		list_add_tail(&jump->entries, head);
672 	}
673 
674 	str_printf(r, "  Location:\n");
675 	for (j = 0; --i >= 0; j++) {
676 		int jk = -1;
677 		int indent = 2 * j + 4;
678 
679 		menu = submenu[i];
680 		if (jump && menu == location) {
681 			jump->offset = strlen(r->s);
682 			jk = get_jump_key_char();
683 		}
684 
685 		if (jk >= 0) {
686 			str_printf(r, "(%c)", jk);
687 			indent -= 3;
688 		}
689 
690 		str_printf(r, "%*c-> %s", indent, ' ', menu_get_prompt(menu));
691 		if (menu->sym) {
692 			str_printf(r, " (%s [=%s])", menu->sym->name ?
693 				menu->sym->name : "<choice>",
694 				sym_get_string_value(menu->sym));
695 		}
696 		str_append(r, "\n");
697 	}
698 }
699 
700 static void get_symbol_props_str(struct gstr *r, struct symbol *sym,
701 				 enum prop_type tok, const char *prefix)
702 {
703 	bool hit = false;
704 	struct property *prop;
705 
706 	for_all_properties(sym, prop, tok) {
707 		if (!hit) {
708 			str_append(r, prefix);
709 			hit = true;
710 		} else
711 			str_printf(r, " && ");
712 		expr_gstr_print(prop->expr, r);
713 	}
714 	if (hit)
715 		str_append(r, "\n");
716 }
717 
718 /*
719  * head is optional and may be NULL
720  */
721 static void get_symbol_str(struct gstr *r, struct symbol *sym,
722 		    struct list_head *head)
723 {
724 	struct property *prop;
725 	struct menu *menu;
726 
727 	if (sym && sym->name) {
728 		str_printf(r, "Symbol: %s [=%s]\n", sym->name,
729 			   sym_get_string_value(sym));
730 		str_printf(r, "Type  : %s\n", sym_type_name(sym->type));
731 		if (sym->type == S_INT || sym->type == S_HEX) {
732 			prop = sym_get_range_prop(sym);
733 			if (prop) {
734 				str_printf(r, "Range : ");
735 				expr_gstr_print(prop->expr, r);
736 				str_append(r, "\n");
737 			}
738 		}
739 	}
740 
741 	/* Print the definitions with prompts before the ones without */
742 	list_for_each_entry(menu, &sym->menus, link) {
743 		if (menu->prompt) {
744 			get_def_str(r, menu);
745 			get_prompt_str(r, menu->prompt, head);
746 		}
747 	}
748 
749 	list_for_each_entry(menu, &sym->menus, link) {
750 		if (!menu->prompt) {
751 			get_def_str(r, menu);
752 			get_dep_str(r, menu->dep, "  Depends on: ");
753 		}
754 	}
755 
756 	get_symbol_props_str(r, sym, P_SELECT, "Selects: ");
757 	if (sym->rev_dep.expr) {
758 		expr_gstr_print_revdep(sym->rev_dep.expr, r, yes, "Selected by [y]:\n");
759 		expr_gstr_print_revdep(sym->rev_dep.expr, r, mod, "Selected by [m]:\n");
760 		expr_gstr_print_revdep(sym->rev_dep.expr, r, no, "Selected by [n]:\n");
761 	}
762 
763 	get_symbol_props_str(r, sym, P_IMPLY, "Implies: ");
764 	if (sym->implied.expr) {
765 		expr_gstr_print_revdep(sym->implied.expr, r, yes, "Implied by [y]:\n");
766 		expr_gstr_print_revdep(sym->implied.expr, r, mod, "Implied by [m]:\n");
767 		expr_gstr_print_revdep(sym->implied.expr, r, no, "Implied by [n]:\n");
768 	}
769 
770 	str_append(r, "\n\n");
771 }
772 
773 struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head)
774 {
775 	struct symbol *sym;
776 	struct gstr res = str_new();
777 	int i;
778 
779 	for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
780 		get_symbol_str(&res, sym, head);
781 	if (!i)
782 		str_append(&res, "No matches found.\n");
783 	return res;
784 }
785 
786 
787 void menu_get_ext_help(struct menu *menu, struct gstr *help)
788 {
789 	struct symbol *sym = menu->sym;
790 	const char *help_text = nohelp_text;
791 
792 	if (menu->help) {
793 		if (sym->name)
794 			str_printf(help, "%s%s:\n\n", CONFIG_, sym->name);
795 		help_text = menu->help;
796 	}
797 	str_printf(help, "%s\n", help_text);
798 	if (sym)
799 		get_symbol_str(help, sym, NULL);
800 }
801 
802 /**
803  * menu_dump - dump all menu entries in a tree-like format
804  */
805 void menu_dump(void)
806 {
807 	struct menu *menu = &rootmenu;
808 	unsigned long long bits = 0;
809 	int indent = 0;
810 
811 	while (menu) {
812 
813 		for (int i = indent - 1; i >= 0; i--) {
814 			if (bits & (1ULL << i)) {
815 				if (i > 0)
816 					printf("|   ");
817 				else
818 					printf("|-- ");
819 			} else {
820 				if (i > 0)
821 					printf("    ");
822 				else
823 					printf("`-- ");
824 			}
825 		}
826 
827 		switch (menu->type) {
828 		case M_CHOICE:
829 			printf("choice \"%s\"\n", menu->prompt->text);
830 			break;
831 		case M_COMMENT:
832 			printf("comment \"%s\"\n", menu->prompt->text);
833 			break;
834 		case M_IF:
835 			printf("if\n");
836 			break;
837 		case M_MENU:
838 			printf("menu \"%s\"", menu->prompt->text);
839 			if (!menu->sym) {
840 				printf("\n");
841 				break;
842 			}
843 			printf(" + ");
844 			/* fallthrough */
845 		case M_NORMAL:
846 			printf("symbol %s\n", menu->sym->name);
847 			break;
848 		}
849 		if (menu->list) {
850 			bits <<= 1;
851 			menu = menu->list;
852 			if (menu->next)
853 				bits |= 1;
854 			else
855 				bits &= ~1;
856 			indent++;
857 			continue;
858 		}
859 
860 		while (menu && !menu->next) {
861 			menu = menu->parent;
862 			bits >>= 1;
863 			indent--;
864 		}
865 
866 		if (menu) {
867 			menu = menu->next;
868 			if (menu->next)
869 				bits |= 1;
870 			else
871 				bits &= ~1;
872 		}
873 	}
874 }
875