]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Add a plural_distribution_length argument.
authorBruno Haible <bruno@clisp.org>
Sat, 20 Oct 2007 19:55:50 +0000 (19:55 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:20 +0000 (12:15 +0200)
gettext-tools/libgettextpo/ChangeLog
gettext-tools/libgettextpo/gettext-po.c
gettext-tools/src/ChangeLog
gettext-tools/src/format.c
gettext-tools/src/format.h
gettext-tools/src/msgl-check.c
gettext-tools/src/msgl-check.h

index 52cfde2ac191af5234badaeafe297af038103a59..381b99be3e9ebd41395892a655ad177312fe4399 100644 (file)
@@ -1,3 +1,8 @@
+2007-10-20  Bruno Haible  <bruno@clisp.org>
+
+       * gettext-po.c (po_message_check_format): Update call to check_message,
+       check_msgid_msgstr_format.
+
 2007-10-07  Bruno Haible  <bruno@clisp.org>
 
        * libgettextpo.rc (Comments): Update.
index 0125d5a1ae1cf796c526ec6e13c6d928b25a4acc..a4ca30088cc57fa0fe2f729ce8ae0284fe56449e 100644 (file)
@@ -1219,7 +1219,7 @@ po_message_check_format (po_message_t message, po_xerror_handler_t handler)
     handler->xerror2;
 
   if (!mp->obsolete)
-    check_message (mp, &mp->pos, 0, 1, NULL, 0, 0, 0, 0);
+    check_message (mp, &mp->pos, 0, 1, NULL, 0, 0, 0, 0, 0);
 
   /* Restore error handler.  */
   po_xerror  = textmode_xerror;
@@ -1263,7 +1263,7 @@ po_message_check_format (po_message_t message, po_error_handler_t handler)
 
   check_msgid_msgstr_format (mp->msgid, mp->msgid_plural,
                             mp->msgstr, mp->msgstr_len,
-                            mp->is_format, NULL, po_error_logger);
+                            mp->is_format, NULL, 0, po_error_logger);
 
   /* Restore error handler.  */
   po_error = error;
index e94ba3e5cdf7557fcbedcb653fbc0047bfff2d05..538d5dd8a0d0b978c23ca968b06b450b07b4898a 100644 (file)
@@ -1,3 +1,13 @@
+2007-10-20  Bruno Haible  <bruno@clisp.org>
+
+       * format.h (check_msgid_msgstr_format): Add plural_distribution_length
+       argument.
+       * format.c (check_msgid_msgstr_format): Likewise.
+       * msgl-check.h (check_message): Likewise.
+       * msgl-check.c (check_plural_eval, check_plural, check_pair,
+       check_message): Likewise.
+       (check_message_list): Update.
+
 2007-10-18  Bruno Haible  <bruno@clisp.org>
 
        * plural-count.c (get_plural_count): Adapt to changed prototype of
index 0ac665464e635e7dd55f0acc9ad7e9894e5760d7..f85fa146d0a6cabeea5d21ace683297463c733f8 100644 (file)
@@ -63,12 +63,14 @@ struct formatstring_parser *formatstring_parsers[NFORMATS] =
    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;
@@ -135,7 +137,9 @@ check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
                    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,
index 718482a256594c258df34256d11dadeeb5b449b3..df5d37e35205caa48f7f216643031a424bef18c3 100644 (file)
@@ -143,12 +143,14 @@ extern unsigned int get_python_format_unnamed_arg_count (const char *string);
    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_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);
 
 
index ca1c277507ba6b0ed9d45bde6b49041a62d2ba5c..0baee307fe43d41c8d1e408f2dbc0f6501ae142f 100644 (file)
    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.  */
@@ -118,7 +120,10 @@ check_plural_eval (struct expression *plural_expr,
 
          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;
@@ -196,9 +201,12 @@ plural_help (const char *nullentry)
 /* 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;
@@ -209,6 +217,7 @@ check_plural (message_list_ty *mlp, unsigned char **plural_distribution)
   size_t j;
   message_ty *header;
   unsigned char *distribution = NULL;
+  unsigned long distribution_length = 0;
 
   /* Determine whether mlp has plural entries.  */
   has_plural = NULL;
@@ -369,7 +378,7 @@ check_plural (message_list_ty *mlp, unsigned char **plural_distribution)
          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)
@@ -427,8 +436,10 @@ check_plural (message_list_ty *mlp, unsigned char **plural_distribution)
     {
       free (distribution);
       distribution = NULL;
+      distribution_length = 0;
     }
   *plural_distribution = distribution;
+  *plural_distribution_length = distribution_length;
 
   return seen_errors;
 }
@@ -460,7 +471,9 @@ formatstring_error_logger (const char *format, ...)
 /* 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,
@@ -469,7 +482,9 @@ check_pair (const message_ty *mp,
            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)
 {
@@ -587,6 +602,7 @@ plural handling is a GNU gettext extension"));
       seen_errors +=
        check_msgid_msgstr_format (msgid, msgid_plural, msgstr, msgstr_len,
                                   is_format, plural_distribution,
+                                  plural_distribution_length,
                                   formatstring_error_logger);
     }
 
@@ -712,12 +728,15 @@ some header fields still have the initial default value\n"));
    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)
@@ -730,7 +749,8 @@ check_message (const message_ty *mp,
                     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);
 }
@@ -748,10 +768,12 @@ check_message_list (message_list_ty *mlp,
 {
   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++)
     {
@@ -760,7 +782,9 @@ check_message_list (message_list_ty *mlp,
       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);
     }
index 5945d33628e9baa6d5fd4397a0d098dd6bb20c90..2c5e4ab93816c14a45c34e06d318933a4156279e 100644 (file)
@@ -1,5 +1,5 @@
 /* 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
@@ -31,11 +31,14 @@ extern "C" {
    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);