ajout des free en fonction du process

This commit is contained in:
wescande 2017-03-08 02:40:58 +01:00
parent 3a186407b1
commit 157519224d
9 changed files with 88 additions and 23 deletions

View file

@ -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\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -6,14 +6,15 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_cond.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_subshell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}