normalement les fonctions sont fonctionnelles. necessitent plus de test.

This commit is contained in:
wescande 2017-03-08 04:49:50 +01:00
parent b3e03c71c7
commit 9f8f9bb729
15 changed files with 86 additions and 113 deletions

View file

@ -65,38 +65,37 @@ exec/exec_ampersand.c\
exec/exec_and_if.c\
exec/exec_case_branch.c\
exec/exec_command.c\
exec/exec_default.c\
exec/exec_elif.c\
exec/exec_else.c\
exec/exec_func.c\
exec/exec_leaf.c\
exec/exec_math.c\
exec/exec_or_if.c\
exec/exec_pipe.c\
exec/exec_semi.c\
exec/exec_until.c\
exec/exec_var.c\
exec/fd_is_valid.c\
exec/ft_exec.c\
exec/ft_findexec.c\
exec/is_function.c\
exec/launch_builtin.c\
exec/launch_case.c\
exec/launch_file.c\
exec/launch_for.c\
exec/launch_function.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/node_copy.c\
exec/process_redirect.c\
exec/process_reset.c\
exec/process_setexec.c\
exec/process_setgroup.c\
exec/process_setsig.c\
exec/redir_free.c\
exec/redir_copy.c\
exec/node_copy.c\
exec/redir_free.c\
exec/redirect_dgreat.c\
exec/redirect_dless.c\
exec/redirect_great.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 03:05:38 by ariard ### ########.fr */
/* Updated: 2017/03/08 03:25:53 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -74,6 +74,7 @@ union u_process_data
{
struct s_data_cmd cmd;
struct s_data_subshell subshell;
struct s_data_subshell function;
struct s_data_cond d_while;
struct s_data_cond d_until;
struct s_data_cond d_if;
@ -130,31 +131,6 @@ extern t_itof g_execmap[];
extern t_itof g_redirmap[];
extern t_itof g_launchmap[];
int ft_exec(t_btree **ast);
int exec_default(t_btree **ast);
int exec_semi(t_btree **ast);
int exec_ampersand(t_btree **ast);
int exec_or_if(t_btree **ast);
int exec_and_if(t_btree **ast);
int exec_pipe(t_btree **ast);
/* int exec_redir(t_btree **ast); */
//int exec_cmd(t_btree **ast);
int exec_leaf(t_btree **ast);
//int exec_while(t_btree **ast);
//int exec_if(t_btree **ast);
int exec_elif(t_btree **ast);
int exec_else(t_btree **ast);
//int exec_until(t_btree **ast);
//int exec_default(t_btree **ast);
int exec_var(t_btree **ast);
//int exec_for(t_btree **ast);
//int exec_case(t_btree **ast);
int exec_case_branch(t_btree **ast);
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);
@ -186,6 +162,7 @@ char **token_to_argv(t_ld *ld, int do_match);
int add_new_job(t_job *job);
int error_badidentifier(char *name);
t_btree *is_function(t_process *p);
/*
** Mapping pour free les process
@ -208,6 +185,7 @@ int launch_case(t_process *p);
int launch_file(t_process *p);
int launch_builtin(t_process *p);
int launch_subshell(t_process *p);
int launch_function(t_process *p);
/*
** Mapping pour set les process
@ -222,4 +200,20 @@ 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);
/*
** Mapping pour exec les process
*/
int ft_exec(t_btree **ast);
int exec_leaf(t_btree **ast);
int exec_semi(t_btree **ast);
int exec_ampersand(t_btree **ast);
int exec_or_if(t_btree **ast);
int exec_and_if(t_btree **ast);
int exec_pipe(t_btree **ast);
int exec_elif(t_btree **ast);
int exec_else(t_btree **ast);
int exec_var(t_btree **ast);
int exec_case_branch(t_btree **ast);
int exec_math(t_btree **ast);
#endif

@ -1 +1 @@
Subproject commit 4a36b1a5e650ada2f66034d13312367694a6481a
Subproject commit 73c28532404e437d670607c909fbe56d717e9683

View file

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_default.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/31 19:29:59 by ariard #+# #+# */
/* Updated: 2017/02/05 22:18:50 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int exec_default(t_btree **ast)
{
(void)ast;
// btree_delone(ast, &ast_free);
return (0);
}

View file

@ -1,15 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */
/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/07 21:30:29 by wescande ### ########.fr */
/* Updated: 2017/03/08 03:25:23 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -17,11 +17,9 @@ 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);

View file

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* exec_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */
/* Updated: 2017/03/08 02:09:21 by ariard ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int exec_until(t_btree **ast)
{
ft_exec(&(*ast)->left);
while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "1") == 0)
{
DG("before right");
ft_exec(&(*ast)->right);
DG("before left");
ft_exec(&(*ast)->left);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2017/03/08 01:48:55 by ariard ### ########.fr */
/* Updated: 2017/03/08 03:34:10 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,7 +44,6 @@ 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)

View file

@ -6,7 +6,7 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:45:15 by wescande #+# #+# */
/* Updated: 2017/03/08 03:10:25 by wescande ### ########.fr */
/* Updated: 2017/03/08 03:22:34 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,7 +20,7 @@ t_btree *is_function(t_process *p)
while (tmp)
{
if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0]))
btree_map(p->data.subshell.content, node_copy);
return (btree_map(p->data.subshell.content, node_copy));
tmp = tmp->next;
}
return (NULL);

View file

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/08 03:24:53 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int do_function(t_process *p)
{
ft_exec(&p->data.function.content);
return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
}
int launch_function(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_function(p));
}
else if (pid > 0)
return (pid);
}
else
do_function(p);
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/03/08 00:11:15 by wescande ### ########.fr */
/* Updated: 2017/03/08 03:23:16 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
t_itof g_launchmap[] =
{
{PROCESS_FUNCTION, NULL},
{PROCESS_FUNCTION, launch_function},
{PROCESS_BUILTIN, launch_builtin},
{PROCESS_FILE, launch_file},
{PROCESS_SUBSHELL, launch_subshell},

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ast_copy.c :+: :+: :+: */
/* node_copy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:44:42 by wescande #+# #+# */
/* Updated: 2017/03/08 01:00:05 by ariard ### ########.fr */
/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */
/* Updated: 2017/03/08 04:40:50 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -20,13 +20,13 @@ void *node_copy(void *data)
if (!data)
return (NULL);
old = data;
ft_bzero((void *)&new, sizeof(t_astdata));
new = (t_astnode *)ft_memalloc(sizeof(t_astnode));
new->nest = old->nest;
new->full = old->full;
new->type = old->type;
new->pattern = old->pattern;
if (old->type == CMD || old->type == TK_ASSIGNEMENT_WORD)
{
{
new->data.cmd.redir = ft_lstdup(&old->data.cmd.redir, &redir_copy);
new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */
/* Updated: 2017/03/08 03:08:30 by wescande ### ########.fr */
/* Updated: 2017/03/08 03:32:49 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,10 +14,14 @@
int process_setexec(t_process *p)
{
t_btree *func;
p->data.cmd.path = NULL;
p->data.cmd.execf = NULL;
if ((p->data.subshell.content = is_function(p)))
if ((func = is_function(p)))
{
p->data.subshell.content = func;
p->type = PROCESS_FUNCTION;
}
else if ((p->data.cmd.execf = is_builtin(p)))
p->type = PROCESS_BUILTIN;
else if (ft_strchr(p->data.cmd.av[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 03:07:01 by ariard ### ########.fr */
/* Updated: 2017/03/08 03:26:28 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,7 @@
t_itof g_freemap[] =
{
{PROCESS_FUNCTION, NULL},
{PROCESS_FUNCTION, process_free_subshell},
{PROCESS_BUILTIN, NULL},
{PROCESS_FILE, process_free_cmd},
{PROCESS_SUBSHELL, process_free_subshell},

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/24 23:43:07 by ariard #+# #+# */
/* Updated: 2017/03/08 03:04:45 by wescande ### ########.fr */
/* Updated: 2017/03/08 03:21:13 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -88,6 +88,7 @@ int add_one_func(t_btree **ast, t_list **lst)
{
t_btree *func_ast;
(void)lst;
func_ast = btree_map(*ast, node_copy);
ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast)));
DG("arbre ajoute");