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