summaryrefslogtreecommitdiffstats
path: root/src/p_lblock_next.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/p_lblock_next.c')
-rw-r--r--src/p_lblock_next.c55
1 files changed, 45 insertions, 10 deletions
diff --git a/src/p_lblock_next.c b/src/p_lblock_next.c
index 3fa0ea5..0c1c1f4 100644
--- a/src/p_lblock_next.c
+++ b/src/p_lblock_next.c
@@ -110,16 +110,30 @@ static t_bool
return (FALSE);
}
-void
- p_subst_alias(char word[], t_msh *msh)
+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];
+ size_t j;
+ size_t usedcmp;
char *ptr;
t_bool good;
t_quote_mode mode;
+ if (reset == TRUE)
+ {
+ i = 0;
+ while (i < 4096)
+ {
+ used[i] = 0;
+ i++;
+ }
+ i = 0;
+ }
mode = Q_NONE;
ptr = word;
ptr = p_skip_whitespace(ptr);
@@ -157,15 +171,36 @@ void
ft_strlcpy(tmp,
word + locat[0],
((locat[1] - locat[0] < 253) ? (locat[1] - locat[0]) : (254)) + 1);
- if (u_get_alias_value(value, tmp, ARG_MAX, msh) != 0)
- return ;
- (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));
+ if ((usedcmp = u_get_alias_value(value, tmp, ARG_MAX, msh)) != 0)
+ {
+ j = 0;
+ good = TRUE;
+ while (j < i)
+ {
+ if (used[j] == usedcmp)
+ good = FALSE;
+ j++;
+ }
+ if (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;
+ i++;
+ return (usedcmp);
+ }
+ }
+ /* ptr = value; */
+ /* save = value; */
+ /* while (*ptr != C_NUL && ft_iswhitespace(*ptr) == FALSE) */
+ /* ptr++; */
+ /* ft_strlcpy(tmp, save, (ptr - save) + 1); */
}
+ return (0);
}
char