revert between 56095 -> 55830 in arch
[AROS.git] / tools / MetaMake / list.h
blob3bc56a877333df5554b8734490cad96f5814abad
1 #ifndef __MMAKE_LIST_H
2 #define __MMAKE_LIST_H
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)
12 any later version.
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. */
24 #include <stddef.h>
26 /* This file specifies the API for the list functions */
28 #include "compiler.h"
30 /* Types */
31 struct __mayalias Node;
32 struct Node
34 struct Node * next,
35 * prev;
36 char * name;
39 #ifndef __GNUC__
40 struct List
42 struct Node * first,
43 * last,
44 * prelast;
46 #else
47 struct __mayalias List;
48 struct List
50 union
52 struct Node * first;
53 struct Node ** _first;
55 struct Node * last;
56 union
58 struct Node * prelast;
59 struct List * _prelast;
62 #endif
64 /* inline functions and macros */
65 static inline void __NewList(struct List *l)
67 #ifndef __GNUC__
68 l->prelast = (struct Node *)l;
69 l->_first = (struct Node *)&l->last;
70 #else
71 l->_prelast = l;
72 l->_first = &l->last;
73 #endif
74 l->last = 0;
76 #define NewList(l) __NewList((struct List *)l)
78 static inline void __AddHead(struct List *l, struct Node *n)
80 n->next = l->first;
81 n->prev = (struct Node *)&l->first;
82 l->first->prev = n;
83 l->first = n;
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;
90 n->prev = l->prelast;
91 l->prelast->next = n;
92 l->prelast = n;
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 \
105 : (struct Node *)0)
106 # define GetTail(l) (void *)(((struct List *)l)->prelast->prev \
107 ? ((struct List *)l)->prelast \
108 : (struct Node *)0)
109 # define GetNext(n) (void *)(((struct Node *)n)->next->next \
110 ? ((struct Node *)n)->next \
111 : (struct Node *)0)
112 # define GetPrev(n) (void *)(((struct Node *)n)->prev->prev \
113 ? ((struct Node *)n)->prev \
114 : (struct Node *)0)
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))
124 /* Functions */
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 */