Simplify the common combination of sprintf() and OutputDebugString() (PR #1031)

- Update LogOutput() and LogFileOutput().
- Add StrFormat() to produce std::string out of snprintf() & add StrFormat.cpp to projects.
- Add PTRDIFF_T_FMT in parallel to SIZE_T_FMT to StdAfx.h, for completeness.
- In Log.cpp, changed to get timestamp using posix functions.
- Removed TCHAR usage throughout - simply use char.
This commit is contained in:
Kelvin Lee
2022-02-14 08:37:05 +11:00
committed by GitHub
parent 83e56924f7
commit 9a3832084a
22 changed files with 222 additions and 133 deletions
+14 -23
View File
@@ -3820,11 +3820,10 @@ Update_t CmdConfigSetDebugDir (int nArgs)
while ((iPathSeparator = sNewPath.find( PATH_SEPARATOR, iPrevSeparator )) != std::string::npos)
{
#if _DEBUG
char zDebug[128];
sprintf( zDebug, "Prev: %d\n", iPrevSeparator ); OutputDebugStringA( zDebug );
sprintf( zDebug, "Next: %d\n", iPathSeparator ); OutputDebugStringA( zDebug );
sprintf( zDebug, "%s\n", sNewPath.c_str() ); OutputDebugStringA( zDebug );
sprintf( zDebug, "%*s%s\n", iPathSeparator, "", "^"); OutputDebugStringA( zDebug );
LogOutput( "Prev: %" SIZE_T_FMT "\n", iPrevSeparator );
LogOutput( "Next: %" SIZE_T_FMT "\n", iPathSeparator );
LogOutput( "%s\n", sNewPath.c_str() );
LogOutput( "%*s%s\n", int(iPathSeparator), "", "^" );
#endif
std::string sSubDir = sNewPath.substr( iPrevSeparator, iPathSeparator - iPrevSeparator + 1 );
@@ -3843,9 +3842,9 @@ Update_t CmdConfigSetDebugDir (int nArgs)
if (nLastSeperator != std::string::npos)
{
#if _DEBUG
sprintf( zDebug, "Last: %d\n", nLastSeperator ); OutputDebugStringA( zDebug );
sprintf( zDebug, "%s\n", g_sCurrentDir.c_str() ); OutputDebugStringA( zDebug );
sprintf( zDebug, "%*s%s\n", nLastSeperator, "", "^"); OutputDebugStringA( zDebug );
LogOutput( "Last: %" SIZE_T_FMT "\n", nLastSeperator );
LogOutput( "%s\n", g_sCurrentDir.c_str() );
LogOutput( "%*s%s\n", int(nLastSeperator), "", "^" );
#endif
std::string sCurrentDir = g_sCurrentDir.substr( 0, nLastSeperator + 1 ); // Path always has trailing slash so include it
g_sCurrentDir = sCurrentDir;
@@ -4741,7 +4740,7 @@ Update_t CmdNTSC (int nArgs)
public:
static void update( const char *pPrefixText )
{
TCHAR text[ CONSOLE_WIDTH*2 ] = TEXT("");
char text[ CONSOLE_WIDTH*2 ] = "";
size_t len1 = strlen( pPrefixText );
size_t len2 = sPaletteFilePath.size();
@@ -4752,11 +4751,9 @@ Update_t CmdNTSC (int nArgs)
ConsoleBufferPush( pPrefixText ); // TODO: Add a ": " separator
#if _DEBUG
sprintf( text, "Filename.length.1: %d\n", len1 );
OutputDebugString( text );
sprintf( text, "Filename.length.2: %d\n", len2 );
OutputDebugString( text );
OutputDebugString( sPaletteFilePath.c_str() );
LogOutput( "Filename.length.1: %d\n", len1 );
LogOutput( "Filename.length.2: %d\n", len2 );
OutputDebugStringA( sPaletteFilePath.c_str() );
#endif
// File path is too long
// TODO: Need to split very long path names
@@ -4892,9 +4889,7 @@ Update_t CmdNTSC (int nArgs)
if (iDstX == 15)
iSrcX = 15;
#if 0 // _DEBUG
char text[ 128 ];
sprintf( text, "[ %X ] = [ %X ]\n", iDstX, iSrcX );
OutputDebugStringA( text );
LogOutput( "[ %X ] = [ %X ]\n", iDstX, iSrcX );
#endif
pTmp[ iDstX + 16*iPhase ] = pPhase0[ iSrcX ];
}
@@ -6205,11 +6200,9 @@ int FindSourceLine( WORD nAddress )
// iSourceLine = g_aSourceDebug.find( nAddress );
#if 0 // _DEBUG
{
TCHAR sText[ CONSOLE_WIDTH ];
for (int i = 0; i < g_vSourceLines.size(); i++ )
{
wsprintf( sText, "%d: %s\n", i, g_vSourceLines[ i ] );
OutputDebugString( sText );
LogOutput( "%d: %s\n", i, g_vSourceLines[ i ] );
}
}
#endif
@@ -6221,9 +6214,7 @@ int FindSourceLine( WORD nAddress )
iLine = iSource->second;
#if 0 // _DEBUG
TCHAR sText[ CONSOLE_WIDTH ];
wsprintf( sText, "%04X -> %d line\n", iAddress, iLine );
OutputDebugString( sText );
LogOutput( "%04X -> %d line\n", iAddress, iLine );
#endif
if (iAddress == nAddress)