menu.c 18 KB

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