diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-03 14:05:48 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-10-03 14:05:48 +0200 |
commit | 0bd9e2655d57084e5e66ec83bbadef75b78f2252 (patch) | |
tree | aebbd0cd87fa79c8867b7f899384c005ae9b46f3 /src | |
parent | Norming p_subst_alias (diff) | |
download | 42-minishell-0bd9e2655d57084e5e66ec83bbadef75b78f2252.tar.gz 42-minishell-0bd9e2655d57084e5e66ec83bbadef75b78f2252.tar.bz2 42-minishell-0bd9e2655d57084e5e66ec83bbadef75b78f2252.tar.xz 42-minishell-0bd9e2655d57084e5e66ec83bbadef75b78f2252.tar.zst 42-minishell-0bd9e2655d57084e5e66ec83bbadef75b78f2252.zip |
In progress
Diffstat (limited to 'src')
-rw-r--r-- | src/p_subst_alias.c | 60 | ||||
-rw-r--r-- | src/p_subst_alias.h | 9 |
2 files changed, 38 insertions, 31 deletions
diff --git a/src/p_subst_alias.c b/src/p_subst_alias.c index 289a951..b011d15 100644 --- a/src/p_subst_alias.c +++ b/src/p_subst_alias.c @@ -13,6 +13,7 @@ #include <libft.h> #include <stddef.h> +#include "p_subst_alias.h" #include "s_struct.h" #include "u_alias.h" #include "u_parse.h" @@ -82,47 +83,44 @@ static void p_reset_used(size_t used[], t_bool reset, size_t *i) size_t p_subst_alias(char word[], t_bool reset, t_msh *msh) { - static size_t used[4096]; - static size_t i = 0; - char value[ARG_MAX]; - char tmp[255]; - size_t locat[2]; - char *ptr; - int64_t j; - size_t usedcmp; - t_bool good; + struct s_subst_alias s; + static size_t used[4096]; + static size_t i = 0; + char *ptr; + int64_t j; p_reset_used(used, reset, &i); ptr = word; ptr = p_skip_whitespace(ptr); - good = TRUE; - locat[0] = (ptr - word); - locat[1] = (ptr - word); - ptr = p_set_ptr(ptr, word, &good, locat); - if (*ptr == C_NUL && good == TRUE) - locat[1] = (ptr - word); - if (good == FALSE) + s.good = TRUE; + s.locat[0] = (ptr - word); + s.locat[1] = (ptr - word); + ptr = p_set_ptr(ptr, word, &s.good, s.locat); + if (*ptr == C_NUL && s.good == TRUE) + s.locat[1] = (ptr - word); + if (s.good == FALSE) return (0); - ft_strlcpy(tmp, - word + locat[0], - ((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1); - if ((usedcmp = u_get_alias_value(value, tmp, ARG_MAX, msh)) != 0) + ft_strlcpy(s.tmp, + 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) { - good = TRUE; + s.good = TRUE; j = -1; while (++j < (int64_t)i) - good = (used[j] == usedcmp) ? (FALSE) : (good); - if (good == TRUE) + s.good = (used[j] == s.usedcmp) ? (FALSE) : (s.good); + if (s.good == TRUE) { - (void)ft_memmove(word + (locat[0] + ft_strlen(value)), - word + locat[1], - ft_strlen(word + locat[1]) + 1 * sizeof(char)); - (void)ft_memmove(word + locat[0], - value, - ft_strlen(value) * sizeof(char)); - used[i] = usedcmp; + (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 (usedcmp); + return (s.usedcmp); } } return (0); diff --git a/src/p_subst_alias.h b/src/p_subst_alias.h index 5d5476f..2aa29fb 100644 --- a/src/p_subst_alias.h +++ b/src/p_subst_alias.h @@ -18,6 +18,15 @@ # include "s_struct.h" +struct s_subst_alias +{ + char value[ARG_MAX]; + char tmp[255]; + size_t locat[2]; + size_t usedcmp; + t_bool good; +}; + size_t p_subst_alias(char word[], t_bool reset, t_msh *msh); #endif |