aboutsummaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-10 13:04:20 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-10 13:04:20 +0200
commitf5579768b8e27dbba16101dc3295927c15b36a1a (patch)
treeedfdaae3d0c16de4d3412148869f5d5d3c71f420 /src/eval
parentcccd4692fab390d0c4fbab3fcae7f4aa55ca9f1a (diff)
downloadminishell-f5579768b8e27dbba16101dc3295927c15b36a1a.tar.gz
minishell-f5579768b8e27dbba16101dc3295927c15b36a1a.tar.bz2
minishell-f5579768b8e27dbba16101dc3295927c15b36a1a.zip
Fixing signal last status code
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/cmd.c4
-rw-r--r--src/eval/eval.c4
-rw-r--r--src/eval/operation.c20
-rw-r--r--src/eval/parenthesis.c12
4 files changed, 34 insertions, 6 deletions
diff --git a/src/eval/cmd.c b/src/eval/cmd.c
index d107ce2..5bc397d 100644
--- a/src/eval/cmd.c
+++ b/src/eval/cmd.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/14 10:41:31 by charles #+# #+# */
-/* Updated: 2020/10/10 11:32:36 by cacharle ### ########.fr */
+/* Updated: 2020/10/10 12:57:23 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -78,6 +78,6 @@ int eval_cmd(int fds[2], t_env env, t_ast *ast)
param.env = env;
status = fork_wrap(fds, &param, (t_wrapped_func)st_wrapped_cmd);
ft_split_destroy(argv);
- g_state.last_status = status;
+ g_state.last_status = g_state.killed ? g_state.last_status : status;
return (status);
}
diff --git a/src/eval/eval.c b/src/eval/eval.c
index f78e8ee..c2aaf8c 100644
--- a/src/eval/eval.c
+++ b/src/eval/eval.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/13 20:38:06 by charles #+# #+# */
-/* Updated: 2020/10/10 11:28:12 by cacharle ### ########.fr */
+/* Updated: 2020/10/10 13:00:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -57,6 +57,8 @@ int fork_wrap(int fds[2], void *passed, t_wrapped_func wrapped)
int eval(int fds[2], t_env env, t_ast *ast)
{
+ if (g_state.killed)
+ return (0);
if (ast->tag == AST_OP)
return (eval_operation(fds, env, ast));
if (ast->tag == AST_CMD)
diff --git a/src/eval/operation.c b/src/eval/operation.c
index 826727a..3b6275a 100644
--- a/src/eval/operation.c
+++ b/src/eval/operation.c
@@ -6,12 +6,21 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/17 15:27:22 by charles #+# #+# */
-/* Updated: 2020/10/09 20:39:33 by charles ### ########.fr */
+/* Updated: 2020/10/10 13:01:56 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "eval.h"
+/*
+** \brief Evaluate an operation &&/||/;
+** \param fds Input/output filedescriptor
+** \param env Environment
+** \param ast Operation AST node
+** \return Status code of the left hand side if short circuit,
+** stat code of the right hand side otherwise.
+*/
+
int eval_operation(int fds[2], t_env env, t_ast *ast)
{
int status;
@@ -24,9 +33,9 @@ int eval_operation(int fds[2], t_env env, t_ast *ast)
right_fds[FD_WRITE] = fds[FD_WRITE];
if ((status = eval(left_fds, env, ast->op.left)) == EVAL_FATAL)
return (EVAL_FATAL);
- g_state.last_status = status;
if (g_state.killed)
return (status);
+ g_state.last_status = status;
if ((ast->op.sep == TAG_AND && status != 0) ||
(ast->op.sep == TAG_OR && status == 0))
return (status);
@@ -62,6 +71,13 @@ static int st_run_piped(
return (pid);
}
+/*
+** \brief Evaluate a pipeline
+** \param env Environment
+** \param ast Pipeline AST node
+** \return Status of the last command in the pipeline
+*/
+
int eval_pipeline(t_env env, t_ast *ast)
{
t_ftlst *curr;
diff --git a/src/eval/parenthesis.c b/src/eval/parenthesis.c
index 6f4f9e0..c7bc2d2 100644
--- a/src/eval/parenthesis.c
+++ b/src/eval/parenthesis.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/09/13 20:38:29 by charles #+# #+# */
-/* Updated: 2020/10/07 15:56:09 by cacharle ### ########.fr */
+/* Updated: 2020/10/10 12:44:59 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,16 @@ int wrapped_eval(t_fork_param_args *param)
return (eval(param->fds, param->env, param->ast));
}
+/*
+** \brief Evaluate a parenthesized expression
+** Extract parenthesis redirection and evaluate
+** the expression contained in the parenthesis in a fork
+** \param fds Input/output filedescriptor
+** \param env Environment
+** \param ast Parenthesis AST node
+** \return Expression status code
+*/
+
int eval_parenthesis(int fds[2], t_env env, t_ast *ast)
{
int status;