From 9a038e9290a80905bf2c12fd05b1cdf2187d3b94 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Sun, 5 Mar 2017 15:19:18 +0100 Subject: [PATCH] && || seem to work now --- 42sh/includes/exec.h | 4 ++-- 42sh/src/exec/exec_and_if.c | 3 ++- 42sh/src/exec/exec_command.c | 2 +- 42sh/src/exec/exec_if.c | 2 +- 42sh/src/exec/exec_or_if.c | 5 +++-- 42sh/src/exec/set_process.c | 7 ++++++- 42sh/src/job-control/job_addprocess.c | 2 +- 42sh/src/main/main.c | 4 ++-- 8 files changed, 18 insertions(+), 11 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 25f430e4..f81bbeef 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:04:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:14:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,7 @@ # define EXEC_IS_BG(j) (j & EXEC_BG) # define EXEC_IS_FG(j) (!EXEC_IS_BG(j)) # define EXEC_IS_AND_IF(j) (j & EXEC_AND_IF) -# define EXEC_IS_OR_IF(j) (j & EXEC_JOB_OR_IF) +# define EXEC_IS_OR_IF(j) (j & EXEC_OR_IF) # define EXEC_AOL_MASK (EXEC_AND_IF | EXEC_OR_IF) # define EXEC_IS_IF_BRANCH(j) (j & EXEC_IF_BRANCH) diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index 874f8004..42ee38a7 100644 --- a/42sh/src/exec/exec_and_if.c +++ b/42sh/src/exec/exec_and_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:05:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:18:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,7 @@ int exec_and_if(t_btree **ast) exec = &data_singleton()->exec; push(&exec->op_stack, TK_AND_IF); ft_exec(&(*ast)->left); + exec->attrs &= ~EXEC_OR_IF; exec->attrs |= EXEC_AND_IF; ft_exec(&(*ast)->right); diff --git a/42sh/src/exec/exec_command.c b/42sh/src/exec/exec_command.c index f8907f9b..a0656c3a 100644 --- a/42sh/src/exec/exec_command.c +++ b/42sh/src/exec/exec_command.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:03:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:14:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_if.c b/42sh/src/exec/exec_if.c index 02f972e6..c1a59aef 100644 --- a/42sh/src/exec/exec_if.c +++ b/42sh/src/exec/exec_if.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 18:07:31 by ariard #+# #+# */ -/* Updated: 2017/03/04 17:37:11 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:12:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index ec6bc226..5cc45a5e 100644 --- a/42sh/src/exec/exec_or_if.c +++ b/42sh/src/exec/exec_or_if.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:07:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:18:49 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,8 @@ int exec_or_if(t_btree **ast) exec = &data_singleton()->exec; push(&exec->op_stack, TK_OR_IF); ft_exec(&(*ast)->left); - exec->attrs |= EXEC_OR_IF; + exec->attrs &= ~EXEC_AND_IF; + exec->attrs = EXEC_OR_IF; ft_exec(&(*ast)->right); /* data = data_singleton(); */ diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 8c4b27c4..878ce011 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:05:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:18:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,6 +23,11 @@ int set_process(t_process *p, t_btree *ast) process_reset(p); exec = &data_singleton()->exec; op = pop(&exec->op_stack); + if ((EXEC_IS_AND_IF(exec->attrs) + && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0) + || (EXEC_IS_OR_IF(exec->attrs) + && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) + return (1); if (!(p->av = token_to_argv(cmd->token, 1))) return (1); fds[PIPE_WRITE] = STDOUT; diff --git a/42sh/src/job-control/job_addprocess.c b/42sh/src/job-control/job_addprocess.c index a4ace432..8afe2cee 100644 --- a/42sh/src/job-control/job_addprocess.c +++ b/42sh/src/job-control/job_addprocess.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 13:54:51 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:05:21 by jhalford ### ########.fr */ +/* Updated: 2017/03/05 15:12:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 256f42f2..7ebb7a70 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/04 19:29:28 by ariard ### ########.fr */ +/* Updated: 2017/03/05 15:16:12 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ int handle_instruction(int fd) error_syntax(&token, &parser, &ast); } DG("Before execution:"); -// btree_print(STDBUG, ast, &ft_putast); + btree_print(STDBUG, ast, &ft_putast); if (ft_exec(&ast)) return (1); instruction_free(&token, &parser, &ast);