SAMANTHA EST CHAUDE
This commit is contained in:
@ -6,17 +6,17 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/23 13:20:55 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/02/23 16:50:01 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
int print_env(t_list **head, int fd)
|
||||
int print_env(t_list **env, int fd)
|
||||
{
|
||||
t_list *current;
|
||||
|
||||
current = *head;
|
||||
current = *env;
|
||||
while (current->next != NULL)
|
||||
{
|
||||
ft_putstr_fd(((t_env *)(current->content))->key, fd);
|
||||
|
@ -6,17 +6,25 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/02/14 14:52:50 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/02/23 17:15:13 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../minishell.h"
|
||||
|
||||
int print_export(t_list **head, int fd)
|
||||
int error(char *str, int fd)
|
||||
{
|
||||
write(fd, "bash: export: `", 15);
|
||||
write(fd, str, ft_strlen(str));
|
||||
write(fd, "': not a valid identifier\n", 26);
|
||||
return (1);
|
||||
}
|
||||
|
||||
void print_export(t_list **env, int fd)
|
||||
{
|
||||
t_list *current;
|
||||
|
||||
current = *head;
|
||||
current = *env;
|
||||
while (current->next != NULL)
|
||||
{
|
||||
write(fd, "declare -x ", 11);
|
||||
@ -27,5 +35,50 @@ int print_export(t_list **head, int fd)
|
||||
write(fd, "\"\n", 2);
|
||||
current = current->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
void add_export(t_list **env, char *args, int fd, int *err)
|
||||
{
|
||||
char *key;
|
||||
char *value;
|
||||
|
||||
key = args;
|
||||
value = "";
|
||||
if (ft_strchr(args, '=') != NULL)
|
||||
{
|
||||
key = ft_strndup(args, ft_strnchr(args, '='));
|
||||
value = ft_strchr(args, '=') + 1;
|
||||
}
|
||||
if (!possible_key(key))
|
||||
{
|
||||
*err = error(key, fd);
|
||||
return ;
|
||||
}
|
||||
create_value_by_key_dup(key, value, env);
|
||||
}
|
||||
|
||||
int export(t_list **env, char **args, int fd)
|
||||
{
|
||||
int err;
|
||||
int i;
|
||||
|
||||
err = 0;
|
||||
if (args[0] == NULL)
|
||||
print_export(env, fd);
|
||||
else
|
||||
{
|
||||
i = -1;
|
||||
while (args[++i])
|
||||
add_export(env, args[i], fd, &err);
|
||||
}
|
||||
return (err);
|
||||
}
|
||||
|
||||
/*int main(int argc, char *argv[], char **env)
|
||||
{
|
||||
t_list **n_env;
|
||||
|
||||
n_env = init_env(env);
|
||||
export(n_env, argv + 1, 1);
|
||||
return (0);
|
||||
}*/
|
||||
|
@ -6,13 +6,28 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/22 13:28:27 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/02/22 13:37:27 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/02/23 15:49:21 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int error(char *str, int fd)
|
||||
{
|
||||
write(fd, "bash: unset: `", 14);
|
||||
write(fd, str, ft_strlen(str));
|
||||
write(fd, "': not a valid identifier", 25);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int unset(t_list **env, char **args, int fd)
|
||||
{
|
||||
while (args++)
|
||||
delete_by_key(*args, env);
|
||||
return (0);
|
||||
int i;
|
||||
int err;
|
||||
|
||||
i = -1;
|
||||
err = 0;
|
||||
while (args[++i])
|
||||
if (delete_by_key(args[i], env))
|
||||
if (!possible_key(args[i]))
|
||||
err = error(args[i], fd);
|
||||
return (err);
|
||||
}
|
||||
|
Reference in New Issue
Block a user