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