Wed, 10 Mar 2004 18:31:01 +0100
trunk: changeset 1374
Added include checks to rb header.
58 | 1 | /* |
2 | * libtu/common.h | |
3 | * | |
4 | * Copyright (c) Tuomo Valkonen 1999-2002. | |
5 | * | |
6 | * You may distribute and modify this library under the terms of either | |
7 | * the Clarified Artistic License or the GNU LGPL, version 2.1 or later. | |
8 | */ | |
9 | ||
10 | #ifndef LIBTU_DLIST_H | |
11 | #define LIBTU_DLIST_H | |
12 | ||
13 | #define LINK_ITEM(LIST, ITEM, NEXT, PREV) \ | |
62 | 14 | (ITEM)->NEXT=NULL; \ |
15 | if((LIST)==NULL){ \ | |
16 | (LIST)=(ITEM); \ | |
17 | (ITEM)->PREV=(ITEM); \ | |
18 | }else{ \ | |
19 | (ITEM)->PREV=(LIST)->PREV; \ | |
20 | (ITEM)->PREV->NEXT=(ITEM); \ | |
21 | (LIST)->PREV=(ITEM); \ | |
22 | } | |
58 | 23 | |
24 | ||
25 | #define LINK_ITEM_FIRST(LIST, ITEM, NEXT, PREV) \ | |
62 | 26 | (ITEM)->NEXT=(LIST); \ |
27 | if((LIST)==NULL){ \ | |
28 | (ITEM)->PREV=(ITEM); \ | |
29 | }else{ \ | |
30 | (ITEM)->PREV=(LIST)->PREV; \ | |
31 | (LIST)->PREV=(ITEM); \ | |
32 | } \ | |
33 | (LIST)=(ITEM); | |
58 | 34 | |
35 | ||
36 | #define LINK_ITEM_LIST LINK_ITEM | |
37 | ||
38 | ||
39 | #define LINK_ITEM_BEFORE(LIST, BEFORE, ITEM, NEXT, PREV) \ | |
62 | 40 | (ITEM)->NEXT=(BEFORE); \ |
41 | (ITEM)->PREV=(BEFORE)->PREV; \ | |
42 | (BEFORE)->PREV=(ITEM); \ | |
43 | if((BEFORE)==(LIST)) \ | |
44 | (LIST)=(ITEM); \ | |
45 | else \ | |
46 | (ITEM)->PREV->NEXT=(ITEM) | |
58 | 47 | |
48 | ||
49 | #define LINK_ITEM_AFTER(LIST, AFTER, ITEM, NEXT, PREV) \ | |
62 | 50 | (ITEM)->NEXT=(AFTER)->NEXT; \ |
51 | (ITEM)->PREV=(AFTER); \ | |
52 | (AFTER)->NEXT=(ITEM); \ | |
53 | if((ITEM)->NEXT==NULL) \ | |
54 | (LIST)->PREV=(ITEM); \ | |
55 | else \ | |
56 | (ITEM)->NEXT->PREV=ITEM; | |
58 | 57 | |
58 | ||
59 | #define UNLINK_ITEM(LIST, ITEM, NEXT, PREV) \ | |
62 | 60 | if((ITEM)->PREV!=NULL){ \ |
61 | if((ITEM)==(LIST)){ \ | |
62 | (LIST)=(ITEM)->NEXT; \ | |
63 | if((LIST)!=NULL) \ | |
64 | (LIST)->PREV=(ITEM)->PREV; \ | |
65 | }else if((ITEM)->NEXT==NULL){ \ | |
66 | (ITEM)->PREV->NEXT=NULL; \ | |
67 | (LIST)->PREV=(ITEM)->PREV; \ | |
68 | }else{ \ | |
69 | (ITEM)->PREV->NEXT=(ITEM)->NEXT; \ | |
70 | (ITEM)->NEXT->PREV=(ITEM)->PREV; \ | |
71 | } \ | |
72 | } \ | |
73 | (ITEM)->NEXT=NULL; \ | |
74 | (ITEM)->PREV=NULL; | |
58 | 75 | |
76 | #endif /* LIBTU_DLIST_H */ |