1 /************************** toolbox/list.c *************************************
3 Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
5 See file COPYRIGHT for information on usage and disclaimer of warranties
7 Not documented, see chain.h.
9 Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
11 Last Change: 1996/10/03
13 *******************************************************************************/
23 void list_init (list *l, int nodeoffset)
27 l->nodeoffset = nodeoffset;
30 void list_addlast (list *l, void *element)
32 listnode *n = (listnode*) ( ((char*) element) + l->nodeoffset );
48 void list_addfirst (list *l, void *element)
50 listnode *n = (listnode*) ( ((char*) element) + l->nodeoffset );
67 void list_remove (list *l, void *element)
69 listnode *n = (listnode*) ( ((char*) element) + l->nodeoffset );
71 if (n->next) n->next->prev = n->prev;
72 else l->last = n->prev;
73 if (n->prev) n->prev->next = n->next;
74 else l->first = n->next;
78 void *list_first (list *l)
80 if (!l->first) return NULL;
81 return ((char*) l->first) - l->nodeoffset;
85 void *list_last (list *l)
87 if (!l->last) return NULL;
88 return ((char*) l->last) - l->nodeoffset;
92 void *list_next (list *l, void *element)
95 n = (listnode*) ( ((char*) element) + l->nodeoffset );
96 if (!n->next) return NULL;
97 return ((char*) n->next) - l->nodeoffset;
101 void *list_prev (list *l, void *element)
104 n = (listnode*) ( ((char*) element) + l->nodeoffset );
105 if (!n->prev) return NULL;
106 return ((char*) n->prev) - l->nodeoffset;