comparison lib/llist.c @ 315:aaac01796688

Upgrade patch to detect hunks that start after a false start. Imagine a hunk that starts with a blank line, but the site to patch starts with two blank lines. Before we'd read the first blank line, think it was the start of the hunk and buffer it, read the second blank line, notice that it didn't match the second line of the hunk, and discard _both_ buffered lines of context (writing them to the output file) without checking that one of the later context lines might have been the real start of the hunk. Make it re-check the rest of the buffered context for matches each time it discards a line of buffered context.
author Rob Landley <rob@landley.net>
date Thu, 23 Oct 2008 16:44:30 -0500
parents 630b2e12db16
children f1e9da78c5dd
comparison
equal deleted inserted replaced
314:5ab9d0e5e0f8 315:aaac01796688
12 void llist_free(void *list, void (*freeit)(void *data)) 12 void llist_free(void *list, void (*freeit)(void *data))
13 { 13 {
14 while (list) { 14 while (list) {
15 void *pop = llist_pop(&list); 15 void *pop = llist_pop(&list);
16 if (freeit) freeit(pop); 16 if (freeit) freeit(pop);
17 else free(pop);
18
19 // End doubly linked list too.
20 if (list==pop) break;
17 } 21 }
18 } 22 }
19 23
20 // Return the first item from the list, advancing the list (which must be called 24 // Return the first item from the list, advancing the list (which must be called
21 // as &list) 25 // as &list)
30 34
31 return (void *)next; 35 return (void *)next;
32 } 36 }
33 37
34 // Add an entry to the end off a doubly linked list 38 // Add an entry to the end off a doubly linked list
35 void dlist_add(struct double_list **list, char *data) 39 struct double_list *dlist_add(struct double_list **list, char *data)
36 { 40 {
37 struct double_list *line = xmalloc(sizeof(struct double_list)); 41 struct double_list *line = xmalloc(sizeof(struct double_list));
38 42
39 line->data = data; 43 line->data = data;
40 if (*list) { 44 if (*list) {
41 line->next = *list; 45 line->next = *list;
42 line->prev = (*list)->prev; 46 line->prev = (*list)->prev;
43 (*list)->prev->next = line; 47 (*list)->prev->next = line;
44 (*list)->prev = line; 48 (*list)->prev = line;
45 } else *list = line->next = line->prev = line; 49 } else *list = line->next = line->prev = line;
50
51 return line;
46 } 52 }