]> code.citadel.org Git - citadel.git/blob - libCxClient/src/listmgt.c
Initial revision
[citadel.git] / libCxClient / src / listmgt.c
1 /**
2  ** libCxClient - Citadel/UX Extensible Client API
3  ** Copyright (c) 2000, Flaming Sword Productions
4  ** Copyright (c) 2001, The Citadel/UX Consortium
5  ** All Rights Reserved
6  **
7  ** Module: listmgt.o
8  ** Date: 2000-10-15
9  ** Last Revision: 2000-10-15
10  ** Description: Brian's Linked-list Manager
11  ** CVS: $Id$
12  **
13  ** Based loosely upon the ideas expressed in Jesse Sweetland's
14  ** linked-list code.
15  **/
16 #include        <stdio.h>
17 #include        <stdlib.h>
18 #include        <stdarg.h>
19 #include        <string.h>
20 #include        <CxClient.h>
21 #include        "autoconf.h"
22
23 /**
24  ** CxLiInsert(): Insert a new string into the linked-list.
25  **
26  ** [Expects]
27  **  (CXLIST)li: The list we're inserting into.
28  **  (char *)s: The string (or data) we are inserting into @li.
29  **
30  ** [Returns]
31  **  li
32  **/
33 CXLIST          CxLlInsert(CXLIST li, char *s) {
34 CXLIST          p,new = 0;
35 int             loop = 0;
36
37         DPF((DFA,"List @0x%08x",li));
38         DPF((DFA,"Inserting \"%s\"",s));
39
40         for(loop = 0; loop < 5; loop++ ) {
41                 DPF((DFA,"malloc safety loop, iteration %d",loop));
42                 if((new = (CXLIST) CxMalloc( sizeof( CXLIST ) ))) break;
43         }
44
45         if(!new) return(li);
46
47         new->data = (char *) CxMalloc( strlen( s ) +1 );
48         strcpy(new->data, s);
49         new->next = NULL;
50
51         if(li) {
52                 p = li;
53                 while( p->next ) p = p->next;
54                 p->next = new;
55
56         } else {
57                 li = new;
58         }
59
60         return(li);
61 }
62
63 /**
64  ** CxLlRemove(): Remove the n'th item from the linked-list. [SKEL]
65  **
66  ** [Expects]
67  **  (CXLIST)li: The list we are altering.
68  **  (int)d: The item number to remove.
69  **
70  ** [Returns]
71  **  li
72  **/
73 CXLIST          CxLlRemove(CXLIST li, unsigned int d) {
74         return(li);
75 }
76
77 /**
78  ** CxLlFlush(): Flush all of a list's memory.  (Erases the entire
79  ** list.)
80  **
81  ** [Expects]
82  **  (CXLIST)li: The list to be nuked.
83  **
84  ** [Returns]
85  **  NULL
86  **/
87 CXLIST          CxLlFlush(CXLIST li) {
88 CXLIST          t,p;
89
90         DPF((DFA,"Clearing list @0x%08x",li));
91         p = li;
92         while ( p ) {
93                 t = p;
94                 CxFree(p->data);
95                 p = p->next;
96                 CxFree(t);
97         }
98
99         /**
100          ** This function should _ALWAYS_ eliminate the list...
101          ** Therefore it's not necessary to return @li.
102          **/
103         return(NULL);
104 }