From: Bruno Haible Date: Thu, 5 Oct 2023 12:30:20 +0000 (+0200) Subject: xgettext: Simplify code that emits diagnostics. X-Git-Tag: v0.23~318 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e1140f0c4664e3aa609812da3965e92af793fa66;p=thirdparty%2Fgettext.git xgettext: Simplify code that emits diagnostics. 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. --- diff --git a/gettext-tools/po/Makevars b/gettext-tools/po/Makevars index 5afee7256..67458e192 100644 --- a/gettext-tools/po/Makevars +++ b/gettext-tools/po/Makevars @@ -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 diff --git a/gettext-tools/po/POTFILES.in b/gettext-tools/po/POTFILES.in index 69e90fbd1..ec8b29dd2 100644 --- a/gettext-tools/po/POTFILES.in +++ b/gettext-tools/po/POTFILES.in @@ -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 diff --git a/gettext-tools/src/FILES b/gettext-tools/src/FILES index 705cf8edc..68ba0127a 100644 --- a/gettext-tools/src/FILES +++ b/gettext-tools/src/FILES @@ -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 diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am index ae50de135..dcf98880e 100644 --- a/gettext-tools/src/Makefile.am +++ b/gettext-tools/src/Makefile.am @@ -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 index 000000000..1e90f9e05 --- /dev/null +++ b/gettext-tools/src/if-error.c @@ -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 . */ + +/* Written by Bruno Haible , 2023. */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/* Specification. */ +#include "if-error.h" + +#include +#include + +#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 + ? _("") + : _("")); + + 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 index 000000000..23cc50485 --- /dev/null +++ b/gettext-tools/src/if-error.h @@ -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 . */ + +/* Written by Bruno Haible , 2023. */ + +#ifndef _IF_ERROR_H +#define _IF_ERROR_H + +#include +#include + +#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 */ diff --git a/gettext-tools/src/x-awk.c b/gettext-tools/src/x-awk.c index 1a2098e98..50643c6e1 100644 --- a/gettext-tools/src/x-awk.c +++ b/gettext-tools/src/x-awk.c @@ -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))) diff --git a/gettext-tools/src/x-c.c b/gettext-tools/src/x-c.c index 49c6b12e4..1698e3df3 100644 --- a/gettext-tools/src/x-c.c +++ b/gettext-tools/src/x-c.c @@ -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))) diff --git a/gettext-tools/src/x-csharp.c b/gettext-tools/src/x-csharp.c index 8eb29b423..81552c93a 100644 --- a/gettext-tools/src/x-csharp.c +++ b/gettext-tools/src/x-csharp.c @@ -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; diff --git a/gettext-tools/src/x-elisp.c b/gettext-tools/src/x-elisp.c index e961da3d3..a98c26ed7 100644 --- a/gettext-tools/src/x-elisp.c +++ b/gettext-tools/src/x-elisp.c @@ -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; diff --git a/gettext-tools/src/x-java.c b/gettext-tools/src/x-java.c index 0e1e62387..84af97540 100644 --- a/gettext-tools/src/x-java.c +++ b/gettext-tools/src/x-java.c @@ -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; diff --git a/gettext-tools/src/x-javascript.c b/gettext-tools/src/x-javascript.c index 26dcd4fb5..644f9db33 100644 --- a/gettext-tools/src/x-javascript.c +++ b/gettext-tools/src/x-javascript.c @@ -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))) diff --git a/gettext-tools/src/x-librep.c b/gettext-tools/src/x-librep.c index 1891a3222..a333b109f 100644 --- a/gettext-tools/src/x-librep.c +++ b/gettext-tools/src/x-librep.c @@ -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; diff --git a/gettext-tools/src/x-lisp.c b/gettext-tools/src/x-lisp.c index 4b29f08a6..f184f6127 100644 --- a/gettext-tools/src/x-lisp.c +++ b/gettext-tools/src/x-lisp.c @@ -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; diff --git a/gettext-tools/src/x-lua.c b/gettext-tools/src/x-lua.c index 78f0d179b..17acde94b 100644 --- a/gettext-tools/src/x-lua.c +++ b/gettext-tools/src/x-lua.c @@ -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))) diff --git a/gettext-tools/src/x-perl.c b/gettext-tools/src/x-perl.c index ee24e1ebb..182d5674a 100644 --- a/gettext-tools/src/x-perl.c +++ b/gettext-tools/src/x-perl.c @@ -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 (); } diff --git a/gettext-tools/src/x-php.c b/gettext-tools/src/x-php.c index a92cab4ba..d50617634 100644 --- a/gettext-tools/src/x-php.c +++ b/gettext-tools/src/x-php.c @@ -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))) diff --git a/gettext-tools/src/x-python.c b/gettext-tools/src/x-python.c index 6dc5ed631..4946b0b77 100644 --- a/gettext-tools/src/x-python.c +++ b/gettext-tools/src/x-python.c @@ -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))) diff --git a/gettext-tools/src/x-rst.c b/gettext-tools/src/x-rst.c index ea67faf0e..25252d631 100644 --- a/gettext-tools/src/x-rst.c +++ b/gettext-tools/src/x-rst.c @@ -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; } diff --git a/gettext-tools/src/x-scheme.c b/gettext-tools/src/x-scheme.c index d27d95886..386e080ca 100644 --- a/gettext-tools/src/x-scheme.c +++ b/gettext-tools/src/x-scheme.c @@ -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 (); diff --git a/gettext-tools/src/x-sh.c b/gettext-tools/src/x-sh.c index d611d6dfa..397358da3 100644 --- a/gettext-tools/src/x-sh.c +++ b/gettext-tools/src/x-sh.c @@ -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; diff --git a/gettext-tools/src/x-tcl.c b/gettext-tools/src/x-tcl.c index b078a1bee..9542ac25a 100644 --- a/gettext-tools/src/x-tcl.c +++ b/gettext-tools/src/x-tcl.c @@ -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--; diff --git a/gettext-tools/src/x-vala.c b/gettext-tools/src/x-vala.c index 6f5485387..6aaba64f1 100644 --- a/gettext-tools/src/x-vala.c +++ b/gettext-tools/src/x-vala.c @@ -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, diff --git a/gettext-tools/src/x-ycp.c b/gettext-tools/src/x-ycp.c index ab9749613..dd548508b 100644 --- a/gettext-tools/src/x-ycp.c +++ b/gettext-tools/src/x-ycp.c @@ -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; diff --git a/gettext-tools/src/xg-arglist-parser.c b/gettext-tools/src/xg-arglist-parser.c index b5bf26c59..a96776f1c 100644 --- a/gettext-tools/src/xg-arglist-parser.c +++ b/gettext-tools/src/xg-arglist-parser.c @@ -25,8 +25,7 @@ #include #include -#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); diff --git a/gettext-tools/src/xg-message.c b/gettext-tools/src/xg-message.c index d7097f9e2..a70f02b00 100644 --- a/gettext-tools/src/xg-message.c +++ b/gettext-tools/src/xg-message.c @@ -24,7 +24,7 @@ #include #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); diff --git a/gettext-tools/src/xg-mixed-string.c b/gettext-tools/src/xg-mixed-string.c index 1892267af..4c0d64447 100644 --- a/gettext-tools/src/xg-mixed-string.c +++ b/gettext-tools/src/xg-mixed-string.c @@ -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 #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); }