mirror of
https://github.com/KeyZox71/ft_minipowershell.git
synced 2025-03-15 03:16:51 +01:00
「🏗️」 wip: CD reworked
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/22 13:05:18 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/25 10:46:04 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/25 11:30:49 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
# define PATH_MAX_LEN 4096
|
||||
|
||||
void ft_pwd(t_env *env);
|
||||
void ft_pwd(void);
|
||||
void ft_cd(t_env *env, char *args);
|
||||
char *ret_cwd(void);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/22 15:07:24 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/25 11:22:08 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/25 13:47:17 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,7 +19,7 @@ char *__get_parent_directory(char *pwd)
|
||||
{
|
||||
char *tmp;
|
||||
char *dir;
|
||||
char *parent;
|
||||
//char *parent;
|
||||
|
||||
tmp = pwd;
|
||||
while (*tmp)
|
||||
@ -28,9 +28,27 @@ char *__get_parent_directory(char *pwd)
|
||||
dir = tmp;
|
||||
tmp++;
|
||||
}
|
||||
parent = ft_calloc(dir - pwd + 1, sizeof(char));
|
||||
ft_strlcpy(parent, pwd, dir - pwd + 1);
|
||||
return (parent);
|
||||
//parent = ft_calloc(dir - pwd + 1, sizeof(char));
|
||||
ft_strlcpy(pwd, pwd, dir - pwd + 1);
|
||||
return (pwd);
|
||||
}
|
||||
|
||||
char *__relative_path(char *args, char *pwd)
|
||||
{
|
||||
char **path;
|
||||
char **tmp;
|
||||
char *new_path;
|
||||
|
||||
path = ft_split(args, '/');
|
||||
tmp = path;
|
||||
new_path = pwd;
|
||||
while (*tmp)
|
||||
{
|
||||
if (is_str(*tmp, ".."))
|
||||
new_path = __get_parent_directory(new_path);
|
||||
tmp++;
|
||||
}
|
||||
return (new_path);
|
||||
}
|
||||
|
||||
void ft_cd(t_env *env, char *args)
|
||||
@ -47,7 +65,7 @@ void ft_cd(t_env *env, char *args)
|
||||
new_pwd = env_get_value("HOME", env);
|
||||
else if (args[0] == '/')
|
||||
new_pwd = ft_strdup(args);
|
||||
else if (is_str(args, ".."))
|
||||
else
|
||||
new_pwd = __get_parent_directory(pwd);
|
||||
ft_putendl_fd(new_pwd, STDOUT_FILENO);
|
||||
ret = chdir(new_pwd);
|
||||
|
@ -6,19 +6,19 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/06/22 13:02:02 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/24 12:33:50 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/25 11:31:15 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "env.h"
|
||||
#include "libft.h"
|
||||
#include "builtins.h"
|
||||
|
||||
void ft_pwd(t_env *env)
|
||||
void ft_pwd(void)
|
||||
{
|
||||
char *pwd;
|
||||
|
||||
pwd = env_get_value("PWD", env);
|
||||
pwd = ret_cwd();
|
||||
ft_putendl_fd(pwd, STDOUT_FILENO);
|
||||
free(pwd);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/04/24 11:18:04 by adjoly #+# #+# */
|
||||
/* Updated: 2024/06/24 12:47:08 by adjoly ### ########.fr */
|
||||
/* Updated: 2024/06/25 11:31:25 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -89,7 +89,7 @@ int main(int ac, char **av, char **env)
|
||||
break ;
|
||||
if (is_str(test, "pwd"))
|
||||
{
|
||||
ft_pwd(&env_l);
|
||||
ft_pwd();
|
||||
continue ;
|
||||
}
|
||||
if (is_str(test, "cd"))
|
||||
|
Reference in New Issue
Block a user