[Ttssh2-commit] [7471] codeconvに合わせて修正

scmno****@osdn***** scmno****@osdn*****
2019年 3月 10日 (日) 23:32:59 JST


Revision: 7471
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7471
Author:   zmatsuo
Date:     2019-03-10 23:32:59 +0900 (Sun, 10 Mar 2019)
Log Message:
-----------
codeconvに合わせて修正

Modified Paths:
--------------
    branches/cmake/teraterm/common/i18n.c
    branches/cmake/teraterm/common/ttcommon.h
    branches/cmake/teraterm/teraterm/vtdisp.c
    branches/cmake/teraterm/teraterm/vtterm.c
    branches/cmake/teraterm/teraterm/vtwin.cpp
    branches/cmake/teraterm/ttpcmn/language.c
    branches/cmake/teraterm/ttpcmn/language.h
    branches/cmake/teraterm/ttpcmn/ttcmn.c
    branches/cmake/teraterm/ttpmacro/ttl_gui.cpp

-------------- next part --------------
Modified: branches/cmake/teraterm/common/i18n.c
===================================================================
--- branches/cmake/teraterm/common/i18n.c	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/common/i18n.c	2019-03-10 14:32:59 UTC (rev 7471)
@@ -56,7 +56,7 @@
 // TODO: \x83o\x83b\x83t\x83@\x95s\x91\xAB\x8E\x9E\x82̓\xAE\x8D\xEC
 DllExport void GetI18nStrU8(const char *section, const char *key, char *buf, int buf_len, const char *def, const char *iniFile)
 {
-	int r;
+	size_t r;
 #if defined(UNICODE)
 	wchar_t tmp[MAX_UIMSG];
 	wchar_t defW[MAX_UIMSG];
@@ -63,7 +63,8 @@
 	r = UTF8ToWideChar(def, -1, defW, _countof(defW));
 	assert(r != 0);
 	GetI18nStrW(section, key, tmp, _countof(tmp), defW, iniFile);
-	r = WideCharToUTF8(tmp, -1, buf, buf_len);
+	r = buf_len;
+	WideCharToUTF8(tmp, NULL, buf, &r);
 	assert(r != 0);
 #else
 	// ANSI -> Wide -> utf8
@@ -72,7 +73,8 @@
 	GetI18nStr(section, key, strA, _countof(strA), def, iniFile);
 	r = MultiByteToWideChar(CP_ACP, 0, strA, -1, strW, _countof(strW));
 	assert(r != 0);
-	r = WideCharToUTF8(strW, -1, buf, buf_len);
+	r = buf_len;
+	WideCharToUTF8(strW, NULL, buf, &r);
 	assert(r != 0);
 #endif
 }

Modified: branches/cmake/teraterm/common/ttcommon.h
===================================================================
--- branches/cmake/teraterm/common/ttcommon.h	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/common/ttcommon.h	2019-03-10 14:32:59 UTC (rev 7471)
@@ -90,8 +90,10 @@
 DllExport int WINAPI CommBinaryOut(PComVar cv, PCHAR B, int C);
 DllExport int WINAPI CommBinaryBuffOut(PComVar cv, PCHAR B, int C);
 DllExport int WINAPI CommTextOut(PComVar cv, PCHAR B, int C);
+DllExport int WINAPI CommTextOutW(PComVar cv, const wchar_t *B, int C);
 DllExport int WINAPI CommBinaryEcho(PComVar cv, PCHAR B, int C);
 DllExport int WINAPI CommTextEcho(PComVar cv, PCHAR B, int C);
+DllExport int WINAPI CommTextEchoW(PComVar cv, const wchar_t *B, int C);
 
 DllExport void WINAPI CreateNotifyIcon(PComVar cv);
 DllExport void WINAPI DeleteNotifyIcon(PComVar cv);

Modified: branches/cmake/teraterm/teraterm/vtdisp.c
===================================================================
--- branches/cmake/teraterm/teraterm/vtdisp.c	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/teraterm/vtdisp.c	2019-03-10 14:32:59 UTC (rev 7471)
@@ -1958,7 +1958,7 @@
   VTFont[0] = CreateFontIndirect(&VTlf);
 
   /* set IME font */
-  SetConversionLogFont(&VTlf);
+  SetConversionLogFont(HVTWin, &VTlf);
 
   SelectObject(TmpDC, VTFont[0]);
   GetTextMetrics(TmpDC, &Metrics);
@@ -2039,7 +2039,7 @@
 			if (ts.IMEInline>0) {
 				LOGFONTA VTlf;
 				SetLogFont(&VTlf);
-				SetConversionLogFont(&VTlf);
+				SetConversionLogFont(HVTWin, &VTlf);
 			}
 			else
 				SetConversionWindow(HVTWin,-1,0);

Modified: branches/cmake/teraterm/teraterm/vtterm.c
===================================================================
--- branches/cmake/teraterm/teraterm/vtterm.c	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/teraterm/vtterm.c	2019-03-10 14:32:59 UTC (rev 7471)
@@ -5414,13 +5414,6 @@
 }
 
 //
-// UTF-8
-//
-#include "uni2sjis.map"
-#include "unisym2decsp.map"
-
-
-//
 // Unicode Combining Character Support
 //
 #include "uni_combining.map"
@@ -5473,10 +5466,9 @@
 	return (index);
 }
 
-// unicode(UTF-16,wchar_t)\x82\xF0\x83o\x83b\x83t\x83@\x82֏\x91\x82\xAB\x8D\x9E\x82\xDE
+// unicode(UTF-32,wchar_t)\x82\xF0\x83o\x83b\x83t\x83@\x82֏\x91\x82\xAB\x8D\x9E\x82\xDE
 static void UnicodeToCP932(unsigned int code)
 {
-	wchar_t wchar = (wchar_t)code;
 	int ret;
 	char mbchar[2];
 	unsigned short cset;
@@ -5483,7 +5475,7 @@
 
 	// Unicode\x82\xA9\x82\xE7DEC\x93\xC1\x8Eꕶ\x8E\x9A\x82ւ̃}\x83b\x83s\x83\x93\x83O
 	if (ts.UnicodeDecSpMapping) {
-		cset = ConvertUnicode(wchar, mapUnicodeSymbolToDecSp, MAPSIZE(mapUnicodeSymbolToDecSp));
+		cset = UTF32ToDecSp(code);
 		if (((cset >> 8) & ts.UnicodeDecSpMapping) != 0) {
 			PutDecSp(cset & 0xff);
 			return;
@@ -5491,20 +5483,19 @@
 	}
 
 	// Unicode -> \x93\xE0\x95\x94\x83R\x81[\x83h(ts.CodePage)\x82֕ϊ\xB7\x82\xB5\x82ďo\x97\xCD
-	ret = WideCharToMultiByte(ts.CodePage, 0, &wchar, 1, mbchar, 2, NULL, NULL);
+	if (ts.CodePage == 932) {
+		ret = (int)UTF32ToCP932(code, mbchar, 2);
+	} else {
+		if (code >= 0x10000) {
+			goto unknown;
+		}
+		wchar_t wchar;
+		wchar = (wchar_t)code;
+		ret = WideCharToMultiByte(ts.CodePage, 0, &wchar, 1, mbchar, 2, NULL, NULL);
+	}
 	switch (ret) {
 	case 0:
-		if (ts.CodePage == 932) {
-			// CP932
-			// U+301C\x82Ȃǂ͕ϊ\xB7\x82ł\xAB\x82Ȃ\xA2\x81BUnicode -> Shift_JIS\x82֕ϊ\xB7\x82\xB5\x82Ă݂\xE9\x81B
-			cset = ConvertUnicode(code, mapUnicodeToSJIS, MAPSIZE(mapUnicodeToSJIS));
-			if (cset != 0) {
-				Kanji = cset & 0xff00;
-				PutKanji(cset & 0x00ff);
-				return;
-			}
-		}
-
+	unknown:
 		PutChar('?');
 		if (ts.UnknownUnicodeCharaAsWide) {
 			PutChar('?');

Modified: branches/cmake/teraterm/teraterm/vtwin.cpp
===================================================================
--- branches/cmake/teraterm/teraterm/vtwin.cpp	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/teraterm/vtwin.cpp	2019-03-10 14:32:59 UTC (rev 7471)
@@ -3097,7 +3097,6 @@
 }
 //-->
 
-
 LRESULT CVTWindow::OnIMEStartComposition(WPARAM wParam, LPARAM lParam)
 {
 	// \x88ʒu\x82\xF0\x92ʒm\x82\xB7\x82\xE9
@@ -3110,58 +3109,29 @@
 
 LRESULT CVTWindow::OnIMEComposition(WPARAM wParam, LPARAM lParam)
 {
-	HGLOBAL hstr;
-	//LPSTR lpstr;
-	wchar_t *lpstr;
-	int Len;
-	char *mbstr;
-	int mlen;
-
 	if (CanUseIME()) {
-		hstr = GetConvString(wParam, lParam);
-	}
-	else {
-		hstr = NULL;
-	}
-
-	if (hstr!=NULL) {
-		//lpstr = (LPSTR)GlobalLock(hstr);
-		lpstr = (wchar_t *)GlobalLock(hstr);
-		if (lpstr!=NULL) {
-			mlen = wcstombs(NULL, lpstr, 0);
-			mbstr = (char *)malloc(sizeof(char) * (mlen + 1));
-			if (mbstr == NULL) {
-				goto skip;
-			}
-			Len = wcstombs(mbstr, lpstr, mlen + 1);
-
-			// add this string into text buffer of application
-			Len = strlen(mbstr);
-			if (Len==1) {
-				switch (mbstr[0]) {
+		size_t len;
+		const wchar_t *lpstr = GetConvString(HVTWin, wParam, lParam, &len);
+		if (lpstr != NULL) {
+			if (len == 1 && ControlKey()) {
+				const static wchar_t code_ctrl_space = 0;
+				const static wchar_t code_ctrl_backslash = 0x1c;
+				switch(*lpstr) {
 				case 0x20:
-					if (ControlKey()) {
-						mbstr[0] = 0; /* Ctrl-Space */
-					}
+					lpstr = &code_ctrl_space;
 					break;
 				case 0x5c: // Ctrl-\ support for NEC-PC98
-					if (ControlKey()) {
-						mbstr[0] = 0x1c;
-					}
+					lpstr = &code_ctrl_backslash;
 					break;
 				}
 			}
 			if (ts.LocalEcho>0) {
-				CommTextEcho(&cv,mbstr,Len);
+				CommTextEchoW(&cv,lpstr,len);
 			}
-			CommTextOut(&cv,mbstr,Len);
-
-			free(mbstr);
-			GlobalUnlock(hstr);
+			CommTextOutW(&cv,lpstr,len);
+			free((void *)lpstr);
+			return 0;
 		}
-skip:
-		GlobalFree(hstr);
-		return 0;
 	}
 	return CFrameWnd::DefWindowProc(WM_IME_COMPOSITION,wParam,lParam);
 }
@@ -6229,6 +6199,9 @@
 		OnDeviceChange((UINT)wp, (DWORD_PTR)lp);
 		DefWindowProc(msg, wp, lp);
 		break;
+	case WM_IME_STARTCOMPOSITION :
+		OnIMEStartComposition(wp, lp);
+		break;
 	case WM_IME_COMPOSITION:
 		OnIMEComposition(wp, lp);
 		break;

Modified: branches/cmake/teraterm/ttpcmn/language.c
===================================================================
--- branches/cmake/teraterm/ttpcmn/language.c	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/ttpcmn/language.c	2019-03-10 14:32:59 UTC (rev 7471)
@@ -36,10 +36,9 @@
 #include "tttypes.h"
 #include <mbstring.h>
 #include <locale.h>
+#include "codemap.h"
 
 #include "language.h"
-#include "codeconv.h"
-#include "sjis2uni.map"
 
 #if !defined(DllExport)
 #if defined(TTPCMN)
@@ -75,69 +74,6 @@
 	return (result);
 }
 
-// \x93\xE0\x95\x94\x83R\x81[\x83h(CodePage)\x82\xF0UTF8\x82֕ϊ\xB7\x82\xB7\x82\xE9
-DllExport unsigned int WINAPI SJIS2UTF8(WORD KCode, int *byte, int CodePage)
-{
-	wchar_t wchar;
-	int ret;
-	unsigned int code;
-	unsigned int c, c1, c2, c3;
-	unsigned char buf[3];
-	unsigned char KCode_h;
-	int len = 0;
-
-	// \x93\xE0\x95\x94\x83R\x81[\x83h(CodePage)\x82\xA9\x82\xE7UTF-16LE\x82֕ϊ\xB7\x82\xB7\x82\xE9
-	KCode_h = (unsigned char)(KCode >> 8);
-	if (KCode_h != 0) {
-		buf[len++] = KCode_h;
-	}
-	buf[len++] = KCode & 0xff;
-	ret = MultiByteToWideChar(CodePage, MB_ERR_INVALID_CHARS, buf, len, &wchar, 1);
-	if (ret <= 0) {
-		// \x95ϊ\xB7\x8E\xB8\x94s
-		unsigned short cset = 0;
-		if (CodePage == 932) {
-			// CP932
-			cset = ConvertUnicode(KCode, mapSJISToUnicode, sizeof(mapSJISToUnicode)/sizeof(mapSJISToUnicode[0]));
-		}
-		if (cset == 0) {
-			c = 0xfffd; // U+FFFD: Replacement Character
-		} else {
-			c = cset;
-		}
-	} else {
-		c = (unsigned int)wchar;
-	}
-
-	// UTF-16LE\x82\xA9\x82\xE7UTF-8\x82֕ϊ\xB7\x82\xB7\x82\xE9
-	if (c <= 0x0000007f) {
-		// 0x00000000 <= c <= 0x0000007f
-		code = (c & 0xff);
-		*byte = 1;
-
-	} else if (c <= 0x000007ff) {
-		// 0x00000080 <= c <= 0x000007ff
-		c1 = ((c >> 6) & 0x1f) | 0xc0;
-		c2 = (c & 0x3f) | 0x80;
-		code = (c1 << 8) | c2;
-		*byte = 2;
-
-	} else if (c <= 0x0000ffff) {
-		// 0x00000800 <= c <= 0x0000ffff
-		c1 = ((c >> 12) & 0xf) | 0xe0;
-		c2 = ((c >> 6) & 0x3f) | 0x80;
-		c3 = ((c) & 0x3f) | 0x80;
-		code = (c1 << 16) | (c2 << 8) | c3;
-		*byte = 3;
-	} else {
-		code = KCode;
-		*byte = 2;
-	}
-
-	return (code);
-}
-
-
 // Japanese SJIS -> JIS
 DllExport WORD WINAPI SJIS2JIS(WORD KCode)
 {

Modified: branches/cmake/teraterm/ttpcmn/language.h
===================================================================
--- branches/cmake/teraterm/ttpcmn/language.h	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/ttpcmn/language.h	2019-03-10 14:32:59 UTC (rev 7471)
@@ -32,7 +32,6 @@
 #pragma once
 
 #include <windows.h>	// for WINAPI
-#include "codemap.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -43,13 +42,11 @@
 #endif
 
 /* proto types */
-DllExport unsigned int WINAPI SJIS2UTF8(WORD KCode, int *byte, int CodePage);
 DllExport WORD WINAPI SJIS2JIS(WORD KCode);
 DllExport WORD WINAPI SJIS2EUC(WORD KCode);
 DllExport WORD WINAPI JIS2SJIS(WORD KCode);
 DllExport BYTE WINAPI RussConv(int cin, int cout, BYTE b);
 DllExport void WINAPI RussConvStr(int cin, int cout, PCHAR Str, int count);
-DllExport unsigned short ConvertUnicode(unsigned short code, const codemap_t *table, int tmax);
 
 #ifdef __cplusplus
 }

Modified: branches/cmake/teraterm/ttpcmn/ttcmn.c
===================================================================
--- branches/cmake/teraterm/ttpcmn/ttcmn.c	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/ttpcmn/ttcmn.c	2019-03-10 14:32:59 UTC (rev 7471)
@@ -40,6 +40,7 @@
 #include <setupapi.h>
 #include <locale.h>
 #include <htmlhelp.h>
+#include <assert.h>
 
 #define DllExport __declspec(dllexport) 
 #include "language.h"
@@ -1587,31 +1588,26 @@
 	return i;
 }
 
+// \x93\xE0\x95\x94\x83R\x81[\x83h(CodePage)\x82\xF0UTF-8\x82֏o\x97͂\xB7\x82\xE9
 static int OutputTextUTF8(WORD K, char *TempStr, PComVar cv)
 {
+	int CodePage = *cv->CodePage;
 	unsigned int code;
 	int outlen;
-	int TempLen = 0;
 
-	code = SJIS2UTF8(K, &outlen, *cv->CodePage);
-	switch (outlen) {
-	  case 4:
-		TempStr[TempLen++] = (code >> 24) & 0xff;
-	  case 3:
-		TempStr[TempLen++] = (code >> 16) & 0xff;
-	  case 2:
-		TempStr[TempLen++] = (code >> 8) & 0xff;
-	  case 1:
-		TempStr[TempLen++] = code & 0xff;
+	code = MBCP_UTF32(K, CodePage);
+	if (code == 0) {
+		// \x95ϊ\xB7\x8E\xB8\x94s
+		code = 0xfffd; // U+FFFD: Replacement Character
 	}
-
-	return TempLen;
+	outlen = UTF32ToUTF8(code, TempStr, 4);
+	return outlen;
 }
 
 //
 // MBCS\x82\xA9\x82\xE7\x8Ae\x8E튿\x8E\x9A\x83R\x81[\x83h\x82֕ϊ\xB7\x82\xB5\x82ďo\x97͂\xB7\x82\xE9\x81B
 //
-int TextOutMBCS(PComVar cv, PCHAR B, int C)
+static int TextOutMBCS(PComVar cv, PCHAR B, int C)
 {
 	int i, TempLen, OutLen;
 	WORD K;
@@ -1928,6 +1924,42 @@
 	return i;
 }
 
+/**
+ * CommTextOut() \x82\xCC wchar_t \x94\xC5
+ * \x8D\xA1\x82̏\x8AIME\x82\xA9\x82炵\x82\xA9\x8Eg\x82\xC1\x82Ă\xA2\x82Ȃ\xA2\x82\xBD\x82\xDF
+ * \x90\xA7\x8C\xE4\x83R\x81[\x83h\x8Cn\x82͖\xA2\x83e\x83X\x83g
+ */
+int WINAPI CommTextOutW(PComVar cv, const wchar_t *B, int C)
+{
+	int CodePage = *cv->CodePage;
+	size_t mb_len;
+	int r;
+	char *mb_str = _WideCharToMultiByte(B, C, CodePage, &mb_len);
+	if (mb_str == NULL) {
+		r = 0;
+	} else {
+		r = CommTextOut(cv, mb_str, mb_len);
+		free(mb_str);
+	}
+	return r;
+}
+
+// TODO: UTF-16\x82\xA9\x82璼\x90ڕϊ\xB7\x82\xB5\x82ďo\x97͂\xB7\x82\xE9
+int WINAPI CommTextEchoW(PComVar cv, const wchar_t *B, int C)
+{
+	int CodePage = *cv->CodePage;
+	size_t mb_len;
+	int r;
+	char *mb_str = _WideCharToMultiByte(B, C, CodePage, &mb_len);
+	if (mb_str == NULL) {
+		r = 0;
+	} else {
+		r = CommTextEcho(cv, mb_str, mb_len);
+		free(mb_str);
+	}
+	return r;
+}
+
 int WINAPI CommBinaryEcho(PComVar cv, PCHAR B, int C)
 {
 	int a, i, Len;
@@ -1972,7 +2004,7 @@
 	return i;
 }
 
-int WINAPI TextEchoMBCS(PComVar cv, PCHAR B, int C)
+static int WINAPI TextEchoMBCS(PComVar cv, PCHAR B, int C)
 {
 	int i, TempLen;
 	WORD K;

Modified: branches/cmake/teraterm/ttpmacro/ttl_gui.cpp
===================================================================
--- branches/cmake/teraterm/ttpmacro/ttl_gui.cpp	2019-03-10 14:32:45 UTC (rev 7470)
+++ branches/cmake/teraterm/ttpmacro/ttl_gui.cpp	2019-03-10 14:32:59 UTC (rev 7471)
@@ -528,9 +528,9 @@
 	{
 #if defined(UNICODE)
 		TCHAR input_string[MaxStrLen];
+		size_t Temp2_len = sizeof(Temp2);
 		OpenInpDlg(input_string, tc::fromUtf8(Str2), _T("Enter password"), _T(""), TRUE);
-		WideCharToUTF8(input_string, -1,
-					   Temp2, _countof(Temp2));
+		WideCharToUTF8(input_string, NULL, Temp2, &Temp2_len);
 #else
 		OpenInpDlg(Temp2, Str2, _T("Enter password"), _T(""), TRUE);
 #endif
@@ -599,8 +599,8 @@
 		TCHAR input_string[MaxStrLen];
 		OpenInpDlg(input_string,tc::fromUtf8(Str1),tc::fromUtf8(Str2),tc::fromUtf8(Str3),Paswd);
 		char *output = StrVarPtr(VarId);
-		WideCharToUTF8(input_string, -1,
-					   output, MaxStrLen);
+		size_t str_len = MaxStrLen;
+		WideCharToUTF8(input_string, NULL, output, &str_len);
 #else
 		OpenInpDlg(StrVarPtr(VarId),Str1,Str2,Str3,Paswd);
 #endif


Ttssh2-commit メーリングリストの案内