xref: /original-bsd/usr.bin/make/lst.h (revision c3e32dec)
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.1 (Berkeley) 06/06/93
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 (*)()) 0)
43 #define NOCOPY		((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 Lst		  Lst_Init();	    	/* Create a new list */
52 Lst	    	  Lst_Duplicate();  	/* Duplicate an existing list */
53 void		  Lst_Destroy();	/* Destroy an old one */
54 
55 int	    	  Lst_Length();	    	/* Find the length of a list */
56 Boolean		  Lst_IsEmpty();	/* True if list is empty */
57 
58 /*
59  * Functions to modify a list
60  */
61 ReturnStatus	  Lst_Insert();	    	/* Insert an element before another */
62 ReturnStatus	  Lst_Append();	    	/* Insert an element after another */
63 ReturnStatus	  Lst_AtFront();    	/* Place an element at the front of
64 					 * a lst. */
65 ReturnStatus	  Lst_AtEnd();	    	/* Place an element at the end of a
66 					 * lst. */
67 ReturnStatus	  Lst_Remove();	    	/* Remove an element */
68 ReturnStatus	  Lst_Replace();	/* Replace a node with a new value */
69 ReturnStatus	  Lst_Move();	    	/* Move an element to another place */
70 ReturnStatus	  Lst_Concat();	    	/* Concatenate two lists */
71 
72 /*
73  * Node-specific functions
74  */
75 LstNode		  Lst_First();	    	/* Return first element in list */
76 LstNode		  Lst_Last();	    	/* Return last element in list */
77 LstNode		  Lst_Succ();	    	/* Return successor to given element */
78 LstNode		  Lst_Pred();	    	/* Return predecessor to given
79 					 * element */
80 ClientData	  Lst_Datum();	    	/* Get datum from LstNode */
81 
82 /*
83  * Functions for entire lists
84  */
85 LstNode		  Lst_Find();	    	/* Find an element in a list */
86 LstNode		  Lst_FindFrom();	/* Find an element starting from
87 					 * somewhere */
88 LstNode	    	  Lst_Member();	    	/* See if the given datum is on the
89 					 * list. Returns the LstNode containing
90 					 * the datum */
91 int	    	  Lst_Index();	    	/* Returns the index of a datum in the
92 					 * list, starting from 0 */
93 void		  Lst_ForEach();	/* Apply a function to all elements of
94 					 * a lst */
95 void	    	  Lst_ForEachFrom();  	/* Apply a function to all elements of
96 					 * a lst starting from a certain point.
97 					 * If the list is circular, the
98 					 * application will wrap around to the
99 					 * beginning of the list again. */
100 /*
101  * these functions are for dealing with a list as a table, of sorts.
102  * An idea of the "current element" is kept and used by all the functions
103  * between Lst_Open() and Lst_Close().
104  */
105 ReturnStatus	  Lst_Open();	    	/* Open the list */
106 LstNode		  Lst_Prev();	    	/* Previous element */
107 LstNode		  Lst_Cur();	    	/* The current element, please */
108 LstNode		  Lst_Next();	    	/* Next element please */
109 Boolean		  Lst_IsAtEnd();	/* Done yet? */
110 void		  Lst_Close();	    	/* Finish table access */
111 
112 /*
113  * for using the list as a queue
114  */
115 ReturnStatus	  Lst_EnQueue();	/* Place an element at tail of queue */
116 ClientData	  Lst_DeQueue();	/* Remove an element from head of
117 					 * queue */
118 
119 #endif _LST_H_
120