From 985745f881edb8bff6e5795b60d510685f430f4f Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Fri, 3 Feb 2017 13:21:06 +0100 Subject: [PATCH] starting to fixi redirections --- 42sh/Makefile | 1 + 42sh/includes/parser.h | 3 ++- 42sh/src/exec/exec_great.c | 2 +- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/main/main.c | 2 +- 42sh/src/parser/ft_parse.c | 12 +++--------- 42sh/src/parser/parse_dgreat.c | 2 +- 42sh/src/parser/parse_great.c | 2 +- 42sh/src/parser/parse_redir.c | 34 ++++++++++++++++++++++++++++++++++ 9 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 42sh/src/parser/parse_redir.c diff --git a/42sh/Makefile b/42sh/Makefile index 8d286750..8a4eda07 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -187,6 +187,7 @@ parser/parse_great.c\ parser/parse_greatand.c\ parser/parse_less.c\ parser/parse_lessand.c\ +parser/parse_redir.c\ parser/parse_separator.c\ parser/parse_subshell.c\ parser/parse_word.c diff --git a/42sh/includes/parser.h b/42sh/includes/parser.h index 3a6f5392..0bbc3553 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/02/02 14:03:15 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 19:03:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -60,6 +60,7 @@ extern t_parser g_parser[]; int ft_parse(t_btree **ast, t_list **token); int parse_separator(t_btree **ast, t_list **start, t_list **lst); +int parse_redir(t_btree **ast, t_list **start, t_list **lst); int parse_less(t_btree **ast, t_list **start, t_list **lst); int parse_great(t_btree **ast, t_list **start, t_list **lst); int parse_dless(t_btree **ast, t_list **start, t_list **lst); diff --git a/42sh/src/exec/exec_great.c b/42sh/src/exec/exec_great.c index 6b410e7b..fa307617 100644 --- a/42sh/src/exec/exec_great.c +++ b/42sh/src/exec/exec_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 17:27:51 by jhalford #+# #+# */ -/* Updated: 2016/12/13 17:14:19 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 19:06:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index e257cd9e..1b5f4c59 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 15:04:50 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 19:06:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 8fb8d026..931f4a63 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 15:45:17 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 18:57:56 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/ft_parse.c b/42sh/src/parser/ft_parse.c index beb0cfaa..fbcb39a2 100644 --- a/42sh/src/parser/ft_parse.c +++ b/42sh/src/parser/ft_parse.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 17:14:58 by jhalford #+# #+# */ -/* Updated: 2017/02/02 15:45:33 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 19:02:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,7 @@ t_parser g_parser[] = {TK_AND_IF | TK_OR_IF, &parse_separator}, {TK_AMP, &parse_separator}, {TK_PIPE, &parse_separator}, - {TK_LESS, &parse_less}, - {TK_GREAT, &parse_great}, - {TK_DLESS, &parse_dless}, - {TK_DGREAT, &parse_dgreat}, - {TK_LESSAND, &parse_lessand}, - {TK_GREATAND, &parse_greatand}, + {TK_REDIR, &parse_redir}, {TK_SUBSHELL, &parse_subshell}, {TK_WORD, &parse_word}, {0, 0}, @@ -48,8 +43,7 @@ int ft_parse(t_btree **ast, t_list **start) if ((lst = ft_lst_find(*start, &g_parser[i].type, &token_cmp_type))) { if (g_parser[i].f) - (*g_parser[i].f)(ast, start, &lst); - return (0); + return ((*g_parser[i].f)(ast, start, &lst)); } i++; } diff --git a/42sh/src/parser/parse_dgreat.c b/42sh/src/parser/parse_dgreat.c index 15d7b579..dcfe9a5d 100644 --- a/42sh/src/parser/parse_dgreat.c +++ b/42sh/src/parser/parse_dgreat.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2017/01/10 14:44:12 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 19:02:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_great.c b/42sh/src/parser/parse_great.c index 490965dc..f81c0de4 100644 --- a/42sh/src/parser/parse_great.c +++ b/42sh/src/parser/parse_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/14 12:49:45 by jhalford #+# #+# */ -/* Updated: 2017/01/10 14:45:50 by jhalford ### ########.fr */ +/* Updated: 2017/02/02 19:05:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/parse_redir.c b/42sh/src/parser/parse_redir.c new file mode 100644 index 00000000..e937b1a3 --- /dev/null +++ b/42sh/src/parser/parse_redir.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_redir.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/02/02 18:58:27 by jhalford #+# #+# */ +/* Updated: 2017/02/02 19:04:32 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "parser.h" + +int parse_redir(t_btree **ast, t_list **start, t_list **lst) +{ + t_token *tok; + + tok = (*lst)->content; + if (tok->type == TK_LESS) + return (parse_less(ast, start, lst)); + else if (tok->type == TK_GREAT) + return (parse_great(ast, start, lst)); + else if (tok->type == TK_DLESS) + return (parse_dless(ast, start, lst)); + else if (tok->type == TK_DGREAT) + return (parse_dgreat(ast, start, lst)); + else if (tok->type == TK_LESSAND) + return (parse_lessand(ast, start, lst)); + else if (tok->type == TK_GREATAND) + return (parse_greatand(ast, start, lst)); + else + return (-42); +}