xref: /original-bsd/usr.bin/make/lst.lib/lstInt.h (revision a9392a99)
1 /*
2  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Adam de Boor.
7  *
8  * Redistribution and use in source and binary forms are permitted
9  * provided that the above copyright notice and this paragraph are
10  * duplicated in all such forms and that any documentation,
11  * advertising materials, and other materials related to such
12  * distribution and use acknowledge that the software was developed
13  * by the University of California, Berkeley.  The name of the
14  * University may not be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  *	@(#)lstInt.h	5.2 (Berkeley) 03/12/90
21  */
22 
23 /*-
24  * lstInt.h --
25  *	Internals for the list library
26  */
27 #ifndef _LSTINT_H_
28 #define _LSTINT_H_
29 
30 #include	  "lst.h"
31 
32 typedef struct ListNode {
33 	struct ListNode	*prevPtr;   /* previous element in list */
34 	struct ListNode	*nextPtr;   /* next in list */
35 	short	    	useCount:8, /* Count of functions using the node.
36 				     * node may not be deleted until count
37 				     * goes to 0 */
38  	    	    	flags:8;    /* Node status flags */
39 	ClientData	datum;	    /* datum associated with this element */
40 } *ListNode;
41 /*
42  * Flags required for synchronization
43  */
44 #define LN_DELETED  	0x0001      /* List node should be removed when done */
45 
46 #define NilListNode	((ListNode)-1)
47 
48 typedef enum {
49     Head, Middle, Tail, Unknown
50 } Where;
51 
52 typedef struct	{
53 	ListNode  	firstPtr; /* first node in list */
54 	ListNode  	lastPtr;  /* last node in list */
55 	Boolean	  	isCirc;	  /* true if the list should be considered
56 				   * circular */
57 /*
58  * fields for sequential access
59  */
60 	Where	  	atEnd;	  /* Where in the list the last access was */
61 	Boolean	  	isOpen;	  /* true if list has been Lst_Open'ed */
62 	ListNode  	curPtr;	  /* current node, if open. NilListNode if
63 				   * *just* opened */
64 	ListNode  	prevPtr;  /* Previous node, if open. Used by
65 				   * Lst_Remove */
66 } *List;
67 
68 #define NilList	  	((List)-1)
69 
70 /*
71  * PAlloc (var, ptype) --
72  *	Allocate a pointer-typedef structure 'ptype' into the variable 'var'
73  */
74 #define	PAlloc(var,ptype)	var = (ptype) Malloc (sizeof (*var))
75 
76 /*
77  * LstValid (l) --
78  *	Return TRUE if the list l is valid
79  */
80 #define LstValid(l)	(((Lst)l == NILLST) ? FALSE : TRUE)
81 
82 /*
83  * LstNodeValid (ln, l) --
84  *	Return TRUE if the LstNode ln is valid with respect to l
85  */
86 #define LstNodeValid(ln, l)	((((LstNode)ln) == NILLNODE) ? FALSE : TRUE)
87 
88 /*
89  * LstIsEmpty (l) --
90  *	TRUE if the list l is empty.
91  */
92 #define LstIsEmpty(l)	(((List)l)->firstPtr == NilListNode)
93 
94 #endif _LSTINT_H_
95