diff --git a/42sh/Makefile b/42sh/Makefile index 9603b0b3..0c74d20c 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -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\ diff --git a/42sh/includes/builtin_read.h b/42sh/includes/builtin_read.h index bb8256a8..e0ebfc9f 100644 --- a/42sh/includes/builtin_read.h +++ b/42sh/includes/builtin_read.h @@ -6,16 +6,16 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 54405e5a..23457a32 100644 --- a/42sh/includes/exec.h +++ b/42sh/includes/exec.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:29:56 by jhalford #+# #+# */ -/* Updated: 2017/03/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 -# 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 diff --git a/42sh/includes/job_control.h b/42sh/includes/job_control.h index a5af071d..24c0432a 100644 --- a/42sh/includes/job_control.h +++ b/42sh/includes/job_control.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 74b54da2..b84e2c89 100644 --- a/42sh/includes/types.h +++ b/42sh/includes/types.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:11:48 by jhalford #+# #+# */ -/* Updated: 2017/03/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 diff --git a/42sh/libft b/42sh/libft index b209bb1f..9382dc10 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6 +Subproject commit 9382dc10fdb91892ab26604a5776e5301ab88b71 diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index f410ed1f..d0ca6526 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,21 +6,38 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 960b10cd..cc732fd0 100644 --- a/42sh/src/exec/ft_exec.c +++ b/42sh/src/exec/ft_exec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/27 20:30:32 by jhalford #+# #+# */ -/* Updated: 2017/03/13 19:08:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 20:24:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/job-control/process_free_cmd.c b/42sh/src/exec/pfree_cmd.c similarity index 83% rename from 42sh/src/job-control/process_free_cmd.c rename to 42sh/src/exec/pfree_cmd.c index ab2e446c..9715ef1a 100644 --- a/42sh/src/job-control/process_free_cmd.c +++ b/42sh/src/exec/pfree_cmd.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_free_cmd.c :+: :+: :+: */ +/* pfree_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/job-control/process_free_cond.c b/42sh/src/exec/pfree_cond.c similarity index 82% rename from 42sh/src/job-control/process_free_cond.c rename to 42sh/src/exec/pfree_cond.c index 69624104..57168280 100644 --- a/42sh/src/job-control/process_free_cond.c +++ b/42sh/src/exec/pfree_cond.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_free_cond.c :+: :+: :+: */ +/* pfree_cond.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/job-control/process_free_list.c b/42sh/src/exec/pfree_list.c similarity index 82% rename from 42sh/src/job-control/process_free_list.c rename to 42sh/src/exec/pfree_list.c index d0b05f69..55236f61 100644 --- a/42sh/src/job-control/process_free_list.c +++ b/42sh/src/exec/pfree_list.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_free_list.c :+: :+: :+: */ +/* pfree_list.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/job-control/process_free_subshell.c b/42sh/src/exec/pfree_subshell.c similarity index 81% rename from 42sh/src/job-control/process_free_subshell.c rename to 42sh/src/exec/pfree_subshell.c index 9bfded99..d9968512 100644 --- a/42sh/src/job-control/process_free_subshell.c +++ b/42sh/src/exec/pfree_subshell.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_free_subshell.c :+: :+: :+: */ +/* pfree_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/exec/launch_brace.c b/42sh/src/exec/plaunch_brace.c similarity index 83% rename from 42sh/src/exec/launch_brace.c rename to 42sh/src/exec/plaunch_brace.c index a8db3f08..7b67d92a 100644 --- a/42sh/src/exec/launch_brace.c +++ b/42sh/src/exec/plaunch_brace.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_brace.c :+: :+: :+: */ +/* plaunch_brace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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)) { diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/plaunch_builtin.c similarity index 88% rename from 42sh/src/exec/launch_builtin.c rename to 42sh/src/exec/plaunch_builtin.c index c0107239..f55875f4 100644 --- a/42sh/src/exec/launch_builtin.c +++ b/42sh/src/exec/plaunch_builtin.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_builtin.c :+: :+: :+: */ +/* plaunch_builtin.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_case.c b/42sh/src/exec/plaunch_case.c similarity index 91% rename from 42sh/src/exec/launch_case.c rename to 42sh/src/exec/plaunch_case.c index 6f248ae0..1a9bccab 100644 --- a/42sh/src/exec/launch_case.c +++ b/42sh/src/exec/plaunch_case.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_case.c :+: :+: :+: */ +/* plaunch_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/process_empty.c b/42sh/src/exec/plaunch_empty.c similarity index 92% rename from 42sh/src/exec/process_empty.c rename to 42sh/src/exec/plaunch_empty.c index cc10fd2a..18630e16 100644 --- a/42sh/src/exec/process_empty.c +++ b/42sh/src/exec/plaunch_empty.c @@ -6,13 +6,13 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/plaunch_file.c similarity index 90% rename from 42sh/src/exec/launch_file.c rename to 42sh/src/exec/plaunch_file.c index ff5d9a18..cb03c043 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/plaunch_file.c @@ -1,21 +1,22 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_file.c :+: :+: :+: */ +/* plaunch_file.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/13 17:40:45 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 22:39:43 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) { diff --git a/42sh/src/exec/launch_for.c b/42sh/src/exec/plaunch_for.c similarity index 92% rename from 42sh/src/exec/launch_for.c rename to 42sh/src/exec/plaunch_for.c index 0c39ac59..46c8f5bb 100644 --- a/42sh/src/exec/launch_for.c +++ b/42sh/src/exec/plaunch_for.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_for.c :+: :+: :+: */ +/* plaunch_for.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_function.c b/42sh/src/exec/plaunch_function.c similarity index 87% rename from 42sh/src/exec/launch_function.c rename to 42sh/src/exec/plaunch_function.c index 74678b8e..d0bc5bcf 100644 --- a/42sh/src/exec/launch_function.c +++ b/42sh/src/exec/plaunch_function.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_function.c :+: :+: :+: */ +/* plaunch_function.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_if.c b/42sh/src/exec/plaunch_if.c similarity index 89% rename from 42sh/src/exec/launch_if.c rename to 42sh/src/exec/plaunch_if.c index d29d5d2d..a6208223 100644 --- a/42sh/src/exec/launch_if.c +++ b/42sh/src/exec/plaunch_if.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_if.c :+: :+: :+: */ +/* plaunch_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/plaunch_subshell.c similarity index 88% rename from 42sh/src/exec/launch_subshell.c rename to 42sh/src/exec/plaunch_subshell.c index 0682f63f..d24f6ff7 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/plaunch_subshell.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_subshell.c :+: :+: :+: */ +/* plaunch_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_until.c b/42sh/src/exec/plaunch_until.c similarity index 89% rename from 42sh/src/exec/launch_until.c rename to 42sh/src/exec/plaunch_until.c index 4c0f566d..96df7079 100644 --- a/42sh/src/exec/launch_until.c +++ b/42sh/src/exec/plaunch_until.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_until.c :+: :+: :+: */ +/* plaunch_until.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_while.c b/42sh/src/exec/plaunch_while.c similarity index 91% rename from 42sh/src/exec/launch_while.c rename to 42sh/src/exec/plaunch_while.c index 7dfafe7d..d1e4a65f 100644 --- a/42sh/src/exec/launch_while.c +++ b/42sh/src/exec/plaunch_while.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_while.c :+: :+: :+: */ +/* plaunch_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/process_launch.c similarity index 50% rename from 42sh/src/exec/launch_process.c rename to 42sh/src/exec/process_launch.c index 669fe0f0..93ff72aa 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/process_launch.c @@ -1,56 +1,54 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_process.c :+: :+: :+: */ +/* process_launch.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* 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); } diff --git a/42sh/src/exec/process_reset.c b/42sh/src/exec/process_reset.c deleted file mode 100644 index f10d78a3..00000000 --- a/42sh/src/exec/process_reset.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* process_reset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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; -} diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/process_set.c similarity index 66% rename from 42sh/src/exec/set_process.c rename to 42sh/src/exec/process_set.c index 56992205..a5b55dd8 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/process_set.c @@ -6,16 +6,47 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/13 19:06:50 by jhalford ### ########.fr */ +/* Updated: 2017/03/13 22:39:48 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)); } diff --git a/42sh/src/exec/set_process_brace.c b/42sh/src/exec/pset_brace.c similarity index 81% rename from 42sh/src/exec/set_process_brace.c rename to 42sh/src/exec/pset_brace.c index c6bc4e0f..b9997a48 100644 --- a/42sh/src/exec/set_process_brace.c +++ b/42sh/src/exec/pset_brace.c @@ -1,19 +1,19 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_brace.c :+: :+: :+: */ +/* pset_brace.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/set_process_case.c b/42sh/src/exec/pset_case.c similarity index 83% rename from 42sh/src/exec/set_process_case.c rename to 42sh/src/exec/pset_case.c index ac184d08..e6aa9cde 100644 --- a/42sh/src/exec/set_process_case.c +++ b/42sh/src/exec/pset_case.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_case.c :+: :+: :+: */ +/* pset_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/exec/set_process_cmd.c b/42sh/src/exec/pset_cmd.c similarity index 89% rename from 42sh/src/exec/set_process_cmd.c rename to 42sh/src/exec/pset_cmd.c index 64666f0c..12f468a2 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/pset_cmd.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_cmd.c :+: :+: :+: */ +/* pset_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/set_process_for.c b/42sh/src/exec/pset_for.c similarity index 83% rename from 42sh/src/exec/set_process_for.c rename to 42sh/src/exec/pset_for.c index e51621ed..a5b4a4f6 100644 --- a/42sh/src/exec/set_process_for.c +++ b/42sh/src/exec/pset_for.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_for.c :+: :+: :+: */ +/* pset_for.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/exec/set_process_if.c b/42sh/src/exec/pset_if.c similarity index 82% rename from 42sh/src/exec/set_process_if.c rename to 42sh/src/exec/pset_if.c index 90b173d8..31440d0d 100644 --- a/42sh/src/exec/set_process_if.c +++ b/42sh/src/exec/pset_if.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_if.c :+: :+: :+: */ +/* pset_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/exec/set_process_subshell.c b/42sh/src/exec/pset_subshell.c similarity index 81% rename from 42sh/src/exec/set_process_subshell.c rename to 42sh/src/exec/pset_subshell.c index f963ca73..bbe43f32 100644 --- a/42sh/src/exec/set_process_subshell.c +++ b/42sh/src/exec/pset_subshell.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_sub.c :+: :+: :+: */ +/* pset_sub.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/exec/set_process_until.c b/42sh/src/exec/pset_until.c similarity index 82% rename from 42sh/src/exec/set_process_until.c rename to 42sh/src/exec/pset_until.c index c28b4172..120c12d6 100644 --- a/42sh/src/exec/set_process_until.c +++ b/42sh/src/exec/pset_until.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_until.c :+: :+: :+: */ +/* pset_until.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/exec/set_process_while.c b/42sh/src/exec/pset_while.c similarity index 82% rename from 42sh/src/exec/set_process_while.c rename to 42sh/src/exec/pset_while.c index 22f9fd60..8360e2be 100644 --- a/42sh/src/exec/set_process_while.c +++ b/42sh/src/exec/pset_while.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* set_process_while.c :+: :+: :+: */ +/* pset_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/exec/set_process_map.c b/42sh/src/exec/set_process_map.c deleted file mode 100644 index e536a30d..00000000 --- a/42sh/src/exec/set_process_map.c +++ /dev/null @@ -1,50 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* set_process_map.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/42sh/src/glob/command_getoutput.c b/42sh/src/glob/command_getoutput.c index 9a01da8b..96accab5 100644 --- a/42sh/src/glob/command_getoutput.c +++ b/42sh/src/glob/command_getoutput.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/12 14:01:59 by jhalford #+# #+# */ -/* Updated: 2017/03/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(); diff --git a/42sh/src/job-control/pprint_brace.c b/42sh/src/job-control/pprint_brace.c new file mode 100644 index 00000000..5d28d782 --- /dev/null +++ b/42sh/src/job-control/pprint_brace.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* pprint_brace.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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); +} diff --git a/42sh/src/job-control/process_print_case.c b/42sh/src/job-control/pprint_case.c similarity index 81% rename from 42sh/src/job-control/process_print_case.c rename to 42sh/src/job-control/pprint_case.c index 165045fb..adcd0b77 100644 --- a/42sh/src/job-control/process_print_case.c +++ b/42sh/src/job-control/pprint_case.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_case.c :+: :+: :+: */ +/* pprint_case.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/42sh/src/job-control/process_print_cmd.c b/42sh/src/job-control/pprint_cmd.c similarity index 81% rename from 42sh/src/job-control/process_print_cmd.c rename to 42sh/src/job-control/pprint_cmd.c index 8ae2307b..63e3809e 100644 --- a/42sh/src/job-control/process_print_cmd.c +++ b/42sh/src/job-control/pprint_cmd.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_cmd.c :+: :+: :+: */ +/* pprint_cmd.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); diff --git a/42sh/src/job-control/process_print_for.c b/42sh/src/job-control/pprint_for.c similarity index 81% rename from 42sh/src/job-control/process_print_for.c rename to 42sh/src/job-control/pprint_for.c index 0d622e01..555332d7 100644 --- a/42sh/src/job-control/process_print_for.c +++ b/42sh/src/job-control/pprint_for.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_for.c :+: :+: :+: */ +/* pprint_for.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/42sh/src/job-control/process_print_function.c b/42sh/src/job-control/pprint_function.c similarity index 81% rename from 42sh/src/job-control/process_print_function.c rename to 42sh/src/job-control/pprint_function.c index e0f0f91f..5f36f29b 100644 --- a/42sh/src/job-control/process_print_function.c +++ b/42sh/src/job-control/pprint_function.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_function.c :+: :+: :+: */ +/* pprint_function.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/42sh/src/job-control/process_print_if.c b/42sh/src/job-control/pprint_if.c similarity index 81% rename from 42sh/src/job-control/process_print_if.c rename to 42sh/src/job-control/pprint_if.c index a64d3276..300790fd 100644 --- a/42sh/src/job-control/process_print_if.c +++ b/42sh/src/job-control/pprint_if.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_if.c :+: :+: :+: */ +/* pprint_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/42sh/src/job-control/process_print_subshell.c b/42sh/src/job-control/pprint_subshell.c similarity index 81% rename from 42sh/src/job-control/process_print_subshell.c rename to 42sh/src/job-control/pprint_subshell.c index 647db0b5..1adc2195 100644 --- a/42sh/src/job-control/process_print_subshell.c +++ b/42sh/src/job-control/pprint_subshell.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_subshell.c :+: :+: :+: */ +/* pprint_subshell.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/42sh/src/job-control/process_print_until.c b/42sh/src/job-control/pprint_until.c similarity index 81% rename from 42sh/src/job-control/process_print_until.c rename to 42sh/src/job-control/pprint_until.c index 2732e796..f676268a 100644 --- a/42sh/src/job-control/process_print_until.c +++ b/42sh/src/job-control/pprint_until.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_until.c :+: :+: :+: */ +/* pprint_until.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/42sh/src/job-control/process_print_while.c b/42sh/src/job-control/pprint_while.c similarity index 81% rename from 42sh/src/job-control/process_print_while.c rename to 42sh/src/job-control/pprint_while.c index 9c4a67f3..1db3885d 100644 --- a/42sh/src/job-control/process_print_while.c +++ b/42sh/src/job-control/pprint_while.c @@ -1,18 +1,18 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* process_print_while.c :+: :+: :+: */ +/* pprint_while.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/42sh/src/job-control/process_format.c b/42sh/src/job-control/process_format.c index 9fcd987f..1dc3388c 100644 --- a/42sh/src/job-control/process_format.c +++ b/42sh/src/job-control/process_format.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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; diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index e145e733..928ac258 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,25 +6,25 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/42sh/src/job-control/process_print.c b/42sh/src/job-control/process_print.c deleted file mode 100644 index af0313dc..00000000 --- a/42sh/src/job-control/process_print.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* process_print.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: wescande +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 59908643..1e1b7d51 100644 --- a/42sh/src/main/main.c +++ b/42sh/src/main/main.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */ -/* Updated: 2017/03/13 21:36:40 by ariard ### ########.fr */ +/* Updated: 2017/03/13 22:50:49 by ariard ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/parser/add_redir.c b/42sh/src/parser/add_redir.c index 440624c8..4d5276ff 100644 --- a/42sh/src/parser/add_redir.c +++ b/42sh/src/parser/add_redir.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/17 16:39:05 by ariard #+# #+# */ -/* Updated: 2017/03/13 19:31:26 by ariard ### ########.fr */ +/* Updated: 2017/03/13 22:39:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */