From 4373c0da3d197abc17df8d8af5832904237ff8e5 Mon Sep 17 00:00:00 2001 From: tomoron Date: Wed, 3 Apr 2024 22:07:09 +0200 Subject: [PATCH] =?UTF-8?q?whatthecommit.com=E2=80=99s=20server=20IP=20add?= =?UTF-8?q?ress=20could=20not=20be=20found.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- srcs/exec_bonus.c | 63 +++++++++++++++---------------------------- srcs/main.c | 4 +-- srcs/pipe.c | 2 +- srcs/signal_handler.c | 12 ++++++--- 4 files changed, 33 insertions(+), 48 deletions(-) diff --git a/srcs/exec_bonus.c b/srcs/exec_bonus.c index 26537cf..c35c4d4 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 17:46:14 by tomoron ### ########.fr */ +/* Updated: 2024/04/03 19:37:44 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,7 +39,7 @@ void exec_command_bonus(t_msh *msh, char *cmd_str) if (tmp) { print_syntax_error_bonus(tmp); - printf("error\n");//debug + printf("error\n"); // debug free_cmd(cmds); return ; } @@ -48,16 +48,17 @@ void exec_command_bonus(t_msh *msh, char *cmd_str) if ((cmds->cmd_type == AND && !g_return_code) || (cmds->cmd_type == OR && g_return_code) || !is_operand_type(cmds)) { - if(is_operand_type(cmds)) + if (is_operand_type(cmds)) cmds = cmds->next; msh->tokens = parse_command(cmds->value, msh->env); msh->cmds = cmds; get_redirections(msh, cmds); - print_msh_struct(msh); // debug + print_msh_struct(msh); // debug print_parsed_token(msh->tokens); // debug exec_commands(msh); } - while(cmds && (is_cmd_type(cmds) || cmds->cmd_type == PIPE)) + while (cmds && (is_cmd_type(cmds) || cmds->cmd_type == PIPE + || is_output_type(cmds) || is_input_type(cmds))) cmds = cmds->next; } } @@ -103,6 +104,20 @@ void exec_command(t_msh *msh, int i, int cmd_count) remove_command_from_msh(msh); } +int get_cmd_count(t_cmd *cmds) +{ + int nb; + + nb = 0; + while (cmds && !is_operand_type(cmds)) + { + if (is_cmd_type(cmds)) + nb++; + cmds = cmds->next; + } + return (nb); +} + void end_execution(t_msh *msh, int cmd_count) { int i; @@ -123,25 +138,11 @@ void end_execution(t_msh *msh, int cmd_count) set_echoctl(0); } -int get_cmd_count(t_cmd *cmds) -{ - int nb; - - nb = 0; - while(cmds && !is_operand_type(cmds)) - { - if(is_cmd_type(cmds)) - nb++; - cmds = cmds->next; - } - return(nb); -} void exec_commands(t_msh *msh) { int cmd_count; int i; - int status; if (!msh->tokens) return ; @@ -150,32 +151,12 @@ void exec_commands(t_msh *msh) msh->pids = ft_calloc(cmd_count, sizeof(int *)); if (!msh->pids || !msh->fds) ft_exit(msh, 1); - i = 0; while (i < cmd_count) { exec_command(msh, i, cmd_count); i++; } - i = 0; - while (i < cmd_count) - { - waitpid(msh->pids[i], &status, 0); - i++; - } - if (!g_return_code && WIFEXITED(status)) - g_return_code = WEXITSTATUS(status); - i = 0; - while (i < cmd_count) - { - free(msh->fds[i]); - msh->fds[i] = 0; - i++; - } - free(msh->fds); - msh->fds = 0; - free(msh->pids); - msh->pids = 0; - //signal(SIGINT, signal_handler_interactive); - signal(SIGQUIT, signal_handler_interactive); + end_execution(msh, cmd_count); } + diff --git a/srcs/main.c b/srcs/main.c index 01b604d..f6c3924 100755 --- a/srcs/main.c +++ b/srcs/main.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */ -/* Updated: 2024/04/03 15:46:12 by tomoron ### ########.fr */ +/* Updated: 2024/04/03 19:29:29 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -83,7 +83,7 @@ int init_minishell(t_msh **msh, int argc, char **argv, char **envp) (*msh)->env = get_env(envp); tcgetattr(1, &t_p); (*msh)->echoctl = t_p.c_lflag & ECHOCTL; - //signal(SIGINT, signal_handler_interactive); //enables ctrl-C +// signal(SIGINT, signal_handler_interactive); //enables ctrl-C signal(SIGQUIT, signal_handler_interactive); if (set_echoctl(0)) ft_exit(*msh, 1); diff --git a/srcs/pipe.c b/srcs/pipe.c index 2d877c9..04764b1 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 17:21:41 by tomoron ### ########.fr */ +/* Updated: 2024/04/03 19:07:32 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/srcs/signal_handler.c b/srcs/signal_handler.c index 0b2f39c..8e766b9 100755 --- a/srcs/signal_handler.c +++ b/srcs/signal_handler.c @@ -6,7 +6,7 @@ /* By: marde-vr +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */ -/* Updated: 2024/04/01 20:10:09 by marde-vr ### ########.fr */ +/* Updated: 2024/04/03 19:23:33 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,12 +57,16 @@ int set_echoctl(int value) { struct termios t_p; + ft_printf("echoctl value : %d\n",value); if (tcgetattr(1, &t_p)) { - ft_printf_fd(2, "minishell: an error occured while setting the local fl\ -ags"); + ft_printf_fd(2, "minishell: an error occured while getting the local fl\ +ags\n"); return (1); } + if (((t_p.c_lflag & ECHOCTL) != 0) == value) + return (0); + ft_printf("change\n"); if (value) t_p.c_lflag = t_p.c_lflag | ECHOCTL; else @@ -70,7 +74,7 @@ ags"); if (tcsetattr(1, TCSANOW, &t_p)) { ft_printf_fd(2, "minishell: an error occured while setting the local fl\ -ags"); +ags\n"); return (1); } return (0);