ptrlist.c

Mon, 07 May 2012 15:25:18 +0200

author
Tuomo Valkonen <tuomov@iki.fi>
date
Mon, 07 May 2012 15:25:18 +0200
changeset 115
f60f9a415d1b
parent 111
7d1dccdd7215
permissions
-rw-r--r--

-DCF_NO_GETTEXT option to system.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
111
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
56 bool ptrlist_contains(PtrList *ptrlist, void *ptr)
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
57 {
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
58 return (ptrlist_find_node(ptrlist, ptr)!=NULL);
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
59 }
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
60
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
61
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
62 bool ptrlist_insert_last(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
63 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
64 PtrList *node=mknode(ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
65
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
66 if(node==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
67 return FALSE;
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 LINK_ITEM_LAST(*ptrlist, node, next, prev);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
70
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
71 return TRUE;
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
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
74
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
75 bool ptrlist_insert_first(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
76 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
77 PtrList *node=mknode(ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
78
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
79 if(node==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
80 return FALSE;
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 LINK_ITEM_FIRST(*ptrlist, node, next, prev);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
83
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
84 return TRUE;
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
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
87
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
88 bool ptrlist_reinsert_last(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
89 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
90 PtrList *node=ptrlist_find_node(*ptrlist, ptr);
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 if(node==NULL)
111
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
93 return ptrlist_insert_last(ptrlist, ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
94
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
95 UNLINK_ITEM(*ptrlist, node, next, prev);
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
96 LINK_ITEM_LAST(*ptrlist, node, next, prev);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
97
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
98 return TRUE;
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
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
101
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
102 bool ptrlist_reinsert_first(PtrList **ptrlist, void *ptr)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
103 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
104 PtrList *node=ptrlist_find_node(*ptrlist, ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
105
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
106 if(node==NULL)
111
7d1dccdd7215 Some list code improvements
Tuomo Valkonen <tuomov@iki.fi>
parents: 101
diff changeset
107 return ptrlist_insert_first(ptrlist, ptr);
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
108
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
109 UNLINK_ITEM(*ptrlist, node, next, prev);
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
110 LINK_ITEM_FIRST(*ptrlist, node, next, prev);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
111
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
112 return TRUE;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
113 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
114
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
115
101
50525dab6c8e *list_remove return true if the item was found (and removed).
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
116 bool ptrlist_remove(PtrList **ptrlist, void *ptr)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
117 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
118 PtrList *node=ptrlist_find_node(*ptrlist, ptr);
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
119
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
120 if(node!=NULL)
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
121 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
122
50525dab6c8e *list_remove return true if the item was found (and removed).
Tuomo Valkonen <tuomov@iki.fi>
parents: 92
diff changeset
123 return (node!=NULL);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
124 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
125
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
126
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
127 void ptrlist_clear(PtrList **ptrlist)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
128 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
129 while(*ptrlist!=NULL)
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
130 free_node(ptrlist, *ptrlist);
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
131 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
132
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
133
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
134 PtrListIterTmp ptrlist_iter_tmp=NULL;
60
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_init(PtrListIterTmp *state, PtrList *ptrlist)
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 *state=ptrlist;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
140 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
141
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
142
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
143 void *ptrlist_iter(PtrListIterTmp *state)
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
144 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
145 void *ptr=NULL;
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
146
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
147 if(*state!=NULL){
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
148 ptr=(*state)->ptr;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
149 (*state)=(*state)->next;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
150 }
62
aae5facf9fc5 trunk: changeset 1318
tuomov
parents: 60
diff changeset
151
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
152 return ptr;
60
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
153 }
a4033700e35c trunk: changeset 1313
tuomov
parents:
diff changeset
154
88
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_init(PtrListIterTmp *state, PtrList *ptrlist)
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 *state=(ptrlist==NULL ? NULL : ptrlist->prev);
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
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
161
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
162 void *ptrlist_iter_rev(PtrListIterTmp *state)
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
163 {
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
164 void *ptr=NULL;
88
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 if(*state!=NULL){
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
167 ptr=(*state)->ptr;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
168 *state=(*state)->prev;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
169 if((*state)->next==NULL)
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
170 *state=NULL;
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
171 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
172
90
f5a392131875 Renamed Symlist PtrList.
Tuomo Valkonen <tuomov@iki.fi>
parents: 88
diff changeset
173 return ptr;
88
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
174 }
308dfa54da3e Symlist improvements.
Tuomo Valkonen <tuomov@iki.fi>
parents: 62
diff changeset
175
92
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
176
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
177 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
178 {
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
179 PtrList *node=*ptrlist;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
180 void *ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
181
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
182 if(node==NULL)
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
183 return NULL;
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 ptr=node->ptr;
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 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
188
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
189 return ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
190 }
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
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
193 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
194 {
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
195 PtrList *node=*ptrlist;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
196 void *ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
197
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
198 if(node==NULL)
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
199 return NULL;
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 node=node->prev;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
202
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
203 ptr=node->ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
204
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
205 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
206
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
207 return ptr;
55fcdff5bcea Added routines to take first/last elements of objlist and ptrlist.
Tuomo Valkonen <tuomov@iki.fi>
parents: 90
diff changeset
208 }

mercurial