This commit is contained in:
Jack Halford 2017-03-08 15:55:56 +01:00
commit 67bbc22fd7
26 changed files with 103 additions and 81 deletions

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 14:51:04 by jhalford ### ########.fr */ /* Updated: 2017/03/08 14:58:19 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -193,14 +193,14 @@ int launch_function(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);
int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_cmd(t_process *p, t_btree *ast);
int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_while(t_process *p, t_btree *ast);
int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_until(t_process *p, t_btree *ast);
int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_if(t_process *p, t_btree *ast);
int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_for(t_process *p, t_btree *ast);
int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_case(t_process *p, t_btree *ast);
int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_subshell(t_process *p, t_btree *ast);
/* /*
** Mapping pour exec les process ** Mapping pour exec les process

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:43:35 by jhalford ### ########.fr */ /* Updated: 2017/03/08 15:10:49 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -30,6 +30,7 @@ int launch_builtin(t_process *p)
process_setsig(); process_setsig();
if (process_redirect(p)) if (process_redirect(p))
exit (1); exit (1);
exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William
exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env)); exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */
/* Updated: 2017/03/07 21:02:46 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:11:02 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -57,6 +57,11 @@ int launch_case(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_case(p)); exit(do_case(p));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */ /* Created: 2017/03/07 17:34:43 by wescande #+# #+# */
/* Updated: 2017/03/07 21:02:18 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:07:55 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -51,6 +51,11 @@ int launch_for(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_for(p)); exit(do_for(p));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/08 03:24:53 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:08:20 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,6 +29,11 @@ int launch_function(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_function(p)); exit(do_function(p));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
/* Updated: 2017/03/07 21:03:04 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:07:47 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,6 +38,11 @@ int launch_if(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_if(p)); exit(do_if(p));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
/* Updated: 2017/03/08 14:44:57 by jhalford ### ########.fr */ /* Updated: 2017/03/08 15:08:04 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -29,6 +29,11 @@ int launch_subshell(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_subshell(p)); exit(do_subshell(p));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
/* Updated: 2017/03/08 02:35:09 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:08:13 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -38,6 +38,11 @@ int launch_until(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_until(p)); exit(do_until(p));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
/* Updated: 2017/03/07 20:59:40 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:18:36 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -55,6 +55,11 @@ int launch_while(t_process *p)
{ {
data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_INTERACTIVE;
data_singleton()->opts &= ~SH_OPTS_JOBC; data_singleton()->opts &= ~SH_OPTS_JOBC;
process_setgroup(p, 0);
process_setsig();
if (process_redirect(p))
exit (1);
exec_reset();
exit(do_while(p)); exit(do_while(p));
} }
else if (pid > 0) else if (pid > 0)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/08 14:55:35 by jhalford ### ########.fr */ /* Updated: 2017/03/08 15:55:27 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -15,11 +15,11 @@
int set_process(t_process *p, t_btree *ast) int set_process(t_process *p, t_btree *ast)
{ {
t_exec *exec; t_exec *exec;
t_cmd *cmd; // t_cmd *cmd;
int op; int op;
int fds[2]; int fds[2];
cmd = &((t_astnode *)ast->item)->data.cmd; // cmd = &((t_astnode *)ast->item)->data.cmd;
/* process_reset(p); */ /* process_reset(p); */
exec = &data_singleton()->exec; exec = &data_singleton()->exec;
op = pop(&exec->op_stack); op = pop(&exec->op_stack);
@ -38,6 +38,6 @@ int set_process(t_process *p, t_btree *ast)
p->to_close = fds[PIPE_READ]; p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE]; p->fdout = fds[PIPE_WRITE];
exec->fdin = fds[PIPE_READ]; exec->fdin = fds[PIPE_READ];
p->redirs = ft_lstmap(cmd->redir, &redir_copy); p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy);
return (set_process_map(p, ast, cmd)); return (set_process_map(p, ast));
} }

View file

@ -6,15 +6,14 @@
/* 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:49:48 by ariard ### ########.fr */ /* Updated: 2017/03/08 14:59:25 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_case(t_process *p, t_btree *ast)
{ {
(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; p->type = PROCESS_CASE;

View file

@ -6,23 +6,23 @@
/* 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/08 14:46:10 by jhalford ### ########.fr */ /* Updated: 2017/03/08 15:55:25 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_cmd(t_process *p, t_btree *ast)
{ {
t_btree *func; t_btree *func;
(void)ast; if (!(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1)))
if (!(p->data.cmd.av = token_to_argv(cmd->token, 1)))
return (1); return (1);
p->data.cmd.path = NULL; p->data.cmd.path = NULL;
p->data.cmd.execf = NULL; p->data.cmd.execf = NULL;
p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); p->data.cmd.stat = ft_memalloc(sizeof(struct stat));
DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]);
p->type = PROCESS_FILE;
if ((func = is_function(p))) if ((func = is_function(p)))
{ {
p->data.subshell.content = func; p->data.subshell.content = func;
@ -32,24 +32,19 @@ int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd)
p->type = PROCESS_BUILTIN; p->type = PROCESS_BUILTIN;
else if (ft_strchr(p->data.cmd.av[0], '/')) else if (ft_strchr(p->data.cmd.av[0], '/'))
{ {
p->type = PROCESS_FILE;
p->data.cmd.execf = &execve; p->data.cmd.execf = &execve;
p->data.cmd.path = ft_strdup(p->data.cmd.av[0]); p->data.cmd.path = ft_strdup(p->data.cmd.av[0]);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
ft_memdel((void**)&p->data.cmd.stat); ft_memdel((void**)&p->data.cmd.stat);
} }
else else if (ft_hash(p))
{ {
p->type = PROCESS_FILE; p->data.cmd.execf = &execve;
if (ft_hash(p)) DG("found hash at [%s]", p->data.cmd.path);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
{ {
p->data.cmd.execf = &execve; ft_memdel((void**)&p->data.cmd.stat);
DG("found hash at [%s]", p->data.cmd.path); ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path);
if (stat(p->data.cmd.path, p->data.cmd.stat) == -1)
{
ft_memdel((void**)&p->data.cmd.stat);
ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path);
}
} }
} }
return (0); return (0);

View file

@ -6,15 +6,14 @@
/* 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:50:33 by ariard ### ########.fr */ /* Updated: 2017/03/08 14:59:08 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_for(t_process *p, t_btree *ast)
{ {
(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; p->type = PROCESS_FOR;

View file

@ -6,15 +6,14 @@
/* 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 01:51:09 by ariard ### ########.fr */ /* Updated: 2017/03/08 14:59:17 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_if(t_process *p, t_btree *ast)
{ {
(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; p->type = PROCESS_IF;

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/08 14:48:02 by jhalford ### ########.fr */ /* Updated: 2017/03/08 14:58:36 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -35,7 +35,7 @@ t_itof g_setprocessmap[] =
{0, NULL} {0, NULL}
}; };
int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_map(t_process *p, t_btree *ast)
{ {
int i; int i;
t_astnode *item; t_astnode *item;
@ -49,7 +49,7 @@ int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd)
{ {
if (!g_setprocessmap[i].f) if (!g_setprocessmap[i].f)
return (1); return (1);
return ((*g_setprocessmap[i].f)(p, ast, cmd)); return ((*g_setprocessmap[i].f)(p, ast));
} }
return (1); return (1);
} }

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */
/* Updated: 2017/03/08 11:51:04 by jhalford ### ########.fr */ /* Updated: 2017/03/08 14:59:55 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_subshell(t_process *p, t_btree *ast)
{ {
(void)cmd;
p->data.subshell.content = btree_map(ast->right, &node_copy); p->data.subshell.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_SUBSHELL; p->type = PROCESS_SUBSHELL;
return (0); return (0);

View file

@ -6,15 +6,14 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:22:24 by wescande #+# #+# */ /* Created: 2017/03/07 22:22:24 by wescande #+# #+# */
/* Updated: 2017/03/08 03:06:03 by ariard ### ########.fr */ /* Updated: 2017/03/08 14:59:36 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_until(t_process *p, t_btree *ast)
{ {
(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_UNTIL; p->type = PROCESS_UNTIL;

View file

@ -6,15 +6,14 @@
/* 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:51:38 by ariard ### ########.fr */ /* Updated: 2017/03/08 14:58:54 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "minishell.h" #include "minishell.h"
int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd) int set_process_while(t_process *p, t_btree *ast)
{ {
(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; p->type = PROCESS_WHILE;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 12:07:16 by wescande #+# #+# */ /* Created: 2017/01/30 12:07:16 by wescande #+# #+# */
/* Updated: 2017/02/24 22:04:49 by ariard ### ########.fr */ /* Updated: 2017/03/08 14:50:58 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -49,9 +49,13 @@ int dir_research(t_glob *gl, char *p,
{ {
DIR *dir; DIR *dir;
struct dirent *in; struct dirent *in;
int ret;
ret = 0; if (!pat)
{
gl->found = 1;
ft_ld_pushfront(&gl->match, ft_strjoin(p, "/"));
return (0);
}
if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p))
{ {
dir = opendir(p); dir = opendir(p);
@ -60,5 +64,5 @@ int dir_research(t_glob *gl, char *p,
(char *[2]){p, in->d_name}, pat, recursive); (char *[2]){p, in->d_name}, pat, recursive);
closedir(dir); closedir(dir);
} }
return (ret); return (0);
} }

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */
/* Updated: 2017/03/03 20:38:53 by wescande ### ########.fr */ /* Updated: 2017/03/08 14:50:56 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -66,8 +66,7 @@ char **glob(char *pat, unsigned char *esc,
else else
dir_research(&gl, "/", gl.pat + 1, 0); dir_research(&gl, "/", gl.pat + 1, 0);
if (!gl.found) if (!gl.found)
ft_ld_pushfront(&gl.match, ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0]));
ft_strjoin(gl.cur_dir ? "" : "./", CH(gl.m_pat)[0]));
if (!gl.m_pat->next) if (!gl.m_pat->next)
break ; break ;
gl.m_pat = gl.m_pat->next; gl.m_pat = gl.m_pat->next;

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/24 17:30:23 by wescande #+# #+# */ /* Created: 2017/01/24 17:30:23 by wescande #+# #+# */
/* Updated: 2017/02/24 22:06:01 by ariard ### ########.fr */ /* Updated: 2017/03/08 14:35:43 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -90,6 +90,7 @@ static char *manage_pat(t_glob *gl, char *pat, char *str)
if (pat[0] == '.' && pat[1] == '/' if (pat[0] == '.' && pat[1] == '/'
&& ((str[0] == '.' && str[1] != '/') || str[0] != '.')) && ((str[0] == '.' && str[1] != '/') || str[0] != '.'))
{ {
DG("%s vs %s", pat, str);
gl->cur_dir = 0; gl->cur_dir = 0;
return (pat + 2); return (pat + 2);
} }

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/08 02:03:58 by ariard ### ########.fr */ /* Updated: 2017/03/08 15:06:12 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -22,7 +22,6 @@ 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,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */ /* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */
/* Updated: 2017/03/08 02:31:01 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:04:45 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,5 +16,7 @@ int process_free_cmd(t_process *p)
{ {
ft_strdel(&p->data.cmd.path); ft_strdel(&p->data.cmd.path);
ft_sstrfree(p->data.cmd.av); ft_sstrfree(p->data.cmd.av);
p->data.cmd.execf = NULL;
ft_memdel((void**)&p->data.cmd.stat);
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/08 02:38:12 by wescande #+# #+# */ /* Created: 2017/03/08 02:38:12 by wescande #+# #+# */
/* Updated: 2017/03/08 02:38:27 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:16:22 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -14,6 +14,6 @@
int process_free_subshell(t_process *p) int process_free_subshell(t_process *p)
{ {
btree_del(&p->data.d_while.content, &ast_free); btree_del(&p->data.subshell.content, &ast_free);
return (0); return (0);
} }

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/08 00:35:38 by wescande ### ########.fr */ /* Updated: 2017/03/08 15:05:31 by wescande ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -26,24 +26,16 @@ 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);
tcgetattr(STDIN, &j->tmodes); tcgetattr(STDIN, &j->tmodes);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
} }
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: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 15:51:17 by jhalford #+# #+# */ /* Created: 2017/03/08 15:51:17 by jhalford #+# #+# */
/* Updated: 2017/03/08 15:52:48 by jhalford ### ########.fr */ /* Updated: 2017/03/08 15:53:57 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */