From: Bruno Haible Date: Sat, 3 Aug 2024 09:40:26 +0000 (+0200) Subject: Add an xerror_handler parameter to msgdomain_list_print. X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=cca977f8f238b778307eed69497d27b71e6f2fcd;p=thirdparty%2Fgettext.git Add an xerror_handler parameter to msgdomain_list_print. * gettext-tools/src/write-catalog.h: Include xerror-handler.h. (struct catalog_output_format): Add xerror_handler_ty parameter to the print method. (msgdomain_list_print): Add xerror_handler_ty parameter. * gettext-tools/src/write-catalog.c: Include xerror-handler.h instead of po-xerror.h. (msgdomain_list_print): Add xerror_handler_ty parameter. Use it for error handling. * gettext-tools/src/write-po.c: Include xerror-handler.h instead of po-xerror.h. (wrap, message_print, message_print_obsolete, msgdomain_list_print_po): Add xerror_handler_ty parameter. Use it for error handling. * gettext-tools/src/write-properties.c: Include xerror-handler.h. (write_properties, msgdomain_list_print_properties): Add xerror_handler_ty parameter. Use it for error handling. * gettext-tools/src/write-stringtable.c: Include xerror-handler.h. (write_stringtable, msgdomain_list_print_stringtable): Add xerror_handler_ty parameter. Use it for error handling. * gettext-tools/libgettextpo/gettext-po.c (po_file_write): Pass a stack-allocated xerror_handler to msgdomain_list_print. * gettext-tools/src/msgl-iconv.h: Include xerror-handler.h. (iconv_message_list, iconv_msgdomain_list): Add xerror_handler_ty parameter. * gettext-tools/src/msgl-iconv.c: Include xerror-handler.h instead of po-xerror.h. (conversion_error, convert_string, convert_string_list, convert_prev_msgid, convert_msgid, convert_msgstr, iconv_message_list_internal, iconv_message_list, iconv_msgdomain_list): Add xerror_handler_ty parameter. Use it for error handling. (convert_string_directly, convert_string_desc_directly): Use the default xerror_handler. * gettext-tools/src/msgattrib.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msgcat.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msgcmp.c: Include xerror-handler.h. (compare): Use the default xerror_handler. * gettext-tools/src/msgcomm.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msgconv.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msgen.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msgfilter.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msgfmt.c: Include xerror-handler.h. (msgfmt_operand_list_add_from_directory): Use the default xerror_handler. * gettext-tools/src/msggrep.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msginit.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msgl-cat.c: Include xerror-handler.h. (catenate_msgdomain_list): Use the default xerror_handler. * gettext-tools/src/msgmerge.c: Include xerror-handler.h. (main, merge): Use the default xerror_handler. * gettext-tools/src/msgunfmt.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/msguniq.c: Include xerror-handler.h. (main): Use the default xerror_handler. * gettext-tools/src/write-csharp.c: Include xerror-handler.h. (msgdomain_write_csharp): Use the default xerror_handler. * gettext-tools/src/write-desktop.c: Include xerror-handler.h. (msgdomain_write_desktop): Use the default xerror_handler. * gettext-tools/src/write-java.c: Include xerror-handler.h. (msgdomain_write_java): Use the default xerror_handler. * gettext-tools/src/write-mo.c: Include xerror-handler.h. (msgdomain_write_mo): Use the default xerror_handler. * gettext-tools/src/write-qt.c: Include xerror-handler.h. (msgdomain_write_qt): Use the default xerror_handler. * gettext-tools/src/write-resources.c: Include xerror-handler.h. (msgdomain_write_csharp_resources): Use the default xerror_handler. * gettext-tools/src/write-tcl.c: Include xerror-handler.h. (msgdomain_write_tcl): Use the default xerror_handler. * gettext-tools/src/write-xml.c: Include xerror-handler.h. (msgdomain_write_xml): Use the default xerror_handler. * gettext-tools/src/x-po.c (extract): Use the default xerror_handler. * gettext-tools/src/xgettext.c: Include xerror-handler.h. (main, finalize_header): Use the default xerror_handler. --- diff --git a/gettext-tools/libgettextpo/gettext-po.c b/gettext-tools/libgettextpo/gettext-po.c index 4cf51709d..43cea1136 100644 --- a/gettext-tools/libgettextpo/gettext-po.c +++ b/gettext-tools/libgettextpo/gettext-po.c @@ -139,19 +139,19 @@ po_file_read (const char *filename, po_xerror_handler_t handler) po_file_t po_file_write (po_file_t file, const char *filename, po_xerror_handler_t handler) { - /* Establish error handler around msgdomain_list_print(). */ - po_xerror = - (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *)) - handler->xerror; - po_xerror2 = - (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *, const message_ty *, const char *, size_t, size_t, int, const char *)) - handler->xerror2; - - msgdomain_list_print (file->mdlp, filename, &output_format_po, true, false); + /* Establish error handler for msgdomain_list_print(). */ + unsigned int error_count = 0; + struct xerror_handler local_xerror_handler = + { + (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *)) + handler->xerror, + (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *, const message_ty *, const char *, size_t, size_t, int, const char *)) + handler->xerror2, + &error_count + }; - /* Restore error handler. */ - po_xerror = textmode_xerror; - po_xerror2 = textmode_xerror2; + msgdomain_list_print (file->mdlp, filename, &output_format_po, + &local_xerror_handler, true, false); return file; } diff --git a/gettext-tools/src/msgattrib.c b/gettext-tools/src/msgattrib.c index 88ea68de1..67407807a 100644 --- a/gettext-tools/src/msgattrib.c +++ b/gettext-tools/src/msgattrib.c @@ -45,6 +45,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "propername.h" #include "xalloc.h" #include "gettext.h" @@ -400,7 +401,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_sort_by_msgid (result); /* Write the PO file. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgcat.c b/gettext-tools/src/msgcat.c index 6554b8ce1..2fb6ad356 100644 --- a/gettext-tools/src/msgcat.c +++ b/gettext-tools/src/msgcat.c @@ -47,6 +47,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "msgl-cat.h" #include "msgl-header.h" #include "propername.h" @@ -346,7 +347,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_set_header_field (result, "Language:", catalogname); /* Write the PO file. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgcmp.c b/gettext-tools/src/msgcmp.c index 2d55ca33b..2b744397b 100644 --- a/gettext-tools/src/msgcmp.c +++ b/gettext-tools/src/msgcmp.c @@ -42,6 +42,7 @@ #include "read-stringtable.h" #include "xmalloca.h" #include "po-xerror.h" +#include "xerror-handler.h" #include "xvasprintf.h" #include "po-charset.h" #include "msgl-iconv.h" @@ -435,7 +436,8 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax) } } if (was_utf8) - def = iconv_msgdomain_list (def, po_charset_utf8, true, fn1); + def = iconv_msgdomain_list (def, po_charset_utf8, true, fn1, + textmode_xerror_handler); } /* Determine canonicalized encoding name of the definitions now, after diff --git a/gettext-tools/src/msgcomm.c b/gettext-tools/src/msgcomm.c index 44287ad32..a740a661b 100644 --- a/gettext-tools/src/msgcomm.c +++ b/gettext-tools/src/msgcomm.c @@ -47,6 +47,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "msgl-cat.h" #include "propername.h" #include "gettext.h" @@ -338,7 +339,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_sort_by_msgid (result); /* Write the PO file. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgconv.c b/gettext-tools/src/msgconv.c index fd1075e70..a5a678794 100644 --- a/gettext-tools/src/msgconv.c +++ b/gettext-tools/src/msgconv.c @@ -46,6 +46,7 @@ #include "write-properties.h" #include "write-stringtable.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "localcharset.h" #include "propername.h" #include "gettext.h" @@ -277,7 +278,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Convert if and only if the output syntax supports different encodings. */ if (!output_syntax->requires_utf8) - result = iconv_msgdomain_list (result, to_code, true, input_file); + result = iconv_msgdomain_list (result, to_code, true, input_file, + textmode_xerror_handler); /* Sort the results. */ if (sort_by_filepos) @@ -286,7 +288,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_sort_by_msgid (result); /* Write the merged message list out. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgen.c b/gettext-tools/src/msgen.c index 6d975f1c8..c635b8f95 100644 --- a/gettext-tools/src/msgen.c +++ b/gettext-tools/src/msgen.c @@ -47,6 +47,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "propername.h" #include "gettext.h" @@ -283,7 +284,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_set_header_field (result, "Language:", catalogname); /* Write the merged message list out. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgfilter.c b/gettext-tools/src/msgfilter.c index 151ff8d14..174498154 100644 --- a/gettext-tools/src/msgfilter.c +++ b/gettext-tools/src/msgfilter.c @@ -57,6 +57,7 @@ #include "xsetenv.h" #include "filters.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "po-charset.h" #include "propername.h" #include "gettext.h" @@ -351,21 +352,24 @@ There is NO WARRANTY, to the extent permitted by law.\n\ filter = serbian_to_latin; /* Convert the input to UTF-8 first. */ - result = iconv_msgdomain_list (result, po_charset_utf8, true, input_file); + result = iconv_msgdomain_list (result, po_charset_utf8, true, input_file, + textmode_xerror_handler); } else if (strcmp (sub_name, "quot") == 0 && sub_argc == 1) { filter = ascii_quote_to_unicode; /* Convert the input to UTF-8 first. */ - result = iconv_msgdomain_list (result, po_charset_utf8, true, input_file); + result = iconv_msgdomain_list (result, po_charset_utf8, true, input_file, + textmode_xerror_handler); } else if (strcmp (sub_name, "boldquot") == 0 && sub_argc == 1) { filter = ascii_quote_to_unicode_bold; /* Convert the input to UTF-8 first. */ - result = iconv_msgdomain_list (result, po_charset_utf8, true, input_file); + result = iconv_msgdomain_list (result, po_charset_utf8, true, input_file, + textmode_xerror_handler); } else { @@ -393,7 +397,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_sort_by_msgid (result); /* Write the merged message list out. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index eeeb13851..d1a275ec6 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -62,6 +62,7 @@ #include "read-stringtable.h" #include "read-desktop.h" #include "po-xerror.h" +#include "xerror-handler.h" #include "po-charset.h" #include "msgl-check.h" #include "msgl-iconv.h" @@ -1621,7 +1622,8 @@ msgfmt_operand_list_add_from_directory (msgfmt_operand_list_ty *operands, } /* Convert the messages to Unicode. */ - iconv_message_list (mlp, NULL, po_charset_utf8, NULL); + iconv_message_list (mlp, NULL, po_charset_utf8, NULL, + textmode_xerror_handler); msgfmt_operand_list_append (operands, language, mlp); } diff --git a/gettext-tools/src/msggrep.c b/gettext-tools/src/msggrep.c index 408286316..7d773a4b8 100644 --- a/gettext-tools/src/msggrep.c +++ b/gettext-tools/src/msggrep.c @@ -56,6 +56,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "str-list.h" #include "msgl-charset.h" #include "xalloc.h" @@ -481,7 +482,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_sort_by_msgid (result); /* Write the merged message list out. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (EXIT_SUCCESS); } diff --git a/gettext-tools/src/msginit.c b/gettext-tools/src/msginit.c index 9cf0d997c..1258fecc6 100644 --- a/gettext-tools/src/msginit.c +++ b/gettext-tools/src/msginit.c @@ -63,6 +63,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "po-charset.h" #include "localcharset.h" #include "localename.h" @@ -378,7 +379,8 @@ the output .po file through the --output-file option.\n"), result = update_msgstr_plurals (result); /* Write the modified message list out. */ - msgdomain_list_print (result, output_file, output_syntax, true, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, true, false); if (!no_translator) fprintf (stderr, "\n"); diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c index a3bba5f53..afa01f6bf 100644 --- a/gettext-tools/src/msgl-cat.c +++ b/gettext-tools/src/msgl-cat.c @@ -40,6 +40,7 @@ #include "msgl-ofn.h" #include "msgl-equal.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "xalloc.h" #include "xmalloca.h" #include "c-strstr.h" @@ -532,7 +533,7 @@ Converting the output to %s.\n\ if (!(to_code == NULL && canon_charsets[n][k] == canon_to_code)) if (iconv_message_list (mdlp->item[k]->messages, canon_charsets[n][k], canon_to_code, - files[n])) + files[n], textmode_xerror_handler)) { multiline_error (xstrdup (""), xasprintf (_("\ diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index 33b1aa88a..05b09676d 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-2009, 2019-2023 Free Software Foundation, Inc. + Copyright (C) 2001-2024 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -46,7 +46,7 @@ #include "xmalloca.h" #include "c-strstr.h" #include "xvasprintf.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "gettext.h" #define _(str) gettext (str) @@ -54,20 +54,23 @@ #if HAVE_ICONV -_GL_NORETURN_FUNC static void conversion_error (const struct conversion_context* context); +_GL_NORETURN_FUNC static void +conversion_error (const struct conversion_context* context, + xerror_handler_ty xeh); static void -conversion_error (const struct conversion_context* context) +conversion_error (const struct conversion_context* context, + xerror_handler_ty xeh) { if (context->to_code == po_charset_utf8) /* If a conversion to UTF-8 fails, the problem lies in the input. */ - po_xerror (PO_SEVERITY_FATAL_ERROR, context->message, NULL, 0, 0, false, - xasprintf (_("%s: input is not valid in \"%s\" encoding"), - context->from_filename, context->from_code)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, context->message, NULL, 0, 0, false, + xasprintf (_("%s: input is not valid in \"%s\" encoding"), + context->from_filename, context->from_code)); else - po_xerror (PO_SEVERITY_FATAL_ERROR, context->message, NULL, 0, 0, false, - xasprintf (_("%s: error while converting from \"%s\" encoding to \"%s\" encoding"), - context->from_filename, context->from_code, - context->to_code)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, context->message, NULL, 0, 0, false, + xasprintf (_("%s: error while converting from \"%s\" encoding to \"%s\" encoding"), + context->from_filename, context->from_code, + context->to_code)); /* NOTREACHED */ abort (); } @@ -86,7 +89,7 @@ convert_string_directly (iconv_t cd, const char *string, && strlen (result) == resultlen - 1) return result; - conversion_error (context); + conversion_error (context, textmode_xerror_handler); /* NOTREACHED */ return NULL; } @@ -102,14 +105,15 @@ convert_string_desc_directly (iconv_t cd, string_desc_t string, cd, &result, &resultlen) == 0) return string_desc_new_addr (resultlen, result); - conversion_error (context); + conversion_error (context, textmode_xerror_handler); /* NOTREACHED */ return string_desc_new_empty (); } static char * convert_string (const iconveh_t *cd, const char *string, - const struct conversion_context* context) + const struct conversion_context* context, + xerror_handler_ty xeh) { size_t len = strlen (string) + 1; char *result = NULL; @@ -122,48 +126,53 @@ convert_string (const iconveh_t *cd, const char *string, && strlen (result) == resultlen - 1) return result; - conversion_error (context); + conversion_error (context, xeh); /* NOTREACHED */ return NULL; } static void convert_string_list (const iconveh_t *cd, string_list_ty *slp, - const struct conversion_context* context) + const struct conversion_context* context, + xerror_handler_ty xeh) { size_t i; if (slp != NULL) for (i = 0; i < slp->nitems; i++) - slp->item[i] = convert_string (cd, slp->item[i], context); + slp->item[i] = convert_string (cd, slp->item[i], context, xeh); } static void convert_prev_msgid (const iconveh_t *cd, message_ty *mp, - const struct conversion_context* context) + const struct conversion_context* context, + xerror_handler_ty xeh) { if (mp->prev_msgctxt != NULL) - mp->prev_msgctxt = convert_string (cd, mp->prev_msgctxt, context); + mp->prev_msgctxt = convert_string (cd, mp->prev_msgctxt, context, xeh); if (mp->prev_msgid != NULL) - mp->prev_msgid = convert_string (cd, mp->prev_msgid, context); + mp->prev_msgid = convert_string (cd, mp->prev_msgid, context, xeh); if (mp->prev_msgid_plural != NULL) - mp->prev_msgid_plural = convert_string (cd, mp->prev_msgid_plural, context); + mp->prev_msgid_plural = + convert_string (cd, mp->prev_msgid_plural, context, xeh); } static void convert_msgid (const iconveh_t *cd, message_ty *mp, - const struct conversion_context* context) + const struct conversion_context* context, + xerror_handler_ty xeh) { if (mp->msgctxt != NULL) - mp->msgctxt = convert_string (cd, mp->msgctxt, context); - mp->msgid = convert_string (cd, mp->msgid, context); + mp->msgctxt = convert_string (cd, mp->msgctxt, context, xeh); + mp->msgid = convert_string (cd, mp->msgid, context, xeh); if (mp->msgid_plural != NULL) - mp->msgid_plural = convert_string (cd, mp->msgid_plural, context); + mp->msgid_plural = convert_string (cd, mp->msgid_plural, context, xeh); } static void convert_msgstr (const iconveh_t *cd, message_ty *mp, - const struct conversion_context* context) + const struct conversion_context* context, + xerror_handler_ty xeh) { char *result = NULL; size_t resultlen = 0; @@ -197,7 +206,7 @@ convert_msgstr (const iconveh_t *cd, message_ty *mp, } } - conversion_error (context); + conversion_error (context, xeh); } #endif @@ -208,7 +217,8 @@ iconv_message_list_internal (message_list_ty *mlp, const char *canon_from_code, const char *canon_to_code, bool update_header, - const char *from_filename) + const char *from_filename, + xerror_handler_ty xeh) { bool canon_from_code_overridden = (canon_from_code != NULL); bool msgids_changed; @@ -260,10 +270,10 @@ iconv_message_list_internal (message_list_ty *mlp, || is_ascii_message_list (mlp))) canon_charset = po_charset_ascii; else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, - false, - xasprintf (_("present charset \"%s\" is not a portable encoding name"), - charset)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, + false, + xasprintf (_("present charset \"%s\" is not a portable encoding name"), + charset)); } } else @@ -271,10 +281,10 @@ iconv_message_list_internal (message_list_ty *mlp, if (canon_from_code == NULL) canon_from_code = canon_charset; else if (canon_from_code != canon_charset) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, - false, - xasprintf (_("two different charsets \"%s\" and \"%s\" in input file"), - canon_from_code, canon_charset)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, + false, + xasprintf (_("two different charsets \"%s\" and \"%s\" in input file"), + canon_from_code, canon_charset)); } freea (charset); @@ -302,8 +312,8 @@ iconv_message_list_internal (message_list_ty *mlp, if (is_ascii_message_list (mlp)) canon_from_code = po_charset_ascii; else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - _("input file doesn't contain a header entry with a charset specification")); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("input file doesn't contain a header entry with a charset specification")); } msgids_changed = false; @@ -316,10 +326,10 @@ iconv_message_list_internal (message_list_ty *mlp, struct conversion_context context; 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(), and iconv() does not support this conversion."), - canon_from_code, canon_to_code, - last_component (program_name))); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), and iconv() does not support this conversion."), + canon_from_code, canon_to_code, + last_component (program_name))); context.from_code = canon_from_code; context.to_code = canon_to_code; @@ -333,25 +343,25 @@ iconv_message_list_internal (message_list_ty *mlp, || !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, xeh); + convert_string_list (&cd, mp->comment_dot, &context, xeh); + convert_prev_msgid (&cd, mp, &context, xeh); + convert_msgid (&cd, mp, &context, xeh); + convert_msgstr (&cd, mp, &context, xeh); } iconveh_close (&cd); if (msgids_changed) if (message_list_msgids_changed (mlp)) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("Conversion from \"%s\" to \"%s\" introduces duplicates: some different msgids become equal."), - canon_from_code, canon_to_code)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("Conversion from \"%s\" to \"%s\" introduces duplicates: some different msgids become equal."), + canon_from_code, canon_to_code)); #else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("Cannot convert from \"%s\" to \"%s\". %s relies on iconv(). This version was built without iconv()."), - canon_from_code, canon_to_code, - last_component (program_name))); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("Cannot convert from \"%s\" to \"%s\". %s relies on iconv(). This version was built without iconv()."), + canon_from_code, canon_to_code, + last_component (program_name))); #endif } @@ -361,18 +371,19 @@ iconv_message_list_internal (message_list_ty *mlp, bool iconv_message_list (message_list_ty *mlp, const char *canon_from_code, const char *canon_to_code, - const char *from_filename) + const char *from_filename, xerror_handler_ty xeh) { return iconv_message_list_internal (mlp, canon_from_code, canon_to_code, true, - from_filename); + from_filename, xeh); } msgdomain_list_ty * iconv_msgdomain_list (msgdomain_list_ty *mdlp, const char *to_code, bool update_header, - const char *from_filename) + const char *from_filename, + xerror_handler_ty xeh) { const char *canon_to_code; size_t k; @@ -380,23 +391,23 @@ iconv_msgdomain_list (msgdomain_list_ty *mdlp, /* Canonicalize target encoding. */ canon_to_code = po_charset_canonicalize (to_code); if (canon_to_code == NULL) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("target charset \"%s\" is not a portable encoding name."), - to_code)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("target charset \"%s\" is not a portable encoding name."), + to_code)); /* Test whether the control characters required for escaping file names with spaces are present in the target encoding. */ if (msgdomain_list_has_filenames_with_spaces (mdlp) && !(canon_to_code == po_charset_utf8 || strcmp (canon_to_code, "GB18030") == 0)) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf (_("Cannot write the control characters that protect file names with spaces in the %s encoding"), - canon_to_code)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf (_("Cannot write the control characters that protect file names with spaces in the %s encoding"), + canon_to_code)); for (k = 0; k < mdlp->nitems; k++) iconv_message_list_internal (mdlp->item[k]->messages, mdlp->encoding, canon_to_code, update_header, - from_filename); + from_filename, xeh); mdlp->encoding = canon_to_code; return mdlp; diff --git a/gettext-tools/src/msgl-iconv.h b/gettext-tools/src/msgl-iconv.h index 13bed10be..955b05779 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, 2009, 2023 Free Software Foundation, Inc. + Copyright (C) 2001-2024 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -26,6 +26,7 @@ #include "string-desc.h" #include "message.h" +#include "xerror-handler.h" #ifdef __cplusplus @@ -63,7 +64,8 @@ extern bool iconv_message_list (message_list_ty *mlp, const char *canon_from_code, const char *canon_to_code, - const char *from_filename); + const char *from_filename, + xerror_handler_ty xerror_handler); /* Converts all the message lists in MDLP to the encoding TO_CODE. UPDATE_HEADER specifies whether to update the "charset=..." specification @@ -72,7 +74,8 @@ extern msgdomain_list_ty * iconv_msgdomain_list (msgdomain_list_ty *mdlp, const char *to_code, bool update_header, - const char *from_filename); + const char *from_filename, + xerror_handler_ty xerror_handler); /* Tests whether the message list MLP could be converted to CANON_TO_CODE. The (already canonicalized) encoding before conversion can be passed as diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index 1782bef8b..481b3ae87 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -67,6 +67,7 @@ #include "plural-count.h" #include "msgl-check.h" #include "po-xerror.h" +#include "xerror-handler.h" #include "xvasprintf.h" #include "backupfile.h" #include "copy-file.h" @@ -517,14 +518,15 @@ There is NO WARRANTY, to the extent permitted by law.\n\ } /* Write the merged message list out. */ - msgdomain_list_print (result, output_file, output_syntax, true, - false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, true, false); } } else { /* Write the merged message list out. */ msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, for_msgfmt || force_po, false); } @@ -1827,11 +1829,13 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, } if (was_utf8) { - def = iconv_msgdomain_list (def, po_charset_utf8, true, fn1); + def = iconv_msgdomain_list (def, po_charset_utf8, true, fn1, + textmode_xerror_handler); if (compendiums != NULL) for (k = 0; k < compendiums->nitems; k++) iconv_message_list (compendiums->item[k], NULL, po_charset_utf8, - compendium_filenames->item[k]); + compendium_filenames->item[k], + textmode_xerror_handler); } else if (compendiums != NULL && compendiums->nitems > 0) { @@ -1898,7 +1902,8 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, for (k = 0; k < compendiums->nitems; k++) iconv_message_list (compendiums->item[k], NULL, canon_charset, - compendium_filenames->item[k]); + compendium_filenames->item[k], + textmode_xerror_handler); conversion_done = true; } } @@ -1971,12 +1976,14 @@ merge (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax, { /* It's too hairy to find out what would be the optimal target encoding. So, convert everything to UTF-8. */ - def = iconv_msgdomain_list (def, po_charset_utf8, true, fn1); + def = iconv_msgdomain_list (def, po_charset_utf8, true, fn1, + textmode_xerror_handler); if (compendiums != NULL) for (k = 0; k < compendiums->nitems; k++) iconv_message_list (compendiums->item[k], NULL, po_charset_utf8, - compendium_filenames->item[k]); + compendium_filenames->item[k], + textmode_xerror_handler); } } } diff --git a/gettext-tools/src/msgunfmt.c b/gettext-tools/src/msgunfmt.c index 80955b375..4d8a9511d 100644 --- a/gettext-tools/src/msgunfmt.c +++ b/gettext-tools/src/msgunfmt.c @@ -46,6 +46,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "propername.h" #include "gettext.h" @@ -405,7 +406,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_sort_by_msgid (result); /* Write the resulting message list to the given .po file. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); /* No problems. */ exit (EXIT_SUCCESS); diff --git a/gettext-tools/src/msguniq.c b/gettext-tools/src/msguniq.c index cbb067c20..692af237e 100644 --- a/gettext-tools/src/msguniq.c +++ b/gettext-tools/src/msguniq.c @@ -46,6 +46,7 @@ #include "write-po.h" #include "write-properties.h" #include "write-stringtable.h" +#include "xerror-handler.h" #include "msgl-cat.h" #include "propername.h" #include "gettext.h" @@ -305,7 +306,8 @@ There is NO WARRANTY, to the extent permitted by law.\n\ msgdomain_list_sort_by_msgid (result); /* Write the PO file. */ - msgdomain_list_print (result, output_file, output_syntax, force_po, false); + msgdomain_list_print (result, output_file, output_syntax, + textmode_xerror_handler, force_po, false); exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/gettext-tools/src/write-catalog.c b/gettext-tools/src/write-catalog.c index c25916d1b..b17f6a3e5 100644 --- a/gettext-tools/src/write-catalog.c +++ b/gettext-tools/src/write-catalog.c @@ -1,6 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2008, 2012, 2019-2020 Free Software - Foundation, Inc. + Copyright (C) 1995-2024 Free Software Foundation, Inc. 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 @@ -39,7 +38,7 @@ #include "fwriteerror.h" #include "error-progname.h" #include "xvasprintf.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "gettext.h" /* Our regular abbreviation. */ @@ -90,6 +89,7 @@ message_page_width_set (size_t n) void msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, catalog_output_format_ty output_syntax, + xerror_handler_ty xeh, bool force, bool debug) { bool to_stdout; @@ -121,11 +121,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, if (!output_syntax->supports_multiple_domains && mdlp->nitems > 1) { if (output_syntax->alternative_is_po) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - _("Cannot output multiple translation domains into a single file with the specified output format. Try using PO file syntax instead.")); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("Cannot output multiple translation domains into a single file with the specified output format. Try using PO file syntax instead.")); else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - _("Cannot output multiple translation domains into a single file with the specified output format.")); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("Cannot output multiple translation domains into a single file with the specified output format.")); } else { @@ -155,10 +155,10 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, if (has_context != NULL) { error_with_progname = false; - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - has_context->file_name, has_context->line_number, - (size_t)(-1), false, - _("message catalog has context dependent translations, but the output format does not support them.")); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, + has_context->file_name, has_context->line_number, + (size_t)(-1), false, + _("message catalog has context dependent translations, but the output format does not support them.")); error_with_progname = true; } } @@ -190,15 +190,15 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, { error_with_progname = false; if (output_syntax->alternative_is_java_class) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - has_plural->file_name, has_plural->line_number, - (size_t)(-1), false, - _("message catalog has plural form translations, but the output format does not support them. Try generating a Java class using \"msgfmt --java\", instead of a properties file.")); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, + has_plural->file_name, has_plural->line_number, + (size_t)(-1), false, + _("message catalog has plural form translations, but the output format does not support them. Try generating a Java class using \"msgfmt --java\", instead of a properties file.")); else - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - has_plural->file_name, has_plural->line_number, - (size_t)(-1), false, - _("message catalog has plural form translations, but the output format does not support them.")); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, + has_plural->file_name, has_plural->line_number, + (size_t)(-1), false, + _("message catalog has plural form translations, but the output format does not support them.")); error_with_progname = true; } } @@ -226,11 +226,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, if (fd < 0) { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("cannot create output file \"%s\""), - filename), - errno_description)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("cannot create output file \"%s\""), + filename), + errno_description)); } } else @@ -244,18 +244,18 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, "po-default.css"); stream = styled_ostream_create (fd, filename, TTYCTL_AUTO, style_file_name); - output_syntax->print (mdlp, stream, page_width, debug); + output_syntax->print (mdlp, stream, page_width, xeh, debug); ostream_free (stream); /* Make sure nothing went wrong. */ if (close (fd) < 0) { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while writing \"%s\" file"), - filename), - errno_description)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while writing \"%s\" file"), + filename), + errno_description)); } } else @@ -271,11 +271,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, if (fp == NULL) { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("cannot create output file \"%s\""), - filename), - errno_description)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("cannot create output file \"%s\""), + filename), + errno_description)); } } else @@ -295,14 +295,15 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, if (mdlp->encoding != po_charset_utf8) { mdlp = msgdomain_list_copy (mdlp, 0); - mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, false, NULL); + mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, false, NULL, + xeh); } style_file_prepare ("PO_STYLE", "GETTEXTSTYLESDIR", relocate (GETTEXTSTYLESDIR), "po-default.css"); html_stream = html_styled_ostream_create (stream, style_file_name); - output_syntax->print (mdlp, html_stream, page_width, debug); + output_syntax->print (mdlp, html_stream, page_width, xeh, debug); ostream_free (html_stream); } else @@ -310,11 +311,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, noop_styled_ostream_t styled_stream; styled_stream = noop_styled_ostream_create (stream, false); - output_syntax->print (mdlp, styled_stream, page_width, debug); + output_syntax->print (mdlp, styled_stream, page_width, xeh, debug); ostream_free (styled_stream); } #else - output_syntax->print (mdlp, stream, page_width, debug); + output_syntax->print (mdlp, stream, page_width, xeh, debug); /* Don't call ostream_free if file_ostream_create is a dummy. */ if (stream != fp) #endif @@ -324,11 +325,11 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, if (fwriteerror (fp)) { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while writing \"%s\" file"), - filename), - errno_description)); + xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while writing \"%s\" file"), + filename), + errno_description)); } } } diff --git a/gettext-tools/src/write-catalog.h b/gettext-tools/src/write-catalog.h index d9bbece34..9b3137188 100644 --- a/gettext-tools/src/write-catalog.h +++ b/gettext-tools/src/write-catalog.h @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2003, 2006, 2008, 2019, 2021 Free Software Foundation, Inc. + Copyright (C) 1995-2024 Free Software Foundation, Inc. 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 @@ -22,6 +22,7 @@ #include #include "message.h" +#include "xerror-handler.h" #ifdef __cplusplus @@ -33,7 +34,8 @@ extern "C" { struct catalog_output_format { /* Outputs a list of domains of messages to a stream. */ - void (*print) (msgdomain_list_ty *mdlp, ostream_t stream, size_t page_width, bool debug); + void (*print) (msgdomain_list_ty *mdlp, ostream_t stream, size_t page_width, + xerror_handler_ty xerror_handler, bool debug); /* Whether the print function requires the MDLP to be encoded in UTF-8 encoding. */ @@ -79,6 +81,7 @@ extern void msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, catalog_output_format_ty output_syntax, + xerror_handler_ty xerror_handler, bool force, bool debug); /* Sort MDLP destructively according to the given criterion. */ diff --git a/gettext-tools/src/write-csharp.c b/gettext-tools/src/write-csharp.c index c6415a6ae..dac983d8f 100644 --- a/gettext-tools/src/write-csharp.c +++ b/gettext-tools/src/write-csharp.c @@ -79,6 +79,7 @@ #include "message.h" #include "msgfmt.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "plural-exp.h" #include "po-charset.h" @@ -645,7 +646,8 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding, retval = 1; /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, + textmode_xerror_handler); /* Support for "reproducible builds": Delete information that may vary between builds in the same conditions. */ diff --git a/gettext-tools/src/write-desktop.c b/gettext-tools/src/write-desktop.c index e63b8f516..0c8f02eca 100644 --- a/gettext-tools/src/write-desktop.c +++ b/gettext-tools/src/write-desktop.c @@ -30,6 +30,7 @@ #include #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "po-charset.h" #include "read-catalog.h" @@ -203,7 +204,8 @@ msgdomain_write_desktop (message_list_ty *mlp, msgfmt_operand_list_ty operands; /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, + textmode_xerror_handler); /* Support for "reproducible builds": Delete information that may vary between builds in the same conditions. */ diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index 8fca62406..02b0add95 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -63,6 +63,7 @@ #include "message.h" #include "msgfmt.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "plural-exp.h" #include "po-charset.h" @@ -1067,7 +1068,8 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding, retval = 1; /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, + textmode_xerror_handler); /* Support for "reproducible builds": Delete information that may vary between builds in the same conditions. */ diff --git a/gettext-tools/src/write-mo.c b/gettext-tools/src/write-mo.c index c345fce9c..73e6a9ea7 100644 --- a/gettext-tools/src/write-mo.c +++ b/gettext-tools/src/write-mo.c @@ -47,6 +47,7 @@ #include "xmalloca.h" #include "po-charset.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "binary-io.h" #include "supersede.h" @@ -1195,7 +1196,8 @@ msgdomain_write_mo (message_list_ty *mlp, It is also helpful for performance on glibc systems, since most locales nowadays have UTF-8 as locale encoding, whereas some PO files still are encoded in EUC-JP or so. */ - iconv_message_list (mlp, NULL, po_charset_utf8, input_file); + iconv_message_list (mlp, NULL, po_charset_utf8, input_file, + textmode_xerror_handler); } /* Support for "reproducible builds": Delete information that may vary diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index 1c03b2932..eeb190a0e 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2010, 2012, 2014-2015, 2018-2021, 2023 Free Software Foundation, Inc. + Copyright (C) 1995-2024 Free Software Foundation, Inc. This file was written by Peter Miller @@ -49,7 +49,7 @@ #include "c-strstr.h" #include "xvasprintf.h" #include "verify.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "gettext.h" /* Our regular abbreviation. */ @@ -654,7 +654,7 @@ wrap (const message_ty *mp, ostream_t stream, const char *line_prefix, int extra_indent, const char *css_class, const char *name, const char *value, enum is_wrap do_wrap, size_t page_width, - const char *charset) + const char *charset, xerror_handler_ty xeh) { const char *canon_charset; char *fmtdir; @@ -845,8 +845,9 @@ wrap (const message_ty *mp, ostream_t stream, { if (errno == EILSEQ) { - po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false, - _("invalid multibyte sequence")); + xeh->xerror (CAT_SEVERITY_ERROR, mp, NULL, 0, 0, + false, + _("invalid multibyte sequence")); continue; } else if (errno == EINVAL) @@ -854,8 +855,9 @@ wrap (const message_ty *mp, ostream_t stream, /* This could happen if an incomplete multibyte sequence at the end of input bytes. */ - po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false, - _("incomplete multibyte sequence")); + xeh->xerror (CAT_SEVERITY_ERROR, mp, NULL, 0, 0, + false, + _("incomplete multibyte sequence")); continue; } else @@ -920,8 +922,8 @@ wrap (const message_ty *mp, ostream_t stream, char *error_message = xasprintf (_("internationalized messages should not contain the '\\%c' escape sequence"), c); - po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, false, - error_message); + xeh->xerror (CAT_SEVERITY_WARNING, mp, NULL, 0, 0, false, + error_message); free (error_message); } } @@ -982,8 +984,8 @@ wrap (const message_ty *mp, ostream_t stream, { if (errno == EILSEQ) { - po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, - false, _("invalid multibyte sequence")); + xeh->xerror (CAT_SEVERITY_ERROR, mp, NULL, 0, 0, + false, _("invalid multibyte sequence")); continue; } else @@ -1304,7 +1306,7 @@ print_blank_line (ostream_t stream) static void message_print (const message_ty *mp, ostream_t stream, const char *charset, size_t page_width, bool blank_line, - bool debug) + xerror_handler_ty xeh, bool debug) { int extra_indent; @@ -1346,13 +1348,13 @@ message_print (const message_ty *mp, ostream_t stream, begin_css_class (stream, class_previous_comment); if (mp->prev_msgctxt != NULL) wrap (mp, stream, "#| ", 0, class_previous, "msgctxt", mp->prev_msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); if (mp->prev_msgid != NULL) wrap (mp, stream, "#| ", 0, class_previous, "msgid", mp->prev_msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); if (mp->prev_msgid_plural != NULL) wrap (mp, stream, "#| ", 0, class_previous, "msgid_plural", - mp->prev_msgid_plural, mp->do_wrap, page_width, charset); + mp->prev_msgid_plural, mp->do_wrap, page_width, charset, xeh); end_css_class (stream, class_previous_comment); extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL || mp->prev_msgid_plural != NULL @@ -1373,7 +1375,7 @@ The following msgctxt contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgctxt instead.\n\ %s\n"), mp->msgctxt); - po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); + xeh->xerror (CAT_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); free (warning_message); } if (!is_ascii_string (mp->msgid) @@ -1385,21 +1387,21 @@ The following msgid contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgid instead.\n\ %s\n"), mp->msgid); - po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); + xeh->xerror (CAT_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); free (warning_message); } if (mp->msgctxt != NULL) wrap (mp, stream, NULL, extra_indent, class_msgid, "msgctxt", mp->msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); wrap (mp, stream, NULL, extra_indent, class_msgid, "msgid", mp->msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); if (mp->msgid_plural != NULL) wrap (mp, stream, NULL, extra_indent, class_msgid, "msgid_plural", - mp->msgid_plural, mp->do_wrap, page_width, charset); + mp->msgid_plural, mp->do_wrap, page_width, charset, xeh); if (mp->msgid_plural == NULL) wrap (mp, stream, NULL, extra_indent, class_msgstr, "msgstr", mp->msgstr, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); else { char prefix_buf[20]; @@ -1412,7 +1414,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ { sprintf (prefix_buf, "msgstr[%u]", i); wrap (mp, stream, NULL, extra_indent, class_msgstr, prefix_buf, p, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); } } @@ -1430,7 +1432,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ static void message_print_obsolete (const message_ty *mp, ostream_t stream, const char *charset, size_t page_width, bool blank_line, - bool debug) + xerror_handler_ty xeh, bool debug) { int extra_indent; @@ -1517,13 +1519,13 @@ message_print_obsolete (const message_ty *mp, ostream_t stream, begin_css_class (stream, class_previous_comment); if (mp->prev_msgctxt != NULL) wrap (mp, stream, "#~| ", 0, class_previous, "msgctxt", mp->prev_msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); if (mp->prev_msgid != NULL) wrap (mp, stream, "#~| ", 0, class_previous, "msgid", mp->prev_msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); if (mp->prev_msgid_plural != NULL) wrap (mp, stream, "#~| ", 0, class_previous, "msgid_plural", - mp->prev_msgid_plural, mp->do_wrap, page_width, charset); + mp->prev_msgid_plural, mp->do_wrap, page_width, charset, xeh); end_css_class (stream, class_previous_comment); extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL || mp->prev_msgid_plural != NULL @@ -1543,7 +1545,7 @@ The following msgctxt contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgctxt instead.\n\ %s\n"), mp->msgctxt); - po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); + xeh->xerror (CAT_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); free (warning_message); } if (!is_ascii_string (mp->msgid) @@ -1555,21 +1557,21 @@ The following msgid contains non-ASCII characters.\n\ This will cause problems to translators who use a character encoding\n\ different from yours. Consider using a pure ASCII msgid instead.\n\ %s\n"), mp->msgid); - po_xerror (PO_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); + xeh->xerror (CAT_SEVERITY_WARNING, mp, NULL, 0, 0, true, warning_message); free (warning_message); } if (mp->msgctxt != NULL) wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgctxt", mp->msgctxt, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgid", mp->msgid, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); if (mp->msgid_plural != NULL) wrap (mp, stream, "#~ ", extra_indent, class_msgid, "msgid_plural", - mp->msgid_plural, mp->do_wrap, page_width, charset); + mp->msgid_plural, mp->do_wrap, page_width, charset, xeh); if (mp->msgid_plural == NULL) wrap (mp, stream, "#~ ", extra_indent, class_msgstr, "msgstr", mp->msgstr, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); else { char prefix_buf[20]; @@ -1582,7 +1584,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ { sprintf (prefix_buf, "msgstr[%u]", i); wrap (mp, stream, "#~ ", extra_indent, class_msgstr, prefix_buf, p, - mp->do_wrap, page_width, charset); + mp->do_wrap, page_width, charset, xeh); } } @@ -1592,7 +1594,7 @@ different from yours. Consider using a pure ASCII msgid instead.\n\ static void msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream, - size_t page_width, bool debug) + size_t page_width, xerror_handler_ty xeh, bool debug) { size_t j, k; bool blank_line; @@ -1668,7 +1670,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream, if (!mlp->item[j]->obsolete) { message_print (mlp->item[j], stream, charset, page_width, - blank_line, debug); + blank_line, xeh, debug); blank_line = true; } @@ -1677,7 +1679,7 @@ msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream, if (mlp->item[j]->obsolete) { message_print_obsolete (mlp->item[j], stream, charset, page_width, - blank_line, debug); + blank_line, xeh, debug); blank_line = true; } diff --git a/gettext-tools/src/write-properties.c b/gettext-tools/src/write-properties.c index 706a388ba..43eb40fc2 100644 --- a/gettext-tools/src/write-properties.c +++ b/gettext-tools/src/write-properties.c @@ -35,6 +35,7 @@ #include "msgl-ascii.h" #include "msgl-iconv.h" #include "po-charset.h" +#include "xerror-handler.h" #include "unistr.h" #include "write-po.h" #include "xalloc.h" @@ -241,13 +242,14 @@ write_message (ostream_t stream, const message_ty *mp, /* Writes an entire message list to the stream. */ static void write_properties (ostream_t stream, message_list_ty *mlp, - const char *canon_encoding, size_t page_width, bool debug) + const char *canon_encoding, size_t page_width, + xerror_handler_ty xeh, bool debug) { bool blank_line; size_t j, i; /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, xeh); for (j = 0; j < mlp->nitems; ++j) { message_ty *mp = mlp->item[j]; @@ -281,7 +283,8 @@ write_properties (ostream_t stream, message_list_ty *mlp, /* Output the contents of a PO file in Java .properties syntax. */ static void msgdomain_list_print_properties (msgdomain_list_ty *mdlp, ostream_t stream, - size_t page_width, bool debug) + size_t page_width, xerror_handler_ty xeh, + bool debug) { message_list_ty *mlp; @@ -289,7 +292,7 @@ msgdomain_list_print_properties (msgdomain_list_ty *mdlp, ostream_t stream, mlp = mdlp->item[0]->messages; else mlp = message_list_alloc (false); - write_properties (stream, mlp, mdlp->encoding, page_width, debug); + write_properties (stream, mlp, mdlp->encoding, page_width, xeh, debug); } /* Describes a PO file in Java .properties syntax. */ diff --git a/gettext-tools/src/write-qt.c b/gettext-tools/src/write-qt.c index 6b603b90a..5326c3fbe 100644 --- a/gettext-tools/src/write-qt.c +++ b/gettext-tools/src/write-qt.c @@ -35,6 +35,7 @@ #include "message.h" #include "po-charset.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "hash-string.h" #include "unistr.h" @@ -674,7 +675,8 @@ but the Qt message catalog format doesn't support plural handling\n"))); } /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, + textmode_xerror_handler); /* Determine whether mlp has non-ISO-8859-1 msgctxt entries. */ { diff --git a/gettext-tools/src/write-resources.c b/gettext-tools/src/write-resources.c index a6fc2b423..40aca4ec8 100644 --- a/gettext-tools/src/write-resources.c +++ b/gettext-tools/src/write-resources.c @@ -37,6 +37,7 @@ #include "message.h" #include "msgfmt.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "po-charset.h" #include "xalloc.h" @@ -156,7 +157,8 @@ but the C# .resources format doesn't support plural handling\n"))); } /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, + textmode_xerror_handler); /* Support for "reproducible builds": Delete information that may vary between builds in the same conditions. */ diff --git a/gettext-tools/src/write-stringtable.c b/gettext-tools/src/write-stringtable.c index a86c9d9a7..cfe59da6b 100644 --- a/gettext-tools/src/write-stringtable.c +++ b/gettext-tools/src/write-stringtable.c @@ -1,5 +1,5 @@ /* Writing NeXTstep/GNUstep .strings files. - Copyright (C) 2003-2023 Free Software Foundation, Inc. + Copyright (C) 2003-2024 Free Software Foundation, Inc. Written by Bruno Haible , 2003. This program is free software: you can redistribute it and/or modify @@ -32,6 +32,7 @@ #include "msgl-ascii.h" #include "msgl-iconv.h" #include "po-charset.h" +#include "xerror-handler.h" #include "c-strstr.h" #include "xvasprintf.h" #include "write-po.h" @@ -279,13 +280,14 @@ write_message (ostream_t stream, const message_ty *mp, /* Writes an entire message list to the stream. */ static void write_stringtable (ostream_t stream, message_list_ty *mlp, - const char *canon_encoding, size_t page_width, bool debug) + const char *canon_encoding, size_t page_width, + xerror_handler_ty xeh, bool debug) { bool blank_line; size_t j; /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, xeh); /* Output the BOM. */ if (!is_ascii_message_list (mlp)) @@ -312,7 +314,8 @@ write_stringtable (ostream_t stream, message_list_ty *mlp, /* Output the contents of a PO file in .strings syntax. */ static void msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, ostream_t stream, - size_t page_width, bool debug) + size_t page_width, xerror_handler_ty xeh, + bool debug) { message_list_ty *mlp; @@ -320,7 +323,7 @@ msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, ostream_t stream, mlp = mdlp->item[0]->messages; else mlp = message_list_alloc (false); - write_stringtable (stream, mlp, mdlp->encoding, page_width, debug); + write_stringtable (stream, mlp, mdlp->encoding, page_width, xeh, debug); } /* Describes a PO file in .strings syntax. */ diff --git a/gettext-tools/src/write-tcl.c b/gettext-tools/src/write-tcl.c index d5c039c09..581317976 100644 --- a/gettext-tools/src/write-tcl.c +++ b/gettext-tools/src/write-tcl.c @@ -33,6 +33,7 @@ #include "xerror.h" #include "message.h" #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "po-charset.h" #include "xalloc.h" @@ -183,7 +184,8 @@ but the Tcl message catalog format doesn't support plural handling\n"))); } /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, + textmode_xerror_handler); /* Support for "reproducible builds": Delete information that may vary between builds in the same conditions. */ diff --git a/gettext-tools/src/write-xml.c b/gettext-tools/src/write-xml.c index ae5f7c59a..6c94d7cad 100644 --- a/gettext-tools/src/write-xml.c +++ b/gettext-tools/src/write-xml.c @@ -29,6 +29,7 @@ #include #include "msgl-iconv.h" +#include "xerror-handler.h" #include "msgl-header.h" #include "po-charset.h" #include "read-catalog.h" @@ -93,7 +94,8 @@ msgdomain_write_xml (message_list_ty *mlp, msgfmt_operand_list_ty operands; /* Convert the messages to Unicode. */ - iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); + iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL, + textmode_xerror_handler); /* Support for "reproducible builds": Delete information that may vary between builds in the same conditions. */ diff --git a/gettext-tools/src/x-po.c b/gettext-tools/src/x-po.c index 8c610c3e0..7ddc052fe 100644 --- a/gettext-tools/src/x-po.c +++ b/gettext-tools/src/x-po.c @@ -212,7 +212,8 @@ extract (FILE *fp, /* Convert the messages to UTF-8. finalize_header() expects this. */ message_list_ty *mlp = mdlp->item[0]->messages; - iconv_message_list (mlp, NULL, po_charset_utf8, logical_filename); + iconv_message_list (mlp, NULL, po_charset_utf8, logical_filename, + textmode_xerror_handler); } } diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index aff039833..5ae03e69e 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -74,6 +74,7 @@ #include "message.h" #include "pos.h" #include "po-xerror.h" +#include "xerror-handler.h" #include "po-charset.h" #include "msgl-iconv.h" #include "msgl-ascii.h" @@ -849,7 +850,8 @@ xgettext cannot work without keywords to look for")); extract_from_file (file_name, po_extractor, mdlp); if (!is_ascii_msgdomain_list (mdlp)) - mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, true, file_name); + mdlp = iconv_msgdomain_list (mdlp, po_charset_utf8, true, file_name, + textmode_xerror_handler); dir_list_restore (saved_directory_list); } @@ -1038,7 +1040,8 @@ xgettext cannot work without keywords to look for")); } /* Write the PO file. */ - msgdomain_list_print (mdlp, file_name, output_syntax, force_po, do_debug); + msgdomain_list_print (mdlp, file_name, output_syntax, textmode_xerror_handler, + force_po, do_debug); if (its_locating_rules) locating_rule_list_free (its_locating_rules); @@ -2191,7 +2194,8 @@ finalize_header (msgdomain_list_ty *mdlp) { message_list_ty *mlp = mdlp->item[0]->messages; - iconv_message_list (mlp, po_charset_utf8, po_charset_utf8, NULL); + iconv_message_list (mlp, po_charset_utf8, po_charset_utf8, NULL, + textmode_xerror_handler); } } }