]> mj.ucw.cz Git - libucw.git/commitdiff
Opt: Accept arguments for short options even in bundles
authorMartin Mares <mj@ucw.cz>
Mon, 27 Jan 2014 14:57:32 +0000 (15:57 +0100)
committerMartin Mares <mj@ucw.cz>
Mon, 27 Jan 2014 14:57:32 +0000 (15:57 +0100)
Traditional getopt() seems to support this, so we should, too.

ucw/opt.c

index 54f8b2b51c811a01cbf067977367ffa1d21a86b6..eae95cf135cfbc32d9021578f674478b5c5310c0 100644 (file)
--- 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);