summaryrefslogtreecommitdiffstats
path: root/src/u_alias.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/u_alias.c')
-rw-r--r--src/u_alias.c36
1 files changed, 28 insertions, 8 deletions
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 <libft.h>
+#include <stdint.h>
#include <stddef.h>
#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);
+ }
}