From a2dc5174eb19caebf074b446dae129d17485e7bb Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 14 Aug 2020 20:50:57 +0200 Subject: && and || works pretty bav --- src/p_split.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/p_split.c') diff --git a/src/p_split.c b/src/p_split.c index d834e58..bbe9bf5 100644 --- a/src/p_split.c +++ b/src/p_split.c @@ -69,6 +69,18 @@ static char return ((char*)line_ptr); } +static char + **p_split_destroy(char **words, + size_t i) +{ + while (i > 0) + { + ft_memdel((void*)&words[i]); + } + ft_memdel((void*)&words); + return (NULL); +} + static char **p_split_to_stuff(const char line[], const size_t count) @@ -94,7 +106,7 @@ static char { if ((words[i] = (char*)malloc(((ft_strlen(line_ptr) + 2) * sizeof(char)))) == NULL) - return (NULL); + return (p_split_destroy(words, i)); ft_memcpy(words[i], line_ptr, ft_strlen(line_ptr)); words[i][ft_strlen(line_ptr)] = ';'; words[i][ft_strlen(line_ptr) + 1] = '\0'; @@ -103,7 +115,7 @@ static char { if ((words[i] = (char*)malloc(((need_ptr - line_ptr) + 1) * sizeof(char))) == NULL) - return (NULL); + return (p_split_destroy(words, i)); ft_memcpy(words[i], line_ptr, (need_ptr - line_ptr) - 1); words[i][(need_ptr - line_ptr) - ((c == ';') ? (1) : (2))] = c; words[i][(need_ptr - line_ptr) - ((c == ';') ? (0) : (1))] = '\0'; @@ -119,7 +131,6 @@ char **p_split_line(const char line[]) { char **words; - size_t i; size_t count; count = p_count_semi_words(line); @@ -128,14 +139,5 @@ char count += 1; if ((words = p_split_to_stuff(line, count)) == NULL) return (NULL); - /* TODO: delete this */ - ft_printf("words[]:\n--------\n"); - i = 0; - while (words[i] != NULL) { - ft_printf("[%s]\n", words[i]); - i++; - } - ft_printf("[%s]\n", words[i]); - exit(0); return (words); } -- cgit v1.2.3