summaryrefslogtreecommitdiffstats
path: root/src/b_cd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/b_cd.c')
-rw-r--r--src/b_cd.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/b_cd.c b/src/b_cd.c
index c4b5c1b..07410f8 100644
--- a/src/b_cd.c
+++ b/src/b_cd.c
@@ -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);
}