diff options
author | Ulrich Drepper <drepper@redhat.com> | 2000-03-21 20:18:34 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 2000-03-21 20:18:34 +0000 |
commit | 8d617a716df0ed5fd9ea1c8e65dd8e59b168573e (patch) | |
tree | 9bae23f82c38958c166ca3d65bb308f52ab2d14c /iconv | |
parent | bc4831b956f96efd9f4185b739b8ce8f3fa4dae6 (diff) | |
download | glibc-8d617a716df0ed5fd9ea1c8e65dd8e59b168573e.tar glibc-8d617a716df0ed5fd9ea1c8e65dd8e59b168573e.tar.gz glibc-8d617a716df0ed5fd9ea1c8e65dd8e59b168573e.tar.bz2 glibc-8d617a716df0ed5fd9ea1c8e65dd8e59b168573e.zip |
Update.
* iconv/gconv_builtin.c: Include <endian.h>.
* iconv/gconv_builtin.h: Add UCS-BE aliases.
Add UCS-4LE transformation. Define UNICODEBIG and UNICODELITTLE
according to current platform.
* iconv/gconv_int.h: Declare __gconv_transform_ucs2reverse_internal,
__gconv_transform_internal_ucs2reverse, and
__gconv_transform_internal_ucs4le.
* iconv/gconv_simple.c: Implement __gconv_transform_internal_ucs4le,
__gconv_transform_ucs2reverse_internal and
__gconv_transform_internal_ucs2reverse.
* iconvdata/Makefile (modules): Add UNICODE.
(distribute): Add unicode.c.
* iconvdata/gconv-modules: Add definitions for UNICODE module.
* iconvdata/unicode.c: New file.
* iconvdata/utf-16.c: Rewrite code to emit BOM. Correct code to
determine byte order of input and convert accordingly.
Diffstat (limited to 'iconv')
-rw-r--r-- | iconv/gconv_builtin.c | 3 | ||||
-rw-r--r-- | iconv/gconv_builtin.h | 56 | ||||
-rw-r--r-- | iconv/gconv_int.h | 3 | ||||
-rw-r--r-- | iconv/gconv_simple.c | 59 |
4 files changed, 106 insertions, 15 deletions
diff --git a/iconv/gconv_builtin.c b/iconv/gconv_builtin.c index ca3ca3e5e6..68c9f68c17 100644 --- a/iconv/gconv_builtin.c +++ b/iconv/gconv_builtin.c @@ -1,5 +1,5 @@ /* Table for builtin transformation mapping. - Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -18,6 +18,7 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <endian.h> #include <limits.h> #include <string.h> diff --git a/iconv/gconv_builtin.h b/iconv/gconv_builtin.h index 6e91a8646c..150457b223 100644 --- a/iconv/gconv_builtin.h +++ b/iconv/gconv_builtin.h @@ -20,12 +20,14 @@ BUILTIN_ALIAS ("UCS4//", "ISO-10646/UCS4/") BUILTIN_ALIAS ("UCS-4//", "ISO-10646/UCS4/") +BUILTIN_ALIAS ("UCS-4BE//", "ISO-10646/UCS4/") +BUILTIN_ALIAS ("CSUCS4//", "ISO-10646/UCS4/") BUILTIN_ALIAS ("ISO-10646//", "ISO-10646/UCS4/") BUILTIN_ALIAS ("10646-1:1993//", "ISO-10646/UCS4/") BUILTIN_ALIAS ("10646-1:1993/UCS4/", "ISO-10646/UCS4/") -BUILTIN_ALIAS ("OSF00010104//", "ISO-10646/UCS4/") -BUILTIN_ALIAS ("OSF00010105//", "ISO-10646/UCS4/") -BUILTIN_ALIAS ("OSF00010106//", "ISO-10646/UCS4/") +BUILTIN_ALIAS ("OSF00010104//", "ISO-10646/UCS4/") /* level 1 */ +BUILTIN_ALIAS ("OSF00010105//", "ISO-10646/UCS4/") /* level 2 */ +BUILTIN_ALIAS ("OSF00010106//", "ISO-10646/UCS4/") /* level 3 */ BUILTIN_TRANSFORMATION (NULL, "INTERNAL", 8, "ISO-10646/UCS4/", 1, "=INTERNAL->ucs4", @@ -37,6 +39,16 @@ BUILTIN_TRANSFORMATION (NULL, "ISO-10646/UCS4/", 15, 4, 4, 4, 4) /* Please note that we need only one function for both direction. */ +BUILTIN_TRANSFORMATION (NULL, "INTERNAL", 8, + "UCS-4LE//", 1, "=INTERNAL->ucs4le", + __gconv_transform_internal_ucs4le, NULL, NULL, + 4, 4, 4, 4) +BUILTIN_TRANSFORMATION (NULL, "UCS-4LE//", 15, + "INTERNAL", 1, "=ucs4le->INTERNAL", + __gconv_transform_internal_ucs4le, NULL, NULL, + 4, 4, 4, 4) +/* Please note that we need only one function for both direction. */ + BUILTIN_ALIAS ("UTF8//", "ISO-10646/UTF8/") BUILTIN_ALIAS ("UTF-8//", "ISO-10646/UTF8/") BUILTIN_ALIAS ("ISO-IR-193//", "ISO-10646/UTF8/") @@ -54,11 +66,9 @@ BUILTIN_TRANSFORMATION ("ISO-10646/UTF-?8/", "ISO-10646/UTF", 13, BUILTIN_ALIAS ("UCS2//", "ISO-10646/UCS2/") BUILTIN_ALIAS ("UCS-2//", "ISO-10646/UCS2/") -BUILTIN_ALIAS ("UNICODE//", "ISO-10646/UCS2/") -BUILTIN_ALIAS ("UNICODEBIG//", "ISO-10646/UCS2/") -BUILTIN_ALIAS ("OSF00010100//", "ISO-10646/UCS2/") -BUILTIN_ALIAS ("OSF00010101//", "ISO-10646/UCS2/") -BUILTIN_ALIAS ("OSF00010102//", "ISO-10646/UCS2/") +BUILTIN_ALIAS ("OSF00010100//", "ISO-10646/UCS2/") /* level 1 */ +BUILTIN_ALIAS ("OSF00010101//", "ISO-10646/UCS2/") /* level 2 */ +BUILTIN_ALIAS ("OSF00010102//", "ISO-10646/UCS2/") /* level 3 */ BUILTIN_TRANSFORMATION (NULL, "ISO-10646/UCS2/", 15, "INTERNAL", 1, "=ucs2->INTERNAL", @@ -71,12 +81,34 @@ BUILTIN_TRANSFORMATION (NULL, "INTERNAL", 8, "ISO-10646/UCS2/", 4, 4, 2, 2) +#if BYTE_ORDER == BIG_ENDIAN +BUILTIN_ALIAS ("UNICODEBIG//", "ISO-10646/UCS2/") +BUILTIN_ALIAS ("UCS-2BE//", "ISO-10646/UCS2/") + +BUILTIN_ALIAS ("UCS-2LE//", "UNICODELITTLE//") + BUILTIN_TRANSFORMATION (NULL, "UNICODELITTLE//", 15, "INTERNAL", - 1, "=ucs2little->INTERNAL", - __gconv_transform_ucs2little_internal, NULL, NULL, + 1, "=ucs2reverse->INTERNAL", + __gconv_transform_ucs2reverse_internal, NULL, NULL, 2, 2, 4, 4) BUILTIN_TRANSFORMATION (NULL, "INTERNAL", 8, "UNICODELITTLE//", - 1, "=INTERNAL->ucs2little", - __gconv_transform_internal_ucs2little, NULL, NULL, + 1, "=INTERNAL->ucs2reverse", + __gconv_transform_internal_ucs2reverse, NULL, NULL, + 4, 4, 2, 2) +#else +BUILTIN_ALIAS ("UNICODELITTLE//", "ISO-10646/UCS2/") +BUILTIN_ALIAS ("UCS-2LE//", "ISO-10646/UCS2/") + +BUILTIN_ALIAS ("UCS-2BE//", "UNICODEBIG//") + +BUILTIN_TRANSFORMATION (NULL, "UNICODEBIG//", 15, "INTERNAL", + 1, "=ucs2reverse->INTERNAL", + __gconv_transform_ucs2reverse_internal, NULL, NULL, + 2, 2, 4, 4) + +BUILTIN_TRANSFORMATION (NULL, "INTERNAL", 8, "UNICODEBIG//", + 1, "=INTERNAL->ucs2reverse", + __gconv_transform_internal_ucs2reverse, NULL, NULL, 4, 4, 2, 2) +#endif diff --git a/iconv/gconv_int.h b/iconv/gconv_int.h index da9e012794..6b81526594 100644 --- a/iconv/gconv_int.h +++ b/iconv/gconv_int.h @@ -169,9 +169,12 @@ __BUILTIN_TRANS (__gconv_transform_utf8_internal); __BUILTIN_TRANS (__gconv_transform_internal_utf8); __BUILTIN_TRANS (__gconv_transform_ucs2_internal); __BUILTIN_TRANS (__gconv_transform_internal_ucs2); +__BUILTIN_TRANS (__gconv_transform_ucs2reverse_internal); +__BUILTIN_TRANS (__gconv_transform_internal_ucs2reverse); __BUILTIN_TRANS (__gconv_transform_ucs2little_internal); __BUILTIN_TRANS (__gconv_transform_internal_ucs2little); __BUILTIN_TRANS (__gconv_transform_internal_ucs4); +__BUILTIN_TRANS (__gconv_transform_internal_ucs4le); __BUILTIN_TRANS (__gconv_transform_internal_utf16); __BUILTIN_TRANS (__gconv_transform_utf16_internal); # undef __BUITLIN_TRANS diff --git a/iconv/gconv_simple.c b/iconv/gconv_simple.c index 31e7970847..89c0384b8d 100644 --- a/iconv/gconv_simple.c +++ b/iconv/gconv_simple.c @@ -105,6 +105,61 @@ internal_ucs4_loop (const unsigned char **inptrp, const unsigned char *inend, #include <iconv/skeleton.c> +/* Similarly for the other byte order. */ +#define DEFINE_INIT 0 +#define DEFINE_FINI 0 +#define MIN_NEEDED_FROM 4 +#define MIN_NEEDED_TO 4 +#define FROM_DIRECTION 1 +#define FROM_LOOP internal_ucs4le_loop +#define TO_LOOP internal_ucs4le_loop /* This is not used. */ +#define FUNCTION_NAME __gconv_transform_internal_ucs4le + + +static inline int +internal_ucs4le_loop (const unsigned char **inptrp, const unsigned char *inend, + unsigned char **outptrp, unsigned char *outend, + mbstate_t *state, void *data, size_t *converted) +{ + const unsigned char *inptr = *inptrp; + unsigned char *outptr = *outptrp; + size_t n_convert = MIN (inend - inptr, outend - outptr) / 4; + int result; + +#if __BYTE_ORDER == __BIG_ENDIAN + /* Sigh, we have to do some real work. */ + size_t cnt; + + for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4) + *((uint32_t *) outptr)++ = bswap_32 (*(uint32_t *) inptr); + + *inptrp = inptr; + *outptrp = outptr; +#elif __BYTE_ORDER == __LITTLE_ENDIAN + /* Simply copy the data. */ + *inptrp = inptr + n_convert * 4; + *outptrp = __mempcpy (outptr, inptr, n_convert * 4); +#else +# error "This endianess is not supported." +#endif + + /* Determine the status. */ + if (*outptrp == outend) + result = __GCONV_FULL_OUTPUT; + else if (*inptrp == inend) + result = __GCONV_EMPTY_INPUT; + else + result = __GCONV_INCOMPLETE_INPUT; + + if (converted != NULL) + converted += n_convert; + + return result; +} + +#include <iconv/skeleton.c> + + /* Convert from ISO 646-IRV to the internal (UCS4-like) format. */ #define DEFINE_INIT 0 #define DEFINE_FINI 0 @@ -408,7 +463,7 @@ internal_ucs4_loop (const unsigned char **inptrp, const unsigned char *inend, #define FROM_DIRECTION 1 #define FROM_LOOP ucs2little_internal_loop #define TO_LOOP ucs2little_internal_loop /* This is not used.*/ -#define FUNCTION_NAME __gconv_transform_ucs2little_internal +#define FUNCTION_NAME __gconv_transform_ucs2reverse_internal #define MIN_NEEDED_INPUT MIN_NEEDED_FROM #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO @@ -433,7 +488,7 @@ internal_ucs4_loop (const unsigned char **inptrp, const unsigned char *inend, #define FROM_DIRECTION 1 #define FROM_LOOP internal_ucs2little_loop #define TO_LOOP internal_ucs2little_loop /* This is not used.*/ -#define FUNCTION_NAME __gconv_transform_internal_ucs2little +#define FUNCTION_NAME __gconv_transform_internal_ucs2reverse #define MIN_NEEDED_INPUT MIN_NEEDED_FROM #define MIN_NEEDED_OUTPUT MIN_NEEDED_TO |