big refactoring of execution and process handling

This commit is contained in:
Jack Halford 2017-03-13 22:39:12 +01:00
parent c167d80270
commit b7804d547a
49 changed files with 319 additions and 358 deletions

View file

@ -82,25 +82,37 @@ exec/fd_is_valid.c\
exec/ft_exec.c\
exec/ft_findexec.c\
exec/is_function.c\
exec/launch_brace.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_empty.c\
exec/pfree_cmd.c\
exec/pfree_cond.c\
exec/pfree_list.c\
exec/pfree_subshell.c\
exec/plaunch_brace.c\
exec/plaunch_builtin.c\
exec/plaunch_case.c\
exec/plaunch_empty.c\
exec/plaunch_file.c\
exec/plaunch_for.c\
exec/plaunch_function.c\
exec/plaunch_if.c\
exec/plaunch_subshell.c\
exec/plaunch_until.c\
exec/plaunch_while.c\
exec/process_launch.c\
exec/process_redirect.c\
exec/process_reset.c\
exec/process_resetfds.c\
exec/process_set.c\
exec/process_setgroup.c\
exec/process_setsig.c\
exec/pset_brace.c\
exec/pset_case.c\
exec/pset_cmd.c\
exec/pset_for.c\
exec/pset_if.c\
exec/pset_subshell.c\
exec/pset_until.c\
exec/pset_while.c\
exec/redir_copy.c\
exec/redir_free.c\
exec/redirect_dgreat.c\
@ -110,16 +122,6 @@ exec/redirect_greatand.c\
exec/redirect_less.c\
exec/redirect_lessand.c\
exec/set_exitstatus.c\
exec/set_process.c\
exec/set_process_brace.c\
exec/set_process_case.c\
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\
glob/dir_glob.c\
@ -189,22 +191,18 @@ job-control/job_update_id.c\
job-control/job_update_status.c\
job-control/job_wait.c\
job-control/mark_job_as_running.c\
job-control/pprint_brace.c\
job-control/pprint_case.c\
job-control/pprint_cmd.c\
job-control/pprint_for.c\
job-control/pprint_function.c\
job-control/pprint_if.c\
job-control/pprint_subshell.c\
job-control/pprint_until.c\
job-control/pprint_while.c\
job-control/process_cmp_pid.c\
job-control/process_format.c\
job-control/process_free.c\
job-control/process_free_cmd.c\
job-control/process_free_cond.c\
job-control/process_free_list.c\
job-control/process_free_subshell.c\
job-control/process_print.c\
job-control/process_print_case.c\
job-control/process_print_cmd.c\
job-control/process_print_for.c\
job-control/process_print_function.c\
job-control/process_print_if.c\
job-control/process_print_subshell.c\
job-control/process_print_until.c\
job-control/process_print_while.c\
job-control/put_job_in_background.c\
job-control/put_job_in_foreground.c\
job-control/sigchld_handler.c\

View file

@ -6,16 +6,16 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/20 15:02:39 by jhalford #+# #+# */
/* Updated: 2017/02/03 15:59:15 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:39:49 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef BUILTIN_READ_H
# define BUILTIN_READ_H
# include "types.h"
# include "builtin.h"
# include "minishell.h"
/* # include "types.h" */
/* # include "builtin.h" */
/* # include "minishell.h" */
# define READ_OPT_LA (1 << 0)
# define READ_OPT_LD (1 << 1)

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */
/* Updated: 2017/03/13 19:14:44 by jhalford ### ########.fr */
/* Updated: 2017/03/13 22:36:52 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -14,7 +14,8 @@
# define EXEC_H
# include <sys/stat.h>
# include "minishell.h"
/* # include "types.h" */
/* # include "minishell.h" */
# define PIPE_READ 0
# define PIPE_WRITE 1
@ -99,16 +100,19 @@ enum e_process_type
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_map
{
int type;
int (*launch)();
int (*print)();
int (*free)();
};
struct s_process
{
t_process_type type;
t_process_data data;
t_process_map map;
pid_t pid;
int fdin;
int fdout;
@ -129,11 +133,8 @@ struct s_exec
int control_count;
};
extern t_itof g_execmap[];
extern t_itof g_redirmap[];
extern t_itof g_launchmap[];
/* extern t_itof g_redirmap[]; */
/* extern t_itof g_execmap[]; */
int exec_reset(void);
int process_setgroup(t_process *p, pid_t pid);
@ -172,40 +173,41 @@ t_btree *is_function(t_process *p);
** Mapping pour free les process
*/
void process_free(void *content, size_t content_size);
int process_free_cmd(t_process *p);
int process_free_cond(t_process *p);
int process_free_list(t_process *p);
int process_free_subshell(t_process *p);
int pfree_cmd(t_process *p);
int pfree_cond(t_process *p);
int pfree_list(t_process *p);
int pfree_subshell(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);
int launch_brace(t_process *p);
int launch_function(t_process *p);
int launch_empty(t_process *p);
int process_launch(t_process *p);
int plaunch_if(t_process *p);
int plaunch_while(t_process *p);
int plaunch_until(t_process *p);
int plaunch_for(t_process *p);
int plaunch_case(t_process *p);
int plaunch_file(t_process *p);
int plaunch_builtin(t_process *p);
int plaunch_subshell(t_process *p);
int plaunch_brace(t_process *p);
int plaunch_function(t_process *p);
int plaunch_empty(t_process *p);
/*
** Mapping pour set les process
*/
int set_process(t_process *p, t_btree *ast);
int set_process_map(t_process *p, t_btree *ast);
int set_process_cmd(t_process *p, t_btree *ast);
int set_process_while(t_process *p, t_btree *ast);
int set_process_until(t_process *p, t_btree *ast);
int set_process_if(t_process *p, t_btree *ast);
int set_process_for(t_process *p, t_btree *ast);
int set_process_case(t_process *p, t_btree *ast);
int set_process_subshell(t_process *p, t_btree *ast);
int process_set(t_process *p, t_btree *ast);
int pset_map(t_process *p, t_btree *ast);
int pset_cmd(t_process *p, t_btree *ast);
int pset_while(t_process *p, t_btree *ast);
int pset_until(t_process *p, t_btree *ast);
int pset_if(t_process *p, t_btree *ast);
int pset_for(t_process *p, t_btree *ast);
int pset_case(t_process *p, t_btree *ast);
int pset_subshell(t_process *p, t_btree *ast);
int pset_brace(t_process *p, t_btree *ast);
/*
** Mapping pour exec les process

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/10 16:55:09 by jhalford #+# #+# */
/* Updated: 2017/03/13 17:19:36 by jhalford ### ########.fr */
/* Updated: 2017/03/13 22:29:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -88,14 +88,15 @@ void process_format(t_list **p, int firstp, int opts);
/*
** Mapping pour afficher les process
*/
void process_print(t_process *p);
int process_print_subshell(t_process *p);
int process_print_while(t_process *p);
int process_print_if(t_process *p);
int process_print_case(t_process *p);
int process_print_until(t_process *p);
int process_print_function(t_process *p);
int process_print_for(t_process *p);
int process_print_cmd(t_process *p);
void pprint(t_process *p);
int pprint_subshell(t_process *p);
int pprint_brace(t_process *p);
int pprint_while(t_process *p);
int pprint_if(t_process *p);
int pprint_case(t_process *p);
int pprint_until(t_process *p);
int pprint_function(t_process *p);
int pprint_for(t_process *p);
int pprint_cmd(t_process *p);
#endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */
/* Updated: 2017/03/12 01:01:33 by ariard ### ########.fr */
/* Updated: 2017/03/13 20:39:05 by jhalford ### ########.fr */
/* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -60,6 +60,13 @@ typedef struct s_process t_process;
typedef int (t_execf)(const char *path,
char *const argv[],
char *const envp[]);
typedef enum e_process_type t_process_type;
typedef union u_process_data t_process_data;
typedef struct s_process_map t_process_map;
typedef struct s_data_cond t_data_while;
typedef struct s_data_cond t_data_if;
typedef struct s_data_cond t_data_if;
/*
** Parser types

View file

@ -6,21 +6,38 @@
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:47:30 by wescande #+# #+# */
/* Updated: 2017/03/13 19:06:45 by jhalford ### ########.fr */
/* Updated: 2017/03/13 22:37:51 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_process_map g_process_map[] =
{
{PROCESS_FUNCTION, plaunch_function, pprint_function, pfree_subshell},
{PROCESS_BUILTIN, plaunch_builtin, pprint_cmd, pfree_cmd},
{PROCESS_FILE, plaunch_file, pprint_cmd, pfree_cmd},
{PROCESS_SUBSHELL, plaunch_subshell, pprint_subshell, pfree_subshell},
{PROCESS_BRACE, plaunch_brace, pprint_brace, pfree_subshell},
{PROCESS_WHILE, plaunch_while, pprint_while, pfree_cond},
{PROCESS_UNTIL, plaunch_until, pprint_until, pfree_cond},
{PROCESS_IF, plaunch_if, pprint_if, pfree_cond},
{PROCESS_FOR, plaunch_for, pprint_for, pfree_list},
{PROCESS_CASE, plaunch_case, pprint_case, pfree_list},
{PROCESS_EMPTY, plaunch_empty, NULL, NULL},
};
int exec_leaf(t_btree **ast)
{
t_process p;
t_job *job;
job = &data_singleton()->exec.job;
if (set_process(&p, *ast))
if (process_set(&p, *ast))
return (1);
if (!(launch_process(&p)))
DG("p.type=%i", p.type);
p.map = g_process_map[p.type];
if (!(process_launch(&p)))
{
DG("check");
DG("forked pid=[%i]", p.pid);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */
/* Updated: 2017/03/13 19:08:20 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:24:01 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_cmd.c :+: :+: :+: */
/* pfree_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:58:02 by wescande #+# #+# */
/* Updated: 2017/03/08 15:04:45 by wescande ### ########.fr */
/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_free_cmd(t_process *p)
int pfree_cmd(t_process *p)
{
ft_strdel(&p->data.cmd.path);
ft_sstrfree(p->data.cmd.av);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_cond.c :+: :+: :+: */
/* pfree_cond.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:26:31 by wescande #+# #+# */
/* Updated: 2017/03/08 02:39:12 by wescande ### ########.fr */
/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_free_cond(t_process *p)
int pfree_cond(t_process *p)
{
btree_del(&p->data.d_while.condition, &ast_free);
btree_del(&p->data.d_while.content, &ast_free);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_list.c :+: :+: :+: */
/* pfree_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:37:04 by wescande #+# #+# */
/* Updated: 2017/03/08 02:37:52 by wescande ### ########.fr */
/* Updated: 2017/03/13 22:31:32 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_free_list(t_process *p)
int pfree_list(t_process *p)
{
ft_ld_del(&p->data.d_for.list_word, &ft_tabdel);
btree_del(&p->data.d_for.content, &ast_free);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_free_subshell.c :+: :+: :+: */
/* pfree_subshell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 02:38:12 by wescande #+# #+# */
/* Updated: 2017/03/08 23:31:53 by ariard ### ########.fr */
/* Updated: 2017/03/13 22:31:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_free_subshell(t_process *p)
int pfree_subshell(t_process *p)
{
btree_del(&p->data.subshell.content, &ast_free);
return (0);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_brace.c :+: :+: :+: */
/* plaunch_brace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 19:09:30 by jhalford #+# #+# */
/* Updated: 2017/03/13 19:21:39 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int launch_brace(t_process *p)
int plaunch_brace(t_process *p)
{
if (process_redirect(p))
{

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_builtin.c :+: :+: :+: */
/* plaunch_builtin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */
/* Updated: 2017/03/13 19:15:13 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int launch_builtin(t_process *p)
int plaunch_builtin(t_process *p)
{
pid_t pid;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_case.c :+: :+: :+: */
/* plaunch_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:02:23 by wescande #+# #+# */
/* Updated: 2017/03/08 15:11:02 by wescande ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -46,7 +46,7 @@ static int do_case(t_process *p)
return (0);
}
int launch_case(t_process *p)
int plaunch_case(t_process *p)
{
pid_t pid;

View file

@ -6,13 +6,13 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 17:26:01 by jhalford #+# #+# */
/* Updated: 2017/03/13 17:31:05 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:29:43 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int launch_empty(t_process *p)
int plaunch_empty(t_process *p)
{
int pid;

View file

@ -1,21 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_file.c :+: :+: :+: */
/* plaunch_file.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */
/* Updated: 2017/03/13 17:40:45 by jhalford ### ########.fr */
/* Updated: 2017/03/13 22:34:37 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int launch_file(t_process *p)
int plaunch_file(t_process *p)
{
int pid;
DG("plaunch_file");
pid = fork();
if (pid == 0)
{

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_for.c :+: :+: :+: */
/* plaunch_for.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:34:43 by wescande #+# #+# */
/* Updated: 2017/03/08 15:07:55 by wescande ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -40,7 +40,7 @@ static int do_for(t_process *p)
return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
}
int launch_for(t_process *p)
int plaunch_for(t_process *p)
{
pid_t pid;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_function.c :+: :+: :+: */
/* plaunch_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */
/* Updated: 2017/03/08 15:08:20 by wescande ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,7 +18,7 @@ static int do_function(t_process *p)
return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
}
int launch_function(t_process *p)
int plaunch_function(t_process *p)
{
pid_t pid;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_if.c :+: :+: :+: */
/* plaunch_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:26:53 by wescande #+# #+# */
/* Updated: 2017/03/11 13:48:19 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,7 @@ static int do_if(t_process *p)
return (ft_atoi(ft_getenv(data_singleton()->env, "?")));
}
int launch_if(t_process *p)
int plaunch_if(t_process *p)
{
pid_t pid;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_subshell.c :+: :+: :+: */
/* plaunch_subshell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:11:44 by wescande #+# #+# */
/* Updated: 2017/03/13 19:12:26 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -25,7 +25,7 @@ static int do_subshell(t_process *p)
return (ret);
}
int launch_subshell(t_process *p)
int plaunch_subshell(t_process *p)
{
pid_t pid;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_until.c :+: :+: :+: */
/* plaunch_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:04:42 by wescande #+# #+# */
/* Updated: 2017/03/08 15:08:13 by wescande ### ########.fr */
/* Updated: 2017/03/13 20:28:57 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -27,7 +27,7 @@ static int do_until(t_process *p)
return (ret);
}
int launch_until(t_process *p)
int plaunch_until(t_process *p)
{
pid_t pid;

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_while.c :+: :+: :+: */
/* plaunch_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 17:20:53 by wescande #+# #+# */
/* Updated: 2017/03/13 14:18:07 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:28:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -44,7 +44,7 @@ static int do_while(t_process *p)
return (ret);
}
int launch_while(t_process *p)
int plaunch_while(t_process *p)
{
pid_t pid;

View file

@ -1,56 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* launch_process.c :+: :+: :+: */
/* process_launch.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */
/* Updated: 2017/03/13 19:21:40 by jhalford ### ########.fr */
/* Created: 2017/03/13 22:21:19 by jhalford #+# #+# */
/* Updated: 2017/03/13 22:35:24 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_itof g_launchmap[] =
{
{PROCESS_FUNCTION, launch_function},
{PROCESS_BUILTIN, launch_builtin},
{PROCESS_FILE, launch_file},
{PROCESS_SUBSHELL, launch_subshell},
{PROCESS_BRACE, launch_brace},
{PROCESS_WHILE, launch_while},
{PROCESS_UNTIL, launch_until},
{PROCESS_IF, launch_if},
{PROCESS_FOR, launch_for},
{PROCESS_CASE, launch_case},
{PROCESS_EMPTY, launch_empty},
};
/* t_itof g_launchmap[] = */
/* { */
/* {PROCESS_FUNCTION, launch_function}, */
/* {PROCESS_BUILTIN, launch_builtin}, */
/* {PROCESS_FILE, launch_file}, */
/* {PROCESS_SUBSHELL, launch_subshell}, */
/* {PROCESS_BRACE, launch_brace}, */
/* {PROCESS_WHILE, launch_while}, */
/* {PROCESS_UNTIL, launch_until}, */
/* {PROCESS_IF, launch_if}, */
/* {PROCESS_FOR, launch_for}, */
/* {PROCESS_CASE, launch_case}, */
/* {PROCESS_EMPTY, launch_empty}, */
/* }; */
int launch_process(t_process *p)
int process_launch(t_process *p)
{
int pid;
DG("p->type=%i", p->type);
if (p->type >= PROCESS_MAX)
return (-1);
if (!g_launchmap[p->type].f)
return (-1);
/* if (p->type >= PROCESS_MAX) */
/* return (-1); */
/* if (!g_launch_map[p->type].f) */
/* return (-1); */
p->attrs &= ~PROCESS_STATE_MASK;
p->attrs |= PROCESS_RUNNING;
if (!(pid = (*g_launchmap[p->type].f)(p)))
if (!(pid = (*p->map.launch)(p)))
{
process_resetfds(p);
return (1);
}
DG("launcher did not fork!");
p->pid = pid;
DG("check");
process_setgroup(p, pid);
DG("check");
if (p->fdin != STDIN)
close(p->fdin);
if (p->fdout != STDOUT)
close(p->fdout);
DG("check");
return (0);
}

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_reset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */
/* Updated: 2017/03/09 15:09:42 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void process_reset(t_process *p)
{
// p->av = NULL;
// p->path = NULL;
// p->execf = NULL;
p->pid = 0;
p->fdin = STDIN;
p->fdout = STDOUT;
p->to_close = 0;
p->redirs = NULL;
p->status = -1;
p->attrs = 0;
}

View file

@ -6,16 +6,47 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */
/* Updated: 2017/03/13 19:06:50 by jhalford ### ########.fr */
/* Updated: 2017/03/13 22:38:22 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process(t_process *p, t_btree *ast)
t_itof g_setprocessmap[] =
{
{TK_WHILE, &pset_while},
{TK_IF, &pset_if},
{TK_UNTIL, &pset_until},
{TK_FOR, &pset_for},
{TK_CASE, &pset_case},
{SUBSHELL, &pset_subshell},
{CMD, &pset_cmd},
{TK_LBRACE, &pset_brace},
{0, NULL}
};
static int process_set_spec(t_process *p, t_btree *ast)
{
int i;
t_astnode *item;
i = -1;
if (!ast)
return (0);
item = ast->item;
while (g_setprocessmap[++i].id)
if (item->type == g_setprocessmap[i].id)
{
if (!g_setprocessmap[i].f)
return (1);
return ((*g_setprocessmap[i].f)(p, ast));
}
return (1);
}
int process_set(t_process *p, t_btree *ast)
{
t_exec *exec;
// t_cmd *cmd;
int op;
int fds[2];
@ -29,14 +60,11 @@ int set_process(t_process *p, t_btree *ast)
fds[PIPE_WRITE] = STDOUT;
fds[PIPE_READ] = STDIN;
if (op == TK_PIPE)
{
pipe(fds);
/* DG("[%i] -> PIPE -> [%i]", fds[PIPE_WRITE], fds[PIPE_READ]); */
}
p->fdin = exec->fdin;
p->to_close = fds[PIPE_READ];
p->fdout = fds[PIPE_WRITE];
exec->fdin = fds[PIPE_READ];
p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy);
return (set_process_map(p, ast));
return (process_set_spec(p, ast));
}

View file

@ -1,19 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_brace.c :+: :+: :+: */
/* pset_brace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 19:07:34 by jhalford #+# #+# */
/* Updated: 2017/03/13 19:08:27 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_brace(t_process *p, t_btree *ast)
int pset_brace(t_process *p, t_btree *ast)
{
p->data.subshell.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_BRACE;

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_case.c :+: :+: :+: */
/* pset_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 20:36:04 by wescande #+# #+# */
/* Updated: 2017/03/08 14:59:25 by wescande ### ########.fr */
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_case(t_process *p, t_btree *ast)
int pset_case(t_process *p, t_btree *ast)
{
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);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_cmd.c :+: :+: :+: */
/* pset_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:06:05 by wescande #+# #+# */
/* Updated: 2017/03/13 17:40:37 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_cmd(t_process *p, t_btree *ast)
int pset_cmd(t_process *p, t_btree *ast)
{
t_btree *func;

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_for.c :+: :+: :+: */
/* pset_for.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:05 by wescande #+# #+# */
/* Updated: 2017/03/08 14:59:08 by wescande ### ########.fr */
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_for(t_process *p, t_btree *ast)
int pset_for(t_process *p, t_btree *ast)
{
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);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_if.c :+: :+: :+: */
/* pset_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:19:50 by wescande #+# #+# */
/* Updated: 2017/03/10 14:32:31 by ariard ### ########.fr */
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_if(t_process *p, t_btree *ast)
int pset_if(t_process *p, t_btree *ast)
{
p->data.d_if.condition = btree_map(ast->left, &node_copy);
p->data.d_if.content = btree_map(ast->right, &node_copy);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_sub.c :+: :+: :+: */
/* pset_sub.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 00:02:01 by wescande #+# #+# */
/* Updated: 2017/03/13 19:07:18 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_subshell(t_process *p, t_btree *ast)
int pset_subshell(t_process *p, t_btree *ast)
{
p->data.subshell.content = btree_map(ast->right, &node_copy);
p->type = PROCESS_SUBSHELL;

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_until.c :+: :+: :+: */
/* pset_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 22:22:24 by wescande #+# #+# */
/* Updated: 2017/03/08 14:59:36 by wescande ### ########.fr */
/* Updated: 2017/03/13 20:31:21 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_until(t_process *p, t_btree *ast)
int pset_until(t_process *p, t_btree *ast)
{
p->data.d_while.condition = btree_map(ast->left, &node_copy);
p->data.d_while.content = btree_map(ast->right, &node_copy);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_while.c :+: :+: :+: */
/* pset_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 19:38:10 by wescande #+# #+# */
/* Updated: 2017/03/10 14:32:22 by ariard ### ########.fr */
/* Updated: 2017/03/13 20:31:19 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int set_process_while(t_process *p, t_btree *ast)
int pset_while(t_process *p, t_btree *ast)
{
p->data.d_while.condition = btree_map(ast->left, &node_copy);
p->data.d_while.content = btree_map(ast->right, &node_copy);

View file

@ -1,50 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* set_process_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/07 15:08:12 by wescande #+# #+# */
/* Updated: 2017/03/13 19:08:25 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_itof g_setprocessmap[] =
{
{TK_WHILE, &set_process_while},
{TK_IF, &set_process_if},
{TK_ELIF, NULL},
{TK_ELSE, 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},
{SUBSHELL, &set_process_subshell},
{CMD, &set_process_cmd},
{TK_LBRACE, &set_process_subshell},
{0, NULL}
};
int set_process_map(t_process *p, t_btree *ast)
{
int i;
t_astnode *item;
i = -1;
if (!ast)
return (0);
item = ast->item;
while (g_setprocessmap[++i].id)
if (item->type == g_setprocessmap[i].id)
{
if (!g_setprocessmap[i].f)
return (1);
return ((*g_setprocessmap[i].f)(p, ast));
}
return (1);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */
/* Updated: 2017/03/08 23:46:06 by wescande ### ########.fr */
/* Updated: 2017/03/13 22:25:13 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -67,10 +67,10 @@ char *command_getoutput(char *command)
DG("\033[38;5;46mbefore");
ast = gen_t_btree(command);
DG();
if (set_process(&p, ast))
if (process_set(&p, ast))
return (NULL);
DG();
if (!(pid = launch_subshell(&p)))
if (!(pid = plaunch_subshell(&p)))
return (NULL);
waitpid(pid, &ret, WUNTRACED);
DG();

View file

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pprint_brace.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/13 20:42:06 by jhalford #+# #+# */
/* Updated: 2017/03/13 20:42:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int pprint_brace(t_process *p)
{
(void)p;
ft_putstr("BRACE GROUP");
return (0);
}

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_case.c :+: :+: :+: */
/* pprint_case.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:15:22 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:50 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:41:59 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_case(t_process *p)
int pprint_case(t_process *p)
{
(void)p;
ft_putstr("CASE GROUP");

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_cmd.c :+: :+: :+: */
/* pprint_cmd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:17:16 by wescande #+# #+# */
/* Updated: 2017/03/08 20:28:10 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_cmd(t_process *p)
int pprint_cmd(t_process *p)
{
ft_sstrprint(p->data.cmd.av, ' ');
return (0);

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_for.c :+: :+: :+: */
/* pprint_for.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:14:21 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:16 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_for(t_process *p)
int pprint_for(t_process *p)
{
(void)p;
ft_putstr("FOR GROUP");

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_function.c :+: :+: :+: */
/* pprint_function.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:12:18 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:54 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_function(t_process *p)
int pprint_function(t_process *p)
{
(void)p;
ft_putstr("FUNCTION GROUP");

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_if.c :+: :+: :+: */
/* pprint_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:14:48 by wescande #+# #+# */
/* Updated: 2017/03/08 19:14:01 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_if(t_process *p)
int pprint_if(t_process *p)
{
(void)p;
ft_putstr("IF GROUP");

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_subshell.c :+: :+: :+: */
/* pprint_subshell.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:06:06 by wescande #+# #+# */
/* Updated: 2017/03/08 19:14:54 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_subshell(t_process *p)
int pprint_subshell(t_process *p)
{
(void)p;
ft_putstr("SUBSHELL GROUP");

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_until.c :+: :+: :+: */
/* pprint_until.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:16:00 by wescande #+# #+# */
/* Updated: 2017/03/08 19:13:36 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_until(t_process *p)
int pprint_until(t_process *p)
{
(void)p;
ft_putstr("UNTIL GROUP");

View file

@ -1,18 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print_while.c :+: :+: :+: */
/* pprint_while.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:15:01 by wescande #+# #+# */
/* Updated: 2017/03/08 19:14:13 by jhalford ### ########.fr */
/* Updated: 2017/03/13 20:23:18 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
int process_print_while(t_process *p)
int pprint_while(t_process *p)
{
(void)p;
ft_putstr("WHILE GROUP");

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/09 13:05:55 by jhalford #+# #+# */
/* Updated: 2017/03/10 16:27:33 by jhalford ### ########.fr */
/* Updated: 2017/03/13 22:29:29 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
@ -42,7 +42,8 @@ static void process_format_com_long(t_list **plist)
t_process *p;
p = (*plist)->content;
process_print(p);
(p->map.print)(p);
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
if ((*plist)->next)
ft_putstr(" |");
(*plist) = (*plist)->next;
@ -63,7 +64,8 @@ static void process_format_com_short(t_list **plist, t_flag state)
p->attrs &= ~PROCESS_STATE_MASK;
p->attrs &= ~PROCESS_RUNNING;
}
process_print(p);
(p->map.print)(p);
// faudrait printer les redirections (p->redir) ici genre avec ft_lstiter je pense
if ((*plist)->next)
ft_putstr(" | ");
(*plist) = (*plist)->next;

View file

@ -6,25 +6,25 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */
/* Updated: 2017/03/13 17:33:32 by jhalford ### ########.fr */
/* Updated: 2017/03/13 22:19:53 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_itof g_freemap[] =
{
{PROCESS_FUNCTION, process_free_subshell},
{PROCESS_BUILTIN, process_free_cmd},
{PROCESS_FILE, process_free_cmd},
{PROCESS_SUBSHELL, process_free_subshell},
{PROCESS_WHILE, process_free_cond},
{PROCESS_UNTIL, process_free_cond},
{PROCESS_IF, process_free_cond},
{PROCESS_FOR, process_free_list},
{PROCESS_CASE, process_free_list},
{PROCESS_EMPTY, NULL},
};
/* t_itof g_freemap[] = */
/* { */
/* {PROCESS_FUNCTION, process_free_subshell}, */
/* {PROCESS_BUILTIN, process_free_cmd}, */
/* {PROCESS_FILE, process_free_cmd}, */
/* {PROCESS_SUBSHELL, process_free_subshell}, */
/* {PROCESS_WHILE, process_free_cond}, */
/* {PROCESS_UNTIL, process_free_cond}, */
/* {PROCESS_IF, process_free_cond}, */
/* {PROCESS_FOR, process_free_list}, */
/* {PROCESS_CASE, process_free_list}, */
/* {PROCESS_EMPTY, NULL}, */
/* }; */
void process_free(void *content, size_t content_size)
{
@ -32,13 +32,11 @@ void process_free(void *content, size_t content_size)
p = content;
(void)content_size;
DG("gonna free");
if (p->type >= PROCESS_MAX)
return ;
DG("gonna free");
if (g_freemap[p->type].f)
(g_freemap[p->type].f)(p);
DG("gonna free");
/* if (p->type >= PROCESS_MAX) */
/* return ; */
/* if (g_freemap[p->type].f) */
/* (g_freemap[p->type].f)(p); */
(p->map.free)(p);
ft_lstdel(&p->redirs, redir_free);
free(p);
}

View file

@ -1,34 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* process_print.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wescande <wescande@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 16:03:32 by wescande #+# #+# */
/* Updated: 2017/03/08 20:44:26 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_itof g_printmap[] =
{
{PROCESS_FUNCTION, process_print_function},
{PROCESS_BUILTIN, process_print_cmd},
{PROCESS_FILE, process_print_cmd},
{PROCESS_SUBSHELL, process_print_subshell},
{PROCESS_WHILE, process_print_while},
{PROCESS_UNTIL, process_print_until},
{PROCESS_IF, process_print_if},
{PROCESS_FOR, process_print_for},
{PROCESS_CASE, process_print_case},
};
void process_print(t_process *p)
{
if (p->type >= PROCESS_MAX)
return ;
if (g_printmap[p->type].f)
(*g_printmap[p->type].f)(p);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/13 17:51:05 by jhalford ### ########.fr */
/* Updated: 2017/03/13 19:55:20 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: ariard <ariard@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/02/17 16:39:05 by ariard #+# #+# */
/* Updated: 2017/03/13 19:22:24 by jhalford ### ########.fr */
/* Updated: 2017/03/13 19:26:38 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */