From: Bruno Haible Date: Sat, 15 Oct 2005 13:45:34 +0000 (+0000) Subject: Combine all msgfmt checks in a single place. X-Git-Tag: v0.15~364 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ef7029af76dea73d697e878274b90e83a524b70d;p=thirdparty%2Fgettext.git Combine all msgfmt checks in a single place. Return the number of errors instead of relying on error_message_count. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 50ea6bdd9..245cadeb3 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,18 @@ +2005-10-04 Bruno Haible + + 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 * msgl-check.h (check_message_list): New declaration. diff --git a/gettext-tools/src/format.c b/gettext-tools/src/format.c index 6ebd367a6..e232799ce 100644 --- a/gettext-tools/src/format.c +++ b/gettext-tools/src/format.c @@ -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; } diff --git a/gettext-tools/src/format.h b/gettext-tools/src/format.h index 80a609a2f..872dc37ac 100644 --- a/gettext-tools/src/format.h +++ b/gettext-tools/src/format.h @@ -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], diff --git a/gettext-tools/src/msgfmt.c b/gettext-tools/src/msgfmt.c index ef223a78f..89c52d1b7 100644 --- a/gettext-tools/src/msgfmt.c +++ b/gettext-tools/src/msgfmt.c @@ -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; } } } diff --git a/gettext-tools/src/msgl-check.c b/gettext-tools/src/msgl-check.c index b7fa867e5..0a94c2425 100644 --- a/gettext-tools/src/msgl-check.c +++ b/gettext-tools/src/msgl-check.c @@ -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; } diff --git a/gettext-tools/src/msgl-check.h b/gettext-tools/src/msgl-check.h index 186c73241..612d33c77 100644 --- a/gettext-tools/src/msgl-check.h +++ b/gettext-tools/src/msgl-check.h @@ -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, diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 647470a1c..b2b0d6350 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,7 @@ +2005-10-04 Bruno Haible + + * msgfmt-10: Change expected error message, to match new line numbers. + 2005-10-03 Bruno Haible Add support for contexts in xgettext. diff --git a/gettext-tools/tests/msgfmt-10 b/gettext-tools/tests/msgfmt-10 index fad6c17c5..d95c7ca37 100755 --- a/gettext-tools/tests/msgfmt-10 +++ b/gettext-tools/tests/msgfmt-10 @@ -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