1 /* 2 * Copyright (c) 1988, 1989, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * Copyright (c) 1989 by Berkeley Softworks 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Adam de Boor. 9 * 10 * %sccs.include.redist.c% 11 * 12 * @(#)lst.h 8.2 (Berkeley) 04/28/95 13 */ 14 15 /*- 16 * lst.h -- 17 * Header for using the list library 18 */ 19 #ifndef _LST_H_ 20 #define _LST_H_ 21 22 #include <sprite.h> 23 #if __STDC__ 24 #include <stdlib.h> 25 #endif 26 27 /* 28 * basic typedef. This is what the Lst_ functions handle 29 */ 30 31 typedef struct Lst *Lst; 32 typedef struct LstNode *LstNode; 33 34 #define NILLST ((Lst) NIL) 35 #define NILLNODE ((LstNode) NIL) 36 37 /* 38 * NOFREE can be used as the freeProc to Lst_Destroy when the elements are 39 * not to be freed. 40 * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate. 41 */ 42 #define NOFREE ((void (*) __P((ClientData))) 0) 43 #define NOCOPY ((ClientData (*) __P((ClientData))) 0) 44 45 #define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */ 46 #define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */ 47 48 /* 49 * Creation/destruction functions 50 */ 51 /* Create a new list */ 52 Lst Lst_Init __P((Boolean)); 53 /* Duplicate an existing list */ 54 Lst Lst_Duplicate __P((Lst, ClientData (*)(ClientData))); 55 /* Destroy an old one */ 56 void Lst_Destroy __P((Lst, void (*)(ClientData))); 57 /* True if list is empty */ 58 Boolean Lst_IsEmpty __P((Lst)); 59 60 /* 61 * Functions to modify a list 62 */ 63 /* Insert an element before another */ 64 ReturnStatus Lst_Insert __P((Lst, LstNode, ClientData)); 65 /* Insert an element after another */ 66 ReturnStatus Lst_Append __P((Lst, LstNode, ClientData)); 67 /* Place an element at the front of a lst. */ 68 ReturnStatus Lst_AtFront __P((Lst, ClientData)); 69 /* Place an element at the end of a lst. */ 70 ReturnStatus Lst_AtEnd __P((Lst, ClientData)); 71 /* Remove an element */ 72 ReturnStatus Lst_Remove __P((Lst, LstNode)); 73 /* Replace a node with a new value */ 74 ReturnStatus Lst_Replace __P((LstNode, ClientData)); 75 /* Concatenate two lists */ 76 ReturnStatus Lst_Concat __P((Lst, Lst, int)); 77 78 /* 79 * Node-specific functions 80 */ 81 /* Return first element in list */ 82 LstNode Lst_First __P((Lst)); 83 /* Return last element in list */ 84 LstNode Lst_Last __P((Lst)); 85 /* Return successor to given element */ 86 LstNode Lst_Succ __P((LstNode)); 87 /* Get datum from LstNode */ 88 ClientData Lst_Datum __P((LstNode)); 89 90 /* 91 * Functions for entire lists 92 */ 93 /* Find an element in a list */ 94 LstNode Lst_Find __P((Lst, ClientData, 95 int (*)(ClientData, ClientData))); 96 /* Find an element starting from somewhere */ 97 LstNode Lst_FindFrom __P((Lst, LstNode, ClientData, 98 int (*cProc)(ClientData, ClientData))); 99 /* 100 * See if the given datum is on the list. Returns the LstNode containing 101 * the datum 102 */ 103 LstNode Lst_Member __P((Lst, ClientData)); 104 /* Apply a function to all elements of a lst */ 105 void Lst_ForEach __P((Lst, int (*)(ClientData, ClientData), 106 ClientData)); 107 /* 108 * Apply a function to all elements of a lst starting from a certain point. 109 * If the list is circular, the application will wrap around to the 110 * beginning of the list again. 111 */ 112 void Lst_ForEachFrom __P((Lst, LstNode, 113 int (*)(ClientData, ClientData), 114 ClientData)); 115 /* 116 * these functions are for dealing with a list as a table, of sorts. 117 * An idea of the "current element" is kept and used by all the functions 118 * between Lst_Open() and Lst_Close(). 119 */ 120 /* Open the list */ 121 ReturnStatus Lst_Open __P((Lst)); 122 /* Next element please */ 123 LstNode Lst_Next __P((Lst)); 124 /* Done yet? */ 125 Boolean Lst_IsAtEnd __P((Lst)); 126 /* Finish table access */ 127 void Lst_Close __P((Lst)); 128 129 /* 130 * for using the list as a queue 131 */ 132 /* Place an element at tail of queue */ 133 ReturnStatus Lst_EnQueue __P((Lst, ClientData)); 134 /* Remove an element from head of queue */ 135 ClientData Lst_DeQueue __P((Lst)); 136 137 #endif /* _LST_H_ */ 138