diff --git a/42sh/Makefile b/42sh/Makefile index 3dc7d3f8..2fbc2bc6 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -6,7 +6,7 @@ # 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/completion.c\ exec/ast_free.c\ +exec/redir_free.c\ exec/bad_fd.c\ exec/exec_ampersand.c\ exec/exec_and_if.c\ diff --git a/42sh/file1 b/42sh/file1 deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/file2 b/42sh/file2 deleted file mode 100644 index 37e50d1b..00000000 --- a/42sh/file2 +++ /dev/null @@ -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 diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index a115f3cb..81140b50 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* 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 ast_free(void *data, size_t content_size); +void redir_free(void *data, size_t content_size); char **token_to_argv(t_astnode *node); diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 7ca24e5f..167ffecb 100644 --- a/42sh/includes/parser.h +++ b/42sh/includes/parser.h @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ast_free.c b/42sh/src/exec/ast_free.c index de356f4f..487cf063 100644 --- a/42sh/src/exec/ast_free.c +++ b/42sh/src/exec/ast_free.c @@ -6,34 +6,32 @@ /* 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" +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) { t_astnode *node; - (void)node; - (void)data; - (void)content_size; - - return ; -/* (void)content_size; node = data; - if (node->type == TK_COMMAND) + if (node->type == CMD) + { ft_ld_clear(&node->data.cmd.token, &ft_tabdel); - else if (node->type == TK_SUBSHELL) - { - ft_sstrfree(node->data.sstr); - node->data.sstr = NULL; + ft_lstdel(&node->data.cmd.redir, &redir_free); } - else if (node->type == TK_LESS || node->type == TK_GREAT || node->type == TK_DGREAT) - { - ft_strdel(&node->data.cmd.redir.word.word); - } -*/ +// if (node->type == WORDLIST) +// do clear + } diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c new file mode 100644 index 00000000..9e0a1b06 --- /dev/null +++ b/42sh/src/exec/redir_free.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* redir_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ariard +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/lexer/token_free.c b/42sh/src/lexer/token_free.c index 09fb728f..d88b0e1b 100644 --- a/42sh/src/lexer/token_free.c +++ b/42sh/src/lexer/token_free.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index a4ca3108..3867ddad 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 9605f7a1..fa49951e 100644 --- a/42sh/src/parser/add_cmd.c +++ b/42sh/src/parser/add_cmd.c @@ -6,7 +6,7 @@ /* 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, (char *)token->esc); 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); } diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index fa17904c..a26d2755 100644 --- a/42sh/src/parser/add_loop.c +++ b/42sh/src/parser/add_loop.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index f3cc03bd..7d88688e 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* 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)) redir->word.fd = ft_atoi(token->data); else - redir->word.word = token->data; + redir->word.word = ft_strdup(token->data); } return (0); } @@ -78,7 +78,7 @@ int add_redir_type(t_btree **ast, t_list **lst) { t_astnode *node; t_token *token; - t_redir *redir; + t_redir redir; DG("add redir"); if (!*ast) @@ -86,8 +86,7 @@ int add_redir_type(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; node->type = REDIR; - redir = ft_memalloc(sizeof(redir)); - redir->type = token->type; - ft_lsteadd(&node->data.cmd.redir, ft_lstnew(redir, sizeof(redir))); + redir.type = token->type; + ft_lsteadd(&node->data.cmd.redir, ft_lstnew(&redir, sizeof(redir))); return (0); } diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 5889b603..8672cfc8 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -33,7 +33,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) { produce_sym(*parser->stack, parser->new_sym, token); 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)) return ((parser->state = ERROR)); else diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index af056626..f7e07c32 100644 --- a/42sh/src/parser/produce_sym.c +++ b/42sh/src/parser/produce_sym.c @@ -6,7 +6,7 @@ /* 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, SEQUENTIAL_SEP, NEWLINE_LIST}, {TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP}, - {TK_SEMI, CMD_SUPERIOR, SEPARATOR_OP}, - {TK_SEMI, TERM, SEPARATOR_OP}, {TK_SEMI, LIST, SEPARATOR_OP}, {TK_SEMI, PIPE_SEMI_SEQUENCE, SEPARATOR_OP}, {TK_AMP, CMD_SUPERIOR, SEPARATOR_OP}, - {TK_AMP, TERM, SEPARATOR_OP}, {TK_AMP, LIST, SEPARATOR_OP}, + {TK_AMP, PIPE_SEMI_SEQUENCE, SEPARATOR_OP}, {0, 0, 0}, }; diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index 38e51155..e033924e 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* 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 */ /* */ /* ************************************************************************** */