[Ttssh2-commit] [7406] language.c SJIS2UTF8()の仕様変更

scmno****@osdn***** scmno****@osdn*****
2019年 1月 25日 (金) 21:37:52 JST


Revision: 7406
          http://sourceforge.jp/projects/ttssh2/scm/svn/commits/7406
Author:   zmatsuo
Date:     2019-01-25 21:37:51 +0900 (Fri, 25 Jan 2019)
Log Message:
-----------
language.c SJIS2UTF8()の仕様変更
- locale文字列ではなく、コードページを使うようにした
- 内部コードに合わせて変換するようにした(CP932決め打ちだった)
- ConvertUnicode()のプロトタイプをlanguage.hに入れた

Modified Paths:
--------------
    trunk/teraterm/common/codeconv.cpp
    trunk/teraterm/teraterm/vtterm.c
    trunk/teraterm/ttpcmn/language.c
    trunk/teraterm/ttpcmn/language.h
    trunk/teraterm/ttpcmn/ttcmn.c

-------------- next part --------------
Modified: trunk/teraterm/common/codeconv.cpp
===================================================================
--- trunk/teraterm/common/codeconv.cpp	2019-01-25 12:37:39 UTC (rev 7405)
+++ trunk/teraterm/common/codeconv.cpp	2019-01-25 12:37:51 UTC (rev 7406)
@@ -90,7 +90,7 @@
  *	\x83}\x83\x8B\x83`\x83o\x83C\x83g\x95\xB6\x8E\x9A\x97\xF1\x82\xF0wchar_t\x95\xB6\x8E\x9A\x97\xF1\x82֕ϊ\xB7
  *	@param[in]	*str_ptr	mb(char)\x95\xB6\x8E\x9A\x97\xF1
  *	@param[in]	str_len		mb(char)\x95\xB6\x8E\x9A\x97\xF1\x92\xB7(0\x82̂Ƃ\xAB\x8E\xA9\x93\xAE)
- *	@param[in]	code_page	\x95ϊ\xB7\x90\xE6\x83R\x81[\x83h\x83y\x81[\x83W
+ *	@param[in]	code_page	\x95ϊ\xB7\x8C\xB3\x83R\x81[\x83h\x83y\x81[\x83W
  *	@param[out]	*w_len_		wchar_t\x95\xB6\x8E\x9A\x97\xF1\x92\xB7
  *	@retval		mb\x95\xB6\x8E\x9A\x97\xF1\x82ւ̃|\x83C\x83\x93\x83^(NULL\x82̎\x9E\x95ϊ\xB7\x83G\x83\x89\x81[)
  */

Modified: trunk/teraterm/teraterm/vtterm.c
===================================================================
--- trunk/teraterm/teraterm/vtterm.c	2019-01-25 12:37:39 UTC (rev 7405)
+++ trunk/teraterm/teraterm/vtterm.c	2019-01-25 12:37:51 UTC (rev 7406)
@@ -5414,7 +5414,6 @@
 //
 #include "uni2sjis.map"
 #include "unisym2decsp.map"
-extern unsigned short ConvertUnicode(unsigned short code, codemap_t *table, int tmax);
 
 
 //

Modified: trunk/teraterm/ttpcmn/language.c
===================================================================
--- trunk/teraterm/ttpcmn/language.c	2019-01-25 12:37:39 UTC (rev 7405)
+++ trunk/teraterm/ttpcmn/language.c	2019-01-25 12:37:51 UTC (rev 7406)
@@ -34,6 +34,7 @@
 #include <mbstring.h>
 #include <locale.h>
 
+#include "language.h"
 #include "codeconv.h"
 #include "sjis2uni.map"
 
@@ -63,29 +64,29 @@
 	return (result);
 }
 
-unsigned int PASCAL SJIS2UTF8(WORD KCode, int *byte, char *locale)
+// \x93\xE0\x95\x94\x83R\x81[\x83h(CodePage)\x82\xF0UTF8\x82֕ϊ\xB7\x82\xB7\x82\xE9
+unsigned int PASCAL SJIS2UTF8(WORD KCode, int *byte, int CodePage)
 {
 	wchar_t wchar;
 	int ret;
-	unsigned int code = KCode;
+	unsigned int code;
 	unsigned int c, c1, c2, c3;
-	unsigned char *ptr, buf[3];
-	unsigned short cset;
+	unsigned char buf[3];
 	unsigned char KCode_h;
 	int len = 0;
 
-	*byte = 2;
-
-	// CP932\x82\xA9\x82\xE7UTF-16LE\x82֕ϊ\xB7\x82\xB7\x82\xE9
+	// \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 = CP932ToWideChar(buf, len, &wchar, 1);
-	if (ret <= 0) { // \x95ϊ\xB7\x8E\xB8\x94s
-		cset = 0;
-		if (_stricmp(locale, DEFAULT_LOCALE) == 0) {
+	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) {
@@ -94,27 +95,32 @@
 			c = cset;
 		}
 	} else {
-		ptr = (unsigned char *)&wchar;
-		c = ((ptr[1] << 8) | ptr[0]);
+		c = (unsigned int)wchar;
 	}
 
 	// UTF-16LE\x82\xA9\x82\xE7UTF-8\x82֕ϊ\xB7\x82\xB7\x82\xE9
-	if (0x00000000 <= c && c <= 0x0000007f) {
+	if (c <= 0x0000007f) {
+		// 0x00000000 <= c <= 0x0000007f
 		code = (c & 0xff);
 		*byte = 1;
 
-	} else if (0x00000080 <= c && c <= 0x000007ff) {
+	} else if (c <= 0x000007ff) {
+		// 0x00000080 <= c <= 0x000007ff
 		c1 = ((c >> 6) & 0x1f) | 0xc0;
 		c2 = (c & 0x3f) | 0x80;
 		code = (c1 << 8) | c2;
 		*byte = 2;
 
-	} else if (0x00000800 <= c && c <= 0x0000ffff) {
+	} 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);

Modified: trunk/teraterm/ttpcmn/language.h
===================================================================
--- trunk/teraterm/ttpcmn/language.h	2019-01-25 12:37:39 UTC (rev 7405)
+++ trunk/teraterm/ttpcmn/language.h	2019-01-25 12:37:51 UTC (rev 7406)
@@ -29,18 +29,19 @@
 
 /* TTCMN.DLL, character code conversion */
 
+#include "codemap.h"
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 /* proto types */
-unsigned int PASCAL SJIS2UTF8(WORD KCode, int *byte, char *locale);
+unsigned int PASCAL SJIS2UTF8(WORD KCode, int *byte, int CodePage);
 WORD PASCAL SJIS2JIS(WORD KCode);
 WORD PASCAL SJIS2EUC(WORD KCode);
 WORD PASCAL JIS2SJIS(WORD KCode);
 BYTE PASCAL RussConv(int cin, int cout, BYTE b);
-void PASCAL RussConvStr
-  (int cin, int cout, PCHAR Str, int count);
+void PASCAL RussConvStr(int cin, int cout, PCHAR Str, int count);
+unsigned short ConvertUnicode(unsigned short code, codemap_t *table, int tmax);
 
 #ifdef __cplusplus
 }

Modified: trunk/teraterm/ttpcmn/ttcmn.c
===================================================================
--- trunk/teraterm/ttpcmn/ttcmn.c	2019-01-25 12:37:39 UTC (rev 7405)
+++ trunk/teraterm/ttpcmn/ttcmn.c	2019-01-25 12:37:51 UTC (rev 7406)
@@ -1553,7 +1553,7 @@
 	int outlen;
 	int TempLen = 0;
 
-	code = SJIS2UTF8(K, &outlen, cv->Locale);
+	code = SJIS2UTF8(K, &outlen, *cv->CodePage);
 	switch (outlen) {
 	  case 4:
 		TempStr[TempLen++] = (code >> 24) & 0xff;


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