From: Bruno Haible Date: Sun, 30 Aug 2009 15:47:21 +0000 (+0200) Subject: Accommodate the Solaris iconv_open function, which cannot convert directly. X-Git-Tag: v0.18~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c31defda8d15abc8b8a0a315e3d2d7d6d8155a4;p=thirdparty%2Fgettext.git Accommodate the Solaris iconv_open function, which cannot convert directly. --- diff --git a/ChangeLog b/ChangeLog index 929bf8963..fc8be252c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2009-08-30 Bruno Haible + + * autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC): Add xstriconveh. + 2009-08-30 Bruno Haible * configure.ac (AC_PREREQ): Require at least autoconf 2.59. diff --git a/autogen.sh b/autogen.sh index 2f0045899..3e3e1503e 100755 --- a/autogen.sh +++ b/autogen.sh @@ -209,6 +209,7 @@ if ! $skip_gnulib; then xerror xsetenv xstriconv + xstriconveh xvasprintf ' # Not yet used. Add some files to gettext-tools-misc instead. diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index b234ec27d..e04131722 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,20 @@ +2009-08-30 Bruno Haible + + Accommodate the Solaris iconv_open function, which cannot convert + directly between many pairs of encodings. + * msgl-iconv.h (convert_string_directly): Renamed from convert_string. + * msgl-iconv.c: Include xstriconveh.h. + (convert_string_directly): Renamed from convert_string. + (convert_string): New function. + (convert_string_list, convert_prev_msgid, convert_msgid, + iconvable_string_list, iconvable_prev_msgid, iconvable_msgid): Change + argument type to 'const iconveh_t *'. + (convert_msgstr, iconvable_string, iconvable_msgstr): Likewise. Invoke + xmem_cd_iconveh instead of xmem_cd_iconv. + (iconv_message_list_internal, is_message_list_iconvable): Invoke + iconveh_open, iconveh_close instead of iconv_open, iconv_close. + * xgettext.c (from_current_source_encoding): Update. + 2009-08-16 Bruno Haible Reduce dependency on project-id heuristic. diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index c3748094f..1e5832ae3 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-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -37,6 +37,7 @@ #include "message.h" #include "po-charset.h" #include "xstriconv.h" +#include "xstriconveh.h" #include "msgl-ascii.h" #include "xalloc.h" #include "xmalloca.h" @@ -74,8 +75,8 @@ conversion_error (const struct conversion_context* context) } char * -convert_string (iconv_t cd, const char *string, - const struct conversion_context* context) +convert_string_directly (iconv_t cd, const char *string, + const struct conversion_context* context) { size_t len = strlen (string) + 1; char *result = NULL; @@ -92,8 +93,28 @@ convert_string (iconv_t cd, const char *string, return NULL; } +static char * +convert_string (const iconveh_t *cd, const char *string, + const struct conversion_context* context) +{ + size_t len = strlen (string) + 1; + char *result = NULL; + size_t resultlen = 0; + + if (xmem_cd_iconveh (string, len, cd, iconveh_error, NULL, + &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) + return result; + + conversion_error (context); + /* NOTREACHED */ + return NULL; +} + static void -convert_string_list (iconv_t cd, string_list_ty *slp, +convert_string_list (const iconveh_t *cd, string_list_ty *slp, const struct conversion_context* context) { size_t i; @@ -104,7 +125,7 @@ convert_string_list (iconv_t cd, string_list_ty *slp, } static void -convert_prev_msgid (iconv_t cd, message_ty *mp, +convert_prev_msgid (const iconveh_t *cd, message_ty *mp, const struct conversion_context* context) { if (mp->prev_msgctxt != NULL) @@ -116,7 +137,7 @@ convert_prev_msgid (iconv_t cd, message_ty *mp, } static void -convert_msgid (iconv_t cd, message_ty *mp, +convert_msgid (const iconveh_t *cd, message_ty *mp, const struct conversion_context* context) { if (mp->msgctxt != NULL) @@ -127,7 +148,7 @@ convert_msgid (iconv_t cd, message_ty *mp, } static void -convert_msgstr (iconv_t cd, message_ty *mp, +convert_msgstr (const iconveh_t *cd, message_ty *mp, const struct conversion_context* context) { char *result = NULL; @@ -136,7 +157,8 @@ convert_msgstr (iconv_t cd, message_ty *mp, if (!(mp->msgstr_len > 0 && mp->msgstr[mp->msgstr_len - 1] == '\0')) abort (); - if (xmem_cd_iconv (mp->msgstr, mp->msgstr_len, cd, &result, &resultlen) == 0) + if (xmem_cd_iconveh (mp->msgstr, mp->msgstr_len, cd, iconveh_error, NULL, + &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. */ @@ -275,17 +297,10 @@ input file doesn't contain a header entry with a charset specification")); if (canon_from_code != canon_to_code) { #if HAVE_ICONV - iconv_t cd; + iconveh_t cd; struct conversion_context context; - /* Avoid glibc-2.1 bug with EUC-KR. */ -# if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION - if (strcmp (canon_from_code, "EUC-KR") == 0) - cd = (iconv_t)(-1); - else -# endif - cd = iconv_open (canon_to_code, canon_from_code); - if (cd == (iconv_t)(-1)) + if (iconveh_open (canon_to_code, canon_from_code, &cd) < 0) po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, xasprintf (_("\ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \ @@ -305,14 +320,14 @@ and iconv() does not support this conversion."), || !is_ascii_string (mp->msgid)) msgids_changed = true; context.message = mp; - convert_string_list (cd, mp->comment, &context); - convert_string_list (cd, mp->comment_dot, &context); - convert_prev_msgid (cd, mp, &context); - convert_msgid (cd, mp, &context); - convert_msgstr (cd, mp, &context); + convert_string_list (&cd, mp->comment, &context); + convert_string_list (&cd, mp->comment_dot, &context); + convert_prev_msgid (&cd, mp, &context); + convert_msgid (&cd, mp, &context); + convert_msgstr (&cd, mp, &context); } - iconv_close (cd); + iconveh_close (&cd); if (msgids_changed) if (message_list_msgids_changed (mlp)) @@ -373,13 +388,14 @@ target charset \"%s\" is not a portable encoding name."), #if HAVE_ICONV static bool -iconvable_string (iconv_t cd, const char *string) +iconvable_string (const iconveh_t *cd, const char *string) { size_t len = strlen (string) + 1; char *result = NULL; size_t resultlen = 0; - if (xmem_cd_iconv (string, len, cd, &result, &resultlen) == 0) + if (xmem_cd_iconveh (string, len, cd, iconveh_error, NULL, + &result, &resultlen) == 0) { /* Test if the result has exactly one NUL byte, at the end. */ bool ok = (resultlen > 0 && result[resultlen - 1] == '\0' @@ -391,7 +407,7 @@ iconvable_string (iconv_t cd, const char *string) } static bool -iconvable_string_list (iconv_t cd, string_list_ty *slp) +iconvable_string_list (const iconveh_t *cd, string_list_ty *slp) { size_t i; @@ -403,7 +419,7 @@ iconvable_string_list (iconv_t cd, string_list_ty *slp) } static bool -iconvable_prev_msgid (iconv_t cd, message_ty *mp) +iconvable_prev_msgid (const iconveh_t *cd, message_ty *mp) { if (mp->prev_msgctxt != NULL) if (!iconvable_string (cd, mp->prev_msgctxt)) @@ -418,7 +434,7 @@ iconvable_prev_msgid (iconv_t cd, message_ty *mp) } static bool -iconvable_msgid (iconv_t cd, message_ty *mp) +iconvable_msgid (const iconveh_t *cd, message_ty *mp) { if (mp->msgctxt != NULL) if (!iconvable_string (cd, mp->msgctxt)) @@ -432,7 +448,7 @@ iconvable_msgid (iconv_t cd, message_ty *mp) } static bool -iconvable_msgstr (iconv_t cd, message_ty *mp) +iconvable_msgstr (const iconveh_t *cd, message_ty *mp) { char *result = NULL; size_t resultlen = 0; @@ -440,7 +456,8 @@ iconvable_msgstr (iconv_t cd, message_ty *mp) if (!(mp->msgstr_len > 0 && mp->msgstr[mp->msgstr_len - 1] == '\0')) abort (); - if (xmem_cd_iconv (mp->msgstr, mp->msgstr_len, cd, &result, &resultlen) == 0) + if (xmem_cd_iconveh (mp->msgstr, mp->msgstr_len, cd, iconveh_error, NULL, + &result, &resultlen) == 0) { bool ok = false; @@ -551,16 +568,9 @@ is_message_list_iconvable (message_list_ty *mlp, if (canon_from_code != canon_to_code) { #if HAVE_ICONV - iconv_t cd; + iconveh_t cd; - /* Avoid glibc-2.1 bug with EUC-KR. */ -# if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION - if (strcmp (canon_from_code, "EUC-KR") == 0) - cd = (iconv_t)(-1); - else -# endif - cd = iconv_open (canon_to_code, canon_from_code); - if (cd == (iconv_t)(-1)) + if (iconveh_open (canon_to_code, canon_from_code, &cd) < 0) /* iconv() doesn't support this conversion. */ return false; @@ -568,15 +578,15 @@ is_message_list_iconvable (message_list_ty *mlp, { message_ty *mp = mlp->item[j]; - if (!(iconvable_string_list (cd, mp->comment) - && iconvable_string_list (cd, mp->comment_dot) - && iconvable_prev_msgid (cd, mp) - && iconvable_msgid (cd, mp) - && iconvable_msgstr (cd, mp))) + if (!(iconvable_string_list (&cd, mp->comment) + && iconvable_string_list (&cd, mp->comment_dot) + && iconvable_prev_msgid (&cd, mp) + && iconvable_msgid (&cd, mp) + && iconvable_msgstr (&cd, mp))) return false; } - iconv_close (cd); + iconveh_close (&cd); #else /* This version was built without iconv(). */ return false; diff --git a/gettext-tools/src/msgl-iconv.h b/gettext-tools/src/msgl-iconv.h index d3ce2eac1..5833db11a 100644 --- a/gettext-tools/src/msgl-iconv.h +++ b/gettext-tools/src/msgl-iconv.h @@ -1,5 +1,5 @@ /* Message list character set conversion. - Copyright (C) 2001-2003, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005-2006, 2009 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -42,9 +42,10 @@ struct conversion_context const message_ty *message; /* message being converted, or NULL */ }; -/* Converts the STRING through the conversion descriptor CD. */ -extern char *convert_string (iconv_t cd, const char *string, - const struct conversion_context* context); +/* Converts the STRING through the conversion descriptor CD. + Assumes that either FROM_CODE or TO_CODE is UTF-8. */ +extern char *convert_string_directly (iconv_t cd, const char *string, + const struct conversion_context* context); #endif diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index e96c44ced..1e7d800bf 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -1973,12 +1973,13 @@ Please specify the source encoding through --from-code."))); context.from_filename = file_name; context.message = NULL; - string = convert_string (xgettext_current_source_iconv, string, &context); + string = convert_string_directly (xgettext_current_source_iconv, string, + &context); #else /* If we don't have iconv(), the only supported values for xgettext_global_source_encoding and thus also for xgettext_current_source_encoding are ASCII and UTF-8. - convert_string() should not be called in this case. */ + convert_string_directly() should not be called in this case. */ abort (); #endif }