X-Git-Url: https://hackdaworld.org/gitweb/?a=blobdiff_plain;f=list%2Flist.c;h=64a282a14e1f33dfd505fdaec215f5668bb8701a;hb=40946b581d43a81ef427115bc284a4240c389e8f;hp=681db539924fb7242d4f3cbca58bdc18a8cd57ce;hpb=040060604e2dc08d17d900825072aad88206ae3b;p=my-code%2Fapi.git diff --git a/list/list.c b/list/list.c index 681db53..64a282a 100644 --- a/list/list.c +++ b/list/list.c @@ -6,7 +6,114 @@ #include "list.h" -int list_init(t_list *list) { +int list_init(t_list *list,int outfd) { - if(list->type==SINGLE) { - 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_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) { + + } + + 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; + } + } + list->current=list->current->next; + } + + return L_NO_SUCH_ELEMENT; +} + +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);