commit 7c345be323b418d66ff6bf1885b920cff85db060
parent fc3864dce7535304804f68335e11d4bd6438bbce
Author: hhvn <dev@hhvn.uk>
Date: Fri, 3 Dec 2021 11:35:35 +0000
hist.c ui.c commands.c struct.h: HIST_SELTMP->HIST_TMP, support HIST_TMP|HIST_MAIN
Diffstat:
4 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/commands.c b/commands.c
@@ -297,7 +297,8 @@ command_connect(struct Server *server, char *str) {
tserver = serv_add(&servers, network, host, port, nick, username, realname, tls, tls_verify);
serv_connect(tserver);
- ui_select(tserver, NULL);
+ if (!readingconf)
+ ui_select(tserver, NULL);
}
static void
@@ -513,16 +514,16 @@ command_help(struct Server *server, char *str) {
}
if (strcmp(str, "commands") == 0) {
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :Commands:");
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :Commands:");
for (i=0; commands[i].name && commands[i].func; i++)
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI : %s", commands[i].name);
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI : %s", commands[i].name);
return;
}
if (strcmp(str, "variables") == 0) {
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :Variables:");
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :Variables:");
for (i=0; config[i].name; i++)
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI : %s", config[i].name);
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI : %s", config[i].name);
return;
}
@@ -533,11 +534,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(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", str);
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :===");
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :%s", str);
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :===");
for (j=0; commands[i].description[j]; j++)
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", commands[i].description[j]);
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :");
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :%s", commands[i].description[j]);
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :");
return;
}
}
@@ -545,11 +546,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(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", str);
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :===");
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :%s", str);
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :===");
for (j=0; config[i].description[j]; j++)
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :%s", config[i].description[j]);
- hist_format(selected.history, Activity_none, HIST_SHOW|HIST_SELTMP, "SELF_UI :");
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :%s", config[i].description[j]);
+ hist_format(selected.history, Activity_none, HIST_SHOW|HIST_TMP|HIST_MAIN, "SELF_UI :");
return;
}
}
diff --git a/hist.c b/hist.c
@@ -64,17 +64,18 @@ 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 && !recursive) {
- recursive = 1;
+ if (options & HIST_TMP && histinfo == main_buf) {
hist_add(main_buf, from, msg, params, activity, timestamp, HIST_SHOW);
- recursive = 0;
- } else
+ return NULL;
+ } else if (histinfo != main_buf) {
+ hist_add(main_buf, from, msg, params, activity, timestamp, HIST_SHOW);
+ } else {
ui_error("HIST_MAIN specified, but history is &main_buf", NULL);
+ }
}
if (options & HIST_SELF && histinfo->server)
@@ -127,7 +128,7 @@ hist_purgetmp(struct HistInfo *histinfo) {
for (; p; p = next) {
next = p->next;
- if (p->options & HIST_SELTMP) {
+ if (p->options & HIST_TMP) {
if (p->prev)
p->prev->next = p->next;
else
diff --git a/struct.h b/struct.h
@@ -32,11 +32,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_SELTMP = 16, /* copy to selected buffer temporarily */
+ 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_TMP = 16, /* purge later */
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(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP,
+ hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN,
"SELF_ERROR %s %d :%s",
file, line, msg);
}
void
ui_perror_(char *file, int line, char *str) {
- hist_format(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP,
+ hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN,
"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(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP,
+ hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN,
"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(selected.history, Activity_error, HIST_SHOW|HIST_SELTMP,
+ hist_format(selected.history, Activity_error, HIST_SHOW|HIST_TMP|HIST_MAIN,
"SELF_ERROR %s %d :%s: %s",
file, line, str, tls_error(ctx));
}