]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Use the 'xstriconv' module instead of the 'iconvstring' module.
authorBruno Haible <bruno@clisp.org>
Wed, 6 Sep 2006 12:32:54 +0000 (12:32 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:58 +0000 (12:13 +0200)
14 files changed:
ChangeLog
autogen.sh
gettext-runtime/src/Makefile.am
gettext-tools/src/ChangeLog
gettext-tools/src/msgl-iconv.c
gettext-tools/src/recode-sr-latin.c
gnulib-local/ChangeLog
gnulib-local/Makefile.am
gnulib-local/lib/iconvstring.c [deleted file]
gnulib-local/lib/iconvstring.h [deleted file]
gnulib-local/lib/propername.c
gnulib-local/modules/gettext-tools-misc
gnulib-local/modules/iconvstring [deleted file]
gnulib-local/modules/propername

index a7b51d67959148af29a14e3bf61ffa19193f66e9..0b4c8dd11e3f9108c583e7f8751f3484cd985955 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-06  Bruno Haible  <bruno@clisp.org>
+
+       * autogen.sh (GNULIB_MODULES_FOR_SRC): Add xstriconv, remove
+       iconvstring.
+
 2006-08-26  Bruno Haible  <bruno@clisp.org>
 
        * m4/woe32-dll.m4: Update comments.
index 16a6673651eaff4d9fa00ef61378c6b118a4cc47..a1970a9f3cf14e01826527ec7c877d60dc5e9e21 100755 (executable)
@@ -110,7 +110,6 @@ if test -n "$GNULIB_TOOL"; then
   gettext-h
   hash
   iconv
-  iconvstring
   javacomp
   javaexec
   linebreak
@@ -131,6 +130,7 @@ if test -n "$GNULIB_TOOL"; then
   stpcpy
   stpncpy
   strcspn
+  xstriconv
   strpbrk
   strtol
   strtoul
index 289d36007d6ae69abc3dc2a4f9746774fdd82cf8..5657efa2689f15d7f985df0999b10c0426b18eb2 100644 (file)
@@ -38,7 +38,7 @@ ngettext_SOURCES = ngettext.c
 envsubst_SOURCES = envsubst.c
 
 # Link dependencies.
-# Need @LTLIBICONV@ because iconvstring.c uses iconv().
+# Need @LTLIBICONV@ because striconv.c uses iconv().
 LDADD = ../gnulib-lib/libgrt.a @LTLIBINTL@ @LTLIBICONV@
 
 # Specify installation directory, for --enable-relocatable.
index 586edfa96f78e6ab357dedc8093416e80c79baab..5191d8f5fcb6b9b5845debc2dfe1deccb5980eb8 100644 (file)
@@ -1,3 +1,11 @@
+2006-09-06  Bruno Haible  <bruno@clisp.org>
+
+       * msgl-iconv.c: Include xstriconv.h instead of iconvstring.h.
+       (convert_string, convert_msgstr, iconvable_string, iconvable_msgstr):
+       Use xmem_cd_iconv instead of iconv_string.
+       * recode-sr-latin.c: Include xstriconv.h instead of iconvstring.h.
+       (process): Use xmem_cd_iconv instead of iconv_string.
+
 2006-09-04  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (msginit_SOURCES): Add ../../gettext-runtime/intl/lock.c.
index 957fe4f6624fe9d7b6e717c992ccc07c2a0f94cc..61afda8e6e6a9c54c7fdf187ee68e185b5bb5987 100644 (file)
@@ -37,7 +37,7 @@
 #include "basename.h"
 #include "message.h"
 #include "po-charset.h"
-#include "iconvstring.h"
+#include "xstriconv.h"
 #include "msgl-ascii.h"
 #include "xalloc.h"
 #include "xallocsa.h"
@@ -82,7 +82,7 @@ convert_string (iconv_t cd, const char *string,
   char *result = NULL;
   size_t resultlen;
 
-  if (iconv_string (cd, string, string + len, &result, &resultlen) == 0)
+  if (xmem_cd_iconv (string, len, cd, &result, &resultlen) == 0)
     /* Verify the result has exactly one NUL byte, at the end.  */
     if (resultlen > 0 && result[resultlen - 1] == '\0'
        && strlen (result) == resultlen - 1)
@@ -125,8 +125,7 @@ convert_msgstr (iconv_t cd, message_ty *mp,
   if (!(mp->msgstr_len > 0 && mp->msgstr[mp->msgstr_len - 1] == '\0'))
     abort ();
 
-  if (iconv_string (cd, mp->msgstr, mp->msgstr + mp->msgstr_len,
-                   &result, &resultlen) == 0)
+  if (xmem_cd_iconv (mp->msgstr, mp->msgstr_len, cd, &result, &resultlen) == 0)
     /* Verify the result has a NUL byte at the end.  */
     if (resultlen > 0 && result[resultlen - 1] == '\0')
       /* Verify the result has the same number of NUL bytes.  */
@@ -349,7 +348,7 @@ iconvable_string (iconv_t cd, const char *string)
   char *result = NULL;
   size_t resultlen;
 
-  if (iconv_string (cd, string, string + len, &result, &resultlen) == 0)
+  if (xmem_cd_iconv (string, len, cd, &result, &resultlen) == 0)
     {
       /* Test if the result has exactly one NUL byte, at the end.  */
       bool ok = (resultlen > 0 && result[resultlen - 1] == '\0'
@@ -395,8 +394,7 @@ iconvable_msgstr (iconv_t cd, message_ty *mp)
   if (!(mp->msgstr_len > 0 && mp->msgstr[mp->msgstr_len - 1] == '\0'))
     abort ();
 
-  if (iconv_string (cd, mp->msgstr, mp->msgstr + mp->msgstr_len,
-                   &result, &resultlen) == 0)
+  if (xmem_cd_iconv (mp->msgstr, mp->msgstr_len, cd, &result, &resultlen) == 0)
     {
       bool ok = false;
 
index a74bd909b1f3b8b6853703e78eecb4b549c8ac51..c2a69c091ff750b18ddcc2b4336570e02d7a909e 100644 (file)
@@ -40,7 +40,7 @@
 #include "exit.h"
 #include "localcharset.h"
 #include "c-strcase.h"
-#include "iconvstring.h"
+#include "xstriconv.h"
 #include "filters.h"
 #include "propername.h"
 #include "gettext.h"
@@ -326,8 +326,8 @@ This version was built without iconv()."),
       /* Convert it to UTF-8.  */
       if (need_code_conversion)
        {
-         if (iconv_string (conv_to_utf8, line, line + line_len,
-                           &utf8_line, &utf8_line_len) != 0)
+         if (xmem_cd_iconv (line, line_len, conv_to_utf8,
+                            &utf8_line, &utf8_line_len) != 0)
            error (EXIT_FAILURE, errno,
                   _("input is not valid in \"%s\" encoding"),
                   locale_code);
@@ -343,9 +343,8 @@ This version was built without iconv()."),
       /* Convert it back to the original encoding.  */
       if (need_code_conversion)
        {
-         if (iconv_string (conv_from_utf8,
-                           filtered_line, filtered_line + filtered_line_len,
-                           &backconv_line, &backconv_line_len) != 0)
+         if (xmem_cd_iconv (filtered_line, filtered_line_len, conv_from_utf8,
+                            &backconv_line, &backconv_line_len) != 0)
            error (EXIT_FAILURE, errno,
                   _("error while converting from \"%s\" encoding to \"%s\" encoding"),
                   "UTF-8", locale_code);
index 675a5a9d0985bd507e1006ced32163d2f1b89b6a..0ba4b96c93113f76bd5e0b07af7ad90860575a67 100644 (file)
@@ -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.
index 97200e31143dc756ec00602f1be964c35682c004..457485407f1f4c2af9107272be4f22282d859da8 100644 (file)
@@ -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 (file)
index b09f9e9..0000000
+++ /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 (file)
index 4ab5f96..0000000
+++ /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 */
index f66d828f45d1c2274b0fadd1c219fad159203451..56c4bc7cd8fb65b1d9069d6e09c02ce5ef688a35 100644 (file)
@@ -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
index e62a93acd0ed377573498d756c57790b9f267a8f..9395bbb0880eaa5ace7c6a5265946af8aaf5847c 100644 (file)
@@ -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 (file)
index 7905b84..0000000
+++ /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
-
index f4a4293c5adf70f29a1cef8a0d757b25eae6a40f..4ab93eb07a02bb3d9e8e9aa7fc36d12917ee63b7 100644 (file)
@@ -9,7 +9,7 @@ Depends-on:
 iconv
 localcharset
 c-strcase
-iconvstring
+xstriconv
 c-strstr
 strstr
 xalloc