1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
From 6eb3b6bab7a8a605b653e3bda11ebf59d941a323 Mon Sep 17 00:00:00 2001
From: Michael Forney <mforney@mforney.org>
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 | 19 ++++++++++---------
complete.c | 4 ++--
handle.c | 45 +++++++++++++++++++++++++++------------------
ignore.c | 2 +-
ui.c | 7 ++++++-
6 files changed, 47 insertions(+), 33 deletions(-)
diff --git a/Makefile b/Makefile
index 08e90ab..942f879 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 4c51433..aec1d4b 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) {
@@ -226,7 +226,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) {
@@ -238,7 +238,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) {
@@ -399,11 +399,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";
execlp(shell, shell, "-c", params, NULL);
warn("%s", shell);
_exit(EX_UNAVAILABLE);
@@ -418,7 +419,7 @@ static void commandHelp(uint id, char *params) {
if (pid) return;
char buf[256];
- snprintf(buf, sizeof(buf), "ip%s$", (params ?: "COMMANDS"));
+ snprintf(buf, sizeof(buf), "ip%s$", (params ? 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 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 fcc0c5d..01f6dc8 100644
--- a/handle.c
+++ b/handle.c
@@ -280,9 +280,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');
}
}
}
@@ -329,7 +329,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]
);
@@ -361,12 +361,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] : "")
);
}
@@ -383,12 +385,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);
@@ -427,13 +431,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);
@@ -605,7 +611,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),
@@ -647,13 +653,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 : "")
);
}
}
@@ -680,7 +686,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;
@@ -837,7 +843,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[3])
+ "%s", (msg->params[4] ? msg->params[4] : msg->params[3])
);
}
@@ -970,14 +976,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 : "")
);
}
@@ -1010,7 +1017,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] : "")
);
}
@@ -1063,7 +1072,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] ?: ' ');
+ char b = (match[len] ? match[len] : ' ');
if ((isspace(a) || ispunct(a)) && (isspace(b) || ispunct(b))) {
return true;
}
diff --git a/ignore.c b/ignore.c
index f8e4d59..73d2d90 100644
--- a/ignore.c
+++ b/ignore.c
@@ -79,7 +79,7 @@ enum Heat ignoreCheck(enum Heat heat, uint id, const struct Message *msg) {
snprintf(
match, sizeof(match), "%s!%s@%s %s %s %s",
msg->nick, msg->user, msg->host,
- msg->cmd, idNames[id], (msg->params[1] ?: "")
+ msg->cmd, idNames[id], msg->params[1] ? msg->params[1] : ""
);
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 59903c9..773f415 100644
--- a/ui.c
+++ b/ui.c
@@ -965,7 +965,6 @@ static void keyCode(int code) {
break; case KeyMetaGt: windowScroll(window, -WindowLines);
break; case KeyMetaLt: windowScroll(window, +WindowLines);
- 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);
@@ -989,6 +988,12 @@ static void keyCode(int code) {
break; case KEY_SEND: windowScroll(window, -WindowLines);
break; case KEY_SHOME: windowScroll(window, +WindowLines);
break; case KEY_UP: windowScroll(window, +1);
+
+ break; default: {
+ if (code >= KeyMeta0 && code <= KeyMeta9) {
+ uiShowNum(code - KeyMeta0);
+ }
+ }
}
}
--
2.28.0
|