imapfilter/src/list.c
Lefteris Chatzimparmpas 2cafede975 Use session pointer to denote accounts
Instead of the account details, a pointer to the C structure is used in
Lua, stored as light userdata.

The 1.x deprecated configuration format has been removed, partly due to
the above change, and partly because it has been included for long
enough now.
2012-02-14 22:13:15 +01:00

64 lines
787 B
C

#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;
if (!lst)
return NULL;
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;
}
}
return lst;
}