From fceb6d1300a651bf4bb544978c743330f98d3ead Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Thu, 7 May 2020 00:36:14 -0700 Subject: [PATCH] Revert "Use gnu-case-range and gnu-conditional-omitted-operand extensions" This reverts commit 75a6aa9258270169f43f56e063f1bfb57eebe56b. --- Makefile | 3 +-- command.c | 32 ++++++++++++++++++-------------- complete.c | 4 ++-- handle.c | 45 +++++++++++++++++++++++++++------------------ ui.c | 9 +++++++-- url.c | 2 +- 6 files changed, 56 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 5caa3ba..d164315 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,7 @@ PREFIX ?= /usr/local MANDIR ?= ${PREFIX}/share/man -CEXTS = gnu-case-range gnu-conditional-omitted-operand -CFLAGS += -std=c11 -Wall -Wextra -Wpedantic ${CEXTS:%=-Wno-%} +CFLAGS += -std=c11 -Wall -Wextra -Wpedantic LDLIBS = -lncursesw -ltls -include config.mk diff --git a/command.c b/command.c index 1154942..93b7478 100644 --- a/command.c +++ b/command.c @@ -69,8 +69,8 @@ static void splitMessage(char *cmd, uint id, char *params) { int overhead = snprintf( NULL, 0, ":%s!%*s@%*s %s %s :\r\n", self.nick, - (self.user ? 0 : network.userLen), (self.user ?: "*"), - (self.host ? 0 : network.hostLen), (self.host ?: "*"), + (self.user ? 0 : network.userLen), (self.user ? self.user : "*"), + (self.host ? 0 : network.hostLen), (self.host ? self.host : "*"), cmd, idNames[id] ); assert(overhead > 0 && overhead < 512); @@ -109,7 +109,7 @@ static void commandNotice(uint id, char *params) { static void commandMe(uint id, char *params) { char buf[512]; - snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ?: "")); + snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ? params : "")); echoMessage("PRIVMSG", id, buf); } @@ -140,7 +140,7 @@ static void commandPart(uint id, char *params) { static void commandQuit(uint id, char *params) { (void)id; - set(&self.quit, (params ?: "nyaa~")); + set(&self.quit, (params ? params : "nyaa~")); } static void commandNick(uint id, char *params) { @@ -238,7 +238,7 @@ static void commandOp(uint id, char *params) { } static void commandDeop(uint id, char *params) { - channelListMode(id, '-', 'o', (params ?: self.nick)); + channelListMode(id, '-', 'o', (params ? params : self.nick)); } static void commandVoice(uint id, char *params) { @@ -250,7 +250,7 @@ static void commandVoice(uint id, char *params) { } static void commandDevoice(uint id, char *params) { - channelListMode(id, '-', 'v', (params ?: self.nick)); + channelListMode(id, '-', 'v', (params ? params : self.nick)); } static void commandBan(uint id, char *params) { @@ -392,7 +392,8 @@ static void commandFilter(enum Heat heat, uint id, char *params) { uiFormat( id, Cold, NULL, "%sing \3%02d%s %s %s %s", (heat == Hot ? "Highlight" : "Ignor"), Brown, filter.mask, - (filter.cmd ?: ""), (filter.chan ?: ""), (filter.mesg ?: "") + (filter.cmd ? filter.cmd : ""), (filter.chan ? filter.chan : ""), + (filter.mesg ? filter.mesg : "") ); } else { for (size_t i = 0; i < FilterCap && filters[i].mask; ++i) { @@ -400,8 +401,9 @@ static void commandFilter(enum Heat heat, uint id, char *params) { uiFormat( Network, Warm, NULL, "%sing \3%02d%s %s %s %s", (heat == Hot ? "Highlight" : "Ignor"), Brown, filters[i].mask, - (filters[i].cmd ?: ""), (filters[i].chan ?: ""), - (filters[i].mesg ?: "") + (filters[i].cmd ? filters[i].cmd : ""), + (filters[i].chan ? filters[i].chan : ""), + (filters[i].mesg ? filters[i].mesg : "") ); } } @@ -414,8 +416,8 @@ static void commandUnfilter(enum Heat heat, uint id, char *params) { uiFormat( id, Cold, NULL, "%s %sing \3%02d%s %s %s %s", (found ? "No longer" : "Not"), (heat == Hot ? "highlight" : "ignor"), - Brown, filter.mask, (filter.cmd ?: ""), (filter.chan ?: ""), - (filter.mesg ?: "") + Brown, filter.mask, (filter.cmd ? filter.cmd : ""), + (filter.chan ? filter.chan : ""), (filter.mesg ? filter.mesg : "") ); } @@ -439,11 +441,12 @@ static void commandExec(uint id, char *params) { if (pid < 0) err(EX_OSERR, "fork"); if (pid) return; + const char *shell = getenv("SHELL"); + if (!shell) shell = "/bin/sh"; + close(STDIN_FILENO); dup2(execPipe[1], STDOUT_FILENO); dup2(utilPipe[1], STDERR_FILENO); - - const char *shell = getenv("SHELL") ?: "/bin/sh"; execl(shell, shell, "-c", params, NULL); warn("%s", shell); _exit(EX_UNAVAILABLE); @@ -468,7 +471,8 @@ static void commandHelp(uint id, char *params) { if (pid) return; char buf[256]; - snprintf(buf, sizeof(buf), "%sp^COMMANDS$", (getenv("LESS") ?: "")); + const char *less = getenv("LESS"); + snprintf(buf, sizeof(buf), "%sp^COMMANDS$", (less ? less : "")); setenv("LESS", buf, 1); execlp("man", "man", "1", "catgirl", NULL); dup2(utilPipe[1], STDERR_FILENO); diff --git a/complete.c b/complete.c index 5835926..0e1de47 100644 --- a/complete.c +++ b/complete.c @@ -71,7 +71,7 @@ static struct Node *prepend(struct Node *node) { node->next = head; if (head) head->prev = node; head = node; - tail = (tail ?: node); + if (!tail) tail = node; return node; } @@ -80,7 +80,7 @@ static struct Node *append(struct Node *node) { node->prev = tail; if (tail) tail->next = node; tail = node; - head = (head ?: node); + if (!head) head = node; return node; } diff --git a/handle.c b/handle.c index 44001bb..caba5ff 100644 --- a/handle.c +++ b/handle.c @@ -290,9 +290,9 @@ static void handleReplyISupport(struct Message *msg) { set(&network.setParamModes, setParam); set(&network.channelModes, channel); } else if (!strcmp(key, "EXCEPTS")) { - network.excepts = (msg->params[i] ?: "e")[0]; + network.excepts = (msg->params[i] ? msg->params[i][0] : 'e'); } else if (!strcmp(key, "INVEX")) { - network.invex = (msg->params[i] ?: "I")[0]; + network.invex = (msg->params[i] ? msg->params[i][0] : 'I'); } } } @@ -345,7 +345,7 @@ static void handleJoin(struct Message *msg) { "\3%02d%s\3\t%s%s%sarrives in \3%02d%s\3", hash(msg->user), msg->nick, (msg->params[2] ? "(" : ""), - (msg->params[2] ?: ""), + (msg->params[2] ? msg->params[2] : ""), (msg->params[2] ? ") " : ""), hash(msg->params[0]), msg->params[0] ); @@ -377,12 +377,14 @@ static void handlePart(struct Message *msg) { id, heat, tagTime(msg), "\3%02d%s\3\tleaves \3%02d%s\3%s%s", hash(msg->user), msg->nick, hash(msg->params[0]), msg->params[0], - (msg->params[1] ? ": " : ""), (msg->params[1] ?: "") + (msg->params[1] ? ": " : ""), + (msg->params[1] ? msg->params[1] : "") ); logFormat( id, tagTime(msg), "%s leaves %s%s%s", msg->nick, msg->params[0], - (msg->params[1] ? ": " : ""), (msg->params[1] ?: "") + (msg->params[1] ? ": " : ""), + (msg->params[1] ? msg->params[1] : "") ); } @@ -399,12 +401,14 @@ static void handleKick(struct Message *msg) { hash(msg->user), msg->nick, completeColor(id, msg->params[1]), msg->params[1], hash(msg->params[0]), msg->params[0], - (msg->params[2] ? ": " : ""), (msg->params[2] ?: "") + (msg->params[2] ? ": " : ""), + (msg->params[2] ? msg->params[2] : "") ); logFormat( id, tagTime(msg), "%s kicks %s out of %s%s%s", msg->nick, msg->params[1], msg->params[0], - (msg->params[2] ? ": " : ""), (msg->params[2] ?: "") + (msg->params[2] ? ": " : ""), + (msg->params[2] ? msg->params[2] : "") ); completeRemove(id, msg->params[1]); if (kicked) completeClear(id); @@ -455,13 +459,15 @@ static void handleQuit(struct Message *msg) { id, heat, tagTime(msg), "\3%02d%s\3\tleaves%s%s", hash(msg->user), msg->nick, - (msg->params[0] ? ": " : ""), (msg->params[0] ?: "") + (msg->params[0] ? ": " : ""), + (msg->params[0] ? msg->params[0] : "") ); if (id == Network) continue; logFormat( id, tagTime(msg), "%s leaves%s%s", msg->nick, - (msg->params[0] ? ": " : ""), (msg->params[0] ?: "") + (msg->params[0] ? ": " : ""), + (msg->params[0] ? msg->params[0] : "") ); } completeRemove(None, msg->nick); @@ -696,7 +702,7 @@ static void handleReplyUserModeIs(struct Message *msg) { for (char *ch = msg->params[1]; *ch; ++ch) { if (*ch == '+') continue; const char *name = UserModes[(byte)*ch]; - catf(&cat, ", +%c%s%s", *ch, (name ? " " : ""), (name ?: "")); + catf(&cat, ", +%c%s%s", *ch, (name ? " " : ""), (name ? name : "")); } uiFormat( Network, Warm, tagTime(msg), @@ -735,13 +741,13 @@ static void handleReplyChannelModeIs(struct Message *msg) { assert(param < ParamCap); catf( &cat, ", +%c%s%s %s", - *ch, (name ? " " : ""), (name ?: ""), + *ch, (name ? " " : ""), (name ? name : ""), msg->params[param++] ); } else { catf( &cat, ", +%c%s%s", - *ch, (name ? " " : ""), (name ?: "") + *ch, (name ? " " : ""), (name ? name : "") ); } } @@ -768,7 +774,7 @@ static void handleMode(struct Message *msg) { hash(msg->user), msg->nick, (set ? "" : "un"), self.color, msg->params[0], - set["-+"], *ch, (name ? " " : ""), (name ?: "") + set["-+"], *ch, (name ? " " : ""), (name ? name : "") ); } return; @@ -925,7 +931,7 @@ static void handleErrorBanListFull(struct Message *msg) { require(msg, false, 4); uiFormat( idFor(msg->params[1]), Warm, tagTime(msg), - "%s", (msg->params[4] ?: msg->params[3]) + "%s", (msg->params[4] ? msg->params[4] : msg->params[3]) ); } @@ -1030,14 +1036,15 @@ static void handleReplyWhoisIdle(struct Message *msg) { } } char signon[sizeof("0000-00-00 00:00:00")]; - time_t time = strtol((msg->params[3] ?: ""), NULL, 10); + time_t time = (msg->params[3] ? strtol(msg->params[3], NULL, 10) : 0); strftime(signon, sizeof(signon), "%F %T", localtime(&time)); uiFormat( Network, Warm, tagTime(msg), "\3%02d%s\3\tis idle for %lu %s%s%s%s", completeColor(Network, msg->params[1]), msg->params[1], idle, unit, (idle != 1 ? "s" : ""), - (msg->params[3] ? ", signed on " : ""), (msg->params[3] ? signon : "") + (msg->params[3] ? ", signed on " : ""), + (msg->params[3] ? signon : "") ); } @@ -1068,7 +1075,9 @@ static void handleReplyWhoisGeneric(struct Message *msg) { Network, Warm, tagTime(msg), "\3%02d%s\3\t%s%s%s", completeColor(Network, msg->params[1]), msg->params[1], - msg->params[2], (msg->params[3] ? " " : ""), (msg->params[3] ?: "") + msg->params[2], + (msg->params[3] ? " " : ""), + (msg->params[3] ? msg->params[3] : "") ); } @@ -1135,7 +1144,7 @@ static bool isMention(const struct Message *msg) { const char *match = msg->params[1]; while (NULL != (match = strstr(match, self.nick))) { char a = (match > msg->params[1] ? match[-1] : ' '); - char b = (match[len] ?: ' '); + char b = (match[len] ? match[len] : ' '); if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) { return true; } diff --git a/ui.c b/ui.c index 557d0dc..91a6993 100644 --- a/ui.c +++ b/ui.c @@ -470,7 +470,7 @@ static size_t windowTop(const struct Window *window) { } static size_t windowBottom(const struct Window *window) { - size_t bottom = BufferCap - (window->scroll ?: 1); + size_t bottom = BufferCap - (window->scroll ? window->scroll : 1); if (window->scroll) bottom -= SplitLines + MarkerLines; return bottom; } @@ -920,7 +920,6 @@ static void keyCode(int code) { break; case KeyMetaGt: scrollTo(window, 0); break; case KeyMetaLt: scrollTop(window); - break; case KeyMeta0 ... KeyMeta9: uiShowNum(code - KeyMeta0); break; case KeyMetaA: showAuto(); break; case KeyMetaB: edit(id, EditPrevWord, 0); break; case KeyMetaD: edit(id, EditDeleteNextWord, 0); @@ -947,6 +946,12 @@ static void keyCode(int code) { break; case KEY_SEND: scrollTo(window, 0); break; case KEY_SHOME: scrollTo(window, BufferCap); break; case KEY_UP: windowScroll(window, +1); + + break; default: { + if (code >= KeyMeta0 && code <= KeyMeta9) { + uiShowNum(code - KeyMeta0); + } + } } } diff --git a/url.c b/url.c index 21f946c..1330d36 100644 --- a/url.c +++ b/url.c @@ -246,7 +246,7 @@ int urlSave(FILE *file) { if (!url->url) continue; int error = 0 || writeString(file, idNames[url->id]) - || writeString(file, (url->nick ?: "")) + || writeString(file, (url->nick ? url->nick : "")) || writeString(file, url->url); if (error) return error; } -- 2.30.0