diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-01 13:03:26 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-01 13:03:26 +0200 |
| commit | 551e668e1b7a030fdff236067963100c7d8747a5 (patch) | |
| tree | 198055e7c4e7f847d61949347dbd8dd3cbdc44ee /src/ast.c | |
| parent | b15ab562d74b5111ac7c9bd6e0ec185435902472 (diff) | |
| download | minishell-551e668e1b7a030fdff236067963100c7d8747a5.tar.gz minishell-551e668e1b7a030fdff236067963100c7d8747a5.tar.bz2 minishell-551e668e1b7a030fdff236067963100c7d8747a5.zip | |
Added AST functions, tested eval with basic input
Diffstat (limited to 'src/ast.c')
| -rw-r--r-- | src/ast.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/ast.c b/src/ast.c new file mode 100644 index 0000000..7c3fb8f --- /dev/null +++ b/src/ast.c @@ -0,0 +1,42 @@ +#include "ast.h" + +t_ast *ast_new(t_ast_tag tag, void *data) +{ + 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->data.cmd, (t_cmd*)data, sizeof(t_cmd)); + else if (tag == TAG_LINE) + ft_memcpy(&ast->data.line, (t_line*)data, sizeof(t_line)); + return (ast); +} + +static void cmd_destroy(t_cmd *cmd) +{ + ft_split_destroy(cmd->argv); + free(cmd->in); + free(cmd->out); +} + +static void line_destroy(t_line *line) +{ + ast_destroy(line->left); + ast_destroy(line->right); +} + +void ast_destroy(t_ast *ast) +{ + if (ast == NULL) + return ; + if (ast->tag == TAG_CMD) + cmd_destroy(&ast->data.cmd); + else if (ast->tag == TAG_LINE) + line_destroy(&ast->data.line); + free(ast); +} |
