diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-26 17:18:16 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-04-26 17:18:16 +0200 |
commit | 75492244a377c8d5d61459a162d73d60dd32759e (patch) | |
tree | c1d86b502143a97a7fde36db303bdab4a62ae2dd /src/ft_p_lcom_next.c | |
parent | Todo update (diff) | |
download | 42-minishell-75492244a377c8d5d61459a162d73d60dd32759e.tar.gz 42-minishell-75492244a377c8d5d61459a162d73d60dd32759e.tar.bz2 42-minishell-75492244a377c8d5d61459a162d73d60dd32759e.tar.xz 42-minishell-75492244a377c8d5d61459a162d73d60dd32759e.tar.zst 42-minishell-75492244a377c8d5d61459a162d73d60dd32759e.zip |
Tryna subst vars
Diffstat (limited to '')
-rw-r--r-- | src/ft_p_lcom_next.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ft_p_lcom_next.c b/src/ft_p_lcom_next.c index df312bc..d1ab206 100644 --- a/src/ft_p_lcom_next.c +++ b/src/ft_p_lcom_next.c @@ -14,6 +14,44 @@ #include <stdlib.h> #include <stdint.h> +#include "ft_s_struct.h" +#include "ft_u_utils.h" + +char + **ft_subst_vars(char *words[], + t_msh *msh) +{ + /* TODO: norme */ + char **p_words; + char **p_env; + char *s_varname; + int64_t i; + size_t varlen; + + p_words = words; + varlen = 0; + while (*p_words) + { + while (varlen < ft_strlen(*p_words) && + (i = ft_strlchr((*p_words) + varlen, '$'))) + { + if (i == -1) + break ; + varlen = i + 1; + while ((*p_words)[varlen] != '\0' && (*p_words)[varlen] != '$') + 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)); + p_env = msh->envp; + ft_memdel((void*)&s_varname); + varlen += 1; + } + p_words += 1; + } + return (words); +} + char **ft_subst_args(const char word[], int8_t redir) |