summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--command.c15
-rw-r--r--complete.c4
-rw-r--r--handle.c45
-rw-r--r--ignore.c3
-rw-r--r--ui.c7
6 files changed, 31 insertions, 46 deletions
diff --git a/Makefile b/Makefile
index 4a610b7..68e673b 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,8 @@
PREFIX = /usr/local
MANDIR = ${PREFIX}/share/man
-CFLAGS += -std=c11 -Wall -Wextra -Wpedantic
+CEXTS = gnu-case-range gnu-conditional-omitted-operand
+CFLAGS += -std=c11 -Wall -Wextra -Wpedantic ${CEXTS:%=-Wno-%}
LDLIBS = -lcrypto -ltls -lncursesw
-include config.mk
diff --git a/command.c b/command.c
index adcc0c8..ca8dfa3 100644
--- a/command.c
+++ b/command.c
@@ -58,8 +58,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.user : "*"),
- (self.host ? 0 : network.hostLen), (self.host ? self.host : "*"),
+ (self.user ? 0 : network.userLen), (self.user ?: "*"),
+ (self.host ? 0 : network.hostLen), (self.host ?: "*"),
cmd, idNames[id]
);
assert(overhead > 0 && overhead < 512);
@@ -98,7 +98,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 ? params : ""));
+ snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ?: ""));
echoMessage("PRIVMSG", id, buf);
}
@@ -129,7 +129,7 @@ static void commandPart(uint id, char *params) {
static void commandQuit(uint id, char *params) {
(void)id;
- set(&self.quit, (params ? params : "nyaa~"));
+ set(&self.quit, (params ?: "nyaa~"));
}
static void commandNick(uint id, char *params) {
@@ -384,12 +384,11 @@ 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";
execlp(shell, shell, "-c", params, NULL);
warn("%s", shell);
_exit(EX_UNAVAILABLE);
@@ -404,7 +403,7 @@ static void commandHelp(uint id, char *params) {
if (pid) return;
char buf[256];
- snprintf(buf, sizeof(buf), "ip%s$", (params ? params : "COMMANDS"));
+ snprintf(buf, sizeof(buf), "ip%s$", (params ?: "COMMANDS"));
setenv("LESS", buf, 1);
execlp("man", "man", "1", "catgirl", NULL);
dup2(utilPipe[1], STDERR_FILENO);
diff --git a/complete.c b/complete.c
index ad9bfd7..d23932c 100644
--- a/complete.c
+++ b/complete.c
@@ -60,7 +60,7 @@ static struct Node *prepend(struct Node *node) {
node->next = head;
if (head) head->prev = node;
head = node;
- if (!tail) tail = node;
+ tail = (tail ?: node);
return node;
}
@@ -69,7 +69,7 @@ static struct Node *append(struct Node *node) {
node->prev = tail;
if (tail) tail->next = node;
tail = node;
- if (!head) head = node;
+ head = (head ?: node);
return node;
}
diff --git a/handle.c b/handle.c
index a98c316..00e854c 100644
--- a/handle.c
+++ b/handle.c
@@ -260,9 +260,9 @@ static void handleReplyISupport(struct Message *msg) {
set(&network.setParamModes, strsep(&msg->params[i], ","));
set(&network.channelModes, strsep(&msg->params[i], ","));
} else if (!strcmp(key, "EXCEPTS")) {
- network.excepts = (msg->params[i] ? msg->params[i][0] : 'e');
+ network.excepts = (msg->params[i] ?: "e")[0];
} else if (!strcmp(key, "INVEX")) {
- network.invex = (msg->params[i] ? msg->params[i][0] : 'I');
+ network.invex = (msg->params[i] ?: "I")[0];
}
}
}
@@ -309,7 +309,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]
);
@@ -340,14 +340,12 @@ static void handlePart(struct Message *msg) {
id, ignoreCheck(Cold, msg), 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] ?: "")
);
}
@@ -364,14 +362,12 @@ 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);
@@ -409,15 +405,13 @@ static void handleQuit(struct Message *msg) {
id, ignoreCheck(Cold, msg), 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);
@@ -576,7 +570,7 @@ static void handleReplyUserModeIs(struct Message *msg) {
const char *name = UserModes[(byte)*ch];
catf(
buf, sizeof(buf), ", +%c%s%s",
- *ch, (name ? " " : ""), (name ? name : "")
+ *ch, (name ? " " : ""), (name ?: "")
);
}
uiFormat(
@@ -618,13 +612,13 @@ static void handleReplyChannelModeIs(struct Message *msg) {
assert(param < ParamCap);
catf(
buf, sizeof(buf), ", +%c%s%s %s",
- *ch, (name ? " " : ""), (name ? name : ""),
+ *ch, (name ? " " : ""), (name ?: ""),
msg->params[param++]
);
} else {
catf(
buf, sizeof(buf), ", +%c%s%s",
- *ch, (name ? " " : ""), (name ? name : "")
+ *ch, (name ? " " : ""), (name ?: "")
);
}
}
@@ -651,7 +645,7 @@ static void handleMode(struct Message *msg) {
hash(msg->user), msg->nick,
(set ? "" : "un"),
self.color, msg->params[0],
- set["-+"], *ch, (name ? " " : ""), (name ? name : "")
+ set["-+"], *ch, (name ? " " : ""), (name ?: "")
);
}
return;
@@ -800,7 +794,7 @@ static void handleErrorBanListFull(struct Message *msg) {
require(msg, false, 4);
uiFormat(
idFor(msg->params[1]), Cold, tagTime(msg),
- "%s", (msg->params[4] ? msg->params[4] : msg->params[3])
+ "%s", (msg->params[4] ?: msg->params[3])
);
}
@@ -933,15 +927,14 @@ static void handleReplyWhoisIdle(struct Message *msg) {
}
}
char signon[sizeof("0000-00-00 00:00:00")];
- time_t time = (msg->params[3] ? strtol(msg->params[3], NULL, 10) : 0);
+ time_t time = strtol((msg->params[3] ?: ""), NULL, 10);
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 : "")
);
}
@@ -976,9 +969,7 @@ 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[3] : "")
+ msg->params[2], (msg->params[3] ? " " : ""), (msg->params[3] ?: "")
);
}
@@ -1031,7 +1022,7 @@ static bool isMention(const struct Message *msg) {
const char *match = msg->params[1];
while (NULL != (match = strcasestr(match, self.nick))) {
char a = (match > msg->params[1] ? match[-1] : ' ');
- char b = (match[len] ? match[len] : ' ');
+ char b = (match[len] ?: ' ');
if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) {
return true;
}
diff --git a/ignore.c b/ignore.c
index 5c14b7d..d65c35a 100644
--- a/ignore.c
+++ b/ignore.c
@@ -62,8 +62,7 @@ enum Heat ignoreCheck(enum Heat heat, const struct Message *msg) {
char match[512];
snprintf(
match, sizeof(match), "%s!%s@%s %s %s",
- msg->nick, msg->user, msg->host, msg->cmd,
- (msg->params[0] ? msg->params[0] : "")
+ msg->nick, msg->user, msg->host, msg->cmd, (msg->params[0] ?: "")
);
for (size_t i = 0; i < ignore.len; ++i) {
if (fnmatch(ignore.patterns[i], match, FNM_CASEFOLD)) continue;
diff --git a/ui.c b/ui.c
index 6d9dddc..2a26ac3 100644
--- a/ui.c
+++ b/ui.c
@@ -891,6 +891,7 @@ static void keyCode(int code) {
break; case KeyMetaMinus: window->ignore ^= true; reflow(window);
break; case KeyMetaSlash: windowShow(windows.swap);
+ 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);
@@ -911,12 +912,6 @@ static void keyCode(int code) {
break; case KEY_PPAGE: windowScroll(window, +(PAGE_LINES - 2));
break; case KEY_RIGHT: edit(id, EditNext, 0);
break; case KEY_UP: windowScroll(window, +1);
-
- break; default: {
- if (code >= KeyMeta0 && code <= KeyMeta9) {
- uiShowNum(code - KeyMeta0);
- }
- }
}
}