hirc

IRC client
Log | Files | Refs

commit 08bcbb6c1bde6f7206c4b9354fe64f226ce1067c
parent a1dcae4aa7ba99f25a7ff7cc6902e8912c09881b
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 11 Apr 2022 16:04:23 +0100

/dump ignore rules

Diffstat:
Msrc/commands.c | 29+++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/commands.c b/src/commands.c @@ -357,6 +357,7 @@ struct Command commands[] = { " -servers dump /server commands", " -channels dump /join commands for respective servers", " -queries dump /query commands for respective servers", + " -ignores dump /ignore commands", " -default dump default settings (dump non-default otherwise)", "If none (excluding -default) of the above are selected, it is", "treated as though all are selected.", @@ -1653,7 +1654,7 @@ command_source) { return; } p = strrchr(str, ' '); - if (*(p+1) == '\0') + if (p && *(p+1) == '\0') *p = '\0'; /* remove trailing spaces */ config_read(str); } @@ -1669,6 +1670,7 @@ command_dump) { struct Channel *chp; struct Alias *ap; struct Keybind *kp; + struct Ignore *ip; enum { opt_aliases = 1, opt_bindings = 2, @@ -1678,7 +1680,8 @@ command_dump) { opt_channels = 32, opt_queries = 64, opt_autocmds = 128, - opt_default = 256, + opt_ignores = 256, + opt_default = 512, }; static struct CommandOpts opts[] = { {"aliases", CMD_NARG, opt_aliases}, @@ -1689,6 +1692,7 @@ command_dump) { {"autocmds", CMD_NARG, opt_autocmds}, {"channels", CMD_NARG, opt_channels}, {"queries", CMD_NARG, opt_queries}, + {"ignores", CMD_NARG, opt_ignores}, {"default", CMD_NARG, opt_default}, {NULL, 0, 0}, }; @@ -1704,6 +1708,7 @@ command_dump) { case opt_servers: case opt_channels: case opt_autocmds: + case opt_ignores: selected |= ret; break; case opt_default: @@ -1720,7 +1725,7 @@ command_dump) { return; } p = strrchr(str, ' '); - if (*(p+1) == '\0') + if (p && *(p+1) == '\0') *p = '\0'; if ((file = fopen(str, "wb")) == NULL) { @@ -1765,7 +1770,7 @@ command_dump) { } if (selected & opt_aliases) { - fprintf(file, "ALiases\n"); + fprintf(file, "Aliases\n"); for (ap = aliases; ap; ap = ap->next) fprintf(file, "/alias %s %s\n", ap->alias, ap->cmd); fprintf(file, "\n"); @@ -1797,6 +1802,22 @@ command_dump) { fprintf(file, "\n"); } + if (selected & opt_ignores) { + fprintf(file, "Ignore rules\n"); + for (ip = ignores; ip; ip = ip->next) { + if (ip->server) + fprintf(file, "/server %s /ignore -server ", ip->server); + else + fprintf(file, "/ignore "); + + if (ip->format) + fprintf(file, "-format %s ", ip->format); + + fprintf(file, "%s\n", ip->text); + } + fprintf(file, "\n"); + } + fclose(file); }