mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-05 23:18:08 +01:00
refactor cmdlist.num_cmds -> cmdlist.num_cmd to be more consistent
This commit is contained in:
parent
448458b37f
commit
88ed66e138
7 changed files with 27 additions and 27 deletions
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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++;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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.
|
||||
**
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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++;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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++;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue