/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* s_lpipes.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include "s_com.h" #include "s_line.h" #include "s_lpipes.h" #include "s_struct.h" struct s_lpipes *s_lpipes_last(struct s_lpipes *lpipes) { while (lpipes->next != NULL) lpipes = lpipes->next; return (lpipes); } void s_lpipes_add_back(struct s_lpipes **alpipes, struct s_lpipes *new) { struct s_lpipes *tmp; if (!*alpipes) *alpipes = new; else { tmp = s_lpipes_last(*alpipes); tmp->next = new; } } void s_lpipes_clear(struct s_lpipes **lpipes) { struct s_lpipes *tmp; struct s_lpipes *renext; if (!lpipes) return ; tmp = *lpipes; while (tmp) { renext = tmp->next; s_com_destroy(&tmp->com); ft_memdel((void*)&tmp); tmp = renext; } *lpipes = NULL; } struct s_lpipes *s_lpipes_new(const char pipedword[], t_msh *msh) { struct s_lpipes *link; if ((link = (struct s_lpipes*)malloc(sizeof(struct s_lpipes))) == NULL) return (NULL); link->com = NULL; if ((link->com = s_com_new(pipedword, msh)) == NULL) { return (NULL); } link->next = NULL; return (link); } struct s_lpipes *s_split_pipes(const char word[], t_msh *msh) { struct s_lpipes *lpipes; char **words; size_t i; if (!(words = ft_split(word, '|'))) return (NULL); i = 0; while (words[i]) { if (!(lpipes = s_lpipes_new(words[i], msh))) { return (NULL); } s_lpipes_add_back(&msh->pipes, lpipes); i++; } ft_delwords(words); return (lpipes); }