Revision: 7398 http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7398 Author: zmatsuo Date: 2019-01-19 17:18:24 +0900 (Sat, 19 Jan 2019) Log Message: ----------- setlocale()を起動時のみ呼び出すようにした Modified Paths: -------------- trunk/teraterm/common/codeconv.cpp trunk/teraterm/common/codeconv.h trunk/teraterm/teraterm/vtdisp.c trunk/teraterm/teraterm/vtterm.c trunk/teraterm/teraterm/vtwin.cpp trunk/teraterm/ttpcmn/language.c -------------- next part -------------- Modified: trunk/teraterm/common/codeconv.cpp =================================================================== --- trunk/teraterm/common/codeconv.cpp 2019-01-17 14:02:52 UTC (rev 7397) +++ trunk/teraterm/common/codeconv.cpp 2019-01-19 08:18:24 UTC (rev 7398) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 TeraTerm Project + * Copyright (C) 2018-2019 TeraTerm Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,6 +38,11 @@ #define free(p) _free_dbg((p), _NORMAL_BLOCK) #endif +int CP932ToWideChar(const char *cp932_ptr, int cp932_len, wchar_t *wstr_ptr, int wstr_len) +{ + return MultiByteToWideChar(932, 0, cp932_ptr, cp932_len, wstr_ptr, wstr_len); +} + /** * wchar_t\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83}\x83\x8B\x83`\x83o\x83C\x83g\x95\xB6\x8E\x9A\x97\xF1\x82֕ϊ\xB7 * @param[in] *wstr_ptr wchar_t\x95\xB6\x8E\x9A\x97\xF1 Modified: trunk/teraterm/common/codeconv.h =================================================================== --- trunk/teraterm/common/codeconv.h 2019-01-17 14:02:52 UTC (rev 7397) +++ trunk/teraterm/common/codeconv.h 2019-01-19 08:18:24 UTC (rev 7398) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 TeraTerm Project + * Copyright (C) 2018-2019 TeraTerm Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,9 +34,15 @@ extern "C" { #endif +// MultiByteToWideChar() wrappers +// CP932(shift-jis) to wchar(UTF-16) +int CP932ToWideChar(const char *cp932_ptr, int cp932_len, wchar_t *wstr_ptr, int wstr_len); + +// API wrappers char *_WideCharToMultiByte(const wchar_t *wstr_ptr, size_t wstr_len, int code_page, size_t *mb_len_); wchar_t *_MultiByteToWideChar(const char *str_ptr, size_t str_len, int code_page, size_t *w_len_); +// convinience funcs (for windows api params) const char *ToCharA(const char *strA); const char *ToCharW(const wchar_t *strW); const char *ToCharU8(const char *strU8); Modified: trunk/teraterm/teraterm/vtdisp.c =================================================================== --- trunk/teraterm/teraterm/vtdisp.c 2019-01-17 14:02:52 UTC (rev 7397) +++ trunk/teraterm/teraterm/vtdisp.c 2019-01-19 08:18:24 UTC (rev 7398) @@ -2879,7 +2879,7 @@ Count = 6; #endif - setlocale(LC_ALL, ts.Locale); + setlocale(LC_ALL, ts.Locale); // TODO \x83R\x81[\x83h\x95ϊ\xB7\x82\xB1\x82\xB1\x82ł\xB7\x82\xE9?,\x96\xB3\x8C\x{27B0B3}\x82ꂽ\x83R\x81[\x83h ch = Buff[Count]; Buff[Count] = 0; Modified: trunk/teraterm/teraterm/vtterm.c =================================================================== --- trunk/teraterm/teraterm/vtterm.c 2019-01-17 14:02:52 UTC (rev 7397) +++ trunk/teraterm/teraterm/vtterm.c 2019-01-19 08:18:24 UTC (rev 7398) @@ -1,6 +1,6 @@ /* * Copyright (C) 1994-1998 T. Teranishi - * (C) 2004-2017 TeraTerm Project + * (C) 2004-2019 TeraTerm Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -5509,10 +5509,7 @@ unsigned int code; unsigned short cset; - char *locptr; - locptr = setlocale(LC_ALL, ts.Locale); - if (ts.FallbackToCP932 && Fallbacked) { return ParseFirstJP(b); } Modified: trunk/teraterm/teraterm/vtwin.cpp =================================================================== --- trunk/teraterm/teraterm/vtwin.cpp 2019-01-17 14:02:52 UTC (rev 7397) +++ trunk/teraterm/teraterm/vtwin.cpp 2019-01-19 08:18:24 UTC (rev 7398) @@ -2041,7 +2041,6 @@ static void EscapeFilename(const char *src, char *dest) { #define ESCAPE_CHARS " ;&()$!`'[]{}#^~" - setlocale(LC_ALL, ts.Locale); const char *s = src; char *d = dest; while (*s) { Modified: trunk/teraterm/ttpcmn/language.c =================================================================== --- trunk/teraterm/ttpcmn/language.c 2019-01-17 14:02:52 UTC (rev 7397) +++ trunk/teraterm/ttpcmn/language.c 2019-01-19 08:18:24 UTC (rev 7398) @@ -1,6 +1,6 @@ /* * Copyright (C) 1994-1998 T. Teranishi - * (C) 2006-2017 TeraTerm Project + * (C) 2006-2019 TeraTerm Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ #include <mbstring.h> #include <locale.h> +#include "codeconv.h" #include "sjis2uni.map" unsigned short ConvertUnicode(unsigned short code, codemap_t *table, int tmax) @@ -70,19 +71,18 @@ unsigned int c, c1, c2, c3; unsigned char *ptr, buf[3]; unsigned short cset; + unsigned char KCode_h; int len = 0; *byte = 2; // CP932\x82\xA9\x82\xE7UTF-16LE\x82֕ϊ\xB7\x82\xB7\x82\xE9 - setlocale(LC_ALL, locale); - - buf[0] = KCode >> 8; - if (buf[0] > 0) { - len++; + KCode_h = (unsigned char)(KCode >> 8); + if (KCode_h != 0) { + buf[len++] = KCode_h; } buf[len++] = KCode & 0xff; - ret = mbtowc(&wchar, buf, len); + ret = CP932ToWideChar(buf, len, &wchar, 1); if (ret <= 0) { // \x95ϊ\xB7\x8E\xB8\x94s cset = 0; if (_stricmp(locale, DEFAULT_LOCALE) == 0) {