From b95476a0bef93c8fa1050df31dfecba7d19252ac Mon Sep 17 00:00:00 2001 From: Antoine Riard Date: Fri, 24 Mar 2017 15:18:17 +0100 Subject: [PATCH] error for + case fix close #174 --- 42sh/Makefile | 3 +-- 42sh/includes/exec.h | 4 +--- 42sh/sample/case/case.sh | 5 ++++- 42sh/src/exec/error_badidentifier.c | 21 --------------------- 42sh/src/exec/plaunch_for.c | 6 ++++-- 42sh/src/lexer/get_reserved_words.c | 3 ++- 42sh/src/lexer/isrw_delim.c | 2 +- 42sh/src/main/main.c | 3 ++- 42sh/src/parser/add_case.c | 8 ++++---- 42sh/src/parser/build_tree.c | 3 +-- 42sh/src/parser/ft_parse.c | 3 ++- 42sh/src/parser/tree_wrapper.c | 2 +- 12 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 42sh/src/exec/error_badidentifier.c diff --git a/42sh/Makefile b/42sh/Makefile index 5e78833d..5fddcd99 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/24 12:02:21 by gwojda ### ########.fr # +# Updated: 2017/03/24 14:53:07 by ariard ### ########.fr # # # # **************************************************************************** # @@ -65,7 +65,6 @@ completion/c_terminal.c\ completion/completion.c\ exec/ast_free.c\ exec/bad_fd.c\ -exec/error_badidentifier.c\ exec/exec_ampersand.c\ exec/exec_and_if.c\ exec/exec_bang.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 92a89a05..2d24813b 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/03/23 16:27:10 by ariard ### ########.fr */ +/* Updated: 2017/03/24 14:47:12 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -166,8 +166,6 @@ void *redir_copy(void *data); void redir_free(void *data, size_t content_size); char **token_to_argv(t_ld *ld, int do_match); - -int error_badidentifier(char *name); t_btree *is_function(t_process *p); /* diff --git a/42sh/sample/case/case.sh b/42sh/sample/case/case.sh index f41470f9..14b13108 100644 --- a/42sh/sample/case/case.sh +++ b/42sh/sample/case/case.sh @@ -1,5 +1,8 @@ case van in ( "bus" ) echo Hello world ;; ( "velo" ) echo Comment va ;; - ( "van" ) ls ;; + ( "van" ) case tutu in + ( toto ) pwd ;; + ( tutu ) ls ;; + esac ;; esac diff --git a/42sh/src/exec/error_badidentifier.c b/42sh/src/exec/error_badidentifier.c deleted file mode 100644 index 9238d892..00000000 --- a/42sh/src/exec/error_badidentifier.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* error_badidentifier.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/06 18:03:51 by ariard #+# #+# */ -/* Updated: 2017/03/06 18:11:26 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int error_badidentifier(char *name) -{ - ft_putstr_fd("`", 2); - ft_putstr(name); - ft_putstr_fd("' not a valid identifier", 2); - return (1); -} diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index bfaab55d..c5f97f8a 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -6,12 +6,14 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ -/* Updated: 2017/03/22 22:20:02 by ariard ### ########.fr */ +/* Updated: 2017/03/24 14:52:00 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#define FORERR_0 ": `%s' not a valid identifier" + int plaunch_for(t_process *p) { t_ld *temp; @@ -22,7 +24,7 @@ int plaunch_for(t_process *p) temp = p->data.d_for.token; var = ((char **)temp->content)[0]; if (!word_is_assignment(temp->content)) - return (error_badidentifier(var)); + return (SH_ERR(FORERR_0, var)); i = 0; av = token_to_argv(temp, 1); while (av[++i]) diff --git a/42sh/src/lexer/get_reserved_words.c b/42sh/src/lexer/get_reserved_words.c index 3426c33d..ed33e3ce 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/22 16:38:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/24 15:01:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,6 +39,7 @@ static int recognization_rvwords(t_token *pv_tk, t_token *at_tk) || pv_tk->type == TK_ELIF || pv_tk->type == TK_ELSE || pv_tk->type == TK_DSEMI || pv_tk->type == TK_PAREN_OPEN || pv_tk->type == TK_LBRACE || pv_tk->type == TK_UNTIL) + || pv_tk->type == TK_PAREN_CLOSE || (pv_tk->type == TK_PAREN_CLOSE && at_tk->type == TK_PAREN_OPEN)); } diff --git a/42sh/src/lexer/isrw_delim.c b/42sh/src/lexer/isrw_delim.c index cede1c3d..5d9212a5 100644 --- a/42sh/src/lexer/isrw_delim.c +++ b/42sh/src/lexer/isrw_delim.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 19:12:50 by ariard #+# #+# */ -/* Updated: 2017/03/23 17:25:03 by ariard ### ########.fr */ +/* Updated: 2017/03/24 14:49:17 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 2b2f966c..0d3fa344 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 14:45:40 by gwojda #+# #+# */ -/* Updated: 2017/03/23 16:58:43 by ariard ### ########.fr */ +/* Updated: 2017/03/24 14:55:27 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,6 +43,7 @@ static int handle_instruction(t_list **token, t_btree **ast) return (ret); if (do_lexer_routine(token, stream) > 0) continue ; + token_print(*token); if ((ret = do_parser_routine(token, ast)) == 1 && SH_NO_INTERACTIVE(data->opts)) return (ret); diff --git a/42sh/src/parser/add_case.c b/42sh/src/parser/add_case.c index 42e864da..889b6142 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/22 15:30:25 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:17:40 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,12 +62,12 @@ int add_case_cmd(t_btree **ast, t_list **lst) node->nest++; if (token->type == TK_ESAC && (node->type == TK_PAREN_OPEN || node->type == TK_CASE) && node->nest > 0) - return ((node->nest--)); + node->nest--; else if (token->type == TK_DSEMI && node->type == TK_PAREN_OPEN && node->nest == 0) return ((node->full = 1)); - else if ((token->type == TK_ESAC) - && node->nest == 0) + else if ((token->type == TK_ESAC) && node->nest == 0 + && (node->type == TK_CASE || node->type == TK_PAREN_OPEN)) return ((node->full = 1)); else if (token->type == TK_PAREN_CLOSE) return (0); diff --git a/42sh/src/parser/build_tree.c b/42sh/src/parser/build_tree.c index afbb8fc4..7fee0309 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/23 16:49:18 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:01:36 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -84,7 +84,6 @@ int build_tree(t_btree **ast, t_list **lst) i = 0; token = (*lst)->content; check_cache(token, cache); - DG("new"); while (g_treematch[i].type) { if ((isseparator(token, cache) && g_treematch[i].type == token->type)) diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index 49426b09..a6845ec7 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/18 19:18:34 by ariard ### ########.fr */ +/* Updated: 2017/03/24 15:02:51 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,6 +49,7 @@ int ft_parse(t_btree **ast, t_list **token, t_parser *parser) parser->state = SUCCESS; else parser->state = UNDEFINED; + btree_print(STDBUG, *ast, &ft_putast); build_tree(ast, token); if ((end_instruction(&parser->stack) && !(*token)->next)) insert_linebreak(token); diff --git a/42sh/src/parser/tree_wrapper.c b/42sh/src/parser/tree_wrapper.c index 93622211..f056cdb8 100644 --- a/42sh/src/parser/tree_wrapper.c +++ b/42sh/src/parser/tree_wrapper.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 18:57:44 by ariard #+# #+# */ -/* Updated: 2017/03/21 15:46:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/24 15:00:14 by ariard ### ########.fr */ /* */ /* ************************************************************************** */