From 157519224db12be17d14b6cbb867d032b4e83fd0 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 8 Mar 2017 02:40:58 +0100 Subject: [PATCH] ajout des free en fonction du process --- 42sh/Makefile | 4 ++++ 42sh/includes/exec.h | 10 ++++++---- 42sh/src/exec/launch_until.c | 8 ++++---- 42sh/src/exec/set_process_until.c | 6 +++--- 42sh/src/job-control/process_free.c | 19 +++++++++---------- 42sh/src/job-control/process_free_cmd.c | 5 +++-- 42sh/src/job-control/process_free_cond.c | 20 ++++++++++++++++++++ 42sh/src/job-control/process_free_list.c | 20 ++++++++++++++++++++ 42sh/src/job-control/process_free_subshell.c | 19 +++++++++++++++++++ 9 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 42sh/src/job-control/process_free_cond.c create mode 100644 42sh/src/job-control/process_free_list.c create mode 100644 42sh/src/job-control/process_free_subshell.c diff --git a/42sh/Makefile b/42sh/Makefile index fd6c392f..b162da3b 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -184,6 +184,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 b49ca82e..a9809369 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:04:12 by wescande ### ########.fr */ +/* Updated: 2017/03/08 02:38:42 by wescande ### ########.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; }; @@ -190,7 +189,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 1238d828..17a00488 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/07 22:22:36 by wescande ### ########.fr */ +/* Updated: 2017/03/08 02:35:27 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,8 +15,8 @@ int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd) { (void)cmd; - p->data.d_while.condition = ast_copy(ast->left); - p->data.d_while.content = ast_copy(ast->right); + p->data.d_until.condition = ast_copy(ast->left); + p->data.d_until.content = ast_copy(ast->right); p->type = PROCESS_UNTIL; return (0); } diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index 7f5706ac..77eb5b96 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 01:38:58 by wescande ### ########.fr */ +/* Updated: 2017/03/08 02:38:47 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,12 +17,12 @@ t_itof g_freemap[] = {PROCESS_FUNCTION, NULL}, {PROCESS_BUILTIN, NULL}, {PROCESS_FILE, process_free_cmd}, - {PROCESS_SUBSHELL, NULL}, - {PROCESS_WHILE, NULL}, - {PROCESS_UNTIL, NULL}, - {PROCESS_IF, NULL}, - {PROCESS_FOR, NULL}, - {PROCESS_CASE, NULL}, + {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} }; @@ -34,9 +34,8 @@ void process_free(void *content, size_t content_size) (void)content_size; if (p->type >= PROCESS_MAX) return ; - if (!g_launchmap[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); } 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); +}