master hovercats/oakiss / pkg / catgirl / patch / 0001-Revert-Use-gnu-case-range-and-gnu-conditional-omitte.patch
  1From 3da6204de2eb2d8c74ff3ee634baefe9e7660134 Mon Sep 17 00:00:00 2001
  2From: Michael Forney <mforney@mforney.org>
  3Date: Thu, 7 May 2020 00:36:14 -0700
  4Subject: [PATCH] Revert "Use gnu-case-range and
  5 gnu-conditional-omitted-operand extensions"
  6
  7This reverts commit 75a6aa9258270169f43f56e063f1bfb57eebe56b.
  8---
  9 Makefile   |  2 --
 10 command.c  | 33 +++++++++++++++++++--------------
 11 complete.c |  4 ++--
 12 edit.c     |  2 +-
 13 handle.c   | 47 ++++++++++++++++++++++++++++-------------------
 14 input.c    |  7 ++++++-
 15 url.c      |  2 +-
 16 window.c   |  2 +-
 17 8 files changed, 58 insertions(+), 41 deletions(-)
 18
 19diff --git a/Makefile b/Makefile
 20index 66fb408..aacf43d 100644
 21--- a/Makefile
 22+++ b/Makefile
 23@@ -2,9 +2,7 @@ PREFIX ?= /usr/local
 24 BINDIR ?= ${PREFIX}/bin
 25 MANDIR ?= ${PREFIX}/man
 26 
 27-CEXTS = gnu-case-range gnu-conditional-omitted-operand
 28 CFLAGS += -std=c11 -Wall -Wextra -Wpedantic -Wmissing-prototypes
 29-CFLAGS += ${CEXTS:%=-Wno-%}
 30 LDADD.libtls = -ltls
 31 LDADD.ncursesw = -lncursesw
 32 
 33diff --git a/command.c b/command.c
 34index 502ff17..d822187 100644
 35--- a/command.c
 36+++ b/command.c
 37@@ -68,8 +68,8 @@ static int splitChunk(const char *cmd, uint id) {
 38 	int overhead = snprintf(
 39 		NULL, 0, ":%s!%*s@%*s %s %s :\r\n",
 40 		self.nick,
 41-		(self.user ? 0 : network.userLen), (self.user ?: "*"),
 42-		(self.host ? 0 : network.hostLen), (self.host ?: "*"),
 43+		(self.user ? 0 : network.userLen), (self.user ? self.user : "*"),
 44+		(self.host ? 0 : network.hostLen), (self.host ? self.host : "*"),
 45 		cmd, idNames[id]
 46 	);
 47 	assert(overhead > 0 && overhead < 512);
 48@@ -171,7 +171,7 @@ static void commandPart(uint id, char *params) {
 49 
 50 static void commandQuit(uint id, char *params) {
 51 	(void)id;
 52-	set(&self.quit, (params ?: "nyaa~"));
 53+	set(&self.quit, (params ? params : "nyaa~"));
 54 }
 55 
 56 static void commandNick(uint id, char *params) {
 57@@ -304,7 +304,7 @@ static void commandOp(uint id, char *params) {
 58 }
 59 
 60 static void commandDeop(uint id, char *params) {
 61-	channelListMode(id, '-', 'o', (params ?: self.nick));
 62+	channelListMode(id, '-', 'o', (params ? params : self.nick));
 63 }
 64 
 65 static void commandVoice(uint id, char *params) {
 66@@ -316,7 +316,7 @@ static void commandVoice(uint id, char *params) {
 67 }
 68 
 69 static void commandDevoice(uint id, char *params) {
 70-	channelListMode(id, '-', 'v', (params ?: self.nick));
 71+	channelListMode(id, '-', 'v', (params ? params : self.nick));
 72 }
 73 
 74 static void commandBan(uint id, char *params) {
 75@@ -391,12 +391,12 @@ static void commandWhowas(uint id, char *params) {
 76 
 77 static void commandNS(uint id, char *params) {
 78 	(void)id;
 79-	ircFormat("NS %s\r\n", (params ?: "HELP"));
 80+	ircFormat("NS %s\r\n", (params ? params : "HELP"));
 81 }
 82 
 83 static void commandCS(uint id, char *params) {
 84 	(void)id;
 85-	ircFormat("CS %s\r\n", (params ?: "HELP"));
 86+	ircFormat("CS %s\r\n", (params ? params : "HELP"));
 87 }
 88 
 89 static void commandQuery(uint id, char *params) {
 90@@ -472,7 +472,8 @@ static void commandFilter(enum Heat heat, uint id, char *params) {
 91 		uiFormat(
 92 			id, Cold, NULL, "%sing \3%02d%s %s %s %s",
 93 			(heat == Hot ? "Highlight" : "Ignor"), Brown, filter.mask,
 94-			(filter.cmd ?: ""), (filter.chan ?: ""), (filter.mesg ?: "")
 95+			(filter.cmd ? filter.cmd : ""), (filter.chan ? filter.chan : ""),
 96+			(filter.mesg ? filter.mesg : "")
 97 		);
 98 	} else {
 99 		for (size_t i = 0; i < FilterCap && filters[i].mask; ++i) {
100@@ -480,8 +481,9 @@ static void commandFilter(enum Heat heat, uint id, char *params) {
101 			uiFormat(
102 				Network, Warm, NULL, "%sing \3%02d%s %s %s %s",
103 				(heat == Hot ? "Highlight" : "Ignor"), Brown, filters[i].mask,
104-				(filters[i].cmd ?: ""), (filters[i].chan ?: ""),
105-				(filters[i].mesg ?: "")
106+				(filters[i].cmd ? filters[i].cmd : ""),
107+				(filters[i].chan ? filters[i].chan : ""),
108+				(filters[i].mesg ? filters[i].mesg : "")
109 			);
110 		}
111 	}
112@@ -494,8 +496,8 @@ static void commandUnfilter(enum Heat heat, uint id, char *params) {
113 	uiFormat(
114 		id, Cold, NULL, "%s %sing \3%02d%s %s %s %s",
115 		(found ? "No longer" : "Not"), (heat == Hot ? "highlight" : "ignor"),
116-		Brown, filter.mask, (filter.cmd ?: ""), (filter.chan ?: ""),
117-		(filter.mesg ?: "")
118+		Brown, filter.mask, (filter.cmd ? filter.cmd : ""),
119+		(filter.chan ? filter.chan : ""), (filter.mesg ? filter.mesg : "")
120 	);
121 }
122 
123@@ -524,7 +526,9 @@ static void commandExec(uint id, char *params) {
124 	dup2(execPipe[1], STDOUT_FILENO);
125 	dup2(utilPipe[1], STDERR_FILENO);
126 
127-	const char *shell = getenv("SHELL") ?: "/bin/sh";
128+	const char *shell = getenv("SHELL");
129+	if (!shell)
130+		shell = "/bin/sh";
131 	execl(shell, shell, "-c", params, NULL);
132 	warn("%s", shell);
133 	_exit(EX_UNAVAILABLE);
134@@ -549,7 +553,8 @@ static void commandHelp(uint id, char *params) {
135 	if (pid) return;
136 
137 	char buf[256];
138-	snprintf(buf, sizeof(buf), "%sp^COMMANDS$", (getenv("LESS") ?: ""));
139+	const char *less = getenv("LESS");
140+	snprintf(buf, sizeof(buf), "%sp^COMMANDS$", (less ? less : ""));
141 	setenv("LESS", buf, 1);
142 	execlp("man", "man", "1", "catgirl", NULL);
143 	dup2(utilPipe[1], STDERR_FILENO);
144diff --git a/complete.c b/complete.c
145index 3552c7c..7d24c7c 100644
146--- a/complete.c
147+++ b/complete.c
148@@ -71,7 +71,7 @@ static struct Node *prepend(struct Node *node) {
149 	node->next = head;
150 	if (head) head->prev = node;
151 	head = node;
152-	tail = (tail ?: node);
153+	if (!tail) tail = node;
154 	return node;
155 }
156 
157@@ -80,7 +80,7 @@ static struct Node *append(struct Node *node) {
158 	node->prev = tail;
159 	if (tail) tail->next = node;
160 	tail = node;
161-	head = (head ?: node);
162+	if (!head) head = node;
163 	return node;
164 }
165 
166diff --git a/edit.c b/edit.c
167index effb623..3c503d1 100644
168--- a/edit.c
169+++ b/edit.c
170@@ -69,7 +69,7 @@ int editReserve(struct Edit *e, size_t index, size_t count) {
171 		return -1;
172 	}
173 	if (e->len + count > e->cap) {
174-		size_t cap = (e->cap ?: 256);
175+		size_t cap = (e->cap ? e->cap : 256);
176 		while (cap < e->len + count) cap *= 2;
177 		wchar_t *buf = realloc(e->buf, sizeof(*buf) * cap);
178 		if (!buf) return -1;
179diff --git a/handle.c b/handle.c
180index 5a2cf7c..b973161 100644
181--- a/handle.c
182+++ b/handle.c
183@@ -332,9 +332,9 @@ static void handleReplyISupport(struct Message *msg) {
184 			set(&network.setParamModes, setParam);
185 			set(&network.channelModes, channel);
186 		} else if (!strcmp(key, "EXCEPTS")) {
187-			network.excepts = (msg->params[i] ?: "e")[0];
188+			network.excepts = (msg->params[i] ? msg->params[i][0] : 'e');
189 		} else if (!strcmp(key, "INVEX")) {
190-			network.invex = (msg->params[i] ?: "I")[0];
191+			network.invex = (msg->params[i] ? msg->params[i][0] : 'I');
192 		}
193 	}
194 }
195@@ -387,7 +387,7 @@ static void handleJoin(struct Message *msg) {
196 		"\3%02d%s\3\t%s%s%sarrives in \3%02d%s\3",
197 		hash(msg->user), msg->nick,
198 		(msg->params[2] ? "(" : ""),
199-		(msg->params[2] ?: ""),
200+		(msg->params[2] ? msg->params[2] : ""),
201 		(msg->params[2] ? "\17) " : ""),
202 		hash(msg->params[0]), msg->params[0]
203 	);
204@@ -419,12 +419,14 @@ static void handlePart(struct Message *msg) {
205 		id, heat, tagTime(msg),
206 		"\3%02d%s\3\tleaves \3%02d%s\3%s%s",
207 		hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0],
208-		(msg->params[1] ? ": " : ""), (msg->params[1] ?: "")
209+		(msg->params[1] ? ": " : ""),
210+		(msg->params[1] ? msg->params[1] : "")
211 	);
212 	logFormat(
213 		id, tagTime(msg), "%s leaves %s%s%s",
214 		msg->nick, msg->params[0],
215-		(msg->params[1] ? ": " : ""), (msg->params[1] ?: "")
216+		(msg->params[1] ? ": " : ""),
217+		(msg->params[1] ? msg->params[1] : "")
218 	);
219 }
220 
221@@ -441,12 +443,14 @@ static void handleKick(struct Message *msg) {
222 		hash(msg->user), msg->nick,
223 		completeColor(id, msg->params[1]), msg->params[1],
224 		hash(msg->params[0]), msg->params[0],
225-		(msg->params[2] ? ": " : ""), (msg->params[2] ?: "")
226+		(msg->params[2] ? ": " : ""),
227+		(msg->params[2] ? msg->params[2] : "")
228 	);
229 	logFormat(
230 		id, tagTime(msg), "%s kicks %s out of %s%s%s",
231 		msg->nick, msg->params[1], msg->params[0],
232-		(msg->params[2] ? ": " : ""), (msg->params[2] ?: "")
233+		(msg->params[2] ? ": " : ""),
234+		(msg->params[2] ? msg->params[2] : "")
235 	);
236 	completeRemove(id, msg->params[1]);
237 	if (kicked) completeRemove(id, NULL);
238@@ -500,13 +504,15 @@ static void handleQuit(struct Message *msg) {
239 			id, heat, tagTime(msg),
240 			"\3%02d%s\3\tleaves%s%s",
241 			hash(msg->user), msg->nick,
242-			(msg->params[0] ? ": " : ""), (msg->params[0] ?: "")
243+			(msg->params[0] ? ": " : ""),
244+			(msg->params[0] ? msg->params[0] : "")
245 		);
246 		if (id == Network) continue;
247 		logFormat(
248 			id, tagTime(msg), "%s leaves%s%s",
249 			msg->nick,
250-			(msg->params[0] ? ": " : ""), (msg->params[0] ?: "")
251+			(msg->params[0] ? ": " : ""),
252+			(msg->params[0] ? msg->params[0] : "")
253 		);
254 	}
255 	completeRemove(None, msg->nick);
256@@ -760,7 +766,7 @@ static void handleReplyUserModeIs(struct Message *msg) {
257 		if (*ch == '+') continue;
258 		const char *name = UserModes[(byte)*ch];
259 		ptr = seprintf(
260-			ptr, end, ", +%c%s%s", *ch, (name ? " " : ""), (name ?: "")
261+			ptr, end, ", +%c%s%s", *ch, (name ? " " : ""), (name ? name : "")
262 		);
263 	}
264 	uiFormat(
265@@ -800,13 +806,13 @@ static void handleReplyChannelModeIs(struct Message *msg) {
266 			assert(param < ParamCap);
267 			ptr = seprintf(
268 				ptr, end, ", +%c%s%s %s",
269-				*ch, (name ? " " : ""), (name ?: ""),
270+				*ch, (name ? " " : ""), (name ? name : ""),
271 				msg->params[param++]
272 			);
273 		} else {
274 			ptr = seprintf(
275 				ptr, end, ", +%c%s%s",
276-				*ch, (name ? " " : ""), (name ?: "")
277+				*ch, (name ? " " : ""), (name ? name : "")
278 			);
279 		}
280 	}
281@@ -833,7 +839,7 @@ static void handleMode(struct Message *msg) {
282 				hash(msg->user), msg->nick,
283 				(set ? "" : "un"),
284 				self.color, msg->params[0],
285-				set["-+"], *ch, (name ? " " : ""), (name ?: "")
286+				set["-+"], *ch, (name ? " " : ""), (name ? name : "")
287 			);
288 		}
289 		return;
290@@ -996,7 +1002,7 @@ static void handleErrorBanListFull(struct Message *msg) {
291 	require(msg, false, 4);
292 	uiFormat(
293 		idFor(msg->params[1]), Warm, tagTime(msg),
294-		"%s", (msg->params[4] ?: msg->params[3])
295+		"%s", (msg->params[4] ? msg->params[4] : msg->params[3])
296 	);
297 }
298 
299@@ -1061,7 +1067,7 @@ static void handleReplyList(struct Message *msg) {
300 		"In \3%02d%s\3 are %ld under the banner: %s",
301 		hash(msg->params[1]), msg->params[1],
302 		strtol(msg->params[2], NULL, 10),
303-		(msg->params[3] ?: "")
304+		(msg->params[3] ? msg->params[3] : "")
305 	);
306 }
307 
308@@ -1101,14 +1107,15 @@ static void handleReplyWhoisIdle(struct Message *msg) {
309 		}
310 	}
311 	char signon[sizeof("0000-00-00 00:00:00")];
312-	time_t time = strtol((msg->params[3] ?: ""), NULL, 10);
313+	time_t time = (msg->params[3] ? strtol(msg->params[3], NULL, 10) : 0);
314 	strftime(signon, sizeof(signon), "%F %T", localtime(&time));
315 	uiFormat(
316 		Network, Warm, tagTime(msg),
317 		"\3%02d%s\3\tis idle for %lu %s%s%s%s",
318 		completeColor(Network, msg->params[1]), msg->params[1],
319 		idle, unit, (idle != 1 ? "s" : ""),
320-		(msg->params[3] ? ", signed on " : ""), (msg->params[3] ? signon : "")
321+		(msg->params[3] ? ", signed on " : ""),
322+		(msg->params[3] ? signon : "")
323 	);
324 }
325 
326@@ -1143,7 +1150,9 @@ static void handleReplyWhoisGeneric(struct Message *msg) {
327 		Network, Warm, tagTime(msg),
328 		"\3%02d%s\3\t%s%s%s",
329 		completeColor(Network, msg->params[1]), msg->params[1],
330-		msg->params[2], (msg->params[3] ? " " : ""), (msg->params[3] ?: "")
331+		msg->params[2],
332+		(msg->params[3] ? " " : ""),
333+		(msg->params[3] ? msg->params[3] : "")
334 	);
335 }
336 
337@@ -1213,7 +1222,7 @@ static bool matchWord(const char *str, const char *word) {
338 	const char *match = str;
339 	while (NULL != (match = strstr(match, word))) {
340 		char a = (match > str ? match[-1] : ' ');
341-		char b = (match[len] ?: ' ');
342+		char b = (match[len] ? match[len] : ' ');
343 		if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) {
344 			return true;
345 		}
346diff --git a/input.c b/input.c
347index 6b33b93..9334315 100644
348--- a/input.c
349+++ b/input.c
350@@ -418,7 +418,6 @@ static void keyCode(int code) {
351 		break; case KeyMetaGt: windowScroll(ScrollAll, -1);
352 		break; case KeyMetaLt: windowScroll(ScrollAll, +1);
353 
354-		break; case KeyMeta0 ... KeyMeta9: windowShow(code - KeyMeta0);
355 		break; case KeyMetaA: windowAuto();
356 		break; case KeyMetaB: error = editFn(edit, EditPrevWord);
357 		break; case KeyMetaD: error = editFn(edit, EditDeleteNextWord);
358@@ -449,6 +448,12 @@ static void keyCode(int code) {
359 		break; case KEY_SEND: windowScroll(ScrollAll, -1);
360 		break; case KEY_SHOME: windowScroll(ScrollAll, +1);
361 		break; case KEY_UP: windowScroll(ScrollOne, +1);
362+
363+		break; default: {
364+			if (code >= KeyMeta0 && code <= KeyMeta9) {
365+				windowShow(code - KeyMeta0);
366+			}
367+		}
368 	}
369 	if (error) err(EX_OSERR, "editFn");
370 }
371diff --git a/url.c b/url.c
372index 7da0968..c1cb917 100644
373--- a/url.c
374+++ b/url.c
375@@ -249,7 +249,7 @@ int urlSave(FILE *file) {
376 		if (!url->url) continue;
377 		int error = 0
378 			|| writeString(file, idNames[url->id])
379-			|| writeString(file, (url->nick ?: ""))
380+			|| writeString(file, (url->nick ? url->nick : ""))
381 			|| writeString(file, url->url);
382 		if (error) return error;
383 	}
384diff --git a/window.c b/window.c
385index f700fd7..aadf646 100644
386--- a/window.c
387+++ b/window.c
388@@ -221,7 +221,7 @@ static size_t windowTop(const struct Window *window) {
389 }
390 
391 static size_t windowBottom(const struct Window *window) {
392-	size_t bottom = BufferCap - (window->scroll ?: 1);
393+	size_t bottom = BufferCap - (window->scroll ? window->scroll : 1);
394 	if (window->scroll) bottom -= SplitLines + MarkerLines;
395 	return bottom;
396 }
397-- 
3982.49.0
399