From: Bruno Haible Date: Fri, 31 Aug 2001 18:38:34 +0000 (+0000) Subject: Reorganize msgfmt checking options. X-Git-Tag: v0.11~528 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7f1c0c38648b452c17a69ed23227a2a7e6841ba;p=thirdparty%2Fgettext.git Reorganize msgfmt checking options. --- diff --git a/po/ChangeLog b/po/ChangeLog index 9bedf7f73..8a29d8ad9 100644 --- a/po/ChangeLog +++ b/po/ChangeLog @@ -1,3 +1,8 @@ +2001-08-30 Bruno Haible + + * Makefile.in.in (.po.mo, .po.gmo): Add msgfmt option -c, to guarantee + the PO file is really valid. + 2001-08-31 Bruno Haible * da.po: Update from Keld Simonsen . diff --git a/po/Makefile.in.in b/po/Makefile.in.in index bf3998380..a1943c523 100644 --- a/po/Makefile.in.in +++ b/po/Makefile.in.in @@ -55,11 +55,11 @@ CATALOGS = @CATALOGS@ $(MSGMERGE) $< $(srcdir)/$(PACKAGE).pot -o $*.pox .po.mo: - $(MSGFMT) -o $@ $< + $(MSGFMT) -c -o $@ $< .po.gmo: file=$(srcdir)/`echo $* | sed 's,.*/,,'`.gmo \ - && rm -f $$file && $(GMSGFMT) --statistics -o $$file $< + && rm -f $$file && $(GMSGFMT) -c --statistics -o $$file $< all: all-@USE_NLS@ diff --git a/src/ChangeLog b/src/ChangeLog index 4cc15711d..dccec66fd 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2001-08-30 Bruno Haible + + Reorganize msgfmt checking options. + * msgfmt.c: Include limits.h. + (verbose): Renamed from verbose_level. + (check_format_strings): Renamed from do_check. + (check_header, check_domain, check_compatibility): New variables. + (long_options): Add --check-domain, --check-format, --check-header, + --check-compatibility. + (main): Recognize options -C, --check-compatibility, --check-domain, + --check-format, --check-header. Option -c implies the last three. + (usage): Update. + (format_debrief): Test check_header, not verbose_level. + (format_directive_domain): Test check_domain, not verbose_level. + (format_directive_message): Test check_compatibility and check_header, + not verbose_level. Always perform the check for duplicates. + (format_comment_special): Test check_compatibility, not verbose_level. + (check_pair): Error if check_compatibility is true an msgid_plural is + used. + 2001-08-26 Bruno Haible * format.h: New file. diff --git a/src/msgfmt.c b/src/msgfmt.c index e11dbf8e3..ae66fb016 100644 --- a/src/msgfmt.c +++ b/src/msgfmt.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -120,12 +121,25 @@ struct msg_domain static struct msg_domain *domain_list; static struct msg_domain *current_domain; -/* If not zero list duplicate message identifiers. */ -static int verbose_level; +/* Be more verbose. Use only 'fprintf' and 'multiline_warning' but not + 'error' or 'multiline_error' to emit verbosity messages, because 'error' + and 'multiline_error' during PO file parsing cause the program to exit + with EXIT_FAILURE. See function lex_end(). */ +static bool verbose = false; /* If true check strings according to format string rules for the language. */ -static bool do_check = false; +static bool check_format_strings = false; + +/* If true check the header entry is present and complete. */ +static bool check_header = false; + +/* Check that domain directives can be satisfied. */ +static bool check_domain = false; + +/* Check that msgfmt's behaviour is semantically compatible with + X/Open msgfmt or XView msgfmt. */ +static bool check_compatibility = false; /* Counters for statistics on translations for the processed files. */ static int msgs_translated; @@ -140,6 +154,10 @@ static const struct option long_options[] = { { "alignment", required_argument, NULL, 'a' }, { "check", no_argument, NULL, 'c' }, + { "check-compatibility", no_argument, NULL, 'C' }, + { "check-domain", no_argument, NULL, CHAR_MAX + 1 }, + { "check-format", no_argument, NULL, CHAR_MAX + 2 }, + { "check-header", no_argument, NULL, CHAR_MAX + 3 }, { "directory", required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "no-hash", no_argument, &no_hash_table, 1 }, @@ -221,7 +239,7 @@ main (argc, argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); - while ((opt = getopt_long (argc, argv, "a:cD:fho:vV", long_options, NULL)) + while ((opt = getopt_long (argc, argv, "a:cCD:fho:vV", long_options, NULL)) != EOF) switch (opt) { @@ -237,7 +255,12 @@ main (argc, argv) } break; case 'c': - do_check = true; + check_domain = true; + check_format_strings = true; + check_header = true; + break; + case 'C': + check_compatibility = true; break; case 'D': dir_list_append (optarg); @@ -255,11 +278,20 @@ main (argc, argv) strict_uniforum = true; break; case 'v': - ++verbose_level; + verbose = true; break; case 'V': do_version = true; break; + case CHAR_MAX + 1: + check_domain = true; + break; + case CHAR_MAX + 2: + check_format_strings = true; + break; + case CHAR_MAX + 3: + check_header = true; + break; default: usage (EXIT_FAILURE); break; @@ -352,7 +384,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\ } /* Print statistics if requested. */ - if (verbose_level > 0 || do_statistics) + if (verbose || do_statistics) { fprintf (stderr, ngettext ("%d translated message", "%d translated messages", @@ -420,7 +452,13 @@ If output file is -, output is written to standard output.\n\ /* xgettext: no-wrap */ printf (_("\ Input file interpretation:\n\ - -c, --check perform language dependent checks on strings\n\ + -c, --check perform all the checks implied by\n\ + --check-format, --check-header, --check-domain\n\ + --check-format check language dependent format strings\n\ + --check-header verify presence and contents of the header entry\n\ + --check-domain check for conflicts between domain directives\n\ + and the --output-file option\n\ + -C, --check-compatibility check that GNU msgfmt behaves like X/Open msgfmt\n\ -f, --use-fuzzy use fuzzy entries in output\n\ ")); printf ("\n"); @@ -437,8 +475,7 @@ Informative output:\n\ -h, --help display this help and exit\n\ -V, --version output version information and exit\n\ --statistics print statistics about translations\n\ - -v, --verbose list input file anomalies\n\ -Giving the -v option more than once increases the verbosity level.\n\ + -v, --verbose increase verbosity level\n\ ")); printf ("\n"); fputs (_("Report bugs to .\n"), stdout); @@ -498,10 +535,8 @@ format_debrief (that) { msgfmt_class_ty *this = (msgfmt_class_ty *) that; - /* Test whether header entry was found. - FIXME: Should do this even if not in verbose mode, because the - consequences are not harmless. But it breaks the test suite. */ - if (verbose_level > 0 && !this->has_header_entry) + /* Test whether header entry was found. */ + if (check_header && !this->has_header_entry) { multiline_error (xasprintf ("%s: ", gram_pos.file_name), xasprintf (_("\ @@ -546,9 +581,7 @@ domain name \"%s\" not suitable as file name: will use prefix"), name); } else { - if (verbose_level > 0) - /* We don't change the exit status here because this is really - only an information. */ + if (check_domain) error (0, 0, _("`domain %s' directive ignored"), name); /* NAME was allocated in po-gram.y but is not used anywhere. */ @@ -579,10 +612,8 @@ format_directive_message (that, msgid_string, msgid_pos, msgid_plural, if (msgstr_string[0] == '\0' || (!include_all && this->is_fuzzy && msgid_string[0] != '\0')) { - if (verbose_level > 1) + if (check_compatibility) { - /* We don't change the exit status here because this is really - only an information. */ error_with_progname = false; error_at_line (0, 0, msgstr_pos->file_name, msgstr_pos->line_number, (msgstr_string[0] == '\0' @@ -608,7 +639,7 @@ format_directive_message (that, msgid_string, msgid_pos, msgid_plural, this->has_header_entry = true; /* Do some more tests on test contents of the header entry. */ - if (verbose_level > 0) + if (check_header) { static const char *required_fields[] = { @@ -694,25 +725,19 @@ some header fields still have the initial default value")); /* We don't need the just constructed entry. */ free (entry); - if (verbose_level > 0) + /* We give a fatal error about this, regardless whether the + translations are equal or different. This is for consistency + with msgmerge, msgcat and others. The user can use the + msguniq program to get rid of duplicates. */ + find_entry (¤t_domain->symbol_tab, msgid_string, + strlen (msgid_string) + 1, (void **) &entry); + if (msgstr_len != entry->msgstr_len + || memcmp (msgstr_string, entry->msgstr, msgstr_len) != 0) { - /* We give a fatal error about this, but only if the - translations are different. Tell the user the old - definition for reference. */ - find_entry (¤t_domain->symbol_tab, msgid_string, - strlen (msgid_string) + 1, (void **) &entry); - if (msgstr_len != entry->msgstr_len - || memcmp (msgstr_string, entry->msgstr, msgstr_len) != 0) - { - po_gram_error_at_line (msgid_pos, _("\ + po_gram_error_at_line (msgid_pos, _("\ duplicate message definition")); - po_gram_error_at_line (&entry->pos, _("\ + po_gram_error_at_line (&entry->pos, _("\ ...this is the location of the first definition")); - - /* FIXME Should this be always a reason for an - exit status != 0? */ - exit_status = EXIT_FAILURE; - } } /* We don't need the just constructed entries' @@ -747,7 +772,7 @@ format_comment_special (that, s) { static bool warned = false; - if (!include_all && verbose_level > 1 && !warned) + if (!include_all && check_compatibility && !warned) { warned = true; error (0, 0, _("\ @@ -1039,7 +1064,16 @@ check_pair (msgid, msgid_pos, msgid_plural, msgstr, msgstr_len, msgstr_pos, } #undef TEST_NEWLINE - if (do_check && msgid_plural == NULL) + if (check_compatibility && msgid_plural != NULL) + { + error_with_progname = false; + error_at_line (0, 0, msgid_pos->file_name, msgid_pos->line_number, + _("plural handling is a GNU gettext extension")); + error_with_progname = true; + exit_status = EXIT_FAILURE; + } + + if (check_format_strings && msgid_plural == NULL) /* Test 3: Check whether both formats strings contain the same number of format specifications. We check only those messages for which the msgid's is_format flag diff --git a/tests/ChangeLog b/tests/ChangeLog index 84866420f..4191e5bf0 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,17 @@ +2001-08-30 Bruno Haible + + * Makefile.am (TESTS_ENVIRONMENT): Define MSGCAT environment variable. + * format-c-2: Use --check-format, not -c, because the test snippets + don't have a header entry. + * format-java-2: Likewise. + * format-lisp-2: Likewise. + * format-python-2: Likewise. + * format-ycp-2: Likewise. + * msgcomm-16: Add ycp-format to expected output. + * msgfmt-1: Use msgcat --use-first to pass msgfmt's duplicate checking. + * msgfmt-2: Likewise. + * xg-test1.ok.po: Update. + 2001-08-26 Bruno Haible * format-c-1: New file. diff --git a/tests/Makefile.am b/tests/Makefile.am index 66e36781f..91ae8a94c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -48,8 +48,9 @@ TESTS_ENVIRONMENT = top_srcdir=$(top_srcdir) PATH=.:../src:$$PATH \ GETTEXT=tstgettext \ NGETTEXT=tstngettext \ XGETTEXT=`echo xgettext|sed '$(transform)'` \ - MSGFMT=`echo msgfmt|sed '$(transform)'` \ + MSGCAT=`echo msgcat|sed '$(transform)'` \ MSGCMP=`echo msgcmp|sed '$(transform)'` \ + MSGFMT=`echo msgfmt|sed '$(transform)'` \ MSGMERGE=`echo msgmerge|sed '$(transform)'` \ MSGUNFMT=`echo msgunfmt|sed '$(transform)'` \ MSGCAT=`echo msgcat|sed '$(transform)'` \ diff --git a/tests/format-c-2 b/tests/format-c-2 index 697a2ea20..21ec40ba6 100755 --- a/tests/format-c-2 +++ b/tests/format-c-2 @@ -161,13 +161,13 @@ ${msgstr_line} EOF fail= if echo "$comment" | grep 'Valid:' > /dev/null; then - if ${MSGFMT} -c -o f-c-2-$n.mo f-c-2-$n.po; then + if ${MSGFMT} --check-format -o f-c-2-$n.mo f-c-2-$n.po; then : else fail=yes fi else - ${MSGFMT} -c -o f-c-2-$n.mo f-c-2-$n.po 2> /dev/null + ${MSGFMT} --check-format -o f-c-2-$n.mo f-c-2-$n.po 2> /dev/null if test $? = 1; then : else diff --git a/tests/format-java-2 b/tests/format-java-2 index 3248321e3..0058501f6 100755 --- a/tests/format-java-2 +++ b/tests/format-java-2 @@ -122,13 +122,13 @@ ${msgstr_line} EOF fail= if echo "$comment" | grep 'Valid:' > /dev/null; then - if ${MSGFMT} -c -o f-j-2-$n.mo f-j-2-$n.po; then + if ${MSGFMT} --check-format -o f-j-2-$n.mo f-j-2-$n.po; then : else fail=yes fi else - ${MSGFMT} -c -o f-j-2-$n.mo f-j-2-$n.po 2> /dev/null + ${MSGFMT} --check-format -o f-j-2-$n.mo f-j-2-$n.po 2> /dev/null if test $? = 1; then : else diff --git a/tests/format-lisp-2 b/tests/format-lisp-2 index 64514cd47..f89bacfd8 100755 --- a/tests/format-lisp-2 +++ b/tests/format-lisp-2 @@ -179,13 +179,13 @@ ${msgstr_line} EOF fail= if echo "$comment" | grep 'Valid:' > /dev/null; then - if ${MSGFMT} -c -o f-l-2-$n.mo f-l-2-$n.po; then + if ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po; then : else fail=yes fi else - ${MSGFMT} -c -o f-l-2-$n.mo f-l-2-$n.po 2> /dev/null + ${MSGFMT} --check-format -o f-l-2-$n.mo f-l-2-$n.po 2> /dev/null if test $? = 1; then : else diff --git a/tests/format-python-2 b/tests/format-python-2 index 81b33ac0b..634239483 100755 --- a/tests/format-python-2 +++ b/tests/format-python-2 @@ -116,13 +116,13 @@ ${msgstr_line} EOF fail= if echo "$comment" | grep 'Valid:' > /dev/null; then - if ${MSGFMT} -c -o f-p-2-$n.mo f-p-2-$n.po; then + if ${MSGFMT} --check-format -o f-p-2-$n.mo f-p-2-$n.po; then : else fail=yes fi else - ${MSGFMT} -c -o f-p-2-$n.mo f-p-2-$n.po 2> /dev/null + ${MSGFMT} --check-format -o f-p-2-$n.mo f-p-2-$n.po 2> /dev/null if test $? = 1; then : else diff --git a/tests/format-ycp-2 b/tests/format-ycp-2 index 05b81385a..528615df6 100755 --- a/tests/format-ycp-2 +++ b/tests/format-ycp-2 @@ -47,13 +47,13 @@ ${msgstr_line} EOF fail= if echo "$comment" | grep 'Valid:' > /dev/null; then - if ${MSGFMT} -c -o f-y-2-$n.mo f-y-2-$n.po; then + if ${MSGFMT} --check-format -o f-y-2-$n.mo f-y-2-$n.po; then : else fail=yes fi else - ${MSGFMT} -c -o f-y-2-$n.mo f-y-2-$n.po 2> /dev/null + ${MSGFMT} --check-format -o f-y-2-$n.mo f-y-2-$n.po 2> /dev/null if test $? = 1; then : else diff --git a/tests/msgcomm-16 b/tests/msgcomm-16 index 0eb16c463..50e124daa 100755 --- a/tests/msgcomm-16 +++ b/tests/msgcomm-16 @@ -86,6 +86,7 @@ msgstr "Glückwunsch!" #. Remind user of the login name he chose #: clients/inst_ask_config.ycp:72 +#, ycp-format msgid "You can log in as \"%1\"." msgstr "Sie können sich als \"%1\" einloggen." EOF diff --git a/tests/msgfmt-1 b/tests/msgfmt-1 index 18f97890f..d4c3a42ea 100755 --- a/tests/msgfmt-1 +++ b/tests/msgfmt-1 @@ -37,7 +37,7 @@ msgstr "mesg 4 translation" # domain "error_dom" msgid "error 3" -msgstr "alternate error 2 translation" +msgstr "alternate error 3 translation" msgid "error 5" msgstr "error 5 translation" # @@ -46,8 +46,17 @@ msgid "window 6" msgstr "window 6 translation" EOF +# Without use of msgcat, expect a "duplicate message definition" error. : ${MSGFMT=msgfmt} -${MSGFMT} module1.po module2.po -o LC_MESSAGES/gen.mo +if ${MSGFMT} module1.po module2.po -o LC_MESSAGES/gen.mo 2> /dev/null; then + exit 1 +fi + +# With msgcat, it should work. +tmpfiles="$tmpfiles modules.po" +: ${MSGCAT=msgcat} ${MSGFMT=msgfmt} +${MSGCAT} --use-first module1.po module2.po -o modules.po +${MSGFMT} modules.po -o LC_MESSAGES/gen.mo tmpfiles="$tmpfiles mf-test1.out" : ${GETTEXT=gettext} diff --git a/tests/msgfmt-2 b/tests/msgfmt-2 index 5c90eb0ad..5b385bb67 100755 --- a/tests/msgfmt-2 +++ b/tests/msgfmt-2 @@ -52,7 +52,7 @@ msgstr "mesg 4 translation" # domain "error_dom" msgid "error 3" -msgstr "alternate error 2 translation" +msgstr "alternate error 3 translation" msgid "error 5" msgstr "error 5 translation" # @@ -61,8 +61,17 @@ msgid "window 6" msgstr "window 6 translation" EOF +# Without use of msgcat, expect a "duplicate message definition" error. : ${MSGFMT=msgfmt} -${MSGFMT} module1.po module2.po -o LC_MESSAGES/gen.mo +if ${MSGFMT} module1.po module2.po -o LC_MESSAGES/gen.mo 2> /dev/null; then + exit 1 +fi + +# With msgcat, it should work. +tmpfiles="$tmpfiles modules.po" +: ${MSGCAT=msgcat} ${MSGFMT=msgfmt} +${MSGCAT} --use-first module1.po module2.po -o modules.po +${MSGFMT} modules.po -o LC_MESSAGES/gen.mo tmpfiles="$tmpfiles mf-test2.out" : ${GETTEXT=gettext} diff --git a/tests/xg-test1.ok.po b/tests/xg-test1.ok.po index c4f4968c6..d84f7fa6e 100644 --- a/tests/xg-test1.ok.po +++ b/tests/xg-test1.ok.po @@ -121,25 +121,14 @@ msgstr "" msgid "Report bugs to .\n" msgstr "" -#, c-format -msgid "error while opening \"%s\" for reading" -msgstr "" - msgid "this file may not contain domain directives" msgstr "" -#, c-format -msgid "%s:%d: warning: keyword nested in keyword arg" +msgid "standard input" msgstr "" #, c-format -msgid "%s:%d: warning: keyword between outer keyword and its arg" -msgstr "" - -msgid "duplicate message definition" -msgstr "" - -msgid "...this is the location of the first definition" +msgid "error while opening \"%s\" for reading" msgstr "" #, c-format @@ -199,7 +188,13 @@ msgstr "" #, no-wrap msgid "" "Input file interpretation:\n" -" -c, --check perform language dependent checks on strings\n" +" -c, --check perform all the checks implied by\n" +" --check-format, --check-header, --check-domain\n" +" --check-format check language dependent format strings\n" +" --check-header verify presence and contents of the header entry\n" +" --check-domain check for conflicts between domain directives\n" +" and the --output-file option\n" +" -C, --check-compatibility check that GNU msgfmt behaves like X/Open msgfmt\n" " -f, --use-fuzzy use fuzzy entries in output\n" msgstr "" @@ -216,8 +211,7 @@ msgid "" " -h, --help display this help and exit\n" " -V, --version output version information and exit\n" " --statistics print statistics about translations\n" -" -v, --verbose list input file anomalies\n" -"Giving the -v option more than once increases the verbosity level.\n" +" -v, --verbose increase verbosity level\n" msgstr "" msgid "while creating hash table" @@ -262,6 +256,12 @@ msgstr "" msgid "field `%s' still has initial default value" msgstr "" +msgid "duplicate message definition" +msgstr "" + +msgid "...this is the location of the first definition" +msgstr "" + #, c-format msgid "%s: warning: source file contains fuzzy translation" msgstr "" @@ -286,11 +286,11 @@ msgstr "" msgid "`msgid' and `msgstr' entries do not both end with '\\n'" msgstr "" -msgid "number of format specifications in `msgid' and `msgstr' does not match" +msgid "plural handling is a GNU gettext extension" msgstr "" #, c-format -msgid "format specifications for argument %lu are not the same" +msgid "'msgstr' is not a valid %s format string, unlike 'msgid'" msgstr "" msgid "too many arguments"