1 /*
2   $Log: lists.h,v $
3   Revision 1.2  2000/10/10 08:50:01  ivo
4   some annotation for lclint
5 
6   Revision 1.1  1997/08/04 21:05:32  walter
7   Initial revision
8 
9 */
10 
11 #ifndef	__LIST_H
12 #define	__LIST_H
13 
14 /*---------------------- Macros and type definitions ----------------------*/
15 
16 typedef struct LST_BUCKET {
17   struct LST_BUCKET *next;
18 }
19 LST_BUCKET;
20 
21 typedef struct {
22   int count;			/* Number of elements currently in list */
23   LST_BUCKET *head;		/* Pointer to head element of list      */
24   LST_BUCKET *z;		/* Pointer to last node of list         */
25   LST_BUCKET hz[2];		/* Space for head and z nodes           */
26 }
27 LIST;
28 
29 /* Return a pointer to the user space given the address of the header of
30  * a node.
31  */
32 
33 #define	LST_USERSPACE(h)	((void*)((LST_BUCKET*)(h) + 1))
34 
35 /* Return a pointer to the header of a node, given the address of the
36  * user space.
37  */
38 
39 #define	LST_HEADER(n)		((LST_BUCKET*)(n) - 1)
40 
41 /* Return a pointer to the user space of the list's head node. This user
42  * space does not actually exist, but it is useful to be able to address
43  * it to enable insertion at the start of the list.
44  */
45 
46 #define	LST_HEAD(l)		LST_USERSPACE((l)->head)
47 
48 /* Determine if a list is empty
49  */
50 
51 #define	LST_EMPTY(l)		((l)->count == 0)
52 
53 /*-------------------------- Function Prototypes --------------------------*/
54 
55 /*@only@*//*@out@*/ void *lst_newnode (int size);
56 void lst_freenode (/*@only@*/ void *node);
57 /*@only@*//*@out@*/  LIST *lst_init (void);
58 void lst_kill (LIST * l, void (*freeNode) ());
59 void lst_insertafter (LIST * l, /*@keep@*/ void *node, void *after);
60 void *lst_deletenext (/*@only@*/ LIST * l, void *node);
61 /*@dependent@*/ void *lst_first (LIST * l);
62 /*@dependent@*/ void *lst_next (void *prev);
63 void lst_mergesort (LIST * l, int (*cmp_func) ());
64 
65 #endif
66