From: Martin Mares Date: Mon, 27 Jan 2014 14:57:32 +0000 (+0100) Subject: Opt: Accept arguments for short options even in bundles X-Git-Tag: v5.99~25^2~18 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=a806861a95a7e923d8e9a373f051951378b2118b;p=libucw.git Opt: Accept arguments for short options even in bundles Traditional getopt() seems to support this, so we should, too. --- diff --git a/ucw/opt.c b/ucw/opt.c index 54f8b2b5..eae95cf1 100644 --- a/ucw/opt.c +++ b/ucw/opt.c @@ -390,20 +390,18 @@ static int opt_shortopt(struct opt_context * oc, char ** argv, int index) { if (opt->flags & OPT_NO_VALUE) opt_parse_value(oc, opt, NULL, 0); else if (opt->flags & OPT_REQUIRED_VALUE) { - if (chr == 1 && argv[index][2]) { - opt_parse_value(oc, opt, argv[index] + 2, 0); + if (argv[index][chr+1]) { + opt_parse_value(oc, opt, argv[index] + chr + 1, 0); return 0; - } else if (argv[index][chr+1]) - opt_failure("Option -%c must have a value, but found inside a bunch of short opts.", o); - else if (!argv[index+1]) + } else if (!argv[index+1]) opt_failure("Option -%c must have a value, but nothing supplied.", o); else { opt_parse_value(oc, opt, argv[index+1], 0); return 1; } } else if (opt->flags & OPT_MAYBE_VALUE) { - if (chr == 1 && argv[index][2]) { - opt_parse_value(oc, opt, argv[index] + 2, 0); + if (argv[index][chr+1]) { + opt_parse_value(oc, opt, argv[index] + chr + 1, 0); return 0; } else opt_parse_value(oc, opt, NULL, 0);