From 831cc03ff6c01fb78d77629b7a8f2a75d9e9f75a Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 19 Jun 2020 13:45:32 +0200 Subject: Fixed ast_print --- src/debug.c | 15 ++++++++++++--- src/eval/op.c | 35 ++++++++++++++++++----------------- src/main.c | 10 +++++----- src/parse/parse.c | 30 +++++++++++++++--------------- 4 files changed, 50 insertions(+), 40 deletions(-) diff --git a/src/debug.c b/src/debug.c index dd0919e..b23fe51 100644 --- a/src/debug.c +++ b/src/debug.c @@ -27,6 +27,15 @@ void print_level(int level) void ast_print(int level, t_ast *ast) { + if (ast->tag == AST_PARENT) + { + print_level(level); + printf("parent: redir [ "); + ft_lstiter(ast->redirs, token_put); + printf(" ]\n"); + ast_print(level + 1, ast->parent_ast); + + } if (ast->tag == AST_CMD) { print_level(level); @@ -40,9 +49,9 @@ void ast_print(int level, t_ast *ast) { /* printf("SEP: %d\n", ast->op.sep); */ print_level(level); - printf("redirs: ["); - ft_lstiter(ast->redirs, token_put); - printf(" ] "); + /* printf("redirs: ["); */ + /* ft_lstiter(ast->redirs, token_put); */ + /* printf(" ] "); */ printf("{\n"); print_level(level); diff --git a/src/eval/op.c b/src/eval/op.c index b8ad63c..e022fc1 100644 --- a/src/eval/op.c +++ b/src/eval/op.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 15:27:22 by charles #+# #+# */ -/* Updated: 2020/06/19 12:18:57 by charles ### ########.fr */ +/* Updated: 2020/06/19 13:34:28 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,12 +29,6 @@ int eval_op(int fds[2], t_env env, t_path path, t_ast *ast) left_fds[FDS_WRITE] = p[FDS_WRITE]; right_fds[FDS_READ] = p[FDS_READ]; } - if (!redir_extract(ast->redirs, env, fds)) - { - ast->redirs = NULL; - return (-1); - } - ast->redirs = NULL; if ((status = eval(left_fds, env, path, ast->op.left)) == -1) return (-1); if ((ast->op.sep == TAG_AND && status != 0) || @@ -52,21 +46,28 @@ int wrapped_eval(void *void_param) return (eval(param->fds, param->env, param->path, param->ast)); } -int eval(int fds[2], t_env env, t_path path, t_ast *ast) +int eval_parent(int fds[2], t_env env, t_path path, t_ast *ast) { t_fork_param_parent param; - // need to handle pipe and redir - if (ast->tag & AST_PARENT) + if (!redir_extract(ast->redirs, env, fds)) { - param.fds[0] = fds[0]; - param.fds[1] = fds[1]; - param.env = env; - param.path = path; - ast->tag ^= AST_PARENT; - param.ast = ast; - return (fork_wrap(fds, ¶m, wrapped_eval)); + ast->redirs = NULL; + return (-1); } + param.fds[0] = fds[0]; + param.fds[1] = fds[1]; + param.env = env; + param.path = path; + ast->tag ^= AST_PARENT; + param.ast = ast; + return (fork_wrap(fds, ¶m, wrapped_eval)); +} + +int eval(int fds[2], t_env env, t_path path, t_ast *ast) +{ + if (ast->tag & AST_PARENT) + return (eval_parent(fds, env, path, ast)); if (ast->tag == AST_OP) return (eval_op(fds, env, path, ast)); if (ast->tag == AST_CMD) diff --git a/src/main.c b/src/main.c index 0358a91..77f4070 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */ -/* Updated: 2020/06/19 13:30:40 by charles ### ########.fr */ +/* Updated: 2020/06/19 13:37:42 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,16 +48,16 @@ int main(int argc, char **argv, char **envp) if (parser_out == NULL || parser_out->unexpected != NULL) return (1); - /* ast_print(0, parser_out->ast); */ + ast_print(0, parser_out->ast); /* printf("===cmd_argv===\n"); */ /* ft_lstiter(parser_out->ast->cmd_argv, token_debug); */ /* printf("===redirs===\n"); */ /* ft_lstiter(parser_out->ast->redirs, token_debug); */ - int fds[2] = {MS_NO_FD, MS_NO_FD}; - int eval_out = eval(fds, env, path, parser_out->ast); - (void)eval_out; + /* int fds[2] = {MS_NO_FD, MS_NO_FD}; */ + /* int eval_out = eval(fds, env, path, parser_out->ast); */ + /* (void)eval_out; */ } ft_htdestroy(path, free); diff --git a/src/parse/parse.c b/src/parse/parse.c index cc4d56d..02357da 100755 --- a/src/parse/parse.c +++ b/src/parse/parse.c @@ -6,7 +6,7 @@ /* By: nahaddac +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 18:09:04 by nahaddac #+# #+# */ -/* Updated: 2020/06/19 13:28:12 by nahaddac ### ########.fr */ +/* Updated: 2020/06/19 13:38:23 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -118,7 +118,7 @@ t_ret *parse_expr(t_ftlst *input) return (NULL); input = input->next; t_ast *new_ast = ast_new(AST_PARENT); - new_ast = tmp->ast; + new_ast->parent_ast = tmp->ast; tmp->ast = new_ast; if (tag & TAG_IS_REDIR) { @@ -145,17 +145,17 @@ t_ret *parse(t_ftlst *input) t_ret *ret; t_ftlst *in_f; - in_f = input; - if (input == NULL) - return NULL; - if (!(ret = malloc(sizeof(t_ret) * 1))) - return (NULL); - ret->ast = NULL; - ret->rest = NULL; - if((ret->unexpected = error_syntax_simple(input)) != NULL) - printf("%s\n", ret->unexpected->content); - ret = parse_op(in_f); - ast_destroy(ret->ast); - ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); - return (NULL); + /* in_f = input; */ + /* if (input == NULL) */ + /* return NULL; */ + /* if (!(ret = malloc(sizeof(t_ret) * 1))) */ + /* return (NULL); */ + /* ret->ast = NULL; */ + /* ret->rest = NULL; */ + /* if((ret->unexpected = error_syntax_simple(input)) != NULL) */ + /* printf("%s\n", ret->unexpected->content); */ + ret = parse_op(input); + /* ast_destroy(ret->ast); */ + /* ft_lstdestroy(&ret->rest, (void (*)(void*))token_destroy); */ + return (ret); } -- cgit