4 ** $Id: ListMacros.h,v 1.2 1999/02/07 14:41:02 bernie Exp $
6 ** Copyright (C) 1997 Bernardo Innocenti <bernardo.innocenti@usa.net>
7 ** All rights reserved.
9 ** Use 4 chars wide TABs to read this source
11 ** Some handy macros for list operations. Using these macros is faster
12 ** than calling their exec.library equivalents, but they will eventually
13 ** make your code a little bigger and are also subject to common macro
18 #define NEWLIST(l) ( (l)->lh_TailPred = (struct Node *)(l), \
20 (l)->lh_Head = (struct Node *)(&((l)->lh_Tail)) )
22 #define ADDHEAD(l,n) ( (n)->ln_Pred = (struct Node *)(l), \
23 (n)->ln_Succ = (l)->lh_Head, \
24 (l)->lh_Head->ln_Pred = (n), \
27 #define ADDTAIL(l,n) ( (n)->ln_Succ = (struct Node *)(&((l)->lh_Tail)), \
28 (n)->ln_Pred = (l)->lh_TailPred, \
29 (l)->lh_TailPred->ln_Succ = (n), \
30 (l)->lh_TailPred = (n) )
32 #define REMOVE(n) ( (n)->ln_Succ->ln_Pred = (n)->ln_Pred, \
33 (n)->ln_Pred->ln_Succ = (n)->ln_Succ )
35 #define GETHEAD(l) ( (l)->lh_Head->ln_Succ ? (l)->lh_Head : (struct Node *)NULL )
37 #define GETTAIL(l) ( (l)->lh_TailPred->ln_Succ ? (l)->lh_TailPred : (struct Node *)NULL )
39 #define GETSUCC(n) ( (n)->ln_Succ->ln_Succ ? (n)->ln_Succ : (struct Node *)NULL )
41 #define GETPRED(n) ( (n)->ln_Pred->ln_Pred ? (n)->ln_Pred : (struct Node *)NULL )
48 struct Node *n = (l)->lh_Head; \
50 (l)->lh_Head = n->ln_Succ, \
51 (l)->lh_Head->ln_Pred = (struct Node *)(l), \
58 struct Node *n = (l)->lh_TailPred; \
60 (l)->lh_TailPred = n->ln_Pred, \
61 (l)->lh_TailPred->ln_Succ = (struct Node *)(&((l)->lh_Tail)), \
69 /* These two can't be implemented as macros without the GCC ({...}) language extension */
71 INLINE struct Node *REMHEAD(struct List *l)
73 struct Node *n = l->lh_Head;
77 l->lh_Head = n->ln_Succ;
78 l->lh_Head->ln_Pred = (struct Node *)l;
84 INLINE struct Node *REMTAIL(struct List *l)
86 struct Node *n = l->lh_TailPred;
90 l->lh_TailPred = n->ln_Pred;
91 l->lh_TailPred->ln_Succ = (struct Node *)(&(l->lh_Tail));
99 #endif /* !LISTMACROS_H */