From ee4b8e5e481850c936c5df10a0d3e70038234754 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 21 Nov 2019 02:53:41 +0100 Subject: WIP: adding ft_*printf --- ft_printf/list.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 ft_printf/list.c (limited to 'ft_printf/list.c') diff --git a/ft_printf/list.c b/ft_printf/list.c new file mode 100644 index 0000000..99491f4 --- /dev/null +++ b/ft_printf/list.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/29 00:14:50 by cacharle #+# #+# */ +/* Updated: 2019/11/05 23:45:42 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_vasprintf.h" + +t_flist *list_new(t_pformat *content) +{ + t_flist *lst; + + if ((lst = (t_flist*)malloc(sizeof(t_flist))) == NULL) + return (NULL); + lst->content = content; + lst->next = NULL; + return (lst); +} + +void *list_destroy(t_flist **lst) +{ + if (lst == NULL) + return (NULL); + while (*lst != NULL) + list_pop_front(lst); + return (NULL); +} + +void list_push_front(t_flist **lst, t_flist *new) +{ + if (lst == NULL || new == NULL) + return ; + new->next = *lst; + *lst = new; +} + +void list_pop_front(t_flist **lst) +{ + t_flist *tmp; + + if (lst == NULL || *lst == NULL) + return ; + tmp = (*lst)->next; + free((*lst)->content); + free(*lst); + *lst = tmp; +} + +t_flist *list_reverse(t_flist *lst) +{ + t_flist *tmp; + + if (lst == NULL) + return (NULL); + if (lst->next == NULL) + return (lst); + tmp = list_reverse(lst->next); + lst->next->next = lst; + lst->next = NULL; + return (tmp); +} -- cgit