mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
cmdlist_from_wordlist: make a copy of a wordlist
This commit is contained in:
parent
a79194de1a
commit
3778d0a7ee
4 changed files with 13 additions and 5 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
|
/* 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.
|
** 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_cmdlist_builder builder;
|
||||||
|
t_wordlist *words;
|
||||||
|
|
||||||
|
words = wordlist_copy(wordlist);
|
||||||
|
if (words == NULL)
|
||||||
|
return (NULL);
|
||||||
if (setup_cmdlist_builder(&builder, &words) == NULL)
|
if (setup_cmdlist_builder(&builder, &words) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
while (builder.error == false && builder.current_word != NULL)
|
while (builder.error == false && builder.current_word != NULL)
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/24 17:45:01 by khais #+# #+# */
|
/* 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_operator *operators;
|
||||||
} t_cmdlist;
|
} 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);
|
void cmdlist_destroy(t_cmdlist *cmd);
|
||||||
|
|
||||||
#endif // COMMAND_LIST_H
|
#endif // COMMAND_LIST_H
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ int main(void)
|
||||||
{
|
{
|
||||||
t_wordlist *words = minishell_wordsplit("|");
|
t_wordlist *words = minishell_wordsplit("|");
|
||||||
t_cmdlist *cmd = cmdlist_from_wordlist(words);
|
t_cmdlist *cmd = cmdlist_from_wordlist(words);
|
||||||
|
wordlist_destroy(words);
|
||||||
assert(cmd == NULL);
|
assert(cmd == NULL);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/02/24 17:40:48 by khais #+# #+# */
|
/* 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);
|
ft_dprintf(STDERR_FILENO, "Now checking command list with input [%s]\n", input);
|
||||||
t_wordlist *words = minishell_wordsplit(input);
|
t_wordlist *words = minishell_wordsplit(input);
|
||||||
t_cmdlist *cmd = cmdlist_from_wordlist(words);
|
t_cmdlist *cmd = cmdlist_from_wordlist(words);
|
||||||
|
wordlist_destroy(words);
|
||||||
return (cmd);
|
return (cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue