diff options
-rw-r--r-- | gettext-tools/src/ChangeLog | 13 | ||||
-rw-r--r-- | gettext-tools/src/msgl-iconv.c | 57 | ||||
-rw-r--r-- | gettext-tools/src/msgl-iconv.h | 15 | ||||
-rw-r--r-- | gettext-tools/src/xgettext.c | 12 |
4 files changed, 79 insertions, 18 deletions
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 9a75d92..0036cab 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,16 @@ +2005-05-01 Bruno Haible <bruno@clisp.org> + + Improved error message. + * msgl-iconv.h (struct conversion_context): New type. + (convert_string): Add context argument. + * msgl-iconv.c (conversion_error): New function. + (convert_string, convert_string_list, convert_msgid, convert_msgstr): + Add context argument. + (iconv_message_list): Construct context for them. + * xgettext.c (convert_string): Add context argument. + (from_current_source_encoding): Construct context for convert_string. + Reported by Hans Ulrich Niedermann <debian@n-dimensional.de>. + 2005-04-18 Bruno Haible <bruno@clisp.org> * po-lex.h (po_gram_error, po_gram_error_at_line): Test for diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index d5f93b7..f1c549e 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 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005 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 @@ -171,8 +171,29 @@ iconv_string (iconv_t cd, const char *start, const char *end, #undef tmpbufsize } +static void conversion_error (const struct conversion_context* context) +#if defined __GNUC__ && ((__GNUC__ == 2 && __GNUC_MINOR__ >= 5) || __GNUC__ > 2) + __attribute__ ((noreturn)) +#endif +; +static void +conversion_error (const struct conversion_context* context) +{ + if (context->to_code == po_charset_utf8) + /* If a conversion to UTF-8 fails, the problem lies in the input. */ + error (EXIT_FAILURE, 0, _("%s: input is not valid in \"%s\" encoding"), + context->from_filename, context->from_code); + else + error (EXIT_FAILURE, 0, + _("%s: error while converting from \"%s\" encoding to \"%s\" encoding"), + context->from_filename, context->from_code, context->to_code); + /* NOTREACHED */ + abort (); +} + char * -convert_string (iconv_t cd, const char *string) +convert_string (iconv_t cd, const char *string, + const struct conversion_context* context) { size_t len = strlen (string) + 1; char *result = NULL; @@ -184,31 +205,34 @@ convert_string (iconv_t cd, const char *string) && strlen (result) == resultlen - 1) return result; - error (EXIT_FAILURE, 0, _("conversion failure")); + conversion_error (context); /* NOTREACHED */ return NULL; } static void -convert_string_list (iconv_t cd, string_list_ty *slp) +convert_string_list (iconv_t cd, string_list_ty *slp, + const struct conversion_context* context) { size_t i; if (slp != NULL) for (i = 0; i < slp->nitems; i++) - slp->item[i] = convert_string (cd, slp->item[i]); + slp->item[i] = convert_string (cd, slp->item[i], context); } static void -convert_msgid (iconv_t cd, message_ty *mp) +convert_msgid (iconv_t cd, message_ty *mp, + const struct conversion_context* context) { - mp->msgid = convert_string (cd, mp->msgid); + mp->msgid = convert_string (cd, mp->msgid, context); if (mp->msgid_plural != NULL) - mp->msgid_plural = convert_string (cd, mp->msgid_plural); + mp->msgid_plural = convert_string (cd, mp->msgid_plural, context); } static void -convert_msgstr (iconv_t cd, message_ty *mp) +convert_msgstr (iconv_t cd, message_ty *mp, + const struct conversion_context* context) { char *result = NULL; size_t resultlen; @@ -242,7 +266,7 @@ convert_msgstr (iconv_t cd, message_ty *mp) } } - error (EXIT_FAILURE, 0, _("conversion failure")); + conversion_error (context); } #endif @@ -345,6 +369,7 @@ input file doesn't contain a header entry with a charset specification")); { #if HAVE_ICONV iconv_t cd; + struct conversion_context context; bool msgids_changed; /* Avoid glibc-2.1 bug with EUC-KR. */ @@ -360,6 +385,10 @@ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \ and iconv() does not support this conversion."), canon_from_code, canon_to_code, basename (program_name)); + context.from_code = canon_from_code; + context.to_code = canon_to_code; + context.from_filename = from_filename; + msgids_changed = false; for (j = 0; j < mlp->nitems; j++) { @@ -367,10 +396,10 @@ and iconv() does not support this conversion."), if (!is_ascii_string (mp->msgid)) msgids_changed = true; - convert_string_list (cd, mp->comment); - convert_string_list (cd, mp->comment_dot); - convert_msgid (cd, mp); - convert_msgstr (cd, mp); + convert_string_list (cd, mp->comment, &context); + convert_string_list (cd, mp->comment_dot, &context); + convert_msgid (cd, mp, &context); + convert_msgstr (cd, mp, &context); } iconv_close (cd); diff --git a/gettext-tools/src/msgl-iconv.h b/gettext-tools/src/msgl-iconv.h index 44acb71..2696dd1 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 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2005 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 @@ -32,8 +32,19 @@ extern "C" { #if HAVE_ICONV + +/* A context, used for accurate error messages. */ +struct conversion_context +{ + const char *from_code; /* canonicalized encoding name for input */ + const char *to_code; /* canonicalized encoding name for output */ + const char *from_filename; /* file name where the input comes from */ +}; + /* Converts the STRING through the conversion descriptor CD. */ -extern char *convert_string (iconv_t cd, const char *string); +extern char *convert_string (iconv_t cd, const char *string, + const struct conversion_context* context); + #endif /* Converts the message list MLP to the (already canonicalized) encoding diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index eb035f9..30b6608 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -1647,7 +1647,7 @@ extract_from_file (const char *file_name, extractor_ty extractor, 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. */ -#define convert_string(cd,string) (abort (), (string)) +#define convert_string(cd,string,context) (abort (), (string)) #endif /* Convert the given string from xgettext_current_source_encoding to @@ -1677,7 +1677,15 @@ Please specify the source encoding through --from-code.\n"), } } else if (xgettext_current_source_encoding != po_charset_utf8) - string = convert_string (xgettext_current_source_iconv, string); + { + struct conversion_context context; + + context.from_code = xgettext_current_source_encoding; + context.to_code = po_charset_utf8; + context.from_filename = file_name; + + string = convert_string (xgettext_current_source_iconv, string, &context); + } return (char *) string; } |