Remove static buffer from colorMentions

weechat-hashes
C. McEnroe 2020-11-08 15:16:25 -05:00
parent a8264f31e0
commit ded0455d3e
1 changed files with 12 additions and 14 deletions

View File

@ -1160,7 +1160,7 @@ static bool isMention(const struct Message *msg) {
return false; return false;
} }
static const char *colorMentions(uint id, struct Message *msg) { static void colorMentions(struct Cat *cat, uint id, struct Message *msg) {
char *split = strstr(msg->params[1], ": "); char *split = strstr(msg->params[1], ": ");
if (!split) { if (!split) {
split = strchr(msg->params[1], ' '); split = strchr(msg->params[1], ' ');
@ -1168,19 +1168,16 @@ static const char *colorMentions(uint id, struct Message *msg) {
} }
if (!split) split = &msg->params[1][strlen(msg->params[1])]; if (!split) split = &msg->params[1][strlen(msg->params[1])];
for (char *ch = msg->params[1]; ch < split; ++ch) { for (char *ch = msg->params[1]; ch < split; ++ch) {
if (iscntrl(*ch)) return ""; if (iscntrl(*ch)) return;
} }
char delimit = *split; char delimit = *split;
char *mention = msg->params[1]; char *mention = msg->params[1];
msg->params[1] = (delimit ? &split[1] : split); msg->params[1] = (delimit ? &split[1] : split);
*split = '\0'; *split = '\0';
static char buf[1024];
buf[0] = '\0';
struct Cat cat = { buf, sizeof(buf), 0 };
while (*mention) { while (*mention) {
size_t skip = strspn(mention, ",<> "); size_t skip = strspn(mention, ",<> ");
catf(&cat, "%.*s", (int)skip, mention); catf(cat, "%.*s", (int)skip, mention);
mention += skip; mention += skip;
size_t len = strcspn(mention, ",<> "); size_t len = strcspn(mention, ",<> ");
@ -1188,15 +1185,14 @@ static const char *colorMentions(uint id, struct Message *msg) {
mention[len] = '\0'; mention[len] = '\0';
enum Color color = completeColor(id, mention); enum Color color = completeColor(id, mention);
if (color != Default) { if (color != Default) {
catf(&cat, "\3%02d%s\3", color, mention); catf(cat, "\3%02d%s\3", color, mention);
} else { } else {
catf(&cat, "%s", mention); catf(cat, "%s", mention);
} }
mention[len] = punct; mention[len] = punct;
mention += len; mention += len;
} }
catf(&cat, "%c", delimit); catf(cat, "%c", delimit);
return buf;
} }
static void handlePrivmsg(struct Message *msg) { static void handlePrivmsg(struct Message *msg) {
@ -1223,6 +1219,8 @@ static void handlePrivmsg(struct Message *msg) {
} }
if (heat > Ice) urlScan(id, msg->nick, msg->params[1]); if (heat > Ice) urlScan(id, msg->nick, msg->params[1]);
char buf[1024] = "";
struct Cat cat = { buf, sizeof(buf), 0 };
if (notice) { if (notice) {
if (id != Network) { if (id != Network) {
logFormat(id, tagTime(msg), "-%s- %s", msg->nick, msg->params[1]); logFormat(id, tagTime(msg), "-%s- %s", msg->nick, msg->params[1]);
@ -1234,21 +1232,21 @@ static void handlePrivmsg(struct Message *msg) {
); );
} else if (action) { } else if (action) {
logFormat(id, tagTime(msg), "* %s %s", msg->nick, msg->params[1]); logFormat(id, tagTime(msg), "* %s %s", msg->nick, msg->params[1]);
const char *mentions = colorMentions(id, msg); colorMentions(&cat, id, msg);
uiFormat( uiFormat(
id, heat, tagTime(msg), id, heat, tagTime(msg),
"%s\35\3%d* %s\17\35\t%s%s", "%s\35\3%d* %s\17\35\t%s%s",
(mention ? "\26" : ""), hash(msg->user), msg->nick, (mention ? "\26" : ""), hash(msg->user), msg->nick,
mentions, msg->params[1] buf, msg->params[1]
); );
} else { } else {
logFormat(id, tagTime(msg), "<%s> %s", msg->nick, msg->params[1]); logFormat(id, tagTime(msg), "<%s> %s", msg->nick, msg->params[1]);
const char *mentions = colorMentions(id, msg); colorMentions(&cat, id, msg);
uiFormat( uiFormat(
id, heat, tagTime(msg), id, heat, tagTime(msg),
"%s\3%d<%s>\17\t%s%s", "%s\3%d<%s>\17\t%s%s",
(mention ? "\26" : ""), hash(msg->user), msg->nick, (mention ? "\26" : ""), hash(msg->user), msg->nick,
mentions, msg->params[1] buf, msg->params[1]
); );
} }
} }