diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-14 20:50:57 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-14 20:50:57 +0200 |
commit | a2dc5174eb19caebf074b446dae129d17485e7bb (patch) | |
tree | 7fcf83e441d10ed9ef60db10de819b1c927dc263 /src/p_split.c | |
parent | Just a few more line and we're good (diff) | |
download | 42-minishell-a2dc5174eb19caebf074b446dae129d17485e7bb.tar.gz 42-minishell-a2dc5174eb19caebf074b446dae129d17485e7bb.tar.bz2 42-minishell-a2dc5174eb19caebf074b446dae129d17485e7bb.tar.xz 42-minishell-a2dc5174eb19caebf074b446dae129d17485e7bb.tar.zst 42-minishell-a2dc5174eb19caebf074b446dae129d17485e7bb.zip |
&& and || works pretty bav
Diffstat (limited to '')
-rw-r--r-- | src/p_split.c | 26 |
1 files changed, 14 insertions, 12 deletions
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 @@ -70,6 +70,18 @@ static char } 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); } |