fix: keep parsing after redirects
This commit is contained in:
parent
b3b6ed6d88
commit
97069cac62
@ -19,16 +19,18 @@ static int count_cmds(t_list *list)
|
|||||||
{
|
{
|
||||||
int cmds;
|
int cmds;
|
||||||
t_list *current;
|
t_list *current;
|
||||||
|
t_list *prev;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
|
|
||||||
cmds = 0;
|
cmds = 0;
|
||||||
current = list;
|
current = list;
|
||||||
|
prev = NULL;
|
||||||
while (current)
|
while (current)
|
||||||
{
|
{
|
||||||
token = ((t_token *)current->content);
|
token = ((t_token *)current->content);
|
||||||
if (token->type > 2)
|
if (token->type < 3 && (!prev || ((t_token *)prev->content)->type < 3))
|
||||||
break ;
|
|
||||||
cmds++;
|
cmds++;
|
||||||
|
prev = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
return (cmds);
|
return (cmds);
|
||||||
@ -84,17 +86,19 @@ char **parser_get_arguments(t_list *list, t_minishell *msh)
|
|||||||
t_list *current;
|
t_list *current;
|
||||||
t_list *prev;
|
t_list *prev;
|
||||||
char **args;
|
char **args;
|
||||||
int cmds;
|
int argc;
|
||||||
int i;
|
int i;
|
||||||
char *str;
|
char *str;
|
||||||
char *cat;
|
char *cat;
|
||||||
|
|
||||||
cmds = count_cmds(list);
|
argc = count_cmds(list);
|
||||||
args = malloc_safe(msh, (cmds + 1) * sizeof(char *));
|
args = malloc_safe(msh, (argc + 1) * sizeof(char *));
|
||||||
current = list;
|
current = list;
|
||||||
i = 0;
|
i = 0;
|
||||||
prev = NULL;
|
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);
|
str = parser_process_token(msh, args, prev, current);
|
||||||
if (i > 0 && prev && ft_strcmp(((t_token *)prev->content)->value, "") == 0)
|
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)
|
else if (str)
|
||||||
args[i++] = str;
|
args[i++] = str;
|
||||||
|
argc--;
|
||||||
|
}
|
||||||
prev = current;
|
prev = current;
|
||||||
current = current->next;
|
current = current->next;
|
||||||
cmds--;
|
|
||||||
}
|
}
|
||||||
args[i] = 0;
|
args[i] = 0;
|
||||||
return (args);
|
return (args);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user