This commit is contained in:
Antoine Riard 2017-03-08 03:05:01 +01:00
commit bce509e19c
25 changed files with 277 additions and 49 deletions

View file

@ -85,6 +85,8 @@ exec/launch_file.c\
exec/launch_for.c\ exec/launch_for.c\
exec/launch_if.c\ exec/launch_if.c\
exec/launch_process.c\ exec/launch_process.c\
exec/launch_subshell.c\
exec/launch_until.c\
exec/launch_while.c\ exec/launch_while.c\
exec/mark_process_status.c\ exec/mark_process_status.c\
exec/process_redirect.c\ exec/process_redirect.c\
@ -108,6 +110,8 @@ exec/set_process_cmd.c\
exec/set_process_for.c\ exec/set_process_for.c\
exec/set_process_if.c\ exec/set_process_if.c\
exec/set_process_map.c\ exec/set_process_map.c\
exec/set_process_subshell.c\
exec/set_process_until.c\
exec/set_process_while.c\ exec/set_process_while.c\
exec/token_to_argv.c\ exec/token_to_argv.c\
glob/command_getoutput.c\ glob/command_getoutput.c\

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 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,9 +65,15 @@ struct s_data_list
t_btree *content; t_btree *content;
}; };
struct s_data_subshell
{
t_btree *content;
};
union u_process_data union u_process_data
{ {
struct s_data_cmd cmd; struct s_data_cmd cmd;
struct s_data_subshell subshell;
struct s_data_cond d_while; struct s_data_cond d_while;
struct s_data_cond d_if; struct s_data_cond d_if;
struct s_data_cond d_else; struct s_data_cond d_else;
@ -83,15 +89,18 @@ enum e_process_type
PROCESS_FILE, PROCESS_FILE,
PROCESS_SUBSHELL, PROCESS_SUBSHELL,
PROCESS_WHILE, PROCESS_WHILE,
PROCESS_UNTIL,
PROCESS_IF, PROCESS_IF,
PROCESS_FOR, PROCESS_FOR,
PROCESS_CASE, PROCESS_CASE,
PROCESS_MAX
}; };
typedef enum e_process_type t_process_type; typedef enum e_process_type t_process_type;
typedef union u_process_data t_process_data; typedef union u_process_data t_process_data;
typedef struct s_data_cond t_data_while; typedef struct s_data_cond t_data_while;
typedef struct s_data_cond t_data_if; typedef struct s_data_cond t_data_if;
typedef struct s_data_cond t_data_if;
struct s_process struct s_process
{ {
@ -150,7 +159,6 @@ int exec_math(t_btree **ast);
int process_setexec(t_process *p); int process_setexec(t_process *p);
int process_setgroup(t_process *p, pid_t pid); int process_setgroup(t_process *p, pid_t pid);
void process_setsig(void); void process_setsig(void);
void process_free(void *content, size_t content_size);
void process_reset(t_process *p); void process_reset(t_process *p);
void process_resetfds(void); void process_resetfds(void);
@ -180,16 +188,24 @@ int add_new_job(t_job *job);
int error_badidentifier(char *name); 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 ** Mapping pour launch les process
*/ */
int launch_process(t_process *p); int launch_process(t_process *p);
int launch_if(t_process *p); int launch_if(t_process *p);
int launch_while(t_process *p); int launch_while(t_process *p);
int launch_until(t_process *p);
int launch_for(t_process *p); int launch_for(t_process *p);
int launch_case(t_process *p); int launch_case(t_process *p);
int launch_file(t_process *p); int launch_file(t_process *p);
int launch_builtin(t_process *p); int launch_builtin(t_process *p);
int launch_subshell(t_process *p);
/* /*
** Mapping pour set les process ** 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(t_process *p, t_btree *ast);
int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd); 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_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 #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 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 */ /* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -118,7 +118,6 @@ enum e_sym
TK_IO_NUMBER, TK_IO_NUMBER,
TK_DLESSDASH, TK_DLESSDASH,
TK_LESSGREAT, TK_LESSGREAT,
TK_SUBSHELL,
TK_CASE, TK_CASE,
TK_IN, TK_IN,
TK_ESAC, TK_ESAC,

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 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_process p;
t_job *job; t_job *job;
DG("in exec leaf");
job = &data_singleton()->exec.job; job = &data_singleton()->exec.job;
if (set_process(&p, *ast)) if (set_process(&p, *ast))
return (1); return (1);
DG("set_process done");
if (!(launch_process(&p))) if (!(launch_process(&p)))
{ {
job_addprocess(&p); job_addprocess(&p);

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 20:42:20 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 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_PAREN_OPEN, &exec_case_branch},
{TK_ASSIGNEMENT_WORD, &exec_var}, {TK_ASSIGNEMENT_WORD, &exec_var},
{MATH, &exec_math}, {MATH, &exec_math},
/* {TK_SUBSHELL, &exec_leaf}, */ {SUBSHELL, &exec_leaf},
{CMD, &exec_leaf}, {CMD, &exec_leaf},
{0, 0}, {0, 0},
}; };
@ -44,6 +44,7 @@ int ft_exec(t_btree **ast)
if (!*ast) if (!*ast)
return (0); return (0);
item = (*ast)->item; item = (*ast)->item;
DG("COMPARE : %d vs %d (SUBSHEELLL)", item->type, SUBSHELL);
while (g_execmap[i].id) while (g_execmap[i].id)
{ {
if (item->type == g_execmap[i].id) if (item->type == g_execmap[i].id)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 14:53:31 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; int pid;
DG("in file");
pid = fork(); pid = fork();
if (pid == 0) if (pid == 0)
{ {

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 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_FUNCTION, NULL},
{PROCESS_BUILTIN, launch_builtin}, {PROCESS_BUILTIN, launch_builtin},
{PROCESS_FILE, launch_file}, {PROCESS_FILE, launch_file},
{PROCESS_SUBSHELL, NULL}, {PROCESS_SUBSHELL, launch_subshell},
{PROCESS_WHILE, launch_while}, {PROCESS_WHILE, launch_while},
{PROCESS_UNTIL, launch_until},
{PROCESS_IF, launch_if}, {PROCESS_IF, launch_if},
{PROCESS_FOR, launch_for}, {PROCESS_FOR, launch_for},
{PROCESS_CASE, launch_case}, {PROCESS_CASE, launch_case},
@ -27,9 +28,21 @@ t_itof g_launchmap[] =
int launch_process(t_process *p) int launch_process(t_process *p)
{ {
int i; // int i;
int pid; 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; i = 0;
while (g_launchmap[i].id) while (g_launchmap[i].id)
{ {
@ -49,4 +62,5 @@ int launch_process(t_process *p)
i++; i++;
} }
return (-1); return (-1);
*/
} }

View file

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

View file

@ -0,0 +1,49 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#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);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */ /* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:07:10 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:36:04 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; (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.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->data.d_case.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_CASE;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:06:05 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 */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:05 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; (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.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->data.d_for.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_FOR;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:19:50 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; (void)cmd;
p->data.d_if.condition = btree_map(ast->left, &node_copy); p->data.d_if.condition = btree_map(ast->left, &node_copy);
p->data.d_if.content = btree_map(ast->right, &node_copy); p->data.d_if.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_IF;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:08:12 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_AND_IF, NULL},
{TK_OR_IF,NULL}, {TK_OR_IF,NULL},
{TK_PIPE, NULL}, {TK_PIPE, NULL},
{TK_WHILE, NULL}, {TK_WHILE, &set_process_while},
{TK_IF, NULL}, {TK_IF, &set_process_if},
{TK_ELIF, NULL}, {TK_ELIF, NULL},
{TK_ELSE, NULL}, {TK_ELSE, NULL},
{TK_UNTIL, NULL}, {TK_UNTIL, &set_process_until},
{TK_FOR, NULL}, {TK_FOR, &set_process_for},
{TK_CASE, NULL}, {TK_CASE, &set_process_case},
{TK_PAREN_OPEN, NULL}, {TK_PAREN_OPEN, NULL},
{TK_ASSIGNEMENT_WORD, NULL}, {TK_ASSIGNEMENT_WORD, NULL},
{MATH, NULL}, {MATH, NULL},
/* {TK_SUBSHELL, &exec_}, */ {SUBSHELL, &set_process_subshell},
{CMD, &set_process_cmd}, {CMD, &set_process_cmd},
{0, NULL} {0, NULL}
}; };
@ -38,15 +38,18 @@ t_itof g_setprocessmap[] =
int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd)
{ {
int i; int i;
t_astnode *item;
i = 0; i = -1;
if (!ast) if (!ast)
return (0); return (0);
while (g_setprocessmap[i].id) item = ast->item;
while (g_setprocessmap[++i].id)
if (item->type == g_setprocessmap[i].id)
{ {
if (p->type == g_setprocessmap[i].id) if (!g_setprocessmap[i].f)
return (0);
return ((*g_setprocessmap[i].f)(p, ast, cmd)); return ((*g_setprocessmap[i].f)(p, ast, cmd));
i++;
} }
return (0); return (0);
} }

View file

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

View file

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

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:10 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; (void)cmd;
p->data.d_while.condition = btree_map(ast->left, &node_copy); p->data.d_while.condition = btree_map(ast->left, &node_copy);
p->data.d_while.content = btree_map(ast->right, &node_copy); p->data.d_while.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_WHILE;
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/12 14:01:59 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; */ /* output = NULL; */
/* exec = &data_singleton()->exec; */ /* exec = &data_singleton()->exec; */
/* item.type = TK_SUBSHELL; */ /* item.type = SUBSHELL; */
/* item.data.sstr = malloc(4 * sizeof(char *)); */ /* item.data.sstr = malloc(4 * sizeof(char *)); */
/* item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]); */ /* item.data.sstr[0] = ft_strdup(data_singleton()->argv[0]); */
/* item.data.sstr[1] = ft_strdup("-c"); */ /* item.data.sstr[1] = ft_strdup("-c"); */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 12:51:08 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; j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content;
if (job_is_completed(id)) if (job_is_completed(id))
{ {
DG();
p = ft_lstlast(j->first_process)->content; p = ft_lstlast(j->first_process)->content;
set_exitstatus(p->status, 0); set_exitstatus(p->status, 0);
if (id < data_singleton()->jobc.current_id) if (id < data_singleton()->jobc.current_id)

View file

@ -6,20 +6,39 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 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" #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) void process_free(void *content, size_t content_size)
{ {
t_process *p; t_process *p;
(void)content_size;
p = content; p = content;
ft_strdel(&p->data.cmd.path); DG();
ft_sstrfree(p->data.cmd.av); (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); ft_lstdel(&p->redirs, ft_lst_cfree);
free(p); free(p);
DG();
} }

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* 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 */
/* */
/* ************************************************************************** */
#include "minishell.h"
void process_free_cmd(t_process *p)
{
ft_strdel(&p->data.cmd.path);
ft_sstrfree(p->data.cmd.av);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 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) if (kill(-j->pgid, SIGCONT) < 0)
DG("kill(SIGCONT) failed"); DG("kill(SIGCONT) failed");
} }
DG();
job_wait(j->id); job_wait(j->id);
DG();
job_remove(j->id); job_remove(j->id);
DG();
tcsetpgrp(STDIN, jobc->shell_pgid); tcsetpgrp(STDIN, jobc->shell_pgid);
@ -36,8 +39,11 @@ int put_job_in_foreground(t_job *j, int cont)
} }
else else
{ {
DG();
job_wait(j->id); job_wait(j->id);
DG();
job_remove(j->id); job_remove(j->id);
DG();
} }
return (0); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */ /* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/09 15:32:10 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"); return ("TK_LESSAND");
if (current == TK_GREATAND) if (current == TK_GREATAND)
return ("TK_GREATAND"); return ("TK_GREATAND");
if (current == TK_SUBSHELL) if (current == SUBSHELL)
return ("TK_SUBSEHLL"); return ("SUBSEHLL");
if (current == CMD_SUPERIOR) if (current == CMD_SUPERIOR)
return ("CMD_SUPERIOR"); return ("CMD_SUPERIOR");
if (current == TK_IO_NUMBER) if (current == TK_IO_NUMBER)