aboutsummaryrefslogtreecommitdiff
path: root/list.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2019-10-12 10:43:01 +0200
committerCharles <sircharlesaze@gmail.com>2019-10-12 11:48:54 +0200
commit6ea4606cd3f74377691d200d69df8398f90cc2ff (patch)
treef354459b9054f5bd23a7508c12ef1589af38e75a /list.c
parentbddc2d153a4c47257740a0bf0651513058a612d5 (diff)
downloadft_printf-6ea4606cd3f74377691d200d69df8398f90cc2ff.tar.gz
ft_printf-6ea4606cd3f74377691d200d69df8398f90cc2ff.tar.bz2
ft_printf-6ea4606cd3f74377691d200d69df8398f90cc2ff.zip
Basic conversion parsing
Using a list to store each format conversion informations.
Diffstat (limited to 'list.c')
-rw-r--r--list.c54
1 files changed, 54 insertions, 0 deletions
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 <stdlib.h>
+#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;
+}