From: Bruno Haible Date: Sat, 11 Nov 2023 15:48:16 +0000 (+0100) Subject: libgettextpo: Remove static variable 'width.0'. X-Git-Tag: v0.23~310 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7ad43b102c254f5b81eb91b83b70ed027423ffe1;p=thirdparty%2Fgettext.git libgettextpo: Remove static variable 'width.0'. * gnulib-local/lib/xerror.h: Include . (multiline_warning, multiline_error): Change return type to size_t. Don't suggest to pass a NULL prefix. (multiline_append): New declaration. * gnulib-local/lib/xerror.c (multiline_internal): New function, extracted from multiline_warning. (multiline_warning, multiline_error): Reject a NULL prefix. Call multiline_internal. (multiline_append): New function. * gettext-tools/src/msgl-charset.c (compare_po_locale_charsets): Invoke multiline_append instead of multiline_warning with NULL argument. * gettext-tools/src/msgfmt.c (msgfmt_parse_debrief): Invoke multiline_append instead of multiline_error with NULL argument. * gettext-tools/src/po-error.c (void_multiline_warning, void_multiline_error): New functions. (po_multiline_warning, po_multiline_error): Use them as initializer. * gettext-tools/libgettextpo/gettext-po.c (void_multiline_warning, void_multiline_error): New functions. (po_file_read_v2, po_file_write): Use them as defaults for po_multiline_warning, po_multiline_error. --- diff --git a/gettext-tools/libgettextpo/gettext-po.c b/gettext-tools/libgettextpo/gettext-po.c index 343f03bac..7a1412198 100644 --- a/gettext-tools/libgettextpo/gettext-po.c +++ b/gettext-tools/libgettextpo/gettext-po.c @@ -86,6 +86,19 @@ struct po_message_iterator int libgettextpo_version = LIBGETTEXTPO_VERSION; +static void +void_multiline_warning (char *prefix, char *message) +{ + multiline_warning (prefix, message); +} + +static void +void_multiline_error (char *prefix, char *message) +{ + multiline_error (prefix, message); +} + + /* Create an empty PO file representation in memory. */ po_file_t @@ -188,8 +201,8 @@ po_file_read_v2 (const char *filename, po_error_handler_t handler) /* Restore error handler. */ po_error = orig_error; po_error_at_line = orig_error_at_line; - po_multiline_warning = multiline_warning; - po_multiline_error = multiline_error; + po_multiline_warning = void_multiline_warning; + po_multiline_error = void_multiline_error; gram_max_allowed_errors = 20; if (fp != stdin) @@ -274,8 +287,8 @@ po_file_write (po_file_t file, const char *filename, po_error_handler_t handler) /* Restore error handler. */ po_error = orig_error; po_error_at_line = orig_error_at_line; - po_multiline_warning = multiline_warning; - po_multiline_error = multiline_error; + po_multiline_warning = void_multiline_warning; + po_multiline_error = void_multiline_error; return file; } diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index c84536cbf..a0eab229a 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -1188,10 +1188,11 @@ msgfmt_parse_debrief (abstract_catalog_reader_ty *that) { if (!this->has_header_entry) { - multiline_error (xasprintf ("%s: ", this->file_name), - xasprintf (_("warning: PO file header missing or invalid\n"))); - multiline_error (NULL, - xasprintf (_("warning: charset conversion will not work\n"))); + size_t prefix_width = + multiline_error (xasprintf ("%s: ", this->file_name), + xasprintf (_("warning: PO file header missing or invalid\n"))); + multiline_append (prefix_width, + xasprintf (_("warning: charset conversion will not work\n"))); } } } diff --git a/gettext-tools/src/msgl-charset.c b/gettext-tools/src/msgl-charset.c index 9cf0cc424..7e5c7f896 100644 --- a/gettext-tools/src/msgl-charset.c +++ b/gettext-tools/src/msgl-charset.c @@ -1,5 +1,5 @@ /* Message list charset and locale charset handling. - Copyright (C) 2001-2003, 2005-2007, 2009, 2019-2020 Free Software Foundation, Inc. + Copyright (C) 2001-2023 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -88,20 +88,21 @@ compare_po_locale_charsets (const msgdomain_list_ty *mdlp) freea (charset); if (canon_locale_code != canon_charset) { - multiline_warning (xasprintf (_("warning: ")), - xasprintf (_("\ + size_t prefix_width = + multiline_warning (xasprintf (_("warning: ")), + xasprintf (_("\ Locale charset \"%s\" is different from\n\ input file charset \"%s\".\n\ Output of '%s' might be incorrect.\n\ Possible workarounds are:\n\ "), locale_code, canon_charset, last_component (program_name))); - multiline_warning (NULL, - xasprintf (_("\ + multiline_append (prefix_width, + xasprintf (_("\ - Set LC_ALL to a locale with encoding %s.\n\ "), canon_charset)); if (canon_locale_code != NULL) - multiline_warning (NULL, - xasprintf (_("\ + multiline_append (prefix_width, + xasprintf (_("\ - Convert the translation catalog to %s using 'msgconv',\n\ then apply '%s',\n\ then convert back to %s using 'msgconv'.\n\ @@ -109,8 +110,8 @@ Possible workarounds are:\n\ if (strcmp (canon_charset, "UTF-8") != 0 && (canon_locale_code == NULL || strcmp (canon_locale_code, "UTF-8") != 0)) - multiline_warning (NULL, - xasprintf (_("\ + multiline_append (prefix_width, + xasprintf (_("\ - Set LC_ALL to a locale with encoding %s,\n\ convert the translation catalog to %s using 'msgconv',\n\ then apply '%s',\n\ diff --git a/gettext-tools/src/po-error.c b/gettext-tools/src/po-error.c index 9a6298425..90ab578e1 100644 --- a/gettext-tools/src/po-error.c +++ b/gettext-tools/src/po-error.c @@ -38,7 +38,19 @@ void (*po_error_at_line) (int status, int errnum, const char *format, ...) = error_at_line; +static void +void_multiline_warning (char *prefix, char *message) +{ + multiline_warning (prefix, message); +} + +static void +void_multiline_error (char *prefix, char *message) +{ + multiline_error (prefix, message); +} + void (*po_multiline_warning) (char *prefix, char *message) - = multiline_warning; + = void_multiline_warning; void (*po_multiline_error) (char *prefix, char *message) - = multiline_error; + = void_multiline_error; diff --git a/gnulib-local/lib/xerror.c b/gnulib-local/lib/xerror.c index fd1cabaec..c43aa4495 100644 --- a/gnulib-local/lib/xerror.c +++ b/gnulib-local/lib/xerror.c @@ -35,15 +35,14 @@ #endif /* Emit a multiline warning to stderr, consisting of MESSAGE, with the - first line prefixed with PREFIX and the remaining lines prefixed with - the same amount of spaces. Reuse the spaces of the previous call if - PREFIX is NULL. Free the PREFIX and MESSAGE when done. */ -void -multiline_warning (char *prefix, char *message) + first line prefixed with PREFIX or, if that is NULL, with PREFIX_WIDTH + spaces, and the remaining lines prefixed with the same amount of spaces. + Free the PREFIX and MESSAGE when done. Return the amount of spaces. */ +static size_t +multiline_internal (char *prefix, size_t prefix_width, char *message) { - static int width; + size_t width; const char *cp; - int i; fflush (stdout); @@ -62,13 +61,19 @@ multiline_warning (char *prefix, char *message) free (prefix); goto after_indent; } + else + width = prefix_width; for (;;) { const char *np; - for (i = width; i > 0; i--) - putc (' ', stderr); + { + size_t i; + + for (i = width; i > 0; i--) + putc (' ', stderr); + } after_indent: np = strchr (cp, '\n'); @@ -85,16 +90,31 @@ multiline_warning (char *prefix, char *message) } free (message); + + return width; } -/* Emit a multiline error to stderr, consisting of MESSAGE, with the - first line prefixed with PREFIX and the remaining lines prefixed with - the same amount of spaces. Reuse the spaces of the previous call if - PREFIX is NULL. Free the PREFIX and MESSAGE when done. */ -void +size_t +multiline_warning (char *prefix, char *message) +{ + if (prefix == NULL) + /* Invalid argument. */ + abort (); + return multiline_internal (prefix, 0, message); +} + +size_t multiline_error (char *prefix, char *message) { - if (prefix != NULL) - ++error_message_count; - multiline_warning (prefix, message); + if (prefix == NULL) + /* Invalid argument. */ + abort (); + ++error_message_count; + return multiline_internal (prefix, 0, message); +} + +void +multiline_append (size_t prefix_width, char *message) +{ + multiline_internal (NULL, prefix_width, message); } diff --git a/gnulib-local/lib/xerror.h b/gnulib-local/lib/xerror.h index 4386c0c4e..73b222976 100644 --- a/gnulib-local/lib/xerror.h +++ b/gnulib-local/lib/xerror.h @@ -1,5 +1,5 @@ /* Multiline error-reporting functions. - Copyright (C) 2001-2003, 2006 Free Software Foundation, Inc. + Copyright (C) 2001-2003, 2006, 2023 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -18,6 +18,7 @@ #ifndef _XERROR_H #define _XERROR_H +#include #ifdef __cplusplus extern "C" { @@ -26,15 +27,20 @@ extern "C" { /* Emit a multiline warning to stderr, consisting of MESSAGE, with the first line prefixed with PREFIX and the remaining lines prefixed with - the same amount of spaces. Reuse the spaces of the previous call if - PREFIX is NULL. Free the PREFIX and MESSAGE when done. */ -extern void multiline_warning (char *prefix, char *message); + the same amount of spaces. Free the PREFIX and MESSAGE when done. + Return the width of PREFIX, for later uses of multiline_append. */ +extern size_t multiline_warning (char *prefix, char *message); /* Emit a multiline error to stderr, consisting of MESSAGE, with the first line prefixed with PREFIX and the remaining lines prefixed with - the same amount of spaces. Reuse the spaces of the previous call if - PREFIX is NULL. Free the PREFIX and MESSAGE when done. */ -extern void multiline_error (char *prefix, char *message); + the same amount of spaces. Free the PREFIX and MESSAGE when done. + Return the width of PREFIX, for later uses of multiline_append. */ +extern size_t multiline_error (char *prefix, char *message); + +/* Following a call to multiline_warning or multiline_error, append another + MESSAGE, with each line prefixed with PREFIX_WIDTH spaces. + Free the MESSAGE when done. */ +extern void multiline_append (size_t prefix_width, char *message); #ifdef __cplusplus