]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgfmt: Add .mo suffix to output files generated for domain directives.
authorBruno Haible <bruno@clisp.org>
Mon, 11 Jun 2001 12:10:46 +0000 (12:10 +0000)
committerBruno Haible <bruno@clisp.org>
Mon, 11 Jun 2001 12:10:46 +0000 (12:10 +0000)
src/ChangeLog
src/msgfmt.c
tests/ChangeLog
tests/Makefile.am
tests/msgfmt-5 [new file with mode: 0755]

index 34de81907471df366a0265e77eba8b5f350f19ba..5eb3bf826af16ff93f876959c6f32cf3f2615bd9 100644 (file)
@@ -1,3 +1,18 @@
+2001-06-10  Bruno Haible  <haible@clisp.cons.org>
+
+       * msgfmt.c: Change the --strict option to not apply to domain
+       directives, only to the output filename argument.
+       (struct msg_domain): Add file_name field.
+       (domain_list): Renamed from domain.
+       (new_domain): Add file_name argument.
+       (main): Pass file name to new_domain(). Use file_name passed to
+       new_domain() in fopen call; don't free it.
+       (new_domain): New argument 'file_name'.
+       (format_directive_domain): Always ensure ".mo" suffix, independently
+       of --strict.
+       (format_directive_message): Likewise.
+       (add_mo_suffix): Don't call xstrdup.
+
 2001-06-01  Bruno Haible  <haible@clisp.cons.org>
 
        * Makefile.am (datadir): Remove definition.
index 338dc5233c3dcf1d95e9f915edc6b8d13cd78b49..69951f43ff46b996ffac4a6f580130abf0ff08c1 100644 (file)
@@ -112,10 +112,12 @@ struct msg_domain
   hash_table symbol_tab;
   /* Name of domain these ID/String pairs are part of.  */
   const char *domain_name;
+  /* Output file name.  */
+  const char *file_name;
   /* Link to the next domain.  */
   struct msg_domain *next;
 };
-static struct msg_domain *domain;
+static struct msg_domain *domain_list;
 static struct msg_domain *current_domain;
 
 /* If not zero list duplicate message identifiers.  */
@@ -178,7 +180,8 @@ static void format_directive_message PARAMS ((po_ty *__pop, char *__msgid,
                                              int __obsolete));
 static void format_comment_special PARAMS ((po_ty *pop, const char *s));
 static void format_debrief PARAMS ((po_ty *));
-static struct msg_domain *new_domain PARAMS ((const char *name));
+static struct msg_domain *new_domain PARAMS ((const char *name,
+                                             const char *file_name));
 static int compare_id PARAMS ((const void *pval1, const void *pval2));
 static void write_table PARAMS ((FILE *output_file, hash_table *tab));
 static void check_pair PARAMS ((const char *msgid, const lex_pos_ty *msgid_pos,
@@ -197,6 +200,7 @@ main (argc, argv)
   int do_help = 0;
   int do_version = 0;
   int strict_uniforum = 0;
+  struct msg_domain *domain;
 
   /* Set default value for global variables.  */
   alignment = DEFAULT_OUTPUT_ALIGNMENT;
@@ -288,7 +292,10 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
   /* The -o option determines the name of the domain and therefore
      the output file.  */
   if (output_file_name != NULL)
-    current_domain = new_domain (output_file_name);
+    current_domain =
+      new_domain (output_file_name,
+                 strict_uniforum ? add_mo_suffix (output_file_name)
+                                 : output_file_name);
 
   /* Prepare PO file reader.  We need to see the comments because inexact
      translations must be reported.  */
@@ -309,7 +316,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
       ++optind;
     }
 
-  while (domain != NULL)
+  for (domain = domain_list; domain != NULL; domain = domain->next)
     {
       FILE *output_file;
 
@@ -323,10 +330,7 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
            }
          else
            {
-             const char *fname;
-
-             fname = strict_uniforum ? add_mo_suffix (domain->domain_name)
-                                     : domain->domain_name;
+             const char *fname = domain->file_name;
 
              output_file = fopen (fname, "wb");
              if (output_file == NULL)
@@ -335,9 +339,6 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
                         _("error while opening \"%s\" for writing"), fname);
                  exit_status = EXIT_FAILURE;
                }
-
-             if (strict_uniforum)
-               free ((void *) fname);
            }
 
          if (output_file != NULL)
@@ -347,8 +348,6 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
                fclose (output_file);
            }
        }
-
-      domain = domain->next;
     }
 
   /* Print statistics if requested.  */
@@ -449,22 +448,26 @@ Giving the -v option more than once increases the verbosity level.\n\
 
 
 static struct msg_domain *
-new_domain (name)
+new_domain (name, file_name)
      const char *name;
+     const char *file_name;
 {
-  struct msg_domain **p_dom = &domain;
+  struct msg_domain **p_dom = &domain_list;
 
   while (*p_dom != NULL && strcmp (name, (*p_dom)->domain_name) != 0)
     p_dom = &(*p_dom)->next;
 
   if (*p_dom == NULL)
     {
-      *p_dom = (struct msg_domain *) xmalloc (sizeof (**p_dom));
+      struct msg_domain *domain;
 
-      if (init_hash (&(*p_dom)->symbol_tab, 100) != 0)
+      domain = (struct msg_domain *) xmalloc (sizeof (struct msg_domain));
+      if (init_hash (&domain->symbol_tab, 100) != 0)
        error (EXIT_FAILURE, errno, _("while creating hash table"));
-      (*p_dom)->domain_name = name;
-      (*p_dom)->next = NULL;
+      domain->domain_name = name;
+      domain->file_name = file_name;
+      domain->next = NULL;
+      *p_dom = domain;
     }
 
   return *p_dom;
@@ -536,7 +539,7 @@ domain name \"%s\" not suitable as file name: will use prefix"), name);
        }
 
       /* Set new domain.  */
-      current_domain = new_domain (name);
+      current_domain = new_domain (name, add_mo_suffix (name));
     }
   else
     {
@@ -676,7 +679,8 @@ some header fields still have the initial default value"));
       /* Check whether already a domain is specified.  If not use default
         domain.  */
       if (current_domain == NULL)
-       current_domain = new_domain ("messages");
+       current_domain = new_domain (MESSAGE_DOMAIN_DEFAULT,
+                                    add_mo_suffix (MESSAGE_DOMAIN_DEFAULT));
 
       /* We insert the ID/string pair into the hashing table.  But we have
         to take care for duplicates.  */
@@ -1114,9 +1118,9 @@ add_mo_suffix (fname)
 
   len = strlen (fname);
   if (len > 3 && memcmp (fname + len - 3, ".mo", 3) == 0)
-    return xstrdup (fname);
+    return fname;
   if (len > 4 && memcmp (fname + len - 4, ".gmo", 4) == 0)
-    return xstrdup (fname);
+    return fname;
   result = (char *) xmalloc (len + 4);
   stpcpy (stpcpy (result, fname), ".mo");
   return result;
index 83f2b56695b75056dd1277114f78047ee1da3048..546d4248aebc67d410db69d038fca268b4de3578 100644 (file)
@@ -1,3 +1,8 @@
+2001-06-10  Bruno Haible  <haible@clisp.cons.org>
+
+       * msgfmt-5: New file.
+       * Makefile.am (TESTS): Add it.
+
 2001-06-10  Bruno Haible  <haible@clisp.cons.org>
 
        * msgcmp-2: Add program name prefix to expected output.
index 79e0f4225c10249ea63e611a68d52018bdb35731..0d777b5cbf4974196a8c1470325efe40ec8fe6f8 100644 (file)
@@ -24,7 +24,7 @@ TESTS = gettext-1 gettext-2 \
        msgcomm-1 msgcomm-2 msgcomm-3 msgcomm-4 msgcomm-5 msgcomm-6 msgcomm-7 \
        msgcomm-8 msgcomm-9 msgcomm-10 msgcomm-11 msgcomm-12 msgcomm-13 \
        msgcomm-14 msgcomm-15 msgcomm-16 \
-       msgfmt-1 msgfmt-2 msgfmt-3 msgfmt-4 \
+       msgfmt-1 msgfmt-2 msgfmt-3 msgfmt-4 msgfmt-5 \
        msgmerge-1 msgmerge-2 msgmerge-3 msgmerge-4 msgmerge-5 msgmerge-6 \
        msgmerge-7 msgmerge-8 msgmerge-9 \
        msgunfmt-1 \
diff --git a/tests/msgfmt-5 b/tests/msgfmt-5
new file mode 100755 (executable)
index 0000000..f19dbef
--- /dev/null
@@ -0,0 +1,74 @@
+#! /bin/sh
+
+# Test multi-domain handling.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="foo.po"
+cat <<EOF > foo.po
+domain "foo-de"
+msgid ""
+msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
+
+# Das ist ein Kommentar.
+msgid "hello"
+msgstr "Hallo"
+
+# Noch einer.
+msgid "bye"
+msgstr "Tschüß"
+
+domain "foo-fr"
+msgid ""
+msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
+
+# Ceci est un commentaire.
+msgid "hello"
+msgstr "Salut"
+
+# Encore un.
+msgid "bye"
+msgstr "A bientôt"
+EOF
+
+tmpfiles="$tmpfiles foo-de.mo foo-fr.mo"
+: ${MSGFMT=msgfmt}
+${MSGFMT} foo.po
+
+tmpfiles="$tmpfiles foo-de.out foo-fr.out"
+: ${MSGUNFMT=msgunfmt}
+${MSGUNFMT} foo-de.mo -o foo-de.out
+${MSGUNFMT} foo-fr.mo -o foo-fr.out
+
+tmpfiles="$tmpfiles foo-de.ok"
+cat <<EOF > foo-de.ok
+msgid ""
+msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
+
+msgid "bye"
+msgstr "Tschüß"
+
+msgid "hello"
+msgstr "Hallo"
+EOF
+
+tmpfiles="$tmpfiles foo-fr.ok"
+cat <<EOF > foo-fr.ok
+msgid ""
+msgstr "Content-Type: text/plain; charset=ISO-8859-1\n"
+
+msgid "bye"
+msgstr "A bientôt"
+
+msgid "hello"
+msgstr "Salut"
+EOF
+
+: ${DIFF=diff}
+${DIFF} foo-de.ok foo-de.out && ${DIFF} foo-fr.ok foo-fr.out
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result