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