From 82f142c0acc87e55373102687aa718effcbf7cb9 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Sat, 20 Jan 2024 02:41:39 +0100 Subject: Remember lines that were printed during connect so they can be output in case of an error --- vchat-client.c | 7 ++++++- vchat-protocol.c | 1 + vchat-ui.c | 31 ++++++++++++++++++++++++++++--- vchat.h | 3 +++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/vchat-client.c b/vchat-client.c index a22df94..92d1905 100644 --- a/vchat-client.c +++ b/vchat-client.c @@ -343,8 +343,13 @@ void cleanup(int signal) { /* inform user if we where killed by signal */ if (signal > 1) { fprintf(stderr, "vchat-client: terminated with signal %d.\n", signal); - } else if (errstr[0]) + if (!loggedin) + dumpconnect(); + } else if (errstr[0]) { fputs(errstr, stderr); + if (!loggedin) + dumpconnect(); + } /* end of story */ exit(0); } diff --git a/vchat-protocol.c b/vchat-protocol.c index ac65639..c5021e4 100644 --- a/vchat-protocol.c +++ b/vchat-protocol.c @@ -235,6 +235,7 @@ static void justloggedin(char *message) { loadcfg(getstroption(CF_LOGINSCRIPT), 0, handleline); handleline(".S"); loggedin = 1; + flushconnect(); } } diff --git a/vchat-ui.c b/vchat-ui.c index bb33287..185cad0 100644 --- a/vchat-ui.c +++ b/vchat-ui.c @@ -91,6 +91,7 @@ struct sb_data { static struct sb_data *sb_pub = NULL; static struct sb_data *sb_priv = NULL; static struct sb_data *sb_out = NULL; +static struct sb_data *sb_connect = NULL; /* Tells, which window is active */ static int sb_win = 0; /* 0 for pub, 1 for priv */ @@ -310,14 +311,18 @@ static void sb_flush(struct sb_data *sb) { now = tmp; } sb->entries = NULL; + sb->last = NULL; + sb->count = 0; + sb->scroll = 0; } -/*static void -sb_clear ( struct sb_data **sb ) { +/* +static void sb_clear ( struct sb_data **sb ) { sb_flush(*sb); free( *sb ); *sb = NULL; -}*/ +} +*/ static struct sb_entry *sb_add(struct sb_data *sb, const char *line, time_t when) { @@ -407,9 +412,27 @@ int writecf(formtstr id, char *str) { else consoleline(NULL); + if (!loggedin) + sb_add(sb_connect, str, now); + return i; } +void dumpconnect() { + struct sb_entry *now = sb_connect->entries, *prev = NULL, *tmp; + while (now) { + tmp = (struct sb_entry *)((unsigned long)prev ^ (unsigned long)now->link); + fputs(now->what, stderr); + fputc(10, stderr); + prev = now; + now = tmp; + } +} + +void flushconnect() { + sb_flush(sb_connect); +} + int writepriv(char *str, int maybeep) { int i = 0; if (private) { @@ -1222,6 +1245,7 @@ void initui(void) { /* Prepare our scrollback buffers */ sb_pub = (struct sb_data *)malloc(sizeof(struct sb_data)); sb_out = (struct sb_data *)malloc(sizeof(struct sb_data)); + sb_connect = (struct sb_data *)malloc(sizeof(struct sb_data)); if (privheight) sb_priv = (struct sb_data *)malloc(sizeof(struct sb_data)); else @@ -1230,6 +1254,7 @@ void initui(void) { memset(sb_pub, 0, sizeof(struct sb_data)); memset(sb_priv, 0, sizeof(struct sb_data)); memset(sb_out, 0, sizeof(struct sb_data)); + memset(sb_connect, 0, sizeof(struct sb_data)); /* set colors for windows */ if (has_colors()) { diff --git a/vchat.h b/vchat.h index 412566a..3fdbb37 100644 --- a/vchat.h +++ b/vchat.h @@ -195,6 +195,9 @@ void flushout(void); } void hideout(void); int writecf(formtstr id, char *str); +/* dumps aggregated connect output in case of a connection error */ +void dumpconnect(); +void flushconnect(); extern int outputcountdown; -- cgit v1.2.3