From 45b33b463c8acc2c0ff37e209387d6b664576cc4 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Mon, 14 Feb 2011 23:22:56 -0800 Subject: Sort contents of encodings.dir Allows easier comparison between builds to detect changes. Helps reduce deltas in packaging systems that compare old & new versions. Signed-off-by: Alan Coopersmith --- list.c | 34 ++++++++++++++++++++++++++++++++++ list.h | 1 + mkfontscale.c | 1 + 3 files changed, 36 insertions(+) diff --git a/list.c b/list.c index cdedb89..fdf81d3 100644 --- a/list.c +++ b/list.c @@ -217,6 +217,40 @@ reverseList(ListPtr old) return new; } +/* qsort helper for sorting list entries */ +static int +compareListEntries(const void *a, const void *b) +{ + const ListPtr lista = *(const ListPtr *) a; + const ListPtr listb = *(const ListPtr *) b; + + return strcmp(lista->value, listb->value); +} + +ListPtr +sortList(ListPtr old) +{ + int i; + int l = listLength(old); + ListPtr n; + ListPtr *sorted = malloc(l * sizeof(ListPtr)); + + if (sorted == NULL) + return old; + + for (n = old, i = 0; n != NULL; n = n->next) { + sorted[i++] = n; + } + qsort(sorted, i, sizeof(ListPtr), compareListEntries); + n = sorted[0]; + for (i = 0; i < (l - 1); i++) { + sorted[i]->next = sorted[i+1]; + } + sorted[i]->next = NULL; + free(sorted); + return n; +} + void destroyList(ListPtr old) { diff --git a/list.h b/list.h index 4e4bb27..463933d 100644 --- a/list.h +++ b/list.h @@ -39,6 +39,7 @@ int listLength(ListPtr list); ListPtr appendList(ListPtr first, ListPtr second); ListPtr makeList(char **a, int n, ListPtr old, int begin); ListPtr reverseList(ListPtr old); +ListPtr sortList(ListPtr old); void destroyList(ListPtr old); void deepDestroyList(ListPtr old); diff --git a/mkfontscale.c b/mkfontscale.c index ea4cd27..ef3f490 100644 --- a/mkfontscale.c +++ b/mkfontscale.c @@ -978,6 +978,7 @@ doDirectory(char *dirname_given, int numEncodings, ListPtr encodingsToDo) exit(1); } fprintf(encfile, "%d\n", numEncodings); + encodingsToDo = sortList(encodingsToDo); for(lp = encodingsToDo; lp; lp = lp->next) { fprintf(encfile, "%s\n", lp->value); } -- cgit v1.2.3