PLURAL_DISTRIBUTION is either NULL or an array of nplurals elements,
PLURAL_DISTRIBUTION[j] being true if the value j appears to be assumed
infinitely often by the plural formula.
+ PLURAL_DISTRIBUTION_LENGTH is the length of the PLURAL_DISTRIBUTION array.
Return the number of errors that were seen. */
int
check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
const char *msgstr, size_t msgstr_len,
const enum is_format is_format[NFORMATS],
const unsigned char *plural_distribution,
+ unsigned long plural_distribution_length,
formatstring_error_logger_t error_logger)
{
int seen_errors = 0;
bool strict_checking =
(msgid_plural == NULL
|| !has_plural_translations
- || (plural_distribution != NULL && plural_distribution[j]));
+ || (plural_distribution != NULL
+ && j < plural_distribution_length
+ && plural_distribution[j]));
if (parser->check (msgid_descr, msgstr_descr,
strict_checking,
Return the number of errors that were seen.
If no errors, returns in *PLURAL_DISTRIBUTION either NULL or an array
of length NPLURALS_VALUE describing which plural formula values appear
- infinitely often. */
+ infinitely often and in *PLURAL_DISTRIBUTION_LENGTH the length of this
+ array. */
static int
check_plural_eval (struct expression *plural_expr,
unsigned long nplurals_value,
const message_ty *header,
- unsigned char **plural_distribution)
+ unsigned char **plural_distribution,
+ unsigned long *plural_distribution_length)
{
/* Do as if the plural formula assumes a value N infinitely often if it
assumes it at least 5 times. */
for (val = 0; val < nplurals_value; val++)
distribution[val] = (distribution[val] == OFTEN ? 1 : 0);
+ *plural_distribution_length = nplurals_value;
}
+ else
+ *plural_distribution_length = 0;
*plural_distribution = distribution;
return 0;
/* Perform plural expression checking.
Return the number of errors that were seen.
If no errors, returns in *PLURAL_DISTRIBUTION either NULL or an array
- describing which plural formula values appear infinitely often. */
+ describing which plural formula values appear infinitely often and in
+ *PLURAL_DISTRIBUTION_LENGTH the length of this array. */
static int
-check_plural (message_list_ty *mlp, unsigned char **plural_distribution)
+check_plural (message_list_ty *mlp,
+ unsigned char **plural_distribution,
+ unsigned long *plural_distribution_length)
{
int seen_errors = 0;
const message_ty *has_plural;
size_t j;
message_ty *header;
unsigned char *distribution = NULL;
+ unsigned long distribution_length = 0;
/* Determine whether mlp has plural entries. */
has_plural = NULL;
if (!seen_errors)
seen_errors =
check_plural_eval (plural_expr, nplurals_value, header,
- &distribution);
+ &distribution, &distribution_length);
/* Check the number of plurals of the translations. */
if (!seen_errors)
{
free (distribution);
distribution = NULL;
+ distribution_length = 0;
}
*plural_distribution = distribution;
+ *plural_distribution_length = distribution_length;
return seen_errors;
}
/* Perform miscellaneous checks on a message.
PLURAL_DISTRIBUTION is either NULL or an array of nplurals elements,
PLURAL_DISTRIBUTION[j] being true if the value j appears to be assumed
- infinitely often by the plural formula. */
+ infinitely often by the plural formula.
+ PLURAL_DISTRIBUTION_LENGTH is the length of the PLURAL_DISTRIBUTION
+ array. */
static int
check_pair (const message_ty *mp,
const char *msgid,
const char *msgstr, size_t msgstr_len,
const enum is_format is_format[NFORMATS],
int check_newlines,
- int check_format_strings, const unsigned char *plural_distribution,
+ int check_format_strings,
+ const unsigned char *plural_distribution,
+ unsigned long plural_distribution_length,
int check_compatibility,
int check_accelerators, char accelerator_char)
{
seen_errors +=
check_msgid_msgstr_format (msgid, msgid_plural, msgstr, msgstr_len,
is_format, plural_distribution,
+ plural_distribution_length,
formatstring_error_logger);
}
PLURAL_DISTRIBUTION is either NULL or an array of nplurals elements,
PLURAL_DISTRIBUTION[j] being true if the value j appears to be assumed
infinitely often by the plural formula.
+ PLURAL_DISTRIBUTION_LENGTH is the length of the PLURAL_DISTRIBUTION array.
Return the number of errors that were seen. */
int
check_message (const message_ty *mp,
const lex_pos_ty *msgid_pos,
int check_newlines,
- int check_format_strings, const unsigned char *plural_distribution,
+ int check_format_strings,
+ const unsigned char *plural_distribution,
+ unsigned long plural_distribution_length,
int check_header,
int check_compatibility,
int check_accelerators, char accelerator_char)
mp->msgstr, mp->msgstr_len,
mp->is_format,
check_newlines,
- check_format_strings, plural_distribution,
+ check_format_strings,
+ plural_distribution, plural_distribution_length,
check_compatibility,
check_accelerators, accelerator_char);
}
{
int seen_errors = 0;
unsigned char *plural_distribution = NULL;
+ unsigned long plural_distribution_length = 0;
size_t j;
if (check_header)
- seen_errors += check_plural (mlp, &plural_distribution);
+ seen_errors +=
+ check_plural (mlp, &plural_distribution, &plural_distribution_length);
for (j = 0; j < mlp->nitems; j++)
{
if (!mp->obsolete)
seen_errors += check_message (mp, &mp->pos,
check_newlines,
- check_format_strings, plural_distribution,
+ check_format_strings,
+ plural_distribution,
+ plural_distribution_length,
check_header, check_compatibility,
check_accelerators, accelerator_char);
}
/* Checking of messages in PO files.
- Copyright (C) 2005 Free Software Foundation, Inc.
+ Copyright (C) 2005, 2007 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2005.
This program is free software: you can redistribute it and/or modify
PLURAL_DISTRIBUTION is either NULL or an array of nplurals elements,
PLURAL_DISTRIBUTION[j] being true if the value j appears to be assumed
infinitely often by the plural formula.
+ PLURAL_DISTRIBUTION_LENGTH is the length of the PLURAL_DISTRIBUTION array.
Return the number of errors that were seen. */
extern int check_message (const message_ty *mp,
const lex_pos_ty *msgid_pos,
int check_newlines,
- int check_format_strings, const unsigned char *plural_distribution,
+ int check_format_strings,
+ const unsigned char *plural_distribution,
+ unsigned long plural_distribution_length,
int check_header,
int check_compatibility,
int check_accelerators, char accelerator_char);