aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndres Salomon <dilinger@debian.org>2007-12-17 01:34:58 -0500
committerSam Ravnborg <sam@ravnborg.org>2008-01-28 17:14:36 -0500
commit2f4b489b77c68b9cba1bd9dec5a1bbf0ab3c47f8 (patch)
tree36e0bbe86be28a801e0907c3a17731c4fafbe17b
parent666ab414fe14e8bbbe86a110437346128e1ec869 (diff)
kconfig: use getopt() in conf.c for handling command line arguments
Switch from doing our own parsing of command line arguments to using getopt(3) to do it. Aside from simplifying things, this allows us to specify multiple arguments; the old code could only accept two arguments (input_mode and kconfig name). Note some subtle changes: - The argument '-?' is no longer supported. - '-h' is not treated as an error, so output goes to stdout, and we exit with '0'. - There is no compatibility checking amongst arguments; the last option will simply override earlier options. For example, 'conf -n -y foo' is perfectly valid now (input_mode will be set_yes). Previously, that would have been an error ("can't find file -y"). Signed-off-by: Andres Salomon <dilinger@debian.org> Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Cc: Roman Zippel <zippel@linux-m68k.org>
-rw-r--r--scripts/kconfig/conf.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c
index 8d6f17490c5e..d4737d35e720 100644
--- a/scripts/kconfig/conf.c
+++ b/scripts/kconfig/conf.c
@@ -495,12 +495,12 @@ static void check_conf(struct menu *menu)
495 495
496int main(int ac, char **av) 496int main(int ac, char **av)
497{ 497{
498 int i = 1; 498 int opt;
499 const char *name; 499 const char *name;
500 struct stat tmpstat; 500 struct stat tmpstat;
501 501
502 if (ac > i && av[i][0] == '-') { 502 while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) {
503 switch (av[i++][1]) { 503 switch (opt) {
504 case 'o': 504 case 'o':
505 input_mode = ask_new; 505 input_mode = ask_new;
506 break; 506 break;
@@ -513,12 +513,7 @@ int main(int ac, char **av)
513 break; 513 break;
514 case 'D': 514 case 'D':
515 input_mode = set_default; 515 input_mode = set_default;
516 defconfig_file = av[i++]; 516 defconfig_file = optarg;
517 if (!defconfig_file) {
518 printf(_("%s: No default config file specified\n"),
519 av[0]);
520 exit(1);
521 }
522 break; 517 break;
523 case 'n': 518 case 'n':
524 input_mode = set_no; 519 input_mode = set_no;
@@ -534,16 +529,19 @@ int main(int ac, char **av)
534 srandom(time(NULL)); 529 srandom(time(NULL));
535 break; 530 break;
536 case 'h': 531 case 'h':
537 case '?': 532 printf("See README for usage info\n");
538 fprintf(stderr, "See README for usage info\n");
539 exit(0); 533 exit(0);
534 break;
535 default:
536 fprintf(stderr, "See README for usage info\n");
537 exit(1);
540 } 538 }
541 } 539 }
542 name = av[i]; 540 if (ac == optind) {
543 if (!name) {
544 printf(_("%s: Kconfig file missing\n"), av[0]); 541 printf(_("%s: Kconfig file missing\n"), av[0]);
545 exit(1); 542 exit(1);
546 } 543 }
544 name = av[optind];
547 conf_parse(name); 545 conf_parse(name);
548 //zconfdump(stdout); 546 //zconfdump(stdout);
549 switch (input_mode) { 547 switch (input_mode) {