xref: /original-bsd/usr.bin/make/lst.h (revision e59fb703)
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.
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	5.3 (Berkeley) 06/01/90
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 
24 /*
25  * basic typedef. This is what the Lst_ functions handle
26  */
27 
28 typedef	struct	Lst	*Lst;
29 typedef	struct	LstNode	*LstNode;
30 
31 #define	NILLST		((Lst) NIL)
32 #define	NILLNODE	((LstNode) NIL)
33 
34 /*
35  * NOFREE can be used as the freeProc to Lst_Destroy when the elements are
36  *	not to be freed.
37  * NOCOPY performs similarly when given as the copyProc to Lst_Duplicate.
38  */
39 #define NOFREE		((void (*)()) 0)
40 #define NOCOPY		((ClientData (*)()) 0)
41 
42 #define LST_CONCNEW	0   /* create new LstNode's when using Lst_Concat */
43 #define LST_CONCLINK	1   /* relink LstNode's when using Lst_Concat */
44 
45 /*
46  * Creation/destruction functions
47  */
48 Lst		  Lst_Init();	    	/* Create a new list */
49 Lst	    	  Lst_Duplicate();  	/* Duplicate an existing list */
50 void		  Lst_Destroy();	/* Destroy an old one */
51 
52 int	    	  Lst_Length();	    	/* Find the length of a list */
53 Boolean		  Lst_IsEmpty();	/* True if list is empty */
54 
55 /*
56  * Functions to modify a list
57  */
58 ReturnStatus	  Lst_Insert();	    	/* Insert an element before another */
59 ReturnStatus	  Lst_Append();	    	/* Insert an element after another */
60 ReturnStatus	  Lst_AtFront();    	/* Place an element at the front of
61 					 * a lst. */
62 ReturnStatus	  Lst_AtEnd();	    	/* Place an element at the end of a
63 					 * lst. */
64 ReturnStatus	  Lst_Remove();	    	/* Remove an element */
65 ReturnStatus	  Lst_Replace();	/* Replace a node with a new value */
66 ReturnStatus	  Lst_Move();	    	/* Move an element to another place */
67 ReturnStatus	  Lst_Concat();	    	/* Concatenate two lists */
68 
69 /*
70  * Node-specific functions
71  */
72 LstNode		  Lst_First();	    	/* Return first element in list */
73 LstNode		  Lst_Last();	    	/* Return last element in list */
74 LstNode		  Lst_Succ();	    	/* Return successor to given element */
75 LstNode		  Lst_Pred();	    	/* Return predecessor to given
76 					 * element */
77 ClientData	  Lst_Datum();	    	/* Get datum from LstNode */
78 
79 /*
80  * Functions for entire lists
81  */
82 LstNode		  Lst_Find();	    	/* Find an element in a list */
83 LstNode		  Lst_FindFrom();	/* Find an element starting from
84 					 * somewhere */
85 LstNode	    	  Lst_Member();	    	/* See if the given datum is on the
86 					 * list. Returns the LstNode containing
87 					 * the datum */
88 int	    	  Lst_Index();	    	/* Returns the index of a datum in the
89 					 * list, starting from 0 */
90 void		  Lst_ForEach();	/* Apply a function to all elements of
91 					 * a lst */
92 void	    	  Lst_ForEachFrom();  	/* Apply a function to all elements of
93 					 * a lst starting from a certain point.
94 					 * If the list is circular, the
95 					 * application will wrap around to the
96 					 * beginning of the list again. */
97 /*
98  * these functions are for dealing with a list as a table, of sorts.
99  * An idea of the "current element" is kept and used by all the functions
100  * between Lst_Open() and Lst_Close().
101  */
102 ReturnStatus	  Lst_Open();	    	/* Open the list */
103 LstNode		  Lst_Prev();	    	/* Previous element */
104 LstNode		  Lst_Cur();	    	/* The current element, please */
105 LstNode		  Lst_Next();	    	/* Next element please */
106 Boolean		  Lst_IsAtEnd();	/* Done yet? */
107 void		  Lst_Close();	    	/* Finish table access */
108 
109 /*
110  * for using the list as a queue
111  */
112 ReturnStatus	  Lst_EnQueue();	/* Place an element at tail of queue */
113 ClientData	  Lst_DeQueue();	/* Remove an element from head of
114 					 * queue */
115 
116 #endif _LST_H_
117