diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-06-19 12:19:50 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-06-19 12:19:50 +0200 |
| commit | a2ebd4ad078d7056a4c28ea697cfd3ebbf09d0f6 (patch) | |
| tree | b021f962e60e614ce0baabbd4cbf1a933a001def /src/eval | |
| parent | bf97035e8d444c141725c0cf91aaaa285ae712af (diff) | |
| download | minishell-a2ebd4ad078d7056a4c28ea697cfd3ebbf09d0f6.tar.gz minishell-a2ebd4ad078d7056a4c28ea697cfd3ebbf09d0f6.tar.bz2 minishell-a2ebd4ad078d7056a4c28ea697cfd3ebbf09d0f6.zip | |
Added parenthesis handling in eval (not tested)
Diffstat (limited to 'src/eval')
| -rw-r--r-- | src/eval/cmd.c | 3 | ||||
| -rw-r--r-- | src/eval/op.c | 46 |
2 files changed, 38 insertions, 11 deletions
diff --git a/src/eval/cmd.c b/src/eval/cmd.c index f502984..4405cdd 100644 --- a/src/eval/cmd.c +++ b/src/eval/cmd.c @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/14 10:41:31 by charles #+# #+# */ -/* Updated: 2020/06/17 17:02:07 by charles ### ########.fr */ +/* Updated: 2020/06/19 12:03:13 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,6 +75,7 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast) return (-1); } + // can have no command (e.g `< file`) param.builtin = builtin_search_func(argv[0]); if (param.builtin == NULL) { diff --git a/src/eval/op.c b/src/eval/op.c index e47698b..b8ad63c 100644 --- a/src/eval/op.c +++ b/src/eval/op.c @@ -6,14 +6,13 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/06/17 15:27:22 by charles #+# #+# */ -/* Updated: 2020/06/17 17:03:48 by charles ### ########.fr */ +/* Updated: 2020/06/19 12:18:57 by charles ### ########.fr */ /* */ /* ************************************************************************** */ #include "eval.h" -// TODO: add parent tag on first operation of parent to fork -int eval_op(int fds[2], t_env env, t_path path, t_op *op) +int eval_op(int fds[2], t_env env, t_path path, t_ast *ast) { int status; int left_fds[2]; @@ -24,25 +23,52 @@ int eval_op(int fds[2], t_env env, t_path path, t_op *op) left_fds[FDS_WRITE] = MS_NO_FD; right_fds[FDS_READ] = MS_NO_FD; right_fds[FDS_WRITE] = fds[FDS_WRITE]; - if (op->sep == TAG_PIPE) + if (ast->op.sep == TAG_PIPE) { pipe(p); left_fds[FDS_WRITE] = p[FDS_WRITE]; right_fds[FDS_READ] = p[FDS_READ]; } - if ((status = eval(left_fds, env, path, op->left)) == -1) + 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 ((op->sep == TAG_AND && status != 0) || - (op->sep == TAG_PIPE && status != 0) || - (op->sep == TAG_OR && status == 0)) + if ((ast->op.sep == TAG_AND && status != 0) || + (ast->op.sep == TAG_PIPE && status != 0) || + (ast->op.sep == TAG_OR && status == 0)) return (status); - return (eval(right_fds, env, path, op->right)); + return (eval(right_fds, env, path, ast->op.right)); +} + +int wrapped_eval(void *void_param) +{ + t_fork_param_parent *param; + + param = 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) { + t_fork_param_parent param; + + // need to handle pipe and redir + if (ast->tag & AST_PARENT) + { + 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)); + } if (ast->tag == AST_OP) - return (eval_op(fds, env, path, &ast->op)); + return (eval_op(fds, env, path, ast)); if (ast->tag == AST_CMD) return (eval_cmd(fds, env, path, ast)); return (-1); |
