Mercurial > hg > toybox
view lib/llist.c @ 293:6baa13382880
Sort was including the trailing comma and getting the order wrong.
(Specifically, it was comparing "sh," with "sha1sum," and putting sha1sum first
in generated/newtoys.h so the binary search wasn't finding sha1sum. Alas, you
can't feed separate beginning and ending delimiters to "sort -t". The fix is
to copy the appropriate field out with sed, duplicate it at the start of the
string where it's easy to compare, and then remove it again with a second
sed after the sort.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 12 May 2008 01:23:19 -0500 |
parents | 630b2e12db16 |
children | aaac01796688 |
line wrap: on
line source
/* vi: set sw=4 ts=4 : * llist.c - Linked list functions * * Linked list structures have a next pointer as their first element. */ #include "toys.h" // Free all the elements of a linked list // if freeit!=NULL call freeit() on each element before freeing it. void llist_free(void *list, void (*freeit)(void *data)) { while (list) { void *pop = llist_pop(&list); if (freeit) freeit(pop); } } // Return the first item from the list, advancing the list (which must be called // as &list) void *llist_pop(void *list) { // I'd use a void ** for the argument, and even accept the typecast in all // callers as documentation you need the &, except the stupid compiler // would then scream about type-punned pointers. Screw it. void **llist = (void **)list; void **next = (void **)*llist; *llist = *next; return (void *)next; } // Add an entry to the end off a doubly linked list void dlist_add(struct double_list **list, char *data) { struct double_list *line = xmalloc(sizeof(struct double_list)); line->data = data; if (*list) { line->next = *list; line->prev = (*list)->prev; (*list)->prev->next = line; (*list)->prev = line; } else *list = line->next = line->prev = line; }