Annotation of src/usr.bin/make/lst.h, Revision 1.18
1.18 ! espie 1: /* $OpenBSD: lst.h,v 1.17 2000/06/23 16:15:49 espie Exp $ */
1.4 millert 2: /* $NetBSD: lst.h,v 1.7 1996/11/06 17:59:12 christos Exp $ */
1.1 deraadt 3:
4: /*
5: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
6: * Copyright (c) 1988, 1989 by Adam de Boor
7: * Copyright (c) 1989 by Berkeley Softworks
8: * All rights reserved.
9: *
10: * This code is derived from software contributed to Berkeley by
11: * Adam de Boor.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. All advertising materials mentioning features or use of this software
22: * must display the following acknowledgement:
23: * This product includes software developed by the University of
24: * California, Berkeley and its contributors.
25: * 4. Neither the name of the University nor the names of its contributors
26: * may be used to endorse or promote products derived from this software
27: * without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39: * SUCH DAMAGE.
40: *
1.4 millert 41: * from: @(#)lst.h 8.1 (Berkeley) 6/6/93
1.1 deraadt 42: */
43:
44: /*-
45: * lst.h --
46: * Header for using the list library
47: */
48: #ifndef _LST_H_
49: #define _LST_H_
50:
1.7 deraadt 51: #include "sprite.h"
1.2 niklas 52: #include <sys/param.h>
1.5 mickey 53: #ifdef __STDC__
1.1 deraadt 54: #include <stdlib.h>
55: #endif
56:
1.14 espie 57: /* These data structures are PRIVATE !!!
58: * Here for efficiency, so that some functions can be recoded as inlines,
59: * and so that lst headers don't need dynamic allocation most of the time. */
60: typedef struct ListNode_ {
61: struct ListNode_ *prevPtr; /* previous element in list */
62: struct ListNode_ *nextPtr; /* next in list */
63: short useCount:8, /* Count of functions using the node.
64: * node may not be deleted until count
65: * goes to 0 */
66: flags:8; /* Node status flags */
67: void *datum; /* datum associated with this element */
68: } *LstNode;
69:
70: typedef enum {
71: Head, Middle, Tail, Unknown
72: } Where;
73:
74: typedef struct {
75: LstNode firstPtr; /* first node in list */
76: LstNode lastPtr; /* last node in list */
77: /*
78: * fields for sequential access
79: */
80: Where atEnd; /* Where in the list the last access was */
81: Boolean isOpen; /* true if list has been Lst_Open'ed */
82: LstNode curPtr; /* current node, if open. NULL if
83: * *just* opened */
84: LstNode prevPtr; /* Previous node, if open. Used by
85: * Lst_Remove */
86: } LIST;
87:
88: typedef LIST *Lst;
1.1 deraadt 89: /*
90: * basic typedef. This is what the Lst_ functions handle
91: */
92:
1.13 espie 93: typedef int (*FindProc) __P((void *, void *));
94: typedef void (*SimpleProc) __P((void *));
95: typedef void (*ForEachProc) __P((void *, void *));
96: typedef void * (*DuplicateProc) __P((void *));
1.1 deraadt 97:
98: /*
99: * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
100: * not to be freed.
1.16 espie 101: * NOCOPY performs similarly when given as the copyProc to Lst_Clone.
1.1 deraadt 102: */
1.12 espie 103: #define NOFREE ((SimpleProc)0)
104: #define NOCOPY ((DuplicateProc)0)
1.1 deraadt 105:
106: /*
1.18 ! espie 107: * Constructors/destructors
1.1 deraadt 108: */
1.16 espie 109: /* Create a new list */
1.18 ! espie 110: extern void Lst_Init __P((Lst));
1.16 espie 111: /* Destroy an old one */
1.18 ! espie 112: extern void Lst_Destroy __P((Lst, SimpleProc));
1.15 espie 113:
1.1 deraadt 114: /* Duplicate an existing list */
1.18 ! espie 115: extern Lst Lst_Clone __P((Lst, Lst, DuplicateProc));
1.1 deraadt 116: /* True if list is empty */
1.18 ! espie 117: extern Boolean Lst_IsEmpty __P((Lst));
1.1 deraadt 118:
119: /*
1.18 ! espie 120: * List modifications
1.1 deraadt 121: */
122: /* Insert an element before another */
1.18 ! espie 123: extern void Lst_Insert __P((Lst, LstNode, void *));
1.1 deraadt 124: /* Insert an element after another */
1.18 ! espie 125: extern void Lst_Append __P((Lst, LstNode, void *));
1.1 deraadt 126: /* Place an element at the front of a lst. */
1.18 ! espie 127: extern void Lst_AtFront __P((Lst, void *));
1.1 deraadt 128: /* Place an element at the end of a lst. */
1.18 ! espie 129: extern void Lst_AtEnd __P((Lst, void *));
1.1 deraadt 130: /* Remove an element */
1.18 ! espie 131: extern void Lst_Remove __P((Lst, LstNode));
1.1 deraadt 132: /* Replace a node with a new value */
1.18 ! espie 133: extern void Lst_Replace __P((LstNode, void *));
1.16 espie 134: /* Concatenate two lists, destructive. */
1.18 ! espie 135: extern void Lst_ConcatDestroy __P((Lst, Lst));
1.16 espie 136: /* Concatenate two lists, non destructive */
1.18 ! espie 137: extern void Lst_Concat __P((Lst, Lst));
1.1 deraadt 138:
139: /*
1.18 ! espie 140: * Node handling
1.1 deraadt 141: */
142: /* Return first element in list */
1.17 espie 143: #define Lst_First(l) ((l)->firstPtr)
1.1 deraadt 144: /* Return last element in list */
1.17 espie 145: #define Lst_Last(l) ((l)->lastPtr)
1.1 deraadt 146: /* Return successor to given element */
1.18 ! espie 147: extern LstNode Lst_Succ __P((LstNode));
1.17 espie 148: /* Return successor to existing element */
149: #define Lst_Adv(ln) ((ln)->nextPtr)
1.1 deraadt 150: /* Get datum from LstNode */
1.17 espie 151: #define Lst_Datum(ln) ((ln)->datum)
1.1 deraadt 152:
153: /*
1.18 ! espie 154: * Apply to entire lists
1.1 deraadt 155: */
1.11 espie 156:
1.1 deraadt 157: /* Find an element in a list */
1.11 espie 158: #define Lst_Find(l, cProc, d) Lst_FindFrom(Lst_First(l), cProc, d)
159:
1.1 deraadt 160: /* Find an element starting from somewhere */
1.18 ! espie 161: extern LstNode Lst_FindFrom __P((LstNode, FindProc, void *));
1.12 espie 162:
163: /* Apply a function to all elements of a lst */
164: #define Lst_ForEach(l, proc, d) Lst_ForEachFrom(Lst_First(l), proc, d)
165: /* Apply a function to all elements of a lst starting from a certain point. */
1.18 ! espie 166: extern void Lst_ForEachFrom __P((LstNode, ForEachProc, void *));
! 167: extern void Lst_Every __P((Lst, SimpleProc));
1.12 espie 168:
169:
1.18 ! espie 170: /* Find datum in a list. Returns the LstNode containing the datum */
! 171: extern LstNode Lst_Member __P((Lst, void *));
1.12 espie 172:
1.1 deraadt 173: /*
1.18 ! espie 174: * Visitor-like pattern. Except the visitor is kept in the list.
! 175: * Error-prone and wasteful (used by only a few lists), to be killed.
1.1 deraadt 176: */
177: /* Open the list */
1.18 ! espie 178: extern void Lst_Open __P((Lst));
1.1 deraadt 179: /* Next element please */
1.18 ! espie 180: extern LstNode Lst_Next __P((Lst));
1.1 deraadt 181: /* Done yet? */
1.18 ! espie 182: extern Boolean Lst_IsAtEnd __P((Lst));
1.1 deraadt 183: /* Finish table access */
1.18 ! espie 184: extern void Lst_Close __P((Lst));
1.1 deraadt 185:
186: /*
1.18 ! espie 187: * Queue manipulators
1.1 deraadt 188: */
189: /* Place an element at tail of queue */
1.18 ! espie 190: extern void Lst_EnQueue __P((Lst, void *));
1.1 deraadt 191: /* Remove an element from head of queue */
1.18 ! espie 192: extern void * Lst_DeQueue __P((Lst));
1.1 deraadt 193:
194: #endif /* _LST_H_ */