Commit cc672bb2 authored by dp-arm's avatar dp-arm
Browse files

fiptool: Use getopt for the top level command parsing



Change-Id: I18a4327e41fc090dcea9a647f7673182ca0ed1d9
Signed-off-by: default avatardp-arm <dimitris.papastamos@arm.com>
parent 20f87e78
...@@ -977,17 +977,36 @@ int main(int argc, char *argv[]) ...@@ -977,17 +977,36 @@ int main(int argc, char *argv[])
{ {
int i, ret = 0; int i, ret = 0;
if (argc < 2) while (1) {
usage(); int c, opt_index = 0;
argc--, argv++; static struct option opts[] = {
{ "verbose", no_argument, NULL, 'v' },
{ NULL, no_argument, NULL, 0 }
};
/*
* Set POSIX mode so getopt stops at the first non-option
* which is the subcommand.
*/
c = getopt_long(argc, argv, "+v", opts, &opt_index);
if (c == -1)
break;
if (strcmp(argv[0], "-v") == 0 || switch (c) {
strcmp(argv[0], "--verbose") == 0) { case 'v':
verbose = 1; verbose = 1;
argc--, argv++; break;
if (argc < 1) default:
usage(); usage();
} }
}
argc -= optind;
argv += optind;
/* Reset optind for subsequent getopt processing. */
optind = 0;
if (argc == 0)
usage();
for (i = 0; i < NELEM(cmds); i++) { for (i = 0; i < NELEM(cmds); i++) {
if (strcmp(cmds[i].name, argv[0]) == 0) { if (strcmp(cmds[i].name, argv[0]) == 0) {
......
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