diff options
author | Ulrich Drepper <drepper@redhat.com> | 2002-09-24 04:19:03 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2002-09-24 04:19:03 +0000 |
commit | fa00744e514a99087f5fe70cac9334b29a04c93a (patch) | |
tree | afb188699c7ba3d139c0c1e5962a749bec6480b7 /iconvdata | |
parent | f2a444335f8deabb58145db315b33a87e4f576da (diff) | |
download | glibc-fa00744e514a99087f5fe70cac9334b29a04c93a.zip glibc-fa00744e514a99087f5fe70cac9334b29a04c93a.tar.gz glibc-fa00744e514a99087f5fe70cac9334b29a04c93a.tar.bz2 |
Update.
* iconv/iconv_prog.c (main): Provide an error message that identifies
the wrong encoding.
2002-09-22 Bruno Haible <bruno@clisp.org>
* iconvdata/tscii.c: New file.
* iconvdata/testdata/TSCII: New file.
* iconvdata/testdata/TSCII..UTF8: New file.
* iconvdata/TSCII.precomposed: New file.
* iconvdata/TSCII.irreversible: New file.
* iconvdata/gconv-modules (TSCII): New module.
* iconvdata/Makefile (modules): Add TSCII.
(distribute): Add tscii.c.
* iconvdata/tst-table-from.c (try, utf8_decode, main): Double output
buffer size.
* iconvdata/tst-tables.sh: Add TSCII.
* iconvdata/TESTS: Add TSCII.
2002-09-22 Bruno Haible <bruno@clisp.org>
Revert 2002-04-18 patch.
* iconvdata/euc-jisx0213.c (EMIT_SHIFT_TO_INIT, BODY for
FROM_DIRECTION): Make the FROM direction stateful again.
* iconvdata/shift_jisx0213.c (EMIT_SHIFT_TO_INIT, BODY for
FROM_DIRECTION): Likewise.
2002-09-22 Bruno Haible <bruno@clisp.org>
Diffstat (limited to 'iconvdata')
-rw-r--r-- | iconvdata/Makefile | 4 | ||||
-rw-r--r-- | iconvdata/TESTS | 1 | ||||
-rw-r--r-- | iconvdata/TSCII.irreversible | 1 | ||||
-rw-r--r-- | iconvdata/TSCII.precomposed | 66 | ||||
-rw-r--r-- | iconvdata/euc-jisx0213.c | 171 | ||||
-rw-r--r-- | iconvdata/gconv-modules | 4 | ||||
-rw-r--r-- | iconvdata/shift_jisx0213.c | 189 | ||||
-rw-r--r-- | iconvdata/testdata/TSCII | 27 | ||||
-rw-r--r-- | iconvdata/testdata/TSCII..UTF8 | 27 | ||||
-rw-r--r-- | iconvdata/tscii.c | 851 | ||||
-rw-r--r-- | iconvdata/tst-table-from.c | 12 | ||||
-rwxr-xr-x | iconvdata/tst-tables.sh | 1 |
12 files changed, 1187 insertions, 167 deletions
diff --git a/iconvdata/Makefile b/iconvdata/Makefile index 49cf62c..10a307f 100644 --- a/iconvdata/Makefile +++ b/iconvdata/Makefile @@ -51,7 +51,7 @@ modules := ISO8859-1 ISO8859-2 ISO8859-3 ISO8859-4 ISO8859-5 \ GB18030 ISO-2022-CN-EXT VISCII GBBIG5 CP10007 KOI8-T \ GEORGIAN-PS GEORGIAN-ACADEMY ISO-IR-209 MAC-SAMI ARMSCII-8 \ TCVN5712-1 libJISX0213 EUC-JISX0213 SHIFT_JISX0213 \ - ISO-2022-JP-3 + ISO-2022-JP-3 TSCII modules.so := $(addsuffix .so, $(modules)) @@ -166,7 +166,7 @@ distribute := gconv-modules extra-module.mk gap.awk gaptab.awk \ mac-sami.c ibm1160.c ibm1160.h ibm1161.c ibm1161.h \ ibm1163.c ibm1163.h ibm1164.c ibm1164.h jisx0213.c jisx0213.h \ euc-jisx0213.c shift_jisx0213.c iso-2022-jp-3.c \ - tcvn5712-1.c armscii-8.c + tcvn5712-1.c armscii-8.c tscii.c # We build the transformation modules only when we build shared libs. ifeq (yes,$(build-shared)) diff --git a/iconvdata/TESTS b/iconvdata/TESTS index 8d6df22..57e86ac 100644 --- a/iconvdata/TESTS +++ b/iconvdata/TESTS @@ -118,3 +118,4 @@ TCVN-5712 TCVN-5712 Y UTF8 EUC-JISX0213 EUC-JISX0213 Y UTF8 SHIFT_JISX0213 SHIFT_JISX0213 Y UTF8 ISO-2022-JP-3 ISO-2022-JP-3 N UTF8 +TSCII TSCII Y UTF8 diff --git a/iconvdata/TSCII.irreversible b/iconvdata/TSCII.irreversible new file mode 100644 index 0000000..fe9dd3a --- /dev/null +++ b/iconvdata/TSCII.irreversible @@ -0,0 +1 @@ +0xAD 0x0B87 diff --git a/iconvdata/TSCII.precomposed b/iconvdata/TSCII.precomposed new file mode 100644 index 0000000..033e93d --- /dev/null +++ b/iconvdata/TSCII.precomposed @@ -0,0 +1,66 @@ +0x82 0x0BB8 0x0BCD 0x0BB0 0x0BC0 +0x87 0x0B95 0x0BCD 0x0BB7 +0x88 0x0B9C 0x0BCD +0x89 0x0BB7 0x0BCD +0x8A 0x0BB8 0x0BCD +0x8B 0x0BB9 0x0BCD +0x8C 0x0B95 0x0BCD 0x0BB7 0x0BCD +0x99 0x0B99 0x0BC1 +0x9A 0x0B9E 0x0BC1 +0x9B 0x0B99 0x0BC2 +0x9C 0x0B9E 0x0BC2 +0xA6A1 0x0BCA +0xA7A1 0x0BCB +0xA7AA 0x0BCC +0xCA 0x0B9F 0x0BBF +0xCB 0x0B9F 0x0BC0 +0xCC 0x0B95 0x0BC1 +0xCD 0x0B9A 0x0BC1 +0xCE 0x0B9F 0x0BC1 +0xCF 0x0BA3 0x0BC1 +0xD0 0x0BA4 0x0BC1 +0xD1 0x0BA8 0x0BC1 +0xD2 0x0BAA 0x0BC1 +0xD3 0x0BAE 0x0BC1 +0xD4 0x0BAF 0x0BC1 +0xD5 0x0BB0 0x0BC1 +0xD6 0x0BB2 0x0BC1 +0xD7 0x0BB5 0x0BC1 +0xD8 0x0BB4 0x0BC1 +0xD9 0x0BB3 0x0BC1 +0xDA 0x0BB1 0x0BC1 +0xDB 0x0BA9 0x0BC1 +0xDC 0x0B95 0x0BC2 +0xDD 0x0B9A 0x0BC2 +0xDE 0x0B9F 0x0BC2 +0xDF 0x0BA3 0x0BC2 +0xE0 0x0BA4 0x0BC2 +0xE1 0x0BA8 0x0BC2 +0xE2 0x0BAA 0x0BC2 +0xE3 0x0BAE 0x0BC2 +0xE4 0x0BAF 0x0BC2 +0xE5 0x0BB0 0x0BC2 +0xE6 0x0BB2 0x0BC2 +0xE7 0x0BB5 0x0BC2 +0xE8 0x0BB4 0x0BC2 +0xE9 0x0BB3 0x0BC2 +0xEA 0x0BB1 0x0BC2 +0xEB 0x0BA9 0x0BC2 +0xEC 0x0B95 0x0BCD +0xED 0x0B99 0x0BCD +0xEE 0x0B9A 0x0BCD +0xEF 0x0B9E 0x0BCD +0xF0 0x0B9F 0x0BCD +0xF1 0x0BA3 0x0BCD +0xF2 0x0BA4 0x0BCD +0xF3 0x0BA8 0x0BCD +0xF4 0x0BAA 0x0BCD +0xF5 0x0BAE 0x0BCD +0xF6 0x0BAF 0x0BCD +0xF7 0x0BB0 0x0BCD +0xF8 0x0BB2 0x0BCD +0xF9 0x0BB5 0x0BCD +0xFA 0x0BB4 0x0BCD +0xFB 0x0BB3 0x0BCD +0xFC 0x0BB1 0x0BCD +0xFD 0x0BA9 0x0BCD diff --git a/iconvdata/euc-jisx0213.c b/iconvdata/euc-jisx0213.c index 8a41756..733cbc1 100644 --- a/iconvdata/euc-jisx0213.c +++ b/iconvdata/euc-jisx0213.c @@ -67,7 +67,9 @@ *statep = saved_state -/* During UCS-4 to EUC-JISX0213 conversion, the COUNT element of the state +/* During EUC-JISX0213 to UCS-4 conversion, the COUNT element of the state + contains the last UCS-4 character, shifted by 3 bits. + During UCS-4 to EUC-JISX0213 conversion, the COUNT element of the state contains the last two bytes to be output, shifted by 3 bits. */ /* Since this is a stateful encoding we have to provide code which resets @@ -77,8 +79,17 @@ if (data->__statep->__count != 0) \ { \ if (FROM_DIRECTION) \ - /* We don't use shift states in the FROM_DIRECTION. */ \ - data->__statep->__count = 0; \ + { \ + if (__builtin_expect (outbuf + 4 <= outend, 1)) \ + { \ + /* Write out the last character. */ \ + *((uint32_t *) outbuf)++ = data->__statep->__count >> 3; \ + data->__statep->__count = 0; \ + } \ + else \ + /* We don't have enough room in the output buffer. */ \ + status = __GCONV_FULL_OUTPUT; \ + } \ else \ { \ if (__builtin_expect (outbuf + 2 <= outend, 1)) \ @@ -104,104 +115,114 @@ #define LOOPFCT FROM_LOOP #define BODY \ { \ - uint32_t ch = *inptr; \ + uint32_t ch; \ \ - if (ch < 0x80) \ - /* Plain ASCII character. */ \ - ++inptr; \ - else if ((ch >= 0xa1 && ch <= 0xfe) || ch == 0x8e || ch == 0x8f) \ + /* Determine whether there is a buffered character pending. */ \ + ch = *statep >> 3; \ + if (__builtin_expect (ch == 0, 1)) \ { \ - /* Two or three byte character. */ \ - uint32_t ch2; \ + /* No - so look at the next input byte. */ \ + ch = *inptr; \ \ - if (__builtin_expect (inptr + 1 >= inend, 0)) \ + if (ch < 0x80) \ + /* Plain ASCII character. */ \ + ++inptr; \ + else if ((ch >= 0xa1 && ch <= 0xfe) || ch == 0x8e || ch == 0x8f) \ { \ - /* The second byte is not available. */ \ - result = __GCONV_INCOMPLETE_INPUT; \ - break; \ - } \ + /* Two or three byte character. */ \ + uint32_t ch2; \ \ - ch2 = inptr[1]; \ + if (__builtin_expect (inptr + 1 >= inend, 0)) \ + { \ + /* The second byte is not available. */ \ + result = __GCONV_INCOMPLETE_INPUT; \ + break; \ + } \ \ - /* The second byte must be >= 0xa1 and <= 0xfe. */ \ - if (__builtin_expect (ch2 < 0xa1 || ch2 > 0xfe, 0)) \ - { \ - /* This is an illegal character. */ \ - STANDARD_FROM_LOOP_ERR_HANDLER (1); \ - } \ + ch2 = inptr[1]; \ \ - if (ch == 0x8e) \ - { \ - /* Half-width katakana. */ \ - if (__builtin_expect (ch2 > 0xdf, 0)) \ - STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + /* The second byte must be >= 0xa1 and <= 0xfe. */ \ + if (__builtin_expect (ch2 < 0xa1 || ch2 > 0xfe, 0)) \ + { \ + /* This is an illegal character. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + } \ \ - ch = ch2 + 0xfec0; \ - inptr += 2; \ - } \ - else \ - { \ - const unsigned char *endp; \ + if (ch == 0x8e) \ + { \ + /* Half-width katakana. */ \ + if (__builtin_expect (ch2 > 0xdf, 0)) \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ \ - if (ch == 0x8f) \ + ch = ch2 + 0xfec0; \ + inptr += 2; \ + } \ + else \ { \ - /* JISX 0213 plane 2. */ \ - uint32_t ch3; \ + const unsigned char *endp; \ \ - if (__builtin_expect (inptr + 2 >= inend, 0)) \ + if (ch == 0x8f) \ { \ - /* The third byte is not available. */ \ - result = __GCONV_INCOMPLETE_INPUT; \ - break; \ - } \ + /* JISX 0213 plane 2. */ \ + uint32_t ch3; \ \ - ch3 = inptr[2]; \ - endp = inptr + 3; \ + if (__builtin_expect (inptr + 2 >= inend, 0)) \ + { \ + /* The third byte is not available. */ \ + result = __GCONV_INCOMPLETE_INPUT; \ + break; \ + } \ \ - ch = jisx0213_to_ucs4 (0x200 - 0x80 + ch2, ch3 ^ 0x80); \ - } \ - else \ - { \ - /* JISX 0213 plane 1. */ \ - endp = inptr + 2; \ + ch3 = inptr[2]; \ + endp = inptr + 3; \ \ - ch = jisx0213_to_ucs4 (0x100 - 0x80 + ch, ch2 ^ 0x80); \ - } \ + ch = jisx0213_to_ucs4 (0x200 - 0x80 + ch2, ch3 ^ 0x80); \ + } \ + else \ + { \ + /* JISX 0213 plane 1. */ \ + endp = inptr + 2; \ \ - if (ch == 0) \ - /* This is an illegal character. */ \ - STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + ch = jisx0213_to_ucs4 (0x100 - 0x80 + ch, ch2 ^ 0x80); \ + } \ \ - if (ch < 0x80) \ - { \ - /* It's a combining character. */ \ - uint32_t u1 = __jisx0213_to_ucs_combining[ch - 1][0]; \ - uint32_t u2 = __jisx0213_to_ucs_combining[ch - 1][1]; \ + if (ch == 0) \ + /* This is an illegal character. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ \ - /* See whether we have room for two characters. */ \ - if (outptr + 8 <= outend) \ + inptr = endp; \ + \ + if (ch < 0x80) \ { \ - inptr = endp; \ + /* It's a combining character. */ \ + uint32_t u1 = __jisx0213_to_ucs_combining[ch - 1][0]; \ + uint32_t u2 = __jisx0213_to_ucs_combining[ch - 1][1]; \ + \ put32 (outptr, u1); \ outptr += 4; \ - put32 (outptr, u2); \ - outptr += 4; \ - continue; \ - } \ - else \ - { \ + \ + /* See whether we have room for two characters. */ \ + if (outptr + 4 <= outend) \ + { \ + put32 (outptr, u2); \ + outptr += 4; \ + continue; \ + } \ + \ + /* Otherwise store only the first character now, and \ + put the second one into the queue. */ \ + *statep = u2 << 3; \ + /* Tell the caller why we terminate the loop. */ \ result = __GCONV_FULL_OUTPUT; \ break; \ } \ } \ - \ - inptr = endp; \ } \ - } \ - else \ - { \ - /* This is illegal. */ \ - STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + else \ + { \ + /* This is illegal. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + } \ } \ \ put32 (outptr, ch); \ diff --git a/iconvdata/gconv-modules b/iconvdata/gconv-modules index b351353..c5fc10e 100644 --- a/iconvdata/gconv-modules +++ b/iconvdata/gconv-modules @@ -1523,3 +1523,7 @@ module INTERNAL EUC-JISX0213// EUC-JISX0213 1 # from to module cost module Shift_JISX0213// INTERNAL SHIFT_JISX0213 1 module INTERNAL Shift_JISX0213// SHIFT_JISX0213 1 + +# from to module cost +module TSCII// INTERNAL TSCII 1 +module INTERNAL TSCII// TSCII 1 diff --git a/iconvdata/shift_jisx0213.c b/iconvdata/shift_jisx0213.c index d48d67e..119e001 100644 --- a/iconvdata/shift_jisx0213.c +++ b/iconvdata/shift_jisx0213.c @@ -67,7 +67,9 @@ *statep = saved_state -/* During UCS-4 to Shift_JISX0213 conversion, the COUNT element of the state +/* During Shift_JISX0213 to UCS-4 conversion, the COUNT element of the state + contains the last UCS-4 character, shifted by 3 bits. + During UCS-4 to Shift_JISX0213 conversion, the COUNT element of the state contains the last two bytes to be output, shifted by 3 bits. */ /* Since this is a stateful encoding we have to provide code which resets @@ -77,8 +79,17 @@ if (data->__statep->__count != 0) \ { \ if (FROM_DIRECTION) \ - /* We don't use shift states in the FROM_DIRECTION. */ \ - data->__statep->__count = 0; \ + { \ + if (__builtin_expect (outbuf + 4 <= outend, 1)) \ + { \ + /* Write out the last character. */ \ + *((uint32_t *) outbuf)++ = data->__statep->__count >> 3; \ + data->__statep->__count = 0; \ + } \ + else \ + /* We don't have enough room in the output buffer. */ \ + status = __GCONV_FULL_OUTPUT; \ + } \ else \ { \ if (__builtin_expect (outbuf + 2 <= outend, 1)) \ @@ -104,106 +115,116 @@ #define LOOPFCT FROM_LOOP #define BODY \ { \ - uint32_t ch = *inptr; \ + uint32_t ch; \ \ - if (ch < 0x80) \ - { \ - /* Plain ISO646-JP character. */ \ - if (__builtin_expect (ch == 0x5c, 0)) \ - ch = 0xa5; \ - else if (__builtin_expect (ch == 0x7e, 0)) \ - ch = 0x203e; \ - ++inptr; \ - } \ - else if (ch >= 0xa1 && ch <= 0xdf) \ + /* Determine whether there is a buffered character pending. */ \ + ch = *statep >> 3; \ + if (__builtin_expect (ch == 0, 1)) \ { \ - /* Half-width katakana. */ \ - ch += 0xfec0; \ - ++inptr; \ - } \ - else if ((ch >= 0x81 && ch <= 0x9f) || (ch >= 0xe0 && ch <= 0xfc)) \ - { \ - /* Two byte character. */ \ - uint32_t ch2; \ + /* No - so look at the next input byte. */ \ + ch = *inptr; \ \ - if (__builtin_expect (inptr + 1 >= inend, 0)) \ + if (ch < 0x80) \ { \ - /* The second byte is not available. */ \ - result = __GCONV_INCOMPLETE_INPUT; \ - break; \ + /* Plain ISO646-JP character. */ \ + if (__builtin_expect (ch == 0x5c, 0)) \ + ch = 0xa5; \ + else if (__builtin_expect (ch == 0x7e, 0)) \ + ch = 0x203e; \ + ++inptr; \ } \ - \ - ch2 = inptr[1]; \ - \ - /* The second byte must be in the range 0x{40..7E,80..FC}. */ \ - if (__builtin_expect (ch2 < 0x40 || ch2 == 0x7f || ch2 > 0xfc, 0)) \ + else if (ch >= 0xa1 && ch <= 0xdf) \ { \ - /* This is an illegal character. */ \ - STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + /* Half-width katakana. */ \ + ch += 0xfec0; \ + ++inptr; \ } \ - \ - /* Convert to row and column. */ \ - if (ch < 0xe0) \ - ch -= 0x81; \ - else \ - ch -= 0xc1; \ - if (ch2 < 0x80) \ - ch2 -= 0x40; \ - else \ - ch2 -= 0x41; \ - /* Now 0 <= ch <= 0x3b, 0 <= ch2 <= 0xbb. */ \ - ch = 2 * ch; \ - if (ch2 >= 0x5e) \ - ch2 -= 0x5e, ch++; \ - ch2 += 0x21; \ - if (ch >= 0x5e) \ + else if ((ch >= 0x81 && ch <= 0x9f) || (ch >= 0xe0 && ch <= 0xfc)) \ { \ - /* Handling of JISX 0213 plane 2 rows. */ \ - if (ch >= 0x67) \ - ch += 230; \ - else if (ch >= 0x63 || ch == 0x5f) \ - ch += 168; \ - else \ - ch += 162; \ - } \ - \ - ch = jisx0213_to_ucs4 (0x121 + ch, ch2); \ + /* Two byte character. */ \ + uint32_t ch2; \ \ - if (ch == 0) \ - { \ - /* This is an illegal character. */ \ - STANDARD_FROM_LOOP_ERR_HANDLER (1); \ - } \ + if (__builtin_expect (inptr + 1 >= inend, 0)) \ + { \ + /* The second byte is not available. */ \ + result = __GCONV_INCOMPLETE_INPUT; \ + break; \ + } \ \ - if (ch < 0x80) \ - { \ - /* It's a combining character. */ \ - uint32_t u1 = __jisx0213_to_ucs_combining[ch - 1][0]; \ - uint32_t u2 = __jisx0213_to_ucs_combining[ch - 1][1]; \ + ch2 = inptr[1]; \ \ - /* See whether we have room for two characters. */ \ - if (outptr + 8 <= outend) \ + /* The second byte must be in the range 0x{40..7E,80..FC}. */ \ + if (__builtin_expect (ch2 < 0x40 || ch2 == 0x7f || ch2 > 0xfc, 0))\ { \ - inptr += 2; \ - put32 (outptr, u1); \ - outptr += 4; \ - put32 (outptr, u2); \ - outptr += 4; \ - continue; \ + /* This is an illegal character. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ } \ + \ + /* Convert to row and column. */ \ + if (ch < 0xe0) \ + ch -= 0x81; \ + else \ + ch -= 0xc1; \ + if (ch2 < 0x80) \ + ch2 -= 0x40; \ else \ + ch2 -= 0x41; \ + /* Now 0 <= ch <= 0x3b, 0 <= ch2 <= 0xbb. */ \ + ch = 2 * ch; \ + if (ch2 >= 0x5e) \ + ch2 -= 0x5e, ch++; \ + ch2 += 0x21; \ + if (ch >= 0x5e) \ { \ + /* Handling of JISX 0213 plane 2 rows. */ \ + if (ch >= 0x67) \ + ch += 230; \ + else if (ch >= 0x63 || ch == 0x5f) \ + ch += 168; \ + else \ + ch += 162; \ + } \ + \ + ch = jisx0213_to_ucs4 (0x121 + ch, ch2); \ + \ + if (ch == 0) \ + { \ + /* This is an illegal character. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + } \ + \ + inptr += 2; \ + \ + if (ch < 0x80) \ + { \ + /* It's a combining character. */ \ + uint32_t u1 = __jisx0213_to_ucs_combining[ch - 1][0]; \ + uint32_t u2 = __jisx0213_to_ucs_combining[ch - 1][1]; \ + \ + put32 (outptr, u1); \ + outptr += 4; \ + \ + /* See whether we have room for two characters. */ \ + if (outptr + 4 <= outend) \ + { \ + put32 (outptr, u2); \ + outptr += 4; \ + continue; \ + } \ + \ + /* Otherwise store only the first character now, and \ + put the second one into the queue. */ \ + *statep = u2 << 3; \ + /* Tell the caller why we terminate the loop. */ \ result = __GCONV_FULL_OUTPUT; \ break; \ } \ } \ - \ - inptr += 2; \ - } \ - else \ - { \ - /* This is illegal. */ \ - STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + else \ + { \ + /* This is illegal. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + } \ } \ \ put32 (outptr, ch); \ diff --git a/iconvdata/testdata/TSCII b/iconvdata/testdata/TSCII new file mode 100644 index 0000000..51691e1 --- /dev/null +++ b/iconvdata/testdata/TSCII @@ -0,0 +1,27 @@ + + + + + + + + + + + + + ¡ ¢ £ ¡ ¡ ª + á â ã á á ê + ġ Ģ ģ ġ ġ Ī + š Ţ ţ š š Ū + ơ Ƣ ƣ ơ ơ ƪ + ȡ Ȣ ȣ ȡ ȡ Ȫ + ɡ ɢ ɣ ɡ ɡ ɪ + + + + + + + + diff --git a/iconvdata/testdata/TSCII..UTF8 b/iconvdata/testdata/TSCII..UTF8 new file mode 100644 index 0000000..28f15ae --- /dev/null +++ b/iconvdata/testdata/TSCII..UTF8 @@ -0,0 +1,27 @@ +அ ஆ இ ஈ உ ஊ எ ஏ ஒ ஓ ஔ ஃ + +க கா கி கீ கு கூ கெ கே கை கொ கோ கௌ +ங ஙா ஙி ஙீ ஙு ஙூ ஙெ ஙே ஙை ஙொ ஙொ ஙௌ +ச சா சி சீ சு சூ செ சே சை சொ சோ சௌ +ஞ ஞா ஞி ஞீ ஞு ஞூ ஞெ ஞே ஞை ஞொ ஞோ ஞௌ +ட டா டி டீ டு டூ டெ டே டை டொ டோ டௌ +ண ணா ணி ணீ ணு ணூ ணெ ணே ணை ணொ ணோ ணௌ +த தா தி தீ து தூ தெ தே தை தொ தோ தௌ +ந நா நி நீ நு நூ நெ நே நை நொ நோ நௌ +ப பா பி பீ பு பூ பெ பே பை பொ போ பௌ +ம மா மி மீ மு மூ மெ மே மை மொ மோ மௌ +ய யா யி யீ யு யூ யெ யே யை யொ யோ யௌ +ர ரா ரி ரீ ரு ரூ ரெ ரே ரை ரொ ரோ ரௌ +ல லா லி லீ லு லூ லெ லே லை லொ லோ லௌ +வ வா வி வீ வு வூ வெ வே வை வொ வோ வௌ +ழ ழா ழி ழீ ழு ழூ ழெ ழே ழை ழொ ழோ ழௌ +ற றா றி றீ று றூ றெ றே றை றொ றோ றௌ +ன னா னி னீ னு னூ னெ னே னை னொ னோ னௌ + +ஸ்ரீ + +ஜ ஜா ஜி ஜீ ஜு ஜூ ெஜ ேஜ ைஜ ெஜா ேஜா ெஜௗ +ஷ ஷா ஷி ஷீ ஷு ஷூ ெஷ ேஷ ைஷ ெஷா ேஷா ெஷௗ +ஸ ஸா ஸி ஸீ ஸு ஸூ ெஸ ேஸ ைஸ ெஸா ேஸா ெஸௗ +ஹ ஹா ஹி ஹீ ஹு ஹூ ெஹ ேஹ ைஹ ெஹா ேஹா ெஹௗ +க்ஷ க்ஷா க்ஷி க்ஷீ க்ஷூ க்ஷூ ெக்ஷ ேக்ஷ ைக்ஷ ெக்ஷா ேக்ஷா ெக்ஷௗ diff --git a/iconvdata/tscii.c b/iconvdata/tscii.c new file mode 100644 index 0000000..66e4062 --- /dev/null +++ b/iconvdata/tscii.c @@ -0,0 +1,851 @@ +/* Conversion from and to TSCII. + Copyright (C) 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Bruno Haible <bruno@clisp.org>, 2002. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dlfcn.h> +#include <stdint.h> +#include <gconv.h> +#include <assert.h> + +/* TSCII is an 8-bit encoding consisting of: + 0x00..0x7F: ASCII + 0x80..0x90, 0x95..0x9F, 0xAB..0xFE: + Tamil letters and glyphs + 0xA1..0xA5, 0xAA: Tamil combining letters (after the base character) + 0xA6..0xA8: Tamil combining letters (before the base character) + 0x91..0x94: Punctuation + 0xA9: Symbols +*/ + +/* Definitions used in the body of the `gconv' function. */ +#define CHARSET_NAME "TSCII//" +#define FROM_LOOP from_tscii +#define TO_LOOP to_tscii +#define DEFINE_INIT 1 +#define DEFINE_FINI 1 +#define FROM_LOOP_MIN_NEEDED_FROM 1 +#define FROM_LOOP_MAX_NEEDED_FROM 2 +#define FROM_LOOP_MIN_NEEDED_TO 4 +#define FROM_LOOP_MAX_NEEDED_TO 16 +#define TO_LOOP_MIN_NEEDED_FROM 4 +#define TO_LOOP_MAX_NEEDED_FROM 4 +#define TO_LOOP_MIN_NEEDED_TO 1 +#define TO_LOOP_MAX_NEEDED_TO 3 +#define PREPARE_LOOP \ + int saved_state; \ + int *statep = &data->__statep->__count; +#define EXTRA_LOOP_ARGS , statep + + +/* Since we might have to reset input pointer we must be able to save + and restore the state. */ +#define SAVE_RESET_STATE(Save) \ + if (Save) \ + saved_state = *statep; \ + else \ + *statep = saved_state + + +/* During TSCII to UCS-4 conversion, the COUNT element of the state contains + the last UCS-4 character to be output, shifted by 8 bits, and an encoded + representation of additional UCS-4 characters to be output (if any), + shifted by 4 bits. This character can be: + 0x0000 Nothing pending. + 0x0BCD Pending VIRAMA sign. If bit 3 is set, it may be + omitted if followed by a vowel sign U or UU. + 0x0BC6, 0x0BC7, 0x0BC8 Pending vowel sign. Bit 3 is set after the + consonant was seen. + Other Bit 3 always cleared. */ + +/* During UCS-4 to TSCII conversion, the COUNT element of the state contains + the last byte (or sometimes the last two bytes) to be output, shifted by + 3 bits. This can be: + 0x00 Nothing pending. + 0xB8..0xC9, 0x83..0x86 A consonant. + 0xEC, 0x8A A consonant with VIRAMA sign (final or joining). + 0x87, 0xC38A Two consonants combined through a VIRAMA sign. */ + +/* Since this is a stateful encoding we have to provide code which resets + the output state to the initial state. This has to be done during the + flushing. */ +#define EMIT_SHIFT_TO_INIT \ + if (data->__statep->__count != 0) \ + { \ + if (FROM_DIRECTION) \ + { \ + do \ + { \ + if (__builtin_expect (outbuf + 4 > outend, 0)) \ + { \ + /* We don't have enough room in the output buffer. */ \ + status = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + /* Write out the pending character. */ \ + *((uint32_t *) outbuf)++ = data->__statep->__count >> 8; \ + /* Retrieve the successor state. */ \ + data->__statep->__count = \ + tscii_next_state[(data->__statep->__count >> 4) & 0x0f]; \ + } \ + while (data->__statep->__count != 0); \ + } \ + else \ + { \ + uint32_t last = data->__statep->__count >> 3; \ + if (__builtin_expect (last >> 8, 0)) \ + { \ + /* Write out the last character, two bytes. */ \ + if (__builtin_expect (outbuf + 2 <= outend, 1)) \ + { \ + *outbuf++ = last & 0xff; \ + *outbuf++ = (last >> 8) & 0xff; \ + data->__statep->__count = 0; \ + } \ + else \ + /* We don't have enough room in the output buffer. */ \ + status = __GCONV_FULL_OUTPUT; \ + } \ + else \ + { \ + /* Write out the last character, a single byte. */ \ + if (__builtin_expect (outbuf < outend, 1)) \ + { \ + *outbuf++ = last & 0xff; \ + data->__statep->__count = 0; \ + } \ + else \ + /* We don't have enough room in the output buffer. */ \ + status = __GCONV_FULL_OUTPUT; \ + } \ + } \ + } + + +/* First define the conversion function from TSCII to UCS-4. */ + +static const uint16_t tscii_to_ucs4[128][2] = + { + { 0x0BE6, 0 }, + { 0x0BE7, 0 }, + { 0, 0 }, /* 0x82 - maps to <U0BB8><U0BCD><U0BB0><U0BC0> */ + { 0x0B9C, 0 }, + { 0x0BB7, 0 }, + { 0x0BB8, 0 }, + { 0x0BB9, 0 }, + { 0, 0 }, /* 0x87 - maps to <U0B95><U0BCD><U0BB7> */ + { 0x0B9C, 0x0BCD }, + { 0x0BB7, 0x0BCD }, + { 0, 0 }, /* 0x8a - maps to <U0BB8> and buffers <U0BCD> */ + { 0, 0 }, /* 0x8b - maps to <U0BB9> and buffers <U0BCD> */ + { 0, 0 }, /* 0x8c - maps to <U0B95><U0BCD><U0BB7><U0BCD> */ + { 0x0BE8, 0 }, + { 0x0BE9, 0 }, + { 0x0BEA, 0 }, + { 0x0BEB, 0 }, + { 0x2018, 0 }, + { 0x2019, 0 }, + { 0x201C, 0 }, + { 0x201D, 0 }, + { 0x0BEC, 0 }, + { 0x0BED, 0 }, + { 0x0BEE, 0 }, + { 0x0BEF, 0 }, + { 0x0B99, 0x0BC1 }, + { 0x0B9E, 0x0BC1 }, + { 0x0B99, 0x0BC2 }, + { 0x0B9E, 0x0BC2 }, + { 0x0BF0, 0 }, + { 0x0BF1, 0 }, + { 0x0BF2, 0 }, + { 0, 0 }, /* 0xa0 - unmapped */ + { 0x0BBE, 0 }, + { 0x0BBF, 0 }, + { 0x0BC0, 0 }, + { 0x0BC1, 0 }, + { 0x0BC2, 0 }, + { 0, 0 }, /* 0xa6 - buffers <U0BC6> */ + { 0, 0 }, /* 0xa7 - buffers <U0BC7> */ + { 0, 0 }, /* 0xa8 - buffers <U0BC8> */ + { 0x00A9, 0 }, + { 0x0BD7, 0 }, + { 0x0B85, 0 }, + { 0x0B86, 0 }, + { 0x0B87, 0 }, + { 0x0B88, 0 }, + { 0x0B89, 0 }, + { 0x0B8A, 0 }, + { 0x0B8E, 0 }, + { 0x0B8F, 0 }, + { 0x0B90, 0 }, + { 0x0B92, 0 }, + { 0x0B93, 0 }, + { 0x0B94, 0 }, + { 0x0B83, 0 }, + { 0x0B95, 0 }, + { 0x0B99, 0 }, + { 0x0B9A, 0 }, + { 0x0B9E, 0 }, + { 0x0B9F, 0 }, + { 0x0BA3, 0 }, + { 0x0BA4, 0 }, + { 0x0BA8, 0 }, + { 0x0BAA, 0 }, + { 0x0BAE, 0 }, + { 0x0BAF, 0 }, + { 0x0BB0, 0 }, + { 0x0BB2, 0 }, + { 0x0BB5, 0 }, + { 0x0BB4, 0 }, + { 0x0BB3, 0 }, + { 0x0BB1, 0 }, + { 0x0BA9, 0 }, + { 0x0B9F, 0x0BBF }, + { 0x0B9F, 0x0BC0 }, + { 0x0B95, 0x0BC1 }, + { 0x0B9A, 0x0BC1 }, + { 0x0B9F, 0x0BC1 }, + { 0x0BA3, 0x0BC1 }, + { 0x0BA4, 0x0BC1 }, + { 0x0BA8, 0x0BC1 }, + { 0x0BAA, 0x0BC1 }, + { 0x0BAE, 0x0BC1 }, + { 0x0BAF, 0x0BC1 }, + { 0x0BB0, 0x0BC1 }, + { 0x0BB2, 0x0BC1 }, + { 0x0BB5, 0x0BC1 }, + { 0x0BB4, 0x0BC1 }, + { 0x0BB3, 0x0BC1 }, + { 0x0BB1, 0x0BC1 }, + { 0x0BA9, 0x0BC1 }, + { 0x0B95, 0x0BC2 }, + { 0x0B9A, 0x0BC2 }, + { 0x0B9F, 0x0BC2 }, + { 0x0BA3, 0x0BC2 }, + { 0x0BA4, 0x0BC2 }, + { 0x0BA8, 0x0BC2 }, + { 0x0BAA, 0x0BC2 }, + { 0x0BAE, 0x0BC2 }, + { 0x0BAF, 0x0BC2 }, + { 0x0BB0, 0x0BC2 }, + { 0x0BB2, 0x0BC2 }, + { 0x0BB5, 0x0BC2 }, + { 0x0BB4, 0x0BC2 }, + { 0x0BB3, 0x0BC2 }, + { 0x0BB1, 0x0BC2 }, + { 0x0BA9, 0x0BC2 }, + { 0x0B95, 0x0BCD }, + { 0x0B99, 0x0BCD }, + { 0x0B9A, 0x0BCD }, + { 0x0B9E, 0x0BCD }, + { 0x0B9F, 0x0BCD }, + { 0x0BA3, 0x0BCD }, + { 0x0BA4, 0x0BCD }, + { 0x0BA8, 0x0BCD }, + { 0x0BAA, 0x0BCD }, + { 0x0BAE, 0x0BCD }, + { 0x0BAF, 0x0BCD }, + { 0x0BB0, 0x0BCD }, + { 0x0BB2, 0x0BCD }, + { 0x0BB5, 0x0BCD }, + { 0x0BB4, 0x0BCD }, + { 0x0BB3, 0x0BCD }, + { 0x0BB1, 0x0BCD }, + { 0x0BA9, 0x0BCD }, + { 0x0B87, 0 }, + { 0, 0 } /* 0xff - unmapped */ + }; + +static const uint32_t tscii_next_state[6] = + { + /* 0 means no more pending Unicode characters. */ + 0, + /* 1 means <U0BB7>. */ + (0x0BB7 << 8), + /* 2 means <U0BC0>. */ + (0x0BC0 << 8), + /* 3 means <U0BCD>. */ + (0x0BCD << 8), + /* 4 means <U0BB0><U0BC0>. */ + (0x0BB0 << 8) + (2 << 4), + /* 5 means <U0BB7><U0BCD>. */ + (0x0BB7 << 8) + (3 << 4) + }; + +#define MIN_NEEDED_INPUT FROM_LOOP_MIN_NEEDED_FROM +#define MAX_NEEDED_INPUT FROM_LOOP_MAX_NEEDED_FROM +#define MIN_NEEDED_OUTPUT FROM_LOOP_MIN_NEEDED_TO +#define MAX_NEEDED_OUTPUT FROM_LOOP_MAX_NEEDED_TO +#define LOOPFCT FROM_LOOP +#define BODY \ + { \ + uint32_t ch = *inptr; \ + \ + if ((*statep >> 8) != 0) \ + { \ + /* Attempt to combine the last character with this one. */ \ + uint32_t last = *statep >> 8; \ + \ + if (last == 0x0BCD && (*statep & (1 << 3))) \ + { \ + if (ch == 0xa4 || ch == 0xa5) \ + { \ + ch += 0xb1d; \ + /* Now ch = 0x0BC1 or ch = 0x0BC2. */ \ + put32 (outptr, ch); \ + outptr += 4; \ + *statep = 0; \ + inptr++; \ + continue; \ + } \ + } \ + else if (last >= 0x0BC6 && last <= 0x0BC8) \ + { \ + if ((last == 0x0BC6 && ch == 0xa1) \ + || (last == 0x0BC7 && (ch == 0xa1 || ch == 0xaa))) \ + { \ + ch = last + 4 + (ch != 0xa1); \ + /* Now ch = 0x0BCA or ch = 0x0BCB or ch = 0x0BCC. */ \ + put32 (outptr, ch); \ + outptr += 4; \ + *statep = 0; \ + inptr++; \ + continue; \ + } \ + if ((ch >= 0xb8 && ch <= 0xc9) && (*statep & (1 << 3)) == 0) \ + { \ + ch = tscii_to_ucs4[ch - 0x80][0]; \ + put32 (outptr, ch); \ + outptr += 4; \ + *statep |= 1 << 3; \ + inptr++; \ + continue; \ + } \ + } \ + \ + do \ + { \ + /* Output the buffered character. */ \ + put32 (outptr, last); \ + outptr += 4; \ + /* Retrieve the successor state. */ \ + *statep = tscii_next_state[(*statep >> 4) & 0x0f]; \ + } \ + while (*statep != 0 && __builtin_expect (outptr + 4 <= outend, 1)); \ + \ + if (*statep != 0) \ + { \ + /* We don't have enough room in the output buffer. \ + Tell the caller why we terminate the loop. */ \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + \ + continue; \ + } \ + \ + if (ch < 0x80) \ + { \ + /* Plain ASCII character. */ \ + put32 (outptr, ch); \ + outptr += 4; \ + } \ + else \ + { \ + /* Tamil character. */ \ + uint32_t u1 = tscii_to_ucs4[ch - 0x80][0]; \ + \ + if (u1 != 0) \ + { \ + uint32_t u2 = tscii_to_ucs4[ch - 0x80][1]; \ + \ + inptr++; \ + \ + put32 (outptr, u1); \ + outptr += 4; \ + \ + if (u2 != 0) \ + { \ + /* See whether we have room for two characters. Otherwise \ + store only the first character now, and put the second \ + one into the queue. */ \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = u2 << 8; \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, u2); \ + outptr += 4; \ + } \ + continue; \ + } \ + /* Special handling of a few Tamil characters. */ \ + else if (ch == 0xa6 || ch == 0xa7 || ch == 0xa8) \ + { \ + ch += 0x0b20; \ + /* Now ch = 0x0BC6 or ch = 0x0BC7 or ch = 0x0BC8. */ \ + *statep = ch << 8; \ + inptr++; \ + continue; \ + } \ + else if (ch == 0x8a || ch == 0x8b) \ + { \ + ch += 0x0b2e; \ + /* Now ch = 0x0BB8 or ch = 0x0BB9. */ \ + put32 (outptr, ch); \ + outptr += 4; \ + *statep = (0x0BCD << 8) + (1 << 3); \ + inptr++; \ + continue; \ + } \ + else if (ch == 0x82) \ + { \ + /* Output <U0BB8><U0BCD><U0BB0><U0BC0>, if we have room for \ + four characters. */ \ + inptr++; \ + put32 (outptr, 0x0BB8); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BCD << 8) + (4 << 4); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BCD); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BB0 << 8) + (2 << 4); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BB0); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BC0 << 8); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BC0); \ + outptr += 4; \ + continue; \ + } \ + else if (ch == 0x87) \ + { \ + /* Output <U0B95><U0BCD><U0BB7>, if we have room for \ + three characters. */ \ + inptr++; \ + put32 (outptr, 0x0B95); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BCD << 8) + (1 << 4); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BCD); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BB7 << 8); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BB7); \ + outptr += 4; \ + continue; \ + } \ + else if (ch == 0x8c) \ + { \ + /* Output <U0B95><U0BCD><U0BB7><U0BCD>, if we have room for \ + four characters. */ \ + inptr++; \ + put32 (outptr, 0x0B95); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BCD << 8) + (5 << 4); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BCD); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BB7 << 8) + (3 << 4); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BB7); \ + outptr += 4; \ + if (__builtin_expect (outptr + 4 > outend, 0)) \ + { \ + *statep = (0x0BCD << 8); \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + put32 (outptr, 0x0BCD); \ + outptr += 4; \ + continue; \ + } \ + else \ + { \ + /* This is illegal. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + } \ + } \ + \ + /* Now that we wrote the output increment the input pointer. */ \ + inptr++; \ + } +#define LOOP_NEED_FLAGS +#define EXTRA_LOOP_DECLS , int *statep +#include <iconv/loop.c> + + +/* Next, define the other direction, from UCS-4 to TSCII. */ + +static const uint8_t ucs4_to_tscii[128] = + { + 0, 0, 0, 0xb7, 0, 0xab, 0xac, 0xfe, /* 0x0B80..0x0B87 */ + 0xae, 0xaf, 0xb0, 0, 0, 0, 0xb1, 0xb2, /* 0x0B88..0x0B8F */ + 0xb3, 0, 0xb4, 0xb5, 0xb6, 0xb8, 0, 0, /* 0x0B90..0x0B97 */ + 0, 0xb9, 0xba, 0, 0x83, 0, 0xbb, 0xbc, /* 0x0B98..0x0B9F */ + 0, 0, 0, 0xbd, 0xbe, 0, 0, 0, /* 0x0BA0..0x0BA7 */ + 0xbf, 0xc9, 0xc0, 0, 0, 0, 0xc1, 0xc2, /* 0x0BA8..0x0BAF */ + 0xc3, 0xc8, 0xc4, 0xc7, 0xc6, 0xc5, 0, 0x84, /* 0x0BB0..0x0BB7 */ + 0x85, 0x86, 0, 0, 0, 0, 0xa1, 0xa2, /* 0x0BB8..0x0BBF */ + 0xa3, 0xa4, 0xa5, 0, 0, 0, 0xa6, 0xa7, /* 0x0BC0..0x0BC7 */ + 0xa8, 0, 0, 0, 0, 0, 0, 0, /* 0x0BC8..0x0BCF */ + 0, 0, 0, 0, 0, 0, 0, 0xaa, /* 0x0BD0..0x0BD7 */ + 0, 0, 0, 0, 0, 0, 0, 0, /* 0x0BD8..0x0BDF */ + 0, 0, 0, 0, 0, 0, 0x80, 0x81, /* 0x0BE0..0x0BE7 */ + 0x8d, 0x8e, 0x8f, 0x90, 0x95, 0x96, 0x97, 0x98, /* 0x0BE8..0x0BEF */ + 0x9d, 0x9e, 0x9f, 0, 0, 0, 0, 0, /* 0x0BF0..0x0BF7 */ + 0, 0, 0, 0, 0, 0, 0, 0 /* 0x0BF8..0x0BFF */ + }; + +static const uint8_t consonant_with_u[18] = + { + 0xcc, 0x99, 0xcd, 0x9a, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, + 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb + }; + +static const uint8_t consonant_with_uu[18] = + { + 0xdc, 0x9b, 0xdd, 0x9c, 0xde, 0xdf, 0xe0, 0xe1, 0xe2, + 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb + }; + +static const uint8_t consonant_with_virama[18] = + { + 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd + }; + +#define MIN_NEEDED_INPUT TO_LOOP_MIN_NEEDED_FROM +#define MAX_NEEDED_INPUT TO_LOOP_MAX_NEEDED_FROM +#define MIN_NEEDED_OUTPUT TO_LOOP_MIN_NEEDED_TO +#define MAX_NEEDED_OUTPUT TO_LOOP_MAX_NEEDED_TO +#define LOOPFCT TO_LOOP +#define BODY \ + { \ + uint32_t ch = get32 (inptr); \ + \ + if ((*statep >> 3) != 0) \ + { \ + /* Attempt to combine the last character with this one. */ \ + uint32_t last = *statep >> 3; \ + \ + if (last >= 0xb8 && last <= 0xc9) \ + { \ + if (ch == 0x0BC1) \ + { \ + *outptr++ = consonant_with_u[last - 0xb8]; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + if (ch == 0x0BC2) \ + { \ + *outptr++ = consonant_with_uu[last - 0xb8]; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + if (ch == 0x0BC6) \ + { \ + if (__builtin_expect (outptr + 2 <= outend, 1)) \ + { \ + *outptr++ = 0xa6; \ + *outptr++ = last; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + if (ch == 0x0BC7) \ + { \ + if (__builtin_expect (outptr + 2 <= outend, 1)) \ + { \ + *outptr++ = 0xa7; \ + *outptr++ = last; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + if (ch == 0x0BC8) \ + { \ + if (__builtin_expect (outptr + 2 <= outend, 1)) \ + { \ + *outptr++ = 0xa8; \ + *outptr++ = last; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + if (ch == 0x0BCA) \ + { \ + if (__builtin_expect (outptr + 3 <= outend, 1)) \ + { \ + *outptr++ = 0xa6; \ + *outptr++ = last; \ + *outptr++ = 0xa1; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + if (ch == 0x0BCB) \ + { \ + if (__builtin_expect (outptr + 3 <= outend, 1)) \ + { \ + *outptr++ = 0xa7; \ + *outptr++ = last; \ + *outptr++ = 0xa1; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + if (ch == 0x0BCC) \ + { \ + if (__builtin_expect (outptr + 3 <= outend, 1)) \ + { \ + *outptr++ = 0xa7; \ + *outptr++ = last; \ + *outptr++ = 0xaa; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + if (ch == 0x0BCD) \ + { \ + if (last != 0xb8) \ + { \ + *outptr++ = consonant_with_virama[last - 0xb8]; \ + *statep = 0; \ + } \ + else \ + *statep = 0xec << 3; \ + inptr += 4; \ + continue; \ + } \ + if (last == 0xbc && (ch == 0x0BBF || ch == 0x0BC0)) \ + { \ + *outptr++ = ch - 0x0af5; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + } \ + else if (last >= 0x83 && last <= 0x86) \ + { \ + if (last >= 0x85 && (ch == 0x0BC1 || ch == 0x0BC2)) \ + { \ + *outptr++ = last + 5; \ + *statep = 0; \ + continue; \ + } \ + if (ch == 0x0BCD) \ + { \ + if (last != 0x85) \ + { \ + *outptr++ = last + 5; \ + *statep = 0; \ + } \ + else \ + *statep = 0x8a << 3; \ + inptr += 4; \ + continue; \ + } \ + } \ + else if (last == 0xec) \ + { \ + if (ch == 0x0BB7) \ + { \ + *statep = 0x87 << 3; \ + inptr += 4; \ + continue; \ + } \ + } \ + else if (last == 0x8a) \ + { \ + if (ch == 0x0BB0) \ + { \ + *statep = 0xc38a << 3; \ + inptr += 4; \ + continue; \ + } \ + } \ + else if (last == 0x87) \ + { \ + if (ch == 0x0BCD) \ + { \ + *outptr++ = 0x8c; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + } \ + else \ + { \ + assert (last == 0xc38a); \ + if (ch == 0x0BC0) \ + { \ + *outptr++ = 0x82; \ + *statep = 0; \ + inptr += 4; \ + continue; \ + } \ + } \ + \ + /* Output the buffered character. */ \ + if (__builtin_expect (last >> 8, 0)) \ + { \ + if (__builtin_expect (outptr + 2 <= outend, 1)) \ + { \ + *outptr++ = last & 0xff; \ + *outptr++ = (last >> 8) & 0xff; \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + else \ + *outptr++ = last & 0xff; \ + *statep = 0; \ + continue; \ + } \ + \ + if (ch < 0x80) \ + /* Plain ASCII character. */ \ + *outptr++ = ch; \ + else if (ch >= 0x0B80 && ch <= 0x0BFF) \ + { \ + /* Tamil character. */ \ + uint8_t t = ucs4_to_tscii[ch - 0x0B80]; \ + \ + if (t != 0) \ + { \ + if ((t >= 0xb8 && t <= 0xc9) || (t >= 0x83 && t <= 0x86)) \ + *statep = (uint32_t) t << 3; \ + else \ + *outptr++ = t; \ + } \ + else if (ch >= 0x0BCA && ch <= 0x0BCC) \ + { \ + /* See whether we have room for two bytes. */ \ + if (__builtin_expect (outptr + 2 <= outend, 1)) \ + { \ + *outptr++ = (ch == 0x0BCA ? 0xa6 : 0xa7); \ + *outptr++ = (ch != 0x0BCC ? 0xa1 : 0xaa); \ + } \ + else \ + { \ + result = __GCONV_FULL_OUTPUT; \ + break; \ + } \ + } \ + else \ + { \ + /* Illegal character. */ \ + STANDARD_TO_LOOP_ERR_HANDLER (4); \ + } \ + } \ + else if (ch == 0x00A9) \ + *outptr++ = ch; \ + else if (ch == 0x2018 || ch == 0x2019) \ + *outptr++ = ch - 0x1f87; \ + else if (ch == 0x201C || ch == 0x201D) \ + *outptr++ = ch - 0x1f89; \ + else \ + { \ + UNICODE_TAG_HANDLER (ch, 4); \ + \ + /* Illegal character. */ \ + STANDARD_TO_LOOP_ERR_HANDLER (4); \ + } \ + \ + /* Now that we wrote the output increment the input pointer. */ \ + inptr += 4; \ + } +#define LOOP_NEED_FLAGS +#define EXTRA_LOOP_DECLS , int *statep +#include <iconv/loop.c> + + +/* Now define the toplevel functions. */ +#include <iconv/skeleton.c> diff --git a/iconvdata/tst-table-from.c b/iconvdata/tst-table-from.c index 084de5f..34ea793 100644 --- a/iconvdata/tst-table-from.c +++ b/iconvdata/tst-table-from.c @@ -57,7 +57,7 @@ hexbuf (unsigned char buf[], unsigned int buflen) return msg; } -/* Attempts to convert a byte buffer BUF (BUFLEN bytes) to OUT (6 bytes) +/* Attempts to convert a byte buffer BUF (BUFLEN bytes) to OUT (12 bytes) using the conversion descriptor CD. Returns the number of written bytes, or 0 if ambiguous, or -1 if invalid. */ static int @@ -66,7 +66,7 @@ try (iconv_t cd, unsigned char buf[], unsigned int buflen, unsigned char *out) const char *inbuf = (const char *) buf; size_t inbytesleft = buflen; char *outbuf = (char *) out; - size_t outbytesleft = 6; + size_t outbytesleft = 12; size_t result; iconv (cd, NULL, NULL, NULL, NULL); @@ -100,10 +100,10 @@ try (iconv_t cd, unsigned char buf[], unsigned int buflen, unsigned char *out) fprintf (stderr, "%s: inbytes = %ld, outbytes = %ld\n", hexbuf (buf, buflen), (long) (buflen - inbytesleft), - (long) (6 - outbytesleft)); + (long) (12 - outbytesleft)); exit (1); } - return 6 - outbytesleft; + return 12 - outbytesleft; } } @@ -111,7 +111,7 @@ try (iconv_t cd, unsigned char buf[], unsigned int buflen, unsigned char *out) static const char * utf8_decode (const unsigned char *out, unsigned int outlen) { - static char hexbuf[42]; + static char hexbuf[84]; char *p = hexbuf; while (outlen > 0) @@ -203,7 +203,7 @@ main (int argc, char *argv[]) search_depth = (strcmp (charset, "UTF-8") == 0 ? 3 : 4); { - unsigned char out[6]; + unsigned char out[12]; unsigned char buf[4]; unsigned int i0, i1, i2, i3; int result; diff --git a/iconvdata/tst-tables.sh b/iconvdata/tst-tables.sh index c1aaac5..e5bb7f0 100755 --- a/iconvdata/tst-tables.sh +++ b/iconvdata/tst-tables.sh @@ -202,6 +202,7 @@ cat <<EOF | MAC-SAMI ARMSCII-8 TCVN5712-1 + TSCII # # Multibyte encodings come here # |