diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-04 17:54:15 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-08-04 17:54:15 +0200 |
commit | f2924d712bfb49037763f232e0132d78334f4219 (patch) | |
tree | c184b2cd238c53b0293f29f69ed948931035ed59 /src/b_cd.c | |
parent | Added -P to cwd (diff) | |
download | 42-minishell-f2924d712bfb49037763f232e0132d78334f4219.tar.gz 42-minishell-f2924d712bfb49037763f232e0132d78334f4219.tar.bz2 42-minishell-f2924d712bfb49037763f232e0132d78334f4219.tar.xz 42-minishell-f2924d712bfb49037763f232e0132d78334f4219.tar.zst 42-minishell-f2924d712bfb49037763f232e0132d78334f4219.zip |
FeelsGoodMan
Diffstat (limited to 'src/b_cd.c')
-rw-r--r-- | src/b_cd.c | 45 |
1 files changed, 45 insertions, 0 deletions
@@ -19,6 +19,7 @@ #include "s_struct.h" #include "u_utils.h" #include "u_vars.h" +#include "u_vars_next.h" static void set_path(char **path, @@ -41,6 +42,49 @@ static void } } +static void + b_upgrade_pwd(const char path[], t_msh *msh) +{ + char **splited; + char *rtmp; + char repath[131072]; + size_t i; + size_t j; + + if (path[0] == '/') + { + u_subst_var_value("$PWD", path, msh); + /* TODO: /home///////////////////////////////////jozan////////////// */ + return ; + } + rtmp = u_get_var_value("$PWD", msh); + ft_memcpy(repath, rtmp, ft_strlen(rtmp) + 1); + ft_memdel((void*)&rtmp); + splited = ft_split(path, '/'); + i = 0; + while (splited[i] != '\0') + { + ft_printf("{%s}\n{%s}\n", path, path + i); + if (splited[i][0] == '.' && splited[i][1] == '.') + { + j = ft_strlen(repath); + ft_printf("[%s]\n", repath); + while (repath[j] != '/') + j--; + repath[j] = '\0'; + } + else + { + j = ft_strlen(repath) + 1; + repath[j - 1] = '/'; + ft_strlcpy(repath + j, splited[i], ft_strlen(splited[i]) + 1); + } + i++; + } + ft_delwords(splited); + u_subst_var_value("$PWD", repath, msh); +} + uint8_t b_cd(char *args[], t_msh *msh) @@ -66,6 +110,7 @@ uint8_t ft_memdel((void*)&path); return (1); } + b_upgrade_pwd(path, msh); ft_memdel((void*)&path); return (0); } |