]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgfmt: Remove POT-Creation-Date field from the header in the output.
authorJohn Darrington <john@darrington.wattle.id.au>
Thu, 15 Dec 2016 20:56:44 +0000 (21:56 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 15 Dec 2016 20:56:44 +0000 (21:56 +0100)
This helps reproducible builds.
Reported at <https://savannah.gnu.org/bugs/?49654>.
* gettext-tools/src/msgl-header.h (message_list_delete_header_field): New
declaration.
* gettext-tools/src/msgl-header.c (known_fields): New variable, extracted from
msgdomain_list_set_header_field.
(message_list_delete_header_field): New function.
* gettext-tools/src/write-mo.c: Include msgl-header.h.
(msgdomain_write_mo): Delete the POT-Creation-Date field.
* gettext-tools/src/write-java.c: Include msgl-header.h.
(msgdomain_write_java): Delete the POT-Creation-Date field.
* gettext-tools/src/write-csharp.c: Include msgl-header.h.
(msgdomain_write_csharp): Delete the POT-Creation-Date field.
* gettext-tools/src/write-resources.c: Include msgl-header.h.
(msgdomain_write_csharp_resources): Delete the POT-Creation-Date field.
* gettext-tools/src/write-tcl.c: Include msgl-header.h.
(msgdomain_write_tcl): Delete the POT-Creation-Date field.
* gettext-tools/src/write-qt.c: Include msgl-header.h.
(msgdomain_write_qt): Delete the POT-Creation-Date field.
* gettext-tools/src/write-desktop.c: Include msgl-header.h.
(msgdomain_write_desktop): Delete the POT-Creation-Date field.
* gettext-tools/src/write-xml.c: Include msgl-header.h.
(msgdomain_write_xml): Delete the POT-Creation-Date field.
* gettext-tools/tests/msgfmt-19: New file, based on
gettext-tools/tests/msgfmt-18.
* gettext-tools/tests/Makefile.am (TESTS): Add it.

12 files changed:
gettext-tools/src/msgl-header.c
gettext-tools/src/msgl-header.h
gettext-tools/src/write-csharp.c
gettext-tools/src/write-desktop.c
gettext-tools/src/write-java.c
gettext-tools/src/write-mo.c
gettext-tools/src/write-qt.c
gettext-tools/src/write-resources.c
gettext-tools/src/write-tcl.c
gettext-tools/src/write-xml.c
gettext-tools/tests/Makefile.am
gettext-tools/tests/msgfmt-19 [new file with mode: 0755]

index 987c1c47eb4759c769fea4bf6d7626128b07acf7..25ae33af3f1c7f6cb738fedc31af0105689d6ffa 100644 (file)
 #define SIZEOF(a) (sizeof(a) / sizeof(a[0]))
 
 
-void
-msgdomain_list_set_header_field (msgdomain_list_ty *mdlp,
-                                 const char *field, const char *value)
+/* The known fields in their usual order.  */
+static const struct
 {
-  /* The known fields in their usual order.  */
-  static const struct
-    {
-      const char *name;
-      size_t len;
-    }
+  const char *name;
+  size_t len;
+}
   known_fields[] =
     {
       { "Project-Id-Version:", sizeof ("Project-Id-Version:") - 1 },
@@ -54,6 +50,11 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp,
       { "Content-Transfer-Encoding:",
         sizeof ("Content-Transfer-Encoding:") - 1 }
     };
+
+void
+msgdomain_list_set_header_field (msgdomain_list_ty *mdlp,
+                                 const char *field, const char *value)
+{
   size_t field_len;
   int field_index;
   size_t k, i;
@@ -168,3 +169,71 @@ msgdomain_list_set_header_field (msgdomain_list_ty *mdlp,
           }
     }
 }
+
+
+void
+message_list_delete_header_field (message_list_ty *mlp,
+                                  const char *field)
+{
+  size_t j;
+  int field_index;
+  size_t k;
+
+  /* Search the field in known_fields[].  */
+  field_index = -1;
+  for (k = 0; k < SIZEOF (known_fields); k++)
+    if (strcmp (known_fields[k].name, field) == 0)
+      {
+        field_index = k;
+        break;
+      }
+
+  size_t field_len;
+  field_len = strlen (field);
+
+  /* Search the header entry.  */
+  for (j = 0; j < mlp->nitems; j++)
+    if (is_header (mlp->item[j]) && !mlp->item[j]->obsolete)
+      {
+        message_ty *mp = mlp->item[j];
+
+        /* Modify the header entry.  */
+        const char *header = mp->msgstr;
+        char *new_header =
+          XCALLOC (strlen (header) + 1,
+                    char);
+
+        /* Test whether the field already occurs in the header entry.  */
+        const char *h;
+
+        for (h = header; *h != '\0'; )
+          {
+            if (strncmp (h, field, field_len) == 0)
+              break;
+            h = strchr (h, '\n');
+            if (h == NULL)
+              break;
+            h++;
+          }
+        if (h != NULL && *h != '\0')
+          {
+            /* Replace the field.  */
+            char *p = new_header;
+            memcpy (p, header, h - header);
+            p += h - header;
+            h = strchr (h, '\n');
+            if (h != NULL)
+              {
+                h++;
+                stpcpy (p, h);
+              }
+          }
+        else
+          {
+            char *p = new_header;
+            p = stpcpy (p, header);
+          }
+        
+        mp->msgstr = new_header;
+      }
+}
index 9685157113bb8611ed07eb4ae486aec55fcfc9b7..34726e7b0da16160e925ffd5d883e2a6b4fe1d22 100644 (file)
@@ -34,6 +34,9 @@ extern void
        msgdomain_list_set_header_field (msgdomain_list_ty *mdlp,
                                         const char *field, const char *value);
 
+extern void
+       message_list_delete_header_field (message_list_ty *mlp, const char *field);
+
 
 #ifdef __cplusplus
 }
index 5cf573a0f27c6000838205898113e8119985b241..30e8411ccbab2dcf35db53a1ece29a69924ecb82 100644 (file)
@@ -78,6 +78,7 @@
 #include "message.h"
 #include "msgfmt.h"
 #include "msgl-iconv.h"
+#include "msgl-header.h"
 #include "plural-exp.h"
 #include "po-charset.h"
 #include "xalloc.h"
@@ -645,6 +646,8 @@ msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
 
+  message_list_delete_header_field (mlp, "POT-Creation-Date:");
+  
   /* Create a temporary directory where we can put the C# file.
      A simple temporary file would also be possible but would require us to
      define our own variant of mkstemp(): On one hand the functions mktemp(),
index 898ac3024f7ea7cc18846d3b9afd70935b387366..e568d47fb7c431ecc0710c9cff4efc5e32e01c44 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include "error.h"
 #include "msgl-iconv.h"
+#include "msgl-header.h"
 #include "po-charset.h"
 #include "read-catalog.h"
 #include "read-po.h"
@@ -203,6 +204,8 @@ msgdomain_write_desktop (message_list_ty *mlp,
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
 
+  message_list_delete_header_field (mlp, "POT-Creation-Date:");
+  
   /* Create a single-element operands and run the bulk operation on it.  */
   operand.language = (char *) locale_name;
   operand.mlp = mlp;
index eef8c79d2588e2e5eb99cb0bb61b2d66ccb59090..039ed94d938663c1daa3b6d07d4e9a5b02e6a7ae 100644 (file)
@@ -61,6 +61,7 @@
 #include "message.h"
 #include "msgfmt.h"
 #include "msgl-iconv.h"
+#include "msgl-header.h"
 #include "plural-exp.h"
 #include "po-charset.h"
 #include "xalloc.h"
@@ -1066,6 +1067,8 @@ msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
 
+  message_list_delete_header_field (mlp, "POT-Creation-Date:");
+
   if (output_source)
     {
       tmpdir = NULL;
index b4a7894944af14cdef3dced6ed4818c5d2ad1549..b99dece021d52d01f7199ed430d83da0747ce6ad 100644 (file)
@@ -48,6 +48,9 @@
 #include "binary-io.h"
 #include "fwriteerror.h"
 #include "gettext.h"
+#include "read-catalog.h"
+#include "read-stringtable.h"
+#include "msgl-header.h"
 
 #define _(str) gettext (str)
 
@@ -804,6 +807,7 @@ msgdomain_write_mo (message_list_ty *mlp,
 
       if (output_file != NULL)
         {
+          message_list_delete_header_field (mlp, "POT-Creation-Date:");
           write_table (output_file, mlp);
 
           /* Make sure nothing went wrong.  */
index 978bf093849c678109a70f7cc63814e8e07629a1..4a47d241fc7c2c7fe4fb127619adf4bd3140dd03 100644 (file)
@@ -35,6 +35,7 @@
 #include "message.h"
 #include "po-charset.h"
 #include "msgl-iconv.h"
+#include "msgl-header.h"
 #include "hash-string.h"
 #include "unistr.h"
 #include "xalloc.h"
@@ -742,6 +743,7 @@ strings, not in the untranslated strings\n")));
 
       if (output_file != NULL)
         {
+          message_list_delete_header_field (mlp, "POT-Creation-Date:");
           write_qm (output_file, mlp);
 
           /* Make sure nothing went wrong.  */
index e5103c4b07c7942ec23c1f5fda3e7a9cf3ea1712..ec74eadcdc1a0e46de21a3185509950eadac3fed 100644 (file)
@@ -38,6 +38,7 @@
 #include "message.h"
 #include "msgfmt.h"
 #include "msgl-iconv.h"
+#include "msgl-header.h"
 #include "po-charset.h"
 #include "xalloc.h"
 #include "concat-filename.h"
@@ -114,6 +115,8 @@ msgdomain_write_csharp_resources (message_list_ty *mlp,
                                   const char *domain_name,
                                   const char *file_name)
 {
+  message_list_delete_header_field (mlp, "POT-Creation-Date:");
+  
   /* If no entry for this domain don't even create the file.  */
   if (mlp->nitems != 0)
     {
index 0dbe3aa881eb392c4eac03dc8cbde361066aec6f..04b62d9c84baa786861a985efe0ff4754616d5cc 100644 (file)
@@ -34,6 +34,7 @@
 #include "xerror.h"
 #include "message.h"
 #include "msgl-iconv.h"
+#include "msgl-header.h"
 #include "po-charset.h"
 #include "xalloc.h"
 #include "xmalloca.h"
@@ -216,6 +217,7 @@ but the Tcl message catalog format doesn't support plural handling\n")));
         return 1;
       }
 
+    message_list_delete_header_field (mlp, "POT-Creation-Date:");
     write_msg (output_file, mlp, frobbed_locale_name);
 
     /* Make sure nothing went wrong.  */
index 79b7b5dbc3893bf7abe728b09a9af8a7078c1e88..f6cd6c003d8a6638923cdaa31c716ed45bba6eca 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdio.h>
 #include "error.h"
 #include "msgl-iconv.h"
+#include "msgl-header.h"
 #include "po-charset.h"
 #include "read-catalog.h"
 #include "read-po.h"
@@ -94,6 +95,8 @@ msgdomain_write_xml (message_list_ty *mlp,
   /* Convert the messages to Unicode.  */
   iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
 
+  message_list_delete_header_field (mlp, "POT-Creation-Date:");
+  
   /* Create a single-element operands and run the bulk operation on it.  */
   operand.language = (char *) locale_name;
   operand.mlp = mlp;
index 0dfb4d867aa6746d7322d180c7066fea3f9f8f35..38b47b92212b12d0b81490106c8f2356e454826a 100644 (file)
@@ -46,7 +46,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \
        msgfilter-sr-latin-1 msgfilter-quote-1 \
        msgfmt-1 msgfmt-2 msgfmt-3 msgfmt-4 msgfmt-5 msgfmt-6 msgfmt-7 \
        msgfmt-8 msgfmt-9 msgfmt-10 msgfmt-11 msgfmt-12 msgfmt-13 msgfmt-14 \
-       msgfmt-15 msgfmt-16 msgfmt-17 msgfmt-18 \
+       msgfmt-15 msgfmt-16 msgfmt-17 msgfmt-18 msgfmt-19 \
        msgfmt-properties-1 \
        msgfmt-qt-1 msgfmt-qt-2 \
        msgfmt-desktop-1 msgfmt-desktop-2 \
diff --git a/gettext-tools/tests/msgfmt-19 b/gettext-tools/tests/msgfmt-19
new file mode 100755 (executable)
index 0000000..88574c8
--- /dev/null
@@ -0,0 +1,66 @@
+#! /bin/sh
+. "${srcdir=.}/init.sh"; path_prepend_ . ../src
+
+# Test accelerators.
+
+cat <<\EOF > mf-19-1.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: GNU bison\n"
+"POT-Creation-Date: 2017-04-05 19:47+0200\n"
+"PO-Revision-Date: 2017-06-07 09:07+0000\n"
+"Last-Translator: ABC DEF <abc@gnu.uucp>\n"
+"Language-Team: test <test@li.org>\n"
+"Language: test\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "pen &File"
+msgstr "pen File"
+
+msgid "how _Help"
+msgstr "how Help"
+EOF
+
+
+cat <<\EOF > mf-19-2.po
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Free Software Foundation, Inc.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: GNU bison\n"
+"POT-Creation-Date: 2016-03-04 18:46+0100\n"
+"PO-Revision-Date: 2017-06-07 09:07+0000\n"
+"Last-Translator: ABC DEF <abc@gnu.uucp>\n"
+"Language-Team: test <test@li.org>\n"
+"Language: test\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "pen &File"
+msgstr "pen File"
+
+msgid "how _Help"
+msgstr "how Help"
+EOF
+
+
+: ${MSGFMT=msgfmt}
+${MSGFMT} -o mf-19-1.mo mf-19-1.po 2>/dev/null
+test $? = 0 || { Exit 1; }
+
+: ${MSGFMT=msgfmt}
+${MSGFMT} -o mf-19-2.mo mf-19-2.po 2>/dev/null
+test $? = 0 || { Exit 1; }
+
+: ${DIFF=diff}
+${DIFF} mf-19-1.mo mf-19-2.mo
+test $? = 0 || { Exit 1; }