diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/s_destroy.c | 1 | ||||
| -rw-r--r-- | src/s_lalias.c | 78 | ||||
| -rw-r--r-- | src/s_lalias.h | 5 | ||||
| -rw-r--r-- | src/s_lvars.c | 17 | ||||
| -rw-r--r-- | src/s_struct.h | 2 | ||||
| -rw-r--r-- | src/u_alias.c | 43 | ||||
| -rw-r--r-- | src/u_alias.h | 26 | ||||
| -rw-r--r-- | src/u_vars.h | 2 | 
8 files changed, 163 insertions, 11 deletions
| diff --git a/src/s_destroy.c b/src/s_destroy.c index 6626bd9..f9ce3c4 100644 --- a/src/s_destroy.c +++ b/src/s_destroy.c @@ -13,6 +13,7 @@  #include <libft.h>  #include "s_destroy.h" +#include "s_lalias.h"  #include "s_lvars.h"  void diff --git a/src/s_lalias.c b/src/s_lalias.c index 3bbee14..b4b9430 100644 --- a/src/s_lalias.c +++ b/src/s_lalias.c @@ -10,9 +10,85 @@  /*                                                                            */  /* ************************************************************************** */ +#include <libft.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +  #include "s_struct.h" +void +	s_lalias_rebind(t_lalias **lalias, +					const char newname[], +					const char newval[]) +{ +	t_lalias	*tmp; + +	tmp = *lalias; +	while (tmp != NULL && +		ft_strncmp(tmp->name, newname, ft_strlen(newname) + 1) != 0) +	{ +		tmp = tmp->next; +	} +	if (tmp == NULL) +	{ +		return ; +	} +	ft_memdel((void*)&tmp->val); +	if ((tmp->val = ft_strdup(newval)) == NULL) +	{ +		ft_dprintf(STDERR_FILENO, "%s\n", strerror(errno)); +	} +} + +void +	s_lalias_add_front(t_lalias **lalias, t_lalias *new) +{ +	if (lalias == NULL || new == NULL) +	{ +		return ; +	} +	new->next = *lalias; +	*lalias = new; +} + +void +	s_lalias_clear(t_lalias **lalias) +{ +	t_lalias	*tmp; +	t_lalias	*renext; + +	if (lalias == NULL) +		return ; +	tmp = *lalias; +	while (tmp != NULL) +	{ +		renext = tmp->next; +		ft_memdel((void*)&tmp->name); +		ft_memdel((void*)&tmp->val); +		ft_memdel((void*)&tmp); +	} +	*lalias = NULL; +} +  t_lalias -*s_lalias_new(const char name[], const char val[])	 +	*s_lalias_new(const char name[], const char val[])	  { +	t_lalias	*link; + +	if ((link = (t_lalias*)malloc(sizeof(t_lalias))) == NULL) +	{ +		return (NULL); +	} +	if ((link->name = ft_strdup(name)) == NULL) +	{ +		return (NULL); +	} +	if ((link->val = ft_strdup(val)) == NULL) +	{ +		return (NULL); +	} +	link->next = NULL; +	return (link);  } diff --git a/src/s_lalias.h b/src/s_lalias.h index 8add358..5218a88 100644 --- a/src/s_lalias.h +++ b/src/s_lalias.h @@ -15,6 +15,11 @@  #include "s_struct.h" +void		s_lalias_rebind(t_lalias **lalias, +							const char name[], +							const char newval[]); +void		s_lalias_add_front(t_lalias **lalias, t_lalias *new); +void		s_lalias_clear(t_lalias **lalias);  t_lalias	*s_lalias_new(const char name[], const char val[]);  #endif diff --git a/src/s_lvars.c b/src/s_lvars.c index 3eb4943..e4b054e 100644 --- a/src/s_lvars.c +++ b/src/s_lvars.c @@ -11,8 +11,8 @@  /* ************************************************************************** */  #include <libft.h> -#include <string.h>  #include <stdlib.h> +#include <string.h>  #include <errno.h>  #include <unistd.h> @@ -24,7 +24,7 @@ void  	t_lvars	*tmp;  	tmp = *lvars; -	while (tmp && ft_strncmp(tmp->name, name, ft_strlen(name) + 1)) +	while (tmp != NULL && ft_strncmp(tmp->name, name, ft_strlen(name) + 1) != 0)  	{  		tmp = tmp->next;  	} @@ -33,10 +33,9 @@ void  		return ;  	}  	ft_memdel((void*)&tmp->val); -	if (!(tmp->val = ft_strdup(newval))) +	if ((tmp->val = ft_strdup(newval)) == NULL)  	{  		ft_dprintf(STDERR_FILENO, "%s\n", strerror(errno)); -		exit(FT_RET_ALLOC);  	}  } @@ -71,7 +70,7 @@ void  void  	lvars_add_front(t_lvars **alvars, t_lvars *new)  { -	if (!alvars || !new) +	if (alvars == NULL || new == NULL)  	{  		return ;  	} @@ -88,7 +87,7 @@ void  	if (lvars == NULL)  		return ;  	tmp = *lvars; -	while (tmp) +	while (tmp != NULL)  	{  		renext = tmp->next;  		ft_memdel((void*)&tmp->name); @@ -104,15 +103,15 @@ t_lvars  {  	t_lvars	*link; -	if (!(link = (t_lvars*)malloc(sizeof(t_lvars)))) +	if ((link = (t_lvars*)malloc(sizeof(t_lvars))) == NULL)  	{  		return (NULL);  	} -	if (!(link->name = ft_strdup(name))) +	if ((link->name = ft_strdup(name)) == NULL)  	{  		return (NULL);  	} -	if (!(link->val = ft_strdup(val))) +	if ((link->val = ft_strdup(val)) == NULL)  	{  		return (NULL);  	} diff --git a/src/s_struct.h b/src/s_struct.h index d678c36..963d5ad 100644 --- a/src/s_struct.h +++ b/src/s_struct.h @@ -28,7 +28,7 @@ typedef struct			s_lvars  typedef struct			s_lalias  {  	char				*name; -	char				*value; +	char				*val;  	struct s_lalias		*next;  }						t_lalias; diff --git a/src/u_alias.c b/src/u_alias.c new file mode 100644 index 0000000..6253d60 --- /dev/null +++ b/src/u_alias.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   u_alias.c                                          :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#include <libft.h> +#include <stddef.h> + +#include "d_define.h" +#include "s_struct.h" + +void +	u_get_alias_value(char str[], const char name[], size_t dstsize, t_msh *msh) +{ +	t_lalias	*ptr; + +	str[0] = C_NUL; +	ptr = msh->alias; +	while (ptr != NULL && ft_strncmp(tmp->name, name, ft_strlen(name)) != 0) +	{ +		ptr = ptr->next; +	} +	if (ptr != NULL) +	{ +		ft_strlcpy(str, tmp->value, dstsize); +	} +} + +void +	u_set_alias_value(const char name[], const char value[], t_msh *msh) +{ +	t_lalias	*tmp; + +	tmp = msh->alias; +	while (tmp) +} diff --git a/src/u_alias.h b/src/u_alias.h new file mode 100644 index 0000000..c660484 --- /dev/null +++ b/src/u_alias.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/*                                                                            */ +/*                                                        :::      ::::::::   */ +/*   u_alias.h                                          :+:      :+:    :+:   */ +/*                                                    +:+ +:+         +:+     */ +/*   By: rbousset <marvin@42.fr>                    +#+  +:+       +#+        */ +/*                                                +#+#+#+#+#+   +#+           */ +/*   Created: 2020/02/14 17:19:27 by rbousset          #+#    #+#             */ +/*   Updated: 2020/02/14 17:19:29 by rbousset         ###   ########lyon.fr   */ +/*                                                                            */ +/* ************************************************************************** */ + +#ifndef U_ALIAS_H +#define U_ALIAS_H + +#include <stddef.h> + +#include "s_struct.h" + +void	u_get_alias_value(char str[], +						const char name[], +						size_t dstsize, +						t_msh *msh); +void	u_set_alias_value(const char name[], const char value[], t_msh *msh); + +#endif diff --git a/src/u_vars.h b/src/u_vars.h index fbdaffc..27c975f 100644 --- a/src/u_vars.h +++ b/src/u_vars.h @@ -13,6 +13,8 @@  #ifndef U_VARS_H  #define U_VARS_H +#include <stddef.h> +  #include "s_struct.h"  void	u_get_custom_var(char str[], | 
