]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Combine all msgfmt checks in a single place.
authorBruno Haible <bruno@clisp.org>
Sat, 15 Oct 2005 13:45:34 +0000 (13:45 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:12:54 +0000 (12:12 +0200)
Return the number of errors instead of relying on error_message_count.

gettext-tools/src/ChangeLog
gettext-tools/src/format.c
gettext-tools/src/format.h
gettext-tools/src/msgfmt.c
gettext-tools/src/msgl-check.c
gettext-tools/src/msgl-check.h
gettext-tools/tests/ChangeLog
gettext-tools/tests/msgfmt-10

index 50ea6bdd9fe19f7070e119995683e8b3cca8c88f..245cadeb3514463393e30e6d69698cce66b53522 100644 (file)
@@ -1,3 +1,18 @@
+2005-10-04  Bruno Haible  <bruno@clisp.org>
+
+       Combine all msgfmt checks in a single place.
+       * format.h (check_msgid_msgstr_format): Change return type to int.
+       * format.c (check_msgid_msgstr_format): Return the number of errors.
+       * msgl-check.h (check_plural): Remove declaration.
+       * msgl-check.c (check_plural): Make static. Return the number of
+       errors.
+       (check_pair): Return the number of errors.
+       (check_message_list): Likewise.
+       * msgfmt.c (main): Perform the message checks here, after all files
+       were read. Call check_message_list instead of check_plural and
+       check_message. Emit statistics of fatal errors.
+       (msgfmt_frob_new_message): Don't call check_message here.
+
 2005-10-04  Bruno Haible  <bruno@clisp.org>
 
        * msgl-check.h (check_message_list): New declaration.
index 6ebd367a620fd77091e8ec117f26355868fddacc..e232799ce690b0f9f8c82df31e89ca5ce992b44b 100644 (file)
@@ -58,14 +58,14 @@ struct formatstring_parser *formatstring_parsers[NFORMATS] =
 };
 
 /* Check whether both formats strings contain compatible format
-   specifications.  Return true if there is an error.  */
-bool
+   specifications.  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],
                           formatstring_error_logger_t error_logger)
 {
-  bool err = false;
+  int seen_errors = 0;
   size_t i;
   unsigned int j;
 
@@ -128,7 +128,7 @@ check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
                    if (parser->check (msgid_descr, msgstr_descr,
                                       strict_checking,
                                       error_logger, pretty_msgstr))
-                     err = true;
+                     seen_errors++;
 
                    parser->free (msgstr_descr);
                  }
@@ -138,7 +138,7 @@ check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
 '%s' is not a valid %s format string, unlike 'msgid'. Reason: %s"),
                                  pretty_msgstr, format_language_pretty[i],
                                  invalid_reason);
-                   err = true;
+                   seen_errors++;
                    free (invalid_reason);
                  }
              }
@@ -149,5 +149,5 @@ check_msgid_msgstr_format (const char *msgid, const char *msgid_plural,
          free (invalid_reason);
       }
 
-  return err;
+  return seen_errors;
 }
index 80a609a2feb3c5056694eaaba4ea4d44d6a77b46..872dc37acf36969dcb88837ec42f1b1cab2722e4 100644 (file)
@@ -107,8 +107,8 @@ extern void
                                 struct interval **intervalsp, size_t *lengthp);
 
 /* Check whether both formats strings contain compatible format
-   specifications.  Return true if there is an error.  */
-extern bool
+   specifications.  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],
index ef223a78fe12085140960c82095888f7de2d8be3..89c52d1b7d1f3b51d9a3f48d1842d3d3eb3bb906 100644 (file)
@@ -522,11 +522,27 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
   for (domain = domain_list; domain != NULL; domain = domain->next)
     message_list_remove_if_not (domain->mlp, is_nonobsolete);
 
-  /* Check the plural expression is present if needed and has valid syntax.  */
-  if (check_header)
+  /* Perform all kinds of checks: plural expressions, format strings, ...  */
+  {
+    int nerrors = 0;
+
     for (domain = domain_list; domain != NULL; domain = domain->next)
-      if (check_plural (domain->mlp))
+      nerrors +=
+       check_message_list (domain->mlp,
+                           1, check_format_strings, check_header,
+                           check_compatibility,
+                           check_accelerators, accelerator_char);
+
+    /* Exit with status 1 on any error.  */
+    if (nerrors > 0)
+      {
+       error (0, 0,
+              ngettext ("found %d fatal error", "found %d fatal errors",
+                        nerrors),
+              nerrors);
        exit_status = EXIT_FAILURE;
+      }
+  }
 
   /* Now write out all domains.  */
   for (domain = domain_list; domain != NULL; domain = domain->next)
@@ -987,12 +1003,6 @@ msgfmt_frob_new_message (default_po_reader_ty *that, message_ty *mp,
              ++msgs_fuzzy;
            else
              ++msgs_translated;
-
-         if (check_message (mp, msgid_pos,
-                            1, check_format_strings, check_header,
-                            check_compatibility,
-                            check_accelerators, accelerator_char))
-           exit_status = EXIT_FAILURE;
        }
     }
 }
index b7fa867e503a8b4a5080092b0285524082b8bab5..0a94c2425009f6093ce2e39ee4d7a433bf2a249e 100644 (file)
@@ -228,11 +228,11 @@ plural_help (const char *nullentry)
 
 
 /* Perform plural expression checking.
-   Return nonzero if an error was seen.  */
-int
+   Return the number of errors that were seen.  */
+static int
 check_plural (message_list_ty *mlp)
 {
-  int seen_error = 0;
+  int seen_errors = 0;
   const message_ty *has_plural;
   unsigned long min_nplurals;
   const message_ty *min_pos;
@@ -313,7 +313,7 @@ check_plural (message_list_ty *mlp)
                        has_plural, NULL, 0, 0, false, msg1,
                        header, NULL, 0, 0, false, msg2);
 
-         seen_error = 1;
+         seen_errors++;
        }
       if (nplurals == NULL && has_plural != NULL)
        {
@@ -337,7 +337,7 @@ check_plural (message_list_ty *mlp)
                        has_plural, NULL, 0, 0, false, msg1,
                        header, NULL, 0, 0, false, msg2);
 
-         seen_error = 1;
+         seen_errors++;
        }
       if (plural != NULL && nplurals != NULL)
        {
@@ -370,7 +370,7 @@ check_plural (message_list_ty *mlp)
              else
                po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg);
 
-             seen_error = 1;
+             seen_errors++;
            }
 
          /* Then check the expression.  */
@@ -392,16 +392,16 @@ check_plural (message_list_ty *mlp)
              else
                po_xerror (PO_SEVERITY_ERROR, header, NULL, 0, 0, false, msg);
 
-             seen_error = 1;
+             seen_errors++;
            }
          plural_expr = args.res;
 
          /* See whether nplurals and plural fit together.  */
-         if (!seen_error)
-           seen_error = check_plural_eval (plural_expr, nplurals_value, header);
+         if (!seen_errors)
+           seen_errors = check_plural_eval (plural_expr, nplurals_value, header);
 
          /* Check the number of plurals of the translations.  */
-         if (!seen_error)
+         if (!seen_errors)
            {
              if (min_nplurals < nplurals_value)
                {
@@ -417,7 +417,7 @@ check_plural (message_list_ty *mlp)
                              min_pos, NULL, 0, 0, false, msg2);
                  free (msg2);
                  free (msg1);
-                 seen_error = 1;
+                 seen_errors++;
                }
              else if (max_nplurals > nplurals_value)
                {
@@ -433,7 +433,7 @@ check_plural (message_list_ty *mlp)
                              max_pos, NULL, 0, 0, false, msg2);
                  free (msg2);
                  free (msg1);
-                 seen_error = 1;
+                 seen_errors++;
                }
              /* The only valid case is max_nplurals <= n <= min_nplurals,
                 which means either has_plural == NULL or
@@ -445,10 +445,10 @@ check_plural (message_list_ty *mlp)
     {
       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;\""));
-      seen_error = 1;
+      seen_errors++;
     }
 
-  return seen_error;
+  return seen_errors;
 }
 
 
@@ -485,7 +485,7 @@ check_pair (const message_ty *mp,
            int check_compatibility,
            int check_accelerators, char accelerator_char)
 {
-  int seen_error;
+  int seen_errors;
   int has_newline;
   unsigned int j;
   const char *p;
@@ -495,7 +495,7 @@ check_pair (const message_ty *mp,
   if (msgid[0] == '\0')
     return 0;
 
-  seen_error = 0;
+  seen_errors = 0;
 
   if (check_newlines)
     {
@@ -510,7 +510,7 @@ check_pair (const message_ty *mp,
                         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_error = 1;
+             seen_errors++;
            }
          for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
            if (TEST_NEWLINE(p) != has_newline)
@@ -522,7 +522,7 @@ check_pair (const message_ty *mp,
                           mp, msgid_pos->file_name, msgid_pos->line_number,
                           (size_t)(-1), false, msg);
                free (msg);
-               seen_error = 1;
+               seen_errors++;
              }
        }
       else
@@ -533,7 +533,7 @@ check_pair (const message_ty *mp,
                         mp, msgid_pos->file_name, msgid_pos->line_number,
                         (size_t)(-1), false, _("\
 `msgid' and `msgstr' entries do not both begin with '\\n'"));
-             seen_error = 1;
+             seen_errors++;
            }
        }
 #undef TEST_NEWLINE
@@ -549,7 +549,7 @@ check_pair (const message_ty *mp,
                         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_error = 1;
+             seen_errors++;
            }
          for (p = msgstr, j = 0; p < msgstr + msgstr_len; p += strlen (p) + 1, j++)
            if (TEST_NEWLINE(p) != has_newline)
@@ -561,7 +561,7 @@ check_pair (const message_ty *mp,
                           mp, msgid_pos->file_name, msgid_pos->line_number,
                           (size_t)(-1), false, msg);
                free (msg);
-               seen_error = 1;
+               seen_errors++;
              }
        }
       else
@@ -572,7 +572,7 @@ check_pair (const message_ty *mp,
                         mp, msgid_pos->file_name, msgid_pos->line_number,
                         (size_t)(-1), false, _("\
 `msgid' and `msgstr' entries do not both end with '\\n'"));
-             seen_error = 1;
+             seen_errors++;
            }
        }
 #undef TEST_NEWLINE
@@ -584,7 +584,7 @@ check_pair (const message_ty *mp,
                 mp, msgid_pos->file_name, msgid_pos->line_number,
                 (size_t)(-1), false, _("\
 plural handling is a GNU gettext extension"));
-      seen_error = 1;
+      seen_errors++;
     }
 
   if (check_format_strings)
@@ -593,9 +593,9 @@ plural handling is a GNU gettext extension"));
     {
       curr_mp = mp;
       curr_msgid_pos = *msgid_pos;
-      if (check_msgid_msgstr_format (msgid, msgid_plural, msgstr, msgstr_len,
-                                    is_format, formatstring_error_logger))
-       seen_error = 1;
+      seen_errors +=
+       check_msgid_msgstr_format (msgid, msgid_plural, msgstr, msgstr_len,
+                                  is_format, formatstring_error_logger);
     }
 
   if (check_accelerators && msgid_plural == NULL)
@@ -643,7 +643,7 @@ plural handling is a GNU gettext extension"));
        }
     }
 
-  return seen_error;
+  return seen_errors;
 }
 
 
@@ -717,7 +717,7 @@ some header fields still have the initial default value\n"));
 
 
 /* Perform all checks on a non-obsolete message.
-   Return nonzero if an error was seen.  */
+   Return the number of errors that were seen.  */
 int
 check_message (const message_ty *mp,
               const lex_pos_ty *msgid_pos,
@@ -740,7 +740,7 @@ check_message (const message_ty *mp,
 
 
 /* Perform all checks on a message list.
-   Return nonzero if an error was seen.  */
+   Return the number of errors that were seen.  */
 int
 check_message_list (message_list_ty *mlp,
                    int check_newlines,
@@ -749,24 +749,22 @@ check_message_list (message_list_ty *mlp,
                    int check_compatibility,
                    int check_accelerators, char accelerator_char)
 {
-  int seen_error = 0;
+  int seen_errors = 0;
   size_t j;
 
   if (check_header)
-    if (check_plural (mlp))
-      seen_error = 1;
+    seen_errors += check_plural (mlp);
 
   for (j = 0; j < mlp->nitems; j++)
     {
       message_ty *mp = mlp->item[j];
 
       if (!mp->obsolete)
-       if (check_message (mp, &mp->pos,
-                          check_newlines, check_format_strings,
-                          check_header, check_compatibility,
-                          check_accelerators, accelerator_char))
-         seen_error = 1;
+       seen_errors += check_message (mp, &mp->pos,
+                                     check_newlines, check_format_strings,
+                                     check_header, check_compatibility,
+                                     check_accelerators, accelerator_char);
     }
 
-  return seen_error;
+  return seen_errors;
 }
index 186c732416a037d2f35fd7596f755e02c4eba08d..612d33c77817ecdbe06d480aef643ae87cda244e 100644 (file)
@@ -28,12 +28,8 @@ extern "C" {
 #endif
 
 
-/* Perform plural expression checking.
-   Return nonzero if an error was seen.  */
-extern int check_plural (message_list_ty *mlp);
-
 /* Perform all checks on a non-obsolete message.
-   Return nonzero if an error was seen.  */
+   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,
@@ -43,7 +39,7 @@ extern int check_message (const message_ty *mp,
                          int check_accelerators, char accelerator_char);
 
 /* Perform all checks on a message list.
-   Return nonzero if an error was seen.  */
+   Return the number of errors that were seen.  */
 extern int check_message_list (message_list_ty *mlp,
                               int check_newlines,
                               int check_format_strings,
index 647470a1cec5dff34b235ccc95fbdb4444c9e93b..b2b0d6350715546d5b12872eb38a7efd30a7d9c4 100644 (file)
@@ -1,3 +1,7 @@
+2005-10-04  Bruno Haible  <bruno@clisp.org>
+
+       * msgfmt-10: Change expected error message, to match new line numbers.
+
 2005-10-03  Bruno Haible  <bruno@clisp.org>
 
        Add support for contexts in xgettext.
index fad6c17c59c7ade4afec5e73de5e008e83c5f610..d95c7ca37e23fdbd2a7b942f4ca19924981683f5 100755 (executable)
@@ -74,7 +74,7 @@ ${MSGFMT} --check mf-test10.po2 -o /dev/null \
 
 tmpfiles="$tmpfiles mf-test10.ok"
 cat << EOF > mf-test10.ok
-mf-test10.po2:18: number of format specifications in 'msgid' and 'msgstr[1]' does not match
+mf-test10.po2:20: number of format specifications in 'msgid' and 'msgstr[1]' does not match
 msgfmt: found 1 fatal error
 EOF