about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-02 16:29:36 -0400
committerJune McEnroe <june@causal.agency>2020-04-02 16:29:36 -0400
commitd156d07f44536bca14c847f7f5313c956a625f96 (patch)
tree805442ac51f29a9e62adf85730b4db9b173da14f
parentUpdate unscoop catgirl matchers (diff)
downloadlitterbox-d156d07f44536bca14c847f7f5313c956a625f96.tar.gz
litterbox-d156d07f44536bca14c847f7f5313c956a625f96.zip
Update style
Replacing declarations followed by while loops with for loops and
generating the short option string from the long options.
-rw-r--r--litterbox.c47
-rw-r--r--scoop.c3
-rw-r--r--unscoop.c6
3 files changed, 29 insertions, 27 deletions
diff --git a/litterbox.c b/litterbox.c
index 1591b39..14dd626 100644
--- a/litterbox.c
+++ b/litterbox.c
@@ -474,8 +474,7 @@ static void clearJoins(const char *nick, const char *channel) {
 
 static void handleReplyNames(struct Message *msg) {
 	require(msg, false, 3);
-	char *names = msg->params[3];
-	while (names) {
+	for (char *names = msg->params[3]; names;) {
 		char *nick = strsep(&names, " ");
 		nick += strspn(nick, prefixes);
 		insertJoin(nick, msg->params[2]);
@@ -677,28 +676,34 @@ int main(int argc, char *argv[]) {
 	const char *user = NULL;
 	const char *pass = NULL;
 
-	const char *Opts = "!N:Qb:c:d:h:ij:k:l:mn:p:qu:vw:";
-	const struct option LongOpts[] = {
-		{ "insecure", no_argument, NULL, '!' },
-		{ "network", required_argument, NULL, 'N' },
-		{ "public-query", no_argument, NULL, 'Q' },
-		{ "cert", required_argument, NULL, 'c' },
-		{ "database", required_argument, NULL, 'd' },
-		{ "host", required_argument, NULL, 'h' },
-		{ "join", required_argument, NULL, 'j' },
-		{ "priv", required_argument, NULL, 'k' },
-		{ "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' },
+	struct option options[] = {
+		{ .val = '!', .name = "insecure", no_argument },
+		{ .val = 'N', .name = "network", required_argument },
+		{ .val = 'Q', .name = "public-query", no_argument },
+		{ .val = 'b', .name = "backup", required_argument },
+		{ .val = 'c', .name = "cert", required_argument },
+		{ .val = 'd', .name = "database", required_argument },
+		{ .val = 'h', .name = "host", required_argument },
+		{ .val = 'i', .name = "init", no_argument },
+		{ .val = 'j', .name = "join", required_argument },
+		{ .val = 'k', .name = "priv", required_argument },
+		{ .val = 'l', .name = "limit", required_argument },
+		{ .val = 'm', .name = "migrate", no_argument },
+		{ .val = 'n', .name = "nick", required_argument },
+		{ .val = 'p', .name = "port", required_argument },
+		{ .val = 'q', .name = "private-query", no_argument },
+		{ .val = 'u', .name = "user", required_argument },
+		{ .val = 'v', .name = "verbose", 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))) {
+	for (int opt; 0 < (opt = getopt_config(argc, argv, opts, options, NULL));) {
 		switch (opt) {
 			break; case '!': insecure = true;
 			break; case 'N': defaultNetwork = optarg;
diff --git a/scoop.c b/scoop.c
index 7750a47..a1b75c7 100644
--- a/scoop.c
+++ b/scoop.c
@@ -385,9 +385,8 @@ int main(int argc, char *argv[]) {
 	const char *search = NULL;
 	const char *where = NULL;
 
-	int opt;
 	const char *Opts = "D:F:LN:T:a:b:c:d:f:gh:l:m:n:pqst:u:vw:";
-	while (0 < (opt = getopt(argc, argv, Opts))) {
+	for (int opt; 0 < (opt = getopt(argc, argv, Opts));) {
 		switch (opt) {
 			break; case 'D': binds[n++] = Bind(":date", optarg, 0);
 			break; case 'F': binds[n++] = Bind(":format", optarg, 0);
diff --git a/unscoop.c b/unscoop.c
index afc42b5..6e7b362 100644
--- a/unscoop.c
+++ b/unscoop.c
@@ -305,8 +305,7 @@ int main(int argc, char *argv[]) {
 	const char *context = NULL;
 	const struct Format *format = &Formats[0];
 
-	int opt;
-	while (0 < (opt = getopt(argc, argv, "DN:c:d:f:v"))) {
+	for (int opt; 0 < (opt = getopt(argc, argv, "DN:c:d:f:v"));) {
 		switch (opt) {
 			break; case 'D': dedup = true;
 			break; case 'N': network = optarg;
@@ -391,8 +390,7 @@ int main(int argc, char *argv[]) {
 		}
 		dbRun(insertContext);
 
-		ssize_t len;
-		while (0 < (len = getline(&line, &cap, file))) {
+		for (ssize_t len; 0 < (len = getline(&line, &cap, file));) {
 			matchLine(format, regex, line);
 			sizeRead += len;
 			if (100 * sizeRead / sizeTotal != sizePercent) {