From 0bf035eaac1106c3eb6daecb277c193c9160d1af Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 12 Oct 2010 14:39:31 +0200 Subject: Return a bitmask of found options from parse_opts() This patch makes it easier to analyze "bool" type options - now they are all just bits in a single return value, no need to have an integer variable for each option. The previous behavior is retained too: it is useful for "cumulative" options like -vvv. The patch also removes all OPT_GROUPs. Signed-off-by: Denys Vlasenko --- lib/utils/parse_options.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/utils/parse_options.c') diff --git a/lib/utils/parse_options.c b/lib/utils/parse_options.c index 5f4fbd63..de6f4e23 100644 --- a/lib/utils/parse_options.c +++ b/lib/utils/parse_options.c @@ -61,7 +61,7 @@ static int parse_opt_size(const struct options *opt) return size; } -void parse_opts(int argc, char **argv, const struct options *opt, +unsigned parse_opts(int argc, char **argv, const struct options *opt, const char *usage) { int help = 0; @@ -107,6 +107,7 @@ void parse_opts(int argc, char **argv, const struct options *opt, longopts[ii].val = 0; */ + unsigned retval = 0; while (1) { int c = getopt_long(argc, argv, shortopts->buf, longopts, NULL); @@ -125,7 +126,10 @@ void parse_opts(int argc, char **argv, const struct options *opt, { if (opt[ii].short_name == c) { - switch (opt[ii].type) + if (ii < sizeof(retval)*8) + retval |= (1 << ii); + + if (opt[ii].value != NULL) switch (opt[ii].type) { case OPTION_BOOL: *(int*)opt[ii].value += 1; @@ -147,4 +151,6 @@ void parse_opts(int argc, char **argv, const struct options *opt, free(longopts); strbuf_free(shortopts); + + return retval; } -- cgit