diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-27 15:46:27 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-27 15:46:27 +0200 |
commit | bcc9a58fe387e02f8aeb140df7d11e9cd627220a (patch) | |
tree | 00ee13a9128248e84c81b2913fd99b2bd2887a48 | |
parent | Variables fixed (diff) | |
download | 42-minishell-bcc9a58fe387e02f8aeb140df7d11e9cd627220a.tar.gz 42-minishell-bcc9a58fe387e02f8aeb140df7d11e9cd627220a.tar.bz2 42-minishell-bcc9a58fe387e02f8aeb140df7d11e9cd627220a.tar.xz 42-minishell-bcc9a58fe387e02f8aeb140df7d11e9cd627220a.tar.zst 42-minishell-bcc9a58fe387e02f8aeb140df7d11e9cd627220a.zip |
Normed
-rw-r--r-- | src/ft_p_lcom_next.c | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c index c4666f4..53292ff 100644 --- a/src/ft_p_lcom_next.c +++ b/src/ft_p_lcom_next.c @@ -17,34 +17,43 @@ #include "ft_s_struct.h" #include "ft_u_vars.h" +static int8_t + ft_subst_those_vars(int64_t i, + char **p_words, + t_msh *msh) +{ + size_t varlen; + char *s_varname; + char *varval; + + varval = NULL; + s_varname = NULL; + varlen = i + 1; + while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') + varlen += 1; + if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i))) + return (-1); + 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); + return (0); +} + char **ft_subst_vars(char *words[], t_msh *msh) { - /* TODO: norme */ char **p_words; - char *s_varname; - char *varval; int64_t i; - size_t varlen; p_words = words; - varlen = 0; - varval = NULL; - s_varname = NULL; while (*p_words) { while ((i = ft_strlchr(*p_words, '$')) != -1) { - varlen = i + 1; - while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') - varlen += 1; - if (!(s_varname = ft_substr(*p_words, (uint32_t)i, varlen - i))) + if (ft_subst_those_vars(i, p_words, msh) != 0) return (NULL); - 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); } p_words += 1; } |