/* 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
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
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 \
--- /dev/null
+#! /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 <<EOF > 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