diff --git a/lib/argp-help.c b/lib/argp-help.c index 52260f3..ca5f397 100644 --- a/lib/argp-help.c +++ b/lib/argp-help.c @@ -822,12 +822,50 @@ hol_sort (struct hol *hol) { if (hol->num_entries > 0) { - unsigned i; + unsigned i, j, k; struct hol_entry *e; for (i = 0, e = hol->entries; i < hol->num_entries; i++, e++) e->ord = i; + + fprintf (stderr, "hol_sort: entries = {\n"); + for (i = 0; i < hol->num_entries; i++) + { + e = hol->entries + i; + fprintf (stderr, " [%u] = [%s] [%s]\n", i, e->opt->name != NULL ? e->opt->name : "", e->opt->doc != NULL ? e->opt->doc : ""); + } + fprintf (stderr, "}\n"); + fprintf (stderr, "hol_sort: comparisons =\n"); + for (i = 0; i < hol->num_entries; i++) + { + fprintf (stderr, " "); + for (j = 0; j < hol->num_entries; j++) + { + int cmp = hol_entry_cmp (hol->entries + i, hol->entries + j); + fprintf (stderr, cmp > 0 ? " +" : cmp < 0 ? " -" : " ."); + } + fprintf (stderr, "\n"); + } + for (i = 0; i < hol->num_entries; i++) + for (j = 0; j < hol->num_entries; j++) + for (k = 0; k < hol->num_entries; k++) { + int cmp1 = hol_entry_cmp (hol->entries + i, hol->entries + j); + int cmp2 = hol_entry_cmp (hol->entries + j, hol->entries + k); + int cmp3 = hol_entry_cmp (hol->entries + i, hol->entries + k); + if (((cmp1 < 0 && cmp2 <= 0) || (cmp1 <= 0 && cmp2 < 0)) && !(cmp3 < 0)) + fprintf (stderr, "hol_sort: transitivity violated for [%u] [%u] [%u]\n", i, j, k); + } qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry), hol_entry_qcmp); + fprintf (stderr, "hol_sort: sort result:\n"); + for (i = 0; i < hol->num_entries; i++) + fprintf (stderr, " [%u] <- [%u]\n", i, hol->entries[i].ord); + fprintf (stderr, "hol_sort: compare after sort:\n"); + for (i = 1; i < hol->num_entries; i++) + { + int cmp = hol_entry_cmp (hol->entries + i-1, hol->entries + i); + fprintf (stderr, cmp > 0 ? " +" : cmp < 0 ? " -" : " ."); + } + fprintf (stderr, "\n"); } }