diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 112481a..32e9ad4 100755 --- a/srcs/exec_bonus.c +++ b/srcs/exec_bonus.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */ -/* Updated: 2024/04/19 10:44:36 by tomoron ### ########.fr */ +/* Updated: 2024/04/19 13:46:21 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,14 +18,12 @@ void get_redirections(t_msh *msh, t_cmd *cmds) msh->out_type = 0; if (first_is_in_type(cmds)) { - get_in_type(msh, cmds); - if (!g_return_code) + if (!get_in_type(msh, cmds)) get_out_type(msh, cmds); } else { - get_out_type(msh, cmds); - if (!g_return_code) + if (!get_out_type(msh, cmds)) get_in_type(msh, cmds); } } diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index 9a58d32..b0144da 100755 --- a/srcs/input_redirections.c +++ b/srcs/input_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:15:27 by marde-vr #+# #+# */ -/* Updated: 2024/04/19 09:43:39 by tomoron ### ########.fr */ +/* Updated: 2024/04/19 13:46:32 by marde-vr ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ void redirect_input(t_msh *msh, int i) } } -void open_input_file(t_msh *msh, t_cmd **cur_token) +int open_input_file(t_msh *msh, t_cmd **cur_token) { t_token *filename; @@ -52,12 +52,13 @@ void open_input_file(t_msh *msh, t_cmd **cur_token) { fprintf(stderr, "minishell: %s: ", (*cur_token)->next->value); perror(""); - g_return_code = 1; + return (1); } } + return (0); } -void get_in_type(t_msh *msh, t_cmd *tokens) +int get_in_type(t_msh *msh, t_cmd *tokens) { t_cmd *cur_token; @@ -65,7 +66,7 @@ void get_in_type(t_msh *msh, t_cmd *tokens) if (cur_token && cur_token->cmd_type == PIPE) { msh->in_type = PIPE; - return ; + return (0); } while (cur_token && (cur_token->cmd_type == CMD || cur_token->cmd_type == PAREN)) @@ -73,10 +74,12 @@ void get_in_type(t_msh *msh, t_cmd *tokens) if (cur_token && is_input_type(cur_token)) { msh->in_type = cur_token->cmd_type; - open_input_file(msh, &cur_token); + if (open_input_file(msh, &cur_token)) + return (1); } if (cur_token && cur_token->next && !is_operand_type(cur_token->next)) - get_in_type(msh, cur_token->next); + return (get_in_type(msh, cur_token->next)); + return (0); } int first_is_in_type(t_cmd *cmd) diff --git a/srcs/minishell.h b/srcs/minishell.h index f48585a..41515d3 100755 --- a/srcs/minishell.h +++ b/srcs/minishell.h @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/04 17:31:38 by tomoron #+# #+# */ -/* Updated: 2024/04/19 13:19:48 by tomoron ### ########.fr */ +/* Updated: 2024/04/19 13:51:04 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,8 +92,11 @@ void child(t_msh *msh, char **cmd_args, int i); t_token *parse_tokens(char *command, t_env *env); void parent(t_msh *msh, int i, int cmd_count); char *ft_get_env(t_env *env, char *var_name); +int is_fd_open(int fd); +int get_out_type(t_msh *msh, t_cmd *cmds); +void exec_commands(t_msh *msh); void handle_here_doc(t_msh *msh, char *eof); -void get_in_type(t_msh *msh, t_cmd *tokens); +int get_in_type(t_msh *msh, t_cmd *tokens); void signal_handler_interactive(int signum); void get_out_type(t_msh *msh, t_cmd *cmds); int get_token_len(char *cmd, t_env *env); diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index 44049e2..88e1cbf 100755 --- a/srcs/output_redirections.c +++ b/srcs/output_redirections.c @@ -6,7 +6,11 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */ +<<<<<<< HEAD /* Updated: 2024/04/19 09:45:21 by tomoron ### ########.fr */ +======= +/* Updated: 2024/04/19 13:33:50 by marde-vr ### ########.fr */ +>>>>>>> 7ae7a09 (fixed priorities and return codes) /* */ /* ************************************************************************** */ @@ -34,7 +38,7 @@ void redirect_output(t_msh *msh, int i) } } -void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename) +int open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename) { if (msh->out_type == RED_O) msh->out_fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644); @@ -42,10 +46,9 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename) msh->out_fd = open(filename, O_CREAT | O_RDWR | O_APPEND, 0644); if (msh->out_fd == -1) { - g_return_code = 1; ft_putstr_fd("minishell: ", 2); perror(filename); - return ; + return (1); } if ((*cur_cmd)->cmd_type != PIPE) { @@ -54,6 +57,7 @@ void open_out_file(t_msh *msh, t_cmd **cur_cmd, char *filename) if ((*cur_cmd)->next && is_output_type((*cur_cmd)->next)) get_out_type(msh, *cur_cmd); } + return (0); } void get_out_type(t_msh *msh, t_cmd *cmds)