-rw-r--r-- | libical/src/libical/pvl.c | 493 |
1 files changed, 158 insertions, 335 deletions
diff --git a/libical/src/libical/pvl.c b/libical/src/libical/pvl.c index 2a733e8..9c271ce 100644 --- a/libical/src/libical/pvl.c +++ b/libical/src/libical/pvl.c | |||
@@ -12,54 +12,47 @@ | |||
12 | 12 | ||
13 | #include "pvl.h" | 13 | #include "pvl.h" |
14 | #include <errno.h> | 14 | #include <errno.h> |
15 | #include <assert.h> | 15 | #include <assert.h> |
16 | #include <stdlib.h> | 16 | #include <stdlib.h> |
17 | 17 | ||
18 | 18 | /** | |
19 | |||
20 | /* | ||
21 | struct pvl_list_t | 19 | struct pvl_list_t |
22 | 20 | ||
23 | The list structure. This is the hanlde for the entire list | 21 | The list structure. This is the hanlde for the entire list |
24 | 22 | ||
25 | This type is also private. Use pvl_list instead | 23 | This type is also private. Use pvl_list instead |
26 | 24 | ||
27 | */ | 25 | */ |
28 | 26 | ||
29 | typedef struct pvl_list_t | 27 | typedef struct pvl_list_t |
30 | { | 28 | { |
31 | int MAGIC; /* Magic Identifier */ | 29 | int MAGIC; /**< Magic Identifier */ |
32 | struct pvl_elem_t *head;/* Head of list */ | 30 | struct pvl_elem_t *head;/**< Head of list */ |
33 | struct pvl_elem_t *tail;/* Tail of list */ | 31 | struct pvl_elem_t *tail;/**< Tail of list */ |
34 | int count; /* Number of items in the list */ | 32 | int count; /**< Number of items in the list */ |
35 | struct pvl_elem_t *p; /* Pointer used for iterators */ | 33 | struct pvl_elem_t *p; /**< Pointer used for iterators */ |
36 | } pvl_list_t; | 34 | } pvl_list_t; |
37 | 35 | ||
38 | 36 | ||
39 | 37 | ||
40 | 38 | ||
41 | /* This global is incremented for each call to pvl_new_element(); it gives each | 39 | /** |
42 | * list a unique identifer */ | 40 | * This global is incremented for each call to pvl_new_element(); it gives each |
41 | * list a unique identifer | ||
42 | */ | ||
43 | 43 | ||
44 | int pvl_elem_count = 0; | 44 | int pvl_elem_count = 0; |
45 | int pvl_list_count = 0; | 45 | int pvl_list_count = 0; |
46 | 46 | ||
47 | 47 | ||
48 | /*---------------------------------------------------------------------- | 48 | /** |
49 | Function: pvl_list pvl_newlist() | 49 | * @brief Creates a new list, clears the pointers and assigns a magic number |
50 | 50 | * | |
51 | Purpose: | 51 | * @return Pointer to the new list, 0 if there is no available memory. |
52 | 52 | */ | |
53 | Creates a new list, clears the pointers and assigns a magic number | ||
54 | |||
55 | Returns: | ||
56 | |||
57 | Pointer to the new list | ||
58 | 0 if there is no available memory. | ||
59 | *----------------------------------------------------------------------*/ | ||
60 | 53 | ||
61 | pvl_list | 54 | pvl_list |
62 | pvl_newlist() | 55 | pvl_newlist() |
63 | { | 56 | { |
64 | struct pvl_list_t *L; | 57 | struct pvl_list_t *L; |
65 | 58 | ||
@@ -86,35 +79,26 @@ pvl_free(pvl_list l) | |||
86 | 79 | ||
87 | pvl_clear(l); | 80 | pvl_clear(l); |
88 | 81 | ||
89 | free(L); | 82 | free(L); |
90 | } | 83 | } |
91 | 84 | ||
92 | /*---------------------------------------------------------------------- | 85 | /** |
93 | Function: pvl_new_element(void *d, struct pvl_elem_t *next,struct pvl_elem_t *prior) | 86 | * @brief Creates a new list element, assigns a magic number, and assigns |
94 | 87 | * the next and previous pointers. | |
95 | Purpose: | 88 | * |
96 | Creates a new list element, assigns a magic number, and assigns | 89 | * Passing in the next and previous points may seem odd, but it allos the user |
97 | the next and previous pointers. | 90 | * to set them while keeping the internal data hidden. In nearly all cases, |
98 | 91 | * the user is the pvl library itself. | |
99 | Passing in the next and previous points may seem odd, but it allos the user | 92 | * |
100 | to set them while keeping the internal data hidden. In nearly all cases, | 93 | * @param dThe data item to be stored in the list |
101 | the user is the pvl library itself. | 94 | * @param next Pointer value to assign to the member "next" |
102 | 95 | * @param prior Pointer value to assign to the member "prior" | |
103 | Parameters: | 96 | * |
104 | 97 | * @return A pointer to the new element, 0 if there is no memory available. | |
105 | dThe data item to be stored in the list | 98 | */ |
106 | next Pointer value to assign to the member "next" | ||
107 | prior Pointer value to assign to the member "prior" | ||
108 | |||
109 | Returns: | ||
110 | |||
111 | A pointer to the new element. | ||
112 | 0 if there is no memory available. | ||
113 | |||
114 | *----------------------------------------------------------------------*/ | ||
115 | 99 | ||
116 | pvl_elem | 100 | pvl_elem |
117 | pvl_new_element(void *d, pvl_elem next,pvl_elem prior) | 101 | pvl_new_element(void *d, pvl_elem next,pvl_elem prior) |
118 | { | 102 | { |
119 | struct pvl_elem_t *E; | 103 | struct pvl_elem_t *E; |
120 | 104 | ||
@@ -129,31 +113,22 @@ pvl_new_element(void *d, pvl_elem next,pvl_elem prior) | |||
129 | E->next = next; | 113 | E->next = next; |
130 | E->prior = prior; | 114 | E->prior = prior; |
131 | 115 | ||
132 | return (pvl_elem)E; | 116 | return (pvl_elem)E; |
133 | } | 117 | } |
134 | 118 | ||
135 | /*---------------------------------------------------------------------- | 119 | /** |
136 | Function: pvl_unshift(pvl_list l,void *d) | 120 | * @brief Add a new element to the from of the list |
137 | 121 | * | |
138 | Purpose: | 122 | * @param LThe list to add the item to |
139 | 123 | * @param dPointer to the item to add | |
140 | Add a new element to the from of the list | 124 | */ |
141 | |||
142 | Parameters: | ||
143 | |||
144 | lThe list to add the item to | ||
145 | dPointer to the item to add | ||
146 | |||
147 | Returns: | ||
148 | *----------------------------------------------------------------------*/ | ||
149 | 125 | ||
150 | void | 126 | void |
151 | pvl_unshift(pvl_list l,void *d) | 127 | pvl_unshift(pvl_list L,void *d) |
152 | { | 128 | { |
153 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
154 | struct pvl_elem_t *E = pvl_new_element(d,L->head,0); | 129 | struct pvl_elem_t *E = pvl_new_element(d,L->head,0); |
155 | 130 | ||
156 | if (E->next != 0) | 131 | if (E->next != 0) |
157 | { | 132 | { |
158 | /* Link the head node to it */ | 133 | /* Link the head node to it */ |
159 | E->next->prior = E; | 134 | E->next->prior = E; |
@@ -169,59 +144,43 @@ pvl_unshift(pvl_list l,void *d) | |||
169 | L->tail = E; | 144 | L->tail = E; |
170 | } | 145 | } |
171 | 146 | ||
172 | L->count++; | 147 | L->count++; |
173 | } | 148 | } |
174 | 149 | ||
175 | /*---------------------------------------------------------------------- | 150 | /** |
176 | Function: pvl_shift(pvl_list l) | 151 | * @brief Remove an element from the front of the list |
177 | 152 | * | |
178 | Purpose: | 153 | * @param LThe list to operate on |
179 | 154 | * | |
180 | Remove an element from the front of the list | 155 | * @return the entry on the front of the list |
181 | 156 | */ | |
182 | Parameters: | ||
183 | |||
184 | lThe list to operate on | ||
185 | |||
186 | Returns: | ||
187 | *----------------------------------------------------------------------*/ | ||
188 | 157 | ||
189 | void* | 158 | void* |
190 | pvl_shift(pvl_list l) | 159 | pvl_shift(pvl_list L) |
191 | { | 160 | { |
192 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
193 | |||
194 | if (L->head == 0) | 161 | if (L->head == 0) |
195 | { | 162 | { |
196 | return 0; | 163 | return 0; |
197 | } | 164 | } |
198 | 165 | ||
199 | return pvl_remove(l,(void*)L->head); | 166 | return pvl_remove(L,(void*)L->head); |
200 | 167 | ||
201 | } | 168 | } |
202 | 169 | ||
203 | /*---------------------------------------------------------------------- | 170 | /** |
204 | Function: void pvl_push(pvl_list l,void *d) | 171 | * @brief Add a new item to the tail of the list |
205 | 172 | * | |
206 | Purpose: | 173 | * @param LThe list to operate on |
207 | 174 | * @param dPointer to the item to add | |
208 | Add a new item to the tail of the list | 175 | * |
209 | 176 | */ | |
210 | Paramters: | ||
211 | |||
212 | lThe list to operate on | ||
213 | dPointer to the item to add | ||
214 | |||
215 | Returns: | ||
216 | *----------------------------------------------------------------------*/ | ||
217 | 177 | ||
218 | void | 178 | void |
219 | pvl_push(pvl_list l,void *d) | 179 | pvl_push(pvl_list L,void *d) |
220 | { | 180 | { |
221 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
222 | struct pvl_elem_t *E = pvl_new_element(d,0,L->tail); | 181 | struct pvl_elem_t *E = pvl_new_element(d,0,L->tail); |
223 | 182 | ||
224 | /* These are done in pvl_new_element | 183 | /* These are done in pvl_new_element |
225 | E->next = 0; | 184 | E->next = 0; |
226 | E->prior = L->tail; | 185 | E->prior = L->tail; |
227 | */ | 186 | */ |
@@ -239,141 +198,105 @@ pvl_push(pvl_list l,void *d) | |||
239 | L->tail = E; | 198 | L->tail = E; |
240 | 199 | ||
241 | L->count++; | 200 | L->count++; |
242 | 201 | ||
243 | } | 202 | } |
244 | 203 | ||
245 | /*---------------------------------------------------------------------- | 204 | /** |
246 | Function: void* pvl_pop(pvl_list l) | 205 | * @brief Remove an element from the tail of the list |
247 | 206 | * | |
248 | Purpose: | 207 | * @param LThe list to operate on |
249 | 208 | */ | |
250 | Remove an element from the tail of the list | ||
251 | |||
252 | Paramters: | ||
253 | |||
254 | lThe list to operate on | ||
255 | |||
256 | Returns: | ||
257 | *----------------------------------------------------------------------*/ | ||
258 | 209 | ||
259 | void* | 210 | void* |
260 | pvl_pop(pvl_list l) | 211 | pvl_pop(pvl_list L) |
261 | { | 212 | { |
262 | |||
263 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
264 | |||
265 | if ( L->tail == 0) | 213 | if ( L->tail == 0) |
266 | { | 214 | { |
267 | return 0; | 215 | return 0; |
268 | } | 216 | } |
269 | 217 | ||
270 | return pvl_remove(l,(void*) L->tail);; | 218 | return pvl_remove(L,(void*) L->tail);; |
271 | 219 | ||
272 | } | 220 | } |
273 | 221 | ||
274 | 222 | ||
275 | /*---------------------------------------------------------------------- | 223 | /** |
276 | Function: void pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) | 224 | * Add a new item to a list that is ordered by a comparison function. |
277 | 225 | * This routine assumes that the list is properly ordered. | |
278 | Purpose: | 226 | * |
279 | 227 | * @param LThe list to operate on | |
280 | Add a new item to a list that is ordered by a comparison function. | 228 | * @param fPointer to a comparison function |
281 | This routine assumes that the list is properly ordered. | 229 | * @param d Pointer to data to pass to the comparison function |
282 | 230 | */ | |
283 | lThe list to operate on | ||
284 | fPointer to a comparison function | ||
285 | d Pointer to data to pass to the comparison function | ||
286 | |||
287 | Returns: | ||
288 | |||
289 | void | ||
290 | |||
291 | *----------------------------------------------------------------------*/ | ||
292 | 231 | ||
293 | void | 232 | void |
294 | pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) | 233 | pvl_insert_ordered(pvl_list L,pvl_comparef f,void *d) |
295 | { | 234 | { |
296 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
297 | |||
298 | struct pvl_elem_t *P; | 235 | struct pvl_elem_t *P; |
299 | 236 | ||
300 | L->count++; | 237 | L->count++; |
301 | 238 | ||
302 | /* Empty list, add to head */ | 239 | /* Empty list, add to head */ |
303 | 240 | ||
304 | if(L->head == 0) | 241 | if(L->head == 0) |
305 | { | 242 | { |
306 | pvl_unshift(l,d); | 243 | pvl_unshift(L,d); |
307 | return; | 244 | return; |
308 | } | 245 | } |
309 | 246 | ||
310 | /* smaller than head, add to head */ | 247 | /* smaller than head, add to head */ |
311 | 248 | ||
312 | if ( ((*f)(d,L->head->d)) <= 0) | 249 | if ( ((*f)(d,L->head->d)) <= 0) |
313 | { | 250 | { |
314 | pvl_unshift(l,d); | 251 | pvl_unshift(L,d); |
315 | return; | 252 | return; |
316 | } | 253 | } |
317 | 254 | ||
318 | /* larger than tail, add to tail */ | 255 | /* larger than tail, add to tail */ |
319 | if ( (*f)(d,L->tail->d) >= 0) | 256 | if ( (*f)(d,L->tail->d) >= 0) |
320 | { | 257 | { |
321 | pvl_push(l,d); | 258 | pvl_push(L,d); |
322 | return; | 259 | return; |
323 | } | 260 | } |
324 | 261 | ||
325 | 262 | ||
326 | /* Search for the first element that is smaller, and add before it */ | 263 | /* Search for the first element that is smaller, and add before it */ |
327 | 264 | ||
328 | for (P=L->head; P != 0; P = P->next) | 265 | for (P=L->head; P != 0; P = P->next) |
329 | { | 266 | { |
330 | if ( (*f)(P->d,d) >= 0) | 267 | if ( (*f)(P->d,d) >= 0) |
331 | { | 268 | { |
332 | pvl_insert_before(l,P,d); | 269 | pvl_insert_before(L,P,d); |
333 | return; | 270 | return; |
334 | } | 271 | } |
335 | } | 272 | } |
336 | 273 | ||
337 | /* badness, choke */ | 274 | /* badness, choke */ |
338 | 275 | #ifndef lint | |
339 | assert(0); | 276 | assert(0); |
340 | 277 | #endif | |
341 | } | 278 | } |
342 | 279 | ||
343 | /*---------------------------------------------------------------------- | 280 | /** |
344 | Function: void pvl_insert_after(pvl_list l,pvl_elem p,void *d) | 281 | * @brief Add a new item after the referenced element. |
345 | 282 | * @param LThe list to operate on | |
346 | Purpose: | 283 | * @param PThe list element to add the item after |
347 | 284 | * @param dPointer to the item to add. | |
348 | Add a new item after the referenced element. | 285 | */ |
349 | |||
350 | Parameters: | ||
351 | |||
352 | lThe list to operate on | ||
353 | pThe list element to add the item after | ||
354 | dPointer to the item to add. | ||
355 | |||
356 | Returns: | ||
357 | |||
358 | void | ||
359 | |||
360 | *----------------------------------------------------------------------*/ | ||
361 | 286 | ||
362 | void | 287 | void |
363 | pvl_insert_after(pvl_list l,pvl_elem p,void *d) | 288 | pvl_insert_after(pvl_list L,pvl_elem P,void *d) |
364 | { | 289 | { |
365 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
366 | struct pvl_elem_t *P = (struct pvl_elem_t *)p; | ||
367 | struct pvl_elem_t *E = 0; | 290 | struct pvl_elem_t *E = 0; |
368 | 291 | ||
369 | L->count++; | 292 | L->count++; |
370 | 293 | ||
371 | if (P == 0) | 294 | if (P == 0) |
372 | { | 295 | { |
373 | pvl_unshift(l,d); | 296 | pvl_unshift(L,d); |
374 | return; | 297 | return; |
375 | } | 298 | } |
376 | 299 | ||
377 | if ( P == L->tail) | 300 | if ( P == L->tail) |
378 | { | 301 | { |
379 | E = pvl_new_element(d,0,P); | 302 | E = pvl_new_element(d,0,P); |
@@ -385,40 +308,30 @@ pvl_insert_after(pvl_list l,pvl_elem p,void *d) | |||
385 | E = pvl_new_element(d,P->next,P); | 308 | E = pvl_new_element(d,P->next,P); |
386 | E->next->prior = E; | 309 | E->next->prior = E; |
387 | E->prior->next = E; | 310 | E->prior->next = E; |
388 | } | 311 | } |
389 | } | 312 | } |
390 | 313 | ||
391 | /*---------------------------------------------------------------------- | 314 | /** |
392 | Function: void pvl_insert_before(pvl_list l,pvl_elem p,void *d) | 315 | * @brief Add an item after a referenced item |
393 | 316 | * | |
394 | Purpose: | 317 | * @param LThe list to operate on |
395 | 318 | * @param PThe list element to add the item before | |
396 | Add an item after a referenced item | 319 | * @param dPointer to the data to be added. |
397 | 320 | */ | |
398 | Parameters: | ||
399 | |||
400 | lThe list to operate on | ||
401 | pThe list element to add the item before | ||
402 | dPointer to the data to be added. | ||
403 | |||
404 | Returns: | ||
405 | *----------------------------------------------------------------------*/ | ||
406 | 321 | ||
407 | void | 322 | void |
408 | pvl_insert_before(pvl_list l,pvl_elem p,void *d) | 323 | pvl_insert_before(pvl_list L,pvl_elem P,void *d) |
409 | { | 324 | { |
410 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
411 | struct pvl_elem_t *P = (struct pvl_elem_t *)p; | ||
412 | struct pvl_elem_t *E = 0; | 325 | struct pvl_elem_t *E = 0; |
413 | 326 | ||
414 | L->count++; | 327 | L->count++; |
415 | 328 | ||
416 | if (P == 0) | 329 | if (P == 0) |
417 | { | 330 | { |
418 | pvl_unshift(l,d); | 331 | pvl_unshift(L,d); |
419 | return; | 332 | return; |
420 | } | 333 | } |
421 | 334 | ||
422 | if ( P == L->head) | 335 | if ( P == L->head) |
423 | { | 336 | { |
424 | E = pvl_new_element(d,P,0); | 337 | E = pvl_new_element(d,P,0); |
@@ -430,35 +343,25 @@ pvl_insert_before(pvl_list l,pvl_elem p,void *d) | |||
430 | E = pvl_new_element(d,P,P->prior); | 343 | E = pvl_new_element(d,P,P->prior); |
431 | E->prior->next = E; | 344 | E->prior->next = E; |
432 | E->next->prior = E; | 345 | E->next->prior = E; |
433 | } | 346 | } |
434 | } | 347 | } |
435 | 348 | ||
436 | /*---------------------------------------------------------------------- | 349 | /** |
437 | Function: void pvl_remove(pvl_list l,pvl_elem e) | 350 | * @brief Remove the referenced item from the list. |
438 | 351 | * | |
439 | Purpose: | 352 | * This routine will free the element, but not the data item that the |
440 | 353 | * element contains. | |
441 | Remove the referenced item from the list | 354 | * |
442 | 355 | * @param LThe list to operate on | |
443 | This routine will free the element, but not the data item that the | 356 | * @param EThe element to remove. |
444 | element contains. | 357 | */ |
445 | |||
446 | Parameters: | ||
447 | |||
448 | lThe list to operate on | ||
449 | eThe element to remove. | ||
450 | |||
451 | Returns: | ||
452 | *----------------------------------------------------------------------*/ | ||
453 | 358 | ||
454 | void* | 359 | void* |
455 | pvl_remove(pvl_list l,pvl_elem e) | 360 | pvl_remove(pvl_list L,pvl_elem E) |
456 | { | 361 | { |
457 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
458 | struct pvl_elem_t *E = (struct pvl_elem_t *)e; | ||
459 | void* data; | 362 | void* data; |
460 | 363 | ||
461 | if (E == L->head) | 364 | if (E == L->head) |
462 | { | 365 | { |
463 | if (E->next != 0) | 366 | if (E->next != 0) |
464 | { | 367 | { |
@@ -501,34 +404,25 @@ pvl_remove(pvl_list l,pvl_elem e) | |||
501 | free(E); | 404 | free(E); |
502 | 405 | ||
503 | return data; | 406 | return data; |
504 | 407 | ||
505 | } | 408 | } |
506 | 409 | ||
507 | /*---------------------------------------------------------------------- | 410 | /** |
508 | Function: pvl_elem pvl_find(pvl_list l,pvl_findf f,void* v) | 411 | * @brief Return a pointer to data that satisfies a function. |
509 | 412 | * | |
510 | Purpose: | 413 | * This routine will interate through the entire list and call the |
511 | 414 | * find function for each item. It will break and return a pointer to the | |
512 | Return a pointer to data that satisfies a function | 415 | * data that causes the find function to return 1. |
513 | 416 | * | |
514 | This routine will interate through the entire list and call the | 417 | * @param lThe list to operate on |
515 | find function for each item. It will break and return a pointer to the | 418 | * @param fPointer to the find function |
516 | data that causes the find function to return 1. | 419 | * @param vPointer to constant data to pass into the function |
517 | 420 | * | |
518 | Parameters: | 421 | * @return Pointer to the element that the find function found. |
519 | 422 | */ | |
520 | lThe list to operate on | ||
521 | fPointer to the find function | ||
522 | vPointer to constant data to pass into the function | ||
523 | |||
524 | Returns: | ||
525 | |||
526 | Pointer to the element that the find function found. | ||
527 | |||
528 | *----------------------------------------------------------------------*/ | ||
529 | 423 | ||
530 | pvl_elem | 424 | pvl_elem |
531 | pvl_find(pvl_list l,pvl_findf f,void* v) | 425 | pvl_find(pvl_list l,pvl_findf f,void* v) |
532 | { | 426 | { |
533 | pvl_elem e; | 427 | pvl_elem e; |
534 | 428 | ||
@@ -542,31 +436,23 @@ pvl_find(pvl_list l,pvl_findf f,void* v) | |||
542 | } | 436 | } |
543 | } | 437 | } |
544 | 438 | ||
545 | return 0; | 439 | return 0; |
546 | 440 | ||
547 | } | 441 | } |
548 | /*---------------------------------------------------------------------- | ||
549 | Function: void* pvl_find_next(pvl_list l,pvl_findf f,void* v) | ||
550 | |||
551 | Purpose: | ||
552 | |||
553 | Like pvl_find(), but continues the search where the last find() or | ||
554 | find_next() left off | ||
555 | |||
556 | Parameters: | ||
557 | |||
558 | lThe list to operate on | ||
559 | fPointer to the find function | ||
560 | vPointer to constant data to pass into the function | ||
561 | |||
562 | Returns: | ||
563 | 442 | ||
564 | Pointer to the element that the find function found. | 443 | /** |
565 | 444 | * @brief Like pvl_find(), but continues the search where the last find() or | |
566 | *----------------------------------------------------------------------*/ | 445 | * find_next() left off. |
446 | * | ||
447 | * @param lThe list to operate on | ||
448 | * @param fPointer to the find function | ||
449 | * @param vPointer to constant data to pass into the function | ||
450 | * | ||
451 | * @return Pointer to the element that the find function found. | ||
452 | */ | ||
567 | 453 | ||
568 | pvl_elem | 454 | pvl_elem |
569 | pvl_find_next(pvl_list l,pvl_findf f,void* v) | 455 | pvl_find_next(pvl_list l,pvl_findf f,void* v) |
570 | { | 456 | { |
571 | 457 | ||
572 | pvl_elem e; | 458 | pvl_elem e; |
@@ -582,23 +468,16 @@ pvl_find_next(pvl_list l,pvl_findf f,void* v) | |||
582 | } | 468 | } |
583 | 469 | ||
584 | return 0; | 470 | return 0; |
585 | 471 | ||
586 | } | 472 | } |
587 | 473 | ||
588 | /*---------------------------------------------------------------------- | 474 | /** |
589 | Function: void pvl_clear(pvl_list l) | 475 | * @brief Remove the all the elements in the list. The does not free |
590 | 476 | * the data items the elements hold. | |
591 | Purpose: | 477 | */ |
592 | |||
593 | Remove the all the elements in the list. The does not free the data items | ||
594 | the elements hold. | ||
595 | |||
596 | |||
597 | Returns: | ||
598 | *----------------------------------------------------------------------*/ | ||
599 | 478 | ||
600 | void | 479 | void |
601 | pvl_clear(pvl_list l) | 480 | pvl_clear(pvl_list l) |
602 | { | 481 | { |
603 | pvl_elem e = pvl_head(l); | 482 | pvl_elem e = pvl_head(l); |
604 | pvl_elem next; | 483 | pvl_elem next; |
@@ -612,144 +491,88 @@ pvl_clear(pvl_list l) | |||
612 | next = pvl_next(e); | 491 | next = pvl_next(e); |
613 | pvl_remove(l,e); | 492 | pvl_remove(l,e); |
614 | e = next; | 493 | e = next; |
615 | } | 494 | } |
616 | } | 495 | } |
617 | 496 | ||
618 | /*---------------------------------------------------------------------- | ||
619 | Function: int pvl_count(pvl_list l) | ||
620 | |||
621 | Purpose: | ||
622 | |||
623 | Returns the number of items in the list. | ||
624 | 497 | ||
625 | Returns: | 498 | /** |
626 | *----------------------------------------------------------------------*/ | 499 | * @brief Returns the number of items in the list. |
500 | */ | ||
627 | 501 | ||
628 | int | 502 | int |
629 | pvl_count(pvl_list l) | 503 | pvl_count(pvl_list L) |
630 | { | 504 | { |
631 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
632 | |||
633 | return L->count; | 505 | return L->count; |
634 | } | 506 | } |
635 | 507 | ||
636 | 508 | ||
637 | /*---------------------------------------------------------------------- | 509 | /** |
638 | Function: pvl_elem pvl_next(pvl_elem e) | 510 | * @brief Returns a pointer to the given element |
639 | 511 | */ | |
640 | Purpose: | ||
641 | Returns a pointer to the given element | ||
642 | |||
643 | Returns: | ||
644 | *----------------------------------------------------------------------*/ | ||
645 | 512 | ||
646 | pvl_elem | 513 | pvl_elem |
647 | pvl_next(pvl_elem e) | 514 | pvl_next(pvl_elem E) |
648 | { | 515 | { |
649 | struct pvl_elem_t *E = (struct pvl_elem_t *)e; | ||
650 | |||
651 | if (E == 0){ | 516 | if (E == 0){ |
652 | return 0; | 517 | return 0; |
653 | } | 518 | } |
654 | 519 | ||
655 | return (pvl_elem)E->next; | 520 | return (pvl_elem)E->next; |
656 | } | 521 | } |
657 | 522 | ||
658 | /*---------------------------------------------------------------------- | ||
659 | Function: pvl_elem pvl_prior(pvl_elem e) | ||
660 | |||
661 | Purpose: | ||
662 | |||
663 | Returns a pointer to the element previous to the element given. | ||
664 | 523 | ||
665 | Returns: | 524 | /** |
666 | *----------------------------------------------------------------------*/ | 525 | * @brief Returns a pointer to the element previous to the element given. |
526 | */ | ||
667 | 527 | ||
668 | pvl_elem | 528 | pvl_elem |
669 | pvl_prior(pvl_elem e) | 529 | pvl_prior(pvl_elem E) |
670 | { | 530 | { |
671 | struct pvl_elem_t *E = (struct pvl_elem_t *)e; | ||
672 | |||
673 | return (pvl_elem)E->prior; | 531 | return (pvl_elem)E->prior; |
674 | } | 532 | } |
675 | 533 | ||
676 | /*---------------------------------------------------------------------- | ||
677 | Function: pvl_elem pvl_head(pvl_list l ) | ||
678 | |||
679 | Purpose: | ||
680 | 534 | ||
681 | Returns a pointer to the first item in the list. | 535 | /** |
536 | * @brief Returns a pointer to the first item in the list. | ||
537 | */ | ||
682 | 538 | ||
683 | Returns: | ||
684 | *----------------------------------------------------------------------*/ | ||
685 | pvl_elem | 539 | pvl_elem |
686 | pvl_head(pvl_list l ) | 540 | pvl_head(pvl_list L ) |
687 | { | 541 | { |
688 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
689 | |||
690 | return (pvl_elem)L->head; | 542 | return (pvl_elem)L->head; |
691 | } | 543 | } |
692 | 544 | ||
693 | /*---------------------------------------------------------------------- | 545 | /** |
694 | Function: pvl_elem pvl_tail(pvl_list l) | 546 | * @brief Returns a pointer to the last item in the list. |
695 | 547 | */ | |
696 | Purpose: | ||
697 | |||
698 | Returns a pointer to the last item in the list. | ||
699 | |||
700 | Returns: | ||
701 | *----------------------------------------------------------------------*/ | ||
702 | pvl_elem | 548 | pvl_elem |
703 | pvl_tail(pvl_list l) | 549 | pvl_tail(pvl_list L) |
704 | { | 550 | { |
705 | struct pvl_list_t *L = (struct pvl_list_t *)l; | ||
706 | return (pvl_elem)L->tail; | 551 | return (pvl_elem)L->tail; |
707 | } | 552 | } |
708 | 553 | ||
709 | /*---------------------------------------------------------------------- | ||
710 | Function: | ||
711 | |||
712 | |||
713 | Purpose: | ||
714 | |||
715 | |||
716 | Returns: | ||
717 | *----------------------------------------------------------------------*/ | ||
718 | |||
719 | #ifndef PVL_USE_MACROS | 554 | #ifndef PVL_USE_MACROS |
720 | void* | 555 | void* |
721 | pvl_data(pvl_elem e) | 556 | pvl_data(pvl_elem E) |
722 | { | 557 | { |
723 | struct pvl_elem_t *E = (struct pvl_elem_t *)e; | 558 | if ( E == 0){ |
724 | |||
725 | if ( e == 0){ | ||
726 | return 0; | 559 | return 0; |
727 | } | 560 | } |
728 | 561 | ||
729 | return E->d; | 562 | return E->d; |
730 | } | 563 | } |
731 | #endif | 564 | #endif |
732 | 565 | ||
733 | /*---------------------------------------------------------------------- | 566 | /** |
734 | Function: void pvl_apply(pvl_list l,pvl_applyf f, void *v) | 567 | * @brief Call a function for every item in the list. |
735 | 568 | * | |
736 | Purpose: | 569 | * @param lThe list to operate on |
737 | 570 | * @param fPointer to the function to call | |
738 | Call a function for every item in the list. | 571 | * @param vData to pass to the function on every iteration |
739 | 572 | */ | |
740 | Paramters: | ||
741 | |||
742 | lThe list to operate on | ||
743 | fPointer to the function to call | ||
744 | vData to pass to the function on every iteration | ||
745 | |||
746 | Returns: | ||
747 | |||
748 | void | ||
749 | *----------------------------------------------------------------------*/ | ||
750 | 573 | ||
751 | void | 574 | void |
752 | pvl_apply(pvl_list l,pvl_applyf f, void *v) | 575 | pvl_apply(pvl_list l,pvl_applyf f, void *v) |
753 | { | 576 | { |
754 | pvl_elem e; | 577 | pvl_elem e; |
755 | 578 | ||