4 /* MetaMake - A Make extension
5 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
7 This file is part of MetaMake.
9 MetaMake is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 MetaMake is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 /* This file specifies the API for the list functions */
31 struct __mayalias Node
;
47 struct __mayalias List
;
53 struct Node
** _first
;
58 struct Node
* prelast
;
59 struct List
* _prelast
;
64 /* inline functions and macros */
65 static inline void __NewList(struct List
*l
)
68 l
->prelast
= (struct Node
*)l
;
69 l
->_first
= (struct Node
*)&l
->last
;
76 #define NewList(l) __NewList((struct List *)l)
78 static inline void __AddHead(struct List
*l
, struct Node
*n
)
81 n
->prev
= (struct Node
*)&l
->first
;
85 #define AddHead(l,n) __AddHead((struct List *)l, (struct Node *)n)
87 static inline void __AddTail(struct List
*l
, struct Node
*n
)
89 n
->next
= (struct Node
*)&l
->last
;
94 #define AddTail(l,n) __AddTail((struct List *)l, (struct Node *)n)
96 static inline void __Remove(struct Node
*n
)
98 n
->prev
->next
= n
->next
;
99 n
->next
->prev
= n
->prev
;
101 #define Remove(n) __Remove((struct Node *)n)
103 # define GetHead(l) (void *)(((struct List *)l)->first->next \
104 ? ((struct List *)l)->first \
106 # define GetTail(l) (void *)(((struct List *)l)->prelast->prev \
107 ? ((struct List *)l)->prelast \
109 # define GetNext(n) (void *)(((struct Node *)n)->next->next \
110 ? ((struct Node *)n)->next \
112 # define GetPrev(n) (void *)(((struct Node *)n)->prev->prev \
113 ? ((struct Node *)n)->prev \
115 # define ForeachNode(l,n) \
116 for (n=(void *)(((struct List *)(l))->first); \
117 ((struct Node *)(n))->next; \
118 n=(void *)(((struct Node *)(n))->next))
119 # define ForeachNodeSafe(l,node,nextnode) \
120 for (node=(void *)(((struct List *)(l))->first); \
121 ((nextnode)=(void*)((struct Node *)(node))->next); \
122 (node)=(void *)(nextnode))
125 void AssignList (struct List
* dest
, struct List
* src
); /* After assignment only dest may be used !!! */
126 void *FindNode (const struct List
* l
, const char * name
);
127 void printlist (struct List
* l
);
128 void freelist (struct List
* l
);
129 struct Node
*newnode (const char * name
);
130 void *newnodesize (const char * name
, size_t size
);
131 struct Node
*addnodeonce (struct List
* l
, const char * name
);
132 void *addnodeoncesize (struct List
* l
, const char * name
, size_t size
);
134 #endif /* __MMAKE_LIST_H */