summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2022-03-03 08:24:13 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2022-03-03 08:24:13 +0000
commit0aaa2e326aab0b986ef30ec2b569d6a13ffa1ef6 (patch)
tree51048c4b6d98d4019086f04c969f5aeef7f82304 /usr.bin
parent55d6fa902a6851be288ec7d26b37e2e42c51963b (diff)
Allow optional arguments.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/tmux/arguments.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/usr.bin/tmux/arguments.c b/usr.bin/tmux/arguments.c
index ce3313801f5..8b1f9c60786 100644
--- a/usr.bin/tmux/arguments.c
+++ b/usr.bin/tmux/arguments.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: arguments.c,v 1.52 2021/11/02 10:57:04 nicm Exp $ */
+/* $OpenBSD: arguments.c,v 1.53 2022/03/03 08:24:12 nicm Exp $ */
/*
* Copyright (c) 2010 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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);