diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-05-07 13:49:10 +0200 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-05-07 13:49:10 +0200 | 
| commit | 9666a0a0ef6f5a4fb30bac93797d0f029ad8294a (patch) | |
| tree | a09f917723ae3a0dfeaef025b5e9a76e2c8602f2 | |
| parent | Preparing the structs (diff) | |
| download | 42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.gz 42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.bz2 42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.xz 42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.tar.zst 42-minishell-9666a0a0ef6f5a4fb30bac93797d0f029ad8294a.zip | |
Still pipin'
Diffstat (limited to '')
| -rw-r--r-- | src/ft_d_enum.h | 6 | ||||
| -rw-r--r-- | src/ft_m_loop.c | 5 | ||||
| -rw-r--r-- | src/ft_p_lcom.c | 23 | ||||
| -rw-r--r-- | src/ft_s_lcom.c | 8 | ||||
| -rw-r--r-- | src/ft_s_lcom.h | 6 | ||||
| -rw-r--r-- | src/ft_s_lpipes.c | 90 | ||||
| -rw-r--r-- | src/ft_s_lpipes.h | 9 | ||||
| -rw-r--r-- | src/ft_s_struct.h | 3 | 
8 files changed, 137 insertions, 13 deletions
| diff --git a/src/ft_d_enum.h b/src/ft_d_enum.h index c34f296..b712097 100644 --- a/src/ft_d_enum.h +++ b/src/ft_d_enum.h @@ -20,6 +20,12 @@  ** 1: alloc err  */ +typedef enum +{ +	FALSE, +	TRUE +}	t_bool; +  enum  {  	FT_RET_FINE, diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index 0b590a0..e44c85c 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -28,9 +28,9 @@ static char  {  	size_t	i;  	size_t	j; -	char	*dst;  	size_t	size1;  	size_t	size2; +	char	*dst;  	i = -1;  	j = -1; @@ -87,8 +87,11 @@ uint8_t  	char	*line;  	char	*quote;  	int8_t	gnl; +	int32_t	pipefd[2];  	gnl = 1; +	pipefd[0] = STDOUT_FILENO; +	pipefd[1] = STDIN_FILENO;  	while (gnl > 0)  	{  		ft_m_prompt(msh); diff --git a/src/ft_p_lcom.c b/src/ft_p_lcom.c index 9a678e6..823db3b 100644 --- a/src/ft_p_lcom.c +++ b/src/ft_p_lcom.c @@ -17,8 +17,10 @@  #include <unistd.h>  #include <errno.h> +#include "ft_d_define.h"  #include "ft_f_fail.h"  #include "ft_s_lcom.h" +#include "ft_s_lpipes.h"  #include "ft_s_struct.h"  static void @@ -125,19 +127,30 @@ int8_t  			const uint64_t count,  			t_msh *msh)  { -	uint64_t	i; -	t_lcom		*link; -	char		**words; +	/* TODO: norme */ +	uint64_t		i; +	t_lcom			*link; +	struct s_lpipes	*lpipes; +	char			**words; +	t_bool			next;  	i = 0;  	if (!(words = ft_split(line, ';')))  		return (-1);  	while (i <= count && words[i])  	{ -		if (!(link = ft_lcom_new(words[i], msh))) +		next = FALSE; +		/* TODO: split pipes here */ +		if (ft_strchr(words[i], '|'))  		{ -			return (-1); +			if (!(link = ft_lcom_new(NULL, msh))) +				return (-1); +			if (!(lpipes = ft_split_pipes(words[i], link, msh))) +				return (-1); +			next = TRUE;  		} +		if (next == FALSE && !(link = ft_lcom_new(words[i], NULL, msh))) +			return (-1);  		ft_lcom_add_back(&msh->curr, link);  		i++;  	} diff --git a/src/ft_s_lcom.c b/src/ft_s_lcom.c index 524eb32..d56ba7f 100644 --- a/src/ft_s_lcom.c +++ b/src/ft_s_lcom.c @@ -110,6 +110,7 @@ t_lcom  	*ft_lcom_new(const char word[],  				t_msh *msh)  { +	/* TODO: norme */  	t_lcom	*link;  	char	**words; @@ -120,6 +121,13 @@ t_lcom  	link->argv = NULL;  	link->rdrfd = 0;  	link->rdrpath = NULL; +	link->pipes = NULL; +	if (!word) +	{ +		link->next = NULL; +		return (link); +	} +	link->pipes = NULL;  	if (ft_get_redir(word, &link) != 0)  		return (NULL);  	if (!(words = ft_subst_args(word, link->redir))) diff --git a/src/ft_s_lcom.h b/src/ft_s_lcom.h index 6db58d3..ea78d6f 100644 --- a/src/ft_s_lcom.h +++ b/src/ft_s_lcom.h @@ -15,11 +15,9 @@  #include "ft_s_struct.h" -void	ft_lcom_add_back(t_lcom **alcom, -						t_lcom *new); +void	ft_lcom_add_back(t_lcom **alcom, t_lcom *new);  void	ft_lcom_clear(t_lcom **lcom); -t_lcom	*ft_lcom_new(const char word[], -					t_msh *msh); +t_lcom	*ft_lcom_new(const char word[], t_msh *msh);  t_lcom	*ft_lcom_last(t_lcom *lcom);  #endif diff --git a/src/ft_s_lpipes.c b/src/ft_s_lpipes.c index addbe7b..0a637ce 100644 --- a/src/ft_s_lpipes.c +++ b/src/ft_s_lpipes.c @@ -10,6 +10,96 @@  /*                                                                            */  /* ************************************************************************** */ +#include <libft.h> +#include <stdlib.h>  #include <stdint.h> +#include "ft_s_lcom.h"  #include "ft_s_lpipes.h" +#include "ft_s_struct.h" + +struct s_lpipes +	*ft_lpipes_last(struct s_lpipes *lpipes) +{ +	while (lpipes->next != NULL) +		lpipes = lpipes->next; +	return (lpipes); +} + +void +	ft_lpipes_add_back(struct s_lpipes **alpipes, +					struct s_lpipes *new) +{ +	t_lcom	*tmp; + +	if (!*alpipes) +		*alpipes = new; +	else +	{ +		tmp = ft_lpipes_last(*alpipes); +		tmp->next = new; +	} +} + +void +	ft_lpipes_clear(struct s_lpipes **lpipes) +{ +	struct s_lpipes	*tmp; +	struct s_lpipes	*renext; + +	if (!lcom) +		return ; +	tmp = *lpipes; +	while (tmp) +	{ +		renext = tmp->next; +		ft_lcom_clear(&tmp->one); +		ft_memdel((void*)&tmp); +		tmp = renext; +	} +	*lpipes = NULL; +} + +struct s_lpipes +	*ft_lpipes_new(const char pipedword[], +					t_msh *msh) +{ +	struct s_lpipes	*link; + +	if (!(link = (struct s_lpipes*)malloc(sizeof(struct s_lpipes)))) +		return (NULL); +	link->one = NULL; +	if (!(link->one = ft_lcom_new(pipedword, msh))) +	{ +		return (NULL); +	} +	link->next = NULL; +	return (link); +} + +struct s_lpipes +	*ft_split_pipes(const char word[], +					t_lcom *lcom, +					t_msh *msh) +{ +	struct s_pipes	*link; +	struct s_pipes	*lpipes; +	char			**words; +	size_t			i; + +	if (!(words = ft_split(word, '|'))) +		return (NULL); +	i = 0; +	if (!(lpipes = (struct s_lpipes*)malloc(sizeof(struct s_lpipes)))) +	while (words[i]) +	{ +		if (!(link = ft_lpipes_new(words[i], msh))) +		{ +			return (NULL); +		} +		ft_lpipes_add_back(); +		i++; +	} +	ft_delwords(words); +	return (lpipes); +} diff --git a/src/ft_s_lpipes.h b/src/ft_s_lpipes.h index bbde11b..50fd693 100644 --- a/src/ft_s_lpipes.h +++ b/src/ft_s_lpipes.h @@ -13,4 +13,13 @@  #ifndef FT_S_LPIPES_H  #define FT_S_LPIPES_H +#include "ft_s_struct.h" + +struct s_lpipes	*ft_lpipes_last(struct s_lpipes *lpipes); +void			ft_lpipes_add_back(struct s_lpipes **alpipes, +								struct s_lpipes *new); +void			ft_lpipes_clear(struct s_lpipes **lpipes); +struct s_lpipes	*ft_lpipes_new(const char pipedword[], t_msh *msh); +struct s_lpipes	*ft_split_pipes(const char word[], t_lcom *lcom, t_msh *msh); +  #endif diff --git a/src/ft_s_struct.h b/src/ft_s_struct.h index 56c1eeb..3a8df0a 100644 --- a/src/ft_s_struct.h +++ b/src/ft_s_struct.h @@ -48,9 +48,6 @@ typedef struct		s_lcom  struct		s_lpipes  { -	int32_t			pipefd[2]; -	char			*com; -	char			**argv;  	struct s_lcom	*one;  	struct s_lpipes	*next;  }; | 
