xref: /original-bsd/usr.bin/make/lst.lib/lstInt.h (revision e8af0247)
1 /*
2  * Copyright (c) 1988, 1989, 1990, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Adam de Boor.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)lstInt.h	8.2 (Berkeley) 04/28/95
11  */
12 
13 /*-
14  * lstInt.h --
15  *	Internals for the list library
16  */
17 #ifndef _LSTINT_H_
18 #define _LSTINT_H_
19 
20 #include	  "lst.h"
21 
22 typedef struct ListNode {
23 	struct ListNode	*prevPtr;   /* previous element in list */
24 	struct ListNode	*nextPtr;   /* next in list */
25 	short	    	useCount:8, /* Count of functions using the node.
26 				     * node may not be deleted until count
27 				     * goes to 0 */
28  	    	    	flags:8;    /* Node status flags */
29 	ClientData	datum;	    /* datum associated with this element */
30 } *ListNode;
31 /*
32  * Flags required for synchronization
33  */
34 #define LN_DELETED  	0x0001      /* List node should be removed when done */
35 
36 #define NilListNode	((ListNode)-1)
37 
38 typedef enum {
39     Head, Middle, Tail, Unknown
40 } Where;
41 
42 typedef struct	{
43 	ListNode  	firstPtr; /* first node in list */
44 	ListNode  	lastPtr;  /* last node in list */
45 	Boolean	  	isCirc;	  /* true if the list should be considered
46 				   * circular */
47 /*
48  * fields for sequential access
49  */
50 	Where	  	atEnd;	  /* Where in the list the last access was */
51 	Boolean	  	isOpen;	  /* true if list has been Lst_Open'ed */
52 	ListNode  	curPtr;	  /* current node, if open. NilListNode if
53 				   * *just* opened */
54 	ListNode  	prevPtr;  /* Previous node, if open. Used by
55 				   * Lst_Remove */
56 } *List;
57 
58 #define NilList	  	((List)-1)
59 
60 /*
61  * PAlloc (var, ptype) --
62  *	Allocate a pointer-typedef structure 'ptype' into the variable 'var'
63  */
64 #define	PAlloc(var,ptype)	var = (ptype) malloc (sizeof (*var))
65 
66 /*
67  * LstValid (l) --
68  *	Return TRUE if the list l is valid
69  */
70 #define LstValid(l)	(((Lst)l == NILLST) ? FALSE : TRUE)
71 
72 /*
73  * LstNodeValid (ln, l) --
74  *	Return TRUE if the LstNode ln is valid with respect to l
75  */
76 #define LstNodeValid(ln, l)	((((LstNode)ln) == NILLNODE) ? FALSE : TRUE)
77 
78 /*
79  * LstIsEmpty (l) --
80  *	TRUE if the list l is empty.
81  */
82 #define LstIsEmpty(l)	(((List)l)->firstPtr == NilListNode)
83 
84 #endif _LSTINT_H_
85