From 88ed66e138e288db2aa377c2dc811f2df11f36aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Wed, 19 Mar 2025 16:26:45 +0100 Subject: [PATCH] refactor cmdlist.num_cmds -> cmdlist.num_cmd to be more consistent --- src/parser/cmdlist/cmdlist.c | 4 ++-- src/parser/cmdlist/cmdlist.h | 4 ++-- src/parser/cmdlist/cmdlist_builder.c | 10 +++++----- src/parser/cmdlist/cmdlist_debug.c | 10 +++++----- .../redirections/cmdgroup_redirection_parsing.c | 4 ++-- tests/test_parse_cmdlists.c | 14 +++++++------- tests/testutil.c | 8 ++++---- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/parser/cmdlist/cmdlist.c b/src/parser/cmdlist/cmdlist.c index 9b3f953..9676b8c 100644 --- a/src/parser/cmdlist/cmdlist.c +++ b/src/parser/cmdlist/cmdlist.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:49:46 by khais #+# #+# */ -/* Updated: 2025/03/18 15:52:43 by khais ### ########.fr */ +/* Updated: 2025/03/19 16:43:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -106,7 +106,7 @@ void cmdlist_destroy(t_cmdlist *cmd) if (cmd == NULL) return ; i = 0; - while (i < cmd->num_cmds) + while (i < cmd->num_cmd) { cmdlist_item_destroy(cmd->cmds[i]); i++; diff --git a/src/parser/cmdlist/cmdlist.h b/src/parser/cmdlist/cmdlist.h index dd5c05c..86145ee 100644 --- a/src/parser/cmdlist/cmdlist.h +++ b/src/parser/cmdlist/cmdlist.h @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:45:01 by khais #+# #+# */ -/* Updated: 2025/03/19 12:12:12 by khais ### ########.fr */ +/* Updated: 2025/03/19 16:43:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,7 +71,7 @@ typedef struct s_cmdlist /* ** Number of commands in this command list. */ - int num_cmds; + int num_cmd; /* ** Operators that separate the pipelines. ** diff --git a/src/parser/cmdlist/cmdlist_builder.c b/src/parser/cmdlist/cmdlist_builder.c index bd45e7e..c34cb4b 100644 --- a/src/parser/cmdlist/cmdlist_builder.c +++ b/src/parser/cmdlist/cmdlist_builder.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/26 13:51:18 by khais #+# #+# */ -/* Updated: 2025/03/18 15:03:41 by khais ### ########.fr */ +/* Updated: 2025/03/19 16:43:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,13 +53,13 @@ static t_cmdlist *allocate_cmdlist(t_wordlist *words) output = ft_calloc(1, sizeof(t_cmdlist)); if (output == NULL) return (NULL); - output->num_cmds = cmdlist_count_pipelines(words); + output->num_cmd = cmdlist_count_pipelines(words); output->cmds - = ft_calloc(output->num_cmds, sizeof(struct s_cmdlist_item **)); + = ft_calloc(output->num_cmd, sizeof(struct s_cmdlist_item **)); if (output->cmds == NULL) return (free(output), NULL); output->operators - = ft_calloc(output->num_cmds, sizeof(t_operator)); + = ft_calloc(output->num_cmd, sizeof(t_operator)); if (output->operators == NULL) return (free(output->cmds), free(output), NULL); return (output); @@ -100,5 +100,5 @@ void cmdlist_builder_next_word( */ bool cmdlist_builder_at_last_pipeline(t_cmdlist_builder *builder) { - return (builder->idx == builder->cmdlist->num_cmds - 1); + return (builder->idx == builder->cmdlist->num_cmd - 1); } diff --git a/src/parser/cmdlist/cmdlist_debug.c b/src/parser/cmdlist/cmdlist_debug.c index 6f50416..ac85419 100644 --- a/src/parser/cmdlist/cmdlist_debug.c +++ b/src/parser/cmdlist/cmdlist_debug.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/18 15:52:28 by khais #+# #+# */ -/* Updated: 2025/03/19 14:43:39 by khais ### ########.fr */ +/* Updated: 2025/03/19 16:43:14 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,12 +43,12 @@ void cmdlist_debug(t_cmdlist *cmd, t_buffer *leader, bool is_last) ft_printf("%s\n", "t_cmdlist"); i = 0; last = false; - if (cmd->num_cmds == 0) + if (cmd->num_cmd == 0) last = true; - cmdlist_num_cmds_debug(cmd->num_cmds, leader, last); - while (i < cmd->num_cmds) + cmdlist_num_cmds_debug(cmd->num_cmd, leader, last); + while (i < cmd->num_cmd) { - if (i == cmd->num_cmds - 1) + if (i == cmd->num_cmd - 1) last = true; cmdlist_array_debug(cmd, i, leader, last); i++; diff --git a/src/postprocess/redirections/cmdgroup_redirection_parsing.c b/src/postprocess/redirections/cmdgroup_redirection_parsing.c index 22e0dd9..4004909 100644 --- a/src/postprocess/redirections/cmdgroup_redirection_parsing.c +++ b/src/postprocess/redirections/cmdgroup_redirection_parsing.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/19 16:37:09 by khais #+# #+# */ -/* Updated: 2025/03/19 18:40:04 by khais ### ########.fr */ +/* Updated: 2025/03/20 11:56:28 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,7 +57,7 @@ static t_cmdlist *cmdlist_parse_redirections(t_cmdlist *cmd) if (cmd == NULL) return (NULL); i = 0; - while (i < cmd->num_cmds) + while (i < cmd->num_cmd) { if (cmdlist_item_parse_redirections(cmd->cmds[i]) == NULL) return (NULL); diff --git a/tests/test_parse_cmdlists.c b/tests/test_parse_cmdlists.c index 82fa6c6..c80fde4 100644 --- a/tests/test_parse_cmdlists.c +++ b/tests/test_parse_cmdlists.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/24 17:40:48 by khais #+# #+# */ -/* Updated: 2025/03/18 15:05:05 by khais ### ########.fr */ +/* Updated: 2025/03/20 11:57:26 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ static void test_parse_cmdlist_single_pipeline(void) assert(cmd != NULL); assert_pipelineequal("echo this | cat -e", cmd, 0); assert(cmd->operators[0] == OP_END); - assert(cmd->num_cmds == 1); + assert(cmd->num_cmd == 1); cmdlist_destroy(cmd); } @@ -45,7 +45,7 @@ static void test_parse_cmdlist_simple_and(void) 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_cmds == 2); + assert(cmd->num_cmd == 2); cmdlist_destroy(cmd); } @@ -57,7 +57,7 @@ static void test_parse_cmdlist_simple_or(void) 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_cmds == 2); + assert(cmd->num_cmd == 2); cmdlist_destroy(cmd); } @@ -71,7 +71,7 @@ static void test_parse_cmdlist_triple_or(void) assert_pipelineequal("echo works | wc -c", cmd, 1); assert(cmd->operators[1] == OP_OR); assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2); - assert(cmd->num_cmds == 3); + assert(cmd->num_cmd == 3); cmdlist_destroy(cmd); } @@ -86,7 +86,7 @@ static void test_parse_cmdlist_triple_both_operators(void) assert(cmd->operators[1] == OP_AND); assert_pipelineequal("echo as well | cut -d' ' -f1", cmd, 2); assert(cmd->operators[2] == OP_END); - assert(cmd->num_cmds == 3); + assert(cmd->num_cmd == 3); cmdlist_destroy(cmd); } @@ -121,7 +121,7 @@ static void test_parse_cmdlist_simple_command(void) assert(cmd != NULL); assert_pipelineequal("echo this", cmd, 0); assert(cmd->operators[0] == OP_END); - assert(cmd->num_cmds == 1); + assert(cmd->num_cmd == 1); cmdlist_destroy(cmd); } diff --git a/tests/testutil.c b/tests/testutil.c index 17efe6d..87e4bfe 100644 --- a/tests/testutil.c +++ b/tests/testutil.c @@ -6,7 +6,7 @@ /* By: khais +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/02/13 15:21:09 by khais #+# #+# */ -/* Updated: 2025/03/18 15:05:45 by khais ### ########.fr */ +/* Updated: 2025/03/20 11:57:29 by khais ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,8 +84,8 @@ void assert_pipelineequal_raw(t_pipeline *expected, t_pipeline *got) 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_cmds); - assert(cmd->num_cmds >= idx + 1); + ft_printf("Expected command list %p to have at least %d pipelines, and got %d\n", cmd, idx + 1, cmd->num_cmd); + assert(cmd->num_cmd >= idx + 1); t_pipeline *got = cmd->cmds[idx]->inner.pipeline; ft_dprintf(STDERR_FILENO, "Expected pipeline %p to equal [%s]\n", got, expected); t_pipeline *expected_pipeline = parse_pipeline(expected); @@ -136,7 +136,7 @@ void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int } ft_dprintf(STDERR_FILENO, "checking if the list matches...\n"); int i = 0; - while (i < expected->num_cmds) + while (i < expected->num_cmd) { i++; }