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