2010-12-10 12:21:13 -03:00
|
|
|
/*
|
|
|
|
debugstr.c - Auxiliary debug functionality.
|
|
|
|
*/
|
|
|
|
|
2010-12-12 21:58:35 +10:00
|
|
|
#include "ansicon.h"
|
2010-12-10 12:21:13 -03:00
|
|
|
|
2010-12-12 21:58:35 +10:00
|
|
|
#if (MYDEBUG > 1)
|
|
|
|
char tempfile[MAX_PATH];
|
|
|
|
#endif
|
2010-12-10 12:21:13 -03:00
|
|
|
|
|
|
|
#if (MYDEBUG > 0)
|
|
|
|
void DEBUGSTR( LPTSTR szFormat, ... ) // sort of OutputDebugStringf
|
|
|
|
{
|
|
|
|
TCHAR szBuffer[1024], szEscape[1024];
|
|
|
|
va_list pArgList;
|
2010-12-12 21:58:35 +10:00
|
|
|
|
|
|
|
#if (MYDEBUG > 1)
|
|
|
|
if (*tempfile == '\0')
|
|
|
|
_snprintf( tempfile, MAX_PATH, "%s\\ansicon.log", getenv( "TEMP" ) );
|
|
|
|
if (szFormat == NULL)
|
|
|
|
{
|
|
|
|
DeleteFileA( tempfile );
|
|
|
|
return;
|
|
|
|
}
|
2010-12-12 23:32:22 +10:00
|
|
|
#endif
|
2010-12-12 21:58:35 +10:00
|
|
|
|
2010-12-10 12:21:13 -03:00
|
|
|
va_start( pArgList, szFormat );
|
|
|
|
_vsnwprintf( szBuffer, lenof(szBuffer), szFormat, pArgList );
|
|
|
|
va_end( pArgList );
|
|
|
|
|
|
|
|
szFormat = szBuffer;
|
|
|
|
if (*szFormat == '\\')
|
|
|
|
{
|
|
|
|
BOOL first = TRUE;
|
|
|
|
LPTSTR pos = szEscape;
|
|
|
|
while (*++szFormat != '\0' && pos < szEscape + lenof(szEscape) - 4)
|
|
|
|
{
|
|
|
|
if (*szFormat < 32)
|
|
|
|
{
|
2010-12-12 21:58:35 +10:00
|
|
|
*pos++ = '\\';
|
|
|
|
switch (*szFormat)
|
|
|
|
{
|
|
|
|
case '\a': *pos++ = 'a'; break;
|
|
|
|
case '\b': *pos++ = 'b'; break;
|
|
|
|
case '\t': *pos++ = 't'; break;
|
|
|
|
case '\r': *pos++ = 'r'; break;
|
|
|
|
case '\n': *pos++ = 'n'; break;
|
|
|
|
case 27 : *pos++ = 'e'; break;
|
|
|
|
default:
|
|
|
|
pos += _snwprintf( pos, 32, L"%.*o",
|
|
|
|
(szFormat[1] >= '0' && szFormat[1] <= '7') ? 3 : 1,
|
|
|
|
*szFormat );
|
|
|
|
}
|
2010-12-10 12:21:13 -03:00
|
|
|
}
|
|
|
|
else if (*szFormat == '"')
|
|
|
|
{
|
2010-12-12 21:58:35 +10:00
|
|
|
if (first)
|
|
|
|
first = FALSE;
|
|
|
|
else if (szFormat[1] == '\0')
|
|
|
|
;
|
|
|
|
else
|
|
|
|
*pos++ = '\\';
|
|
|
|
*pos++ = '"';
|
2010-12-10 12:21:13 -03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-12 21:58:35 +10:00
|
|
|
*pos++ = *szFormat;
|
2010-12-10 12:21:13 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
*pos = '\0';
|
|
|
|
szFormat = szEscape;
|
|
|
|
}
|
|
|
|
#if (MYDEBUG > 1)
|
|
|
|
{
|
|
|
|
FILE* file = fopen( tempfile, "at" ); // _fmode might be binary
|
|
|
|
if (file != NULL)
|
|
|
|
{
|
|
|
|
fwprintf( file, L"%s\n", szFormat );
|
|
|
|
fclose( file );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
OutputDebugString( szFormat );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|