Fix minor issues
authorLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 17:47:53 +0000 (19:47 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sun, 21 Jul 2024 17:47:53 +0000 (19:47 +0200)
src/execution.c

index b730c6f7314a4366e1fede21e9629292e148fdad..118b0709fa1b7ba284c886cfed277b03f511a349 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <ljiriste@student.42prague.com>   +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   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)