Revision: 10767 https://osdn.net/projects/ttssh2/scm/svn/commits/10767 Author: zmatsuo Date: 2023-06-16 22:44:33 +0900 (Fri, 16 Jun 2023) Log Message: ----------- ParseFirstUTF8()内のstaticワークをなくした Modified Paths: -------------- trunk/teraterm/teraterm/charset.c -------------- next part -------------- Modified: trunk/teraterm/teraterm/charset.c =================================================================== --- trunk/teraterm/teraterm/charset.c 2023-06-16 13:44:22 UTC (rev 10766) +++ trunk/teraterm/teraterm/charset.c 2023-06-16 13:44:33 UTC (rev 10767) @@ -75,6 +75,9 @@ int Gn[4]; // char32_t replacement_char; + // UTF-8 work + BYTE buf[4]; + int count; } VttermKanjiWork; static VttermKanjiWork KanjiWork; @@ -566,8 +569,6 @@ static BOOL ParseFirstUTF8(BYTE b) { VttermKanjiWork *w = &KanjiWork; - static BYTE buf[4]; - static int count = 0; char32_t code; if (Fallbacked) { @@ -606,7 +607,7 @@ // - 1byte == 0xf4 \x82̂Ƃ\xAB 0x90 - 0x8f\x82̂\xDDok recheck: // 1byte(7bit) - if (count == 0) { + if (w->count == 0) { if (b <= 0x7f) { // 1byte(7bit) // 0x7f\x88ȉ\xBA, \x82̂Ƃ\xAB\x81A\x82\xBB\x82̂܂o\x97\xCD @@ -615,7 +616,7 @@ } if (0xc2 <= b && b <= 0xf4) { // 1byte\x96ڕۑ\xB6 - buf[count++] = b; + w->buf[w->count++] = b; return TRUE; } @@ -637,8 +638,8 @@ } else { // fallback\x82\xB5\x82Ȃ\xA2, \x95s\x90\xB3\x82ȕ\xB6\x8E\x9A\x93\xFC\x97\xCD - buf[0] = b; - PutReplacementChr(w, buf, 1, FALSE); + w->buf[0] = b; + PutReplacementChr(w, w->buf, 1, FALSE); } return TRUE; } @@ -646,21 +647,21 @@ // 2byte\x88ȍ~\x90\xB3\x8F\xED? if((b & 0xc0) != 0x80) { // == (b <= 0x7f || 0xc0 <= b) // \x95s\x90\xB3\x82ȕ\xB6\x8E\x9A, (\x8F\xE3\x88\xCA2bit\x82\xAA 0b10xx_xxxx \x82ł͂Ȃ\xA2) - PutReplacementChr(w, buf, count, ts.FallbackToCP932); - count = 0; + PutReplacementChr(w, w->buf, w->count, ts.FallbackToCP932); + w->count = 0; goto recheck; } // 2byte\x96ڈȍ~\x95ۑ\xB6 - buf[count++] = b; + w->buf[w->count++] = b; // 2byte(11bit) - if (count == 2) { - if ((buf[0] & 0xe0) == 0xc0) { // == (0xc2 <= buf[0] && buf[0] <= 0xdf) + if (w->count == 2) { + if ((w->buf[0] & 0xe0) == 0xc0) { // == (0xc2 <= w->buf[0] && w->buf[0] <= 0xdf) // 5bit + 6bit - code = ((buf[0] & 0x1f) << 6) | (b & 0x3f); + code = ((w->buf[0] & 0x1f) << 6) | (b & 0x3f); PutU32(code); - count = 0; + w->count = 0; return TRUE; } return TRUE; @@ -667,21 +668,21 @@ } // 3byte(16bit) - if (count == 3) { - if ((buf[0] & 0xf0) == 0xe0) { - if ((buf[0] == 0xe0 && (buf[1] < 0xa0 || 0xbf < buf[1])) || - (buf[0] == 0xed && ( 0x9f < buf[1]))) { + if (w->count == 3) { + if ((w->buf[0] & 0xf0) == 0xe0) { + if ((w->buf[0] == 0xe0 && (w->buf[1] < 0xa0 || 0xbf < w->buf[1])) || + (w->buf[0] == 0xed && ( 0x9f < w->buf[1]))) { // \x95s\x90\xB3\x82\xC8 UTF-8 - PutReplacementChr(w, buf, 2, ts.FallbackToCP932); - count = 0; + PutReplacementChr(w, w->buf, 2, ts.FallbackToCP932); + w->count = 0; goto recheck; } // 4bit + 6bit + 6bit - code = ((buf[0] & 0xf) << 12); - code |= ((buf[1] & 0x3f) << 6); - code |= ((buf[2] & 0x3f)); + code = ((w->buf[0] & 0xf) << 12); + code |= ((w->buf[1] & 0x3f) << 6); + code |= ((w->buf[2] & 0x3f)); PutU32(code); - count = 0; + w->count = 0; return TRUE; } return TRUE; @@ -688,22 +689,22 @@ } // 4byte(21bit) - assert(count == 4); - assert((buf[0] & 0xf8) == 0xf0); - if ((buf[0] == 0xf0 && (buf[1] < 0x90 || 0x9f < buf[1])) || - (buf[0] == 0xf4 && (buf[1] < 0x80 || 0x8f < buf[1]))) { + assert(w->count == 4); + assert((w->buf[0] & 0xf8) == 0xf0); + if ((w->buf[0] == 0xf0 && (w->buf[1] < 0x90 || 0x9f < w->buf[1])) || + (w->buf[0] == 0xf4 && (w->buf[1] < 0x80 || 0x8f < w->buf[1]))) { // \x95s\x90\xB3\x82\xC8 UTF-8 - PutReplacementChr(w, buf, 3, ts.FallbackToCP932); - count = 0; + PutReplacementChr(w, w->buf, 3, ts.FallbackToCP932); + w->count = 0; goto recheck; } // 3bit + 6bit + 6bit + 6bit - code = ((buf[0] & 0x07) << 18); - code |= ((buf[1] & 0x3f) << 12); - code |= ((buf[2] & 0x3f) << 6); - code |= (buf[3] & 0x3f); + code = ((w->buf[0] & 0x07) << 18); + code |= ((w->buf[1] & 0x3f) << 12); + code |= ((w->buf[2] & 0x3f) << 6); + code |= (w->buf[3] & 0x3f); PutU32(code); - count = 0; + w->count = 0; return TRUE; }