From: Bruno Haible Date: Wed, 29 Oct 2003 11:48:44 +0000 (+0000) Subject: Keep the message list's hash table up to date when the msgids are converted X-Git-Tag: v0.13~185 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a9e5acdb05e46d81d17460533eff4b009a8e1c1;p=thirdparty%2Fgettext.git Keep the message list's hash table up to date when the msgids are converted from one encoding to another. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 8b58adfd2..3f08b0605 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,10 @@ +2003-10-21 Bruno Haible + + * 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 * message.h (format_type): New enum value 'format_qt'. diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index e168b57e1..0df0b7f8a 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -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) { diff --git a/gettext-tools/src/message.h b/gettext-tools/src/message.h index 085fd3754..92c9b9452 100644 --- a/gettext-tools/src/message.h +++ b/gettext-tools/src/message.h @@ -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 * diff --git a/gettext-tools/src/msgl-iconv.c b/gettext-tools/src/msgl-iconv.c index 1c04edc54..5eb99ff58 100644 --- a/gettext-tools/src/msgl-iconv.c +++ b/gettext-tools/src/msgl-iconv.c @@ -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(). \ diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 9c70bc757..5cb57b1d0 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,8 @@ +2003-10-21 Bruno Haible + + * msgmerge-25: New file. + * Makefile.am (TESTS): Add it. + 2003-10-19 Bruno Haible * format-qt-1: New file. @@ -399,4 +404,4 @@ * 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 diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index d51e3a7cb..17609818c 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -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 index 000000000..9ed3b5d06 --- /dev/null +++ b/gettext-tools/tests/msgmerge-25 @@ -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 \n" +"Language-Team: Polish \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 < 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 , 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 \n" +"Language-Team: LANGUAGE \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 \n" +"Language-Team: Polish \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