From 9666a0a0ef6f5a4fb30bac93797d0f029ad8294a Mon Sep 17 00:00:00 2001
From: JozanLeClerc <bousset.rudy@gmail.com>
Date: Thu, 7 May 2020 13:49:10 +0200
Subject: Still pipin'

---
 src/ft_s_lpipes.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

(limited to 'src/ft_s_lpipes.c')

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);
+}
-- 
cgit v1.2.3