Annotation of src/usr.bin/make/lst.h, Revision 1.20
1.20 ! espie 1: #ifndef _LST_H_
! 2: #define _LST_H_
! 3:
1.19 espie 4: /* $OpenPackages$ */
5: /* $OpenBSD: lst.h,v 1.7 1999/07/29 19:55:19 deraadt Exp $ */
6: /* $NetBSD: lst.h,v 1.7 1996/11/06 17:59:12 christos Exp $ */
1.1 deraadt 7:
8: /*
9: * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
10: * Copyright (c) 1988, 1989 by Adam de Boor
11: * Copyright (c) 1989 by Berkeley Softworks
12: * All rights reserved.
13: *
14: * This code is derived from software contributed to Berkeley by
15: * Adam de Boor.
16: *
17: * Redistribution and use in source and binary forms, with or without
18: * modification, are permitted provided that the following conditions
19: * are met:
20: * 1. Redistributions of source code must retain the above copyright
21: * notice, this list of conditions and the following disclaimer.
22: * 2. Redistributions in binary form must reproduce the above copyright
23: * notice, this list of conditions and the following disclaimer in the
24: * documentation and/or other materials provided with the distribution.
25: * 3. All advertising materials mentioning features or use of this software
26: * must display the following acknowledgement:
27: * This product includes software developed by the University of
28: * California, Berkeley and its contributors.
29: * 4. Neither the name of the University nor the names of its contributors
30: * may be used to endorse or promote products derived from this software
31: * without specific prior written permission.
32: *
33: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43: * SUCH DAMAGE.
44: *
1.19 espie 45: * from: @(#)lst.h 8.1 (Berkeley) 6/6/93
1.1 deraadt 46: */
47:
48: /*-
49: * lst.h --
50: * Header for using the list library
51: */
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. */
1.20 ! espie 60: struct ListNode_ {
1.19 espie 61: struct ListNode_ *prevPtr; /* previous element in list */
62: struct ListNode_ *nextPtr; /* next in list */
1.14 espie 63: void *datum; /* datum associated with this element */
1.20 ! espie 64: };
1.14 espie 65:
1.20 ! espie 66: #ifndef LIST_TYPE
! 67: #include "lst_t.h"
! 68: #endif
1.1 deraadt 69:
1.19 espie 70: typedef void (*SimpleProc)(void *);
71: typedef int (*FindProc)(void *, void *);
72: typedef int (*FindProcConst)(void *, const void *);
73: typedef void (*ForEachProc)(void *, void *);
74: typedef void *(*DuplicateProc)(void *);
1.1 deraadt 75:
76: /*
77: * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
78: * not to be freed.
1.19 espie 79: * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
1.1 deraadt 80: */
1.19 espie 81: #define NOFREE ((SimpleProc) 0)
82: #define NOCOPY ((DuplicateProc) 0)
1.1 deraadt 83:
84: /*
1.19 espie 85: * Creation/destruction functions
1.1 deraadt 86: */
1.16 espie 87: /* Create a new list */
1.19 espie 88: extern void Lst_Init(LIST *);
89: /* Duplicate an existing list */
90: extern Lst Lst_Clone(Lst, Lst, DuplicateProc);
1.16 espie 91: /* Destroy an old one */
1.19 espie 92: extern void Lst_Destroy(LIST *, SimpleProc);
1.1 deraadt 93: /* True if list is empty */
1.19 espie 94: #define Lst_IsEmpty(l) ((l)->firstPtr == NULL)
1.1 deraadt 95:
96: /*
1.19 espie 97: * Functions to modify a list
1.1 deraadt 98: */
99: /* Insert an element before another */
1.19 espie 100: extern void Lst_Insert(Lst, LstNode, void *);
101: extern void Lst_AtFront(Lst, void *);
1.1 deraadt 102: /* Insert an element after another */
1.19 espie 103: extern void Lst_Append(Lst, LstNode, void *);
104: extern void Lst_AtEnd(Lst, void *);
1.1 deraadt 105: /* Remove an element */
1.19 espie 106: extern void Lst_Remove(Lst, LstNode);
1.1 deraadt 107: /* Replace a node with a new value */
1.19 espie 108: extern void Lst_Replace(LstNode, void *);
109: /* Concatenate two lists, destructive. */
110: extern void Lst_ConcatDestroy(Lst, Lst);
111: /* Concatenate two lists, non-destructive. */
112: extern void Lst_Concat(Lst, Lst);
1.1 deraadt 113:
114: /*
1.19 espie 115: * Node-specific functions
1.1 deraadt 116: */
117: /* Return first element in list */
118: /* Return last element in list */
119: /* Return successor to given element */
1.19 espie 120: extern LstNode Lst_Succ(LstNode);
1.1 deraadt 121:
122: /*
1.19 espie 123: * Functions for entire lists
1.1 deraadt 124: */
125: /* Find an element starting from somewhere */
1.19 espie 126: extern LstNode Lst_FindFrom(LstNode, FindProc, void *);
1.1 deraadt 127: /*
1.19 espie 128: * See if the given datum is on the list. Returns the LstNode containing
129: * the datum
1.1 deraadt 130: */
1.19 espie 131: extern LstNode Lst_Member(Lst, void *);
132: /* Apply a function to elements of a lst starting from a certain point. */
133: extern void Lst_ForEachFrom(LstNode, ForEachProc, void *);
134: extern void Lst_Every(Lst, SimpleProc);
1.1 deraadt 135:
1.20 ! espie 136: extern bool Lst_AddNew(Lst, void *);
1.1 deraadt 137: /*
1.19 espie 138: * for using the list as a queue
1.1 deraadt 139: */
140: /* Place an element at tail of queue */
1.19 espie 141: #define Lst_EnQueue Lst_AtEnd
142: #define Lst_QueueNew Lst_AddNew
143:
1.20 ! espie 144: /*
! 145: * for using the list as a stack
! 146: */
! 147: #define Lst_Push Lst_AtFront
! 148: #define Lst_Pop Lst_DeQueue
! 149:
1.1 deraadt 150: /* Remove an element from head of queue */
1.19 espie 151: extern void * Lst_DeQueue(Lst);
152:
153: #define Lst_Datum(ln) ((ln)->datum)
154: #define Lst_First(l) ((l)->firstPtr)
155: #define Lst_Last(l) ((l)->lastPtr)
156: #define Lst_ForEach(l, proc, d) Lst_ForEachFrom(Lst_First(l), proc, d)
157: #define Lst_Find(l, cProc, d) Lst_FindFrom(Lst_First(l), cProc, d)
158: #define Lst_Adv(ln) ((ln)->nextPtr)
159: #define Lst_Rev(ln) ((ln)->prevPtr)
160:
161:
1.20 ! espie 162: /* Inlines are preferable to macros here because of the type checking. */
1.19 espie 163: #ifdef HAS_INLINES
164: static INLINE LstNode
165: Lst_FindConst(Lst l, FindProcConst cProc, const void *d)
166: {
167: return Lst_FindFrom(Lst_First(l), (FindProc)cProc, (void *)d);
168: }
169:
170: static INLINE LstNode
171: Lst_FindFromConst(LstNode ln, FindProcConst cProc, const void *d)
172: {
173: return Lst_FindFrom(ln, (FindProc)cProc, (void *)d);
174: }
175: #else
176: #define Lst_FindConst(l, cProc, d) \
177: Lst_FindFrom(Lst_First(l), (FindProc)cProc, (void *)d)
178: #define Lst_FindFromConst(ln, cProc, d) \
179: Lst_FindFrom(ln, (FindProc)cProc, (void *)d)
180: #endif
1.1 deraadt 181:
182: #endif /* _LST_H_ */