From cf39c418a49808eb63cf4e1b5e2e363455f2da84 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Fri, 11 Sep 2020 17:58:05 +0200 Subject: alias utils prepared --- src/u_alias.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'src/u_alias.c') diff --git a/src/u_alias.c b/src/u_alias.c index 6253d60..f273a5c 100644 --- a/src/u_alias.c +++ b/src/u_alias.c @@ -11,33 +11,53 @@ /* ************************************************************************** */ #include +#include #include #include "d_define.h" +#include "s_lalias.h" #include "s_struct.h" -void +uint8_t u_get_alias_value(char str[], const char name[], size_t dstsize, t_msh *msh) { t_lalias *ptr; - str[0] = C_NUL; + if (str != NULL) + { + str[0] = C_NUL; + } ptr = msh->alias; - while (ptr != NULL && ft_strncmp(tmp->name, name, ft_strlen(name)) != 0) + while (ptr != NULL && ft_strncmp(ptr->name, name, ft_strlen(name) + 1) != 0) { ptr = ptr->next; } - if (ptr != NULL) + if (ptr == NULL) + { + return (1); + } + if (str != NULL) { - ft_strlcpy(str, tmp->value, dstsize); + ft_strlcpy(str, ptr->val, dstsize); } + return (0); } void u_set_alias_value(const char name[], const char value[], t_msh *msh) { - t_lalias *tmp; + t_lalias *new; - tmp = msh->alias; - while (tmp) + if (u_get_alias_value(NULL, name, 0, msh) != 0) + { + s_lalias_rebind(&msh->alias, name, value); + } + else + { + if ((new = s_lalias_new(name, value)) == NULL) + { + return ; + } + s_lalias_add_front(&msh->alias, new); + } } -- cgit v1.2.3