#include "read-po-lex.h"
#include "write-catalog.h"
#include "write-po.h"
-#include "po-xerror.h"
#include "xvasprintf.h"
#include "msgl-check.h"
#include "gettext.h"
msgdomain_list_ty *mdlp;
size_t k;
- /* Establish error handler. */
- 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 check_message_list(). */
+ 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
+ };
mdlp = file->mdlp;
for (k = 0; k < mdlp->nitems; k++)
- check_message_list (mdlp->item[k]->messages, 1, 1, 1, 1, 1, 0, 0, 0);
-
- /* Restore error handler. */
- po_xerror = textmode_xerror;
- po_xerror2 = textmode_xerror2;
+ check_message_list (mdlp->item[k]->messages, 1, 1, 1, 1, 1, 0, 0, 0,
+ &local_xerror_handler);
}
{
message_ty *mp = (message_ty *) message;
- /* Establish error handler. */
- 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 check_message_list(). */
+ 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
+ };
/* For plural checking, combine the message and its header into a small,
two-element message list. */
if (mp != header)
message_list_append (&ml, mp);
- check_message_list (&ml, 1, 1, 1, 1, 1, 0, 0, 0);
+ check_message_list (&ml, 1, 1, 1, 1, 1, 0, 0, 0, &local_xerror_handler);
}
}
-
- /* Restore error handler. */
- po_xerror = textmode_xerror;
- po_xerror2 = textmode_xerror2;
}
{
message_ty *mp = (message_ty *) message;
- /* Establish error handler. */
- 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 check_message(). */
+ 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
+ };
if (!mp->obsolete)
- check_message (mp, &mp->pos, 0, 1, NULL, 0, 0, 0, 0);
-
- /* Restore error handler. */
- po_xerror = textmode_xerror;
- po_xerror2 = textmode_xerror2;
+ check_message (mp, &mp->pos, 0, 1, NULL, 0, 0, 0, 0, &local_xerror_handler);
}
check_plural_eval (const struct expression *plural_expr,
unsigned long nplurals_value,
const message_ty *header,
- struct plural_distribution *distribution)
+ struct plural_distribution *distribution,
+ xerror_handler_ty xeh)
{
/* Do as if the plural formula assumes a value N infinitely often if it
assumes it at least 5 times. */
if (res.status != PE_OK)
{
if (res.status == PE_INTDIV)
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false,
- _("plural expression can produce division by zero"));
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+ _("plural expression can produce division by zero"));
else if (res.status == PE_INTOVF)
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false,
- _("plural expression can produce integer overflow"));
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+ _("plural expression can produce integer overflow"));
else if (res.status == PE_STACKOVF)
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false,
- _("plural expression can produce stack overflow"));
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+ _("plural expression can produce stack overflow"));
else
/* Other res.status values should not occur. */
abort ();
if ((long) val < 0)
{
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false,
- _("plural expression can produce negative values"));
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+ _("plural expression can produce negative values"));
free (array);
return 1;
}
char *msg =
xasprintf (_("nplurals = %lu but plural expression can produce values as large as %lu"),
nplurals_value, val);
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg);
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false, msg);
free (msg);
free (array);
return 1;
check_plural (message_list_ty *mlp,
int ignore_untranslated_messages,
int ignore_fuzzy_messages,
- struct plural_distribution *distributionp)
+ struct plural_distribution *distributionp,
+ xerror_handler_ty xeh)
{
int seen_errors = 0;
const message_ty *has_plural;
if (help != NULL)
{
char *msg2ext = xasprintf ("%s\n%s", msg2, help);
- po_xerror2 (PO_SEVERITY_ERROR,
- has_plural, NULL, 0, 0, false, msg1,
- header, NULL, 0, 0, true, msg2ext);
+ xeh->xerror2 (CAT_SEVERITY_ERROR,
+ has_plural, NULL, 0, 0, false, msg1,
+ header, NULL, 0, 0, true, msg2ext);
free (msg2ext);
free (help);
}
else
- po_xerror2 (PO_SEVERITY_ERROR,
- has_plural, NULL, 0, 0, false, msg1,
- header, NULL, 0, 0, false, msg2);
+ xeh->xerror2 (CAT_SEVERITY_ERROR,
+ has_plural, NULL, 0, 0, false, msg1,
+ header, NULL, 0, 0, false, msg2);
seen_errors++;
}
if (help != NULL)
{
char *msg2ext = xasprintf ("%s\n%s", msg2, help);
- po_xerror2 (PO_SEVERITY_ERROR,
- has_plural, NULL, 0, 0, false, msg1,
- header, NULL, 0, 0, true, msg2ext);
+ xeh->xerror2 (CAT_SEVERITY_ERROR,
+ has_plural, NULL, 0, 0, false, msg1,
+ header, NULL, 0, 0, true, msg2ext);
free (msg2ext);
free (help);
}
else
- po_xerror2 (PO_SEVERITY_ERROR,
- has_plural, NULL, 0, 0, false, msg1,
- header, NULL, 0, 0, false, msg2);
+ xeh->xerror2 (CAT_SEVERITY_ERROR,
+ has_plural, NULL, 0, 0, false, msg1,
+ header, NULL, 0, 0, false, msg2);
seen_errors++;
}
if (help != NULL)
{
char *msgext = xasprintf ("%s\n%s", msg, help);
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, true,
- msgext);
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, true,
+ msgext);
free (msgext);
free (help);
}
else
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg);
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+ msg);
seen_errors++;
}
if (help != NULL)
{
char *msgext = xasprintf ("%s\n%s", msg, help);
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, true,
- msgext);
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, true,
+ msgext);
free (msgext);
free (help);
}
else
- po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg);
+ xeh->xerror (CAT_SEVERITY_ERROR, header, NULL, 0, 0, false,
+ msg);
seen_errors++;
}
if (!seen_errors)
seen_errors =
check_plural_eval (plural_expr, nplurals_value, header,
- &distribution);
+ &distribution, xeh);
/* Check the number of plurals of the translations. */
if (!seen_errors)
"but some messages have only %lu plural forms",
min_nplurals),
min_nplurals);
- po_xerror2 (PO_SEVERITY_ERROR,
- header, NULL, 0, 0, false, msg1,
- min_pos, NULL, 0, 0, false, msg2);
+ xeh->xerror2 (CAT_SEVERITY_ERROR,
+ header, NULL, 0, 0, false, msg1,
+ min_pos, NULL, 0, 0, false, msg2);
free (msg2);
free (msg1);
seen_errors++;
"but some messages have %lu plural forms",
max_nplurals),
max_nplurals);
- po_xerror2 (PO_SEVERITY_ERROR,
- header, NULL, 0, 0, false, msg1,
- max_pos, NULL, 0, 0, false, msg2);
+ xeh->xerror2 (CAT_SEVERITY_ERROR,
+ header, NULL, 0, 0, false, msg1,
+ max_pos, NULL, 0, 0, false, msg2);
free (msg2);
free (msg1);
seen_errors++;
{
if (has_plural != NULL)
{
- po_xerror (PO_SEVERITY_ERROR, has_plural, NULL, 0, 0, false,
- _("message catalog has plural form translations, but lacks a header entry with \"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\""));
+ xeh->xerror (CAT_SEVERITY_ERROR, has_plural, NULL, 0, 0, false,
+ _("message catalog has plural form translations, but lacks a header entry with \"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\""));
seen_errors++;
}
no_plural:
/* Signal an error when checking format strings. */
struct formatstring_error_logger_locals
{
+ xerror_handler_ty xeh;
const message_ty *curr_mp;
lex_pos_ty curr_msgid_pos;
};
va_start (args, format);
if (vasprintf (&msg, format, args) < 0)
- error (EXIT_FAILURE, 0, _("memory exhausted"));
+ l->xeh->xerror (CAT_SEVERITY_FATAL_ERROR, NULL, NULL, 0, 0, false,
+ _("memory exhausted"));
va_end (args);
- po_xerror (PO_SEVERITY_ERROR,
- l->curr_mp,
- l->curr_msgid_pos.file_name, l->curr_msgid_pos.line_number,
- (size_t)(-1), false, msg);
+ l->xeh->xerror (CAT_SEVERITY_ERROR,
+ l->curr_mp,
+ l->curr_msgid_pos.file_name, l->curr_msgid_pos.line_number,
+ (size_t)(-1), false, msg);
free (msg);
}
int check_format_strings,
const struct plural_distribution *distribution,
int check_compatibility,
- int check_accelerators, char accelerator_char)
+ int check_accelerators, char accelerator_char,
+ xerror_handler_ty xeh)
{
int seen_errors;
int has_newline;
if (TEST_NEWLINE(msgid_plural) != has_newline)
{
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false,
- _("'msgid' and 'msgid_plural' entries do not both begin with '\\n'"));
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false,
+ _("'msgid' and 'msgid_plural' entries do not both begin with '\\n'"));
seen_errors++;
}
for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
char *msg =
xasprintf (_("'msgid' and 'msgstr[%u]' entries do not both begin with '\\n'"),
j);
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false, msg);
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false, msg);
free (msg);
seen_errors++;
}
{
if (TEST_NEWLINE(msgstr) != has_newline)
{
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false,
- _("'msgid' and 'msgstr' entries do not both begin with '\\n'"));
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false,
+ _("'msgid' and 'msgstr' entries do not both begin with '\\n'"));
seen_errors++;
}
}
if (TEST_NEWLINE(msgid_plural) != has_newline)
{
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false,
- _("'msgid' and 'msgid_plural' entries do not both end with '\\n'"));
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false,
+ _("'msgid' and 'msgid_plural' entries do not both end with '\\n'"));
seen_errors++;
}
for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
char *msg =
xasprintf (_("'msgid' and 'msgstr[%u]' entries do not both end with '\\n'"),
j);
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false, msg);
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false, msg);
free (msg);
seen_errors++;
}
{
if (TEST_NEWLINE(msgstr) != has_newline)
{
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false,
- _("'msgid' and 'msgstr' entries do not both end with '\\n'"));
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false,
+ _("'msgid' and 'msgstr' entries do not both end with '\\n'"));
seen_errors++;
}
}
if (check_compatibility && msgid_plural != NULL)
{
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false,
- _("plural handling is a GNU gettext extension"));
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false,
+ _("plural handling is a GNU gettext extension"));
seen_errors++;
}
of format specifications. */
{
struct formatstring_error_logger_locals locals;
+ locals.xeh = xeh;
locals.curr_mp = mp;
locals.curr_msgid_pos = *msgid_pos;
seen_errors +=
char *msg =
xasprintf (_("msgstr lacks the keyboard accelerator mark '%c'"),
accelerator_char);
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false, msg);
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false, msg);
free (msg);
seen_errors++;
}
char *msg =
xasprintf (_("msgstr has too many keyboard accelerator marks '%c'"),
accelerator_char);
- po_xerror (PO_SEVERITY_ERROR,
- mp, msgid_pos->file_name, msgid_pos->line_number,
- (size_t)(-1), false, msg);
+ xeh->xerror (CAT_SEVERITY_ERROR,
+ mp, msgid_pos->file_name, msgid_pos->line_number,
+ (size_t)(-1), false, msg);
free (msg);
seen_errors++;
}
/* Perform miscellaneous checks on a header entry. */
static int
-check_header_entry (const message_ty *mp, const char *msgstr_string)
+check_header_entry (const message_ty *mp, const char *msgstr_string,
+ xerror_handler_ty xeh)
{
static const char *required_fields[] =
{
{
#if 0
int severity =
- (cnt < nrequiredfields ? PO_SEVERITY_ERROR : PO_SEVERITY_WARNING);
+ (cnt < nrequiredfields ? CAT_SEVERITY_ERROR : CAT_SEVERITY_WARNING);
#else
int severity =
- PO_SEVERITY_WARNING;
+ CAT_SEVERITY_WARNING;
#endif
const char *field = required_fields[cnt];
size_t len = strlen (field);
char *msg =
xasprintf (_("header field '%s' still has the initial default value\n"),
field);
- po_xerror (severity, mp, NULL, 0, 0, true, msg);
+ xeh->xerror (severity, mp, NULL, 0, 0, true, msg);
free (msg);
- if (severity == PO_SEVERITY_ERROR)
+ if (severity == CAT_SEVERITY_ERROR)
seen_errors++;
}
}
char *msg =
xasprintf (_("header field '%s' missing in header\n"),
field);
- po_xerror (severity, mp, NULL, 0, 0, true, msg);
+ xeh->xerror (severity, mp, NULL, 0, 0, true, msg);
free (msg);
- if (severity == PO_SEVERITY_ERROR)
+ if (severity == CAT_SEVERITY_ERROR)
seen_errors++;
}
}
const struct plural_distribution *distribution,
int check_header,
int check_compatibility,
- int check_accelerators, char accelerator_char)
+ int check_accelerators, char accelerator_char,
+ xerror_handler_ty xeh)
{
int seen_errors = 0;
if (check_header && is_header (mp))
- seen_errors += check_header_entry (mp, mp->msgstr);
+ seen_errors += check_header_entry (mp, mp->msgstr, xeh);
seen_errors += check_pair (mp,
mp->msgid, msgid_pos, mp->msgid_plural,
check_format_strings,
distribution,
check_compatibility,
- check_accelerators, accelerator_char);
+ check_accelerators, accelerator_char,
+ xeh);
return seen_errors;
}
int check_format_strings,
int check_header,
int check_compatibility,
- int check_accelerators, char accelerator_char)
+ int check_accelerators, char accelerator_char,
+ xerror_handler_ty xeh)
{
int seen_errors = 0;
struct plural_distribution distribution;
if (check_header)
seen_errors += check_plural (mlp, ignore_untranslated_messages,
- ignore_fuzzy_messages, &distribution);
+ ignore_fuzzy_messages, &distribution, xeh);
for (j = 0; j < mlp->nitems; j++)
{
check_format_strings,
&distribution,
check_header, check_compatibility,
- check_accelerators, accelerator_char);
+ check_accelerators, accelerator_char,
+ xeh);
}
return seen_errors;