Browse Source

engine: strip color codes when writing to log

pull/2/head
Velaron 3 years ago committed by a1batross
parent
commit
568c7fd917
  1. 9
      engine/common/sys_con.c
  2. 11
      public/crtlib.c
  3. 1
      public/crtlib.h

9
engine/common/sys_con.c

@ -230,6 +230,9 @@ void Sys_PrintLog( const char *pMsg )
time( &crt_time ); time( &crt_time );
crt_tm = localtime( &crt_time ); crt_tm = localtime( &crt_time );
// strip color codes
Q_cleanstr( pMsg, pMsg );
// platform-specific output // platform-specific output
#if XASH_ANDROID && !XASH_DEDICATED #if XASH_ANDROID && !XASH_DEDICATED
__android_log_print( ANDROID_LOG_DEBUG, "Xash", "%s", pMsg ); __android_log_print( ANDROID_LOG_DEBUG, "Xash", "%s", pMsg );
@ -253,15 +256,15 @@ void Sys_PrintLog( const char *pMsg )
Sys_FlushStdout(); Sys_FlushStdout();
#endif #endif
// save last char to detect when line was not ended
lastchar = pMsg[strlen(pMsg)-1];
if( !s_ld.logfile ) if( !s_ld.logfile )
return; return;
if( !lastchar || lastchar == '\n') if( !lastchar || lastchar == '\n')
strftime( logtime, sizeof( logtime ), "[%Y:%m:%d|%H:%M:%S] ", crt_tm ); //full time strftime( logtime, sizeof( logtime ), "[%Y:%m:%d|%H:%M:%S] ", crt_tm ); //full time
// save last char to detect when line was not ended
lastchar = pMsg[strlen(pMsg)-1];
fprintf( s_ld.logfile, "%s%s", logtime, pMsg ); fprintf( s_ld.logfile, "%s%s", logtime, pMsg );
Sys_FlushLogfile(); Sys_FlushLogfile();
} }

11
public/crtlib.c

@ -615,6 +615,17 @@ char *Q_strpbrk(const char *s, const char *accept)
return NULL; return NULL;
} }
void Q_cleanstr( const char *in, char *out )
{
while ( *in )
{
if ( IsColorString( in ) )
in += 2;
else *out++ = *in++;
}
*out = '\0';
}
uint Q_hashkey( const char *string, uint hashSize, qboolean caseinsensitive ) uint Q_hashkey( const char *string, uint hashSize, qboolean caseinsensitive )
{ {
uint i, hashKey = 0; uint i, hashKey = 0;

1
public/crtlib.h

@ -73,6 +73,7 @@ int Q_vsnprintf( char *buffer, size_t buffersize, const char *format, va_list ar
int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format( 3 ); int Q_snprintf( char *buffer, size_t buffersize, const char *format, ... ) _format( 3 );
int Q_sprintf( char *buffer, const char *format, ... ) _format( 2 ); int Q_sprintf( char *buffer, const char *format, ... ) _format( 2 );
char *Q_strpbrk(const char *s, const char *accept); char *Q_strpbrk(const char *s, const char *accept);
void Q_cleanstr( char *in, char *out );
#define Q_memprint( val ) Q_pretifymem( val, 2 ) #define Q_memprint( val ) Q_pretifymem( val, 2 )
char *Q_pretifymem( float value, int digitsafterdecimal ); char *Q_pretifymem( float value, int digitsafterdecimal );
char *va( const char *format, ... ) _format( 1 ); char *va( const char *format, ... ) _format( 1 );

Loading…
Cancel
Save