2018-04-07 19:25:47 +02:00
|
|
|
#include <string.h>
|
2018-04-07 19:28:00 +02:00
|
|
|
#include <stdio.h>
|
2018-04-07 19:25:47 +02:00
|
|
|
|
|
|
|
#include "mlist.h"
|
|
|
|
|
2018-04-07 19:28:00 +02:00
|
|
|
struct mlistelem * mlist_delete(mlist_t list, void *data)
|
2018-04-07 19:25:47 +02:00
|
|
|
{
|
|
|
|
struct mlistelem *e;
|
|
|
|
|
2018-04-07 19:28:00 +02:00
|
|
|
mlist_foreach(e,list){
|
|
|
|
void *tdata = mlistelem_dataptr(e);
|
|
|
|
if (list->cmp(tdata,data)==0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-07 19:25:47 +02:00
|
|
|
if (e == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2018-04-07 19:28:00 +02:00
|
|
|
if (e->prev==NULL && e->next==NULL){
|
|
|
|
if (list->del)
|
|
|
|
list->del(e);
|
|
|
|
free(e);
|
|
|
|
list->count=0;
|
|
|
|
list->first=NULL;
|
|
|
|
list->last=NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e==list->first){
|
|
|
|
list->first=e->next;
|
|
|
|
e->next->prev=NULL;
|
|
|
|
if (list->del)
|
|
|
|
list->del(e);
|
|
|
|
list->count--;
|
|
|
|
free(e);
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (e==list->last){
|
|
|
|
list->last=e->prev;
|
|
|
|
e->prev->next=NULL;
|
|
|
|
if (list->del)
|
|
|
|
list->del(e);
|
|
|
|
list->count--;
|
|
|
|
free(e);
|
|
|
|
return NULL;
|
2018-04-07 19:25:47 +02:00
|
|
|
|
2018-04-07 19:28:00 +02:00
|
|
|
}
|
2018-04-07 19:25:47 +02:00
|
|
|
|
2018-04-07 19:28:00 +02:00
|
|
|
e->next->prev=e->prev;
|
|
|
|
e->prev->next=e->next;
|
|
|
|
if (list->del)
|
|
|
|
list->del(e);
|
|
|
|
list->count--;
|
|
|
|
free(e);
|
|
|
|
return NULL;
|
2018-04-07 19:25:47 +02:00
|
|
|
|
|
|
|
}
|