From bd2debcf7d36bf64d1dd33fa6cd6a41cfa7afc25 Mon Sep 17 00:00:00 2001 From: "jazz (gitea)" Date: Mon, 9 Mar 2026 12:45:24 -0500 Subject: [PATCH] write big ugly panic message for when main() freaks out too much --- src/chat.h | 1 + src/main.cc | 32 ++++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/chat.h b/src/chat.h index fc9c412..e058d42 100644 --- a/src/chat.h +++ b/src/chat.h @@ -13,6 +13,7 @@ typedef struct __wclient_args_t wclient_args_t; void *await_client(void *a); +void big_panic_msg(void); void clear_rows(int s, int e); int count_lines(std::string p); int file_disp(std::string p, int lnstart, int lncount = 10); diff --git a/src/main.cc b/src/main.cc index 774c4c4..23d5537 100644 --- a/src/main.cc +++ b/src/main.cc @@ -21,7 +21,6 @@ typedef enum { NO_MODE = 0, SERVER_MODE = 1, CLIENT_MODE = 2 } chatmode_t; chatmode_t mode = NO_MODE; -// const int LOG_LENGTH = 10; int line_position = 0; struct timeval time_start; @@ -107,10 +106,7 @@ main(int argc, char *argv[]) return 0; panic_no_mode: - fprintf(stderr, "-----FATAL ERROR, THIS SHOULD NEVER HAPPEN-----\n"); - fprintf(stderr, "You may ask yourself... how do I work this?\n"); - fprintf(stderr, "And you may find yourself... past the point of return 0;!\n"); - fprintf(stderr, "And you may ask yourself... well, how did I get here?\n"); + big_panic_msg(); if (mode == NO_MODE) fprintf(stderr, "Fatal: Mode was not set!\n"); @@ -120,7 +116,31 @@ panic_no_mode: return 1; panic_no_server_sock: - endwin(); + big_panic_msg(); + fprintf(stderr, "Fatal: Could not establish server socket!\n"); return 1; } + +/* + * For when things go really really bad. + * Check if there is a window and if so, close it. + * Spit out a really loud obnoxious error afterwards. + */ +void +big_panic_msg(void) +{ + if (!isendwin()) + endwin(); + + fprintf(stderr, "-----FATAL ERROR, THIS SHOULD NEVER HAPPEN-----\n"); + usleep(400 * 1000); + fprintf(stderr, "You may ask yourself... how do I work this?\n"); + putchar(7); + usleep(400 * 1000); + fprintf(stderr, "And you may find yourself... past the point of return 0;!\n"); + putchar(7); + usleep(400 * 1000); + fprintf(stderr, "And you may ask yourself... well, how did I get here?\n"); + putchar(7); +}