From 45ff8de009ed0740a4a68d8d90168e31944646fb Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 1 Nov 2021 17:38:51 +0000 Subject: str_list_uniqify: keep ordering, so kpsewhich -a and kpsewhich are consistent git-svn-id: svn://tug.org/texlive/trunk@60918 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/kpathsea/ChangeLog | 7 ++++++ Build/source/texk/kpathsea/str-list.c | 46 +++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog index 31cbe14b140..44b6f5cb957 100644 --- a/Build/source/texk/kpathsea/ChangeLog +++ b/Build/source/texk/kpathsea/ChangeLog @@ -1,3 +1,10 @@ +2021-11-01 Marcel Fabian Krueger + + * str-list.c (str_list_uniqify): compare each input element + against the elements to be returned, to keep the ordering of the + result the same as the input. Then the first result in a list + from kpsewhich -a will be the same as the result of just kpsewhich. + 2021-05-14 Karl Berry * texmf.cnf (TEXINPUTS.optex): new definition for new format. diff --git a/Build/source/texk/kpathsea/str-list.c b/Build/source/texk/kpathsea/str-list.c index 676aaa0ad26..96fa210b3af 100644 --- a/Build/source/texk/kpathsea/str-list.c +++ b/Build/source/texk/kpathsea/str-list.c @@ -128,20 +128,28 @@ str_list_uniqify (str_list_type *l) for (e = 0; e < STR_LIST_LENGTH (*l); e++) { string elt1 = STR_LIST_ELT (*l, e); + /* printf ("outer l[%d]: %s\n", e, elt1); */ + + /* Compare against known-unique list ret; this keeps the elements in + the return list in the same order as the input list. */ unsigned f; - for (f = e + 1; f < STR_LIST_LENGTH (*l); f++) { - string elt2 = STR_LIST_ELT (*l, f); - /* I don't think our list should ever contain NULL's, but if - it does, let it stay and don't bother collapsing multiple + for (f = 0; f < STR_LIST_LENGTH (ret); f++) { + string elt2 = STR_LIST_ELT (ret, f); + /* printf(" inner ret[%d]: %s\n", f, elt2); */ + + /* I don't think our lists should ever contain NULL's, but if + it does, let them stay and don't bother collapsing multiple NULL's into one. */ if (FILESTRCASEEQ (elt1, elt2)) { break; } } - if (f == STR_LIST_LENGTH (*l)) { + if (f == STR_LIST_LENGTH (ret)) { + /* printf (" added new\n"); */ str_list_add (&ret, elt1); /* not found */ } else { + /* printf (" skipped duplicate\n"); */ free (elt1); /* duplicate, forget this one */ } } @@ -149,3 +157,31 @@ str_list_uniqify (str_list_type *l) /* Replace the passed list with what we constructed. */ *l = ret; } + +#ifdef TEST +int +main () +{ + unsigned e; + str_list_type tst = str_list_init (); + str_list_add (&tst, xstrdup("a")); + str_list_add (&tst, xstrdup("a")); + str_list_add (&tst, xstrdup("b")); + str_list_add (&tst, xstrdup("a")); + str_list_uniqify (&tst); + + for (e = 0; e < STR_LIST_LENGTH (tst); e++) { + printf ("ret[%d]: %s\n", e, STR_LIST_ELT(tst, e)); + } + + return 0; +} + +#endif /* TEST */ + + +/* +Local variables: +standalone-compile-command: "gcc -g -I. -I.. -I$WK -DTEST -DMAKE_KPSE_DLL str-list.c $wk/.libs/libkpathsea.a" +End: +*/ -- cgit v1.2.3