From 49d7a2b9ffecd6ca2b549f222ac4bb4873fd120f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Fri, 21 Feb 2025 12:35:51 +0100 Subject: [PATCH] simple_cmd: initial setup of create/destroy functions --- Makefile | 1 + src/parser/simple_cmd/simple_cmd.c | 28 ++++++++++++++++++++++ src/parser/simple_cmd/simple_cmd.h | 25 ++++++++++++++++++++ src/parser/wordsplit/wordsplit.c | 4 ++-- tests/Makefile | 4 +++- tests/parse_simple_cmds.c | 37 ++++++++++++++++++++++++++++++ 6 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 src/parser/simple_cmd/simple_cmd.c create mode 100644 src/parser/simple_cmd/simple_cmd.h create mode 100644 tests/parse_simple_cmds.c diff --git a/Makefile b/Makefile index b0ebf8b..508f7dd 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ srcs = \ src/parser/matchers/operator_combo.c \ src/parser/matchers/operator_start.c \ src/parser/matchers/quote.c \ + src/parser/simple_cmd/simple_cmd.c \ src/parser/worddesc/worddesc.c \ src/parser/wordlist/wordlist.c \ src/parser/wordsplit/rule_utils.c \ diff --git a/src/parser/simple_cmd/simple_cmd.c b/src/parser/simple_cmd/simple_cmd.c new file mode 100644 index 0000000..daf9a7b --- /dev/null +++ b/src/parser/simple_cmd/simple_cmd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* simple_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/21 12:30:07 by khais #+# #+# */ +/* Updated: 2025/02/21 12:36:08 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "simple_cmd.h" +#include "libft.h" + +/* +** parse a wordlist and yield a simple command +*/ +t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words) +{ + (void)words; + return (ft_calloc(1, sizeof(t_simple_cmd))); +} + +void simple_cmd_destroy(t_simple_cmd *cmd) +{ + free(cmd); +} diff --git a/src/parser/simple_cmd/simple_cmd.h b/src/parser/simple_cmd/simple_cmd.h new file mode 100644 index 0000000..469a74d --- /dev/null +++ b/src/parser/simple_cmd/simple_cmd.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* simple_cmd.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/21 12:24:57 by khais #+# #+# */ +/* Updated: 2025/02/21 12:33:00 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SIMPLE_CMD_H +# define SIMPLE_CMD_H + +# include "../wordlist/wordlist.h" + +typedef struct s_simple_cmd +{ +} t_simple_cmd; + +t_simple_cmd *simple_cmd_from_wordlist(t_wordlist *words); +void simple_cmd_destroy(t_simple_cmd *cmd); + +#endif diff --git a/src/parser/wordsplit/wordsplit.c b/src/parser/wordsplit/wordsplit.c index 65c523d..36d5a19 100644 --- a/src/parser/wordsplit/wordsplit.c +++ b/src/parser/wordsplit/wordsplit.c @@ -5,8 +5,8 @@ /* +:+ +:+ +:+ */ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2025/02/21 12:40:26 by khais #+# #+# */ -/* Updated: 2025/02/21 12:40:32 by khais ### ########.fr */ +/* Created: 2025/02/21 12:29:36 by khais #+# #+# */ +/* Updated: 2025/02/21 12:42:46 by khais ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/tests/Makefile b/tests/Makefile index a3a992e..e317f03 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,8 +1,9 @@ # make gets confused if a file with the same name exists in the sources, so some # file are prefixed with test_ rawtests = \ - test_env_manip \ metacharacters \ + parse_simple_cmds \ + test_env_manip \ word_splitting \ ifeq ($(CFLAGS),) @@ -42,6 +43,7 @@ run_test_%: test_% @echo "====== Now running test: $* ======" @echo ./test_$* + @echo "====== End of test: $* ======" fclean: rm -f $(tests) diff --git a/tests/parse_simple_cmds.c b/tests/parse_simple_cmds.c new file mode 100644 index 0000000..5c65ae0 --- /dev/null +++ b/tests/parse_simple_cmds.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_simple_cmds.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: khais +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/02/21 12:20:20 by khais #+# #+# */ +/* Updated: 2025/02/21 12:33:32 by khais ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "../src/parser/simple_cmd/simple_cmd.h" +#include "../src/parser/wordsplit/wordsplit.h" +#include "../src/parser/wordlist/wordlist.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); +} + +static void test_parse_empty_command(void) +{ + t_simple_cmd *cmd = parse_simple_cmd(""); + assert(cmd != NULL); + simple_cmd_destroy(cmd); +} + +int main(void) +{ + test_parse_empty_command(); + return (0); +}