summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-10-12 14:39:31 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-10-12 14:39:31 +0200
commit0bf035eaac1106c3eb6daecb277c193c9160d1af (patch)
treeccae87d00f91b9e3e68b3070f5dab3027d1891d4 /lib
parent4d68ae093b68bd857165cc249deb3486f81966bf (diff)
downloadabrt-0bf035eaac1106c3eb6daecb277c193c9160d1af.tar.gz
abrt-0bf035eaac1106c3eb6daecb277c193c9160d1af.tar.xz
abrt-0bf035eaac1106c3eb6daecb277c193c9160d1af.zip
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 <dvlasenk@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/utils/parse_options.c10
-rw-r--r--lib/utils/parse_options.h2
2 files changed, 9 insertions, 3 deletions
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;
}
diff --git a/lib/utils/parse_options.h b/lib/utils/parse_options.h
index 0e768eb7..f44f29b1 100644
--- a/lib/utils/parse_options.h
+++ b/lib/utils/parse_options.h
@@ -39,7 +39,7 @@ struct options {
#define OPT__VERBOSE(v) OPT_BOOL('v', "verbose", (v), "be verbose")
-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);
void parse_usage_and_die(const char *usage, const struct options *opt);