command list parse: handle triple pipeline separated with ||

This commit is contained in:
Khaïs COLIN 2025-02-25 13:46:11 +01:00 committed by Khaïs COLIN
parent e6dd1d6a56
commit 1c00020c86
2 changed files with 42 additions and 11 deletions

View file

@ -6,12 +6,13 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
/* Updated: 2025/02/25 13:33:53 by khais ### ########.fr */
/* Updated: 2025/02/25 14:57:20 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "command_list.h"
#include "libft.h"
#include "unistd.h"
#include <stdlib.h>
/*
@ -84,23 +85,33 @@ t_command_list *command_list_from_wordlist(t_wordlist *words)
t_command_list *output;
t_wordlist *current_wordlist;
t_worddesc *current_word;
int idx;
output = allocate_command_list(words);
if (output == NULL)
return (NULL);
current_wordlist = NULL;
current_word = wordlist_pop(&words);
while (current_word != NULL && match_op(current_word->word) == OP_INVALID)
idx = 0;
while (current_word != NULL)
{
current_wordlist = wordlist_push(current_wordlist, current_word);
current_word = wordlist_pop(&words);
if (match_op(current_word->word) == OP_INVALID)
{
current_wordlist = wordlist_push(current_wordlist, current_word);
current_word = wordlist_pop(&words);
}
else
{
output->pipelines[idx] = pipeline_from_wordlist(current_wordlist);
output->operator = match_op(current_word->word);
current_wordlist = NULL;
worddesc_destroy(current_word);
current_word = wordlist_pop(&words);
idx++;
}
}
if (current_word != NULL)
output->operator = match_op(current_word->word);
worddesc_destroy(current_word);
output->pipelines[0] = pipeline_from_wordlist(current_wordlist);
if (words != NULL)
output->pipelines[1] = pipeline_from_wordlist(words);
if (current_wordlist != NULL)
output->pipelines[idx] = pipeline_from_wordlist(current_wordlist);
return (output);
}