diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-26 19:43:38 +0200 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-26 19:43:38 +0200 | 
| commit | cd0db603de6660c4f9388a5f69e36996788ed625 (patch) | |
| tree | 91eaa42a7c52635bbeed65e20bade9ab12380b50 /src | |
| parent | In progress (diff) | |
| download | 42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.gz 42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.bz2 42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.xz 42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.tar.zst 42-minishell-cd0db603de6660c4f9388a5f69e36996788ed625.zip | |
Fixed qwe>~/qweqwe
Diffstat (limited to '')
| -rw-r--r-- | src/p_redirs.c | 18 | ||||
| -rw-r--r-- | src/p_redirs.h | 2 | ||||
| -rw-r--r-- | src/s_com.c | 2 | 
3 files changed, 10 insertions, 12 deletions
| diff --git a/src/p_redirs.c b/src/p_redirs.c index d83ebfd..581ac48 100644 --- a/src/p_redirs.c +++ b/src/p_redirs.c @@ -43,7 +43,7 @@ static void		p_append_redir(const char path[],  static size_t	p_get_path(char path[],  						char *ptr,  						const char word[], -						int8_t redir) +						t_msh *msh)  {  	char	home[PATH_MAX];  	size_t	pos[2]; @@ -51,8 +51,8 @@ static size_t	p_get_path(char path[],  	size_t	len;  	hlen = 0; -	redir = (redir < 0) ? (-redir) : (redir); -	ptr += redir; +	while (ft_ischarset("<>", *ptr) == TRUE) +		ptr++;  	while (*ptr != C_NUL && ft_iswhitespace(*ptr) == TRUE)  		ptr++;  	if (*ptr == C_TILDE && u_get_var_value(home, "$HOME", PATH_MAX, msh) == 0) @@ -62,15 +62,13 @@ static size_t	p_get_path(char path[],  		ptr++;  	}  	pos[0] = (ptr - word); -	while (*ptr != C_NUL && -		ft_iswhitespace(*ptr) == FALSE && +	while (*ptr != C_NUL && ft_iswhitespace(*ptr) == FALSE &&  		u_is_not_escaped(word, ptr) == TRUE)  		ptr++;  	pos[1] = (ptr - word);  	len = (pos[1] - pos[0]);  	len = ((hlen + len + 1) > PATH_MAX) ? (PATH_MAX - 1) : (len);  	ft_strlcpy(path + hlen, word + pos[0], len + 1); -	ft_printf("%s\n", path);  	return (pos[1]);  } @@ -97,7 +95,7 @@ static int32_t	p_get_fd(const char word[], char *ptr)  	return (ft_atoi(digit));  } -static int8_t	p_get_redir(char word[], char *ptr, t_com *com) +static int8_t	p_get_redir(char word[], char *ptr, t_com *com, t_msh *msh)  {  	char	path[PATH_MAX];  	size_t	pos[2]; @@ -115,14 +113,14 @@ static int8_t	p_get_redir(char word[], char *ptr, t_com *com)  		pos[0] = (ptr - word);  	else  		pos[0] = (ptr - word) - ft_intlen(fd); -	pos[1] = p_get_path(path, ptr, word, redir); +	pos[1] = p_get_path(path, ptr, word, 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);  	return (0);  } -int8_t			p_redirs(char word[], t_com **com) +int8_t			p_redirs(char word[], t_com **com, t_msh *msh)  {  	char			*ptr;  	t_quote_mode	mode; @@ -137,7 +135,7 @@ int8_t			p_redirs(char word[], t_com **com)  			mode = u_meet_squote(word, ptr, mode);  		else if (mode == Q_NONE && (*ptr == '<' || *ptr == '>') == 1)  		{ -			if (p_get_redir(word, ptr, *com) != 0) +			if (p_get_redir(word, ptr, *com, msh) != 0)  				return (1);  			ptr = word;  		} diff --git a/src/p_redirs.h b/src/p_redirs.h index 57294e3..67e8ab1 100644 --- a/src/p_redirs.h +++ b/src/p_redirs.h @@ -17,6 +17,6 @@  #include "s_struct.h" -int8_t	p_redirs(char word[], t_com **com); +int8_t	p_redirs(char word[], t_com **com, t_msh *msh);  #endif diff --git a/src/s_com.c b/src/s_com.c index 527829d..4f06c84 100644 --- a/src/s_com.c +++ b/src/s_com.c @@ -109,7 +109,7 @@ t_com  	com->rdr = NULL;  	nword[0] = C_NUL;  	ft_strlcpy(nword, word, ARG_MAX); -	if (p_redirs(nword, &com) != 0) +	if (p_redirs(nword, &com, msh) != 0)  		return (NULL);  	if (msh->alias != NULL)  	{ | 
