/* 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 */
/* */
/* ************************************************************************** */
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
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
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)