Merge illumos-gate
[unleashed.git] / bin / make / lst.lib / lstInt.h
blobac53dcb67d7750863fa77c32982c54bc7db40ea5
1 /* $NetBSD: lstInt.h,v 1.22 2014/09/07 20:55:34 joerg Exp $ */
3 /*
4 * Copyright (c) 1988, 1989, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Adam de Boor.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * from: @(#)lstInt.h 8.1 (Berkeley) 6/6/93
37 /*-
38 * lstInt.h --
39 * Internals for the list library
41 #ifndef _LSTINT_H_
42 #define _LSTINT_H_
44 #include "../lst.h"
45 #include "../make_malloc.h"
47 typedef struct ListNode {
48 struct ListNode *prevPtr; /* previous element in list */
49 struct ListNode *nextPtr; /* next in list */
50 unsigned int useCount:8, /* Count of functions using the node.
51 * node may not be deleted until count
52 * goes to 0 */
53 flags:8; /* Node status flags */
54 void *datum; /* datum associated with this element */
55 } *ListNode;
57 * Flags required for synchronization
59 #define LN_DELETED 0x0001 /* List node should be removed when done */
61 typedef enum {
62 Head, Middle, Tail, Unknown
63 } Where;
65 typedef struct List {
66 ListNode firstPtr; /* first node in list */
67 ListNode lastPtr; /* last node in list */
68 Boolean isCirc; /* true if the list should be considered
69 * circular */
71 * fields for sequential access
73 Where atEnd; /* Where in the list the last access was */
74 Boolean isOpen; /* true if list has been Lst_Open'ed */
75 ListNode curPtr; /* current node, if open. NULL if
76 * *just* opened */
77 ListNode prevPtr; /* Previous node, if open. Used by
78 * Lst_Remove */
79 } *List;
82 * PAlloc (var, ptype) --
83 * Allocate a pointer-typedef structure 'ptype' into the variable 'var'
85 #define PAlloc(var,ptype) var = (ptype) bmake_malloc(sizeof *(var))
88 * LstValid (l) --
89 * Return TRUE if the list l is valid
91 #define LstValid(l) ((Lst)(l) != NULL)
94 * LstNodeValid (ln, l) --
95 * Return TRUE if the LstNode ln is valid with respect to l
97 #define LstNodeValid(ln, l) ((ln) != NULL)
100 * LstIsEmpty (l) --
101 * TRUE if the list l is empty.
103 #define LstIsEmpty(l) (((List)(l))->firstPtr == NULL)
105 #endif /* _LSTINT_H_ */