diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-14 10:36:53 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-14 10:36:53 +0200 |
| commit | 26ddbd7146f65a2cf100713f422a9ab5b1890620 (patch) | |
| tree | 76daa703ee5ea4c3eafcbce0f8127ab5c92983ab /src/ast.c | |
| parent | ab1e32c348c649c1c7c8dad5922cfe1c0f11ac5d (diff) | |
| download | minishell-26ddbd7146f65a2cf100713f422a9ab5b1890620.tar.gz minishell-26ddbd7146f65a2cf100713f422a9ab5b1890620.tar.bz2 minishell-26ddbd7146f65a2cf100713f422a9ab5b1890620.zip | |
Changing ast related struct and fixing functions accordingly
Diffstat (limited to 'src/ast.c')
| -rw-r--r-- | src/ast.c | 29 |
1 files changed, 13 insertions, 16 deletions
@@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 17:05:42 by charles #+# #+# */ -/* Updated: 2020/05/04 12:00:20 by charles ### ########.fr */ +/* Updated: 2020/06/14 10:29:21 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,25 +20,22 @@ /* ** \brief Create a new AST node according to `tag` ** \param tag Tag of node -** \param data Pointer to node data (t_cmd or t_line) -** which will be copied in ast::data union ** \return Created node or NULL on error */ -t_ast *ast_new(t_ast_tag tag, void *data) +t_ast *ast_new(enum e_ast_tag tag) { t_ast *ast; - if (data == NULL) - return (NULL); if ((ast = (t_ast*)malloc(sizeof(t_ast))) == NULL) return (NULL); - ft_bzero(ast, sizeof(t_ast)); ast->tag = tag; - if (tag == TAG_CMD) - ft_memcpy(&ast->cmd, (t_cmd*)data, sizeof(t_cmd)); - else if (tag == TAG_LINE) - ft_memcpy(&ast->line, (t_line*)data, sizeof(t_line)); + ast->in = NULL; + ast->out = NULL; + ast->is_append = false; + ast->line.left = NULL; + ast->line.right = NULL; + ast->cmd_argv = NULL; return (ast); } @@ -51,13 +48,13 @@ void ast_destroy(t_ast *ast) { if (ast == NULL) return ; - if (ast->tag == TAG_CMD) + if (ast->tag == AST_CMD) { - ft_split_destroy(ast->cmd.argv); - free(ast->cmd.in); - free(ast->cmd.out); + ft_lstdestroy(&ast->cmd_argv, (void (*)(void*))token_destroy); + ft_lstdestroy(&ast->in, (void (*)(void*))token_destroy); + ft_lstdestroy(&ast->out, (void (*)(void*))token_destroy); } - else if (ast->tag == TAG_LINE) + else if (ast->tag == AST_LINE) { ast_destroy(ast->line.left); ast_destroy(ast->line.right); |
