summary refs log tree commit diff
path: root/chat.c
diff options
context:
space:
mode:
authorKlemens Nanni2021-06-13 23:39:23 +0000
committerC. McEnroe2021-06-14 17:00:15 -0400
commit1ccadd7c72e10854f4562115d9ce783d50163afa (patch)
tree7360ca1bfc487a61c93dfd97f40d679a0c90b4dd /chat.c
parente18c5857017f60a63f8a754f050906ca67d269d6 (diff)
Treat `-T's optional argument as optional
`-T[format]' is not possible with getopt(3) but getopt_long(3) supports
"T::" exactly for that, so make the command line option go in line with
configuration files and documentation.

While here, check `has_arg' explicitly as getopt_long(3) only documents
mnemonic values not numerical ones.
Diffstat (limited to 'chat.c')
-rw-r--r--chat.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/chat.c b/chat.c
index 3f6aa71..09d0ca6 100644
--- a/chat.c
+++ b/chat.c
@@ -190,10 +190,11 @@ int main(int argc, char *argv[]) {
 		{ .val = 'w', .name = "pass", required_argument },
 		{0},
 	};
-	char opts[2 * ARRAY_LEN(options)];
+	char opts[3 * ARRAY_LEN(options)];
 	for (size_t i = 0, j = 0; i < ARRAY_LEN(options); ++i) {
 		opts[j++] = options[i].val;
-		if (options[i].has_arg) opts[j++] = ':';
+		if (options[i].has_arg != no_argument) opts[j++] = ':';
+		if (options[i].has_arg == optional_argument) opts[j++] = ':';
 	}
 
 	for (int opt; 0 < (opt = getopt_config(argc, argv, opts, options, NULL));) {