From 356b1efa516f760a401b70f2f588e172e1c613eb Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Sun, 21 Jul 2024 19:47:53 +0200 Subject: [PATCH] Fix minor issues --- src/execution.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/execution.c b/src/execution.c index b730c6f..118b070 100644 --- a/src/execution.c +++ b/src/execution.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/21 08:57:54 by ljiriste #+# #+# */ -/* Updated: 2024/07/21 19:45:29 by ljiriste ### ########.fr */ +/* Updated: 2024/07/21 19:47:22 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -475,13 +475,15 @@ int subshell(t_parse_tree_node *program, const t_execution_env *env) if (copy_env(&env_copy, env)) return (1); res = ex_program(program, &env_copy); - env->ret_val = env_copy->ret_val; + env->ret_val = env_copy.ret_val; free_env(&env_copy); return (res); } int ex_command(t_parse_tree_node *command, t_execution_env *env) { + t_parse_tree_node *comp_command; + if (is_token_type(ft_vec_caccess(&command->children, 0), "simple_command")) return (ex_simple_command(ft_vec_access(&command->children, 0), env)); else @@ -493,6 +495,8 @@ int ex_command(t_parse_tree_node *command, t_execution_env *env) int ex_pipeline(t_parse_tree_node *pipeline, t_execution_env *env) { + int pipe_fds[2]; + if (pipeline->children.size == 1) return (ex_command(ft_vec_access(&pipeline->children, 0), env)); else @@ -514,19 +518,20 @@ int ex_pipeline(t_parse_tree_node *pipeline, t_execution_env *env) int ex_program(t_parse_tree_node *program, t_execution_env *env) { if (program->children.size == 1) - ex_pipeline(ft_vec_access(&program->children, 0), env); - else if (is_token_type(ft_vec_caccess(&program->children, 1), "AND_IF")) + return (ex_pipeline(ft_vec_access(&program->children, 0), env)); + if (ex_program(ft_vec_access(&program->children, 0), env)) + return (1); + if (is_token_type(ft_vec_caccess(&program->children, 1), "AND_IF")) { - ex_program(ft_vec_access(&program->children, 0), env); if (env->ret_val == 0) - ex_pipeline(ft_vec_access(&program->children, 2), env); + return (ex_pipeline(ft_vec_access(&program->children, 2), env)); } else { - ex_program(ft_vec_access(&program->children, 0), env); if (env->ret_val != 0) - ex_pipeline(ft_vec_access(&program->children, 2), env); + return (ex_pipeline(ft_vec_access(&program->children, 2), env)); } + return (0); } int execute(t_tree *parse_tree, t_vars *vars) -- 2.30.2