bug-groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

"refer -s" sorts missing fields incorrectly


From: Stephen Gildea
Subject: "refer -s" sorts missing fields incorrectly
Date: Wed, 20 Aug 2003 06:48:02 -0400

GROFF VERSION: 

1.19


INPUT FILES:

%A J. Third
%T Abc

%A J. Second
%L Def

%A J. First
%C Ghi


COMMAND LINE:

refer -B -sTLC sorting-bug.refer


DESCRIPTION OF INCORRECT BEHAVIOUR:

With certain combination of sort specifications, refer will sort entries
in the wrong order.  In particular, entries with a missing field should
be sorted before all entries that have that field, before refer looks to
the next field.

With the example input file and command line given above, the major sort
is on the T field, so the only entry with a T field (the entry with
author J. Third) should be third.  Instead, it is sorted first.
Similarly, the entry by J. First should be sorted first, but it is last.

The problem appears to be that ^A separators between sort fields are not
always inserted into the sort key.  The sort keys for the three entries
in the example should be as follows:

abc^A^A
^Adef^A
^A^Aghi

instead they are:

abc
def
ghi

which get sorted backwards.


SUGGESTED FIX:

This simple diff fixes the problem.  As a side effect, it inserts an
extra ^A at the beginning of every sort key, but on the other hand it
also makes the code shorter.

--- src/preproc/refer/ref.cpp-dist-1.19 Thu Apr 19 10:01:56 2001
+++ src/preproc/refer/ref.cpp   Tue Aug 12 07:21:10 2003
@@ -420,8 +420,7 @@ void reference::compute_sort_key()
   sort_fields += '\0';
   const char *sf = sort_fields.contents();
   while (*sf != '\0') {
-    if (sf > sort_fields)
-      sort_key += SORT_SEP;
+    sort_key += SORT_SEP;
     char f = *sf++;
     int n = 1;
     if (*sf == '+') {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]