-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildin_cd2.c
89 lines (79 loc) · 2.22 KB
/
buildin_cd2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buildin_cd2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/14 09:54:48 by ggiannit #+# #+# */
/* Updated: 2023/04/14 09:55:18 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_slash(t_mish *meta)
{
ft_free((void **) &(meta->olddir));
meta->olddir = ft_strdup(meta->curdir);
ft_free((void **) &(meta->curdir));
meta->curdir = ft_strdup("/");
}
void ft_next_slash(t_mish *meta, char *str)
{
int j;
int k;
char *cwd;
j = 0;
k = 0;
cwd = NULL;
cwd = ft_strdup(meta->curdir);
ft_free((void **) &(meta->curdir));
meta->curdir = (char *) ft_calloc (ft_strlen(cwd)
+ ft_strlen(str) + 1, sizeof(char));
if (cwd[1] != '\0')
meta->curdir[j++] = '/';
while (str[k] && str[k] != '/')
meta->curdir[j++] = str[k++];
meta->curdir = ft_strjoin_free(cwd, meta->curdir);
}
int len_slash(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == '/')
return (i);
i++;
}
return (i);
}
int ft_pre_slash(t_mish *meta, t_cmd *node)
{
int i;
i = 0;
ft_free((void **) &(meta->olddir));
meta->olddir = ft_strdup(meta->curdir);
if (!ft_strncmp(&node->pot[1][i], "..", 2)
|| !ft_strncmp(&node->pot[1][i], "../", 3))
{
ft_find_path(meta->home_path, &i);
chdir(&meta->home_path[i]);
ft_cd_pre(meta);
i = 3;
}
ft_pre_slash_2(meta, node, i);
return (1);
}
void ft_cd_slash2(t_mish *meta, t_cmd *node)
{
int i;
int k;
i = 1;
k = 0;
ft_slash(meta);
while (node->pot[1][i] && !ft_isalpha(node->pot[1][i])
&& !ft_isdigit(node->pot[1][i]))
i++;
i--;
ft_cd_slash2_2(meta, node, i, k);
}