From 2bfd801ba336d22f9dda0fadff6a51b412102424 Mon Sep 17 00:00:00 2001 From: tomoron Date: Sat, 6 Apr 2024 19:24:34 +0200 Subject: [PATCH] ckc --- srcs/commands.c | 30 +++++------------------------- srcs/exec_bonus.c | 4 +++- srcs/input_redirections.c | 4 ++-- srcs/output_redirections.c | 8 +++++--- srcs/pipe.c | 5 +++-- 5 files changed, 18 insertions(+), 33 deletions(-) diff --git a/srcs/commands.c b/srcs/commands.c index 26319f1..194bd62 100755 --- a/srcs/commands.c +++ b/srcs/commands.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:22:15 by marde-vr #+# #+# */ -/* Updated: 2024/04/03 15:45:49 by tomoron ### ########.fr */ +/* Updated: 2024/04/06 12:18:31 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,28 +60,8 @@ char **get_cmd_args(t_msh *msh) void remove_command_from_msh(t_msh *msh) { - t_token *cur_cmd; - t_token *cmd_tmp; - - cur_cmd = msh->tokens; - while (cur_cmd && cur_cmd->next) - { - if (/*cur_cmd->type == PIPE*/ 0) - { - cmd_tmp = cur_cmd; - cur_cmd = cur_cmd->next; - //msh->in_type = cmd_tmp->type; - free(cmd_tmp->value); - free(cmd_tmp); - msh->tokens = cur_cmd; - return ; - } - cmd_tmp = cur_cmd; - cur_cmd = cur_cmd->next; - //msh->in_type = cur_cmd->type; - free(cmd_tmp->value); - free(cmd_tmp); - msh->tokens = cur_cmd; - } - //msh->in_type = msh->tokens->type; + free_token(msh->tokens); + while(msh->cmds && !is_cmd_type(msh->cmds)) + msh->cmds = msh->cmds->next; + msh->tokens = parse_command(msh->cmds->value, msh->env); } diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index c35c4d4..1762b08 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/03 19:37:44 by tomoron ### ########.fr */ +/* Updated: 2024/04/04 13:30:31 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -70,6 +70,7 @@ int exec(t_msh *msh, char **cmd_args, int i, int cmd_count) if (i != cmd_count - 1) { + printf("pipe\n"); if (pipe(fds) == -1) { perror("minishell: pipe"); @@ -147,6 +148,7 @@ void exec_commands(t_msh *msh) if (!msh->tokens) return ; cmd_count = get_cmd_count(msh->cmds); + printf("cmd_count : %d\n", cmd_count); msh->fds = ft_calloc(cmd_count, sizeof(int **)); msh->pids = ft_calloc(cmd_count, sizeof(int *)); if (!msh->pids || !msh->fds) diff --git a/srcs/input_redirections.c b/srcs/input_redirections.c index b7d2f0a..f0318fb 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/03 12:32:30 by tomoron ### ########.fr */ +/* Updated: 2024/04/04 13:48:52 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -58,7 +58,7 @@ void get_in_type(t_msh *msh, t_cmd *tokens) cur_token = tokens; while (cur_token && (cur_token->cmd_type == CMD || cur_token->cmd_type == PAREN)) cur_token = cur_token->next; - if (cur_token && is_input_type(cur_token)) + if (cur_token && (is_input_type(cur_token) || cur_token->cmd_type == PIPE)) { msh->in_type = cur_token->cmd_type; open_input_file(msh, &cur_token); diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index 588f3f5..bd10d5b 100755 --- a/srcs/output_redirections.c +++ b/srcs/output_redirections.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 19:10:52 by marde-vr #+# #+# */ -/* Updated: 2024/04/03 15:09:52 by tomoron ### ########.fr */ +/* Updated: 2024/04/04 16:44:37 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,11 +56,11 @@ void get_out_type(t_msh *msh, t_cmd *cmds) msh->out_type = CMD; msh->out_fd = 0; cur_cmd = cmds; - while (cur_cmd && cur_cmd->next && !is_operand_type(cur_cmd)) + while (cur_cmd && cur_cmd->next && !is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) cur_cmd = cur_cmd->next; if (cur_cmd->cmd_type == CMD || cur_cmd->cmd_type == PAREN) msh->out_type = 0; - else if(cur_cmd && !is_operand_type(cur_cmd)) + else if(cur_cmd && !is_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) { msh->out_type = cur_cmd->cmd_type; filename = parse_command(cur_cmd->value, msh->env); @@ -69,4 +69,6 @@ void get_out_type(t_msh *msh, t_cmd *cmds) open_out_file(msh, &cur_cmd, filename->value); free_token(filename); } + else if(cur_cmd && cur_cmd->cmd_type == PIPE) + msh->out_type = PIPE; } diff --git a/srcs/pipe.c b/srcs/pipe.c index 04764b1..c42e444 100755 --- a/srcs/pipe.c +++ b/srcs/pipe.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:17:25 by marde-vr #+# #+# */ -/* Updated: 2024/04/03 19:07:32 by tomoron ### ########.fr */ +/* Updated: 2024/04/04 13:23:51 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,8 @@ void execute_command(t_msh *msh, char **cmd_args) { set_echoctl(msh->echoctl); env = env_to_char_tab(msh->env); - execve(msh->tokens->value, cmd_args, env); + if(env) + execve(msh->tokens->value, cmd_args, env); ft_free_str_arr(env); } }