diff options
Diffstat (limited to 'src/ft_s_lpipes.c')
-rw-r--r-- | src/ft_s_lpipes.c | 90 |
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); +} |