Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Commit

Permalink
norminette
Browse files Browse the repository at this point in the history
  • Loading branch information
mcombeau committed Nov 7, 2022
1 parent bd56321 commit c59312e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 30 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
8 changes: 5 additions & 3 deletions includes/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: mcombeau <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -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);
Expand Down
29 changes: 2 additions & 27 deletions sources/parser/cmd_lst_utils.c
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions sources/parser/cmd_lst_utils_cleanup.c
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit c59312e

Please sign in to comment.