/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* s_line.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 "d_define.h" #include "p_line.h" #include "s_com.h" #include "s_struct.h" t_line_block *s_line_last(t_line_block *line) { while (line->next != NULL) { line = line->next; } return (line); } void s_line_add_back(t_line_block **aline, t_line_block *new) { t_line_block *tmp; if (*aline == NULL) { *aline = new; } else { tmp = s_line_last(*aline); tmp->next = new; } } void s_line_clear(t_line_block **line) { t_line_block *renext; t_line_block *tmp; if (line == NULL) { return ; } tmp = *line; while (tmp != NULL) { renext = tmp->next; ft_memdel((void*)&tmp->lblock); ft_memdel((void*)&tmp); tmp = renext; } *line = NULL; } t_line_block *s_line_new(const char word[], uint8_t nextif) { t_line_block *link; if ((link = (t_line_block*)malloc(sizeof(t_line_block))) == NULL) return (NULL); link->lblock = NULL; link->nextif = nextif; link->next = NULL; if (word == NULL) { link->next = NULL; return (link); } else if ((link->lblock = ft_strdup(word)) == NULL) { return (NULL); } return (link); }