From 0f50556720b81d07f88e20e86d504d7d548938b4 Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Mon, 13 Mar 2017 16:56:09 +0100 Subject: [PATCH] pipe ok with control flow --- 42sh/file | 1 + 42sh/src/lexer/get_reserved_words.c | 14 ++++++++------ 42sh/src/main/main.c | 6 +++--- 42sh/src/parser/add_bang.c | 2 +- 42sh/src/parser/add_case.c | 6 +++++- 42sh/src/parser/add_condition.c | 7 +++---- 42sh/src/parser/add_func.c | 5 +++-- 42sh/src/parser/add_loop.c | 5 +++-- 42sh/src/parser/add_number.c | 2 +- 42sh/src/parser/add_redir.c | 20 +++++--------------- 42sh/src/parser/add_sep.c | 2 +- 42sh/src/parser/add_subshell.c | 2 +- 42sh/src/parser/aggregate_sym.c | 10 +++++----- 42sh/src/parser/eval_sym.c | 7 ++++--- 42sh/src/parser/heredoc_parser.c | 4 ++-- 42sh/src/parser/produce_sym.c | 8 ++++---- 16 files changed, 50 insertions(+), 51 deletions(-) create mode 100644 42sh/file diff --git a/42sh/file b/42sh/file new file mode 100644 index 00000000..f6536de2 --- /dev/null +++ b/42sh/file @@ -0,0 +1 @@ +cat: wefwewef: No such file or directory diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index e1c525ff..dc63c869 100644 --- a/42sh/src/lexer/get_reserved_words.c +++ b/42sh/src/lexer/get_reserved_words.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/26 00:07:05 by ariard #+# #+# */ -/* Updated: 2017/03/06 17:59:39 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:55:08 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,11 +33,13 @@ t_rvwords g_rvwords[] = static int recognization_rvwords(t_token *pv_tk) { - if (!pv_tk || (pv_tk->type == TK_NEWLINE || pv_tk->type == TK_AMP - || pv_tk->type == TK_SEMI || pv_tk->type == TK_WHILE - || pv_tk->type == TK_DONE || pv_tk->type == TK_DO - || pv_tk->type == TK_IF || pv_tk->type == TK_FI || pv_tk->type == TK_THEN - || pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE)) + if (!pv_tk || (pv_tk->type == TK_NEWLINE || pv_tk->type == TK_AMP + || pv_tk->type == TK_SEMI || pv_tk->type == TK_PIPE + || pv_tk->type == TK_WHILE || pv_tk->type == TK_DONE + || pv_tk->type == TK_DO || pv_tk->type == TK_IF + || pv_tk->type == TK_FI || pv_tk->type == TK_THEN + || pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE + || pv_tk->type == TK_DSEMI)) return (1); return (0); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index be0aeb36..e473017d 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/13 15:03:26 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:36:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -73,8 +73,8 @@ int handle_instruction(int fd) } } btree_print(STDBUG, ast, &ft_putast); - if (ft_exec(&ast)) - return (1); +// if (ft_exec(&ast)) +// return (1); instruction_free(&token, &parser, &ast); if (SH_IS_INTERACTIVE(data_singleton()->opts)) ft_add_str_in_history(lexer.str); diff --git a/42sh/src/parser/add_bang.c b/42sh/src/parser/add_bang.c index 2a81934b..910e7be8 100644 --- a/42sh/src/parser/add_bang.c +++ b/42sh/src/parser/add_bang.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 14:57:45 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:29:08 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:25:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index f4a2c1bc..0669707e 100644 --- a/42sh/src/parser/add_case.c +++ b/42sh/src/parser/add_case.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/04 20:42:13 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:33:30 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:26:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,10 @@ int iscase(t_btree **ast, t_list **lst) if (*ast) { node = (*ast)->item; + if ((node->type == TK_NEWLINE || node->type == TK_SEMI + || node->type == TK_AMP || node->type == TK_PIPE) + && iscase(&(*ast)->right, lst) == 1) + return (1); if (node->type == TK_CASE || node->type == TK_PAREN_OPEN) return (1); } diff --git a/42sh/src/parser/add_condition.c b/42sh/src/parser/add_condition.c index 426d3572..d72d3cfd 100644 --- a/42sh/src/parser/add_condition.c +++ b/42sh/src/parser/add_condition.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 17:06:16 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:36:33 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:10:30 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,15 +15,14 @@ int iscondition(t_btree **ast, t_list **lst) { t_astnode *node; -// t_token *token; node = NULL; -// token = (*lst)->content; if (*ast) { node = (*ast)->item; if ((node->type == TK_NEWLINE || node->type == TK_SEMI - || node->type == TK_AMP) && iscondition(&(*ast)->right, lst) == 1) + || node->type == TK_AMP || node->type == TK_PIPE) + && iscondition(&(*ast)->right, lst) == 1) return (1); if ((node->type == TK_IF || node->type == TK_ELIF || node->type == TK_ELSE) && node->full == 0) diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index 909a915e..ca30af45 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/11 15:41:11 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:24:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,7 +44,8 @@ int isfunc(t_btree **ast, t_list **lst) { node = (*ast)->item; if ((node->type == TK_NEWLINE || node->type == TK_SEMI - || node->type == TK_AMP) && isfunc(&(*ast)->right, lst) == 1) + || node->type == TK_AMP || node->type == TK_PIPE) + && isfunc(&(*ast)->right, lst) == 1) return (1); if (node->type == FNAME && node->full == 0) return (1); diff --git a/42sh/src/parser/add_loop.c b/42sh/src/parser/add_loop.c index c690145f..d8694a03 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/13 14:23:53 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:12:35 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ int isloop(t_btree **ast, t_list **lst) { node = (*ast)->item; if ((node->type == TK_NEWLINE || node->type == TK_SEMI - || node->type == TK_AMP) && isloop(&(*ast)->right, lst) == 1) + || node->type == TK_AMP || node->type == TK_PIPE) + && isloop(&(*ast)->right, lst) == 1) return (1); if ((node->type == TK_WHILE || node->type == TK_UNTIL || node->type == TK_FOR) && node->full == 0) diff --git a/42sh/src/parser/add_number.c b/42sh/src/parser/add_number.c index 190a8f03..49809151 100644 --- a/42sh/src/parser/add_number.c +++ b/42sh/src/parser/add_number.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 17:28:31 by ariard #+# #+# */ -/* Updated: 2017/03/13 15:01:22 by ariard ### ########.fr */ +/* Updated: 2017/03/13 15:57:10 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index c66215e2..fec9a2a6 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,6 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ +/* Updated: 2017/03/13 15:56:25 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -67,39 +68,28 @@ int add_redir_word(t_btree **ast, t_list **lst) t_astnode *node; t_token *token; t_redir *redir; - t_redir *other; token = (*lst)->content; node = (*ast)->item; - other = NULL; if (node->data.cmd.redir) { redir = (ft_lstlast(node->data.cmd.redir))->content; redir->word = ft_strdup(token->data); - if (TK_DLESS) - { - DG(); - other = ft_lstlast(data_singleton()->heredoc_queue)->content; - DG(); - DG("type is %s", read_state(other->type)); - DG("word is %s", other->word); - } - } + } return (0); } static int add_redir_type_number(t_btree **ast, t_list **lst) { - t_redir *temp; -// t_redir *temp_heredoc; + t_redir *redir; t_astnode *node; t_token *token; DG(); token = (*lst)->content; node = (*ast)->item; - temp = (ft_lstlast(node->data.cmd.redir))->content; - temp->type = token->type; + redir = (ft_lstlast(node->data.cmd.redir))->content; + redir->type = token->type; if (token->type == TK_DLESS) ft_lsteadd(&data_singleton()->heredoc_queue, ft_lstlast(node->data.cmd.redir)); return (0); diff --git a/42sh/src/parser/add_sep.c b/42sh/src/parser/add_sep.c index fd15b298..c57a0944 100644 --- a/42sh/src/parser/add_sep.c +++ b/42sh/src/parser/add_sep.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 19:12:07 by ariard #+# #+# */ -/* Updated: 2017/03/11 15:55:45 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:25:31 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_subshell.c b/42sh/src/parser/add_subshell.c index 528a81da..5b64d400 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/13 14:25:12 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:09:23 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/aggregate_sym.c b/42sh/src/parser/aggregate_sym.c index adce88c6..c0830b11 100644 --- a/42sh/src/parser/aggregate_sym.c +++ b/42sh/src/parser/aggregate_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 15:58:38 by ariard #+# #+# */ -/* Updated: 2017/03/12 00:50:41 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:26:59 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -388,20 +388,20 @@ int aggregate_sym(t_list **stack, t_sym *new_sym, t_parstate *state) return (1); i = 0; head = (*stack)->content; -// DG("aggregate head %s && sym %s", -// read_state(*head), read_state(*new_sym)); + DG("aggregate head %s && sym %s", + read_state(*head), read_state(*new_sym)); while (g_aggrematch[i].top) { if (*new_sym == g_aggrematch[i].top && MATCH_STACK(*head, g_aggrematch[i].under)) { -// DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); + DG("MATCH : %s", read_state(g_aggrematch[i].new_sym)); *new_sym = g_aggrematch[i].new_sym; if (g_aggrematch[i].erase_sym) { pop_stack(stack, g_aggrematch[i].erase_sym); head = (*stack)->content; -// DG("stack after pop: %s", read_state(*head)); + DG("stack after pop: %s", read_state(*head)); } if (eval_sym(stack, *new_sym)) { diff --git a/42sh/src/parser/eval_sym.c b/42sh/src/parser/eval_sym.c index 8159698a..9ac70bf1 100644 --- a/42sh/src/parser/eval_sym.c +++ b/42sh/src/parser/eval_sym.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/11 16:11:21 by ariard #+# #+# */ -/* Updated: 2017/03/11 16:17:10 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:39:28 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -830,12 +830,13 @@ t_stackmatch g_stackmatch[] = {CONDITION, COMPOUND_LIST}, {CONDITION, CASE_LIST_NS}, {CONDITION, COMPLETE_CONDITION}, + {CONDITION, SEQUENCE}, {COMPLETE_CONDITION, LINEBREAK}, {COMPLETE_CONDITION, TK_PAREN_OPEN}, {COMPLETE_CONDITION, TK_LBRACE}, {COMPLETE_CONDITION, COMPLETE_COMMANDS}, {COMPLETE_CONDITION, COMPLETE_CONDITION}, - {COMPLETE_CONDITION, COMPLETE_CONDITION}, + {COMPLETE_CONDITION, SEQUENCE}, {BRACE_GROUP, LINEBREAK}, {BRACE_GROUP, TK_PAREN_OPEN}, {BRACE_GROUP, TK_LBRACE}, @@ -1266,7 +1267,7 @@ int eval_sym(t_list **stack, t_sym new_sym) if (!*stack) return (1); head = (*stack)->content; -// DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); + DG("eval head %s && sym %s", read_state(*head), read_state(new_sym)); i = 0; while (g_stackmatch[i].top) { diff --git a/42sh/src/parser/heredoc_parser.c b/42sh/src/parser/heredoc_parser.c index 2b84d738..e0cf26bd 100644 --- a/42sh/src/parser/heredoc_parser.c +++ b/42sh/src/parser/heredoc_parser.c @@ -21,12 +21,12 @@ int pop_heredoc(t_list **lst) token = (*lst)->content; if (token->type == HEREDOCDATA && data_singleton()->heredoc_queue != NULL) { - head = data_singleton()->heredoc_queue->content; temp = data_singleton()->heredoc_queue; + head = temp->content; if (head && token) { if (ft_strcmp((char *)token->data, head->word) == 0) - data_singleton()->heredoc_queue = temp->next; + ft_lst_removeif(&data_singleton()->heredoc_queue, temp->content, &ft_addrcmp); else { head->heredoc_data = ft_strjoin(head->heredoc_data, diff --git a/42sh/src/parser/produce_sym.c b/42sh/src/parser/produce_sym.c index 61aa47f0..bf806b2b 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/11 16:22:18 by ariard ### ########.fr */ +/* Updated: 2017/03/13 16:31:42 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -130,8 +130,8 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) return (1); token = (*lst)->content; head = (*stack)->content; -// DG("produce stack : %s && token : %s", read_state(*head), -// read_state(token->type)); + DG("produce stack : %s && token : %s", read_state(*head), + read_state(token->type)); i = 0; *new_sym = 0; while (g_prodmatch[i].new_sym) @@ -139,7 +139,7 @@ int produce_sym(t_list **stack, t_sym *new_sym, t_list **lst) if (token->type == g_prodmatch[i].token && *head == g_prodmatch[i].stack) { -// DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); + DG("MATCH : %s", read_state(g_prodmatch[i].new_sym)); *new_sym = g_prodmatch[i].new_sym; } i++;