diff options
author | dp-arm <dimitris.papastamos@arm.com> | 2016-11-07 10:45:59 +0000 |
---|---|---|
committer | dp-arm <dimitris.papastamos@arm.com> | 2016-12-05 10:38:49 +0000 |
commit | cc672bb2bf389a2241dfd76e12373a8c5237179a (patch) | |
tree | 3d0ff2ad6e1ba5528b0a5a6506a6f9075ad814c6 /tools | |
parent | 20f87e78e39d70fd5f65779ebdc4dd16299e26b9 (diff) |
fiptool: Use getopt for the top level command parsing
Change-Id: I18a4327e41fc090dcea9a647f7673182ca0ed1d9
Signed-off-by: dp-arm <dimitris.papastamos@arm.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/fiptool/fiptool.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/tools/fiptool/fiptool.c b/tools/fiptool/fiptool.c index f53e9ab3..70ec6fd7 100644 --- a/tools/fiptool/fiptool.c +++ b/tools/fiptool/fiptool.c @@ -977,17 +977,36 @@ int main(int argc, char *argv[]) { int i, ret = 0; - if (argc < 2) - usage(); - argc--, argv++; + while (1) { + int c, opt_index = 0; + 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 || - strcmp(argv[0], "--verbose") == 0) { - verbose = 1; - argc--, argv++; - if (argc < 1) + switch (c) { + case 'v': + verbose = 1; + break; + default: usage(); + } } + argc -= optind; + argv += optind; + /* Reset optind for subsequent getopt processing. */ + optind = 0; + + if (argc == 0) + usage(); for (i = 0; i < NELEM(cmds); i++) { if (strcmp(cmds[i].name, argv[0]) == 0) { |