Main Page | Class List | File List | Class Members | File Members

LList.c File Reference

#include <stdio.h>
#include "LList.h"

Go to the source code of this file.

Functions

listmklist (void)
void linsert (list *l, void *data, int len, int key)
void * lfind (list *l, int key, int *len)
void * lremove (list *l, int key, int *len)


Function Documentation

void* lfind list l,
int  key,
int *  len
 

Definition at line 36 of file LList.c.

References list::data, list::key, list::len, and list::next.

00037 {
00038   /* skip first node (dummy) */
00039   l=l->next;
00040 
00041   while ((l->key!=key) && (l->next!=NULL))
00042     l=l->next;
00043   if (l->key!=key)
00044     return(NULL);
00045   *len=l->len;
00046   return l->data;
00047 }

void linsert list l,
void *  data,
int  len,
int  key
 

Definition at line 16 of file LList.c.

References list::data, list::key, list::len, and list::next.

00017 {
00018   list *newnode;
00019 
00020   printf("linsert() - inserting into list at location 0x%x...\n",l);
00021   while (l->next != NULL)
00022     l=l->next;
00023 
00024   newnode = (list*) malloc(sizeof(list));
00025   if (newnode==NULL) {
00026     fprintf(stderr, "insert to a list failed, Ack!\n");
00027     return;
00028   }
00029   newnode->data=data;
00030   newnode->len=len;
00031   newnode->key=key;
00032   newnode->next=NULL;
00033   l->next=newnode;
00034 }

void* lremove list l,
int  key,
int *  len
 

Definition at line 49 of file LList.c.

References data, list::data, list::key, list::len, and list::next.

00050 {
00051   void *data;
00052   list *it;
00053   list *nxt;
00054 
00055   /* save pointer to start of list */
00056   it=l;
00057 
00058   if (it->next==NULL)
00059     return NULL;
00060 
00061   /* skip first node (dummy) */
00062   it=it->next;
00063 
00064   /* find match */
00065   while ((it->key!=key) && (it->next!=NULL)) 
00066     it=it->next;
00067 
00068   /* if we didn't find a match, return NULL */
00069   if (it->key!=key)
00070     return(NULL);
00071 
00072   /* Save the stuff we're looking for */
00073   *len=it->len;
00074   data=it->data;
00075 
00076   /* Now try to remove the node */
00077   nxt=it->next;
00078   while (l->next!=it)
00079     l=l->next;
00080   l->next=nxt;
00081   free(it);
00082 
00083   return(data);
00084 }

list* mklist void   ) 
 

Definition at line 4 of file LList.c.

References list::data, list::key, and list::next.

00005 {
00006   list *l;
00007   l=(list*)malloc(sizeof(list));
00008   if (l==NULL) 
00009     return NULL;
00010   l->data=NULL;
00011   l->key=-1;
00012   l->next=NULL;
00013   return l;
00014 }


Generated on Sun Jul 16 16:27:47 2006 by  doxygen 1.3.9.1