[Ttssh2-commit] [7465] 未使用関数削除、CP_ACP考慮

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


Revision: 7465
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7465
Author:   zmatsuo
Date:     2019-03-10 02:33:16 +0900 (Sun, 10 Mar 2019)
Log Message:
-----------
未使用関数削除、CP_ACP考慮

Modified Paths:
--------------
    trunk/teraterm/common/codeconv.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/codeconv.cpp
===================================================================
--- trunk/teraterm/common/codeconv.cpp	2019-03-09 17:33:06 UTC (rev 7464)
+++ trunk/teraterm/common/codeconv.cpp	2019-03-09 17:33:16 UTC (rev 7465)
@@ -94,39 +94,72 @@
 }
 
 /**
- *	1\x95\xB6\x8E\x9A\x82Ƃ\xB5\x82Ĉ\xB5\x82\xA4\x82\xBD\x82߂ɁA\x95K\x97v\x82ȃL\x83\x83\x83\x89\x83N\x83^\x90\x94\x82𓾂\xE9
- *	@retval	0	\x95\xB6\x8E\x9A\x82Ƃ\xB5\x82Ĉ\xB5\x82\xA6\x82Ȃ\xA2(\x95\xB6\x8E\x9A\x83R\x81[\x83h\x82\xAA\x82\xA8\x82\xA9\x82\xB5\x82\xA2)
- *	@retval	1	1\x83L\x83\x83\x83\x89\x83N\x83^\x82\xC51\x95\xB6\x8E\x9A\x82Ƃ\xB5\x82Ĉ\xB5\x82\xA6\x82\xE9
- *	@retval	2	2\x83L\x83\x83\x83\x89\x83N\x83^\x82\xC51\x95\xB6\x8E\x9A\x82Ƃ\xB5\x82Ĉ\xB5\x82\xA6\x82\xE9
+ * CP932\x95\xB6\x8E\x9A(Shift_JIS) 1\x95\xB6\x8E\x9A\x82\xA9\x82\xE7UTF-32\x82֕ϊ\xB7\x82\xB7\x82\xE9
+ * @param[in]		cp932		CP932\x95\xB6\x8E\x9A
+ * @retval			\x95ϊ\xB7\x82\xB5\x82\xBDUTF-32\x95\xB6\x8E\x9A\x90\x94
+ *					0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD)
  */
-#if 0
-static size_t UTF16GetCharCount(const wchar_t *wstr_ptr, size_t wstr_len)
+unsigned int CP932ToUTF32(unsigned short cp932)
 {
-	wchar_t u16;
-	assert(wstr_ptr != NULL);
-	if (wstr_len == 0) {
-		return 0;
+#include "../ttpcmn/sjis2uni.map"		// mapSJISToUnicode[]
+	wchar_t wchar;
+	int ret;
+	unsigned int u32;
+	unsigned char buf[2];
+	int len = 0;
+
+#if defined(PRIORITY_CP932_TABLE)
+	u32 = _ConvertUnicode(cp932, mapSJISToUnicode, sizeof(mapSJISToUnicode)/sizeof(mapSJISToUnicode[0]));
+	if (u32 != 0) {
+		return u32;
 	}
-	u16 = *wstr_ptr++;
-	if (IsHighSurrogate(u16)) {
-		if (wstr_len >= 2) {
-			const wchar_t u16_lo = *wstr_ptr++;
-			if (IsLowSurrogate(u16_lo)) {
-				return 2;
-			} else {
-				return 0;
-			}
-		} else {
-			return 0;
-		}
-	} else if (IsLowSurrogate(u16)) {
-		return 0;
+#endif
+	if (cp932 < 0x100) {
+		buf[0] = cp932 & 0xff;
+		len = 1;
+	} else {
+		buf[0] = cp932 >> 8;
+		buf[1] = cp932 & 0xff;
+		len = 2;
 	}
-	return 1;
-}
+	ret = MultiByteToWideChar(932, MB_ERR_INVALID_CHARS, (char *)buf, len, &wchar, 1);
+	if (ret <= 0) {
+		// MultiByteToWideChar()\x82\xAA\x95ϊ\xB7\x8E\xB8\x94s
+#if !defined(PRIORITY_CP932_TABLE)
+		u32 = _ConvertUnicode(cp932, mapSJISToUnicode, sizeof(mapSJISToUnicode)/sizeof(mapSJISToUnicode[0]));
+		// \x83e\x81[\x83u\x83\x8B\x82ɂ\xE0\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ c = 0(\x95ϊ\xB7\x8E\xB8\x94s\x8E\x9E)
+#else
+		u32 = 0;
 #endif
+	} else {
+		u32 = (unsigned int)wchar;
+	}
 
+	return u32;
+}
+
 /**
+ * Unicode\x82\xA9\x82\xE7DEC\x93\xC1\x8Eꕶ\x8E\x9A\x82֕ϊ\xB7
+ * @param	u32			UTF-32\x95\xB6\x8E\x9A\x83R\x81[\x83h
+ * @return	\x89\xBA\x88\xCA8bit	DEC\x93\xC1\x8Eꕶ\x8E\x9A\x83R\x81[\x83h
+ *			\x8F\xE3\x88\xCA8bit	\x95\xB6\x8E\x9A\x83R\x81[\x83h\x8E\xED\x95\xCA (1,2,4)
+ *						file://../../doc/ja/html/setup/teraterm-term.html \x8EQ\x8F\xC6
+ *			0			\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD
+ */
+unsigned short UTF32ToDecSp(unsigned int u32)
+{
+#include "../teraterm/unisym2decsp.map"		// mapUnicodeSymbolToDecSp[]
+	unsigned short cset;
+	if (u32 > 0x10000) {
+		cset = 0;
+	} else {
+		const unsigned short u16 = (unsigned short)u32;
+		cset = _ConvertUnicode(u16, mapUnicodeSymbolToDecSp, _countof(mapUnicodeSymbolToDecSp));
+	}
+	return cset;
+}
+
+/**
  *	code page \x82\xCC mulit byte \x95\xB6\x8E\x9A\x82\xF0 UTF-32\x82֕ϊ\xB7\x82\xB7\x82\xE9
  *	@param KCode	\x83}\x83\x8B\x83`\x83o\x83C\x83g\x82̕\xB6\x8E\x9A\x83R\x81[\x83h(0x0000-0xffff)
  *	@param CoePage	\x83}\x83\x8B\x83`\x83o\x83C\x83g\x82̃R\x81[\x83h\x83y\x81[\x83W
@@ -162,6 +195,158 @@
 }
 
 /**
+ * UTF-32\x95\xB6\x8E\x9A\x82\xF0CP932\x95\xB6\x8E\x9A(Shift_JIS) 1\x95\xB6\x8E\x9A\x82֕ϊ\xB7\x82\xB7\x82\xE9
+ * @retval		\x8Eg\x97p\x82\xB5\x82\xBDCP932\x95\xB6\x8E\x9A
+ *				0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD)
+ */
+unsigned short UTF32_CP932(unsigned int u32)
+{
+#include "../teraterm/uni2sjis.map"		// mapUnicodeToSJIS[]
+	char mbstr[2];
+	unsigned short mb;
+	DWORD mblen;
+	wchar_t u16_str[2];
+	size_t u16_len;
+
+	if (u32 < 0x80) {
+		return (unsigned short)u32;
+	}
+
+#if defined(PRIORITY_CP932_TABLE)
+	if (u32 < 0x10000) {
+		wchar_t u16 = (wchar_t)u32;
+		// Tera Term\x82̕ϊ\xB7\x83e\x81[\x83u\x83\x8B\x82\xC5 Unicode -> Shift_JIS\x82֕ϊ\xB7
+		mb = _ConvertUnicode(u16, mapUnicodeToSJIS, _countof(mapUnicodeToSJIS));
+		if (mb != 0) {
+			// \x95ϊ\xB7\x82ł\xAB\x82\xBD
+			return mb;
+		}
+	}
+#endif
+	u16_len = UTF32ToUTF16(u32, u16_str, 2);
+	if (u16_len == 0) {
+		return 0;
+	}
+	mblen = WideCharToMultiByte(932, 0, u16_str, (int)u16_len, mbstr, 2, NULL, NULL);
+	switch (mblen) {
+	case 0:
+	case 1:
+	default:
+		if (mblen == 0 || mbstr[0] == '?') {
+			goto next_convert;
+		} else {
+			mb = (unsigned char)mbstr[0];
+			return mb;
+		}
+	case 2:
+		if (mbstr[0] == '?' && mbstr[1] == '?') {
+			// 2byte\x8Fo\x97\xCD && "??" \x82̏ꍇ\x82͕ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD
+			goto next_convert;
+		}
+		mb = (((unsigned char)mbstr[0]) << 8) | (unsigned char)mbstr[1];
+		return mb;
+	}
+
+next_convert:
+#if !defined(PRIORITY_CP932_TABLE)
+	if (u32 < 0x10000) {
+		wchar_t u16 = (wchar_t)u32;
+		// Tera Term\x82̕ϊ\xB7\x83e\x81[\x83u\x83\x8B\x82\xC5 Unicode -> Shift_JIS\x82֕ϊ\xB7
+		mb = _ConvertUnicode(u16, mapUnicodeToSJIS, _countof(mapUnicodeToSJIS));
+		if (mb != 0) {
+			// \x95ϊ\xB7\x82ł\xAB\x82\xBD
+			return mb;
+		}
+	}
+#endif
+	return 0;
+}
+
+/**
+ * UTF-8\x95\xB6\x8E\x9A\x97񂩂\xE7UTF-32\x82\xF01\x95\xB6\x8E\x9A\x8E\xE6\x82\xE8\x8Fo\x82\xB7
+ * @param[in]	u8_ptr	UTF-8\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
+ * @param[in]	u8_len	UTF-8\x95\xB6\x8E\x9A\x97񒷂\xB3
+ * @param[out]	u32		\x95ϊ\xB7\x82\xB5\x82\xBDUTF-32\x95\xB6\x8E\x9A
+ * @retval		\x8Eg\x97p\x82\xB5\x82\xBDUTF-8\x95\xB6\x8E\x9A\x90\x94(byte\x90\x94\x81j
+ *				0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD)
+ */
+size_t UTF8ToUTF32(const char *u8_ptr_, size_t u8_len, uint32_t *u32_)
+{
+	uint8_t *u8_ptr = (uint8_t *)u8_ptr_;
+	uint32_t u32;
+	size_t u8_in;
+	const uint8_t c1 = *u8_ptr++;
+    if (c1 <= 0x7f) {
+		// 1byte
+		if (u8_len >= 1) {
+			u32 = (uint32_t)c1;
+			u8_in = 1;
+		} else {
+			goto error;
+		}
+	} else if (0xc2 <= c1 && c1 <= 0xdf) {
+		// 2byte
+		if (u8_len >= 2) {
+			const uint8_t c2 = *u8_ptr++;
+			if (((c1 & 0x1e) != 0) &&
+				((c2 & 0xc0) == 0x80))
+			{
+				u32 = (uint32_t)((c1 & 0x1f) << 6) + (c2 & 0x3f);
+				u8_in = 2;
+			} else {
+				goto error;
+			}
+		} else {
+			goto error;
+		}
+	} else if (0xe0 <= c1 && c1 <= 0xef) {
+		// 3byte
+		if (u8_len >= 3) {
+			const uint8_t c2 = *u8_ptr++;
+			const uint8_t c3 = *u8_ptr++;
+			if ((((c1 & 0x0f) != 0) || ((c2 & 0x20) != 0)) &&
+				((c2 & 0xc0) == 0x80) &&
+				((c3 & 0xc0) == 0x80) )
+			{
+				u32 = (uint32_t)((c1 & 0x0f) << 12) + ((c2 & 0x3f) << 6);
+				u32 += (c3 & 0x3f);
+				u8_in = 3;
+			} else {
+				goto error;
+			}
+		} else {
+			goto error;
+		}
+	} else if (0xf0 <= c1 && c1 <= 0xf7 && u8_len >= 4) {
+		// 4byte
+		if (u8_len >= 4) {
+			const uint8_t c2 = *u8_ptr++;
+			const uint8_t c3 = *u8_ptr++;
+			const uint8_t c4 = *u8_ptr++;
+			if ((((c1 & 0x07) != 0) || ((c2 & 0x30) != 0)) &&
+				((c2 & 0xc0) == 0x80) &&
+				((c3 & 0xc0) == 0x80) &&
+				((c4 & 0xc0) == 0x80) )
+			{
+				u32 = (uint32_t)((c1 & 0x07) << 18) + ((c2 & 0x3f) << 12);
+				u32 += ((c3 & 0x3f) << 6) + (c4 & 0x3f);
+				u8_in = 4;
+			} else {
+				goto error;
+			}
+		} else {
+			goto error;
+		}
+    } else {
+	error:
+		u32 = 0;
+		u8_in = 0;
+	}
+	*u32_ = u32;
+	return u8_in;
+}
+
+/**
  *	wchar_t\x95\xB6\x8E\x9A\x97񂩂\xE7unicode(UTF-32)\x82\xF01\x95\xB6\x8E\x9A\x8E\xE6\x82\xE8\x8Fo\x82\xB7
  *	@retval	0	\x95\xB6\x8E\x9A\x82Ƃ\xB5\x82Ĉ\xB5\x82\xA6\x82Ȃ\xA2(\x95\xB6\x8E\x9A\x83R\x81[\x83h\x82\xAA\x82\xA8\x82\xA9\x82\xB5\x82\xA2)
  *	@retval	1	1\x83L\x83\x83\x83\x89\x83N\x83^\x82\xC51\x95\xB6\x8E\x9A\x82Ƃ\xB5\x82Ĉ\xB5\x82\xA6\x82\xE9
@@ -261,90 +446,6 @@
 }
 
 /**
- * UTF-8\x95\xB6\x8E\x9A\x97񂩂\xE7UTF-32\x82\xF01\x95\xB6\x8E\x9A\x8E\xE6\x82\xE8\x8Fo\x82\xB7
- * @param[in]	u8_ptr	UTF-8\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^
- * @param[in]	u8_len	UTF-8\x95\xB6\x8E\x9A\x97񒷂\xB3
- * @param[out]	u32		\x95ϊ\xB7\x82\xB5\x82\xBDUTF-32\x95\xB6\x8E\x9A
- * @retval		\x8Eg\x97p\x82\xB5\x82\xBDUTF-8\x95\xB6\x8E\x9A\x90\x94(byte\x90\x94\x81j
- *				0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD)
- */
-size_t UTF8ToUTF32(const char *u8_ptr_, size_t u8_len, uint32_t *u32_)
-{
-	uint8_t *u8_ptr = (uint8_t *)u8_ptr_;
-	uint32_t u32;
-	size_t u8_in;
-	const uint8_t c1 = *u8_ptr++;
-    if (c1 <= 0x7f) {
-		// 1byte
-		if (u8_len >= 1) {
-			u32 = (uint32_t)c1;
-			u8_in = 1;
-		} else {
-			goto error;
-		}
-	} else if (0xc2 <= c1 && c1 <= 0xdf) {
-		// 2byte
-		if (u8_len >= 2) {
-			const uint8_t c2 = *u8_ptr++;
-			if (((c1 & 0x1e) != 0) &&
-				((c2 & 0xc0) == 0x80))
-			{
-				u32 = (uint32_t)((c1 & 0x1f) << 6) + (c2 & 0x3f);
-				u8_in = 2;
-			} else {
-				goto error;
-			}
-		} else {
-			goto error;
-		}
-	} else if (0xe0 <= c1 && c1 <= 0xef) {
-		// 3byte
-		if (u8_len >= 3) {
-			const uint8_t c2 = *u8_ptr++;
-			const uint8_t c3 = *u8_ptr++;
-			if ((((c1 & 0x0f) != 0) || ((c2 & 0x20) != 0)) &&
-				((c2 & 0xc0) == 0x80) &&
-				((c3 & 0xc0) == 0x80) )
-			{
-				u32 = (uint32_t)((c1 & 0x0f) << 12) + ((c2 & 0x3f) << 6);
-				u32 += (c3 & 0x3f);
-				u8_in = 3;
-			} else {
-				goto error;
-			}
-		} else {
-			goto error;
-		}
-	} else if (0xf0 <= c1 && c1 <= 0xf7 && u8_len >= 4) {
-		// 4byte
-		if (u8_len >= 4) {
-			const uint8_t c2 = *u8_ptr++;
-			const uint8_t c3 = *u8_ptr++;
-			const uint8_t c4 = *u8_ptr++;
-			if ((((c1 & 0x07) != 0) || ((c2 & 0x30) != 0)) &&
-				((c2 & 0xc0) == 0x80) &&
-				((c3 & 0xc0) == 0x80) &&
-				((c4 & 0xc0) == 0x80) )
-			{
-				u32 = (uint32_t)((c1 & 0x07) << 18) + ((c2 & 0x3f) << 12);
-				u32 += ((c3 & 0x3f) << 6) + (c4 & 0x3f);
-				u8_in = 4;
-			} else {
-				goto error;
-			}
-		} else {
-			goto error;
-		}
-    } else {
-	error:
-		u32 = 0;
-		u8_in = 0;
-	}
-	*u32_ = u32;
-	return u8_in;
-}
-
-/**
  * UTF-32 \x82\xA9\x82\xE7 UTF-16 \x82֕ϊ\xB7\x82\xB7\x82\xE9
  * @param[in]		u32			\x95ϊ\xB7\x82\xB7\x82\xE9UTF-32
  * @param[in,out]	wstr_ptr	\x95ϊ\xB7\x8C\xE3UTF-16\x95\xB6\x8E\x9A\x97\xF1\x8Fo\x97͐\xE6(NULL\x82̂Ƃ\xAB\x8Fo\x97͂\xB5\x82Ȃ\xA2)
@@ -382,140 +483,6 @@
 }
 
 /**
- * UTF-32\x95\xB6\x8E\x9A\x82\xF0CP932\x95\xB6\x8E\x9A(Shift_JIS) 1\x95\xB6\x8E\x9A\x82֕ϊ\xB7\x82\xB7\x82\xE9
- * @retval		\x8Eg\x97p\x82\xB5\x82\xBDCP932\x95\xB6\x8E\x9A
- *				0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD)
- */
-unsigned short UTF32_CP932(unsigned int u32)
-{
-#include "../teraterm/uni2sjis.map"		// mapUnicodeToSJIS[]
-	char mbstr[2];
-	unsigned short mb;
-	DWORD mblen;
-	wchar_t u16_str[2];
-	size_t u16_len;
-
-	if (u32 < 0x80) {
-		return (unsigned short)u32;
-	}
-
-#if defined(PRIORITY_CP932_TABLE)
-	if (u32 < 0x10000) {
-		wchar_t u16 = (wchar_t)u32;
-		// Tera Term\x82̕ϊ\xB7\x83e\x81[\x83u\x83\x8B\x82\xC5 Unicode -> Shift_JIS\x82֕ϊ\xB7
-		mb = _ConvertUnicode(u16, mapUnicodeToSJIS, _countof(mapUnicodeToSJIS));
-		if (mb != 0) {
-			// \x95ϊ\xB7\x82ł\xAB\x82\xBD
-			return mb;
-		}
-	}
-#endif
-	u16_len = UTF32ToUTF16(u32, u16_str, 2);
-	if (u16_len == 0) {
-		return 0;
-	}
-	mblen = WideCharToMultiByte(932, 0, u16_str, (int)u16_len, mbstr, 2, NULL, NULL);
-	switch (mblen) {
-	case 0:
-	case 1:
-	default:
-		if (mblen == 0 || mbstr[0] == '?') {
-			goto next_convert;
-		} else {
-			mb = (unsigned char)mbstr[0];
-			return mb;
-		}
-	case 2:
-		if (mbstr[0] == '?' && mbstr[1] == '?') {
-			// 2byte\x8Fo\x97\xCD && "??" \x82̏ꍇ\x82͕ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD
-			goto next_convert;
-		}
-		mb = (((unsigned char)mbstr[0]) << 8) | (unsigned char)mbstr[1];
-		return mb;
-	}
-
-next_convert:
-#if !defined(PRIORITY_CP932_TABLE)
-	if (u32 < 0x10000) {
-		wchar_t u16 = (wchar_t)u32;
-		// Tera Term\x82̕ϊ\xB7\x83e\x81[\x83u\x83\x8B\x82\xC5 Unicode -> Shift_JIS\x82֕ϊ\xB7
-		mb = _ConvertUnicode(u16, mapUnicodeToSJIS, _countof(mapUnicodeToSJIS));
-		if (mb != 0) {
-			// \x95ϊ\xB7\x82ł\xAB\x82\xBD
-			return mb;
-		}
-	}
-#endif
-	return 0;
-}
-
-/**
- * CP932\x95\xB6\x8E\x9A(Shift_JIS) 1\x95\xB6\x8E\x9A\x82\xA9\x82\xE7UTF-32\x82֕ϊ\xB7\x82\xB7\x82\xE9
- * @param[in]		cp932		CP932\x95\xB6\x8E\x9A
- * @retval			\x95ϊ\xB7\x82\xB5\x82\xBDUTF-32\x95\xB6\x8E\x9A\x90\x94
- *					0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD)
- */
-unsigned int CP932ToUTF32(unsigned short cp932)
-{
-#include "../ttpcmn/sjis2uni.map"		// mapSJISToUnicode[]
-	wchar_t wchar;
-	int ret;
-	unsigned int u32;
-	unsigned char buf[2];
-	int len = 0;
-
-#if defined(PRIORITY_CP932_TABLE)
-	u32 = _ConvertUnicode(cp932, mapSJISToUnicode, sizeof(mapSJISToUnicode)/sizeof(mapSJISToUnicode[0]));
-	if (u32 != 0) {
-		return u32;
-	}
-#endif
-	if (cp932 < 0x100) {
-		buf[0] = cp932 & 0xff;
-		len = 1;
-	} else {
-		buf[0] = cp932 >> 8;
-		buf[1] = cp932 & 0xff;
-		len = 2;
-	}
-	ret = MultiByteToWideChar(932, MB_ERR_INVALID_CHARS, (char *)buf, len, &wchar, 1);
-	if (ret <= 0) {
-		// MultiByteToWideChar()\x82\xAA\x95ϊ\xB7\x8E\xB8\x94s
-#if !defined(PRIORITY_CP932_TABLE)
-		u32 = _ConvertUnicode(cp932, mapSJISToUnicode, sizeof(mapSJISToUnicode)/sizeof(mapSJISToUnicode[0]));
-		// \x83e\x81[\x83u\x83\x8B\x82ɂ\xE0\x82Ȃ\xA9\x82\xC1\x82\xBD\x8Fꍇ c = 0(\x95ϊ\xB7\x8E\xB8\x94s\x8E\x9E)
-#else
-		u32 = 0;
-#endif
-	} else {
-		u32 = (unsigned int)wchar;
-	}
-
-	return u32;
-}
-
-/**
- * Unicode\x82\xA9\x82\xE7DEC\x93\xC1\x8Eꕶ\x8E\x9A\x82֕ϊ\xB7
- * @param	u32			UTF-32\x95\xB6\x8E\x9A\x83R\x81[\x83h
- * @return	\x89\xBA\x88\xCA8bit	DEC\x93\xC1\x8Eꕶ\x8E\x9A\x83R\x81[\x83h
- *			\x8F\xE3\x88\xCA8bit	\x95\xB6\x8E\x9A\x83R\x81[\x83h\x8E\xED\x95\xCA (1,2,4)
- *						file://../../doc/ja/html/setup/teraterm-term.html \x8EQ\x8F\xC6
- *			0			\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD
- */
-unsigned short UTF32ToDecSp(unsigned int u32)
-{
-#include "../teraterm/unisym2decsp.map"		// mapUnicodeSymbolToDecSp[]
-	unsigned short cset;
-	if (u32 > 0x10000) {
-		cset = 0;
-	} else {
-		const unsigned short u16 = (unsigned short)u32;
-		cset = _ConvertUnicode(u16, mapUnicodeSymbolToDecSp, _countof(mapUnicodeSymbolToDecSp));
-	}
-	return cset;
-}
-
-/**
  * UTF-32 \x82\xA9\x82\xE7 CP932 \x82֕ϊ\xB7\x82\xB7\x82\xE9
  * @param[in]		u32			\x95ϊ\xB7\x82\xB7\x82\xE9UTF-32
  * @param[in,out]	mb_ptr		\x95ϊ\xB7\x8C\xE3CP932\x95\xB6\x8E\x9A\x97\xF1\x8Fo\x97͐\xE6(NULL\x82̂Ƃ\xAB\x8Fo\x97͂\xB5\x82Ȃ\xA2)
@@ -556,8 +523,20 @@
 	return cp932_out;
 }
 
+/**
+ * UTF-32 \x82\xA9\x82\xE7 MultiByte\x95\xB6\x8E\x9A(code_page) \x82֕ϊ\xB7\x82\xB7\x82\xE9
+ * @param[in]		u32			\x95ϊ\xB7\x8C\xB3UTF-32
+ * @param[in]		code_page	\x95ϊ\xB7\x90\xE6codepage
+ * @param[in,out]	mb_ptr		\x95ϊ\xB7\x90敶\x8E\x9A\x97\xF1\x8Fo\x97͐\xE6(NULL\x82̂Ƃ\xAB\x8Fo\x97͂\xB5\x82Ȃ\xA2)
+ * @param[in]		mb_len		CP932\x8Fo\x97͐敶\x8E\x9A\x90\x94(\x95\xB6\x8E\x9A\x90\x94,sizeof(wchar_t)*wstr_len bytes)
+ * @retval			\x8Fo\x97͂\xB5\x82\xBDCP932\x95\xB6\x8E\x9A\x90\x94(byte\x90\x94)
+ *					0=\x83G\x83\x89\x81[(\x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD)
+ */
 size_t UTF32ToMBCP(unsigned int u32, int code_page, char *mb_ptr, size_t mb_len)
 {
+	if (code_page == CP_ACP) {
+		code_page = (int)GetACP();
+	}
 	if (code_page == 932) {
 		return UTF32ToCP932(u32, mb_ptr, mb_len);
 	} else {
@@ -568,7 +547,7 @@
 			return 0;
 		}
 		mb_len = WideCharToMultiByte(code_page, 0, u16_str, u16_len, mb_ptr, mb_len, NULL, NULL);
-		if (u32 != '?' && mb_len == 1 && mb_ptr[0] == '?') {
+		if (mb_ptr != NULL && u32 != '?' && mb_len == 1 && mb_ptr[0] == '?') {
 			// \x95ϊ\xB7\x82ł\xAB\x82Ȃ\xA9\x82\xC1\x82\xBD\x82Ƃ\xAB\x81A\x96߂\xE8\x92l=1, \x95\xB6\x8E\x9A[0]='?' \x82\xF0\x95Ԃ\xB5\x82Ă\xAD\x82\xE9
 			mb_len = 0;
 		}
@@ -577,7 +556,7 @@
 }
 
 /**
- *	wchar_t(UTF-16)\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83}\x83\x8B\x83`\x83o\x83C\x83g\x82ɕϊ\xB7\x82\xB7\x82\xE9
+ *	wchar_t(UTF-16)\x95\xB6\x8E\x9A\x97\xF1\x82\xF0\x83}\x83\x8B\x83`\x83o\x83C\x83g\x95\xB6\x8E\x9A\x97\xF1\x82ɕϊ\xB7\x82\xB7\x82\xE9
  *
  *	@param[in]		*wstr_ptr	wchar_t\x95\xB6\x8E\x9A\x97\xF1
  *	@param[in,out]	*wstr_len	wchar_t\x95\xB6\x8E\x9A\x97\xF1\x92\xB7
@@ -667,15 +646,16 @@
 
 void WideCharToCP932(const wchar_t *wstr_ptr, size_t *wstr_len, char *cp932_ptr, size_t *cp932_len)
 {
-	WideCharToMB(wstr_ptr, wstr_len,
-				 cp932_ptr, cp932_len,
-				 UTF32ToCP932);
+	WideCharToMB(wstr_ptr, wstr_len, cp932_ptr, cp932_len, UTF32ToCP932);
 }
 
 void WideCharToMBCP(const wchar_t *wstr_ptr, size_t *wstr_len, char *mb_ptr, size_t *mb_len,
-				  int code_page)
+					int code_page)
 {
 	size_t (*utf32_to_mb)(uint32_t u32, char *mb_ptr, size_t mb_len);
+	if (code_page == CP_ACP) {
+		code_page = (int)GetACP();
+	}
 	switch (code_page) {
 	case CP_UTF8:
 		utf32_to_mb = UTF32ToUTF8;
@@ -763,6 +743,9 @@
 {
 	const DWORD flags = 0;
 	char *mb_ptr;
+	if (code_page == CP_ACP) {
+		code_page = (int)GetACP();
+	}
 	if (mb_len_ != NULL) {
 		*mb_len_ = 0;
 	}
@@ -823,6 +806,9 @@
 wchar_t *_MultiByteToWideChar(const char *str_ptr, size_t str_len, int code_page, size_t *w_len_)
 {
 	DWORD flags = MB_ERR_INVALID_CHARS;
+	if (code_page == CP_ACP) {
+		code_page = (int)GetACP();
+	}
 	if (code_page == CP_UTF8) {
 		// CP_UTF8 When this is set, dwFlags must be zero.
 		flags = 0;


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