ast free
This commit is contained in:
parent
a78416ae40
commit
29692ef8fa
15 changed files with 63 additions and 51 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
# By: wescande <wescande@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
# Created: 2016/08/29 21:32:58 by wescande #+# #+# #
|
||||||
# Updated: 2017/03/03 16:05:17 by ariard ### ########.fr #
|
# Updated: 2017/03/03 18:20:32 by ariard ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -59,6 +59,7 @@ completion/c_sizing.c\
|
||||||
completion/c_terminal.c\
|
completion/c_terminal.c\
|
||||||
completion/completion.c\
|
completion/completion.c\
|
||||||
exec/ast_free.c\
|
exec/ast_free.c\
|
||||||
|
exec/redir_free.c\
|
||||||
exec/bad_fd.c\
|
exec/bad_fd.c\
|
||||||
exec/exec_ampersand.c\
|
exec/exec_ampersand.c\
|
||||||
exec/exec_and_if.c\
|
exec/exec_and_if.c\
|
||||||
|
|
|
||||||
14
42sh/file2
14
42sh/file2
|
|
@ -1,14 +0,0 @@
|
||||||
total 576
|
|
||||||
-rwxr-xr-x 1 ariard 2016_paris 690 Feb 21 15:30 update_makefile.sh
|
|
||||||
drwxr-xr-x 13 ariard 2016_paris 442 Feb 21 15:30 src
|
|
||||||
drwxr-xr-x 28 ariard 2016_paris 952 Feb 25 18:21 sample
|
|
||||||
drwxr-xr-x 6 ariard 2016_paris 204 Feb 21 15:30 pdf
|
|
||||||
drwxr-xr-x 13 ariard 2016_paris 442 Mar 2 20:15 objs
|
|
||||||
drwxr-xr-x 12 ariard 2016_paris 408 Mar 2 20:15 libft
|
|
||||||
drwxr-xr-x 19 ariard 2016_paris 646 Mar 2 20:36 includes
|
|
||||||
-rw-r--r-- 1 ariard 2016_paris 0 Mar 2 20:40 file2
|
|
||||||
-rw-r--r-- 1 ariard 2016_paris 0 Mar 2 20:40 file1
|
|
||||||
-rw-r--r-- 1 ariard 2016_paris 4396 Feb 21 15:40 donovan_segaults_06-02
|
|
||||||
-rw-r--r-- 1 ariard 2016_paris 21985 Mar 2 20:39 STDBUG
|
|
||||||
-rw-r--r-- 1 ariard 2016_paris 8051 Mar 1 16:42 Makefile
|
|
||||||
-rwxr-xr-x 1 ariard 2016_paris 246884 Mar 2 20:38 42sh
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/20 20:20:15 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 18:39:32 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -130,6 +130,7 @@ char *ft_findexec(char *path, char *file);
|
||||||
void set_exitstatus(int status, int override);
|
void set_exitstatus(int status, int override);
|
||||||
|
|
||||||
void ast_free(void *data, size_t content_size);
|
void ast_free(void *data, size_t content_size);
|
||||||
|
void redir_free(void *data, size_t content_size);
|
||||||
|
|
||||||
char **token_to_argv(t_astnode *node);
|
char **token_to_argv(t_astnode *node);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
/* Created: 2016/12/01 12:15:54 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/03 16:07:33 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 18:18:14 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,34 +6,32 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
/* Created: 2016/12/05 11:50:51 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:40:54 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 19:59:33 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
|
|
||||||
|
void read_redir(void *data)
|
||||||
|
{
|
||||||
|
t_redir *redir;
|
||||||
|
|
||||||
|
redir = data;
|
||||||
|
DG("file : [%s]", redir->word.word);
|
||||||
|
}
|
||||||
|
|
||||||
void ast_free(void *data, size_t content_size)
|
void ast_free(void *data, size_t content_size)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
|
|
||||||
(void)node;
|
|
||||||
(void)data;
|
|
||||||
(void)content_size;
|
|
||||||
|
|
||||||
return ;
|
|
||||||
/*
|
|
||||||
(void)content_size;
|
(void)content_size;
|
||||||
node = data;
|
node = data;
|
||||||
if (node->type == TK_COMMAND)
|
if (node->type == CMD)
|
||||||
|
{
|
||||||
ft_ld_clear(&node->data.cmd.token, &ft_tabdel);
|
ft_ld_clear(&node->data.cmd.token, &ft_tabdel);
|
||||||
else if (node->type == TK_SUBSHELL)
|
ft_lstdel(&node->data.cmd.redir, &redir_free);
|
||||||
{
|
|
||||||
ft_sstrfree(node->data.sstr);
|
|
||||||
node->data.sstr = NULL;
|
|
||||||
}
|
}
|
||||||
else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT)
|
// if (node->type == WORDLIST)
|
||||||
{
|
// do clear
|
||||||
ft_strdel(&node->data.cmd.redir.word.word);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
29
42sh/src/exec/redir_free.c
Normal file
29
42sh/src/exec/redir_free.c
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* redir_free.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2017/03/03 18:12:57 by ariard #+# #+# */
|
||||||
|
/* Updated: 2017/03/03 20:02:24 by ariard ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "exec.h"
|
||||||
|
|
||||||
|
void redir_free(void *data, size_t content_size)
|
||||||
|
{
|
||||||
|
t_redir *redir;
|
||||||
|
|
||||||
|
(void)content_size;
|
||||||
|
redir = data;
|
||||||
|
if (redir->type == TK_GREAT || redir->type == TK_LESS || redir->type == TK_DGREAT)
|
||||||
|
ft_strdel(&redir->word.word);
|
||||||
|
else
|
||||||
|
redir->word.fd = 0;
|
||||||
|
redir->type = 0;
|
||||||
|
redir->n = 0;
|
||||||
|
redir->close = 1;
|
||||||
|
free(redir);
|
||||||
|
}
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
|
/* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/02/20 20:55:25 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 18:57:46 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
|
||||||
/* Updated: 2017/03/02 21:40:50 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 19:30:48 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
/* Created: 2017/02/15 20:49:15 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/03 15:34:38 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 19:43:22 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ int add_cmd(t_btree **ast, t_list **lst)
|
||||||
my_tab = ft_sstradd(my_tab, token->data);
|
my_tab = ft_sstradd(my_tab, token->data);
|
||||||
my_tab = ft_sstradd(my_tab, (char *)token->esc);
|
my_tab = ft_sstradd(my_tab, (char *)token->esc);
|
||||||
my_tab = ft_sstradd(my_tab, (char *)token->esc2);
|
my_tab = ft_sstradd(my_tab, (char *)token->esc2);
|
||||||
ft_ld_pushback(&node->data.cmd.token, my_tab);
|
ft_ld_pushback(&node->data.cmd.token, my_tab);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
|
/* Created: 2017/02/17 22:17:14 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/03 14:27:27 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 18:01:55 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/03 14:35:14 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 20:02:22 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -69,7 +69,7 @@ int add_redir_word(t_btree **ast, t_list **lst)
|
||||||
else if (ft_stris((char *)token->data, &ft_isdigit))
|
else if (ft_stris((char *)token->data, &ft_isdigit))
|
||||||
redir->word.fd = ft_atoi(token->data);
|
redir->word.fd = ft_atoi(token->data);
|
||||||
else
|
else
|
||||||
redir->word.word = token->data;
|
redir->word.word = ft_strdup(token->data);
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
@ -78,7 +78,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
||||||
{
|
{
|
||||||
t_astnode *node;
|
t_astnode *node;
|
||||||
t_token *token;
|
t_token *token;
|
||||||
t_redir *redir;
|
t_redir redir;
|
||||||
|
|
||||||
DG("add redir");
|
DG("add redir");
|
||||||
if (!*ast)
|
if (!*ast)
|
||||||
|
|
@ -86,8 +86,7 @@ int add_redir_type(t_btree **ast, t_list **lst)
|
||||||
token = (*lst)->content;
|
token = (*lst)->content;
|
||||||
node = (*ast)->item;
|
node = (*ast)->item;
|
||||||
node->type = REDIR;
|
node->type = REDIR;
|
||||||
redir = ft_memalloc(sizeof(redir));
|
redir.type = token->type;
|
||||||
redir->type = token->type;
|
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir)));
|
||||||
ft_lsteadd(&node->data.cmd.redir, ft_lstnew(redir, sizeof(redir)));
|
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser)
|
||||||
{
|
{
|
||||||
produce_sym(*parser->stack, parser->new_sym, token);
|
produce_sym(*parser->stack, parser->new_sym, token);
|
||||||
DG("new sym %s", read_state(*parser->new_sym));
|
DG("new sym %s", read_state(*parser->new_sym));
|
||||||
|
DG("number of token to treat: %d", ft_lstsize(*token));
|
||||||
if (eval_sym(*parser->stack, *parser->new_sym))
|
if (eval_sym(*parser->stack, *parser->new_sym))
|
||||||
return ((parser->state = ERROR));
|
return ((parser->state = ERROR));
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
/* Created: 2017/02/09 17:58:34 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/03 16:22:31 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 18:43:13 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -88,13 +88,11 @@ t_prodmatch g_prodmatch[] =
|
||||||
{TK_NEWLINE, FOR_WORDLIST, NEWLINE_LIST},
|
{TK_NEWLINE, FOR_WORDLIST, NEWLINE_LIST},
|
||||||
{TK_NEWLINE, SEQUENTIAL_SEP, NEWLINE_LIST},
|
{TK_NEWLINE, SEQUENTIAL_SEP, NEWLINE_LIST},
|
||||||
{TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP},
|
{TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP},
|
||||||
{TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP},
|
|
||||||
{TK_SEMI, TERM, SEPARATOR_OP},
|
|
||||||
{TK_SEMI, LIST, SEPARATOR_OP},
|
{TK_SEMI, LIST, SEPARATOR_OP},
|
||||||
{TK_SEMI, PIPE_SEMI_SEQUENCE, SEPARATOR_OP},
|
{TK_SEMI, PIPE_SEMI_SEQUENCE, SEPARATOR_OP},
|
||||||
{TK_AMP, CMD_SUPERIOR, SEPARATOR_OP},
|
{TK_AMP, CMD_SUPERIOR, SEPARATOR_OP},
|
||||||
{TK_AMP, TERM, SEPARATOR_OP},
|
|
||||||
{TK_AMP, LIST, SEPARATOR_OP},
|
{TK_AMP, LIST, SEPARATOR_OP},
|
||||||
|
{TK_AMP, PIPE_SEMI_SEQUENCE, SEPARATOR_OP},
|
||||||
|
|
||||||
{0, 0, 0},
|
{0, 0, 0},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
|
/* Created: 2017/02/09 15:32:10 by ariard #+# #+# */
|
||||||
/* Updated: 2017/03/03 14:28:12 by ariard ### ########.fr */
|
/* Updated: 2017/03/03 18:44:44 by ariard ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue