summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjoe <rbousset@42lyon.fr>2020-11-30 13:25:02 +0100
committerjoe <rbousset@42lyon.fr>2020-11-30 13:25:02 +0100
commit8d6a9c4848cae74be5b07390079cf888af2786b4 (patch)
tree069cc533a46ca8a036333dcc60e48da96ab6591b
parentFix (diff)
download42-minishell-8d6a9c4848cae74be5b07390079cf888af2786b4.tar.gz
42-minishell-8d6a9c4848cae74be5b07390079cf888af2786b4.tar.bz2
42-minishell-8d6a9c4848cae74be5b07390079cf888af2786b4.tar.xz
42-minishell-8d6a9c4848cae74be5b07390079cf888af2786b4.tar.zst
42-minishell-8d6a9c4848cae74be5b07390079cf888af2786b4.zip
Fixed alias but norme
-rw-r--r--src/b_alias.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/b_alias.c b/src/b_alias.c
index 02dfedb..fc1651b 100644
--- a/src/b_alias.c
+++ b/src/b_alias.c
@@ -72,11 +72,14 @@ static unsigned char b_print_arg(const char arg[], t_msh *msh)
return (b_print_arg_next(ptr, arg, invalid, msh));
}
+#include <stdlib.h>
static void b_register_arg(const char arg[], t_msh *msh)
{
char *ptr;
+ char *rptr;
char name[255];
char value[ARG_MAX];
+ char tmp;
ptr = (char*)arg;
while (*ptr != C_NUL && *ptr != C_EQUALS)
@@ -87,7 +90,21 @@ static void b_register_arg(const char arg[], t_msh *msh)
{
ft_strlcpy(name, arg, (ptr - arg < 255) ? ((ptr - arg) + 1) : (255));
ptr += 1;
- ft_strlcpy(value, ptr, ARG_MAX);
+ rptr = ptr;
+ while (*rptr != C_NUL && ft_iswhitespace(*rptr) == TRUE)
+ rptr++;
+ tmp = *(rptr + ft_strlen(name));
+ *(rptr + ft_strlen(name)) = C_NUL;
+ if (ft_strncmp(rptr, name, ft_strlen(name) + 1) == 0) {
+ *(rptr + ft_strlen(name)) = tmp;
+ ft_strlcpy(value, ptr, ARG_MAX);
+ ft_memmove(value + (rptr - ptr) + 1, value + (rptr - ptr), ft_strlen(value + (rptr - ptr)) + 1);
+ *(value + (rptr - ptr)) = C_BACKS;
+ }
+ else {
+ *(rptr + ft_strlen(name)) = tmp;
+ ft_strlcpy(value, ptr, ARG_MAX);
+ }
u_set_alias_value(name, value, msh);
}
}