summaryrefslogtreecommitdiffstats
path: root/newlib/libc/iconv/ces/utf-8.c
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2004-06-25 20:33:28 +0000
committerJeff Johnston <jjohnstn@redhat.com>2004-06-25 20:33:28 +0000
commit660dade387b1e24665ea8826417b096df2f25e83 (patch)
tree611b5d25b92b226523a09d99f6dd4514acab5422 /newlib/libc/iconv/ces/utf-8.c
parent6778dc3f1a5e444c281bf39a3f199abde00478bd (diff)
downloadcygnal-660dade387b1e24665ea8826417b096df2f25e83.tar.gz
cygnal-660dade387b1e24665ea8826417b096df2f25e83.tar.bz2
cygnal-660dade387b1e24665ea8826417b096df2f25e83.zip
2004-06-25 Artem B. Bityuckiy <dedekind@oktetlabs.ru>
* acinclude.m4: Move iconv options into configure.in. * aclocal.m4: Regenerated. * configure: Ditto. * configure.in: Add iconv options. * newlib.hin: Add new iconv encodings and remove deleted ones. * doc/aclocal.m4: Regenerated. * doc/configure: Ditto. * iconvdata/aclocal.m4: Ditto. * iconvdata/configure: Ditto. * libc/iconv: Design change. New size-optimized ccs format. * libc/iconv/AUTHORS: Removed. * libc/iconv/COPYING: Ditto. * libc/iconv/README.ORIGINAL: Ditto. * libc/iconv/README.TODO: Ditto. * libc/iconv/charset.aliases: Ditto. * libc/iconv/encoding.aliases: New file. * libc/iconv/Makefile.am: Updated. * libc/iconv/Makefile.in: Regenerated. * libc/iconv/iconv.tex: Updated. * libc/iconv/ccs/Makefile.am: Ditto. * libc/iconv/ccs/Makefile.in: Regenerated. * libc/iconv/ccs/big5.c: Updated. * libc/iconv/ccs/cns11643_plane1.c: Ditto. * libc/iconv/ccs/cns11643_plane14.c: Ditto. * libc/iconv/ccs/cns11643_plane2.c: Ditto. * libc/iconv/ccs/cp775.c: Ditto. * libc/iconv/ccs/cp850.c: Ditto. * libc/iconv/ccs/cp852.c: Ditto. * libc/iconv/ccs/cp855.c: Ditto. * libc/iconv/ccs/cp866.c: Ditto. * libc/iconv/ccs/iso_8859_1.c: Ditto. * libc/iconv/ccs/README.CCS.SOURCES: Removed. * libc/iconv/ccs/gb_2312_80.c: Ditto. * libc/iconv/ccs/iconv_mktbl: Ditto. * libc/iconv/ccs/jis_x0201.c: Ditto. * libc/iconv/ccs/jis_x0208_1983.c: Ditto. * libc/iconv/ccs/shift_jis.c: Ditto. * libc/iconv/ccs/us_ascii.c: Ditto. * libc/iconv/ccs/ccs.h: New file. * libc/iconv/ccs/ccsbi.c: Ditto. * libc/iconv/ccs/ccsbi.h: Ditto. * libc/iconv/ccs/ccsnames.h: Ditto. * libc/iconv/ccs/iso_8859_10.c: Ditto. * libc/iconv/ccs/iso_8859_11.c: Ditto. * libc/iconv/ccs/iso_8859_13.c: Ditto. * libc/iconv/ccs/iso_8859_14.c: Ditto. * libc/iconv/ccs/iso_8859_3.c: Ditto. * libc/iconv/ccs/iso_8859_6.c: Ditto. * libc/iconv/ccs/iso_8859_7.c: Ditto. * libc/iconv/ccs/iso_8859_8.c: Ditto. * libc/iconv/ccs/iso_8859_9.c: Ditto. * libc/iconv/ccs/iso_ir_111.c: Ditto. * libc/iconv/ccs/jis_x0201_1976.c: Ditto. * libc/iconv/ccs/jis_x0208_1990.c: Ditto. * libc/iconv/ccs/koi8_ru.c: Ditto. * libc/iconv/ccs/koi8_uni.c: Ditto. * libc/iconv/ccs/mktbl.pl: Ditto. * libc/iconv/ccs/win_1250.c: Ditto. * libc/iconv/ccs/win_1251.c: Ditto. * libc/iconv/ccs/win_1252.c: Ditto. * libc/iconv/ccs/win_1253.c: Ditto. * libc/iconv/ccs/win_1254.c: Ditto. * libc/iconv/ccs/win_1255.c: Ditto. * libc/iconv/ccs/win_1256.c: Ditto. * libc/iconv/ccs/win_1257.c: Ditto. * libc/iconv/ccs/win_1258.c: Ditto. * libc/iconv/ccs/iso_8859_15.c * libc/iconv/ccs/iso_8859_2.c * libc/iconv/ccs/iso_8859_4.c * libc/iconv/ccs/iso_8859_5.c * libc/iconv/ccs/jis_x0212_1990.c * libc/iconv/ccs/koi8_r.c * libc/iconv/ccs/koi8_u.c * libc/iconv/ccs/ksx1001.c * libc/iconv/ccs/binary/gb_2312_80.cct: Removed. * libc/iconv/ccs/binary/jis_x0201.cct: Ditto. * libc/iconv/ccs/binary/shift_jis.cct: Ditto. * libc/iconv/ccs/binary/us_ascii.cct: Ditto. * libc/iconv/ccs/binary/jis_x0208_1983.cct: Ditto. * libc/iconv/ccs/binary/Makefile.am: Updated. * libc/iconv/ccs/binary/Makefile.in: Regenerated. * libc/iconv/ccs/binary/big5.cct: Updated. * libc/iconv/ccs/binary/cns11643_plane1.cct: Ditto. * libc/iconv/ccs/binary/cns11643_plane14.cct: Ditto. * libc/iconv/ccs/binary/cns11643_plane2.cct: Ditto. * libc/iconv/ccs/binary/cp775.cct: Updated.: Ditto. * libc/iconv/ccs/binary/cp850.cct: Ditto.: Ditto. * libc/iconv/ccs/binary/cp852.cct: Ditto.: Ditto. * libc/iconv/ccs/binary/cp855.cct: Ditto.: Ditto. * libc/iconv/ccs/binary/cp866.cct: Ditto.: Ditto. * libc/iconv/ccs/binary/iso_8859_1.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_15.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_4.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_5.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_2.cct: Ditto. * libc/iconv/ccs/binary/jis_x0212_1990.cct: Ditto. * libc/iconv/ccs/binary/koi8_r.cct: Ditto. * libc/iconv/ccs/binary/koi8_u.cct: Ditto. * libc/iconv/ccs/binary/ksx1001.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_10.cct: New file. * libc/iconv/ccs/binary/iso_8859_11.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_13.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_14.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_3.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_6.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_7.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_8.cct: Ditto. * libc/iconv/ccs/binary/iso_8859_9.cct: Ditto. * libc/iconv/ccs/binary/iso_ir_111.cct: Ditto. * libc/iconv/ccs/binary/jis_x0201_1976.cct: Ditto. * libc/iconv/ccs/binary/jis_x0208_1990.cct: Ditto. * libc/iconv/ccs/binary/koi8_ru.cct: Ditto. * libc/iconv/ccs/binary/koi8_uni.cct: Ditto. * libc/iconv/ccs/binary/win_1250.cct: Ditto. * libc/iconv/ccs/binary/win_1251.cct: Ditto. * libc/iconv/ccs/binary/win_1252.cct: Ditto. * libc/iconv/ccs/binary/win_1253.cct: Ditto. * libc/iconv/ccs/binary/win_1254.cct: Ditto. * libc/iconv/ccs/binary/win_1255.cct: Ditto. * libc/iconv/ccs/binary/win_1256.cct: Ditto. * libc/iconv/ccs/binary/win_1257.cct: Ditto. * libc/iconv/ccs/binary/win_1258.cct: Ditto. * libc/iconv/ces/Makefile.am: Updated. * libc/iconv/ces/Makefile.in: Regenerated. * libc/iconv/ces/ucs-2-internal.c: Updated. * libc/iconv/ces/ucs-4-internal.c: Ditto. * libc/iconv/ces/utf-16.c: Ditto. * libc/iconv/ces/utf-8.c: Ditto. * libc/iconv/ces/cesbi.c: New file. * libc/iconv/ces/cesbi.h: Ditto. * libc/iconv/ces/cesdeps.h: Ditto. * libc/iconv/ces/euc.c: Ditto. * libc/iconv/ces/mkdeps.pl: Ditto. * libc/iconv/ces/table-pcs.c: Ditto. * libc/iconv/ces/table.c: Ditto. * libc/iconv/ces/ucs-2.c: Ditto. * libc/iconv/ces/ucs-4.c: Ditto. * libc/iconv/ces/us-ascii.c: Ditto. * libc/iconv/ces/euc-jp.c: Removed. * libc/iconv/ces/euc-kr.c: Ditto. * libc/iconv/ces/euc-tw.c: Ditto. * libc/iconv/ces/gb2312.c: Ditto. * libc/iconv/ces/iso-10646-ucs-2.: Ditto.c * libc/iconv/ces/iso-10646-ucs-4.c: Ditto. * libc/iconv/lib/Makefile.am: Updated. * libc/iconv/lib/Makefile.in: Regenerated. * libc/iconv/lib/endian.h: Updated. * libc/iconv/lib/iconv.c: Ditto. * libc/iconv/lib/local.h: Ditto. * libc/iconv/lib/aliases.c: Removed. * libc/iconv/lib/bialiasesi.c: Ditto. * libc/iconv/lib/biccs.c: Ditto. * libc/iconv/lib/bices.c: Ditto. * libc/iconv/lib/ccs.c: Ditto. * libc/iconv/lib/ces.c: Ditto. * libc/iconv/lib/ces_euc.c: Ditto. * libc/iconv/lib/ces_iso2022.c: Ditto. * libc/iconv/lib/ces_table.c: Ditto. * libc/iconv/lib/converter.c: Ditto. * libc/iconv/lib/deps.h: Ditto. * libc/iconv/lib/aliasesbi.c: Ditto. * libc/iconv/lib/aliasesi.c: Ditto. * libc/iconv/lib/conv.h: Ditto. * libc/iconv/lib/encnames.h: Ditto. * libc/iconv/lib/encoding.deps: Ditto. * libc/iconv/lib/iconvnls.c: Ditto. * libc/iconv/lib/iconvnls.h: Ditto. * libc/iconv/lib/loaddata.c: Ditto. * libc/iconv/lib/nullconv.c: Ditto. * libc/iconv/lib/ucsconv.c: Ditto. * libc/iconv/lib/ucsconv.h: Ditto. * libc/include/iconv.h: Update copyright. * libc/*/aclocal.m4: Regenerated. * libc/*/configure: Ditto. * libm/*/aclocal.m4: Ditto. * libm/*/configure: Ditto.
Diffstat (limited to 'newlib/libc/iconv/ces/utf-8.c')
-rw-r--r--newlib/libc/iconv/ces/utf-8.c396
1 files changed, 253 insertions, 143 deletions
diff --git a/newlib/libc/iconv/ces/utf-8.c b/newlib/libc/iconv/ces/utf-8.c
index 157afc089..fda1e6e3b 100644
--- a/newlib/libc/iconv/ces/utf-8.c
+++ b/newlib/libc/iconv/ces/utf-8.c
@@ -1,6 +1,6 @@
-/*-
- * Copyright (c) 1999,2000
- * Konstantin Chuguev. All rights reserved.
+/*
+ * Copyright (c) 2003-2004, Artem B. Bityuckiy
+ * Copyright (c) 1999,2000, Konstantin Chuguev. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -22,166 +22,276 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
- *
- * iconv (Charset Conversion Library) v2.0
*/
-#include "../lib/deps.h"
+#include "cesbi.h"
+
+#if defined (ICONV_TO_UCS_CES_UTF_8) \
+ || defined (ICONV_FROM_UCS_CES_UTF_8)
-#ifdef _ICONV_CONVERTER_UTF_8
+#include <_ansi.h>
+#include <reent.h>
+#include <sys/types.h>
#include "../lib/local.h"
+#include "../lib/ucsconv.h"
-#define cont_byte(b) (((b) & 0x3F) | 0x80)
+#define UTF8_MB_CUR_MAX 6
+
+/*
+ * UTF-8 CES converter doesn't interpret BOM. Reject overlong sequences,
+ * U'FFFF, U'FFFE codes, UTF-16 surrogate codes and all codes > 0x7FFFFFFF.
+ */
-static ssize_t
-_DEFUN(convert_from_ucs, (ces, in, outbuf, outbytesleft),
- struct iconv_ces *ces _AND
- ucs_t in _AND
- unsigned char **outbuf _AND
- size_t *outbytesleft)
+#if defined (ICONV_FROM_UCS_CES_UTF_8)
+static size_t
+_DEFUN(convert_from_ucs, (data, in, outbuf, outbytesleft),
+ _VOID_PTR data _AND
+ register ucs4_t in _AND
+ unsigned char **outbuf _AND
+ size_t *outbytesleft)
{
- unsigned char *cp;
- int n;
- if (in == UCS_CHAR_NONE)
- return 1; /* No state reinitialization for table charsets */
- if (in < 0x80) {
- n = 1;
- } else if (in < 0x800) {
- n = 2;
- } else if (in < 0x10000) {
- n = 3;
- } else if (in < 0x200000) {
- n = 4;
- } else if (in < 0x4000000) {
- n = 5;
- } else if (in <= 0x7FFFFFFF) {
- n = 6;
- } else
- return -1;
- if (*outbytesleft < n)
- return 0;
- cp = *outbuf;
- switch (n) {
- case 1:
+ register unsigned char *cp;
+ register size_t bytes;
+
+ if ((in >= 0x0000D800 && in <= 0x0000DFFF)
+ || in > 0x7FFFFFFF || in == 0x0000FFFF || in == 0x0000FFFE)
+ return (size_t)ICONV_CES_INVALID_CHARACTER;
+
+ if (in < 0x80)
+ bytes = 1;
+ else if (in < 0x800)
+ bytes = 2;
+ else if (in < 0x10000)
+ bytes = 3;
+ else if (in < 0x200000)
+ bytes = 4;
+ else if (in < 0x4000000)
+ bytes = 5;
+ else
+ bytes = 6;
+
+ if (*outbytesleft < bytes)
+ return (size_t)ICONV_CES_NOSPACE;
+
+ cp = *outbuf;
+
+ switch (bytes)
+ {
+ case 1:
*cp = (unsigned char)in;
break;
- case 2:
- *cp++ = (unsigned char)((in >> 6) | 0xC0);
- *cp++ = (unsigned char)cont_byte(in);
+
+ case 2:
+ *cp++ = (unsigned char)((in >> 6) | 0x000000C0);
+ *cp++ = (unsigned char)((in & 0x0000003F) | 0x00000080);
break;
- case 3:
- *cp++ = (unsigned char)((in >> 12) | 0xE0);
- *cp++ = (unsigned char)cont_byte(in >> 6);
- *cp++ = (unsigned char)cont_byte(in);
+
+ case 3:
+ *cp++ = (unsigned char)((in >> 12) | 0x000000E0);
+ *cp++ = (unsigned char)(((in >> 6) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)((in & 0x0000003F) | 0x00000080);
break;
- case 4:
- *cp++ = (unsigned char)((in >> 18) | 0xF0);
- *cp++ = (unsigned char)cont_byte(in >> 12);
- *cp++ = (unsigned char)cont_byte(in >> 6);
- *cp++ = (unsigned char)cont_byte(in);
+
+ case 4:
+ *cp++ = (unsigned char)((in >> 18) | 0x000000F0);
+ *cp++ = (unsigned char)(((in >> 12) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)(((in >> 6) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)((in & 0x0000003F) | 0x00000080);
break;
- case 5:
- *cp++ = (unsigned char)((in >> 24) | 0xF8);
- *cp++ = (unsigned char)cont_byte(in >> 18);
- *cp++ = (unsigned char)cont_byte(in >> 12);
- *cp++ = (unsigned char)cont_byte(in >> 6);
- *cp++ = (unsigned char)cont_byte(in);
+
+ case 5:
+ *cp++ = (unsigned char)((in >> 24) | 0x000000F8);
+ *cp++ = (unsigned char)(((in >> 18) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)(((in >> 12) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)(((in >> 6) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)((in & 0x0000003F) | 0x00000080);
break;
- case 6:
- *cp++ = (unsigned char)((in >> 30) | 0xFC);
- *cp++ = (unsigned char)cont_byte(in >> 24);
- *cp++ = (unsigned char)cont_byte(in >> 18);
- *cp++ = (unsigned char)cont_byte(in >> 12);
- *cp++ = (unsigned char)cont_byte(in >> 6);
- *cp++ = (unsigned char)cont_byte(in);
+
+ case 6:
+ *cp++ = (unsigned char)((in >> 30) | 0x000000FC);
+ *cp++ = (unsigned char)(((in >> 24) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)(((in >> 18) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)(((in >> 12) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)(((in >> 6) & 0x0000003F) | 0x00000080);
+ *cp++ = (unsigned char)((in & 0x0000003F) | 0x00000080);
break;
}
- (*outbytesleft) -= n;
- (*outbuf) += n;
- return 1;
+
+ *outbytesleft -= bytes;
+ *outbuf += bytes;
+
+ return bytes;
}
+#endif /* ICONV_FROM_UCS_CES_UTF_8 */
-static ucs_t
-_DEFUN(convert_to_ucs, (ces, inbuf, inbytesleft),
- struct iconv_ces *ces _AND
+#if defined (ICONV_TO_UCS_CES_UTF_8)
+static ucs4_t
+_DEFUN(convert_to_ucs, (data, inbuf, inbytesleft),
+ _VOID_PTR data _AND
_CONST unsigned char **inbuf _AND
size_t *inbytesleft)
{
- _CONST unsigned char *in = *inbuf;
- unsigned char byte = *in++;
- ucs_t res = byte;
-
- if (byte >= 0xC0) {
- if (byte < 0xE0) {
- if (*inbytesleft < 2)
- return UCS_CHAR_NONE;
- if (((byte & ~0x1F) == 0xC0)
- && ((in[0] & 0xC0) == 0x80)) {
- res = ((byte & 0x1F) << 6) | (*in++ & 0x3F);
- } else
- res = UCS_CHAR_INVALID;
- } else if (byte < 0xF0) {
- if (*inbytesleft < 3)
- return UCS_CHAR_NONE;
- if (((byte & ~0x0F) == 0xE0)
- && ((in[0] & 0xC0) == 0x80)
- && ((in[1] & 0xC0) == 0x80)) {
- res = ((byte & 0x0F) << 12) | ((in[0] & 0x3F) << 6)
- | (in[1] & 0x3F);
- in += 2;
- } else
- res = UCS_CHAR_INVALID;
- } else if (byte < 0xF8) {
- if (*inbytesleft < 4)
- return UCS_CHAR_NONE;
- if (((byte & ~0x7) == 0xF0)
- && ((in[0] & 0xC0) == 0x80)
- && ((in[1] & 0xC0) == 0x80)
- && ((in[2] & 0xC0) == 0x80)) {
- res = ((byte & 0x7) << 18) | ((in[0] & 0x3F) << 12)
- | ((in[1] & 0x3F) << 6) | (in[2] & 0x3F);
- in += 3;
- } else
- res = UCS_CHAR_INVALID;
- } else if (byte < 0xFC) {
- if (*inbytesleft < 5)
- return UCS_CHAR_NONE;
- if (((byte & ~0x3) == 0xF8)
- && ((in[0] & 0xC0) == 0x80)
- && ((in[1] & 0xC0) == 0x80)
- && ((in[2] & 0xC0) == 0x80)
- && ((in[3] & 0xC0) == 0x80)) {
- res = ((byte & 0x3) << 24) | ((in[0] & 0x3F) << 18)
- | ((in[1] & 0x3F) << 12) | ((in[2] & 0x3F) << 8)
- | (in[3] & 0x3F);
- in += 4;
- } else
- res = UCS_CHAR_INVALID;
- } else if (byte <= 0xFD) {
- if (*inbytesleft < 6)
- return UCS_CHAR_NONE;
- if (((byte & ~0x1) == 0xFC)
- && ((in[0] & 0xC0) == 0x80)
- && ((in[1] & 0xC0) == 0x80)
- && ((in[2] & 0xC0) == 0x80)
- && ((in[3] & 0xC0) == 0x80)
- && ((in[4] & 0xC0) == 0x80)) {
- res = ((byte & 0x1) << 30) | ((in[0] & 0x3F) << 24)
- | ((in[1] & 0x3F) << 18) | ((in[2] & 0x3F) << 12)
- | ((in[3] & 0x3F) << 8) | (in[4] & 0x3F);
- in += 5;
- } else
- res = UCS_CHAR_INVALID;
- } else
- res = UCS_CHAR_INVALID;
- } else if (byte & 0x80)
- res = UCS_CHAR_INVALID;
-
- (*inbytesleft) -= (in - *inbuf);
- *inbuf = in;
- return res;
+ register _CONST unsigned char *in = *inbuf;
+ register size_t bytes;
+ ucs4_t res;
+
+ if (in[0] >= 0xC0)
+ {
+ if (in[0] < 0xE0)
+ {
+ if (*inbytesleft < (bytes = 2))
+ return (ucs4_t)ICONV_CES_BAD_SEQUENCE;
+
+ if ( ((in[0] & ~0x1F) == 0xC0)
+ && ((in[1] & 0xC0) == 0x80))
+ res = ((ucs4_t)(in[0] & 0x1F) << 6)
+ | ((ucs4_t)(in[1] & 0x3F));
+ else
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+
+ if (res < 0x00000080) /* Overlong sequence */
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+ }
+
+ else if (in[0] < 0xF0)
+ {
+ if (*inbytesleft < (bytes = 3))
+ return (ucs4_t)ICONV_CES_BAD_SEQUENCE;
+
+ if ( ((in[0] & ~0x0F) == 0xE0)
+ && ((in[1] & 0xC0) == 0x80)
+ && ((in[2] & 0xC0) == 0x80))
+ res = ((ucs4_t)(in[0] & 0x0F) << 12)
+ | ((ucs4_t)(in[1] & 0x3F) << 6)
+ | ((ucs4_t)(in[2] & 0x3F));
+ else
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+
+ if (res < 0x00000800) /* Overlong sequence */
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+ }
+
+ else if (in[0] < 0xF8)
+ {
+ if (*inbytesleft < (bytes = 4))
+ return (ucs4_t)ICONV_CES_BAD_SEQUENCE;
+
+ if ( ((in[0] & ~0x07) == 0xF0)
+ && ((in[1] & 0xC0) == 0x80)
+ && ((in[2] & 0xC0) == 0x80)
+ && ((in[3] & 0xC0) == 0x80))
+ res = ((ucs4_t)(in[0] & 0x07) << 18)
+ | ((ucs4_t)(in[1] & 0x3F) << 12)
+ | ((ucs4_t)(in[2] & 0x3F) << 6)
+ | ((ucs4_t)(in[3] & 0x3F));
+ else
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+
+ if (res < 0x00010000) /* Overlong sequence */
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+ }
+
+ else if (in[0] < 0xFC)
+ {
+ if (*inbytesleft < (bytes = 5))
+ return (ucs4_t)ICONV_CES_BAD_SEQUENCE;
+
+ if ( ((in[0] & ~0x03) == 0xF8)
+ && ((in[1] & 0xC0) == 0x80)
+ && ((in[2] & 0xC0) == 0x80)
+ && ((in[3] & 0xC0) == 0x80)
+ && ((in[4] & 0xC0) == 0x80))
+ res = ((ucs4_t)(in[0] & 0x03) << 24)
+ | ((ucs4_t)(in[1] & 0x3F) << 18)
+ | ((ucs4_t)(in[2] & 0x3F) << 12)
+ | ((ucs4_t)(in[3] & 0x3F) << 6)
+ | ((ucs4_t)(in[4] & 0x3F));
+ else
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+
+ if (res < 0x00200000) /* Overlong sequence */
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+ }
+
+ else if (in[0] <= 0xFD)
+ {
+ if (*inbytesleft < (bytes = 6))
+ return (ucs4_t)ICONV_CES_BAD_SEQUENCE;
+
+ if ( ((in[0] & ~0x01) == 0xFC)
+ && ((in[1] & 0xC0) == 0x80)
+ && ((in[2] & 0xC0) == 0x80)
+ && ((in[3] & 0xC0) == 0x80)
+ && ((in[4] & 0xC0) == 0x80)
+ && ((in[5] & 0xC0) == 0x80))
+ res = ((ucs4_t)(in[0] & 0x1) << 30)
+ | ((ucs4_t)(in[1] & 0x3F) << 24)
+ | ((ucs4_t)(in[2] & 0x3F) << 18)
+ | ((ucs4_t)(in[3] & 0x3F) << 12)
+ | ((ucs4_t)(in[4] & 0x3F) << 6)
+ | ((ucs4_t)(in[5] & 0x3F));
+ else
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+
+ if (res < 0x04000000) /* Overlong sequence */
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+ }
+
+ else
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+ }
+ else if (in[0] & 0x80)
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+ else
+ {
+ res = (ucs4_t)in[0];
+ bytes = 1;
+ }
+
+ if ( (res >= 0x0000D800 && res <= 0x0000DFFF)
+ || res > 0x7FFFFFFF || res == 0x0000FFFF || res == 0x0000FFFE)
+ return (ucs4_t)ICONV_CES_INVALID_CHARACTER;
+
+ *inbytesleft -= bytes;
+ *inbuf += bytes;
+
+ return res;
+}
+#endif /* ICONV_TO_UCS_CES_UTF_8 */
+
+static int
+_DEFUN(get_mb_cur_max, (data),
+ _VOID_PTR data)
+{
+ return UTF8_MB_CUR_MAX;
}
-ICONV_CES_STATELESS_MODULE_DECL(utf_8);
+#if defined (ICONV_TO_UCS_CES_UTF_8)
+_CONST iconv_to_ucs_ces_handlers_t
+_iconv_to_ucs_ces_handlers_utf_8 =
+{
+ NULL,
+ NULL,
+ get_mb_cur_max,
+ NULL,
+ NULL,
+ NULL,
+ convert_to_ucs
+};
+#endif
+
+#if defined (ICONV_FROM_UCS_CES_UTF_8)
+_CONST iconv_from_ucs_ces_handlers_t
+_iconv_from_ucs_ces_handlers_utf_8 =
+{
+ NULL,
+ NULL,
+ get_mb_cur_max,
+ NULL,
+ NULL,
+ NULL,
+ convert_from_ucs
+};
+#endif
-#endif /* #ifdef _ICONV_CONVERTER_UTF_8 */
+#endif /* ICONV_TO_UCS_CES_UTF_8 || ICONV_FROM_UCS_CES_UTF_8 */