int hb_snprintf( char * buffer, size_t bufsize, const char * format, ... ) { va_list ap; int iResult; va_start( ap, format ); iResult = hb_vsnprintf( buffer, bufsize, format, ap ); va_end( ap ); return iResult; }
void hb_ToOutDebug( const char * sTraceMsg, ... ) { if( sTraceMsg && s_bToOutputDebug ) { char buffer[ 1024 ]; va_list ap; va_start( ap, sTraceMsg ); hb_vsnprintf( buffer, sizeof( buffer ), sTraceMsg, ap ); va_end( ap ); hb_OutDebug( ( const char * ) buffer, strlen( buffer ) ); } }
static void hb_tracelog_( int level, const char * file, int line, const char * proc, const char * fmt, va_list ap ) { const char * pszLevel; /* * Clean up the file, so that instead of showing * * ../../../foo/bar/baz.c * * we just show * * foo/bar/baz.c */ if( file ) { while( *file == '.' || *file == '/' || *file == '\\' ) file++; } else file = ""; pszLevel = ( level >= HB_TR_ALWAYS && level <= HB_TR_LAST ) ? s_slevel[ level ] : "(\?\?\?)"; if( s_sysout > 0 ) { #if ( defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE ) ) || \ ( defined( HB_OS_UNIX ) && \ ! defined( __WATCOMC__ ) && \ ! defined( HB_OS_VXWORKS ) && \ ! defined( HB_OS_SYMBIAN ) && \ ! defined( HB_OS_QNX_BB10 ) ) char message[ 1024 ]; va_list vargs; va_copy( vargs, ap ); /* NOTE: This is protection against recursive call to trace engine when there is more than 16 parameters in format string */ if( hb_xtraced() && hb_printf_params( fmt ) > 16 ) hb_snprintf( message, sizeof( message ), "more then 16 parameters in message '%s'", fmt ); else hb_vsnprintf( message, sizeof( message ), fmt, vargs ); va_end( vargs ); # if defined( HB_OS_WIN ) { union { char psz[ 1024 ]; TCHAR lp[ 1024 ]; } buf; /* We add \n at the end of the buffer to make WinDbg display look readable. */ if( proc ) hb_snprintf( buf.psz, sizeof( buf.psz ), "%s:%d:%s() %s %s\n", file, line, proc, pszLevel, message ); else hb_snprintf( buf.psz, sizeof( buf.psz ), "%s:%d: %s %s\n", file, line, pszLevel, message ); #if defined( UNICODE ) MultiByteToWideChar( CP_ACP, 0, ( LPCSTR ) memcpy( message, buf.psz, sizeof( message ) ), -1, buf.lp, HB_SIZEOFARRAY( buf.lp ) ); buf.lp[ HB_SIZEOFARRAY( buf.lp ) - 1 ] = 0; #endif OutputDebugString( buf.lp ); } # else { int slevel; switch( level ) { case HB_TR_ALWAYS: slevel = LOG_ALERT; break; case HB_TR_FATAL: slevel = LOG_CRIT; break; case HB_TR_ERROR: slevel = LOG_ERR; break; case HB_TR_WARNING: slevel = LOG_WARNING; break; case HB_TR_INFO: slevel = LOG_INFO; break; case HB_TR_DEBUG: slevel = LOG_DEBUG; break; default: slevel = LOG_DEBUG; } if( proc ) syslog( slevel, "%s:%d:%s() %s %s", file, line, proc, pszLevel, message ); else syslog( slevel, "%s:%d: %s %s", file, line, pszLevel, message ); } # endif #endif } /* * Print file and line. */ if( proc ) fprintf( s_fp, "%s:%d:%s(): %s ", file, line, proc, pszLevel ); else fprintf( s_fp, "%s:%d: %s ", file, line, pszLevel ); /* * Print the name and arguments for the function. */ vfprintf( s_fp, fmt, ap ); /* * Print a new-line. */ fprintf( s_fp, "\n" ); if( s_flush > 0 ) fflush( s_fp ); }