diff options
Diffstat (limited to 'scripts/kconfig/conf.c')
-rw-r--r-- | scripts/kconfig/conf.c | 161 |
1 files changed, 75 insertions, 86 deletions
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index bde01b4200ee..2dec584f1268 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c | |||
@@ -10,6 +10,7 @@ | |||
10 | #include <string.h> | 10 | #include <string.h> |
11 | #include <time.h> | 11 | #include <time.h> |
12 | #include <unistd.h> | 12 | #include <unistd.h> |
13 | #include <getopt.h> | ||
13 | #include <sys/stat.h> | 14 | #include <sys/stat.h> |
14 | #include <sys/time.h> | 15 | #include <sys/time.h> |
15 | 16 | ||
@@ -23,18 +24,19 @@ | |||
23 | static void conf(struct menu *menu); | 24 | static void conf(struct menu *menu); |
24 | static void check_conf(struct menu *menu); | 25 | static void check_conf(struct menu *menu); |
25 | 26 | ||
26 | enum { | 27 | enum input_mode { |
27 | ask_all, | 28 | oldaskconfig, |
28 | ask_new, | 29 | silentoldconfig, |
29 | ask_silent, | 30 | oldconfig, |
30 | dont_ask, | 31 | allnoconfig, |
31 | dont_ask_dont_tell, | 32 | allyesconfig, |
32 | set_default, | 33 | allmodconfig, |
33 | set_yes, | 34 | randconfig, |
34 | set_mod, | 35 | defconfig, |
35 | set_no, | 36 | nonint_oldconfig, |
36 | set_random | 37 | loose_nonint_oldconfig, |
37 | } input_mode = ask_all; | 38 | } input_mode = oldaskconfig; |
39 | |||
38 | char *defconfig_file; | 40 | char *defconfig_file; |
39 | 41 | ||
40 | static int indent = 1; | 42 | static int indent = 1; |
@@ -100,14 +102,14 @@ static int conf_askvalue(struct symbol *sym, const char *def) | |||
100 | } | 102 | } |
101 | 103 | ||
102 | switch (input_mode) { | 104 | switch (input_mode) { |
103 | case ask_new: | 105 | case oldconfig: |
104 | case ask_silent: | 106 | case silentoldconfig: |
105 | if (sym_has_value(sym)) { | 107 | if (sym_has_value(sym)) { |
106 | printf("%s\n", def); | 108 | printf("%s\n", def); |
107 | return 0; | 109 | return 0; |
108 | } | 110 | } |
109 | check_stdin(); | 111 | check_stdin(); |
110 | case ask_all: | 112 | case oldaskconfig: |
111 | fflush(stdout); | 113 | fflush(stdout); |
112 | fgets(line, 128, stdin); | 114 | fgets(line, 128, stdin); |
113 | return 1; | 115 | return 1; |
@@ -297,15 +299,15 @@ static int conf_choice(struct menu *menu) | |||
297 | printf("?"); | 299 | printf("?"); |
298 | printf("]: "); | 300 | printf("]: "); |
299 | switch (input_mode) { | 301 | switch (input_mode) { |
300 | case ask_new: | 302 | case oldconfig: |
301 | case ask_silent: | 303 | case silentoldconfig: |
302 | if (!is_new) { | 304 | if (!is_new) { |
303 | cnt = def; | 305 | cnt = def; |
304 | printf("%d\n", cnt); | 306 | printf("%d\n", cnt); |
305 | break; | 307 | break; |
306 | } | 308 | } |
307 | check_stdin(); | 309 | check_stdin(); |
308 | case ask_all: | 310 | case oldaskconfig: |
309 | fflush(stdout); | 311 | fflush(stdout); |
310 | fgets(line, 128, stdin); | 312 | fgets(line, 128, stdin); |
311 | strip(line); | 313 | strip(line); |
@@ -363,9 +365,9 @@ static void conf(struct menu *menu) | |||
363 | 365 | ||
364 | switch (prop->type) { | 366 | switch (prop->type) { |
365 | case P_MENU: | 367 | case P_MENU: |
366 | if ((input_mode == ask_silent || | 368 | if ((input_mode == silentoldconfig || |
367 | input_mode == dont_ask || | 369 | input_mode == nonint_oldconfig || |
368 | input_mode == dont_ask_dont_tell) && | 370 | input_mode == loose_nonint_oldconfig) && |
369 | rootEntry != menu) { | 371 | rootEntry != menu) { |
370 | check_conf(menu); | 372 | check_conf(menu); |
371 | return; | 373 | return; |
@@ -424,9 +426,9 @@ static void check_conf(struct menu *menu) | |||
424 | if (sym && !sym_has_value(sym)) { | 426 | if (sym && !sym_has_value(sym)) { |
425 | if (sym_is_changable(sym) || | 427 | if (sym_is_changable(sym) || |
426 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { | 428 | (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { |
427 | if (input_mode == dont_ask || | 429 | if (input_mode == nonint_oldconfig || |
428 | input_mode == dont_ask_dont_tell) { | 430 | input_mode == loose_nonint_oldconfig) { |
429 | if (input_mode == dont_ask && | 431 | if (input_mode == nonint_oldconfig && |
430 | sym->name && !sym_is_choice_value(sym)) { | 432 | sym->name && !sym_is_choice_value(sym)) { |
431 | if (!unset_variables) | 433 | if (!unset_variables) |
432 | fprintf(stderr, "The following" | 434 | fprintf(stderr, "The following" |
@@ -448,6 +450,20 @@ static void check_conf(struct menu *menu) | |||
448 | check_conf(child); | 450 | check_conf(child); |
449 | } | 451 | } |
450 | 452 | ||
453 | static struct option long_opts[] = { | ||
454 | {"oldaskconfig", no_argument, NULL, oldaskconfig}, | ||
455 | {"oldconfig", no_argument, NULL, oldconfig}, | ||
456 | {"silentoldconfig", no_argument, NULL, silentoldconfig}, | ||
457 | {"defconfig", optional_argument, NULL, defconfig}, | ||
458 | {"allnoconfig", no_argument, NULL, allnoconfig}, | ||
459 | {"allyesconfig", no_argument, NULL, allyesconfig}, | ||
460 | {"allmodconfig", no_argument, NULL, allmodconfig}, | ||
461 | {"randconfig", no_argument, NULL, randconfig}, | ||
462 | {"nonint_oldconfig", no_argument, NULL, nonint_oldconfig}, | ||
463 | {"loose_nonint_oldconfig", no_argument, NULL, loose_nonint_oldconfig}, | ||
464 | {NULL, 0, NULL, 0} | ||
465 | }; | ||
466 | |||
451 | int main(int ac, char **av) | 467 | int main(int ac, char **av) |
452 | { | 468 | { |
453 | int opt; | 469 | int opt; |
@@ -458,38 +474,16 @@ int main(int ac, char **av) | |||
458 | bindtextdomain(PACKAGE, LOCALEDIR); | 474 | bindtextdomain(PACKAGE, LOCALEDIR); |
459 | textdomain(PACKAGE); | 475 | textdomain(PACKAGE); |
460 | 476 | ||
461 | while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) { | 477 | while ((opt = getopt_long_only(ac, av, "", long_opts, NULL)) != -1) { |
478 | input_mode = (enum input_mode)opt; | ||
462 | switch (opt) { | 479 | switch (opt) { |
463 | case 'o': | 480 | case silentoldconfig: |
464 | input_mode = ask_silent; | ||
465 | break; | ||
466 | case 's': | ||
467 | input_mode = ask_silent; | ||
468 | sync_kconfig = 1; | 481 | sync_kconfig = 1; |
469 | break; | 482 | break; |
470 | case 'b': | 483 | case defconfig: |
471 | input_mode = dont_ask; | ||
472 | break; | ||
473 | case 'B': | ||
474 | input_mode = dont_ask_dont_tell; | ||
475 | break; | ||
476 | case 'd': | ||
477 | input_mode = set_default; | ||
478 | break; | ||
479 | case 'D': | ||
480 | input_mode = set_default; | ||
481 | defconfig_file = optarg; | 484 | defconfig_file = optarg; |
482 | break; | 485 | break; |
483 | case 'n': | 486 | case randconfig: |
484 | input_mode = set_no; | ||
485 | break; | ||
486 | case 'm': | ||
487 | input_mode = set_mod; | ||
488 | break; | ||
489 | case 'y': | ||
490 | input_mode = set_yes; | ||
491 | break; | ||
492 | case 'r': | ||
493 | { | 487 | { |
494 | struct timeval now; | 488 | struct timeval now; |
495 | unsigned int seed; | 489 | unsigned int seed; |
@@ -502,17 +496,12 @@ int main(int ac, char **av) | |||
502 | 496 | ||
503 | seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); | 497 | seed = (unsigned int)((now.tv_sec + 1) * (now.tv_usec + 1)); |
504 | srand(seed); | 498 | srand(seed); |
505 | |||
506 | input_mode = set_random; | ||
507 | break; | 499 | break; |
508 | } | 500 | } |
509 | case 'h': | 501 | case '?': |
510 | printf(_("See README for usage info\n")); | ||
511 | exit(0); | ||
512 | break; | ||
513 | default: | ||
514 | fprintf(stderr, _("See README for usage info\n")); | 502 | fprintf(stderr, _("See README for usage info\n")); |
515 | exit(1); | 503 | exit(1); |
504 | break; | ||
516 | } | 505 | } |
517 | } | 506 | } |
518 | if (ac == optind) { | 507 | if (ac == optind) { |
@@ -537,7 +526,7 @@ int main(int ac, char **av) | |||
537 | } | 526 | } |
538 | 527 | ||
539 | switch (input_mode) { | 528 | switch (input_mode) { |
540 | case set_default: | 529 | case defconfig: |
541 | if (!defconfig_file) | 530 | if (!defconfig_file) |
542 | defconfig_file = conf_get_default_confname(); | 531 | defconfig_file = conf_get_default_confname(); |
543 | if (conf_read(defconfig_file)) { | 532 | if (conf_read(defconfig_file)) { |
@@ -547,27 +536,27 @@ int main(int ac, char **av) | |||
547 | exit(1); | 536 | exit(1); |
548 | } | 537 | } |
549 | break; | 538 | break; |
550 | case ask_silent: | 539 | case silentoldconfig: |
551 | case ask_all: | 540 | case oldaskconfig: |
552 | case ask_new: | 541 | case oldconfig: |
553 | case dont_ask: | 542 | case nonint_oldconfig: |
554 | case dont_ask_dont_tell: | 543 | case loose_nonint_oldconfig: |
555 | conf_read(NULL); | 544 | conf_read(NULL); |
556 | break; | 545 | break; |
557 | case set_no: | 546 | case allnoconfig: |
558 | case set_mod: | 547 | case allyesconfig: |
559 | case set_yes: | 548 | case allmodconfig: |
560 | case set_random: | 549 | case randconfig: |
561 | name = getenv("KCONFIG_ALLCONFIG"); | 550 | name = getenv("KCONFIG_ALLCONFIG"); |
562 | if (name && !stat(name, &tmpstat)) { | 551 | if (name && !stat(name, &tmpstat)) { |
563 | conf_read_simple(name, S_DEF_USER); | 552 | conf_read_simple(name, S_DEF_USER); |
564 | break; | 553 | break; |
565 | } | 554 | } |
566 | switch (input_mode) { | 555 | switch (input_mode) { |
567 | case set_no: name = "allno.config"; break; | 556 | case allnoconfig: name = "allno.config"; break; |
568 | case set_mod: name = "allmod.config"; break; | 557 | case allyesconfig: name = "allyes.config"; break; |
569 | case set_yes: name = "allyes.config"; break; | 558 | case allmodconfig: name = "allmod.config"; break; |
570 | case set_random: name = "allrandom.config"; break; | 559 | case randconfig: name = "allrandom.config"; break; |
571 | default: break; | 560 | default: break; |
572 | } | 561 | } |
573 | if (!stat(name, &tmpstat)) | 562 | if (!stat(name, &tmpstat)) |
@@ -592,37 +581,37 @@ int main(int ac, char **av) | |||
592 | } | 581 | } |
593 | 582 | ||
594 | switch (input_mode) { | 583 | switch (input_mode) { |
595 | case set_no: | 584 | case allnoconfig: |
596 | conf_set_all_new_symbols(def_no); | 585 | conf_set_all_new_symbols(def_no); |
597 | break; | 586 | break; |
598 | case set_yes: | 587 | case allyesconfig: |
599 | conf_set_all_new_symbols(def_yes); | 588 | conf_set_all_new_symbols(def_yes); |
600 | break; | 589 | break; |
601 | case set_mod: | 590 | case allmodconfig: |
602 | conf_set_all_new_symbols(def_mod); | 591 | conf_set_all_new_symbols(def_mod); |
603 | break; | 592 | break; |
604 | case set_random: | 593 | case randconfig: |
605 | conf_set_all_new_symbols(def_random); | 594 | conf_set_all_new_symbols(def_random); |
606 | break; | 595 | break; |
607 | case set_default: | 596 | case defconfig: |
608 | conf_set_all_new_symbols(def_default); | 597 | conf_set_all_new_symbols(def_default); |
609 | break; | 598 | break; |
610 | case ask_new: | 599 | case oldconfig: |
611 | case ask_all: | 600 | case oldaskconfig: |
612 | rootEntry = &rootmenu; | 601 | rootEntry = &rootmenu; |
613 | conf(&rootmenu); | 602 | conf(&rootmenu); |
614 | input_mode = ask_silent; | 603 | input_mode = silentoldconfig; |
615 | /* fall through */ | 604 | /* fall through */ |
616 | case dont_ask: | 605 | case nonint_oldconfig: |
617 | case dont_ask_dont_tell: | 606 | case loose_nonint_oldconfig: |
618 | case ask_silent: | 607 | case silentoldconfig: |
619 | /* Update until a loop caused no more changes */ | 608 | /* Update until a loop caused no more changes */ |
620 | do { | 609 | do { |
621 | conf_cnt = 0; | 610 | conf_cnt = 0; |
622 | check_conf(&rootmenu); | 611 | check_conf(&rootmenu); |
623 | } while (conf_cnt && | 612 | } while (conf_cnt && |
624 | (input_mode != dont_ask && | 613 | (input_mode != nonint_oldconfig && |
625 | input_mode != dont_ask_dont_tell)); | 614 | input_mode != loose_nonint_oldconfig)); |
626 | break; | 615 | break; |
627 | } | 616 | } |
628 | 617 | ||
@@ -638,7 +627,7 @@ int main(int ac, char **av) | |||
638 | fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n")); | 627 | fprintf(stderr, _("\n*** Error during update of the kernel configuration.\n\n")); |
639 | return 1; | 628 | return 1; |
640 | } | 629 | } |
641 | } else if (!unset_variables || input_mode != dont_ask) { | 630 | } else if (!unset_variables || input_mode != nonint_oldconfig) { |
642 | if (conf_write(NULL)) { | 631 | if (conf_write(NULL)) { |
643 | fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); | 632 | fprintf(stderr, _("\n*** Error during writing of the kernel configuration.\n\n")); |
644 | exit(1); | 633 | exit(1); |