diff --git a/42sh/Makefile b/42sh/Makefile index 58949194..716bbc9f 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -85,6 +85,8 @@ exec/launch_file.c\ exec/launch_for.c\ exec/launch_if.c\ exec/launch_process.c\ +exec/launch_subshell.c\ +exec/launch_until.c\ exec/launch_while.c\ exec/mark_process_status.c\ exec/process_redirect.c\ @@ -108,6 +110,8 @@ exec/set_process_cmd.c\ exec/set_process_for.c\ exec/set_process_if.c\ exec/set_process_map.c\ +exec/set_process_subshell.c\ +exec/set_process_until.c\ exec/set_process_while.c\ exec/token_to_argv.c\ glob/command_getoutput.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index fc0a5419..81caf07b 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:00:34 by ariard ### ########.fr */ +/* Updated: 2017/03/08 01:48:29 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -65,15 +65,21 @@ struct s_data_list t_btree *content; }; +struct s_data_subshell +{ + t_btree *content; +}; + union u_process_data { - struct s_data_cmd cmd; - struct s_data_cond d_while; - 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; + struct s_data_cmd cmd; + struct s_data_subshell subshell; + struct s_data_cond d_while; + 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; }; enum e_process_type @@ -83,15 +89,18 @@ enum e_process_type PROCESS_FILE, PROCESS_SUBSHELL, PROCESS_WHILE, + PROCESS_UNTIL, PROCESS_IF, PROCESS_FOR, PROCESS_CASE, + PROCESS_MAX }; typedef enum e_process_type t_process_type; typedef union u_process_data t_process_data; typedef struct s_data_cond t_data_while; typedef struct s_data_cond t_data_if; +typedef struct s_data_cond t_data_if; struct s_process { @@ -150,7 +159,6 @@ int exec_math(t_btree **ast); int process_setexec(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); -void process_free(void *content, size_t content_size); void process_reset(t_process *p); void process_resetfds(void); @@ -180,16 +188,24 @@ int add_new_job(t_job *job); 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); + /* ** Mapping pour launch les process */ int launch_process(t_process *p); int launch_if(t_process *p); int launch_while(t_process *p); +int launch_until(t_process *p); int launch_for(t_process *p); int launch_case(t_process *p); int launch_file(t_process *p); int launch_builtin(t_process *p); +int launch_subshell(t_process *p); /* ** Mapping pour set les process @@ -197,4 +213,11 @@ int launch_builtin(t_process *p); int set_process(t_process *p, t_btree *ast); int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd); +int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd); +int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd); +int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd); +int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd); +int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd); +int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd); + #endif diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 8bd09d87..95e2be0c 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/07 20:57:19 by wescande ### ########.fr */ +/* Updated: 2017/03/08 00:22:56 by wescande ### ########.fr */ /* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -118,7 +118,6 @@ enum e_sym TK_IO_NUMBER, TK_DLESSDASH, TK_LESSGREAT, - TK_SUBSHELL, TK_CASE, TK_IN, TK_ESAC, diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index e237cb99..9a0ae4fd 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/07 17:34:51 by jhalford ### ########.fr */ +/* Updated: 2017/03/07 21:30:29 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,9 +17,11 @@ int exec_leaf(t_btree **ast) t_process p; t_job *job; + DG("in exec leaf"); job = &data_singleton()->exec.job; if (set_process(&p, *ast)) return (1); + DG("set_process done"); if (!(launch_process(&p))) { job_addprocess(&p); diff --git a/42sh/src/exec/exec_until.c b/42sh/src/exec/exec_until.c index c8b4943a..a26563e9 100644 --- a/42sh/src/exec/exec_until.c +++ b/42sh/src/exec/exec_until.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 20:42:20 by ariard #+# #+# */ -/* Updated: 2017/03/04 18:16:38 by ariard ### ########.fr */ +/* Updated: 2017/03/08 02:09:21 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 127b8cd5..87b37ab5 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/07 22:49:00 by ariard ### ########.fr */ +/* Updated: 2017/03/08 01:48:55 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ t_itof g_execmap[] = {TK_PAREN_OPEN, &exec_case_branch}, {TK_ASSIGNEMENT_WORD, &exec_var}, {MATH, &exec_math}, - /* {TK_SUBSHELL, &exec_leaf}, */ + {SUBSHELL, &exec_leaf}, {CMD, &exec_leaf}, {0, 0}, }; @@ -44,6 +44,7 @@ int ft_exec(t_btree **ast) if (!*ast) return (0); item = (*ast)->item; + DG("COMPARE : %d vs %d (SUBSHEELLL)", item->type, SUBSHELL); while (g_execmap[i].id) { if (item->type == g_execmap[i].id) diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 80c990b3..afe5cb81 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/07 20:58:31 by wescande ### ########.fr */ +/* Updated: 2017/03/07 21:33:56 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ int launch_file(t_process *p) { int pid; + DG("in file"); pid = fork(); if (pid == 0) { diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index a677f76d..72f080fd 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/07 21:07:33 by wescande ### ########.fr */ +/* Updated: 2017/03/08 00:11:15 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,9 @@ t_itof g_launchmap[] = {PROCESS_FUNCTION, NULL}, {PROCESS_BUILTIN, launch_builtin}, {PROCESS_FILE, launch_file}, - {PROCESS_SUBSHELL, NULL}, + {PROCESS_SUBSHELL, launch_subshell}, {PROCESS_WHILE, launch_while}, + {PROCESS_UNTIL, launch_until}, {PROCESS_IF, launch_if}, {PROCESS_FOR, launch_for}, {PROCESS_CASE, launch_case}, @@ -27,9 +28,21 @@ t_itof g_launchmap[] = int launch_process(t_process *p) { - int i; +// int i; int pid; + if (p->type >= PROCESS_MAX) + return (-1); + if (!g_launchmap[p->type].f) + return (-1); + p->attrs &= ~PROCESS_STATE_MASK; + p->attrs |= PROCESS_RUNNING; + if (!(pid = (*g_launchmap[p->type].f)(p))) + return (-1); + p->pid = pid; + process_setgroup(p, pid); + return (0); + /* i = 0; while (g_launchmap[i].id) { @@ -49,4 +62,5 @@ int launch_process(t_process *p) i++; } return (-1); + */ } diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c new file mode 100644 index 00000000..aa2f481d --- /dev/null +++ b/42sh/src/exec/launch_subshell.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* launch_subshell.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ +/* Updated: 2017/03/08 00:32:13 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int do_subshell(t_process *p) +{ + ft_exec(&p->data.subshell.content); + return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); +} + +int launch_subshell(t_process *p) +{ + pid_t pid; + + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + { + pid = fork(); + if (pid == 0) + { + data_singleton()->opts &= ~SH_INTERACTIVE; + data_singleton()->opts &= ~SH_OPTS_JOBC; + exit(do_subshell(p)); + } + else if (pid > 0) + return (pid); + } + else + do_subshell(p); + return (0); +} diff --git a/42sh/src/exec/launch_until.c b/42sh/src/exec/launch_until.c new file mode 100644 index 00000000..66a23a36 --- /dev/null +++ b/42sh/src/exec/launch_until.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* launch_until.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ +/* Updated: 2017/03/07 22:06:50 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int do_until(t_process *p) +{ + int ret; + + ft_exec(&p->data.d_while.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); + ret = ft_atoi(ft_getenv(data_singleton()->env, "?")); + ft_exec(&p->data.d_while.condition); + } + return (ret); +} + +int launch_until(t_process *p) +{ + pid_t pid; + + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + { + pid = fork(); + if (pid == 0) + { + data_singleton()->opts &= ~SH_INTERACTIVE; + data_singleton()->opts &= ~SH_OPTS_JOBC; + exit(do_until(p)); + } + else if (pid > 0) + return (pid); + } + else + do_until(p); + return (0); +} diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 2f4ba13a..4242fb47 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:54:13 by wescande ### ########.fr */ +/* Updated: 2017/03/07 21:44:37 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process_case.c b/42sh/src/exec/set_process_case.c index 8e5b4e42..e7626df9 100644 --- a/42sh/src/exec/set_process_case.c +++ b/42sh/src/exec/set_process_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:01:37 by ariard ### ########.fr */ +/* Updated: 2017/03/08 01:49:48 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,6 @@ int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd) (void)cmd; p->data.d_case.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, 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/set_process_cmd.c b/42sh/src/exec/set_process_cmd.c index e66d1645..4a7c6a1b 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/set_process_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:12:31 by wescande ### ########.fr */ +/* Updated: 2017/03/07 21:44:40 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process_for.c b/42sh/src/exec/set_process_for.c index cc8767a7..66489f57 100644 --- a/42sh/src/exec/set_process_for.c +++ b/42sh/src/exec/set_process_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:02:15 by ariard ### ########.fr */ +/* Updated: 2017/03/08 01:50:33 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,6 @@ int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd) (void)cmd; p->data.d_for.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, 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/set_process_if.c b/42sh/src/exec/set_process_if.c index 792611b5..0fae0f0a 100644 --- a/42sh/src/exec/set_process_if.c +++ b/42sh/src/exec/set_process_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/08 00:59:08 by ariard ### ########.fr */ +/* Updated: 2017/03/08 01:51:09 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,6 @@ int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd) (void)cmd; p->data.d_if.condition = btree_map(ast->left, &node_copy); p->data.d_if.content = btree_map(ast->right, &node_copy); + p->type = PROCESS_IF; return (0); } diff --git a/42sh/src/exec/set_process_map.c b/42sh/src/exec/set_process_map.c index 004bb01a..9db3679d 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/07 15:50:56 by wescande ### ########.fr */ +/* Updated: 2017/03/08 00:23:22 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,17 +20,17 @@ t_itof g_setprocessmap[] = {TK_AND_IF, NULL}, {TK_OR_IF,NULL}, {TK_PIPE, NULL}, - {TK_WHILE, NULL}, - {TK_IF, NULL}, + {TK_WHILE, &set_process_while}, + {TK_IF, &set_process_if}, {TK_ELIF, NULL}, {TK_ELSE, NULL}, - {TK_UNTIL, NULL}, - {TK_FOR, NULL}, - {TK_CASE, NULL}, + {TK_UNTIL, &set_process_until}, + {TK_FOR, &set_process_for}, + {TK_CASE, &set_process_case}, {TK_PAREN_OPEN, NULL}, {TK_ASSIGNEMENT_WORD, NULL}, {MATH, NULL}, - /* {TK_SUBSHELL, &exec_}, */ + {SUBSHELL, &set_process_subshell}, {CMD, &set_process_cmd}, {0, NULL} }; @@ -38,15 +38,18 @@ t_itof g_setprocessmap[] = int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd) { int i; + t_astnode *item; - i = 0; + i = -1; if (!ast) return (0); - while (g_setprocessmap[i].id) - { - if (p->type == g_setprocessmap[i].id) + item = ast->item; + while (g_setprocessmap[++i].id) + if (item->type == g_setprocessmap[i].id) + { + if (!g_setprocessmap[i].f) + return (0); return ((*g_setprocessmap[i].f)(p, ast, cmd)); - i++; - } + } return (0); } diff --git a/42sh/src/exec/set_process_subshell.c b/42sh/src/exec/set_process_subshell.c new file mode 100644 index 00000000..897a9183 --- /dev/null +++ b/42sh/src/exec/set_process_subshell.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* set_process_sub.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ +/* Updated: 2017/03/08 01:52:45 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd) +{ + (void)cmd; + p->data.subshell.content = btree_map(ast->right, &node_copy); + p->type = PROCESS_SUBSHELL; + return (0); +} diff --git a/42sh/src/exec/set_process_until.c b/42sh/src/exec/set_process_until.c new file mode 100644 index 00000000..4d036585 --- /dev/null +++ b/42sh/src/exec/set_process_until.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* set_process_until.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/07 22:22:24 by wescande #+# #+# */ +/* Updated: 2017/03/08 01:54:37 by ariard ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd) +{ + (void)cmd; + p->data.d_while.condition = btree_map(ast->left, &node_copy); + p->data.d_while.content = btree_map(ast->right, &node_copy); + p->type = PROCESS_UNTIL; + return (0); +} diff --git a/42sh/src/exec/set_process_while.c b/42sh/src/exec/set_process_while.c index 6854d85d..acde7eb6 100644 --- a/42sh/src/exec/set_process_while.c +++ b/42sh/src/exec/set_process_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:10 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:03:05 by ariard ### ########.fr */ +/* Updated: 2017/03/08 01:51:38 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,5 +17,6 @@ int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd) (void)cmd; p->data.d_while.condition = btree_map(ast->left, &node_copy); p->data.d_while.content = btree_map(ast->right, &node_copy); + p->type = PROCESS_WHILE; return (0); } diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index 4949cd86..1ed5f3c8 100644 --- a/42sh/src/glob/command_getoutput.c +++ b/42sh/src/glob/command_getoutput.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ -/* Updated: 2017/03/05 18:07:24 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 00:24:07 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,7 +26,7 @@ char *command_getoutput(char *command) /* output = NULL; */ /* exec = &data_singleton()->exec; */ - /* item.type = TK_SUBSHELL; */ + /* item.type = SUBSHELL; */ /* item.data.sstr = malloc(4 * sizeof(char *)); */ /* item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]); */ /* item.data.sstr[1] = ft_strdup("-c"); */ diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index 794a6c44..dffc51c3 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:53:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 02:03:58 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,6 +22,7 @@ void job_remove(int id) j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; if (job_is_completed(id)) { + DG(); p = ft_lstlast(j->first_process)->content; set_exitstatus(p->status, 0); if (id < data_singleton()->jobc.current_id) diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index f4e0047c..8260861f 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,20 +6,39 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/07 14:46:41 by wescande ### ########.fr */ +/* Updated: 2017/03/08 02:06:04 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +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}, + {0, NULL} +}; + void process_free(void *content, size_t content_size) { t_process *p; - (void)content_size; p = content; - ft_strdel(&p->data.cmd.path); - ft_sstrfree(p->data.cmd.av); + DG(); + (void)content_size; + if (p->type >= PROCESS_MAX) + return ; + if (!g_freemap[p->type].f) + return ; + (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 new file mode 100644 index 00000000..1989df65 --- /dev/null +++ b/42sh/src/job-control/process_free_cmd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* process_free_cmd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ +/* Updated: 2017/03/08 00:59:38 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +void process_free_cmd(t_process *p) +{ + ft_strdel(&p->data.cmd.path); + ft_sstrfree(p->data.cmd.av); +} diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 67570957..3ff70ce0 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/03 19:46:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 00:35:38 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,8 +26,11 @@ int put_job_in_foreground(t_job *j, int cont) if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); } + DG(); job_wait(j->id); + DG(); job_remove(j->id); + DG(); tcsetpgrp(STDIN, jobc->shell_pgid); @@ -36,8 +39,11 @@ int put_job_in_foreground(t_job *j, int cont) } else { + DG(); job_wait(j->id); + DG(); job_remove(j->id); + DG(); } return (0); } diff --git a/42sh/src/parser/read_stack.c b/42sh/src/parser/read_stack.c index ddb76ad3..4f28e16c 100644 --- a/42sh/src/parser/read_stack.c +++ b/42sh/src/parser/read_stack.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 15:32:10 by ariard #+# #+# */ -/* Updated: 2017/03/03 20:03:24 by ariard ### ########.fr */ +/* Updated: 2017/03/08 00:23:48 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -146,8 +146,8 @@ char *read_state(t_sym current) return ("TK_LESSAND"); if (current == TK_GREATAND) return ("TK_GREATAND"); - if (current == TK_SUBSHELL) - return ("TK_SUBSEHLL"); + if (current == SUBSHELL) + return ("SUBSEHLL"); if (current == CMD_SUPERIOR) return ("CMD_SUPERIOR"); if (current == TK_IO_NUMBER)