free start
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#ifndef MINISHELL_H
|
||||
# define MINISHELL_H
|
||||
|
||||
# define DEBUG 1
|
||||
# define DEBUG 0
|
||||
|
||||
typedef struct s_ast_n t_ast_n;
|
||||
typedef struct s_node t_node;
|
||||
|
||||
@@ -80,4 +80,7 @@ void create_pline(t_ast_n *self, t_node *lst, t_node *token, t_msh *msh);
|
||||
// and_or
|
||||
void create_and_or(t_ast_n *parrent, t_node *lst, t_node *token, t_msh *msh);
|
||||
|
||||
// free
|
||||
void free_ast(t_ast_n *node);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -43,12 +43,10 @@ static char **add_space_to_tab(char **tab, int count)
|
||||
|
||||
void add_to_tab(char ***tab, char *str)
|
||||
{
|
||||
char **tmp;
|
||||
int i;
|
||||
|
||||
if (!str)
|
||||
return ;
|
||||
tmp = *tab;
|
||||
i = 0;
|
||||
if (*tab)
|
||||
{
|
||||
@@ -60,8 +58,6 @@ void add_to_tab(char ***tab, char *str)
|
||||
{
|
||||
*tab = malloc(sizeof(char *) * 2);
|
||||
}
|
||||
if (tmp)
|
||||
free(tmp);
|
||||
(*tab)[i] = ft_strdup(str);
|
||||
(*tab)[i + 1] = NULL;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ void interpret_cmd(char **input, t_msh *msh)
|
||||
{
|
||||
msh->head = parser(*input, msh);
|
||||
msh->ex_code = execute_command(msh->head);
|
||||
free_ast(msh->head);
|
||||
msh->head = NULL;
|
||||
free(*input);
|
||||
*input = NULL;
|
||||
}
|
||||
|
||||
50
srcs/parsing/ast/free_ast.c
Normal file
50
srcs/parsing/ast/free_ast.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* free_ast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/02/05 14:39:28 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/02/05 14:39:28 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../../includes/minishell.h"
|
||||
|
||||
static void free_redirs(t_ast_n *node)
|
||||
{
|
||||
free(node->redir);
|
||||
if (node->files)
|
||||
free_tab(node->files);
|
||||
free_tab(node->args);
|
||||
}
|
||||
|
||||
void free_ast(t_ast_n *node)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (node->state == _AND || node->state == _OR)
|
||||
{
|
||||
free_ast(node->left);
|
||||
free_ast(node->right);
|
||||
}
|
||||
else if (node->state == _PLINE)
|
||||
{
|
||||
i = -1;
|
||||
while (node->pline[++i])
|
||||
free_ast(node->pline[i]);
|
||||
}
|
||||
else if (node->state == _SUBSH)
|
||||
{
|
||||
free_ast(node->left);
|
||||
free_redirs(node);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(node->cmd);
|
||||
free_redirs(node);
|
||||
}
|
||||
|
||||
free(node);
|
||||
}
|
||||
@@ -46,4 +46,5 @@ void create_subsh(t_ast_n *self, t_node *lst, t_msh *msh)
|
||||
self->redir = ft_calloc(1, sizeof(t_redir));
|
||||
self->redir[0] = _NR;
|
||||
create_redir_subsh(lst, self);
|
||||
// free(cutted);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user