wbsio(4): support W83687THF (0x85); hw mon is already supported by lm(4) as W83627THF...
[dragonfly.git] / usr.bin / make / lst.h
blobbb43f7fd7db3c1e0c37c5569dca9b34b66ced1cd
1 /*-
2 * Copyright (c) 1988, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1988, 1989 by Adam de Boor
5 * Copyright (c) 1989 by Berkeley Softworks
6 * All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Adam de Boor.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
39 * from: @(#)lst.h 8.1 (Berkeley) 6/6/93
40 * $FreeBSD: src/usr.bin/make/lst.h,v 1.28 2005/02/10 14:25:12 harti Exp $
41 * $DragonFly: src/usr.bin/make/lst.h,v 1.32 2005/08/03 19:48:44 okumoto Exp $
44 #ifndef lst_h_38f3ead1
45 #define lst_h_38f3ead1
47 /*-
48 * lst.h --
49 * Header for using the list library
52 #include <stdbool.h>
55 * Structure of a list node.
57 struct LstNode {
58 struct LstNode *prevPtr; /* previous element in list */
59 struct LstNode *nextPtr; /* next in list */
60 void *datum; /* datum associated with this element */
62 typedef struct LstNode LstNode;
65 * The list itself
67 struct Lst {
68 LstNode *firstPtr; /* first node in list */
69 LstNode *lastPtr; /* last node in list */
71 typedef struct Lst Lst;
73 typedef void *DuplicateProc(void *);
74 typedef void FreeProc(void *);
77 * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
78 * not to be freed.
79 * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
81 #define NOFREE ((FreeProc *)NULL)
82 #define NOCOPY ((DuplicateProc *)NULL)
84 #define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */
85 #define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */
88 * Creation/destruction functions
90 /* Create a new list */
91 #define Lst_Init(LST) do { \
92 (LST)->firstPtr = NULL; \
93 (LST)->lastPtr = NULL; \
94 } while (0)
95 #define Lst_Initializer(NAME) { NULL, NULL }
97 /* Duplicate an existing list */
98 void Lst_Duplicate(Lst *, Lst *, DuplicateProc *);
100 /* Destroy an old one */
101 void Lst_Destroy(Lst *, FreeProc *);
104 * Functions to modify a list
106 /* Insert an element before another */
107 void Lst_Insert(Lst *, LstNode *, void *);
108 /* Insert an element after another */
109 void Lst_Append(Lst *, LstNode *, void *);
110 /* Place an element at the front of a lst. */
111 #define Lst_AtFront(LST, D) (Lst_Insert((LST), Lst_First(LST), (D)))
112 /* Place an element at the end of a lst. */
113 #define Lst_AtEnd(LST, D) (Lst_Append((LST), Lst_Last(LST), (D)))
114 /* Remove an element */
115 void Lst_Remove(Lst *, LstNode *);
116 /* Replace a node with a new value */
117 #define Lst_Replace(NODE, D) ((void)((NODE)->datum = (D)))
118 /* Concatenate two lists */
119 void Lst_Concat(Lst *, Lst *, int);
122 * Node-specific functions
124 /* Return first element in list */
125 #define Lst_First(LST) ((Lst_Valid(LST) && !Lst_IsEmpty(LST)) \
126 ? (LST)->firstPtr : NULL)
127 /* Return last element in list */
128 #define Lst_Last(LST) ((Lst_Valid(LST) && !Lst_IsEmpty(LST)) \
129 ? (LST)->lastPtr : NULL)
130 /* Return successor to given element */
131 #define Lst_Succ(NODE) (((NODE) == NULL) ? NULL : (NODE)->nextPtr)
132 #define LST_NEXT(NODE) ((NODE)->nextPtr)
133 /* Get datum from LstNode */
134 #define Lst_Datum(NODE) ((NODE)->datum)
137 * Functions for entire lists
141 * See if the given datum is on the list. Returns the LstNode containing
142 * the datum
144 LstNode *Lst_Member(Lst *, const void *);
146 /* Loop through a list. Note, that you may not delete the list element. */
147 #define LST_FOREACH(PTR, LST) \
148 for ((PTR) = (LST)->firstPtr; (PTR) != NULL; (PTR) = (PTR)->nextPtr)
151 * for using the list as a queue
153 /* Place an element at tail of queue */
154 #define Lst_EnQueue(LST, D) (Lst_Valid(LST) \
155 ? Lst_Append((LST), Lst_Last(LST), (D)) \
156 : (void)0)
157 /* Remove an element from head of queue */
158 void *Lst_DeQueue(Lst *);
161 * LstValid (L) --
162 * Return true if the list L is valid
164 #define Lst_Valid(L) (((L) == NULL) ? false : true)
167 * LstNodeValid (LN, L) --
168 * Return true if the LstNode LN is valid with respect to L
170 #define Lst_NodeValid(LN, L) (((LN) == NULL) ? false : true)
173 * Lst_IsEmpty(L) --
174 * true if the list L is empty.
176 #define Lst_IsEmpty(L) (!Lst_Valid(L) || (L)->firstPtr == NULL)
178 #endif /* lst_h_38f3ead1 */