diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-03 14:09:00 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-03 14:09:00 +0200 |
commit | e098cee679a7dbb2ae1dd9cfa79b7adde29b9dc8 (patch) | |
tree | abc3dc4e13922b37141f7c509a5edaed279a29eb | |
parent | In progress (diff) | |
download | 42-minishell-e098cee679a7dbb2ae1dd9cfa79b7adde29b9dc8.tar.gz 42-minishell-e098cee679a7dbb2ae1dd9cfa79b7adde29b9dc8.tar.bz2 42-minishell-e098cee679a7dbb2ae1dd9cfa79b7adde29b9dc8.tar.xz 42-minishell-e098cee679a7dbb2ae1dd9cfa79b7adde29b9dc8.tar.zst 42-minishell-e098cee679a7dbb2ae1dd9cfa79b7adde29b9dc8.zip |
New func
-rw-r--r-- | src/p_subst_alias.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/p_subst_alias.c b/src/p_subst_alias.c index b011d15..55087de 100644 --- a/src/p_subst_alias.c +++ b/src/p_subst_alias.c @@ -81,6 +81,33 @@ static void p_reset_used(size_t used[], t_bool reset, size_t *i) } } +static size_t p_subst_alias_return(struct s_subst_alias s, + char word[], + char used[], + size_t i) +{ + if ((s.usedcmp = u_get_alias_value(s.value, s.tmp, ARG_MAX, msh)) != 0) + { + s.good = TRUE; + j = -1; + while (++j < (int64_t)i) + s.good = (used[j] == s.usedcmp) ? (FALSE) : (s.good); + if (s.good == TRUE) + { + (void)ft_memmove(word + (s.locat[0] + ft_strlen(s.value)), + word + s.locat[1], + ft_strlen(word + s.locat[1]) + 1 * sizeof(char)); + (void)ft_memmove(word + s.locat[0], + s.value, + ft_strlen(s.value) * sizeof(char)); + used[i] = s.usedcmp; + i++; + return (s.usedcmp); + } + } + return (0); +} + size_t p_subst_alias(char word[], t_bool reset, t_msh *msh) { struct s_subst_alias s; @@ -104,24 +131,5 @@ size_t p_subst_alias(char word[], t_bool reset, t_msh *msh) word + s.locat[0], ((s.locat[1] - s.locat[0] < 253) ? (s.locat[1] - s.locat[0]) : (254)) + 1); - if ((s.usedcmp = u_get_alias_value(s.value, s.tmp, ARG_MAX, msh)) != 0) - { - s.good = TRUE; - j = -1; - while (++j < (int64_t)i) - s.good = (used[j] == s.usedcmp) ? (FALSE) : (s.good); - if (s.good == TRUE) - { - (void)ft_memmove(word + (s.locat[0] + ft_strlen(s.value)), - word + s.locat[1], - ft_strlen(word + s.locat[1]) + 1 * sizeof(char)); - (void)ft_memmove(word + s.locat[0], - s.value, - ft_strlen(s.value) * sizeof(char)); - used[i] = s.usedcmp; - i++; - return (s.usedcmp); - } - } - return (0); + return (p_subst_alias_return(s, word, used, i)); } |