diff --git a/includes/parser/ast.h b/includes/parser/ast.h index 04f8c51..92a62fa 100644 --- a/includes/parser/ast.h +++ b/includes/parser/ast.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* ast.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: nalebrun +#+ +:+ +#+ */ +/* By: lderidde +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/24 08:23:27 by nalebrun #+# #+# */ -/* Updated: 2025/01/24 08:23:27 by nalebrun ### ########.fr */ +/* Created: 2025/01/24 08:23:27 by lderidde #+# #+# */ +/* Updated: 2025/02/03 15:10:17 by lderidde ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,6 +47,7 @@ typedef struct s_ast_n int fds[2]; int _stdout; int _stdin; + int save_std; t_redir redir; char *infile; char *outfile; diff --git a/srcs/execution/exec.c b/srcs/execution/exec.c index 6a8d56d..046a98b 100644 --- a/srcs/execution/exec.c +++ b/srcs/execution/exec.c @@ -6,11 +6,13 @@ /* By: lderidde +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/01/27 11:22:33 by lderidde #+# #+# */ -/* Updated: 2025/02/03 14:05:14 by lderidde ### ########.fr */ +/* Updated: 2025/02/03 15:44:14 by lderidde ### ########.fr */ /* */ /* ************************************************************************** */ #include "../../includes/minishell.h" +#include +#include void handle_file(t_ast_n *node, int check) { @@ -76,23 +78,39 @@ int is_builtin(char *str) return (0); } +void reset_redir(t_ast_n *node) +{ + int fd; + + fd = open("/dev/pts/1", O_WRONLY); + (void)node; + if (dup2(fd, 1) == -1) + printf("error\n"); + close(fd); + // close(node->save_std); +} + int exec_builtin(t_ast_n *node) { + int ret; + handle_redir(node); if (ft_strncmp(node->cmd, "exit", 4) == 0) - return (builtin_exit(node->args, false, node)); + ret = builtin_exit(node->args, false, node); else if (ft_strncmp(node->cmd, "pwd", 3) == 0) - return (builtin_pwd(node->args)); + ret = builtin_pwd(node->args); else if (ft_strncmp(node->cmd, "echo", 4) == 0) - return (builtin_echo(node->args, node->msh->env)); + ret = builtin_echo(node->args, node->msh->env); else if (ft_strncmp(node->cmd, "env", 3) == 0) - return (builtin_env(node->args, node->msh->env)); + ret = builtin_env(node->args, node->msh->env); else if (ft_strncmp(node->cmd, "unset", 5) == 0) - return (builtin_unset(node->args, node)); + ret = builtin_unset(node->args, node); else if (ft_strncmp(node->cmd, "cd", 2) == 0) - return (builtin_cd(node->args, node)); + ret = builtin_cd(node->args, node); else - return (builtin_export(node->args, node)); + ret = builtin_export(node->args, node); + reset_redir(node); + return (ret); } int count_cmds(t_ast_n **pline) diff --git a/srcs/parsing/ast/ast.c b/srcs/parsing/ast/ast.c index f995d71..c294ca1 100644 --- a/srcs/parsing/ast/ast.c +++ b/srcs/parsing/ast/ast.c @@ -3,14 +3,15 @@ /* ::: :::::::: */ /* ast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: nalebrun +#+ +:+ +#+ */ +/* By: lderidde +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/01/24 08:22:16 by nalebrun #+# #+# */ -/* Updated: 2025/02/01 11:13:58 by nalebrun ### ########.fr */ +/* Created: 2025/01/24 08:22:16 by lderidde #+# #+# */ +/* Updated: 2025/02/03 15:44:56 by lderidde ### ########.fr */ /* */ /* ************************************************************************** */ #include "../../../includes/minishell.h" +#include // =================================================================== @@ -211,6 +212,8 @@ t_ast_n *create_ast_n(t_node *lst, t_ast_n *parent, t_msh *msh) node->pline = NULL; node->msh = msh; node->parent = parent; + node->_stdout = 1; + node->_stdin = 0; if (node->state == _AND || node->state == _OR) create_and_or(node, lst, token, msh); else if (node->state == _SUBSH)