diff options
| author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-11 17:58:05 +0200 | 
|---|---|---|
| committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-11 17:58:05 +0200 | 
| commit | cf39c418a49808eb63cf4e1b5e2e363455f2da84 (patch) | |
| tree | d6e0403dfd1b72cb1cc76c15254d53d21c8bec6b | |
| parent | Aliases list in progress (diff) | |
| download | 42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.gz 42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.bz2 42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.xz 42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.tar.zst 42-minishell-cf39c418a49808eb63cf4e1b5e2e363455f2da84.zip | |
alias utils prepared
Diffstat (limited to '')
| -rw-r--r-- | src/m_loop.c | 1 | ||||
| -rw-r--r-- | src/s_lalias.c | 7 | ||||
| -rw-r--r-- | src/u_alias.c | 36 | ||||
| -rw-r--r-- | src/u_alias.h | 2 | 
4 files changed, 32 insertions, 14 deletions
| diff --git a/src/m_loop.c b/src/m_loop.c index 50357eb..bd4fb1c 100644 --- a/src/m_loop.c +++ b/src/m_loop.c @@ -26,6 +26,7 @@  #include "s_lpipes.h"  #include "s_line.h"  #include "u_vars.h" +#include "u_alias.h"  static void  	m_parse_and_run_line(char line[], t_msh *msh) diff --git a/src/s_lalias.c b/src/s_lalias.c index b4b9430..eeac08b 100644 --- a/src/s_lalias.c +++ b/src/s_lalias.c @@ -19,15 +19,12 @@  #include "s_struct.h"  void -	s_lalias_rebind(t_lalias **lalias, -					const char newname[], -					const char newval[]) +	s_lalias_rebind(t_lalias **lalias, const char name[], const char newval[])  {  	t_lalias	*tmp;  	tmp = *lalias; -	while (tmp != NULL && -		ft_strncmp(tmp->name, newname, ft_strlen(newname) + 1) != 0) +	while (tmp != NULL && ft_strncmp(tmp->name, name, ft_strlen(name) + 1) != 0)  	{  		tmp = tmp->next;  	} diff --git a/src/u_alias.c b/src/u_alias.c index 6253d60..f273a5c 100644 --- a/src/u_alias.c +++ b/src/u_alias.c @@ -11,33 +11,53 @@  /* ************************************************************************** */  #include <libft.h> +#include <stdint.h>  #include <stddef.h>  #include "d_define.h" +#include "s_lalias.h"  #include "s_struct.h" -void +uint8_t  	u_get_alias_value(char str[], const char name[], size_t dstsize, t_msh *msh)  {  	t_lalias	*ptr; -	str[0] = C_NUL; +	if (str != NULL) +	{ +		str[0] = C_NUL; +	}  	ptr = msh->alias; -	while (ptr != NULL && ft_strncmp(tmp->name, name, ft_strlen(name)) != 0) +	while (ptr != NULL && ft_strncmp(ptr->name, name, ft_strlen(name) + 1) != 0)  	{  		ptr = ptr->next;  	} -	if (ptr != NULL) +	if (ptr == NULL) +	{ +		return (1); +	} +	if (str != NULL)  	{ -		ft_strlcpy(str, tmp->value, dstsize); +		ft_strlcpy(str, ptr->val, dstsize);  	} +	return (0);  }  void  	u_set_alias_value(const char name[], const char value[], t_msh *msh)  { -	t_lalias	*tmp; +	t_lalias	*new; -	tmp = msh->alias; -	while (tmp) +	if (u_get_alias_value(NULL, name, 0, msh) != 0) +	{ +		s_lalias_rebind(&msh->alias, name, value); +	} +	else +	{ +		if ((new = s_lalias_new(name, value)) == NULL) +		{ +			return ; +		} +		s_lalias_add_front(&msh->alias, new); +	}  } diff --git a/src/u_alias.h b/src/u_alias.h index c660484..59860db 100644 --- a/src/u_alias.h +++ b/src/u_alias.h @@ -17,7 +17,7 @@  #include "s_struct.h" -void	u_get_alias_value(char str[], +uint8_t	u_get_alias_value(char str[],  						const char name[],  						size_t dstsize,  						t_msh *msh); | 
