From 27da345e70ec3ec1206bcb2f1dfa45d39ab07adb Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 21 Mar 2017 17:40:51 +0100 Subject: [PATCH] added a backup path to hash algorithm --- 42sh/libft/src/sys/fd_replace.c | 2 +- 42sh/src/builtin/builtin_unsetenv.c | 2 +- 42sh/src/exec/ft_findexec.c | 2 +- 42sh/src/exec/process_redirect.c | 2 +- 42sh/src/exec/redirect_greatand.c | 2 +- 42sh/src/hash_table/ft_add_hash.c | 9 ++++++--- 42sh/src/hash_table/hash.c | 2 +- 42sh/src/hash_table/is_hash.c | 2 +- 8 files changed, 13 insertions(+), 10 deletions(-) diff --git a/42sh/libft/src/sys/fd_replace.c b/42sh/libft/src/sys/fd_replace.c index 905b340c..f8a753dd 100644 --- a/42sh/libft/src/sys/fd_replace.c +++ b/42sh/libft/src/sys/fd_replace.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/21 16:32:26 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:40:17 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 16:42:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/builtin/builtin_unsetenv.c b/42sh/src/builtin/builtin_unsetenv.c index 5275a6ff..61069a81 100644 --- a/42sh/src/builtin/builtin_unsetenv.c +++ b/42sh/src/builtin/builtin_unsetenv.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/28 14:29:17 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:40:05 by wescande ### ########.fr */ +/* Updated: 2017/03/21 17:40:31 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/ft_findexec.c b/42sh/src/exec/ft_findexec.c index acb87a63..813992da 100644 --- a/42sh/src/exec/ft_findexec.c +++ b/42sh/src/exec/ft_findexec.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/03 13:37:49 by jhalford #+# #+# */ -/* Updated: 2017/03/21 15:11:09 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 17:40:28 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/process_redirect.c b/42sh/src/exec/process_redirect.c index 80d54701..5b1d0c8d 100644 --- a/42sh/src/exec/process_redirect.c +++ b/42sh/src/exec/process_redirect.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/29 16:04:18 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:40:13 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 17:40:35 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/exec/redirect_greatand.c b/42sh/src/exec/redirect_greatand.c index 76724439..09beb928 100644 --- a/42sh/src/exec/redirect_greatand.c +++ b/42sh/src/exec/redirect_greatand.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/06 22:12:31 by jhalford #+# #+# */ -/* Updated: 2017/03/21 16:35:42 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 17:40:36 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/hash_table/ft_add_hash.c b/42sh/src/hash_table/ft_add_hash.c index 4c4781d5..1c4e63f3 100644 --- a/42sh/src/hash_table/ft_add_hash.c +++ b/42sh/src/hash_table/ft_add_hash.c @@ -6,19 +6,22 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:20:11 by gwojda #+# #+# */ -/* Updated: 2017/03/19 16:40:25 by wescande ### ########.fr */ +/* Updated: 2017/03/21 17:40:13 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" +#define BACKUP_PATH "/bin:/usr/bin" + char *ft_add_hash(char *cmd) { int id; t_hash hash; + char *path; - if (!(hash.path = ft_findexec(ft_getenv( - data_singleton()->env, "PATH"), cmd))) + path = ft_getenv(data_singleton()->env, "PATH"); + if (!(hash.path = ft_findexec(path ? path : BACKUP_PATH, cmd))) return (NULL); hash.key = ft_strdup(cmd); id = ft_hash_str(cmd); diff --git a/42sh/src/hash_table/hash.c b/42sh/src/hash_table/hash.c index 1cf1dd79..846643e0 100644 --- a/42sh/src/hash_table/hash.c +++ b/42sh/src/hash_table/hash.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:06:19 by gwojda #+# #+# */ -/* Updated: 2017/03/19 16:38:12 by wescande ### ########.fr */ +/* Updated: 2017/03/21 17:40:19 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/hash_table/is_hash.c b/42sh/src/hash_table/is_hash.c index fc7c687d..5f808380 100644 --- a/42sh/src/hash_table/is_hash.c +++ b/42sh/src/hash_table/is_hash.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/02/18 11:08:40 by gwojda #+# #+# */ -/* Updated: 2017/03/19 16:39:18 by wescande ### ########.fr */ +/* Updated: 2017/03/21 17:40:20 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */