]> git.ozlabs.org Git - ccan/blobdiff - ccan/opt/opt.c
opt: allow parameter names in arguments.
[ccan] / ccan / opt / opt.c
index a5180706c45e28e52394411ad5ff271f10cdeb2c..e7ebc3dd0550e2181b13c41438ddeb9e8f244dff 100644 (file)
@@ -17,14 +17,14 @@ const char *opt_argv0;
 /* Returns string after first '-'. */
 static const char *first_name(const char *names, unsigned *len)
 {
-       *len = strcspn(names + 1, "/");
+       *len = strcspn(names + 1, "/");
        return names + 1;
 }
 
 static const char *next_name(const char *names, unsigned *len)
 {
        names += *len;
-       if (!names[0])
+       if (names[0] == ' ' || names[0] == '=' || names[0] == '\0')
                return NULL;
        return first_name(names + 1, len);
 }
@@ -124,6 +124,9 @@ static void check_opt(const struct opt_table *entry)
                                assert(*p != '?');
                        }
                }
+               /* Don't document args unless there are some. */
+               if (entry->flags == OPT_NOARG)
+                       assert(p[len] != ' ' && p[len] != '=');
        }
 }