From 03edcfc777bf1a1788b0f9e07fde377e356bd2d7 Mon Sep 17 00:00:00 2001 From: gwojda Date: Mon, 20 Mar 2017 17:08:39 +0100 Subject: [PATCH] fin mise a la norme exec (reste un fichier mais il faut que vous y regardiez) --- 42sh/src/exec/ft_findexec.c | 28 +++++++++++++++++----------- 42sh/src/exec/process_set.c | 12 +++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/42sh/src/exec/ft_findexec.c b/42sh/src/exec/ft_findexec.c index d2230456..cbc4545d 100644 --- a/42sh/src/exec/ft_findexec.c +++ b/42sh/src/exec/ft_findexec.c @@ -1,22 +1,33 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* lib_path.c :+: :+: :+: */ +/* ft_findexec.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 13:37:49 by jhalford #+# #+# */ -/* Updated: 2017/01/10 13:18:56 by jhalford ### ########.fr */ +/* Updated: 2017/03/20 16:52:10 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -char *ft_findexec(char *path, char *file) +static char *create_path(char *path, char *name, char **spath) +{ + char *execpath; + + if (path[ft_strlen(path)] != '/') + execpath = ft_str3join(path, "/", name); + else + execpath = ft_strjoin(path, name); + ft_sstrfree(spath); + return (execpath); +} + +char *ft_findexec(char *path, char *file) { int i; DIR *dir; - char *execpath; char **spath; struct dirent *dirent; @@ -30,13 +41,8 @@ char *ft_findexec(char *path, char *file) { if (ft_strcmp(dirent->d_name, file)) continue ; - if (spath[i][ft_strlen(spath[i])] != '/') - execpath = ft_str3join(spath[i], "/", dirent->d_name); - else - execpath = ft_strjoin(spath[i], dirent->d_name); - ft_sstrfree(spath); closedir(dir); - return (execpath); + return (create_path(spath[i], dirent->d_name, spath)); } closedir(dir); } diff --git a/42sh/src/exec/process_set.c b/42sh/src/exec/process_set.c index 2eebdef3..15d7d29f 100644 --- a/42sh/src/exec/process_set.c +++ b/42sh/src/exec/process_set.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/05 14:54:45 by jhalford #+# #+# */ -/* Updated: 2017/03/20 16:02:08 by gwojda ### ########.fr */ +/* Updated: 2017/03/20 17:07:01 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -53,16 +53,14 @@ int process_set(t_process *p, t_btree *ast) exec = &data_singleton()->exec; op = pop(&exec->op_stack); if ((EXEC_IS_AND_IF(exec->attrs) - && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0) + && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") != 0) || (EXEC_IS_OR_IF(exec->attrs) - && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) + && ft_strcmp(ft_getenv(data_singleton()->env, "?"), "0") == 0)) return (1); fds[PIPE_WRITE] = STDOUT; fds[PIPE_READ] = STDIN; - if (op == TK_PIPE) - pipe(fds); - else if (op == TK_AMP) - exec->job.attrs |= JOB_BG; + (op == TK_PIPE) ? pipe(fds) : (0); + exec->job.attrs |= (op == TK_AMP ? JOB_BG : 0); p->fdin = exec->fdin; p->to_close = fds[PIPE_READ]; p->fdout = fds[PIPE_WRITE];