aboutsummaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-19 13:31:08 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-19 13:31:08 +0200
commit35434a76eaab34e4d639f5bd0a3b7ba610001c5e (patch)
treecf30a93445da19b38392c0c5e8303038164de906 /src/eval
parenta2ebd4ad078d7056a4c28ea697cfd3ebbf09d0f6 (diff)
parentc8091831c4ce1c4cf8703b18de22441aff191f44 (diff)
downloadminishell-35434a76eaab34e4d639f5bd0a3b7ba610001c5e.tar.gz
minishell-35434a76eaab34e4d639f5bd0a3b7ba610001c5e.tar.bz2
minishell-35434a76eaab34e4d639f5bd0a3b7ba610001c5e.zip
Merge branch 'parse_cmd'
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/eval.c82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/eval/eval.c b/src/eval/eval.c
new file mode 100644
index 0000000..a831237
--- /dev/null
+++ b/src/eval/eval.c
@@ -0,0 +1,82 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* eval.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/01 17:05:21 by charles #+# #+# */
+/* Updated: 2020/06/18 13:16:34 by nahaddac ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+/*
+** \file eval.c
+** \brief Evaluation of an AST
+*/
+
+/* #include "eval.h" */
+
+/* #<{(| */
+/* ** \brief Evaluate a line */
+/* ** \param state State of the evaluation */
+/* ** \param line Line to evaluate */
+/* ** \return Last Executed command status or -1 on error */
+/* |)}># */
+/* */
+/* static int eval_line(void *param) */
+/* { */
+/* int status; */
+/* t_eval_state *state; */
+/* t_line *line; */
+/* int fd_in; */
+/* int fd_out; */
+/* */
+/* state = ((t_fork_param_line*)param)->state; */
+/* line = ((t_fork_param_line*)param)->line; */
+/* fd_in = ((t_fork_param_line*)param)->fd_in; */
+/* fd_out = ((t_fork_param_line*)param)->fd_out; */
+/* */
+/* #<{(| if (line->right == NULL) |)}># */
+/* #<{(| return (eval(state, line->left)); |)}># */
+/* */
+/* #<{(| if (line->sep == SEP_PIPE) |)}># */
+/* #<{(| pipe(state->p); |)}># */
+/* */
+/* if (line->left->tag == AST_LINE) */
+/* { */
+/* return (fork_wrap(fd_in, fd_out, param, &eval_line)); */
+/* } */
+/* if ((status = eval(fd_in, fd_out, state, line->left)) == -1) */
+/* return (-1); */
+/* if ((line->sep == SEP_AND && status != 0) || */
+/* (line->sep == SEP_OR && status == 0)) */
+/* return (status); */
+/* */
+/* return (eval(fd_in, fd_out, state, line->right)); */
+/* } */
+/* */
+/* #<{(| */
+/* ** \brief Evaluate an AST */
+/* ** \param state State of the evaluation */
+/* ** \param ast Abstract syntax tree to evaluate */
+/* ** \return Last command status or -1 on error */
+/* |)}># */
+/* */
+/* int eval(int fd_in, int fd_out, t_eval_state *state, t_ast *ast) */
+/* { */
+/* t_fork_param_line param; */
+/* */
+/* errno = 0; */
+/* if (ast->tag == TAG_LINE) */
+/* { */
+/* param.state = state; */
+/* param.line = &ast->line; */
+/* param.fd_in = fd_in; */
+/* param.fd_out = fd_out; */
+/* return (eval_line(&param)); */
+/* } */
+/* if (ast->tag == TAG_CMD) */
+/* return (eval_cmd(fd_in, fd_out, state, &ast->cmd)); */
+/* return (-1); */
+/* } */