[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.5

1.5     ! mickey      1: /*     $OpenBSD: lst.h,v 1.4 1996/11/30 21:08:58 millert 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:
                     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;
                     63:
                     64: #define        NILLST          ((Lst) NIL)
                     65: #define        NILLNODE        ((LstNode) NIL)
                     66:
                     67: /*
                     68:  * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
                     69:  *     not to be freed.
                     70:  * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
                     71:  */
                     72: #define NOFREE         ((void (*) __P((ClientData))) 0)
                     73: #define NOCOPY         ((ClientData (*) __P((ClientData))) 0)
                     74:
                     75: #define LST_CONCNEW    0   /* create new LstNode's when using Lst_Concat */
                     76: #define LST_CONCLINK   1   /* relink LstNode's when using Lst_Concat */
                     77:
                     78: /*
                     79:  * Creation/destruction functions
                     80:  */
                     81: /* Create a new list */
                     82: Lst            Lst_Init __P((Boolean));
                     83: /* Duplicate an existing list */
                     84: Lst            Lst_Duplicate __P((Lst, ClientData (*)(ClientData)));
                     85: /* Destroy an old one */
                     86: void           Lst_Destroy __P((Lst, void (*)(ClientData)));
                     87: /* True if list is empty */
                     88: Boolean                Lst_IsEmpty __P((Lst));
                     89:
                     90: /*
                     91:  * Functions to modify a list
                     92:  */
                     93: /* Insert an element before another */
                     94: ReturnStatus   Lst_Insert __P((Lst, LstNode, ClientData));
                     95: /* Insert an element after another */
                     96: ReturnStatus   Lst_Append __P((Lst, LstNode, ClientData));
                     97: /* Place an element at the front of a lst. */
                     98: ReturnStatus   Lst_AtFront __P((Lst, ClientData));
                     99: /* Place an element at the end of a lst. */
                    100: ReturnStatus   Lst_AtEnd __P((Lst, ClientData));
                    101: /* Remove an element */
                    102: ReturnStatus   Lst_Remove __P((Lst, LstNode));
                    103: /* Replace a node with a new value */
                    104: ReturnStatus   Lst_Replace __P((LstNode, ClientData));
                    105: /* Concatenate two lists */
                    106: ReturnStatus   Lst_Concat __P((Lst, Lst, int));
                    107:
                    108: /*
                    109:  * Node-specific functions
                    110:  */
                    111: /* Return first element in list */
                    112: LstNode                Lst_First __P((Lst));
                    113: /* Return last element in list */
                    114: LstNode                Lst_Last __P((Lst));
                    115: /* Return successor to given element */
                    116: LstNode                Lst_Succ __P((LstNode));
                    117: /* Get datum from LstNode */
                    118: ClientData     Lst_Datum __P((LstNode));
                    119:
                    120: /*
                    121:  * Functions for entire lists
                    122:  */
                    123: /* Find an element in a list */
1.4       millert   124: LstNode                Lst_Find __P((Lst, ClientData,
1.1       deraadt   125:                              int (*)(ClientData, ClientData)));
                    126: /* Find an element starting from somewhere */
                    127: LstNode                Lst_FindFrom __P((Lst, LstNode, ClientData,
                    128:                                  int (*cProc)(ClientData, ClientData)));
1.4       millert   129: /*
1.1       deraadt   130:  * See if the given datum is on the list. Returns the LstNode containing
                    131:  * the datum
                    132:  */
                    133: LstNode                Lst_Member __P((Lst, ClientData));
                    134: /* Apply a function to all elements of a lst */
                    135: void           Lst_ForEach __P((Lst, int (*)(ClientData, ClientData),
                    136:                                 ClientData));
                    137: /*
                    138:  * Apply a function to all elements of a lst starting from a certain point.
                    139:  * If the list is circular, the application will wrap around to the
                    140:  * beginning of the list again.
                    141:  */
                    142: void           Lst_ForEachFrom __P((Lst, LstNode,
                    143:                                     int (*)(ClientData, ClientData),
                    144:                                     ClientData));
                    145: /*
                    146:  * these functions are for dealing with a list as a table, of sorts.
                    147:  * An idea of the "current element" is kept and used by all the functions
                    148:  * between Lst_Open() and Lst_Close().
                    149:  */
                    150: /* Open the list */
                    151: ReturnStatus   Lst_Open __P((Lst));
                    152: /* Next element please */
                    153: LstNode                Lst_Next __P((Lst));
                    154: /* Done yet? */
                    155: Boolean                Lst_IsAtEnd __P((Lst));
                    156: /* Finish table access */
                    157: void           Lst_Close __P((Lst));
                    158:
                    159: /*
                    160:  * for using the list as a queue
                    161:  */
                    162: /* Place an element at tail of queue */
                    163: ReturnStatus   Lst_EnQueue __P((Lst, ClientData));
                    164: /* Remove an element from head of queue */
                    165: ClientData     Lst_DeQueue __P((Lst));
                    166:
                    167: #endif /* _LST_H_ */