From 853307c91317a0cf4799d0b0b54c2a78a6ef5026 Mon Sep 17 00:00:00 2001 From: Lukas Jiriste Date: Sun, 21 Jul 2024 12:58:56 +0200 Subject: [PATCH] Refactor the subshell execution --- src/execution.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/execution.c b/src/execution.c index eb48768..05c6e31 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 09:10:19 by ljiriste ### ########.fr */ +/* Updated: 2024/07/21 12:56:41 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,19 @@ int ex_simple_command(t_parse_tree_node *simple_command, t_execution_info *info) return (0); } +int subshell(t_parse_tree_node *program, const t_execution_info *info) +{ + int res; + t_execution_info info_copy; + + if (copy_info(&info_copy, info)) + return (1); + res = ex_program(program, &info_copy); + info->ret_val = info_copy->ret_val; + free_info(info_copy); + return (res); +} + int ex_command(t_parse_tree_node *command, t_execution_info *info) { if (is_token_type(ft_vec_caccess(&command->children, 0), "simple_command")) @@ -45,12 +58,7 @@ int ex_command(t_parse_tree_node *command, t_execution_info *info) else { comp_command = ft_vec_access(&command->children, 0); - info_copy = copy_info(info); - if (!info_copy) - return (1); - res = ex_program(ft_vec_access(&comp_command->children, 1), info_copy); - free_info(info_copy); - return (res); + return (subshell(ft_vec_access(&comp_command->children, 1), info)); } } -- 2.30.2