diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ft_b_cd.c | 2 | ||||
| -rw-r--r-- | src/ft_b_echo.c | 5 | ||||
| -rw-r--r-- | src/ft_b_type.c | 62 | ||||
| -rw-r--r-- | src/ft_e_externs.c | 1 | 
4 files changed, 62 insertions, 8 deletions
diff --git a/src/ft_b_cd.c b/src/ft_b_cd.c index 630005d..cbb392a 100644 --- a/src/ft_b_cd.c +++ b/src/ft_b_cd.c @@ -55,6 +55,6 @@ uint8_t  	ft_memdel((void*)&msh->cwd);  	msh->cwd = getcwd(NULL, 0);  	ft_memdel((void*)&path); -	/* TODO: do cd */ +	/* TODO: finish cd */  	return (0);  } diff --git a/src/ft_b_echo.c b/src/ft_b_echo.c index c50bd8b..fdac868 100644 --- a/src/ft_b_echo.c +++ b/src/ft_b_echo.c @@ -12,14 +12,15 @@  #include <libft.h>  #include <stdint.h> +  #include "ft_s_struct.h"  #include "ft_u_utils.h" -/* TODO: norme, echo $variables, echo "quoted text", echo 'quoted text', */ +/* TODO: norme, echo $variables (variables are subst when parsing the line), */ +/* echo "quoted text", echo 'quoted text', */  /* echo kill\nbackslash\nbut\nnot\nn, echo "quoted\nnew\nlines" */  /* Might need to go full buffer */ -  uint8_t  	ft_b_echo(char *args[],  			t_msh *msh) diff --git a/src/ft_b_type.c b/src/ft_b_type.c index f17ca45..f6601d8 100644 --- a/src/ft_b_type.c +++ b/src/ft_b_type.c @@ -10,15 +10,69 @@  /*                                                                            */  /* ************************************************************************** */ +#include <libft.h>  #include <stdint.h> +  #include "ft_s_struct.h" +#include "ft_e_externs_next.h" +#include "ft_u_utils.h" + +static char +	*ft_type_get_path(char *com, +					t_msh *msh) +{ +	char	**envpath; +	char	*fullpath; + +	envpath = NULL; +	fullpath = NULL; +	if (ft_ischarset("/.", com[0])) +	{ +		/* TODO: ft_get_absolute_path(ptr->com); */ +	} +	else if ((envpath = ft_get_env_path(msh)) != NULL) +	{ +		fullpath = ft_search_in_path(com, envpath, msh); +		ft_delwords(envpath); +	} +	return (fullpath); +}  uint8_t  	ft_b_type(char *args[],  			t_msh *msh)  { -	(void)args; -	(void)msh; -	/* TODO: do type */ -	return (0); +	/* TODO: norme */ +	char	**ptr; +	char	**p_bu; +	char	*fullpath; +	int32_t	ret; + +	ptr = args; +	if (!*ptr) +		return (1); +	ret = 0; +	while (*ptr) +	{ +		p_bu = msh->bu_ref; +		while (*p_bu && ft_strncmp(*ptr, *p_bu, ft_strlen(*p_bu) + 1)) +			p_bu++; +		if (*p_bu != NULL) +			ft_printf("%s is a shell builtin\n", *ptr); +		else +		{ +			fullpath = ft_type_get_path(*ptr, msh); +			if (fullpath) +				ft_printf("%s is %s\n", *ptr, fullpath); +			else +			{ +				ft_printf("minishell: type: %s: not found\n", *ptr); +				ret = 1; +			} +			ft_memdel((void*)&fullpath); +		} +		ptr++; +	} +	/* TODO: finish type */ +	return (ret);  } diff --git a/src/ft_e_externs.c b/src/ft_e_externs.c index fa682a0..58459e8 100644 --- a/src/ft_e_externs.c +++ b/src/ft_e_externs.c @@ -75,7 +75,6 @@ void  	else if ((envpath = ft_get_env_path(msh)) != NULL)  	{  		fullpath = ft_search_in_path(ptr->com, envpath, msh); -		/* TODO: exec $PATH stuff */  		ft_delwords(envpath);  	}  	/* TODO: deal if not found etc */  | 
