summaryrefslogtreecommitdiffstats
path: root/src/ft_s_lpipes.c
diff options
context:
space:
mode:
authorJozanLeClerc <bousset.rudy@gmail.com>2020-05-07 13:49:10 +0200
committerJozanLeClerc <bousset.rudy@gmail.com>2020-05-07 13:49:10 +0200
commit9666a0a0ef6f5a4fb30bac93797d0f029ad8294a (patch)
treea09f917723ae3a0dfeaef025b5e9a76e2c8602f2 /src/ft_s_lpipes.c
parentPreparing the structs (diff)
download42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.gz
42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.bz2
42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.xz
42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.zst
42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.zip
Still pipin'
Diffstat (limited to '')
-rw-r--r--src/ft_s_lpipes.c90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/ft_s_lpipes.c b/src/ft_s_lpipes.c
index addbe7b..0a637ce 100644
--- a/src/ft_s_lpipes.c
+++ b/src/ft_s_lpipes.c
@@ -10,6 +10,96 @@
/* */
/* ************************************************************************** */
+#include <libft.h>
+#include <stdlib.h>
#include <stdint.h>
+#include "ft_s_lcom.h"
#include "ft_s_lpipes.h"
+#include "ft_s_struct.h"
+
+struct s_lpipes
+ *ft_lpipes_last(struct s_lpipes *lpipes)
+{
+ while (lpipes->next != NULL)
+ lpipes = lpipes->next;
+ return (lpipes);
+}
+
+void
+ ft_lpipes_add_back(struct s_lpipes **alpipes,
+ struct s_lpipes *new)
+{
+ t_lcom *tmp;
+
+ if (!*alpipes)
+ *alpipes = new;
+ else
+ {
+ tmp = ft_lpipes_last(*alpipes);
+ tmp->next = new;
+ }
+}
+
+void
+ ft_lpipes_clear(struct s_lpipes **lpipes)
+{
+ struct s_lpipes *tmp;
+ struct s_lpipes *renext;
+
+ if (!lcom)
+ return ;
+ tmp = *lpipes;
+ while (tmp)
+ {
+ renext = tmp->next;
+ ft_lcom_clear(&tmp->one);
+ ft_memdel((void*)&tmp);
+ tmp = renext;
+ }
+ *lpipes = NULL;
+}
+
+struct s_lpipes
+ *ft_lpipes_new(const char pipedword[],
+ t_msh *msh)
+{
+ struct s_lpipes *link;
+
+ if (!(link = (struct s_lpipes*)malloc(sizeof(struct s_lpipes))))
+ return (NULL);
+ link->one = NULL;
+ if (!(link->one = ft_lcom_new(pipedword, msh)))
+ {
+ return (NULL);
+ }
+ link->next = NULL;
+ return (link);
+}
+
+struct s_lpipes
+ *ft_split_pipes(const char word[],
+ t_lcom *lcom,
+ t_msh *msh)
+{
+ struct s_pipes *link;
+ struct s_pipes *lpipes;
+ char **words;
+ size_t i;
+
+ if (!(words = ft_split(word, '|')))
+ return (NULL);
+ i = 0;
+ if (!(lpipes = (struct s_lpipes*)malloc(sizeof(struct s_lpipes))))
+ while (words[i])
+ {
+ if (!(link = ft_lpipes_new(words[i], msh)))
+ {
+ return (NULL);
+ }
+ ft_lpipes_add_back();
+ i++;
+ }
+ ft_delwords(words);
+ return (lpipes);
+}