From: Bruno Haible Date: Sun, 29 Sep 2019 18:20:36 +0000 (+0200) Subject: msgcat: Signal error when the same msgid is used with and without msgid_plural. X-Git-Tag: v0.21~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e219e828ed44c2bfd00a05bc4bacfce16d22e109;p=thirdparty%2Fgettext.git msgcat: Signal error when the same msgid is used with and without msgid_plural. Suggested by Mikko Rantalainen in . * gettext-tools/src/msgl-cat.c (catenate_msgdomain_list): Signal an error when the same msgid is used with and without msgid_plural. * gettext-tools/src/msgcat.c (main): Exit with failure code if there was an error. * gettext-tools/src/msgcomm.c (main): Likewise. * gettext-tools/src/msguniq.c (main): Likewise. * gettext-tools/tests/msgcat-21: New file. * gettext-tools/tests/Makefile.am (TESTS): Add it. --- diff --git a/gettext-tools/src/msgcat.c b/gettext-tools/src/msgcat.c index 17f6c6658..831d48739 100644 --- a/gettext-tools/src/msgcat.c +++ b/gettext-tools/src/msgcat.c @@ -350,7 +350,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Write the PO file. */ msgdomain_list_print (result, output_file, output_syntax, force_po, false); - exit (EXIT_SUCCESS); + exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgcomm.c b/gettext-tools/src/msgcomm.c index dc97c4b6a..d1fecd8f7 100644 --- a/gettext-tools/src/msgcomm.c +++ b/gettext-tools/src/msgcomm.c @@ -342,7 +342,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Write the PO file. */ msgdomain_list_print (result, output_file, output_syntax, force_po, false); - exit (EXIT_SUCCESS); + exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/gettext-tools/src/msgl-cat.c b/gettext-tools/src/msgl-cat.c index ed3a197bb..2e806497c 100644 --- a/gettext-tools/src/msgl-cat.c +++ b/gettext-tools/src/msgl-cat.c @@ -297,7 +297,18 @@ catenate_msgdomain_list (string_list_ty *file_list, size_t i; tmp = message_list_search (total_mlp, mp->msgctxt, mp->msgid); - if (tmp == NULL) + if (tmp != NULL) + { + if ((tmp->msgid_plural != NULL) != (mp->msgid_plural != NULL)) + { + char *errormsg = + xasprintf (_("msgid '%s' is used without plural and with plural."), + mp->msgid); + multiline_error (xstrdup (""), + xasprintf ("%s\n", errormsg)); + } + } + else { tmp = message_alloc (mp->msgctxt, mp->msgid, mp->msgid_plural, NULL, 0, &mp->pos); diff --git a/gettext-tools/src/msguniq.c b/gettext-tools/src/msguniq.c index fb28ecfc8..0d2c27cce 100644 --- a/gettext-tools/src/msguniq.c +++ b/gettext-tools/src/msguniq.c @@ -310,7 +310,7 @@ There is NO WARRANTY, to the extent permitted by law.\n\ /* Write the PO file. */ msgdomain_list_print (result, output_file, output_syntax, force_po, false); - exit (EXIT_SUCCESS); + exit (error_message_count > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 0b68a964e..53d6af754 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -32,7 +32,7 @@ TESTS = gettext-1 gettext-2 \ msgattrib-properties-1 \ msgcat-1 msgcat-2 msgcat-3 msgcat-4 msgcat-5 msgcat-6 msgcat-7 \ msgcat-8 msgcat-9 msgcat-10 msgcat-11 msgcat-12 msgcat-13 msgcat-14 \ - msgcat-15 msgcat-16 msgcat-17 msgcat-18 msgcat-19 msgcat-20 \ + msgcat-15 msgcat-16 msgcat-17 msgcat-18 msgcat-19 msgcat-20 msgcat-21 \ msgcat-properties-1 msgcat-properties-2 \ msgcat-stringtable-1 \ msgcmp-1 msgcmp-2 msgcmp-3 msgcmp-4 \ diff --git a/gettext-tools/tests/msgcat-21 b/gettext-tools/tests/msgcat-21 new file mode 100755 index 000000000..7b9a4373f --- /dev/null +++ b/gettext-tools/tests/msgcat-21 @@ -0,0 +1,40 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Verify that msgcat complains when the same msgid occurs with and without +# msgid_plural. + +cat <<\EOF > mcat-test21.in1 +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +msgid "File" +msgstr "Soumettre" +EOF + +cat <<\EOF > mcat-test21.in2 +msgid "" +msgstr "" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +msgid "File" +msgid_plural "Files" +msgstr[0] "fichier" +msgstr[1] "fichiers" +EOF + +rm -f mcat-test21.out1 +: ${MSGCAT=msgcat} +${MSGCAT} -o mcat-test21.out1 mcat-test21.in1 mcat-test21.in2 2>/dev/null +test $? = 1 || { Exit 1; } + +rm -f mcat-test21.out2 +: ${MSGCAT=msgcat} +${MSGCAT} -o mcat-test21.out2 mcat-test21.in2 mcat-test21.in1 2>/dev/null +test $? = 1 || { Exit 1; } + +Exit 0