Browse Source

Use PascalCase for constants

Begone underscores.
June 3 months ago
parent
commit
240f9ebf84
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
12 changed files with 252 additions and 248 deletions
  1. 6
    6
      chat.c
  2. 50
    50
      chat.h
  3. 17
    17
      edit.c
  4. 32
    32
      handle.c
  5. 17
    17
      input.c
  6. 4
    4
      irc.c
  7. 1
    1
      log.c
  8. 2
    2
      tab.c
  9. 7
    7
      tag.c
  10. 9
    8
      term.c
  11. 94
    91
      ui.c
  12. 13
    13
      url.c

+ 6
- 6
chat.c View File

@@ -60,7 +60,7 @@ static union {
60 60
 
61 61
 void spawn(char *const argv[]) {
62 62
 	if (fds.pipe.events) {
63
-		uiLog(TAG_STATUS, UI_WARM, L"spawn: existing pipe");
63
+		uiLog(TagStatus, UIWarm, L"spawn: existing pipe");
64 64
 		return;
65 65
 	}
66 66
 
@@ -93,7 +93,7 @@ static void pipeRead(void) {
93 93
 	if (len) {
94 94
 		buf[len] = '\0';
95 95
 		len = strcspn(buf, "\n");
96
-		uiFmt(TAG_STATUS, UI_WARM, "spawn: %.*s", (int)len, buf);
96
+		uiFmt(TagStatus, UIWarm, "spawn: %.*s", (int)len, buf);
97 97
 	} else {
98 98
 		close(fds.pipe.fd);
99 99
 		fds.pipe.events = 0;
@@ -124,15 +124,15 @@ static void sigchld(int sig) {
124 124
 	pid_t pid = wait(&status);
125 125
 	if (pid < 0) err(EX_OSERR, "wait");
126 126
 	if (WIFEXITED(status) && WEXITSTATUS(status)) {
127
-		uiFmt(TAG_STATUS, UI_WARM, "spawn: exit %d", WEXITSTATUS(status));
127
+		uiFmt(TagStatus, UIWarm, "spawn: exit %d", WEXITSTATUS(status));
128 128
 	} else if (WIFSIGNALED(status)) {
129
-		uiFmt(TAG_STATUS, UI_WARM, "spawn: signal %d", WTERMSIG(status));
129
+		uiFmt(TagStatus, UIWarm, "spawn: signal %d", WTERMSIG(status));
130 130
 	}
131 131
 }
132 132
 
133 133
 static void sigint(int sig) {
134 134
 	(void)sig;
135
-	input(TAG_STATUS, "/quit");
135
+	input(TagStatus, "/quit");
136 136
 	uiExit();
137 137
 	exit(EX_OK);
138 138
 }
@@ -183,7 +183,7 @@ int main(int argc, char *argv[]) {
183 183
 	inputTab();
184 184
 
185 185
 	uiInit();
186
-	uiLog(TAG_STATUS, UI_WARM, L"Traveling...");
186
+	uiLog(TagStatus, UIWarm, L"Traveling...");
187 187
 	uiDraw();
188 188
 
189 189
 	fds.irc.fd = ircConnect(host, port, pass, webirc);

+ 50
- 50
chat.h View File

@@ -42,38 +42,38 @@ struct Tag {
42 42
 	const char *name;
43 43
 };
44 44
 
45
-enum { TAGS_LEN = 256 };
46
-const struct Tag TAG_NONE;
47
-const struct Tag TAG_STATUS;
48
-const struct Tag TAG_VERBOSE;
45
+enum { TagsLen = 256 };
46
+const struct Tag TagNone;
47
+const struct Tag TagStatus;
48
+const struct Tag TagVerbose;
49 49
 struct Tag tagFind(const char *name);
50 50
 struct Tag tagFor(const char *name);
51 51
 
52 52
 enum {
53
-	IRC_WHITE,
54
-	IRC_BLACK,
55
-	IRC_BLUE,
56
-	IRC_GREEN,
57
-	IRC_RED,
58
-	IRC_BROWN,
59
-	IRC_MAGENTA,
60
-	IRC_ORANGE,
61
-	IRC_YELLOW,
62
-	IRC_LIGHT_GREEN,
63
-	IRC_CYAN,
64
-	IRC_LIGHT_CYAN,
65
-	IRC_LIGHT_BLUE,
66
-	IRC_PINK,
67
-	IRC_GRAY,
68
-	IRC_LIGHT_GRAY,
53
+	IRCWhite,
54
+	IRCBlack,
55
+	IRCBlue,
56
+	IRCGreen,
57
+	IRCRed,
58
+	IRCBrown,
59
+	IRCMagenta,
60
+	IRCOrange,
61
+	IRCYellow,
62
+	IRCLightGreen,
63
+	IRCCyan,
64
+	IRCLightCyan,
65
+	IRCLightBlue,
66
+	IRCPink,
67
+	IRCGray,
68
+	IRCLightGray,
69 69
 };
70 70
 enum {
71
-	IRC_BOLD      = 002,
72
-	IRC_COLOR     = 003,
73
-	IRC_REVERSE   = 026,
74
-	IRC_RESET     = 017,
75
-	IRC_ITALIC    = 035,
76
-	IRC_UNDERLINE = 037,
71
+	IRCBold      = 002,
72
+	IRCColor     = 003,
73
+	IRCReverse   = 026,
74
+	IRCReset     = 017,
75
+	IRCItalic    = 035,
76
+	IRCUnderline = 037,
77 77
 };
78 78
 
79 79
 void handle(char *line);
@@ -98,24 +98,24 @@ void uiViewNum(int num);
98 98
 void uiCloseTag(struct Tag tag);
99 99
 
100 100
 enum UIHeat {
101
-	UI_COLD,
102
-	UI_WARM,
103
-	UI_HOT,
101
+	UICold,
102
+	UIWarm,
103
+	UIHot,
104 104
 };
105 105
 void uiTopic(struct Tag tag, const char *topic);
106 106
 void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line);
107 107
 void uiFmt(struct Tag tag, enum UIHeat heat, const wchar_t *format, ...);
108 108
 
109 109
 enum TermMode {
110
-	TERM_FOCUS,
111
-	TERM_PASTE,
110
+	TermFocus,
111
+	TermPaste,
112 112
 };
113 113
 enum TermEvent {
114
-	TERM_NONE,
115
-	TERM_FOCUS_IN,
116
-	TERM_FOCUS_OUT,
117
-	TERM_PASTE_START,
118
-	TERM_PASTE_END,
114
+	TermNone,
115
+	TermFocusIn,
116
+	TermFocusOut,
117
+	TermPasteStart,
118
+	TermPasteEnd,
119 119
 };
120 120
 void termInit(void);
121 121
 void termTitle(const char *title);
@@ -123,20 +123,20 @@ void termMode(enum TermMode mode, bool set);
123 123
 enum TermEvent termEvent(char ch);
124 124
 
125 125
 enum Edit {
126
-	EDIT_LEFT,
127
-	EDIT_RIGHT,
128
-	EDIT_HOME,
129
-	EDIT_END,
130
-	EDIT_BACK_WORD,
131
-	EDIT_FORE_WORD,
132
-	EDIT_INSERT,
133
-	EDIT_BACKSPACE,
134
-	EDIT_DELETE,
135
-	EDIT_KILL_BACK_WORD,
136
-	EDIT_KILL_FORE_WORD,
137
-	EDIT_KILL_LINE,
138
-	EDIT_COMPLETE,
139
-	EDIT_ENTER,
126
+	EditLeft,
127
+	EditRight,
128
+	EditHome,
129
+	EditEnd,
130
+	EditBackWord,
131
+	EditForeWord,
132
+	EditInsert,
133
+	EditBackspace,
134
+	EditDelete,
135
+	EditKillBackWord,
136
+	EditKillForeWord,
137
+	EditKillLine,
138
+	EditComplete,
139
+	EditEnter,
140 140
 };
141 141
 void edit(struct Tag tag, enum Edit op, wchar_t ch);
142 142
 const wchar_t *editHead(void);

+ 17
- 17
edit.c View File

@@ -22,9 +22,9 @@
22 22
 
23 23
 #include "chat.h"
24 24
 
25
-enum { BUF_LEN = 512 };
25
+enum { BufLen = 512 };
26 26
 static struct {
27
-	wchar_t buf[BUF_LEN];
27
+	wchar_t buf[BufLen];
28 28
 	wchar_t *ptr;
29 29
 	wchar_t *end;
30 30
 	wchar_t *tab;
@@ -66,7 +66,7 @@ static void foreWord(void) {
66 66
 }
67 67
 
68 68
 static void insert(wchar_t ch) {
69
-	if (line.end == &line.buf[BUF_LEN - 1]) return;
69
+	if (line.end == &line.buf[BufLen - 1]) return;
70 70
 	if (line.ptr != line.end) {
71 71
 		wmemmove(line.ptr + 1, line.ptr, line.end - line.ptr);
72 72
 	}
@@ -166,24 +166,24 @@ static void enter(struct Tag tag) {
166 166
 
167 167
 void edit(struct Tag tag, enum Edit op, wchar_t ch) {
168 168
 	switch (op) {
169
-		break; case EDIT_LEFT:  reject(); left();
170
-		break; case EDIT_RIGHT: reject(); right();
171
-		break; case EDIT_HOME:  reject(); line.ptr = line.buf;
172
-		break; case EDIT_END:   reject(); line.ptr = line.end;
169
+		break; case EditLeft:  reject(); left();
170
+		break; case EditRight: reject(); right();
171
+		break; case EditHome:  reject(); line.ptr = line.buf;
172
+		break; case EditEnd:   reject(); line.ptr = line.end;
173 173
 
174
-		break; case EDIT_BACK_WORD: reject(); backWord();
175
-		break; case EDIT_FORE_WORD: reject(); foreWord();
174
+		break; case EditBackWord: reject(); backWord();
175
+		break; case EditForeWord: reject(); foreWord();
176 176
 
177
-		break; case EDIT_INSERT:    accept(); insert(ch);
178
-		break; case EDIT_BACKSPACE: reject(); backspace();
179
-		break; case EDIT_DELETE:    reject(); delete();
177
+		break; case EditInsert:    accept(); insert(ch);
178
+		break; case EditBackspace: reject(); backspace();
179
+		break; case EditDelete:    reject(); delete();
180 180
 
181
-		break; case EDIT_KILL_BACK_WORD: reject(); killBackWord();
182
-		break; case EDIT_KILL_FORE_WORD: reject(); killForeWord();
183
-		break; case EDIT_KILL_LINE:      reject(); line.end = line.ptr;
181
+		break; case EditKillBackWord: reject(); killBackWord();
182
+		break; case EditKillForeWord: reject(); killForeWord();
183
+		break; case EditKillLine:      reject(); line.end = line.ptr;
184 184
 
185
-		break; case EDIT_COMPLETE: complete(tag);
185
+		break; case EditComplete: complete(tag);
186 186
 
187
-		break; case EDIT_ENTER: accept(); enter(tag);
187
+		break; case EditEnter: accept(); enter(tag);
188 188
 	}
189 189
 }

+ 32
- 32
handle.c View File

@@ -33,15 +33,15 @@ static uint32_t hashChar(uint32_t hash, char ch) {
33 33
 	return hash;
34 34
 }
35 35
 static int color(const char *str) {
36
-	if (!str) return IRC_GRAY;
36
+	if (!str) return IRCGray;
37 37
 	uint32_t hash = 0;
38 38
 	for (; str[0]; ++str) {
39 39
 		hash = hashChar(hash, str[0]);
40 40
 	}
41
-	while (IRC_BLACK == (hash & IRC_LIGHT_GRAY)) {
41
+	while (IRCBlack == (hash & IRCLightGray)) {
42 42
 		hash = hashChar(hash, '\0');
43 43
 	}
44
-	return (hash & IRC_LIGHT_GRAY);
44
+	return (hash & IRCLightGray);
45 45
 }
46 46
 
47 47
 static char *paramField(char **params) {
@@ -125,8 +125,8 @@ static void handlePing(char *prefix, char *params) {
125 125
 static void handleReplyErroneousNickname(char *prefix, char *params) {
126 126
 	char *mesg;
127 127
 	shift(prefix, NULL, NULL, NULL, params, 3, 0, NULL, NULL, &mesg);
128
-	uiFmt(TAG_STATUS, UI_HOT, "You can't use that name here: \"%s\"", mesg);
129
-	uiLog(TAG_STATUS, UI_COLD, L"Type /nick <name> to choose a new one");
128
+	uiFmt(TagStatus, UIHot, "You can't use that name here: \"%s\"", mesg);
129
+	uiLog(TagStatus, UICold, L"Type /nick <name> to choose a new one");
130 130
 }
131 131
 
132 132
 static void handleReplyWelcome(char *prefix, char *params) {
@@ -135,9 +135,9 @@ static void handleReplyWelcome(char *prefix, char *params) {
135 135
 
136 136
 	if (strcmp(nick, self.nick)) selfNick(nick);
137 137
 	if (self.join) ircFmt("JOIN %s\r\n", self.join);
138
-	tabTouch(TAG_STATUS, self.nick);
138
+	tabTouch(TagStatus, self.nick);
139 139
 
140
-	uiLog(TAG_STATUS, UI_WARM, L"You have arrived");
140
+	uiLog(TagStatus, UIWarm, L"You have arrived");
141 141
 }
142 142
 
143 143
 static void handleReplyMOTD(char *prefix, char *params) {
@@ -145,8 +145,8 @@ static void handleReplyMOTD(char *prefix, char *params) {
145 145
 	shift(prefix, NULL, NULL, NULL, params, 2, 0, NULL, &mesg);
146 146
 	if (mesg[0] == '-' && mesg[1] == ' ') mesg = &mesg[2];
147 147
 
148
-	urlScan(TAG_STATUS, mesg);
149
-	uiFmt(TAG_STATUS, UI_COLD, "%s", mesg);
148
+	urlScan(TagStatus, mesg);
149
+	uiFmt(TagStatus, UICold, "%s", mesg);
150 150
 }
151 151
 
152 152
 static void handleJoin(char *prefix, char *params) {
@@ -155,13 +155,13 @@ static void handleJoin(char *prefix, char *params) {
155 155
 	struct Tag tag = tagFor(chan);
156 156
 
157 157
 	if (isSelf(nick, user)) {
158
-		tabTouch(TAG_NONE, chan);
158
+		tabTouch(TagNone, chan);
159 159
 		uiViewTag(tag);
160 160
 	}
161 161
 	tabTouch(tag, nick);
162 162
 
163 163
 	uiFmt(
164
-		tag, UI_COLD,
164
+		tag, UICold,
165 165
 		"\3%d%s\3 arrives in \3%d%s\3",
166 166
 		color(user), nick, color(chan), chan
167 167
 	);
@@ -182,14 +182,14 @@ static void handlePart(char *prefix, char *params) {
182 182
 	if (mesg) {
183 183
 		urlScan(tag, mesg);
184 184
 		uiFmt(
185
-			tag, UI_COLD,
185
+			tag, UICold,
186 186
 			"\3%d%s\3 leaves \3%d%s\3, \"%s\"",
187 187
 			color(user), nick, color(chan), chan, dequote(mesg)
188 188
 		);
189 189
 		logFmt(tag, NULL, "%s leaves %s, \"%s\"", nick, chan, dequote(mesg));
190 190
 	} else {
191 191
 		uiFmt(
192
-			tag, UI_COLD,
192
+			tag, UICold,
193 193
 			"\3%d%s\3 leaves \3%d%s\3",
194 194
 			color(user), nick, color(chan), chan
195 195
 		);
@@ -212,7 +212,7 @@ static void handleKick(char *prefix, char *params) {
212 212
 	if (mesg) {
213 213
 		urlScan(tag, mesg);
214 214
 		uiFmt(
215
-			tag, (kicked ? UI_HOT : UI_COLD),
215
+			tag, (kicked ? UIHot : UICold),
216 216
 			"\3%d%s\3 kicks \3%d%s\3 out of \3%d%s\3, \"%s\"",
217 217
 			color(user), nick, color(kick), kick, color(chan), chan,
218 218
 			dequote(mesg)
@@ -223,7 +223,7 @@ static void handleKick(char *prefix, char *params) {
223 223
 		);
224 224
 	} else {
225 225
 		uiFmt(
226
-			tag, (kicked ? UI_HOT : UI_COLD),
226
+			tag, (kicked ? UIHot : UICold),
227 227
 			"\3%d%s\3 kicks \3%d%s\3 out of \3%d%s\3",
228 228
 			color(user), nick, color(kick), kick, color(chan), chan
229 229
 		);
@@ -236,19 +236,19 @@ static void handleQuit(char *prefix, char *params) {
236 236
 	shift(prefix, &nick, &user, NULL, params, 0, 1, &mesg);
237 237
 
238 238
 	struct Tag tag;
239
-	while (TAG_NONE.id != (tag = tabTag(nick)).id) {
239
+	while (TagNone.id != (tag = tabTag(nick)).id) {
240 240
 		tabRemove(tag, nick);
241 241
 
242 242
 		if (mesg) {
243 243
 			urlScan(tag, mesg);
244 244
 			uiFmt(
245
-				tag, UI_COLD,
245
+				tag, UICold,
246 246
 				"\3%d%s\3 leaves, \"%s\"",
247 247
 				color(user), nick, dequote(mesg)
248 248
 			);
249 249
 			logFmt(tag, NULL, "%s leaves, \"%s\"", nick, dequote(mesg));
250 250
 		} else {
251
-			uiFmt(tag, UI_COLD, "\3%d%s\3 leaves", color(user), nick);
251
+			uiFmt(tag, UICold, "\3%d%s\3 leaves", color(user), nick);
252 252
 			logFmt(tag, NULL, "%s leaves", nick);
253 253
 		}
254 254
 	}
@@ -262,7 +262,7 @@ static void handleReplyTopic(char *prefix, char *params) {
262 262
 	urlScan(tag, topic);
263 263
 	uiTopic(tag, topic);
264 264
 	uiFmt(
265
-		tag, UI_COLD,
265
+		tag, UICold,
266 266
 		"The sign in \3%d%s\3 reads, \"%s\"",
267 267
 		color(chan), chan, topic
268 268
 	);
@@ -279,7 +279,7 @@ static void handleTopic(char *prefix, char *params) {
279 279
 	urlScan(tag, topic);
280 280
 	uiTopic(tag, topic);
281 281
 	uiFmt(
282
-		tag, UI_COLD,
282
+		tag, UICold,
283 283
 		"\3%d%s\3 places a new sign in \3%d%s\3, \"%s\"",
284 284
 		color(user), nick, color(chan), chan, topic
285 285
 	);
@@ -322,7 +322,7 @@ static void handleReplyEndOfWho(char *prefix, char *params) {
322 322
 	struct Tag tag = tagFor(chan);
323 323
 
324 324
 	uiFmt(
325
-		tag, UI_COLD,
325
+		tag, UICold,
326 326
 		"In \3%d%s\3 are %s",
327 327
 		color(chan), chan, who.buf
328 328
 	);
@@ -336,11 +336,11 @@ static void handleNick(char *prefix, char *params) {
336 336
 	if (isSelf(prev, user)) selfNick(next);
337 337
 
338 338
 	struct Tag tag;
339
-	while (TAG_NONE.id != (tag = tabTag(prev)).id) {
339
+	while (TagNone.id != (tag = tabTag(prev)).id) {
340 340
 		tabReplace(tag, prev, next);
341 341
 
342 342
 		uiFmt(
343
-			tag, UI_COLD,
343
+			tag, UICold,
344 344
 			"\3%d%s\3 is now known as \3%d%s\3",
345 345
 			color(user), prev, color(user), next
346 346
 		);
@@ -360,7 +360,7 @@ static void handleCTCP(struct Tag tag, char *nick, char *user, char *mesg) {
360 360
 	urlScan(tag, params);
361 361
 	bool ping = !self && isPing(params);
362 362
 	uiFmt(
363
-		tag, (ping ? UI_HOT : UI_WARM),
363
+		tag, (ping ? UIHot : UIWarm),
364 364
 		"%c\3%d* %s\17 %s",
365 365
 		ping["\17\26"], color(user), nick, params
366 366
 	);
@@ -383,7 +383,7 @@ static void handlePrivmsg(char *prefix, char *params) {
383 383
 	urlScan(tag, mesg);
384 384
 	bool ping = !self && (direct || isPing(mesg));
385 385
 	uiFmt(
386
-		tag, (ping ? UI_HOT : UI_WARM),
386
+		tag, (ping ? UIHot : UIWarm),
387 387
 		"%c\3%d%c%s%c\17 %s",
388 388
 		ping["\17\26"], color(user), self["<("], nick, self[">)"], mesg
389 389
 	);
@@ -393,7 +393,7 @@ static void handlePrivmsg(char *prefix, char *params) {
393 393
 static void handleNotice(char *prefix, char *params) {
394 394
 	char *nick, *user, *chan, *mesg;
395 395
 	shift(prefix, &nick, &user, NULL, params, 2, 0, &chan, &mesg);
396
-	struct Tag tag = TAG_STATUS;
396
+	struct Tag tag = TagStatus;
397 397
 	if (user) tag = (strcmp(chan, self.nick) ? tagFor(chan) : tagFor(nick));
398 398
 
399 399
 	bool self = isSelf(nick, user);
@@ -402,7 +402,7 @@ static void handleNotice(char *prefix, char *params) {
402 402
 	urlScan(tag, mesg);
403 403
 	bool ping = !self && isPing(mesg);
404 404
 	uiFmt(
405
-		tag, (ping ? UI_HOT : UI_WARM),
405
+		tag, (ping ? UIHot : UIWarm),
406 406
 		"%c\3%d-%s-\17 %s",
407 407
 		ping["\17\26"], color(user), nick, mesg
408 408
 	);
@@ -412,7 +412,7 @@ static void handleNotice(char *prefix, char *params) {
412 412
 static const struct {
413 413
 	const char *command;
414 414
 	Handler handler;
415
-} HANDLERS[] = {
415
+} Handlers[] = {
416 416
 	{ "001", handleReplyWelcome },
417 417
 	{ "315", handleReplyEndOfWho },
418 418
 	{ "332", handleReplyTopic },
@@ -432,7 +432,7 @@ static const struct {
432 432
 	{ "QUIT", handleQuit },
433 433
 	{ "TOPIC", handleTopic },
434 434
 };
435
-static const size_t HANDLERS_LEN = sizeof(HANDLERS) / sizeof(HANDLERS[0]);
435
+static const size_t HandlersLen = sizeof(Handlers) / sizeof(Handlers[0]);
436 436
 
437 437
 void handle(char *line) {
438 438
 	char *prefix = NULL;
@@ -441,9 +441,9 @@ void handle(char *line) {
441 441
 		if (!line) errx(EX_PROTOCOL, "unexpected eol");
442 442
 	}
443 443
 	char *command = strsep(&line, " ");
444
-	for (size_t i = 0; i < HANDLERS_LEN; ++i) {
445
-		if (strcmp(command, HANDLERS[i].command)) continue;
446
-		HANDLERS[i].handler(prefix, line);
444
+	for (size_t i = 0; i < HandlersLen; ++i) {
445
+		if (strcmp(command, Handlers[i].command)) continue;
446
+		Handlers[i].handler(prefix, line);
447 447
 		break;
448 448
 	}
449 449
 }

+ 17
- 17
input.c View File

@@ -40,7 +40,7 @@ static void privmsg(struct Tag tag, bool action, const char *mesg) {
40 40
 static char *param(const char *command, char **params, const char *name) {
41 41
 	char *param = strsep(params, " ");
42 42
 	if (param) return param;
43
-	uiFmt(TAG_STATUS, UI_WARM, "%s requires a %s", command, name);
43
+	uiFmt(TagStatus, UIHot, "%s requires a %s", command, name);
44 44
 	return NULL;
45 45
 }
46 46
 
@@ -76,7 +76,7 @@ static void inputQuery(struct Tag tag, char *params) {
76 76
 	(void)tag;
77 77
 	char *nick = param("/query", &params, "nick");
78 78
 	if (!nick) return;
79
-	tabTouch(TAG_NONE, nick);
79
+	tabTouch(TagNone, nick);
80 80
 	uiViewTag(tagFor(nick));
81 81
 }
82 82
 
@@ -121,10 +121,10 @@ static void inputView(struct Tag tag, char *params) {
121 121
 		uiViewNum(num);
122 122
 	} else {
123 123
 		struct Tag tag = tagFind(view);
124
-		if (tag.id != TAG_NONE.id) {
124
+		if (tag.id != TagNone.id) {
125 125
 			uiViewTag(tag);
126 126
 		} else {
127
-			uiFmt(TAG_STATUS, UI_WARM, "No view for %s", view);
127
+			uiFmt(TagStatus, UIHot, "No view for %s", view);
128 128
 		}
129 129
 	}
130 130
 }
@@ -132,13 +132,13 @@ static void inputView(struct Tag tag, char *params) {
132 132
 static void inputClose(struct Tag tag, char *params) {
133 133
 	(void)params;
134 134
 	uiCloseTag(tag);
135
-	tabRemove(TAG_NONE, tag.name);
135
+	tabRemove(TagNone, tag.name);
136 136
 }
137 137
 
138 138
 static const struct {
139 139
 	const char *command;
140 140
 	Handler handler;
141
-} COMMANDS[] = {
141
+} Commands[] = {
142 142
 	{ "/close", inputClose },
143 143
 	{ "/join", inputJoin },
144 144
 	{ "/me", inputMe },
@@ -153,7 +153,7 @@ static const struct {
153 153
 	{ "/view", inputView },
154 154
 	{ "/who", inputWho },
155 155
 };
156
-static const size_t COMMANDS_LEN = sizeof(COMMANDS) / sizeof(COMMANDS[0]);
156
+static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]);
157 157
 
158 158
 void input(struct Tag tag, char *input) {
159 159
 	bool slash = (input[0] == '/');
@@ -164,9 +164,9 @@ void input(struct Tag tag, char *input) {
164 164
 	}
165 165
 
166 166
 	if (!slash) {
167
-		if (tag.id == TAG_VERBOSE.id) {
167
+		if (tag.id == TagVerbose.id) {
168 168
 			ircFmt("%s\r\n", input);
169
-		} else if (tag.id != TAG_STATUS.id) {
169
+		} else if (tag.id != TagStatus.id) {
170 170
 			privmsg(tag, false, input);
171 171
 		}
172 172
 		return;
@@ -183,24 +183,24 @@ void input(struct Tag tag, char *input) {
183 183
 	}
184 184
 
185 185
 	const char *command = word;
186
-	const char *uniq = tabNext(TAG_NONE, command);
187
-	if (uniq && uniq == tabNext(TAG_NONE, command)) {
186
+	const char *uniq = tabNext(TagNone, command);
187
+	if (uniq && uniq == tabNext(TagNone, command)) {
188 188
 		command = uniq;
189 189
 		tabAccept();
190 190
 	} else {
191 191
 		tabReject();
192 192
 	}
193 193
 
194
-	for (size_t i = 0; i < COMMANDS_LEN; ++i) {
195
-		if (strcasecmp(command, COMMANDS[i].command)) continue;
196
-		COMMANDS[i].handler(tag, input);
194
+	for (size_t i = 0; i < CommandsLen; ++i) {
195
+		if (strcasecmp(command, Commands[i].command)) continue;
196
+		Commands[i].handler(tag, input);
197 197
 		return;
198 198
 	}
199
-	uiFmt(TAG_STATUS, UI_WARM, "%s isn't a recognized command", command);
199
+	uiFmt(TagStatus, UIHot, "%s isn't a recognized command", command);
200 200
 }
201 201
 
202 202
 void inputTab(void) {
203
-	for (size_t i = 0; i < COMMANDS_LEN; ++i) {
204
-		tabTouch(TAG_NONE, COMMANDS[i].command);
203
+	for (size_t i = 0; i < CommandsLen; ++i) {
204
+		tabTouch(TagNone, Commands[i].command);
205 205
 	}
206 206
 }

+ 4
- 4
irc.c View File

@@ -108,8 +108,8 @@ void ircFmt(const char *format, ...) {
108 108
 	if (!buf) err(EX_OSERR, "vasprintf");
109 109
 	if (self.verbose) {
110 110
 		uiFmt(
111
-			TAG_VERBOSE, UI_COLD,
112
-			"\3%d<<<\3 %.*s", IRC_WHITE, len - 2, buf
111
+			TagVerbose, UICold,
112
+			"\3%d<<<\3 %.*s", IRCWhite, len - 2, buf
113 113
 		);
114 114
 	}
115 115
 	ircWrite(buf, len);
@@ -133,8 +133,8 @@ void ircRead(void) {
133 133
 		crlf[0] = '\0';
134 134
 		if (self.verbose) {
135 135
 			uiFmt(
136
-				TAG_VERBOSE, UI_COLD,
137
-				"\3%d>>>\3 %s", IRC_GRAY, line
136
+				TagVerbose, UICold,
137
+				"\3%d>>>\3 %s", IRCGray, line
138 138
 			);
139 139
 		}
140 140
 		handle(line);

+ 1
- 1
log.c View File

@@ -34,7 +34,7 @@ static struct Log {
34 34
 	int month;
35 35
 	int day;
36 36
 	FILE *file;
37
-} logs[TAGS_LEN];
37
+} logs[TagsLen];
38 38
 
39 39
 void logOpen(const char *path) {
40 40
 	logRoot = open(path, O_RDONLY | O_CLOEXEC);

+ 2
- 2
tab.c View File

@@ -121,14 +121,14 @@ struct Tag tabTag(const char *word) {
121 121
 		return entry->tag;
122 122
 	}
123 123
 	iter = NULL;
124
-	return TAG_NONE;
124
+	return TagNone;
125 125
 }
126 126
 
127 127
 const char *tabNext(struct Tag tag, const char *prefix) {
128 128
 	size_t len = strlen(prefix);
129 129
 	struct Entry *start = (iter ? iter->next : head);
130 130
 	for (struct Entry *entry = start; entry; entry = entry->next) {
131
-		if (entry->tag.id != TAG_NONE.id && entry->tag.id != tag.id) continue;
131
+		if (entry->tag.id != TagNone.id && entry->tag.id != tag.id) continue;
132 132
 		if (strncasecmp(entry->word, prefix, len)) continue;
133 133
 		iter = entry;
134 134
 		return entry->word;

+ 7
- 7
tag.c View File

@@ -21,12 +21,12 @@
21 21
 
22 22
 #include "chat.h"
23 23
 
24
-const struct Tag TAG_NONE    = { 0, "" };
25
-const struct Tag TAG_STATUS  = { 1, "(status)" };
26
-const struct Tag TAG_VERBOSE = { 2, "(irc)" };
24
+const struct Tag TagNone    = { 0, "" };
25
+const struct Tag TagStatus  = { 1, "(status)" };
26
+const struct Tag TagVerbose = { 2, "(irc)" };
27 27
 
28 28
 static struct {
29
-	char *name[TAGS_LEN];
29
+	char *name[TagsLen];
30 30
 	size_t len;
31 31
 } tags = {
32 32
 	.name = { "", "(status)", "(irc)" },
@@ -42,13 +42,13 @@ struct Tag tagFind(const char *name) {
42 42
 		if (strcmp(tags.name[id], name)) continue;
43 43
 		return Tag(id);
44 44
 	}
45
-	return TAG_NONE;
45
+	return TagNone;
46 46
 }
47 47
 
48 48
 struct Tag tagFor(const char *name) {
49 49
 	struct Tag tag = tagFind(name);
50
-	if (tag.id != TAG_NONE.id) return tag;
51
-	if (tags.len == TAGS_LEN) return TAG_STATUS;
50
+	if (tag.id != TagNone.id) return tag;
51
+	if (tags.len == TagsLen) return TagStatus;
52 52
 	size_t id = tags.len++;
53 53
 	tags.name[id] = strdup(name);
54 54
 	if (!tags.name[id]) err(EX_OSERR, "strdup");

+ 9
- 8
term.c View File

@@ -42,27 +42,28 @@ static void privateMode(const char *mode, bool set) {
42 42
 
43 43
 void termMode(enum TermMode mode, bool set) {
44 44
 	switch (mode) {
45
-		break; case TERM_FOCUS: privateMode("1004", set);
46
-		break; case TERM_PASTE: privateMode("2004", set);
45
+		break; case TermFocus: privateMode("1004", set);
46
+		break; case TermPaste: privateMode("2004", set);
47 47
 	}
48 48
 }
49 49
 
50
-#define ESC '\33'
51 50
 #define T(s, i) ((s) << 8 | (i))
52 51
 
52
+enum { Esc = '\33' };
53
+
53 54
 enum TermEvent termEvent(char ch) {
54 55
 	static int state = 0;
55 56
 	switch (T(state, ch)) {
56
-		case T(0, ESC): state = 1; return 0;
57
+		case T(0, Esc): state = 1; return 0;
57 58
 		case T(1, '['): state = 2; return 0;
58
-		case T(2, 'I'): state = 0; return TERM_FOCUS_IN;
59
-		case T(2, 'O'): state = 0; return TERM_FOCUS_OUT;
59
+		case T(2, 'I'): state = 0; return TermFocusIn;
60
+		case T(2, 'O'): state = 0; return TermFocusOut;
60 61
 		case T(2, '2'): state = 3; return 0;
61 62
 		case T(3, '0'): state = 4; return 0;
62 63
 		case T(4, '0'): state = 5; return 0;
63
-		case T(5, '~'): state = 0; return TERM_PASTE_START;
64
+		case T(5, '~'): state = 0; return TermPasteStart;
64 65
 		case T(4, '1'): state = 6; return 0;
65
-		case T(6, '~'): state = 0; return TERM_PASTE_END;
66
+		case T(6, '~'): state = 0; return TermPasteEnd;
66 67
 		default:        state = 0; return 0;
67 68
 	}
68 69
 }

+ 94
- 91
ui.c View File

@@ -85,7 +85,7 @@ struct View {
85 85
 static struct {
86 86
 	struct View *head;
87 87
 	struct View *tail;
88
-	struct View *tags[TAGS_LEN];
88
+	struct View *tags[TagsLen];
89 89
 } views;
90 90
 
91 91
 static void viewAppend(struct View *view) {
@@ -105,13 +105,13 @@ static void viewRemove(struct View *view) {
105 105
 	views.tags[view->tag.id] = NULL;
106 106
 }
107 107
 
108
-static const int LOG_LINES = 256;
108
+static const int LogLines = 256;
109 109
 
110 110
 static int logHeight(const struct View *view) {
111 111
 	return LINES - (view->topic ? 2 : 0) - 2;
112 112
 }
113 113
 static int lastLogLine(void) {
114
-	return LOG_LINES - 1;
114
+	return LogLines - 1;
115 115
 }
116 116
 static int lastLine(void) {
117 117
 	return LINES - 1;
@@ -128,11 +128,11 @@ static struct View *viewTag(struct Tag tag) {
128 128
 	if (!view) err(EX_OSERR, "calloc");
129 129
 
130 130
 	view->tag = tag;
131
-	view->log = newpad(LOG_LINES, COLS);
131
+	view->log = newpad(LogLines, COLS);
132 132
 	wsetscrreg(view->log, 0, lastLogLine());
133 133
 	scrollok(view->log, true);
134 134
 	wmove(view->log, lastLogLine() - logHeight(view) + 2, 0);
135
-	view->scroll = LOG_LINES;
135
+	view->scroll = LogLines;
136 136
 	view->mark = true;
137 137
 
138 138
 	viewAppend(view);
@@ -141,7 +141,7 @@ static struct View *viewTag(struct Tag tag) {
141 141
 
142 142
 static void viewResize(void) {
143 143
 	for (struct View *view = views.head; view; view = view->next) {
144
-		wresize(view->log, LOG_LINES, COLS);
144
+		wresize(view->log, LogLines, COLS);
145 145
 		wmove(view->log, lastLogLine(), lastCol());
146 146
 	}
147 147
 }
@@ -162,8 +162,6 @@ static void viewUnmark(struct View *view) {
162 162
 	view->mark = false;
163 163
 }
164 164
 
165
-static const int COLS_MAX = 512;
166
-
167 165
 static struct {
168 166
 	bool hide;
169 167
 	struct View *view;
@@ -173,12 +171,12 @@ static struct {
173 171
 
174 172
 static void uiShow(void) {
175 173
 	ui.hide = false;
176
-	termMode(TERM_FOCUS, true);
174
+	termMode(TermFocus, true);
177 175
 }
178 176
 
179 177
 void uiHide(void) {
180 178
 	ui.hide = true;
181
-	termMode(TERM_FOCUS, false);
179
+	termMode(TermFocus, false);
182 180
 	endwin();
183 181
 }
184 182
 
@@ -225,23 +223,23 @@ static void uiRedraw(void) {
225 223
 	clearok(curscr, true);
226 224
 }
227 225
 
228
-static const short IRC_COLORS[] = {
229
-	[IRC_WHITE]       = 8 + COLOR_WHITE,
230
-	[IRC_BLACK]       = 0 + COLOR_BLACK,
231
-	[IRC_BLUE]        = 0 + COLOR_BLUE,
232
-	[IRC_GREEN]       = 0 + COLOR_GREEN,
233
-	[IRC_RED]         = 8 + COLOR_RED,
234
-	[IRC_BROWN]       = 0 + COLOR_RED,
235
-	[IRC_MAGENTA]     = 0 + COLOR_MAGENTA,
236
-	[IRC_ORANGE]      = 0 + COLOR_YELLOW,
237
-	[IRC_YELLOW]      = 8 + COLOR_YELLOW,
238
-	[IRC_LIGHT_GREEN] = 8 + COLOR_GREEN,
239
-	[IRC_CYAN]        = 0 + COLOR_CYAN,
240
-	[IRC_LIGHT_CYAN]  = 8 + COLOR_CYAN,
241
-	[IRC_LIGHT_BLUE]  = 8 + COLOR_BLUE,
242
-	[IRC_PINK]        = 8 + COLOR_MAGENTA,
243
-	[IRC_GRAY]        = 8 + COLOR_BLACK,
244
-	[IRC_LIGHT_GRAY]  = 0 + COLOR_WHITE,
226
+static const short IRCColors[] = {
227
+	[IRCWhite]      = 8 + COLOR_WHITE,
228
+	[IRCBlack]      = 0 + COLOR_BLACK,
229
+	[IRCBlue]       = 0 + COLOR_BLUE,
230
+	[IRCGreen]      = 0 + COLOR_GREEN,
231
+	[IRCRed]        = 8 + COLOR_RED,
232
+	[IRCBrown]      = 0 + COLOR_RED,
233
+	[IRCMagenta]    = 0 + COLOR_MAGENTA,
234
+	[IRCOrange]     = 0 + COLOR_YELLOW,
235
+	[IRCYellow]     = 8 + COLOR_YELLOW,
236
+	[IRCLightGreen] = 8 + COLOR_GREEN,
237
+	[IRCCyan]       = 0 + COLOR_CYAN,
238
+	[IRCLightCyan]  = 8 + COLOR_CYAN,
239
+	[IRCLightBlue]  = 8 + COLOR_BLUE,
240
+	[IRCPink]       = 8 + COLOR_MAGENTA,
241
+	[IRCGray]       = 8 + COLOR_BLACK,
242
+	[IRCLightGray]  = 0 + COLOR_WHITE,
245 243
 };
246 244
 
247 245
 static const wchar_t *parseColor(short *pair, const wchar_t *str) {
@@ -262,8 +260,8 @@ static const wchar_t *parseColor(short *pair, const wchar_t *str) {
262 260
 	if (bgLen) str = &str[1 + bgLen];
263 261
 
264 262
 	if (*pair == -1) *pair = 0;
265
-	*pair = (*pair & 0xF0) | IRC_COLORS[fg & 0x0F];
266
-	if (bgLen) *pair = (*pair & 0x0F) | (IRC_COLORS[bg & 0x0F] << 4);
263
+	*pair = (*pair & 0xF0) | IRCColors[fg & 0x0F];
264
+	if (bgLen) *pair = (*pair & 0x0F) | (IRCColors[bg & 0x0F] << 4);
267 265
 
268 266
 	return str;
269 267
 }
@@ -286,14 +284,14 @@ static void wordWrap(WINDOW *win, const wchar_t *str) {
286 284
 	}
287 285
 }
288 286
 
289
-static const wchar_t IRC_CODES[] = {
287
+static const wchar_t IRCCodes[] = {
290 288
 	L' ',
291
-	IRC_BOLD,
292
-	IRC_COLOR,
293
-	IRC_REVERSE,
294
-	IRC_RESET,
295
-	IRC_ITALIC,
296
-	IRC_UNDERLINE,
289
+	IRCBold,
290
+	IRCColor,
291
+	IRCReverse,
292
+	IRCReset,
293
+	IRCItalic,
294
+	IRCUnderline,
297 295
 	L'\0',
298 296
 };
299 297
 
@@ -301,7 +299,7 @@ static void addIRC(WINDOW *win, const wchar_t *str) {
301 299
 	attr_t attr = A_NORMAL;
302 300
 	short pair = -1;
303 301
 	for (;;) {
304
-		size_t cc = wcscspn(str, IRC_CODES);
302
+		size_t cc = wcscspn(str, IRCCodes);
305 303
 		wattr_set(win, attr | attr8(pair), 1 + pair8(pair), NULL);
306 304
 		waddnwstr(win, str, cc);
307 305
 		if (!str[cc]) break;
@@ -309,12 +307,12 @@ static void addIRC(WINDOW *win, const wchar_t *str) {
309 307
 		str = &str[cc];
310 308
 		switch (*str++) {
311 309
 			break; case L' ':          wordWrap(win, str);
312
-			break; case IRC_BOLD:      attr ^= A_BOLD;
313
-			break; case IRC_ITALIC:    attr ^= A_ITALIC;
314
-			break; case IRC_UNDERLINE: attr ^= A_UNDERLINE;
315
-			break; case IRC_REVERSE:   attr ^= A_REVERSE;
316
-			break; case IRC_COLOR:     str = parseColor(&pair, str);
317
-			break; case IRC_RESET:     attr = A_NORMAL; pair = -1;
310
+			break; case IRCBold:      attr ^= A_BOLD;
311
+			break; case IRCItalic:    attr ^= A_ITALIC;
312
+			break; case IRCUnderline: attr ^= A_UNDERLINE;
313
+			break; case IRCReverse:   attr ^= A_REVERSE;
314
+			break; case IRCColor:     str = parseColor(&pair, str);
315
+			break; case IRCReset:     attr = A_NORMAL; pair = -1;
318 316
 		}
319 317
 	}
320 318
 }
@@ -327,13 +325,13 @@ static void uiStatus(void) {
327 325
 	int count = 0;
328 326
 	for (const struct View *view = views.head; view; view = view->next, ++num) {
329 327
 		if (!view->unread) continue;
330
-		bool status = (view->tag.id == TAG_STATUS.id);
328
+		bool status = (view->tag.id == TagStatus.id);
331 329
 
332 330
 		int unread;
333 331
 		wchar_t *str;
334 332
 		int len = aswprintf(
335 333
 			&str, L",\3%02d%d\3%s%s%n(%d)",
336
-			(view->hot ? IRC_YELLOW : IRC_WHITE), num,
334
+			(view->hot ? IRCYellow : IRCWhite), num,
337 335
 			&status[":"], (status ? "" : view->tag.name),
338 336
 			&unread, view->unread
339 337
 		);
@@ -396,11 +394,13 @@ void uiViewNum(int num) {
396 394
 	}
397 395
 }
398 396
 
397
+static const int ColsMax = 512;
398
+
399 399
 void uiTopic(struct Tag tag, const char *topic) {
400 400
 	struct View *view = viewTag(tag);
401 401
 	if (!view->topic) {
402
-		view->topic = newpad(2, COLS_MAX);
403
-		mvwhline(view->topic, 1, 0, ACS_HLINE, COLS_MAX);
402
+		view->topic = newpad(2, ColsMax);
403
+		mvwhline(view->topic, 1, 0, ACS_HLINE, ColsMax);
404 404
 	}
405 405
 	wchar_t *wcs = ambstowcs(topic);
406 406
 	if (!wcs) err(EX_DATAERR, "ambstowcs");
@@ -413,9 +413,9 @@ void uiTopic(struct Tag tag, const char *topic) {
413 413
 void uiLog(struct Tag tag, enum UIHeat heat, const wchar_t *line) {
414 414
 	struct View *view = viewTag(tag);
415 415
 	waddch(view->log, '\n');
416
-	if (view->mark && heat > UI_COLD) {
416
+	if (view->mark && heat > UICold) {
417 417
 		if (!view->unread++) waddch(view->log, '\n');
418
-		if (heat > UI_WARM) {
418
+		if (heat > UIWarm) {
419 419
 			view->hot = true;
420 420
 			beep(); // TODO: Notification.
421 421
 		}
@@ -444,13 +444,13 @@ void uiInit(void) {
444 444
 	colorInit();
445 445
 	termInit();
446 446
 
447
-	ui.status = newpad(1, COLS_MAX);
448
-	ui.input = newpad(1, COLS_MAX);
447
+	ui.status = newpad(1, ColsMax);
448
+	ui.input = newpad(1, ColsMax);
449 449
 	keypad(ui.input, true);
450 450
 	nodelay(ui.input, true);
451 451
 
452
-	ui.view = viewTag(TAG_STATUS);
453
-	uiViewTag(TAG_STATUS);
452
+	ui.view = viewTag(TagStatus);
453
+	uiViewTag(TagStatus);
454 454
 	uiStatus();
455 455
 	uiShow();
456 456
 }
@@ -466,13 +466,13 @@ void uiExit(void) {
466 466
 static void logScrollUp(int lines) {
467 467
 	int height = logHeight(ui.view);
468 468
 	if (ui.view->scroll == height) return;
469
-	if (ui.view->scroll == LOG_LINES) viewMark(ui.view);
469
+	if (ui.view->scroll == LogLines) viewMark(ui.view);
470 470
 	ui.view->scroll = MAX(ui.view->scroll - lines, height);
471 471
 }
472 472
 static void logScrollDown(int lines) {
473
-	if (ui.view->scroll == LOG_LINES) return;
474
-	ui.view->scroll = MIN(ui.view->scroll + lines, LOG_LINES);
475
-	if (ui.view->scroll == LOG_LINES) viewUnmark(ui.view);
473
+	if (ui.view->scroll == LogLines) return;
474
+	ui.view->scroll = MIN(ui.view->scroll + lines, LogLines);
475
+	if (ui.view->scroll == LogLines) viewUnmark(ui.view);
476 476
 }
477 477
 static void logPageUp(void) {
478 478
 	logScrollUp(logHeight(ui.view) / 2);
@@ -485,11 +485,14 @@ static bool keyChar(wchar_t ch) {
485 485
 	if (ch < 0200) {
486 486
 		enum TermEvent event = termEvent((char)ch);
487 487
 		switch (event) {
488
-			break; case TERM_FOCUS_IN:  viewUnmark(ui.view);
489
-			break; case TERM_FOCUS_OUT: viewMark(ui.view);
488
+			break; case TermFocusIn:  viewUnmark(ui.view);
489
+			break; case TermFocusOut: viewMark(ui.view);
490 490
 			break; default: {}
491 491
 		}
492
-		if (event) return false;
492
+		if (event) {
493
+			uiStatus();
494
+			return false;
495
+		}
493 496
 	}
494 497
 
495 498
 	static bool meta;
@@ -501,10 +504,10 @@ static bool keyChar(wchar_t ch) {
501 504
 	if (meta) {
502 505
 		bool update = true;
503 506
 		switch (ch) {
504
-			break; case L'b':  edit(ui.view->tag, EDIT_BACK_WORD, 0);
505
-			break; case L'f':  edit(ui.view->tag, EDIT_FORE_WORD, 0);
506
-			break; case L'\b': edit(ui.view->tag, EDIT_KILL_BACK_WORD, 0);
507
-			break; case L'd':  edit(ui.view->tag, EDIT_KILL_FORE_WORD, 0);
507
+			break; case L'b':  edit(ui.view->tag, EditBackWord, 0);
508
+			break; case L'f':  edit(ui.view->tag, EditForeWord, 0);
509
+			break; case L'\b': edit(ui.view->tag, EditKillBackWord, 0);
510
+			break; case L'd':  edit(ui.view->tag, EditKillForeWord, 0);
508 511
 			break; default: {
509 512
 				update = false;
510 513
 				if (ch < L'0' || ch > L'9') break;
@@ -519,29 +522,29 @@ static bool keyChar(wchar_t ch) {
519 522
 	switch (ch) {
520 523
 		break; case CTRL(L'L'): uiRedraw(); return false;
521 524
 
522
-		break; case CTRL(L'A'): edit(ui.view->tag, EDIT_HOME, 0);
523
-		break; case CTRL(L'B'): edit(ui.view->tag, EDIT_LEFT, 0);
524
-		break; case CTRL(L'D'): edit(ui.view->tag, EDIT_DELETE, 0);
525
-		break; case CTRL(L'E'): edit(ui.view->tag, EDIT_END, 0);
526
-		break; case CTRL(L'F'): edit(ui.view->tag, EDIT_RIGHT, 0);
527
-		break; case CTRL(L'K'): edit(ui.view->tag, EDIT_KILL_LINE, 0);
528
-		break; case CTRL(L'W'): edit(ui.view->tag, EDIT_KILL_BACK_WORD, 0);
529
-
530
-		break; case CTRL(L'C'): edit(ui.view->tag, EDIT_INSERT, IRC_COLOR);
531
-		break; case CTRL(L'N'): edit(ui.view->tag, EDIT_INSERT, IRC_RESET);
532
-		break; case CTRL(L'O'): edit(ui.view->tag, EDIT_INSERT, IRC_BOLD);
533
-		break; case CTRL(L'R'): edit(ui.view->tag, EDIT_INSERT, IRC_COLOR);
534
-		break; case CTRL(L'T'): edit(ui.view->tag, EDIT_INSERT, IRC_ITALIC);
535
-		break; case CTRL(L'U'): edit(ui.view->tag, EDIT_INSERT, IRC_UNDERLINE);
536
-		break; case CTRL(L'V'): edit(ui.view->tag, EDIT_INSERT, IRC_REVERSE);
537
-
538
-		break; case L'\b': edit(ui.view->tag, EDIT_BACKSPACE, 0);
539
-		break; case L'\t': edit(ui.view->tag, EDIT_COMPLETE, 0);
540
-		break; case L'\n': edit(ui.view->tag, EDIT_ENTER, 0);
525
+		break; case CTRL(L'A'): edit(ui.view->tag, EditHome, 0);
526
+		break; case CTRL(L'B'): edit(ui.view->tag, EditLeft, 0);
527
+		break; case CTRL(L'D'): edit(ui.view->tag, EditDelete, 0);
528
+		break; case CTRL(L'E'): edit(ui.view->tag, EditEnd, 0);
529
+		break; case CTRL(L'F'): edit(ui.view->tag, EditRight, 0);
530
+		break; case CTRL(L'K'): edit(ui.view->tag, EditKillLine, 0);
531
+		break; case CTRL(L'W'): edit(ui.view->tag, EditKillBackWord, 0);
532
+
533
+		break; case CTRL(L'C'): edit(ui.view->tag, EditInsert, IRCColor);
534
+		break; case CTRL(L'N'): edit(ui.view->tag, EditInsert, IRCReset);
535
+		break; case CTRL(L'O'): edit(ui.view->tag, EditInsert, IRCBold);
536
+		break; case CTRL(L'R'): edit(ui.view->tag, EditInsert, IRCColor);
537
+		break; case CTRL(L'T'): edit(ui.view->tag, EditInsert, IRCItalic);
538
+		break; case CTRL(L'U'): edit(ui.view->tag, EditInsert, IRCUnderline);
539
+		break; case CTRL(L'V'): edit(ui.view->tag, EditInsert, IRCReverse);
540
+
541
+		break; case L'\b': edit(ui.view->tag, EditBackspace, 0);
542
+		break; case L'\t': edit(ui.view->tag, EditComplete, 0);
543
+		break; case L'\n': edit(ui.view->tag, EditEnter, 0);
541 544
 
542 545
 		break; default: {
543 546
 			if (!iswprint(ch)) return false;
544
-			edit(ui.view->tag, EDIT_INSERT, ch);
547
+			edit(ui.view->tag, EditInsert, ch);
545 548
 		}
546 549
 	}
547 550
 	return true;
@@ -554,13 +557,13 @@ static bool keyCode(wchar_t ch) {
554 557
 		break; case KEY_SRIGHT:    logScrollDown(1); return false;
555 558
 		break; case KEY_PPAGE:     logPageUp(); return false;
556 559
 		break; case KEY_NPAGE:     logPageDown(); return false;
557
-		break; case KEY_LEFT:      edit(ui.view->tag, EDIT_LEFT, 0);
558
-		break; case KEY_RIGHT:     edit(ui.view->tag, EDIT_RIGHT, 0);
559
-		break; case KEY_HOME:      edit(ui.view->tag, EDIT_HOME, 0);
560
-		break; case KEY_END:       edit(ui.view->tag, EDIT_END, 0);
561
-		break; case KEY_DC:        edit(ui.view->tag, EDIT_DELETE, 0);
562
-		break; case KEY_BACKSPACE: edit(ui.view->tag, EDIT_BACKSPACE, 0);
563
-		break; case KEY_ENTER:     edit(ui.view->tag, EDIT_ENTER, 0);
560
+		break; case KEY_LEFT:      edit(ui.view->tag, EditLeft, 0);
561
+		break; case KEY_RIGHT:     edit(ui.view->tag, EditRight, 0);
562
+		break; case KEY_HOME:      edit(ui.view->tag, EditHome, 0);
563
+		break; case KEY_END:       edit(ui.view->tag, EditEnd, 0);
564
+		break; case KEY_DC:        edit(ui.view->tag, EditDelete, 0);
565
+		break; case KEY_BACKSPACE: edit(ui.view->tag, EditBackspace, 0);
566
+		break; case KEY_ENTER:     edit(ui.view->tag, EditEnter, 0);
564 567
 	}
565 568
 	return true;
566 569
 }

+ 13
- 13
url.c View File

@@ -23,23 +23,23 @@
23 23
 
24 24
 #include "chat.h"
25 25
 
26
-static const char *SCHEMES[] = {
26
+static const char *Schemes[] = {
27 27
 	"https:",
28 28
 	"http:",
29 29
 	"ftp:",
30 30
 };
31
-static const size_t SCHEMES_LEN = sizeof(SCHEMES) / sizeof(SCHEMES[0]);
31
+static const size_t SchemesLen = sizeof(Schemes) / sizeof(Schemes[0]);
32 32
 
33 33
 struct Entry {
34 34
 	size_t tag;
35 35
 	char *url;
36 36
 };
37 37
 
38
-enum { RING_LEN = 32 };
39
-static_assert(!(RING_LEN & (RING_LEN - 1)), "power of two RING_LEN");
38
+enum { RingLen = 32 };
39
+static_assert(!(RingLen & (RingLen - 1)), "power of two RingLen");
40 40
 
41 41
 static struct {
42
-	struct Entry buf[RING_LEN];
42
+	struct Entry buf[RingLen];
43 43
 	size_t end;
44 44
 } ring;
45 45
 
@@ -48,14 +48,14 @@ static void push(struct Tag tag, const char *url, size_t len) {
48 48
 	ring.buf[ring.end].tag = tag.id;
49 49
 	ring.buf[ring.end].url = strndup(url, len);
50 50
 	if (!ring.buf[ring.end].url) err(EX_OSERR, "strndup");
51
-	ring.end = (ring.end + 1) & (RING_LEN - 1);
51
+	ring.end = (ring.end + 1) & (RingLen - 1);
52 52
 }
53 53
 
54 54
 void urlScan(struct Tag tag, const char *str) {
55 55
 	while (str[0]) {
56 56
 		size_t len = 1;
57
-		for (size_t i = 0; i < SCHEMES_LEN; ++i) {
58
-			if (strncmp(str, SCHEMES[i], strlen(SCHEMES[i]))) continue;
57
+		for (size_t i = 0; i < SchemesLen; ++i) {
58
+			if (strncmp(str, Schemes[i], strlen(Schemes[i]))) continue;
59 59
 			len = strcspn(str, " >\"");
60 60
 			push(tag, str, len);
61 61
 		}
@@ -65,8 +65,8 @@ void urlScan(struct Tag tag, const char *str) {
65 65
 
66 66
 void urlList(struct Tag tag) {
67 67
 	uiHide();
68
-	for (size_t i = 0; i < RING_LEN; ++i) {
69
-		struct Entry entry = ring.buf[(ring.end + i) & (RING_LEN - 1)];
68
+	for (size_t i = 0; i < RingLen; ++i) {
69
+		struct Entry entry = ring.buf[(ring.end + i) & (RingLen - 1)];
70 70
 		if (!entry.url || entry.tag != tag.id) continue;
71 71
 		printf("%s\n", entry.url);
72 72
 	}
@@ -74,10 +74,10 @@ void urlList(struct Tag tag) {
74 74
 
75 75
 void urlOpen(struct Tag tag, size_t at, size_t to) {
76 76
 	size_t argc = 1;
77
-	char *argv[2 + RING_LEN] = { "open" };
77
+	char *argv[2 + RingLen] = { "open" };
78 78
 	size_t tagIndex = 0;
79
-	for (size_t i = 0; i < RING_LEN; ++i) {
80
-		struct Entry entry = ring.buf[(ring.end - i) & (RING_LEN - 1)];
79
+	for (size_t i = 0; i < RingLen; ++i) {
80
+		struct Entry entry = ring.buf[(ring.end - i) & (RingLen - 1)];
81 81
 		if (!entry.url || entry.tag != tag.id) continue;
82 82
 		if (tagIndex >= at && tagIndex < to) argv[argc++] = entry.url;
83 83
 		tagIndex++;

Loading…
Cancel
Save