[BACK]Return to lst.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / make

Annotation of src/usr.bin/make/lst.h, Revision 1.13

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