Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andres Salomon and committed by
Sam Ravnborg
2f4b489b 666ab414

+11 -13
+11 -13
scripts/kconfig/conf.c
··· 495 495 496 496 int main(int ac, char **av) 497 497 { 498 - int i = 1; 498 + int opt; 499 499 const char *name; 500 500 struct stat tmpstat; 501 501 502 - if (ac > i && av[i][0] == '-') { 503 - switch (av[i++][1]) { 502 + while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) { 503 + switch (opt) { 504 504 case 'o': 505 505 input_mode = ask_new; 506 506 break; ··· 513 513 break; 514 514 case 'D': 515 515 input_mode = set_default; 516 - defconfig_file = av[i++]; 517 - if (!defconfig_file) { 518 - printf(_("%s: No default config file specified\n"), 519 - av[0]); 520 - exit(1); 521 - } 516 + defconfig_file = optarg; 522 517 break; 523 518 case 'n': 524 519 input_mode = set_no; ··· 529 534 srandom(time(NULL)); 530 535 break; 531 536 case 'h': 532 - case '?': 533 - fprintf(stderr, "See README for usage info\n"); 537 + printf("See README for usage info\n"); 534 538 exit(0); 539 + break; 540 + default: 541 + fprintf(stderr, "See README for usage info\n"); 542 + exit(1); 535 543 } 536 544 } 537 - name = av[i]; 538 - if (!name) { 545 + if (ac == optind) { 539 546 printf(_("%s: Kconfig file missing\n"), av[0]); 540 547 exit(1); 541 548 } 549 + name = av[optind]; 542 550 conf_parse(name); 543 551 //zconfdump(stdout); 544 552 switch (input_mode) {