Masahiro Yamada | 0c87410 | 2018-12-18 21:13:35 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Arnaud Lacombe | dd00330 | 2011-06-01 16:06:22 -0400 | [diff] [blame] | 6 | #include <ctype.h> |
Arnaud Lacombe | 10a4b27 | 2011-06-01 16:00:46 -0400 | [diff] [blame] | 7 | #include <stdarg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "lkc.h" |
| 12 | |
Arnaud Lacombe | 57e6292 | 2011-08-03 21:52:07 -0400 | [diff] [blame] | 13 | static const char nohelp_text[] = "There is no help available for this option."; |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | struct menu rootmenu; |
| 16 | static struct menu **last_entry_ptr; |
| 17 | |
| 18 | struct file *file_list; |
| 19 | struct file *current_file; |
| 20 | |
Roman Zippel | 9344908 | 2008-01-14 04:50:54 +0100 | [diff] [blame] | 21 | void menu_warn(struct menu *menu, const char *fmt, ...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
| 23 | va_list ap; |
| 24 | va_start(ap, fmt); |
| 25 | fprintf(stderr, "%s:%d:warning: ", menu->file->name, menu->lineno); |
| 26 | vfprintf(stderr, fmt, ap); |
| 27 | fprintf(stderr, "\n"); |
| 28 | va_end(ap); |
| 29 | } |
| 30 | |
| 31 | static void prop_warn(struct property *prop, const char *fmt, ...) |
| 32 | { |
| 33 | va_list ap; |
| 34 | va_start(ap, fmt); |
| 35 | fprintf(stderr, "%s:%d:warning: ", prop->file->name, prop->lineno); |
| 36 | vfprintf(stderr, fmt, ap); |
| 37 | fprintf(stderr, "\n"); |
| 38 | va_end(ap); |
| 39 | } |
| 40 | |
nir.tzachar@gmail.com | 692d97c | 2009-11-25 12:28:43 +0200 | [diff] [blame] | 41 | void _menu_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
| 43 | current_entry = current_menu = &rootmenu; |
| 44 | last_entry_ptr = &rootmenu.list; |
| 45 | } |
| 46 | |
| 47 | void menu_add_entry(struct symbol *sym) |
| 48 | { |
| 49 | struct menu *menu; |
| 50 | |
Alan Cox | 177acf7 | 2012-11-06 14:32:08 +0000 | [diff] [blame] | 51 | menu = xmalloc(sizeof(*menu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | memset(menu, 0, sizeof(*menu)); |
| 53 | menu->sym = sym; |
| 54 | menu->parent = current_menu; |
| 55 | menu->file = current_file; |
| 56 | menu->lineno = zconf_lineno(); |
| 57 | |
| 58 | *last_entry_ptr = menu; |
| 59 | last_entry_ptr = &menu->next; |
| 60 | current_entry = menu; |
Sam Ravnborg | 59e89e3 | 2010-07-31 23:35:29 +0200 | [diff] [blame] | 61 | if (sym) |
| 62 | menu_add_symbol(P_SYMBOL, sym, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 65 | struct menu *menu_add_menu(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | last_entry_ptr = ¤t_entry->list; |
Roman Zippel | a02f057 | 2005-11-08 21:34:53 -0800 | [diff] [blame] | 68 | return current_menu = current_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | void menu_end_menu(void) |
| 72 | { |
| 73 | last_entry_ptr = ¤t_menu->next; |
| 74 | current_menu = current_menu->parent; |
| 75 | } |
| 76 | |
Ulf Magnusson | 9a82684 | 2017-10-05 14:01:13 +0200 | [diff] [blame] | 77 | /* |
| 78 | * Rewrites 'm' to 'm' && MODULES, so that it evaluates to 'n' when running |
| 79 | * without modules |
| 80 | */ |
| 81 | static struct expr *rewrite_m(struct expr *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
| 83 | if (!e) |
| 84 | return e; |
| 85 | |
| 86 | switch (e->type) { |
| 87 | case E_NOT: |
Ulf Magnusson | 9a82684 | 2017-10-05 14:01:13 +0200 | [diff] [blame] | 88 | e->left.expr = rewrite_m(e->left.expr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | break; |
| 90 | case E_OR: |
| 91 | case E_AND: |
Ulf Magnusson | 9a82684 | 2017-10-05 14:01:13 +0200 | [diff] [blame] | 92 | e->left.expr = rewrite_m(e->left.expr); |
| 93 | e->right.expr = rewrite_m(e->right.expr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | break; |
| 95 | case E_SYMBOL: |
| 96 | /* change 'm' into 'm' && MODULES */ |
| 97 | if (e->left.sym == &symbol_mod) |
| 98 | return expr_alloc_and(e, expr_alloc_symbol(modules_sym)); |
| 99 | break; |
| 100 | default: |
| 101 | break; |
| 102 | } |
| 103 | return e; |
| 104 | } |
| 105 | |
| 106 | void menu_add_dep(struct expr *dep) |
| 107 | { |
Ulf Magnusson | f77850d | 2017-10-05 14:01:15 +0200 | [diff] [blame] | 108 | current_entry->dep = expr_alloc_and(current_entry->dep, dep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void menu_set_type(int type) |
| 112 | { |
| 113 | struct symbol *sym = current_entry->sym; |
| 114 | |
| 115 | if (sym->type == type) |
| 116 | return; |
| 117 | if (sym->type == S_UNKNOWN) { |
| 118 | sym->type = type; |
| 119 | return; |
| 120 | } |
Martin Walch | 57540f1d | 2013-10-03 18:32:02 +0200 | [diff] [blame] | 121 | menu_warn(current_entry, |
| 122 | "ignoring type redefinition of '%s' from '%s' to '%s'", |
| 123 | sym->name ? sym->name : "<choice>", |
| 124 | sym_type_name(sym->type), sym_type_name(type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Masahiro Yamada | 2ffeef6 | 2019-12-17 13:14:21 +0900 | [diff] [blame] | 127 | static struct property *menu_add_prop(enum prop_type type, struct expr *expr, |
| 128 | struct expr *dep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
Masahiro Yamada | adf7c5b | 2019-12-17 13:14:23 +0900 | [diff] [blame] | 130 | struct property *prop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Masahiro Yamada | adf7c5b | 2019-12-17 13:14:23 +0900 | [diff] [blame] | 132 | prop = xmalloc(sizeof(*prop)); |
| 133 | memset(prop, 0, sizeof(*prop)); |
| 134 | prop->type = type; |
| 135 | prop->file = current_file; |
| 136 | prop->lineno = zconf_lineno(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | prop->menu = current_entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | prop->expr = expr; |
Ulf Magnusson | f77850d | 2017-10-05 14:01:15 +0200 | [diff] [blame] | 139 | prop->visible.expr = dep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | |
Masahiro Yamada | adf7c5b | 2019-12-17 13:14:23 +0900 | [diff] [blame] | 141 | /* append property to the prop list of symbol */ |
| 142 | if (current_entry->sym) { |
| 143 | struct property **propp; |
| 144 | |
| 145 | for (propp = ¤t_entry->sym->prop; |
| 146 | *propp; |
| 147 | propp = &(*propp)->next) |
| 148 | ; |
| 149 | *propp = prop; |
| 150 | } |
| 151 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | return prop; |
| 153 | } |
| 154 | |
Masahiro Yamada | 024352ff | 2019-12-17 13:14:20 +0900 | [diff] [blame] | 155 | struct property *menu_add_prompt(enum prop_type type, char *prompt, |
| 156 | struct expr *dep) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
Masahiro Yamada | 2ffeef6 | 2019-12-17 13:14:21 +0900 | [diff] [blame] | 158 | struct property *prop = menu_add_prop(type, NULL, dep); |
Masahiro Yamada | 024352ff | 2019-12-17 13:14:20 +0900 | [diff] [blame] | 159 | |
| 160 | if (isspace(*prompt)) { |
| 161 | prop_warn(prop, "leading whitespace ignored"); |
| 162 | while (isspace(*prompt)) |
| 163 | prompt++; |
| 164 | } |
| 165 | if (current_entry->prompt) |
| 166 | prop_warn(prop, "prompt redefined"); |
| 167 | |
| 168 | /* Apply all upper menus' visibilities to actual prompts. */ |
| 169 | if (type == P_PROMPT) { |
| 170 | struct menu *menu = current_entry; |
| 171 | |
| 172 | while ((menu = menu->parent) != NULL) { |
| 173 | struct expr *dup_expr; |
| 174 | |
| 175 | if (!menu->visibility) |
| 176 | continue; |
| 177 | /* |
| 178 | * Do not add a reference to the menu's visibility |
| 179 | * expression but use a copy of it. Otherwise the |
| 180 | * expression reduction functions will modify |
| 181 | * expressions that have multiple references which |
| 182 | * can cause unwanted side effects. |
| 183 | */ |
| 184 | dup_expr = expr_copy(menu->visibility); |
| 185 | |
| 186 | prop->visible.expr = expr_alloc_and(prop->visible.expr, |
| 187 | dup_expr); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | current_entry->prompt = prop; |
| 192 | prop->text = prompt; |
| 193 | |
| 194 | return prop; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Arnaud Lacombe | 86e187f | 2010-11-06 18:30:23 -0300 | [diff] [blame] | 197 | void menu_add_visibility(struct expr *expr) |
| 198 | { |
| 199 | current_entry->visibility = expr_alloc_and(current_entry->visibility, |
| 200 | expr); |
| 201 | } |
| 202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep) |
| 204 | { |
Masahiro Yamada | 2ffeef6 | 2019-12-17 13:14:21 +0900 | [diff] [blame] | 205 | menu_add_prop(type, expr, dep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep) |
| 209 | { |
Masahiro Yamada | 2ffeef6 | 2019-12-17 13:14:21 +0900 | [diff] [blame] | 210 | menu_add_prop(type, expr_alloc_symbol(sym), dep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Masahiro Yamada | ce2164a | 2018-12-11 20:01:00 +0900 | [diff] [blame] | 213 | void menu_add_option_modules(void) |
Roman Zippel | f6a88aa | 2006-06-08 22:12:44 -0700 | [diff] [blame] | 214 | { |
Masahiro Yamada | ce2164a | 2018-12-11 20:01:00 +0900 | [diff] [blame] | 215 | if (modules_sym) |
| 216 | zconf_error("symbol '%s' redefines option 'modules' already defined by symbol '%s'", |
| 217 | current_entry->sym->name, modules_sym->name); |
| 218 | modules_sym = current_entry->sym; |
| 219 | } |
| 220 | |
| 221 | void menu_add_option_defconfig_list(void) |
| 222 | { |
| 223 | if (!sym_defconfig_list) |
| 224 | sym_defconfig_list = current_entry->sym; |
| 225 | else if (sym_defconfig_list != current_entry->sym) |
| 226 | zconf_error("trying to redefine defconfig symbol"); |
| 227 | sym_defconfig_list->flags |= SYMBOL_NO_WRITE; |
| 228 | } |
| 229 | |
| 230 | void menu_add_option_allnoconfig_y(void) |
| 231 | { |
| 232 | current_entry->sym->flags |= SYMBOL_ALLNOCONFIG_Y; |
Roman Zippel | f6a88aa | 2006-06-08 22:12:44 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Arnaud Lacombe | ab60bd0 | 2010-12-05 01:29:25 -0500 | [diff] [blame] | 235 | static int menu_validate_number(struct symbol *sym, struct symbol *sym2) |
Roman Zippel | 4cf3cbe | 2005-11-08 21:34:49 -0800 | [diff] [blame] | 236 | { |
| 237 | return sym2->type == S_INT || sym2->type == S_HEX || |
| 238 | (sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name)); |
| 239 | } |
| 240 | |
Trevor Keith | 4356f48 | 2009-09-18 12:49:23 -0700 | [diff] [blame] | 241 | static void sym_check_prop(struct symbol *sym) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | struct property *prop; |
| 244 | struct symbol *sym2; |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 245 | char *use; |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | for (prop = sym->prop; prop; prop = prop->next) { |
| 248 | switch (prop->type) { |
| 249 | case P_DEFAULT: |
| 250 | if ((sym->type == S_STRING || sym->type == S_INT || sym->type == S_HEX) && |
| 251 | prop->expr->type != E_SYMBOL) |
| 252 | prop_warn(prop, |
Li Zefan | 4280eae | 2010-04-14 11:44:05 +0800 | [diff] [blame] | 253 | "default for config symbol '%s'" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | " must be a single symbol", sym->name); |
Arnaud Lacombe | ab60bd0 | 2010-12-05 01:29:25 -0500 | [diff] [blame] | 255 | if (prop->expr->type != E_SYMBOL) |
| 256 | break; |
| 257 | sym2 = prop_get_symbol(prop); |
| 258 | if (sym->type == S_HEX || sym->type == S_INT) { |
| 259 | if (!menu_validate_number(sym, sym2)) |
| 260 | prop_warn(prop, |
| 261 | "'%s': number is invalid", |
| 262 | sym->name); |
| 263 | } |
Ulf Magnusson | 2c37e08 | 2017-10-04 01:25:46 +0200 | [diff] [blame] | 264 | if (sym_is_choice(sym)) { |
| 265 | struct property *choice_prop = |
| 266 | sym_get_choice_prop(sym2); |
| 267 | |
| 268 | if (!choice_prop || |
| 269 | prop_get_symbol(choice_prop) != sym) |
| 270 | prop_warn(prop, |
| 271 | "choice default symbol '%s' is not contained in the choice", |
| 272 | sym2->name); |
| 273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | break; |
| 275 | case P_SELECT: |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 276 | case P_IMPLY: |
| 277 | use = prop->type == P_SELECT ? "select" : "imply"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | sym2 = prop_get_symbol(prop); |
| 279 | if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE) |
| 280 | prop_warn(prop, |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 281 | "config symbol '%s' uses %s, but is " |
Masahiro Yamada | b92d804 | 2017-12-16 00:38:02 +0900 | [diff] [blame] | 282 | "not bool or tristate", sym->name, use); |
Sam Ravnborg | 603d498 | 2008-02-02 21:09:57 +0100 | [diff] [blame] | 283 | else if (sym2->type != S_UNKNOWN && |
Masahiro Yamada | bb66fc6 | 2014-06-10 19:08:13 +0900 | [diff] [blame] | 284 | sym2->type != S_BOOLEAN && |
| 285 | sym2->type != S_TRISTATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | prop_warn(prop, |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 287 | "'%s' has wrong type. '%s' only " |
Masahiro Yamada | b92d804 | 2017-12-16 00:38:02 +0900 | [diff] [blame] | 288 | "accept arguments of bool and " |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 289 | "tristate type", sym2->name, use); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | break; |
| 291 | case P_RANGE: |
| 292 | if (sym->type != S_INT && sym->type != S_HEX) |
| 293 | prop_warn(prop, "range is only allowed " |
Masahiro Yamada | bb66fc6 | 2014-06-10 19:08:13 +0900 | [diff] [blame] | 294 | "for int or hex symbols"); |
Arnaud Lacombe | ab60bd0 | 2010-12-05 01:29:25 -0500 | [diff] [blame] | 295 | if (!menu_validate_number(sym, prop->expr->left.sym) || |
| 296 | !menu_validate_number(sym, prop->expr->right.sym)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | prop_warn(prop, "range is invalid"); |
| 298 | break; |
| 299 | default: |
| 300 | ; |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | void menu_finalize(struct menu *parent) |
| 306 | { |
| 307 | struct menu *menu, *last_menu; |
| 308 | struct symbol *sym; |
| 309 | struct property *prop; |
| 310 | struct expr *parentdep, *basedep, *dep, *dep2, **ep; |
| 311 | |
| 312 | sym = parent->sym; |
| 313 | if (parent->list) { |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 314 | /* |
| 315 | * This menu node has children. We (recursively) process them |
| 316 | * and propagate parent dependencies before moving on. |
| 317 | */ |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (sym && sym_is_choice(sym)) { |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 320 | if (sym->type == S_UNKNOWN) { |
| 321 | /* find the first choice value to find out choice type */ |
| 322 | current_entry = parent; |
| 323 | for (menu = parent->list; menu; menu = menu->next) { |
| 324 | if (menu->sym && menu->sym->type != S_UNKNOWN) { |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 325 | menu_set_type(menu->sym->type); |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 326 | break; |
| 327 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 330 | /* set the type of the remaining choice values */ |
| 331 | for (menu = parent->list; menu; menu = menu->next) { |
| 332 | current_entry = menu; |
| 333 | if (menu->sym && menu->sym->type == S_UNKNOWN) |
| 334 | menu_set_type(sym->type); |
| 335 | } |
Ulf Magnusson | d3465af | 2018-01-14 15:12:05 +0100 | [diff] [blame] | 336 | |
| 337 | /* |
| 338 | * Use the choice itself as the parent dependency of |
| 339 | * the contained items. This turns the mode of the |
| 340 | * choice into an upper bound on the visibility of the |
| 341 | * choice value symbols. |
| 342 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | parentdep = expr_alloc_symbol(sym); |
Masahiro Yamada | de026ca | 2019-12-17 13:14:17 +0900 | [diff] [blame] | 344 | } else { |
| 345 | /* Menu node for 'menu', 'if' */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | parentdep = parent->dep; |
Masahiro Yamada | de026ca | 2019-12-17 13:14:17 +0900 | [diff] [blame] | 347 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 349 | /* For each child menu node... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | for (menu = parent->list; menu; menu = menu->next) { |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 351 | /* |
| 352 | * Propagate parent dependencies to the child menu |
| 353 | * node, also rewriting and simplifying expressions |
| 354 | */ |
Ulf Magnusson | f77850d | 2017-10-05 14:01:15 +0200 | [diff] [blame] | 355 | basedep = rewrite_m(menu->dep); |
| 356 | basedep = expr_transform(basedep); |
Linus Torvalds | e8b8c97 | 2007-10-19 21:25:45 -0700 | [diff] [blame] | 357 | basedep = expr_alloc_and(expr_copy(parentdep), basedep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | basedep = expr_eliminate_dups(basedep); |
| 359 | menu->dep = basedep; |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | if (menu->sym) |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 362 | /* |
| 363 | * Note: For symbols, all prompts are included |
| 364 | * too in the symbol's own property list |
| 365 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | prop = menu->sym->prop; |
| 367 | else |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 368 | /* |
| 369 | * For non-symbol menu nodes, we just need to |
| 370 | * handle the prompt |
| 371 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | prop = menu->prompt; |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 373 | |
| 374 | /* For each property... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | for (; prop; prop = prop->next) { |
| 376 | if (prop->menu != menu) |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 377 | /* |
| 378 | * Two possibilities: |
| 379 | * |
| 380 | * 1. The property lacks dependencies |
| 381 | * and so isn't location-specific, |
| 382 | * e.g. an 'option' |
| 383 | * |
| 384 | * 2. The property belongs to a symbol |
| 385 | * defined in multiple locations and |
| 386 | * is from some other location. It |
| 387 | * will be handled there in that |
| 388 | * case. |
| 389 | * |
| 390 | * Skip the property. |
| 391 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | continue; |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 393 | |
| 394 | /* |
| 395 | * Propagate parent dependencies to the |
| 396 | * property's condition, rewriting and |
| 397 | * simplifying expressions at the same time |
| 398 | */ |
Ulf Magnusson | f77850d | 2017-10-05 14:01:15 +0200 | [diff] [blame] | 399 | dep = rewrite_m(prop->visible.expr); |
| 400 | dep = expr_transform(dep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | dep = expr_alloc_and(expr_copy(basedep), dep); |
| 402 | dep = expr_eliminate_dups(dep); |
| 403 | if (menu->sym && menu->sym->type != S_TRISTATE) |
| 404 | dep = expr_trans_bool(dep); |
| 405 | prop->visible.expr = dep; |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 406 | |
| 407 | /* |
| 408 | * Handle selects and implies, which modify the |
| 409 | * dependencies of the selected/implied symbol |
| 410 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | if (prop->type == P_SELECT) { |
| 412 | struct symbol *es = prop_get_symbol(prop); |
| 413 | es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr, |
| 414 | expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep))); |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 415 | } else if (prop->type == P_IMPLY) { |
| 416 | struct symbol *es = prop_get_symbol(prop); |
| 417 | es->implied.expr = expr_alloc_or(es->implied.expr, |
| 418 | expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | } |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 422 | |
Ulf Magnusson | 7cf33f8 | 2017-10-08 19:35:46 +0200 | [diff] [blame] | 423 | if (sym && sym_is_choice(sym)) |
| 424 | expr_free(parentdep); |
| 425 | |
Ulf Magnusson | fa8ceda | 2017-10-05 14:01:14 +0200 | [diff] [blame] | 426 | /* |
| 427 | * Recursively process children in the same fashion before |
| 428 | * moving on |
| 429 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | for (menu = parent->list; menu; menu = menu->next) |
| 431 | menu_finalize(menu); |
| 432 | } else if (sym) { |
Ulf Magnusson | 05cccce | 2017-10-08 19:42:18 +0200 | [diff] [blame] | 433 | /* |
| 434 | * Automatic submenu creation. If sym is a symbol and A, B, C, |
| 435 | * ... are consecutive items (symbols, menus, ifs, etc.) that |
| 436 | * all depend on sym, then the following menu structure is |
| 437 | * created: |
| 438 | * |
| 439 | * sym |
| 440 | * +-A |
| 441 | * +-B |
| 442 | * +-C |
| 443 | * ... |
| 444 | * |
| 445 | * This also works recursively, giving the following structure |
| 446 | * if A is a symbol and B depends on A: |
| 447 | * |
| 448 | * sym |
| 449 | * +-A |
| 450 | * | +-B |
| 451 | * +-C |
| 452 | * ... |
| 453 | */ |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | basedep = parent->prompt ? parent->prompt->visible.expr : NULL; |
| 456 | basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no); |
| 457 | basedep = expr_eliminate_dups(expr_transform(basedep)); |
Ulf Magnusson | 05cccce | 2017-10-08 19:42:18 +0200 | [diff] [blame] | 458 | |
| 459 | /* Examine consecutive elements after sym */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | last_menu = NULL; |
| 461 | for (menu = parent->next; menu; menu = menu->next) { |
| 462 | dep = menu->prompt ? menu->prompt->visible.expr : menu->dep; |
| 463 | if (!expr_contains_symbol(dep, sym)) |
Ulf Magnusson | 05cccce | 2017-10-08 19:42:18 +0200 | [diff] [blame] | 464 | /* No dependency, quit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | break; |
| 466 | if (expr_depends_symbol(dep, sym)) |
Ulf Magnusson | 05cccce | 2017-10-08 19:42:18 +0200 | [diff] [blame] | 467 | /* Absolute dependency, put in submenu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | goto next; |
Ulf Magnusson | 05cccce | 2017-10-08 19:42:18 +0200 | [diff] [blame] | 469 | |
| 470 | /* |
| 471 | * Also consider it a dependency on sym if our |
| 472 | * dependencies contain sym and are a "superset" of |
| 473 | * sym's dependencies, e.g. '(sym || Q) && R' when sym |
| 474 | * depends on R. |
| 475 | * |
| 476 | * Note that 'R' might be from an enclosing menu or if, |
| 477 | * making this a more common case than it might seem. |
| 478 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no); |
| 480 | dep = expr_eliminate_dups(expr_transform(dep)); |
| 481 | dep2 = expr_copy(basedep); |
| 482 | expr_eliminate_eq(&dep, &dep2); |
| 483 | expr_free(dep); |
| 484 | if (!expr_is_yes(dep2)) { |
Ulf Magnusson | 05cccce | 2017-10-08 19:42:18 +0200 | [diff] [blame] | 485 | /* Not superset, quit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | expr_free(dep2); |
| 487 | break; |
| 488 | } |
Ulf Magnusson | 05cccce | 2017-10-08 19:42:18 +0200 | [diff] [blame] | 489 | /* Superset, put in submenu */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | expr_free(dep2); |
| 491 | next: |
| 492 | menu_finalize(menu); |
| 493 | menu->parent = parent; |
| 494 | last_menu = menu; |
| 495 | } |
Ulf Magnusson | ae7440e | 2017-10-08 19:35:44 +0200 | [diff] [blame] | 496 | expr_free(basedep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | if (last_menu) { |
| 498 | parent->list = parent->next; |
| 499 | parent->next = last_menu->next; |
| 500 | last_menu->next = NULL; |
| 501 | } |
Arnaud Lacombe | ff5ff60 | 2010-09-26 16:22:03 -0400 | [diff] [blame] | 502 | |
Arnaud Lacombe | ec6452a | 2011-06-08 01:42:11 -0400 | [diff] [blame] | 503 | sym->dir_dep.expr = expr_alloc_or(sym->dir_dep.expr, parent->dep); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | for (menu = parent->list; menu; menu = menu->next) { |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 506 | if (sym && sym_is_choice(sym) && |
| 507 | menu->sym && !sym_is_choice_value(menu->sym)) { |
| 508 | current_entry = menu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | menu->sym->flags |= SYMBOL_CHOICEVAL; |
| 510 | if (!menu->prompt) |
| 511 | menu_warn(menu, "choice value must have a prompt"); |
| 512 | for (prop = menu->sym->prop; prop; prop = prop->next) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | if (prop->type == P_DEFAULT) |
| 514 | prop_warn(prop, "defaults for choice " |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 515 | "values not supported"); |
| 516 | if (prop->menu == menu) |
| 517 | continue; |
| 518 | if (prop->type == P_PROMPT && |
| 519 | prop->menu->parent->sym != sym) |
| 520 | prop_warn(prop, "choice value used outside its choice group"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 522 | /* Non-tristate choice values of tristate choices must |
| 523 | * depend on the choice being set to Y. The choice |
| 524 | * values' dependencies were propagated to their |
| 525 | * properties above, so the change here must be re- |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 526 | * propagated. |
| 527 | */ |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 528 | if (sym->type == S_TRISTATE && menu->sym->type != S_TRISTATE) { |
| 529 | basedep = expr_alloc_comp(E_EQUAL, sym, &symbol_yes); |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 530 | menu->dep = expr_alloc_and(basedep, menu->dep); |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 531 | for (prop = menu->sym->prop; prop; prop = prop->next) { |
| 532 | if (prop->menu != menu) |
| 533 | continue; |
Roman Zippel | 5a1aa8a | 2008-02-29 05:11:50 +0100 | [diff] [blame] | 534 | prop->visible.expr = expr_alloc_and(expr_copy(basedep), |
| 535 | prop->visible.expr); |
Jan Beulich | f5eaa32 | 2008-01-24 11:54:23 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | menu_add_symbol(P_CHOICE, sym, NULL); |
| 539 | prop = sym_get_choice_prop(sym); |
| 540 | for (ep = &prop->expr; *ep; ep = &(*ep)->left.expr) |
| 541 | ; |
Roman Zippel | 7a96292 | 2008-01-14 04:50:23 +0100 | [diff] [blame] | 542 | *ep = expr_alloc_one(E_LIST, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | (*ep)->right.sym = menu->sym; |
| 544 | } |
Ulf Magnusson | 9d1a9e8 | 2018-01-14 15:49:26 +0100 | [diff] [blame] | 545 | |
| 546 | /* |
| 547 | * This code serves two purposes: |
| 548 | * |
| 549 | * (1) Flattening 'if' blocks, which do not specify a submenu |
| 550 | * and only add dependencies. |
| 551 | * |
| 552 | * (Automatic submenu creation might still create a submenu |
| 553 | * from an 'if' before this code runs.) |
| 554 | * |
| 555 | * (2) "Undoing" any automatic submenus created earlier below |
| 556 | * promptless symbols. |
| 557 | * |
| 558 | * Before: |
| 559 | * |
| 560 | * A |
| 561 | * if ... (or promptless symbol) |
| 562 | * +-B |
| 563 | * +-C |
| 564 | * D |
| 565 | * |
| 566 | * After: |
| 567 | * |
| 568 | * A |
| 569 | * if ... (or promptless symbol) |
| 570 | * B |
| 571 | * C |
| 572 | * D |
| 573 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | if (menu->list && (!menu->prompt || !menu->prompt->text)) { |
| 575 | for (last_menu = menu->list; ; last_menu = last_menu->next) { |
| 576 | last_menu->parent = parent; |
| 577 | if (!last_menu->next) |
| 578 | break; |
| 579 | } |
| 580 | last_menu->next = menu->next; |
| 581 | menu->next = menu->list; |
| 582 | menu->list = NULL; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | if (sym && !(sym->flags & SYMBOL_WARNED)) { |
| 587 | if (sym->type == S_UNKNOWN) |
Roman Zippel | f001f7f | 2006-06-08 22:12:48 -0700 | [diff] [blame] | 588 | menu_warn(parent, "config symbol defined without type"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
| 590 | if (sym_is_choice(sym) && !parent->prompt) |
Roman Zippel | f001f7f | 2006-06-08 22:12:48 -0700 | [diff] [blame] | 591 | menu_warn(parent, "choice must have a prompt"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
| 593 | /* Check properties connected to this symbol */ |
| 594 | sym_check_prop(sym); |
| 595 | sym->flags |= SYMBOL_WARNED; |
| 596 | } |
| 597 | |
Ulf Magnusson | 3e41ba0 | 2018-01-14 10:56:20 +0100 | [diff] [blame] | 598 | /* |
| 599 | * For non-optional choices, add a reverse dependency (corresponding to |
| 600 | * a select) of '<visibility> && m'. This prevents the user from |
| 601 | * setting the choice mode to 'n' when the choice is visible. |
| 602 | * |
| 603 | * This would also work for non-choice symbols, but only non-optional |
| 604 | * choices clear SYMBOL_OPTIONAL as of writing. Choices are implemented |
| 605 | * as a type of symbol. |
| 606 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | if (sym && !sym_is_optional(sym) && parent->prompt) { |
| 608 | sym->rev_dep.expr = expr_alloc_or(sym->rev_dep.expr, |
| 609 | expr_alloc_and(parent->prompt->visible.expr, |
| 610 | expr_alloc_symbol(&symbol_mod))); |
| 611 | } |
| 612 | } |
| 613 | |
Li Zefan | 22c7eca | 2010-04-14 11:46:02 +0800 | [diff] [blame] | 614 | bool menu_has_prompt(struct menu *menu) |
| 615 | { |
| 616 | if (!menu->prompt) |
| 617 | return false; |
| 618 | return true; |
| 619 | } |
| 620 | |
Dirk Gouders | 1278ebd | 2013-05-19 21:49:34 +0200 | [diff] [blame] | 621 | /* |
| 622 | * Determine if a menu is empty. |
| 623 | * A menu is considered empty if it contains no or only |
| 624 | * invisible entries. |
| 625 | */ |
| 626 | bool menu_is_empty(struct menu *menu) |
| 627 | { |
| 628 | struct menu *child; |
| 629 | |
| 630 | for (child = menu->list; child; child = child->next) { |
| 631 | if (menu_is_visible(child)) |
| 632 | return(false); |
| 633 | } |
| 634 | return(true); |
| 635 | } |
| 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | bool menu_is_visible(struct menu *menu) |
| 638 | { |
| 639 | struct menu *child; |
| 640 | struct symbol *sym; |
| 641 | tristate visible; |
| 642 | |
| 643 | if (!menu->prompt) |
| 644 | return false; |
Li Zefan | 22c7eca | 2010-04-14 11:46:02 +0800 | [diff] [blame] | 645 | |
Arnaud Lacombe | 86e187f | 2010-11-06 18:30:23 -0300 | [diff] [blame] | 646 | if (menu->visibility) { |
| 647 | if (expr_calc_value(menu->visibility) == no) |
Vegard Nossum | aab24a8 | 2016-01-01 17:34:05 +0100 | [diff] [blame] | 648 | return false; |
Arnaud Lacombe | 86e187f | 2010-11-06 18:30:23 -0300 | [diff] [blame] | 649 | } |
| 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | sym = menu->sym; |
| 652 | if (sym) { |
| 653 | sym_calc_value(sym); |
| 654 | visible = menu->prompt->visible.tri; |
| 655 | } else |
| 656 | visible = menu->prompt->visible.tri = expr_calc_value(menu->prompt->visible.expr); |
| 657 | |
| 658 | if (visible != no) |
| 659 | return true; |
Li Zefan | 22c7eca | 2010-04-14 11:46:02 +0800 | [diff] [blame] | 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | if (!sym || sym_get_tristate_value(menu->sym) == no) |
| 662 | return false; |
| 663 | |
Li Zefan | 3fb9acb | 2010-05-07 13:57:07 +0800 | [diff] [blame] | 664 | for (child = menu->list; child; child = child->next) { |
| 665 | if (menu_is_visible(child)) { |
| 666 | if (sym) |
| 667 | sym->flags |= SYMBOL_DEF_USER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return true; |
Li Zefan | 3fb9acb | 2010-05-07 13:57:07 +0800 | [diff] [blame] | 669 | } |
| 670 | } |
Li Zefan | 22c7eca | 2010-04-14 11:46:02 +0800 | [diff] [blame] | 671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | return false; |
| 673 | } |
| 674 | |
| 675 | const char *menu_get_prompt(struct menu *menu) |
| 676 | { |
| 677 | if (menu->prompt) |
EGRY Gabor | 01771b0 | 2008-01-11 23:53:43 +0100 | [diff] [blame] | 678 | return menu->prompt->text; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | else if (menu->sym) |
EGRY Gabor | 01771b0 | 2008-01-11 23:53:43 +0100 | [diff] [blame] | 680 | return menu->sym->name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | return NULL; |
| 682 | } |
| 683 | |
| 684 | struct menu *menu_get_root_menu(struct menu *menu) |
| 685 | { |
| 686 | return &rootmenu; |
| 687 | } |
| 688 | |
| 689 | struct menu *menu_get_parent_menu(struct menu *menu) |
| 690 | { |
| 691 | enum prop_type type; |
| 692 | |
| 693 | for (; menu != &rootmenu; menu = menu->parent) { |
| 694 | type = menu->prompt ? menu->prompt->type : 0; |
| 695 | if (type == P_MENU) |
| 696 | break; |
| 697 | } |
| 698 | return menu; |
| 699 | } |
| 700 | |
Sam Ravnborg | 03d2912 | 2007-07-21 00:00:36 +0200 | [diff] [blame] | 701 | bool menu_has_help(struct menu *menu) |
| 702 | { |
| 703 | return menu->help != NULL; |
| 704 | } |
| 705 | |
| 706 | const char *menu_get_help(struct menu *menu) |
| 707 | { |
| 708 | if (menu->help) |
| 709 | return menu->help; |
| 710 | else |
| 711 | return ""; |
| 712 | } |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 713 | |
Thomas Hebb | edda15f | 2019-12-17 08:15:43 -0800 | [diff] [blame] | 714 | static void get_def_str(struct gstr *r, struct menu *menu) |
| 715 | { |
| 716 | str_printf(r, "Defined at %s:%d\n", |
| 717 | menu->file->name, menu->lineno); |
| 718 | } |
| 719 | |
| 720 | static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix) |
| 721 | { |
| 722 | if (!expr_is_yes(expr)) { |
| 723 | str_append(r, prefix); |
| 724 | expr_gstr_print(expr, r); |
| 725 | str_append(r, "\n"); |
| 726 | } |
| 727 | } |
| 728 | |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 729 | static void get_prompt_str(struct gstr *r, struct property *prop, |
Benjamin Poirier | bad9955 | 2012-10-21 05:27:53 -0400 | [diff] [blame] | 730 | struct list_head *head) |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 731 | { |
| 732 | int i, j; |
Benjamin Poirier | 5e609ad | 2012-08-23 14:55:06 -0400 | [diff] [blame] | 733 | struct menu *submenu[8], *menu, *location = NULL; |
Peter Kümmel | 2d56030 | 2014-11-04 12:01:59 +0100 | [diff] [blame] | 734 | struct jump_key *jump = NULL; |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 735 | |
Thomas Hebb | edda15f | 2019-12-17 08:15:43 -0800 | [diff] [blame] | 736 | str_printf(r, " Prompt: %s\n", prop->text); |
| 737 | |
| 738 | get_dep_str(r, prop->menu->dep, " Depends on: "); |
Thomas Hebb | 3460d0bc | 2019-12-17 08:15:44 -0800 | [diff] [blame] | 739 | /* |
| 740 | * Most prompts in Linux have visibility that exactly matches their |
| 741 | * dependencies. For these, we print only the dependencies to improve |
| 742 | * readability. However, prompts with inline "if" expressions and |
| 743 | * prompts with a parent that has a "visible if" expression have |
| 744 | * differing dependencies and visibility. In these rare cases, we |
| 745 | * print both. |
| 746 | */ |
| 747 | if (!expr_eq(prop->menu->dep, prop->visible.expr)) |
| 748 | get_dep_str(r, prop->visible.expr, " Visible if: "); |
| 749 | |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 750 | menu = prop->menu->parent; |
Benjamin Poirier | 5e609ad | 2012-08-23 14:55:06 -0400 | [diff] [blame] | 751 | for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent) { |
| 752 | bool accessible = menu_is_visible(menu); |
| 753 | |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 754 | submenu[i++] = menu; |
Benjamin Poirier | 5e609ad | 2012-08-23 14:55:06 -0400 | [diff] [blame] | 755 | if (location == NULL && accessible) |
| 756 | location = menu; |
| 757 | } |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 758 | if (head && location) { |
Alan Cox | 177acf7 | 2012-11-06 14:32:08 +0000 | [diff] [blame] | 759 | jump = xmalloc(sizeof(struct jump_key)); |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 760 | |
Benjamin Poirier | 5e609ad | 2012-08-23 14:55:06 -0400 | [diff] [blame] | 761 | if (menu_is_visible(prop->menu)) { |
| 762 | /* |
| 763 | * There is not enough room to put the hint at the |
| 764 | * beginning of the "Prompt" line. Put the hint on the |
| 765 | * last "Location" line even when it would belong on |
| 766 | * the former. |
| 767 | */ |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 768 | jump->target = prop->menu; |
Benjamin Poirier | 5e609ad | 2012-08-23 14:55:06 -0400 | [diff] [blame] | 769 | } else |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 770 | jump->target = location; |
| 771 | |
Benjamin Poirier | bad9955 | 2012-10-21 05:27:53 -0400 | [diff] [blame] | 772 | if (list_empty(head)) |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 773 | jump->index = 0; |
| 774 | else |
Benjamin Poirier | bad9955 | 2012-10-21 05:27:53 -0400 | [diff] [blame] | 775 | jump->index = list_entry(head->prev, struct jump_key, |
| 776 | entries)->index + 1; |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 777 | |
Benjamin Poirier | bad9955 | 2012-10-21 05:27:53 -0400 | [diff] [blame] | 778 | list_add_tail(&jump->entries, head); |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 779 | } |
Benjamin Poirier | 5e609ad | 2012-08-23 14:55:06 -0400 | [diff] [blame] | 780 | |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 781 | if (i > 0) { |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 782 | str_printf(r, " Location:\n"); |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 783 | for (j = 4; --i >= 0; j += 2) { |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 784 | menu = submenu[i]; |
Peter Kümmel | 2d56030 | 2014-11-04 12:01:59 +0100 | [diff] [blame] | 785 | if (jump && menu == location) |
Martin Walch | 503c823 | 2013-10-03 18:35:16 +0200 | [diff] [blame] | 786 | jump->offset = strlen(r->s); |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 787 | str_printf(r, "%*c-> %s", j, ' ', |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 788 | menu_get_prompt(menu)); |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 789 | if (menu->sym) { |
| 790 | str_printf(r, " (%s [=%s])", menu->sym->name ? |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 791 | menu->sym->name : "<choice>", |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 792 | sym_get_string_value(menu->sym)); |
| 793 | } |
| 794 | str_append(r, "\n"); |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 799 | static void get_symbol_props_str(struct gstr *r, struct symbol *sym, |
| 800 | enum prop_type tok, const char *prefix) |
| 801 | { |
| 802 | bool hit = false; |
| 803 | struct property *prop; |
| 804 | |
| 805 | for_all_properties(sym, prop, tok) { |
| 806 | if (!hit) { |
| 807 | str_append(r, prefix); |
| 808 | hit = true; |
| 809 | } else |
| 810 | str_printf(r, " && "); |
| 811 | expr_gstr_print(prop->expr, r); |
| 812 | } |
| 813 | if (hit) |
| 814 | str_append(r, "\n"); |
| 815 | } |
| 816 | |
Wengmeiling | bcdedcc | 2013-04-30 15:28:46 -0700 | [diff] [blame] | 817 | /* |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 818 | * head is optional and may be NULL |
Benjamin Poirier | 5e609ad | 2012-08-23 14:55:06 -0400 | [diff] [blame] | 819 | */ |
Michal Marek | ad8d40c | 2015-02-24 16:37:13 +0100 | [diff] [blame] | 820 | static void get_symbol_str(struct gstr *r, struct symbol *sym, |
Benjamin Poirier | bad9955 | 2012-10-21 05:27:53 -0400 | [diff] [blame] | 821 | struct list_head *head) |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 822 | { |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 823 | struct property *prop; |
| 824 | |
Li Zefan | b040b44 | 2010-05-07 13:56:33 +0800 | [diff] [blame] | 825 | if (sym && sym->name) { |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 826 | str_printf(r, "Symbol: %s [=%s]\n", sym->name, |
| 827 | sym_get_string_value(sym)); |
Li Zefan | b040b44 | 2010-05-07 13:56:33 +0800 | [diff] [blame] | 828 | str_printf(r, "Type : %s\n", sym_type_name(sym->type)); |
Li Zefan | 70ed074 | 2010-05-07 13:56:50 +0800 | [diff] [blame] | 829 | if (sym->type == S_INT || sym->type == S_HEX) { |
| 830 | prop = sym_get_range_prop(sym); |
| 831 | if (prop) { |
| 832 | str_printf(r, "Range : "); |
| 833 | expr_gstr_print(prop->expr, r); |
| 834 | str_append(r, "\n"); |
| 835 | } |
| 836 | } |
Li Zefan | b040b44 | 2010-05-07 13:56:33 +0800 | [diff] [blame] | 837 | } |
Li Zefan | 383da76 | 2013-05-07 15:56:54 +0200 | [diff] [blame] | 838 | |
Thomas Hebb | edda15f | 2019-12-17 08:15:43 -0800 | [diff] [blame] | 839 | /* Print the definitions with prompts before the ones without */ |
| 840 | for_all_properties(sym, prop, P_SYMBOL) { |
| 841 | if (prop->menu->prompt) { |
| 842 | get_def_str(r, prop->menu); |
| 843 | get_prompt_str(r, prop->menu->prompt, head); |
| 844 | } |
| 845 | } |
| 846 | |
| 847 | for_all_properties(sym, prop, P_SYMBOL) { |
| 848 | if (!prop->menu->prompt) { |
| 849 | get_def_str(r, prop->menu); |
| 850 | get_dep_str(r, prop->menu->dep, " Depends on: "); |
Li Zefan | 383da76 | 2013-05-07 15:56:54 +0200 | [diff] [blame] | 851 | } |
Wengmeiling | bcdedcc | 2013-04-30 15:28:46 -0700 | [diff] [blame] | 852 | } |
Li Zefan | 383da76 | 2013-05-07 15:56:54 +0200 | [diff] [blame] | 853 | |
Thomas Hebb | a960968 | 2019-12-17 08:15:45 -0800 | [diff] [blame] | 854 | get_symbol_props_str(r, sym, P_SELECT, "Selects: "); |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 855 | if (sym->rev_dep.expr) { |
Thomas Hebb | a960968 | 2019-12-17 08:15:45 -0800 | [diff] [blame] | 856 | expr_gstr_print_revdep(sym->rev_dep.expr, r, yes, "Selected by [y]:\n"); |
| 857 | expr_gstr_print_revdep(sym->rev_dep.expr, r, mod, "Selected by [m]:\n"); |
| 858 | expr_gstr_print_revdep(sym->rev_dep.expr, r, no, "Selected by [n]:\n"); |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 859 | } |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 860 | |
Thomas Hebb | a960968 | 2019-12-17 08:15:45 -0800 | [diff] [blame] | 861 | get_symbol_props_str(r, sym, P_IMPLY, "Implies: "); |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 862 | if (sym->implied.expr) { |
Thomas Hebb | a960968 | 2019-12-17 08:15:45 -0800 | [diff] [blame] | 863 | expr_gstr_print_revdep(sym->implied.expr, r, yes, "Implied by [y]:\n"); |
| 864 | expr_gstr_print_revdep(sym->implied.expr, r, mod, "Implied by [m]:\n"); |
| 865 | expr_gstr_print_revdep(sym->implied.expr, r, no, "Implied by [n]:\n"); |
Nicolas Pitre | 237e3ad | 2016-11-11 00:10:05 -0500 | [diff] [blame] | 866 | } |
| 867 | |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 868 | str_append(r, "\n\n"); |
| 869 | } |
| 870 | |
Benjamin Poirier | bad9955 | 2012-10-21 05:27:53 -0400 | [diff] [blame] | 871 | struct gstr get_relations_str(struct symbol **sym_arr, struct list_head *head) |
nir.tzachar@gmail.com | 692d97c | 2009-11-25 12:28:43 +0200 | [diff] [blame] | 872 | { |
| 873 | struct symbol *sym; |
| 874 | struct gstr res = str_new(); |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 875 | int i; |
nir.tzachar@gmail.com | 692d97c | 2009-11-25 12:28:43 +0200 | [diff] [blame] | 876 | |
| 877 | for (i = 0; sym_arr && (sym = sym_arr[i]); i++) |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 878 | get_symbol_str(&res, sym, head); |
nir.tzachar@gmail.com | 692d97c | 2009-11-25 12:28:43 +0200 | [diff] [blame] | 879 | if (!i) |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 880 | str_append(&res, "No matches found.\n"); |
nir.tzachar@gmail.com | 692d97c | 2009-11-25 12:28:43 +0200 | [diff] [blame] | 881 | return res; |
| 882 | } |
| 883 | |
| 884 | |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 885 | void menu_get_ext_help(struct menu *menu, struct gstr *help) |
| 886 | { |
| 887 | struct symbol *sym = menu->sym; |
Arnaud Lacombe | 57e6292 | 2011-08-03 21:52:07 -0400 | [diff] [blame] | 888 | const char *help_text = nohelp_text; |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 889 | |
| 890 | if (menu_has_help(menu)) { |
Srinivas Kandagatla | 3f198df | 2011-08-02 18:49:52 +0100 | [diff] [blame] | 891 | if (sym->name) |
Arnaud Lacombe | ffb5957 | 2010-08-14 23:57:43 -0400 | [diff] [blame] | 892 | str_printf(help, "%s%s:\n\n", CONFIG_, sym->name); |
Arnaud Lacombe | 57e6292 | 2011-08-03 21:52:07 -0400 | [diff] [blame] | 893 | help_text = menu_get_help(menu); |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 894 | } |
Sam Ravnborg | 694c49a | 2018-05-22 21:36:12 +0200 | [diff] [blame] | 895 | str_printf(help, "%s\n", help_text); |
Cheng Renquan | 4779105 | 2009-07-12 16:11:46 +0800 | [diff] [blame] | 896 | if (sym) |
Benjamin Poirier | 95ac9b3 | 2012-08-23 14:55:08 -0400 | [diff] [blame] | 897 | get_symbol_str(help, sym, NULL); |
Cheng Renquan | 6bd5999 | 2009-07-12 16:11:44 +0800 | [diff] [blame] | 898 | } |