write big ugly panic message for when main() freaks out too much

This commit is contained in:
2026-03-09 12:45:24 -05:00
parent 59e34977da
commit bd2debcf7d
2 changed files with 27 additions and 6 deletions

View File

@@ -13,6 +13,7 @@
typedef struct __wclient_args_t wclient_args_t; typedef struct __wclient_args_t wclient_args_t;
void *await_client(void *a); void *await_client(void *a);
void big_panic_msg(void);
void clear_rows(int s, int e); void clear_rows(int s, int e);
int count_lines(std::string p); int count_lines(std::string p);
int file_disp(std::string p, int lnstart, int lncount = 10); int file_disp(std::string p, int lnstart, int lncount = 10);

View File

@@ -21,7 +21,6 @@ typedef enum { NO_MODE = 0, SERVER_MODE = 1, CLIENT_MODE = 2 } chatmode_t;
chatmode_t mode = NO_MODE; chatmode_t mode = NO_MODE;
// const int LOG_LENGTH = 10;
int line_position = 0; int line_position = 0;
struct timeval time_start; struct timeval time_start;
@@ -107,10 +106,7 @@ main(int argc, char *argv[])
return 0; return 0;
panic_no_mode: panic_no_mode:
fprintf(stderr, "-----FATAL ERROR, THIS SHOULD NEVER HAPPEN-----\n"); big_panic_msg();
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");
if (mode == NO_MODE) if (mode == NO_MODE)
fprintf(stderr, "Fatal: Mode was not set!\n"); fprintf(stderr, "Fatal: Mode was not set!\n");
@@ -120,7 +116,31 @@ panic_no_mode:
return 1; return 1;
panic_no_server_sock: panic_no_server_sock:
endwin(); big_panic_msg();
fprintf(stderr, "Fatal: Could not establish server socket!\n"); fprintf(stderr, "Fatal: Could not establish server socket!\n");
return 1; 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);
}