From cc1b57c96cc8c0fdd53e781b54a83bb9c743179a Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 28 Feb 2020 09:41:52 +0100 Subject: Added environment and state Also dummy files eval.c parse.c --- src/path.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index 0a9dbd1..d4f4418 100644 --- a/src/path.c +++ b/src/path.c @@ -6,26 +6,18 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/27 15:51:01 by cacharle #+# #+# */ -/* Updated: 2020/02/27 18:07:16 by cacharle ### ########.fr */ +/* Updated: 2020/02/28 12:33:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "minishell.h" -static void st_path_command_entry_del(t_ftht_content *content) -{ - if (content == NULL) - return ; - free(content->key); - free(content->value); -} - static int st_in_dirs(char **dirs, char *dir) { while (*dirs != NULL) if (ft_strcmp(*dirs++, dir) == 0) - return (TRUE); // maybe change ft_lstremove_if func to cmp instead of bool - return (FALSE); + return (0); + return (-1); } static t_path *st_path_commands_update(t_path *path, char *dirname) @@ -40,7 +32,7 @@ static t_path *st_path_commands_update(t_path *path, char *dirname) { if ((tmp = ft_strjoin(dirname, entry->d_name)) == NULL) return (NULL); - if (ft_htset(path->commands, entry->d_name, st_path_command_entry_del) == NULL) + if (ft_htset(path->commands, entry->d_name, tmp, ms_ht_del_str_entry) == NULL) return (NULL); } if (closedir(dir) == -1) @@ -56,7 +48,7 @@ static t_path *st_path_dir_update(t_path *path, char *dirname) { t_ftlst *front; - if (ft_lstlfind(path->dirs, (int (*)(void*, void*))ft_strcmp, dirname) == NULL) + if (ft_lstlfind(path->dirs, (int (*)(const void*, const void*))ft_strcmp, dirname) == NULL) { if ((dirname = ft_strdup(dirname)) == NULL) return (NULL); @@ -85,7 +77,7 @@ t_path *ms_path_update(t_path *path, const char *path_str) return (NULL); if ((dirs = ft_split(path_str, ':')) == NULL) return (NULL); - ft_lstremove_if(&path->dirs, (t_ftbool (*)(void*, void*))st_in_dirs, free, (void*)dirs); // change t_ftbool to std bool + ft_lstremove_if(&path->dirs, (int (*)(const void*, const void*))st_in_dirs, free, (void*)dirs); i = -1; while (dirs[i] != NULL) if (st_path_dir_update(path, dirs[i]) == NULL) @@ -99,6 +91,6 @@ void ms_path_destroy(t_path *path) if (path == NULL) return ; ft_lstclear(&path->dirs, free); - ft_htdestroy(path->commands, st_path_command_entry_del); + ft_htdestroy(path->commands, ms_ht_del_str_entry); free(path); } -- cgit