summaryrefslogtreecommitdiffstats
path: root/src/u_alias.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-11 17:58:05 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-11 17:58:05 +0200
commitcf39c418a49808eb63cf4e1b5e2e363455f2da84 (patch)
treed6e0403dfd1b72cb1cc76c15254d53d21c8bec6b /src/u_alias.c
parentAliases list in progress (diff)
download42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.gz
42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.bz2
42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.xz
42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.zst
42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.zip
alias utils prepared
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);
+ }
}