2011-03-06 06:58:58 -05:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "imapfilter.h"
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a new element at the end of the list.
|
|
|
|
*/
|
|
|
|
list *
|
|
|
|
list_append(list *lst, void *data)
|
|
|
|
{
|
|
|
|
list *l, *nl;
|
|
|
|
|
|
|
|
nl = (list *)xmalloc(sizeof(list));
|
|
|
|
nl->data = data;
|
|
|
|
nl->prev = nl->next = NULL;
|
|
|
|
|
|
|
|
if (lst != NULL) {
|
|
|
|
for (l = lst; l->next != NULL; l = l->next);
|
|
|
|
l->next = nl;
|
|
|
|
nl->prev = l;
|
|
|
|
|
|
|
|
return lst;
|
|
|
|
} else {
|
|
|
|
return nl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove an element from the list.
|
|
|
|
*/
|
|
|
|
list *
|
|
|
|
list_remove(list *lst, void *data)
|
|
|
|
{
|
|
|
|
list *l;
|
|
|
|
|
2012-02-14 16:13:15 -05:00
|
|
|
if (!lst)
|
|
|
|
return NULL;
|
|
|
|
|
2011-03-06 06:58:58 -05:00
|
|
|
l = lst;
|
|
|
|
while (l != NULL) {
|
|
|
|
if (l->data != data)
|
|
|
|
l = l->next;
|
|
|
|
else {
|
|
|
|
if (l->prev)
|
|
|
|
l->prev->next = l->next;
|
|
|
|
if (l->next)
|
|
|
|
l->next->prev = l->prev;
|
|
|
|
if (lst == l)
|
|
|
|
lst = lst->next;
|
|
|
|
|
|
|
|
xfree(l);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 16:13:15 -05:00
|
|
|
|
2011-03-06 06:58:58 -05:00
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|