xref: /minix3/usr.bin/make/lst.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: lst.h,v 1.20 2014/09/07 20:55:34 joerg Exp $	*/
22e2caf59SThomas Veerman 
32e2caf59SThomas Veerman /*
42e2caf59SThomas Veerman  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
52e2caf59SThomas Veerman  * All rights reserved.
62e2caf59SThomas Veerman  *
72e2caf59SThomas Veerman  * This code is derived from software contributed to Berkeley by
82e2caf59SThomas Veerman  * Adam de Boor.
92e2caf59SThomas Veerman  *
102e2caf59SThomas Veerman  * Redistribution and use in source and binary forms, with or without
112e2caf59SThomas Veerman  * modification, are permitted provided that the following conditions
122e2caf59SThomas Veerman  * are met:
132e2caf59SThomas Veerman  * 1. Redistributions of source code must retain the above copyright
142e2caf59SThomas Veerman  *    notice, this list of conditions and the following disclaimer.
152e2caf59SThomas Veerman  * 2. Redistributions in binary form must reproduce the above copyright
162e2caf59SThomas Veerman  *    notice, this list of conditions and the following disclaimer in the
172e2caf59SThomas Veerman  *    documentation and/or other materials provided with the distribution.
182e2caf59SThomas Veerman  * 3. Neither the name of the University nor the names of its contributors
192e2caf59SThomas Veerman  *    may be used to endorse or promote products derived from this software
202e2caf59SThomas Veerman  *    without specific prior written permission.
212e2caf59SThomas Veerman  *
222e2caf59SThomas Veerman  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
232e2caf59SThomas Veerman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
242e2caf59SThomas Veerman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
252e2caf59SThomas Veerman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
262e2caf59SThomas Veerman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
272e2caf59SThomas Veerman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
282e2caf59SThomas Veerman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
292e2caf59SThomas Veerman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
302e2caf59SThomas Veerman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
312e2caf59SThomas Veerman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
322e2caf59SThomas Veerman  * SUCH DAMAGE.
332e2caf59SThomas Veerman  *
342e2caf59SThomas Veerman  *	from: @(#)lst.h	8.1 (Berkeley) 6/6/93
352e2caf59SThomas Veerman  */
362e2caf59SThomas Veerman 
372e2caf59SThomas Veerman /*
382e2caf59SThomas Veerman  * Copyright (c) 1988, 1989 by Adam de Boor
392e2caf59SThomas Veerman  * Copyright (c) 1989 by Berkeley Softworks
402e2caf59SThomas Veerman  * All rights reserved.
412e2caf59SThomas Veerman  *
422e2caf59SThomas Veerman  * This code is derived from software contributed to Berkeley by
432e2caf59SThomas Veerman  * Adam de Boor.
442e2caf59SThomas Veerman  *
452e2caf59SThomas Veerman  * Redistribution and use in source and binary forms, with or without
462e2caf59SThomas Veerman  * modification, are permitted provided that the following conditions
472e2caf59SThomas Veerman  * are met:
482e2caf59SThomas Veerman  * 1. Redistributions of source code must retain the above copyright
492e2caf59SThomas Veerman  *    notice, this list of conditions and the following disclaimer.
502e2caf59SThomas Veerman  * 2. Redistributions in binary form must reproduce the above copyright
512e2caf59SThomas Veerman  *    notice, this list of conditions and the following disclaimer in the
522e2caf59SThomas Veerman  *    documentation and/or other materials provided with the distribution.
532e2caf59SThomas Veerman  * 3. All advertising materials mentioning features or use of this software
542e2caf59SThomas Veerman  *    must display the following acknowledgement:
552e2caf59SThomas Veerman  *	This product includes software developed by the University of
562e2caf59SThomas Veerman  *	California, Berkeley and its contributors.
572e2caf59SThomas Veerman  * 4. Neither the name of the University nor the names of its contributors
582e2caf59SThomas Veerman  *    may be used to endorse or promote products derived from this software
592e2caf59SThomas Veerman  *    without specific prior written permission.
602e2caf59SThomas Veerman  *
612e2caf59SThomas Veerman  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
622e2caf59SThomas Veerman  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
632e2caf59SThomas Veerman  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
642e2caf59SThomas Veerman  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
652e2caf59SThomas Veerman  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
662e2caf59SThomas Veerman  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
672e2caf59SThomas Veerman  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
682e2caf59SThomas Veerman  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
692e2caf59SThomas Veerman  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
702e2caf59SThomas Veerman  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
712e2caf59SThomas Veerman  * SUCH DAMAGE.
722e2caf59SThomas Veerman  *
732e2caf59SThomas Veerman  *	from: @(#)lst.h	8.1 (Berkeley) 6/6/93
742e2caf59SThomas Veerman  */
752e2caf59SThomas Veerman 
762e2caf59SThomas Veerman /*-
772e2caf59SThomas Veerman  * lst.h --
782e2caf59SThomas Veerman  *	Header for using the list library
792e2caf59SThomas Veerman  */
802e2caf59SThomas Veerman #ifndef _LST_H_
812e2caf59SThomas Veerman #define _LST_H_
822e2caf59SThomas Veerman 
832e2caf59SThomas Veerman #include	<sys/param.h>
842e2caf59SThomas Veerman #include	<stdlib.h>
852e2caf59SThomas Veerman 
862e2caf59SThomas Veerman #include	"sprite.h"
872e2caf59SThomas Veerman 
882e2caf59SThomas Veerman /*
892e2caf59SThomas Veerman  * basic typedef. This is what the Lst_ functions handle
902e2caf59SThomas Veerman  */
912e2caf59SThomas Veerman 
922e2caf59SThomas Veerman typedef	struct List	*Lst;
932e2caf59SThomas Veerman typedef	struct ListNode	*LstNode;
942e2caf59SThomas Veerman 
952e2caf59SThomas Veerman typedef void		*DuplicateProc(void *);
962e2caf59SThomas Veerman typedef void		FreeProc(void *);
972e2caf59SThomas Veerman 
982e2caf59SThomas Veerman #define LST_CONCNEW	0   /* create new LstNode's when using Lst_Concat */
992e2caf59SThomas Veerman #define LST_CONCLINK	1   /* relink LstNode's when using Lst_Concat */
1002e2caf59SThomas Veerman 
1012e2caf59SThomas Veerman /*
1022e2caf59SThomas Veerman  * Creation/destruction functions
1032e2caf59SThomas Veerman  */
1042e2caf59SThomas Veerman /* Create a new list */
1052e2caf59SThomas Veerman Lst		Lst_Init(Boolean);
1062e2caf59SThomas Veerman /* Duplicate an existing list */
1072e2caf59SThomas Veerman Lst		Lst_Duplicate(Lst, DuplicateProc *);
1082e2caf59SThomas Veerman /* Destroy an old one */
1092e2caf59SThomas Veerman void		Lst_Destroy(Lst, FreeProc *);
1102e2caf59SThomas Veerman /* True if list is empty */
1112e2caf59SThomas Veerman Boolean		Lst_IsEmpty(Lst);
1122e2caf59SThomas Veerman 
1132e2caf59SThomas Veerman /*
1142e2caf59SThomas Veerman  * Functions to modify a list
1152e2caf59SThomas Veerman  */
1162e2caf59SThomas Veerman /* Insert an element before another */
1172e2caf59SThomas Veerman ReturnStatus	Lst_InsertBefore(Lst, LstNode, void *);
1182e2caf59SThomas Veerman /* Insert an element after another */
1192e2caf59SThomas Veerman ReturnStatus	Lst_InsertAfter(Lst, LstNode, void *);
1202e2caf59SThomas Veerman /* Place an element at the front of a lst. */
1212e2caf59SThomas Veerman ReturnStatus	Lst_AtFront(Lst, void *);
1222e2caf59SThomas Veerman /* Place an element at the end of a lst. */
1232e2caf59SThomas Veerman ReturnStatus	Lst_AtEnd(Lst, void *);
1242e2caf59SThomas Veerman /* Remove an element */
1252e2caf59SThomas Veerman ReturnStatus	Lst_Remove(Lst, LstNode);
1262e2caf59SThomas Veerman /* Replace a node with a new value */
1272e2caf59SThomas Veerman ReturnStatus	Lst_Replace(LstNode, void *);
1282e2caf59SThomas Veerman /* Concatenate two lists */
1292e2caf59SThomas Veerman ReturnStatus	Lst_Concat(Lst, Lst, int);
1302e2caf59SThomas Veerman 
1312e2caf59SThomas Veerman /*
1322e2caf59SThomas Veerman  * Node-specific functions
1332e2caf59SThomas Veerman  */
1342e2caf59SThomas Veerman /* Return first element in list */
1352e2caf59SThomas Veerman LstNode		Lst_First(Lst);
1362e2caf59SThomas Veerman /* Return last element in list */
1372e2caf59SThomas Veerman LstNode		Lst_Last(Lst);
1382e2caf59SThomas Veerman /* Return successor to given element */
1392e2caf59SThomas Veerman LstNode		Lst_Succ(LstNode);
1402e2caf59SThomas Veerman /* Return predecessor to given element */
1412e2caf59SThomas Veerman LstNode		Lst_Prev(LstNode);
1422e2caf59SThomas Veerman /* Get datum from LstNode */
1432e2caf59SThomas Veerman void		*Lst_Datum(LstNode);
1442e2caf59SThomas Veerman 
1452e2caf59SThomas Veerman /*
1462e2caf59SThomas Veerman  * Functions for entire lists
1472e2caf59SThomas Veerman  */
1482e2caf59SThomas Veerman /* Find an element in a list */
1492e2caf59SThomas Veerman LstNode		Lst_Find(Lst, const void *, int (*)(const void *, const void *));
1502e2caf59SThomas Veerman /* Find an element starting from somewhere */
1512e2caf59SThomas Veerman LstNode		Lst_FindFrom(Lst, LstNode, const void *,
1522e2caf59SThomas Veerman 			     int (*cProc)(const void *, const void *));
1532e2caf59SThomas Veerman /*
1542e2caf59SThomas Veerman  * See if the given datum is on the list. Returns the LstNode containing
1552e2caf59SThomas Veerman  * the datum
1562e2caf59SThomas Veerman  */
1572e2caf59SThomas Veerman LstNode		Lst_Member(Lst, void *);
1582e2caf59SThomas Veerman /* Apply a function to all elements of a lst */
1592e2caf59SThomas Veerman int		Lst_ForEach(Lst, int (*)(void *, void *), void *);
1602e2caf59SThomas Veerman /*
1612e2caf59SThomas Veerman  * Apply a function to all elements of a lst starting from a certain point.
1622e2caf59SThomas Veerman  * If the list is circular, the application will wrap around to the
1632e2caf59SThomas Veerman  * beginning of the list again.
1642e2caf59SThomas Veerman  */
1652e2caf59SThomas Veerman int		Lst_ForEachFrom(Lst, LstNode, int (*)(void *, void *),
1662e2caf59SThomas Veerman 				void *);
1672e2caf59SThomas Veerman /*
1682e2caf59SThomas Veerman  * these functions are for dealing with a list as a table, of sorts.
1692e2caf59SThomas Veerman  * An idea of the "current element" is kept and used by all the functions
1702e2caf59SThomas Veerman  * between Lst_Open() and Lst_Close().
1712e2caf59SThomas Veerman  */
1722e2caf59SThomas Veerman /* Open the list */
1732e2caf59SThomas Veerman ReturnStatus	Lst_Open(Lst);
1742e2caf59SThomas Veerman /* Next element please */
1752e2caf59SThomas Veerman LstNode		Lst_Next(Lst);
1762e2caf59SThomas Veerman /* Done yet? */
1772e2caf59SThomas Veerman Boolean		Lst_IsAtEnd(Lst);
1782e2caf59SThomas Veerman /* Finish table access */
1792e2caf59SThomas Veerman void		Lst_Close(Lst);
1802e2caf59SThomas Veerman 
1812e2caf59SThomas Veerman /*
1822e2caf59SThomas Veerman  * for using the list as a queue
1832e2caf59SThomas Veerman  */
1842e2caf59SThomas Veerman /* Place an element at tail of queue */
1852e2caf59SThomas Veerman ReturnStatus	Lst_EnQueue(Lst, void *);
1862e2caf59SThomas Veerman /* Remove an element from head of queue */
1872e2caf59SThomas Veerman void		*Lst_DeQueue(Lst);
1882e2caf59SThomas Veerman 
1892e2caf59SThomas Veerman #endif /* _LST_H_ */
190