diff options
author | megamage <none@none> | 2009-08-19 17:02:29 -0500 |
---|---|---|
committer | megamage <none@none> | 2009-08-19 17:02:29 -0500 |
commit | f5085b2f39c91ed0103c79d95f8d18a4ef2a6371 (patch) | |
tree | cba9f8c0706f9db972cb915d27ee9e7fd3daf1d5 | |
parent | d7e4392f796f5624a75216f64ae7520c00439cb9 (diff) |
[8388] Replaced UTF8PRINT macro by a function
Should also fix possible color leak on Windows CLI.
Signed-off-by: freghar <compmancz@gmail.com>
--HG--
branch : trunk
-rw-r--r-- | src/shared/Log.cpp | 20 | ||||
-rw-r--r-- | src/shared/Util.cpp | 25 | ||||
-rw-r--r-- | src/shared/Util.h | 27 |
3 files changed, 36 insertions, 36 deletions
diff --git a/src/shared/Log.cpp b/src/shared/Log.cpp index 8de6e635dec..32483486628 100644 --- a/src/shared/Log.cpp +++ b/src/shared/Log.cpp @@ -388,7 +388,7 @@ void Log::outString( const char * str, ... ) if(m_colored) SetColor(true,m_colors[LOGL_NORMAL]); - UTF8PRINTF(stdout,str,); + utf8printf(stdout, str); if(m_colored) ResetColor(true); @@ -438,7 +438,7 @@ void Log::outCrash( const char * err, ... ) if(m_colored) SetColor(false,RED); - UTF8PRINTF(stderr,err,); + utf8printf(stdout, err); if(m_colored) ResetColor(false); @@ -478,7 +478,7 @@ void Log::outError( const char * err, ... ) if(m_colored) SetColor(false,RED); - UTF8PRINTF(stderr,err,); + utf8printf(stderr, err); if(m_colored) ResetColor(false); @@ -526,7 +526,7 @@ void Log::outErrorDb( const char * err, ... ) if(m_colored) SetColor(false,RED); - UTF8PRINTF(stderr,err,); + utf8printf(stderr, err); if(m_colored) ResetColor(false); @@ -581,7 +581,7 @@ void Log::outBasic( const char * str, ... ) if(m_colored) SetColor(true,m_colors[LOGL_BASIC]); - UTF8PRINTF(stdout,str,); + utf8printf(stdout, str); if(m_colored) ResetColor(true); @@ -622,7 +622,7 @@ void Log::outDetail( const char * str, ... ) if(m_colored) SetColor(true,m_colors[LOGL_DETAIL]); - UTF8PRINTF(stdout,str,); + utf8printf(stdout, str); if(m_colored) ResetColor(true); @@ -650,7 +650,7 @@ void Log::outDebugInLine( const char * str, ... ) if( m_logLevel > LOGL_DETAIL ) { - UTF8PRINTF(stdout,str,); + utf8printf(stdout, str); } if(logfile && m_logFileLevel > LOGL_DETAIL) { @@ -681,7 +681,7 @@ void Log::outDebug( const char * str, ... ) if(m_colored) SetColor(true,m_colors[LOGL_DEBUG]); - UTF8PRINTF(stdout,str,); + utf8printf(stdout, str); if(m_colored) ResetColor(true); @@ -707,7 +707,7 @@ void Log::outStringInLine( const char * str, ... ) if( !str ) return; - UTF8PRINTF(stdout,str,); + utf8printf(stdout, str); if(logfile) { @@ -739,7 +739,7 @@ void Log::outCommand( uint32 account, const char * str, ... ) if(m_colored) SetColor(true,m_colors[LOGL_BASIC]); - UTF8PRINTF(stdout,str,); + utf8printf(stdout, str); if(m_colored) ResetColor(true); diff --git a/src/shared/Util.cpp b/src/shared/Util.cpp index 644769f2069..3d3b205209a 100644 --- a/src/shared/Util.cpp +++ b/src/shared/Util.cpp @@ -478,3 +478,28 @@ bool Utf8FitTo(const std::string& str, std::wstring search) return true; } +void utf8printf(FILE *out, const char *str, ...) +{ + va_list ap; + +#if PLATFORM == PLATFORM_WINDOWS + char temp_buf[32*1024]; + wchar_t wtemp_buf[32*1024]; + size_t temp_len; + size_t wtemp_len; + + va_start(ap, str); + temp_len = vsnprintf(temp_buf, 32*1024, str, ap); + va_end(ap); + + wtemp_len = 32*1024-1; + Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len); + + CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], wtemp_len+1); + fprintf(out, temp_buf); +#else + va_start(ap, str); + vfprintf(out, str, ap); + va_end(ap); +#endif +} diff --git a/src/shared/Util.h b/src/shared/Util.h index 496411d8be3..a57c7b2a2f4 100644 --- a/src/shared/Util.h +++ b/src/shared/Util.h @@ -285,32 +285,7 @@ std::wstring GetMainPartOfName(std::wstring wname, uint32 declension); bool utf8ToConsole(const std::string& utf8str, std::string& conStr); bool consoleToUtf8(const std::string& conStr,std::string& utf8str); bool Utf8FitTo(const std::string& str, std::wstring search); - -#if PLATFORM == PLATFORM_WINDOWS -#define UTF8PRINTF(OUT,FRM,RESERR) \ -{ \ - char temp_buf[32*1024]; \ - va_list ap; \ - va_start(ap, FRM); \ - size_t temp_len = vsnprintf(temp_buf,32*1024,FRM,ap); \ - va_end(ap); \ - \ - wchar_t wtemp_buf[32*1024]; \ - size_t wtemp_len = 32*1024-1; \ - if(!Utf8toWStr(temp_buf,temp_len,wtemp_buf,wtemp_len)) \ - return RESERR; \ - CharToOemBuffW(&wtemp_buf[0],&temp_buf[0],wtemp_len+1);\ - fprintf(OUT,temp_buf); \ -} -#else -#define UTF8PRINTF(OUT,FRM,RESERR) \ -{ \ - va_list ap; \ - va_start(ap, FRM); \ - vfprintf(OUT, FRM, ap ); \ - va_end(ap); \ -} -#endif +void utf8printf(FILE *out, const char *str, ...); bool IsIPAddress(char const* ipaddress); uint32 CreatePIDFile(const std::string& filename); |