diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-07-31 23:47:45 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-07-31 23:47:45 +0200 |
commit | 11aeaaf8deeb265ac98cbabfa501d2da155475d7 (patch) | |
tree | 455cf1bedab878d606a7beea69bf57dfebe76893 /src/p_lcom_next.c | |
parent | Stuff to fix (diff) | |
download | 42-minishell-11aeaaf8deeb265ac98cbabfa501d2da155475d7.tar.gz 42-minishell-11aeaaf8deeb265ac98cbabfa501d2da155475d7.tar.bz2 42-minishell-11aeaaf8deeb265ac98cbabfa501d2da155475d7.tar.xz 42-minishell-11aeaaf8deeb265ac98cbabfa501d2da155475d7.tar.zst 42-minishell-11aeaaf8deeb265ac98cbabfa501d2da155475d7.zip |
The hell it works, now asan lol
Diffstat (limited to '')
-rw-r--r-- | src/p_lcom_next.c | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/src/p_lcom_next.c b/src/p_lcom_next.c index e3f1dfa..f340294 100644 --- a/src/p_lcom_next.c +++ b/src/p_lcom_next.c @@ -15,10 +15,14 @@ #include <stdint.h> #include "d_enum.h" +#include "s_destroy.h" +#include "f_fail.h" #include "s_struct.h" #include "u_vars.h" #include "u_vars_next.h" +/* TODO: norme */ + static int8_t subst_those_vars(int64_t i, char **p_words, @@ -124,69 +128,77 @@ static void i++; ptr++; } + val[i] = '\0'; u_subst_var_value(name, val, msh); } static char **p_add_to_variables_and_delete( /* t_bool equals[], */ char *words[], + t_bool reg, int64_t i, t_msh *msh) { - char *ptr; - t_bool reg; int64_t j; + int64_t k; + char **rewords; - reg = FALSE; - ptr = words[i - 1]; - while (*ptr != '\0' && *ptr != '=') - { - ptr++; - } - if (*ptr != '\0') - { - reg = TRUE; - } j = 0; if (reg == TRUE) { - while (words[j]) + while (words[j] && j < i) { p_register_word(words[j], msh); j++; } } j = 0; - while (j < i) - { - ft_memdel((void*)&words[0]); - words = words + 1; + while (words[i + j] != NULL) j++; + if (!(rewords = (char**)malloc((j + 1) * sizeof(char*)))) + { + ft_delwords(words); + s_destroy(msh); + f_fail_alloc(msh); } - return (words); + k = i; + while (i - k < j) + { + if (!(rewords[i - k] = ft_strdup(words[i]))) + { + ft_delwords(words); + s_destroy(msh); + f_fail_alloc(msh); + } + i++; + } + rewords[i - k] = 0; + ft_delwords(words); + i++; + return (rewords); } char **p_check_args_equals(char *words[], t_msh *msh) { - /* t_bool equals[255]; */ char *ptr; + t_bool reg; int64_t i; - /* i = -1; */ - /* while (++i < 255) */ - /* equals[i] = FALSE; */ - i = -1; - while (words[++i]) + i = 0; + reg = TRUE; + while (words[i]) { ptr = words[i]; while (*ptr != '\0' && *ptr != '=') ptr++; - /* if (*ptr != '\0') */ - /* equals[i] = TRUE; */ - if (*ptr == '\0') + if (*ptr == '\0' || words[i][0] == '=') + { + reg = FALSE; break ; + } + i++; } - return (p_add_to_variables_and_delete(/* equals, */words, i, msh)); + return (p_add_to_variables_and_delete(/* equals, */words, reg, i, msh)); } |