From: Bruno Haible Date: Wed, 29 Mar 2006 11:26:37 +0000 (+0000) Subject: New library module 'iconvstring'. X-Git-Tag: v0.15~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=698cc8278864d95a03e7e57b6d563acbf2fb8488;p=thirdparty%2Fgettext.git New library module 'iconvstring'. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index 59ab2fa89..740a1b948 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,13 @@ +2006-03-28 Bruno Haible + + * iconvstring.h: New file. + * iconvstring.c: New file, mostly extracted from ../src/msgl-iconv.c. + * Makefile.am (libgettextlib_la_SOURCES): Add them. + * Makefile.msvc (OBJECTS): Add iconvstring.obj. + (iconvstring.obj): New rule. + * Makefile.vms (OBJECTS): Add iconvstring.obj. + (iconvstring.obj): New rule. + 2006-03-12 Bruno Haible * javaexec.sh.in: Update for changed javaexec.m4. diff --git a/gettext-tools/lib/Makefile.am b/gettext-tools/lib/Makefile.am index c34c6a258..8fa737356 100644 --- a/gettext-tools/lib/Makefile.am +++ b/gettext-tools/lib/Makefile.am @@ -56,6 +56,7 @@ libgettextlib_la_SOURCES = \ fwriteerror.h fwriteerror.c \ gcd.h gcd.c \ hash.h hash.c \ + iconvstring.h iconvstring.c \ javacomp.h javacomp.c \ javaexec.h javaexec.c \ linebreak.h linebreak.c lbrkprop.h utf8-ucs4.h utf16-ucs4.h \ diff --git a/gettext-tools/lib/Makefile.msvc b/gettext-tools/lib/Makefile.msvc index d5d49977b..a4525ed54 100644 --- a/gettext-tools/lib/Makefile.msvc +++ b/gettext-tools/lib/Makefile.msvc @@ -102,6 +102,7 @@ OBJECTS = \ fwriteerror.obj \ gcd.obj \ hash.obj \ + iconvstring.obj \ javacomp.obj \ javaexec.obj \ linebreak.obj \ @@ -207,6 +208,9 @@ gcd.obj : gcd.c hash.obj : hash.c $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c hash.c +iconvstring.obj : iconvstring.c + $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c iconvstring.c + javacomp.obj : javacomp.c $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c javacomp.c diff --git a/gettext-tools/lib/Makefile.vms b/gettext-tools/lib/Makefile.vms index 07557a141..41d6a2562 100644 --- a/gettext-tools/lib/Makefile.vms +++ b/gettext-tools/lib/Makefile.vms @@ -60,6 +60,7 @@ OBJECTS = \ fwriteerror.obj, \ gcd.obj, \ hash.obj, \ + iconvstring.obj, \ javacomp.obj, \ javaexec.obj, \ linebreak.obj, \ @@ -169,6 +170,9 @@ gcd.obj : gcd.c hash.obj : hash.c $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) hash.c +iconvstring.obj : iconvstring.c + $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) iconvstring.c + javacomp.obj : javacomp.c,alloca.h $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) javacomp.c diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 3530975c3..e3c3ffd06 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,8 @@ +2006-03-28 Bruno Haible + + * msgl-iconv.c: Include iconvstring.h. Don't include . + (iconv_string): Remove function, moved to ../lib/. + 2006-03-19 Bruno Haible * xgettext.h (struct callshape): New field 'xcomments'. @@ -9,6 +14,7 @@ (arglist_parser_done): After calling remember_a_message, attach the specified extracted comments. * x-perl.c (extract_variable): Update. + Suggested by Behdad Esfahbod . 2006-03-19 Bruno Haible diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index 123ef4925..163cdf1c5 100644 --- a/gettext-tools/src/msgl-iconv.c +++ b/gettext-tools/src/msgl-iconv.c @@ -1,5 +1,5 @@ /* Message list charset and locale charset handling. - Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2006 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software; you can redistribute it and/or modify @@ -25,7 +25,6 @@ /* Specification. */ #include "msgl-iconv.h" -#include #include #include #include @@ -38,6 +37,7 @@ #include "basename.h" #include "message.h" #include "po-charset.h" +#include "iconvstring.h" #include "msgl-ascii.h" #include "xalloc.h" #include "xallocsa.h" @@ -51,126 +51,6 @@ #if HAVE_ICONV -/* Converts an entire string from one encoding to another, using iconv. - Return value: 0 if successful, otherwise -1 and errno set. */ -static 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; - - /* 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) - break; - else - return -1; - } -# if !defined _LIBICONV_VERSION && (defined sgi || defined __sgi) - /* Irix iconv() inserts a NUL byte if it cannot convert. */ - 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; - size_t insize = end - start; - char *outptr = result; - size_t outsize = length; - - while (insize > 0) - { - size_t res = iconv (cd, - (ICONV_CONST char **) &inptr, &insize, - &outptr, &outsize); - - if (res == (size_t)(-1)) - { - if (errno == EINVAL) - break; - else - return -1; - } -# if !defined _LIBICONV_VERSION && (defined sgi || defined __sgi) - /* Irix iconv() inserts a NUL byte if it cannot convert. */ - 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 -} - static void conversion_error (const struct conversion_context* context) #if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) __attribute__ ((noreturn))