This commit is contained in:
2024-04-06 19:24:34 +02:00
parent 2a4c52f370
commit 2bfd801ba3
5 changed files with 18 additions and 33 deletions

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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)

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}

View File

@ -6,7 +6,7 @@
/* By: marde-vr <marde-vr@42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}
}