mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
simple_cmd: actually contain words
This commit is contained in:
parent
49d7a2b9ff
commit
a50b2f6d74
3 changed files with 29 additions and 7 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:30:07 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 12:36:08 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/21 12:51:07 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,15 +14,25 @@
|
|||
#include "libft.h"
|
||||
|
||||
/*
|
||||
** parse a wordlist and yield a simple command
|
||||
** parse a wordlist and yield a simple command.
|
||||
**
|
||||
** takes ownership of words
|
||||
*/
|
||||
t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words)
|
||||
{
|
||||
(void)words;
|
||||
return (ft_calloc(1, sizeof(t_simple_cmd)));
|
||||
t_simple_cmd *cmd;
|
||||
|
||||
cmd = ft_calloc(1, sizeof(t_simple_cmd));
|
||||
if (cmd == NULL)
|
||||
return (NULL);
|
||||
cmd->words = words;
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
void simple_cmd_destroy(t_simple_cmd *cmd)
|
||||
{
|
||||
if (cmd == NULL)
|
||||
return ;
|
||||
wordlist_destroy(cmd->words);
|
||||
free(cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:24:57 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 12:33:00 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/21 12:48:53 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
typedef struct s_simple_cmd
|
||||
{
|
||||
t_wordlist *words;
|
||||
} t_simple_cmd;
|
||||
|
||||
t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/21 12:20:20 by khais #+# #+# */
|
||||
/* Updated: 2025/02/21 12:33:32 by khais ### ########.fr */
|
||||
/* Updated: 2025/02/21 12:49:55 by khais ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -14,12 +14,12 @@
|
|||
#include "../src/parser/simple_cmd/simple_cmd.h"
|
||||
#include "../src/parser/wordsplit/wordsplit.h"
|
||||
#include "../src/parser/wordlist/wordlist.h"
|
||||
#include "testutil.h"
|
||||
|
||||
static t_simple_cmd *parse_simple_cmd(char *input)
|
||||
{
|
||||
t_wordlist *words = minishell_wordsplit(input);
|
||||
t_simple_cmd *cmd = simple_cmd_from_wordlist(words);
|
||||
wordlist_destroy(words);
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
|
|
@ -30,8 +30,19 @@ static void test_parse_empty_command(void)
|
|||
simple_cmd_destroy(cmd);
|
||||
}
|
||||
|
||||
static void test_parse_nonempty_command(void)
|
||||
{
|
||||
t_simple_cmd *cmd = parse_simple_cmd("echo Hello World!");
|
||||
assert(cmd != NULL);
|
||||
assert_strequal("echo", wordlist_get(cmd->words, 0)->word);
|
||||
assert_strequal("Hello", wordlist_get(cmd->words, 1)->word);
|
||||
assert_strequal("World!", wordlist_get(cmd->words, 2)->word);
|
||||
simple_cmd_destroy(cmd);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_parse_empty_command();
|
||||
test_parse_nonempty_command();
|
||||
return (0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue