| 1 |
|
/* slist.c -- generalised singly linked lists |
| 2 |
|
|
| 3 |
< |
Copyright (C) 2000, 2004, 2007, 2008 Free Software Foundation, Inc. |
| 3 |
> |
Copyright (C) 2000, 2004, 2007-2009, 2011-2014 Free Software |
| 4 |
> |
Foundation, Inc. |
| 5 |
|
Written by Gary V. Vaughan, 2000 |
| 6 |
|
|
| 7 |
|
NOTE: The canonical source of this file is maintained with the |
| 32 |
|
#include <assert.h> |
| 33 |
|
|
| 34 |
|
#include "slist.h" |
| 35 |
< |
#include <stddef.h> |
| 35 |
> |
#include <stdlib.h> |
| 36 |
|
|
| 37 |
|
static SList * slist_sort_merge (SList *left, SList *right, |
| 38 |
|
SListCompare *compare, void *userdata); |
| 74 |
|
the stale item, you should probably return that from FIND if |
| 75 |
|
it makes a successful match. Don't forget to slist_unbox() |
| 76 |
|
every item in a boxed list before operating on its contents. */ |
| 77 |
< |
void * |
| 77 |
> |
SList * |
| 78 |
|
slist_remove (SList **phead, SListCallback *find, void *matchdata) |
| 79 |
|
{ |
| 80 |
|
SList *stale = 0; |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
< |
return result; |
| 111 |
> |
return (SList *) result; |
| 112 |
|
} |
| 113 |
|
|
| 114 |
|
/* Call FIND repeatedly with each element of SLIST and MATCHDATA, until |
| 230 |
|
next = slist->next; |
| 231 |
|
slist->next = result; |
| 232 |
|
result = slist; |
| 233 |
< |
slist = next; |
| 233 |
> |
slist = next; |
| 234 |
|
} |
| 235 |
|
|
| 236 |
|
return result; |
| 315 |
|
left = slist; |
| 316 |
|
right = slist->next; |
| 317 |
|
|
| 318 |
+ |
if (!right) |
| 319 |
+ |
return left; |
| 320 |
+ |
|
| 321 |
|
/* Skip two items with RIGHT and one with SLIST, until RIGHT falls off |
| 322 |
|
the end. SLIST must be about half way along. */ |
| 323 |
|
while (right && (right = right->next)) |
| 345 |
|
used for the boxes. It us usually a very bad idea to mix boxed and |
| 346 |
|
non-boxed items in a single list. */ |
| 347 |
|
|
| 348 |
< |
/* Return a `boxed' freshly mallocated 1 element list containing |
| 348 |
> |
/* Return a 'boxed' freshly mallocated 1 element list containing |
| 349 |
|
USERDATA. */ |
| 350 |
|
SList * |
| 351 |
|
slist_box (const void *userdata) |
| 361 |
|
return item; |
| 362 |
|
} |
| 363 |
|
|
| 364 |
< |
/* Return the contents of a `boxed' ITEM, recycling the box itself. */ |
| 364 |
> |
/* Return the contents of a 'boxed' ITEM, recycling the box itself. */ |
| 365 |
|
void * |
| 366 |
|
slist_unbox (SList *item) |
| 367 |
|
{ |