From: Bruno Haible Date: Fri, 2 Aug 2024 20:33:13 +0000 (+0200) Subject: Refactor: Don't use po_gram_error_at_line outside the PO file reader. X-Git-Tag: v0.23~193 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9e52c0e65975c39983117bc45d5c5403af8f5f47;p=thirdparty%2Fgettext.git Refactor: Don't use po_gram_error_at_line outside the PO file reader. * gettext-tools/src/msgcmp.c: Include po-xerror.h, xvasprintf.h. (match_domain, compare): Use po_xerror, po_xerror2 instead of po_gram_error_at_line. * gettext-tools/src/msgfmt.c: Include po-xerror.h. (msgfmt_set_domain): Use po_xerror instead of po_gram_error_at_line. * gettext-tools/src/msgmerge.c: Include xvasprintf.h. (match_domain): Use po_xerror, po_xerror2 instead of po_gram_error_at_line. * gettext-tools/src/read-catalog.c (default_set_domain): Use po_xerror instead of po_gram_error_at_line. * gettext-tools/src/xgettext.c: Include po-xerror.h. (exclude_directive_domain): Use po_xerror instead of po_gram_error_at_line. --- diff --git a/gettext-tools/src/msgcmp.c b/gettext-tools/src/msgcmp.c index 731178fef..2d55ca33b 100644 --- a/gettext-tools/src/msgcmp.c +++ b/gettext-tools/src/msgcmp.c @@ -41,6 +41,8 @@ #include "read-properties.h" #include "read-stringtable.h" #include "xmalloca.h" +#include "po-xerror.h" +#include "xvasprintf.h" #include "po-charset.h" #include "msgl-iconv.h" #include "msgl-fsearch.h" @@ -323,14 +325,14 @@ match_domain (const char *fn1, const char *fn2, if (!include_untranslated && defmsg->msgstr[0] == '\0') { (*nerrors)++; - po_gram_error_at_line (&defmsg->pos, - _("this message is untranslated")); + po_xerror (PO_SEVERITY_ERROR, defmsg, NULL, 0, 0, false, + _("this message is untranslated")); } else if (!include_fuzzies && defmsg->is_fuzzy && !is_header (defmsg)) { (*nerrors)++; - po_gram_error_at_line (&defmsg->pos, - _("this message needs to be reviewed by the translator")); + po_xerror (PO_SEVERITY_ERROR, defmsg, NULL, 0, 0, false, + _("this message needs to be reviewed by the translator")); } else defmsg->used = 1; @@ -368,17 +370,18 @@ match_domain (const char *fn1, const char *fn2, defmsg = NULL; if (defmsg) { - po_gram_error_at_line (&refmsg->pos, - _("this message is used but not defined...")); - error_message_count--; - po_gram_error_at_line (&defmsg->pos, - _("...but this definition is similar")); + po_xerror2 (PO_SEVERITY_ERROR, + refmsg, NULL, 0, 0, false, + _("this message is used but not defined"), + defmsg, NULL, 0, 0, false, + _("but this definition is similar")); defmsg->used = 1; } else - po_gram_error_at_line (&refmsg->pos, - _("this message is used but not defined in %s"), - fn1); + po_xerror (PO_SEVERITY_ERROR, refmsg, NULL, 0, 0, false, + xasprintf ( + _("this message is used but not defined in %s"), + fn1)); } } } @@ -545,8 +548,8 @@ compare (const char *fn1, const char *fn2, catalog_input_format_ty input_syntax) message_ty *defmsg = defmlp->item[j]; if (!defmsg->used) - po_gram_error_at_line (&defmsg->pos, - _("warning: this message is not used")); + po_xerror (PO_SEVERITY_ERROR, defmsg, NULL, 0, 0, false, + _("warning: this message is not used")); } } diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index 7e6cbb345..cb088180f 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -60,6 +60,7 @@ #include "read-properties.h" #include "read-stringtable.h" #include "read-desktop.h" +#include "po-xerror.h" #include "po-charset.h" #include "msgl-check.h" #include "msgl-iconv.h" @@ -1236,8 +1237,10 @@ msgfmt_set_domain (default_catalog_reader_ty *dcatr, else { if (check_domain) - po_gram_error_at_line (name_pos, - _("'domain %s' directive ignored"), name); + po_xerror (PO_SEVERITY_ERROR, NULL, + name_pos->file_name, name_pos->line_number, (size_t)(-1), + false, + xasprintf (_("'domain %s' directive ignored"), name)); /* NAME was allocated in read-po-gram.y but is not used anywhere. */ free (name); diff --git a/gettext-tools/src/msgmerge.c b/gettext-tools/src/msgmerge.c index fb09b265f..1782bef8b 100644 --- a/gettext-tools/src/msgmerge.c +++ b/gettext-tools/src/msgmerge.c @@ -67,6 +67,7 @@ #include "plural-count.h" #include "msgl-check.h" #include "po-xerror.h" +#include "xvasprintf.h" #include "backupfile.h" #include "copy-file.h" #include "propername.h" @@ -1596,13 +1597,11 @@ match_domain (const char *fn1, const char *fn2, message_ty *mp; if (verbosity_level > 1) - { - po_gram_error_at_line (&refmsg->pos, - _("this message is used but not defined...")); - error_message_count--; - po_gram_error_at_line (&defmsg->pos, - _("...but this definition is similar")); - } + po_xerror2 (PO_SEVERITY_ERROR, + refmsg, NULL, 0, 0, false, + _("this message is used but not defined"), + defmsg, NULL, 0, 0, false, + _("but this definition is similar")); /* Merge the reference with the definition: take the #. and #: comments from the reference, take the # comments from @@ -1629,9 +1628,10 @@ match_domain (const char *fn1, const char *fn2, const char *pend; if (verbosity_level > 1) - po_gram_error_at_line (&refmsg->pos, - _("this message is used but not defined in %s"), - fn1); + po_xerror (PO_SEVERITY_ERROR, refmsg, NULL, 0, 0, false, + xasprintf ( + _("this message is used but not defined in %s"), + fn1)); mp = message_copy (refmsg); @@ -1708,8 +1708,8 @@ match_domain (const char *fn1, const char *fn2, unsigned long i; if (verbosity_level > 1) - po_gram_error_at_line (&mp->pos, - _("this message should define plural forms")); + po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false, + _("this message should define plural forms")); new_msgstr_len = nplurals * mp->msgstr_len; new_msgstr = XNMALLOC (new_msgstr_len, char); @@ -1729,8 +1729,8 @@ match_domain (const char *fn1, const char *fn2, Use only the first among the plural forms. */ if (verbosity_level > 1) - po_gram_error_at_line (&mp->pos, - _("this message should not define plural forms")); + po_xerror (PO_SEVERITY_ERROR, mp, NULL, 0, 0, false, + _("this message should not define plural forms")); mp->msgstr_len = strlen (mp->msgstr) + 1; mp->is_fuzzy = true; diff --git a/gettext-tools/src/read-catalog.c b/gettext-tools/src/read-catalog.c index 7b373aae7..51f237ef2 100644 --- a/gettext-tools/src/read-catalog.c +++ b/gettext-tools/src/read-catalog.c @@ -324,8 +324,9 @@ default_set_domain (default_catalog_reader_ty *dcatr, dcatr->domain = name; else { - po_gram_error_at_line (name_pos, - _("this file may not contain domain directives")); + 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")); /* NAME was allocated in read-po-gram.y but is not used anywhere. */ free (name); diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index fdcb85cc4..d3ebfa3d6 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -72,6 +72,7 @@ #include "read-po-lex.h" #include "message.h" #include "pos.h" +#include "po-xerror.h" #include "po-charset.h" #include "msgl-iconv.h" #include "msgl-ascii.h" @@ -1272,8 +1273,9 @@ static void exclude_directive_domain (abstract_catalog_reader_ty *catr, char *name, lex_pos_ty *name_pos) { - po_gram_error_at_line (name_pos, - _("this file may not contain domain directives")); + 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")); }