diff options
author | Thomas Adam <thomas@xteddy.org> | 2022-03-03 10:01:09 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2022-03-03 10:01:09 +0000 |
commit | f84f1c0cfe5dcad99105e94955bdf1f104c0f14c (patch) | |
tree | 3ed2f8f930784f0bfeff6b696dabe121fed4ed7f | |
parent | bf14bf6259a03d83502e281a34d88296faaa02dc (diff) | |
parent | 7d4224f2073ca4111968573e35997b65a0d5787a (diff) | |
download | rtmux-f84f1c0cfe5dcad99105e94955bdf1f104c0f14c.tar.gz rtmux-f84f1c0cfe5dcad99105e94955bdf1f104c0f14c.tar.bz2 rtmux-f84f1c0cfe5dcad99105e94955bdf1f104c0f14c.zip |
Merge branch 'obsd-master' into master
-rw-r--r-- | arguments.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/arguments.c b/arguments.c index a27d8e0a..91c470e2 100644 --- a/arguments.c +++ b/arguments.c @@ -131,8 +131,9 @@ args_parse(const struct args_parse *parse, struct args_value *values, u_int i; enum args_parse_type type; struct args_value *value, *new; - u_char flag, argument; + u_char flag; const char *found, *string, *s; + int optional_argument; if (count == 0) return (args_create()); @@ -169,18 +170,27 @@ args_parse(const struct args_parse *parse, struct args_value *values, args_free(args); return (NULL); } - argument = *++found; - if (argument != ':') { + if (*++found != ':') { log_debug("%s: -%c", __func__, flag); args_set(args, flag, NULL); continue; } + if (*found == ':') { + optional_argument = 1; + found++; + } new = xcalloc(1, sizeof *new); if (*string != '\0') { new->type = ARGS_STRING; new->string = xstrdup(string); } else { if (i == count) { + if (optional_argument) { + log_debug("%s: -%c", __func__, + flag); + args_set(args, flag, NULL); + continue; + } xasprintf(cause, "-%c expects an argument", flag); |