From: Bruno Haible Date: Fri, 17 Jul 2020 22:01:57 +0000 (+0200) Subject: msgmerge: Make --sort-by-file sort messages without file reference correctly. X-Git-Tag: v0.21~29 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a40d29d71380489f9495a3d9c031366f8ab5029f;p=thirdparty%2Fgettext.git msgmerge: Make --sort-by-file sort messages without file reference correctly. Reported by in . * gettext-tools/src/write-catalog.c (cmp_by_filepos): When a->filepos_count and b->filepos_count are both 0, compare the msgid strings. * gettext-tools/tests/msgmerge-29: New file. * gettext-tools/tests/Makefile.am (TESTS): Add it. --- diff --git a/gettext-tools/src/write-catalog.c b/gettext-tools/src/write-catalog.c index 504bbaccd..c25916d1b 100644 --- a/gettext-tools/src/write-catalog.c +++ b/gettext-tools/src/write-catalog.c @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2008, 2012, 2019 Free Software + Copyright (C) 1995-1998, 2000-2008, 2012, 2019-2020 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -423,23 +423,22 @@ cmp_by_filepos (const void *va, const void *vb) int cmp; /* No filepos is smaller than any other filepos. */ - if (a->filepos_count == 0) - { - if (b->filepos_count != 0) - return -1; - } - if (b->filepos_count == 0) - return 1; - - /* Compare on the file names... */ - cmp = strcmp (a->filepos[0].file_name, b->filepos[0].file_name); + cmp = (a->filepos_count != 0) - (b->filepos_count != 0); if (cmp != 0) return cmp; - /* If they are equal, compare on the line numbers... */ - cmp = a->filepos[0].line_number - b->filepos[0].line_number; - if (cmp != 0) - return cmp; + if (a->filepos_count != 0) + { + /* Compare on the file names... */ + cmp = strcmp (a->filepos[0].file_name, b->filepos[0].file_name); + if (cmp != 0) + return cmp; + + /* If they are equal, compare on the line numbers... */ + cmp = a->filepos[0].line_number - b->filepos[0].line_number; + if (cmp != 0) + return cmp; + } /* If they are equal, compare on the msgid strings. */ /* Because msgids normally contain only ASCII characters or are UTF-8 diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 07d41323b..6b7ec29ea 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -62,7 +62,7 @@ TESTS = gettext-1 gettext-2 \ 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-25 msgmerge-26 msgmerge-27 \ - msgmerge-28 \ + msgmerge-28 msgmerge-29 \ msgmerge-compendium-1 msgmerge-compendium-2 msgmerge-compendium-3 \ msgmerge-compendium-4 msgmerge-compendium-5 msgmerge-compendium-6 \ msgmerge-properties-1 msgmerge-properties-2 \ diff --git a/gettext-tools/tests/msgmerge-29 b/gettext-tools/tests/msgmerge-29 new file mode 100644 index 000000000..4213178d8 --- /dev/null +++ b/gettext-tools/tests/msgmerge-29 @@ -0,0 +1,49 @@ +#! /bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test --sort-by-file option, when no file positions are present. + +cat <<\EOF > mm-test29.po +msgid "a" +msgstr "a" + +#~ msgid "c" +#~ msgstr "c" + +#~ msgid "d" +#~ msgstr "d" + +#~ msgid "b" +#~ msgstr "b" +EOF + +cat < mm-test29.pot +msgid "a" +msgstr "" +EOF + +: ${MSGMERGE=msgmerge} +${MSGMERGE} -q --sort-by-file -o mm-test29.tmp mm-test29.po mm-test29.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test29.tmp > mm-test29.po2 || Exit 1 +${MSGMERGE} -q --sort-by-file -o mm-test29.tmp mm-test29.po2 mm-test29.pot || Exit 1 +LC_ALL=C tr -d '\r' < mm-test29.tmp > mm-test29.po3 || Exit 1 + +cat <<\EOF > mm-test29.ok +msgid "a" +msgstr "a" + +#~ msgid "b" +#~ msgstr "b" + +#~ msgid "c" +#~ msgstr "c" + +#~ msgid "d" +#~ msgstr "d" +EOF + +: ${DIFF=diff} +${DIFF} mm-test29.ok mm-test29.po2 || Exit 1 +${DIFF} mm-test29.ok mm-test29.po3 || Exit 1 + +Exit 0