[Ttssh2-commit] [7464] UTF32ToMBCP(), MBCPToUTF32()を使用するよう調整

scmno****@osdn***** scmno****@osdn*****
2019年 3月 10日 (日) 02:33:06 JST


Revision: 7464
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7464
Author:   zmatsuo
Date:     2019-03-10 02:33:06 +0900 (Sun, 10 Mar 2019)
Log Message:
-----------
UTF32ToMBCP(), MBCPToUTF32()を使用するよう調整

Modified Paths:
--------------
    trunk/teraterm/teraterm/vtterm.c
    trunk/teraterm/ttpcmn/ttcmn.c

-------------- next part --------------
Modified: trunk/teraterm/teraterm/vtterm.c
===================================================================
--- trunk/teraterm/teraterm/vtterm.c	2019-03-09 17:32:55 UTC (rev 7463)
+++ trunk/teraterm/teraterm/vtterm.c	2019-03-09 17:33:06 UTC (rev 7464)
@@ -5461,22 +5461,16 @@
 	return (index);
 }
 
-// unicode(UTF-32,wchar_t)\x82\xF0\x83o\x83b\x83t\x83@\x82֏\x91\x82\xAB\x8D\x9E\x82\xDE
+// unicode(UTF-32)\x82\xF0\x83o\x83b\x83t\x83@(t.CodePage)\x82֏\x91\x82\xAB\x8D\x9E\x82\xDE
 static void UnicodeToCP932(unsigned int code)
 {
-	wchar_t wchar;
-	int ret;
+	size_t mblen;
 	char mbchar[2];
-	unsigned short cset;
 
-	if (code >= 0x10000) {
-		goto unknown;
-	}
-	wchar = (wchar_t)code;
-
 	// Unicode\x82\xA9\x82\xE7DEC\x93\xC1\x8Eꕶ\x8E\x9A\x82ւ̃}\x83b\x83s\x83\x93\x83O
 	if (ts.UnicodeDecSpMapping) {
-		cset = UTF32ToDecSp(wchar);
+		unsigned short cset;
+		cset = UTF32ToDecSp(code);
 		if (((cset >> 8) & ts.UnicodeDecSpMapping) != 0) {
 			PutDecSp(cset & 0xff);
 			return;
@@ -5484,31 +5478,18 @@
 	}
 
 	// Unicode -> \x93\xE0\x95\x94\x83R\x81[\x83h(ts.CodePage)\x82֕ϊ\xB7\x82\xB5\x82ďo\x97\xCD
-	if (ts.CodePage == 932) {
-		ret = (int)UTF16ToCP932(&wchar, 1, &cset);
-		if (ret == 0) {
-			// \x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD
-			;
-		} else if (cset < 0x100) {
-			// 1byte\x95\xB6\x8E\x9A
-			mbchar[0] = (char)cset;
-			ret = 1;
-		} else {
-			// 2byte\x95\xB6\x8E\x9A
-			mbchar[0] = (char)(cset >> 8);
-			mbchar[1] = (char)(cset & 0xff);
-			ret = 2;
-		}
-	} else {
-		ret = WideCharToMultiByte(ts.CodePage, 0, &wchar, 1, mbchar, 2, NULL, NULL);
+	mblen = UTF32ToMBCP(code, ts.CodePage, mbchar, 2);
+#if 1	// U+203e OVERLINE \x93\xC1\x95ʏ\x88\x97\x9D
+	if (code == 0x203e && ts.CodePage == 932) {
+		// U+203e\x82\xCD0x7e'~'\x82ɕϊ\xB7\x82\xB3\x82\xEA\x82\xE9
+		// \x96\xB3\x97\x9D\x82\xE2\x82芿\x8E\x9A\x8Fo\x97͂\xB7\x82\xE9
+		mbchar[0] = 0;			// \x82\xB1\x82\xCC0\x82̂\xBD\x82߁A\x83N\x83\x8A\x83b\x83v\x83{\x81[\x83h\x82ɕ\xB6\x8E\x9A\x97񂪂\xA4\x82܂\xAD\x93\xFC\x82\xE7\x82Ȃ\xA2
+		mbchar[1] = 0x7e;
+		mblen = 2;
 	}
-	if (ret == 1 && mbchar[0] == '?' && code != '?') {
-		// \x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD\x82Ƃ\xAB\x81Aret=1, '?' \x82\xF0\x95Ԃ\xB5\x82Ă\xAD\x82\xE9
-		ret = 0;
-	}
-	switch (ret) {
+#endif
+	switch (mblen) {
 	case 0:
-	unknown:
 		PutChar('?');
 		if (ts.UnknownUnicodeCharaAsWide) {
 			PutChar('?');

Modified: trunk/teraterm/ttpcmn/ttcmn.c
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn.c	2019-03-09 17:32:55 UTC (rev 7463)
+++ trunk/teraterm/ttpcmn/ttcmn.c	2019-03-09 17:33:06 UTC (rev 7464)
@@ -1582,42 +1582,6 @@
 	return i;
 }
 
-// \x93\xE0\x95\x94\x83R\x81[\x83h(CodePage)\x82\xF0UTF-32(UTF-16LE)\x82֕ϊ\xB7\x82\xB7\x82\xE9
-static unsigned int SJIS2UTF32(WORD KCode, int CodePage)
-{
-	unsigned int c;
-
-	// \x93\xE0\x95\x94\x83R\x81[\x83h(CodePage)\x82\xA9\x82\xE7UTF-16LE\x82֕ϊ\xB7\x82\xB7\x82\xE9
-	if (CodePage == 932) {
-		c = CP932ToUTF32(KCode);
-	} else {
-		unsigned char buf[3];
-		wchar_t wchar;
-		int ret;
-		int len = 0;
-		if (KCode < 0x100) {
-			buf[0] = KCode & 0xff;
-			len = 1;
-		} else {
-			buf[0] = KCode >> 8;
-			buf[1] = KCode & 0xff;
-			len = 2;
-		}
-		ret = MultiByteToWideChar(CodePage, MB_ERR_INVALID_CHARS, buf, len, &wchar, 1);
-		if (ret <= 0) {
-			c = 0;
-		} else {
-			c = (unsigned int)wchar;
-		}
-	}
-	if (c <= 0) {
-		// \x95ϊ\xB7\x8E\xB8\x94s
-		c = 0xfffd; // U+FFFD: Replacement Character
-	}
-
-	return c;
-}
-
 // \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)
 {
@@ -1625,7 +1589,11 @@
 	unsigned int code;
 	int outlen;
 
-	code = SJIS2UTF32(K, CodePage);
+	code = MBCPToUTF32(K, CodePage);
+	if (code == 0) {
+		// \x95ϊ\xB7\x8E\xB8\x94s
+		code = 0xfffd; // U+FFFD: Replacement Character
+	}
 	outlen = UTF32ToUTF8(code, TempStr, 4);
 	return outlen;
 }


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