summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-02 14:14:43 -0400
committerJune McEnroe <june@causal.agency>2020-04-02 14:14:43 -0400
commit06543b7030780824aa86fe4dbd4d6bca2f75ce1e (patch)
tree2842c0a796063fabbd012b28211024e6e34fb183
parentDo not add an extra blank line on uiLoad (diff)
downloadcatgirl-06543b7030780824aa86fe4dbd4d6bca2f75ce1e.tar.gz
catgirl-06543b7030780824aa86fe4dbd4d6bca2f75ce1e.zip
Generate short option string with a loop
Also change the way option structs are initialized so that the array
sorts the same way as the switch statement.
-rw-r--r--chat.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/chat.c b/chat.c
index 8ead5da..22c5665 100644
--- a/chat.c
+++ b/chat.c
@@ -127,35 +127,40 @@ int main(int argc, char *argv[]) {
 	const char *user = NULL;
 	const char *real = NULL;
 
-	const char *Opts = "!C:H:N:O:RS:a:c:eg:h:i:j:k:ln:p:r:s:u:vw:";
-	const struct option LongOpts[] = {
-		{ "insecure", no_argument, NULL, '!' },
-		{ "copy", required_argument, NULL, 'C' },
-		{ "hash", required_argument, NULL, 'H' },
-		{ "notify", required_argument, NULL, 'N' },
-		{ "open", required_argument, NULL, 'O' },
-		{ "restrict", no_argument, NULL, 'R' },
-		{ "bind", required_argument, NULL, 'S' },
-		{ "sasl-plain", required_argument, NULL, 'a' },
-		{ "cert", required_argument, NULL, 'c' },
-		{ "sasl-external", no_argument, NULL, 'e' },
-		{ "host", required_argument, NULL, 'h' },
-		{ "ignore", required_argument, NULL, 'i' },
-		{ "join", required_argument, NULL, 'j' },
-		{ "priv", required_argument, NULL, 'k' },
-		{ "log", no_argument, NULL, 'l' },
-		{ "nick", required_argument, NULL, 'n' },
-		{ "port", required_argument, NULL, 'p' },
-		{ "real", required_argument, NULL, 'r' },
-		{ "save", required_argument, NULL, 's' },
-		{ "user", required_argument, NULL, 'u' },
-		{ "debug", no_argument, NULL, 'v' },
-		{ "pass", required_argument, NULL, 'w' },
+	struct option options[] = {
+		{ .val = '!', .name = "insecure", no_argument },
+		{ .val = 'C', .name = "copy", required_argument },
+		{ .val = 'H', .name = "hash", required_argument },
+		{ .val = 'N', .name = "notify", required_argument },
+		{ .val = 'O', .name = "open", required_argument },
+		{ .val = 'R', .name = "restrict", no_argument },
+		{ .val = 'S', .name = "bind", required_argument },
+		{ .val = 'a', .name = "sasl-plain", required_argument },
+		{ .val = 'c', .name = "cert", required_argument },
+		{ .val = 'e', .name = "sasl-external", no_argument },
+		{ .val = 'g', .name = "generate", required_argument },
+		{ .val = 'h', .name = "host", required_argument },
+		{ .val = 'i', .name = "ignore", required_argument },
+		{ .val = 'j', .name = "join", required_argument },
+		{ .val = 'k', .name = "priv", required_argument },
+		{ .val = 'l', .name = "log", no_argument },
+		{ .val = 'n', .name = "nick", required_argument },
+		{ .val = 'p', .name = "port", required_argument },
+		{ .val = 'r', .name = "real", required_argument },
+		{ .val = 's', .name = "save", required_argument },
+		{ .val = 'u', .name = "user", required_argument },
+		{ .val = 'v', .name = "debug", no_argument },
+		{ .val = 'w', .name = "pass", required_argument },
 		{0},
 	};
+	char opts[2 * 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++] = ':';
+	}
 
 	int opt;
-	while (0 < (opt = getopt_config(argc, argv, Opts, LongOpts, NULL))) {
+	while (0 < (opt = getopt_config(argc, argv, opts, options, NULL))) {
 		switch (opt) {
 			break; case '!': insecure = true;
 			break; case 'C': utilPush(&urlCopyUtil, optarg);
I hate these things and also this one sucks. 2021-09-21Use Z_FILTERED strategyJune McEnroe 2021-09-21Recalculate various lengths only as neededJune McEnroe This actually speeds things up quite a bit, saving roughly a second on a big PNG screenshot. Almost all the remaining time is spent in deflate. 2021-09-21Rewrite pngo, add explicit optionsJune McEnroe Interesting to see how my code habits have changed. 2021-09-16Fix /* **/ comment matchingJune McEnroe 2021-09-15Remove typer, add downgrade to READMEJune McEnroe 2021-09-15Set bot mode on downgradeJune McEnroe 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe Also bump the message cap to 1024 because that is ostensibly useful for replying to older messages. 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe There are probably better things to sort by but title definitely always exists. 2021-09-13Swap-remove tags as they're foundJune McEnroe This makes it even faster. From ~1s on a sqlite3.c amalgamation to ~0.85s. 2021-09-12Replace htagml regex with strncmpJune McEnroe Since ctags only ever produces regular expressions of the form /^re$/ or /^re/ with no other special characters, instead unescape the pattern and simply use strncmp. Running on a sqlite3.c amalgamation, the regex version takes ~37s while the strncmp version takes ~1s, producing identical output. Big win! 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe This fixes badly indented comments. 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe