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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 void listh_init(ListHead *head)
24 head->head = head->tail = NULL;
28 void listh_prepend(ListHead *head, List *list)
31 list->next = head->head;
33 head->head->prev = list;
40 void listh_append(ListHead *head, List *list)
43 list->prev = head->tail;
45 head->tail->next = list;
52 void listh_add_before(ListHead *head, List *at, List *list)
54 if(at == head->head || head->head == NULL)
55 listh_prepend(head, list);
58 list->prev = at->prev;
64 void listh_add_after(ListHead *head, List *at, List *list)
66 if(at == head->tail || !head->tail)
67 listh_append(head, list);
70 list->next = at->next;
76 void listh_remove(ListHead *head, List *list)
78 if(list == head->head) {
79 head->head = list->next;
81 head->head->prev = NULL;
82 } else if(list == head->tail) {
83 head->tail = list->prev;
85 head->tail->next = NULL;
87 list->next->prev = list->prev;
88 list->prev->next = list->next;
90 if(--head->count == 0)
91 head->head = head->tail = NULL;
94 void listh_concat(ListHead *h1, ListHead *h2)
98 else if(h1->tail == NULL)
101 h1->tail->next = h2->head;
102 h2->head->prev = h1->tail;
105 h1->count += h2->count;
108 void listh_catcon(ListHead *h1, ListHead *h2)
112 else if(h1->head == NULL)
115 h1->head->prev = h2->tail;
116 h2->tail->next = h1->head;
119 h1->count += h2->count;