cmdlist_from_wordlist: make a copy of a wordlist

This commit is contained in:
Khaïs COLIN 2025-03-04 13:31:22 +01:00 committed by Khaïs COLIN
parent a79194de1a
commit 3778d0a7ee
4 changed files with 13 additions and 5 deletions

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
/* Updated: 2025/03/04 13:48:37 by khais ### ########.fr */
/* Updated: 2025/03/04 13:48:56 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -86,11 +86,17 @@ static void cmdlist_builder_delimit(
/*
** Create a new command list from the given wordlist.
**
** Makes a copy of the given wordlist
*/
t_cmdlist *cmdlist_from_wordlist(t_wordlist *words)
t_cmdlist *cmdlist_from_wordlist(const t_wordlist *wordlist)
{
t_cmdlist_builder builder;
t_wordlist *words;
words = wordlist_copy(wordlist);
if (words == NULL)
return (NULL);
if (setup_cmdlist_builder(&builder, &words) == NULL)
return (NULL);
while (builder.error == false && builder.current_word != NULL)

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:45:01 by khais #+# #+# */
/* Updated: 2025/02/26 13:50:46 by khais ### ########.fr */
/* Updated: 2025/03/04 13:25:44 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -83,7 +83,7 @@ typedef struct s_cmdlist
t_operator *operators;
} t_cmdlist;
t_cmdlist *cmdlist_from_wordlist(t_wordlist *words);
t_cmdlist *cmdlist_from_wordlist(const t_wordlist *wordlist);
void cmdlist_destroy(t_cmdlist *cmd);
#endif // COMMAND_LIST_H

View file

@ -19,6 +19,7 @@ int main(void)
{
t_wordlist *words = minishell_wordsplit("|");
t_cmdlist *cmd = cmdlist_from_wordlist(words);
wordlist_destroy(words);
assert(cmd == NULL);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:40:48 by khais #+# #+# */
/* Updated: 2025/02/26 17:29:15 by khais ### ########.fr */
/* Updated: 2025/03/04 13:43:39 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -23,6 +23,7 @@ static t_cmdlist *parse_command_list(char *input)
ft_dprintf(STDERR_FILENO, "Now checking command list with input [%s]\n", input);
t_wordlist *words = minishell_wordsplit(input);
t_cmdlist *cmd = cmdlist_from_wordlist(words);
wordlist_destroy(words);
return (cmd);
}