summaryrefslogtreecommitdiffstats
path: root/src/s_lalias.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-09-11 17:45:49 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-09-11 17:45:49 +0200
commit6e74d376f1a888f4730b9fa39df1b34b251eb3f5 (patch)
treeeb602453b996ca6c67dbe2d281b8252b1e1ed429 /src/s_lalias.c
parentBetter (diff)
download42-minishell-6e74d376f1a888f4730b9fa39df1b34b251eb3f5.tar.gz
42-minishell-6e74d376f1a888f4730b9fa39df1b34b251eb3f5.tar.bz2
42-minishell-6e74d376f1a888f4730b9fa39df1b34b251eb3f5.tar.xz
42-minishell-6e74d376f1a888f4730b9fa39df1b34b251eb3f5.tar.zst
42-minishell-6e74d376f1a888f4730b9fa39df1b34b251eb3f5.zip
Aliases list in progress
Diffstat (limited to 'src/s_lalias.c')
-rw-r--r--src/s_lalias.c78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/s_lalias.c b/src/s_lalias.c
index 3bbee14..b4b9430 100644
--- a/src/s_lalias.c
+++ b/src/s_lalias.c
@@ -10,9 +10,85 @@
/* */
/* ************************************************************************** */
+#include <libft.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
#include "s_struct.h"
+void
+ s_lalias_rebind(t_lalias **lalias,
+ const char newname[],
+ const char newval[])
+{
+ t_lalias *tmp;
+
+ tmp = *lalias;
+ while (tmp != NULL &&
+ ft_strncmp(tmp->name, newname, ft_strlen(newname) + 1) != 0)
+ {
+ tmp = tmp->next;
+ }
+ if (tmp == NULL)
+ {
+ return ;
+ }
+ ft_memdel((void*)&tmp->val);
+ if ((tmp->val = ft_strdup(newval)) == NULL)
+ {
+ ft_dprintf(STDERR_FILENO, "%s\n", strerror(errno));
+ }
+}
+
+void
+ s_lalias_add_front(t_lalias **lalias, t_lalias *new)
+{
+ if (lalias == NULL || new == NULL)
+ {
+ return ;
+ }
+ new->next = *lalias;
+ *lalias = new;
+}
+
+void
+ s_lalias_clear(t_lalias **lalias)
+{
+ t_lalias *tmp;
+ t_lalias *renext;
+
+ if (lalias == NULL)
+ return ;
+ tmp = *lalias;
+ while (tmp != NULL)
+ {
+ renext = tmp->next;
+ ft_memdel((void*)&tmp->name);
+ ft_memdel((void*)&tmp->val);
+ ft_memdel((void*)&tmp);
+ }
+ *lalias = NULL;
+}
+
t_lalias
-*s_lalias_new(const char name[], const char val[])
+ *s_lalias_new(const char name[], const char val[])
{
+ t_lalias *link;
+
+ if ((link = (t_lalias*)malloc(sizeof(t_lalias))) == NULL)
+ {
+ return (NULL);
+ }
+ if ((link->name = ft_strdup(name)) == NULL)
+ {
+ return (NULL);
+ }
+ if ((link->val = ft_strdup(val)) == NULL)
+ {
+ return (NULL);
+ }
+ link->next = NULL;
+ return (link);
}