From: Bruno Haible Date: Sat, 3 Aug 2024 01:11:18 +0000 (+0200) Subject: Add an xerror_handler parameter to read_catalog_stream. X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=497b5fc0536ea53dd054b864cf2726dcac71e66b;p=thirdparty%2Fgettext.git Add an xerror_handler parameter to read_catalog_stream. * gettext-tools/src/read-catalog-abstract.h: Include xerror-handler.h. (ABSTRACT_CATALOG_READER_TY): Add xeh field. (catalog_reader_alloc): Add xerror_handler parameter. * gettext-tools/src/read-catalog-abstract.c: Include xerror-handler.h instead of po-xerror.h. (catalog_reader_alloc): Add xerror_handler parameter. (catalog_reader_parse): Use catr->xeh for error handling. * gettext-tools/src/read-catalog.h: Include xerror-handler.h. (default_catalog_reader_alloc, read_catalog_stream): Add xerror_handler parameter. * gettext-tools/src/read-catalog.c: Include xerror-handler.h instead of po-xerror.h. (default_set_domain, default_add_message): Use catr->xeh for error handling. (default_catalog_reader_alloc, read_catalog_stream): Add xerror_handler parameter. * gettext-tools/src/read-po-lex.h: Include read-catalog-abstract.h. (po_gram_error_at_line): Add catr parameter. * gettext-tools/src/read-po-lex.c: Include xerror-handler.h instead of po-xerror.h. (po_gram_error): Use ps->catr->xeh for error handling. (po_gram_error_at_line): Add catr parameter. Use catr->xeh for error handling. (po_lex_charset_set, mbfile_getc, lex_getc): Use ps->catr->xeh for error handling. (keyword_p, po_gram_lex): Update invocations of po_gram_error_at_line. * gettext-tools/src/read-po-gram.y: Update invocations of po_gram_error_at_line. * gettext-tools/src/read-properties.c: Include xerror-handler.h instead of po-xerror.h. (phase4_getuc, read_escaped_string): Add catr parameter. Use catr->xeh for error handling. (properties_parse): Use catr->xeh for error handling. * gettext-tools/src/read-stringtable.c: Include xerror-handler.h instead of po-xerror.h. (phase1_getc, phase2_getc, phase3_getc): Add catr parameter. Use catr->xeh for error handling. (phase4_getc): Update. (read_string, stringtable_parse): Use catr->xeh for error handling. * gettext-tools/libgettextpo/gettext-po.c (po_file_read): Pass a stack-allocated xerror_handler to read_catalog_stream. * gettext-tools/src/msgfmt.c: Include xerror-handler.h. (read_catalog_file_msgfmt): Use the default xerror_handler. * gettext-tools/src/read-catalog-file.c: Include xerror-handler.h. (read_catalog_file): Use the default xerror_handler. * gettext-tools/src/read-csharp.c: Include xerror-handler.h. (execute_and_read_po_output): Use the default xerror_handler. * gettext-tools/src/read-java.c: Include xerror-handler.h. (execute_and_read_po_output): Use the default xerror_handler. * gettext-tools/src/read-resources.c: Include xerror-handler.h. (execute_and_read_po_output): Use the default xerror_handler. * gettext-tools/src/read-tcl.c: Include xerror-handler.h. (msgdomain_read_tcl): Use the default xerror_handler. * gettext-tools/src/x-po.c: Include xerror-handler.h. (extract): Use the default xerror_handler. * gettext-tools/src/xgettext.c: Include xerror-handler.h. (read_exclusion_file): Use the default xerror_handler. --- diff --git a/gettext-tools/libgettextpo/gettext-po.c b/gettext-tools/libgettextpo/gettext-po.c index 58771e1d5..4cf51709d 100644 --- a/gettext-tools/libgettextpo/gettext-po.c +++ b/gettext-tools/libgettextpo/gettext-po.c @@ -104,25 +104,27 @@ po_file_read (const char *filename, po_xerror_handler_t handler) return NULL; } - /* Establish error handler around read_catalog_stream(). */ - po_xerror = - (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *)) - handler->xerror; - po_xerror2 = - (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *, const message_ty *, const char *, size_t, size_t, int, const char *)) - handler->xerror2; + /* Establish error handler for read_catalog_stream(). */ + unsigned int error_count = 0; + struct xerror_handler local_xerror_handler = + { + (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *)) + handler->xerror, + (void (*) (int, const message_ty *, const char *, size_t, size_t, int, const char *, const message_ty *, const char *, size_t, size_t, int, const char *)) + handler->xerror2, + &error_count + }; gram_max_allowed_errors = UINT_MAX; file = XMALLOC (struct po_file); file->real_filename = filename; file->logical_filename = filename; file->mdlp = read_catalog_stream (fp, file->real_filename, - file->logical_filename, &input_format_po); + file->logical_filename, &input_format_po, + &local_xerror_handler); file->domains = NULL; - /* Restore error handler. */ - po_xerror = textmode_xerror; - po_xerror2 = textmode_xerror2; + /* Restore. */ gram_max_allowed_errors = 20; if (fp != stdin) diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index cb088180f..eeeb13851 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -40,6 +40,7 @@ #include "relocatable.h" #include "basename-lgpl.h" #include "xerror.h" +#include "xerror-handler.h" #include "xvasprintf.h" #include "xalloc.h" #include "msgfmt.h" @@ -1391,7 +1392,8 @@ read_catalog_file_msgfmt (char *filename, catalog_input_format_ty input_syntax) FILE *fp = open_catalog_file (filename, &real_filename, true); default_catalog_reader_ty *dcatr; - dcatr = default_catalog_reader_alloc (&msgfmt_methods); + dcatr = default_catalog_reader_alloc (&msgfmt_methods, + textmode_xerror_handler); dcatr->pass_obsolete_entries = true; dcatr->handle_comments = false; dcatr->allow_domain_directives = true; diff --git a/gettext-tools/src/read-catalog-abstract.c b/gettext-tools/src/read-catalog-abstract.c index 05706d39e..ea455c10e 100644 --- a/gettext-tools/src/read-catalog-abstract.c +++ b/gettext-tools/src/read-catalog-abstract.c @@ -32,7 +32,7 @@ #include "po-charset.h" #include "xalloc.h" #include "xvasprintf.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "gettext.h" @@ -41,12 +41,14 @@ abstract_catalog_reader_ty * -catalog_reader_alloc (abstract_catalog_reader_class_ty *method_table) +catalog_reader_alloc (abstract_catalog_reader_class_ty *method_table, + xerror_handler_ty xerror_handler) { abstract_catalog_reader_ty *catr; catr = (abstract_catalog_reader_ty *) xmalloc (method_table->size); catr->methods = method_table; + catr->xeh = xerror_handler; catr->pass_comments = false; catr->pass_obsolete_entries = false; catr->po_lex_isolate_start = NULL; @@ -155,20 +157,22 @@ catalog_reader_parse (abstract_catalog_reader_ty *catr, FILE *fp, bool is_pot_role, catalog_input_format_ty input_syntax) { - error_message_count = 0; + *(catr->xeh->error_message_count_p) = 0; /* Parse the stream's content. */ call_parse_brief (catr); input_syntax->parse (catr, fp, real_filename, logical_filename, is_pot_role); call_parse_debrief (catr); - if (error_message_count > 0) - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, - /*real_filename*/ NULL, (size_t)(-1), (size_t)(-1), false, - xasprintf (ngettext ("found %u fatal error", - "found %u fatal errors", - error_message_count), - error_message_count)); + unsigned int num_errors = *(catr->xeh->error_message_count_p); + if (num_errors > 0) + catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, + /*real_filename*/ NULL, (size_t)(-1), (size_t)(-1), + false, + xasprintf (ngettext ("found %u fatal error", + "found %u fatal errors", + num_errors), + num_errors)); } diff --git a/gettext-tools/src/read-catalog-abstract.h b/gettext-tools/src/read-catalog-abstract.h index 65e0d895e..e18f9ac6d 100644 --- a/gettext-tools/src/read-catalog-abstract.h +++ b/gettext-tools/src/read-catalog-abstract.h @@ -23,6 +23,7 @@ #include #include "message.h" +#include "xerror-handler.h" #ifdef __cplusplus @@ -127,6 +128,9 @@ struct abstract_catalog_reader_class_ty #define ABSTRACT_CATALOG_READER_TY \ abstract_catalog_reader_class_ty *methods; \ \ + /* The error handler. */ \ + xerror_handler_ty xeh; \ + \ /* True if comments shall be handled, false if they shall be \ ignored. */ \ bool pass_comments; \ @@ -167,7 +171,8 @@ typedef const struct catalog_input_format * catalog_input_format_ty; /* Allocate a fresh abstract_catalog_reader_ty (or derived class) instance and call its constructor. */ extern abstract_catalog_reader_ty * - catalog_reader_alloc (abstract_catalog_reader_class_ty *method_table); + catalog_reader_alloc (abstract_catalog_reader_class_ty *method_table, + xerror_handler_ty xerror_handler); /* Read a PO file from a stream, and dispatch to the various abstract_catalog_reader_class_ty methods. */ diff --git a/gettext-tools/src/read-catalog-file.c b/gettext-tools/src/read-catalog-file.c index 759fb7adc..6567c8588 100644 --- a/gettext-tools/src/read-catalog-file.c +++ b/gettext-tools/src/read-catalog-file.c @@ -1,5 +1,5 @@ /* Reading PO files. - Copyright (C) 1995-2023 Free Software Foundation, Inc. + Copyright (C) 1995-2024 Free Software Foundation, Inc. This file was written by Peter Miller This program is free software: you can redistribute it and/or modify @@ -23,6 +23,7 @@ #include "read-catalog-file.h" #include "open-catalog.h" +#include "xerror-handler.h" msgdomain_list_ty * @@ -32,7 +33,8 @@ read_catalog_file (const char *filename, catalog_input_format_ty input_syntax) FILE *fp = open_catalog_file (filename, &real_filename, true); msgdomain_list_ty *result; - result = read_catalog_stream (fp, real_filename, filename, input_syntax); + result = read_catalog_stream (fp, real_filename, filename, input_syntax, + textmode_xerror_handler); if (fp != stdin) fclose (fp); diff --git a/gettext-tools/src/read-catalog.c b/gettext-tools/src/read-catalog.c index 51f237ef2..8364ef67e 100644 --- a/gettext-tools/src/read-catalog.c +++ b/gettext-tools/src/read-catalog.c @@ -28,7 +28,7 @@ #include "po-charset.h" #include "read-po-lex.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "xalloc.h" #include "read-catalog-special.h" #include "gettext.h" @@ -324,9 +324,10 @@ default_set_domain (default_catalog_reader_ty *dcatr, dcatr->domain = name; else { - po_xerror (PO_SEVERITY_ERROR, NULL, - name_pos->file_name, name_pos->line_number, (size_t)(-1), - false, _("this file may not contain domain directives")); + dcatr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + name_pos->file_name, name_pos->line_number, (size_t)(-1), + false, + _("this file may not contain domain directives")); /* NAME was allocated in read-po-gram.y but is not used anywhere. */ free (name); @@ -369,11 +370,15 @@ default_add_message (default_catalog_reader_ty *dcatr, translations are equal or different. This is for consistency with msgmerge, msgcat and others. The user can use the msguniq program to get rid of duplicates. */ - po_xerror2 (PO_SEVERITY_ERROR, - NULL, msgid_pos->file_name, msgid_pos->line_number, - (size_t)(-1), false, _("duplicate message definition"), - mp, NULL, 0, 0, false, - _("this is the location of the first definition")); + dcatr->xeh->xerror2 (CAT_SEVERITY_ERROR, + NULL, + msgid_pos->file_name, msgid_pos->line_number, (size_t)(-1), + false, + _("duplicate message definition"), + mp, + NULL, 0, 0, + false, + _("this is the location of the first definition")); } /* We don't need the just constructed entries' parameter string (allocated in read-po-gram.y). */ @@ -446,10 +451,12 @@ static default_catalog_reader_class_ty default_methods = default_catalog_reader_ty * -default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table) +default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table, + xerror_handler_ty xerror_handler) { return - (default_catalog_reader_ty *) catalog_reader_alloc (&method_table->super); + (default_catalog_reader_ty *) + catalog_reader_alloc (&method_table->super, xerror_handler); } @@ -466,12 +473,13 @@ bool allow_duplicates = false; msgdomain_list_ty * read_catalog_stream (FILE *fp, const char *real_filename, const char *logical_filename, - catalog_input_format_ty input_syntax) + catalog_input_format_ty input_syntax, + xerror_handler_ty xerror_handler) { default_catalog_reader_ty *dcatr; msgdomain_list_ty *mdlp; - dcatr = default_catalog_reader_alloc (&default_methods); + dcatr = default_catalog_reader_alloc (&default_methods, xerror_handler); dcatr->pass_obsolete_entries = true; dcatr->handle_comments = true; dcatr->allow_domain_directives = true; diff --git a/gettext-tools/src/read-catalog.h b/gettext-tools/src/read-catalog.h index 72d6111f0..b926942c5 100644 --- a/gettext-tools/src/read-catalog.h +++ b/gettext-tools/src/read-catalog.h @@ -20,6 +20,7 @@ #include "message.h" #include "read-catalog-abstract.h" +#include "xerror-handler.h" #include #include @@ -164,7 +165,8 @@ extern void default_add_message (default_catalog_reader_ty *dcatr, /* Allocate a fresh default_catalog_reader_ty (or derived class) instance and call its constructor. */ extern default_catalog_reader_ty * - default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table); + default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table, + xerror_handler_ty xerror_handler); /* If false, duplicate msgids in the same domain and file generate an error. @@ -177,7 +179,8 @@ extern msgdomain_list_ty * read_catalog_stream (FILE *fp, const char *real_filename, const char *logical_filename, - catalog_input_format_ty input_syntax); + catalog_input_format_ty input_syntax, + xerror_handler_ty xerror_handler); #ifdef __cplusplus diff --git a/gettext-tools/src/read-csharp.c b/gettext-tools/src/read-csharp.c index 4a4d70f49..254ea3ab9 100644 --- a/gettext-tools/src/read-csharp.c +++ b/gettext-tools/src/read-csharp.c @@ -35,6 +35,7 @@ #include "wait-process.h" #include "read-catalog.h" #include "read-po.h" +#include "xerror-handler.h" #include "xalloc.h" #include "concat-filename.h" #include "gettext.h" @@ -73,7 +74,8 @@ execute_and_read_po_output (const char *progname, error (EXIT_FAILURE, errno, _("fdopen() failed")); /* Read the message list. */ - l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po); + l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po, + textmode_xerror_handler); fclose (fp); diff --git a/gettext-tools/src/read-java.c b/gettext-tools/src/read-java.c index bf513fd52..f417e501e 100644 --- a/gettext-tools/src/read-java.c +++ b/gettext-tools/src/read-java.c @@ -35,6 +35,7 @@ #include "wait-process.h" #include "read-catalog.h" #include "read-po.h" +#include "xerror-handler.h" #include "gettext.h" #define _(str) gettext (str) @@ -71,7 +72,8 @@ execute_and_read_po_output (const char *progname, error (EXIT_FAILURE, errno, _("fdopen() failed")); /* Read the message list. */ - l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po); + l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po, + textmode_xerror_handler); fclose (fp); diff --git a/gettext-tools/src/read-po-gram.y b/gettext-tools/src/read-po-gram.y index 33ca25174..1d16f308c 100644 --- a/gettext-tools/src/read-po-gram.y +++ b/gettext-tools/src/read-po-gram.y @@ -41,7 +41,8 @@ #define check_obsolete(value1,value2) \ if ((value1).obsolete != (value2).obsolete) \ - po_gram_error_at_line (&(value2).pos, _("inconsistent use of #~")); + po_gram_error_at_line (ps->catr, &(value2).pos, \ + _("inconsistent use of #~")); static inline void do_callback_message (struct po_parser_state *ps, @@ -201,7 +202,7 @@ message { check_obsolete ($1, $2); check_obsolete ($1, $3); - po_gram_error_at_line (&$1.pos, _("missing 'msgstr[]' section")); + po_gram_error_at_line (ps->catr, &$1.pos, _("missing 'msgstr[]' section")); free_message_intro ($1); string_list_destroy (&$2.stringlist); free ($3.string); @@ -210,7 +211,7 @@ message { check_obsolete ($1, $2); check_obsolete ($1, $3); - po_gram_error_at_line (&$1.pos, _("missing 'msgid_plural' section")); + po_gram_error_at_line (ps->catr, &$1.pos, _("missing 'msgid_plural' section")); free_message_intro ($1); string_list_destroy (&$2.stringlist); free ($3.rhs.msgstr); @@ -218,7 +219,7 @@ message | message_intro string_list { check_obsolete ($1, $2); - po_gram_error_at_line (&$1.pos, _("missing 'msgstr' section")); + po_gram_error_at_line (ps->catr, &$1.pos, _("missing 'msgstr' section")); free_message_intro ($1); string_list_destroy (&$2.stringlist); } @@ -357,9 +358,9 @@ pluralform if ($3.number != ps->plural_counter) { if (ps->plural_counter == 0) - po_gram_error_at_line (&$1.pos, _("first plural form has nonzero index")); + po_gram_error_at_line (ps->catr, &$1.pos, _("first plural form has nonzero index")); else - po_gram_error_at_line (&$1.pos, _("plural form has wrong index")); + po_gram_error_at_line (ps->catr, &$1.pos, _("plural form has wrong index")); } ps->plural_counter++; $$.rhs.msgstr = string_list_concat_destroy (&$5.stringlist); diff --git a/gettext-tools/src/read-po-lex.c b/gettext-tools/src/read-po-lex.c index 70e1b474c..3b2d14b62 100644 --- a/gettext-tools/src/read-po-lex.c +++ b/gettext-tools/src/read-po-lex.c @@ -46,7 +46,7 @@ #include "error-progname.h" #include "xvasprintf.h" #include "po-error.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "xmalloca.h" #if !IN_LIBGETTEXTPO # include "basename-lgpl.h" @@ -78,33 +78,38 @@ po_gram_error (struct po_parser_state *ps, const char *fmt, ...) va_start (ap, fmt); if (vasprintf (&buffer, fmt, ap) < 0) - error (EXIT_FAILURE, 0, _("memory exhausted")); + ps->catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("memory exhausted")); va_end (ap); - po_xerror (PO_SEVERITY_ERROR, NULL, - ps->gram_pos.file_name, ps->gram_pos.line_number, - ps->gram_pos_column + 1, false, buffer); + ps->catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + ps->gram_pos.file_name, ps->gram_pos.line_number, + ps->gram_pos_column + 1, false, buffer); free (buffer); - if (error_message_count >= gram_max_allowed_errors) - po_error (EXIT_FAILURE, 0, _("too many errors, aborting")); + if (*(ps->catr->xeh->error_message_count_p) >= gram_max_allowed_errors) + ps->catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("too many errors, aborting")); } void -po_gram_error_at_line (const lex_pos_ty *pp, const char *fmt, ...) +po_gram_error_at_line (abstract_catalog_reader_ty *catr, const lex_pos_ty *pp, + const char *fmt, ...) { va_list ap; char *buffer; va_start (ap, fmt); if (vasprintf (&buffer, fmt, ap) < 0) - error (EXIT_FAILURE, 0, _("memory exhausted")); + catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("memory exhausted")); va_end (ap); - po_xerror (PO_SEVERITY_ERROR, NULL, pp->file_name, pp->line_number, - (size_t)(-1), false, buffer); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, pp->file_name, pp->line_number, + (size_t)(-1), false, buffer); free (buffer); - if (error_message_count >= gram_max_allowed_errors) - po_error (EXIT_FAILURE, 0, _("too many errors, aborting")); + if (*(catr->xeh->error_message_count_p) >= gram_max_allowed_errors) + catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + _("too many errors, aborting")); } @@ -167,9 +172,9 @@ po_lex_charset_set (struct po_parser_state *ps, Charset \"%s\" is not a portable encoding name.\n\ Message conversion to user's charset might not work.\n"), charset); - po_xerror (PO_SEVERITY_WARNING, NULL, - filename, (size_t)(-1), (size_t)(-1), true, - warning_message); + ps->catr->xeh->xerror (CAT_SEVERITY_WARNING, NULL, + filename, (size_t)(-1), (size_t)(-1), true, + warning_message); free (warning_message); } } @@ -284,9 +289,9 @@ would fix this problem.\n"); xasprintf ("%s%s%s\n", warning_message, recommendation, note); - po_xerror (PO_SEVERITY_WARNING, NULL, - filename, (size_t)(-1), (size_t)(-1), true, - whole_message); + ps->catr->xeh->xerror (CAT_SEVERITY_WARNING, NULL, + filename, (size_t)(-1), (size_t)(-1), + true, whole_message); free (whole_message); free (warning_message); @@ -327,9 +332,9 @@ would fix this problem.\n"); xasprintf ("%s%s%s\n", warning_message, recommendation, note); - po_xerror (PO_SEVERITY_WARNING, NULL, - filename, (size_t)(-1), (size_t)(-1), true, - whole_message); + ps->catr->xeh->xerror (CAT_SEVERITY_WARNING, NULL, + filename, (size_t)(-1), (size_t)(-1), + true, whole_message); free (whole_message); free (warning_message); @@ -347,9 +352,9 @@ would fix this problem.\n"); if (!(filenamelen >= 4 && memcmp (filename + filenamelen - 4, ".pot", 4) == 0)) - po_xerror (PO_SEVERITY_WARNING, - NULL, filename, (size_t)(-1), (size_t)(-1), true, - _("\ + ps->catr->xeh->xerror (CAT_SEVERITY_WARNING, + NULL, filename, (size_t)(-1), (size_t)(-1), true, + _("\ Charset missing in header.\n\ Message conversion to user's charset will not work.\n")); } @@ -700,10 +705,11 @@ mbfile_getc (struct po_parser_state *ps, mbchar_t mbc, mbfile_t mbf) else { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - _("iconv failure"), - errno_description)); + ps->catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, + NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + _("iconv failure"), + errno_description)); } } else @@ -864,11 +870,12 @@ lex_getc (struct po_parser_state *ps, mbchar_t mbc) bomb: { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), - ps->gram_pos.file_name), - errno_description)); + ps->catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, + NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while reading \"%s\""), + ps->gram_pos.file_name), + errno_description)); } break; } @@ -953,7 +960,8 @@ keyword_p (struct po_parser_state *ps, const char *s) if (!strcmp (s, "msgctxt")) return PREV_MSGCTXT; } - po_gram_error_at_line (&ps->gram_pos, _("keyword \"%s\" unknown"), s); + po_gram_error_at_line (ps->catr, &ps->gram_pos, + _("keyword \"%s\" unknown"), s); return NAME; } @@ -1195,13 +1203,13 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps) } if (mb_iseof (mbc)) { - po_gram_error_at_line (&ps->gram_pos, + po_gram_error_at_line (ps->catr, &ps->gram_pos, _("end-of-file within string")); break; } if (mb_iseq (mbc, '\n')) { - po_gram_error_at_line (&ps->gram_pos, + po_gram_error_at_line (ps->catr, &ps->gram_pos, _("end-of-line within string")); break; } @@ -1222,7 +1230,7 @@ po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps) /* Strings cannot contain the msgctxt separator, because it cannot be faithfully represented in the msgid of a .mo file. */ if (strchr (buf, MSGCTXT_SEPARATOR) != NULL) - po_gram_error_at_line (&ps->gram_pos, + po_gram_error_at_line (ps->catr, &ps->gram_pos, _("context separator within string")); /* FIXME: Treatment of embedded \000 chars is incorrect. */ diff --git a/gettext-tools/src/read-po-lex.h b/gettext-tools/src/read-po-lex.h index 396312543..69152be34 100644 --- a/gettext-tools/src/read-po-lex.h +++ b/gettext-tools/src/read-po-lex.h @@ -27,6 +27,7 @@ #include "error-progname.h" #include "xerror.h" #include "pos.h" +#include "read-catalog-abstract.h" #ifndef __attribute__ /* This feature is available in gcc versions 2.5 and later. */ @@ -74,8 +75,9 @@ extern int po_gram_lex (union PO_GRAM_STYPE *lval, struct po_parser_state *ps); extern void po_gram_error (struct po_parser_state *ps, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); -extern void po_gram_error_at_line (const lex_pos_ty *pos, const char *fmt, ...) - __attribute__ ((__format__ (__printf__, 2, 3))); +extern void po_gram_error_at_line (abstract_catalog_reader_ty *catr, + const lex_pos_ty *pos, const char *fmt, ...) + __attribute__ ((__format__ (__printf__, 3, 4))); /* Set the PO file's encoding from the header entry. If is_pot_role is true, "charset=CHARSET" is expected and does not deserve diff --git a/gettext-tools/src/read-properties.c b/gettext-tools/src/read-properties.c index 451e80575..543c1c658 100644 --- a/gettext-tools/src/read-properties.c +++ b/gettext-tools/src/read-properties.c @@ -35,7 +35,7 @@ #include "read-catalog-abstract.h" #include "xalloc.h" #include "xvasprintf.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "msgl-ascii.h" #include "read-file.h" #include "unistr.h" @@ -311,7 +311,7 @@ conv_from_java (char *string) #define UTF16_VALUE(p4_result) ((unsigned short) ((p4_result) - 0x10000)) static int -phase4_getuc () +phase4_getuc (abstract_catalog_reader_ty *catr) { int c = phase3_getc (); @@ -347,9 +347,10 @@ phase4_getuc () else { phase3_ungetc (c1); - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), - false, _("warning: invalid \\uxxxx syntax for Unicode character")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), + false, + _("warning: invalid \\uxxxx syntax for Unicode character")); return 'u'; } } @@ -373,7 +374,7 @@ phase4_getuc () - otherwise, if in_key is false, after the end of the logical line. */ static char * -read_escaped_string (bool in_key) +read_escaped_string (abstract_catalog_reader_ty *catr, bool in_key) { /* The part of the string that has already been converted to UTF-8. */ static unsigned char *utf8_buffer; @@ -419,9 +420,10 @@ read_escaped_string (bool in_key) do \ { \ error_with_progname = false; \ - po_xerror (PO_SEVERITY_ERROR, NULL, \ - real_file_name, (line), (size_t)(-1), false, \ - xasprintf (_("warning: lone surrogate U+%04X"), (uc))); \ + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, \ + real_file_name, (line), (size_t)(-1), false, \ + xasprintf (_("warning: lone surrogate U+%04X"), \ + (uc))); \ error_with_progname = true; \ utf8_buffer_ensure_available (3); \ utf8_buffer[utf8_buflen++] = 0xef; \ @@ -462,7 +464,7 @@ read_escaped_string (bool in_key) phase3_ungetc (c); /* Read the next byte or UTF-16 code point. */ - c = phase4_getuc (); + c = phase4_getuc (catr); if (c == P4_EOF) break; @@ -489,9 +491,10 @@ read_escaped_string (bool in_key) if (len < 0) { error_with_progname = false; - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), - false, _("warning: invalid Unicode character")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), + false, + _("warning: invalid Unicode character")); error_with_progname = true; } else @@ -524,9 +527,10 @@ read_escaped_string (bool in_key) if (len < 0) { error_with_progname = false; - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), - false, _("warning: invalid Unicode character")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), + false, + _("warning: invalid Unicode character")); error_with_progname = true; } else @@ -600,11 +604,11 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file, if (contents == NULL) { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), - real_filename), - errno_description)); + catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while reading \"%s\""), + real_filename), + errno_description)); return; } @@ -682,7 +686,7 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file, lex_pos_ty msgid_pos; msgid_pos = pos; - msgid = read_escaped_string (true); + msgid = read_escaped_string (catr, true); if (msgid == NULL) /* Skip blank line. */ ; @@ -693,7 +697,7 @@ properties_parse (abstract_catalog_reader_ty *catr, FILE *file, bool force_fuzzy; msgstr_pos = pos; - msgstr = read_escaped_string (false); + msgstr = read_escaped_string (catr, false); if (msgstr == NULL) msgstr = xstrdup (""); diff --git a/gettext-tools/src/read-resources.c b/gettext-tools/src/read-resources.c index ee44a325d..a0f432e79 100644 --- a/gettext-tools/src/read-resources.c +++ b/gettext-tools/src/read-resources.c @@ -35,6 +35,7 @@ #include "wait-process.h" #include "read-catalog.h" #include "read-po.h" +#include "xerror-handler.h" #include "message.h" #include "concat-filename.h" #include "gettext.h" @@ -74,7 +75,8 @@ execute_and_read_po_output (const char *progname, error (EXIT_FAILURE, errno, _("fdopen() failed")); /* Read the message list. */ - l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po); + l->mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po, + textmode_xerror_handler); fclose (fp); diff --git a/gettext-tools/src/read-stringtable.c b/gettext-tools/src/read-stringtable.c index 6baf3ad42..018e7a131 100644 --- a/gettext-tools/src/read-stringtable.c +++ b/gettext-tools/src/read-stringtable.c @@ -35,7 +35,7 @@ #include "read-catalog-abstract.h" #include "xalloc.h" #include "xvasprintf.h" -#include "po-xerror.h" +#include "xerror-handler.h" #include "unistr.h" #include "gettext.h" @@ -80,7 +80,7 @@ static unsigned char phase1_pushback[4]; static int phase1_pushback_length; static int -phase1_getc () +phase1_getc (abstract_catalog_reader_ty *catr) { int c; @@ -94,11 +94,11 @@ phase1_getc () if (ferror (fp)) { const char *errno_description = strerror (errno); - po_xerror (PO_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, - xasprintf ("%s: %s", - xasprintf (_("error while reading \"%s\""), - real_file_name), - errno_description)); + catr->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false, + xasprintf ("%s: %s", + xasprintf (_("error while reading \"%s\""), + real_file_name), + errno_description)); } return EOF; } @@ -138,7 +138,7 @@ enum enc static enum enc encoding; static int -phase2_getc () +phase2_getc (abstract_catalog_reader_ty *catr) { if (phase2_pushback_length) return phase2_pushback[--phase2_pushback_length]; @@ -148,10 +148,10 @@ phase2_getc () /* Determine the input file's encoding. */ int c0, c1; - c0 = phase1_getc (); + c0 = phase1_getc (catr); if (c0 == EOF) return UEOF; - c1 = phase1_getc (); + c1 = phase1_getc (catr); if (c1 == EOF) { phase1_ungetc (c0); @@ -165,7 +165,7 @@ phase2_getc () { int c2; - c2 = phase1_getc (); + c2 = phase1_getc (catr); if (c2 == EOF) { phase1_ungetc (c1); @@ -191,10 +191,10 @@ phase2_getc () { int c0, c1; - c0 = phase1_getc (); + c0 = phase1_getc (catr); if (c0 == EOF) return UEOF; - c1 = phase1_getc (); + c1 = phase1_getc (catr); if (c1 == EOF) return UEOF; return (c0 << 8) + c1; @@ -205,10 +205,10 @@ phase2_getc () { int c0, c1; - c0 = phase1_getc (); + c0 = phase1_getc (catr); if (c0 == EOF) return UEOF; - c1 = phase1_getc (); + c1 = phase1_getc (catr); if (c1 == EOF) return UEOF; return c0 + (c1 << 8); @@ -222,7 +222,7 @@ phase2_getc () int c; ucs4_t uc; - c = phase1_getc (); + c = phase1_getc (catr); if (c == EOF) return UEOF; buf[0] = c; @@ -230,7 +230,7 @@ phase2_getc () if (buf[0] >= 0xc0) { - c = phase1_getc (); + c = phase1_getc (catr); if (c == EOF) return UEOF; buf[1] = c; @@ -239,7 +239,7 @@ phase2_getc () if (buf[0] >= 0xe0 && ((buf[1] ^ 0x80) < 0x40)) { - c = phase1_getc (); + c = phase1_getc (catr); if (c == EOF) return UEOF; buf[2] = c; @@ -248,7 +248,7 @@ phase2_getc () if (buf[0] >= 0xf0 && ((buf[2] ^ 0x80) < 0x40)) { - c = phase1_getc (); + c = phase1_getc (catr); if (c == EOF) return UEOF; buf[3] = c; @@ -257,7 +257,7 @@ phase2_getc () if (buf[0] >= 0xf8 && ((buf[3] ^ 0x80) < 0x40)) { - c = phase1_getc (); + c = phase1_getc (catr); if (c == EOF) return UEOF; buf[4] = c; @@ -266,7 +266,7 @@ phase2_getc () if (buf[0] >= 0xfc && ((buf[4] ^ 0x80) < 0x40)) { - c = phase1_getc (); + c = phase1_getc (catr); if (c == EOF) return UEOF; buf[5] = c; @@ -284,7 +284,7 @@ phase2_getc () case enc_iso8859_1: /* Read an ISO-8859-1 encoded character. */ { - int c = phase1_getc (); + int c = phase1_getc (catr); if (c == EOF) return UEOF; @@ -307,9 +307,9 @@ phase2_ungetc (int c) /* Phase 3: Read an UCS-4 character, with line number handling. */ static int -phase3_getc () +phase3_getc (abstract_catalog_reader_ty *catr) { - int c = phase2_getc (); + int c = phase2_getc (catr); if (c == '\n') pos.line_number++; @@ -579,10 +579,10 @@ phase4_getc (abstract_catalog_reader_ty *catr) { int c; - c = phase3_getc (); + c = phase3_getc (catr); if (c != '/') return c; - c = phase3_getc (); + c = phase3_getc (catr); switch (c) { default: @@ -603,7 +603,7 @@ phase4_getc (abstract_catalog_reader_ty *catr) /* Drop additional stars at the beginning of the comment. */ for (;;) { - c = phase3_getc (); + c = phase3_getc (catr); if (c != '*') break; last_was_star = true; @@ -611,7 +611,7 @@ phase4_getc (abstract_catalog_reader_ty *catr) phase3_ungetc (c); for (;;) { - c = phase3_getc (); + c = phase3_getc (catr); if (c == UEOF) break; /* We skip all leading white space, but not EOLs. */ @@ -658,7 +658,7 @@ phase4_getc (abstract_catalog_reader_ty *catr) comment_start (); for (;;) { - c = phase3_getc (); + c = phase3_getc (catr); if (c == '\n' || c == UEOF) break; /* We skip all leading white space, but not EOLs. */ @@ -732,12 +732,12 @@ read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *start_pos) /* Read a string enclosed in double-quotes. */ for (;;) { - c = phase3_getc (); + c = phase3_getc (catr); if (c == UEOF || c == '"') break; if (c == '\\') { - c = phase3_getc (); + c = phase3_getc (catr); if (c == UEOF) break; if (c >= '0' && c <= '7') @@ -749,7 +749,7 @@ read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *start_pos) n = n * 8 + (c - '0'); if (++j == 3) break; - c = phase3_getc (); + c = phase3_getc (catr); if (!(c >= '0' && c <= '7')) { phase3_ungetc (c); @@ -764,7 +764,7 @@ read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *start_pos) int j; for (j = 0; j < 4; j++) { - c = phase3_getc (); + c = phase3_getc (catr); if (c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if (c >= 'A' && c <= 'F') @@ -799,17 +799,17 @@ read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *start_pos) buffer[buflen++] = c; } if (c == UEOF) - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), false, - _("warning: unterminated string")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), false, + _("warning: unterminated string")); } else { /* Read a token outside quotes. */ if (is_quotable (c)) - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), false, - _("warning: syntax error")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), false, + _("warning: syntax error")); for (; c != UEOF && !is_quotable (c); c = phase4_getc (catr)) { if (buflen >= bufmax) @@ -869,9 +869,10 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file, /* Expect a '=' or ';'. */ if (c == UEOF) { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), false, - _("warning: unterminated key/value pair")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), + false, + _("warning: unterminated key/value pair")); break; } if (c == ';') @@ -892,9 +893,10 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file, msgstr = read_string (catr, &msgstr_pos); if (msgstr == NULL) { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), - false, _("warning: unterminated key/value pair")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), + false, + _("warning: unterminated key/value pair")); break; } @@ -918,7 +920,7 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file, if (fuzzy_msgstr == NULL && next_is_fuzzy) { do - c = phase3_getc (); + c = phase3_getc (catr); while (c == ' '); phase3_ungetc (c); @@ -939,18 +941,19 @@ stringtable_parse (abstract_catalog_reader_ty *catr, FILE *file, } else { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), - false, - _("warning: syntax error, expected ';' after string")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), + false, + _("warning: syntax error, expected ';' after string")); break; } } else { - po_xerror (PO_SEVERITY_ERROR, NULL, - real_file_name, pos.line_number, (size_t)(-1), false, - _("warning: syntax error, expected '=' or ';' after string")); + catr->xeh->xerror (CAT_SEVERITY_ERROR, NULL, + real_file_name, pos.line_number, (size_t)(-1), + false, + _("warning: syntax error, expected '=' or ';' after string")); break; } } diff --git a/gettext-tools/src/read-tcl.c b/gettext-tools/src/read-tcl.c index 3d6b93ac9..625b2ecb7 100644 --- a/gettext-tools/src/read-tcl.c +++ b/gettext-tools/src/read-tcl.c @@ -36,6 +36,7 @@ #include "wait-process.h" #include "read-catalog.h" #include "read-po.h" +#include "xerror-handler.h" #include "xmalloca.h" #include "gettext.h" @@ -110,7 +111,8 @@ msgdomain_read_tcl (const char *locale_name, const char *directory) error (EXIT_FAILURE, errno, _("fdopen() failed")); /* Read the message list. */ - mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po); + mdlp = read_catalog_stream (fp, "(pipe)", "(pipe)", &input_format_po, + textmode_xerror_handler); fclose (fp); diff --git a/gettext-tools/src/x-po.c b/gettext-tools/src/x-po.c index c6140d030..8c610c3e0 100644 --- a/gettext-tools/src/x-po.c +++ b/gettext-tools/src/x-po.c @@ -34,6 +34,7 @@ #include "message.h" #include "xgettext.h" #include "xalloc.h" +#include "xerror-handler.h" #include "read-catalog.h" #include "read-po.h" #include "read-properties.h" @@ -156,7 +157,8 @@ extract (FILE *fp, header_charset = NULL; - dcatr = default_catalog_reader_alloc (&extract_methods); + dcatr = default_catalog_reader_alloc (&extract_methods, + textmode_xerror_handler); dcatr->handle_comments = true; dcatr->allow_domain_directives = false; dcatr->allow_duplicates = false; diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index d3ebfa3d6..aff039833 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -63,6 +63,7 @@ #include "verify.h" #include "c-strstr.h" #include "xerror.h" +#include "xerror-handler.h" #include "filename.h" #include "concat-filename.h" #include "c-strcase.h" @@ -1342,7 +1343,7 @@ read_exclusion_file (char *filename) FILE *fp = open_catalog_file (filename, &real_filename, true); abstract_catalog_reader_ty *catr; - catr = catalog_reader_alloc (&exclude_methods); + catr = catalog_reader_alloc (&exclude_methods, textmode_xerror_handler); catalog_reader_parse (catr, fp, real_filename, filename, true, &input_format_po); catalog_reader_free (catr);