Module Name: src
Committed By: christos
Date: Sun Apr 7 12:30:38 UTC 2024
Modified Files:
src/external/gpl2/texinfo/dist/util: texindex.c
Log Message:
make qsort sorting deterministic
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/external/gpl2/texinfo/dist/util/texindex.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/gpl2/texinfo/dist/util/texindex.c
diff -u src/external/gpl2/texinfo/dist/util/texindex.c:1.2 src/external/gpl2/texinfo/dist/util/texindex.c:1.3
--- src/external/gpl2/texinfo/dist/util/texindex.c:1.2 Wed Jan 13 19:34:53 2016
+++ src/external/gpl2/texinfo/dist/util/texindex.c Sun Apr 7 08:30:38 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: texindex.c,v 1.2 2016/01/14 00:34:53 christos Exp $ */
+/* $NetBSD: texindex.c,v 1.3 2024/04/07 12:30:38 christos Exp $ */
/* texindex -- sort TeX index dribble output into an actual index.
Id: texindex.c,v 1.11 2004/04/11 17:56:47 karl Exp
@@ -55,6 +55,7 @@ struct lineinfo
long number; /* The numeric value (for numeric comparison). */
} key;
long keylen; /* Length of KEY field. */
+ size_t idx; /* tie breaker */
};
/* This structure describes a field to use as a sort key. */
@@ -369,7 +370,9 @@ compare_full (const void *p1, const void
}
}
- return 0; /* Lines match exactly. */
+ if (*line1 == *line2)
+ abort ();
+ return *line1 < *line2 ? -1 : 1;
}
/* Compare LINE1 and LINE2, described by structures
@@ -428,7 +431,9 @@ compare_prepared (const void *p1, const
}
}
- return 0; /* Lines match exactly. */
+ if (line1->idx == line2->idx)
+ abort ();
+ return line1->idx < line2->idx ? -1 : 1;
}
/* Like compare_full but more general.
@@ -799,11 +804,13 @@ sort_in_core (char *infile, int total, c
if (lineinfo)
{
+ size_t idx = 0;
struct lineinfo *lp;
char **p;
for (lp = lineinfo, p = linearray; p != nextline; lp++, p++)
{
+ lp->idx = idx++;
lp->text = *p;
lp->key.text = find_field (keyfields, *p, &lp->keylen);
if (keyfields->numeric)