From b08b727779a9649a2fa8b729aef3b9ee429ba5f1 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Thu, 2 Feb 2017 15:23:31 +0100 Subject: [PATCH] orphan backquotes and orpan parens generate parse errors --- 42sh/.gitignore | 1 + 42sh/includes/lexer.h | 2 +- 42sh/src/builtin/builtin_exit.c | 2 +- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/lexer/command_getoutput.c | 2 +- 42sh/src/lexer/ft_post_tokenize.c | 15 ++++++++++++++- 42sh/src/lexer/reduce_bquotes.c | 9 +++++++-- 42sh/src/lexer/reduce_parens.c | 2 +- 42sh/src/main/main.c | 4 ++-- 9 files changed, 29 insertions(+), 10 deletions(-) diff --git a/42sh/.gitignore b/42sh/.gitignore index 23a58579..d5fb06f4 100644 --- a/42sh/.gitignore +++ b/42sh/.gitignore @@ -3,4 +3,5 @@ minishell 42sh out debug +.42sh_history *.dSYM diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index d27214cd..8efb7a2b 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/02/02 14:55:46 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:14:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index 80148cb8..220886c9 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/01/09 16:25:06 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:04:48 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 193eddcb..e257cd9e 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/02/02 14:49:49 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:04:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/command_getoutput.c b/42sh/src/lexer/command_getoutput.c index 2684662a..7dbd1c46 100644 --- a/42sh/src/lexer/command_getoutput.c +++ b/42sh/src/lexer/command_getoutput.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ -/* Updated: 2017/02/02 14:52:30 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:16:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/ft_post_tokenize.c b/42sh/src/lexer/ft_post_tokenize.c index 7545b99a..f95e1cb0 100644 --- a/42sh/src/lexer/ft_post_tokenize.c +++ b/42sh/src/lexer/ft_post_tokenize.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:11:11 by jhalford #+# #+# */ -/* Updated: 2017/02/02 14:54:57 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:22:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,13 +15,26 @@ int ft_post_tokenize(t_list **alst, char **str) { int ret; + t_flag tk; while ((ret = reduce_parens(alst, *str))) if (ret == -1) + { + ft_dprintf(2, "{red}%s: parse error near '('{eoc}\n", SHELL_NAME); return (-1); + } + tk = TK_PAREN_CLOSE; + if (ft_lst_find(*alst, &tk, token_cmp_type)) + { + ft_dprintf(2, "{red}%s: parse error near ')'{eoc}\n", SHELL_NAME); + return (-1); + } while ((ret = reduce_bquotes(alst, str))) if (ret == -1) + { + ft_dprintf(2, "{red}%s: parse error near '`'{eoc}\n", SHELL_NAME); return (-1); + } DG("new command from bquotes: '%s'", *str); return (0); } diff --git a/42sh/src/lexer/reduce_bquotes.c b/42sh/src/lexer/reduce_bquotes.c index 1fe3cf4a..418edde5 100644 --- a/42sh/src/lexer/reduce_bquotes.c +++ b/42sh/src/lexer/reduce_bquotes.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:46:27 by jhalford #+# #+# */ -/* Updated: 2017/02/02 14:52:28 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:16:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,10 +24,12 @@ int reduce_bquotes(t_list **alst, char **str) char *bq_end; tk = TK_BQUOTE; + DG("check 0"); if ((start = ft_lst_find(*alst, &tk, token_cmp_type))) { + DG("check 1"); end = &start->next; - while (end) + while (end && *end) { token = (*end)->content; if (token->type == TK_BQUOTE) @@ -35,7 +37,10 @@ int reduce_bquotes(t_list **alst, char **str) end = &(*end)->next; } if (!*end) + { + DG("check 42"); return (-1); + } bq_start = ((t_token*)start->content)->data; bq_end = ((t_token*)(*end)->content)->data; ft_lstdel(end, token_free); diff --git a/42sh/src/lexer/reduce_parens.c b/42sh/src/lexer/reduce_parens.c index dfad6686..7f4f3c39 100644 --- a/42sh/src/lexer/reduce_parens.c +++ b/42sh/src/lexer/reduce_parens.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/11 16:13:31 by jhalford #+# #+# */ -/* Updated: 2017/01/12 13:50:10 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:19:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 5a28ed2d..2df0292f 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/02/02 14:55:29 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 15:22:00 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,7 +53,7 @@ int main(int ac, char **av) { if (ft_readline()) return (1); - if (shell_single_command(ft_strdup(data_singleton()->line.input))) + if (shell_single_command(ft_strdup(data_singleton()->line.input)) < 0) return (1); } return (0);