5 schtroumpf noir rencontre la schtroumpfette que se passe t-il?

This commit is contained in:
Etienne Rey-bethbeder 2023-03-31 20:45:06 +02:00
parent b96b617e09
commit 7e0bbd1203

View File

@ -6,17 +6,21 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
/* Updated: 2023/03/30 15:05:25 by erey-bet ### ########.fr */
/* Updated: 2023/03/31 20:42:17 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
#include "./builtins_private.h"
static int error(char *str)
static int error(char *str, char *to_free1, char *to_free2)
{
write(2, "bozoshell: export: `", 20);
write(2, str, ft_strlen(str));
write(2, "': not a valid identifier\n", 26);
if (to_free1 != NULL)
free(to_free1);
if (to_free2 != NULL)
free(to_free2);
return (1);
}
@ -55,8 +59,7 @@ int set_key_value_export(t_list **env, char *args, char **key, char **value)
if (get_value_by_key(*key, env) == NULL)
*value = ft_strdup(ft_strchr(args, '=') + 1);
else
*value = ft_strjoin(get_value_by_key(*key, env),
ft_strchr(args, '=') + 1);
*value = ft_strjoin(get_value_by_key(*key, env), ft_strchr(args, '=') + 1);
}
else
*value = ft_strdup(ft_strchr(args, '=') + 1);
@ -71,7 +74,7 @@ int add_export(t_list **env, char *args)
if (ft_strchr(args, '=') != NULL)
{
if (set_key_value_export(env, args, &key, &value))
return (error(args));
return (error(args, key, NULL));
}
else
{
@ -80,10 +83,10 @@ int add_export(t_list **env, char *args)
if (value != NULL)
value = ft_strdup(value);
if (possible_key(key) == 2)
return (error(key));
return (error(key, key, value));
}
if (!possible_key(key))
return (error(args));
return (error(args, key, value));
create_value_by_key(key, value, env);
return (0);
}