svnno****@sourc*****
svnno****@sourc*****
2009年 6月 6日 (土) 20:16:25 JST
Revision: 3442 http://svn.sourceforge.jp/view?root=ttssh2&view=rev&rev=3442 Author: doda Date: 2009-06-06 20:16:25 +0900 (Sat, 06 Jun 2009) Log Message: ----------- éä¿¡ãUTF-8ã«è¨å®ããã¦ããæã«ãUTF-8ã«å¤æããã«éä¿¡ããå ´åãããã®ãä¿®æ£ã Modified Paths: -------------- trunk/teraterm/ttpcmn/language.c trunk/teraterm/ttpcmn/ttcmn.c -------------- next part -------------- Modified: trunk/teraterm/ttpcmn/language.c =================================================================== --- trunk/teraterm/ttpcmn/language.c 2009-06-05 07:00:43 UTC (rev 3441) +++ trunk/teraterm/ttpcmn/language.c 2009-06-06 11:16:25 UTC (rev 3442) @@ -45,6 +45,7 @@ unsigned int c, c1, c2, c3; unsigned char *ptr, buf[3]; unsigned short cset; + int len = 0; *byte = 2; @@ -52,9 +53,11 @@ setlocale(LC_ALL, locale); buf[0] = KCode >> 8; - buf[1] = KCode & 0xff; - buf[2] = '\0'; - ret = mbtowc(&wchar, buf, 2); + if (buf[0] > 0) { + len++; + } + buf[len++] = KCode & 0xff; + ret = mbtowc(&wchar, buf, len); if (ret <= 0) { // Ï·¸s cset = 0; if (_stricmp(locale, DEFAULT_LOCALE) == 0) { @@ -67,11 +70,7 @@ } } else { ptr = (unsigned char *)&wchar; - if (ret >= 2) { - c = ((ptr[1] << 8) | ptr[0]); - } else { - c = '?'; - } + c = ((ptr[1] << 8) | ptr[0]); } // UTF-16LE©çUTF-8ÖÏ··é Modified: trunk/teraterm/ttpcmn/ttcmn.c =================================================================== --- trunk/teraterm/ttpcmn/ttcmn.c 2009-06-05 07:00:43 UTC (rev 3441) +++ trunk/teraterm/ttpcmn/ttcmn.c 2009-06-06 11:16:25 UTC (rev 3442) @@ -1119,32 +1119,25 @@ return i; } -static void OutputTextUTF8(WORD K, char *TempStr, int *TempLenSrc, PComVar cv) +static int OutputTextUTF8(WORD K, char *TempStr, PComVar cv) { unsigned int code; - int byte; - int TempLen = *TempLenSrc; + int outlen; + int TempLen = 0; - code = SJIS2UTF8(K, &byte, cv->Locale); - if (byte == 1) { - TempStr[TempLen++] = code; - } - else if (byte == 2) { - TempStr[TempLen++] = (code >> 8) & 0xff; - TempStr[TempLen++] = code & 0xff; - - } - else if (byte == 3) { + code = SJIS2UTF8(K, &outlen, cv->Locale); + switch (outlen) { + case 3: TempStr[TempLen++] = (code >> 16) & 0xff; + case 2: TempStr[TempLen++] = (code >> 8) & 0xff; + case 1: TempStr[TempLen++] = code & 0xff; - } - *TempLenSrc = TempLen; + return TempLen; } - // // SJIS©çeí¿R[hÖÏ·µÄoÍ·éB // @@ -1152,7 +1145,7 @@ { int i, TempLen; WORD K; - char TempStr[11]; + char TempStr[12]; int SendCodeNew; BYTE d; BOOL Full, KanjiFlagNew; @@ -1163,38 +1156,41 @@ TempLen = 0; d = (BYTE)B[i]; SendCodeNew = cv->SendCode; + KanjiFlagNew = FALSE; if (cv->SendKanjiFlag) { - KanjiFlagNew = FALSE; SendCodeNew = IdKanji; K = (cv->SendKanjiFirst << 8) + d; // UTF-8ÖÌÏ·ðs¤B1`3oCgÜÅÌÎÈÌÅÓB if (cv->KanjiCodeSend == IdUTF8 || cv->Language == IdUtf8) { - OutputTextUTF8(K, TempStr, &TempLen, cv); - - } else { - - if (cv->Language == IdJapanese) { - if (cv->KanjiCodeSend == IdEUC) { + TempLen += OutputTextUTF8(K, TempStr, cv); + } + else { + switch (cv->Language) { + case IdJapanese: + switch (cv->KanjiCodeSend) { + case IdEUC: K = SJIS2EUC(K); - } - else if (cv->KanjiCodeSend != IdSJIS) { + break; + case IdJIS: K = SJIS2JIS(K); + if ((cv->SendCode==IdKatakana) && + (cv->JIS7KatakanaSend==1)) { + TempStr[TempLen++] = SI; + } + break; + case IdSJIS: + /* nothing to do */ + break; } - - if ((cv->SendCode==IdKatakana) && - (cv->KanjiCodeSend==IdJIS) && - (cv->JIS7KatakanaSend==1)) { - TempStr[TempLen] = SI; - TempLen++; - } + break; + case IdKorean: + break; } - - TempStr[TempLen] = HIBYTE(K); - TempStr[TempLen+1] = LOBYTE(K); - TempLen = TempLen + 2; + TempStr[TempLen++] = HIBYTE(K); + TempStr[TempLen++] = LOBYTE(K); } } else if (IsDBCSLeadByteEx(*cv->CodePage, d)) { @@ -1202,105 +1198,85 @@ cv->SendKanjiFirst = d; SendCodeNew = IdKanji; - if ((cv->SendCode!=IdKanji) && - (cv->KanjiCodeSend==IdJIS)) { - TempStr[0] = 0x1B; - TempStr[1] = '$'; - if (cv->KanjiIn == IdKanjiInB) { - TempStr[2] = 'B'; + if (cv->Language == IdJapanese) { + if ((cv->SendCode!=IdKanji) && (cv->KanjiCodeSend==IdJIS)) { + TempStr[0] = 0x1B; + TempStr[1] = '$'; + if (cv->KanjiIn == IdKanjiInB) { + TempStr[2] = 'B'; + } + else { + TempStr[2] = '@'; + } + TempLen = 3; } - else { - TempStr[2] = '@'; - } - TempLen = 3; } - else { - TempLen = 0; - } } else { - KanjiFlagNew = FALSE; - - if ((cv->SendCode==IdKanji) && - (cv->KanjiCodeSend==IdJIS)) { - TempStr[0] = 0x1B; - TempStr[1] = '('; - switch (cv->KanjiOut) { - case IdKanjiOutJ: + if (cv->Language == IdJapanese) { + if ((cv->SendCode==IdKanji) && (cv->KanjiCodeSend==IdJIS)) { + TempStr[0] = 0x1B; + TempStr[1] = '('; + switch (cv->KanjiOut) { + case IdKanjiOutJ: TempStr[2] = 'J'; break; - case IdKanjiOutH: + case IdKanjiOutH: TempStr[2] = 'H'; break; - default: + default: TempStr[2] = 'B'; + } + TempLen = 3; } - TempLen = 3; - } - else { - TempLen = 0; - } - if ((0xa0<d) && (d<0xe0)) { - SendCodeNew = IdKatakana; - if ((cv->SendCode!=IdKatakana) && - (cv->KanjiCodeSend==IdJIS) && - (cv->JIS7KatakanaSend==1)) { - TempStr[TempLen] = SO; - TempLen++; + if ((0xa0<d) && (d<0xe0)) { + SendCodeNew = IdKatakana; + if ((cv->SendCode!=IdKatakana) && + (cv->KanjiCodeSend==IdJIS) && + (cv->JIS7KatakanaSend==1)) { + TempStr[TempLen++] = SO; + } } - } - else { - SendCodeNew = IdASCII; - if ((cv->SendCode==IdKatakana) && - (cv->KanjiCodeSend==IdJIS) && - (cv->JIS7KatakanaSend==1)) { - TempStr[TempLen] = SI; - TempLen++; + else { + SendCodeNew = IdASCII; + if ((cv->SendCode==IdKatakana) && + (cv->KanjiCodeSend==IdJIS) && + (cv->JIS7KatakanaSend==1)) { + TempStr[TempLen++] = SI; + } } } if (d==0x0d) { - TempStr[TempLen] = 0x0d; - TempLen++; + TempStr[TempLen++] = 0x0d; if (cv->CRSend==IdCRLF) { - TempStr[TempLen] = 0x0a; - TempLen++; + TempStr[TempLen++] = 0x0a; } else if ((cv->CRSend==IdCR) && cv->TelFlag && ! cv->TelBinSend) { - TempStr[TempLen] = 0; - TempLen++; + TempStr[TempLen++] = 0; } } - else if ((d>=0xa1) && (d<=0xe0)) { - /* Katakana */ + else if ((d>=0x80) && (cv->KanjiCodeSend==IdUTF8 || cv->Language==IdUtf8)) { + TempLen += OutputTextUTF8((WORD)d, TempStr, cv); + } + else if ((d>=0xa1) && (d<=0xe0) && (cv->Language == IdJapanese)) { if (cv->KanjiCodeSend==IdEUC) { - TempStr[TempLen] = (char)0x8E; - TempLen++; + TempStr[TempLen++] = (char)0x8E; } if ((cv->KanjiCodeSend==IdJIS) && (cv->JIS7KatakanaSend==1)) { - TempStr[TempLen] = d & 0x7f; + TempStr[TempLen++] = d & 0x7f; } else { - TempStr[TempLen] = d; + TempStr[TempLen++] = d; } - TempLen++; - - // ¼pJiÍUnicodeÅÍ2oCgÉÈé (2004.10.4 yutaka) - if (cv->KanjiCodeSend==IdUTF8 || cv->Language==IdUtf8) { - TempLen = 0; - K = d; - OutputTextUTF8(K, TempStr, &TempLen, cv); - } } else { - TempStr[TempLen] = d; - TempLen++; + TempStr[TempLen++] = d; if (cv->TelFlag && (d==0xff)) { - TempStr[TempLen] = (char)0xff; - TempLen++; + TempStr[TempLen++] = (char)0xff; } } } // if (cv->SendKanjiFlag) else if ... else ... end @@ -1328,7 +1304,7 @@ int FAR PASCAL CommTextOut(PComVar cv, PCHAR B, int C) { int i, TempLen; - char TempStr[11]; + char TempStr[12]; BYTE d; BOOL Full; @@ -1337,8 +1313,8 @@ } switch (cv->Language) { - case IdJapanese: case IdUtf8: + case IdJapanese: case IdKorean: return TextOutJP(cv, B, C); break; @@ -1452,7 +1428,7 @@ K = (cv->EchoKanjiFirst << 8) + d; // UTF-8ÖÌÏ·ðs¤B1`3oCgÜÅÌÎÈÌÅÓB if (cv->KanjiCodeSend == IdUTF8 || cv->Language==IdUtf8) { - OutputTextUTF8(K, TempStr, &TempLen, cv); + TempLen += OutputTextUTF8(K, TempStr, cv); } else { if (cv->KanjiCodeEcho == IdEUC) { @@ -1618,7 +1594,7 @@ K = (cv->EchoKanjiFirst << 8) + d; // UTF-8ÖÌÏ·ðs¤B1`3oCgÜÅÌÎÈÌÅÓB if (cv->KanjiCodeSend == IdUTF8) { - OutputTextUTF8(K, TempStr, &TempLen, cv); + TempLen += OutputTextUTF8(K, TempStr, cv); } else { TempStr[TempLen] = HIBYTE(K);