diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-26 21:05:11 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-26 21:05:11 +0200 |
commit | 38bbcb10980c5ad1692aadd574e911e9c551cae9 (patch) | |
tree | 8e9ea8db6c558429d33323e7f9258799fcf15a6c /src/ft_p_lcom_next.c | |
parent | searching (diff) | |
download | 42-minishell-38bbcb10980c5ad1692aadd574e911e9c551cae9.tar.gz 42-minishell-38bbcb10980c5ad1692aadd574e911e9c551cae9.tar.bz2 42-minishell-38bbcb10980c5ad1692aadd574e911e9c551cae9.tar.xz 42-minishell-38bbcb10980c5ad1692aadd574e911e9c551cae9.tar.zst 42-minishell-38bbcb10980c5ad1692aadd574e911e9c551cae9.zip |
Better subst
Diffstat (limited to '')
-rw-r--r-- | src/ft_p_lcom_next.c | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c index e025f96..34c0d2c 100644 --- a/src/ft_p_lcom_next.c +++ b/src/ft_p_lcom_next.c @@ -24,6 +24,7 @@ char /* TODO: norme */ char **p_words; char *s_varname; + char *varval; int64_t i; size_t varlen; @@ -31,20 +32,17 @@ char varlen = 0; while (*p_words) { - while (varlen < ft_strlen(*p_words) && - (i = ft_strlchr((*p_words) + varlen, '$'))) + while ((i = ft_strlchr(*p_words, '$')) != -1) { - ft_printf("%ld|||\n", i); - if (i == -1) - break ; varlen = i + 1; while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') varlen += 1; - varlen -= 1; if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen))) return (NULL); - ft_printf("{%s} | {%s}\n", s_varname, ft_subst_var_value(s_varname, msh)); + varval = ft_subst_var_value(s_varname, msh); + *p_words = ft_strsubst(*p_words, s_varname, varval); ft_memdel((void*)&s_varname); + ft_memdel((void*)&varval); varlen += 1; } p_words += 1; |