From 27da345e70ec3ec1206bcb2f1dfa45d39ab07adb Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Tue, 21 Mar 2017 17:40:51 +0100 Subject: [PATCH 1/2] 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 */ /* */ /* ************************************************************************** */ From 647755917f11269baf416c10bc56ec6db1957e41 Mon Sep 17 00:00:00 2001 From: gwojda Date: Tue, 21 Mar 2017 18:14:37 +0100 Subject: [PATCH 2/2] ft_malloc --- 42sh/src/glob/ft_strsplit_esc.c | 4 ++-- 42sh/src/glob/ft_strsplit_spe.c | 6 +++--- 42sh/src/glob/gen_tab_esc.c | 4 ++-- 42sh/src/glob/lib_perso/ft_ld_new.c | 4 ++-- 42sh/src/glob/lib_perso/ft_ld_pushback.c | 4 ++-- 42sh/src/glob/lib_perso/ft_ld_pushfront.c | 4 ++-- 42sh/src/glob/lib_perso/ft_ld_to_tab.c | 4 ++-- 42sh/src/history/list_toolz.c | 4 ++-- 42sh/src/lexer/token_init.c | 6 +++--- 42sh/src/line_editing/copy_cut_paste.c | 4 ++-- 42sh/src/line_editing/init_termcaps.c | 4 ++-- 42sh/src/line_editing/lib_line_editing/toolz.c | 4 ++-- 42sh/src/line_editing/lib_line_editing/toolz2.c | 4 ++-- 42sh/src/line_editing/resize.c | 2 +- 42sh/src/main/data_singleton.c | 4 ++-- 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/42sh/src/glob/ft_strsplit_esc.c b/42sh/src/glob/ft_strsplit_esc.c index 897b4eb3..b47f6ca6 100644 --- a/42sh/src/glob/ft_strsplit_esc.c +++ b/42sh/src/glob/ft_strsplit_esc.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 22:18:46 by wescande #+# #+# */ -/* Updated: 2017/02/24 22:05:41 by ariard ### ########.fr */ +/* Updated: 2017/03/21 18:13:25 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,7 +66,7 @@ unsigned char **ft_strsplit_esc(const char *str, if ((pos = -1) && !str) return (NULL); - if (!(s1 = (unsigned char **)malloc(sizeof(*s1) * (nb_c(str, esc, c) + 1)))) + if (!(s1 = (unsigned char **)ft_malloc(sizeof(*s1) * (nb_c(str, esc, c) + 1)))) return (NULL); i = 0; fix = str; diff --git a/42sh/src/glob/ft_strsplit_spe.c b/42sh/src/glob/ft_strsplit_spe.c index cc65dcf2..ef2bd87a 100644 --- a/42sh/src/glob/ft_strsplit_spe.c +++ b/42sh/src/glob/ft_strsplit_spe.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/31 20:49:30 by wescande #+# #+# */ -/* Updated: 2017/02/24 22:03:22 by ariard ### ########.fr */ +/* Updated: 2017/03/21 18:13:34 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -64,7 +64,7 @@ char **ft_strsplit_spe(const char *str, int len; if (!str || !(s1 = - (char**)malloc(sizeof(*s1) * (ft_nbstr_c(str, esc, c) + 1)))) + (char**)ft_malloc(sizeof(*s1) * (ft_nbstr_c(str, esc, c) + 1)))) return (NULL); i = 0; fix = str; @@ -72,7 +72,7 @@ char **ft_strsplit_spe(const char *str, ++str; while (*str && (len = ft_strlen_c(str, fix, esc, c))) { - if (!(s1[i] = (char*)malloc(sizeof(**s1) * (len + 1)))) + if (!(s1[i] = (char*)ft_malloc(sizeof(**s1) * (len + 1)))) return (NULL); ft_strncpy(s1[i], str, len); s1[i][len] = '\0'; diff --git a/42sh/src/glob/gen_tab_esc.c b/42sh/src/glob/gen_tab_esc.c index 04136888..700be3e8 100644 --- a/42sh/src/glob/gen_tab_esc.c +++ b/42sh/src/glob/gen_tab_esc.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 20:04:40 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:14:55 by wescande ### ########.fr */ +/* Updated: 2017/03/21 18:13:39 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,7 @@ char **gen_tab(const char *pat, char **my_tab; int len; - if (!(my_tab = (char **)malloc(sizeof(char *) * (esc2 ? 4 : 3)))) + if (!(my_tab = (char **)ft_malloc(sizeof(char *) * (esc2 ? 4 : 3)))) return (NULL); if (dup) { diff --git a/42sh/src/glob/lib_perso/ft_ld_new.c b/42sh/src/glob/lib_perso/ft_ld_new.c index 76000294..a457b626 100644 --- a/42sh/src/glob/lib_perso/ft_ld_new.c +++ b/42sh/src/glob/lib_perso/ft_ld_new.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 18:17:34 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:17:20 by wescande ### ########.fr */ +/* Updated: 2017/03/21 18:12:52 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ void ft_ld_new(t_ld **alst, void *content) { t_ld *new; - if ((new = (t_ld *)malloc(sizeof(t_ld)))) + if ((new = (t_ld *)ft_malloc(sizeof(t_ld)))) { new->content = content; new->prev = NULL; diff --git a/42sh/src/glob/lib_perso/ft_ld_pushback.c b/42sh/src/glob/lib_perso/ft_ld_pushback.c index e1dd629c..99fd42aa 100644 --- a/42sh/src/glob/lib_perso/ft_ld_pushback.c +++ b/42sh/src/glob/lib_perso/ft_ld_pushback.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 15:59:38 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:17:28 by wescande ### ########.fr */ +/* Updated: 2017/03/21 18:12:58 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ void ft_ld_pushback(t_ld **alst, void *content) if (!alst || !*alst) return (ft_ld_new(alst, content)); - if ((new = (t_ld *)malloc(sizeof(t_ld)))) + if ((new = (t_ld *)ft_malloc(sizeof(t_ld)))) { back = ft_ld_back(*alst); new->prev = back; diff --git a/42sh/src/glob/lib_perso/ft_ld_pushfront.c b/42sh/src/glob/lib_perso/ft_ld_pushfront.c index 067db748..2a80b101 100644 --- a/42sh/src/glob/lib_perso/ft_ld_pushfront.c +++ b/42sh/src/glob/lib_perso/ft_ld_pushfront.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/01 18:32:40 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:15:42 by wescande ### ########.fr */ +/* Updated: 2017/03/21 18:13:02 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,7 +19,7 @@ void ft_ld_pushfront(t_ld **alst, void *content) if (!alst || !*alst) return (ft_ld_new(alst, content)); - if ((new = (t_ld *)malloc(sizeof(t_ld)))) + if ((new = (t_ld *)ft_malloc(sizeof(t_ld)))) { front = ft_ld_front(*alst); new->next = front; diff --git a/42sh/src/glob/lib_perso/ft_ld_to_tab.c b/42sh/src/glob/lib_perso/ft_ld_to_tab.c index 286e3b3f..b2c99272 100644 --- a/42sh/src/glob/lib_perso/ft_ld_to_tab.c +++ b/42sh/src/glob/lib_perso/ft_ld_to_tab.c @@ -6,7 +6,7 @@ /* By: wescande +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/05 16:17:00 by wescande #+# #+# */ -/* Updated: 2017/03/07 21:20:05 by wescande ### ########.fr */ +/* Updated: 2017/03/21 18:13:08 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ char **ft_ld_to_tab(t_ld *ld) if (!ld) return (NULL); nb_item = ft_ld_size(ld); - if (!(my_tab = (char **)malloc(sizeof(char *) * (nb_item + 1)))) + if (!(my_tab = (char **)ft_malloc(sizeof(char *) * (nb_item + 1)))) return (NULL); index = 0; while (ld) diff --git a/42sh/src/history/list_toolz.c b/42sh/src/history/list_toolz.c index 08959e48..096bec47 100644 --- a/42sh/src/history/list_toolz.c +++ b/42sh/src/history/list_toolz.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/17 11:37:47 by gwojda #+# #+# */ -/* Updated: 2017/03/21 13:37:25 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 18:12:27 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -33,7 +33,7 @@ t_list_history *ft_create_history_list(char *str) { t_list_history *list; - list = (t_list_history *)malloc(sizeof(t_list_history)); + list = (t_list_history *)ft_malloc(sizeof(t_list_history)); if (!list) return (NULL); if (!str) diff --git a/42sh/src/lexer/token_init.c b/42sh/src/lexer/token_init.c index 77acdbcc..2e90638c 100644 --- a/42sh/src/lexer/token_init.c +++ b/42sh/src/lexer/token_init.c @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* token_init.c :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: jhalford +#+ +:+ +#+ */ +/* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/11/10 15:30:25 by jhalford #+# #+# */ -/* Updated: 2017/03/16 19:07:52 by jhalford ### ########.fr */ +/* Updated: 2017/03/21 18:11:43 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ t_token *token_init(void) { t_token *token; - if (!(token = (t_token *)malloc(sizeof(t_token)))) + if (!(token = (t_token *)ft_malloc(sizeof(t_token)))) return (NULL); token->type = 0; token->size = 8; diff --git a/42sh/src/line_editing/copy_cut_paste.c b/42sh/src/line_editing/copy_cut_paste.c index 98e24bd4..3127478d 100644 --- a/42sh/src/line_editing/copy_cut_paste.c +++ b/42sh/src/line_editing/copy_cut_paste.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/19 12:45:06 by gwojda #+# #+# */ -/* Updated: 2017/03/21 10:32:34 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 18:11:14 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ static char *ft_strdupi_space(char const *s) ++i; if (s[i] == '\n') ++i; - if (!(str = (char *)malloc(sizeof(char) * (i + 1)))) + if (!(str = (char *)ft_malloc(sizeof(char) * (i + 1)))) return (NULL); if (str) { diff --git a/42sh/src/line_editing/init_termcaps.c b/42sh/src/line_editing/init_termcaps.c index 1e191485..b8b2dbdb 100644 --- a/42sh/src/line_editing/init_termcaps.c +++ b/42sh/src/line_editing/init_termcaps.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/07 17:33:41 by gwojda #+# #+# */ -/* Updated: 2017/03/07 17:36:38 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 18:11:13 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,7 +23,7 @@ struct termios *ft_save_termios(int save) } if (save > 0) { - term_save = (struct termios *)malloc(sizeof(struct termios)); + term_save = (struct termios *)ft_malloc(sizeof(struct termios)); tcgetattr(0, term_save); } return (term_save); diff --git a/42sh/src/line_editing/lib_line_editing/toolz.c b/42sh/src/line_editing/lib_line_editing/toolz.c index e0401f5b..c07123db 100644 --- a/42sh/src/line_editing/lib_line_editing/toolz.c +++ b/42sh/src/line_editing/lib_line_editing/toolz.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/12/16 17:06:30 by gwojda #+# #+# */ -/* Updated: 2017/03/16 16:37:39 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 18:10:51 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,7 +30,7 @@ char *ft_strndup(char const *s, int n) char *str; i = 0; - if (!(str = (char *)malloc(sizeof(char) * (n + 1)))) + if (!(str = (char *)ft_malloc(sizeof(char) * (n + 1)))) return (NULL); if (str) { diff --git a/42sh/src/line_editing/lib_line_editing/toolz2.c b/42sh/src/line_editing/lib_line_editing/toolz2.c index d6cadfc2..8c531975 100644 --- a/42sh/src/line_editing/lib_line_editing/toolz2.c +++ b/42sh/src/line_editing/lib_line_editing/toolz2.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/07 11:00:28 by gwojda #+# #+# */ -/* Updated: 2017/03/07 17:32:44 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 18:10:50 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -62,7 +62,7 @@ char *ft_strdupi_w(char const *s) i = 0; while (s[i] && s[i] != ' ' && s[i] != '\t') i++; - str = (char *)malloc(sizeof(char) * (i + 1)); + str = (char *)ft_malloc(sizeof(char) * (i + 1)); if (str) { str[i--] = '\0'; diff --git a/42sh/src/line_editing/resize.c b/42sh/src/line_editing/resize.c index dcb557a7..3a1f07c0 100644 --- a/42sh/src/line_editing/resize.c +++ b/42sh/src/line_editing/resize.c @@ -6,7 +6,7 @@ /* By: gwojda +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/03/14 10:56:08 by gwojda #+# #+# */ -/* Updated: 2017/03/18 12:08:50 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 18:11:12 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/42sh/src/main/data_singleton.c b/42sh/src/main/data_singleton.c index 31512ede..9765b47f 100644 --- a/42sh/src/main/data_singleton.c +++ b/42sh/src/main/data_singleton.c @@ -6,7 +6,7 @@ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2017/01/10 11:36:39 by jhalford #+# #+# */ -/* Updated: 2017/03/20 14:45:01 by gwojda ### ########.fr */ +/* Updated: 2017/03/21 18:10:49 by gwojda ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,6 @@ t_data *data_singleton(void) static t_data *data = NULL; if (data == NULL) - data = malloc(sizeof(t_data)); + data = ft_malloc(sizeof(t_data)); return (data); }