diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-12 20:43:30 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-12 20:43:30 +0200 |
commit | ff116f01c3680d0e5d8c32dd9978ed05a37f800c (patch) | |
tree | 73765e5ac7ea4ec8af461f44f6d8288fdad6fd82 /src/s_line.c | |
parent | Lots of stuff to do (diff) | |
download | 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.gz 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.bz2 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.xz 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.tar.zst 42-minishell-ff116f01c3680d0e5d8c32dd9978ed05a37f800c.zip |
FeelsCleanMan
Diffstat (limited to 'src/s_line.c')
-rw-r--r-- | src/s_line.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/s_line.c b/src/s_line.c new file mode 100644 index 0000000..5fe9a96 --- /dev/null +++ b/src/s_line.c @@ -0,0 +1,92 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* s_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:19:27 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:19:29 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stdlib.h> +#include <stdint.h> + +#include "p_line.h" +#include "s_com.h" +#include "s_struct.h" + +t_line + *s_line_last(t_line *line) +{ + while (line->next != NULL) + line = line->next; + return (line); +} + +void + s_line_add_back(t_line **aline, + t_line *new) +{ + t_line *tmp; + + if (!*aline) + *aline = new; + else + { + tmp = s_line_last(*aline); + tmp->next = new; + } +} + +void + s_line_clear(t_line **line) +{ + t_line *tmp; + t_line *renext; + + if (!line) + return ; + tmp = *line; + while (tmp != NULL) + { + renext = tmp->next; + if (tmp->com != NULL) + { + s_com_destroy(&tmp->com); + } + /* ft_memdel((void*)&tmp->com); */ + /* if (tmp->argv) */ + /* ft_delwords(tmp->argv); */ + /* if (tmp->redir != 0) */ + /* ft_memdel((void*)&tmp->rdrpath); */ + /* if (tmp->env_fork != NULL) */ + /* ft_delwords(tmp->env_fork); */ + ft_memdel((void*)&tmp); + tmp = renext; + } + *line = NULL; +} + +t_line + *s_line_new(const char word[], + t_msh *msh) +{ + t_line *link; + + if ((link = (t_line*)malloc(sizeof(t_line))) == NULL) + return (NULL); + link->com = NULL; + link->pipes = NULL; + link->next = NULL; + if (word == NULL) + { + link->next = NULL; + return (link); + } + link->com = s_com_new(word, msh); + /* TODO: check link->com = NULL */ + return (link); +} |