xref: /csrg-svn/usr.bin/make/lst.lib/lstInt.h (revision 69095)
140420Sbostic /*
262091Sbostic  * Copyright (c) 1988, 1989, 1990, 1993
362091Sbostic  *	The Regents of the University of California.  All rights reserved.
440419Sbostic  *
540420Sbostic  * This code is derived from software contributed to Berkeley by
640420Sbostic  * Adam de Boor.
740419Sbostic  *
842741Sbostic  * %sccs.include.redist.c%
940419Sbostic  *
10*69095Schristos  *	@(#)lstInt.h	8.2 (Berkeley) 04/28/95
1140419Sbostic  */
1240420Sbostic 
1340420Sbostic /*-
1440420Sbostic  * lstInt.h --
1540420Sbostic  *	Internals for the list library
1640420Sbostic  */
1740419Sbostic #ifndef _LSTINT_H_
1840419Sbostic #define _LSTINT_H_
1940419Sbostic 
2040419Sbostic #include	  "lst.h"
2140419Sbostic 
2240419Sbostic typedef struct ListNode {
2340419Sbostic 	struct ListNode	*prevPtr;   /* previous element in list */
2440419Sbostic 	struct ListNode	*nextPtr;   /* next in list */
2540419Sbostic 	short	    	useCount:8, /* Count of functions using the node.
2640419Sbostic 				     * node may not be deleted until count
2740419Sbostic 				     * goes to 0 */
2840419Sbostic  	    	    	flags:8;    /* Node status flags */
2940419Sbostic 	ClientData	datum;	    /* datum associated with this element */
3040419Sbostic } *ListNode;
3140419Sbostic /*
3240419Sbostic  * Flags required for synchronization
3340419Sbostic  */
3440419Sbostic #define LN_DELETED  	0x0001      /* List node should be removed when done */
3540419Sbostic 
3640419Sbostic #define NilListNode	((ListNode)-1)
3740419Sbostic 
3840419Sbostic typedef enum {
3940419Sbostic     Head, Middle, Tail, Unknown
4040419Sbostic } Where;
4140419Sbostic 
4240419Sbostic typedef struct	{
4340419Sbostic 	ListNode  	firstPtr; /* first node in list */
4440419Sbostic 	ListNode  	lastPtr;  /* last node in list */
4540419Sbostic 	Boolean	  	isCirc;	  /* true if the list should be considered
4640419Sbostic 				   * circular */
4740419Sbostic /*
4840419Sbostic  * fields for sequential access
4940419Sbostic  */
5040419Sbostic 	Where	  	atEnd;	  /* Where in the list the last access was */
5140419Sbostic 	Boolean	  	isOpen;	  /* true if list has been Lst_Open'ed */
5240419Sbostic 	ListNode  	curPtr;	  /* current node, if open. NilListNode if
5340419Sbostic 				   * *just* opened */
5440419Sbostic 	ListNode  	prevPtr;  /* Previous node, if open. Used by
5540419Sbostic 				   * Lst_Remove */
5640419Sbostic } *List;
5740419Sbostic 
5840419Sbostic #define NilList	  	((List)-1)
5940419Sbostic 
6040419Sbostic /*
6140419Sbostic  * PAlloc (var, ptype) --
6240419Sbostic  *	Allocate a pointer-typedef structure 'ptype' into the variable 'var'
6340419Sbostic  */
6445853Sbostic #define	PAlloc(var,ptype)	var = (ptype) malloc (sizeof (*var))
6540419Sbostic 
6640419Sbostic /*
6740419Sbostic  * LstValid (l) --
6840419Sbostic  *	Return TRUE if the list l is valid
6940419Sbostic  */
7040419Sbostic #define LstValid(l)	(((Lst)l == NILLST) ? FALSE : TRUE)
7140419Sbostic 
7240419Sbostic /*
7340419Sbostic  * LstNodeValid (ln, l) --
7440419Sbostic  *	Return TRUE if the LstNode ln is valid with respect to l
7540419Sbostic  */
7640419Sbostic #define LstNodeValid(ln, l)	((((LstNode)ln) == NILLNODE) ? FALSE : TRUE)
7740419Sbostic 
7840419Sbostic /*
7940419Sbostic  * LstIsEmpty (l) --
8040419Sbostic  *	TRUE if the list l is empty.
8140419Sbostic  */
8240419Sbostic #define LstIsEmpty(l)	(((List)l)->firstPtr == NilListNode)
8340419Sbostic 
8440419Sbostic #endif _LSTINT_H_
85