kconfig: tristate choices with mixed tristate and boolean values
[sfrench/cifs-2.6.git] / scripts / kconfig / menu.c
index 0fce20cb7f3c38a931d9f78c14144d2272b9e809..7bfa181d6ed6f685d45d8a68f301cd75810e3369 100644 (file)
@@ -114,7 +114,7 @@ void menu_set_type(int type)
                sym->type = type;
                return;
        }
-       menu_warn(current_entry, "type of '%s' redefined from '%s' to '%s'\n",
+       menu_warn(current_entry, "type of '%s' redefined from '%s' to '%s'",
            sym->name ? sym->name : "<choice>",
            sym_type_name(sym->type), sym_type_name(type));
 }
@@ -124,15 +124,20 @@ struct property *menu_add_prop(enum prop_type type, char *prompt, struct expr *e
        struct property *prop = prop_alloc(type, current_entry->sym);
 
        prop->menu = current_entry;
-       prop->text = prompt;
        prop->expr = expr;
        prop->visible.expr = menu_check_dep(dep);
 
        if (prompt) {
+               if (isspace(*prompt)) {
+                       prop_warn(prop, "leading whitespace ignored");
+                       while (isspace(*prompt))
+                               prompt++;
+               }
                if (current_entry->prompt)
-                       menu_warn(current_entry, "prompt redefined\n");
+                       prop_warn(prop, "prompt redefined");
                current_entry->prompt = prop;
        }
+       prop->text = prompt;
 
        return prop;
 }
@@ -152,6 +157,24 @@ void menu_add_symbol(enum prop_type type, struct symbol *sym, struct expr *dep)
        menu_add_prop(type, NULL, expr_alloc_symbol(sym), dep);
 }
 
+void menu_add_option(int token, char *arg)
+{
+       struct property *prop;
+
+       switch (token) {
+       case T_OPT_MODULES:
+               prop = prop_alloc(P_DEFAULT, modules_sym);
+               prop->expr = expr_alloc_symbol(current_entry->sym);
+               break;
+       case T_OPT_DEFCONFIG_LIST:
+               if (!sym_defconfig_list)
+                       sym_defconfig_list = current_entry->sym;
+               else if (sym_defconfig_list != current_entry->sym)
+                       zconf_error("trying to redefine defconfig symbol");
+               break;
+       }
+}
+
 static int menu_range_valid_sym(struct symbol *sym, struct symbol *sym2)
 {
        return sym2->type == S_INT || sym2->type == S_HEX ||
@@ -180,7 +203,7 @@ void sym_check_prop(struct symbol *sym)
                        else if (sym2->type == S_UNKNOWN)
                                prop_warn(prop,
                                    "'select' used by config symbol '%s' "
-                                   "refer to undefined symbol '%s'",
+                                   "refers to undefined symbol '%s'",
                                    sym->name, sym2->name);
                        else if (sym2->type != S_BOOLEAN && sym2->type != S_TRISTATE)
                                prop_warn(prop,
@@ -212,16 +235,23 @@ void menu_finalize(struct menu *parent)
        sym = parent->sym;
        if (parent->list) {
                if (sym && sym_is_choice(sym)) {
-                       /* find the first choice value and find out choice type */
+                       /* find out choice type */
+                       enum symbol_type type = S_UNKNOWN;
+
                        for (menu = parent->list; menu; menu = menu->next) {
-                               if (menu->sym) {
-                                       current_entry = parent;
-                                       menu_set_type(menu->sym->type);
-                                       current_entry = menu;
-                                       menu_set_type(sym->type);
-                                       break;
+                               if (menu->sym && menu->sym->type != S_UNKNOWN) {
+                                       if (type == S_UNKNOWN)
+                                               type = menu->sym->type;
+                                       if (type != S_BOOLEAN)
+                                               break;
+                                       if (menu->sym->type == S_TRISTATE) {
+                                               type = S_TRISTATE;
+                                               break;
+                                       }
                                }
                        }
+                       current_entry = parent;
+                       menu_set_type(type);
                        parentdep = expr_alloc_symbol(sym);
                } else if (parent->prompt)
                        parentdep = parent->prompt->visible.expr;
@@ -230,7 +260,16 @@ void menu_finalize(struct menu *parent)
 
                for (menu = parent->list; menu; menu = menu->next) {
                        basedep = expr_transform(menu->dep);
-                       basedep = expr_alloc_and(expr_copy(parentdep), basedep);
+                       dep = parentdep;
+                       if (sym && sym_is_choice(sym) && menu->sym) {
+                               enum symbol_type type = menu->sym->type;
+
+                               if (type == S_UNKNOWN)
+                                       type = sym->type;
+                            if (type != S_TRISTATE)
+                                       dep = expr_alloc_comp(E_EQUAL, sym, &symbol_yes);
+                       }
+                       basedep = expr_alloc_and(expr_copy(dep), basedep);
                        basedep = expr_eliminate_dups(basedep);
                        menu->dep = basedep;
                        if (menu->sym)
@@ -303,7 +342,8 @@ void menu_finalize(struct menu *parent)
                                            "values not supported");
                        }
                        current_entry = menu;
-                       menu_set_type(sym->type);
+                       if (menu->sym->type == S_UNKNOWN)
+                               menu_set_type(sym->type);
                        menu_add_symbol(P_CHOICE, sym, NULL);
                        prop = sym_get_choice_prop(sym);
                        for (ep = &prop->expr; *ep; ep = &(*ep)->left.expr)
@@ -325,11 +365,10 @@ void menu_finalize(struct menu *parent)
 
        if (sym && !(sym->flags & SYMBOL_WARNED)) {
                if (sym->type == S_UNKNOWN)
-                       menu_warn(parent, "config symbol defined "
-                           "without type\n");
+                       menu_warn(parent, "config symbol defined without type");
 
                if (sym_is_choice(sym) && !parent->prompt)
-                       menu_warn(parent, "choice must have a prompt\n");
+                       menu_warn(parent, "choice must have a prompt");
 
                /* Check properties connected to this symbol */
                sym_check_prop(sym);
@@ -395,3 +434,15 @@ struct menu *menu_get_parent_menu(struct menu *menu)
        return menu;
 }
 
+bool menu_has_help(struct menu *menu)
+{
+       return menu->help != NULL;
+}
+
+const char *menu_get_help(struct menu *menu)
+{
+       if (menu->help)
+               return menu->help;
+       else
+               return "";
+}