]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
xgettext: Simplify code that emits diagnostics.
authorBruno Haible <bruno@clisp.org>
Thu, 5 Oct 2023 12:30:20 +0000 (14:30 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 7 Oct 2023 12:55:58 +0000 (14:55 +0200)
Also, for Perl input, clarify some diagnostics as errors vs. warnings.

* gettext-tools/src/if-error.h: New file.
* gettext-tools/src/if-error.c: New file.
* gettext-tools/src/xg-mixed-string.c: Include if-error.h instead of
error-progname.h.
(mixed_string_buffer_append_lone_surrogate): Invoke 'if_error' instead of
'error'.
* gettext-tools/src/x-awk.c: Include if-error.h instead of error-progname.h.
(phase7_getc, x_awk_lex, extract_parenthesized): Invoke 'if_error' instead of
'error'.
* gettext-tools/src/x-c.c: Include if-error.h instead of error-progname.h.
(phase7_getc, phase5_get, extract_parenthesized): Invoke 'if_error' instead of
'error'.
* gettext-tools/src/x-csharp.c: Include if-error.h instead of error-progname.h.
(do_getc_unicode_escaped, accumulate_escaped, extract_parenthesized): Invoke
'if_error' instead of 'error'.
* gettext-tools/src/x-elisp.c: Include if-error.h instead of error-progname.h.
(do_getc_escaped, read_object): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-java.c: Include if-error.h instead of error-progname.h.
(accumulate_escaped, phase5_get, extract_parenthesized): Invoke 'if_error'
instead of 'error'.
* gettext-tools/src/x-javascript.c: Include if-error.h instead of
error-progname.h.
(phase7_getuc, phase5_scan_regexp, phase5_scan_xml_markup, phase5_get,
extract_balanced): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-librep.c: Include if-error.h instead of error-progname.h.
(read_object): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-lisp.c: Include if-error.h instead of error-progname.h.
(read_object): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-lua.c: Include if-error.h instead of error-progname.h.
(extract_balanced): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-perl.c: Include if-error.h instead of error-progname.h.
(get_here_document, extract_quotelike_pass3, interpolate_keywords, x_perl_lex,
extract_balanced): Invoke 'if_error' instead of 'error'.
(interpolate_keywords): Update extract_quotelike_pass3 invocations.
(extract_balanced): Update collect_message invocations. Call fflush before
abort (needed for MSVC).
* gettext-tools/src/x-php.c: Include if-error.h instead of error-progname.h.
(extract_balanced): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-python.c: Include if-error.h instead of error-progname.h.
(phase7_getuc, extract_balanced): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-rst.c: Include if-error.h instead of error-progname.h.
(extract_rst, extract_rsj): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-scheme.c: Include if-error.h instead of error-progname.h.
(read_object): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-sh.c: Include if-error.h instead of error-progname.h.
(read_word, read_command_list): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-tcl.c: Include if-error.h instead of error-progname.h.
(accumulate_word, read_word): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/x-vala.c: Include if-error.h instead of error-progname.h.
(phase7_getc, phase3_scan_regex, phase3_get, extract_balanced): Invoke
'if_error' instead of 'error'.
* gettext-tools/src/x-ycp.c: Include if-error.h instead of error-progname.h.
(extract_parenthesized): Invoke 'if_error' instead of 'error'.
* gettext-tools/src/xg-arglist-parser.c: Include if-error.h instead of error.h,
error-progname.h.
(arglist_parser_done): Invoke 'if_error' instead of 'error_at_line'.
* gettext-tools/src/xg-message.c: Include if-error.h instead of
error-progname.h.
(set_format_flags_from_context, warn_format_string, remember_a_message): Invoke
'if_error' instead of 'multiline_warning'.
* gettext-tools/src/Makefile.am (noinst_HEADERS): Add if-error.h.
(xgettext_SOURCES): Add if-error.c.
* gettext-tools/src/FILES: Mention if-error.h, if-error.c.
* gettext-tools/po/Makevars (XGETTEXT_OPTIONS): Add option regarding the
'if_error' function.
* gettext-tools/po/POTFILES.in: Add src/if-error.c.

27 files changed:
gettext-tools/po/Makevars
gettext-tools/po/POTFILES.in
gettext-tools/src/FILES
gettext-tools/src/Makefile.am
gettext-tools/src/if-error.c [new file with mode: 0644]
gettext-tools/src/if-error.h [new file with mode: 0644]
gettext-tools/src/x-awk.c
gettext-tools/src/x-c.c
gettext-tools/src/x-csharp.c
gettext-tools/src/x-elisp.c
gettext-tools/src/x-java.c
gettext-tools/src/x-javascript.c
gettext-tools/src/x-librep.c
gettext-tools/src/x-lisp.c
gettext-tools/src/x-lua.c
gettext-tools/src/x-perl.c
gettext-tools/src/x-php.c
gettext-tools/src/x-python.c
gettext-tools/src/x-rst.c
gettext-tools/src/x-scheme.c
gettext-tools/src/x-sh.c
gettext-tools/src/x-tcl.c
gettext-tools/src/x-vala.c
gettext-tools/src/x-ycp.c
gettext-tools/src/xg-arglist-parser.c
gettext-tools/src/xg-message.c
gettext-tools/src/xg-mixed-string.c

index 5afee72561abcf93a49aa4b92a7384273ea75629..67458e192453ae0109892dbca676c34c90c6a199 100644 (file)
@@ -20,7 +20,8 @@ XGETTEXT_OPTIONS = \
   --flag=asprintf:2:c-format --flag=vasprintf:2:c-format \
   --flag=xasprintf:1:c-format --flag=error_logger:1:c-format \
   --flag=po_error:3:c-format --flag=po_error_at_line:5:c-format \
-  --flag=po_gram_error:1:c-format --flag=po_gram_error_at_line:2:c-format
+  --flag=po_gram_error:1:c-format --flag=po_gram_error_at_line:2:c-format \
+  --flag=if_error:6:c-format
 
 # This is the copyright holder that gets inserted into the header of the
 # $(DOMAIN).pot file.  Set this to the copyright holder of the surrounding
index 69e90fbd1cae7d1b5363f9c8585421269d5b85bf..ec8b29dd218d8abc478bd85aabe88c402b5356d2 100644 (file)
@@ -67,6 +67,7 @@ src/format-sh.c
 src/format-smalltalk.c
 src/format-tcl.c
 src/hostname.c
+src/if-error.c
 src/its.c
 src/locating-rule.c
 src/msgattrib.c
index 705cf8edc31c8367cb144c09381c6683c36c93b5..68ba0127ac79c59781be6f5d6e9a2537a92624ab 100644 (file)
@@ -291,6 +291,9 @@ msgl-check.c
 +-------------- The 'xgettext' program
 | xgettext.h
 |               Declarations used by the backends.
+| if-error.h
+| if-error.c
+|               Error handling during reading of input files.
 | rc-str-list.h
 |               A reference-counted list-of-immutable-strings type.
 | xg-pos.h
index ae50de135c4c20fc6c6c57dd2aa29c7770adc034..dcf98880ef16509c363559f719a7cd841f5f665d 100644 (file)
@@ -56,6 +56,7 @@ noinst_HEADERS = \
   write-xml.h \
   po-time.h plural-table.h lang-table.h format.h filters.h \
   xgettext.h \
+  if-error.h \
   rc-str-list.h xg-pos.h xg-encoding.h xg-mixed-string.h xg-arglist-context.h \
   xg-arglist-callshape.h xg-arglist-parser.h xg-message.h \
   x-po.h x-properties.h x-stringtable.h \
@@ -227,6 +228,7 @@ else
 xgettext_SOURCES = ../woe32dll/c++xgettext.cc
 endif
 xgettext_SOURCES += \
+  if-error.c \
   xg-pos.c \
   xg-encoding.c \
   xg-mixed-string.c \
diff --git a/gettext-tools/src/if-error.c b/gettext-tools/src/if-error.c
new file mode 100644 (file)
index 0000000..1e90f9e
--- /dev/null
@@ -0,0 +1,110 @@
+/* Error handling during reading of input files.
+   Copyright (C) 2023 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2023.  */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* Specification.  */
+#include "if-error.h"
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "error.h"
+#include "xerror.h"
+#include "error-progname.h"
+#include "xalloc.h"
+#include "xvasprintf.h"
+#include "gettext.h"
+
+#define _(str) gettext (str)
+
+
+void
+if_error (int severity,
+          const char *filename, size_t lineno, size_t column,
+          bool multiline, const char *format, ...)
+{
+  const char *prefix_tail =
+    (severity == IF_SEVERITY_WARNING ? _("warning: ") : _("error: "));
+
+  va_list args;
+  va_start (args, format);
+  char *message_text = xvasprintf (format, args);
+  if (message_text == NULL)
+    message_text = xstrdup (severity == IF_SEVERITY_WARNING
+                            ? _("<unformattable warning message>")
+                            : _("<unformattable error message>"));
+
+  error_with_progname = false;
+  if (multiline)
+    {
+      char *prefix;
+      if (filename != NULL)
+        {
+          if (lineno != (size_t)(-1))
+            {
+              if (column != (size_t)(-1))
+                prefix = xasprintf ("%s:%ld:%ld: %s",
+                                    filename, (long) lineno, (long) column,
+                                    prefix_tail);
+              else
+                prefix = xasprintf ("%s:%ld: %s", filename, (long) lineno,
+                                    prefix_tail);
+            }
+          else
+            prefix = xasprintf ("%s: %s", filename, prefix_tail);
+        }
+      else
+        prefix = xasprintf ("%s", prefix_tail);
+
+      if (severity == IF_SEVERITY_WARNING)
+        multiline_warning (prefix, message_text);
+      else
+        multiline_error (prefix, message_text);
+    }
+  else
+    {
+      if (filename != NULL)
+        {
+          if (lineno != (size_t)(-1))
+            {
+              if (column != (size_t)(-1))
+                error (0, 0, "%s:%ld:%ld: %s%s",
+                       filename, (long) lineno, (long) column, prefix_tail,
+                       message_text);
+              else
+                error (0, 0, "%s:%ld: %s%s",
+                       filename, (long) lineno, prefix_tail, message_text);
+            }
+          else
+            error (0, 0, "%s: %s%s", filename, prefix_tail, message_text);
+        }
+      else
+        error (0, 0, "%s%s", prefix_tail, message_text);
+      if (severity == IF_SEVERITY_WARNING)
+        --error_message_count;
+      free (message_text);
+    }
+  error_with_progname = true;
+
+  va_end (args);
+  if (severity == IF_SEVERITY_FATAL_ERROR)
+    exit (EXIT_FAILURE);
+}
diff --git a/gettext-tools/src/if-error.h b/gettext-tools/src/if-error.h
new file mode 100644 (file)
index 0000000..23cc504
--- /dev/null
@@ -0,0 +1,59 @@
+/* Error handling during reading of input files.
+   Copyright (C) 2023 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
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2023.  */
+
+#ifndef _IF_ERROR_H
+#define _IF_ERROR_H
+
+#include <stdbool.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* A higher-level error printing facility than the one in error.h / xerror.h
+   and error-progname.h.  */
+
+#define IF_SEVERITY_WARNING     0 /* just a warning, tell the user */
+#define IF_SEVERITY_ERROR       1 /* an error, the operation cannot complete */
+#define IF_SEVERITY_FATAL_ERROR 2 /* an error, the operation must be aborted */
+
+/* Signal a problem of the given severity.
+   FILENAME + LINENO indicate where the problem occurred.
+   If FILENAME is NULL, FILENAME and LINENO and COLUMN are ignored.
+   If LINENO is (size_t)(-1), LINENO and COLUMN are ignored.
+   If COLUMN is (size_t)(-1), it is ignored.
+   FORMAT and the following format string arguments are the problem description
+   (if MULTILINE is true, multiple lines of text, each terminated with a
+   newline, otherwise usually a single line).
+   Does not return if SEVERITY is IF_SEVERITY_FATAL_ERROR.  */
+extern void if_error (int severity,
+                      const char *filename, size_t lineno, size_t column,
+                      bool multiline, const char *format, ...)
+#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
+     __attribute__ ((__format__ (__printf__, 6, 7)))
+#endif
+     ;
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _IF_ERROR_H */
index 1a2098e98f893c2687d6a7b9535600f7804470f9..50643c6e1c5da1bef0f3459c69fd50d558b5fb9e 100644 (file)
@@ -39,7 +39,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "gettext.h"
 
@@ -337,10 +337,9 @@ phase7_getc ()
     }
 
   phase1_ungetc (c);
-  error_with_progname = false;
-  error (0, 0, _("%s:%d: warning: unterminated string"), logical_file_name,
-         line_number);
-  error_with_progname = true;
+  if_error (IF_SEVERITY_WARNING,
+            logical_file_name, line_number, (size_t)(-1), false,
+            _("unterminated string"));
   return P7_QUOTES;
 }
 
@@ -588,10 +587,9 @@ x_awk_lex (token_ty *tp)
                   if (c == EOF || c == '\n')
                     {
                       phase1_ungetc (c);
-                      error_with_progname = false;
-                      error (0, 0, _("%s:%d: warning: unterminated regular expression"),
-                             logical_file_name, line_number);
-                      error_with_progname = true;
+                      if_error (IF_SEVERITY_WARNING,
+                                logical_file_name, line_number, (size_t)(-1), false,
+                                _("unterminated regular expression"));
                       break;
                     }
                   else if (c == '[')
@@ -764,11 +762,9 @@ extract_parenthesized (message_list_ty *mlp,
 
         case token_type_lparen:
           if (++nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_parenthesized (mlp, inner_context, next_context_iter,
                                      arglist_parser_alloc (mlp,
                                                            state ? next_shapes : NULL)))
index 49c6b12e47355319c3d3de6197cd7637822bc14f..1698e3df3fcb95246a5c7867b7dd19ba729277fe 100644 (file)
@@ -42,7 +42,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "xvasprintf.h"
 #include "mem-hash-map.h"
@@ -1112,12 +1112,9 @@ phase7_getc ()
               default:
                 phase3_ungetc (c);
                 if (overflow)
-                  {
-                    error_with_progname = false;
-                    error (0, 0, _("%s:%d: warning: hexadecimal escape sequence out of range"),
-                           logical_file_name, line_number);
-                    error_with_progname = true;
-                  }
+                  if_error (IF_SEVERITY_WARNING,
+                            logical_file_name, line_number, (size_t)(-1), false,
+                            _("hexadecimal escape sequence out of range"));
                 return n;
 
               case '0': case '1': case '2': case '3': case '4':
@@ -1202,10 +1199,9 @@ phase7_getc ()
         if (n < 0x110000)
           return UNICODE (n);
 
-        error_with_progname = false;
-        error (0, 0, _("%s:%d: warning: invalid Unicode character"),
-               logical_file_name, line_number);
-        error_with_progname = true;
+        if_error (IF_SEVERITY_WARNING,
+                  logical_file_name, line_number, (size_t)(-1), false,
+                  _("invalid Unicode character"));
 
         while (--j >= 0)
           phase3_ungetc (buf[j]);
@@ -1403,10 +1399,9 @@ phase5_get (token_ty *tp)
                         case '"':
                           /* A double-quote within the delimiter! This is too
                              weird.  We don't support this.  */
-                          error_with_progname = false;
-                          error (0, 0, _("%s:%d: warning: a double-quote in the delimiter of a raw string literal is unsupported"),
-                                 logical_file_name, starting_line_number);
-                          error_with_progname = true;
+                          if_error (IF_SEVERITY_WARNING,
+                                    logical_file_name, starting_line_number, (size_t)(-1), false,
+                                    _("a double-quote in the delimiter of a raw string literal is unsupported"));
                           FALLTHROUGH;
                         default:
                           valid_delimiter_char = false;
@@ -1481,21 +1476,17 @@ phase5_get (token_ty *tp)
                     }
                   if (c == EOF)
                     {
-                      error_with_progname = false;
-                      error (0, 0, _("%s:%d: warning: unterminated raw string literal"),
-                             logical_file_name, starting_line_number);
-                      error_with_progname = true;
+                      if_error (IF_SEVERITY_WARNING,
+                                logical_file_name, starting_line_number, (size_t)(-1), false,
+                                _("unterminated raw string literal"));
                       tp->type = token_type_eof;
                       return;
                     }
-                  /* The error message for c == '"' was already emitted above.  */
+                  /* The warning message for c == '"' was already emitted above.  */
                   if (c != '"')
-                    {
-                      error_with_progname = false;
-                      error (0, 0, _("%s:%d: warning: invalid raw string literal syntax"),
-                             logical_file_name, starting_line_number);
-                      error_with_progname = true;
-                    }
+                    if_error (IF_SEVERITY_WARNING,
+                              logical_file_name, starting_line_number, (size_t)(-1), false,
+                              _("invalid raw string literal syntax"));
                   /* To get into a sane state, read up until the next double-quote,
                      newline, or EOF.  */
                   while (!(c == EOF || c == '"' || c == '\n'))
@@ -1700,10 +1691,9 @@ phase5_get (token_ty *tp)
           c = phase7_getc ();
           if (c == P7_NEWLINE)
             {
-              error_with_progname = false;
-              error (0, 0, _("%s:%d: warning: unterminated character constant"),
-                     logical_file_name, line_number - 1);
-              error_with_progname = true;
+              if_error (IF_SEVERITY_WARNING,
+                        logical_file_name, line_number - 1, (size_t)(-1), false,
+                        _("unterminated character constant"));
               phase7_ungetc ('\n');
               break;
             }
@@ -1737,10 +1727,9 @@ phase5_get (token_ty *tp)
 
             if (c == P7_NEWLINE)
               {
-                error_with_progname = false;
-                error (0, 0, _("%s:%d: warning: unterminated string literal"),
-                       logical_file_name, line_number - 1);
-                error_with_progname = true;
+                if_error (IF_SEVERITY_WARNING,
+                          logical_file_name, line_number - 1, (size_t)(-1), false,
+                          _("unterminated string literal"));
                 phase7_ungetc ('\n');
                 break;
               }
@@ -2342,11 +2331,9 @@ extract_parenthesized (message_list_ty *mlp,
 
         case xgettext_token_type_lparen:
           if (++nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_parenthesized (mlp, inner_context, next_context_iter,
                                      arglist_parser_alloc (mlp,
                                                            state ? next_shapes : NULL)))
index 8eb29b423fe3e8407c4fabd9b320b17d4463ee05..81552c93a5674b77124b8145b052122237e6f26c 100644 (file)
@@ -41,7 +41,7 @@
 #include "xg-message.h"
 #include "c-ctype.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "xerror.h"
 #include "xvasprintf.h"
@@ -1328,12 +1328,9 @@ do_getc_unicode_escaped (bool (*predicate) (int))
         }
 
       if (n >= 0x110000)
-        {
-          error_with_progname = false;
-          error (0, 0, _("%s:%d: warning: invalid Unicode character"),
-                 logical_file_name, line_number);
-          error_with_progname = true;
-        }
+        if_error (IF_SEVERITY_WARNING,
+                  logical_file_name, line_number, (size_t)(-1), false,
+                  _("invalid Unicode character"));
       else if (predicate (n))
         return n;
 
@@ -1447,14 +1444,14 @@ accumulate_escaped (struct mixed_string_buffer *literal, int delimiter)
       if (c == UNL)
         {
           phase3_ungetc (c);
-          error_with_progname = false;
           if (delimiter == '\'')
-            error (0, 0, _("%s:%d: warning: unterminated character constant"),
-                   logical_file_name, line_number);
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("unterminated character constant"));
           else
-            error (0, 0, _("%s:%d: warning: unterminated string constant"),
-                   logical_file_name, line_number);
-          error_with_progname = true;
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("unterminated string constant"));
           break;
         }
       if (c == '\\')
@@ -1941,11 +1938,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
 
         case token_type_lparen:
           if (++paren_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_parenthesized (mlp, token_type_rparen,
                                      inner_context, next_context_iter,
                                      arglist_parser_alloc (mlp,
@@ -1966,24 +1961,18 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
               return false;
             }
           if (terminator == token_type_rbrace)
-            {
-              error_with_progname = false;
-              error (0, 0,
-                     _("%s:%d: warning: ')' found where '}' was expected"),
-                     logical_file_name, token.line_number);
-              error_with_progname = true;
-            }
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, token.line_number, (size_t)(-1), false,
+                      _("')' found where '}' was expected"));
           next_context_iter = null_context_list_iterator;
           state = 0;
           continue;
 
         case token_type_lbrace:
           if (++brace_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open braces"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open braces"));
           if (extract_parenthesized (mlp, token_type_rbrace,
                                      null_context, null_context_list_iterator,
                                      arglist_parser_alloc (mlp, NULL)))
@@ -2003,13 +1992,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
               return false;
             }
           if (terminator == token_type_rparen)
-            {
-              error_with_progname = false;
-              error (0, 0,
-                     _("%s:%d: warning: '}' found where ')' was expected"),
-                     logical_file_name, token.line_number);
-              error_with_progname = true;
-            }
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, token.line_number, (size_t)(-1), false,
+                      _("'}' found where ')' was expected"));
           next_context_iter = null_context_list_iterator;
           state = 0;
           continue;
index e961da3d32b6eb33e8adff3963ddb5706cded166..a98c26ed7ad4889c9dd71b915526858a466bb07a 100644 (file)
@@ -39,7 +39,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "mem-hash-map.h"
 #include "c-ctype.h"
@@ -447,11 +447,9 @@ static int
 do_getc_escaped (int c, bool in_string)
 {
   if (escape_nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested escape sequence"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested escape sequence"));
   switch (c)
     {
     case 'a':
@@ -644,11 +642,9 @@ read_object (struct object *op, bool first_in_list, bool new_backquote_flag,
              flag_context_ty outer_context)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested objects"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested objects"));
   for (;;)
     {
       int ch;
index 0e1e62387603ea41253da35868241bccc4eab821..84af9754039a6f15c5e85f0a7457c6850d57ef78 100644 (file)
@@ -40,7 +40,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "mem-hash-map.h"
 #include "po-charset.h"
@@ -677,14 +677,14 @@ accumulate_escaped (struct mixed_string_buffer *literal, int delimiter)
       if (RED (c) == '\n')
         {
           phase3_ungetc (c);
-          error_with_progname = false;
           if (delimiter == '\'')
-            error (0, 0, _("%s:%d: warning: unterminated character constant"),
-                   logical_file_name, line_number);
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("unterminated character constant"));
           else
-            error (0, 0, _("%s:%d: warning: unterminated string constant"),
-                   logical_file_name, line_number);
-          error_with_progname = true;
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("unterminated string constant"));
           break;
         }
       if (RED (c) == '\\')
@@ -1204,10 +1204,9 @@ phase5_get (token_ty *tp)
                         int ic = phase3_getc ();
                         if (ic == P2_EOF)
                           {
-                            error_with_progname = false;
-                            error (0, 0, _("%s:%d: warning: unterminated text block"),
-                                   logical_file_name, line_number);
-                            error_with_progname = true;
+                            if_error (IF_SEVERITY_WARNING,
+                                      logical_file_name, line_number, (size_t)(-1), false,
+                                      _("unterminated text block"));
                             tp->type = token_type_other;
                             return;
                           }
@@ -1217,10 +1216,9 @@ phase5_get (token_ty *tp)
                           break;
                         else
                           {
-                            error_with_progname = false;
-                            error (0, 0, _("%s:%d: warning: invalid syntax in text block"),
-                                   logical_file_name, line_number);
-                            error_with_progname = true;
+                            if_error (IF_SEVERITY_WARNING,
+                                      logical_file_name, line_number, (size_t)(-1), false,
+                                      _("invalid syntax in text block"));
                             tp->type = token_type_other;
                             return;
                           }
@@ -1248,10 +1246,9 @@ phase5_get (token_ty *tp)
                               }
                             if (ic == P2_EOF)
                               {
-                                error_with_progname = false;
-                                error (0, 0, _("%s:%d: warning: unterminated text block"),
-                                       logical_file_name, block.line_number);
-                                error_with_progname = true;
+                                if_error (IF_SEVERITY_WARNING,
+                                          logical_file_name, block.line_number, (size_t)(-1), false,
+                                          _("unterminated text block"));
                                 break;
                               }
                             if (RED (ic) == '\\')
@@ -1576,11 +1573,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
 
         case token_type_lparen:
           if (++paren_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_parenthesized (mlp, token_type_rparen,
                                      inner_context, next_context_iter,
                                      arglist_parser_alloc (mlp,
@@ -1601,24 +1596,18 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
               return false;
             }
           if (terminator == token_type_rbrace)
-            {
-              error_with_progname = false;
-              error (0, 0,
-                     _("%s:%d: warning: ')' found where '}' was expected"),
-                     logical_file_name, token.line_number);
-              error_with_progname = true;
-            }
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, token.line_number, (size_t)(-1), false,
+                      _("')' found where '}' was expected"));
           next_context_iter = null_context_list_iterator;
           state = 0;
           continue;
 
         case token_type_lbrace:
           if (++brace_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open braces"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open braces"));
           if (extract_parenthesized (mlp, token_type_rbrace,
                                      null_context, null_context_list_iterator,
                                      arglist_parser_alloc (mlp, NULL)))
@@ -1638,13 +1627,9 @@ extract_parenthesized (message_list_ty *mlp, token_type_ty terminator,
               return false;
             }
           if (terminator == token_type_rparen)
-            {
-              error_with_progname = false;
-              error (0, 0,
-                     _("%s:%d: warning: '}' found where ')' was expected"),
-                     logical_file_name, token.line_number);
-              error_with_progname = true;
-            }
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, token.line_number, (size_t)(-1), false,
+                      _("'}' found where ')' was expected"));
           next_context_iter = null_context_list_iterator;
           state = 0;
           continue;
index 26dcd4fb52c869b35b1a210f3729bd6925a96c7b..644f9db3396b41f1db7a7b79be262c5ba65da3a7 100644 (file)
@@ -43,7 +43,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "progname.h"
 #include "xerror.h"
 #include "xvasprintf.h"
@@ -762,10 +762,9 @@ phase7_getuc (int quote_char)
           else
             {
               phase2_ungetc (c);
-              error_with_progname = false;
-              error (0, 0, _("%s:%d: warning: unterminated string"),
-                     logical_file_name, line_number);
-              error_with_progname = true;
+              if_error (IF_SEVERITY_WARNING,
+                        logical_file_name, line_number, (size_t)(-1), false,
+                        _("unterminated string"));
               return P7_STRING_END;
             }
         }
@@ -976,11 +975,9 @@ phase5_scan_regexp (void)
         }
       if (c == UEOF)
         {
-          error_with_progname = false;
-          error (0, 0,
-                 _("%s:%d: warning: RegExp literal terminated too early"),
-                 logical_file_name, line_number);
-          error_with_progname = true;
+          if_error (IF_SEVERITY_WARNING,
+                    logical_file_name, line_number, (size_t)(-1), false,
+                    _("RegExp literal terminated too early"));
           return;
         }
     }
@@ -1105,12 +1102,9 @@ phase5_scan_xml_markup (token_ty *tp)
                   goto eof;
                 if (c != '>')
                   {
-                    error_with_progname = false;
-                    error (0, 0,
-                           _("%s:%d: warning: %s is not allowed"),
-                           logical_file_name, line_number,
-                           end);
-                    error_with_progname = true;
+                    if_error (IF_SEVERITY_WARNING,
+                              logical_file_name, line_number, (size_t)(-1), false,
+                              _("%s is not allowed"), end);
                     return -1;
                   }
                 return i;
@@ -1120,11 +1114,9 @@ phase5_scan_xml_markup (token_ty *tp)
   return -1;
 
  eof:
-  error_with_progname = false;
-  error (0, 0,
-         _("%s:%d: warning: unterminated XML markup"),
-         logical_file_name, line_number);
-  error_with_progname = true;
+  if_error (IF_SEVERITY_WARNING,
+            logical_file_name, line_number, (size_t)(-1), false,
+            _("unterminated XML markup"));
   return -1;
 }
 
@@ -1364,13 +1356,9 @@ phase5_get (token_ty *tp)
                     /* Ignore them all, since they are not part of JSX.
                        But warn about CDATA.  */
                     if (xml_markup_type == 1)
-                      {
-                        error_with_progname = false;
-                        error (0, 0,
-                               _("%s:%d: warning: ignoring CDATA section"),
-                               logical_file_name, line_number);
-                        error_with_progname = true;
-                      }
+                      if_error (IF_SEVERITY_WARNING,
+                                logical_file_name, line_number, (size_t)(-1), false,
+                                _("ignoring CDATA section"));
                     continue;
                   }
 
@@ -1684,11 +1672,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_lparen:
           if (++paren_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
                                 inner_context, next_context_iter,
                                 arglist_parser_alloc (mlp,
@@ -1724,11 +1710,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_lbracket:
           if (++bracket_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open brackets"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
                                 null_context, null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
@@ -1753,11 +1737,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_lbrace:
           if (++brace_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open braces"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open braces"));
           if (extract_balanced (mlp, token_type_rbrace,
                                 null_context, null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
@@ -1809,11 +1791,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_xml_element_start:
           if (++xml_element_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open XML elements"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open XML elements"));
           if (extract_balanced (mlp, token_type_xml_element_end,
                                 null_context, null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
index 1891a32224c5d5b8e57ac6f69b279e72ebd05a43..a333b109ff5fa799ba46ec0f2063f895828547a0 100644 (file)
@@ -40,7 +40,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "mem-hash-map.h"
 #include "gettext.h"
@@ -601,11 +601,9 @@ static void
 read_object (struct object *op, flag_context_ty outer_context)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested objects"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested objects"));
   for (;;)
     {
       int ch;
index 4b29f08a61a4bf57107513b65deb40a0377544dc..f184f6127914b3e0c2e23cfcdffaa6efe4160ed8 100644 (file)
@@ -39,7 +39,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "mem-hash-map.h"
 #include "gettext.h"
@@ -944,11 +944,9 @@ static void
 read_object (struct object *op, flag_context_ty outer_context)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested objects"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested objects"));
   for (;;)
     {
       struct char_syntax curr;
index 78f0d179b40606782fd101025d3b8d5c39adc288..17acde94b81ca3645ad9328432153bd9d79bc555 100644 (file)
@@ -39,7 +39,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "gettext.h"
 #include "po-charset.h"
@@ -1094,11 +1094,9 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
         case token_type_lparen:
           if (++paren_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
                                 inner_context, next_context_iter,
                                 arglist_parser_alloc (mlp,
@@ -1125,11 +1123,9 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
         case token_type_lbracket:
           if (++bracket_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open brackets"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
                                 null_context, null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
index ee24e1ebb80bb454d01319427093726645fdb75e..182d5674a9a14c14f30aa2fcfbb31040dc44da5d 100644 (file)
@@ -42,7 +42,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "c-ctype.h"
 #include "po-charset.h"
@@ -337,12 +337,10 @@ get_here_document (const char *delimiter)
             }
           else
             {
-              error_with_progname = false;
-              error (EXIT_SUCCESS, 0,
-                     _("%s:%d: warning: can't find string terminator \"%s\" anywhere before EOF"),
-                     real_file_name, line_number, delimiter);
-              error_with_progname = true;
-
+              if_error (IF_SEVERITY_WARNING,
+                        real_file_name, line_number, (size_t)(-1), false,
+                        _("can't find string terminator \"%s\" anywhere before EOF"),
+                        delimiter);
               break;
             }
         }
@@ -1079,11 +1077,9 @@ extract_quotelike_pass3 (token_ty *tp, int error_level)
                     const char *end = strchr (crs, '}');
                     if (end == NULL)
                       {
-                        error_with_progname = false;
-                        error (error_level, 0,
-                               _("%s:%d: missing right brace on \\x{HEXNUMBER}"),
-                               real_file_name, line_number);
-                        error_with_progname = true;
+                        if_error (error_level,
+                                  real_file_name, line_number, (size_t)(-1), false,
+                                  _("missing right brace on \\x{HEXNUMBER}"));
                         ++crs;
                         continue;
                       }
@@ -1200,11 +1196,10 @@ extract_quotelike_pass3 (token_ty *tp, int error_level)
                 }
               else if ((unsigned char) *crs >= 0x80)
                 {
-                  error_with_progname = false;
-                  error (error_level, 0,
-                         _("%s:%d: invalid interpolation (\"\\l\") of 8bit character \"%c\""),
-                         real_file_name, line_number, *crs);
-                  error_with_progname = true;
+                  if_error (error_level,
+                            real_file_name, line_number, (size_t)(-1), false,
+                            _("invalid interpolation (\"\\l\") of 8bit character \"%c\""),
+                            *crs);
                 }
               else
                 {
@@ -1220,11 +1215,10 @@ extract_quotelike_pass3 (token_ty *tp, int error_level)
                 }
               else if ((unsigned char) *crs >= 0x80)
                 {
-                  error_with_progname = false;
-                  error (error_level, 0,
-                         _("%s:%d: invalid interpolation (\"\\u\") of 8bit character \"%c\""),
-                         real_file_name, line_number, *crs);
-                  error_with_progname = true;
+                  if_error (error_level,
+                            real_file_name, line_number, (size_t)(-1), false,
+                            _("invalid interpolation (\"\\u\") of 8bit character \"%c\""),
+                            *crs);
                 }
               else
                 {
@@ -1254,11 +1248,9 @@ extract_quotelike_pass3 (token_ty *tp, int error_level)
 
       if (!backslashed && !extract_all && (*crs == '$' || *crs == '@'))
         {
-          error_with_progname = false;
-          error (error_level, 0,
-                 _("%s:%d: invalid variable interpolation at \"%c\""),
-                 real_file_name, line_number, *crs);
-          error_with_progname = true;
+          if_error (error_level,
+                    real_file_name, line_number, (size_t)(-1), false,
+                    _("invalid variable interpolation at \"%c\""), *crs);
           ++crs;
         }
       else if (lowercase)
@@ -1267,11 +1259,10 @@ extract_quotelike_pass3 (token_ty *tp, int error_level)
             buffer[bufpos++] = *crs - 'A' + 'a';
           else if ((unsigned char) *crs >= 0x80)
             {
-              error_with_progname = false;
-              error (error_level, 0,
-                     _("%s:%d: invalid interpolation (\"\\L\") of 8bit character \"%c\""),
-                     real_file_name, line_number, *crs);
-              error_with_progname = true;
+              if_error (error_level,
+                        real_file_name, line_number, (size_t)(-1), false,
+                        _("invalid interpolation (\"\\L\") of 8bit character \"%c\""),
+                        *crs);
               buffer[bufpos++] = *crs;
             }
           else
@@ -1284,11 +1275,10 @@ extract_quotelike_pass3 (token_ty *tp, int error_level)
             buffer[bufpos++] = *crs - 'a' + 'A';
           else if ((unsigned char) *crs >= 0x80)
             {
-              error_with_progname = false;
-              error (error_level, 0,
-                     _("%s:%d: invalid interpolation (\"\\U\") of 8bit character \"%c\""),
-                     real_file_name, line_number, *crs);
-              error_with_progname = true;
+              if_error (error_level,
+                        real_file_name, line_number, (size_t)(-1), false,
+                        _("invalid interpolation (\"\\U\") of 8bit character \"%c\""),
+                        *crs);
               buffer[bufpos++] = *crs;
             }
           else
@@ -1741,11 +1731,9 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
   lex_pos_ty pos;
 
   if (++nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested expressions"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested expressions"));
 
   /* States are:
    *
@@ -1980,7 +1968,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
               /* The resulting string has to be interpolated twice.  */
               buffer[bufpos] = '\0';
               token.string = xstrdup (buffer);
-              extract_quotelike_pass3 (&token, EXIT_FAILURE);
+              extract_quotelike_pass3 (&token, IF_SEVERITY_FATAL_ERROR);
               /* The string can only shrink with interpolation (because
                  we ignore \Q).  */
               if (!(strlen (token.string) <= bufpos))
@@ -2074,7 +2062,7 @@ interpolate_keywords (message_list_ty *mlp, string_desc_t string, int lineno)
             case '}':
               buffer[bufpos] = '\0';
               token.string = xstrdup (buffer);
-              extract_quotelike_pass3 (&token, EXIT_FAILURE);
+              extract_quotelike_pass3 (&token, IF_SEVERITY_FATAL_ERROR);
               remember_a_message (mlp, NULL, token.string, true, false, context,
                                   &pos, NULL, savable_comment, true);
               FALLTHROUGH;
@@ -2796,11 +2784,9 @@ static token_ty *
 x_perl_lex (message_list_ty *mlp)
 {
   if (++nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested expressions"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested expressions"));
 
   #if DEBUG_PERL
   int dummy = token_stack_dump (&token_stack);
@@ -2916,8 +2902,7 @@ x_perl_lex (message_list_ty *mlp)
           tp->sub_type = string_type_q;
           tp->comment = add_reference (savable_comment);
           #if DEBUG_PERL
-          fprintf (stderr,
-                   "%s:%d: token %s mutated to token_type_string\n",
+          fprintf (stderr, "%s:%d: token %s mutated to token_type_string\n",
                    real_file_name, line_number, token2string (tp));
           #endif
         }
@@ -3148,11 +3133,9 @@ extract_balanced (message_list_ty *mlp,
   #endif
 
   if (nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested expressions"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested expressions"));
 
   for (;;)
     {
@@ -3454,7 +3437,7 @@ extract_balanced (message_list_ty *mlp,
 
               if (extract_all)
                 {
-                  char *string = collect_message (mlp, tp, EXIT_SUCCESS);
+                  char *string = collect_message (mlp, tp, IF_SEVERITY_WARNING);
                   lex_pos_ty pos;
 
                   pos.file_name = logical_file_name;
@@ -3483,7 +3466,7 @@ extract_balanced (message_list_ty *mlp,
 
                   if (must_collect)
                     {
-                      char *string = collect_message (mlp, tp, EXIT_FAILURE);
+                      char *string = collect_message (mlp, tp, IF_SEVERITY_FATAL_ERROR);
                       mixed_string_ty *ms =
                         mixed_string_alloc_utf8 (string, lc_string,
                                                  logical_file_name, tp->line_number);
@@ -3715,8 +3698,10 @@ extract_balanced (message_list_ty *mlp,
               break;
 
             default:
-              fprintf (stderr, "%s:%d: error: unknown token type %d\n",
-                       real_file_name, tp->line_number, (int) tp->type);
+              if_error (IF_SEVERITY_ERROR,
+                        real_file_name, tp->line_number, (size_t)(-1), false,
+                        "unknown token type %d", (int) tp->type);
+              fflush (stderr);
               abort ();
             }
 
index a92cab4bafd12515c6aecb851c808e6ad533c407..d50617634b8f894bfd4311c7dcfbc15803c45e39 100644 (file)
@@ -39,7 +39,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "gettext.h"
 
@@ -1482,11 +1482,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_lparen:
           if (++paren_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
                                 inner_context, next_context_iter,
                                 arglist_parser_alloc (mlp,
@@ -1522,11 +1520,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_lbracket:
           if (++bracket_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open brackets"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
                                 null_context, null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
index 6dc5ed631da94dbcf33ac8038a9b2c6e8b9a7a97..4946b0b772613b0588a1732d5f9c4c66f4f193e3 100644 (file)
@@ -42,7 +42,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "progname.h"
 #include "basename-lgpl.h"
 #include "xerror.h"
@@ -892,10 +892,9 @@ phase7_getuc (int quote_char,
               return UNICODE ('\n');
             }
           phase2_ungetc (c);
-          error_with_progname = false;
-          error (0, 0, _("%s:%d: warning: unterminated string"),
-                 logical_file_name, line_number);
-          error_with_progname = true;
+          if_error (IF_SEVERITY_WARNING,
+                    logical_file_name, line_number, (size_t)(-1), false,
+                    _("unterminated string"));
           return P7_STRING_END;
         }
 
@@ -1099,10 +1098,9 @@ phase7_getuc (int quote_char,
                       return UNICODE (n);
                     }
 
-                  error_with_progname = false;
-                  error (0, 0, _("%s:%d: warning: invalid Unicode character"),
-                         logical_file_name, line_number);
-                  error_with_progname = true;
+                  if_error (IF_SEVERITY_WARNING,
+                            logical_file_name, line_number, (size_t)(-1), false,
+                            _("invalid Unicode character"));
 
                   while (--i >= 0)
                     phase2_ungetc (buf[i]);
@@ -1597,11 +1595,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_lparen:
           if (++paren_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
                                 inner_context, next_context_iter,
                                 arglist_parser_alloc (mlp,
@@ -1637,11 +1633,9 @@ extract_balanced (message_list_ty *mlp,
 
         case token_type_lbracket:
           if (++bracket_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open brackets"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open brackets"));
           if (extract_balanced (mlp, token_type_rbracket,
                                 null_context, null_context_list_iterator,
                                 arglist_parser_alloc (mlp, NULL)))
index ea67faf0e9a2026ad06aff46f495e98ef709cc6c..25252d63123715e949c0f4a04323cf310a98239f 100644 (file)
@@ -38,7 +38,7 @@
 #include "xg-mixed-string.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "gettext.h"
 
@@ -111,12 +111,9 @@ extract_rst (FILE *f,
       for (;;)
         {
           if (c == EOF || c == '\n')
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: invalid string definition"),
-                     logical_filename, line_number);
-              error_with_progname = true;
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_filename, line_number, (size_t)(-1), false,
+                      _("invalid string definition"));
           if (bufpos >= bufmax)
             {
               bufmax = 2 * bufmax + 10;
@@ -175,12 +172,9 @@ extract_rst (FILE *f,
               if (c == EOF && ferror (f))
                 goto bomb;
               if (c == EOF || !c_isdigit (c))
-                {
-                  error_with_progname = false;
-                  error (EXIT_FAILURE, 0, _("%s:%d: error: missing number after #"),
-                         logical_filename, line_number);
-                  error_with_progname = true;
-                }
+                if_error (IF_SEVERITY_FATAL_ERROR,
+                          logical_filename, line_number, (size_t)(-1), false,
+                          _("missing number after #"));
               n = (c - '0');
               for (;;)
                 {
@@ -210,12 +204,9 @@ extract_rst (FILE *f,
                 ungetc (c, f);
             }
           else
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: invalid string expression"),
-                     logical_filename, line_number);
-              error_with_progname = true;
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_filename, line_number, (size_t)(-1), false,
+                      _("invalid string expression"));
         }
       if (bufpos >= bufmax)
         {
@@ -673,24 +664,20 @@ extract_rsj (FILE *f,
   return;
 
  invalid_json:
-  error_with_progname = false;
-  error (EXIT_FAILURE, 0, _("%s:%d: error: invalid JSON syntax"),
-         logical_filename, line_number);
-  error_with_progname = true;
+  if_error (IF_SEVERITY_FATAL_ERROR,
+            logical_filename, line_number, (size_t)(-1), false,
+            _("invalid JSON syntax"));
   return;
 
  invalid_rsj:
-  error_with_progname = false;
-  error (EXIT_FAILURE, 0, _("%s:%d: error: invalid RSJ syntax"),
-         logical_filename, line_number);
-  error_with_progname = true;
+  if_error (IF_SEVERITY_FATAL_ERROR,
+            logical_filename, line_number, (size_t)(-1), false,
+            _("invalid RSJ syntax"));
   return;
 
  invalid_rsj_version:
-  error_with_progname = false;
-  error (EXIT_FAILURE, 0,
-         _("%s:%d: error: invalid RSJ version. Only version 1 is supported."),
-         logical_filename, line_number);
-  error_with_progname = true;
+  if_error (IF_SEVERITY_FATAL_ERROR,
+            logical_filename, line_number, (size_t)(-1), false,
+            _("invalid RSJ version. Only version 1 is supported."));
   return;
 }
index d27d95886b4093987f6d773249be760d8f6f8f90..386e080ca322460763f3b127c45fd044a298ef1a 100644 (file)
@@ -39,7 +39,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "mem-hash-map.h"
 #include "gettext.h"
@@ -685,11 +685,9 @@ static void
 read_object (struct object *op, flag_context_ty outer_context)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested objects"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested objects"));
   for (;;)
     {
       int ch = do_getc ();
index d611d6dfa3bc7e3f7f7d44a47f95f35b8614a675..397358da3427ffe1313bc883fcad5e1af2e210d1 100644 (file)
@@ -39,7 +39,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "mem-hash-map.h"
 #include "../../gettext-runtime/src/escapes.h"
@@ -1147,10 +1147,9 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
                                       NULL, savable_comment, false);
                   free_token (&string);
 
-                  error_with_progname = false;
-                  error (0, 0, _("%s:%lu: warning: the syntax $\"...\" is deprecated due to security reasons; use eval_gettext instead"),
-                         pos.file_name, (unsigned long) pos.line_number);
-                  error_with_progname = true;
+                  if_error (IF_SEVERITY_WARNING,
+                            pos.file_name, pos.line_number, (size_t)(-1), false,
+                            _("the syntax $\"...\" is deprecated due to security reasons; use eval_gettext instead"));
 
                   /* The result at runtime is not constant. Therefore we
                      change wp->type.  */
@@ -1507,11 +1506,9 @@ static enum word_type
 read_command_list (int looking_for, flag_context_ty outer_context)
 {
   if (nesting_depth > MAX_NESTING_DEPTH)
-    {
-      error_with_progname = false;
-      error (EXIT_FAILURE, 0, _("%s:%d: error: too deeply nested command list"),
-             logical_file_name, line_number);
-    }
+    if_error (IF_SEVERITY_FATAL_ERROR,
+              logical_file_name, line_number, (size_t)(-1), false,
+              _("too deeply nested command list"));
   for (;;)
     {
       enum word_type terminator;
index b078a1bee1df225bd0f4c2c7b5c2c580a51362db..9542ac25a710a1fe2e0018ad9f50377e5fb7a4e4 100644 (file)
@@ -42,7 +42,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "mem-hash-map.h"
 #include "c-ctype.h"
@@ -767,11 +767,9 @@ accumulate_word (struct word *wp, enum terminator looking_for,
       else if (c == '[')
         {
           if (++bracket_nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open brackets"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open brackets"));
           read_command_list (']', context);
           bracket_nesting_depth--;
           wp->type = t_other;
@@ -800,10 +798,9 @@ accumulate_word (struct word *wp, enum terminator looking_for,
                     }
                   phase2_ungetc (c);
                 }
-              error_with_progname = false;
-              error (0, 0, _("%s:%d: warning: invalid Unicode character"),
-                     logical_file_name, line_number);
-              error_with_progname = true;
+              if_error (IF_SEVERITY_WARNING,
+                        logical_file_name, line_number, (size_t)(-1), false,
+                        _("invalid Unicode character"));
               goto done_escape;
             }
          saw_unicode_escape:
@@ -893,11 +890,9 @@ read_word (struct word *wp, int looking_for, flag_context_ty context)
 
       /* Interpret it as a command list.  */
       if (++brace_nesting_depth > MAX_NESTING_DEPTH)
-        {
-          error_with_progname = false;
-          error (EXIT_FAILURE, 0, _("%s:%d: error: too many open braces"),
-                 logical_file_name, line_number);
-        }
+        if_error (IF_SEVERITY_FATAL_ERROR,
+                  logical_file_name, line_number, (size_t)(-1), false,
+                  _("too many open braces"));
       terminator = read_command_list ('\0', null_context);
       brace_nesting_depth--;
 
index 6f548538754f0cb64b63133e7c03ec2c41e81ba5..6aaba64f16e8de98ae73468ad63ac138c2f16259 100644 (file)
@@ -42,7 +42,7 @@
 #include "xg-arglist-parser.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "xvasprintf.h"
 #include "mem-hash-map.h"
@@ -504,12 +504,9 @@ phase7_getc ()
               default:
                 phase1_ungetc (c);
                 if (overflow)
-                  {
-                    error_with_progname = false;
-                    error (0, 0, _("%s:%d: warning: hexadecimal escape sequence out of range"),
-                           logical_file_name, line_number);
-                    error_with_progname = true;
-                  }
+                  if_error (IF_SEVERITY_WARNING,
+                            logical_file_name, line_number, (size_t)(-1), false,
+                            _("hexadecimal escape sequence out of range"));
                 return n;
 
               case '0': case '1': case '2': case '3': case '4':
@@ -593,10 +590,9 @@ phase7_getc ()
         if (n < 0x110000)
           return UNICODE (n);
 
-        error_with_progname = false;
-        error (0, 0, _("%s:%d: warning: invalid Unicode character"),
-               logical_file_name, line_number);
-        error_with_progname = true;
+        if_error (IF_SEVERITY_WARNING,
+                  logical_file_name, line_number, (size_t)(-1), false,
+                  _("invalid Unicode character"));
 
         while (--j >= 0)
           phase1_ungetc (buf[j]);
@@ -642,11 +638,9 @@ phase3_scan_regex ()
           }
         if (c == EOF)
           {
-            error_with_progname = false;
-            error (0, 0,
-                   _("%s:%d: warning: regular expression literal terminated too early"),
-                   logical_file_name, line_number);
-            error_with_progname = true;
+            if_error (IF_SEVERITY_WARNING,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("regular expression literal terminated too early"));
             return;
           }
       }
@@ -835,10 +829,9 @@ phase3_get (token_ty *tp)
               c = phase7_getc ();
               if (c == P7_NEWLINE)
                 {
-                  error_with_progname = false;
-                  error (0, 0, _("%s:%d: warning: unterminated character constant"),
-                         logical_file_name, line_number - 1);
-                  error_with_progname = true;
+                  if_error (IF_SEVERITY_WARNING,
+                            logical_file_name, line_number - 1, (size_t)(-1), false,
+                            _("unterminated character constant"));
                   phase7_ungetc ('\n');
                   break;
                 }
@@ -935,11 +928,9 @@ phase3_get (token_ty *tp)
 
                   if (c == P7_NEWLINE)
                     {
-                      error_with_progname = false;
-                      error (0, 0,
-                             _("%s:%d: warning: unterminated string literal"),
-                             logical_file_name, line_number - 1);
-                      error_with_progname = true;
+                      if_error (IF_SEVERITY_WARNING,
+                                logical_file_name, line_number - 1, (size_t)(-1), false,
+                                _("unterminated string literal"));
                       phase7_ungetc ('\n');
                       break;
                     }
@@ -1317,11 +1308,9 @@ extract_balanced (message_list_ty *mlp, token_type_ty delim,
 
         case token_type_lparen:
           if (++nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_balanced (mlp, token_type_rparen,
                                 inner_context, next_context_iter,
                                 arglist_parser_alloc (mlp,
index ab9749613a934776c9345cf4a6b3c330dd1bbc8d..dd548508bc7d2f0ef9c17c64d7afb57fe9cf4a9f 100644 (file)
@@ -37,7 +37,7 @@
 #include "xg-arglist-context.h"
 #include "xg-message.h"
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "xalloc.h"
 #include "gettext.h"
 
@@ -693,11 +693,9 @@ extract_parenthesized (message_list_ty *mlp,
         {
         case token_type_i18n:
           if (++nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_parenthesized (mlp, inner_context, next_context_iter,
                                      true))
             return true;
@@ -768,11 +766,9 @@ extract_parenthesized (message_list_ty *mlp,
 
         case token_type_lparen:
           if (++nesting_depth > MAX_NESTING_DEPTH)
-            {
-              error_with_progname = false;
-              error (EXIT_FAILURE, 0, _("%s:%d: error: too many open parentheses"),
-                     logical_file_name, line_number);
-            }
+            if_error (IF_SEVERITY_FATAL_ERROR,
+                      logical_file_name, line_number, (size_t)(-1), false,
+                      _("too many open parentheses"));
           if (extract_parenthesized (mlp, inner_context, next_context_iter,
                                      false))
             return true;
index b5bf26c5900d76a7c84763be0e9813f663c95555..a96776f1cda7087a5465305513989957bcd8ec1d 100644 (file)
@@ -25,8 +25,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "flexmember.h"
 #include "xalloc.h"
 #include "xsize.h"
@@ -380,15 +379,12 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
         }
 
       if (ambiguous)
-        {
-          error_with_progname = false;
-          error_at_line (0, 0,
-                         best_cp->msgid_pos.file_name,
-                         best_cp->msgid_pos.line_number,
-                         _("warning: ambiguous argument specification for keyword '%.*s'"),
-                         (int) ap->keyword_len, ap->keyword);
-          error_with_progname = true;
-        }
+        if_error (IF_SEVERITY_WARNING,
+                  best_cp->msgid_pos.file_name,
+                  best_cp->msgid_pos.line_number,
+                  (size_t)(-1), false,
+                  _("ambiguous argument specification for keyword '%.*s'"),
+                  (int) ap->keyword_len, ap->keyword);
 
       if (best_cp != NULL)
         {
@@ -442,15 +438,12 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
               const char *separator = strchr (best_msgid, '|');
 
               if (separator == NULL)
-                {
-                  error_with_progname = false;
-                  error_at_line (0, 0,
-                                 best_cp->msgid_pos.file_name,
-                                 best_cp->msgid_pos.line_number,
-                                 _("warning: missing context for keyword '%.*s'"),
-                                 (int) ap->keyword_len, ap->keyword);
-                  error_with_progname = true;
-                }
+                if_error (IF_SEVERITY_WARNING,
+                          best_cp->msgid_pos.file_name,
+                          best_cp->msgid_pos.line_number,
+                          (size_t)(-1), false,
+                          _("missing context for keyword '%.*s'"),
+                          (int) ap->keyword_len, ap->keyword);
               else
                 {
                   size_t ctxt_len = separator - best_msgid;
@@ -467,15 +460,12 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
               const char *separator = strchr (best_msgid_plural, '|');
 
               if (separator == NULL)
-                {
-                  error_with_progname = false;
-                  error_at_line (0, 0,
-                                 best_cp->msgid_plural_pos.file_name,
-                                 best_cp->msgid_plural_pos.line_number,
-                                 _("warning: missing context for plural argument of keyword '%.*s'"),
-                                 (int) ap->keyword_len, ap->keyword);
-                  error_with_progname = true;
-                }
+                if_error (IF_SEVERITY_WARNING,
+                          best_cp->msgid_plural_pos.file_name,
+                          best_cp->msgid_plural_pos.line_number,
+                          (size_t)(-1), false,
+                          _("missing context for plural argument of keyword '%.*s'"),
+                          (int) ap->keyword_len, ap->keyword);
               else
                 {
                   size_t ctxt_len = separator - best_msgid_plural;
@@ -488,14 +478,11 @@ arglist_parser_done (struct arglist_parser *ap, int argnum)
                   else
                     {
                       if (strcmp (ctxt, best_msgctxt) != 0)
-                        {
-                          error_with_progname = false;
-                          error_at_line (0, 0,
-                                         best_cp->msgid_plural_pos.file_name,
-                                         best_cp->msgid_plural_pos.line_number,
-                                         _("warning: context mismatch between singular and plural form"));
-                          error_with_progname = true;
-                        }
+                        if_error (IF_SEVERITY_WARNING,
+                                  best_cp->msgid_plural_pos.file_name,
+                                  best_cp->msgid_plural_pos.line_number,
+                                  (size_t)(-1), false,
+                                  _("context mismatch between singular and plural form"));
                       free (ctxt);
                     }
                   best_msgid_plural = xstrdup (separator + 1);
index d7097f9e2fed0418b9bcc53d1bcef2843b89c6c4..a70f02b00adba583419344a3d60af24dc2c081cb 100644 (file)
@@ -24,7 +24,7 @@
 #include <stdio.h>
 
 #include "c-strstr.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "format.h"
 #include "read-catalog-abstract.h"
 #include "xalloc.h"
@@ -85,24 +85,13 @@ set_format_flags_from_context (enum is_format is_format[NFORMATS],
               {
                 /* The string is not a valid format string.  */
                 if (is_format[i] != possible)
-                  {
-                    char buffer[22];
-
-                    error_with_progname = false;
-                    if (pos->line_number == (size_t)(-1))
-                      buffer[0] = '\0';
-                    else
-                      sprintf (buffer, ":%ld", (long) pos->line_number);
-                    multiline_warning (xasprintf (_("%s%s: warning: "),
-                                                  pos->file_name, buffer),
-                                       xasprintf (is_format[i] == yes_according_to_context
-                                                  ? _("Although being used in a format string position, the %s is not a valid %s format string. Reason: %s\n")
-                                                  : _("Although declared as such, the %s is not a valid %s format string. Reason: %s\n"),
-                                                  pretty_msgstr,
-                                                  format_language_pretty[i],
-                                                  invalid_reason));
-                    error_with_progname = true;
-                  }
+                  if_error (IF_SEVERITY_WARNING,
+                            pos->file_name, pos->line_number, (size_t)(-1), true,
+                            is_format[i] == yes_according_to_context
+                            ? _("Although being used in a format string position, the %s is not a valid %s format string. Reason: %s\n")
+                            : _("Although declared as such, the %s is not a valid %s format string. Reason: %s\n"),
+                            pretty_msgstr, format_language_pretty[i],
+                            invalid_reason);
 
                 is_format[i] = impossible;
                 free (invalid_reason);
@@ -222,24 +211,14 @@ warn_format_string (enum is_format is_format[NFORMATS], const char *string,
 {
   if (possible_format_p (is_format[format_python])
       && get_python_format_unnamed_arg_count (string) > 1)
-    {
-      char buffer[22];
-
-      error_with_progname = false;
-      if (pos->line_number == (size_t)(-1))
-        buffer[0] = '\0';
-      else
-        sprintf (buffer, ":%ld", (long) pos->line_number);
-      multiline_warning (xasprintf (_("%s%s: warning: "),
-                                    pos->file_name, buffer),
-                         xasprintf (_("\
+    if_error (IF_SEVERITY_WARNING,
+              pos->file_name, pos->line_number, (size_t)(-1), true,
+              _("\
 '%s' format string with unnamed arguments cannot be properly localized:\n\
 The translator cannot reorder the arguments.\n\
 Please consider using a format string with named arguments,\n\
 and a mapping instead of a tuple for the arguments.\n"),
-                                    pretty_msgstr));
-      error_with_progname = true;
-    }
+              pretty_msgstr);
 }
 
 
@@ -290,22 +269,12 @@ remember_a_message (message_list_ty *mlp, char *msgctxt, char *msgid,
     }
 
   if (msgctxt == NULL && msgid[0] == '\0' && !xgettext_omit_header)
-    {
-      char buffer[22];
-
-      error_with_progname = false;
-      if (pos->line_number == (size_t)(-1))
-        buffer[0] = '\0';
-      else
-        sprintf (buffer, ":%ld", (long) pos->line_number);
-      multiline_warning (xasprintf (_("%s%s: warning: "), pos->file_name,
-                                    buffer),
-                         xstrdup (_("\
+    if_error (IF_SEVERITY_WARNING,
+              pos->file_name, pos->line_number, (size_t)(-1), true,
+              _("\
 Empty msgid.  It is reserved by GNU gettext:\n\
 gettext(\"\") returns the header entry with\n\
-meta information, not the empty string.\n")));
-      error_with_progname = true;
-    }
+meta information, not the empty string.\n"));
 
   /* See if we have seen this message before.  */
   mp = message_list_search (mlp, msgctxt, msgid);
index 1892267afbbbee48b9a83533e63db74e5e1bf502..4c0d64447278a4d2c3f120ae007ab8bb0d5fa2e9 100644 (file)
@@ -1,6 +1,6 @@
 /* Handling strings that are given partially in the source encoding and
    partially in Unicode.
-   Copyright (C) 2001-2018 Free Software Foundation, Inc.
+   Copyright (C) 2001-2023 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
@@ -27,7 +27,7 @@
 #include <string.h>
 
 #include "error.h"
-#include "error-progname.h"
+#include "if-error.h"
 #include "flexmember.h"
 #include "msgl-ascii.h"
 #include "po-charset.h"
@@ -492,10 +492,9 @@ mixed_string_buffer_append_lone_surrogate (struct mixed_string_buffer *bp,
             as a 3-byte sequence, the resulting UTF-8 data stream
             would become ill-formed."
      So use U+FFFD instead.  */
-  error_with_progname = false;
-  error (0, 0, _("%s:%d: warning: lone surrogate U+%04X"),
-         logical_file_name, line_number, uc);
-  error_with_progname = true;
+  if_error (IF_SEVERITY_WARNING,
+            logical_file_name, line_number, (size_t)(-1), false,
+            _("lone surrogate U+%04X"), uc);
   mixed_string_buffer_append_to_utf8_buffer (bp, 0xfffd);
 }