aboutsummaryrefslogtreecommitdiff
path: root/ft_printf/list.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-11-21 02:53:41 +0100
committerCharles <sircharlesaze@gmail.com>2019-11-21 04:03:13 +0100
commitee4b8e5e481850c936c5df10a0d3e70038234754 (patch)
tree5e569b3ebc2bdcafdbd06fef99f32207da29d4ee /ft_printf/list.c
parentafc8c70a66773563f6e7429b500abcbab631722b (diff)
downloadlibft-ee4b8e5e481850c936c5df10a0d3e70038234754.tar.gz
libft-ee4b8e5e481850c936c5df10a0d3e70038234754.tar.bz2
libft-ee4b8e5e481850c936c5df10a0d3e70038234754.zip
WIP: adding ft_*printf
Diffstat (limited to 'ft_printf/list.c')
-rw-r--r--ft_printf/list.c67
1 files changed, 67 insertions, 0 deletions
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 <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* 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);
+}