From e098cee679a7dbb2ae1dd9cfa79b7adde29b9dc8 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sat, 3 Oct 2020 14:09:00 +0200 Subject: New func --- src/p_subst_alias.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'src') 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)); } -- cgit v1.2.3