]> mj.ucw.cz Git - libucw.git/blob - lib/lists.c
Added "name" parameter to obj_fload in order to get better error reporting
[libucw.git] / lib / lists.c
1 /*
2  *      Sherlock Library -- Linked Lists
3  *
4  *      (c) 1997 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
5  */
6
7 #include <stdio.h>
8
9 #include "lists.h"
10
11 void
12 add_tail(list *l, node *n)
13 {
14   node *z = l->tail.prev;
15
16   n->next = &l->tail;
17   n->prev = z;
18   z->next = n;
19   l->tail.prev = n;
20 }
21
22 void
23 add_head(list *l, node *n)
24 {
25   node *z = l->head.next;
26
27   n->next = z;
28   n->prev = &l->head;
29   z->prev = n;
30   l->head.next = n;
31 }
32
33 void
34 insert_node(node *n, node *after)
35 {
36   node *z = after->next;
37
38   n->next = z;
39   n->prev = after;
40   after->next = n;
41   z->prev = n;
42 }
43
44 void
45 rem_node(node *n)
46 {
47   node *z = n->prev;
48   node *x = n->next;
49
50   z->next = x;
51   x->prev = z;
52 }
53
54 void
55 init_list(list *l)
56 {
57   l->head.next = &l->tail;
58   l->head.prev = NULL;
59   l->tail.next = NULL;
60   l->tail.prev = &l->head;
61 }
62
63 void
64 add_tail_list(list *to, list *l)
65 {
66   node *p = to->tail.prev;
67   node *q = l->head.next;
68
69   p->next = q;
70   q->prev = p;
71   q = l->tail.prev;
72   q->next = &to->tail;
73   to->tail.prev = q;
74 }