From 3a7bbac5cb76a9b571964de65d75175ed4304c92 Mon Sep 17 00:00:00 2001 From: tomoron Date: Sun, 7 Apr 2024 18:04:13 +0200 Subject: [PATCH] chepa --- srcs/builtins.c | 2 +- srcs/debug.c | 48 +++++++++++++++++++++++--------------- srcs/exec_bonus.c | 4 +++- srcs/output_redirections.c | 4 ++-- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/srcs/builtins.c b/srcs/builtins.c index 197bc7f..aff406b 100755 --- a/srcs/builtins.c +++ b/srcs/builtins.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 18:20:21 by marde-vr #+# #+# */ -/* Updated: 2024/04/03 15:46:27 by tomoron ### ########.fr */ +/* Updated: 2024/04/07 17:14:57 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/debug.c b/srcs/debug.c index 7facc4c..6005460 100755 --- a/srcs/debug.c +++ b/srcs/debug.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/18 15:46:50 by tomoron #+# #+# */ -/* Updated: 2024/04/02 17:22:43 by tomoron ### ########.fr */ +/* Updated: 2024/04/07 17:27:45 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,28 +22,33 @@ void print_parsed_token(t_token *token) printf("\n"); } +void print_cmd_type(t_cmd_type type, char *value) +{ + if(type == CMD) + printf("[CMD : %s] ", value); + if(type == PAREN) + printf("[PAREN : %s] ", value); + if(type == AND) + printf("[AND] "); + if(type == OR) + printf("[OR] "); + if(type == PIPE) + printf("[PIPE] "); + if(type == RED_O_APP) + printf("[RED_O_APP : %s] ", value); + if(type == RED_O) + printf("[RED_O : %s] ", value); + if(type == RED_I) + printf("[RED_I : %s] ", value); + if(type == HERE_DOC) + printf("[HERE_DOC : %s] ", value); +} + void print_parsed_cmd(t_cmd *cmd) { while(cmd) { - if(cmd->cmd_type == CMD) - printf("[CMD : %s] ", cmd->value); - if(cmd->cmd_type == PAREN) - printf("[PAREN : %s] ", cmd->value); - if(cmd->cmd_type == AND) - printf("[AND] "); - if(cmd->cmd_type == OR) - printf("[OR] "); - if(cmd->cmd_type == PIPE) - printf("[PIPE] "); - if(cmd->cmd_type == RED_O_APP) - printf("[RED_O_APP : %s] ", cmd->value); - if(cmd->cmd_type == RED_O) - printf("[RED_O : %s] ", cmd->value); - if(cmd->cmd_type == RED_I) - printf("[RED_I : %s] ", cmd->value); - if(cmd->cmd_type == HERE_DOC) - printf("[HERE_DOC : %s] ", cmd->value); + print_cmd_type(cmd->cmd_type, cmd->value); cmd = cmd->next; } printf("\n"); @@ -53,4 +58,9 @@ void print_msh_struct(t_msh *msh) { printf("in_fd : %d\n", msh->in_fd); printf("out_fd : %d\n", msh->out_fd); + printf("in_type: "); + print_cmd_type(msh->in_type, 0); + printf("\nout_type: "); + print_cmd_type(msh->out_type, 0); + printf("\n"); } diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 1762b08..6701c75 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/04 13:30:31 by tomoron ### ########.fr */ +/* Updated: 2024/04/07 17:47:44 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,6 +56,8 @@ void exec_command_bonus(t_msh *msh, char *cmd_str) print_msh_struct(msh); // debug print_parsed_token(msh->tokens); // debug exec_commands(msh); + msh->in_fd = 0; + msh->out_fd = 0; } while (cmds && (is_cmd_type(cmds) || cmds->cmd_type == PIPE || is_output_type(cmds) || is_input_type(cmds))) diff --git a/srcs/output_redirections.c b/srcs/output_redirections.c index bd10d5b..176bd3f 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/04 16:44:37 by tomoron ### ########.fr */ +/* Updated: 2024/04/07 17:34:58 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,7 +60,7 @@ void get_out_type(t_msh *msh, t_cmd *cmds) 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_output_type(cur_cmd) && !is_operand_type(cur_cmd) && cur_cmd->cmd_type != PIPE) + 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);