fix: keep parsing after redirects

This commit is contained in:
Quinten 2025-03-05 11:46:46 +01:00
parent b3b6ed6d88
commit 97069cac62

View File

@ -19,16 +19,18 @@ static int count_cmds(t_list *list)
{
int cmds;
t_list *current;
t_list *prev;
t_token *token;
cmds = 0;
current = list;
prev = NULL;
while (current)
{
token = ((t_token *)current->content);
if (token->type > 2)
break ;
if (token->type < 3 && (!prev || ((t_token *)prev->content)->type < 3))
cmds++;
prev = current;
current = current->next;
}
return (cmds);
@ -84,17 +86,19 @@ char **parser_get_arguments(t_list *list, t_minishell *msh)
t_list *current;
t_list *prev;
char **args;
int cmds;
int argc;
int i;
char *str;
char *cat;
cmds = count_cmds(list);
args = malloc_safe(msh, (cmds + 1) * sizeof(char *));
argc = count_cmds(list);
args = malloc_safe(msh, (argc + 1) * sizeof(char *));
current = list;
i = 0;
prev = NULL;
while (cmds > 0 && current)
while (argc > 0 && current)
{
if (((t_token *)current->content)->type < 3 && (!prev || ((t_token *)prev->content)->type < 3))
{
str = parser_process_token(msh, args, prev, current);
if (i > 0 && prev && ft_strcmp(((t_token *)prev->content)->value, "") == 0)
@ -106,9 +110,10 @@ char **parser_get_arguments(t_list *list, t_minishell *msh)
}
else if (str)
args[i++] = str;
argc--;
}
prev = current;
current = current->next;
cmds--;
}
args[i] = 0;
return (args);