1
0
mirror of https://github.com/KeyZox71/ft_minipowershell.git synced 2025-05-15 08:38:46 +02:00

」 feat(builtins/ft_export): += is added !

This commit is contained in:
yosyo
2024-07-15 18:04:17 +02:00
parent ab717f740b
commit ab8177a419
6 changed files with 67 additions and 32 deletions

View File

@ -6,23 +6,13 @@
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 08:42:36 by mmoussou #+# #+# */
/* Updated: 2024/07/15 13:31:22 by mmoussou ### ########.fr */
/* Updated: 2024/07/15 18:02:16 by mmoussou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "builtins.h"
uint ft_arraylen(char **s)
{
char **endptr;
endptr = s;
while (*endptr)
endptr++;
return (endptr - s);
}
void ft_arraysort(char **env)
{
char *tmp;
@ -92,6 +82,32 @@ int export_value(char *arg, t_env *env)
return (0);
}
int export_append_value(char *arg, t_env *env)
{
char *name;
char *content;
t_env *env_t;
name = ft_calloc(sizeof(char), ft_strchr(arg, '=') - arg);
content = ft_calloc(sizeof(char), ft_strlen(ft_strchr(arg, '=')));
if (!name || !content)
{
ft_free("cc", &name, &content);
return (-1);
}
ft_strlcpy(name, arg, ft_strchr(arg, '=') - arg);
ft_strlcpy(content, ft_strchr(arg, '=') + 1,
ft_strlen(ft_strchr(arg, '=')) + 1);
env_t = env;
while (env_t && ft_strcmp(env_t->name, name))
env_t = env_t->next;
if (env_t)
env_append(name, content, env);
else
ft_envadd_back(&env, ft_envnew(name, content));
return (0);
}
void ft_export(char **args, t_env *env)
{
int status;
@ -105,7 +121,10 @@ void ft_export(char **args, t_env *env)
{
if (!check_export_input(*args))
{
status = export_value(*args, env);
if (ft_strchr(*args, '=') && (ft_strchr(*args, '=') - 1)[0] == '+')
status = export_append_value(*args, env);
else
status = export_value(*args, env);
if (status)
return ;
}