From 3fd2db56ad2d4621917215dd9e378d95bbc3021c Mon Sep 17 00:00:00 2001 From: Fabian Greffrath Date: Sun, 14 May 2023 16:09:57 +0200 Subject: [PATCH] distinguish exit with message on error and on success (#1055) --- src/g_game.c | 2 +- src/i_system.c | 12 +++++++++--- src/i_system.h | 4 +++- src/w_wad.c | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index a03478d4..0230d08f 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3966,7 +3966,7 @@ boolean G_CheckDemoStatus(void) int endtime = I_GetTime_RealTime(); // killough -- added fps information and made it work for longer demos: unsigned realtics = endtime-starttime; - I_Error ("Timed %u gametics in %u realtics = %-.1f frames per second", + I_Success("Timed %u gametics in %u realtics = %-.1f frames per second", (unsigned) gametic,realtics, (unsigned) gametic * (double) TICRATE / realtics); } diff --git a/src/i_system.c b/src/i_system.c index 925de518..fb0c93cb 100644 --- a/src/i_system.c +++ b/src/i_system.c @@ -75,8 +75,9 @@ static boolean I_ConsoleStdout(void) // static char errmsg[2048]; // buffer of error message -- killough +static int exit_code; -void I_Error(const char *error, ...) // killough 3/20/98: add const +void I_ErrorOrSuccess(int err_code, const char *error, ...) // killough 3/20/98: add const { size_t len = sizeof(errmsg) - strlen(errmsg) - 1; // [FG] for '\n' char *dest = errmsg + strlen(errmsg); @@ -89,7 +90,10 @@ void I_Error(const char *error, ...) // killough 3/20/98: add const fputs(dest, stderr); - I_SafeExit(-1); + if (exit_code == 0 && err_code != 0) + exit_code = err_code; + + I_SafeExit(exit_code); } void I_ErrorMsg() @@ -102,7 +106,9 @@ void I_ErrorMsg() if (*errmsg && !M_CheckParm("-nogui") && !I_ConsoleStdout()) { - SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, + SDL_ShowSimpleMessageBox(exit_code == 0 ? + SDL_MESSAGEBOX_INFORMATION : + SDL_MESSAGEBOX_ERROR, PROJECT_STRING, errmsg, NULL); } } diff --git a/src/i_system.h b/src/i_system.h index b3d34056..0dbd1412 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -58,7 +58,9 @@ ticcmd_t* I_BaseTiccmd (void); // killough 3/20/98: add const // killough 4/25/98: add gcc attributes -void I_Error(const char *error, ...) PRINTF_ATTR(1, 2); +void I_ErrorOrSuccess(int err_code, const char *error, ...) PRINTF_ATTR(2, 3); +#define I_Error(...) I_ErrorOrSuccess(-1, __VA_ARGS__) +#define I_Success(...) I_ErrorOrSuccess(0, __VA_ARGS__) // Schedule a function to be called when the program exits. // If run_if_error is true, the function is called if the exit diff --git a/src/w_wad.c b/src/w_wad.c index 113f800b..250e43f8 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -523,7 +523,7 @@ void WriteLumpWad(const char *filename, const lumpinfo_t *lumps, const size_t nu fwrite(lumps[i].data, 1, lumps[i].size, file); fclose(file); - I_Error("Internal lumps wad, %s written, exiting\n", filename); + I_Success("Internal lumps wad, %s written, exiting\n", filename); } I_Error("Cannot open internal lumps wad %s for output\n", filename); free(fn);