Replace small integers in size_t with uint
parent
83df94b359
commit
700b5d5870
2
chat.c
2
chat.c
|
@ -63,7 +63,7 @@ enum Color idColors[IDCap] = {
|
|||
[Network] = Gray,
|
||||
};
|
||||
|
||||
size_t idNext = Network + 1;
|
||||
uint idNext = Network + 1;
|
||||
|
||||
struct Network network;
|
||||
struct Self self = { .color = Default };
|
||||
|
|
75
chat.h
75
chat.h
|
@ -26,6 +26,7 @@
|
|||
#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
|
||||
#define BIT(x) x##Bit, x = 1 << x##Bit, x##Bit_ = x##Bit
|
||||
|
||||
typedef unsigned uint;
|
||||
typedef unsigned char byte;
|
||||
|
||||
enum Color {
|
||||
|
@ -38,17 +39,17 @@ enum Color {
|
|||
enum { None, Debug, Network, IDCap = 256 };
|
||||
extern char *idNames[IDCap];
|
||||
extern enum Color idColors[IDCap];
|
||||
extern size_t idNext;
|
||||
extern uint idNext;
|
||||
|
||||
static inline size_t idFind(const char *name) {
|
||||
for (size_t id = 0; id < idNext; ++id) {
|
||||
static inline uint idFind(const char *name) {
|
||||
for (uint id = 0; id < idNext; ++id) {
|
||||
if (!strcmp(idNames[id], name)) return id;
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
static inline size_t idFor(const char *name) {
|
||||
size_t id = idFind(name);
|
||||
static inline uint idFor(const char *name) {
|
||||
uint id = idFind(name);
|
||||
if (id) return id;
|
||||
if (idNext == IDCap) return Network;
|
||||
idNames[idNext] = strdup(name);
|
||||
|
@ -141,29 +142,29 @@ void ircFormat(const char *format, ...)
|
|||
void ircClose(void);
|
||||
|
||||
extern struct Replies {
|
||||
size_t away;
|
||||
size_t join;
|
||||
size_t list;
|
||||
size_t names;
|
||||
size_t topic;
|
||||
size_t whois;
|
||||
uint away;
|
||||
uint join;
|
||||
uint list;
|
||||
uint names;
|
||||
uint topic;
|
||||
uint whois;
|
||||
} replies;
|
||||
|
||||
size_t execID;
|
||||
uint execID;
|
||||
int execPipe[2];
|
||||
|
||||
void handle(struct Message msg);
|
||||
void command(size_t id, char *input);
|
||||
const char *commandIsPrivmsg(size_t id, const char *input);
|
||||
const char *commandIsNotice(size_t id, const char *input);
|
||||
const char *commandIsAction(size_t id, const char *input);
|
||||
void command(uint id, char *input);
|
||||
const char *commandIsPrivmsg(uint id, const char *input);
|
||||
const char *commandIsNotice(uint id, const char *input);
|
||||
const char *commandIsAction(uint id, const char *input);
|
||||
void commandComplete(void);
|
||||
|
||||
int utilPipe[2];
|
||||
|
||||
enum { UtilCap = 16 };
|
||||
struct Util {
|
||||
size_t argc;
|
||||
uint argc;
|
||||
const char *argv[UtilCap];
|
||||
};
|
||||
|
||||
|
@ -181,15 +182,15 @@ void uiInit(void);
|
|||
void uiShow(void);
|
||||
void uiHide(void);
|
||||
void uiDraw(void);
|
||||
void uiShowID(size_t id);
|
||||
void uiShowNum(size_t num);
|
||||
void uiMoveID(size_t id, size_t num);
|
||||
void uiCloseID(size_t id);
|
||||
void uiCloseNum(size_t id);
|
||||
void uiShowID(uint id);
|
||||
void uiShowNum(uint num);
|
||||
void uiMoveID(uint id, uint num);
|
||||
void uiCloseID(uint id);
|
||||
void uiCloseNum(uint id);
|
||||
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(
|
||||
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)));
|
||||
void uiLoad(const char *name);
|
||||
int uiSave(const char *name);
|
||||
|
@ -213,26 +214,26 @@ enum Edit {
|
|||
EditComplete,
|
||||
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);
|
||||
|
||||
const char *complete(size_t id, const char *prefix);
|
||||
const char *complete(uint id, const char *prefix);
|
||||
void completeAccept(void);
|
||||
void completeReject(void);
|
||||
void completeAdd(size_t id, const char *str, enum Color color);
|
||||
void completeTouch(size_t id, const char *str, enum Color color);
|
||||
void completeReplace(size_t id, const char *old, const char *new);
|
||||
void completeRemove(size_t id, const char *str);
|
||||
void completeClear(size_t id);
|
||||
size_t completeID(const char *str);
|
||||
enum Color completeColor(size_t id, const char *str);
|
||||
void completeAdd(uint id, const char *str, enum Color color);
|
||||
void completeTouch(uint id, const char *str, enum Color color);
|
||||
void completeReplace(uint id, const char *old, const char *new);
|
||||
void completeRemove(uint id, const char *str);
|
||||
void completeClear(uint id);
|
||||
uint completeID(const char *str);
|
||||
enum Color completeColor(uint id, const char *str);
|
||||
|
||||
extern struct Util urlOpenUtil;
|
||||
extern struct Util urlCopyUtil;
|
||||
void urlScan(size_t id, const char *nick, const char *mesg);
|
||||
void urlOpenCount(size_t id, size_t count);
|
||||
void urlOpenMatch(size_t id, const char *str);
|
||||
void urlCopyMatch(size_t id, const char *str);
|
||||
void urlScan(uint id, const char *nick, const char *mesg);
|
||||
void urlOpenCount(uint id, uint count);
|
||||
void urlOpenMatch(uint id, const char *str);
|
||||
void urlCopyMatch(uint id, const char *str);
|
||||
|
||||
FILE *configOpen(const char *path, const char *mode);
|
||||
FILE *dataOpen(const char *path, const char *mode);
|
||||
|
|
68
command.c
68
command.c
|
@ -22,9 +22,9 @@
|
|||
|
||||
#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)params;
|
||||
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;
|
||||
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;
|
||||
ircFormat("PRIVMSG %s :%s\r\n", idNames[id], params);
|
||||
struct Message msg = {
|
||||
|
@ -52,7 +52,7 @@ static void commandPrivmsg(size_t id, char *params) {
|
|||
handle(msg);
|
||||
}
|
||||
|
||||
static void commandNotice(size_t id, char *params) {
|
||||
static void commandNotice(uint id, char *params) {
|
||||
if (!params || !params[0]) return;
|
||||
ircFormat("NOTICE %s :%s\r\n", idNames[id], params);
|
||||
struct Message msg = {
|
||||
|
@ -65,21 +65,21 @@ static void commandNotice(size_t id, char *params) {
|
|||
handle(msg);
|
||||
}
|
||||
|
||||
static void commandMe(size_t id, char *params) {
|
||||
static void commandMe(uint id, char *params) {
|
||||
char buf[512];
|
||||
snprintf(buf, sizeof(buf), "\1ACTION %s\1", (params ? params : ""));
|
||||
commandPrivmsg(id, buf);
|
||||
}
|
||||
|
||||
static void commandMsg(size_t id, char *params) {
|
||||
static void commandMsg(uint id, char *params) {
|
||||
(void)id;
|
||||
char *nick = strsep(¶ms, " ");
|
||||
if (!params) return;
|
||||
commandPrivmsg(idFor(nick), params);
|
||||
}
|
||||
|
||||
static void commandJoin(size_t id, char *params) {
|
||||
size_t count = 1;
|
||||
static void commandJoin(uint id, char *params) {
|
||||
uint count = 1;
|
||||
if (params) {
|
||||
for (char *ch = params; *ch && *ch != ' '; ++ch) {
|
||||
if (*ch == ',') count++;
|
||||
|
@ -91,7 +91,7 @@ static void commandJoin(size_t id, char *params) {
|
|||
replies.names += count;
|
||||
}
|
||||
|
||||
static void commandPart(size_t id, char *params) {
|
||||
static void commandPart(uint id, char *params) {
|
||||
if (params) {
|
||||
ircFormat("PART %s :%s\r\n", idNames[id], params);
|
||||
} 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;
|
||||
set(&self.quit, (params ? params : "Goodbye"));
|
||||
}
|
||||
|
||||
static void commandNick(size_t id, char *params) {
|
||||
static void commandNick(uint id, char *params) {
|
||||
(void)id;
|
||||
if (!params) return;
|
||||
ircFormat("NICK :%s\r\n", params);
|
||||
}
|
||||
|
||||
static void commandAway(size_t id, char *params) {
|
||||
static void commandAway(uint id, char *params) {
|
||||
(void)id;
|
||||
if (params) {
|
||||
ircFormat("AWAY :%s\r\n", params);
|
||||
|
@ -120,7 +120,7 @@ static void commandAway(size_t id, char *params) {
|
|||
replies.away++;
|
||||
}
|
||||
|
||||
static void commandTopic(size_t id, char *params) {
|
||||
static void commandTopic(uint id, char *params) {
|
||||
if (params) {
|
||||
ircFormat("TOPIC %s :%s\r\n", idNames[id], params);
|
||||
} 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;
|
||||
ircFormat("NAMES :%s\r\n", idNames[id]);
|
||||
replies.names++;
|
||||
}
|
||||
|
||||
static void commandInvite(size_t id, char *params) {
|
||||
static void commandInvite(uint id, char *params) {
|
||||
if (!params) return;
|
||||
char *nick = strsep(¶ms, " ");
|
||||
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;
|
||||
char *nick = strsep(¶ms, " ");
|
||||
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;
|
||||
if (params) {
|
||||
ircFormat("LIST :%s\r\n", params);
|
||||
|
@ -161,33 +161,33 @@ static void commandList(size_t id, char *params) {
|
|||
replies.list++;
|
||||
}
|
||||
|
||||
static void commandWhois(size_t id, char *params) {
|
||||
static void commandWhois(uint id, char *params) {
|
||||
(void)id;
|
||||
if (!params) return;
|
||||
ircFormat("WHOIS :%s\r\n", params);
|
||||
replies.whois++;
|
||||
}
|
||||
|
||||
static void commandNS(size_t id, char *params) {
|
||||
static void commandNS(uint id, char *params) {
|
||||
(void)id;
|
||||
if (!params) return;
|
||||
ircFormat("PRIVMSG NickServ :%s\r\n", params);
|
||||
}
|
||||
|
||||
static void commandCS(size_t id, char *params) {
|
||||
static void commandCS(uint id, char *params) {
|
||||
(void)id;
|
||||
if (!params) return;
|
||||
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;
|
||||
size_t query = idFor(params);
|
||||
uint query = idFor(params);
|
||||
idColors[query] = completeColor(id, params);
|
||||
uiShowID(query);
|
||||
}
|
||||
|
||||
static void commandWindow(size_t id, char *params) {
|
||||
static void commandWindow(uint id, char *params) {
|
||||
if (!params) return;
|
||||
if (isdigit(params[0])) {
|
||||
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;
|
||||
char *name = strsep(¶ms, " ");
|
||||
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) {
|
||||
uiCloseID(id);
|
||||
} 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) {
|
||||
urlOpenCount(id, 1);
|
||||
} 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);
|
||||
}
|
||||
|
||||
static void commandExec(size_t id, char *params) {
|
||||
static void commandExec(uint id, char *params) {
|
||||
execID = id;
|
||||
|
||||
pid_t pid = fork();
|
||||
|
@ -251,7 +251,7 @@ static void commandExec(size_t id, char *params) {
|
|||
_exit(EX_UNAVAILABLE);
|
||||
}
|
||||
|
||||
static void commandHelp(size_t id, char *params) {
|
||||
static void commandHelp(uint id, char *params) {
|
||||
(void)id;
|
||||
uiHide();
|
||||
|
||||
|
@ -306,7 +306,7 @@ static int compar(const void *cmd, const void *_handler) {
|
|||
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 (input[0] != '/') return input;
|
||||
const char *space = strchr(&input[1], ' ');
|
||||
|
@ -315,19 +315,19 @@ const char *commandIsPrivmsg(size_t id, const char *input) {
|
|||
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 (strncmp(input, "/notice ", 8)) return NULL;
|
||||
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 (strncmp(input, "/me ", 4)) return NULL;
|
||||
return &input[4];
|
||||
}
|
||||
|
||||
void command(size_t id, char *input) {
|
||||
void command(uint id, char *input) {
|
||||
if (id == Debug && input[0] != '/') {
|
||||
commandQuote(id, input);
|
||||
} else if (commandIsPrivmsg(id, input)) {
|
||||
|
|
22
complete.c
22
complete.c
|
@ -23,14 +23,14 @@
|
|||
#include "chat.h"
|
||||
|
||||
struct Node {
|
||||
size_t id;
|
||||
uint id;
|
||||
char *str;
|
||||
enum Color color;
|
||||
struct Node *prev;
|
||||
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));
|
||||
if (!node) err(EX_OSERR, "malloc");
|
||||
node->id = id;
|
||||
|
@ -73,31 +73,31 @@ static struct Node *append(struct Node *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) {
|
||||
if (node->id == id && !strcmp(node->str, str)) return node;
|
||||
}
|
||||
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));
|
||||
}
|
||||
|
||||
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);
|
||||
if (node && node->color != color) node->color = 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);
|
||||
return (node ? node->color : Default);
|
||||
}
|
||||
|
||||
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) {
|
||||
if (match->id && match->id != id) continue;
|
||||
if (strncasecmp(match->str, prefix, strlen(prefix))) continue;
|
||||
|
@ -115,14 +115,14 @@ void completeReject(void) {
|
|||
match = NULL;
|
||||
}
|
||||
|
||||
size_t completeID(const char *str) {
|
||||
uint completeID(const char *str) {
|
||||
for (match = (match ? match->next : head); match; match = match->next) {
|
||||
if (match->id && !strcmp(match->str, str)) return match->id;
|
||||
}
|
||||
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;
|
||||
for (struct Node *node = head; node; 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;
|
||||
for (struct Node *node = head; node; 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;
|
||||
for (struct Node *node = head; node; node = next) {
|
||||
next = node->next;
|
||||
|
|
4
edit.c
4
edit.c
|
@ -78,7 +78,7 @@ static struct {
|
|||
size_t len;
|
||||
} tab;
|
||||
|
||||
static void tabComplete(size_t id) {
|
||||
static void tabComplete(uint id) {
|
||||
if (!tab.len) {
|
||||
tab.pos = pos;
|
||||
while (tab.pos && buf[tab.pos - 1] != L' ') tab.pos--;
|
||||
|
@ -142,7 +142,7 @@ static void tabReject(void) {
|
|||
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;
|
||||
switch (op) {
|
||||
break; case EditHead: pos = 0;
|
||||
|
|
32
handle.c
32
handle.c
|
@ -63,15 +63,15 @@ static const char *capList(enum Cap caps) {
|
|||
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 (!msg->nick) errx(EX_PROTOCOL, "%s missing origin", msg->cmd);
|
||||
if (!msg->user) msg->user = msg->nick;
|
||||
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;
|
||||
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]);
|
||||
completeTouch(Network, self.nick, Default);
|
||||
if (self.join) {
|
||||
size_t count = 1;
|
||||
uint count = 1;
|
||||
for (const char *ch = self.join; *ch && *ch != ' '; ++ch) {
|
||||
if (*ch == ',') count++;
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ static void handleReplyWelcome(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;
|
||||
char *key = strsep(&msg->params[i], "=");
|
||||
if (!msg->params[i]) continue;
|
||||
|
@ -245,7 +245,7 @@ static void handleReplyMOTD(struct Message *msg) {
|
|||
|
||||
static void handleJoin(struct Message *msg) {
|
||||
require(msg, true, 1);
|
||||
size_t id = idFor(msg->params[0]);
|
||||
uint id = idFor(msg->params[0]);
|
||||
if (!strcmp(msg->nick, self.nick)) {
|
||||
if (!self.user) {
|
||||
set(&self.user, msg->user);
|
||||
|
@ -275,7 +275,7 @@ static void handleJoin(struct Message *msg) {
|
|||
|
||||
static void handlePart(struct Message *msg) {
|
||||
require(msg, true, 1);
|
||||
size_t id = idFor(msg->params[0]);
|
||||
uint id = idFor(msg->params[0]);
|
||||
if (!strcmp(msg->nick, self.nick)) {
|
||||
completeClear(id);
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ static void handlePart(struct Message *msg) {
|
|||
|
||||
static void handleKick(struct Message *msg) {
|
||||
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);
|
||||
completeTouch(id, msg->nick, hash(msg->user));
|
||||
urlScan(id, msg->nick, msg->params[2]);
|
||||
|
@ -316,7 +316,7 @@ static void handleNick(struct Message *msg) {
|
|||
set(&self.nick, msg->params[0]);
|
||||
uiRead(); // Update prompt.
|
||||
}
|
||||
size_t id;
|
||||
uint id;
|
||||
while (None != (id = completeID(msg->nick))) {
|
||||
if (!strcmp(idNames[id], msg->nick)) {
|
||||
set(&idNames[id], msg->params[0]);
|
||||
|
@ -332,7 +332,7 @@ static void handleNick(struct Message *msg) {
|
|||
|
||||
static void handleQuit(struct Message *msg) {
|
||||
require(msg, true, 0);
|
||||
size_t id;
|
||||
uint id;
|
||||
while (None != (id = completeID(msg->nick))) {
|
||||
urlScan(id, msg->nick, msg->params[0]);
|
||||
uiFormat(
|
||||
|
@ -348,7 +348,7 @@ static void handleQuit(struct Message *msg) {
|
|||
|
||||
static void handleReplyNames(struct Message *msg) {
|
||||
require(msg, false, 4);
|
||||
size_t id = idFor(msg->params[2]);
|
||||
uint id = idFor(msg->params[2]);
|
||||
char buf[1024];
|
||||
size_t len = 0;
|
||||
while (msg->params[3]) {
|
||||
|
@ -394,7 +394,7 @@ static void handleReplyTopic(struct Message *msg) {
|
|||
require(msg, false, 3);
|
||||
if (!replies.topic) return;
|
||||
replies.topic--;
|
||||
size_t id = idFor(msg->params[1]);
|
||||
uint id = idFor(msg->params[1]);
|
||||
urlScan(id, NULL, msg->params[2]);
|
||||
uiFormat(
|
||||
id, Cold, tagTime(msg),
|
||||
|
@ -405,7 +405,7 @@ static void handleReplyTopic(struct Message *msg) {
|
|||
|
||||
static void handleTopic(struct Message *msg) {
|
||||
require(msg, true, 2);
|
||||
size_t id = idFor(msg->params[0]);
|
||||
uint id = idFor(msg->params[0]);
|
||||
if (msg->params[1][0]) {
|
||||
urlScan(id, msg->nick, msg->params[1]);
|
||||
uiFormat(
|
||||
|
@ -560,7 +560,7 @@ static void handleReplyEndOfWhois(struct Message *msg) {
|
|||
static void handleReplyAway(struct Message *msg) {
|
||||
require(msg, false, 3);
|
||||
// Might be part of a WHOIS response.
|
||||
size_t id;
|
||||
uint id;
|
||||
if (completeColor(Network, msg->params[1]) != Default) {
|
||||
id = Network;
|
||||
} else {
|
||||
|
@ -602,7 +602,7 @@ static bool isMention(const struct Message *msg) {
|
|||
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], ':');
|
||||
if (!split) {
|
||||
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 server = strchr(msg->nick, '.');
|
||||
bool mine = !strcmp(msg->nick, self.nick);
|
||||
size_t id;
|
||||
uint id;
|
||||
if (query && server) {
|
||||
id = Network;
|
||||
} else if (query && !mine) {
|
||||
|
|
4
irc.c
4
irc.c
|
@ -220,7 +220,7 @@ static struct Message parse(char *line) {
|
|||
while (tags) {
|
||||
char *tag = strsep(&tags, ";");
|
||||
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;
|
||||
unescape(tag);
|
||||
msg.tags[i] = tag;
|
||||
|
@ -237,7 +237,7 @@ static struct Message parse(char *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] == ':') {
|
||||
msg.params[i] = &line[1];
|
||||
break;
|
||||
|
|
66
ui.c
66
ui.c
|
@ -78,31 +78,31 @@ static const char *bufferLine(const struct Buffer *buffer, size_t i) {
|
|||
|
||||
enum { WindowLines = BufferCap };
|
||||
struct Window {
|
||||
size_t id;
|
||||
uint id;
|
||||
struct Buffer buffer;
|
||||
WINDOW *pad;
|
||||
int scroll;
|
||||
bool mark;
|
||||
enum Heat heat;
|
||||
int unreadTotal;
|
||||
int unreadWarm;
|
||||
int unreadLines;
|
||||
uint unreadTotal;
|
||||
uint unreadWarm;
|
||||
uint unreadLines;
|
||||
};
|
||||
|
||||
static struct {
|
||||
size_t show;
|
||||
size_t swap;
|
||||
uint show;
|
||||
uint swap;
|
||||
struct Window *ptrs[IDCap];
|
||||
size_t len;
|
||||
uint len;
|
||||
} windows;
|
||||
|
||||
static size_t windowPush(struct Window *window) {
|
||||
static uint windowPush(struct Window *window) {
|
||||
assert(windows.len < IDCap);
|
||||
windows.ptrs[windows.len] = window;
|
||||
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(num <= windows.len);
|
||||
memmove(
|
||||
|
@ -115,7 +115,7 @@ static size_t windowInsert(size_t num, struct Window *window) {
|
|||
return num;
|
||||
}
|
||||
|
||||
static struct Window *windowRemove(size_t num) {
|
||||
static struct Window *windowRemove(uint num) {
|
||||
assert(num < windows.len);
|
||||
struct Window *window = windows.ptrs[num];
|
||||
windows.len--;
|
||||
|
@ -127,8 +127,8 @@ static struct Window *windowRemove(size_t num) {
|
|||
return window;
|
||||
}
|
||||
|
||||
static size_t windowFor(size_t id) {
|
||||
for (size_t num = 0; num < windows.len; ++num) {
|
||||
static uint windowFor(uint id) {
|
||||
for (uint num = 0; num < windows.len; ++num) {
|
||||
if (windows.ptrs[num]->id == id) return num;
|
||||
}
|
||||
|
||||
|
@ -403,7 +403,7 @@ static void statusUpdate(void) {
|
|||
enum Heat otherHeat = Cold;
|
||||
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];
|
||||
if (!window->heat && num != windows.show) continue;
|
||||
if (num != windows.show) {
|
||||
|
@ -413,7 +413,7 @@ static void statusUpdate(void) {
|
|||
int trunc;
|
||||
char buf[256];
|
||||
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" : ""),
|
||||
num, idNames[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;
|
||||
static void notify(size_t id, const char *str) {
|
||||
static void notify(uint id, const char *str) {
|
||||
if (!uiNotifyUtil.argc) return;
|
||||
|
||||
struct Util util = uiNotifyUtil;
|
||||
|
@ -583,7 +583,7 @@ static void notify(size_t id, const char *str) {
|
|||
_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)];
|
||||
time_t clock = (src ? *src : time(NULL));
|
||||
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(
|
||||
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];
|
||||
va_list ap;
|
||||
|
@ -641,7 +641,7 @@ static void resize(void) {
|
|||
int height, width;
|
||||
getmaxyx(windows.ptrs[0]->pad, height, width);
|
||||
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);
|
||||
reflow(windows.ptrs[num]);
|
||||
}
|
||||
|
@ -715,7 +715,7 @@ static void inputAdd(struct Style *style, const char *str) {
|
|||
}
|
||||
|
||||
static void inputUpdate(void) {
|
||||
size_t id = windows.ptrs[windows.show]->id;
|
||||
uint id = windows.ptrs[windows.show]->id;
|
||||
size_t pos;
|
||||
char *buf = editBuffer(&pos);
|
||||
|
||||
|
@ -768,7 +768,7 @@ static void inputUpdate(void) {
|
|||
wmove(input, y, x);
|
||||
}
|
||||
|
||||
static void windowShow(size_t num) {
|
||||
static void windowShow(uint num) {
|
||||
touchwin(windows.ptrs[num]->pad);
|
||||
windows.swap = windows.show;
|
||||
windows.show = num;
|
||||
|
@ -777,15 +777,15 @@ static void windowShow(size_t num) {
|
|||
inputUpdate();
|
||||
}
|
||||
|
||||
void uiShowID(size_t id) {
|
||||
void uiShowID(uint id) {
|
||||
windowShow(windowFor(id));
|
||||
}
|
||||
|
||||
void uiShowNum(size_t num) {
|
||||
void uiShowNum(uint 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));
|
||||
if (num < windows.len) {
|
||||
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;
|
||||
struct Window *window = windowRemove(num);
|
||||
completeClear(window->id);
|
||||
|
@ -809,26 +809,26 @@ static void windowClose(size_t num) {
|
|||
statusUpdate();
|
||||
}
|
||||
|
||||
void uiCloseID(size_t id) {
|
||||
void uiCloseID(uint id) {
|
||||
windowClose(windowFor(id));
|
||||
}
|
||||
|
||||
void uiCloseNum(size_t num) {
|
||||
void uiCloseNum(uint num) {
|
||||
if (num < windows.len) windowClose(num);
|
||||
}
|
||||
|
||||
static void showAuto(void) {
|
||||
static size_t swap;
|
||||
static uint swap;
|
||||
if (windows.swap != swap) {
|
||||
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;
|
||||
windowShow(num);
|
||||
windows.swap = swap;
|
||||
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;
|
||||
windowShow(num);
|
||||
windows.swap = swap;
|
||||
|
@ -839,7 +839,7 @@ static void showAuto(void) {
|
|||
|
||||
static void keyCode(int code) {
|
||||
struct Window *window = windows.ptrs[windows.show];
|
||||
size_t id = window->id;
|
||||
uint id = window->id;
|
||||
switch (code) {
|
||||
break; case KEY_RESIZE: resize();
|
||||
break; case KeyFocusIn: unmark(window);
|
||||
|
@ -880,7 +880,7 @@ static void keyCode(int code) {
|
|||
|
||||
static void keyCtrl(wchar_t ch) {
|
||||
struct Window *window = windows.ptrs[windows.show];
|
||||
size_t id = window->id;
|
||||
uint id = window->id;
|
||||
switch (ch ^ L'@') {
|
||||
break; case L'?': edit(id, EditDeletePrev, 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) {
|
||||
size_t id = windows.ptrs[windows.show]->id;
|
||||
uint id = windows.ptrs[windows.show]->id;
|
||||
switch (iswcntrl(ch) ? ch ^ L'@' : (wchar_t)towupper(ch)) {
|
||||
break; case L'B': edit(id, EditInsert, B);
|
||||
break; case L'C': edit(id, EditInsert, C);
|
||||
|
@ -973,7 +973,7 @@ int uiSave(const char *name) {
|
|||
if (!file) 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];
|
||||
if (writeString(file, idNames[window->id])) return -1;
|
||||
if (writeTime(file, window->heat)) return -1;
|
||||
|
|
18
url.c
18
url.c
|
@ -59,7 +59,7 @@ static void compile(void) {
|
|||
}
|
||||
|
||||
struct URL {
|
||||
size_t id;
|
||||
uint id;
|
||||
char *nick;
|
||||
char *url;
|
||||
};
|
||||
|
@ -71,7 +71,7 @@ static struct {
|
|||
} ring;
|
||||
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];
|
||||
free(url->nick);
|
||||
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");
|
||||
}
|
||||
|
||||
void urlScan(size_t id, const char *nick, const char *mesg) {
|
||||
void urlScan(uint id, const char *nick, const char *mesg) {
|
||||
if (!mesg) return;
|
||||
compile();
|
||||
regmatch_t match = {0};
|
||||
|
@ -175,8 +175,8 @@ static void urlCopy(const char *url) {
|
|||
_exit(EX_CONFIG);
|
||||
}
|
||||
|
||||
void urlOpenCount(size_t id, size_t count) {
|
||||
for (size_t i = 1; i <= Cap; ++i) {
|
||||
void urlOpenCount(uint id, uint count) {
|
||||
for (uint i = 1; i <= Cap; ++i) {
|
||||
const struct URL *url = &ring.urls[(ring.len - i) % Cap];
|
||||
if (!url->url) break;
|
||||
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) {
|
||||
for (size_t i = 1; i <= Cap; ++i) {
|
||||
void urlOpenMatch(uint id, const char *str) {
|
||||
for (uint i = 1; i <= Cap; ++i) {
|
||||
const struct URL *url = &ring.urls[(ring.len - i) % Cap];
|
||||
if (!url->url) break;
|
||||
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) {
|
||||
for (size_t i = 1; i <= Cap; ++i) {
|
||||
void urlCopyMatch(uint id, const char *str) {
|
||||
for (uint i = 1; i <= Cap; ++i) {
|
||||
const struct URL *url = &ring.urls[(ring.len - i) % Cap];
|
||||
if (!url->url) break;
|
||||
if (url->id != id) continue;
|
||||
|
|
Loading…
Reference in New Issue