Commit | Line | Data |
---|---|---|
b0ff1758 KB |
1 | /* |
2 | * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. | |
3 | * Copyright (c) 1988, 1989 by Adam de Boor | |
4 | * Copyright (c) 1989 by Berkeley Softworks | |
5 | * All rights reserved. | |
fe902645 | 6 | * |
b0ff1758 KB |
7 | * This code is derived from software contributed to Berkeley by |
8 | * Adam de Boor. | |
fe902645 | 9 | * |
b0ff1758 KB |
10 | * Redistribution and use in source and binary forms are permitted |
11 | * provided that the above copyright notice and this paragraph are | |
12 | * duplicated in all such forms and that any documentation, | |
13 | * advertising materials, and other materials related to such | |
14 | * distribution and use acknowledge that the software was developed | |
15 | * by the University of California, Berkeley. The name of the | |
16 | * University may not be used to endorse or promote products derived | |
17 | * from this software without specific prior written permission. | |
18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
19 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
fe902645 | 21 | * |
b0ff1758 KB |
22 | * @(#)lst.h 5.2 (Berkeley) %G% |
23 | */ | |
24 | ||
25 | /*- | |
26 | * lst.h -- | |
27 | * Header for using the list library | |
fe902645 KB |
28 | */ |
29 | #ifndef _LST_H_ | |
30 | #define _LST_H_ | |
31 | ||
32 | #include <sprite.h> | |
33 | ||
34 | /* | |
35 | * basic typedef. This is what the Lst_ functions handle | |
36 | */ | |
37 | ||
38 | typedef struct Lst *Lst; | |
39 | typedef struct LstNode *LstNode; | |
40 | ||
41 | #define NILLST ((Lst) NIL) | |
42 | #define NILLNODE ((LstNode) NIL) | |
43 | ||
44 | /* | |
45 | * NOFREE can be used as the freeProc to Lst_Destroy when the elements are | |
46 | * not to be freed. | |
47 | * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate. | |
48 | */ | |
49 | #define NOFREE ((void (*)()) 0) | |
50 | #define NOCOPY ((ClientData (*)()) 0) | |
51 | ||
52 | #define LST_CONCNEW 0 /* create new LstNode's when using Lst_Concat */ | |
53 | #define LST_CONCLINK 1 /* relink LstNode's when using Lst_Concat */ | |
54 | ||
55 | /* | |
56 | * Creation/destruction functions | |
57 | */ | |
58 | Lst Lst_Init(); /* Create a new list */ | |
59 | Lst Lst_Duplicate(); /* Duplicate an existing list */ | |
60 | void Lst_Destroy(); /* Destroy an old one */ | |
61 | ||
62 | int Lst_Length(); /* Find the length of a list */ | |
63 | Boolean Lst_IsEmpty(); /* True if list is empty */ | |
64 | ||
65 | /* | |
66 | * Functions to modify a list | |
67 | */ | |
68 | ReturnStatus Lst_Insert(); /* Insert an element before another */ | |
69 | ReturnStatus Lst_Append(); /* Insert an element after another */ | |
70 | ReturnStatus Lst_AtFront(); /* Place an element at the front of | |
71 | * a lst. */ | |
72 | ReturnStatus Lst_AtEnd(); /* Place an element at the end of a | |
73 | * lst. */ | |
74 | ReturnStatus Lst_Remove(); /* Remove an element */ | |
75 | ReturnStatus Lst_Replace(); /* Replace a node with a new value */ | |
76 | ReturnStatus Lst_Move(); /* Move an element to another place */ | |
77 | ReturnStatus Lst_Concat(); /* Concatenate two lists */ | |
78 | ||
79 | /* | |
80 | * Node-specific functions | |
81 | */ | |
82 | LstNode Lst_First(); /* Return first element in list */ | |
83 | LstNode Lst_Last(); /* Return last element in list */ | |
84 | LstNode Lst_Succ(); /* Return successor to given element */ | |
85 | LstNode Lst_Pred(); /* Return predecessor to given | |
86 | * element */ | |
87 | ClientData Lst_Datum(); /* Get datum from LstNode */ | |
88 | ||
89 | /* | |
90 | * Functions for entire lists | |
91 | */ | |
92 | LstNode Lst_Find(); /* Find an element in a list */ | |
93 | LstNode Lst_FindFrom(); /* Find an element starting from | |
94 | * somewhere */ | |
95 | LstNode Lst_Member(); /* See if the given datum is on the | |
96 | * list. Returns the LstNode containing | |
97 | * the datum */ | |
98 | int Lst_Index(); /* Returns the index of a datum in the | |
99 | * list, starting from 0 */ | |
100 | void Lst_ForEach(); /* Apply a function to all elements of | |
101 | * a lst */ | |
102 | void Lst_ForEachFrom(); /* Apply a function to all elements of | |
103 | * a lst starting from a certain point. | |
104 | * If the list is circular, the | |
105 | * application will wrap around to the | |
106 | * beginning of the list again. */ | |
107 | /* | |
108 | * these functions are for dealing with a list as a table, of sorts. | |
109 | * An idea of the "current element" is kept and used by all the functions | |
110 | * between Lst_Open() and Lst_Close(). | |
111 | */ | |
112 | ReturnStatus Lst_Open(); /* Open the list */ | |
113 | LstNode Lst_Prev(); /* Previous element */ | |
114 | LstNode Lst_Cur(); /* The current element, please */ | |
115 | LstNode Lst_Next(); /* Next element please */ | |
116 | Boolean Lst_IsAtEnd(); /* Done yet? */ | |
117 | void Lst_Close(); /* Finish table access */ | |
118 | ||
119 | /* | |
120 | * for using the list as a queue | |
121 | */ | |
122 | ReturnStatus Lst_EnQueue(); /* Place an element at tail of queue */ | |
123 | ClientData Lst_DeQueue(); /* Remove an element from head of | |
124 | * queue */ | |
125 | ||
126 | #endif _LST_H_ |