diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | iconv/gconv_builtin.h | 23 | ||||
-rw-r--r-- | iconv/gconv_int.h | 4 | ||||
-rw-r--r-- | iconv/gconv_simple.c | 75 | ||||
-rw-r--r-- | wcsmbs/Makefile | 3 | ||||
-rw-r--r-- | wcsmbs/Versions | 3 | ||||
-rw-r--r-- | wcsmbs/c16rtomb.c | 121 | ||||
-rw-r--r-- | wcsmbs/mbrtoc16.c | 122 | ||||
-rw-r--r-- | wcsmbs/mbrtowc.c | 7 | ||||
-rw-r--r-- | wcsmbs/uchar.h | 8 | ||||
-rw-r--r-- | wcsmbs/wchar.h | 8 | ||||
-rw-r--r-- | wcsmbs/wcrtomb.c | 7 | ||||
-rw-r--r-- | wcsmbs/wcsmbsload.c | 90 | ||||
-rw-r--r-- | wcsmbs/wcsmbsload.h | 7 |
14 files changed, 478 insertions, 18 deletions
diff --git a/ChangeLog b/ChangeLog index ca936b38a7..dab8e3590d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -28,6 +28,24 @@ 2011-12-24 Ulrich Drepper <drepper@gmail.com> + * iconv/gconv_simple.c: Add ASCII<->UTF-16 transformations. + * iconv/gconv_builtin.h: Add entries for internal ASCII<->UTF-16 + transformations. + * iconv/gconv_int.h: Likewise. + * wcsmbs/Makefile (routines): Add mbrtoc16 and c16rtomb. + * wcsmbs/Versions: Export mbrtoc16, c16rtomb, mbrtoc32, c32rtomb + from libc for GLIBC_2.16. + * wcsmbs/mbrtowc.c: Define mbrtoc32 alias. + * wcsmbs/wcrtomb.c: Define c32rtomb alias. + * wcsmbs/uchar.h: Really define mbstate_t. + * wcsmbs/wchar.h: Allow defining mbstate_t in uchar.h. + * wcsmbs/c16rtomb.c: New file. + * wcsmbs/mbrtoc16.c: New file. + * wcsmbs/wcsmbsload.c: Add static definitions for c16 conversions + for C/POSIX locale. + (__wcsmbs_load_conv): Do not fill in c16 routines yet. + * wcsmbs/wcsmbsload.h (gconv_fcts): Add entries for c16 routines. + * wcsmbs/wchar.h: Add missing __restrict. 2011-12-23 Ulrich Drepper <drepper@gmail.com> diff --git a/iconv/gconv_builtin.h b/iconv/gconv_builtin.h index ef9ab8d7cf..fd736a480d 100644 --- a/iconv/gconv_builtin.h +++ b/iconv/gconv_builtin.h @@ -1,5 +1,5 @@ /* Builtin transformations. - Copyright (C) 1997-1999, 2000-2002, 2006 Free Software Foundation, Inc. + Copyright (C) 1997-1999, 2000-2002, 2006, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -122,3 +122,24 @@ BUILTIN_TRANSFORMATION ("INTERNAL", "UNICODEBIG//", 1, __gconv_transform_internal_ucs2reverse, NULL, 4, 4, 2, 2) #endif + + +BUILTIN_TRANSFORMATION ("ANSI_X3.4-1968//", "UTF-16//", 1, "=ascii->UTF-16", + __gconv_transform_ascii_utf16, NULL, 2, 2, 1, 1) + +BUILTIN_TRANSFORMATION ("UTF-16//", "ANSI_X3.4-1968//", 1, "=UTF-16->ascii", + __gconv_transform_utf16_ascii, NULL, 2, 2, 1, 1) + +#if BYTE_ORDER == BIG_ENDIAN +BUILTIN_TRANSFORMATION ("ANSI_X3.4-1968//", "UTF-16BE//", 1, "=ascii->UTF-16BE", + __gconv_transform_ascii_utf16, NULL, 2, 2, 1, 1) + +BUILTIN_TRANSFORMATION ("UTF-16BE//", "ANSI_X3.4-1968//", 1, "=UTF-16BE->ascii", + __gconv_transform_utf16_ascii, NULL, 2, 2, 1, 1) +#else +BUILTIN_TRANSFORMATION ("ANSI_X3.4-1968//", "UTF-16LE//", 1, "=ascii->UTF-16LE", + __gconv_transform_ascii_utf16, NULL, 2, 2, 1, 1) + +BUILTIN_TRANSFORMATION ("UTF-16LE//", "ANSI_X3.4-1968//", 1, "=UTF-16LE->ascii", + __gconv_transform_utf16_ascii, NULL, 2, 2, 1, 1) +#endif diff --git a/iconv/gconv_int.h b/iconv/gconv_int.h index fd112204bc..80253dd5be 100644 --- a/iconv/gconv_int.h +++ b/iconv/gconv_int.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1997-2005, 2006, 2007 Free Software Foundation, Inc. +/* Copyright (C) 1997-2005, 2006, 2007, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -303,6 +303,8 @@ __BUILTIN_TRANSFORM (__gconv_transform_internal_ucs4le); __BUILTIN_TRANSFORM (__gconv_transform_ucs4le_internal); __BUILTIN_TRANSFORM (__gconv_transform_internal_utf16); __BUILTIN_TRANSFORM (__gconv_transform_utf16_internal); +__BUILTIN_TRANSFORM (__gconv_transform_ascii_utf16); +__BUILTIN_TRANSFORM (__gconv_transform_utf16_ascii); # undef __BUITLIN_TRANSFORM /* Specialized conversion function for a single byte to INTERNAL, recognizing diff --git a/iconv/gconv_simple.c b/iconv/gconv_simple.c index e34f3770ad..b0ef3e67b0 100644 --- a/iconv/gconv_simple.c +++ b/iconv/gconv_simple.c @@ -1,5 +1,5 @@ /* Simple transformations functions. - Copyright (C) 1997-2005, 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-2005, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. @@ -965,7 +965,7 @@ ucs4le_internal_loop_single (struct __gconv_step *step, cnt = 2; \ ch &= 0x1f; \ } \ - else if (__builtin_expect ((ch & 0xf0) == 0xe0, 1)) \ + else if (__builtin_expect ((ch & 0xf0) == 0xe0, 1)) \ { \ /* We expect three bytes. */ \ cnt = 3; \ @@ -1221,7 +1221,7 @@ ucs4le_internal_loop_single (struct __gconv_step *step, else \ { \ put16 (outptr, val); \ - outptr += sizeof (uint16_t); \ + outptr += sizeof (uint16_t); \ inptr += 4; \ } \ } @@ -1320,3 +1320,72 @@ ucs4le_internal_loop_single (struct __gconv_step *step, #define LOOP_NEED_FLAGS #include <iconv/loop.c> #include <iconv/skeleton.c> + + +/* Convert from ISO 646-IRV to UTF-16. */ +#define DEFINE_INIT 0 +#define DEFINE_FINI 0 +#define MIN_NEEDED_FROM 1 +#define MIN_NEEDED_TO 2 +#define FROM_DIRECTION 1 +#define FROM_LOOP ascii_utf16_loop +#define TO_LOOP ascii_utf16_loop /* This is not used. */ +#define FUNCTION_NAME __gconv_transform_ascii_utf16 +#define ONE_DIRECTION 1 + +#define MIN_NEEDED_INPUT MIN_NEEDED_FROM +#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO +#define LOOPFCT FROM_LOOP +#define BODY \ + { \ + if (__builtin_expect (*inptr > '\x7f', 0)) \ + { \ + /* The value is too large. We don't try transliteration here since \ + this is not an error because of the lack of possibilities to \ + represent the result. This is a genuine bug in the input since \ + ASCII does not allow such values. */ \ + STANDARD_FROM_LOOP_ERR_HANDLER (1); \ + } \ + else \ + { \ + /* It's an one byte sequence. */ \ + *((uint16_t *) outptr) = *inptr++; \ + outptr += sizeof (uint16_t); \ + } \ + } +#define LOOP_NEED_FLAGS +#include <iconv/loop.c> +#include <iconv/skeleton.c> + + +/* Convert from UTF-16 to ISO 646-IRV. */ +#define DEFINE_INIT 0 +#define DEFINE_FINI 0 +#define MIN_NEEDED_FROM 2 +#define MIN_NEEDED_TO 1 +#define FROM_DIRECTION 1 +#define FROM_LOOP utf16_ascii_loop +#define TO_LOOP utf16_ascii_loop /* This is not used. */ +#define FUNCTION_NAME __gconv_transform_utf16_ascii +#define ONE_DIRECTION 1 + +#define MIN_NEEDED_INPUT MIN_NEEDED_FROM +#define MIN_NEEDED_OUTPUT MIN_NEEDED_TO +#define LOOPFCT FROM_LOOP +#define BODY \ + { \ + if (__builtin_expect (*((const uint16_t *) inptr) > 0x7f, 0)) \ + { \ + UNICODE_TAG_HANDLER (*((const uint16_t *) inptr), 2); \ + STANDARD_TO_LOOP_ERR_HANDLER (2); \ + } \ + else \ + { \ + /* It's an one byte sequence. */ \ + *outptr++ = *((const uint16_t *) inptr); \ + inptr += sizeof (uint16_t); \ + } \ + } +#define LOOP_NEED_FLAGS +#include <iconv/loop.c> +#include <iconv/skeleton.c> diff --git a/wcsmbs/Makefile b/wcsmbs/Makefile index 0bb1740838..8c446e1fd3 100644 --- a/wcsmbs/Makefile +++ b/wcsmbs/Makefile @@ -40,7 +40,8 @@ routines := wcscat wcschr wcscmp wcscpy wcscspn wcsdup wcslen wcsncat \ wcscasecmp wcsncase wcscasecmp_l wcsncase_l \ wcsmbsload mbsrtowcs_l \ isoc99_wscanf isoc99_vwscanf isoc99_fwscanf isoc99_vfwscanf \ - isoc99_swscanf isoc99_vswscanf + isoc99_swscanf isoc99_vswscanf \ + mbrtoc16 c16rtomb strop-tests := wcscmp wmemcmp wcslen wcschr wcsrchr wcscpy tests := tst-wcstof wcsmbs-tst1 tst-wcsnlen tst-btowc tst-mbrtowc \ diff --git a/wcsmbs/Versions b/wcsmbs/Versions index b6dfa85a40..10bccc9539 100644 --- a/wcsmbs/Versions +++ b/wcsmbs/Versions @@ -28,4 +28,7 @@ libc { __isoc99_wscanf; __isoc99_vwscanf; __isoc99_fwscanf; __isoc99_vfwscanf; __isoc99_swscanf; __isoc99_vswscanf; } + GLIBC_2.16 { + mbrtoc16; c16rtomb; mbrtoc32; c32rtomb; + } } diff --git a/wcsmbs/c16rtomb.c b/wcsmbs/c16rtomb.c new file mode 100644 index 0000000000..33e6b92d02 --- /dev/null +++ b/wcsmbs/c16rtomb.c @@ -0,0 +1,121 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 2011. + + 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 <assert.h> +#include <dlfcn.h> +#include <errno.h> +#include <gconv.h> +#include <stdlib.h> +#include <uchar.h> +#include <wcsmbsload.h> + +#include <sysdep.h> + +#ifndef EILSEQ +# define EILSEQ EINVAL +#endif + +#if __STDC__ >= 20100L +# define u(c) U##c +#else +# define u(c) L##c +#endif + + +/* This is the private state used if PS is NULL. */ +static mbstate_t state; + +size_t +c16rtomb (char *s, char16_t c16, mbstate_t *ps) +{ + char buf[MB_CUR_MAX]; + struct __gconv_step_data data; + int status; + size_t result; + size_t dummy; + const struct gconv_fcts *fcts; + + /* Set information for this step. */ + data.__invocation_counter = 0; + data.__internal_use = 1; + data.__flags = __GCONV_IS_LAST; + data.__statep = ps ?: &state; + data.__trans = NULL; + + /* A first special case is if S is NULL. This means put PS in the + initial state. */ + if (s == NULL) + { + s = buf; + c16 = u('\0'); + } + + /* Tell where we want to have the result. */ + data.__outbuf = (unsigned char *) s; + data.__outbufend = (unsigned char *) s + MB_CUR_MAX; + + /* Get the conversion functions. */ + fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); + __gconv_fct fct = fcts->fromc16->__fct; +#ifdef PTR_DEMANGLE + if (fcts->tomb->__shlib_handle != NULL) + PTR_DEMANGLE (fct); +#endif + + /* If C16 is the NUL character we write into the output buffer the byte + sequence necessary for PS to get into the initial state, followed + by a NUL byte. */ + if (c16 == L'\0') + { + status = DL_CALL_FCT (fct, (fcts->fromc16, &data, NULL, NULL, + NULL, &dummy, 1, 1)); + + if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT) + *data.__outbuf++ = '\0'; + } + else + { + /* Do a normal conversion. */ + const unsigned char *inbuf = (const unsigned char *) &c16; + + status = DL_CALL_FCT (fct, + (fcts->fromc16, &data, &inbuf, + inbuf + sizeof (char16_t), NULL, &dummy, 0, 1)); + } + + /* There must not be any problems with the conversion but illegal input + characters. The output buffer must be large enough, otherwise the + definition of MB_CUR_MAX is not correct. All the other possible + errors also must not happen. */ + assert (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT + || status == __GCONV_ILLEGAL_INPUT + || status == __GCONV_INCOMPLETE_INPUT + || status == __GCONV_FULL_OUTPUT); + + if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT + || status == __GCONV_FULL_OUTPUT) + result = data.__outbuf - (unsigned char *) s; + else + { + result = (size_t) -1; + __set_errno (EILSEQ); + } + + return result; +} diff --git a/wcsmbs/mbrtoc16.c b/wcsmbs/mbrtoc16.c new file mode 100644 index 0000000000..3a3a45ce1a --- /dev/null +++ b/wcsmbs/mbrtoc16.c @@ -0,0 +1,122 @@ +/* Copyright (C) 2011 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@gnu.org>, 2011. + + 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 <assert.h> +#include <dlfcn.h> +#include <errno.h> +#include <gconv.h> +#include <uchar.h> +#include <wcsmbsload.h> + +#include <sysdep.h> + +#ifndef EILSEQ +# define EILSEQ EINVAL +#endif + +#if __STDC__ >= 20100L +# define U(c) U##c +#else +# define U(c) L##c +#endif + + +/* This is the private state used if PS is NULL. */ +static mbstate_t state; + +size_t +mbrtoc16 (char16_t *pc16, const char *s, size_t n, mbstate_t *ps) +{ + char16_t buf[1]; + struct __gconv_step_data data; + int status; + size_t result; + size_t dummy; + const unsigned char *inbuf, *endbuf; + unsigned char *outbuf = (unsigned char *) (pc16 ?: buf); + const struct gconv_fcts *fcts; + + /* Set information for this step. */ + data.__invocation_counter = 0; + data.__internal_use = 1; + data.__flags = __GCONV_IS_LAST; + data.__statep = ps ?: &state; + data.__trans = NULL; + + /* A first special case is if S is NULL. This means put PS in the + initial state. */ + if (s == NULL) + { + outbuf = (unsigned char *) buf; + s = ""; + n = 1; + } + + /* Tell where we want the result. */ + data.__outbuf = outbuf; + data.__outbufend = outbuf + sizeof (char16_t); + + /* Get the conversion functions. */ + fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); + + /* Do a normal conversion. */ + inbuf = (const unsigned char *) s; + endbuf = inbuf + n; + if (__builtin_expect (endbuf < inbuf, 0)) + endbuf = (const unsigned char *) ~(uintptr_t) 0; + __gconv_fct fct = fcts->toc16->__fct; +#ifdef PTR_DEMANGLE + if (fcts->toc16->__shlib_handle != NULL) + PTR_DEMANGLE (fct); +#endif + status = DL_CALL_FCT (fct, (fcts->toc16, &data, &inbuf, endbuf, + NULL, &dummy, 0, 1)); + + /* There must not be any problems with the conversion but illegal input + characters. The output buffer must be large enough, otherwise the + definition of MB_CUR_MAX is not correct. All the other possible + errors also must not happen. */ + assert (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT + || status == __GCONV_ILLEGAL_INPUT + || status == __GCONV_INCOMPLETE_INPUT + || status == __GCONV_FULL_OUTPUT); + + if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT + || status == __GCONV_FULL_OUTPUT) + { + if (data.__outbuf != (unsigned char *) outbuf + && *(char16_t *) outbuf == U('\0')) + { + /* The converted character is the NUL character. */ + assert (__mbsinit (data.__statep)); + result = 0; + } + else + result = inbuf - (const unsigned char *) s; + } + else if (status == __GCONV_INCOMPLETE_INPUT) + result = (size_t) -2; + else + { + result = (size_t) -1; + __set_errno (EILSEQ); + } + + return result; +} diff --git a/wcsmbs/mbrtowc.c b/wcsmbs/mbrtowc.c index b534571736..03b8348d30 100644 --- a/wcsmbs/mbrtowc.c +++ b/wcsmbs/mbrtowc.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2004, 2005 +/* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2002, 2004, 2005, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 1996. @@ -117,3 +117,8 @@ __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) libc_hidden_def (__mbrtowc) weak_alias (__mbrtowc, mbrtowc) libc_hidden_weak (mbrtowc) + +/* There should be no difference between the UTF-32 handling required + by mbrtoc32 and the wchar_t handling which has long since been + implemented in mbrtowc. */ +weak_alias (__mbrtowc, mbrtoc32) diff --git a/wcsmbs/uchar.h b/wcsmbs/uchar.h index 44637c3396..bb5f3ba35c 100644 --- a/wcsmbs/uchar.h +++ b/wcsmbs/uchar.h @@ -31,6 +31,14 @@ #define __need_mbstate_t #include <wchar.h> +#ifndef __mbstate_t_defined +__BEGIN_NAMESPACE_C99 +/* Public type. */ +typedef __mbstate_t mbstate_t; +__END_NAMESPACE_C99 +# define __mbstate_t_defined 1 +#endif + #ifdef __GNUC__ /* Define the 16-bit and 32-bit character types. Use the information diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h index 2b35f51ad6..ccaaed8f49 100644 --- a/wcsmbs/wchar.h +++ b/wcsmbs/wchar.h @@ -77,8 +77,8 @@ __END_NAMESPACE_STD # endif #endif -#if (defined _WCHAR_H || defined __need_mbstate_t) && !defined __mbstate_t_defined -# define __mbstate_t_defined 1 +#if (defined _WCHAR_H || defined __need_mbstate_t) && !defined ____mbstate_t_defined +# define ____mbstate_t_defined 1 /* Conversion state information. */ typedef struct { @@ -101,10 +101,14 @@ typedef struct defined. */ #ifdef _WCHAR_H +# ifndef __mbstate_t_defined __BEGIN_NAMESPACE_C99 /* Public type. */ typedef __mbstate_t mbstate_t; __END_NAMESPACE_C99 +# define __mbstate_t_defined 1 +# endif + #ifdef __USE_GNU __USING_NAMESPACE_C99(mbstate_t) #endif diff --git a/wcsmbs/wcrtomb.c b/wcsmbs/wcrtomb.c index aa51b6891b..547b05aa9c 100644 --- a/wcsmbs/wcrtomb.c +++ b/wcsmbs/wcrtomb.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1996,1997,1998,2000,2002,2005 Free Software Foundation, Inc. +/* Copyright (C) 1996-1998,2000,2002,2005,2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. @@ -115,3 +115,8 @@ __wcrtomb (char *s, wchar_t wc, mbstate_t *ps) } weak_alias (__wcrtomb, wcrtomb) libc_hidden_weak (wcrtomb) + +/* There should be no difference between the UTF-32 handling required + by c32rtomb and the wchar_t handling which has long since been + implemented in wcrtomb. */ +weak_alias (__wcrtomb, c32rtomb) diff --git a/wcsmbs/wcsmbsload.c b/wcsmbs/wcsmbsload.c index 328f16497c..212a6c8135 100644 --- a/wcsmbs/wcsmbsload.c +++ b/wcsmbs/wcsmbsload.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2002,2004,2005,2008,2010 Free Software Foundation, Inc. +/* Copyright (C) 1998-2002,2004,2005,2008,2010,2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -67,6 +67,44 @@ static const struct __gconv_step to_mb = .__data = NULL }; +static const struct __gconv_step to_c16 = +{ + .__shlib_handle = NULL, + .__modname = NULL, + .__counter = INT_MAX, + .__from_name = (char *) "ANSI_X3.4-1968//TRANSLIT", + .__to_name = (char *) "UTF-16//", + .__fct = __gconv_transform_ascii_utf16, + .__btowc_fct = NULL, + .__init_fct = NULL, + .__end_fct = NULL, + .__min_needed_from = 1, + .__max_needed_from = 1, + .__min_needed_to = 4, + .__max_needed_to = 4, + .__stateful = 0, + .__data = NULL +}; + +static const struct __gconv_step from_c16 = +{ + .__shlib_handle = NULL, + .__modname = NULL, + .__counter = INT_MAX, + .__from_name = (char *) "UTF-16//", + .__to_name = (char *) "ANSI_X3.4-1968//TRANSLIT", + .__fct = __gconv_transform_utf16_ascii, + .__btowc_fct = NULL, + .__init_fct = NULL, + .__end_fct = NULL, + .__min_needed_from = 4, + .__max_needed_from = 4, + .__min_needed_to = 1, + .__max_needed_to = 1, + .__stateful = 0, + .__data = NULL +}; + /* For the default locale we only have to handle ANSI_X3.4-1968. */ const struct gconv_fcts __wcsmbs_gconv_fcts_c = @@ -74,7 +112,12 @@ const struct gconv_fcts __wcsmbs_gconv_fcts_c = .towc = (struct __gconv_step *) &to_wc, .towc_nsteps = 1, .tomb = (struct __gconv_step *) &to_mb, - .tomb_nsteps = 1 + .tomb_nsteps = 1, + + .toc16 = (struct __gconv_step *) &to_c16, + .toc16_nsteps = 1, + .fromc16 = (struct __gconv_step *) &from_c16, + .fromc16_nsteps = 1, }; @@ -191,6 +234,12 @@ __wcsmbs_load_conv (struct __locale_data *new_category) &new_fcts->tomb_nsteps) : NULL); + // XXX + new_fcts->toc16 = (struct __gconv_step *) &to_c16; + new_fcts->toc16_nsteps = 1; + new_fcts->fromc16 = (struct __gconv_step *) &from_c16; + new_fcts->fromc16_nsteps = 1; + /* If any of the conversion functions is not available we don't use any since this would mean we cannot convert back and forth.*/ @@ -242,14 +291,36 @@ internal_function __wcsmbs_named_conv (struct gconv_fcts *copy, const char *name) { copy->towc = __wcsmbs_getfct ("INTERNAL", name, ©->towc_nsteps); - if (copy->towc != NULL) + if (copy->towc == NULL) + return 1; + + copy->tomb = __wcsmbs_getfct (name, "INTERNAL", ©->tomb_nsteps); + if (copy->tomb == NULL) + goto out_mb; + +#if 0 + copy->fromc16 = __wcsmbs_getfct (name, "UTF-16//", ©->fromc16_nsteps); + if (copy->fromc16 == NULL) + goto out_fromc16; + + copy->toc16 = __wcsmbs_getfct ("UTF-16//", name, ©->toc16_nsteps); + if (copy->toc16 == NULL) +#else + if (0) +#endif { - copy->tomb = __wcsmbs_getfct (name, "INTERNAL", ©->tomb_nsteps); - if (copy->tomb == NULL) - __gconv_close_transform (copy->towc, copy->towc_nsteps); +#if 0 + __gconv_close_transform (copy->fromc16, copy->fromc16_nsteps); + out_fromc16: + __gconv_close_transform (copy->tomb, copy->tomb_nsteps); +#endif + out_mb: + __gconv_close_transform (copy->towc, copy->towc_nsteps); + out_wc: + return 1; } - return copy->towc == NULL || copy->tomb == NULL ? 1 : 0; + return 0; } void internal_function @@ -264,6 +335,11 @@ _nl_cleanup_ctype (struct __locale_data *locale) /* Free the old conversions. */ __gconv_close_transform (data->tomb, data->tomb_nsteps); __gconv_close_transform (data->towc, data->towc_nsteps); +#if 0 + // XXX + __gconv_close_transform (data->fromc16, data->fromc16_nsteps); + __gconv_close_transform (data->toc16, data->toc16c_nsteps); +#endif free ((char *) data); } } diff --git a/wcsmbs/wcsmbsload.h b/wcsmbs/wcsmbsload.h index e2b1bfa9c8..064c41c82f 100644 --- a/wcsmbs/wcsmbsload.h +++ b/wcsmbs/wcsmbsload.h @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2002, 2010 Free Software Foundation, Inc. +/* Copyright (C) 1998-2002, 2010, 2011 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. @@ -32,6 +32,11 @@ struct gconv_fcts size_t towc_nsteps; struct __gconv_step *tomb; size_t tomb_nsteps; + + struct __gconv_step *toc16; + size_t toc16_nsteps; + struct __gconv_step *fromc16; + size_t fromc16_nsteps; }; /* Set of currently active conversion functions. */ |