svnno****@sourc*****
svnno****@sourc*****
2010年 6月 7日 (月) 23:01:51 JST
Revision: 3926 http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=3926 Author: yutakapon Date: 2010-06-07 23:01:51 +0900 (Mon, 07 Jun 2010) Log Message: ----------- 以ä¸ã«ç¤ºã UTF-8 éä¿¡å¦çããç´ç²ãªUnicodeã¨ãã¦å¦çããããã«ããã ãã»IMEå ¥å ãã»ã¯ãªãããã¼ãã®è²¼ãä»ã teraterm.iniã« PureUTF8 ã¨ã³ããªã追å ãå½è©²å¦çã® on/off ãåãæ¿ããããã ããã©ã«ãã¯ã¾ã off ã¨ããã ããã«ãããSNOWMAN(U+2603)ãªã©ã®æåãéä¿¡ãã¦ããæ£ããUTF-8ã¨ã³ã³ã¼ãã£ã³ã°ã¨ãã¦ã ãµã¼ãã¸éä¿¡ãããã ãã ãããµãã²ã¼ããã¢ã«ã¯æªå¯¾å¿ã Modified Paths: -------------- trunk/installer/release/TERATERM.INI trunk/teraterm/common/tttypes.h trunk/teraterm/teraterm/clipboar.c trunk/teraterm/teraterm/commlib.c trunk/teraterm/teraterm/ttermpro.vcproj trunk/teraterm/teraterm/ttwinman.h trunk/teraterm/teraterm/vtwin.cpp trunk/teraterm/ttpcmn/language.c trunk/teraterm/ttpcmn/language.h trunk/teraterm/ttpcmn/ttcmn.c trunk/teraterm/ttpcmn/ttpcmn.def trunk/teraterm/ttpcmn/ttpcmn.vcproj trunk/teraterm/ttpset/ttset.c -------------- next part -------------- Modified: trunk/installer/release/TERATERM.INI =================================================================== --- trunk/installer/release/TERATERM.INI 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/installer/release/TERATERM.INI 2010-06-07 14:01:51 UTC (rev 3926) @@ -100,6 +100,9 @@ ; CodePage for Unicode CodePage= +; Pure UTF-8 encoding +PureUTF8=off + ; Background color of text uses background color of screen (on/off) UseNormalBGColor=on Modified: trunk/teraterm/common/tttypes.h =================================================================== --- trunk/teraterm/common/tttypes.h 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/common/tttypes.h 2010-06-07 14:01:51 UTC (rev 3926) @@ -495,6 +495,7 @@ char ConfirmChangePasteStringFile[MAX_PATH]; DWORD Baud; WORD LogBinary; + int pureutf8; }; typedef struct tttset TTTSet, *PTTSet; @@ -874,6 +875,8 @@ BOOL Flush; BOOL TelLineMode; + + int *pureutf8; } TComVar; typedef TComVar far *PComVar; @@ -917,6 +920,9 @@ * Increment the number of this macro value * when you change TMap or member of TMap. * + * - At version 4.67, ttset_memfilemap was replaced with ttset_memfilemap_13. + * added tttset.pureutf8. + * * - At version 4.66, ttset_memfilemap was replaced with ttset_memfilemap_12. * renamed tttset.Baud to Baud_. * added tttset.Baud. @@ -995,4 +1001,4 @@ * added tttset.VTCompatTab. */ -#define TT_FILEMAPNAME "ttset_memfilemap_12" +#define TT_FILEMAPNAME "ttset_memfilemap_13" Modified: trunk/teraterm/teraterm/clipboar.c =================================================================== --- trunk/teraterm/teraterm/clipboar.c 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/teraterm/clipboar.c 2010-06-07 14:01:51 UTC (rev 3926) @@ -16,6 +16,7 @@ #include "clipboar.h" #include "tt_res.h" +#include "language.h" // for clipboard copy static HGLOBAL CBCopyHandle = NULL; @@ -109,7 +110,11 @@ } if (BuffSize==0) { // for clipboar - if (IsClipboardFormatAvailable(CF_TEXT)) { + if (in_utf(ts) && + IsClipboardFormatAvailable(CF_UNICODETEXT)) { + // UTF-8ÌêAUnicode(wchar_t)ÌÜÜó¯æéB + Cf = CF_UNICODETEXT; + } else if (IsClipboardFormatAvailable(CF_TEXT)) { Cf = CF_TEXT; } else if (IsClipboardFormatAvailable(CF_OEMTEXT)) { @@ -169,6 +174,10 @@ static char BracketEnd[] = "\033[201~"; static int BracketPtr = 0; DWORD now; + char *ptr; + wchar_t *wptr; + char *mptr; + int mlen; if (CBMemHandle==NULL) { return; @@ -196,11 +205,26 @@ } } - CBMemPtr = GlobalLock(CBMemHandle); - if (CBMemPtr==NULL) { + ptr = GlobalLock(CBMemHandle); + if (ptr==NULL) { return; } + mptr = NULL; + if (in_utf(ts)) { + /* Unicode©çUTF-8ÖÏ··éBÅãÉ null ðÇÁ·éKvª éÌÅA + * +1 µÄ¢é±ÆÉÓB + */ + wptr = (wchar_t *)ptr; + convert_wchar_to_utf8(wptr, wcslen(wptr) + 1, NULL, &mlen); + mptr = malloc(sizeof(char) * mlen); + convert_wchar_to_utf8(wptr, wcslen(wptr) + 1, mptr, &mlen); + CBMemPtr = mptr; + + } else { + CBMemPtr = ptr; + } + do { if (CBSendCR && (CBMemPtr[CBMemPtr2]==0x0a)) { CBMemPtr2++; @@ -251,6 +275,8 @@ } else { CBEndPaste(); + if (mptr) + free(mptr); return; } @@ -270,7 +296,10 @@ } while (c>0); - if (CBMemPtr!=NULL) { + if (mptr) + free(mptr); + + if (ptr !=NULL) { GlobalUnlock(CBMemHandle); CBMemPtr=NULL; } Modified: trunk/teraterm/teraterm/commlib.c =================================================================== --- trunk/teraterm/teraterm/commlib.c 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/teraterm/commlib.c 2010-06-07 14:01:51 UTC (rev 3926) @@ -293,6 +293,7 @@ cv->Flush = FALSE; cv->FlushLen = 0; cv->TelLineMode = FALSE; + cv->pureutf8 = &ts->pureutf8; if ((ts->PortType!=IdSerial) && (strlen(ts->HostName)==0)) { Modified: trunk/teraterm/teraterm/ttermpro.vcproj =================================================================== --- trunk/teraterm/teraterm/ttermpro.vcproj 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/teraterm/ttermpro.vcproj 2010-06-07 14:01:51 UTC (rev 3926) @@ -49,7 +49,7 @@ Name="VCCLCompilerTool" AdditionalOptions="/D"_CRT_SECURE_NO_DEPRECATE"" Optimization="0" - AdditionalIncludeDirectories="..\common;..\ttpfile" + AdditionalIncludeDirectories="..\common;..\ttpfile;..\ttpcmn" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS" RuntimeLibrary="1" UsePrecompiledHeader="0" @@ -149,7 +149,7 @@ AdditionalOptions="/D"_CRT_SECURE_NO_DEPRECATE"" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="..\common;..\ttpfile" + AdditionalIncludeDirectories="..\common;..\ttpfile;..\ttpcmn" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="true" RuntimeLibrary="0" Modified: trunk/teraterm/teraterm/ttwinman.h =================================================================== --- trunk/teraterm/teraterm/ttwinman.h 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/teraterm/ttwinman.h 2010-06-07 14:01:51 UTC (rev 3926) @@ -38,6 +38,9 @@ extern int SerialNo; +#define in_cv_utf(pure, lang) (pure && (lang == IdUtf8)) +#define in_utf(ts) in_cv_utf(ts.pureutf8, ts.Language) + #ifdef __cplusplus } #endif Modified: trunk/teraterm/teraterm/vtwin.cpp =================================================================== --- trunk/teraterm/teraterm/vtwin.cpp 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/teraterm/vtwin.cpp 2010-06-07 14:01:51 UTC (rev 3926) @@ -53,6 +53,7 @@ #include "tt_res.h" #include "vtwin.h" #include "addsetting.h" +#include "language.h" #define VTClassName "VTWin32" @@ -2864,15 +2865,25 @@ //lpstr = (LPSTR)GlobalLock(hstr); lpstr = (wchar_t *)GlobalLock(hstr); if (lpstr!=NULL) { - mlen = wcstombs(NULL, lpstr, 0); + if (in_utf(ts)) { + convert_wchar_to_utf8(lpstr, wcslen(lpstr), NULL, &mlen); + } else { + 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 (in_utf(ts)) { + convert_wchar_to_utf8(lpstr, wcslen(lpstr), mbstr, &mlen); + Len = mlen; + } else { + Len = wcstombs(mbstr, lpstr, mlen + 1); + // add this string into text buffer of application + Len = strlen(mbstr); + } + if (Len==1) { switch (mbstr[0]) { case 0x20: Modified: trunk/teraterm/ttpcmn/language.c =================================================================== --- trunk/teraterm/ttpcmn/language.c 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/ttpcmn/language.c 2010-06-07 14:01:51 UTC (rev 3926) @@ -8,9 +8,46 @@ #include "tttypes.h" #include <mbstring.h> #include <locale.h> +#include "language.h" #include "sjis2uni.map" +// f[^MAUTF-16LE ©ç UTF-8 ÖÏ··éB +void PASCAL convert_wchar_to_utf8(wchar_t *wbuf, int wbuflen, char *linebuf, int *linesize) +{ + char *p; + int i; + wchar_t ch; + int ratio = 3; + + if (linebuf == NULL) { + *linesize = wbuflen * ratio * sizeof(wchar_t); + return; + } + + p = linebuf; + for (i = 0 ; i < wbuflen ; i++) { + ch = wbuf[i]; + // TODO: TQ[gyAÍ¢T|[g + if ((ch&0xF800) == 0xD800) + ch = '.'; + + if (ch < 0x80) { + *p++ = (char)(ch); + } else if (ch < 0x800) { + *p++ = (0xC0 | (ch >> 6)); + *p++ = (0x80 | (ch & 0x3F)); + } else { + *p++ = (0xE0 | (ch >> 12)); + *p++ = (0x80 | ((ch >> 6) & 0x3F)); + *p++ = (0x80 | (ch & 0x3F)); + } + } + + *linesize = p - linebuf; +} + + unsigned short ConvertUnicode(unsigned short code, codemap_t *table, int tmax) { int low, mid, high; Modified: trunk/teraterm/ttpcmn/language.h =================================================================== --- trunk/teraterm/ttpcmn/language.h 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/ttpcmn/language.h 2010-06-07 14:01:51 UTC (rev 3926) @@ -9,6 +9,7 @@ #endif /* proto types */ +void PASCAL convert_wchar_to_utf8(wchar_t *wbuf, int wbuflen, char *linebuf, int *linesize); unsigned int FAR PASCAL SJIS2UTF8(WORD KCode, int *byte, char *locale); WORD FAR PASCAL SJIS2JIS(WORD KCode); WORD FAR PASCAL SJIS2EUC(WORD KCode); Modified: trunk/teraterm/ttpcmn/ttcmn.c =================================================================== --- trunk/teraterm/ttpcmn/ttcmn.c 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/ttpcmn/ttcmn.c 2010-06-07 14:01:51 UTC (rev 3926) @@ -17,6 +17,7 @@ #include <locale.h> #include "compat_w95.h" +#include "ttwinman.h" /* first instance flag */ static BOOL FirstInstance = TRUE; @@ -1445,12 +1446,17 @@ return C; } - switch (cv->Language) { - case IdUtf8: - case IdJapanese: - case IdKorean: - return TextOutMBCS(cv, B, C); - break; + if (in_cv_utf(cv->pureutf8, cv->Language)) { + // fall through + + } else { + switch (cv->Language) { + case IdUtf8: + case IdJapanese: + case IdKorean: + return TextOutMBCS(cv, B, C); + break; + } } Full = FALSE; Modified: trunk/teraterm/ttpcmn/ttpcmn.def =================================================================== --- trunk/teraterm/ttpcmn/ttpcmn.def 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/ttpcmn/ttpcmn.def 2010-06-07 14:01:51 UTC (rev 3926) @@ -43,3 +43,5 @@ is_NT4 @50 doSelectFolder @51 + convert_wchar_to_utf8 @53 + Modified: trunk/teraterm/ttpcmn/ttpcmn.vcproj =================================================================== --- trunk/teraterm/ttpcmn/ttpcmn.vcproj 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/ttpcmn/ttpcmn.vcproj 2010-06-07 14:01:51 UTC (rev 3926) @@ -49,7 +49,7 @@ AdditionalOptions="/D"_CRT_SECURE_NO_DEPRECATE"" Optimization="2" InlineFunctionExpansion="1" - AdditionalIncludeDirectories="..\common" + AdditionalIncludeDirectories="..\common;..\teraterm" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS" StringPooling="true" RuntimeLibrary="0" @@ -148,7 +148,7 @@ Name="VCCLCompilerTool" AdditionalOptions="/D"_CRT_SECURE_NO_DEPRECATE"" Optimization="0" - AdditionalIncludeDirectories="..\common" + AdditionalIncludeDirectories="..\common;..\teraterm" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS" RuntimeLibrary="1" UsePrecompiledHeader="0" Modified: trunk/teraterm/ttpset/ttset.c =================================================================== --- trunk/teraterm/ttpset/ttset.c 2010-06-03 03:55:26 UTC (rev 3925) +++ trunk/teraterm/ttpset/ttset.c 2010-06-07 14:01:51 UTC (rev 3926) @@ -1169,6 +1169,9 @@ GetPrivateProfileInt(Section, "CodePage ", DEFAULT_CODEPAGE, FName); + ts->pureutf8 = + GetOnOff(Section, "PureUTF8", FName, FALSE); + // UI language message file GetPrivateProfileString(Section, "UILanguageFile", "lang\\Default.lng", Temp, sizeof(Temp), FName); @@ -1564,6 +1567,9 @@ _snprintf_s(Temp, sizeof(Temp), _TRUNCATE, "%d", ts->CodePage); WritePrivateProfileString(Section, "CodePage", Temp, FName); + WriteOnOff(Section, "PureUTF8", FName, + ts->pureutf8); + // ANSI color(2004.9.5 yutaka) Temp[0] = '\0'; for (i = 0; i < 15; i++) {