whatthecommit.com’s server IP address could not be found.
This commit is contained in:
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/28 13:50:14 by tomoron #+# #+# */
|
/* 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)
|
if (tmp)
|
||||||
{
|
{
|
||||||
print_syntax_error_bonus(tmp);
|
print_syntax_error_bonus(tmp);
|
||||||
printf("error\n");//debug
|
printf("error\n"); // debug
|
||||||
free_cmd(cmds);
|
free_cmd(cmds);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
|
|||||||
if ((cmds->cmd_type == AND && !g_return_code) || (cmds->cmd_type == OR
|
if ((cmds->cmd_type == AND && !g_return_code) || (cmds->cmd_type == OR
|
||||||
&& g_return_code) || !is_operand_type(cmds))
|
&& g_return_code) || !is_operand_type(cmds))
|
||||||
{
|
{
|
||||||
if(is_operand_type(cmds))
|
if (is_operand_type(cmds))
|
||||||
cmds = cmds->next;
|
cmds = cmds->next;
|
||||||
msh->tokens = parse_command(cmds->value, msh->env);
|
msh->tokens = parse_command(cmds->value, msh->env);
|
||||||
msh->cmds = cmds;
|
msh->cmds = cmds;
|
||||||
@ -57,7 +57,8 @@ void exec_command_bonus(t_msh *msh, char *cmd_str)
|
|||||||
print_parsed_token(msh->tokens); // debug
|
print_parsed_token(msh->tokens); // debug
|
||||||
exec_commands(msh);
|
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;
|
cmds = cmds->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,6 +104,20 @@ void exec_command(t_msh *msh, int i, int cmd_count)
|
|||||||
remove_command_from_msh(msh);
|
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)
|
void end_execution(t_msh *msh, int cmd_count)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -123,25 +138,11 @@ void end_execution(t_msh *msh, int cmd_count)
|
|||||||
set_echoctl(0);
|
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)
|
void exec_commands(t_msh *msh)
|
||||||
{
|
{
|
||||||
int cmd_count;
|
int cmd_count;
|
||||||
int i;
|
int i;
|
||||||
int status;
|
|
||||||
|
|
||||||
if (!msh->tokens)
|
if (!msh->tokens)
|
||||||
return ;
|
return ;
|
||||||
@ -150,32 +151,12 @@ void exec_commands(t_msh *msh)
|
|||||||
msh->pids = ft_calloc(cmd_count, sizeof(int *));
|
msh->pids = ft_calloc(cmd_count, sizeof(int *));
|
||||||
if (!msh->pids || !msh->fds)
|
if (!msh->pids || !msh->fds)
|
||||||
ft_exit(msh, 1);
|
ft_exit(msh, 1);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < cmd_count)
|
while (i < cmd_count)
|
||||||
{
|
{
|
||||||
exec_command(msh, i, cmd_count);
|
exec_command(msh, i, cmd_count);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
i = 0;
|
end_execution(msh, cmd_count);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/02/02 21:59:20 by tomoron #+# #+# */
|
/* 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);
|
(*msh)->env = get_env(envp);
|
||||||
tcgetattr(1, &t_p);
|
tcgetattr(1, &t_p);
|
||||||
(*msh)->echoctl = t_p.c_lflag & ECHOCTL;
|
(*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);
|
signal(SIGQUIT, signal_handler_interactive);
|
||||||
if (set_echoctl(0))
|
if (set_echoctl(0))
|
||||||
ft_exit(*msh, 1);
|
ft_exit(*msh, 1);
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/05 18:17:25 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 */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/03/22 14:31:13 by tomoron #+# #+# */
|
/* 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;
|
struct termios t_p;
|
||||||
|
|
||||||
|
ft_printf("echoctl value : %d\n",value);
|
||||||
if (tcgetattr(1, &t_p))
|
if (tcgetattr(1, &t_p))
|
||||||
{
|
{
|
||||||
ft_printf_fd(2, "minishell: an error occured while setting the local fl\
|
ft_printf_fd(2, "minishell: an error occured while getting the local fl\
|
||||||
ags");
|
ags\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
if (((t_p.c_lflag & ECHOCTL) != 0) == value)
|
||||||
|
return (0);
|
||||||
|
ft_printf("change\n");
|
||||||
if (value)
|
if (value)
|
||||||
t_p.c_lflag = t_p.c_lflag | ECHOCTL;
|
t_p.c_lflag = t_p.c_lflag | ECHOCTL;
|
||||||
else
|
else
|
||||||
@ -70,7 +74,7 @@ ags");
|
|||||||
if (tcsetattr(1, TCSANOW, &t_p))
|
if (tcsetattr(1, TCSANOW, &t_p))
|
||||||
{
|
{
|
||||||
ft_printf_fd(2, "minishell: an error occured while setting the local fl\
|
ft_printf_fd(2, "minishell: an error occured while setting the local fl\
|
||||||
ags");
|
ags\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
|
Reference in New Issue
Block a user