Home | History | Annotate | Line # | Download | only in make
lst.h revision 1.3
      1 /*
      2  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
      3  * Copyright (c) 1988, 1989 by Adam de Boor
      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  *	from: @(#)lst.h	5.3 (Berkeley) 6/1/90
     39  *	$Id: lst.h,v 1.3 1994/03/05 00:34:52 cgd Exp $
     40  */
     41 
     42 /*-
     43  * lst.h --
     44  *	Header for using the list library
     45  */
     46 #ifndef _LST_H_
     47 #define _LST_H_
     48 
     49 #include	<sprite.h>
     50 #if __STDC__
     51 #include	<stdlib.h>
     52 #endif
     53 
     54 /*
     55  * basic typedef. This is what the Lst_ functions handle
     56  */
     57 
     58 typedef	struct	Lst	*Lst;
     59 typedef	struct	LstNode	*LstNode;
     60 
     61 #define	NILLST		((Lst) NIL)
     62 #define	NILLNODE	((LstNode) NIL)
     63 
     64 /*
     65  * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
     66  *	not to be freed.
     67  * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
     68  */
     69 #define NOFREE		((void (*)()) 0)
     70 #define NOCOPY		((ClientData (*)()) 0)
     71 
     72 #define LST_CONCNEW	0   /* create new LstNode's when using Lst_Concat */
     73 #define LST_CONCLINK	1   /* relink LstNode's when using Lst_Concat */
     74 
     75 /*
     76  * Creation/destruction functions
     77  */
     78 Lst		  Lst_Init();	    	/* Create a new list */
     79 Lst	    	  Lst_Duplicate();  	/* Duplicate an existing list */
     80 void		  Lst_Destroy();	/* Destroy an old one */
     81 
     82 int	    	  Lst_Length();	    	/* Find the length of a list */
     83 Boolean		  Lst_IsEmpty();	/* True if list is empty */
     84 
     85 /*
     86  * Functions to modify a list
     87  */
     88 ReturnStatus	  Lst_Insert();	    	/* Insert an element before another */
     89 ReturnStatus	  Lst_Append();	    	/* Insert an element after another */
     90 ReturnStatus	  Lst_AtFront();    	/* Place an element at the front of
     91 					 * a lst. */
     92 ReturnStatus	  Lst_AtEnd();	    	/* Place an element at the end of a
     93 					 * lst. */
     94 ReturnStatus	  Lst_Remove();	    	/* Remove an element */
     95 ReturnStatus	  Lst_Replace();	/* Replace a node with a new value */
     96 ReturnStatus	  Lst_Move();	    	/* Move an element to another place */
     97 ReturnStatus	  Lst_Concat();	    	/* Concatenate two lists */
     98 
     99 /*
    100  * Node-specific functions
    101  */
    102 LstNode		  Lst_First();	    	/* Return first element in list */
    103 LstNode		  Lst_Last();	    	/* Return last element in list */
    104 LstNode		  Lst_Succ();	    	/* Return successor to given element */
    105 LstNode		  Lst_Pred();	    	/* Return predecessor to given
    106 					 * element */
    107 ClientData	  Lst_Datum();	    	/* Get datum from LstNode */
    108 
    109 /*
    110  * Functions for entire lists
    111  */
    112 LstNode		  Lst_Find();	    	/* Find an element in a list */
    113 LstNode		  Lst_FindFrom();	/* Find an element starting from
    114 					 * somewhere */
    115 LstNode	    	  Lst_Member();	    	/* See if the given datum is on the
    116 					 * list. Returns the LstNode containing
    117 					 * the datum */
    118 int	    	  Lst_Index();	    	/* Returns the index of a datum in the
    119 					 * list, starting from 0 */
    120 void		  Lst_ForEach();	/* Apply a function to all elements of
    121 					 * a lst */
    122 void	    	  Lst_ForEachFrom();  	/* Apply a function to all elements of
    123 					 * a lst starting from a certain point.
    124 					 * If the list is circular, the
    125 					 * application will wrap around to the
    126 					 * beginning of the list again. */
    127 /*
    128  * these functions are for dealing with a list as a table, of sorts.
    129  * An idea of the "current element" is kept and used by all the functions
    130  * between Lst_Open() and Lst_Close().
    131  */
    132 ReturnStatus	  Lst_Open();	    	/* Open the list */
    133 LstNode		  Lst_Prev();	    	/* Previous element */
    134 LstNode		  Lst_Cur();	    	/* The current element, please */
    135 LstNode		  Lst_Next();	    	/* Next element please */
    136 Boolean		  Lst_IsAtEnd();	/* Done yet? */
    137 void		  Lst_Close();	    	/* Finish table access */
    138 
    139 /*
    140  * for using the list as a queue
    141  */
    142 ReturnStatus	  Lst_EnQueue();	/* Place an element at tail of queue */
    143 ClientData	  Lst_DeQueue();	/* Remove an element from head of
    144 					 * queue */
    145 
    146 #endif _LST_H_
    147