diff --git a/42sh/src/exec/exec_and_if.c b/42sh/src/exec/exec_and_if.c index 32267ccf..d1b714ac 100644 --- a/42sh/src/exec/exec_and_if.c +++ b/42sh/src/exec/exec_and_if.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_and_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 20:52:28 by jhalford #+# #+# */ -/* Updated: 2017/03/10 14:26:32 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:40:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int exec_and_if(t_btree **ast) { - /* t_data *data; */ t_exec *exec; exec = &data_singleton()->exec; @@ -23,24 +22,5 @@ int exec_and_if(t_btree **ast) exec->attrs &= ~EXEC_OR_IF; exec->attrs |= EXEC_AND_IF; ft_exec(&(*ast)->right); - - /* data = data_singleton(); */ - /* if (data->exec.aol_status == NULL */ - /* || (data->exec.aol_search == TK_AND_IF */ - /* && *data->exec.aol_status == '0') */ - /* || (data->exec.aol_search == TK_OR_IF */ - /* && *data->exec.aol_status != '0')) */ - /* { */ - /* ft_exec(&(*ast)->left); */ - /* data->exec.aol_status = ft_getenv(data->env, "?"); */ - /* } */ - /* data->exec.aol_search = TK_AND_IF; */ - /* if (*data->exec.aol_status == '0' */ - /* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */ - /* ft_exec(&(*ast)->right); */ - /* data->exec.aol_status = NULL; */ - /* data->exec.aol_search = 0; */ - -// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_bang.c b/42sh/src/exec/exec_bang.c index 3939d1a3..cce5d557 100644 --- a/42sh/src/exec/exec_bang.c +++ b/42sh/src/exec/exec_bang.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/10 14:46:27 by ariard #+# #+# */ -/* Updated: 2017/03/10 16:25:35 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:41:04 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int exec_bang(t_btree **ast) exec = &data_singleton()->exec; push(&exec->op_stack, TK_BANG); - ft_exec(&(*ast)->left); + ft_exec(&(*ast)->left); ft_exec(&(*ast)->right); set_exitstatus(ft_atoi(ft_getenv(data_singleton()->env, "?")) ? 0 : 1, 1); return (0); diff --git a/42sh/src/exec/exec_case_branch.c b/42sh/src/exec/exec_case_branch.c index 9335cdaa..9a618168 100644 --- a/42sh/src/exec/exec_case_branch.c +++ b/42sh/src/exec/exec_case_branch.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:33:45 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:21:45 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:42:17 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,19 +18,15 @@ int exec_case_branch(t_btree **ast) char **av; t_exec *exec; - DG("exec branch case"); exec = &data_singleton()->exec; if (EXEC_IS_CASE_BRANCH(exec->attrs)) return (0); node = (*ast)->item; av = token_to_argv(node->data.cmd.token, 1); - DG("compare pattern %s ", av[0]); - DG("and case %s", ((char **)exec->case_pattern)[0]); - DG(); if (ft_strcmp(av[0], ((char **)exec->case_pattern)[0]) == 0) - { + { exec->attrs |= EXEC_CASE_BRANCH; - ft_exec(&(*ast)->right); + ft_exec(&(*ast)->right); } return (0); } diff --git a/42sh/src/exec/exec_or_if.c b/42sh/src/exec/exec_or_if.c index 50def42a..5885eb6d 100644 --- a/42sh/src/exec/exec_or_if.c +++ b/42sh/src/exec/exec_or_if.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_or_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 21:06:17 by jhalford #+# #+# */ -/* Updated: 2017/03/05 15:18:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:40:15 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,6 @@ int exec_or_if(t_btree **ast) { - /* t_data *data; */ t_exec *exec; exec = &data_singleton()->exec; @@ -23,24 +22,5 @@ int exec_or_if(t_btree **ast) exec->attrs &= ~EXEC_AND_IF; exec->attrs = EXEC_OR_IF; ft_exec(&(*ast)->right); - - /* data = data_singleton(); */ - /* if (data->exec.aol_status == NULL */ - /* || (data->exec.aol_search == TK_AND_IF */ - /* && *data->exec.aol_status == '0') */ - /* || (data->exec.aol_search == TK_OR_IF */ - /* && *data->exec.aol_status != '0')) */ - /* { */ - /* ft_exec(&(*ast)->left); */ - /* data->exec.aol_status = ft_getenv(data->env, "?"); */ - /* } */ - /* data->exec.aol_search = TK_OR_IF; */ - /* if (*data->exec.aol_status != '0' */ - /* || ((t_astnode*)(*ast)->right->item)->type != TK_COMMAND) */ - /* ft_exec(&(*ast)->right); */ - /* data->exec.aol_status = NULL; */ - /* data->exec.aol_search = 0; */ - -// btree_delone(ast, &ast_free); return (0); } diff --git a/42sh/src/exec/exec_pipe.c b/42sh/src/exec/exec_pipe.c index 3668da9e..0c015741 100644 --- a/42sh/src/exec/exec_pipe.c +++ b/42sh/src/exec/exec_pipe.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* exec_pipe.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 21:13:23 by jhalford #+# #+# */ -/* Updated: 2017/03/03 16:27:48 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:42:40 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,5 @@ int exec_pipe(t_btree **ast) push(&exec->op_stack, TK_PIPE); ft_exec(&(*ast)->left); ft_exec(&(*ast)->right); - /* btree_delone(ast, &ast_free); */ return (0); } diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c index 45e91663..161bf6a0 100644 --- a/42sh/src/exec/exec_reset.c +++ b/42sh/src/exec/exec_reset.c @@ -3,28 +3,37 @@ /* ::: :::::::: */ /* exec_reset.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ -/* Updated: 2017/03/20 11:35:49 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:09:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int exec_reset(void) +static void print_error(char *std) +{ + ft_dprintf(2, "{red}%s: internal fcntl %s error errno=%i{eoc}\n", + SHELL_NAME, std, errno); +} + +int exec_reset(void) { t_exec *exec; t_jobc *jobc; exec = &data_singleton()->exec; jobc = &data_singleton()->jobc; - if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) - ft_dprintf(2, "{red}%s: internal fcntl STDIN error errno=%i{eoc}\n", SHELL_NAME, errno); - if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) - ft_dprintf(2, "{red}%s: internal fcntl STDOUT error errno=%i{eoc}\n", SHELL_NAME, errno); - if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1 && errno != EBADF) - ft_dprintf(2, "{red}%s: internal fcntl STDERR error errno=%i{eoc}\n", SHELL_NAME, errno); + if (errno != EBADF) + { + if ((exec->fd_save[0] = fcntl(STDIN, F_DUPFD_CLOEXEC, 10)) == -1) + print_error("STDIN"); + if ((exec->fd_save[1] = fcntl(STDOUT, F_DUPFD_CLOEXEC, 10)) == -1) + print_error("STDOUT"); + if ((exec->fd_save[2] = fcntl(STDERR, F_DUPFD_CLOEXEC, 10)) == -1) + print_error("STDERR"); + } exec->op_stack = NULL; exec->fdin = STDIN; exec->attrs = 0; diff --git a/42sh/src/exec/exec_var.c b/42sh/src/exec/exec_var.c index 9b1136c2..dbeaea7c 100644 --- a/42sh/src/exec/exec_var.c +++ b/42sh/src/exec/exec_var.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 11:12:05 by ariard #+# #+# */ -/* Updated: 2017/03/14 23:55:40 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:43:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,16 +20,16 @@ static int set_var(char *stream, char **var, char **value) return (0); } -int exec_var(t_btree **ast) +int exec_var(t_btree **ast) { t_astnode *node; - char **av; + char **av; char *var; char *value; - + node = (*ast)->item; av = token_to_argv(node->data.cmd.token, 1); - set_var(av[0], &var, &value); + set_var(av[0], &var, &value); if (ft_getenv(data_singleton()->env, var)) return (0); builtin_setenv("internal", (char*[]){"local", var, value, 0}, NULL); diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index fdb7ce33..7a780c82 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ -/* Updated: 2017/03/20 14:06:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:51:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,8 +30,8 @@ void *node_copy(void *data) new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy); new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); } - if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE - || old->type == FNAME) + if (old->type == TK_FOR || old->type == TK_PAREN_OPEN + || old->type == TK_CASE || old->type == FNAME) new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); return (new); } diff --git a/42sh/src/exec/pfree_cmd.c b/42sh/src/exec/pfree_cmd.c index 9715ef1a..ed75ed62 100644 --- a/42sh/src/exec/pfree_cmd.c +++ b/42sh/src/exec/pfree_cmd.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_cmd.c :+: :+: :+: */ +/* pfree_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:50:07 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_cond.c b/42sh/src/exec/pfree_cond.c index 2dae0996..69c185e9 100644 --- a/42sh/src/exec/pfree_cond.c +++ b/42sh/src/exec/pfree_cond.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_cond.c :+: :+: :+: */ +/* pfree_cond.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:26:31 by wescande #+# #+# */ -/* Updated: 2017/03/15 02:04:14 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:49:52 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_list.c b/42sh/src/exec/pfree_list.c index ac896c97..22c8a012 100644 --- a/42sh/src/exec/pfree_list.c +++ b/42sh/src/exec/pfree_list.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_list.c :+: :+: :+: */ +/* pfree_list.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:37:04 by wescande #+# #+# */ -/* Updated: 2017/03/15 01:05:43 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:50:03 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pfree_subshell.c b/42sh/src/exec/pfree_subshell.c index d9968512..1b1357d8 100644 --- a/42sh/src/exec/pfree_subshell.c +++ b/42sh/src/exec/pfree_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pfree_subshell.c :+: :+: :+: */ +/* pfree_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:38:12 by wescande #+# #+# */ -/* Updated: 2017/03/13 22:31:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:50:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_brace.c b/42sh/src/exec/plaunch_brace.c index 791104d8..0406b81e 100644 --- a/42sh/src/exec/plaunch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_brace.c :+: :+: :+: */ +/* plaunch_brace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:35:24 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_builtin.c b/42sh/src/exec/plaunch_builtin.c index f4506d45..00215451 100644 --- a/42sh/src/exec/plaunch_builtin.c +++ b/42sh/src/exec/plaunch_builtin.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_builtin.c :+: :+: :+: */ +/* plaunch_builtin.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:22:12 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_case.c b/42sh/src/exec/plaunch_case.c index 413c2ca8..753d221c 100644 --- a/42sh/src/exec/plaunch_case.c +++ b/42sh/src/exec/plaunch_case.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_case.c :+: :+: :+: */ +/* plaunch_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:17:07 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:14 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_empty.c b/42sh/src/exec/plaunch_empty.c index 39173fb8..c550c3c8 100644 --- a/42sh/src/exec/plaunch_empty.c +++ b/42sh/src/exec/plaunch_empty.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_empty.c :+: :+: :+: */ +/* plaunch_empty.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:23:18 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:16 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,4 +17,3 @@ int plaunch_empty(t_process *p) (void)p; return (0); } - diff --git a/42sh/src/exec/plaunch_file.c b/42sh/src/exec/plaunch_file.c index 0ec58d4d..97059495 100644 --- a/42sh/src/exec/plaunch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_file.c :+: :+: :+: */ +/* plaunch_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/17 20:22:38 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:17 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_for.c b/42sh/src/exec/plaunch_for.c index c7c4d510..21e4f2bc 100644 --- a/42sh/src/exec/plaunch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/15 00:49:20 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:16:46 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:51:47 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ int plaunch_for(t_process *p) av = token_to_argv(temp, 1); while (av[++i]) { - builtin_setenv("setenv", (char*[]){"local" ,var, av[i], 0}, + builtin_setenv("setenv", (char*[]){"local", var, av[i], 0}, NULL); ft_exec(&p->data.d_for.content); } diff --git a/42sh/src/exec/plaunch_function.c b/42sh/src/exec/plaunch_function.c index d312345e..af12c567 100644 --- a/42sh/src/exec/plaunch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_function.c :+: :+: :+: */ +/* plaunch_function.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:29:36 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:21 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_if.c b/42sh/src/exec/plaunch_if.c index dccd5209..7b941d54 100644 --- a/42sh/src/exec/plaunch_if.c +++ b/42sh/src/exec/plaunch_if.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_if.c :+: :+: :+: */ +/* plaunch_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:30:36 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:23 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_subshell.c b/42sh/src/exec/plaunch_subshell.c index ef8cd15a..980a6232 100644 --- a/42sh/src/exec/plaunch_subshell.c +++ b/42sh/src/exec/plaunch_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_subshell.c :+: :+: :+: */ +/* plaunch_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/17 20:28:08 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_until.c b/42sh/src/exec/plaunch_until.c index 4fe8cadb..d9e55135 100644 --- a/42sh/src/exec/plaunch_until.c +++ b/42sh/src/exec/plaunch_until.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_until.c :+: :+: :+: */ +/* plaunch_until.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ -/* Updated: 2017/03/18 01:52:33 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:27 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/plaunch_while.c b/42sh/src/exec/plaunch_while.c index a98fe146..696059de 100644 --- a/42sh/src/exec/plaunch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* plaunch_while.c :+: :+: :+: */ +/* plaunch_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/18 01:48:53 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:50:29 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_launch.c b/42sh/src/exec/process_launch.c index 1b5f89ae..4a7c5825 100644 --- a/42sh/src/exec/process_launch.c +++ b/42sh/src/exec/process_launch.c @@ -3,16 +3,16 @@ /* ::: :::::::: */ /* process_launch.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:57:26 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:58:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int do_the_muther_forker(t_process *p) +int do_the_muther_forker(t_process *p) { pid_t pid; @@ -25,9 +25,8 @@ int do_the_muther_forker(t_process *p) return (pid); if (!p) return (pid); - DG("START OF FORK"); if (process_redirect(p)) - exit (1); + exit(1); process_setgroup(p, 0); process_setsig(); exec_reset(); @@ -51,19 +50,16 @@ static int do_the_fork_if_i_have_to(t_process *p) return (do_the_muther_forker(p)); } -int process_launch(t_process *p) +int process_launch(t_process *p) { pid_t pid; - DG("p->type=%i", p->type); p->state = PROCESS_RUNNING; if (!(pid = do_the_fork_if_i_have_to(p))) { - DG("launcher did not fork!"); process_resetfds(p); return (1); } - DG("launcher forked! with : %d ", pid); p->pid = pid; process_setgroup(p, pid); if (p->fdin != STDIN) diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 7afcb122..b8ac4278 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* process_redirect.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/16 23:28:44 by ariard ### ########.fr */ +/* Updated: 2017/03/20 15:57:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,36 +23,36 @@ t_itof g_redirmap[] = {0, NULL}, }; -int process_redirect(t_process *p) +static void process_close(int fd1, int fd2) +{ + if (fd1 != fd2) + close(fd1); +} + +int process_redirect(t_process *p) { t_list *redirs; t_redir *redir; int i; redirs = p->redirs; - if (p->to_close != STDIN) - close(p->to_close); + process_close(p->to_close, STDIN); while (redirs) { redir = redirs->content; if (redir->n > 9) return (bad_fd(redir->n)); - i = 0; - while (g_redirmap[i].id) - { + i = -1; + while (g_redirmap[++i].id) if (g_redirmap[i].id == redir->type) { if ((g_redirmap[i].f)(redir)) return (1); break ; } - i++; - } redirs = redirs->next; } - if (p->fdin != STDIN) - dup2_close(p->fdin, STDIN); - if (p->fdout != STDOUT) - dup2_close(p->fdout, STDOUT); + process_close(p->fdin, STDIN); + process_close(p->fdout, STDOUT); return (0); } diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index fbb00729..2eebdef3 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process.c :+: :+: :+: */ +/* process_set.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:51:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:02:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -56,7 +56,7 @@ int process_set(t_process *p, t_btree *ast) && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0) || (EXEC_IS_OR_IF(exec->attrs) && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) - return (1); + return (1); fds[PIPE_WRITE] = STDOUT; fds[PIPE_READ] = STDIN; if (op == TK_PIPE) @@ -69,6 +69,7 @@ int process_set(t_process *p, t_btree *ast) exec->fdin = fds[PIPE_READ]; if (!ast) return (0); - p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); + p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, + &redir_copy); return (process_set_spec(p, ast)); } diff --git a/42sh/src/exec/process_setgroup.c b/42sh/src/exec/process_setgroup.c index b5424a8f..1632df9c 100644 --- a/42sh/src/exec/process_setgroup.c +++ b/42sh/src/exec/process_setgroup.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* process_setgroup.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:48:10 by jhalford #+# #+# */ -/* Updated: 2017/03/19 14:04:57 by wescande ### ########.fr */ +/* Updated: 2017/03/20 15:58:33 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,15 +23,10 @@ int process_setgroup(t_process *p, pid_t pid) j = &data->exec.job; if (!SH_IS_INTERACTIVE(data_singleton()->opts)) return (0); - DG("setpgid(%i, %i)", pid, j->pgid); if (setpgid(pid, j->pgid) == -1) - ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", SHELL_NAME, errno); - /* if (JOB_IS_FG(j->attrs)) */ + ft_dprintf(2, "{red}%s: internal setpgid() errno=%i{eoc}\n", + SHELL_NAME, errno); if (pid == 0 && JOB_IS_FG(j->attrs)) - { - DG("tcsetpgrp[%i]", j->pgid); tcsetpgrp(STDIN, j->pgid); - DG("after tcsetpgrp"); - } return (0); } diff --git a/42sh/src/exec/pset_brace.c b/42sh/src/exec/pset_brace.c index a61a3792..226297bb 100644 --- a/42sh/src/exec/pset_brace.c +++ b/42sh/src/exec/pset_brace.c @@ -1,16 +1,15 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_brace.c :+: :+: :+: */ +/* pset_brace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/13 19:07:34 by jhalford #+# #+# */ -/* Updated: 2017/03/20 10:29:06 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:58:50 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ - #include "minishell.h" int pset_brace(t_process *p, t_btree *ast) diff --git a/42sh/src/exec/pset_case.c b/42sh/src/exec/pset_case.c index 5e373168..8719f5d8 100644 --- a/42sh/src/exec/pset_case.c +++ b/42sh/src/exec/pset_case.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_case.c :+: :+: :+: */ +/* pset_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:27:59 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:59:05 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,8 +14,8 @@ int pset_case(t_process *p, t_btree *ast) { - DG("set case"); - p->data.d_case.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); + p->data.d_case.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, + tab_esc_copy); p->data.d_case.content = btree_map(ast->right, &node_copy); p->type = PROCESS_CASE; return (0); diff --git a/42sh/src/exec/pset_for.c b/42sh/src/exec/pset_for.c index 19573f9c..c1b14dbb 100644 --- a/42sh/src/exec/pset_for.c +++ b/42sh/src/exec/pset_for.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_for.c :+: :+: :+: */ +/* pset_for.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:28:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 15:59:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,8 @@ int pset_for(t_process *p, t_btree *ast) { - p->data.d_for.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, tab_esc_copy); + p->data.d_for.token = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.token, + tab_esc_copy); p->data.d_for.content = btree_map(ast->right, &node_copy); p->type = PROCESS_FOR; return (0); diff --git a/42sh/src/exec/pset_if.c b/42sh/src/exec/pset_if.c index 130af429..af80d078 100644 --- a/42sh/src/exec/pset_if.c +++ b/42sh/src/exec/pset_if.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_if.c :+: :+: :+: */ +/* pset_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/20 10:27:36 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:35 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_subshell.c b/42sh/src/exec/pset_subshell.c index a14163fd..7236a58c 100644 --- a/42sh/src/exec/pset_subshell.c +++ b/42sh/src/exec/pset_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* pset_sub.c :+: :+: :+: */ +/* pset_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ -/* Updated: 2017/03/20 12:39:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:37 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/pset_until.c b/42sh/src/exec/pset_until.c index 7c086e7f..df32b275 100644 --- a/42sh/src/exec/pset_until.c +++ b/42sh/src/exec/pset_until.c @@ -1,3 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pset_until.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gwojda +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/20 16:26:43 by gwojda #+# #+# */ +/* Updated: 2017/03/20 16:26:44 by gwojda ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "minishell.h" int pset_until(t_process *p, t_btree *ast) diff --git a/42sh/src/exec/pset_while.c b/42sh/src/exec/pset_while.c index 34777b5f..c62b1180 100644 --- a/42sh/src/exec/pset_while.c +++ b/42sh/src/exec/pset_while.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* pset_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/20 12:39:07 by jhalford #+# #+# */ -/* Updated: 2017/03/20 12:39:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:47 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_copy.c b/42sh/src/exec/redir_copy.c index 5dd758c9..88a86d3a 100644 --- a/42sh/src/exec/redir_copy.c +++ b/42sh/src/exec/redir_copy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ -/* Updated: 2017/03/20 12:21:26 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:50 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c index dcc57dca..afae3991 100644 --- a/42sh/src/exec/redir_free.c +++ b/42sh/src/exec/redir_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ -/* Updated: 2017/03/20 12:38:53 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:26:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */