cmdlist refactor: use cmdlist instead of command_list as a shorthand

I hope this doesn't break too much code ^^
This commit is contained in:
Khaïs COLIN 2025-03-18 14:55:58 +01:00
parent 56fe943efc
commit 131ba36d93
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
18 changed files with 98 additions and 98 deletions

View file

@ -31,10 +31,10 @@ srcs = \
src/ft_errno.c \
src/get_command.c \
src/parser/cmdgroup/cmdgroup.c \
src/parser/command_list/command_list_builder.c \
src/parser/command_list/command_list.c \
src/parser/command_list/command_list_item.c \
src/parser/command_list/operator.c \
src/parser/cmdlist/cmdlist_builder.c \
src/parser/cmdlist/cmdlist.c \
src/parser/cmdlist/cmdlist_item.c \
src/parser/cmdlist/operator.c \
src/parser/matchers/blank.c \
src/parser/matchers/identifier.c \
src/parser/matchers/metacharacter.c \

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/11 15:11:57 by khais #+# #+# */
/* Updated: 2025/03/18 12:27:27 by khais ### ########.fr */
/* Updated: 2025/03/18 15:03:31 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
# define CMDGROUP_H
# include "../wordlist/wordlist.h"
# include "../command_list/command_list.h"
# include "../cmdlist/cmdlist.h"
# include "../../buffer/buffer.h"
/*

View file

@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list.c :+: :+: :+: */
/* cmdlist.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:49:46 by khais #+# #+# */
/* Updated: 2025/03/18 14:43:39 by khais ### ########.fr */
/* Updated: 2025/03/18 15:02:38 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "command_list.h"
#include "command_list_item.h"
#include "command_list_builder.h"
#include "command_list_item_type.h"
#include "cmdlist.h"
#include "cmdlist_item.h"
#include "cmdlist_builder.h"
#include "cmdlist_item_type.h"
#include "operator.h"
#include "libft.h"
#include <unistd.h>

View file

@ -1,17 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list.h :+: :+: :+: */
/* cmdlist.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:45:01 by khais #+# #+# */
/* Updated: 2025/03/18 12:59:56 by khais ### ########.fr */
/* Updated: 2025/03/18 15:10:28 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COMMAND_LIST_H
# define COMMAND_LIST_H
#ifndef CMDLIST_H
# define CMDLIST_H
# include "../wordlist/wordlist.h"
# include "../pipeline/pipeline.h"
@ -81,11 +81,11 @@ typedef struct s_cmdlist
**
** In example above, operators[1] == OP_END
*/
t_operator *operators;
t_operator *operators;
} t_cmdlist;
t_cmdlist *cmdlist_from_wordlist(const t_wordlist *wordlist);
void cmdlist_destroy(t_cmdlist *cmd);
void cmdlist_debug(t_cmdlist *cmd, t_buffer **indent, bool is_last);
#endif // COMMAND_LIST_H
#endif // CMDLIST_H

View file

@ -1,16 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list_builder.c :+: :+: :+: */
/* cmdlist_builder.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/26 13:51:18 by khais #+# #+# */
/* Updated: 2025/03/18 13:31:57 by khais ### ########.fr */
/* Updated: 2025/03/18 15:03:41 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "command_list_builder.h"
#include "cmdlist_builder.h"
#include "libft.h"
/*
@ -21,7 +21,7 @@
** Does not do error checking about repeated operators, or operators in the
** wrong place.
*/
static int command_list_count_pipelines(t_wordlist *words)
static int cmdlist_count_pipelines(t_wordlist *words)
{
t_wordlist *current_word;
int count;
@ -40,11 +40,11 @@ static int command_list_count_pipelines(t_wordlist *words)
}
/*
** Allocate memory for a new command_list, given the input word stream.
** Allocate memory for a new cmdlist, given the input word stream.
**
** Handles malloc error.
*/
static t_cmdlist *allocate_command_list(t_wordlist *words)
static t_cmdlist *allocate_cmdlist(t_wordlist *words)
{
t_cmdlist *output;
@ -53,7 +53,7 @@ static t_cmdlist *allocate_command_list(t_wordlist *words)
output = ft_calloc(1, sizeof(t_cmdlist));
if (output == NULL)
return (NULL);
output->num_cmds = command_list_count_pipelines(words);
output->num_cmds = cmdlist_count_pipelines(words);
output->cmds
= ft_calloc(output->num_cmds, sizeof(struct s_cmdlist_item **));
if (output->cmds == NULL)
@ -74,7 +74,7 @@ t_cmdlist_builder *setup_cmdlist_builder(
t_wordlist **words)
{
ft_bzero(builder, sizeof(t_cmdlist_builder));
builder->cmdlist = allocate_command_list(*words);
builder->cmdlist = allocate_cmdlist(*words);
if (builder->cmdlist == NULL)
return (NULL);
builder->current_wordlist = NULL;

View file

@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list_builder.h :+: :+: :+: */
/* cmdlist_builder.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/26 13:50:25 by khais #+# #+# */
/* Updated: 2025/03/18 12:59:57 by khais ### ########.fr */
/* Updated: 2025/03/18 15:02:53 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COMMAND_LIST_BUILDER_H
# define COMMAND_LIST_BUILDER_H
#ifndef CMDLIST_BUILDER_H
# define CMDLIST_BUILDER_H
# include "command_list.h"
# include "cmdlist.h"
typedef struct s_cmdlist_builder
{
@ -49,4 +49,4 @@ void cmdlist_builder_next_word(
t_cmdlist_builder *builder,
t_wordlist **words);
#endif // COMMAND_LIST_BUILDER_H
#endif // CMDLIST_BUILDER_H

View file

@ -1,16 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list_item.c :+: :+: :+: */
/* cmdlist_item.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 13:02:02 by khais #+# #+# */
/* Updated: 2025/03/18 13:35:25 by khais ### ########.fr */
/* Updated: 2025/03/18 15:03:13 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "command_list_item.h"
#include "cmdlist_item.h"
#include "libft.h"
void cmdlist_item_destroy(t_cmdlist_item *cmd)

View file

@ -1,20 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list_item.h :+: :+: :+: */
/* cmdlist_item.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 12:54:31 by khais #+# #+# */
/* Updated: 2025/03/18 13:34:14 by khais ### ########.fr */
/* Updated: 2025/03/18 15:03:04 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COMMAND_LIST_ITEM_H
# define COMMAND_LIST_ITEM_H
#ifndef CMDLIST_ITEM_H
# define CMDLIST_ITEM_H
# include "../cmdgroup/cmdgroup.h"
# include "command_list_item_type.h"
# include "cmdlist_item_type.h"
typedef struct s_cmdlist_item
{
@ -29,4 +29,4 @@ typedef struct s_cmdlist_item
void cmdlist_item_destroy(t_cmdlist_item *cmd);
t_cmdlist_item *cmdlist_item_create(void);
#endif // COMMAND_LIST_ITEM_H
#endif // CMDLIST_ITEM_H

View file

@ -1,17 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* command_list_item_type.h :+: :+: :+: */
/* cmdlist_item_type.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/18 12:56:30 by khais #+# #+# */
/* Updated: 2025/03/18 12:58:38 by khais ### ########.fr */
/* Updated: 2025/03/18 15:02:27 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef COMMAND_LIST_ITEM_TYPE_H
# define COMMAND_LIST_ITEM_TYPE_H
#ifndef CMDLIST_ITEM_TYPE_H
# define CMDLIST_ITEM_TYPE_H
typedef enum e_cmdlist_item_type
{
@ -20,4 +20,4 @@ typedef enum e_cmdlist_item_type
TYPE_PIPELINE,
} t_cmdlist_item_type;
#endif // COMMAND_LIST_ITEM_TYPE_H
#endif // CMDLIST_ITEM_TYPE_H

View file

@ -8,7 +8,7 @@ rawtests = \
test_redirection_parsing \
test_quote_removal \
test_metacharacters \
test_parse_command_lists \
test_parse_cmdlists \
test_parse_pipelines \
test_parse_simple_cmds \
test_env_manip \
@ -22,7 +22,7 @@ run_tests = $(addprefix run_test_,$(rawtests))
test_objs = $(addsuffix .o,$(tests))
objs := $(addprefix ../,$(objs)) \
testutil.o \
parse_command_list.o \
parse_cmdlist.o \
parse_pipeline.o \
all_objs = $(objs) $(test_objs)

View file

@ -1,22 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_command_list.c :+: :+: :+: */
/* parse_cmdlist.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/11 15:54:43 by khais #+# #+# */
/* Updated: 2025/03/11 15:55:01 by khais ### ########.fr */
/* Updated: 2025/03/18 15:05:39 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "../src/parser/command_list/command_list.h"
#include "../src/parser/cmdlist/cmdlist.h"
#include "../src/parser/wordsplit/wordsplit.h"
#include "libft.h"
#include "unistd.h"
#include <assert.h>
t_cmdlist *parse_command_list(char *input)
t_cmdlist *parse_cmdlist(char *input)
{
ft_dprintf(STDERR_FILENO, "Now checking command list with input [%s]\n", input);
t_wordlist *words = minishell_wordsplit(input);

View file

@ -1,20 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_command_list.h :+: :+: :+: */
/* parse_cmdlist.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/11 15:55:10 by khais #+# #+# */
/* Updated: 2025/03/11 15:55:25 by khais ### ########.fr */
/* Updated: 2025/03/18 15:05:25 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef PARSE_COMMAND_LIST_H
# define PARSE_COMMAND_LIST_H
#ifndef PARSE_CMDLIST_H
# define PARSE_CMDLIST_H
# include "../src/parser/command_list/command_list.h"
# include "../src/parser/cmdlist/cmdlist.h"
t_cmdlist *parse_command_list(char *input);
t_cmdlist *parse_cmdlist(char *input);
#endif // PARSE_COMMAND_LIST_H
#endif // PARSE_CMDLIST_H

View file

@ -6,12 +6,12 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/03 11:40:37 by khais #+# #+# */
/* Updated: 2025/03/18 14:23:19 by khais ### ########.fr */
/* Updated: 2025/03/18 15:05:18 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "../src/parser/wordsplit/wordsplit.h"
#include "../src/parser/command_list/command_list.h"
#include "../src/parser/cmdlist/cmdlist.h"
#include "libft.h"
#include <assert.h>

View file

@ -1,35 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test_parse_command_lists.c :+: :+: :+: */
/* test_parse_cmdlists.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/24 17:40:48 by khais #+# #+# */
/* Updated: 2025/03/18 13:09:51 by khais ### ########.fr */
/* Updated: 2025/03/18 15:05:05 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include "../src/parser/command_list/command_list.h"
#include "../src/parser/cmdlist/cmdlist.h"
#include "testutil.h"
#include "unistd.h"
#include <assert.h>
#include "parse_command_list.h"
#include "parse_cmdlist.h"
static void test_parse_command_list_empty(void)
static void test_parse_cmdlist_empty(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("");
t_cmdlist *cmd = parse_cmdlist("");
assert(cmd == NULL);
cmdlist_destroy(cmd);
}
static void test_parse_command_list_single_pipeline(void)
static void test_parse_cmdlist_single_pipeline(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this | cat -e");
t_cmdlist *cmd = parse_cmdlist("echo this | cat -e");
assert(cmd != NULL);
assert_pipelineequal("echo this | cat -e", cmd, 0);
assert(cmd->operators[0] == OP_END);
@ -37,10 +37,10 @@ static void test_parse_command_list_single_pipeline(void)
cmdlist_destroy(cmd);
}
static void test_parse_command_list_simple_and(void)
static void test_parse_cmdlist_simple_and(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this | cat -e && echo works | wc -c");
t_cmdlist *cmd = parse_cmdlist("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);
@ -49,10 +49,10 @@ static void test_parse_command_list_simple_and(void)
cmdlist_destroy(cmd);
}
static void test_parse_command_list_simple_or(void)
static void test_parse_cmdlist_simple_or(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c");
t_cmdlist *cmd = parse_cmdlist("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);
@ -61,10 +61,10 @@ static void test_parse_command_list_simple_or(void)
cmdlist_destroy(cmd);
}
static void test_parse_command_list_triple_or(void)
static void test_parse_cmdlist_triple_or(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c || echo as well | cut -d' ' -f1");
t_cmdlist *cmd = parse_cmdlist("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);
@ -75,10 +75,10 @@ static void test_parse_command_list_triple_or(void)
cmdlist_destroy(cmd);
}
static void test_parse_command_list_triple_both_operators(void)
static void test_parse_cmdlist_triple_both_operators(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1");
t_cmdlist *cmd = parse_cmdlist("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);
@ -90,10 +90,10 @@ static void test_parse_command_list_triple_both_operators(void)
cmdlist_destroy(cmd);
}
static void test_parse_command_list_quad_both_operators(void)
static void test_parse_cmdlist_quad_both_operators(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this | cat -e || echo works | wc -c && echo as well | cut -d' ' -f1 || echo final");
t_cmdlist *cmd = parse_cmdlist("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);
@ -106,18 +106,18 @@ static void test_parse_command_list_quad_both_operators(void)
cmdlist_destroy(cmd);
}
static void test_parse_command_list_invalid_pipeline(void)
static void test_parse_cmdlist_invalid_pipeline(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this | | cat -e || echo does not work");
t_cmdlist *cmd = parse_cmdlist("echo this | | cat -e || echo does not work");
assert(cmd == NULL);
cmdlist_destroy(cmd);
}
static void test_parse_command_list_simple_command(void)
static void test_parse_cmdlist_simple_command(void)
{
ft_dprintf(STDERR_FILENO, "==> %s <==\n", __FUNCTION__);
t_cmdlist *cmd = parse_command_list("echo this");
t_cmdlist *cmd = parse_cmdlist("echo this");
assert(cmd != NULL);
assert_pipelineequal("echo this", cmd, 0);
assert(cmd->operators[0] == OP_END);
@ -127,23 +127,23 @@ static void test_parse_command_list_simple_command(void)
int main(void)
{
test_parse_command_list_empty();
test_parse_cmdlist_empty();
do_leak_check();
test_parse_command_list_single_pipeline();
test_parse_cmdlist_single_pipeline();
do_leak_check();
test_parse_command_list_simple_and();
test_parse_cmdlist_simple_and();
do_leak_check();
test_parse_command_list_simple_or();
test_parse_cmdlist_simple_or();
do_leak_check();
test_parse_command_list_triple_or();
test_parse_cmdlist_triple_or();
do_leak_check();
test_parse_command_list_triple_both_operators();
test_parse_cmdlist_triple_both_operators();
do_leak_check();
test_parse_command_list_quad_both_operators();
test_parse_cmdlist_quad_both_operators();
do_leak_check();
test_parse_command_list_invalid_pipeline();
test_parse_cmdlist_invalid_pipeline();
do_leak_check();
test_parse_command_list_simple_command();
test_parse_cmdlist_simple_command();
do_leak_check();
return (0);
}

View file

@ -6,20 +6,20 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 15:21:09 by khais #+# #+# */
/* Updated: 2025/03/18 13:09:16 by khais ### ########.fr */
/* Updated: 2025/03/18 15:05:45 by khais ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <assert.h>
#include "testutil.h"
#include "parse_command_list.h"
#include "parse_cmdlist.h"
#include "unistd.h"
#include <assert.h>
#include "parse_pipeline.h"
#include "../src/parser/wordlist/wordlist.h"
#include "../src/parser/wordsplit/wordsplit.h"
#include "../src/parser/command_list/command_list_item.h"
#include "../src/parser/cmdlist/cmdlist_item.h"
void assert_strequal(char *str1, char *str2)
{
@ -128,7 +128,7 @@ t_cmdgroup *parse_cmdgroup(char *input)
void assert_cmdgroup_itemlistequal(char *expected_str, t_cmdgroup *got_cmd, int item_number)
{
ft_dprintf(STDERR_FILENO, "checking that item %d of cmdlist %p matches [%s]\n", item_number, got_cmd, expected_str);
t_cmdlist *expected = parse_command_list(expected_str);
t_cmdlist *expected = parse_cmdlist(expected_str);
if (expected == NULL)
{
ft_dprintf(STDERR_FILENO, "expecting the list to be null\n");

View file

@ -6,7 +6,7 @@
/* By: khais <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/13 15:57:21 by khais #+# #+# */
/* Updated: 2025/03/11 17:26:49 by khais ### ########.fr */
/* Updated: 2025/03/18 15:05:34 by khais ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
# define TESTUTIL_H
# include "../src/parser/simple_cmd/simple_cmd.h"
# include "../src/parser/command_list/command_list.h"
# include "../src/parser/cmdlist/cmdlist.h"
# include "../src/parser/cmdgroup/cmdgroup.h"
void assert_strequal(char *str1, char *str2);