]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Keep the message list's hash table up to date when the msgids are converted
authorBruno Haible <bruno@clisp.org>
Wed, 29 Oct 2003 11:48:44 +0000 (11:48 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:06 +0000 (12:11 +0200)
from one encoding to another.

gettext-tools/src/ChangeLog
gettext-tools/src/message.c
gettext-tools/src/message.h
gettext-tools/src/msgl-iconv.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am
gettext-tools/tests/msgmerge-25 [new file with mode: 0755]

index 8b58adfd2a1b9299a3c7b279596b81d3671a27b1..3f08b0605380b3f5485e586abf5556a0a51819bb 100644 (file)
@@ -1,3 +1,10 @@
+2003-10-21  Bruno Haible  <bruno@clisp.org>
+
+       * message.h (message_list_msgids_changed): New declaration.
+       * message.c (message_list_msgids_changed): New function.
+       * msgl-iconv.c (iconv_message_list): Update the message list's hash
+       table if it happens to contain non-ASCII msgids.
+
 2003-10-19  Bruno Haible  <bruno@clisp.org>
 
         * message.h (format_type): New enum value 'format_qt'.
index e168b57e149a9dfcb2b5e1169a826b95929f2e2a..0df0b7f8ae36cdf31738842cdcbdf73dfd2bb7e2 100644 (file)
@@ -330,6 +330,37 @@ message_list_remove_if_not (message_list_ty *mlp,
 }
 
 
+bool
+message_list_msgids_changed (message_list_ty *mlp)
+{
+  if (mlp->use_hashtable)
+    {
+      unsigned long int size = mlp->htable.size;
+      size_t j;
+
+      delete_hash (&mlp->htable);
+      init_hash (&mlp->htable, size);
+
+      for (j = 0; j < mlp->nitems; j++)
+       {
+         message_ty *mp = mlp->item[j];
+
+         if (insert_entry (&mlp->htable, mp->msgid, strlen (mp->msgid) + 1,
+                           mp))
+           /* A message list has duplicates, although it was allocated with
+              the assertion that it wouldn't have duplicates, and before the
+              msgids changed it indeed didn't have duplicates.  */
+           {
+             delete_hash (&mlp->htable);
+             mlp->use_hashtable = false;
+             return true;
+           }
+       }
+    }
+  return false;
+}
+
+
 message_ty *
 message_list_search (message_list_ty *mlp, const char *msgid)
 {
index 085fd37543a99d724d9c454ed6ea92d019678295..92c9b94525e3ff7b0103939e89557f2c7c96befb 100644 (file)
@@ -196,6 +196,9 @@ typedef bool message_predicate_ty (const message_ty *mp);
 extern void
        message_list_remove_if_not (message_list_ty *mlp,
                                   message_predicate_ty *predicate);
+/* Recompute the hash table of a message list after the msgids changed.  */
+extern bool
+       message_list_msgids_changed (message_list_ty *mlp);
 extern message_ty *
        message_list_search (message_list_ty *mlp, const char *msgid);
 extern message_ty *
index 1c04edc54040184905d84e428246bea98b3aae10..5eb99ff58d0808412b3a25c0b44bda05b8fd1df0 100644 (file)
@@ -343,6 +343,7 @@ input file doesn't contain a header entry with a charset specification"));
     {
 #if HAVE_ICONV
       iconv_t cd;
+      bool msgids_changed;
 
       /* Avoid glibc-2.1 bug with EUC-KR.  */
 # if (__GLIBC__ - 0 == 2 && __GLIBC_MINOR__ - 0 <= 1) && !defined _LIBICONV_VERSION
@@ -357,10 +358,13 @@ Cannot convert from \"%s\" to \"%s\". %s relies on iconv(), \
 and iconv() does not support this conversion."),
               canon_from_code, canon_to_code, basename (program_name));
 
+      msgids_changed = false;
       for (j = 0; j < mlp->nitems; j++)
        {
          message_ty *mp = mlp->item[j];
 
+         if (!is_ascii_string (mp->msgid))
+           msgids_changed = true;
          convert_string_list (cd, mp->comment);
          convert_string_list (cd, mp->comment_dot);
          convert_msgid (cd, mp);
@@ -368,6 +372,13 @@ and iconv() does not support this conversion."),
        }
 
       iconv_close (cd);
+
+      if (msgids_changed)
+       if (message_list_msgids_changed (mlp))
+         error (EXIT_FAILURE, 0, _("\
+Conversion from \"%s\" to \"%s\" introduces duplicates: \
+some different msgids become equal."),
+                canon_from_code, canon_to_code);
 #else
          error (EXIT_FAILURE, 0, _("\
 Cannot convert from \"%s\" to \"%s\". %s relies on iconv(). \
index 9c70bc75723fd449ef57597ea88b0c313d5b3344..5cb57b1d07dba64ee854084927882f4845f7b02f 100644 (file)
@@ -1,3 +1,8 @@
+2003-10-21  Bruno Haible  <bruno@clisp.org>
+
+       * msgmerge-25: New file.
+       * Makefile.am (TESTS): Add it.
+
 2003-10-19  Bruno Haible  <bruno@clisp.org>
 
        * format-qt-1: New file.
        * xgettext-3: Update for changed domain name.
 
 
-See ChangeLog.0 for earlier changes.
+See ChangeLog.0 for earlier changes.
\ No newline at end of file
index d51e3a7cb0f3d96e0bcc93c21ed13b9440c23d6d..17609818c828a519506f49c81cf7f308529e480e 100644 (file)
@@ -43,7 +43,7 @@ TESTS = gettext-1 gettext-2 \
        msgmerge-7 msgmerge-8 msgmerge-9 msgmerge-10 msgmerge-11 msgmerge-12 \
        msgmerge-13 msgmerge-14 msgmerge-15 msgmerge-16 msgmerge-17 \
        msgmerge-18 msgmerge-19 msgmerge-20 msgmerge-21 msgmerge-22 \
-       msgmerge-23 msgmerge-24 \
+       msgmerge-23 msgmerge-24 msgmerge-25 \
        msgunfmt-1 msgunfmt-2 msgunfmt-3 msgunfmt-4 \
        msguniq-1 msguniq-2 msguniq-3 msguniq-4 \
        xgettext-1 xgettext-2 xgettext-3 xgettext-4 xgettext-5 xgettext-6 \
diff --git a/gettext-tools/tests/msgmerge-25 b/gettext-tools/tests/msgmerge-25
new file mode 100755 (executable)
index 0000000..9ed3b5d
--- /dev/null
@@ -0,0 +1,99 @@
+#! /bin/sh
+
+# Test non-ASCII msgids when the PO file and the POT file are in different
+# encodings.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles mm-test25.po"
+cat <<\EOF > mm-test25.po
+msgid ""
+msgstr ""
+"Project-Id-Version: hello-cplusplus-qt 0\n"
+"Report-Msgid-Bugs-To: bug-gnu-gettext@gnu.org\n"
+"POT-Creation-Date: 2003-10-20 10:14+0200\n"
+"PO-Revision-Date: 2003-10-20 10:13+0200\n"
+"Last-Translator: Bruno Haible <bruno@clisp.org>\n"
+"Language-Team: Polish <pl@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=ISO-8859-2\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
+"|| n%100>=20) ? 1 : 2);\n"
+
+#: hello.cc:45
+msgid "Written by François Pinard."
+msgstr "Program napisa³ François Pinard."
+
+#: hello.cc:52
+msgid "error %1."
+msgstr "b³±d %1."
+EOF
+
+tmpfiles="$tmpfiles mm-test25.pot"
+cat <<EOF > mm-test25.pot
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR Yoyodyne, Inc.
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: bug-gnu-gettext@gnu.org\n"
+"POT-Creation-Date: 2003-10-20 10:14+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: hello.cc:45
+msgid "Written by François Pinard."
+msgstr ""
+
+#: hello.cc:52
+msgid "error %1."
+msgstr ""
+EOF
+
+tmpfiles="$tmpfiles mm-test25.new.po"
+: ${MSGMERGE=msgmerge}
+${MSGMERGE} -q mm-test25.po mm-test25.pot -o mm-test25.new.po
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+tmpfiles="$tmpfiles mm-test25.ok"
+cat <<\EOF > mm-test25.ok
+msgid ""
+msgstr ""
+"Project-Id-Version: hello-cplusplus-qt 0\n"
+"Report-Msgid-Bugs-To: bug-gnu-gettext@gnu.org\n"
+"POT-Creation-Date: 2003-10-20 10:14+0200\n"
+"PO-Revision-Date: 2003-10-20 10:13+0200\n"
+"Last-Translator: Bruno Haible <bruno@clisp.org>\n"
+"Language-Team: Polish <pl@li.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
+"|| n%100>=20) ? 1 : 2);\n"
+
+#: hello.cc:45
+msgid "Written by François Pinard."
+msgstr "Program napisał François Pinard."
+
+#: hello.cc:52
+msgid "error %1."
+msgstr "błąd %1."
+EOF
+
+: ${DIFF=diff}
+${DIFF} mm-test25.ok mm-test25.new.po
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result