summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-10-03 14:42:37 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-10-03 14:42:37 +0200
commitdcc57c744bfb24d37c390dc51d1ff9e9d7be795f (patch)
treef7ee3ce5afd10571213bb26dca8bb778a0d6d1f4 /src
parentNormed p_subst_alias (diff)
download42-minishell-dcc57c744bfb24d37c390dc51d1ff9e9d7be795f.tar.gz
42-minishell-dcc57c744bfb24d37c390dc51d1ff9e9d7be795f.tar.bz2
42-minishell-dcc57c744bfb24d37c390dc51d1ff9e9d7be795f.tar.xz
42-minishell-dcc57c744bfb24d37c390dc51d1ff9e9d7be795f.tar.zst
42-minishell-dcc57c744bfb24d37c390dc51d1ff9e9d7be795f.zip
Normed p_subst_alias
Diffstat (limited to 'src')
-rw-r--r--src/p_subst_alias.c19
-rw-r--r--src/p_subst_alias.h13
2 files changed, 17 insertions, 15 deletions
diff --git a/src/p_subst_alias.c b/src/p_subst_alias.c
index 9bf77f7..674b9a3 100644
--- a/src/p_subst_alias.c
+++ b/src/p_subst_alias.c
@@ -45,13 +45,12 @@ static char *p_set_ptr(char *ptr, char word[], t_bool *good, size_t locat[])
locat[1] = (ptr - word);
if (*good == TRUE)
break ;
- else
+ else if ((*good = TRUE))
{
while (*ptr != C_NUL && ft_iswhitespace(*ptr))
ptr++;
locat[0] = (ptr - word);
ptr -= 1;
- *good = TRUE;
}
}
ptr++;
@@ -75,10 +74,12 @@ 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 used[],
size_t i)
{
- if ((s.usedcmp = u_get_alias_value(s.value, s.tmp, ARG_MAX, msh)) != 0)
+ int64_t j;
+
+ if ((s.usedcmp = u_get_alias_value(s.value, s.tmp, ARG_MAX, s.msh)) != 0)
{
s.good = TRUE;
j = -1;
@@ -87,11 +88,11 @@ static size_t p_subst_alias_return(struct s_subst_alias s,
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));
+ 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));
+ s.value,
+ ft_strlen(s.value) * sizeof(char));
used[i] = s.usedcmp;
i++;
return (s.usedcmp);
@@ -106,8 +107,8 @@ size_t p_subst_alias(char word[], t_bool reset, t_msh *msh)
static size_t used[4096];
static size_t i = 0;
char *ptr;
- int64_t j;
+ s.msh = msh;
p_reset_used(used, reset, &i);
ptr = word;
while (*ptr != C_NUL && ft_iswhitespace(*ptr))
diff --git a/src/p_subst_alias.h b/src/p_subst_alias.h
index 2aa29fb..7a797f6 100644
--- a/src/p_subst_alias.h
+++ b/src/p_subst_alias.h
@@ -18,13 +18,14 @@
# include "s_struct.h"
-struct s_subst_alias
+struct s_subst_alias
{
- char value[ARG_MAX];
- char tmp[255];
- size_t locat[2];
- size_t usedcmp;
- t_bool good;
+ char value[ARG_MAX];
+ char tmp[255];
+ size_t locat[2];
+ t_msh *msh;
+ size_t usedcmp;
+ t_bool good;
};
size_t p_subst_alias(char word[], t_bool reset, t_msh *msh);