Replace small integers in size_t with uint

master
C. McEnroe 2020-02-15 22:19:55 -05:00
parent 83df94b359
commit 700b5d5870
9 changed files with 146 additions and 145 deletions

2
chat.c
View File

@ -63,7 +63,7 @@ enum Color idColors[IDCap] = {
[Network] = Gray, [Network] = Gray,
}; };
size_t idNext = Network + 1; uint idNext = Network + 1;
struct Network network; struct Network network;
struct Self self = { .color = Default }; struct Self self = { .color = Default };

75
chat.h
View File

@ -26,6 +26,7 @@
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0])) #define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
#define BIT(x) x##Bit, x = 1 << x##Bit, x##Bit_ = x##Bit #define BIT(x) x##Bit, x = 1 << x##Bit, x##Bit_ = x##Bit
typedef unsigned uint;
typedef unsigned char byte; typedef unsigned char byte;
enum Color { enum Color {
@ -38,17 +39,17 @@ enum Color {
enum { None, Debug, Network, IDCap = 256 }; enum { None, Debug, Network, IDCap = 256 };
extern char *idNames[IDCap]; extern char *idNames[IDCap];
extern enum Color idColors[IDCap]; extern enum Color idColors[IDCap];
extern size_t idNext; extern uint idNext;
static inline size_t idFind(const char *name) { static inline uint idFind(const char *name) {
for (size_t id = 0; id < idNext; ++id) { for (uint id = 0; id < idNext; ++id) {
if (!strcmp(idNames[id], name)) return id; if (!strcmp(idNames[id], name)) return id;
} }
return None; return None;
} }
static inline size_t idFor(const char *name) { static inline uint idFor(const char *name) {
size_t id = idFind(name); uint id = idFind(name);
if (id) return id; if (id) return id;
if (idNext == IDCap) return Network; if (idNext == IDCap) return Network;
idNames[idNext] = strdup(name); idNames[idNext] = strdup(name);
@ -141,29 +142,29 @@ void ircFormat(const char *format, ...)
void ircClose(void); void ircClose(void);
extern struct Replies { extern struct Replies {
size_t away; uint away;
size_t join; uint join;
size_t list; uint list;
size_t names; uint names;
size_t topic; uint topic;
size_t whois; uint whois;
} replies; } replies;
size_t execID; uint execID;
int execPipe[2]; int execPipe[2];
void handle(struct Message msg); void handle(struct Message msg);
void command(size_t id, char *input); void command(uint id, char *input);
const char *commandIsPrivmsg(size_t id, const char *input); const char *commandIsPrivmsg(uint id, const char *input);
const char *commandIsNotice(size_t id, const char *input); const char *commandIsNotice(uint id, const char *input);
const char *commandIsAction(size_t id, const char *input); const char *commandIsAction(uint id, const char *input);
void commandComplete(void); void commandComplete(void);
int utilPipe[2]; int utilPipe[2];
enum { UtilCap = 16 }; enum { UtilCap = 16 };
struct Util { struct Util {
size_t argc; uint argc;
const char *argv[UtilCap]; const char *argv[UtilCap];
}; };
@ -181,15 +182,15 @@ void uiInit(void);
void uiShow(void); void uiShow(void);
void uiHide(void); void uiHide(void);
void uiDraw(void); void uiDraw(void);
void uiShowID(size_t id); void uiShowID(uint id);
void uiShowNum(size_t num); void uiShowNum(uint num);
void uiMoveID(size_t id, size_t num); void uiMoveID(uint id, uint num);
void uiCloseID(size_t id); void uiCloseID(uint id);
void uiCloseNum(size_t id); void uiCloseNum(uint id);
void uiRead(void); void uiRead(void);
void uiWrite(size_t id, enum Heat heat, const time_t *time, const char *str); void uiWrite(uint id, enum Heat heat, const time_t *time, const char *str);
void uiFormat( void uiFormat(
size_t id, enum Heat heat, const time_t *time, const char *format, ... uint id, enum Heat heat, const time_t *time, const char *format, ...
) __attribute__((format(printf, 4, 5))); ) __attribute__((format(printf, 4, 5)));
void uiLoad(const char *name); void uiLoad(const char *name);
int uiSave(const char *name); int uiSave(const char *name);
@ -213,26 +214,26 @@ enum Edit {
EditComplete, EditComplete,
EditEnter, EditEnter,
}; };
void edit(size_t id, enum Edit op, wchar_t ch); void edit(uint id, enum Edit op, wchar_t ch);
char *editBuffer(size_t *pos); char *editBuffer(size_t *pos);
const char *complete(size_t id, const char *prefix); const char *complete(uint id, const char *prefix);
void completeAccept(void); void completeAccept(void);
void completeReject(void); void completeReject(void);
void completeAdd(size_t id, const char *str, enum Color color); void completeAdd(uint id, const char *str, enum Color color);
void completeTouch(size_t id, const char *str, enum Color color); void completeTouch(uint id, const char *str, enum Color color);
void completeReplace(size_t id, const char *old, const char *new); void completeReplace(uint id, const char *old, const char *new);
void completeRemove(size_t id, const char *str); void completeRemove(uint id, const char *str);
void completeClear(size_t id); void completeClear(uint id);
size_t completeID(const char *str); uint completeID(const char *str);
enum Color completeColor(size_t id, const char *str); enum Color completeColor(uint id, const char *str);
extern struct Util urlOpenUtil; extern struct Util urlOpenUtil;
extern struct Util urlCopyUtil; extern struct Util urlCopyUtil;
void urlScan(size_t id, const char *nick, const char *mesg); void urlScan(uint id, const char *nick, const char *mesg);
void urlOpenCount(size_t id, size_t count); void urlOpenCount(uint id, uint count);
void urlOpenMatch(size_t id, const char *str); void urlOpenMatch(uint id, const char *str);
void urlCopyMatch(size_t id, const char *str); void urlCopyMatch(uint id, const char *str);
FILE *configOpen(const char *path, const char *mode); FILE *configOpen(const char *path, const char *mode);
FILE *dataOpen(const char *path, const char *mode); FILE *dataOpen(const char *path, const char *mode);

View File

@ -22,9 +22,9 @@
#include "chat.h" #include "chat.h"
typedef void Command(size_t id, char *params); typedef void Command(uint id, char *params);
static void commandDebug(size_t id, char *params) { static void commandDebug(uint id, char *params) {
(void)id; (void)id;
(void)params; (void)params;
self.debug ^= true; self.debug ^= true;
@ -34,12 +34,12 @@ static void commandDebug(size_t id, char *params) {
); );
} }
static void commandQuote(size_t id, char *params) { static void commandQuote(uint id, char *params) {
(void)id; (void)id;
if (params) ircFormat("%s\r\n", params); if (params) ircFormat("%s\r\n", params);
} }
static void commandPrivmsg(size_t id, char *params) { static void commandPrivmsg(uint id, char *params) {
if (!params || !params[0]) return; if (!params || !params[0]) return;
ircFormat("PRIVMSG %s :%s\r\n", idNames[id], params); ircFormat("PRIVMSG %s :%s\r\n", idNames[id], params);
struct Message msg = { struct Message msg = {
@ -52,7 +52,7 @@ static void commandPrivmsg(size_t id, char *params) {
handle(msg); handle(msg);
} }
static void commandNotice(size_t id, char *params) { static void commandNotice(uint id, char *params) {
if (!params || !params[0]) return; if (!params || !params[0]) return;
ircFormat("NOTICE %s :%s\r\n", idNames[id], params); ircFormat("NOTICE %s :%s\r\n", idNames[id], params);
struct Message msg = { struct Message msg = {
@ -65,21 +65,21 @@ static void commandNotice(size_t id, char *params) {
handle(msg); handle(msg);
} }
static void commandMe(size_t id, char *params) { static void commandMe(uint id, char *params) {
char buf[512]; char buf[512];
snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ? params : "")); snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ? params : ""));
commandPrivmsg(id, buf); commandPrivmsg(id, buf);
} }
static void commandMsg(size_t id, char *params) { static void commandMsg(uint id, char *params) {
(void)id; (void)id;
char *nick = strsep(&params, " "); char *nick = strsep(&params, " ");
if (!params) return; if (!params) return;
commandPrivmsg(idFor(nick), params); commandPrivmsg(idFor(nick), params);
} }
static void commandJoin(size_t id, char *params) { static void commandJoin(uint id, char *params) {
size_t count = 1; uint count = 1;
if (params) { if (params) {
for (char *ch = params; *ch && *ch != ' '; ++ch) { for (char *ch = params; *ch && *ch != ' '; ++ch) {
if (*ch == ',') count++; if (*ch == ',') count++;
@ -91,7 +91,7 @@ static void commandJoin(size_t id, char *params) {
replies.names += count; replies.names += count;
} }
static void commandPart(size_t id, char *params) { static void commandPart(uint id, char *params) {
if (params) { if (params) {
ircFormat("PART %s :%s\r\n", idNames[id], params); ircFormat("PART %s :%s\r\n", idNames[id], params);
} else { } else {
@ -99,18 +99,18 @@ static void commandPart(size_t id, char *params) {
} }
} }
static void commandQuit(size_t id, char *params) { static void commandQuit(uint id, char *params) {
(void)id; (void)id;
set(&self.quit, (params ? params : "Goodbye")); set(&self.quit, (params ? params : "Goodbye"));
} }
static void commandNick(size_t id, char *params) { static void commandNick(uint id, char *params) {
(void)id; (void)id;
if (!params) return; if (!params) return;
ircFormat("NICK :%s\r\n", params); ircFormat("NICK :%s\r\n", params);
} }
static void commandAway(size_t id, char *params) { static void commandAway(uint id, char *params) {
(void)id; (void)id;
if (params) { if (params) {
ircFormat("AWAY :%s\r\n", params); ircFormat("AWAY :%s\r\n", params);
@ -120,7 +120,7 @@ static void commandAway(size_t id, char *params) {
replies.away++; replies.away++;
} }
static void commandTopic(size_t id, char *params) { static void commandTopic(uint id, char *params) {
if (params) { if (params) {
ircFormat("TOPIC %s :%s\r\n", idNames[id], params); ircFormat("TOPIC %s :%s\r\n", idNames[id], params);
} else { } else {
@ -129,19 +129,19 @@ static void commandTopic(size_t id, char *params) {
} }
} }
static void commandNames(size_t id, char *params) { static void commandNames(uint id, char *params) {
(void)params; (void)params;
ircFormat("NAMES :%s\r\n", idNames[id]); ircFormat("NAMES :%s\r\n", idNames[id]);
replies.names++; replies.names++;
} }
static void commandInvite(size_t id, char *params) { static void commandInvite(uint id, char *params) {
if (!params) return; if (!params) return;
char *nick = strsep(&params, " "); char *nick = strsep(&params, " ");
ircFormat("INVITE %s %s\r\n", nick, idNames[id]); ircFormat("INVITE %s %s\r\n", nick, idNames[id]);
} }
static void commandKick(size_t id, char *params) { static void commandKick(uint id, char *params) {
if (!params) return; if (!params) return;
char *nick = strsep(&params, " "); char *nick = strsep(&params, " ");
if (params) { if (params) {
@ -151,7 +151,7 @@ static void commandKick(size_t id, char *params) {
} }
} }
static void commandList(size_t id, char *params) { static void commandList(uint id, char *params) {
(void)id; (void)id;
if (params) { if (params) {
ircFormat("LIST :%s\r\n", params); ircFormat("LIST :%s\r\n", params);
@ -161,33 +161,33 @@ static void commandList(size_t id, char *params) {
replies.list++; replies.list++;
} }
static void commandWhois(size_t id, char *params) { static void commandWhois(uint id, char *params) {
(void)id; (void)id;
if (!params) return; if (!params) return;
ircFormat("WHOIS :%s\r\n", params); ircFormat("WHOIS :%s\r\n", params);
replies.whois++; replies.whois++;
} }
static void commandNS(size_t id, char *params) { static void commandNS(uint id, char *params) {
(void)id; (void)id;
if (!params) return; if (!params) return;
ircFormat("PRIVMSG NickServ :%s\r\n", params); ircFormat("PRIVMSG NickServ :%s\r\n", params);
} }
static void commandCS(size_t id, char *params) { static void commandCS(uint id, char *params) {
(void)id; (void)id;
if (!params) return; if (!params) return;
ircFormat("PRIVMSG ChanServ :%s\r\n", params); ircFormat("PRIVMSG ChanServ :%s\r\n", params);
} }
static void commandQuery(size_t id, char *params) { static void commandQuery(uint id, char *params) {
if (!params) return; if (!params) return;
size_t query = idFor(params); uint query = idFor(params);
idColors[query] = completeColor(id, params); idColors[query] = completeColor(id, params);
uiShowID(query); uiShowID(query);
} }
static void commandWindow(size_t id, char *params) { static void commandWindow(uint id, char *params) {
if (!params) return; if (!params) return;
if (isdigit(params[0])) { if (isdigit(params[0])) {
uiShowNum(strtoul(params, NULL, 10)); uiShowNum(strtoul(params, NULL, 10));
@ -197,7 +197,7 @@ static void commandWindow(size_t id, char *params) {
} }
} }
static void commandMove(size_t id, char *params) { static void commandMove(uint id, char *params) {
if (!params) return; if (!params) return;
char *name = strsep(&params, " "); char *name = strsep(&params, " ");
if (params) { if (params) {
@ -208,7 +208,7 @@ static void commandMove(size_t id, char *params) {
} }
} }
static void commandClose(size_t id, char *params) { static void commandClose(uint id, char *params) {
if (!params) { if (!params) {
uiCloseID(id); uiCloseID(id);
} else if (isdigit(params[0])) { } else if (isdigit(params[0])) {
@ -219,7 +219,7 @@ static void commandClose(size_t id, char *params) {
} }
} }
static void commandOpen(size_t id, char *params) { static void commandOpen(uint id, char *params) {
if (!params) { if (!params) {
urlOpenCount(id, 1); urlOpenCount(id, 1);
} else if (isdigit(params[0])) { } else if (isdigit(params[0])) {
@ -229,11 +229,11 @@ static void commandOpen(size_t id, char *params) {
} }
} }
static void commandCopy(size_t id, char *params) { static void commandCopy(uint id, char *params) {
urlCopyMatch(id, params); urlCopyMatch(id, params);
} }
static void commandExec(size_t id, char *params) { static void commandExec(uint id, char *params) {
execID = id; execID = id;
pid_t pid = fork(); pid_t pid = fork();
@ -251,7 +251,7 @@ static void commandExec(size_t id, char *params) {
_exit(EX_UNAVAILABLE); _exit(EX_UNAVAILABLE);
} }
static void commandHelp(size_t id, char *params) { static void commandHelp(uint id, char *params) {
(void)id; (void)id;
uiHide(); uiHide();
@ -306,7 +306,7 @@ static int compar(const void *cmd, const void *_handler) {
return strcmp(cmd, handler->cmd); return strcmp(cmd, handler->cmd);
} }
const char *commandIsPrivmsg(size_t id, const char *input) { const char *commandIsPrivmsg(uint id, const char *input) {
if (id == Network || id == Debug) return NULL; if (id == Network || id == Debug) return NULL;
if (input[0] != '/') return input; if (input[0] != '/') return input;
const char *space = strchr(&input[1], ' '); const char *space = strchr(&input[1], ' ');
@ -315,19 +315,19 @@ const char *commandIsPrivmsg(size_t id, const char *input) {
return NULL; return NULL;
} }
const char *commandIsNotice(size_t id, const char *input) { const char *commandIsNotice(uint id, const char *input) {
if (id == Network || id == Debug) return NULL; if (id == Network || id == Debug) return NULL;
if (strncmp(input, "/notice ", 8)) return NULL; if (strncmp(input, "/notice ", 8)) return NULL;
return &input[8]; return &input[8];
} }
const char *commandIsAction(size_t id, const char *input) { const char *commandIsAction(uint id, const char *input) {
if (id == Network || id == Debug) return NULL; if (id == Network || id == Debug) return NULL;
if (strncmp(input, "/me ", 4)) return NULL; if (strncmp(input, "/me ", 4)) return NULL;
return &input[4]; return &input[4];
} }
void command(size_t id, char *input) { void command(uint id, char *input) {
if (id == Debug && input[0] != '/') { if (id == Debug && input[0] != '/') {
commandQuote(id, input); commandQuote(id, input);
} else if (commandIsPrivmsg(id, input)) { } else if (commandIsPrivmsg(id, input)) {

View File

@ -23,14 +23,14 @@
#include "chat.h" #include "chat.h"
struct Node { struct Node {
size_t id; uint id;
char *str; char *str;
enum Color color; enum Color color;
struct Node *prev; struct Node *prev;
struct Node *next; struct Node *next;
}; };
static struct Node *alloc(size_t id, const char *str, enum Color color) { static struct Node *alloc(uint id, const char *str, enum Color color) {
struct Node *node = malloc(sizeof(*node)); struct Node *node = malloc(sizeof(*node));
if (!node) err(EX_OSERR, "malloc"); if (!node) err(EX_OSERR, "malloc");
node->id = id; node->id = id;
@ -73,31 +73,31 @@ static struct Node *append(struct Node *node) {
return node; return node;
} }
static struct Node *find(size_t id, const char *str) { static struct Node *find(uint id, const char *str) {
for (struct Node *node = head; node; node = node->next) { for (struct Node *node = head; node; node = node->next) {
if (node->id == id && !strcmp(node->str, str)) return node; if (node->id == id && !strcmp(node->str, str)) return node;
} }
return NULL; return NULL;
} }
void completeAdd(size_t id, const char *str, enum Color color) { void completeAdd(uint id, const char *str, enum Color color) {
if (!find(id, str)) append(alloc(id, str, color)); if (!find(id, str)) append(alloc(id, str, color));
} }
void completeTouch(size_t id, const char *str, enum Color color) { void completeTouch(uint id, const char *str, enum Color color) {
struct Node *node = find(id, str); struct Node *node = find(id, str);
if (node && node->color != color) node->color = color; if (node && node->color != color) node->color = color;
prepend(node ? detach(node) : alloc(id, str, color)); prepend(node ? detach(node) : alloc(id, str, color));
} }
enum Color completeColor(size_t id, const char *str) { enum Color completeColor(uint id, const char *str) {
struct Node *node = find(id, str); struct Node *node = find(id, str);
return (node ? node->color : Default); return (node ? node->color : Default);
} }
static struct Node *match; static struct Node *match;
const char *complete(size_t id, const char *prefix) { const char *complete(uint id, const char *prefix) {
for (match = (match ? match->next : head); match; match = match->next) { for (match = (match ? match->next : head); match; match = match->next) {
if (match->id && match->id != id) continue; if (match->id && match->id != id) continue;
if (strncasecmp(match->str, prefix, strlen(prefix))) continue; if (strncasecmp(match->str, prefix, strlen(prefix))) continue;
@ -115,14 +115,14 @@ void completeReject(void) {
match = NULL; match = NULL;
} }
size_t completeID(const char *str) { uint completeID(const char *str) {
for (match = (match ? match->next : head); match; match = match->next) { for (match = (match ? match->next : head); match; match = match->next) {
if (match->id && !strcmp(match->str, str)) return match->id; if (match->id && !strcmp(match->str, str)) return match->id;
} }
return None; return None;
} }
void completeReplace(size_t id, const char *old, const char *new) { void completeReplace(uint id, const char *old, const char *new) {
struct Node *next = NULL; struct Node *next = NULL;
for (struct Node *node = head; node; node = next) { for (struct Node *node = head; node; node = next) {
next = node->next; next = node->next;
@ -136,7 +136,7 @@ void completeReplace(size_t id, const char *old, const char *new) {
} }
} }
void completeRemove(size_t id, const char *str) { void completeRemove(uint id, const char *str) {
struct Node *next = NULL; struct Node *next = NULL;
for (struct Node *node = head; node; node = next) { for (struct Node *node = head; node; node = next) {
next = node->next; next = node->next;
@ -149,7 +149,7 @@ void completeRemove(size_t id, const char *str) {
} }
} }
void completeClear(size_t id) { void completeClear(uint id) {
struct Node *next = NULL; struct Node *next = NULL;
for (struct Node *node = head; node; node = next) { for (struct Node *node = head; node; node = next) {
next = node->next; next = node->next;

4
edit.c
View File

@ -78,7 +78,7 @@ static struct {
size_t len; size_t len;
} tab; } tab;
static void tabComplete(size_t id) { static void tabComplete(uint id) {
if (!tab.len) { if (!tab.len) {
tab.pos = pos; tab.pos = pos;
while (tab.pos && buf[tab.pos - 1] != L' ') tab.pos--; while (tab.pos && buf[tab.pos - 1] != L' ') tab.pos--;
@ -142,7 +142,7 @@ static void tabReject(void) {
tab.len = 0; tab.len = 0;
} }
void edit(size_t id, enum Edit op, wchar_t ch) { void edit(uint id, enum Edit op, wchar_t ch) {
size_t init = pos; size_t init = pos;
switch (op) { switch (op) {
break; case EditHead: pos = 0; break; case EditHead: pos = 0;

View File

@ -63,15 +63,15 @@ static const char *capList(enum Cap caps) {
return buf; return buf;
} }
static void require(struct Message *msg, bool origin, size_t len) { static void require(struct Message *msg, bool origin, uint len) {
if (origin) { if (origin) {
if (!msg->nick) errx(EX_PROTOCOL, "%s missing origin", msg->cmd); if (!msg->nick) errx(EX_PROTOCOL, "%s missing origin", msg->cmd);
if (!msg->user) msg->user = msg->nick; if (!msg->user) msg->user = msg->nick;
if (!msg->host) msg->host = msg->user; if (!msg->host) msg->host = msg->user;
} }
for (size_t i = 0; i < len; ++i) { for (uint i = 0; i < len; ++i) {
if (msg->params[i]) continue; if (msg->params[i]) continue;
errx(EX_PROTOCOL, "%s missing parameter %zu", msg->cmd, 1 + i); errx(EX_PROTOCOL, "%s missing parameter %u", msg->cmd, 1 + i);
} }
} }
@ -195,7 +195,7 @@ static void handleReplyWelcome(struct Message *msg) {
set(&self.nick, msg->params[0]); set(&self.nick, msg->params[0]);
completeTouch(Network, self.nick, Default); completeTouch(Network, self.nick, Default);
if (self.join) { if (self.join) {
size_t count = 1; uint count = 1;
for (const char *ch = self.join; *ch && *ch != ' '; ++ch) { for (const char *ch = self.join; *ch && *ch != ' '; ++ch) {
if (*ch == ',') count++; if (*ch == ',') count++;
} }
@ -207,7 +207,7 @@ static void handleReplyWelcome(struct Message *msg) {
} }
static void handleReplyISupport(struct Message *msg) { static void handleReplyISupport(struct Message *msg) {
for (size_t i = 1; i < ParamCap; ++i) { for (uint i = 1; i < ParamCap; ++i) {
if (!msg->params[i]) break; if (!msg->params[i]) break;
char *key = strsep(&msg->params[i], "="); char *key = strsep(&msg->params[i], "=");
if (!msg->params[i]) continue; if (!msg->params[i]) continue;
@ -245,7 +245,7 @@ static void handleReplyMOTD(struct Message *msg) {
static void handleJoin(struct Message *msg) { static void handleJoin(struct Message *msg) {
require(msg, true, 1); require(msg, true, 1);
size_t id = idFor(msg->params[0]); uint id = idFor(msg->params[0]);
if (!strcmp(msg->nick, self.nick)) { if (!strcmp(msg->nick, self.nick)) {
if (!self.user) { if (!self.user) {
set(&self.user, msg->user); set(&self.user, msg->user);
@ -275,7 +275,7 @@ static void handleJoin(struct Message *msg) {
static void handlePart(struct Message *msg) { static void handlePart(struct Message *msg) {
require(msg, true, 1); require(msg, true, 1);
size_t id = idFor(msg->params[0]); uint id = idFor(msg->params[0]);
if (!strcmp(msg->nick, self.nick)) { if (!strcmp(msg->nick, self.nick)) {
completeClear(id); completeClear(id);
} }
@ -292,7 +292,7 @@ static void handlePart(struct Message *msg) {
static void handleKick(struct Message *msg) { static void handleKick(struct Message *msg) {
require(msg, true, 2); require(msg, true, 2);
size_t id = idFor(msg->params[0]); uint id = idFor(msg->params[0]);
bool kicked = !strcmp(msg->params[1], self.nick); bool kicked = !strcmp(msg->params[1], self.nick);
completeTouch(id, msg->nick, hash(msg->user)); completeTouch(id, msg->nick, hash(msg->user));
urlScan(id, msg->nick, msg->params[2]); urlScan(id, msg->nick, msg->params[2]);
@ -316,7 +316,7 @@ static void handleNick(struct Message *msg) {
set(&self.nick, msg->params[0]); set(&self.nick, msg->params[0]);
uiRead(); // Update prompt. uiRead(); // Update prompt.
} }
size_t id; uint id;
while (None != (id = completeID(msg->nick))) { while (None != (id = completeID(msg->nick))) {
if (!strcmp(idNames[id], msg->nick)) { if (!strcmp(idNames[id], msg->nick)) {
set(&idNames[id], msg->params[0]); set(&idNames[id], msg->params[0]);
@ -332,7 +332,7 @@ static void handleNick(struct Message *msg) {
static void handleQuit(struct Message *msg) { static void handleQuit(struct Message *msg) {
require(msg, true, 0); require(msg, true, 0);
size_t id; uint id;
while (None != (id = completeID(msg->nick))) { while (None != (id = completeID(msg->nick))) {
urlScan(id, msg->nick, msg->params[0]); urlScan(id, msg->nick, msg->params[0]);
uiFormat( uiFormat(
@ -348,7 +348,7 @@ static void handleQuit(struct Message *msg) {
static void handleReplyNames(struct Message *msg) { static void handleReplyNames(struct Message *msg) {
require(msg, false, 4); require(msg, false, 4);
size_t id = idFor(msg->params[2]); uint id = idFor(msg->params[2]);
char buf[1024]; char buf[1024];
size_t len = 0; size_t len = 0;
while (msg->params[3]) { while (msg->params[3]) {
@ -394,7 +394,7 @@ static void handleReplyTopic(struct Message *msg) {
require(msg, false, 3); require(msg, false, 3);
if (!replies.topic) return; if (!replies.topic) return;
replies.topic--; replies.topic--;
size_t id = idFor(msg->params[1]); uint id = idFor(msg->params[1]);
urlScan(id, NULL, msg->params[2]); urlScan(id, NULL, msg->params[2]);
uiFormat( uiFormat(
id, Cold, tagTime(msg), id, Cold, tagTime(msg),
@ -405,7 +405,7 @@ static void handleReplyTopic(struct Message *msg) {
static void handleTopic(struct Message *msg) { static void handleTopic(struct Message *msg) {
require(msg, true, 2); require(msg, true, 2);
size_t id = idFor(msg->params[0]); uint id = idFor(msg->params[0]);
if (msg->params[1][0]) { if (msg->params[1][0]) {
urlScan(id, msg->nick, msg->params[1]); urlScan(id, msg->nick, msg->params[1]);
uiFormat( uiFormat(
@ -560,7 +560,7 @@ static void handleReplyEndOfWhois(struct Message *msg) {
static void handleReplyAway(struct Message *msg) { static void handleReplyAway(struct Message *msg) {
require(msg, false, 3); require(msg, false, 3);
// Might be part of a WHOIS response. // Might be part of a WHOIS response.
size_t id; uint id;
if (completeColor(Network, msg->params[1]) != Default) { if (completeColor(Network, msg->params[1]) != Default) {
id = Network; id = Network;
} else { } else {
@ -602,7 +602,7 @@ static bool isMention(const struct Message *msg) {
return false; return false;
} }
static const char *colorMentions(size_t id, struct Message *msg) { static const char *colorMentions(uint id, struct Message *msg) {
char *split = strchr(msg->params[1], ':'); char *split = strchr(msg->params[1], ':');
if (!split) { if (!split) {
split = strchr(msg->params[1], ' '); split = strchr(msg->params[1], ' ');
@ -650,7 +650,7 @@ static void handlePrivmsg(struct Message *msg) {
bool query = !strchr(network.chanTypes, msg->params[0][0]); bool query = !strchr(network.chanTypes, msg->params[0][0]);
bool server = strchr(msg->nick, '.'); bool server = strchr(msg->nick, '.');
bool mine = !strcmp(msg->nick, self.nick); bool mine = !strcmp(msg->nick, self.nick);
size_t id; uint id;
if (query && server) { if (query && server) {
id = Network; id = Network;
} else if (query && !mine) { } else if (query && !mine) {

4
irc.c
View File

@ -220,7 +220,7 @@ static struct Message parse(char *line) {
while (tags) { while (tags) {
char *tag = strsep(&tags, ";"); char *tag = strsep(&tags, ";");
char *key = strsep(&tag, "="); char *key = strsep(&tag, "=");
for (size_t i = 0; i < TagCap; ++i) { for (uint i = 0; i < TagCap; ++i) {
if (strcmp(key, TagNames[i])) continue; if (strcmp(key, TagNames[i])) continue;
unescape(tag); unescape(tag);
msg.tags[i] = tag; msg.tags[i] = tag;
@ -237,7 +237,7 @@ static struct Message parse(char *line) {
} }
msg.cmd = strsep(&line, " "); msg.cmd = strsep(&line, " ");
for (size_t i = 0; line && i < ParamCap; ++i) { for (uint i = 0; line && i < ParamCap; ++i) {
if (line[0] == ':') { if (line[0] == ':') {
msg.params[i] = &line[1]; msg.params[i] = &line[1];
break; break;

66
ui.c
View File

@ -78,31 +78,31 @@ static const char *bufferLine(const struct Buffer *buffer, size_t i) {
enum { WindowLines = BufferCap }; enum { WindowLines = BufferCap };
struct Window { struct Window {
size_t id; uint id;
struct Buffer buffer; struct Buffer buffer;
WINDOW *pad; WINDOW *pad;
int scroll; int scroll;
bool mark; bool mark;
enum Heat heat; enum Heat heat;
int unreadTotal; uint unreadTotal;
int unreadWarm; uint unreadWarm;
int unreadLines; uint unreadLines;
}; };
static struct { static struct {
size_t show; uint show;
size_t swap; uint swap;
struct Window *ptrs[IDCap]; struct Window *ptrs[IDCap];
size_t len; uint len;
} windows; } windows;
static size_t windowPush(struct Window *window) { static uint windowPush(struct Window *window) {
assert(windows.len < IDCap); assert(windows.len < IDCap);
windows.ptrs[windows.len] = window; windows.ptrs[windows.len] = window;
return windows.len++; return windows.len++;
} }
static size_t windowInsert(size_t num, struct Window *window) { static uint windowInsert(uint num, struct Window *window) {
assert(windows.len < IDCap); assert(windows.len < IDCap);
assert(num <= windows.len); assert(num <= windows.len);
memmove( memmove(
@ -115,7 +115,7 @@ static size_t windowInsert(size_t num, struct Window *window) {
return num; return num;
} }
static struct Window *windowRemove(size_t num) { static struct Window *windowRemove(uint num) {
assert(num < windows.len); assert(num < windows.len);
struct Window *window = windows.ptrs[num]; struct Window *window = windows.ptrs[num];
windows.len--; windows.len--;
@ -127,8 +127,8 @@ static struct Window *windowRemove(size_t num) {
return window; return window;
} }
static size_t windowFor(size_t id) { static uint windowFor(uint id) {
for (size_t num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
if (windows.ptrs[num]->id == id) return num; if (windows.ptrs[num]->id == id) return num;
} }
@ -403,7 +403,7 @@ static void statusUpdate(void) {
enum Heat otherHeat = Cold; enum Heat otherHeat = Cold;
wmove(status, 0, 0); wmove(status, 0, 0);
for (size_t num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
const struct Window *window = windows.ptrs[num]; const struct Window *window = windows.ptrs[num];
if (!window->heat && num != windows.show) continue; if (!window->heat && num != windows.show) continue;
if (num != windows.show) { if (num != windows.show) {
@ -413,7 +413,7 @@ static void statusUpdate(void) {
int trunc; int trunc;
char buf[256]; char buf[256];
snprintf( snprintf(
buf, sizeof(buf), "\3%d%s %zu %s %n(\3%02d%d\3%d) ", buf, sizeof(buf), "\3%d%s %u %s %n(\3%02d%d\3%d) ",
idColors[window->id], (num == windows.show ? "\26" : ""), idColors[window->id], (num == windows.show ? "\26" : ""),
num, idNames[window->id], num, idNames[window->id],
&trunc, (window->heat > Warm ? White : idColors[window->id]), &trunc, (window->heat > Warm ? White : idColors[window->id]),
@ -555,7 +555,7 @@ static int wordWrap(WINDOW *win, const char *str) {
} }
struct Util uiNotifyUtil; struct Util uiNotifyUtil;
static void notify(size_t id, const char *str) { static void notify(uint id, const char *str) {
if (!uiNotifyUtil.argc) return; if (!uiNotifyUtil.argc) return;
struct Util util = uiNotifyUtil; struct Util util = uiNotifyUtil;
@ -583,7 +583,7 @@ static void notify(size_t id, const char *str) {
_exit(EX_CONFIG); _exit(EX_CONFIG);
} }
void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) { void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) {
struct Window *window = windows.ptrs[windowFor(id)]; struct Window *window = windows.ptrs[windowFor(id)];
time_t clock = (src ? *src : time(NULL)); time_t clock = (src ? *src : time(NULL));
bufferPush(&window->buffer, clock, str); bufferPush(&window->buffer, clock, str);
@ -609,7 +609,7 @@ void uiWrite(size_t id, enum Heat heat, const time_t *src, const char *str) {
} }
void uiFormat( void uiFormat(
size_t id, enum Heat heat, const time_t *time, const char *format, ... uint id, enum Heat heat, const time_t *time, const char *format, ...
) { ) {
char buf[1024]; char buf[1024];
va_list ap; va_list ap;
@ -641,7 +641,7 @@ static void resize(void) {
int height, width; int height, width;
getmaxyx(windows.ptrs[0]->pad, height, width); getmaxyx(windows.ptrs[0]->pad, height, width);
if (width == COLS) return; if (width == COLS) return;
for (size_t num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
wresize(windows.ptrs[num]->pad, BufferCap, COLS); wresize(windows.ptrs[num]->pad, BufferCap, COLS);
reflow(windows.ptrs[num]); reflow(windows.ptrs[num]);
} }
@ -715,7 +715,7 @@ static void inputAdd(struct Style *style, const char *str) {
} }
static void inputUpdate(void) { static void inputUpdate(void) {
size_t id = windows.ptrs[windows.show]->id; uint id = windows.ptrs[windows.show]->id;
size_t pos; size_t pos;
char *buf = editBuffer(&pos); char *buf = editBuffer(&pos);
@ -768,7 +768,7 @@ static void inputUpdate(void) {
wmove(input, y, x); wmove(input, y, x);
} }
static void windowShow(size_t num) { static void windowShow(uint num) {
touchwin(windows.ptrs[num]->pad); touchwin(windows.ptrs[num]->pad);
windows.swap = windows.show; windows.swap = windows.show;
windows.show = num; windows.show = num;
@ -777,15 +777,15 @@ static void windowShow(size_t num) {
inputUpdate(); inputUpdate();
} }
void uiShowID(size_t id) { void uiShowID(uint id) {
windowShow(windowFor(id)); windowShow(windowFor(id));
} }
void uiShowNum(size_t num) { void uiShowNum(uint num) {
if (num < windows.len) windowShow(num); if (num < windows.len) windowShow(num);
} }
void uiMoveID(size_t id, size_t num) { void uiMoveID(uint id, uint num) {
struct Window *window = windowRemove(windowFor(id)); struct Window *window = windowRemove(windowFor(id));
if (num < windows.len) { if (num < windows.len) {
windowShow(windowInsert(num, window)); windowShow(windowInsert(num, window));
@ -794,7 +794,7 @@ void uiMoveID(size_t id, size_t num) {
} }
} }
static void windowClose(size_t num) { static void windowClose(uint num) {
if (windows.ptrs[num]->id == Network) return; if (windows.ptrs[num]->id == Network) return;
struct Window *window = windowRemove(num); struct Window *window = windowRemove(num);
completeClear(window->id); completeClear(window->id);
@ -809,26 +809,26 @@ static void windowClose(size_t num) {
statusUpdate(); statusUpdate();
} }
void uiCloseID(size_t id) { void uiCloseID(uint id) {
windowClose(windowFor(id)); windowClose(windowFor(id));
} }
void uiCloseNum(size_t num) { void uiCloseNum(uint num) {
if (num < windows.len) windowClose(num); if (num < windows.len) windowClose(num);
} }
static void showAuto(void) { static void showAuto(void) {
static size_t swap; static uint swap;
if (windows.swap != swap) { if (windows.swap != swap) {
swap = windows.show; swap = windows.show;
} }
for (size_t num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
if (windows.ptrs[num]->heat < Hot) continue; if (windows.ptrs[num]->heat < Hot) continue;
windowShow(num); windowShow(num);
windows.swap = swap; windows.swap = swap;
return; return;
} }
for (size_t num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
if (windows.ptrs[num]->heat < Warm) continue; if (windows.ptrs[num]->heat < Warm) continue;
windowShow(num); windowShow(num);
windows.swap = swap; windows.swap = swap;
@ -839,7 +839,7 @@ static void showAuto(void) {
static void keyCode(int code) { static void keyCode(int code) {
struct Window *window = windows.ptrs[windows.show]; struct Window *window = windows.ptrs[windows.show];
size_t id = window->id; uint id = window->id;
switch (code) { switch (code) {
break; case KEY_RESIZE: resize(); break; case KEY_RESIZE: resize();
break; case KeyFocusIn: unmark(window); break; case KeyFocusIn: unmark(window);
@ -880,7 +880,7 @@ static void keyCode(int code) {
static void keyCtrl(wchar_t ch) { static void keyCtrl(wchar_t ch) {
struct Window *window = windows.ptrs[windows.show]; struct Window *window = windows.ptrs[windows.show];
size_t id = window->id; uint id = window->id;
switch (ch ^ L'@') { switch (ch ^ L'@') {
break; case L'?': edit(id, EditDeletePrev, 0); break; case L'?': edit(id, EditDeletePrev, 0);
break; case L'A': edit(id, EditHead, 0); break; case L'A': edit(id, EditHead, 0);
@ -906,7 +906,7 @@ static void keyCtrl(wchar_t ch) {
} }
static void keyStyle(wchar_t ch) { static void keyStyle(wchar_t ch) {
size_t id = windows.ptrs[windows.show]->id; uint id = windows.ptrs[windows.show]->id;
switch (iswcntrl(ch) ? ch ^ L'@' : (wchar_t)towupper(ch)) { switch (iswcntrl(ch) ? ch ^ L'@' : (wchar_t)towupper(ch)) {
break; case L'B': edit(id, EditInsert, B); break; case L'B': edit(id, EditInsert, B);
break; case L'C': edit(id, EditInsert, C); break; case L'C': edit(id, EditInsert, C);
@ -973,7 +973,7 @@ int uiSave(const char *name) {
if (!file) return -1; if (!file) return -1;
if (writeTime(file, Signatures[1])) return -1; if (writeTime(file, Signatures[1])) return -1;
for (size_t num = 0; num < windows.len; ++num) { for (uint num = 0; num < windows.len; ++num) {
const struct Window *window = windows.ptrs[num]; const struct Window *window = windows.ptrs[num];
if (writeString(file, idNames[window->id])) return -1; if (writeString(file, idNames[window->id])) return -1;
if (writeTime(file, window->heat)) return -1; if (writeTime(file, window->heat)) return -1;

18
url.c
View File

@ -59,7 +59,7 @@ static void compile(void) {
} }
struct URL { struct URL {
size_t id; uint id;
char *nick; char *nick;
char *url; char *url;
}; };
@ -71,7 +71,7 @@ static struct {
} ring; } ring;
static_assert(!(Cap & (Cap - 1)), "Cap is power of two"); static_assert(!(Cap & (Cap - 1)), "Cap is power of two");
static void push(size_t id, const char *nick, const char *str, size_t len) { static void push(uint id, const char *nick, const char *str, size_t len) {
struct URL *url = &ring.urls[ring.len++ % Cap]; struct URL *url = &ring.urls[ring.len++ % Cap];
free(url->nick); free(url->nick);
free(url->url); free(url->url);
@ -85,7 +85,7 @@ static void push(size_t id, const char *nick, const char *str, size_t len) {
if (!url->url) err(EX_OSERR, "strndup"); if (!url->url) err(EX_OSERR, "strndup");
} }
void urlScan(size_t id, const char *nick, const char *mesg) { void urlScan(uint id, const char *nick, const char *mesg) {
if (!mesg) return; if (!mesg) return;
compile(); compile();
regmatch_t match = {0}; regmatch_t match = {0};
@ -175,8 +175,8 @@ static void urlCopy(const char *url) {
_exit(EX_CONFIG); _exit(EX_CONFIG);
} }
void urlOpenCount(size_t id, size_t count) { void urlOpenCount(uint id, uint count) {
for (size_t i = 1; i <= Cap; ++i) { for (uint i = 1; i <= Cap; ++i) {
const struct URL *url = &ring.urls[(ring.len - i) % Cap]; const struct URL *url = &ring.urls[(ring.len - i) % Cap];
if (!url->url) break; if (!url->url) break;
if (url->id != id) continue; if (url->id != id) continue;
@ -185,8 +185,8 @@ void urlOpenCount(size_t id, size_t count) {
} }
} }
void urlOpenMatch(size_t id, const char *str) { void urlOpenMatch(uint id, const char *str) {
for (size_t i = 1; i <= Cap; ++i) { for (uint i = 1; i <= Cap; ++i) {
const struct URL *url = &ring.urls[(ring.len - i) % Cap]; const struct URL *url = &ring.urls[(ring.len - i) % Cap];
if (!url->url) break; if (!url->url) break;
if (url->id != id) continue; if (url->id != id) continue;
@ -197,8 +197,8 @@ void urlOpenMatch(size_t id, const char *str) {
} }
} }
void urlCopyMatch(size_t id, const char *str) { void urlCopyMatch(uint id, const char *str) {
for (size_t i = 1; i <= Cap; ++i) { for (uint i = 1; i <= Cap; ++i) {
const struct URL *url = &ring.urls[(ring.len - i) % Cap]; const struct URL *url = &ring.urls[(ring.len - i) % Cap];
if (!url->url) break; if (!url->url) break;
if (url->id != id) continue; if (url->id != id) continue;