Commit 2f4b489b authored by Andres Salomon's avatar Andres Salomon Committed by Sam Ravnborg

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: default avatarAndres Salomon <dilinger@debian.org>
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
Cc: Roman Zippel <zippel@linux-m68k.org>
parent 666ab414
...@@ -495,12 +495,12 @@ static void check_conf(struct menu *menu) ...@@ -495,12 +495,12 @@ static void check_conf(struct menu *menu)
int main(int ac, char **av) int main(int ac, char **av)
{ {
int i = 1; int opt;
const char *name; const char *name;
struct stat tmpstat; struct stat tmpstat;
if (ac > i && av[i][0] == '-') { while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) {
switch (av[i++][1]) { switch (opt) {
case 'o': case 'o':
input_mode = ask_new; input_mode = ask_new;
break; break;
...@@ -513,12 +513,7 @@ int main(int ac, char **av) ...@@ -513,12 +513,7 @@ int main(int ac, char **av)
break; break;
case 'D': case 'D':
input_mode = set_default; input_mode = set_default;
defconfig_file = av[i++]; defconfig_file = optarg;
if (!defconfig_file) {
printf(_("%s: No default config file specified\n"),
av[0]);
exit(1);
}
break; break;
case 'n': case 'n':
input_mode = set_no; input_mode = set_no;
...@@ -534,16 +529,19 @@ int main(int ac, char **av) ...@@ -534,16 +529,19 @@ int main(int ac, char **av)
srandom(time(NULL)); srandom(time(NULL));
break; break;
case 'h': case 'h':
case '?': printf("See README for usage info\n");
fprintf(stderr, "See README for usage info\n");
exit(0); exit(0);
break;
default:
fprintf(stderr, "See README for usage info\n");
exit(1);
} }
} }
name = av[i]; if (ac == optind) {
if (!name) {
printf(_("%s: Kconfig file missing\n"), av[0]); printf(_("%s: Kconfig file missing\n"), av[0]);
exit(1); exit(1);
} }
name = av[optind];
conf_parse(name); conf_parse(name);
//zconfdump(stdout); //zconfdump(stdout);
switch (input_mode) { switch (input_mode) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment