diff options
Diffstat (limited to 'src/eval/op.c')
| -rw-r--r-- | src/eval/op.c | 35 |
1 files changed, 18 insertions, 17 deletions
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 <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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) |
