From e2f9efcd7893a472c178cef23ee5d61a0947cb50 Mon Sep 17 00:00:00 2001 From: Karel Klic Date: Thu, 3 Mar 2011 12:21:35 +0100 Subject: parse_options: handle options without short variant --- src/lib/parse_options.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/lib') diff --git a/src/lib/parse_options.c b/src/lib/parse_options.c index 4f2b2a2b..d9ce8a2f 100644 --- a/src/lib/parse_options.c +++ b/src/lib/parse_options.c @@ -89,6 +89,7 @@ unsigned parse_opts(int argc, char **argv, const struct options *opt, { int help = 0; int size = parse_opt_size(opt); + const int LONGOPT_OFFSET = 256; struct strbuf *shortopts = strbuf_new(); @@ -99,7 +100,10 @@ unsigned parse_opts(int argc, char **argv, const struct options *opt, { curopt->name = opt[ii].long_name; /*curopt->flag = 0; - xzalloc did it */ - curopt->val = opt[ii].short_name; + if (opt[ii].short_name) + curopt->val = opt[ii].short_name; + else + curopt->val = LONGOPT_OFFSET + ii; switch (opt[ii].type) { @@ -168,7 +172,7 @@ unsigned parse_opts(int argc, char **argv, const struct options *opt, for (ii = 0; ii < size; ++ii) { - if (opt[ii].short_name == c) + if (opt[ii].short_name == c || LONGOPT_OFFSET + ii == c) { if (ii < sizeof(retval)*8) retval |= (1 << ii); -- cgit