From 6ae49e363795c5bf0c595aa93731588bd51ca020 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Fri, 24 Mar 2017 17:10:14 +0100 Subject: [PATCH 1/2] close #173 --- 42sh/file1 | 1 + 42sh/includes/types.h | 3 ++- 42sh/sample/infinite.sh | 5 ----- 42sh/sample/until2.sh | 11 +++-------- 42sh/src/exec/exec_func.c | 3 ++- 42sh/src/exec/exec_var.c | 4 +--- 42sh/src/exec/plaunch_function.c | 4 +--- 42sh/src/exec/process_redirect.c | 3 ++- 42sh/src/exec/redir_copy.c | 3 ++- 42sh/src/exec/redirect_great.c | 3 ++- 42sh/src/parser/add_cmd.c | 4 +++- 42sh/src/parser/add_func.c | 8 +++----- 42sh/src/parser/add_redir.c | 4 +++- 42sh/src/parser/add_subshell.c | 4 ++-- 42sh/src/parser/build_tree.c | 4 +++- 42sh/src/parser/ft_parse.c | 2 +- 16 files changed, 31 insertions(+), 35 deletions(-) create mode 100644 42sh/file1 diff --git a/42sh/file1 b/42sh/file1 new file mode 100644 index 00000000..cc628ccd --- /dev/null +++ b/42sh/file1 @@ -0,0 +1 @@ +world diff --git a/42sh/includes/types.h b/42sh/includes/types.h index fc142314..a45aa749 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/22 19:36:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 16:50:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -196,6 +196,7 @@ enum e_sym OPEN_FUNC, CLOSE_FUNC, CLOSE_LIST, + OTHER, REDIR, CMD, HEREDOCDATA, diff --git a/42sh/sample/infinite.sh b/42sh/sample/infinite.sh index 90ac1360..740015ae 100644 --- a/42sh/sample/infinite.sh +++ b/42sh/sample/infinite.sh @@ -1,7 +1,2 @@ echo "echo hello" >> sample/infinite.sh echo hello -echo hello -echo hello -echo hello -echo hello -echo hello diff --git a/42sh/sample/until2.sh b/42sh/sample/until2.sh index 28aeabc8..a8a568d1 100644 --- a/42sh/sample/until2.sh +++ b/42sh/sample/until2.sh @@ -4,13 +4,8 @@ do TWO=0 while [ $TWO -le 10 ] do - THREE=0 - while [ $THREE -le 10 ] - do - echo world - ((THREE++)) - done - ((TWO++)) + echo world + math TWO + 1; done - ((ONE++)) + math ONE + 1; done > file1 diff --git a/42sh/src/exec/exec_func.c b/42sh/src/exec/exec_func.c index 7ddb750d..e1c4e621 100644 --- a/42sh/src/exec/exec_func.c +++ b/42sh/src/exec/exec_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/23 16:25:23 by ariard #+# #+# */ -/* Updated: 2017/03/23 16:27:57 by ariard ### ########.fr */ +/* Updated: 2017/03/24 16:36:39 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -45,6 +45,7 @@ int exec_func(t_btree **ast) t_btree *func_ast; t_list *old_func; + DG(); func_ast = btree_map(*ast, &node_copy); if ((old_func = is_already_func(&func_ast))) { diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 8fa2f3b9..4a227eb0 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/23 00:51:22 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:40:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,10 +21,8 @@ int exec_var(t_btree **ast) char *equal; node = (*ast)->item; - DG("before"); if (!(av = token_to_argv(node->data.cmd.token, 1))) return (0); - DG("after"); var = av[0]; if ((equal = ft_strchr(av[0], '='))) *equal = 0; diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index 100dbb18..d86ba3db 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/23 16:35:59 by ariard ### ########.fr */ +/* Updated: 2017/03/24 16:53:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,6 @@ int plaunch_function(t_process *p) { static int protection; - if (!protection) - protection = 0; if (protection >= FUNC_LVL) return (SH_ERR(FUNCERR_0)); protection++; diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 6b5a50de..43280efe 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/23 16:35:25 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:51:24 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,6 +36,7 @@ int process_redirect(t_process *p) fd_replace(p->fdout, STDOUT); while (redirs) { + DG(); redir = redirs->content; if (redir->n > 9) return (bad_fd(redir->n)); diff --git a/42sh/src/exec/redir_copy.c b/42sh/src/exec/redir_copy.c index 88a86d3a..03f17ce0 100644 --- a/42sh/src/exec/redir_copy.c +++ b/42sh/src/exec/redir_copy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ -/* Updated: 2017/03/20 16:26:50 by gwojda ### ########.fr */ +/* Updated: 2017/03/24 15:54:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,6 +19,7 @@ void *redir_copy(void *data) if (!data) return (NULL); + DG(); old = data; new = (t_redir *)ft_memalloc(sizeof(t_redir)); new->type = old->type; diff --git a/42sh/src/exec/redirect_great.c b/42sh/src/exec/redirect_great.c index 49f59d8e..a461858a 100644 --- a/42sh/src/exec/redirect_great.c +++ b/42sh/src/exec/redirect_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:03:53 by jhalford #+# #+# */ -/* Updated: 2017/03/20 18:15:43 by gwojda ### ########.fr */ +/* Updated: 2017/03/24 15:59:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ int redirect_great(t_redir *redir) if ((fdold = open(redir->word, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) exit(1); + DG("%d %d", fdold, fdnew); dup2(fdold, fdnew); return (0); } diff --git a/42sh/src/parser/add_cmd.c b/42sh/src/parser/add_cmd.c index 332ad7cb..3465e91c 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/23 16:49:28 by ariard ### ########.fr */ +/* Updated: 2017/03/24 16:56:50 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -86,6 +86,8 @@ static int add_data_node(t_btree **ast, t_list **lst) if ((token->type == TK_WORD || token->type == TK_NAME) && (node->type == TK_CASE || node->type == TK_PAREN_OPEN)) node->pattern = 1; + if (token->type == SUBSHELL || token->type == TK_LBRACE) + node->nest = 1; return (0); } diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index 27a87b4c..7517b705 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/23 16:26:09 by ariard ### ########.fr */ +/* Updated: 2017/03/24 16:51:13 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,9 +26,6 @@ int isfunc_name(t_btree **ast, t_list **lst) node->type = FNAME; return (1); } - if (node->type == FNAME && token->type == TK_PAREN_CLOSE - && node->nest == 0) - return (1); } return (0); } @@ -62,7 +59,8 @@ int add_func_cmd(t_btree **ast, t_list **lst) if ((token->type == TK_CASE || token->type == TK_WHILE || token->type == TK_IF || token->type == TK_UNTIL || token->type == TK_FOR || token->type == SUBSHELL - || token->type == TK_LBRACE) && node->type == FNAME) + || token->type == TK_LBRACE || token->type == TK_PAREN_OPEN) + && node->type == FNAME) node->nest++; if ((token->type == TK_DONE || token->type == TK_ESAC || token->type == TK_FI || token->type == TK_RBRACE diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 725f5b15..a5b2ee0c 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/23 16:29:03 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:55:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -71,6 +71,7 @@ int add_redir_word(t_btree **ast, t_list **lst) token = (*lst)->content; node = (*ast)->item; + DG("node type is %s", read_state(node->type)); if (node->data.cmd.redir) { redir = (ft_lstlast(node->data.cmd.redir))->content; @@ -111,6 +112,7 @@ int add_redir_type(t_btree **ast, t_list **lst) gen_node(ast); token = (*lst)->content; node = (*ast)->item; + DG("node type is %s", read_state(node->type)); if (!(node->type == TK_IO_NUMBER)) { redir_init(token->type, &redir); diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index c928ae0f..147901fe 100644 --- a/42sh/src/parser/add_subshell.c +++ b/42sh/src/parser/add_subshell.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 18:41:50 by ariard #+# #+# */ -/* Updated: 2017/03/22 15:32:43 by ariard ### ########.fr */ +/* Updated: 2017/03/24 17:02:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -47,7 +47,7 @@ int add_subshell_cmd(t_btree **ast, t_list **lst) if (((token->type == TK_PAREN_CLOSE && node->type == SUBSHELL) || (token->type == TK_RBRACE && node->type == TK_LBRACE)) && node->nest > 0) node->nest--; - else if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL + if (token->type == TK_PAREN_CLOSE && node->type == SUBSHELL && node->nest == 0) return ((node->full = 1)); else if (token->type == TK_RBRACE && node->type == TK_LBRACE diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index 7fee0309..1ebb2189 100644 --- a/42sh/src/parser/build_tree.c +++ b/42sh/src/parser/build_tree.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:32:59 by ariard #+# #+# */ -/* Updated: 2017/03/24 15:01:36 by ariard ### ########.fr */ +/* Updated: 2017/03/24 17:02:43 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -72,6 +72,8 @@ static int check_cache(t_token *token, int cache) if (token->type == TK_PAREN_OPEN && cache != TK_IN && cache != TK_DSEMI && cache != TK_WORD) token->type = SUBSHELL; + if (token->type == TK_PAREN_CLOSE && cache == TK_PAREN_OPEN) + token->type = OTHER; return (0); } diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 8a3af975..08d51084 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:17:38 by ariard #+# #+# */ -/* Updated: 2017/03/24 15:18:51 by ariard ### ########.fr */ +/* Updated: 2017/03/24 17:01:05 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ From b9d526b77be7ced3e555b7160aab44c8c3ad9ad2 Mon Sep 17 00:00:00 2001 From: gwojda Date: Fri, 24 Mar 2017 17:11:16 +0100 Subject: [PATCH 2/2] #185 --- 42sh/src/builtin/builtin_func.c | 5 +---- 42sh/src/lexer/lexer_destroy.c | 4 ++-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/42sh/src/builtin/builtin_func.c b/42sh/src/builtin/builtin_func.c index f9129d66..81353fec 100644 --- a/42sh/src/builtin/builtin_func.c +++ b/42sh/src/builtin/builtin_func.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/24 15:03:02 by wescande #+# #+# */ -/* Updated: 2017/03/24 16:22:13 by gwojda ### ########.fr */ +/* Updated: 2017/03/24 17:04:11 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,10 +32,7 @@ int builtin_func(const char *path, return (SH_ERR("unexpected error")); name = token_to_argv(((t_astnode *)(*ast)->item)->data.cmd.token, 1); if (name && name[0]) - { - DG(); ft_putendl(name[0]); - } ft_tabdel(&name); list = list->next; } diff --git a/42sh/src/lexer/lexer_destroy.c b/42sh/src/lexer/lexer_destroy.c index 73596cd0..d7684a15 100644 --- a/42sh/src/lexer/lexer_destroy.c +++ b/42sh/src/lexer/lexer_destroy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/16 20:25:08 by ariard #+# #+# */ -/* Updated: 2017/03/16 20:43:06 by ariard ### ########.fr */ +/* Updated: 2017/03/24 17:07:56 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,6 @@ void lexer_destroy(t_lexer *lexer) ft_strdel(&lexer->str); lexer->pos = 0; lexer->state = 0; - lexer->stack = NULL; + ft_lstdel(&lexer->stack, ft_lst_cfree); lexer->heredoc_stack = NULL; }