From c59312e24c45ee8540ad866c3967e9a1e223a627 Mon Sep 17 00:00:00 2001 From: Mia Date: Mon, 7 Nov 2022 17:45:19 +0100 Subject: [PATCH] norminette --- Makefile | 1 + includes/minishell.h | 8 ++++--- sources/parser/cmd_lst_utils.c | 29 ++------------------------ sources/parser/cmd_lst_utils_cleanup.c | 27 ++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 30 deletions(-) create mode 100644 sources/parser/cmd_lst_utils_cleanup.c diff --git a/Makefile b/Makefile index 15cbcd6..36f251b 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ SRC = main.c \ parser/parse_heredoc_utils.c \ parser/parse_pipe.c \ parser/cmd_lst_utils.c \ + parser/cmd_lst_utils_cleanup.c \ builtins/export_builtin.c \ builtins/unset_builtin.c \ builtins/cd_builtin.c \ diff --git a/includes/minishell.h b/includes/minishell.h index d8f36b8..d0fe1ae 100644 --- a/includes/minishell.h +++ b/includes/minishell.h @@ -6,7 +6,7 @@ /* By: mcombeau +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/09/17 17:14:16 by mcombeau #+# #+# */ -/* Updated: 2022/11/07 17:39:16 by mcombeau ### ########.fr */ +/* Updated: 2022/11/07 17:43:50 by mcombeau ### ########.fr */ /* */ /* ************************************************************************** */ @@ -233,11 +233,13 @@ void remove_empty_var_args(t_token **tokens); // cmd_lst_utils.c t_command *lst_new_cmd(bool value); void lst_add_back_cmd(t_command **alst, t_command *new_node); -void lst_delone_cmd(t_command *lst, void (*del)(void *)); -void lst_clear_cmd(t_command **lst, void (*del)(void *)); t_command *lst_last_cmd(t_command *cmd); t_command *lst_first_cmd(t_command *cmd); +// cmd_lst_utils_cleanup.c +void lst_delone_cmd(t_command *lst, void (*del)(void *)); +void lst_clear_cmd(t_command **lst, void (*del)(void *)); + // parse_trunc.c void parse_trunc(t_command **last_cmd, t_token **token_lst); char *get_relative_path(char *file_to_open); diff --git a/sources/parser/cmd_lst_utils.c b/sources/parser/cmd_lst_utils.c index b393b84..deabf44 100644 --- a/sources/parser/cmd_lst_utils.c +++ b/sources/parser/cmd_lst_utils.c @@ -1,6 +1,7 @@ + #include "minishell.h" -void initialize_cmd(t_command **cmd) +static void initialize_cmd(t_command **cmd) { (*cmd)->command = NULL; (*cmd)->path = NULL; @@ -43,32 +44,6 @@ void lst_add_back_cmd(t_command **alst, t_command *new_node) } } -void lst_delone_cmd(t_command *lst, void (*del)(void *)) -{ - if (lst->command) - (*del)(lst->command); - if (lst->args) - free_str_tab(lst->args); - if (lst->pipe_fd) - (*del)(lst->pipe_fd); - if (lst->io_fds) - free_io(lst->io_fds); - (*del)(lst); -} - -void lst_clear_cmd(t_command **lst, void (*del)(void *)) -{ - t_command *temp; - - temp = NULL; - while (*lst != NULL) - { - temp = (*lst)->next; - lst_delone_cmd(*lst, del); - *lst = temp; - } -} - t_command *lst_last_cmd(t_command *cmd) { while (cmd->next != NULL) diff --git a/sources/parser/cmd_lst_utils_cleanup.c b/sources/parser/cmd_lst_utils_cleanup.c new file mode 100644 index 0000000..5c7eb69 --- /dev/null +++ b/sources/parser/cmd_lst_utils_cleanup.c @@ -0,0 +1,27 @@ +#include "minishell.h" + +void lst_delone_cmd(t_command *lst, void (*del)(void *)) +{ + if (lst->command) + (*del)(lst->command); + if (lst->args) + free_str_tab(lst->args); + if (lst->pipe_fd) + (*del)(lst->pipe_fd); + if (lst->io_fds) + free_io(lst->io_fds); + (*del)(lst); +} + +void lst_clear_cmd(t_command **lst, void (*del)(void *)) +{ + t_command *temp; + + temp = NULL; + while (*lst != NULL) + { + temp = (*lst)->next; + lst_delone_cmd(*lst, del); + *lst = temp; + } +} \ No newline at end of file