added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / compiler / include / exec / lists.h
blob189e31d67144f0bc7a63725e039f69abbba41333
1 #ifndef EXEC_LISTS_H
2 #define EXEC_LISTS_H
4 /*
5 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
7 Structures and macros for exec lists.
8 */
11 /**************************************
12 Includes
13 **************************************/
14 #ifndef EXEC_NODES_H
15 # include <exec/nodes.h>
16 #endif
19 /**************************************
20 Structures
21 **************************************/
22 /* Normal list */
23 struct List
25 struct Node * lh_Head,
26 * lh_Tail,
27 * lh_TailPred;
28 UBYTE lh_Type;
29 UBYTE l_pad;
32 /* Minimal list */
33 struct MinList
35 struct MinNode * mlh_Head,
36 * mlh_Tail,
37 * mlh_TailPred;
41 /**************************************
42 Makros
43 **************************************/
44 #define IsListEmpty(l) \
45 ( (((struct List *)l)->lh_TailPred) == (struct Node *)(l) )
47 #define IsMsgPortEmpty(mp) \
48 ( (((struct MsgPort *)(mp))->mp_MsgList.lh_TailPred) \
49 == (struct Node *)(&(((struct MsgPort *)(mp))->mp_MsgList)) )
51 #define NEWLIST(_l) \
52 do \
53 { \
54 struct List *__aros_list_tmp = (struct List *)(_l), \
55 *l = __aros_list_tmp; \
57 l->lh_TailPred = (struct Node *)l; \
58 l->lh_Tail = 0; \
59 l->lh_Head = (struct Node *)&l->lh_Tail; \
60 } while (0)
62 #define ADDHEAD(_l,_n) \
63 do \
64 { \
65 struct Node *__aros_node_tmp = (struct Node *)(_n), \
66 *n = __aros_node_tmp; \
67 struct List *__aros_list_tmp = (struct List *)(_l), \
68 *l = __aros_list_tmp; \
70 n->ln_Succ = l->lh_Head; \
71 n->ln_Pred = (struct Node *)&l->lh_Head; \
72 l->lh_Head->ln_Pred = n; \
73 l->lh_Head = n; \
74 } while (0)
76 #define ADDTAIL(_l,_n) \
77 do \
78 { \
79 struct Node *__aros_node_tmp = (struct Node *)(_n), \
80 *n = __aros_node_tmp; \
81 struct List *__aros_list_tmp = (struct List *)(_l), \
82 *l = __aros_list_tmp; \
84 n->ln_Succ = (struct Node *)&l->lh_Tail; \
85 n->ln_Pred = l->lh_TailPred; \
86 l->lh_TailPred->ln_Succ = n; \
87 l->lh_TailPred = n; \
88 } while (0)
90 #define REMOVE(_n) \
91 ({ \
92 struct Node *__aros_node_tmp = (struct Node *)(_n), \
93 *n = __aros_node_tmp; \
95 n->ln_Pred->ln_Succ = n->ln_Succ; \
96 n->ln_Succ->ln_Pred = n->ln_Pred; \
98 n; \
101 #define GetHead(_l) \
102 ({ \
103 struct List *__aros_list_tmp = (struct List *)(_l), \
104 *l = __aros_list_tmp; \
106 l->lh_Head->ln_Succ ? l->lh_Head : (struct Node *)0; \
109 #define GetTail(_l) \
110 ({ \
111 struct List *__aros_list_tmp = (struct List *)(_l), \
112 *l = __aros_list_tmp; \
114 l->lh_TailPred->ln_Pred ? l->lh_TailPred : (struct Node *)0; \
117 #define GetSucc(_n) \
118 ({ \
119 struct Node *__aros_node_tmp = (struct Node *)(_n), \
120 *n = __aros_node_tmp; \
122 n->ln_Succ->ln_Succ ? n->ln_Succ : (struct Node *)0; \
125 #define GetPred(_n) \
126 ({ \
127 struct Node *__aros_node_tmp = (struct Node *)(_n), \
128 *n = __aros_node_tmp; \
130 n->ln_Pred->ln_Pred ? n->ln_Pred : (struct Node *)0; \
133 #define REMHEAD(_l) \
134 ({ \
135 struct List *__aros_list_tmp = (struct List *)(_l), \
136 *l = __aros_list_tmp; \
138 l->lh_Head->ln_Succ ? REMOVE(l->lh_Head) : (struct Node *)0; \
141 #define REMTAIL(_l) \
142 ({ \
143 struct List *__aros_list_tmp = (struct List *)(_l), \
144 *l = __aros_list_tmp; \
146 l->lh_TailPred->ln_Pred ? REMOVE(l->lh_TailPred) : (struct Node *)0; \
149 #define ForeachNode(list, node) \
150 for \
152 node = (void *)(((struct List *)(list))->lh_Head); \
153 ((struct Node *)(node))->ln_Succ; \
154 node = (void *)(((struct Node *)(node))->ln_Succ) \
157 #define ForeachNodeSafe(list, current, next) \
158 for \
160 current = (void *)(((struct List *)(list))->lh_Head); \
161 (next = (void *)((struct Node *)(current))->ln_Succ); \
162 current = (void *)next \
165 #define ListLength(list,count) \
166 do { \
167 struct Node * __n; \
168 count = 0; \
169 ForeachNode (list,__n) count ++; \
170 } while (0)
172 #endif /* EXEC_LISTS_H */