From be78dfbdf88e26839cba9bc2875569e57045b7b2 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 8 Mar 2017 03:10:46 +0100 Subject: [PATCH 01/12] commit pour recup lib & node_copy --- 42sh/includes/builtin.h | 4 +--- 42sh/src/exec/is_function.c | 27 +++++++++++++++++++++++++++ 42sh/src/exec/process_setexec.c | 8 ++++---- 42sh/src/parser/add_func.c | 6 +++--- 4 files changed, 35 insertions(+), 10 deletions(-) create mode 100644 42sh/src/exec/is_function.c diff --git a/42sh/includes/builtin.h b/42sh/includes/builtin.h index be6045e4..3662a1f0 100644 --- a/42sh/includes/builtin.h +++ b/42sh/includes/builtin.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:21:56 by jhalford #+# #+# */ -/* Updated: 2017/03/07 17:29:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 03:08:48 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,6 +32,4 @@ int builtin_bg(const char *path, char *const av[], char *const envp[]); int builtin_history(const char *path, char *const av[], char *const envp[]); int builtin_hash(const char *path, char *const av[], char *const envp[]); -extern t_stof g_builtins[]; - #endif diff --git a/42sh/src/exec/is_function.c b/42sh/src/exec/is_function.c new file mode 100644 index 00000000..227acb3c --- /dev/null +++ b/42sh/src/exec/is_function.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* is_function.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 02:45:15 by wescande #+# #+# */ +/* Updated: 2017/03/08 03:10:25 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +t_btree *is_function(t_process *p) +{ + t_list *tmp; + + tmp = data_singleton()->lst_func; + while (tmp) + { + if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0])) + btree_map(p->data.subshell.content, node_copy); + tmp = tmp->next; + } + return (NULL); +} diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 4242fb47..5f27ecf0 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/07 21:44:37 by wescande ### ########.fr */ +/* Updated: 2017/03/08 03:08:30 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,9 +16,9 @@ int process_setexec(t_process *p) { p->data.cmd.path = NULL; p->data.cmd.execf = NULL; - /* if ((p->execf = is_function(p))) */ - /* p->type = PROCESS_FUNCTION; */ - if ((p->data.cmd.execf = is_builtin(p))) + if ((p->data.subshell.content = is_function(p))) + p->type = PROCESS_FUNCTION; + else if ((p->data.cmd.execf = is_builtin(p))) p->type = PROCESS_BUILTIN; else if (ft_strchr(p->data.cmd.av[0], '/')) { diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index 736e7e22..66041625 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/07 10:49:15 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:04:45 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,7 @@ int isfunc_name(t_btree **ast, t_list **lst) { DG("add func name"); node->type = FNAME; + node->data.str = ft_strdup(token->data); return (1); } if (node->type == FNAME && token->type == TK_PAREN_CLOSE && node->nest == 0) @@ -87,8 +88,7 @@ int add_one_func(t_btree **ast, t_list **lst) { t_btree *func_ast; - (void)lst; -// func_ast = btree_map(*ast, &id); + func_ast = btree_map(*ast, node_copy); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); DG("arbre ajoute"); return (0); From 9f8f9bb72980878ea8790cc21894f84260dd4747 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 8 Mar 2017 04:49:50 +0100 Subject: [PATCH 02/12] normalement les fonctions sont fonctionnelles. necessitent plus de test. --- 42sh/Makefile | 9 +++--- 42sh/includes/exec.h | 46 +++++++++++++---------------- 42sh/libft | 2 +- 42sh/src/exec/exec_default.c | 21 ------------- 42sh/src/exec/exec_func.c | 15 ---------- 42sh/src/exec/exec_leaf.c | 4 +-- 42sh/src/exec/exec_until.c | 26 ---------------- 42sh/src/exec/ft_exec.c | 3 +- 42sh/src/exec/is_function.c | 4 +-- 42sh/src/exec/launch_function.c | 40 +++++++++++++++++++++++++ 42sh/src/exec/launch_process.c | 4 +-- 42sh/src/exec/node_copy.c | 10 +++---- 42sh/src/exec/process_setexec.c | 8 +++-- 42sh/src/job-control/process_free.c | 4 +-- 42sh/src/parser/add_func.c | 3 +- 15 files changed, 86 insertions(+), 113 deletions(-) delete mode 100644 42sh/src/exec/exec_default.c delete mode 100644 42sh/src/exec/exec_func.c delete mode 100644 42sh/src/exec/exec_until.c create mode 100644 42sh/src/exec/launch_function.c diff --git a/42sh/Makefile b/42sh/Makefile index 008572f3..2af77340 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -65,38 +65,37 @@ exec/exec_ampersand.c\ exec/exec_and_if.c\ exec/exec_case_branch.c\ exec/exec_command.c\ -exec/exec_default.c\ exec/exec_elif.c\ exec/exec_else.c\ -exec/exec_func.c\ exec/exec_leaf.c\ exec/exec_math.c\ exec/exec_or_if.c\ exec/exec_pipe.c\ exec/exec_semi.c\ -exec/exec_until.c\ exec/exec_var.c\ exec/fd_is_valid.c\ exec/ft_exec.c\ exec/ft_findexec.c\ +exec/is_function.c\ exec/launch_builtin.c\ exec/launch_case.c\ exec/launch_file.c\ exec/launch_for.c\ +exec/launch_function.c\ exec/launch_if.c\ exec/launch_process.c\ exec/launch_subshell.c\ exec/launch_until.c\ exec/launch_while.c\ exec/mark_process_status.c\ +exec/node_copy.c\ exec/process_redirect.c\ exec/process_reset.c\ exec/process_setexec.c\ exec/process_setgroup.c\ exec/process_setsig.c\ -exec/redir_free.c\ exec/redir_copy.c\ -exec/node_copy.c\ +exec/redir_free.c\ exec/redirect_dgreat.c\ exec/redirect_dless.c\ exec/redirect_great.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index ea85b168..372c4ef0 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/08 03:05:38 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:25:53 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,6 +74,7 @@ union u_process_data { struct s_data_cmd cmd; struct s_data_subshell subshell; + struct s_data_subshell function; struct s_data_cond d_while; struct s_data_cond d_until; struct s_data_cond d_if; @@ -130,31 +131,6 @@ extern t_itof g_execmap[]; extern t_itof g_redirmap[]; extern t_itof g_launchmap[]; -int ft_exec(t_btree **ast); - -int exec_default(t_btree **ast); - -int exec_semi(t_btree **ast); -int exec_ampersand(t_btree **ast); -int exec_or_if(t_btree **ast); -int exec_and_if(t_btree **ast); -int exec_pipe(t_btree **ast); -/* int exec_redir(t_btree **ast); */ -//int exec_cmd(t_btree **ast); -int exec_leaf(t_btree **ast); - -//int exec_while(t_btree **ast); -//int exec_if(t_btree **ast); -int exec_elif(t_btree **ast); -int exec_else(t_btree **ast); -//int exec_until(t_btree **ast); -//int exec_default(t_btree **ast); -int exec_var(t_btree **ast); -//int exec_for(t_btree **ast); -//int exec_case(t_btree **ast); -int exec_case_branch(t_btree **ast); -int exec_math(t_btree **ast); - int process_setexec(t_process *p); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); @@ -186,6 +162,7 @@ char **token_to_argv(t_ld *ld, int do_match); int add_new_job(t_job *job); int error_badidentifier(char *name); +t_btree *is_function(t_process *p); /* ** Mapping pour free les process @@ -208,6 +185,7 @@ int launch_case(t_process *p); int launch_file(t_process *p); int launch_builtin(t_process *p); int launch_subshell(t_process *p); +int launch_function(t_process *p); /* ** Mapping pour set les process @@ -222,4 +200,20 @@ int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd); int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd); +/* +** Mapping pour exec les process +*/ +int ft_exec(t_btree **ast); +int exec_leaf(t_btree **ast); +int exec_semi(t_btree **ast); +int exec_ampersand(t_btree **ast); +int exec_or_if(t_btree **ast); +int exec_and_if(t_btree **ast); +int exec_pipe(t_btree **ast); +int exec_elif(t_btree **ast); +int exec_else(t_btree **ast); +int exec_var(t_btree **ast); +int exec_case_branch(t_btree **ast); +int exec_math(t_btree **ast); + #endif diff --git a/42sh/libft b/42sh/libft index 4a36b1a5..73c28532 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 4a36b1a5e650ada2f66034d13312367694a6481a +Subproject commit 73c28532404e437d670607c909fbe56d717e9683 diff --git a/42sh/src/exec/exec_default.c b/42sh/src/exec/exec_default.c deleted file mode 100644 index 796a10a7..00000000 --- a/42sh/src/exec/exec_default.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* exec_default.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/31 19:29:59 by ariard #+# #+# */ -/* Updated: 2017/02/05 22:18:50 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int exec_default(t_btree **ast) -{ - - (void)ast; -// btree_delone(ast, &ast_free); - return (0); -} diff --git a/42sh/src/exec/exec_func.c b/42sh/src/exec/exec_func.c deleted file mode 100644 index 7255d850..00000000 --- a/42sh/src/exec/exec_func.c +++ /dev/null @@ -1,15 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* exec_while.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/01/30 17:33:53 by ariard #+# #+# */ -/* Updated: 2017/02/06 22:05:35 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - - diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 9a0ae4fd..2fafa04c 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:30:29 by wescande ### ########.fr */ +/* Updated: 2017/03/08 03:25:23 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,11 +17,9 @@ int exec_leaf(t_btree **ast) t_process p; t_job *job; - DG("in exec leaf"); job = &data_singleton()->exec.job; if (set_process(&p, *ast)) return (1); - DG("set_process done"); if (!(launch_process(&p))) { job_addprocess(&p); diff --git a/42sh/src/exec/exec_until.c b/42sh/src/exec/exec_until.c deleted file mode 100644 index a26563e9..00000000 --- a/42sh/src/exec/exec_until.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* exec_until.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: ariard +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2017/02/06 20:42:20 by ariard #+# #+# */ -/* Updated: 2017/03/08 02:09:21 by ariard ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int exec_until(t_btree **ast) -{ - ft_exec(&(*ast)->left); - while (ft_strcmp(ft_getenv(data_singleton()->env, "?"), "1") == 0) - { - DG("before right"); - ft_exec(&(*ast)->right); - DG("before left"); - ft_exec(&(*ast)->left); - } - return (0); -} diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index 87b37ab5..c3cb73dc 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/08 01:48:55 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:34:10 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,7 +44,6 @@ int ft_exec(t_btree **ast) if (!*ast) return (0); item = (*ast)->item; - DG("COMPARE : %d vs %d (SUBSHEELLL)", item->type, SUBSHELL); while (g_execmap[i].id) { if (item->type == g_execmap[i].id) diff --git a/42sh/src/exec/is_function.c b/42sh/src/exec/is_function.c index 227acb3c..36bdcd5a 100644 --- a/42sh/src/exec/is_function.c +++ b/42sh/src/exec/is_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:45:15 by wescande #+# #+# */ -/* Updated: 2017/03/08 03:10:25 by wescande ### ########.fr */ +/* Updated: 2017/03/08 03:22:34 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ t_btree *is_function(t_process *p) while (tmp) { if (!ft_strcmp(((t_astnode *)tmp->content)->data.str, p->data.cmd.av[0])) - btree_map(p->data.subshell.content, node_copy); + return (btree_map(p->data.subshell.content, node_copy)); tmp = tmp->next; } return (NULL); diff --git a/42sh/src/exec/launch_function.c b/42sh/src/exec/launch_function.c new file mode 100644 index 00000000..cd5c08d4 --- /dev/null +++ b/42sh/src/exec/launch_function.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* launch_function.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: wescande +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ +/* Updated: 2017/03/08 03:24:53 by wescande ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +static int do_function(t_process *p) +{ + ft_exec(&p->data.function.content); + return (ft_atoi(ft_getenv(data_singleton()->env, "?"))); +} + +int launch_function(t_process *p) +{ + pid_t pid; + + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + { + pid = fork(); + if (pid == 0) + { + data_singleton()->opts &= ~SH_INTERACTIVE; + data_singleton()->opts &= ~SH_OPTS_JOBC; + exit(do_function(p)); + } + else if (pid > 0) + return (pid); + } + else + do_function(p); + return (0); +} diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 72f080fd..080c92e1 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 00:11:15 by wescande ### ########.fr */ +/* Updated: 2017/03/08 03:23:16 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ t_itof g_launchmap[] = { - {PROCESS_FUNCTION, NULL}, + {PROCESS_FUNCTION, launch_function}, {PROCESS_BUILTIN, launch_builtin}, {PROCESS_FILE, launch_file}, {PROCESS_SUBSHELL, launch_subshell}, diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index 23c4fd13..790102fd 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* ast_copy.c :+: :+: :+: */ +/* node_copy.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ -/* Created: 2017/03/07 20:44:42 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:00:05 by ariard ### ########.fr */ +/* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ +/* Updated: 2017/03/08 04:40:50 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,13 +20,13 @@ void *node_copy(void *data) if (!data) return (NULL); old = data; - ft_bzero((void *)&new, sizeof(t_astdata)); + new = (t_astnode *)ft_memalloc(sizeof(t_astnode)); new->nest = old->nest; new->full = old->full; new->type = old->type; new->pattern = old->pattern; if (old->type == CMD || old->type == TK_ASSIGNEMENT_WORD) - { + { new->data.cmd.redir = ft_lstdup(&old->data.cmd.redir, &redir_copy); new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); } diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 5f27ecf0..08964e53 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/08 03:08:30 by wescande ### ########.fr */ +/* Updated: 2017/03/08 03:32:49 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,14 @@ int process_setexec(t_process *p) { + t_btree *func; p->data.cmd.path = NULL; p->data.cmd.execf = NULL; - if ((p->data.subshell.content = is_function(p))) + if ((func = is_function(p))) + { + p->data.subshell.content = func; p->type = PROCESS_FUNCTION; + } else if ((p->data.cmd.execf = is_builtin(p))) p->type = PROCESS_BUILTIN; else if (ft_strchr(p->data.cmd.av[0], '/')) diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index 23471c08..6cb3f743 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/08 03:07:01 by ariard ### ########.fr */ +/* Updated: 2017/03/08 03:26:28 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,7 @@ t_itof g_freemap[] = { - {PROCESS_FUNCTION, NULL}, + {PROCESS_FUNCTION, process_free_subshell}, {PROCESS_BUILTIN, NULL}, {PROCESS_FILE, process_free_cmd}, {PROCESS_SUBSHELL, process_free_subshell}, diff --git a/42sh/src/parser/add_func.c b/42sh/src/parser/add_func.c index 66041625..e417bcbf 100644 --- a/42sh/src/parser/add_func.c +++ b/42sh/src/parser/add_func.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/24 23:43:07 by ariard #+# #+# */ -/* Updated: 2017/03/08 03:04:45 by wescande ### ########.fr */ +/* Updated: 2017/03/08 03:21:13 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,6 +88,7 @@ int add_one_func(t_btree **ast, t_list **lst) { t_btree *func_ast; + (void)lst; func_ast = btree_map(*ast, node_copy); ft_lsteadd(&data_singleton()->lst_func, ft_lstnew(&func_ast, sizeof(*ast))); DG("arbre ajoute"); From 91a8e81c45726a071fd7a1b2a527784463452a1f Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 12:04:05 +0100 Subject: [PATCH 03/12] minor libft interface changes --- 42sh/libft | 2 +- 42sh/parser_init.c | 0 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/ft_exec.c | 2 +- 42sh/src/exec/node_copy.c | 6 +++--- 42sh/src/exec/redir_copy.c | 10 +++++----- 42sh/src/exec/set_process.c | 6 ++---- 42sh/src/exec/set_process_cmd.c | 2 +- 42sh/src/exec/set_process_map.c | 2 +- 42sh/src/exec/set_process_subshell.c | 2 +- 10 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 42sh/parser_init.c diff --git a/42sh/libft b/42sh/libft index 73c28532..b209bb1f 160000 --- a/42sh/libft +++ b/42sh/libft @@ -1 +1 @@ -Subproject commit 73c28532404e437d670607c909fbe56d717e9683 +Subproject commit b209bb1fb718a68256253d5ab5ff69a46a90d5d6 diff --git a/42sh/parser_init.c b/42sh/parser_init.c deleted file mode 100644 index e69de29b..00000000 diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index 2fafa04c..e8ef5244 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/08 03:25:23 by wescande ### ########.fr */ +/* Updated: 2017/03/08 11:50:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_exec.c b/42sh/src/exec/ft_exec.c index c3cb73dc..34a242b5 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/08 03:34:10 by wescande ### ########.fr */ +/* Updated: 2017/03/08 11:57:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/node_copy.c b/42sh/src/exec/node_copy.c index 790102fd..6c010038 100644 --- a/42sh/src/exec/node_copy.c +++ b/42sh/src/exec/node_copy.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:38:36 by wescande #+# #+# */ -/* Updated: 2017/03/08 04:40:50 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:01:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,10 +27,10 @@ void *node_copy(void *data) new->pattern = old->pattern; if (old->type == CMD || old->type == TK_ASSIGNEMENT_WORD) { - new->data.cmd.redir = ft_lstdup(&old->data.cmd.redir, &redir_copy); + new->data.cmd.redir = ft_lstmap(old->data.cmd.redir, &redir_copy); new->data.cmd.token = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); } if (old->type == TK_FOR || old->type == TK_PAREN_OPEN || old->type == TK_CASE) - new->data.cmd.wordlist = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); + new->data.cmd.wordlist = ft_ld_copy(old->data.cmd.token, &tab_esc_copy); return (new); } diff --git a/42sh/src/exec/redir_copy.c b/42sh/src/exec/redir_copy.c index 65e843e2..3dea51e4 100644 --- a/42sh/src/exec/redir_copy.c +++ b/42sh/src/exec/redir_copy.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:58 by ariard #+# #+# */ -/* Updated: 2017/03/08 00:41:57 by ariard ### ########.fr */ +/* Updated: 2017/03/08 11:53:26 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,14 +15,14 @@ void *redir_copy(void *data) { t_redir *old; - t_redir *new; + t_redir *new; if (!data) return (NULL); old = data; - ft_bzero((void *)&new, sizeof(t_astdata)); + new = (t_redir *)ft_memalloc(sizeof(t_redir)); new->type = old->type; new->n = old->n; new->word = ft_strdup(old->word); - return (0); -} + return (new); +} diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index 336bd5bb..b3912717 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/07 21:12:02 by wescande ### ########.fr */ +/* Updated: 2017/03/08 11:53:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,10 +38,8 @@ int set_process(t_process *p, t_btree *ast) p->to_close = fds[PIPE_READ]; p->fdout = fds[PIPE_WRITE]; exec->fdin = fds[PIPE_READ]; - p->redirs = ft_lstmap(cmd->redir, ft_id); + p->redirs = ft_lstmap(cmd->redir, &redir_copy); if (set_process_map(p, ast, cmd)) return (1); -// if (exec->control_count) -// p->attrs |= PROCESS_CONTROL; return (0); } diff --git a/42sh/src/exec/set_process_cmd.c b/42sh/src/exec/set_process_cmd.c index 4a7c6a1b..e2bdfd50 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/set_process_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:44:40 by wescande ### ########.fr */ +/* Updated: 2017/03/08 11:49:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process_map.c b/42sh/src/exec/set_process_map.c index 9db3679d..bdf91a50 100644 --- a/42sh/src/exec/set_process_map.c +++ b/42sh/src/exec/set_process_map.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:08:12 by wescande #+# #+# */ -/* Updated: 2017/03/08 00:23:22 by wescande ### ########.fr */ +/* Updated: 2017/03/08 11:50:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/set_process_subshell.c b/42sh/src/exec/set_process_subshell.c index 897a9183..e44baf60 100644 --- a/42sh/src/exec/set_process_subshell.c +++ b/42sh/src/exec/set_process_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:52:45 by ariard ### ########.fr */ +/* Updated: 2017/03/08 11:51:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 8cba9bc113a772ef884494bb28ae302819fe49d9 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 12:21:13 +0100 Subject: [PATCH 04/12] issue #52: rewrote lexer_sep entirely --- 42sh/includes/minishell.h | 2 +- 42sh/src/lexer/lexer_delim.c | 2 +- 42sh/src/lexer/lexer_end.c | 2 +- 42sh/src/lexer/lexer_great.c | 2 +- 42sh/src/lexer/lexer_less.c | 2 +- 42sh/src/lexer/lexer_lessand.c | 2 +- 42sh/src/lexer/lexer_paren.c | 4 ++-- 42sh/src/lexer/lexer_sep.c | 26 ++++++++++---------------- 42sh/src/lexer/lexer_word.c | 2 +- 42sh/src/lexer/token_print.c | 4 ++-- 42sh/src/main/main.c | 2 +- 11 files changed, 22 insertions(+), 28 deletions(-) diff --git a/42sh/includes/minishell.h b/42sh/includes/minishell.h index deac19e8..9b20a56e 100644 --- a/42sh/includes/minishell.h +++ b/42sh/includes/minishell.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 13:07:44 by jhalford #+# #+# */ -/* Updated: 2017/03/07 21:13:31 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:05:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_delim.c b/42sh/src/lexer/lexer_delim.c index d67b61d5..72b7c47c 100644 --- a/42sh/src/lexer/lexer_delim.c +++ b/42sh/src/lexer/lexer_delim.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:44 by jhalford #+# #+# */ -/* Updated: 2017/03/05 17:08:23 by ariard ### ########.fr */ +/* Updated: 2017/03/08 12:09:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_end.c b/42sh/src/lexer/lexer_end.c index 4e3be646..5e0b6710 100644 --- a/42sh/src/lexer/lexer_end.c +++ b/42sh/src/lexer/lexer_end.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */ -/* Updated: 2017/03/05 17:29:17 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 12:12:40 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_great.c b/42sh/src/lexer/lexer_great.c index 6e582bdc..f6f6a262 100644 --- a/42sh/src/lexer/lexer_great.c +++ b/42sh/src/lexer/lexer_great.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:35 by jhalford #+# #+# */ -/* Updated: 2017/03/05 18:20:02 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:10:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_less.c b/42sh/src/lexer/lexer_less.c index 9d08611c..02e1ee54 100644 --- a/42sh/src/lexer/lexer_less.c +++ b/42sh/src/lexer/lexer_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ -/* Updated: 2017/03/05 18:19:48 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:10:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_lessand.c b/42sh/src/lexer/lexer_lessand.c index f7d30d45..3930c001 100644 --- a/42sh/src/lexer/lexer_lessand.c +++ b/42sh/src/lexer/lexer_lessand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 11:58:51 by jhalford #+# #+# */ -/* Updated: 2017/03/05 18:05:39 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:12:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_paren.c b/42sh/src/lexer/lexer_paren.c index 735e56fe..5abf4b69 100644 --- a/42sh/src/lexer/lexer_paren.c +++ b/42sh/src/lexer/lexer_paren.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 17:37:15 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:48:06 by ariard ### ########.fr */ +/* Updated: 2017/03/08 12:14:09 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,7 +18,7 @@ int lexer_paren(t_list **alst, t_lexer *lexer) token = (*alst)->content; if (token->type) - lexer_lex(&(*alst)->next, lexer); + return (lexer_lex(&(*alst)->next, lexer)); if (lexer->str[lexer->pos] == '(') { token->type = TK_PAREN_OPEN; diff --git a/42sh/src/lexer/lexer_sep.c b/42sh/src/lexer/lexer_sep.c index 6420498f..b44b41c5 100644 --- a/42sh/src/lexer/lexer_sep.c +++ b/42sh/src/lexer/lexer_sep.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/30 16:29:57 by jhalford #+# #+# */ -/* Updated: 2017/03/07 20:26:36 by ariard ### ########.fr */ +/* Updated: 2017/03/08 12:20:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,26 +19,20 @@ int lexer_sep(t_list **alst, t_lexer *lexer) char cn; lexer->state = DEFAULT; - if (*alst) - { - token = (*alst)->content; - if (*token->data) - return (lexer_sep(&(*alst)->next, lexer)); - } - else - { - token = token_init(); - *alst = ft_lstnew(token, sizeof(*token)); - } token = (*alst)->content; + if (token->type) + return (lexer_lex(&(*alst)->next, lexer)); c = lexer->str[lexer->pos]; - cn = lexer->str[lexer->pos + 1]; + lexer->pos++; + cn = lexer->str[lexer->pos]; if (c == '&') token->type = cn == '&' ? TK_AND_IF : TK_AMP; else if (c == '|') token->type = cn == '|' ? TK_OR_IF : TK_PIPE; - token->type = (c == ';') ? TK_SEMI : token->type; - token->type = (c == ';') && (cn == ';') ? TK_DSEMI : token->type; - lexer->pos += 1 + (token->type & (TK_AND_IF | TK_OR_IF | TK_DSEMI) ? 1 : 0); + else if (c == ';') + token->type = cn == ';' ? TK_DSEMI : TK_SEMI; + if (token->type == TK_AND_IF || token->type == TK_OR_IF + || token->type == TK_DSEMI) + lexer->pos++; return (lexer_lex(&(*alst)->next, lexer)); } diff --git a/42sh/src/lexer/lexer_word.c b/42sh/src/lexer/lexer_word.c index d5ad413c..b3e8aea4 100644 --- a/42sh/src/lexer/lexer_word.c +++ b/42sh/src/lexer/lexer_word.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:11 by jhalford #+# #+# */ -/* Updated: 2017/03/07 21:00:18 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:10:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_print.c b/42sh/src/lexer/token_print.c index c4529027..c17e1605 100644 --- a/42sh/src/lexer/token_print.c +++ b/42sh/src/lexer/token_print.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:39:01 by jhalford #+# #+# */ -/* Updated: 2017/03/05 16:27:58 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 12:14:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ void token_print(t_list *lst) if (lst->content) token = lst->content; if (token->type) - DG("token : %s data [%s]\n", read_state(token->type), token->data); + DG("token : %s data [%s]", read_state(token->type), token->data); lst = lst->next; } } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 0527cf28..e20fcf4f 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/07 21:53:23 by ariard ### ########.fr */ +/* Updated: 2017/03/08 12:20:37 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 8a46d9fe2a4f72853698dd79f821585bba46cbcd Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 12:44:09 +0100 Subject: [PATCH 05/12] issue #48 first step --- 42sh/includes/exec.h | 4 ++-- 42sh/src/exec/launch_file.c | 9 +++++++-- 42sh/src/exec/process_setexec.c | 14 +++++++++++--- 42sh/src/exec/redir_free.c | 6 +----- 42sh/src/job-control/process_free.c | 6 +++--- 42sh/src/main/main.c | 2 +- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 372c4ef0..e8c72bc6 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/08 03:25:53 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:26:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,7 +50,7 @@ struct s_data_cmd char **av; char *path; t_execf *execf; - struct stat stat; + struct stat *stat; }; struct s_data_cond diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index afe5cb81..56b06a04 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/07 21:33:56 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:42:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,7 +25,12 @@ int launch_file(t_process *p) ft_dprintf(2, "{red}%s: command not found: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(127); } - else if (S_ISDIR(p->data.cmd.stat.st_mode)) + else if (!p->data.cmd.stat) + { + ft_dprintf(2, "{red}%s: %s: no such file or directory\n", SHELL_NAME, p->data.cmd.av[0]); + exit(127); + } + else if (S_ISDIR(p->data.cmd.stat->st_mode)) { ft_dprintf(2, "{red}%s: %s: Is a directory{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(126); diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 08964e53..8d10402f 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/08 03:32:49 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:42:32 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,8 @@ int process_setexec(t_process *p) t_btree *func; p->data.cmd.path = NULL; p->data.cmd.execf = NULL; + p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); + DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); if ((func = is_function(p))) { p->data.subshell.content = func; @@ -29,7 +31,8 @@ int process_setexec(t_process *p) p->type = PROCESS_FILE; p->data.cmd.execf = &execve; p->data.cmd.path = ft_strdup(p->data.cmd.av[0]); - stat(p->data.cmd.path, &p->data.cmd.stat); + if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) + ft_memdel((void**)&p->data.cmd.stat); } else { @@ -37,7 +40,12 @@ int process_setexec(t_process *p) if (ft_hash(p)) { p->data.cmd.execf = &execve; - stat(p->data.cmd.path, &p->data.cmd.stat); + DG("found hash at [%s]", p->data.cmd.path); + if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) + { + ft_memdel((void**)&p->data.cmd.stat); + ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path); + } } } return (0); diff --git a/42sh/src/exec/redir_free.c b/42sh/src/exec/redir_free.c index fa19403f..54f40a65 100644 --- a/42sh/src/exec/redir_free.c +++ b/42sh/src/exec/redir_free.c @@ -6,7 +6,7 @@ /* By: ariard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/03 18:12:57 by ariard #+# #+# */ -/* Updated: 2017/03/05 18:06:24 by ariard ### ########.fr */ +/* Updated: 2017/03/08 12:40:34 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,9 +22,5 @@ void redir_free(void *data, size_t content_size) { ft_strdel(&redir->word); } - /* else */ - /* redir->type = 0; */ - /* redir->n = 0; */ - /* redir->close = 1; */ free(redir); } diff --git a/42sh/src/job-control/process_free.c b/42sh/src/job-control/process_free.c index 6cb3f743..be1d1d6c 100644 --- a/42sh/src/job-control/process_free.c +++ b/42sh/src/job-control/process_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 12:41:11 by jhalford #+# #+# */ -/* Updated: 2017/03/08 03:26:28 by wescande ### ########.fr */ +/* Updated: 2017/03/08 12:40:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ t_itof g_freemap[] = { {PROCESS_FUNCTION, process_free_subshell}, - {PROCESS_BUILTIN, NULL}, + {PROCESS_BUILTIN, process_free_cmd}, {PROCESS_FILE, process_free_cmd}, {PROCESS_SUBSHELL, process_free_subshell}, {PROCESS_WHILE, process_free_cond}, @@ -36,6 +36,6 @@ void process_free(void *content, size_t content_size) return ; if (g_freemap[p->type].f) (g_freemap[p->type].f)(p); - ft_lstdel(&p->redirs, ft_lst_cfree); + ft_lstdel(&p->redirs, redir_free); free(p); } diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index e20fcf4f..798ba6ce 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/08 12:20:37 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 12:41:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From e711ffc92704dea451bd6a2cb7ec1a48a0acc202 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 13:07:46 +0100 Subject: [PATCH 06/12] issue #50 done --- 42sh/Makefile | 1 - 42sh/includes/ft_readline.h | 14 ++++++------- 42sh/{ => sample}/laurier.sh | 0 42sh/src/builtin/builtin_exit.c | 12 ++++++------ 42sh/src/exec/launch_builtin.c | 2 +- 42sh/src/exec/process_setexec.c | 2 +- 42sh/src/line-editing/control_c_and_d.c | 2 +- 42sh/src/line-editing/readline.c | 2 +- 42sh/src/main/data_init.c | 3 ++- 42sh/src/main/main.c | 4 ++-- 42sh/src/main/shell_exit.c | 26 ------------------------- 42sh/src/main/shell_init.c | 3 +-- 12 files changed, 22 insertions(+), 49 deletions(-) rename 42sh/{ => sample}/laurier.sh (100%) delete mode 100644 42sh/src/main/shell_exit.c diff --git a/42sh/Makefile b/42sh/Makefile index 2af77340..7e90da5e 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -250,7 +250,6 @@ main/data_singleton.c\ main/ft_putast.c\ main/instruction_free.c\ main/main.c\ -main/shell_exit.c\ main/shell_get_avdata.c\ main/shell_get_opts.c\ main/shell_init.c\ diff --git a/42sh/includes/ft_readline.h b/42sh/includes/ft_readline.h index 419d74df..44fc4bd5 100644 --- a/42sh/includes/ft_readline.h +++ b/42sh/includes/ft_readline.h @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/23 10:35:44 by gwojda #+# #+# */ -/* Updated: 2017/03/07 18:36:00 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:00:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,12 +54,12 @@ # define TOUCHE_F5 892427035 # define TOUCHE_F6 925981467 -# define IS_QUOTES (1 << 0) -# define IS_BQUOTES (1 << 1) -# define IS_DQUOTES (1 << 2) -# define IS_BSLASH (1 << 3) -# define IS_ACCOLADE (1 << 4) -# define IS_BRACKET (1 << 5) +/* # define IS_QUOTES (1 << 0) */ +/* # define IS_BQUOTES (1 << 1) */ +/* # define IS_DQUOTES (1 << 2) */ +/* # define IS_BSLASH (1 << 3) */ +/* # define IS_ACCOLADE (1 << 4) */ +/* # define IS_BRACKET (1 << 5) */ # define STR data_singleton()->line.input # define POS data_singleton()->line.pos diff --git a/42sh/laurier.sh b/42sh/sample/laurier.sh similarity index 100% rename from 42sh/laurier.sh rename to 42sh/sample/laurier.sh diff --git a/42sh/src/builtin/builtin_exit.c b/42sh/src/builtin/builtin_exit.c index 370e60ac..80a40fca 100644 --- a/42sh/src/builtin/builtin_exit.c +++ b/42sh/src/builtin/builtin_exit.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:28:41 by jhalford #+# #+# */ -/* Updated: 2017/02/18 16:48:42 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 13:04:52 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,15 +29,15 @@ int builtin_exit(const char *path, char *const av[], char *const envp[]) ft_dprintf(2, "{red}%s: you have live jobs (running or suspended).{eoc}\n", SHELL_NAME); return (0); } - if (av[1]) + if (av && av[1]) status = ft_atoi(av[1]); else - { - /* status = ft_atoi(ft_getenv(data_singleton()->env, "?")); */ - status = 0; - } + status = ft_atoi(ft_getenv(data_singleton()->env, "?")); ft_save_termios(-1); ft_free_hash_table(); + data_exit(); + if (SH_IS_INTERACTIVE(data_singleton()->opts)) + tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); exit(status); return (0); } diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/launch_builtin.c index aed14ec5..47d090cc 100644 --- a/42sh/src/exec/launch_builtin.c +++ b/42sh/src/exec/launch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:51:58 by wescande ### ########.fr */ +/* Updated: 2017/03/08 13:04:29 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c index 8d10402f..9ad7aedf 100644 --- a/42sh/src/exec/process_setexec.c +++ b/42sh/src/exec/process_setexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:42:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 12:54:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/control_c_and_d.c b/42sh/src/line-editing/control_c_and_d.c index d484cbaa..b80a982c 100644 --- a/42sh/src/line-editing/control_c_and_d.c +++ b/42sh/src/line-editing/control_c_and_d.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/02 15:17:28 by gwojda #+# #+# */ -/* Updated: 2017/02/14 14:08:21 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 12:56:46 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/line-editing/readline.c b/42sh/src/line-editing/readline.c index f9bf13df..19b57e47 100644 --- a/42sh/src/line-editing/readline.c +++ b/42sh/src/line-editing/readline.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */ -/* Updated: 2017/03/07 11:20:27 by gwojda ### ########.fr */ +/* Updated: 2017/03/08 13:00:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index ce7e2a03..e1155419 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:38:43 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:05:23 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,6 +21,7 @@ int data_init(void) data = data_singleton(); data->env = ft_sstrdup(environ); + set_exitstatus(0, 1); data->comp = NULL; data->opts = 0; data->exec.fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC); diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 798ba6ce..22308690 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/08 12:41:03 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 12:59:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -124,6 +124,6 @@ int main(int ac, char **av) // parser_clean; ; } - shell_exit(); + builtin_exit(NULL, NULL, NULL); return (0); } diff --git a/42sh/src/main/shell_exit.c b/42sh/src/main/shell_exit.c deleted file mode 100644 index 30d4ab43..00000000 --- a/42sh/src/main/shell_exit.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* shell_exit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/12 17:37:04 by jhalford #+# #+# */ -/* Updated: 2017/02/21 20:14:43 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -void shell_exit(void) -{ - t_data *data; - - /* DG("shell_exit()"); */ - data = data_singleton(); - data_exit(); - if (SH_HAS_JOBC(data->opts)) - job_kill_all(); - if (SH_IS_INTERACTIVE(data->opts)) - tcsetattr(STDIN, TCSANOW, &data_singleton()->jobc.shell_tmodes); -} diff --git a/42sh/src/main/shell_init.c b/42sh/src/main/shell_init.c index abf15a8e..d767aebd 100644 --- a/42sh/src/main/shell_init.c +++ b/42sh/src/main/shell_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/12 17:23:59 by jhalford #+# #+# */ -/* Updated: 2017/03/07 16:38:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:04:03 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,6 @@ void shell_init(int ac, char **av) data = data_singleton(); data->argc = ac; data->argv = ft_sstrdup(av); - /* atexit(&shell_exit); */ shell_get_opts(ac, av); if (SH_IS_INTERACTIVE(data->opts)) { From 852895104173d966b5a9854ab70384b807c3323c Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 13:48:58 +0100 Subject: [PATCH 07/12] heredoc changes first step --- 42sh/src/lexer/lexer_dless.c | 28 ++++++++++++++-------------- 42sh/src/lexer/lexer_less.c | 7 ++----- 42sh/src/lexer/token_free.c | 2 +- 42sh/src/lexer/token_init.c | 2 +- 42sh/src/main/data_init.c | 2 +- 42sh/src/main/main.c | 2 +- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/42sh/src/lexer/lexer_dless.c b/42sh/src/lexer/lexer_dless.c index d3859b87..4ee8434c 100644 --- a/42sh/src/lexer/lexer_dless.c +++ b/42sh/src/lexer/lexer_dless.c @@ -10,20 +10,20 @@ int lexer_dless(t_list **alst, t_lexer *lexer) (void)lexer; heredoc_lst = *(t_list**)lexer->heredoc_stack->content; heredoc_tok = heredoc_lst->content; - if (!(heredoc_lst->next)) - { - ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); - return (1); - } - eof_tok = heredoc_lst->next->content; - if (!(eof_tok->type == TK_WORD)) - { - ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); - return (1); - } - DG("heredoc contains [%s]", heredoc_tok->data); - DG("heredoc ends at [%s]", eof_tok->data); - DG("input is [%s]", lexer->str + lexer->pos); + /* if (!(heredoc_lst->next)) */ + /* { */ + /* ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); */ + /* return (1); */ + /* } */ + /* eof_tok = heredoc_lst->next->content; */ + /* if (!(eof_tok->type == TK_WORD)) */ + /* { */ + /* ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); */ + /* return (1); */ + /* } */ + /* DG("heredoc contains [%s]", heredoc_tok->data); */ + /* DG("heredoc ends at [%s]", eof_tok->data); */ + /* DG("input is [%s]", lexer->str + lexer->pos); */ if (ft_strcmp(eof_tok->data, lexer->str + lexer->pos) == 0) { pop(&lexer->stack); diff --git a/42sh/src/lexer/lexer_less.c b/42sh/src/lexer/lexer_less.c index 02e1ee54..8b9e0b0d 100644 --- a/42sh/src/lexer/lexer_less.c +++ b/42sh/src/lexer/lexer_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:10:38 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:27:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,6 @@ int lexer_less(t_list **alst, t_lexer *lexer) t_token *token; token = (*alst)->content; - token_append(token, lexer, 0, 0); lexer->pos++; if (lexer->str[lexer->pos] == '&') { @@ -28,11 +27,9 @@ int lexer_less(t_list **alst, t_lexer *lexer) } if (lexer->str[lexer->pos] == '<') { - token_free(token, 0); - (*alst)->content = token_init(); token->type = TK_DLESS; - lexer->pos++; push(&lexer->stack, DLESS); + lexer->pos++; lexer->state = DEFAULT; ft_lsteadd(&lexer->heredoc_stack, ft_lstnew(alst, sizeof(alst))); return (lexer_lex(&(*alst)->next, lexer)); diff --git a/42sh/src/lexer/token_free.c b/42sh/src/lexer/token_free.c index 0727f7a5..148ff2b6 100644 --- a/42sh/src/lexer/token_free.c +++ b/42sh/src/lexer/token_free.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:07:30 by jhalford #+# #+# */ -/* Updated: 2017/03/03 18:57:46 by ariard ### ########.fr */ +/* Updated: 2017/03/08 13:22:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/token_init.c b/42sh/src/lexer/token_init.c index 4739d61b..3e58f078 100644 --- a/42sh/src/lexer/token_init.c +++ b/42sh/src/lexer/token_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */ -/* Updated: 2017/02/20 20:55:35 by ariard ### ########.fr */ +/* Updated: 2017/03/08 13:21:55 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index e1155419..462e0902 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/08 13:05:23 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:48:27 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 22308690..1f7a6f58 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/08 12:59:55 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 13:27:47 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 4ee0f246328ab4fa1ec80fcb766c1ae58e43380f Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 14:28:34 +0100 Subject: [PATCH 08/12] compils now --- 42sh/src/exec/launch_process.c | 2 +- 42sh/src/lexer/lexer_dless.c | 22 +++++++++++----------- 42sh/src/main/data_init.c | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index 080c92e1..e812c0b3 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 03:23:16 by wescande ### ########.fr */ +/* Updated: 2017/03/08 14:26:41 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_dless.c b/42sh/src/lexer/lexer_dless.c index 4ee8434c..16fb05f3 100644 --- a/42sh/src/lexer/lexer_dless.c +++ b/42sh/src/lexer/lexer_dless.c @@ -10,17 +10,17 @@ int lexer_dless(t_list **alst, t_lexer *lexer) (void)lexer; heredoc_lst = *(t_list**)lexer->heredoc_stack->content; heredoc_tok = heredoc_lst->content; - /* if (!(heredoc_lst->next)) */ - /* { */ - /* ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); */ - /* return (1); */ - /* } */ - /* eof_tok = heredoc_lst->next->content; */ - /* if (!(eof_tok->type == TK_WORD)) */ - /* { */ - /* ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); */ - /* return (1); */ - /* } */ + if (!(heredoc_lst->next)) + { + ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); + return (1); + } + eof_tok = heredoc_lst->next->content; + if (!(eof_tok->type == TK_WORD)) + { + ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); + return (1); + } /* DG("heredoc contains [%s]", heredoc_tok->data); */ /* DG("heredoc ends at [%s]", eof_tok->data); */ /* DG("input is [%s]", lexer->str + lexer->pos); */ diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 462e0902..7e1bc423 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/08 13:48:27 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:26:44 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From 95be4e209ccc9d0fb0be96dfea792717d4d2ad71 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 14:52:44 +0100 Subject: [PATCH 09/12] stuff --- 42sh/Makefile | 2 +- 42sh/includes/exec.h | 6 ++-- 42sh/src/exec/exec_leaf.c | 2 +- 42sh/src/exec/exec_reset.c | 31 ++++++++++++++++++++ 42sh/src/exec/launch_builtin.c | 2 +- 42sh/src/exec/launch_file.c | 5 +++- 42sh/src/exec/launch_process.c | 24 +-------------- 42sh/src/exec/launch_subshell.c | 2 +- 42sh/src/exec/process_reset.c | 8 ++--- 42sh/src/exec/process_setexec.c | 52 --------------------------------- 42sh/src/exec/set_process.c | 8 ++--- 42sh/src/exec/set_process_cmd.c | 38 ++++++++++++++++++++++-- 42sh/src/exec/set_process_map.c | 6 ++-- 42sh/src/main/data_init.c | 14 ++------- 42sh/src/main/main.c | 2 +- 15 files changed, 92 insertions(+), 110 deletions(-) create mode 100644 42sh/src/exec/exec_reset.c delete mode 100644 42sh/src/exec/process_setexec.c diff --git a/42sh/Makefile b/42sh/Makefile index 7e90da5e..0cac1aa5 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -71,6 +71,7 @@ exec/exec_leaf.c\ exec/exec_math.c\ exec/exec_or_if.c\ exec/exec_pipe.c\ +exec/exec_reset.c\ exec/exec_semi.c\ exec/exec_var.c\ exec/fd_is_valid.c\ @@ -91,7 +92,6 @@ exec/mark_process_status.c\ exec/node_copy.c\ exec/process_redirect.c\ exec/process_reset.c\ -exec/process_setexec.c\ exec/process_setgroup.c\ exec/process_setsig.c\ exec/redir_copy.c\ diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index e8c72bc6..59fd4d22 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/08 12:26:19 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:51:04 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -131,7 +131,8 @@ extern t_itof g_execmap[]; extern t_itof g_redirmap[]; extern t_itof g_launchmap[]; -int process_setexec(t_process *p); + +int exec_reset(void); int process_setgroup(t_process *p, pid_t pid); void process_setsig(void); void process_reset(t_process *p); @@ -190,6 +191,7 @@ int launch_function(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, t_cmd *cmd); int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd); diff --git a/42sh/src/exec/exec_leaf.c b/42sh/src/exec/exec_leaf.c index e8ef5244..95f1d38b 100644 --- a/42sh/src/exec/exec_leaf.c +++ b/42sh/src/exec/exec_leaf.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:47:30 by wescande #+# #+# */ -/* Updated: 2017/03/08 11:50:20 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:47:30 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/exec_reset.c b/42sh/src/exec/exec_reset.c new file mode 100644 index 00000000..2b925196 --- /dev/null +++ b/42sh/src/exec/exec_reset.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* exec_reset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 14:31:42 by jhalford #+# #+# */ +/* Updated: 2017/03/08 14:45:10 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int exec_reset(void) +{ + t_exec *exec; + + exec = &data_singleton()->exec; + exec->fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC); + exec->fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC); + exec->fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC); + exec->op_stack = NULL; + exec->fdin = STDIN; + exec->attrs = 0; + exec->job.id = 0; + exec->job.pgid = 0; + exec->job.attrs = 0; + exec->job.first_process = NULL; + return (0); +} diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/launch_builtin.c index 47d090cc..71497c10 100644 --- a/42sh/src/exec/launch_builtin.c +++ b/42sh/src/exec/launch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/08 13:04:29 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:43:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/launch_file.c b/42sh/src/exec/launch_file.c index 56b06a04..180d0f58 100644 --- a/42sh/src/exec/launch_file.c +++ b/42sh/src/exec/launch_file.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 14:53:31 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:42:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:46:08 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -40,10 +40,13 @@ int launch_file(t_process *p) ft_dprintf(2, "{red}%s: permission denied: %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(126); } + // for all leaves process_setgroup(p, 0); process_setsig(); if (process_redirect(p)) exit (1); + exec_reset(); + // (*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env); ft_dprintf(2, "{red}%s: internal execve error on %s{eoc}\n", SHELL_NAME, p->data.cmd.av[0]); exit(42); diff --git a/42sh/src/exec/launch_process.c b/42sh/src/exec/launch_process.c index e812c0b3..dbe58ef0 100644 --- a/42sh/src/exec/launch_process.c +++ b/42sh/src/exec/launch_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:20:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:26:41 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:45:54 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,7 +28,6 @@ t_itof g_launchmap[] = int launch_process(t_process *p) { -// int i; int pid; if (p->type >= PROCESS_MAX) @@ -42,25 +41,4 @@ int launch_process(t_process *p) p->pid = pid; process_setgroup(p, pid); return (0); - /* - i = 0; - while (g_launchmap[i].id) - { - if (p->type == g_launchmap[i].id) - { - if (!g_launchmap[i].f) - return (-1); - p->attrs &= ~PROCESS_STATE_MASK; - p->attrs |= PROCESS_RUNNING; - if ((pid = (*g_launchmap[i].f)(p))) - { - p->pid = pid; - process_setgroup(p, pid); - return (0); - } - } - i++; - } - return (-1); - */ } diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index aa2f481d..98fd0bcb 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/launch_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/08 00:32:13 by wescande ### ########.fr */ +/* Updated: 2017/03/08 14:44:57 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_reset.c b/42sh/src/exec/process_reset.c index 3b5c065e..7e12b8b3 100644 --- a/42sh/src/exec/process_reset.c +++ b/42sh/src/exec/process_reset.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/07 17:44:22 by jhalford #+# #+# */ -/* Updated: 2017/03/07 14:36:21 by wescande ### ########.fr */ +/* Updated: 2017/03/08 14:51:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,12 +18,10 @@ void process_reset(t_process *p) // p->path = NULL; // p->execf = NULL; p->pid = 0; - /* p->fdin = STDIN; */ - /* p->fdout = STDOUT; */ + p->fdin = STDIN; + p->fdout = STDOUT; p->to_close = 0; p->redirs = NULL; p->status = -1; p->attrs = 0; -// p->condition = NULL; -// p->content = NULL; } diff --git a/42sh/src/exec/process_setexec.c b/42sh/src/exec/process_setexec.c deleted file mode 100644 index 9ad7aedf..00000000 --- a/42sh/src/exec/process_setexec.c +++ /dev/null @@ -1,52 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* process_setexec.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/12/13 17:07:10 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:54:54 by jhalford ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "minishell.h" - -int process_setexec(t_process *p) -{ - t_btree *func; - p->data.cmd.path = NULL; - p->data.cmd.execf = NULL; - p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); - DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); - if ((func = is_function(p))) - { - p->data.subshell.content = func; - p->type = PROCESS_FUNCTION; - } - else if ((p->data.cmd.execf = is_builtin(p))) - p->type = PROCESS_BUILTIN; - else if (ft_strchr(p->data.cmd.av[0], '/')) - { - p->type = PROCESS_FILE; - p->data.cmd.execf = &execve; - p->data.cmd.path = ft_strdup(p->data.cmd.av[0]); - if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) - ft_memdel((void**)&p->data.cmd.stat); - } - else - { - p->type = PROCESS_FILE; - if (ft_hash(p)) - { - p->data.cmd.execf = &execve; - DG("found hash at [%s]", p->data.cmd.path); - if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) - { - ft_memdel((void**)&p->data.cmd.stat); - ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path); - } - } - } - return (0); -} diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index b3912717..a19e1e1a 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 11:53:31 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:51:22 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ int set_process(t_process *p, t_btree *ast) int fds[2]; cmd = &((t_astnode *)ast->item)->data.cmd; - process_reset(p); + /* process_reset(p); */ exec = &data_singleton()->exec; op = pop(&exec->op_stack); if ((EXEC_IS_AND_IF(exec->attrs) @@ -39,7 +39,5 @@ int set_process(t_process *p, t_btree *ast) p->fdout = fds[PIPE_WRITE]; exec->fdin = fds[PIPE_READ]; p->redirs = ft_lstmap(cmd->redir, &redir_copy); - if (set_process_map(p, ast, cmd)) - return (1); - return (0); + return (set_process_map(p, ast, cmd)); } diff --git a/42sh/src/exec/set_process_cmd.c b/42sh/src/exec/set_process_cmd.c index e2bdfd50..3d4c3c72 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/set_process_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/08 11:49:32 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:46:10 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,43 @@ int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd) { + t_btree *func; + (void)ast; if (!(p->data.cmd.av = token_to_argv(cmd->token, 1))) return (1); - process_setexec(p); + p->data.cmd.path = NULL; + p->data.cmd.execf = NULL; + p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); + DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); + if ((func = is_function(p))) + { + p->data.subshell.content = func; + p->type = PROCESS_FUNCTION; + } + else if ((p->data.cmd.execf = is_builtin(p))) + p->type = PROCESS_BUILTIN; + else if (ft_strchr(p->data.cmd.av[0], '/')) + { + p->type = PROCESS_FILE; + p->data.cmd.execf = &execve; + p->data.cmd.path = ft_strdup(p->data.cmd.av[0]); + if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) + ft_memdel((void**)&p->data.cmd.stat); + } + else + { + p->type = PROCESS_FILE; + if (ft_hash(p)) + { + p->data.cmd.execf = &execve; + DG("found hash at [%s]", p->data.cmd.path); + if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) + { + ft_memdel((void**)&p->data.cmd.stat); + ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path); + } + } + } return (0); } diff --git a/42sh/src/exec/set_process_map.c b/42sh/src/exec/set_process_map.c index bdf91a50..3e32cc57 100644 --- a/42sh/src/exec/set_process_map.c +++ b/42sh/src/exec/set_process_map.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:08:12 by wescande #+# #+# */ -/* Updated: 2017/03/08 11:50:08 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:48:02 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -48,8 +48,8 @@ int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd) if (item->type == g_setprocessmap[i].id) { if (!g_setprocessmap[i].f) - return (0); + return (1); return ((*g_setprocessmap[i].f)(p, ast, cmd)); } - return (0); + return (1); } diff --git a/42sh/src/main/data_init.c b/42sh/src/main/data_init.c index 7e1bc423..843047d7 100644 --- a/42sh/src/main/data_init.c +++ b/42sh/src/main/data_init.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 19:26:32 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:26:44 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:39:07 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,17 +24,7 @@ int data_init(void) set_exitstatus(0, 1); data->comp = NULL; data->opts = 0; - data->exec.fd_save[0] = fcntl(0, F_DUPFD_CLOEXEC); - data->exec.fd_save[1] = fcntl(1, F_DUPFD_CLOEXEC); - data->exec.fd_save[2] = fcntl(2, F_DUPFD_CLOEXEC); - data->exec.op_stack = NULL; - data->exec.fdin = STDIN; - data->exec.attrs = 0; - - data->exec.job.id = 0; - data->exec.job.pgid = 0; - data->exec.job.attrs = 0; - data->exec.job.first_process = NULL; + exec_reset(); data->jobc.first_job = NULL; data->jobc.current_id = 1; diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 1f7a6f58..7cf15069 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/08 13:27:47 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:39:33 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ From e2a254863c24cdb257e6553844ca22938e441fe9 Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 8 Mar 2017 14:53:11 +0100 Subject: [PATCH 10/12] rectif du glob sur l'affichage du pattern quand pas de match, et ajout du / quand match avec un dossier --- 42sh/src/glob/dir_glob.c | 12 ++++++++---- 42sh/src/glob/glob.c | 5 ++--- 42sh/src/glob/match_pattern.c | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/42sh/src/glob/dir_glob.c b/42sh/src/glob/dir_glob.c index 2e9f3281..e83d55b9 100644 --- a/42sh/src/glob/dir_glob.c +++ b/42sh/src/glob/dir_glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/30 12:07:16 by wescande #+# #+# */ -/* Updated: 2017/02/24 22:04:49 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:50:58 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -49,9 +49,13 @@ int dir_research(t_glob *gl, char *p, { DIR *dir; struct dirent *in; - int ret; - ret = 0; + if (!pat) + { + gl->found = 1; + ft_ld_pushfront(&gl->match, ft_strjoin(p, "/")); + return (0); + } if ((ft_strlen(p) <= 1 || p[ft_strlen(p) - 1] != '.') && is_directory(p)) { dir = opendir(p); @@ -60,5 +64,5 @@ int dir_research(t_glob *gl, char *p, (char *[2]){p, in->d_name}, pat, recursive); closedir(dir); } - return (ret); + return (0); } diff --git a/42sh/src/glob/glob.c b/42sh/src/glob/glob.c index b44b5c89..f3bbc2cf 100644 --- a/42sh/src/glob/glob.c +++ b/42sh/src/glob/glob.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/04 16:29:54 by wescande #+# #+# */ -/* Updated: 2017/03/03 20:38:53 by wescande ### ########.fr */ +/* Updated: 2017/03/08 14:50:56 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,8 +66,7 @@ char **glob(char *pat, unsigned char *esc, else dir_research(&gl, "/", gl.pat + 1, 0); if (!gl.found) - ft_ld_pushfront(&gl.match, - ft_strjoin(gl.cur_dir ? "" : "./", CH(gl.m_pat)[0])); + ft_ld_pushfront(&gl.match, ft_strdup(CH(gl.m_pat)[0])); if (!gl.m_pat->next) break ; gl.m_pat = gl.m_pat->next; diff --git a/42sh/src/glob/match_pattern.c b/42sh/src/glob/match_pattern.c index f3573fe5..57323c48 100644 --- a/42sh/src/glob/match_pattern.c +++ b/42sh/src/glob/match_pattern.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/24 17:30:23 by wescande #+# #+# */ -/* Updated: 2017/02/24 22:06:01 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:35:43 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -90,6 +90,7 @@ static char *manage_pat(t_glob *gl, char *pat, char *str) if (pat[0] == '.' && pat[1] == '/' && ((str[0] == '.' && str[1] != '/') || str[0] != '.')) { + DG("%s vs %s", pat, str); gl->cur_dir = 0; return (pat + 2); } From 145c116e1800fa48bb769f4fb9d773e6c803ffae Mon Sep 17 00:00:00 2001 From: wescande Date: Wed, 8 Mar 2017 15:19:10 +0100 Subject: [PATCH 11/12] ajout de reinitialisation du des exec dans les forks + correctif d'un segv sur free du subshell --- 42sh/includes/exec.h | 18 +++++++------- 42sh/src/exec/launch_builtin.c | 3 ++- 42sh/src/exec/launch_case.c | 7 +++++- 42sh/src/exec/launch_for.c | 7 +++++- 42sh/src/exec/launch_function.c | 7 +++++- 42sh/src/exec/launch_if.c | 7 +++++- 42sh/src/exec/launch_subshell.c | 7 +++++- 42sh/src/exec/launch_until.c | 7 +++++- 42sh/src/exec/launch_while.c | 7 +++++- 42sh/src/exec/set_process.c | 10 ++++---- 42sh/src/exec/set_process_case.c | 5 ++-- 42sh/src/exec/set_process_cmd.c | 25 ++++++++------------ 42sh/src/exec/set_process_for.c | 5 ++-- 42sh/src/exec/set_process_if.c | 5 ++-- 42sh/src/exec/set_process_map.c | 6 ++--- 42sh/src/exec/set_process_subshell.c | 5 ++-- 42sh/src/exec/set_process_until.c | 5 ++-- 42sh/src/exec/set_process_while.c | 5 ++-- 42sh/src/job-control/job_remove.c | 3 +-- 42sh/src/job-control/process_free_cmd.c | 4 +++- 42sh/src/job-control/process_free_subshell.c | 4 ++-- 42sh/src/job-control/put_job_in_foreground.c | 10 +------- 22 files changed, 90 insertions(+), 72 deletions(-) diff --git a/42sh/includes/exec.h b/42sh/includes/exec.h index 59fd4d22..baf2e7d6 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/08 14:51:04 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:58:19 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -193,14 +193,14 @@ int launch_function(t_process *p); */ int set_process(t_process *p, t_btree *ast); -int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd); -int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd); -int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd); -int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd); -int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd); -int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd); -int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd); -int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd); +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); /* ** Mapping pour exec les process diff --git a/42sh/src/exec/launch_builtin.c b/42sh/src/exec/launch_builtin.c index 71497c10..0c80ecbe 100644 --- a/42sh/src/exec/launch_builtin.c +++ b/42sh/src/exec/launch_builtin.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:48:24 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:43:35 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 15:10:49 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,6 +30,7 @@ int launch_builtin(t_process *p) process_setsig(); if (process_redirect(p)) exit (1); + exec_reset();///A FAIRE POUR LES BUILTIN OU PAS ? -> Q de William exit((*p->data.cmd.execf)(p->data.cmd.path, p->data.cmd.av, data_singleton()->env)); } else if (pid > 0) diff --git a/42sh/src/exec/launch_case.c b/42sh/src/exec/launch_case.c index a7c096ff..6f248ae0 100644 --- a/42sh/src/exec/launch_case.c +++ b/42sh/src/exec/launch_case.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:02:23 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:02:46 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:11:02 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -57,6 +57,11 @@ int launch_case(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); exit(do_case(p)); } else if (pid > 0) diff --git a/42sh/src/exec/launch_for.c b/42sh/src/exec/launch_for.c index 6de71af2..0c39ac59 100644 --- a/42sh/src/exec/launch_for.c +++ b/42sh/src/exec/launch_for.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:34:43 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:02:18 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:07:55 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -51,6 +51,11 @@ int launch_for(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); exit(do_for(p)); } else if (pid > 0) diff --git a/42sh/src/exec/launch_function.c b/42sh/src/exec/launch_function.c index cd5c08d4..74678b8e 100644 --- a/42sh/src/exec/launch_function.c +++ b/42sh/src/exec/launch_function.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 03:23:59 by wescande #+# #+# */ -/* Updated: 2017/03/08 03:24:53 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:08:20 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,11 @@ int launch_function(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); exit(do_function(p)); } else if (pid > 0) diff --git a/42sh/src/exec/launch_if.c b/42sh/src/exec/launch_if.c index ca80fffb..7d389d56 100644 --- a/42sh/src/exec/launch_if.c +++ b/42sh/src/exec/launch_if.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:26:53 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:03:04 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:07:47 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,11 @@ int launch_if(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); exit(do_if(p)); } else if (pid > 0) diff --git a/42sh/src/exec/launch_subshell.c b/42sh/src/exec/launch_subshell.c index 98fd0bcb..1c2703b1 100644 --- a/42sh/src/exec/launch_subshell.c +++ b/42sh/src/exec/launch_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:11:44 by wescande #+# #+# */ -/* Updated: 2017/03/08 14:44:57 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 15:08:04 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,6 +29,11 @@ int launch_subshell(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); exit(do_subshell(p)); } else if (pid > 0) diff --git a/42sh/src/exec/launch_until.c b/42sh/src/exec/launch_until.c index 21fc64a1..4c0f566d 100644 --- a/42sh/src/exec/launch_until.c +++ b/42sh/src/exec/launch_until.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:04:42 by wescande #+# #+# */ -/* Updated: 2017/03/08 02:35:09 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:08:13 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,6 +38,11 @@ int launch_until(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); exit(do_until(p)); } else if (pid > 0) diff --git a/42sh/src/exec/launch_while.c b/42sh/src/exec/launch_while.c index a003c8b1..462edb8b 100644 --- a/42sh/src/exec/launch_while.c +++ b/42sh/src/exec/launch_while.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:20:53 by wescande #+# #+# */ -/* Updated: 2017/03/07 20:59:40 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:18:36 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -55,6 +55,11 @@ int launch_while(t_process *p) { data_singleton()->opts &= ~SH_INTERACTIVE; data_singleton()->opts &= ~SH_OPTS_JOBC; + process_setgroup(p, 0); + process_setsig(); + if (process_redirect(p)) + exit (1); + exec_reset(); exit(do_while(p)); } else if (pid > 0) diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index a19e1e1a..70d876be 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:51:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:58:21 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,11 +15,11 @@ int set_process(t_process *p, t_btree *ast) { t_exec *exec; - t_cmd *cmd; +// t_cmd *cmd; int op; int fds[2]; - cmd = &((t_astnode *)ast->item)->data.cmd; +// cmd = &((t_astnode *)ast->item)->data.cmd; /* process_reset(p); */ exec = &data_singleton()->exec; op = pop(&exec->op_stack); @@ -38,6 +38,6 @@ int set_process(t_process *p, t_btree *ast) p->to_close = fds[PIPE_READ]; p->fdout = fds[PIPE_WRITE]; exec->fdin = fds[PIPE_READ]; - p->redirs = ft_lstmap(cmd->redir, &redir_copy); - return (set_process_map(p, ast, cmd)); + p->redirs = ft_lstmap(((t_astnode *)ast->item)->data.cmd.redir, &redir_copy); + return (set_process_map(p, ast)); } diff --git a/42sh/src/exec/set_process_case.c b/42sh/src/exec/set_process_case.c index e7626df9..ac184d08 100644 --- a/42sh/src/exec/set_process_case.c +++ b/42sh/src/exec/set_process_case.c @@ -6,15 +6,14 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:36:04 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:49:48 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:59:25 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int set_process_case(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_case(t_process *p, t_btree *ast) { - (void)cmd; p->data.d_case.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); p->data.d_case.content = btree_map(ast->right, &node_copy); p->type = PROCESS_CASE; diff --git a/42sh/src/exec/set_process_cmd.c b/42sh/src/exec/set_process_cmd.c index 3d4c3c72..85d2ca4b 100644 --- a/42sh/src/exec/set_process_cmd.c +++ b/42sh/src/exec/set_process_cmd.c @@ -6,23 +6,23 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:06:05 by wescande #+# #+# */ -/* Updated: 2017/03/08 14:46:10 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 15:03:40 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_cmd(t_process *p, t_btree *ast) { t_btree *func; - (void)ast; - if (!(p->data.cmd.av = token_to_argv(cmd->token, 1))) + if (!(p->data.cmd.av = token_to_argv(((t_astnode *)ast->item)->data.cmd.token, 1))) return (1); p->data.cmd.path = NULL; p->data.cmd.execf = NULL; p->data.cmd.stat = ft_memalloc(sizeof(struct stat)); DG("gonna setexec av[0]=[%s]", p->data.cmd.av[0]); + p->type = PROCESS_FILE; if ((func = is_function(p))) { p->data.subshell.content = func; @@ -32,24 +32,19 @@ int set_process_cmd(t_process *p, t_btree *ast, t_cmd *cmd) p->type = PROCESS_BUILTIN; else if (ft_strchr(p->data.cmd.av[0], '/')) { - p->type = PROCESS_FILE; p->data.cmd.execf = &execve; p->data.cmd.path = ft_strdup(p->data.cmd.av[0]); if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) ft_memdel((void**)&p->data.cmd.stat); } - else + else if (ft_hash(p)) { - p->type = PROCESS_FILE; - if (ft_hash(p)) + p->data.cmd.execf = &execve; + DG("found hash at [%s]", p->data.cmd.path); + if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) { - p->data.cmd.execf = &execve; - DG("found hash at [%s]", p->data.cmd.path); - if (stat(p->data.cmd.path, p->data.cmd.stat) == -1) - { - ft_memdel((void**)&p->data.cmd.stat); - ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path); - } + ft_memdel((void**)&p->data.cmd.stat); + ft_dprintf(2, "{red}%s: %s: unexpected stat (2) failure\n", SHELL_NAME, p->data.cmd.path); } } return (0); diff --git a/42sh/src/exec/set_process_for.c b/42sh/src/exec/set_process_for.c index 66489f57..e51621ed 100644 --- a/42sh/src/exec/set_process_for.c +++ b/42sh/src/exec/set_process_for.c @@ -6,15 +6,14 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:05 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:50:33 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:59:08 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int set_process_for(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_for(t_process *p, t_btree *ast) { - (void)cmd; p->data.d_for.list_word = ft_ld_copy(((t_astnode *)ast->item)->data.cmd.wordlist, tab_esc_copy); p->data.d_for.content = btree_map(ast->right, &node_copy); p->type = PROCESS_FOR; diff --git a/42sh/src/exec/set_process_if.c b/42sh/src/exec/set_process_if.c index 0fae0f0a..3aaac67c 100644 --- a/42sh/src/exec/set_process_if.c +++ b/42sh/src/exec/set_process_if.c @@ -6,15 +6,14 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:19:50 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:51:09 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:59:17 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int set_process_if(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_if(t_process *p, t_btree *ast) { - (void)cmd; p->data.d_if.condition = btree_map(ast->left, &node_copy); p->data.d_if.content = btree_map(ast->right, &node_copy); p->type = PROCESS_IF; diff --git a/42sh/src/exec/set_process_map.c b/42sh/src/exec/set_process_map.c index 3e32cc57..cc9fb49a 100644 --- a/42sh/src/exec/set_process_map.c +++ b/42sh/src/exec/set_process_map.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 15:08:12 by wescande #+# #+# */ -/* Updated: 2017/03/08 14:48:02 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:58:36 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ t_itof g_setprocessmap[] = {0, NULL} }; -int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_map(t_process *p, t_btree *ast) { int i; t_astnode *item; @@ -49,7 +49,7 @@ int set_process_map(t_process *p, t_btree *ast, t_cmd *cmd) { if (!g_setprocessmap[i].f) return (1); - return ((*g_setprocessmap[i].f)(p, ast, cmd)); + return ((*g_setprocessmap[i].f)(p, ast)); } return (1); } diff --git a/42sh/src/exec/set_process_subshell.c b/42sh/src/exec/set_process_subshell.c index e44baf60..b7cdb55f 100644 --- a/42sh/src/exec/set_process_subshell.c +++ b/42sh/src/exec/set_process_subshell.c @@ -6,15 +6,14 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:02:01 by wescande #+# #+# */ -/* Updated: 2017/03/08 11:51:04 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:59:55 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int set_process_subshell(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_subshell(t_process *p, t_btree *ast) { - (void)cmd; p->data.subshell.content = btree_map(ast->right, &node_copy); p->type = PROCESS_SUBSHELL; return (0); diff --git a/42sh/src/exec/set_process_until.c b/42sh/src/exec/set_process_until.c index 20529720..c28b4172 100644 --- a/42sh/src/exec/set_process_until.c +++ b/42sh/src/exec/set_process_until.c @@ -6,15 +6,14 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 22:22:24 by wescande #+# #+# */ -/* Updated: 2017/03/08 03:06:03 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:59:36 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int set_process_until(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_until(t_process *p, t_btree *ast) { - (void)cmd; p->data.d_while.condition = btree_map(ast->left, &node_copy); p->data.d_while.content = btree_map(ast->right, &node_copy); p->type = PROCESS_UNTIL; diff --git a/42sh/src/exec/set_process_while.c b/42sh/src/exec/set_process_while.c index acde7eb6..56807c2e 100644 --- a/42sh/src/exec/set_process_while.c +++ b/42sh/src/exec/set_process_while.c @@ -6,15 +6,14 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 19:38:10 by wescande #+# #+# */ -/* Updated: 2017/03/08 01:51:38 by ariard ### ########.fr */ +/* Updated: 2017/03/08 14:58:54 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -int set_process_while(t_process *p, t_btree *ast, t_cmd *cmd) +int set_process_while(t_process *p, t_btree *ast) { - (void)cmd; p->data.d_while.condition = btree_map(ast->left, &node_copy); p->data.d_while.content = btree_map(ast->right, &node_copy); p->type = PROCESS_WHILE; diff --git a/42sh/src/job-control/job_remove.c b/42sh/src/job-control/job_remove.c index dffc51c3..5dcade64 100644 --- a/42sh/src/job-control/job_remove.c +++ b/42sh/src/job-control/job_remove.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/15 12:51:08 by jhalford #+# #+# */ -/* Updated: 2017/03/08 02:03:58 by ariard ### ########.fr */ +/* Updated: 2017/03/08 15:06:12 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,6 @@ void job_remove(int id) j = ft_lst_find(jobc->first_job, &id, job_cmp_id)->content; if (job_is_completed(id)) { - DG(); p = ft_lstlast(j->first_process)->content; set_exitstatus(p->status, 0); if (id < data_singleton()->jobc.current_id) diff --git a/42sh/src/job-control/process_free_cmd.c b/42sh/src/job-control/process_free_cmd.c index 96efd6e1..ab2e446c 100644 --- a/42sh/src/job-control/process_free_cmd.c +++ b/42sh/src/job-control/process_free_cmd.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 00:58:02 by wescande #+# #+# */ -/* Updated: 2017/03/08 02:31:01 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:04:45 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,5 +16,7 @@ int process_free_cmd(t_process *p) { ft_strdel(&p->data.cmd.path); ft_sstrfree(p->data.cmd.av); + p->data.cmd.execf = NULL; + ft_memdel((void**)&p->data.cmd.stat); return (0); } diff --git a/42sh/src/job-control/process_free_subshell.c b/42sh/src/job-control/process_free_subshell.c index 7fb49c4b..12723743 100644 --- a/42sh/src/job-control/process_free_subshell.c +++ b/42sh/src/job-control/process_free_subshell.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/08 02:38:12 by wescande #+# #+# */ -/* Updated: 2017/03/08 02:38:27 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:16:22 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,6 @@ int process_free_subshell(t_process *p) { - btree_del(&p->data.d_while.content, &ast_free); + btree_del(&p->data.subshell.content, &ast_free); return (0); } diff --git a/42sh/src/job-control/put_job_in_foreground.c b/42sh/src/job-control/put_job_in_foreground.c index 3ff70ce0..9532bb25 100644 --- a/42sh/src/job-control/put_job_in_foreground.c +++ b/42sh/src/job-control/put_job_in_foreground.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */ -/* Updated: 2017/03/08 00:35:38 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:05:31 by wescande ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,24 +26,16 @@ int put_job_in_foreground(t_job *j, int cont) if (kill(-j->pgid, SIGCONT) < 0) DG("kill(SIGCONT) failed"); } - DG(); job_wait(j->id); - DG(); job_remove(j->id); - DG(); - tcsetpgrp(STDIN, jobc->shell_pgid); - tcgetattr(STDIN, &j->tmodes); tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes); } else { - DG(); job_wait(j->id); - DG(); job_remove(j->id); - DG(); } return (0); } From 794a3f9936f3428fba77d238b8561465f73964cf Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 8 Mar 2017 15:53:10 +0100 Subject: [PATCH 12/12] heredoc changes to lexer done --- 42sh/Makefile | 2 +- 42sh/includes/lexer.h | 8 +++-- 42sh/includes/types.h | 3 +- 42sh/src/exec/set_process.c | 2 +- 42sh/src/lexer/lexer_dless.c | 41 -------------------------- 42sh/src/lexer/lexer_end.c | 19 ++++-------- 42sh/src/lexer/lexer_heredoc.c | 53 ++++++++++++++++++++++++++++++++++ 42sh/src/lexer/lexer_less.c | 5 +--- 42sh/src/lexer/lexer_lex.c | 4 +-- 42sh/src/main/main.c | 8 ++--- 10 files changed, 75 insertions(+), 70 deletions(-) delete mode 100644 42sh/src/lexer/lexer_dless.c create mode 100644 42sh/src/lexer/lexer_heredoc.c diff --git a/42sh/Makefile b/42sh/Makefile index 0cac1aa5..4196032e 100644 --- a/42sh/Makefile +++ b/42sh/Makefile @@ -206,11 +206,11 @@ lexer/lexer_bquote.c\ lexer/lexer_curly_braces.c\ lexer/lexer_default.c\ lexer/lexer_delim.c\ -lexer/lexer_dless.c\ lexer/lexer_dquote.c\ lexer/lexer_end.c\ lexer/lexer_great.c\ lexer/lexer_greatand.c\ +lexer/lexer_heredoc.c\ lexer/lexer_init.c\ lexer/lexer_less.c\ lexer/lexer_lessand.c\ diff --git a/42sh/includes/lexer.h b/42sh/includes/lexer.h index d47b2e0f..21b7209a 100644 --- a/42sh/includes/lexer.h +++ b/42sh/includes/lexer.h @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 12:15:50 by jhalford #+# #+# */ -/* Updated: 2017/03/06 18:28:10 by ariard ### ########.fr */ +/* Updated: 2017/03/08 15:52:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,7 @@ enum e_lexstate { DEFAULT, PAREN, + HEREDOC, NEWLINE, DELIM, SEP, @@ -34,7 +35,6 @@ enum e_lexstate GREAT, LESSAND, GREATAND, - DLESS, QUOTE, DQUOTE, BQUOTE, @@ -99,10 +99,13 @@ t_lexstate get_state_redir(t_lexer *lexer); int get_lexer_stack(t_lexer lexer); int get_reserved_words(t_list **alst); int insert_newline(t_list **alst); + void lexer_init(t_lexer *lexer); + int lexer_lex(t_list **alst, t_lexer *lexer); int lexer_default(t_list **alst, t_lexer *lexer); int lexer_newline(t_list **alst, t_lexer *lexer); +int lexer_heredoc(t_list **alst, t_lexer *lexer); int lexer_delim(t_list **alst, t_lexer *lexer); int lexer_sep(t_list **alst, t_lexer *lexer); int lexer_word(t_list **alst, t_lexer *lexer); @@ -111,7 +114,6 @@ int lexer_less(t_list **alst, t_lexer *lexer); int lexer_great(t_list **alst, t_lexer *lexer); int lexer_greatand(t_list **alst, t_lexer *lexer); int lexer_lessand(t_list **alst, t_lexer *lexer); -int lexer_dless(t_list **alst, t_lexer *lexer); int lexer_quote(t_list **alst, t_lexer *lexer); int lexer_dquote(t_list **alst, t_lexer *lexer); int lexer_bquote(t_list **alst, t_lexer *lexer); diff --git a/42sh/includes/types.h b/42sh/includes/types.h index 95e2be0c..791d6634 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/08 00:22:56 by wescande ### ########.fr */ +/* Updated: 2017/03/08 15:50:49 by jhalford ### ########.fr */ /* Updated: 2017/03/07 18:35:11 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -192,6 +192,7 @@ enum e_sym MATH_SUP, REDIR, CMD, + HEREDOCDATA, ALL = 200, TERMINUS = 300, }; diff --git a/42sh/src/exec/set_process.c b/42sh/src/exec/set_process.c index a19e1e1a..7dcf4a55 100644 --- a/42sh/src/exec/set_process.c +++ b/42sh/src/exec/set_process.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/08 14:51:22 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 14:55:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/lexer/lexer_dless.c b/42sh/src/lexer/lexer_dless.c deleted file mode 100644 index 16fb05f3..00000000 --- a/42sh/src/lexer/lexer_dless.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "minishell.h" - -int lexer_dless(t_list **alst, t_lexer *lexer) -{ - t_list *heredoc_lst; - t_token *eof_tok; - t_token *heredoc_tok; - - (void)alst; - (void)lexer; - heredoc_lst = *(t_list**)lexer->heredoc_stack->content; - heredoc_tok = heredoc_lst->content; - if (!(heredoc_lst->next)) - { - ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); - return (1); - } - eof_tok = heredoc_lst->next->content; - if (!(eof_tok->type == TK_WORD)) - { - ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); - return (1); - } - /* DG("heredoc contains [%s]", heredoc_tok->data); */ - /* DG("heredoc ends at [%s]", eof_tok->data); */ - /* DG("input is [%s]", lexer->str + lexer->pos); */ - if (ft_strcmp(eof_tok->data, lexer->str + lexer->pos) == 0) - { - pop(&lexer->stack); - pop(&lexer->heredoc_stack); - while (lexer->str[++lexer->pos]) - ; - ft_strappend(&lexer->str, (char[]){'\n', 0}); - lexer->pos++; - return (0); - } - else - while (lexer->str[lexer->pos]) - token_append_char(heredoc_tok, lexer->str[lexer->pos++], 0, 0); - return (lexer_end(alst, lexer)); -} diff --git a/42sh/src/lexer/lexer_end.c b/42sh/src/lexer/lexer_end.c index 5e0b6710..52a2bd3d 100644 --- a/42sh/src/lexer/lexer_end.c +++ b/42sh/src/lexer/lexer_end.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 16:58:24 by jhalford #+# #+# */ -/* Updated: 2017/03/08 12:12:40 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 15:52:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,21 +16,14 @@ int lexer_end(t_list **alst, t_lexer *lexer) { t_token *token; - if ((*alst && (lexer->state == QUOTE || lexer->state == DQUOTE - || lexer->state == BQUOTE)) || get_lexer_stack(*lexer) == DLESS) + if (*alst && (lexer->state == QUOTE + || lexer->state == DQUOTE + || lexer->state == BQUOTE)) { + token = (*alst)->content; ft_strappend(&lexer->str, (char[]){'\n', 0}); + token_append_char(token, '\n', 1, 0); lexer->pos++; - if (get_lexer_stack(*lexer) == DLESS) - { - token = (*(t_list**)lexer->heredoc_stack->content)->content; - token_append_char(token, '\n', 0, 0); - } - else - { - token = (*alst)->content; - token_append_char(token, '\n', 1, 0); - } return (0); } return (0); diff --git a/42sh/src/lexer/lexer_heredoc.c b/42sh/src/lexer/lexer_heredoc.c new file mode 100644 index 00000000..d5fa357a --- /dev/null +++ b/42sh/src/lexer/lexer_heredoc.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lexer_heredoc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jhalford +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2017/03/08 15:51:17 by jhalford #+# #+# */ +/* Updated: 2017/03/08 15:52:48 by jhalford ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "minishell.h" + +int lexer_heredoc(t_list **alst, t_lexer *lexer) +{ + t_token *token; + + token = (*alst)->content; + token->type = HEREDOCDATA; + token_append_str(token, lexer->str, 0, 0); + return (0); + /* heredoc_lst = *(t_list**)lexer->heredoc_stack->content; */ + /* heredoc_tok = heredoc_lst->content; */ + /* if (!(heredoc_lst->next)) */ + /* { */ + /* ft_dprintf(2, "{red}%s: parse error near `\\n'{eoc}\n", SHELL_NAME); */ + /* return (1); */ + /* } */ + /* eof_tok = heredoc_lst->next->content; */ + /* if (!(eof_tok->type == TK_WORD)) */ + /* { */ + /* ft_dprintf(2, "{red}%s: expected word token after <<{eoc}\n", SHELL_NAME); */ + /* return (1); */ + /* } */ + /* DG("heredoc contains [%s]", heredoc_tok->data); */ + /* DG("heredoc ends at [%s]", eof_tok->data); */ + /* DG("input is [%s]", lexer->str + lexer->pos); */ + /* if (ft_strcmp(eof_tok->data, lexer->str + lexer->pos) == 0) */ + /* { */ + /* /1* pop(&lexer->stack); *1/ */ + /* pop(&lexer->heredoc_stack); */ + /* while (lexer->str[++lexer->pos]) */ + /* ; */ + /* ft_strappend(&lexer->str, (char[]){'\n', 0}); */ + /* lexer->pos++; */ + /* return (0); */ + /* } */ + /* else */ + /* while (lexer->str[lexer->pos]) */ + /* token_append_char(heredoc_tok, lexer->str[lexer->pos++], 0, 0); */ + /* return (lexer_end(alst, lexer)); */ +} diff --git a/42sh/src/lexer/lexer_less.c b/42sh/src/lexer/lexer_less.c index 8b9e0b0d..49354932 100644 --- a/42sh/src/lexer/lexer_less.c +++ b/42sh/src/lexer/lexer_less.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 12:06:53 by jhalford #+# #+# */ -/* Updated: 2017/03/08 13:27:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 15:35:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,17 +21,14 @@ int lexer_less(t_list **alst, t_lexer *lexer) if (lexer->str[lexer->pos] == '&') { token->type = TK_LESSAND; - token_append(token, lexer, 0, 0); lexer->pos++; return (lexer_lessand(alst, lexer)); } if (lexer->str[lexer->pos] == '<') { token->type = TK_DLESS; - push(&lexer->stack, DLESS); lexer->pos++; lexer->state = DEFAULT; - ft_lsteadd(&lexer->heredoc_stack, ft_lstnew(alst, sizeof(alst))); return (lexer_lex(&(*alst)->next, lexer)); } token->type = TK_LESS; diff --git a/42sh/src/lexer/lexer_lex.c b/42sh/src/lexer/lexer_lex.c index 9ec90b49..7a32b1d7 100644 --- a/42sh/src/lexer/lexer_lex.c +++ b/42sh/src/lexer/lexer_lex.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/09 17:08:51 by jhalford #+# #+# */ -/* Updated: 2017/03/06 14:55:25 by ariard ### ########.fr */ +/* Updated: 2017/03/08 15:51:39 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = { &lexer_default, &lexer_paren, + &lexer_heredoc, &lexer_newline, &lexer_delim, &lexer_sep, @@ -25,7 +26,6 @@ int (*g_lexer[])(t_list **alst, t_lexer *lexer) = &lexer_great, &lexer_lessand, &lexer_greatand, - &lexer_dless, &lexer_quote, &lexer_dquote, &lexer_bquote, diff --git a/42sh/src/main/main.c b/42sh/src/main/main.c index 7cf15069..fc5a8925 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/08 14:39:33 by jhalford ### ########.fr */ +/* Updated: 2017/03/08 15:36:38 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ @@ -39,12 +39,12 @@ int handle_instruction(int fd) ft_strappend(&lexer.str, str); if (get_lexer_stack(lexer) == BACKSLASH) pop(&lexer.stack); - else if (get_lexer_stack(lexer) == DLESS) - lexer.state = DLESS; + /* else if (get_lexer_stack(lexer) == DLESS) */ + /* lexer.state = DLESS; */ ltoken = ft_lstlast(token); if (lexer_lex(token ? <oken : &token, &lexer)) return (1); - if (get_lexer_stack(lexer) > 1) + if (get_lexer_stack(lexer) > 2) continue ; lexer.state = DEFAULT; if (get_reserved_words(&token))