BIENTOT FINI POTO PAVAAAARRDDDD

This commit is contained in:
Etienne Rey-bethbeder
2023-03-09 15:07:36 +01:00
parent 876c75bb92
commit f956986789
119 changed files with 1057 additions and 34 deletions

BIN
builtins/cd.o Normal file

Binary file not shown.

BIN
builtins/echo.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:56:02 by cchauvet #+# #+# */
/* Updated: 2023/02/23 16:50:01 by erey-bet ### ########.fr */
/* Updated: 2023/03/09 15:04:47 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,10 +19,13 @@ int print_env(t_list **env, int fd)
current = *env;
while (current->next != NULL)
{
ft_putstr_fd(((t_env *)(current->content))->key, fd);
ft_putstr_fd("=", fd);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\n", 1);
if (((t_env *)(current->content))->original)
{
ft_putstr_fd(((t_env *)(current->content))->key, fd);
ft_putstr_fd("=", fd);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\n", 1);
}
current = current->next;
}
return (0);

BIN
builtins/env.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/24 10:17:59 by erey-bet #+# #+# */
/* Updated: 2023/02/28 14:55:39 by erey-bet ### ########.fr */
/* Updated: 2023/02/28 15:06:50 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -34,7 +34,7 @@ int ft_exit(char **args)
if (err == 1)
return (error(err, "numeric argument required", args[0]));
if (args[1] != NULL)
return (error(-1, "too many arguments", NULL));
return (error(1, "too many arguments", NULL));
if (err > 0)
return(error(err, "numeric argument required", args[0]));
return ((ft_atoi(args[0]) % 256 + 256) % 256);

BIN
builtins/exit.o Normal file

Binary file not shown.

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/14 14:27:08 by cchauvet #+# #+# */
/* Updated: 2023/02/28 14:37:38 by erey-bet ### ########.fr */
/* Updated: 2023/03/09 14:58:11 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -29,38 +29,50 @@ void print_export(t_list **env, int fd)
{
write(fd, "declare -x ", 11);
ft_putstr_fd(((t_env *)(current->content))->key, fd);
ft_putstr_fd("=", fd);
write(fd, "\"", 1);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\"\n", 2);
if (((t_env *)(current->content))->value != NULL)
{
ft_putstr_fd("=", fd);
write(fd, "\"", 1);
ft_putstr_fd(((t_env *)(current->content))->value, fd);
write(fd, "\"\n", 2);
}
else
write(fd, "\n", 2);
current = current->next;
}
}
int add_export(t_list **env, char *args, int fd, int *err)
int add_export(t_list **env, char *args, int fd)
{
char *key;
char *value;
key = args;
value = "";
if (ft_strchr(args, '=') != NULL)
{
key = ft_strndup(args, ft_strnchr(args, '='));
if (key == NULL)
return (1);
if (ft_strlen(key) == 0)
return (error(args, fd));
if (possible_key(key) == 2)
{
error(args, fd);
return (1);
key[ft_strlen(key) - 1] = '\0';
value = ft_strjoin(get_value_by_key(key, env), ft_strchr(args, '=') + 1);
}
value = ft_strchr(args, '=') + 1;
else
value = ft_strchr(args, '=') + 1;
}
else
{
value = get_value_by_key(key, env);
if (ft_strlen(value) == 0)
value = NULL;
if(possible_key(key) == 2)
return (error(key, fd));
}
if (!possible_key(key))
{
*err = error(key, fd);
return (1);
}
return (error(key, fd));
create_value_by_key_dup(key, value, env);
return (0);
}
@ -77,7 +89,7 @@ int export(t_list **env, char **args, int fd)
{
i = -1;
while (args[++i])
if (add_export(env, args[i], fd, &err) == 1)
if (add_export(env, args[i], fd) == 1)
err = 1;
}
return (err);

BIN
builtins/export.o Normal file

Binary file not shown.

BIN
builtins/pwd.o Normal file

Binary file not shown.

BIN
builtins/unset.o Normal file

Binary file not shown.