distinguish exit with message on error and on success (#1055)

This commit is contained in:
Fabian Greffrath 2023-05-14 16:09:57 +02:00 committed by GitHub
parent 53024044fd
commit 3fd2db56ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 6 deletions

View File

@ -3966,7 +3966,7 @@ boolean G_CheckDemoStatus(void)
int endtime = I_GetTime_RealTime(); int endtime = I_GetTime_RealTime();
// killough -- added fps information and made it work for longer demos: // killough -- added fps information and made it work for longer demos:
unsigned realtics = endtime-starttime; 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,realtics,
(unsigned) gametic * (double) TICRATE / realtics); (unsigned) gametic * (double) TICRATE / realtics);
} }

View File

@ -75,8 +75,9 @@ static boolean I_ConsoleStdout(void)
// //
static char errmsg[2048]; // buffer of error message -- killough 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' size_t len = sizeof(errmsg) - strlen(errmsg) - 1; // [FG] for '\n'
char *dest = errmsg + strlen(errmsg); char *dest = errmsg + strlen(errmsg);
@ -89,7 +90,10 @@ void I_Error(const char *error, ...) // killough 3/20/98: add const
fputs(dest, stderr); fputs(dest, stderr);
I_SafeExit(-1); if (exit_code == 0 && err_code != 0)
exit_code = err_code;
I_SafeExit(exit_code);
} }
void I_ErrorMsg() void I_ErrorMsg()
@ -102,7 +106,9 @@ void I_ErrorMsg()
if (*errmsg && !M_CheckParm("-nogui") && !I_ConsoleStdout()) 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); PROJECT_STRING, errmsg, NULL);
} }
} }

View File

@ -58,7 +58,9 @@ ticcmd_t* I_BaseTiccmd (void);
// killough 3/20/98: add const // killough 3/20/98: add const
// killough 4/25/98: add gcc attributes // 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. // Schedule a function to be called when the program exits.
// If run_if_error is true, the function is called if the exit // If run_if_error is true, the function is called if the exit

View File

@ -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); fwrite(lumps[i].data, 1, lumps[i].size, file);
fclose(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); I_Error("Cannot open internal lumps wad %s for output\n", filename);
free(fn); free(fn);