--- np2/common/Attic/codecnv.c 2003/10/16 17:57:16 1.1 +++ np2/common/Attic/codecnv.c 2003/11/23 09:59:10 1.3 @@ -28,7 +28,7 @@ void codecnv_sjis2euc(char *euc, UINT ec } ecnt--; while(1) { - s = *sjis++; + s = (BYTE)*sjis++; if (s < 0x80) { // ascii if (!s) { break; @@ -40,7 +40,7 @@ void codecnv_sjis2euc(char *euc, UINT ec *euc++ = (char)s; } else if ((((s ^ 0x20) - 0xa1) & 0xff) < 0x2f) { - c = *sjis++; + c = (BYTE)*sjis++; if (!c) { break; } @@ -72,6 +72,52 @@ void codecnv_sjis2euc(char *euc, UINT ec *euc = '\0'; } +void codecnv_euc2sjis(char *sjis, UINT scnt, const char *euc, UINT ecnt) { + + UINT h; + UINT l; + + (void)ecnt; // 判定してないのかよ + + if ((sjis == NULL) || (scnt == 0) || (euc == NULL)) { + return; + } + scnt--; + while(1) { + h = (BYTE)*euc++; + if (h < 0x80) { // ascii + if (!h) { + break; + } + if (scnt == 0) { + break; + } + scnt--; + *sjis++ = (char)h; + } + else { + l = (BYTE)*euc++; + if ((!l) || (scnt < 2)) { + break; + } + h &= 0x7f; + l &= 0x7f; + l += ((h & 1) - 1) & 0x5e; + if (l >= 0x60) { + l++; + } + h += 0x121; + l += 0x1f; + h >>= 1; + h ^= 0x20; + *sjis++ = (char)h; + *sjis++ = (char)l; + scnt -= 2; + } + } + *sjis = '\0'; +} + // ----