ptrlist.c

Thu, 03 Aug 2006 23:09:14 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Thu, 03 Aug 2006 23:09:14 +0200
changeset 102
c00694dbcde8
parent 101
50525dab6c8e
child 111
7d1dccdd7215
permissions
-rw-r--r--

Updated locations of *.mk.

60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
1 /*
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
2 * libtu/ptrlist.c
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
3 *
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
4 * Copyright (c) Tuomo Valkonen 1999-2005.
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
5 *
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
6 * You may distribute and modify this library under the terms of either
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
8 */
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
9
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
10 #include "obj.h"
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
11 #include "ptrlist.h"
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
12 #include "types.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
13 #include "dlist.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
14 #include "misc.h"
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
15
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
16
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
17 static void free_node(PtrList **ptrlist, PtrList *node)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
18 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
19 UNLINK_ITEM(*ptrlist, node, next, prev);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
20 free(node);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
21 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
22
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
23
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
24 static PtrList *mknode(void *ptr)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
25 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
26 PtrList *node;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
27
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
28 if(ptr==NULL)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
29 return NULL;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
30
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
31 node=ALLOC(PtrList);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
32
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
33 if(node==NULL)
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
34 return FALSE;
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
35
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
36 node->ptr=ptr;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
37
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
38 return node;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
39 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
40
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
41
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
42 static PtrList *ptrlist_find_node(PtrList *ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
43 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
44 PtrList *node=ptrlist;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
45
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
46 while(node!=NULL){
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
47 if(node->ptr==ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
48 break;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
49 node=node->next;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
50 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
51
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
52 return node;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
53 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
54
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
55
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
56 bool ptrlist_insert_last(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
57 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
58 PtrList *node=mknode(ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
59
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
60 if(node==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
61 return FALSE;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
62
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
63 LINK_ITEM_LAST(*ptrlist, node, next, prev);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
64
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
65 return TRUE;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
66 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
67
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
68
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
69 bool ptrlist_insert_first(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
70 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
71 PtrList *node=mknode(ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
72
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
73 if(node==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
74 return FALSE;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
75
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
76 LINK_ITEM_FIRST(*ptrlist, node, next, prev);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
77
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
78 return TRUE;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
79 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
80
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
81
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
82 bool ptrlist_reinsert_last(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
83 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
84 PtrList *node=ptrlist_find_node(*ptrlist, ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
85
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
86 if(node==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
87 return FALSE;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
88
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
89 UNLINK_ITEM(*ptrlist, node, next, prev);
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
90 LINK_ITEM_LAST(*ptrlist, node, next, prev);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
91
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
92 return TRUE;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
93 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
94
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
95
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
96 bool ptrlist_reinsert_first(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
97 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
98 PtrList *node=ptrlist_find_node(*ptrlist, ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
99
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
100 if(node==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
101 return FALSE;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
102
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
103 UNLINK_ITEM(*ptrlist, node, next, prev);
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
104 LINK_ITEM_FIRST(*ptrlist, node, next, prev);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
105
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
106 return TRUE;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
107 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
108
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
109
101
50525dab6c8e *list_remove return true if the item was found (and removed).
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
110 bool ptrlist_remove(PtrList **ptrlist, void *ptr)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
111 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
112 PtrList *node=ptrlist_find_node(*ptrlist, ptr);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
113
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
114 if(node!=NULL)
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
115 free_node(ptrlist, node);
101
50525dab6c8e *list_remove return true if the item was found (and removed).
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
116
50525dab6c8e *list_remove return true if the item was found (and removed).
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
117 return (node!=NULL);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
118 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
119
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
120
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
121 void ptrlist_clear(PtrList **ptrlist)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
122 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
123 while(*ptrlist!=NULL)
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
124 free_node(ptrlist, *ptrlist);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
125 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
126
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
127
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
128 PtrListIterTmp ptrlist_iter_tmp=NULL;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
129
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
130
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
131 void ptrlist_iter_init(PtrListIterTmp *state, PtrList *ptrlist)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
132 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
133 *state=ptrlist;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
134 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
135
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
136
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
137 void *ptrlist_iter(PtrListIterTmp *state)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
138 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
139 void *ptr=NULL;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
140
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
141 if(*state!=NULL){
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
142 ptr=(*state)->ptr;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
143 (*state)=(*state)->next;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
144 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
145
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
146 return ptr;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
147 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
148
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
149
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
150 void ptrlist_iter_rev_init(PtrListIterTmp *state, PtrList *ptrlist)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
151 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
152 *state=(ptrlist==NULL ? NULL : ptrlist->prev);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
153 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
154
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
155
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
156 void *ptrlist_iter_rev(PtrListIterTmp *state)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
157 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
158 void *ptr=NULL;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
159
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
160 if(*state!=NULL){
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
161 ptr=(*state)->ptr;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
162 *state=(*state)->prev;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
163 if((*state)->next==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
164 *state=NULL;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
165 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
166
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
167 return ptr;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
168 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
169
92
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
170
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
171 void *ptrlist_take_first(PtrList **ptrlist)
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
172 {
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
173 PtrList *node=*ptrlist;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
174 void *ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
175
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
176 if(node==NULL)
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
177 return NULL;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
178
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
179 ptr=node->ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
180
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
181 free_node(ptrlist, node);
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
182
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
183 return ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
184 }
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
185
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
186
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
187 void *ptrlist_take_last(PtrList **ptrlist)
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
188 {
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
189 PtrList *node=*ptrlist;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
190 void *ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
191
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
192 if(node==NULL)
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
193 return NULL;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
194
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
195 node=node->prev;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
196
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
197 ptr=node->ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
198
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
199 free_node(ptrlist, node);
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
200
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
201 return ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
202 }

mercurial