1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 //		Slist.H		Singly-linked list header file
20 //		Rex E. Bradford (REX)
21 /*
22 * $Header: n:/project/lib/src/dstruct/RCS/slist.h 1.1 1993/05/03 10:53:29 rex Exp $
23 * $Log: slist.h $
24  * Revision 1.1  1993/05/03  10:53:29  rex
25  * Initial revision
26  *
27 */
28 
29 #ifndef SLIST_H
30 #define SLIST_H
31 
32 //#include "types.h"
33 
34 //	--------------------------------------------------------------
35 
36 //	Slist node
37 
38 typedef struct _slist {
39 	struct _slist *psnext;	// ptr to next node or NULL if last one
40 									// real data follows, here
41 } slist;
42 
43 //	Slist header
44 
45 typedef struct _slist_head {
46 	struct _slist *psnext;				// ptr to 1st item in list
47 } slist_head;
48 
49 //	Initialize an slist header (must be done before use)
50 
51 #define slist_init(pslh) { (pslh)->psnext = NULL; }
52 
53 //	Add a new slist node to head of list
54 
55 #define slist_add_head(pslh,psl) { \
56 	(psl)->psnext = slist_head(pslh); \
57 	(pslh)->psnext = (slist *) psl; \
58 	}
59 
60 //	Insert after specified node
61 
62 #define slist_insert_after(psl,pnode) { \
63 	(psl)->psnext = (pnode)->psnext; \
64 	(pnode)->psnext = (slist *) psl; \
65 	}
66 
67 //	Remove node (must specify prior node)
68 
69 #define slist_remove(psl,pslbefore) { (pslbefore)->psnext = (psl)->psnext; }
70 
71 //	Get ptr to head slist node
72 
73 #define slist_head(pslh) (slist *)((pslh)->psnext)
74 
75 //	Determine if list empty
76 
77 #define slist_empty(pslh) (slist_head(pslh) == NULL)
78 
79 //	Get next node
80 
81 #define slist_next(psl) (slist *)((psl)->psnext)		// get ptr to next node
82 
83 //	Iterate across all items
84 
85 #define forallinslist(listtype,pslh,psl) for (psl = \
86 	(listtype *)slist_head(pslh); psl != NULL; psl = (listtype *)slist_next(psl))
87 
88 
89 #endif
90