diff options
author | Bruno Haible <bruno@clisp.org> | 2006-09-06 12:32:54 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:13:58 +0200 |
commit | f46d07829d82ff66f77e5fb7b49c3ccdcb39ed99 (patch) | |
tree | fa6748952dc14bcdb23f014a7d51169dd97df544 /gnulib-local | |
parent | 8d766faa6a4f3180f3b95c428a9a91f43664df64 (diff) | |
download | external_gettext-f46d07829d82ff66f77e5fb7b49c3ccdcb39ed99.zip external_gettext-f46d07829d82ff66f77e5fb7b49c3ccdcb39ed99.tar.gz external_gettext-f46d07829d82ff66f77e5fb7b49c3ccdcb39ed99.tar.bz2 |
Use the 'xstriconv' module instead of the 'iconvstring' module.
Diffstat (limited to 'gnulib-local')
-rw-r--r-- | gnulib-local/ChangeLog | 13 | ||||
-rw-r--r-- | gnulib-local/Makefile.am | 3 | ||||
-rw-r--r-- | gnulib-local/lib/iconvstring.c | 239 | ||||
-rw-r--r-- | gnulib-local/lib/iconvstring.h | 51 | ||||
-rw-r--r-- | gnulib-local/lib/propername.c | 62 | ||||
-rw-r--r-- | gnulib-local/modules/gettext-tools-misc | 2 | ||||
-rw-r--r-- | gnulib-local/modules/iconvstring | 25 | ||||
-rw-r--r-- | gnulib-local/modules/propername | 2 |
8 files changed, 27 insertions, 370 deletions
diff --git a/gnulib-local/ChangeLog b/gnulib-local/ChangeLog index 675a5a9..0ba4b96 100644 --- a/gnulib-local/ChangeLog +++ b/gnulib-local/ChangeLog @@ -1,3 +1,16 @@ +2006-09-06 Bruno Haible <bruno@clisp.org> + + * modules/iconvstring: Remove file. + * lib/iconvstring.h: Remove file. + * lib/iconvstring.c: Remove file. + * Makefile.am (EXTRA_DIST): Remove modules/iconvstring, + lib/iconvstring.h, lib/iconvstring.c. + + * lib/propername.c: Include xstriconv.h instead of iconvstring.h. + (convert_name): Remove function. + (proper_name_utf8): Use xstr_iconv instead of convert_name. + * modules/propername: Depend on xstriconv instead of iconvstring. + 2006-08-30 Bruno Haible <bruno@clisp.org> * lib/xerror.h: Don't include error.h. diff --git a/gnulib-local/Makefile.am b/gnulib-local/Makefile.am index 97200e3..4574854 100644 --- a/gnulib-local/Makefile.am +++ b/gnulib-local/Makefile.am @@ -55,8 +55,6 @@ lib/getopt_.h.diff \ lib/gettext.h \ lib/hash.c \ lib/hash.h \ -lib/iconvstring.c \ -lib/iconvstring.h \ lib/javacomp.c.diff \ lib/linebreak.c.diff \ lib/obstack.h.diff \ @@ -113,7 +111,6 @@ modules/getndelim2 \ modules/gettext-runtime-misc \ modules/gettext-tools-misc \ modules/hash \ -modules/iconvstring \ modules/java \ modules/javacomp.diff \ modules/pathmax.diff \ diff --git a/gnulib-local/lib/iconvstring.c b/gnulib-local/lib/iconvstring.c deleted file mode 100644 index b09f9e9..0000000 --- a/gnulib-local/lib/iconvstring.c +++ /dev/null @@ -1,239 +0,0 @@ -/* Charset conversion. - Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc. - Written by Bruno Haible <haible@clisp.cons.org>, 2001. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/* Specification. */ -#include "iconvstring.h" - -#include <errno.h> -#include <stdlib.h> - -#if HAVE_ICONV -# include <iconv.h> -#endif - -#include "xalloc.h" - - -#if HAVE_ICONV - -/* POSIX does not specify clearly what happens when a character in the - source encoding is valid but cannot be represented in the destination - encoding. - GNU libc and libiconv stop the conversion in this case, with errno = EINVAL. - Irix iconv() inserts a NUL byte in this case. NetBSD iconv() inserts - a '?' byte. For other implementations, we don't know. Normally the - number of failed conversions is available as the iconv() result. - The problem with these implementations is that when iconv() fails, for - example with errno = E2BIG or = EINVAL, the number of failed conversions - gets lost. As a workaround, we need to process the input string slowly, - byte after byte. */ -# if !(defined __GLIBC__ || defined _LIBICONV_VERSION) -# define UNSAFE_ICONV -# endif - -/* Converts an entire string from one encoding to another, using iconv. - Return value: 0 if successful, otherwise -1 and errno set. */ -int -iconv_string (iconv_t cd, const char *start, const char *end, - char **resultp, size_t *lengthp) -{ -#define tmpbufsize 4096 - size_t length; - char *result; -# ifdef UNSAFE_ICONV - int expect_einval = 0; -# endif - - /* Avoid glibc-2.1 bug and Solaris 2.7-2.9 bug. */ -# if defined _LIBICONV_VERSION \ - || !((__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) || defined __sun) - /* Set to the initial state. */ - iconv (cd, NULL, NULL, NULL, NULL); -# endif - - /* Determine the length we need. */ - { - size_t count = 0; - char tmpbuf[tmpbufsize]; - const char *inptr = start; - size_t insize = end - start; - - while (insize > 0) - { - char *outptr = tmpbuf; - size_t outsize = tmpbufsize; - size_t res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - - if (res == (size_t)(-1)) - { - if (errno == E2BIG) - ; - else if (errno == EINVAL) - { -# ifdef UNSAFE_ICONV - expect_einval = 1; -# endif - break; - } - else - return -1; - } -# ifdef UNSAFE_ICONV - else if (res > 0) - return -1; -# endif - count += outptr - tmpbuf; - } - /* Avoid glibc-2.1 bug and Solaris 2.7 bug. */ -# if defined _LIBICONV_VERSION \ - || !((__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) || defined __sun) - { - char *outptr = tmpbuf; - size_t outsize = tmpbufsize; - size_t res = iconv (cd, NULL, NULL, &outptr, &outsize); - - if (res == (size_t)(-1)) - return -1; - count += outptr - tmpbuf; - } -# endif - length = count; - } - - *lengthp = length; - *resultp = result = xrealloc (*resultp, length); - if (length == 0) - return 0; - - /* Avoid glibc-2.1 bug and Solaris 2.7-2.9 bug. */ -# if defined _LIBICONV_VERSION \ - || !((__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) || defined __sun) - /* Return to the initial state. */ - iconv (cd, NULL, NULL, NULL, NULL); -# endif - - /* Do the conversion for real. */ - { - const char *inptr = start; - char *outptr = result; - size_t outsize = length; - -# ifdef UNSAFE_ICONV - if (expect_einval) - { - /* Process the characters one by one, so as to not lose the - number of conversion failures. */ - const char *inptr_end = end; - - while (inptr < inptr_end) - { - size_t insize_max = inptr_end - inptr; - size_t insize_avail; - size_t res; - - for (insize_avail = 1; ; insize_avail++) - { - /* Here 1 <= insize_avail <= insize_max. */ - size_t insize = insize_avail; - - res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - if (res == (size_t)(-1)) - { - if (errno == EINVAL) - { - if (insize_avail < insize_max) - continue; - else - break; - } - else - /* E2BIG and other errors shouldn't happen in this - round any more. */ - return -1; - } - else - break; - } - if (res == (size_t)(-1)) - /* errno = EINVAL. Ignore the trailing incomplete character. */ - break; - else if (res > 0) - return -1; - } - } - else -# endif - { - size_t insize = end - start; - - while (insize > 0) - { - size_t res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - - if (res == (size_t)(-1)) - { - if (errno == EINVAL) - { -# ifdef UNSAFE_ICONV - /* EINVAL should already have occurred in the first - round. */ - abort (); -# endif - /* Ignore the trailing incomplete character. */ - break; - } - else - /* E2BIG and other errors shouldn't happen in this round - any more. */ - return -1; - } -# ifdef UNSAFE_ICONV - else if (res > 0) - return -1; -# endif - } - } - /* Avoid glibc-2.1 bug and Solaris 2.7 bug. */ -# if defined _LIBICONV_VERSION \ - || !((__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) || defined __sun) - { - size_t res = iconv (cd, NULL, NULL, &outptr, &outsize); - - if (res == (size_t)(-1)) - return -1; - } -# endif - if (outsize != 0) - abort (); - } - - return 0; -#undef tmpbufsize -} - -#endif diff --git a/gnulib-local/lib/iconvstring.h b/gnulib-local/lib/iconvstring.h deleted file mode 100644 index 4ab5f96..0000000 --- a/gnulib-local/lib/iconvstring.h +++ /dev/null @@ -1,51 +0,0 @@ -/* Charset conversion. - Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc. - Written by Bruno Haible <haible@clisp.cons.org>, 2001. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - -#ifndef _ICONVSTRING_H -#define _ICONVSTRING_H - -#include <stddef.h> -#if HAVE_ICONV -#include <iconv.h> -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - - -#if HAVE_ICONV - -/* Convert an entire string from one encoding to another, using iconv. - *RESULTP should initially contain NULL or malloced memory block. - Return value: 0 if successful, otherwise -1 and errno set. - If successful, the resulting string is stored in *RESULTP and its length - in *LENGTHP. */ -extern int iconv_string (iconv_t cd, const char *start, const char *end, - char **resultp, size_t *lengthp); - -#endif - - -#ifdef __cplusplus -} -#endif - - -#endif /* _ICONVSTRING_H */ diff --git a/gnulib-local/lib/propername.c b/gnulib-local/lib/propername.c index f66d828..56c4bc7 100644 --- a/gnulib-local/lib/propername.c +++ b/gnulib-local/lib/propername.c @@ -32,7 +32,7 @@ #include "localcharset.h" #include "c-strcase.h" -#include "iconvstring.h" +#include "xstriconv.h" #include "c-strstr.h" #include "strstr.h" #include "xalloc.h" @@ -66,38 +66,6 @@ proper_name (const char *name) return name; } -#if HAVE_ICONV - -static char * -convert_name (const char *locale_code, const char *name_utf8) -{ - /* Open conversion descriptor. */ - iconv_t conv_from_utf8 = iconv_open (locale_code, "UTF-8"); - - if (conv_from_utf8 != (iconv_t)(-1)) - { - char *name_converted = NULL; - size_t length; - - /* Convert the name to the locale encoding. */ - if (iconv_string (conv_from_utf8, - name_utf8, name_utf8 + strlen (name_utf8) + 1, - &name_converted, &length) == 0) - /* Verify that the converted string is terminated. */ - if (!(length > 0 && name_converted[length - 1] == '\0')) - abort (); - - /* Free the conversion descriptor. */ - iconv_close (conv_from_utf8); - - return name_converted; - } - else - return NULL; -} - -#endif - /* Return the localization of a name whose original writing is not ASCII. NAME_UTF8 is the real name, written in UTF-8 with octal or hexadecimal escape sequences. NAME_ASCII is a fallback written only with ASCII @@ -120,29 +88,23 @@ proper_name_utf8 (const char *name_ascii, const char *name_utf8) if (c_strcasecmp (locale_code, "UTF-8") != 0) { #if HAVE_ICONV - /* Avoid glibc-2.1 bug with EUC-KR. */ -# if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION - if (strcmp (locale_code, "EUC-KR") != 0) -# endif - { - name_converted = alloc_name_converted = - convert_name (locale_code, name_utf8); + name_converted = alloc_name_converted = + xstr_iconv (name_utf8, "UTF-8", locale_code); # if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \ || _LIBICONV_VERSION >= 0x0105 - { - size_t len = strlen (locale_code); - char *locale_code_translit = (char *) xmalloc (len + 10 + 1); - memcpy (locale_code_translit, locale_code, len); - memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1); + { + size_t len = strlen (locale_code); + char *locale_code_translit = (char *) xmalloc (len + 10 + 1); + memcpy (locale_code_translit, locale_code, len); + memcpy (locale_code_translit + len, "//TRANSLIT", 10 + 1); - name_converted_translit = alloc_name_converted_translit = - convert_name (locale_code_translit, name_utf8); + name_converted_translit = alloc_name_converted_translit = + xstr_iconv (name_utf8, "UTF-8", locale_code_translit); - free (locale_code_translit); - } + free (locale_code_translit); + } # endif - } #endif } else diff --git a/gnulib-local/modules/gettext-tools-misc b/gnulib-local/modules/gettext-tools-misc index e62a93a..9395bbb 100644 --- a/gnulib-local/modules/gettext-tools-misc +++ b/gnulib-local/modules/gettext-tools-misc @@ -21,7 +21,7 @@ AM_CPPFLAGS += -DDEPENDS_ON_LIBICONV=1 -DDEPENDS_ON_LIBINTL=1 lib_LTLIBRARIES = libgettextlib.la # Need @LTLIBINTL@ because many source files use gettext(). -# Need @LTLIBICONV@ because linebreak.c and iconvstring.c use iconv(). +# Need @LTLIBICONV@ because linebreak.c and striconv.c use iconv(). lib_LDFLAGS = \ -release @VERSION@ \ @LTLIBINTL@ @LTLIBICONV@ -lc @LTNOUNDEF@ diff --git a/gnulib-local/modules/iconvstring b/gnulib-local/modules/iconvstring deleted file mode 100644 index 7905b84..0000000 --- a/gnulib-local/modules/iconvstring +++ /dev/null @@ -1,25 +0,0 @@ -Description: -Charset conversion. - -Files: -lib/iconvstring.h -lib/iconvstring.c - -Depends-on: -iconv -xalloc - -configure.ac: - -Makefile.am: -lib_SOURCES += iconvstring.h iconvstring.c - -Include: -"iconvstring.h" - -License: -GPL - -Maintainer: -Bruno Haible - diff --git a/gnulib-local/modules/propername b/gnulib-local/modules/propername index f4a4293..4ab93eb 100644 --- a/gnulib-local/modules/propername +++ b/gnulib-local/modules/propername @@ -9,7 +9,7 @@ Depends-on: iconv localcharset c-strcase -iconvstring +xstriconv c-strstr strstr xalloc |