2 * Copyright (C) 2000, Matias Atria
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 void listh_init(ListHead *head)
23 head->head = head->tail = NULL;
27 void listh_prepend(ListHead *head, List *list)
30 list->next = head->head;
32 head->head->prev = list;
39 void listh_append(ListHead *head, List *list)
42 list->prev = head->tail;
44 head->tail->next = list;
51 void listh_add_before(ListHead *head, List *at, List *list)
53 if(at == head->head || head->head == NULL)
54 listh_prepend(head, list);
57 list->prev = at->prev;
63 void listh_add_after(ListHead *head, List *at, List *list)
65 if(at == head->tail || !head->tail)
66 listh_append(head, list);
69 list->next = at->next;
75 void listh_remove(ListHead *head, List *list)
77 if(list == head->head) {
78 head->head = list->next;
80 head->head->prev = NULL;
81 } else if(list == head->tail) {
82 head->tail = list->prev;
84 head->tail->next = NULL;
86 list->next->prev = list->prev;
87 list->prev->next = list->next;
89 if(--head->count == 0)
90 head->head = head->tail = NULL;
93 void listh_concat(ListHead *h1, ListHead *h2)
97 else if(h1->tail == NULL)
100 h1->tail->next = h2->head;
101 h2->head->prev = h1->tail;
104 h1->count += h2->count;
107 void listh_catcon(ListHead *h1, ListHead *h2)
111 else if(h1->head == NULL)
114 h1->head->prev = h2->tail;
115 h2->tail->next = h1->head;
118 h1->count += h2->count;