kconfig/menu.c
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun May 08 14:14:40 2011 +0200 (2011-05-08)
changeset 2448 a103abae1560
parent 1040 dc17e615de2c
child 2450 68cc5a0d3191
permissions -rw-r--r--
kconfig: update from linux-next

Signed-off-by: "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
yann@1
     1
/*
yann@1
     2
 * Copyright (C) 2002 Roman Zippel <zippel@linux-m68k.org>
yann@1
     3
 * Released under the terms of the GNU GPL v2.0.
yann@1
     4
 */
yann@1
     5
yann@1
     6
#include <stdlib.h>
yann@1
     7
#include <string.h>
yann@1
     8
yann@1
     9
#define LKC_DIRECT_LINK
yann@1
    10
#include "lkc.h"
yann@1
    11
yann@2448
    12
static const char nohelp_text[] = N_(
yann@2448
    13
	"There is no help available for this option.\n");
yann@2448
    14
yann@1
    15
struct menu rootmenu;
yann@1
    16
static struct menu **last_entry_ptr;
yann@1
    17
yann@1
    18
struct file *file_list;
yann@1
    19
struct file *current_file;
yann@1
    20
yann@943
    21
void menu_warn(struct menu *menu, const char *fmt, ...)
yann@1
    22
{
yann@1
    23
	va_list ap;
yann@1
    24
	va_start(ap, fmt);
yann@1
    25
	fprintf(stderr, "%s:%d:warning: ", menu->file->name, menu->lineno);
yann@1
    26
	vfprintf(stderr, fmt, ap);
yann@1
    27
	fprintf(stderr, "\n");
yann@1
    28
	va_end(ap);
yann@1
    29
}
yann@1
    30
yann@1
    31
static void prop_warn(struct property *prop, const char *fmt, ...)
yann@1
    32
{
yann@1
    33
	va_list ap;
yann@1
    34
	va_start(ap, fmt);
yann@1
    35
	fprintf(stderr, "%s:%d:warning: ", prop->file->name, prop->lineno);
yann@1
    36
	vfprintf(stderr, fmt, ap);
yann@1
    37
	fprintf(stderr, "\n");
yann@1
    38
	va_end(ap);
yann@1
    39
}
yann@1
    40
yann@2448
    41
void _menu_init(void)
yann@1
    42
{
yann@1
    43
	current_entry = current_menu = &rootmenu;
yann@1
    44
	last_entry_ptr = &rootmenu.list;
yann@1
    45
}
yann@1
    46
yann@1
    47
void menu_add_entry(struct symbol *sym)
yann@1
    48
{
yann@1
    49
	struct menu *menu;
yann@1
    50
yann@1
    51
	menu = malloc(sizeof(*menu));
yann@1
    52
	memset(menu, 0, sizeof(*menu));
yann@1
    53
	menu->sym = sym;
yann@1
    54
	menu->parent = current_menu;
yann@1
    55
	menu->file = current_file;
yann@1
    56
	menu->lineno = zconf_lineno();
yann@1
    57
yann@1
    58
	*last_entry_ptr = menu;
yann@1
    59
	last_entry_ptr = &menu->next;
yann@1
    60
	current_entry = menu;
yann@2448
    61
	if (sym)
yann@2448
    62
		menu_add_symbol(P_SYMBOL, sym, NULL);
yann@1
    63
}
yann@1
    64
yann@1
    65
void menu_end_entry(void)
yann@1
    66
{
yann@1
    67
}
yann@1
    68
yann@1
    69
struct menu *menu_add_menu(void)
yann@1
    70
{
yann@1
    71
	menu_end_entry();
yann@1
    72
	last_entry_ptr = &current_entry->list;
yann@1
    73
	return current_menu = current_entry;
yann@1
    74
}
yann@1
    75
yann@1
    76
void menu_end_menu(void)
yann@1
    77
{
yann@1
    78
	last_entry_ptr = &current_menu->next;
yann@1
    79
	current_menu = current_menu->parent;
yann@1
    80
}
yann@1
    81
yann@2448
    82
static struct expr *menu_check_dep(struct expr *e)
yann@1
    83
{
yann@1
    84
	if (!e)
yann@1
    85
		return e;
yann@1
    86
yann@1
    87
	switch (e->type) {
yann@1
    88
	case E_NOT:
yann@1
    89
		e->left.expr = menu_check_dep(e->left.expr);
yann@1
    90
		break;
yann@1
    91
	case E_OR:
yann@1
    92
	case E_AND:
yann@1
    93
		e->left.expr = menu_check_dep(e->left.expr);
yann@1
    94
		e->right.expr = menu_check_dep(e->right.expr);
yann@1
    95
		break;
yann@1
    96
	case E_SYMBOL:
yann@1
    97
		/* change 'm' into 'm' && MODULES */
yann@1
    98
		if (e->left.sym == &symbol_mod)
yann@1
    99
			return expr_alloc_and(e, expr_alloc_symbol(modules_sym));
yann@1
   100
		break;
yann@1
   101
	default:
yann@1
   102
		break;
yann@1
   103
	}
yann@1
   104
	return e;
yann@1
   105
}
yann@1
   106
yann@1
   107
void menu_add_dep(struct expr *dep)
yann@1
   108
{
yann@1
   109
	current_entry->dep = expr_alloc_and(current_entry->dep, menu_check_dep(dep));
yann@1
   110
}
yann@1
   111
yann@1
   112
void menu_set_type(int type)
yann@1
   113
{
yann@1
   114
	struct symbol *sym = current_entry->sym;
yann@1
   115
yann@1
   116
	if (sym->type == type)
yann@1
   117
		return;
yann@1
   118
	if (sym->type == S_UNKNOWN) {
yann@1
   119
		sym->type = type;
yann@1
   120
		return;
yann@1
   121
	}
yann@1
   122
	menu_warn(current_entry, "type of '%s' redefined from '%s' to '%s'",
yann@1
   123
	    sym->name ? sym->name : "<choice>",
yann@1
   124
	    sym_type_name(sym->type), sym_type_name(type));
yann@1
   125
}
yann@1
   126
yann@1
   127
struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep)
yann@1
   128
{
yann@1
   129
	struct property *prop = prop_alloc(type, current_entry->sym);
yann@1
   130
yann@1
   131
	prop->menu = current_entry;
yann@1
   132
	prop->expr = expr;
yann@1
   133
	prop->visible.expr = menu_check_dep(dep);
yann@1
   134
yann@1
   135
	if (prompt) {
yann@2448
   136
		if (isspace(*prompt)) {
yann@2448
   137
			prop_warn(prop, "leading whitespace ignored");
yann@1
   138
			while (isspace(*prompt))
yann@1
   139
				prompt++;
yann@1
   140
		}
yann@2448
   141
		if (current_entry->prompt && current_entry != &rootmenu)
yann@1
   142
			prop_warn(prop, "prompt redefined");
yann@2448
   143
yann@2448
   144
		/* Apply all upper menus' visibilities to actual prompts. */
yann@2448
   145
		if(type == P_PROMPT) {
yann@2448
   146
			struct menu *menu = current_entry;
yann@2448
   147
yann@2448
   148
			while ((menu = menu->parent) != NULL) {
yann@2448
   149
				if (!menu->visibility)
yann@2448
   150
					continue;
yann@2448
   151
				prop->visible.expr
yann@2448
   152
					= expr_alloc_and(prop->visible.expr,
yann@2448
   153
							 menu->visibility);
yann@2448
   154
			}
yann@2448
   155
		}
yann@2448
   156
yann@1
   157
		current_entry->prompt = prop;
yann@1
   158
	}
yann@1
   159
	prop->text = prompt;
yann@1
   160
yann@1
   161
	return prop;
yann@1
   162
}
yann@1
   163
yann@1
   164
struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep)
yann@1
   165
{
yann@1
   166
	return menu_add_prop(type, prompt, NULL, dep);
yann@1
   167
}
yann@1
   168
yann@2448
   169
void menu_add_visibility(struct expr *expr)
yann@2448
   170
{
yann@2448
   171
	current_entry->visibility = expr_alloc_and(current_entry->visibility,
yann@2448
   172
	    expr);
yann@2448
   173
}
yann@2448
   174
yann@1
   175
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
yann@1
   176
{
yann@1
   177
	menu_add_prop(type, NULL, expr, dep);
yann@1
   178
}
yann@1
   179
yann@1
   180
void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
yann@1
   181
{
yann@1
   182
	menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
yann@1
   183
}
yann@1
   184
yann@1
   185
void menu_add_option(int token, char *arg)
yann@1
   186
{
yann@1
   187
	struct property *prop;
yann@1
   188
yann@1
   189
	switch (token) {
yann@1
   190
	case T_OPT_MODULES:
yann@1
   191
		prop = prop_alloc(P_DEFAULT, modules_sym);
yann@1
   192
		prop->expr = expr_alloc_symbol(current_entry->sym);
yann@1
   193
		break;
yann@1
   194
	case T_OPT_DEFCONFIG_LIST:
yann@1
   195
		if (!sym_defconfig_list)
yann@1
   196
			sym_defconfig_list = current_entry->sym;
yann@1
   197
		else if (sym_defconfig_list != current_entry->sym)
yann@1
   198
			zconf_error("trying to redefine defconfig symbol");
yann@1
   199
		break;
yann@943
   200
	case T_OPT_ENV:
yann@943
   201
		prop_add_env(arg);
yann@943
   202
		break;
yann@1
   203
	}
yann@1
   204
}
yann@1
   205
yann@2448
   206
static int menu_validate_number(struct symbol *sym, struct symbol *sym2)
yann@1
   207
{
yann@1
   208
	return sym2->type == S_INT || sym2->type == S_HEX ||
yann@1
   209
	       (sym2->type == S_UNKNOWN && sym_string_valid(sym, sym2->name));
yann@1
   210
}
yann@1
   211
yann@2448
   212
static void sym_check_prop(struct symbol *sym)
yann@1
   213
{
yann@1
   214
	struct property *prop;
yann@1
   215
	struct symbol *sym2;
yann@1
   216
	for (prop = sym->prop; prop; prop = prop->next) {
yann@1
   217
		switch (prop->type) {
yann@1
   218
		case P_DEFAULT:
yann@1
   219
			if ((sym->type == S_STRING || sym->type == S_INT || sym->type == S_HEX) &&
yann@1
   220
			    prop->expr->type != E_SYMBOL)
yann@1
   221
				prop_warn(prop,
yann@2448
   222
				    "default for config symbol '%s'"
yann@1
   223
				    " must be a single symbol", sym->name);
yann@2448
   224
			if (prop->expr->type != E_SYMBOL)
yann@2448
   225
				break;
yann@2448
   226
			sym2 = prop_get_symbol(prop);
yann@2448
   227
			if (sym->type == S_HEX || sym->type == S_INT) {
yann@2448
   228
				if (!menu_validate_number(sym, sym2))
yann@2448
   229
					prop_warn(prop,
yann@2448
   230
					    "'%s': number is invalid",
yann@2448
   231
					    sym->name);
yann@2448
   232
			}
yann@1
   233
			break;
yann@1
   234
		case P_SELECT:
yann@1
   235
			sym2 = prop_get_symbol(prop);
yann@1
   236
			if (sym->type != S_BOOLEAN && sym->type != S_TRISTATE)
yann@1
   237
				prop_warn(prop,
yann@1
   238
				    "config symbol '%s' uses select, but is "
yann@1
   239
				    "not boolean or tristate", sym->name);
yann@943
   240
			else if (sym2->type != S_UNKNOWN &&
yann@943
   241
			         sym2->type != S_BOOLEAN &&
yann@943
   242
			         sym2->type != S_TRISTATE)
yann@1
   243
				prop_warn(prop,
yann@1
   244
				    "'%s' has wrong type. 'select' only "
yann@1
   245
				    "accept arguments of boolean and "
yann@1
   246
				    "tristate type", sym2->name);
yann@1
   247
			break;
yann@1
   248
		case P_RANGE:
yann@1
   249
			if (sym->type != S_INT && sym->type != S_HEX)
yann@1
   250
				prop_warn(prop, "range is only allowed "
yann@1
   251
				                "for int or hex symbols");
yann@2448
   252
			if (!menu_validate_number(sym, prop->expr->left.sym) ||
yann@2448
   253
			    !menu_validate_number(sym, prop->expr->right.sym))
yann@1
   254
				prop_warn(prop, "range is invalid");
yann@1
   255
			break;
yann@1
   256
		default:
yann@1
   257
			;
yann@1
   258
		}
yann@1
   259
	}
yann@1
   260
}
yann@1
   261
yann@1
   262
void menu_finalize(struct menu *parent)
yann@1
   263
{
yann@1
   264
	struct menu *menu, *last_menu;
yann@1
   265
	struct symbol *sym;
yann@1
   266
	struct property *prop;
yann@1
   267
	struct expr *parentdep, *basedep, *dep, *dep2, **ep;
yann@1
   268
yann@1
   269
	sym = parent->sym;
yann@1
   270
	if (parent->list) {
yann@1
   271
		if (sym && sym_is_choice(sym)) {
yann@943
   272
			if (sym->type == S_UNKNOWN) {
yann@943
   273
				/* find the first choice value to find out choice type */
yann@943
   274
				current_entry = parent;
yann@943
   275
				for (menu = parent->list; menu; menu = menu->next) {
yann@943
   276
					if (menu->sym && menu->sym->type != S_UNKNOWN) {
yann@943
   277
						menu_set_type(menu->sym->type);
yann@943
   278
						break;
yann@943
   279
					}
yann@943
   280
				}
yann@943
   281
			}
yann@943
   282
			/* set the type of the remaining choice values */
yann@1
   283
			for (menu = parent->list; menu; menu = menu->next) {
yann@943
   284
				current_entry = menu;
yann@943
   285
				if (menu->sym && menu->sym->type == S_UNKNOWN)
yann@1
   286
					menu_set_type(sym->type);
yann@1
   287
			}
yann@1
   288
			parentdep = expr_alloc_symbol(sym);
yann@1
   289
		} else if (parent->prompt)
yann@1
   290
			parentdep = parent->prompt->visible.expr;
yann@1
   291
		else
yann@1
   292
			parentdep = parent->dep;
yann@1
   293
yann@1
   294
		for (menu = parent->list; menu; menu = menu->next) {
yann@1
   295
			basedep = expr_transform(menu->dep);
yann@1
   296
			basedep = expr_alloc_and(expr_copy(parentdep), basedep);
yann@1
   297
			basedep = expr_eliminate_dups(basedep);
yann@1
   298
			menu->dep = basedep;
yann@1
   299
			if (menu->sym)
yann@1
   300
				prop = menu->sym->prop;
yann@1
   301
			else
yann@1
   302
				prop = menu->prompt;
yann@1
   303
			for (; prop; prop = prop->next) {
yann@1
   304
				if (prop->menu != menu)
yann@1
   305
					continue;
yann@1
   306
				dep = expr_transform(prop->visible.expr);
yann@1
   307
				dep = expr_alloc_and(expr_copy(basedep), dep);
yann@1
   308
				dep = expr_eliminate_dups(dep);
yann@1
   309
				if (menu->sym && menu->sym->type != S_TRISTATE)
yann@1
   310
					dep = expr_trans_bool(dep);
yann@1
   311
				prop->visible.expr = dep;
yann@1
   312
				if (prop->type == P_SELECT) {
yann@1
   313
					struct symbol *es = prop_get_symbol(prop);
yann@1
   314
					es->rev_dep.expr = expr_alloc_or(es->rev_dep.expr,
yann@1
   315
							expr_alloc_and(expr_alloc_symbol(menu->sym), expr_copy(dep)));
yann@1
   316
				}
yann@1
   317
			}
yann@1
   318
		}
yann@1
   319
		for (menu = parent->list; menu; menu = menu->next)
yann@1
   320
			menu_finalize(menu);
yann@1
   321
	} else if (sym) {
yann@1
   322
		basedep = parent->prompt ? parent->prompt->visible.expr : NULL;
yann@1
   323
		basedep = expr_trans_compare(basedep, E_UNEQUAL, &symbol_no);
yann@1
   324
		basedep = expr_eliminate_dups(expr_transform(basedep));
yann@1
   325
		last_menu = NULL;
yann@1
   326
		for (menu = parent->next; menu; menu = menu->next) {
yann@1
   327
			dep = menu->prompt ? menu->prompt->visible.expr : menu->dep;
yann@1
   328
			if (!expr_contains_symbol(dep, sym))
yann@1
   329
				break;
yann@1
   330
			if (expr_depends_symbol(dep, sym))
yann@1
   331
				goto next;
yann@1
   332
			dep = expr_trans_compare(dep, E_UNEQUAL, &symbol_no);
yann@1
   333
			dep = expr_eliminate_dups(expr_transform(dep));
yann@1
   334
			dep2 = expr_copy(basedep);
yann@1
   335
			expr_eliminate_eq(&dep, &dep2);
yann@1
   336
			expr_free(dep);
yann@1
   337
			if (!expr_is_yes(dep2)) {
yann@1
   338
				expr_free(dep2);
yann@1
   339
				break;
yann@1
   340
			}
yann@1
   341
			expr_free(dep2);
yann@1
   342
		next:
yann@1
   343
			menu_finalize(menu);
yann@1
   344
			menu->parent = parent;
yann@1
   345
			last_menu = menu;
yann@1
   346
		}
yann@1
   347
		if (last_menu) {
yann@1
   348
			parent->list = parent->next;
yann@1
   349
			parent->next = last_menu->next;
yann@1
   350
			last_menu->next = NULL;
yann@1
   351
		}
yann@2448
   352
yann@2448
   353
		sym->dir_dep.expr = parent->dep;
yann@1
   354
	}
yann@1
   355
	for (menu = parent->list; menu; menu = menu->next) {
yann@943
   356
		if (sym && sym_is_choice(sym) &&
yann@943
   357
		    menu->sym && !sym_is_choice_value(menu->sym)) {
yann@943
   358
			current_entry = menu;
yann@1
   359
			menu->sym->flags |= SYMBOL_CHOICEVAL;
yann@1
   360
			if (!menu->prompt)
yann@1
   361
				menu_warn(menu, "choice value must have a prompt");
yann@1
   362
			for (prop = menu->sym->prop; prop; prop = prop->next) {
yann@1
   363
				if (prop->type == P_DEFAULT)
yann@1
   364
					prop_warn(prop, "defaults for choice "
yann@943
   365
						  "values not supported");
yann@943
   366
				if (prop->menu == menu)
yann@943
   367
					continue;
yann@943
   368
				if (prop->type == P_PROMPT &&
yann@943
   369
				    prop->menu->parent->sym != sym)
yann@943
   370
					prop_warn(prop, "choice value used outside its choice group");
yann@1
   371
			}
yann@943
   372
			/* Non-tristate choice values of tristate choices must
yann@943
   373
			 * depend on the choice being set to Y. The choice
yann@943
   374
			 * values' dependencies were propagated to their
yann@943
   375
			 * properties above, so the change here must be re-
yann@943
   376
			 * propagated.
yann@943
   377
			 */
yann@943
   378
			if (sym->type == S_TRISTATE && menu->sym->type != S_TRISTATE) {
yann@943
   379
				basedep = expr_alloc_comp(E_EQUAL, sym, &symbol_yes);
yann@943
   380
				menu->dep = expr_alloc_and(basedep, menu->dep);
yann@943
   381
				for (prop = menu->sym->prop; prop; prop = prop->next) {
yann@943
   382
					if (prop->menu != menu)
yann@943
   383
						continue;
yann@943
   384
					prop->visible.expr = expr_alloc_and(expr_copy(basedep),
yann@943
   385
									    prop->visible.expr);
yann@943
   386
				}
yann@943
   387
			}
yann@1
   388
			menu_add_symbol(P_CHOICE, sym, NULL);
yann@1
   389
			prop = sym_get_choice_prop(sym);
yann@1
   390
			for (ep = &prop->expr; *ep; ep = &(*ep)->left.expr)
yann@1
   391
				;
yann@943
   392
			*ep = expr_alloc_one(E_LIST, NULL);
yann@1
   393
			(*ep)->right.sym = menu->sym;
yann@1
   394
		}
yann@1
   395
		if (menu->list && (!menu->prompt || !menu->prompt->text)) {
yann@1
   396
			for (last_menu = menu->list; ; last_menu = last_menu->next) {
yann@1
   397
				last_menu->parent = parent;
yann@1
   398
				if (!last_menu->next)
yann@1
   399
					break;
yann@1
   400
			}
yann@1
   401
			last_menu->next = menu->next;
yann@1
   402
			menu->next = menu->list;
yann@1
   403
			menu->list = NULL;
yann@1
   404
		}
yann@1
   405
	}
yann@1
   406
yann@1
   407
	if (sym && !(sym->flags & SYMBOL_WARNED)) {
yann@1
   408
		if (sym->type == S_UNKNOWN)
yann@1
   409
			menu_warn(parent, "config symbol defined without type");
yann@1
   410
yann@1
   411
		if (sym_is_choice(sym) && !parent->prompt)
yann@1
   412
			menu_warn(parent, "choice must have a prompt");
yann@1
   413
yann@1
   414
		/* Check properties connected to this symbol */
yann@1
   415
		sym_check_prop(sym);
yann@1
   416
		sym->flags |= SYMBOL_WARNED;
yann@1
   417
	}
yann@1
   418
yann@1
   419
	if (sym && !sym_is_optional(sym) && parent->prompt) {
yann@1
   420
		sym->rev_dep.expr = expr_alloc_or(sym->rev_dep.expr,
yann@1
   421
				expr_alloc_and(parent->prompt->visible.expr,
yann@1
   422
					expr_alloc_symbol(&symbol_mod)));
yann@1
   423
	}
yann@1
   424
}
yann@1
   425
yann@2448
   426
bool menu_has_prompt(struct menu *menu)
yann@2448
   427
{
yann@2448
   428
	if (!menu->prompt)
yann@2448
   429
		return false;
yann@2448
   430
	return true;
yann@2448
   431
}
yann@2448
   432
yann@1
   433
bool menu_is_visible(struct menu *menu)
yann@1
   434
{
yann@1
   435
	struct menu *child;
yann@1
   436
	struct symbol *sym;
yann@1
   437
	tristate visible;
yann@1
   438
yann@1
   439
	if (!menu->prompt)
yann@1
   440
		return false;
yann@2448
   441
yann@2448
   442
	if (menu->visibility) {
yann@2448
   443
		if (expr_calc_value(menu->visibility) == no)
yann@2448
   444
			return no;
yann@2448
   445
	}
yann@2448
   446
yann@1
   447
	sym = menu->sym;
yann@1
   448
	if (sym) {
yann@1
   449
		sym_calc_value(sym);
yann@1
   450
		visible = menu->prompt->visible.tri;
yann@1
   451
	} else
yann@1
   452
		visible = menu->prompt->visible.tri = expr_calc_value(menu->prompt->visible.expr);
yann@1
   453
yann@1
   454
	if (visible != no)
yann@1
   455
		return true;
yann@2448
   456
yann@1
   457
	if (!sym || sym_get_tristate_value(menu->sym) == no)
yann@1
   458
		return false;
yann@1
   459
yann@2448
   460
	for (child = menu->list; child; child = child->next) {
yann@2448
   461
		if (menu_is_visible(child)) {
yann@2448
   462
			if (sym)
yann@2448
   463
				sym->flags |= SYMBOL_DEF_USER;
yann@1
   464
			return true;
yann@2448
   465
		}
yann@2448
   466
	}
yann@2448
   467
yann@1
   468
	return false;
yann@1
   469
}
yann@1
   470
yann@1
   471
const char *menu_get_prompt(struct menu *menu)
yann@1
   472
{
yann@1
   473
	if (menu->prompt)
yann@943
   474
		return menu->prompt->text;
yann@1
   475
	else if (menu->sym)
yann@943
   476
		return menu->sym->name;
yann@1
   477
	return NULL;
yann@1
   478
}
yann@1
   479
yann@1
   480
struct menu *menu_get_root_menu(struct menu *menu)
yann@1
   481
{
yann@1
   482
	return &rootmenu;
yann@1
   483
}
yann@1
   484
yann@1
   485
struct menu *menu_get_parent_menu(struct menu *menu)
yann@1
   486
{
yann@1
   487
	enum prop_type type;
yann@1
   488
yann@1
   489
	for (; menu != &rootmenu; menu = menu->parent) {
yann@1
   490
		type = menu->prompt ? menu->prompt->type : 0;
yann@1
   491
		if (type == P_MENU)
yann@1
   492
			break;
yann@1
   493
	}
yann@1
   494
	return menu;
yann@1
   495
}
yann@1
   496
yann@943
   497
bool menu_has_help(struct menu *menu)
yann@943
   498
{
yann@943
   499
	return menu->help != NULL;
yann@943
   500
}
yann@943
   501
yann@943
   502
const char *menu_get_help(struct menu *menu)
yann@943
   503
{
yann@943
   504
	if (menu->help)
yann@943
   505
		return menu->help;
yann@943
   506
	else
yann@943
   507
		return "";
yann@943
   508
}
yann@2448
   509
yann@2448
   510
static void get_prompt_str(struct gstr *r, struct property *prop)
yann@2448
   511
{
yann@2448
   512
	int i, j;
yann@2448
   513
	struct menu *submenu[8], *menu;
yann@2448
   514
yann@2448
   515
	str_printf(r, _("Prompt: %s\n"), _(prop->text));
yann@2448
   516
	str_printf(r, _("  Defined at %s:%d\n"), prop->menu->file->name,
yann@2448
   517
		prop->menu->lineno);
yann@2448
   518
	if (!expr_is_yes(prop->visible.expr)) {
yann@2448
   519
		str_append(r, _("  Depends on: "));
yann@2448
   520
		expr_gstr_print(prop->visible.expr, r);
yann@2448
   521
		str_append(r, "\n");
yann@2448
   522
	}
yann@2448
   523
	menu = prop->menu->parent;
yann@2448
   524
	for (i = 0; menu != &rootmenu && i < 8; menu = menu->parent)
yann@2448
   525
		submenu[i++] = menu;
yann@2448
   526
	if (i > 0) {
yann@2448
   527
		str_printf(r, _("  Location:\n"));
yann@2448
   528
		for (j = 4; --i >= 0; j += 2) {
yann@2448
   529
			menu = submenu[i];
yann@2448
   530
			str_printf(r, "%*c-> %s", j, ' ', _(menu_get_prompt(menu)));
yann@2448
   531
			if (menu->sym) {
yann@2448
   532
				str_printf(r, " (%s [=%s])", menu->sym->name ?
yann@2448
   533
					menu->sym->name : _("<choice>"),
yann@2448
   534
					sym_get_string_value(menu->sym));
yann@2448
   535
			}
yann@2448
   536
			str_append(r, "\n");
yann@2448
   537
		}
yann@2448
   538
	}
yann@2448
   539
}
yann@2448
   540
yann@2448
   541
void get_symbol_str(struct gstr *r, struct symbol *sym)
yann@2448
   542
{
yann@2448
   543
	bool hit;
yann@2448
   544
	struct property *prop;
yann@2448
   545
yann@2448
   546
	if (sym && sym->name) {
yann@2448
   547
		str_printf(r, "Symbol: %s [=%s]\n", sym->name,
yann@2448
   548
			   sym_get_string_value(sym));
yann@2448
   549
		str_printf(r, "Type  : %s\n", sym_type_name(sym->type));
yann@2448
   550
		if (sym->type == S_INT || sym->type == S_HEX) {
yann@2448
   551
			prop = sym_get_range_prop(sym);
yann@2448
   552
			if (prop) {
yann@2448
   553
				str_printf(r, "Range : ");
yann@2448
   554
				expr_gstr_print(prop->expr, r);
yann@2448
   555
				str_append(r, "\n");
yann@2448
   556
			}
yann@2448
   557
		}
yann@2448
   558
	}
yann@2448
   559
	for_all_prompts(sym, prop)
yann@2448
   560
		get_prompt_str(r, prop);
yann@2448
   561
	hit = false;
yann@2448
   562
	for_all_properties(sym, prop, P_SELECT) {
yann@2448
   563
		if (!hit) {
yann@2448
   564
			str_append(r, "  Selects: ");
yann@2448
   565
			hit = true;
yann@2448
   566
		} else
yann@2448
   567
			str_printf(r, " && ");
yann@2448
   568
		expr_gstr_print(prop->expr, r);
yann@2448
   569
	}
yann@2448
   570
	if (hit)
yann@2448
   571
		str_append(r, "\n");
yann@2448
   572
	if (sym->rev_dep.expr) {
yann@2448
   573
		str_append(r, _("  Selected by: "));
yann@2448
   574
		expr_gstr_print(sym->rev_dep.expr, r);
yann@2448
   575
		str_append(r, "\n");
yann@2448
   576
	}
yann@2448
   577
	str_append(r, "\n\n");
yann@2448
   578
}
yann@2448
   579
yann@2448
   580
struct gstr get_relations_str(struct symbol **sym_arr)
yann@2448
   581
{
yann@2448
   582
	struct symbol *sym;
yann@2448
   583
	struct gstr res = str_new();
yann@2448
   584
	int i;
yann@2448
   585
yann@2448
   586
	for (i = 0; sym_arr && (sym = sym_arr[i]); i++)
yann@2448
   587
		get_symbol_str(&res, sym);
yann@2448
   588
	if (!i)
yann@2448
   589
		str_append(&res, _("No matches found.\n"));
yann@2448
   590
	return res;
yann@2448
   591
}
yann@2448
   592
yann@2448
   593
yann@2448
   594
void menu_get_ext_help(struct menu *menu, struct gstr *help)
yann@2448
   595
{
yann@2448
   596
	struct symbol *sym = menu->sym;
yann@2448
   597
yann@2448
   598
	if (menu_has_help(menu)) {
yann@2448
   599
		if (sym->name) {
yann@2448
   600
			str_printf(help, "%s%s:\n\n", CONFIG_, sym->name);
yann@2448
   601
			str_append(help, _(menu_get_help(menu)));
yann@2448
   602
			str_append(help, "\n");
yann@2448
   603
		}
yann@2448
   604
	} else {
yann@2448
   605
		str_append(help, nohelp_text);
yann@2448
   606
	}
yann@2448
   607
	if (sym)
yann@2448
   608
		get_symbol_str(help, sym);
yann@2448
   609
}