summary refs log tree commit diff
path: root/litterbox.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-01-04 18:41:20 -0500
committerJune McEnroe <june@causal.agency>2020-01-04 18:41:20 -0500
commitfd28b85e9709b57eef9d1062300aacf2a3b78dab (patch)
tree6765147f4d8c760b9251c46145527bdd61d89347 /litterbox.c
parentAdd -m regexp option to scoop (diff)
downloadlitterbox-fd28b85e9709b57eef9d1062300aacf2a3b78dab.tar.gz
litterbox-fd28b85e9709b57eef9d1062300aacf2a3b78dab.zip
Import getopt_config from pounce
Diffstat (limited to '')
-rw-r--r--litterbox.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/litterbox.c b/litterbox.c
index 4c97794..3fac55a 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -16,6 +16,7 @@
 
 #include <assert.h>
 #include <err.h>
+#include <getopt.h>
 #include <signal.h>
 #include <stdarg.h>
 #include <stdio.h>
@@ -27,6 +28,11 @@
 
 #include "database.h"
 
+int getopt_config(
+	int argc, char *const *argv, const char *optstring,
+	const struct option *longopts, int *longindex
+);
+
 static struct tls *client;
 
 static void clientWrite(const char *ptr, size_t len) {
@@ -624,8 +630,26 @@ int main(int argc, char *argv[]) {
 	const char *user = NULL;
 	const char *pass = NULL;
 
+	const char *Opts = "!N:Qd:h:ij:l:mn:p:qu:vw:";
+	const struct option LongOpts[] = {
+		{ "insecure", no_argument, NULL, '!' },
+		{ "network", required_argument, NULL, 'N' },
+		{ "public-query", no_argument, NULL, 'Q' },
+		{ "database", required_argument, NULL, 'd' },
+		{ "host", required_argument, NULL, 'h' },
+		{ "join", required_argument, NULL, 'j' },
+		{ "limit", required_argument, NULL, 'l' },
+		{ "nick", required_argument, NULL, 'n' },
+		{ "port", required_argument, NULL, 'p' },
+		{ "private-query", no_argument, NULL, 'q' },
+		{ "user", required_argument, NULL, 'u' },
+		{ "verbose", no_argument, NULL, 'v' },
+		{ "pass", required_argument, NULL, 'w' },
+		{0},
+	};
+
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "!N:Qd:h:ij:l:mn:p:qu:vw:"))) {
+	while (0 < (opt = getopt_config(argc, argv, Opts, LongOpts, NULL))) {
 		switch (opt) {
 			break; case '!': insecure = true;
 			break; case 'N': defaultNetwork = optarg;