kconfig: fix default value for choice input
[pandora-kernel.git] / scripts / kconfig / conf.c
index bc20cab..b86c64f 100644 (file)
@@ -63,6 +63,20 @@ static void check_stdin(void)
        }
 }
 
+static char *fgets_check_stream(char *s, int size, FILE *stream)
+{
+       char *ret = fgets(s, size, stream);
+
+       if (ret == NULL && feof(stream)) {
+               printf(_("aborted!\n\n"));
+               printf(_("Console input is closed. "));
+               printf(_("Run 'make oldconfig' to update configuration.\n\n"));
+               exit(1);
+       }
+
+       return ret;
+}
+
 static void conf_askvalue(struct symbol *sym, const char *def)
 {
        enum symbol_type type = sym_get_type(sym);
@@ -82,6 +96,15 @@ static void conf_askvalue(struct symbol *sym, const char *def)
        }
 
        switch (input_mode) {
+       case set_no:
+       case set_mod:
+       case set_yes:
+       case set_random:
+               if (sym_has_value(sym)) {
+                       printf("%s\n", def);
+                       return;
+               }
+               break;
        case ask_new:
        case ask_silent:
                if (sym_has_value(sym)) {
@@ -91,7 +114,7 @@ static void conf_askvalue(struct symbol *sym, const char *def)
                check_stdin();
        case ask_all:
                fflush(stdout);
-               fgets(line, 128, stdin);
+               fgets_check_stream(line, 128, stdin);
                return;
        case set_default:
                printf("%s\n", def);
@@ -305,8 +328,7 @@ static int conf_choice(struct menu *menu)
                printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
                def_sym = sym_get_choice_value(sym);
                cnt = def = 0;
-               line[0] = '0';
-               line[1] = 0;
+               line[0] = 0;
                for (child = menu->list; child; child = child->next) {
                        if (!menu_is_visible(child))
                                continue;
@@ -347,7 +369,7 @@ static int conf_choice(struct menu *menu)
                        check_stdin();
                case ask_all:
                        fflush(stdout);
-                       fgets(line, 128, stdin);
+                       fgets_check_stream(line, 128, stdin);
                        strip(line);
                        if (line[0] == '?') {
                                printf("\n%s\n", menu->sym->help ?
@@ -467,15 +489,14 @@ static void check_conf(struct menu *menu)
                return;
 
        sym = menu->sym;
-       if (sym) {
-               if (sym_is_changable(sym) && !sym_has_value(sym)) {
+       if (sym && !sym_has_value(sym)) {
+               if (sym_is_changable(sym) ||
+                   (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
                        if (!conf_cnt++)
                                printf(_("*\n* Restart config...\n*\n"));
                        rootEntry = menu_get_parent_menu(menu);
                        conf(rootEntry);
                }
-               if (sym_is_choice(sym) && sym_get_tristate_value(sym) != mod)
-                       return;
        }
 
        for (child = menu->list; child; child = child->next)
@@ -559,6 +580,27 @@ int main(int ac, char **av)
        case ask_new:
                conf_read(NULL);
                break;
+       case set_no:
+       case set_mod:
+       case set_yes:
+       case set_random:
+               name = getenv("KCONFIG_ALLCONFIG");
+               if (name && !stat(name, &tmpstat)) {
+                       conf_read_simple(name);
+                       break;
+               }
+               switch (input_mode) {
+               case set_no:     name = "allno.config"; break;
+               case set_mod:    name = "allmod.config"; break;
+               case set_yes:    name = "allyes.config"; break;
+               case set_random: name = "allrandom.config"; break;
+               default: break;
+               }
+               if (!stat(name, &tmpstat))
+                       conf_read_simple(name);
+               else if (!stat("all.config", &tmpstat))
+                       conf_read_simple("all.config");
+               break;
        default:
                break;
        }