]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
libgettextpo: Remove static variable 'width.0'.
authorBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 15:48:16 +0000 (16:48 +0100)
committerBruno Haible <bruno@clisp.org>
Sat, 11 Nov 2023 15:48:16 +0000 (16:48 +0100)
* gnulib-local/lib/xerror.h: Include <stddef.h>.
(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.

gettext-tools/libgettextpo/gettext-po.c
gettext-tools/src/msgfmt.c
gettext-tools/src/msgl-charset.c
gettext-tools/src/po-error.c
gnulib-local/lib/xerror.c
gnulib-local/lib/xerror.h

index 343f03bac7d6da5982f42c1d3532ac0698c6cd16..7a14121985ce50922a0abdb937773575f216527a 100644 (file)
@@ -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;
 }
index c84536cbf20cf280b14f729b5f51a5995716b5bc..a0eab229aaf5ae88dba96938072b454c11b4fc17 100644 (file)
@@ -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")));
         }
     }
 }
index 9cf0cc4248e4012f76acb4f5f6b5fd78c055db74..7e5c7f89692d5a2818d7cbbbe3e23ed46ae1a212 100644 (file)
@@ -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 <haible@clisp.cons.org>, 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\
index 9a62984258ce2dcf57c12b9d2cbb5c9e765d2127..90ab578e1ed43d3a10b5a7aa9ff3cb6d3a3d4032 100644 (file)
@@ -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;
index fd1cabaec00939a8dfb98d59105de5b67389da3a..c43aa449533a7a0cdfaa9900d841bb09c06a53ab 100644 (file)
 #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);
 }
index 4386c0c4e24b64b754f780f2dec341313468321c..73b2229768b9c24a94f1beed52c20284226a819d 100644 (file)
@@ -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 <haible@clisp.cons.org>, 2001.
 
    This program is free software: you can redistribute it and/or modify
@@ -18,6 +18,7 @@
 #ifndef _XERROR_H
 #define _XERROR_H
 
+#include <stddef.h>
 
 #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