_
This commit is contained in:
parent
3e7dcd1ba9
commit
62e887cfbd
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/27 13:41:30 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/05 12:16:50 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/18 12:57:36 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -16,10 +16,10 @@
|
||||
|
||||
int echo(int fd, char **strs);
|
||||
int pwd(int fd);
|
||||
char *get_pwd(int fd);
|
||||
char *get_pwd(void);
|
||||
int print_env(t_list **env, int fd);
|
||||
int ft_export(t_list **env, char **args, int fd);
|
||||
int move_folder(char **args, int fd);
|
||||
int move_folder(char **args, t_list **env, int fd);
|
||||
int unset(t_list **env, char **args, int fd);
|
||||
int ft_exit(char **args, int err);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/27 13:41:42 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/03/31 20:07:36 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/18 12:57:25 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,6 +17,6 @@
|
||||
# include "../env/env.h"
|
||||
# include "../utils/utils.h"
|
||||
|
||||
char *get_pwd(int fd);
|
||||
char *get_pwd(void);
|
||||
|
||||
#endif
|
||||
|
@ -6,31 +6,37 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/20 14:27:36 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/03/31 15:02:43 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/18 13:22:22 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "./builtins_private.h"
|
||||
|
||||
int make_move(char *path, int fd)
|
||||
int make_move(char *path, t_list **env)
|
||||
{
|
||||
char *join;
|
||||
char *old;
|
||||
|
||||
join = ft_strjoin("/", path);
|
||||
join = ft_strfjoin(get_pwd(fd), join);
|
||||
join = ft_strfjoin(get_pwd(), join);
|
||||
old = get_pwd();
|
||||
if (chdir(join) == 0)
|
||||
{
|
||||
set_value_by_key("OLDPWD", old, env);
|
||||
set_value_by_key("PWD", get_pwd(), env);
|
||||
free(join);
|
||||
return (0);
|
||||
}
|
||||
free(old);
|
||||
free(join);
|
||||
write(2, "cd: No such file or directory\n", 30);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int move_folder(char **args, int fd)
|
||||
int move_folder(char **args, t_list **env)
|
||||
{
|
||||
char *path;
|
||||
char *old;
|
||||
|
||||
if (args[0] == NULL || args[1] != NULL)
|
||||
{
|
||||
@ -40,11 +46,17 @@ int move_folder(char **args, int fd)
|
||||
path = args[0];
|
||||
if (path[0] == '/' || ft_strncmp(path, "..", ft_strlen(path)) == 0)
|
||||
{
|
||||
old = get_pwd();
|
||||
if (chdir(path) == 0)
|
||||
{
|
||||
set_value_by_key("OLDPWD", old, env);
|
||||
set_value_by_key("PWD", get_pwd(), env);
|
||||
return (0);
|
||||
}
|
||||
free(old);
|
||||
write(2, "cd: No such file or directory\n", 30);
|
||||
return (1);
|
||||
}
|
||||
else
|
||||
return (make_move(path, fd));
|
||||
return (make_move(path, env));
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/17 16:09:11 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/03/09 20:00:19 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/18 12:59:25 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,13 +20,13 @@ int pwd(int fd)
|
||||
ft_putendl_fd(path, fd);
|
||||
else
|
||||
{
|
||||
ft_putendl_fd("Error getcwd", fd);
|
||||
ft_putendl_fd("Error getcwd", 2);
|
||||
return (1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
char *get_pwd(int fd)
|
||||
char *get_pwd(void)
|
||||
{
|
||||
char *str;
|
||||
|
||||
@ -35,7 +35,7 @@ char *get_pwd(int fd)
|
||||
return (str);
|
||||
else
|
||||
{
|
||||
ft_putendl_fd("Error getcwd", fd);
|
||||
ft_putendl_fd("Error getcwd", 2);
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
|
11
env/env1.c
vendored
11
env/env1.c
vendored
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/03/30 13:07:15 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/18 12:47:08 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -34,7 +34,11 @@ void add_sort(t_list **head, t_env *var)
|
||||
}
|
||||
}
|
||||
if (current->next == NULL)
|
||||
{
|
||||
current->next = ft_calloc(1, sizeof(t_list));
|
||||
if (!current->next)
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
char *get_value_by_key(char *key, t_list **head)
|
||||
@ -61,9 +65,7 @@ int set_value_by_key(char *key, char *value, t_list **head)
|
||||
if (ft_strcmp(((t_env *)current->content)->key, key) == 0)
|
||||
{
|
||||
free(((t_env *)current->content)->value);
|
||||
free(((t_env *)current->content)->key);
|
||||
((t_env *)current->content)->value = value;
|
||||
((t_env *)current->content)->key = key;
|
||||
return (0);
|
||||
}
|
||||
current = current->next;
|
||||
@ -97,7 +99,10 @@ t_list **init_env(char **env)
|
||||
return (NULL);
|
||||
*head = ft_calloc(1, sizeof(t_list));
|
||||
if (*head == NULL)
|
||||
{
|
||||
free(head);
|
||||
return (NULL);
|
||||
}
|
||||
i = -1;
|
||||
while (env[++i])
|
||||
{
|
||||
|
2
env/env2.c
vendored
2
env/env2.c
vendored
@ -6,7 +6,7 @@
|
||||
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/09 19:59:03 by erey-bet #+# #+# */
|
||||
/* Updated: 2023/03/09 19:59:10 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/18 13:26:31 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/21 12:45:16 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/14 17:17:16 by cchauvet ### ########.fr */
|
||||
/* Updated: 2023/04/18 13:00:08 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -23,7 +23,7 @@ static int ft_execute_own_cmd(t_data *data, t_cmd *cmd)
|
||||
else if (ft_strcmp(cmd->executable, "export") == 0)
|
||||
return_code = ft_export(data->env, cmd->args + 1, cmd->fd_out[0]);
|
||||
else if (ft_strcmp(cmd->executable, "cd") == 0)
|
||||
return_code = (move_folder(cmd->args + 1, cmd->fd_out[0]));
|
||||
return_code = (move_folder(cmd->args + 1, data->env, cmd->fd_out[0]));
|
||||
else if (ft_strcmp(cmd->executable, "unset") == 0)
|
||||
return_code = (unset(data->env, cmd->args, cmd->fd_out[0]));
|
||||
else if (ft_strcmp(cmd->executable, "echo") == 0)
|
||||
|
4
main.c
4
main.c
@ -6,7 +6,7 @@
|
||||
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
|
||||
/* Updated: 2023/04/14 16:10:20 by erey-bet ### ########.fr */
|
||||
/* Updated: 2023/04/18 12:59:43 by erey-bet ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -25,7 +25,7 @@ static char *ft_get_user_input(void)
|
||||
char *prompt;
|
||||
char *pwd;
|
||||
|
||||
pwd = get_pwd(2);
|
||||
pwd = get_pwd();
|
||||
if (pwd == NULL)
|
||||
return (NULL);
|
||||
prompt = ft_strmerger(2, pwd, "$ ");
|
||||
|
Loading…
Reference in New Issue
Block a user