diff --git a/42sh/Makefile b/42sh/Makefile index 716bbc9f..008572f3 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -185,6 +185,10 @@ job-control/mark_job_as_running.c\ job-control/process_cmp_pid.c\ job-control/process_format.c\ job-control/process_free.c\ +job-control/process_free_cmd.c\ +job-control/process_free_cond.c\ +job-control/process_free_list.c\ +job-control/process_free_subshell.c\ job-control/put_job_in_background.c\ job-control/put_job_in_foreground.c\ job-control/sigchld_handler.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 81caf07b..ea85b168 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/08 01:48:29 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:05:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,9 +75,8 @@ union u_process_data struct s_data_cmd cmd; struct s_data_subshell subshell; struct s_data_cond d_while; + struct s_data_cond d_until; struct s_data_cond d_if; - struct s_data_cond d_else; - struct s_data_cond d_elif; struct s_data_list d_for; struct s_data_list d_case; }; @@ -192,7 +191,10 @@ int error_badidentifier(char *name); ** Mapping pour free les process */ void process_free(void *content, size_t content_size); -void process_free_cmd(t_process *p); +int process_free_cmd(t_process *p); +int process_free_cond(t_process *p); +int process_free_list(t_process *p); +int process_free_subshell(t_process *p); /* ** Mapping pour launch les process diff --git a/42sh/src/exec/launch_until.c b/42sh/src/exec/launch_until.c index 66a23a36..21fc64a1 100644 --- a/42sh/src/exec/launch_until.c +++ b/42sh/src/exec/launch_until.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ -/* Updated: 2017/03/07 22:06:50 by wescande ### ########.fr */ +/* Updated: 2017/03/08 02:35:09 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,13 @@ static int do_until(t_process *p) { int ret; - ft_exec(&p->data.d_while.condition); + ft_exec(&p->data.d_until.condition); ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0")) { - ft_exec(&p->data.d_while.content); + ft_exec(&p->data.d_until.content); ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); - ft_exec(&p->data.d_while.condition); + ft_exec(&p->data.d_until.condition); } return (ret); } diff --git a/42sh/src/exec/set_process_until.c b/42sh/src/exec/set_process_until.c index 4d036585..20529720 100644 --- a/42sh/src/exec/set_process_until.c +++ b/42sh/src/exec/set_process_until.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:22:24 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:54:37 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:06:03 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index 8260861f..23471c08 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/08 02:06:04 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:07:01 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,13 +16,13 @@ t_itof g_freemap[] = { {PROCESS_FUNCTION, NULL}, {PROCESS_BUILTIN, NULL}, - {PROCESS_FILE, NULL}, - {PROCESS_SUBSHELL, NULL}, - {PROCESS_WHILE, NULL}, - {PROCESS_UNTIL, NULL}, - {PROCESS_IF, NULL}, - {PROCESS_FOR, NULL}, - {PROCESS_CASE, NULL}, + {PROCESS_FILE, process_free_cmd}, + {PROCESS_SUBSHELL, process_free_subshell}, + {PROCESS_WHILE, process_free_cond}, + {PROCESS_UNTIL, process_free_cond}, + {PROCESS_IF, process_free_cond}, + {PROCESS_FOR, process_free_list}, + {PROCESS_CASE, process_free_list}, {0, NULL} }; @@ -31,14 +31,11 @@ void process_free(void *content, size_t content_size) t_process *p; p = content; - DG(); (void)content_size; if (p->type >= PROCESS_MAX) return ; - if (!g_freemap[p->type].f) - return ; - (g_freemap[p->type].f)(p); + if (g_freemap[p->type].f) + (g_freemap[p->type].f)(p); ft_lstdel(&p->redirs, ft_lst_cfree); free(p); - DG(); } diff --git a/42sh/src/job-control/process_free_cmd.c b/42sh/src/job-control/process_free_cmd.c index 1989df65..96efd6e1 100644 --- a/42sh/src/job-control/process_free_cmd.c +++ b/42sh/src/job-control/process_free_cmd.c @@ -6,14 +6,15 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ -/* Updated: 2017/03/08 00:59:38 by wescande ### ########.fr */ +/* Updated: 2017/03/08 02:31:01 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -void process_free_cmd(t_process *p) +int process_free_cmd(t_process *p) { ft_strdel(&p->data.cmd.path); ft_sstrfree(p->data.cmd.av); + return (0); } diff --git a/42sh/src/job-control/process_free_cond.c b/42sh/src/job-control/process_free_cond.c new file mode 100644 index 00000000..69624104 --- /dev/null +++ b/42sh/src/job-control/process_free_cond.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_free_cond.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 02:26:31 by wescande #+# #+# */ +/* Updated: 2017/03/08 02:39:12 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int process_free_cond(t_process *p) +{ + btree_del(&p->data.d_while.condition, &ast_free); + btree_del(&p->data.d_while.content, &ast_free); + return (0); +} diff --git a/42sh/src/job-control/process_free_list.c b/42sh/src/job-control/process_free_list.c new file mode 100644 index 00000000..d0b05f69 --- /dev/null +++ b/42sh/src/job-control/process_free_list.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_free_list.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 02:37:04 by wescande #+# #+# */ +/* Updated: 2017/03/08 02:37:52 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int process_free_list(t_process *p) +{ + ft_ld_del(&p->data.d_for.list_word, &ft_tabdel); + btree_del(&p->data.d_for.content, &ast_free); + return (0); +} diff --git a/42sh/src/job-control/process_free_subshell.c b/42sh/src/job-control/process_free_subshell.c new file mode 100644 index 00000000..7fb49c4b --- /dev/null +++ b/42sh/src/job-control/process_free_subshell.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_free_subshell.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 02:38:12 by wescande #+# #+# */ +/* Updated: 2017/03/08 02:38:27 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int process_free_subshell(t_process *p) +{ + btree_del(&p->data.d_while.content, &ast_free); + return (0); +}