Home | History | Annotate | Line # | Download | only in make
lst.h revision 1.11
      1 /*	$NetBSD: lst.h,v 1.11 2005/08/09 21:36:42 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Adam de Boor.
      9  *
     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.
     21  *
     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.
     33  *
     34  *	from: @(#)lst.h	8.1 (Berkeley) 6/6/93
     35  */
     36 
     37 /*
     38  * Copyright (c) 1988, 1989 by Adam de Boor
     39  * Copyright (c) 1989 by Berkeley Softworks
     40  * All rights reserved.
     41  *
     42  * This code is derived from software contributed to Berkeley by
     43  * Adam de Boor.
     44  *
     45  * Redistribution and use in source and binary forms, with or without
     46  * modification, are permitted provided that the following conditions
     47  * are met:
     48  * 1. Redistributions of source code must retain the above copyright
     49  *    notice, this list of conditions and the following disclaimer.
     50  * 2. Redistributions in binary form must reproduce the above copyright
     51  *    notice, this list of conditions and the following disclaimer in the
     52  *    documentation and/or other materials provided with the distribution.
     53  * 3. All advertising materials mentioning features or use of this software
     54  *    must display the following acknowledgement:
     55  *	This product includes software developed by the University of
     56  *	California, Berkeley and its contributors.
     57  * 4. Neither the name of the University nor the names of its contributors
     58  *    may be used to endorse or promote products derived from this software
     59  *    without specific prior written permission.
     60  *
     61  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     62  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     63  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     64  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     65  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     66  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     67  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     68  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     69  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     70  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     71  * SUCH DAMAGE.
     72  *
     73  *	from: @(#)lst.h	8.1 (Berkeley) 6/6/93
     74  */
     75 
     76 /*-
     77  * lst.h --
     78  *	Header for using the list library
     79  */
     80 #ifndef _LST_H_
     81 #define _LST_H_
     82 
     83 #include	<sys/param.h>
     84 #include	<stdlib.h>
     85 
     86 #include	"sprite.h"
     87 
     88 /*
     89  * basic typedef. This is what the Lst_ functions handle
     90  */
     91 
     92 typedef	struct	Lst	*Lst;
     93 typedef	struct	LstNode	*LstNode;
     94 
     95 typedef ClientData	DuplicateProc(ClientData);
     96 typedef void		FreeProc(ClientData);
     97 
     98 #define	NILLST		((Lst)NIL)
     99 #define	NILLNODE	((LstNode)NIL)
    100 
    101 /*
    102  * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
    103  *	not to be freed.
    104  * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
    105  */
    106 #define NOFREE		((FreeProc *)NULL)
    107 #define NOCOPY		((DuplicateProc *)NULL)
    108 
    109 #define LST_CONCNEW	0   /* create new LstNode's when using Lst_Concat */
    110 #define LST_CONCLINK	1   /* relink LstNode's when using Lst_Concat */
    111 
    112 /*
    113  * Creation/destruction functions
    114  */
    115 /* Create a new list */
    116 Lst		Lst_Init(Boolean);
    117 /* Duplicate an existing list */
    118 Lst		Lst_Duplicate(Lst, DuplicateProc *);
    119 /* Destroy an old one */
    120 void		Lst_Destroy(Lst, FreeProc *);
    121 /* True if list is empty */
    122 Boolean		Lst_IsEmpty(Lst);
    123 
    124 /*
    125  * Functions to modify a list
    126  */
    127 /* Insert an element before another */
    128 ReturnStatus	Lst_Insert(Lst, LstNode, ClientData);
    129 /* Insert an element after another */
    130 ReturnStatus	Lst_Append(Lst, LstNode, ClientData);
    131 /* Place an element at the front of a lst. */
    132 ReturnStatus	Lst_AtFront(Lst, ClientData);
    133 /* Place an element at the end of a lst. */
    134 ReturnStatus	Lst_AtEnd(Lst, ClientData);
    135 /* Remove an element */
    136 ReturnStatus	Lst_Remove(Lst, LstNode);
    137 /* Replace a node with a new value */
    138 ReturnStatus	Lst_Replace(LstNode, ClientData);
    139 /* Concatenate two lists */
    140 ReturnStatus	Lst_Concat(Lst, Lst, int);
    141 
    142 /*
    143  * Node-specific functions
    144  */
    145 /* Return first element in list */
    146 LstNode		Lst_First(Lst);
    147 /* Return last element in list */
    148 LstNode		Lst_Last(Lst);
    149 /* Return successor to given element */
    150 LstNode		Lst_Succ(LstNode);
    151 /* Get datum from LstNode */
    152 ClientData	Lst_Datum(LstNode);
    153 
    154 /*
    155  * Functions for entire lists
    156  */
    157 /* Find an element in a list */
    158 LstNode		Lst_Find(Lst, ClientData, int (*)(ClientData, ClientData));
    159 /* Find an element starting from somewhere */
    160 LstNode		Lst_FindFrom(Lst, LstNode, ClientData,
    161 			     int (*cProc)(ClientData, ClientData));
    162 /*
    163  * See if the given datum is on the list. Returns the LstNode containing
    164  * the datum
    165  */
    166 LstNode		Lst_Member(Lst, ClientData);
    167 /* Apply a function to all elements of a lst */
    168 void		Lst_ForEach(Lst, int (*)(ClientData, ClientData), ClientData);
    169 /*
    170  * Apply a function to all elements of a lst starting from a certain point.
    171  * If the list is circular, the application will wrap around to the
    172  * beginning of the list again.
    173  */
    174 void		Lst_ForEachFrom(Lst, LstNode, int (*)(ClientData, ClientData),
    175 				ClientData);
    176 /*
    177  * these functions are for dealing with a list as a table, of sorts.
    178  * An idea of the "current element" is kept and used by all the functions
    179  * between Lst_Open() and Lst_Close().
    180  */
    181 /* Open the list */
    182 ReturnStatus	Lst_Open(Lst);
    183 /* Next element please */
    184 LstNode		Lst_Next(Lst);
    185 /* Done yet? */
    186 Boolean		Lst_IsAtEnd(Lst);
    187 /* Finish table access */
    188 void		Lst_Close(Lst);
    189 
    190 /*
    191  * for using the list as a queue
    192  */
    193 /* Place an element at tail of queue */
    194 ReturnStatus	Lst_EnQueue(Lst, ClientData);
    195 /* Remove an element from head of queue */
    196 ClientData	Lst_DeQueue(Lst);
    197 
    198 #endif /* _LST_H_ */
    199