From c167d80270f21bbff93ff068f05971fc9a4722ac Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Mon, 13 Mar 2017 19:23:20 +0100 Subject: [PATCH] brace group execution done --- 42sh/Makefile | 2 ++ 42sh/file | 1 - 42sh/includes/exec.h | 5 ++++- 42sh/src/builtin/builtin_export.c | 10 +++------- 42sh/src/builtin/builtin_setenv.c | 2 +- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/ft_exec.c | 3 ++- 42sh/src/exec/launch_brace.c | 24 ++++++++++++++++++++++++ 42sh/src/exec/launch_builtin.c | 5 ++++- 42sh/src/exec/launch_process.c | 3 ++- 42sh/src/exec/launch_subshell.c | 2 +- 42sh/src/exec/redirect_less.c | 2 +- 42sh/src/exec/set_process.c | 2 +- 42sh/src/exec/set_process_brace.c | 21 +++++++++++++++++++++ 42sh/src/exec/set_process_map.c | 3 ++- 42sh/src/exec/set_process_subshell.c | 2 +- 42sh/src/lexer/get_state_global.c | 9 +++++++-- 42sh/src/parser/add_redir.c | 4 ++-- 18 files changed, 79 insertions(+), 23 deletions(-) delete mode 100644 42sh/file create mode 100644 42sh/src/exec/launch_brace.c create mode 100644 42sh/src/exec/set_process_brace.c diff --git a/42sh/Makefile b/42sh/Makefile index 8c56fe00..b93d601d 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -82,6 +82,7 @@ exec/fd_is_valid.c\ exec/ft_exec.c\ exec/ft_findexec.c\ exec/is_function.c\ +exec/launch_brace.c\ exec/launch_builtin.c\ exec/launch_case.c\ exec/launch_file.c\ @@ -110,6 +111,7 @@ exec/redirect_less.c\ exec/redirect_lessand.c\ exec/set_exitstatus.c\ exec/set_process.c\ +exec/set_process_brace.c\ exec/set_process_case.c\ exec/set_process_cmd.c\ exec/set_process_for.c\ diff --git a/42sh/file b/42sh/file deleted file mode 100644 index f6536de2..00000000 --- a/42sh/file +++ /dev/null @@ -1 +0,0 @@ -cat: wefwewef: No such file or directory diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 64729cf1..54405e5a 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/13 17:40:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:14:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,6 +74,7 @@ union u_process_data { struct s_data_cmd cmd; struct s_data_subshell subshell; + struct s_data_subshell brace; struct s_data_subshell function; struct s_data_cond d_while; struct s_data_cond d_until; @@ -88,6 +89,7 @@ enum e_process_type PROCESS_BUILTIN, PROCESS_FILE, PROCESS_SUBSHELL, + PROCESS_BRACE, PROCESS_WHILE, PROCESS_UNTIL, PROCESS_IF, @@ -187,6 +189,7 @@ int launch_case(t_process *p); int launch_file(t_process *p); int launch_builtin(t_process *p); int launch_subshell(t_process *p); +int launch_brace(t_process *p); int launch_function(t_process *p); int launch_empty(t_process *p); diff --git a/42sh/src/builtin/builtin_export.c b/42sh/src/builtin/builtin_export.c index e20d9f8c..bdf78140 100644 --- a/42sh/src/builtin/builtin_export.c +++ b/42sh/src/builtin/builtin_export.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/15 11:39:37 by gwojda #+# #+# */ -/* Updated: 2017/03/13 18:01:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:00:58 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,7 @@ int builtin_export(const char *path, char *const av[], char *const envp[]) if ((equal = ft_strchr(av[1], '='))) { *equal = 0; - return (builtin_setenv(path, (char*[]){"setenv", av[1], equal + 1}, envp)); - } - else - { - // export doit chercher cette variable locale et la mettre dans l'env - return (0); + builtin_setenv(path, (char*[]){"setenv", av[1], equal + 1}, envp); } + return (0); } diff --git a/42sh/src/builtin/builtin_setenv.c b/42sh/src/builtin/builtin_setenv.c index 5aae2425..71126910 100644 --- a/42sh/src/builtin/builtin_setenv.c +++ b/42sh/src/builtin/builtin_setenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:25:17 by jhalford #+# #+# */ -/* Updated: 2017/03/13 18:01:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 18:10:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 9126b48d..f410ed1f 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/13 17:40:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:06:45 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 9ed829d3..960b10cd 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/03/13 14:03:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:08:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -31,6 +31,7 @@ t_itof g_execmap[] = {TK_ASSIGNEMENT_WORD, &exec_var}, {MATH, &exec_math}, {SUBSHELL, &exec_leaf}, + {TK_LBRACE, &exec_leaf}, {TK_BANG, &exec_bang}, {CMD, &exec_leaf}, {0, 0}, diff --git a/42sh/src/exec/launch_brace.c b/42sh/src/exec/launch_brace.c new file mode 100644 index 00000000..a8db3f08 --- /dev/null +++ b/42sh/src/exec/launch_brace.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* launch_brace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ +/* Updated: 2017/03/13 19:21:39 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int launch_brace(t_process *p) +{ + if (process_redirect(p)) + { + set_exitstatus(1, 1); + return (0); + } + ft_exec(&p->data.subshell.content); + return (0); +} diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/launch_builtin.c index b16f0f64..c0107239 100644 --- a/42sh/src/exec/launch_builtin.c +++ b/42sh/src/exec/launch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/11 18:16:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:15:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,10 @@ int launch_builtin(t_process *p) if (IS_PIPESINGLE(*p)) { if (process_redirect(p)) + { + set_exitstatus(1, 1); return (0); + } set_exitstatus((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env), 1); return (0); } diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 5e019ad0..669fe0f0 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/13 17:38:30 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:21:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,7 @@ t_itof g_launchmap[] = {PROCESS_BUILTIN, launch_builtin}, {PROCESS_FILE, launch_file}, {PROCESS_SUBSHELL, launch_subshell}, + {PROCESS_BRACE, launch_brace}, {PROCESS_WHILE, launch_while}, {PROCESS_UNTIL, launch_until}, {PROCESS_IF, launch_if}, diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index 087f2e73..0682f63f 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/launch_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/13 13:27:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:12:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_less.c b/42sh/src/exec/redirect_less.c index 49b8b4e2..1a59bf2e 100644 --- a/42sh/src/exec/redirect_less.c +++ b/42sh/src/exec/redirect_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:09:53 by jhalford #+# #+# */ -/* Updated: 2017/03/13 17:42:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:22:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 2e54d187..56992205 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/13 17:38:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:06:50 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process_brace.c b/42sh/src/exec/set_process_brace.c new file mode 100644 index 00000000..c6bc4e0f --- /dev/null +++ b/42sh/src/exec/set_process_brace.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* set_process_brace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/13 19:07:34 by jhalford #+# #+# */ +/* Updated: 2017/03/13 19:08:27 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + + +#include "minishell.h" + +int set_process_brace(t_process *p, t_btree *ast) +{ + p->data.subshell.content = btree_map(ast->right, &node_copy); + p->type = PROCESS_BRACE; + return (0); +} diff --git a/42sh/src/exec/set_process_map.c b/42sh/src/exec/set_process_map.c index 0c685464..e536a30d 100644 --- a/42sh/src/exec/set_process_map.c +++ b/42sh/src/exec/set_process_map.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:08:12 by wescande #+# #+# */ -/* Updated: 2017/03/13 17:39:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 19:08:25 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,6 +26,7 @@ t_itof g_setprocessmap[] = {MATH, NULL}, {SUBSHELL, &set_process_subshell}, {CMD, &set_process_cmd}, + {TK_LBRACE, &set_process_subshell}, {0, NULL} }; diff --git a/42sh/src/exec/set_process_subshell.c b/42sh/src/exec/set_process_subshell.c index b7cdb55f..f963ca73 100644 --- a/42sh/src/exec/set_process_subshell.c +++ b/42sh/src/exec/set_process_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ -/* Updated: 2017/03/08 14:59:55 by wescande ### ########.fr */ +/* Updated: 2017/03/13 19:07:18 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/get_state_global.c b/42sh/src/lexer/get_state_global.c index 5fd8532e..305e03a9 100644 --- a/42sh/src/lexer/get_state_global.c +++ b/42sh/src/lexer/get_state_global.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 20:39:06 by jhalford #+# #+# */ -/* Updated: 2017/03/07 19:33:58 by ariard ### ########.fr */ +/* Updated: 2017/03/13 19:03:43 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,8 +15,12 @@ t_lexstate get_state_global(t_lexer *lexer) { char c; + char cn; + char cl; c = lexer->str[lexer->pos]; + cn = lexer->str[lexer->pos + 1]; + cl = lexer->str[lexer->pos ? lexer->pos - 1 : 0]; if (ft_is_delim(c)) return (DELIM); else if (c == '&' || c == ';' || c == '|' || c == '!') @@ -31,7 +35,8 @@ t_lexstate get_state_global(t_lexer *lexer) return (BQUOTE); else if (c == '(' || c == ')') return (PAREN); - else if (c == '{' || c == '}') + else if ((c == '{' && cn == ' ') + || (c == '}' && cl == ' ')) return (CURLY_BRACKETS); else if (c == 0) return (END); diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 259e189e..8b0cea05 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/13 16:59:01 by ariard ### ########.fr */ +/* Updated: 2017/03/13 19:22:24 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ int isdir_sep(t_btree **ast, t_list **list) if ((node->type == CMD || node->type == TK_IO_NUMBER || node->type == TK_WHILE || node->type == TK_IF || node->type == TK_FOR || node->type == SUBSHELL - || node->type == TK_CASE || node->type == TK_RBRACE + || node->type == TK_CASE || node->type == TK_LBRACE || node->type == TK_UNTIL) && (token->type == TK_LESS || token->type == TK_GREAT || token->type == TK_GREATAND || token->type == TK_LESSAND