hirc

IRC client
Log | Files | Refs

commit abff8da3b346a03d1a2f9f4e0ec74d76f6ef4dca
parent 79472fdfa5cd7819abea6e6ffad06e6112db2254
Author: hhvn <dev@hhvn.uk>
Date:   Thu,  2 Dec 2021 22:25:49 +0000

hist.c ui.c commands.c struct.h hirc.h: temporary draw to buffer

Diffstat:
Mcommands.c | 24++++++++++++------------
Mhirc.h | 1+
Mhist.c | 34++++++++++++++++++++++++++++++++--
Mstruct.h | 9+++++----
Mui.c | 10++++++----
5 files changed, 56 insertions(+), 22 deletions(-)

diff --git a/commands.c b/commands.c @@ -504,16 +504,16 @@ command_help(struct Server *server, char *str) { } if (strcmp(str, "commands") == 0) { - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :Commands:"); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :Commands:"); for (i=0; commands[i].name && commands[i].func; i++) - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI : %s", commands[i].name); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI : %s", commands[i].name); return; } if (strcmp(str, "variables") == 0) { - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :Variables:"); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :Variables:"); for (i=0; config[i].name; i++) - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI : %s", config[i].name); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI : %s", config[i].name); return; } @@ -524,11 +524,11 @@ command_help(struct Server *server, char *str) { for (i=0; commands[i].name && commands[i].func; i++) { if (strcmp(commands[i].name, str) == 0) { - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", str); - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :==="); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", str); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :==="); for (j=0; commands[i].description[j]; j++) - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", commands[i].description[j]); - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :"); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", commands[i].description[j]); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :"); return; } } @@ -536,11 +536,11 @@ command_help(struct Server *server, char *str) { if (!cmdonly) { for (i=0; config[i].name; i++) { if (strcmp(config[i].name, str) == 0) { - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", str); - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :==="); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", str); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :==="); for (j=0; config[i].description[j]; j++) - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :%s", config[i].description[j]); - hist_format(main_buf, Activity_status, HIST_SHOW, "SELF_UI :"); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", config[i].description[j]); + hist_format(selected.history, Activity_status, HIST_SHOW|HIST_SELTMP, "SELF_UI :"); return; } } diff --git a/hirc.h b/hirc.h @@ -69,6 +69,7 @@ struct History *hist_format(struct HistInfo *history, enum Activity activity, enum HistOpt options, char *format, ...); int hist_len(struct History **history); int hist_log(char *msg, struct Nick *from, time_t timestamp, struct Server *server); +void hist_purgetmp(struct HistInfo *histinfo); /* serv.c */ void serv_free(struct Server *server); diff --git a/hist.c b/hist.c @@ -64,13 +64,16 @@ struct History * hist_add(struct HistInfo *histinfo, struct Nick *from, char *msg, char **params, enum Activity activity, time_t timestamp, enum HistOpt options) { + static int recursive = 0; struct History *new, *p; int i; if (options & HIST_MAIN) { - if (histinfo != main_buf) + if (histinfo != main_buf && !recursive) { + recursive = 1; hist_add(main_buf, from, msg, params, activity, timestamp, HIST_SHOW); - else + recursive = 0; + } else ui_error("HIST_MAIN specified, but history is &main_buf", NULL); } @@ -113,6 +116,33 @@ hist_add(struct HistInfo *histinfo, struct Nick *from, return new; } +void +hist_purgetmp(struct HistInfo *histinfo) { + struct History *p, *next; + + if (!histinfo) + return; + + p = histinfo->history; + + for (; p; p = next) { + next = p->next; + if (p->options & HIST_SELTMP) { + if (p->prev) + p->prev->next = p->next; + else + histinfo->history = p->next; + + if (p->next) + p->next->prev = p->prev; + else + histinfo->history = NULL; + + free(p); + } + } +} + struct History * hist_format(struct HistInfo *histinfo, enum Activity activity, enum HistOpt options, char *format, ...) { char msg[1024], **params; diff --git a/struct.h b/struct.h @@ -31,10 +31,11 @@ enum Activity { }; enum HistOpt { - HIST_SHOW = 1, /* show in buffer */ - HIST_LOG = 2, /* log to server->logfd */ - HIST_MAIN = 4, /* copy to &main_buf */ - HIST_SELF = 8, /* from = self */ + HIST_SHOW = 1, /* show in buffer */ + HIST_LOG = 2, /* log to server->logfd */ + HIST_MAIN = 4, /* copy to &main_buf */ + HIST_SELF = 8, /* from = self */ + HIST_SELTMP = 16, /* copy to selected buffer temporarily */ HIST_DFL = HIST_SHOW|HIST_LOG }; diff --git a/ui.c b/ui.c @@ -174,14 +174,14 @@ ui_error_(char *file, int line, char *format, ...) { vsnprintf(msg, sizeof(msg), format, ap); va_end(ap); - hist_format(main_buf, Activity_error, HIST_SHOW, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP, "SELF_ERROR %s %d :%s", file, line, msg); } void ui_perror_(char *file, int line, char *str) { - hist_format(main_buf, Activity_error, HIST_SHOW, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP, "SELF_ERROR %s %d :%s: %s", file, line, str, strerror(errno)); } @@ -189,14 +189,14 @@ ui_perror_(char *file, int line, char *str) { #ifdef TLS void ui_tls_config_error_(char *file, int line, struct tls_config *config, char *str) { - hist_format(main_buf, Activity_error, HIST_SHOW, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP, "SELF_ERROR %s %d :%s: %s", file, line, str, tls_config_error(config)); } void ui_tls_error_(char *file, int line, struct tls *ctx, char *str) { - hist_format(main_buf, Activity_error, HIST_SHOW, + hist_format(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP, "SELF_ERROR %s %d :%s: %s", file, line, str, tls_error(ctx)); } @@ -912,6 +912,8 @@ ui_select(struct Server *server, struct Channel *channel) { selected.server = server; selected.history = channel ? channel->history : server ? server->history : main_buf; selected.name = channel ? channel->name : server ? server->name : "hirc"; + + hist_purgetmp(selected.history); } static char *