-
Notifications
You must be signed in to change notification settings - Fork 1
/
commands_utils.c
100 lines (92 loc) · 1.47 KB
/
commands_utils.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
90
91
92
93
94
95
96
97
98
99
100
# include "minishell.h"
void change_pwd_env(t_source *src)
{
int i;
int b;
char *s;
int c;
c = 0;
b = 4;
i = 0;
while (src->our_envp[i] != NULL)
{
if (ft_strncmp(src->our_envp[i], "PWD=", 4) == 0)
{
s = malloc(100);
s = getcwd(s, 100);
free(src->our_envp[i]);
src->our_envp[i] = NULL;
src->our_envp[i] = ft_strjoin("PWD=", s);
free(s);
break ;
}
i++;
}
}
void set_old_env(t_source *src, char *pwd)
{
int i;
int check;
char *tmp;
i = 0;
check = 0;
while (src->our_envp[i] != NULL)
{
if (ft_strncmp(src->our_envp[i], "OLDPWD", 6) == 0)
{
check = 1;
tmp = src->our_envp[i];
src->our_envp[i] = ft_strdup(pwd);
free(tmp);
break ;
}
i++;
}
if (!check)
{
src->our_envp[src->lastenv - 1] = ft_strdup(pwd);
}
}
void set_old_pwd(t_source *src, char *pwd)
{
int i;
char *tmp;
i = 0;
while (src->export[i] != NULL)
{
if (ft_strncmp(src->export[i], "OLDPWD", 6) == 0)
{
tmp = src->export[i];
src->export[i] = ft_strjoin("OLD", pwd);
set_old_env(src, src->export[i]);
free(tmp);
break ;
}
i++;
}
}
void change_pwd_export(t_source *src)
{
int i;
int b;
int c;
char *s;
i = 0;
b = 4;
c = 0;
while (src->export[i] != NULL)
{
if (ft_strncmp(src->export[i], "PWD=", 4) == 0)
{
s = malloc(100);
s = getcwd(s, 100);
set_old_pwd(src, src->export[i]);
free(src->export[i]);
src->export[i] = NULL;
src->export[i] = ft_strjoin("PWD=", s);
free(s);
break ;
}
i++;
}
}