Commit 86e187ff authored by Arnaud Lacombe's avatar Arnaud Lacombe Committed by Mauro Carvalho Chehab

kconfig: add an option to determine a menu's visibility

This option is aimed to add the possibility to control a menu's visibility
without adding dependency to the expression to all the submenu.
Signed-off-by: default avatarArnaud Lacombe <lacombar@gmail.com>
Acked-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
Tested-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent e53beacd
...@@ -164,6 +164,7 @@ struct menu { ...@@ -164,6 +164,7 @@ struct menu {
struct menu *list; struct menu *list;
struct symbol *sym; struct symbol *sym;
struct property *prompt; struct property *prompt;
struct expr *visibility;
struct expr *dep; struct expr *dep;
unsigned int flags; unsigned int flags;
char *help; char *help;
......
...@@ -107,6 +107,7 @@ void menu_end_menu(void); ...@@ -107,6 +107,7 @@ void menu_end_menu(void);
void menu_add_entry(struct symbol *sym); void menu_add_entry(struct symbol *sym);
void menu_end_entry(void); void menu_end_entry(void);
void menu_add_dep(struct expr *dep); void menu_add_dep(struct expr *dep);
void menu_add_visibility(struct expr *dep);
struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep); struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *expr, struct expr *dep);
struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep); struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr *dep);
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep); void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep);
......
...@@ -152,6 +152,12 @@ struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr ...@@ -152,6 +152,12 @@ struct property *menu_add_prompt(enum prop_type type, char *prompt, struct expr
return menu_add_prop(type, prompt, NULL, dep); return menu_add_prop(type, prompt, NULL, dep);
} }
void menu_add_visibility(struct expr *expr)
{
current_entry->visibility = expr_alloc_and(current_entry->visibility,
expr);
}
void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep) void menu_add_expr(enum prop_type type, struct expr *expr, struct expr *dep)
{ {
menu_add_prop(type, NULL, expr, dep); menu_add_prop(type, NULL, expr, dep);
...@@ -410,6 +416,11 @@ bool menu_is_visible(struct menu *menu) ...@@ -410,6 +416,11 @@ bool menu_is_visible(struct menu *menu)
if (!menu->prompt) if (!menu->prompt)
return false; return false;
if (menu->visibility) {
if (expr_calc_value(menu->visibility) == no)
return no;
}
sym = menu->sym; sym = menu->sym;
if (sym) { if (sym) {
sym_calc_value(sym); sym_calc_value(sym);
......
...@@ -38,6 +38,7 @@ hex, T_TYPE, TF_COMMAND, S_HEX ...@@ -38,6 +38,7 @@ hex, T_TYPE, TF_COMMAND, S_HEX
string, T_TYPE, TF_COMMAND, S_STRING string, T_TYPE, TF_COMMAND, S_STRING
select, T_SELECT, TF_COMMAND select, T_SELECT, TF_COMMAND
range, T_RANGE, TF_COMMAND range, T_RANGE, TF_COMMAND
visible, T_VISIBLE, TF_COMMAND
option, T_OPTION, TF_COMMAND option, T_OPTION, TF_COMMAND
on, T_ON, TF_PARAM on, T_ON, TF_PARAM
modules, T_OPT_MODULES, TF_OPTION modules, T_OPT_MODULES, TF_OPTION
......
...@@ -36,7 +36,7 @@ static struct menu *current_menu, *current_entry; ...@@ -36,7 +36,7 @@ static struct menu *current_menu, *current_entry;
#define YYERROR_VERBOSE #define YYERROR_VERBOSE
#endif #endif
%} %}
%expect 28 %expect 30
%union %union
{ {
...@@ -68,6 +68,7 @@ static struct menu *current_menu, *current_entry; ...@@ -68,6 +68,7 @@ static struct menu *current_menu, *current_entry;
%token <id>T_DEFAULT %token <id>T_DEFAULT
%token <id>T_SELECT %token <id>T_SELECT
%token <id>T_RANGE %token <id>T_RANGE
%token <id>T_VISIBLE
%token <id>T_OPTION %token <id>T_OPTION
%token <id>T_ON %token <id>T_ON
%token <string> T_WORD %token <string> T_WORD
...@@ -123,7 +124,7 @@ stmt_list: ...@@ -123,7 +124,7 @@ stmt_list:
; ;
option_name: option_name:
T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT T_DEPENDS | T_PROMPT | T_TYPE | T_SELECT | T_OPTIONAL | T_RANGE | T_DEFAULT | T_VISIBLE
; ;
common_stmt: common_stmt:
...@@ -359,7 +360,7 @@ menu: T_MENU prompt T_EOL ...@@ -359,7 +360,7 @@ menu: T_MENU prompt T_EOL
printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno());
}; };
menu_entry: menu depends_list menu_entry: menu visibility_list depends_list
{ {
$$ = menu_add_menu(); $$ = menu_add_menu();
}; };
...@@ -430,6 +431,19 @@ depends: T_DEPENDS T_ON expr T_EOL ...@@ -430,6 +431,19 @@ depends: T_DEPENDS T_ON expr T_EOL
printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno());
}; };
/* visibility option */
visibility_list:
/* empty */
| visibility_list visible
| visibility_list T_EOL
;
visible: T_VISIBLE if_expr
{
menu_add_visibility($2);
};
/* prompt statement */ /* prompt statement */
prompt_stmt_opt: prompt_stmt_opt:
...@@ -526,6 +540,7 @@ static const char *zconf_tokenname(int token) ...@@ -526,6 +540,7 @@ static const char *zconf_tokenname(int token)
case T_IF: return "if"; case T_IF: return "if";
case T_ENDIF: return "endif"; case T_ENDIF: return "endif";
case T_DEPENDS: return "depends"; case T_DEPENDS: return "depends";
case T_VISIBLE: return "visible";
} }
return "<token>"; return "<token>";
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment