2 * Copyright (C) 2000-2005 Erik Edelmann <Erik.Edelmann@iki.fi>
4 * This program is free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License version 2 as published by the Free Software
9 * This program is distributed in the hope that it will be
10 * useful, but WITHOUT ANY WARRANTY; without even the implied
11 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the GNU General Public License for more
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the Free
17 * Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307 USA
27 List
*list_find (List
*l
, const void *data
,
28 int (*cmpfunc
)(const void *, const void *))
30 * If data matching 's' is found, return it's address. If no such data is
33 * 'cmpfunc' should return 0 for equal, non 0 for unequal
40 for (h
= l
; h
; h
= h
->next
)
41 if (cmpfunc(data
, h
->data
) == 0) return h
;
47 List
*list_prepend (List
*l
, void *data
)
49 * Prepend 'data' to 'l', return address to the updated list.
54 new = (List
*) xmalloc(sizeof(List
));
61 List
*list_append (List
*l
, void *data
)
63 * Append 'data' to 'l', return address to the updated list. This function is
64 * slower than 'list_prepend', use only when ordering is important.
69 new = (List
*) xmalloc(sizeof(List
));
76 for (h
= l
; h
->next
; h
= h
->next
) ;
83 void list_free (List
*l
)
95 List
*list_remove (List
*l
, List
*node
)
96 /* Remove 'node' from 'l'. Return address of the new updated list */
105 while (h
!= node
&& h
!= NULL
) {
115 hold
->next
= h
->next
;
123 int list_length (const List
*l
)
128 for (h
= l
; h
; h
= h
->next
) n
++;