From a806861a95a7e923d8e9a373f051951378b2118b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 27 Jan 2014 15:57:32 +0100 Subject: [PATCH] Opt: Accept arguments for short options even in bundles Traditional getopt() seems to support this, so we should, too. --- ucw/opt.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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); -- 2.39.2