summaryrefslogtreecommitdiffabout
path: root/libical/src/libical/pvl.c
Unidiff
Diffstat (limited to 'libical/src/libical/pvl.c') (more/less context) (ignore whitespace changes)
-rw-r--r--libical/src/libical/pvl.c497
1 files changed, 160 insertions, 337 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
@@ -17,5 +17,3 @@
17 17
18 18/**
19
20/*
21 struct pvl_list_t 19 struct pvl_list_t
@@ -30,7 +28,7 @@ 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;
@@ -40,4 +38,6 @@ typedef struct pvl_list_t
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
@@ -47,14 +47,7 @@ int pvl_list_count = 0;
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
@@ -91,28 +84,19 @@ pvl_free(pvl_list l)
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
116pvl_elem 100pvl_elem
117pvl_new_element(void *d, pvl_elem next,pvl_elem prior) 101pvl_new_element(void *d, pvl_elem next, pvl_elem prior)
118{ 102{
@@ -134,21 +118,12 @@ pvl_new_element(void *d, pvl_elem next,pvl_elem prior)
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
150void 126void
151pvl_unshift(pvl_list l,void *d) 127pvl_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);
@@ -174,21 +149,13 @@ pvl_unshift(pvl_list l,void *d)
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
189void* 158void*
190pvl_shift(pvl_list l) 159pvl_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)
@@ -198,3 +165,3 @@ pvl_shift(pvl_list l)
198 165
199 return pvl_remove(l,(void*)L->head); 166 return pvl_remove(L,(void*)L->head);
200 167
@@ -202,21 +169,13 @@ pvl_shift(pvl_list l)
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
218void 178void
219pvl_push(pvl_list l,void *d) 179pvl_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);
@@ -244,22 +203,11 @@ pvl_push(pvl_list l,void *d)
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
259void* 210void*
260pvl_pop(pvl_list l) 211pvl_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)
@@ -269,3 +217,3 @@ pvl_pop(pvl_list l)
269 217
270 return pvl_remove(l,(void*) L->tail);; 218 return pvl_remove(L,(void*) L->tail);;
271 219
@@ -274,25 +222,14 @@ pvl_pop(pvl_list l)
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
293void 232void
294pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d) 233pvl_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;
@@ -305,3 +242,3 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d)
305 { 242 {
306 pvl_unshift(l,d); 243 pvl_unshift(L,d);
307 return; 244 return;
@@ -313,3 +250,3 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d)
313 { 250 {
314 pvl_unshift(l,d); 251 pvl_unshift(L,d);
315 return; 252 return;
@@ -320,3 +257,3 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d)
320 { 257 {
321 pvl_push(l,d); 258 pvl_push(L,d);
322 return; 259 return;
@@ -331,3 +268,3 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d)
331 { 268 {
332 pvl_insert_before(l,P,d); 269 pvl_insert_before(L,P,d);
333 return; 270 return;
@@ -337,31 +274,17 @@ pvl_insert_ordered(pvl_list l,pvl_comparef f,void *d)
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
362void 287void
363pvl_insert_after(pvl_list l,pvl_elem p,void *d) 288pvl_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;
@@ -372,3 +295,3 @@ pvl_insert_after(pvl_list l,pvl_elem p,void *d)
372 { 295 {
373 pvl_unshift(l,d); 296 pvl_unshift(L,d);
374 return; 297 return;
@@ -390,23 +313,13 @@ pvl_insert_after(pvl_list l,pvl_elem p,void *d)
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
407void 322void
408pvl_insert_before(pvl_list l,pvl_elem p,void *d) 323pvl_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;
@@ -417,3 +330,3 @@ pvl_insert_before(pvl_list l,pvl_elem p,void *d)
417 { 330 {
418 pvl_unshift(l,d); 331 pvl_unshift(L,d);
419 return; 332 return;
@@ -435,25 +348,15 @@ pvl_insert_before(pvl_list l,pvl_elem p,void *d)
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
454void* 359void*
455pvl_remove(pvl_list l,pvl_elem e) 360pvl_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;
@@ -506,24 +409,15 @@ pvl_remove(pvl_list l,pvl_elem e)
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
@@ -547,21 +441,13 @@ pvl_find(pvl_list l,pvl_findf f,void* v)
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 442
556 Parameters: 443/**
557 444 * @brief Like pvl_find(), but continues the search where the last find() or
558 lThe list to operate on 445 * find_next() left off.
559 fPointer to the find function 446 *
560 vPointer to constant data to pass into the function 447 * @param lThe list to operate on
561 448 * @param fPointer to the find function
562 Returns: 449 * @param vPointer to constant data to pass into the function
563 450 *
564 Pointer to the element that the find function found. 451 * @return Pointer to the element that the find function found.
565 452 */
566 *----------------------------------------------------------------------*/
567 453
@@ -587,13 +473,6 @@ pvl_find_next(pvl_list l,pvl_findf f,void* v)
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
@@ -617,17 +496,10 @@ pvl_clear(pvl_list l)
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
628int 502int
629pvl_count(pvl_list l) 503pvl_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;
@@ -636,16 +508,9 @@ pvl_count(pvl_list l)
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
646pvl_elem 513pvl_elem
647pvl_next(pvl_elem e) 514pvl_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){
@@ -657,17 +522,10 @@ pvl_next(pvl_elem e)
657 522
658/*----------------------------------------------------------------------
659 Function: pvl_elem pvl_prior(pvl_elem e)
660 523
661 Purpose: 524/**
662 525 * @brief Returns a pointer to the element previous to the element given.
663 Returns a pointer to the element previous to the element given. 526 */
664
665 Returns:
666 *----------------------------------------------------------------------*/
667 527
668pvl_elem 528pvl_elem
669pvl_prior(pvl_elem e) 529pvl_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;
@@ -675,16 +533,10 @@ pvl_prior(pvl_elem e)
675 533
676/*----------------------------------------------------------------------
677 Function: pvl_elem pvl_head(pvl_list l )
678
679 Purpose:
680
681 Returns a pointer to the first item in the list.
682 534
683 Returns: 535/**
684 *----------------------------------------------------------------------*/ 536 * @brief Returns a pointer to the first item in the list.
537 */
538
685pvl_elem 539pvl_elem
686pvl_head(pvl_list l ) 540pvl_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;
@@ -692,15 +544,8 @@ pvl_head(pvl_list l )
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 *----------------------------------------------------------------------*/
702pvl_elem 548pvl_elem
703pvl_tail(pvl_list l) 549pvl_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;
@@ -708,19 +553,7 @@ pvl_tail(pvl_list l)
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
720void* 555void*
721pvl_data(pvl_elem e) 556pvl_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;
@@ -732,19 +565,9 @@ pvl_data(pvl_elem e)
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