1 /* Skippy - Seduces Kids Into Perversion
3 * Copyright (C) 2004 Hyriand <hyriand@thegraveyard.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
39 dlist_add(dlist *l, void *d)
44 new_elem = malloc(sizeof(dlist));
54 dlist_prepend(dlist *l, void *d)
58 new_elem = malloc(sizeof(dlist));
68 dlist_remove(dlist *l)
77 l->prev->next = l->next;
81 l->next->prev = l->prev;
88 dlist_remove_free_data(dlist *l)
92 return dlist_remove(l);
96 dlist_remove_nth(dlist *l, unsigned int n)
98 return dlist_remove(dlist_nth(l, n));
102 dlist_remove_nth_free_data(dlist *l, unsigned int n)
104 return dlist_remove_free_data(dlist_nth(l, n));
108 dlist_same(dlist *l1, dlist *l2)
110 l1 = dlist_first(l1);
120 dlist_reverse(dlist *l)
122 dlist *iter1 = dlist_first(l),
123 *iter2 = dlist_last(l);
125 while(iter1 != iter2) {
126 dlist_swap(iter1, iter2);
127 if(iter1->next == iter2)
155 n = dlist_add(n, l->data);
163 dlist_find_all(dlist *l, dlist_match_func match, void *data)
170 n = dlist_add(n, l->data);
178 dlist_find(dlist *l, dlist_match_func func, void *data)
180 for(l = dlist_first(l); l; l = l->next)
187 dlist_find_data(dlist *l, void *data)
189 for(l = dlist_first(l); l; l = l->next)
196 dlist_free_data(dlist *l)
209 dlist_free_with_data(dlist *l)
225 dlist_free_with_func(dlist *l, dlist_free_func func)
255 dlist_nth(dlist *l, unsigned int n)
268 dlist_swap(dlist *l1, dlist *l2)
270 void *tmp = l1->data;
276 dlist_sort(dlist *l, dlist_cmp_func cmp, void *data)
278 dlist *start = dlist_first(l);
283 if(iter->next && cmp(iter, iter->next, data) == 1) {
284 dlist_swap(iter, iter->next);