fix: remove multiple redirection

This commit is contained in:
Camille Chauvet 2023-03-20 13:18:20 +01:00
parent 96696243d0
commit d56aac4b25
5 changed files with 17 additions and 11 deletions

0
bozo Normal file
View File

3
bozoman Normal file
View File

@ -0,0 +1,3 @@
hi >> ./bozoman
hi >> ./bozoman
hi

2
main.c
View File

@ -44,7 +44,7 @@ static int ft_minishell(t_data *data, char *line)
if (ft_syntax_verif(data, line))
return (0);
line_clean = ft_formater(data, line);
if (line_clean == NULL)
if (line_clean == NULL || line_clean[0] == '\0')
return (0);
if (ft_cmds_parser(data, line_clean))
{

View File

@ -98,17 +98,16 @@ int ft_cmds_parser(t_data *data, const char *line)
i = 0;
while (tab[i] != NULL)
{
if (ft_cmd_parser(data, tab[i]))
{
ft_freer_tab_ultimate(1, tab);
return (1);
}
ft_cmd_parser(data, tab[i]);
i++;
}
if (*data->cmds != NULL)
{
if (((t_cmd *) (*data->cmds)->content)->fd_in[0] == -1)
((t_cmd *) (*data->cmds)->content)->fd_in[0] = 0;
if (((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] == -1)
(((t_cmd *) (ft_lstlast(*data->cmds))->content)->fd_out[0] = 1);
}
ft_freer_tab_ultimate(1, tab);
return (0);
}

View File

@ -42,12 +42,16 @@ void ft_remove_redirection(char *cmd_str)
continue ;
while (cmd_str[i] == cmd_str[start])
i++;
while (cmd_str[i] == ' ')
i++;
while (cmd_str[i] != '\0' && (cmd_str[i] != ' ' || ft_is_in_quote(cmd_str, i)))
i++;
stop = i - start;
if (start != -1)
{
ft_strshift(cmd_str + start, -1 * stop);
i = start;
}
}
}