diff options
| -rw-r--r-- | src/p_redirs.c | 23 | ||||
| -rw-r--r-- | src/p_redirs.h | 5 | 
2 files changed, 16 insertions, 12 deletions
| diff --git a/src/p_redirs.c b/src/p_redirs.c index c978212..7c71d13 100644 --- a/src/p_redirs.c +++ b/src/p_redirs.c @@ -26,9 +26,9 @@  #include "u_vars.h"  static void		p_append_redir(const char path[], -							int32_t fd, -							int8_t redir, -							t_com *com) +							int32_t fd_rdr[], +							t_com *com, +							t_msh *msh)  {  	struct s_lredir	*new; @@ -101,16 +101,15 @@ static void		p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)  	struct s_rdr_tmp	tmp;  	char				path[PATH_MAX];  	size_t				pos[2]; -	int32_t				fd; -	int8_t				redir; +	int32_t				fd_rdr[2];  	pos[0] = 0; -	if ((fd = p_get_fd(word, ptr)) <= 0) -		fd = STDOUT_FILENO; -	redir = (*ptr == '>') ? (1) : (-1); -	redir = (redir == 1 && *(ptr + 1) == '>') ? (2) : (redir); -	redir = (redir == -1 && *(ptr + 1) == '<') ? (-2) : (redir); -	if (fd == STDOUT_FILENO) +	if ((fd_rdr[FD] = p_get_fd(word, ptr)) <= 0) +		fd_rdr[FD] = STDOUT_FILENO; +	fd_rdr[RDR] = (*ptr == '>') ? (1) : (-1); +	fd_rdr[RDR] = (fd_rdr[RDR] == 1 && *(ptr + 1) == '>') ? (2) : (fd_rdr[1]); +	fd_rdr[RDR] = (fd_rdr[RDR] == -1 && *(ptr + 1) == '<') ? (-2) : (fd_rdr[1]); +	if (fd_rdr[FD] == STDOUT_FILENO)  		pos[0] = (ptr - word);  	else  		pos[0] = (ptr - word) - ft_intlen(fd); @@ -120,7 +119,7 @@ static void		p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)  	pos[1] = p_get_path(path, tmp, msh);  	(void)ft_memmove(word + pos[0],  		word + pos[1], (ft_strlen(word + pos[1]) + 1) * sizeof(char)); -	p_append_redir(path, fd, redir, com); +	p_append_redir(path, fd_rdr, redir, com);  }  int8_t			p_redirs(char word[], t_com **com, t_msh *msh) diff --git a/src/p_redirs.h b/src/p_redirs.h index 3845a65..db75cfb 100644 --- a/src/p_redirs.h +++ b/src/p_redirs.h @@ -17,6 +17,11 @@  #include "s_struct.h" +enum	e_fd_rdr_id +{ +	FD, +	RDR +};  struct s_rdr_tmp  {  	const char	*word; | 
