diff options
-rw-r--r-- | lib/lib.h | 6 | ||||
-rw-r--r-- | lib/llist.c | 14 | ||||
-rw-r--r-- | toys/patch.c | 14 |
3 files changed, 18 insertions, 16 deletions
@@ -8,8 +8,6 @@ ssize_t getline(char **lineptr, size_t *n, FILE *stream); // llist.c -void llist_free(void *list, void (*freeit)(void *data)); -void *llist_pop(void *list); // actually void **list, but the compiler's dumb struct string_list { struct string_list *next; @@ -27,6 +25,10 @@ struct double_list { char *data; }; +void llist_free(void *list, void (*freeit)(void *data)); +void *llist_pop(void *list); // actually void **list, but the compiler's dumb +void dlist_add(struct double_list **list, char *data); + // args.c void get_optflags(void); diff --git a/lib/llist.c b/lib/llist.c index 8d6fd265..4f9bc220 100644 --- a/lib/llist.c +++ b/lib/llist.c @@ -30,3 +30,17 @@ void *llist_pop(void *list) 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; +} diff --git a/toys/patch.c b/toys/patch.c index 34d33c79..612b572b 100644 --- a/toys/patch.c +++ b/toys/patch.c @@ -70,20 +70,6 @@ static void do_line(void *data) free(dlist->data); } - -static 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; -} - static void finish_oldfile(void) { if (TT.tempname) replace_tempfile(TT.filein, TT.fileout, &TT.tempname); |