diff options
Diffstat (limited to '')
| -rw-r--r-- | src/ft_b_cd.c | 38 | ||||
| -rw-r--r-- | src/ft_m_funptr.c | 4 | ||||
| -rw-r--r-- | src/ft_m_loop.c | 1 | ||||
| -rw-r--r-- | src/ft_u_utils.c | 11 | ||||
| -rw-r--r-- | src/ft_u_utils.h | 2 | ||||
| -rw-r--r-- | src/minishell.c | 3 | 
6 files changed, 45 insertions, 14 deletions
| diff --git a/src/ft_b_cd.c b/src/ft_b_cd.c index eedb1c2..630005d 100644 --- a/src/ft_b_cd.c +++ b/src/ft_b_cd.c @@ -10,25 +10,51 @@  /*                                                                            */  /* ************************************************************************** */ +#include <libft.h>  #include <stdint.h>  #include <unistd.h>  #include "ft_s_struct.h"  #include "ft_u_utils.h" +/* static void */ +/* 	ft_switch_env_var(char **envp) */ +/* { */ +/* 	char	**ptr; */ +/* 	char	*path; */ + +/* 	ptr = envp; */ +/* 	while (*ptr) */ +/* 	{ */ +/* 		if (ft_strncmp("HOME", *ptr, 4) == 0) */ +/* 		{ */ +/* 			path = ft_substr(*ptr, 5, ft_strlen(*ptr + 5)); */ +/* 			return (path); */ +/* 		} */ +/* 		ptr++; */ +/* 	} */ +/* 	return (NULL); */ +/* } */ +  uint8_t  	ft_b_cd(char *args[],  			t_msh *msh)  { -	char	*path; +	const uint64_t	argc = ft_get_argc((const char**)args); +	char			*path; -	(void)msh; -	if (!args) +	if (argc == 0) +	{ +		path = ft_get_home_dir(msh->envp); +	} +	if (chdir(path) != 0)  	{ -		path = ft_get_home_dir(msh); -		chdir(); -		ft_memdel((void*)&path); +		/* TODO: handle cd failed */  	} +	/* TODO: ft_switch_env_var() */ +	ft_memdel((void*)&msh->cwd); +	msh->cwd = getcwd(NULL, 0); +	ft_memdel((void*)&path);  	/* TODO: do cd */  	return (0);  } diff --git a/src/ft_m_funptr.c b/src/ft_m_funptr.c index de6acd3..0a48d52 100644 --- a/src/ft_m_funptr.c +++ b/src/ft_m_funptr.c @@ -12,6 +12,7 @@  #include <libft.h>  #include <stdlib.h> +  #include "ft_d_enum.h"  #include "ft_b_builtins.h"  #include "ft_f_fail.h" @@ -28,8 +29,7 @@ void  	msh->bu_ptr[4] = ft_b_unset;  	msh->bu_ptr[5] = ft_b_env;  	msh->bu_ptr[6] = ft_b_exit; -	/* TODO: type builtin */ -	/* msh->bu_ptr[7] = ft_b_type; */ +	msh->bu_ptr[7] = ft_b_type;  	if (!(msh->bu_ref = ft_split(FT_BUILTINS, '|')))  	{  		ft_fail_alloc(); diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index def1f91..61f55ba 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -13,6 +13,7 @@  #include <libft.h>  #include <stdint.h>  #include <unistd.h> +  #include "ft_d_enum.h"  #include "ft_e_lcom.h"  #include "ft_m_loop.h" diff --git a/src/ft_u_utils.c b/src/ft_u_utils.c index 8c61bf9..cd9e53f 100644 --- a/src/ft_u_utils.c +++ b/src/ft_u_utils.c @@ -11,23 +11,28 @@  /* ************************************************************************** */  #include <libft.h> +#include <stdlib.h>  #include <stdint.h>  #include "ft_s_struct.h"  char -	*ft_get_home_dir(t_msh *msh) +	*ft_get_home_dir(char **envp)  {  	char	**ptr; +	char	*path; -	ptr = msh->envp; +	ptr = envp;  	while (*ptr)  	{ -		if (ft_strncmp( , , )) +		if (ft_strncmp("HOME", *ptr, 4) == 0)  		{ +			path = ft_substr(*ptr, 5, ft_strlen(*ptr + 5)); +			return (path);  		}  		ptr++;  	} +	return (NULL);  }  uint64_t diff --git a/src/ft_u_utils.h b/src/ft_u_utils.h index 84b2062..d025cb2 100644 --- a/src/ft_u_utils.h +++ b/src/ft_u_utils.h @@ -16,6 +16,6 @@  #include <stdint.h>  uint64_t	ft_get_argc(const char *args[]); -char		*ft_get_home_dir(t_msh *msh); +char		*ft_get_home_dir(char *envp[]);  #endif diff --git a/src/minishell.c b/src/minishell.c index f28b3b5..1b5f4da 100644 --- a/src/minishell.c +++ b/src/minishell.c @@ -12,8 +12,7 @@  #include <libft.h>  #include <stdint.h> -#include "minishell.h" -#include "ft_d_enum.h" +  #include "ft_f_fail.h"  #include "ft_m_loop.h"  #include "ft_s_struct.h" | 
