From: tomo Date: Tue, 15 Jun 1999 11:40:58 +0000 (+0000) Subject: (c2mu): New implementation for UTF2000. X-Git-Tag: r21-2-15-utf2000-0_2-1~7 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=0fc7fd9e8e70d58b8f7d96fe4849a4f791e1110a;p=chise%2Fxemacs-chise.git- (c2mu): New implementation for UTF2000. (m2c): Likewise. --- diff --git a/src/mule-canna.c b/src/mule-canna.c index 069c7b5..39ae702 100644 --- a/src/mule-canna.c +++ b/src/mule-canna.c @@ -1776,6 +1776,80 @@ For canna /* EUC multibyte string to MULE internal string */ +#ifdef UTF2000 +static void +c2mu (unsigned char *cp, int l, unsigned char *mp) +{ + Emchar chr; + unsigned char ch, *ep = cp+l; + + while ((cp < ep) && (ch = *cp++)) + { + if (ch == ISO_CODE_SS2) + { + chr = (*cp++) + MIN_CHAR_HALFWIDTH_KATAKANA - 0x20; + } + else if (ch == ISO_CODE_SS3) + { + chr = MULE_CHAR_PRIVATE_OFFSET + | ( (LEADING_BYTE_JAPANESE_JISX0212 + - FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14 ) + | (((*cp++) & 0x7f) << 7) | ((*cp++) & 0x7f); + } + else if (ch & 0x80) + { + chr = MULE_CHAR_PRIVATE_OFFSET + | ( (LEADING_BYTE_JAPANESE_JISX0208 + - FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14 ) + | ((ch & 0x7f) << 7) | ((*cp++) & 0x7f); + } + else + { + chr = ch; + } + if ( chr <= 0x7f ) + { + *mp++ = chr; + } + else if ( chr <= 0x7ff ) + { + *mp++ = (chr >> 6) | 0xc0; + *mp++ = (chr & 0x3f) | 0x80; + } + else if ( chr <= 0xffff ) + { + *mp++ = (chr >> 12) | 0xe0; + *mp++ = ((chr >> 6) & 0x3f) | 0x80; + *mp++ = (chr & 0x3f) | 0x80; + } + else if ( chr <= 0x1fffff ) + { + *mp++ = (chr >> 18) | 0xf0; + *mp++ = ((chr >> 12) & 0x3f) | 0x80; + *mp++ = ((chr >> 6) & 0x3f) | 0x80; + *mp++ = (chr & 0x3f) | 0x80; + } + else if ( chr <= 0x3ffffff ) + { + *mp++ = (chr >> 24) | 0xf8; + *mp++ = ((chr >> 18) & 0x3f) | 0x80; + *mp++ = ((chr >> 12) & 0x3f) | 0x80; + *mp++ = ((chr >> 6) & 0x3f) | 0x80; + *mp++ = (chr & 0x3f) | 0x80; + } + else + { + *mp++ = (chr >> 30) | 0xfc; + *mp++ = ((chr >> 24) & 0x3f) | 0x80; + *mp++ = ((chr >> 18) & 0x3f) | 0x80; + *mp++ = ((chr >> 12) & 0x3f) | 0x80; + *mp++ = ((chr >> 6) & 0x3f) | 0x80; + *mp++ = (chr & 0x3f) | 0x80; + } + } + *mp = 0; +} +#else static void c2mu (char *cp, int l, char *mp) { @@ -1803,6 +1877,7 @@ c2mu (char *cp, int l, char *mp) } *mp = 0; } +#endif /* MULE internal string to EUC multibyte string */ @@ -1810,9 +1885,70 @@ static void m2c (unsigned char *mp, int l, unsigned char *cp) { unsigned char ch, *ep = mp + l; +#ifdef UTF2000 + unsigned char fb; + int len; + Emchar chr; +#endif while ((mp < ep) && (ch = *mp++)) { +#ifdef UTF2000 + if ( ch >= 0xfc ) + { + chr = (ch & 0x01); + len = 5; + } + else if ( ch >= 0xf8 ) + { + chr = ch & 0x03; + len = 4; + } + else if ( ch >= 0xf0 ) + { + chr = ch & 0x07; + len = 3; + } + else if ( ch >= 0xe0 ) + { + chr = ch & 0x0f; + len = 2; + } + else if ( ch >= 0xc0 ) + { + chr = ch & 0x1f; + len = 1; + } + else + { + chr = ch; + len = 0; + } + for( ; len > 0; len-- ) + { + ch = *mp++; + chr = ( chr << 6 ) | ( ch & 0x3f ); + } + if ( chr <= 0x7f ) + *cp++ = chr; + else if ( chr <= MAX_CHAR_HALFWIDTH_KATAKANA ) + { + *cp++ = ISO_CODE_SS2; + *cp++ = ( chr & 0x7f ) | 0x80; + } + else + { + fb = (chr >> 14) & 0x7f; + switch ( fb ) + { + case 'D': + *cp++ = ISO_CODE_SS3; + default: + *cp++ = ( (chr >> 7) & 0x7f ) | 0x80; + *cp++ = ( chr & 0x7f ) | 0x80; + } + } +#else switch (ch) { case LEADING_BYTE_KATAKANA_JISX0201: @@ -1829,6 +1965,7 @@ m2c (unsigned char *mp, int l, unsigned char *cp) *cp++ = ch; break; } +#endif } *cp = 0; }