diff options
author | michi_cc <michi_cc@openttd.org> | 2013-08-05 20:36:47 +0000 |
---|---|---|
committer | michi_cc <michi_cc@openttd.org> | 2013-08-05 20:36:47 +0000 |
commit | e3648455aa6dba0954c872389f7c7ee3a9a99676 (patch) | |
tree | 3fd72c54d3e6e586e9a74fc93aa08996e7eaba6c | |
parent | e37968aadd8c14d15d49b90754a69126bdf674e7 (diff) | |
download | openttd-e3648455aa6dba0954c872389f7c7ee3a9a99676.tar.xz |
(svn r25674) -Fix: [Win32] The console code page for non-Unicode builds is not the normal ANSI code page and definitely not UTF-8 either.
-rw-r--r-- | src/debug.cpp | 11 | ||||
-rw-r--r-- | src/os/windows/win32.cpp | 10 | ||||
-rw-r--r-- | src/os/windows/win32.h | 2 | ||||
-rw-r--r-- | src/stdafx.h | 2 |
4 files changed, 14 insertions, 11 deletions
diff --git a/src/debug.cpp b/src/debug.cpp index e6fb61292..d173ff14c 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -131,13 +131,14 @@ static void debug_print(const char *dbg, const char *buf) fflush(f); #endif } else { + char buffer[512]; + seprintf(buffer, lastof(buffer), "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf); #if defined(WINCE) - /* We need to do OTTD2FS twice, but as it uses a static buffer, we need to store one temporary */ - TCHAR tbuf[512]; - _sntprintf(tbuf, sizeof(tbuf), _T("%s"), OTTD2FS(dbg)); - NKDbgPrintfW(_T("dbg: [%s] %s\n"), tbuf, OTTD2FS(buf)); + NKDbgPrintfW(OTTD2FS(buffer)); +#elif defined(WIN32) || defined(WIN64) + _fputts(OTTD2FS(buffer, true), stderr); #else - fprintf(stderr, "%sdbg: [%s] %s\n", GetLogPrefix(), dbg, buf); + fputs(buffer, stderr); #endif #ifdef ENABLE_NETWORK NetworkAdminConsole(dbg, buf); diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 37d402ae2..314ff621a 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -621,12 +621,13 @@ const char *FS2OTTD(const TCHAR *name) * The returned value's contents can only be guaranteed until the next call to * this function. So if the value is needed for anything else, use convert_from_fs * @param name pointer to a valid string that will be converted (UTF8) + * @param console_cp convert to the console encoding instead of the normal system encoding. * @return pointer to the converted string; if failed string is of zero-length */ -const TCHAR *OTTD2FS(const char *name) +const TCHAR *OTTD2FS(const char *name, bool console_cp) { static TCHAR system_buf[512]; - return convert_to_fs(name, system_buf, lengthof(system_buf)); + return convert_to_fs(name, system_buf, lengthof(system_buf), console_cp); } @@ -669,9 +670,10 @@ char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen) * @param utf16_buf pointer to a valid wide-char buffer that will receive the * converted string * @param buflen length in wide characters of the receiving buffer + * @param console_cp convert to the console encoding instead of the normal system encoding. * @return pointer to utf16_buf. If conversion fails the string is of zero-length */ -TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen) +TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen, bool console_cp) { #if defined(UNICODE) int len = MultiByteToWideChar(CP_UTF8, 0, name, -1, system_buf, (int)buflen); @@ -686,7 +688,7 @@ TCHAR *convert_to_fs(const char *name, TCHAR *system_buf, size_t buflen) WCHAR *wide_buf = AllocaM(WCHAR, len); MultiByteToWideChar(CP_UTF8, 0, name, -1, wide_buf, len); - len = WideCharToMultiByte(CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, NULL, NULL); + len = WideCharToMultiByte(console_cp ? CP_OEMCP : CP_ACP, 0, wide_buf, len, system_buf, (int)buflen, NULL, NULL); if (len == 0) system_buf[0] = '\0'; #endif diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h index d0eb371aa..f4b03d970 100644 --- a/src/os/windows/win32.h +++ b/src/os/windows/win32.h @@ -19,7 +19,7 @@ typedef void (*Function)(int); bool LoadLibraryList(Function proc[], const char *dll); char *convert_from_fs(const TCHAR *name, char *utf8_buf, size_t buflen); -TCHAR *convert_to_fs(const char *name, TCHAR *utf16_buf, size_t buflen); +TCHAR *convert_to_fs(const char *name, TCHAR *utf16_buf, size_t buflen, bool console_cp = false); /* Function shortcuts for UTF-8 <> UNICODE conversion. When unicode is not * defined these macros return the string passed to them, with UNICODE diff --git a/src/stdafx.h b/src/stdafx.h index b91466403..d38e2b242 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -287,7 +287,7 @@ #endif /* WINCE */ const char *FS2OTTD(const TCHAR *name); - const TCHAR *OTTD2FS(const char *name); + const TCHAR *OTTD2FS(const char *name, bool console_cp = false); #define SQ2OTTD(name) FS2OTTD(name) #define OTTD2SQ(name) OTTD2FS(name) #else |