]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Reorganize msgfmt checking options.
authorBruno Haible <bruno@clisp.org>
Fri, 31 Aug 2001 18:38:34 +0000 (18:38 +0000)
committerBruno Haible <bruno@clisp.org>
Fri, 31 Aug 2001 18:38:34 +0000 (18:38 +0000)
15 files changed:
po/ChangeLog
po/Makefile.in.in
src/ChangeLog
src/msgfmt.c
tests/ChangeLog
tests/Makefile.am
tests/format-c-2
tests/format-java-2
tests/format-lisp-2
tests/format-python-2
tests/format-ycp-2
tests/msgcomm-16
tests/msgfmt-1
tests/msgfmt-2
tests/xg-test1.ok.po

index 9bedf7f73345eaa9892f0fb44f34befdf66f856a..8a29d8ad919028245f2505a18c88b5f3d5da2914 100644 (file)
@@ -1,3 +1,8 @@
+2001-08-30  Bruno Haible  <haible@clisp.cons.org>
+
+       * Makefile.in.in (.po.mo, .po.gmo): Add msgfmt option -c, to guarantee
+       the PO file is really valid.
+
 2001-08-31  Bruno Haible  <haible@clisp.cons.org>
 
        * da.po: Update from Keld Simonsen <keld@dkuug.dk>.
index bf3998380e8177460bc97070700da05a6d470600..a1943c523c4fad30a784be918fd20ff9b37df147 100644 (file)
@@ -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@
index 4cc15711d60b562d3a7a8ef06c09abc885a28e64..dccec66fd3adebaee9e7a88ac1943c67e3482a8b 100644 (file)
@@ -1,3 +1,23 @@
+2001-08-30  Bruno Haible  <haible@clisp.cons.org>
+
+       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  <haible@clisp.cons.org>
 
        * format.h: New file.
index e11dbf8e3a64684fbabc604d8c0fe88da9a0fe20..ae66fb016560e0eb53806c54557ff54692708d2b 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <errno.h>
 #include <getopt.h>
+#include <limits.h>
 #include <stdio.h>
 #include <sys/param.h>
 #include <sys/types.h>
@@ -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 <bug-gnu-gettext@gnu.org>.\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 (&current_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 (&current_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
index 84866420f63f2025b7d090317f52af00a26af0a0..4191e5bf046feea79c6127ceada9833be26319c6 100644 (file)
@@ -1,3 +1,17 @@
+2001-08-30  Bruno Haible  <haible@clisp.cons.org>
+
+       * 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  <haible@clisp.cons.org>
 
        * format-c-1: New file.
index 66e36781f32c401fbda7f6d7c63823343ad78519..91ae8a94c2f9e62d79d0ba45200c7c4fdfd50b37 100644 (file)
@@ -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)'` \
index 697a2ea207b2e0c998d9ccd077f60a2f4f8b1b98..21ec40ba6009d9c8e9931aa7d670dea37e25adec 100755 (executable)
@@ -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
index 3248321e30a7e2e10f1c2ab2bb45e4881a498abc..0058501f633f1a4fb33922548b0a21227c97601b 100755 (executable)
@@ -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
index 64514cd479dda61c4c677a7fb2f90fa39c7075a2..f89bacfd8aca67af172d5aef705e15e91d483371 100755 (executable)
@@ -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
index 81b33ac0b7deb27190dd0e0d547182157cc5a024..634239483d64513ec6da42f86dc71e9b265a2e88 100755 (executable)
@@ -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
index 05b81385a1fa09589186e6f9297e3ed3815d2bed..528615df6c3871f8dfee92338e37ef9fd55dc24b 100755 (executable)
@@ -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
index 0eb16c463ae5f7d895bbc76efb4d59822c81e6bf..50e124daa68ea38d2dcd38549fdec2efb1b46831 100755 (executable)
@@ -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
index 18f97890f80af660c2a39d15c5619223178fcc81..d4c3a42eadad7bdc0325d16a01909077e1648305 100755 (executable)
@@ -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}
index 5c90eb0ad6702c6cacffce694bef4a6afb5d03be..5b385bb67ea0b63423e0c5c0d1e3bf91d21bc99c 100755 (executable)
@@ -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}
index c4f4968c6dde815c51cf6b0dc124706e9b8f08de..d84f7fa6ee79adaa7ba87e571a606f0f1a17882a 100644 (file)
@@ -121,25 +121,14 @@ msgstr ""
 msgid "Report bugs to <bug-gnu-utils@gnu.org>.\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"