hirc

IRC client
Log | Files | Refs

commit a1dcae4aa7ba99f25a7ff7cc6902e8912c09881b
parent 78df2834982ffbb261c999a4444ab034f87dc382
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 11 Apr 2022 15:51:28 +0100

format-specific /ignore rules

Diffstat:
Msrc/commands.c | 32+++++++++++++++++++++++++-------
Msrc/config.c | 4++--
Msrc/format.c | 4++--
Msrc/hirc.h | 2+-
Msrc/hist.c | 21+++++++++++----------
Msrc/struct.h | 1+
6 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -366,7 +366,7 @@ struct Command commands[] = { "usage: /close [id]", "Forget about selected buffer, or a buffer by id.", NULL}}, {"ignore", command_ignore, 0, { - "usage: /ignore [[-server] regex]", + "usage: /ignore [[-server] [-format format] regex]", " /ignore -delete id", " /ignore -hide|-show", "Hide future messages matching regex.", @@ -1844,10 +1844,11 @@ command_close) { COMMAND( command_ignore) { struct Ignore *ign, *p; - char errbuf[BUFSIZ], *s; + char errbuf[BUFSIZ], *s, *format = NULL; + size_t len; long id; int ret, raw = 0, i, regopt = 0, serv = 0; - enum { opt_show, opt_hide, opt_extended, opt_icase, opt_server, opt_delete }; + enum { opt_show, opt_hide, opt_extended, opt_icase, opt_server, opt_delete, opt_format }; static struct CommandOpts opts[] = { {"E", CMD_NARG, opt_extended}, {"i", CMD_NARG, opt_icase}, @@ -1855,6 +1856,7 @@ command_ignore) { {"hide", CMD_NARG, opt_hide}, {"server", CMD_NARG, opt_server}, {"delete", CMD_NARG, opt_delete}, + {"format", CMD_ARG, opt_format}, {NULL, 0, 0}, }; @@ -1862,8 +1864,8 @@ command_ignore) { hist_format(selected.history, Activity_none, HIST_UI, "SELF_IGNORES_START :Ignoring:"); for (p = ignores, i = 1; p; p = p->next, i++) if (!serv || !p->server || strcmp(server->name, p->server) == 0) - hist_format(selected.history, Activity_none, HIST_UI|HIST_NIGN, "SELF_IGNORES_LIST %d %s :%s", - i, p->server ? p->server : "ANY", p->text); + hist_format(selected.history, Activity_none, HIST_UI|HIST_NIGN, "SELF_IGNORES_LIST %d %s %s :%s", + i, p->server ? p->server : "ANY", p->format ? p->format : "ANY", p->text); hist_format(selected.history, Activity_none, HIST_UI, "SELF_IGNORES_END :End of ignore list"); return; } @@ -1908,6 +1910,21 @@ command_ignore) { idlarge: ui_error("id too large: %s", str); return; + case opt_format: + if (strncmp(command_optarg, "format.", 7) == 0) { + format = strdup(command_optarg); + } else { + len = strlen(command_optarg) + 8; + format = emalloc(len); + snprintf(format, len, "format.%s", command_optarg); + } + + if (!config_gets(format)) { + ui_error("no such format: %s", format + 7); + free(format); + return; + } + break; case opt_extended: regopt |= REG_EXTENDED; break; @@ -1938,11 +1955,12 @@ idlarge: free(ign); return; } - ign->text = strdup(str); + ign->text = strdup(str); + ign->format = format; ign->regopt = regopt; ign->server = serv ? strdup(server->name) : NULL; - hist_format(selected.history, Activity_none, HIST_UI, "SELF_IGNORES_ADDED %s :%s", serv ? server->name : "ANY", str); + hist_format(selected.history, Activity_none, HIST_UI, "SELF_IGNORES_ADDED %s %s :%s", serv ? server->name : "ANY", format ? format : "ANY", str); if (!ignores) { ignores = ign; diff --git a/src/config.c b/src/config.c @@ -347,7 +347,7 @@ struct Config config[] = { .description = { "Format of ignore list header.", NULL}}, {"format.ui.ignores", 1, Val_string, - .str = " %{pad:-3,${1}} ${2}: ${3}", + .str = " %{pad:-3,${1}} (server: ${2}, format: ${3}) ${4}", .strhandle = config_redraws, .description = { "Format of ignore list messages.", NULL}}, @@ -357,7 +357,7 @@ struct Config config[] = { .description = { "Format of ignore list footer.", NULL}}, {"format.ui.ignores.added", 1, Val_string, - .str = "Ignore added: ${2} (server: ${1})", + .str = "Ignore added: ${3} (server: ${1}, format: ${2})", .strhandle = config_redraws, .description = { "Format of new ignores.", NULL}}, diff --git a/src/format.c b/src/format.c @@ -228,7 +228,7 @@ format_get_bufact(int activity) { } char * -format_get(struct Window *window, struct History *hist) { +format_get(struct History *hist) { char *cmd, *p1, *p2; int i; @@ -348,7 +348,7 @@ format_(struct Window *window, char *format, struct History *hist, int recursive }; if (!format) - format = config_gets(format_get(window, hist)); + format = config_gets(format_get(hist)); if (!format) return NULL; diff --git a/src/hirc.h b/src/hirc.h @@ -174,7 +174,7 @@ void ui_tls_error_(char *file, int line, const char *func, struct tls *ctx, cha /* format.c */ char * format_get_bufact(int activity); -char * format_get(struct Window *window, struct History *hist); +char * format_get(struct History *hist); char * format_(struct Window *window, char *format, struct History *hist, int recursive); #define format(window, format, hist) format_(window, format, hist, 0) diff --git a/src/hist.c b/src/hist.c @@ -139,26 +139,27 @@ hist_add(struct HistInfo *histinfo, } } + if (options & HIST_SELF && histinfo->server) { + if (histinfo->channel && histinfo->channel->nicks) + from = nick_get(&histinfo->channel->nicks, histinfo->server->self->nick); + if (!from) + from = histinfo->server->self; + } + + new = hist_create(histinfo, from, msg, activity, timestamp, options); + if (!(options & HIST_NIGN)) { for (ign = ignores; ign; ign = ign->next) { if (!ign->server || (histinfo->server && strcmp_n(ign->server, histinfo->server->name))) { - if (regexec(&ign->regex, msg, 0, NULL, 0) == 0) { + if ((!ign->format || strcmp_n(format_get(new), ign->format) == 0) && regexec(&ign->regex, msg, 0, NULL, 0) == 0) { options |= HIST_IGN; + new->options = options; break; } } } } - if (options & HIST_SELF && histinfo->server) { - if (histinfo->channel && histinfo->channel->nicks) - from = nick_get(&histinfo->channel->nicks, histinfo->server->self->nick); - if (!from) - from = histinfo->server->self; - } - - new = hist_create(histinfo, from, msg, activity, timestamp, options); - if (!histinfo->history) { histinfo->history = new; goto ui; diff --git a/src/struct.h b/src/struct.h @@ -294,6 +294,7 @@ struct Alias { #include <regex.h> struct Ignore { struct Ignore *prev; + char *format; char *text; regex_t regex; int regopt;