include/libtu/dlist.h

Sun, 25 Jan 2004 12:07:52 +0100

author
tuomov
date
Sun, 25 Jan 2004 12:07:52 +0100
changeset 57
de75d868bc0b
parent 56
af2c6d224f9d
permissions
-rw-r--r--

trunk: changeset 1220
Some XX_SOURCE flag changes.

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

mercurial