summaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2011-02-14 23:22:56 -0800
committerAlan Coopersmith <alan.coopersmith@oracle.com>2011-02-14 23:22:56 -0800
commit45b33b463c8acc2c0ff37e209387d6b664576cc4 (patch)
treeed9b8d21930c29c15ca4f5ba166f7a5105b489af /list.c
parent623a620bde1988e105b2fe814a3158da0e7b863c (diff)
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 <alan.coopersmith@oracle.com>
Diffstat (limited to 'list.c')
-rw-r--r--list.c34
1 files changed, 34 insertions, 0 deletions
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)
{