From 6ea4606cd3f74377691d200d69df8398f90cc2ff Mon Sep 17 00:00:00 2001 From: Charles Date: Sat, 12 Oct 2019 10:43:01 +0200 Subject: Basic conversion parsing Using a list to store each format conversion informations. --- list.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 list.c (limited to 'list.c') diff --git a/list.c b/list.c new file mode 100644 index 0000000..12c6e62 --- /dev/null +++ b/list.c @@ -0,0 +1,54 @@ +#include +#include "header.h" + +t_list *list_new(t_pformat *data) +{ + t_list *list; + + if ((list = (t_list*)malloc(sizeof(t_list))) == NULL) + return NULL; + list->data = data; + list->next = NULL; + return (list); +} + +t_list *list_destroy(t_list *list) +{ + while (list != NULL) + list_pop_front(&list); + return (NULL); +} + + +void list_push_front(t_list **list, t_list *new_front) +{ + new_front->next = *list; + *list = new_front; +} + +void list_push_back(t_list **list, t_list *new_back) +{ + t_list *cursor; + + if (*list == NULL) + { + *list = new_back; + return ; + } + cursor = *list; + while (cursor->next != NULL) + cursor = cursor->next; + cursor->next = new_back; +} + +void list_pop_front(t_list **list) +{ + t_list *tmp; + + if (*list == NULL) + return ; + tmp = (*list)->next; + free((*list)->data); + free(*list); + *list = tmp; +} -- cgit