diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 61 | ||||
-rw-r--r-- | src/common.h | 4 | ||||
-rw-r--r-- | src/mvd_client.c | 6 | ||||
-rw-r--r-- | src/sv_game.c | 2 | ||||
-rw-r--r-- | src/sys_unix.c | 2 | ||||
-rw-r--r-- | src/sys_win.c | 2 |
6 files changed, 58 insertions, 19 deletions
diff --git a/src/common.c b/src/common.c index 29cc07b..6f65dbd 100644 --- a/src/common.c +++ b/src/common.c @@ -45,7 +45,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static jmp_buf abortframe; // an ERR_DROP occured, exit the entire frame -static char com_errorMsg[MAXPRINTMSG]; +static qboolean com_errorEntered; +static char com_errorMsg[MAXERRORMSG]; // from Com_Printf/Com_Error static char **com_argv; static int com_argc; @@ -332,6 +333,18 @@ void Com_SetColor( color_index_t color ) { #endif } +void Com_SetLastError( const char *msg ) { + if( msg ) { + Q_strlcpy( com_errorMsg, msg, sizeof( com_errorMsg ) ); + } else { + strcpy( com_errorMsg, "No error" ); + } +} + +char *Com_GetLastError( void ) { + return com_errorMsg; +} + /* ============= Com_Printf @@ -341,9 +354,9 @@ to the apropriate place. ============= */ void Com_LPrintf( print_type_t type, const char *fmt, ... ) { + static int recursive; va_list argptr; char msg[MAXPRINTMSG]; - static int recursive; size_t len; if( recursive == 2 ) { @@ -356,6 +369,23 @@ void Com_LPrintf( print_type_t type, const char *fmt, ... ) { len = Q_vscnprintf( msg, sizeof( msg ), fmt, argptr ); va_end( argptr ); + if( type == PRINT_ERROR && !com_errorEntered && len ) { + size_t errlen = len; + + if( errlen >= sizeof( com_errorMsg ) ) { + errlen = sizeof( com_errorMsg ) - 1; + } + + // save error msg + memcpy( com_errorMsg, msg, errlen ); + com_errorMsg[errlen] = 0; + + // strip trailing '\n' + if( com_errorMsg[errlen - 1] == '\n' ) { + com_errorMsg[errlen - 1] = 0; + } + } + if( rd_target ) { Com_Redirect( msg, len ); } else { @@ -415,21 +445,28 @@ do the apropriate things. ============= */ void Com_Error( error_type_t code, const char *fmt, ... ) { - va_list argptr; - static qboolean recursive; + char msg[MAXERRORMSG]; + va_list argptr; + size_t len; - if( recursive ) { + if( com_errorEntered ) { #ifdef _DEBUG Sys_DebugBreak(); #endif Sys_Error( "recursive error after: %s", com_errorMsg ); } - recursive = qtrue; + + com_errorEntered = qtrue; va_start( argptr, fmt ); - Q_vsnprintf( com_errorMsg, sizeof( com_errorMsg ), fmt, argptr ); + len = Q_vscnprintf( msg, sizeof( msg ), fmt, argptr ); va_end( argptr ); + // save error msg + // can't print into it directly since it may + // overlap with one of the arguments! + memcpy( com_errorMsg, msg, len + 1 ); + // fix up drity message buffers MSG_Init(); @@ -485,7 +522,7 @@ abort: if( com_logFile ) { FS_Flush( com_logFile ); } - recursive = qfalse; + com_errorEntered = qfalse; longjmp( abortframe, -1 ); } @@ -1562,11 +1599,7 @@ static size_t Com_MapList_m( char *buffer, size_t size ) { } static void Com_LastError_f( void ) { - if( com_errorMsg[0] ) { - Com_Printf( "%s\n", com_errorMsg ); - } else { - Com_Printf( "No error.\n" ); - } + Com_Printf( "%s\n", com_errorMsg ); } #if 0 @@ -1797,6 +1830,8 @@ void Qcommon_Init( int argc, char **argv ) { com_argc = argc; com_argv = argv; + Com_SetLastError( NULL ); + // prepare enough of the subsystems to handle // cvar and command buffer management Z_Init(); diff --git a/src/common.h b/src/common.h index db4a06b..00df578 100644 --- a/src/common.h +++ b/src/common.h @@ -456,6 +456,7 @@ MISC */ #define MAXPRINTMSG 4096 +#define MAXERRORMSG 1024 typedef enum { COLOR_BLACK, @@ -505,6 +506,9 @@ void Com_EndRedirect (void); void Com_AbortFrame( void ); #endif +char *Com_GetLastError( void ); +void Com_SetLastError( const char *msg ); + void Com_Quit( const char *reason, killtype_t type ) q_noreturn; void Com_SetColor( color_index_t color ); diff --git a/src/mvd_client.c b/src/mvd_client.c index ae6ef5c..ccc737a 100644 --- a/src/mvd_client.c +++ b/src/mvd_client.c @@ -175,7 +175,7 @@ static void MVD_Destroy( mvd_t *mvd ) { void MVD_Destroyf( mvd_t *mvd, const char *fmt, ... ) { va_list argptr; - char text[MAXPRINTMSG]; + char text[MAXERRORMSG]; va_start( argptr, fmt ); Q_vsnprintf( text, sizeof( text ), fmt, argptr ); @@ -266,7 +266,7 @@ COMMON GTV STUFF static void q_noreturn q_printf( 2, 3 ) gtv_dropf( gtv_t *gtv, const char *fmt, ... ) { va_list argptr; - char text[MAXPRINTMSG]; + char text[MAXERRORMSG]; va_start( argptr, fmt ); Q_vsnprintf( text, sizeof( text ), fmt, argptr ); @@ -282,7 +282,7 @@ gtv_dropf( gtv_t *gtv, const char *fmt, ... ) { static void q_noreturn q_printf( 2, 3 ) gtv_destroyf( gtv_t *gtv, const char *fmt, ... ) { va_list argptr; - char text[MAXPRINTMSG]; + char text[MAXERRORMSG]; va_start( argptr, fmt ); Q_vsnprintf( text, sizeof( text ), fmt, argptr ); diff --git a/src/sv_game.c b/src/sv_game.c index 3e7b034..04f4642 100644 --- a/src/sv_game.c +++ b/src/sv_game.c @@ -287,7 +287,7 @@ Abort the server with a game error =============== */ static q_noreturn void PF_error (const char *fmt, ...) { - char msg[MAXPRINTMSG]; + char msg[MAXERRORMSG]; va_list argptr; va_start (argptr,fmt); diff --git a/src/sys_unix.c b/src/sys_unix.c index f38be84..1ff2370 100644 --- a/src/sys_unix.c +++ b/src/sys_unix.c @@ -755,7 +755,7 @@ Sys_Error */ void Sys_Error( const char *error, ... ) { va_list argptr; - char text[MAXPRINTMSG]; + char text[MAXERRORMSG]; #if USE_SYSCON tty_shutdown_input(); diff --git a/src/sys_win.c b/src/sys_win.c index 088f432..211ab29 100644 --- a/src/sys_win.c +++ b/src/sys_win.c @@ -606,7 +606,7 @@ Sys_Error */ void Sys_Error( const char *error, ... ) { va_list argptr; - char text[MAXPRINTMSG]; + char text[MAXERRORMSG]; va_start( argptr, error ); Q_vsnprintf( text, sizeof( text ), error, argptr ); |