kconfig: use C89 random functions in conf.c
[safe/jmp/linux-2.6] / scripts / kconfig / conf.c
index a38787a..01c2f35 100644 (file)
@@ -4,11 +4,11 @@
  */
 
 #include <ctype.h>
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-#include <unistd.h>
 #include <time.h>
+#include <unistd.h>
 #include <sys/stat.h>
 
 #define LKC_DIRECT_LINK
@@ -160,7 +160,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)
                }
        case set_random:
                do {
-                       val = (tristate)(random() % 3);
+                       val = (tristate)(rand() % 3);
                } while (!sym_tristate_within_range(sym, val));
                switch (val) {
                case no: line[0] = 'n'; break;
@@ -374,7 +374,8 @@ static int conf_choice(struct menu *menu)
                                continue;
                        break;
                case set_random:
-                       def = (random() % cnt) + 1;
+                       if (is_new)
+                               def = (rand() % cnt) + 1;
                case set_default:
                case set_yes:
                case set_mod:
@@ -494,12 +495,12 @@ static void check_conf(struct menu *menu)
 
 int main(int ac, char **av)
 {
-       int i = 1;
+       int opt;
        const char *name;
        struct stat tmpstat;
 
-       if (ac > i && av[i][0] == '-') {
-               switch (av[i++][1]) {
+       while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) {
+               switch (opt) {
                case 'o':
                        input_mode = ask_new;
                        break;
@@ -512,12 +513,7 @@ int main(int ac, char **av)
                        break;
                case 'D':
                        input_mode = set_default;
-                       defconfig_file = av[i++];
-                       if (!defconfig_file) {
-                               printf(_("%s: No default config file specified\n"),
-                                       av[0]);
-                               exit(1);
-                       }
+                       defconfig_file = optarg;
                        break;
                case 'n':
                        input_mode = set_no;
@@ -530,19 +526,22 @@ int main(int ac, char **av)
                        break;
                case 'r':
                        input_mode = set_random;
-                       srandom(time(NULL));
+                       srand(time(NULL));
                        break;
                case 'h':
-               case '?':
-                       fprintf(stderr, "See README for usage info\n");
+                       printf("See README for usage info\n");
                        exit(0);
+                       break;
+               default:
+                       fprintf(stderr, "See README for usage info\n");
+                       exit(1);
                }
        }
-       name = av[i];
-       if (!name) {
+       if (ac == optind) {
                printf(_("%s: Kconfig file missing\n"), av[0]);
                exit(1);
        }
+       name = av[optind];
        conf_parse(name);
        //zconfdump(stdout);
        switch (input_mode) {