]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - scripts/kconfig/conf.c
kconfig/conf: merge duplicate switch's case
[linux-2.6.git] / scripts / kconfig / conf.c
index ff5c914c0e5c2559d26a66bc43a86a0d53ed4a28..659326c3e89579b09f86077dbcbe5e1eb3a12d28 100644 (file)
@@ -27,8 +27,10 @@ enum input_mode {
        allnoconfig,
        allyesconfig,
        allmodconfig,
+       alldefconfig,
        randconfig,
        defconfig,
+       savedefconfig,
        listnewconfig,
        oldnoconfig,
 } input_mode = oldaskconfig;
@@ -106,7 +108,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)
                check_stdin();
        case oldaskconfig:
                fflush(stdout);
-               fgets(line, 128, stdin);
+               xfgets(line, 128, stdin);
                return 1;
        default:
                break;
@@ -304,7 +306,7 @@ static int conf_choice(struct menu *menu)
                        check_stdin();
                case oldaskconfig:
                        fflush(stdout);
-                       fgets(line, 128, stdin);
+                       xfgets(line, 128, stdin);
                        strip(line);
                        if (line[0] == '?') {
                                print_help(menu);
@@ -423,9 +425,9 @@ static void check_conf(struct menu *menu)
                    (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) {
                        if (input_mode == listnewconfig) {
                                if (sym->name && !sym_is_choice_value(sym)) {
-                                       printf("CONFIG_%s\n", sym->name);
+                                       printf("%s%s\n", CONFIG_, sym->name);
                                }
-                       } else {
+                       } else if (input_mode != oldnoconfig) {
                                if (!conf_cnt++)
                                        printf(_("*\n* Restart config...\n*\n"));
                                rootEntry = menu_get_parent_menu(menu);
@@ -443,9 +445,11 @@ static struct option long_opts[] = {
        {"oldconfig",       no_argument,       NULL, oldconfig},
        {"silentoldconfig", no_argument,       NULL, silentoldconfig},
        {"defconfig",       optional_argument, NULL, defconfig},
+       {"savedefconfig",   required_argument, NULL, savedefconfig},
        {"allnoconfig",     no_argument,       NULL, allnoconfig},
        {"allyesconfig",    no_argument,       NULL, allyesconfig},
        {"allmodconfig",    no_argument,       NULL, allmodconfig},
+       {"alldefconfig",    no_argument,       NULL, alldefconfig},
        {"randconfig",      no_argument,       NULL, randconfig},
        {"listnewconfig",   no_argument,       NULL, listnewconfig},
        {"oldnoconfig",     no_argument,       NULL, oldnoconfig},
@@ -462,13 +466,14 @@ int main(int ac, char **av)
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) {
+       while ((opt = getopt_long(ac, av, "", long_opts, NULL)) != -1) {
                input_mode = (enum input_mode)opt;
                switch (opt) {
                case silentoldconfig:
                        sync_kconfig = 1;
                        break;
                case defconfig:
+               case savedefconfig:
                        defconfig_file = optarg;
                        break;
                case randconfig:
@@ -503,8 +508,7 @@ int main(int ac, char **av)
                name = conf_get_configname();
                if (stat(name, &tmpstat)) {
                        fprintf(stderr, _("***\n"
-                               "*** You have not yet configured your kernel!\n"
-                               "*** (missing kernel config file \"%s\")\n"
+                               "*** Configuration file \"%s\" not found!\n"
                                "***\n"
                                "*** Please run some configurator (e.g. \"make oldconfig\" or\n"
                                "*** \"make menuconfig\" or \"make xconfig\").\n"
@@ -524,6 +528,7 @@ int main(int ac, char **av)
                        exit(1);
                }
                break;
+       case savedefconfig:
        case silentoldconfig:
        case oldaskconfig:
        case oldconfig:
@@ -534,6 +539,7 @@ int main(int ac, char **av)
        case allnoconfig:
        case allyesconfig:
        case allmodconfig:
+       case alldefconfig:
        case randconfig:
                name = getenv("KCONFIG_ALLCONFIG");
                if (name && !stat(name, &tmpstat)) {
@@ -544,6 +550,7 @@ int main(int ac, char **av)
                case allnoconfig:       name = "allno.config"; break;
                case allyesconfig:      name = "allyes.config"; break;
                case allmodconfig:      name = "allmod.config"; break;
+               case alldefconfig:      name = "alldef.config"; break;
                case randconfig:        name = "allrandom.config"; break;
                default: break;
                }
@@ -561,7 +568,7 @@ int main(int ac, char **av)
                        name = getenv("KCONFIG_NOSILENTUPDATE");
                        if (name && *name) {
                                fprintf(stderr,
-                                       _("\n*** Kernel configuration requires explicit update.\n\n"));
+                                       _("\n*** The configuration requires explicit update.\n\n"));
                                return 1;
                        }
                }
@@ -578,18 +585,23 @@ int main(int ac, char **av)
        case allmodconfig:
                conf_set_all_new_symbols(def_mod);
                break;
+       case alldefconfig:
+               conf_set_all_new_symbols(def_default);
+               break;
        case randconfig:
                conf_set_all_new_symbols(def_random);
                break;
        case defconfig:
                conf_set_all_new_symbols(def_default);
                break;
-       case oldconfig:
+       case savedefconfig:
+               break;
        case oldaskconfig:
                rootEntry = &rootmenu;
                conf(&rootmenu);
                input_mode = silentoldconfig;
                /* fall through */
+       case oldconfig:
        case listnewconfig:
        case oldnoconfig:
        case silentoldconfig:
@@ -608,18 +620,35 @@ int main(int ac, char **av)
                 * All other commands are only used to generate a config.
                 */
                if (conf_get_changed() && conf_write(NULL)) {
-                       fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
+                       fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
                        exit(1);
                }
                if (conf_write_autoconf()) {
-                       fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n"));
+                       fprintf(stderr, _("\n*** Error during update of the configuration.\n\n"));
+                       return 1;
+               }
+       } else if (input_mode == savedefconfig) {
+               if (conf_write_defconfig(defconfig_file)) {
+                       fprintf(stderr, _("n*** Error while saving defconfig to: %s\n\n"),
+                               defconfig_file);
                        return 1;
                }
        } else if (input_mode != listnewconfig) {
                if (conf_write(NULL)) {
-                       fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n"));
+                       fprintf(stderr, _("\n*** Error during writing of the configuration.\n\n"));
                        exit(1);
                }
        }
        return 0;
 }
+/*
+ * Helper function to facilitate fgets() by Jean Sacren.
+ */
+void xfgets(str, size, in)
+       char *str;
+       int size;
+       FILE *in;
+{
+       if (fgets(str, size, in) == NULL)
+               fprintf(stderr, "\nError in reading or end of file.\n");
+}