menu.c 19 KB

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