From 5fceb4713d2cc031e6f840abf3d3701384f4691b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 25 Feb 2025 15:15:23 +0100 Subject: [PATCH] command list refactor: rename t_command_list to t_cmdlist --- src/parser/command_list/command_list.c | 20 +++++++------- src/parser/command_list/command_list.h | 10 +++---- tests/parse_command_lists.c | 36 +++++++++++++------------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/parser/command_list/command_list.c b/src/parser/command_list/command_list.c index 64530b6..15d73ce 100644 --- a/src/parser/command_list/command_list.c +++ b/src/parser/command_list/command_list.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:49:46 by khais #+# #+# */ -/* Updated: 2025/02/25 15:08:48 by khais ### ########.fr */ +/* Updated: 2025/02/25 15:25:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,13 +60,13 @@ static int command_list_count_pipelines(t_wordlist *words) ** ** Handles malloc error. */ -static t_command_list *allocate_command_list(t_wordlist *words) +static t_cmdlist *allocate_command_list(t_wordlist *words) { - t_command_list *output; + t_cmdlist *output; if (words == NULL) return (NULL); - output = ft_calloc(1, sizeof(t_command_list)); + output = ft_calloc(1, sizeof(t_cmdlist)); if (output == NULL) return (NULL); output->num_pipelines = command_list_count_pipelines(words); @@ -84,12 +84,12 @@ static t_command_list *allocate_command_list(t_wordlist *words) /* ** Create a new command list from the given wordlist. */ -t_command_list *command_list_from_wordlist(t_wordlist *words) +t_cmdlist *cmdlist_from_wordlist(t_wordlist *words) { - t_command_list *output; - t_wordlist *current_wordlist; - t_worddesc *current_word; - int idx; + t_cmdlist *output; + t_wordlist *current_wordlist; + t_worddesc *current_word; + int idx; output = allocate_command_list(words); if (output == NULL) @@ -125,7 +125,7 @@ t_command_list *command_list_from_wordlist(t_wordlist *words) /* ** destroy the given command list and all associated memory */ -void command_list_destroy(t_command_list *cmd) +void cmdlist_destroy(t_cmdlist *cmd) { int i; diff --git a/src/parser/command_list/command_list.h b/src/parser/command_list/command_list.h index a1d044a..99166cb 100644 --- a/src/parser/command_list/command_list.h +++ b/src/parser/command_list/command_list.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:45:01 by khais #+# #+# */ -/* Updated: 2025/02/25 15:06:23 by khais ### ########.fr */ +/* Updated: 2025/02/25 15:25:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -78,7 +78,7 @@ typedef enum e_operator ** The return status of AND and OR lists is the exit status of the last command ** executed in the list. */ -typedef struct s_command_list +typedef struct s_cmdlist { /* ** List of pipelines contained in this command list. @@ -100,9 +100,9 @@ typedef struct s_command_list ** In example above, operators[1] == OP_END */ t_operator *operators; -} t_command_list; +} t_cmdlist; -t_command_list *command_list_from_wordlist(t_wordlist *words); -void command_list_destroy(t_command_list *cmd); +t_cmdlist *cmdlist_from_wordlist(t_wordlist *words); +void cmdlist_destroy(t_cmdlist *cmd); #endif // COMMAND_LIST_H diff --git a/tests/parse_command_lists.c b/tests/parse_command_lists.c index 435932b..d18ad1b 100644 --- a/tests/parse_command_lists.c +++ b/tests/parse_command_lists.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:40:48 by khais #+# #+# */ -/* Updated: 2025/02/25 15:10:29 by khais ### ########.fr */ +/* Updated: 2025/02/25 15:25:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,11 +17,11 @@ #include "unistd.h" #include -static t_command_list *parse_command_list(char *input) +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_command_list *cmd = command_list_from_wordlist(words); + t_cmdlist *cmd = cmdlist_from_wordlist(words); return (cmd); } @@ -52,7 +52,7 @@ static void assert_simple_commandequal(t_simple_cmd *expected, t_simple_cmd *got assert(got_word == NULL); } -static void assert_pipelineequal(char *expected, t_command_list *cmd, int idx) +static void assert_pipelineequal(char *expected, t_cmdlist *cmd, int idx) { ft_printf("Expected command list %p to have at least %d pipelines, and got %d\n", cmd, idx + 1, cmd->num_pipelines); assert(cmd->num_pipelines >= idx + 1); @@ -80,46 +80,46 @@ static void assert_pipelineequal(char *expected, t_command_list *cmd, int idx) static void test_parse_command_list_empty(void) { - t_command_list *cmd = parse_command_list(""); + t_cmdlist *cmd = parse_command_list(""); assert(cmd == NULL); - command_list_destroy(cmd); + cmdlist_destroy(cmd); } static void test_parse_command_list_single_pipeline(void) { - t_command_list *cmd = parse_command_list("echo this | cat -e"); + t_cmdlist *cmd = parse_command_list("echo this | cat -e"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_END); assert(cmd->num_pipelines == 1); - command_list_destroy(cmd); + cmdlist_destroy(cmd); } static void test_parse_command_list_simple_and(void) { - t_command_list *cmd = parse_command_list("echo this | cat -e && echo works | wc -c"); + t_cmdlist *cmd = parse_command_list("echo this | cat -e && echo works | wc -c"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_AND); assert_pipelineequal("echo works | wc -c", cmd, 1); assert(cmd->num_pipelines == 2); - command_list_destroy(cmd); + cmdlist_destroy(cmd); } static void test_parse_command_list_simple_or(void) { - t_command_list *cmd = parse_command_list("echo this | cat -e || echo works | wc -c"); + t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); assert_pipelineequal("echo works | wc -c", cmd, 1); assert(cmd->num_pipelines == 2); - command_list_destroy(cmd); + cmdlist_destroy(cmd); } static void test_parse_command_list_triple_or(void) { - t_command_list *cmd = parse_command_list("echo this | cat -e || echo works | wc -c || echo as well | cut -d' ' -f1"); + t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c || echo as well | cut -d' ' -f1"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); @@ -127,12 +127,12 @@ static void test_parse_command_list_triple_or(void) assert(cmd->operators[1] == OP_OR); assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2); assert(cmd->num_pipelines == 3); - command_list_destroy(cmd); + cmdlist_destroy(cmd); } static void test_parse_command_list_triple_both_operators(void) { - t_command_list *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1"); + t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); @@ -141,12 +141,12 @@ static void test_parse_command_list_triple_both_operators(void) assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2); assert(cmd->operators[2] == OP_END); assert(cmd->num_pipelines == 3); - command_list_destroy(cmd); + cmdlist_destroy(cmd); } static void test_parse_command_list_quad_both_operators(void) { - t_command_list *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1 || echo final"); + t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1 || echo final"); assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_OR); @@ -156,7 +156,7 @@ static void test_parse_command_list_quad_both_operators(void) assert(cmd->operators[2] == OP_OR); assert_pipelineequal("echo final", cmd, 3); assert(cmd->operators[3] == OP_END); - command_list_destroy(cmd); + cmdlist_destroy(cmd); } int main(void)