#include "list.h"
-int list_init(t_list *list) {
+int list_init(t_list *list,int outfd) {
- list->
- list->current=&(list->start);
+ dprintf(outfd,"[list] list initilaization ...\n");
+
+ list->outfd=outfd;
+ list->start=NULL;
+ list->current=NULL;
+
+ return L_SUCCESS;
+}
+
+int list_del_next(t_list *list,t_list_element *element) {
+
+ t_list_element *tmp;
+
+ if(element==NULL) {
+ dprintf(list->outfd,"[list] empty element\n");
+ return L_INVALID_ELEMENT;
+ }
+
+ if(element->next!=NULL) {
+ dprintf(list->outfd,"[list] destroying element number %d\n"
+ tmp=element->next->next;
+ if(element->next->data!=NULL) free(element->next->data);
+ free(element->next);
+ element->next=tmp;
+ }
+ else {
+ dprintf(list->outfd,"[list] no next element\n");
+ return L_NO_NEXT_ELEMENT;
+ }
+
+ return L_SUCCESS;
+}
+
+int list_destroy(t_list *list) {
+
+ if(list->start==NULL) {
+ dprintf(list->outfd,"[list] empty list\n");
+ return L_EMPTY_LIST;
+ }
+
+ list->current=list->start;
+
+ while(list->current->next!=NULL)
+ list_del_next(list,list->current);
return L_SUCCESS;
}
-int list_add_element(t_list *list,int nr,void *data,int len) {
+int list_del_nr(t_list *list,int nr) {
+
+ if(list->start==NULL) {
+ dprintf(list->outfd,"[list] empty list\n");
+ return L_EMPTY_LIST;
+ }
+
+ if(list->start->number==nr) {
- if(list->method&C_NUMBER) {
- while(list->current->next!=NULL) {
- if(list->current->number==nr) return L_EXISTS;
- else list->current=list->current->next;
+ }
+
+ list->current=&(list->start);
+
+ while(list->current->next!=NULL) {
+ if(list->current->next->number==nr) {
+ list_del_next(list,list->current);
+ return L_SUCCESS;
+ }
+ list->current=list->current->next;
+ }
+
+ return L_NO_SUCH_ELEMENT;
+}
+
+int list_search_data(t_list *list,void *data,int data_len) {
+
+ t_element *help;
+
+ help=&(list->start);
+
+ while(help->next!=NULL) {
+ if(help->next->data_len==data_len) {
+ if(!(memcmp(help->next->data,data,data_len)) {
+ list->current=help->next;
+ return L_SUCCESS;
+ }
}
- if(list->current->number==nr) return L_EXISTS;
+ list->current=list->current->next;
+ }
+
+ return L_NO_SUCH_ELEMENT;
+}
- /* new element */
- if((list->current->next=(t_list *)malloc(sizeof(t_list)))==NULL) {
- fprintf(stderr,"[list]
+int list_search_nr(t_list *list,int nr) {
+
+ list->current=&(list->start);
+
+ while(list->current->next!=NULL) {
+ if(list->current->next->number==nr) {
+ list->current=list->current->next;
+ return L_SUCCESS;
+ }
+ list->current=list->current->next;
+ }
+
+ return L_NO_SUCH_ELEMENT;
+}
+
+int list_append_element(t_list *list,t_list_element *element) {
+
+ list->current=&(list->start);