-
Notifications
You must be signed in to change notification settings - Fork 0
/
expansions_dir.c
executable file
·67 lines (59 loc) · 1.08 KB
/
expansions_dir.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
#include "minishell.h"
int is_quote(char *str)
{
int len;
len = ft_strlen(str);
if (str[0] == 39)
{
if (str[len - 1] == 39)
return (1);
}
if (str[0] == '"' && str[len - 1] == '"')
return (2);
else
return (0);
}
int expand_var(char ***cmds, int i, int j, t_env *new_envp)
{
char **tmp;
tmp = *cmds;
if (tmp[i][j + 1] == '?')
tmp[i] = join_status(tmp[i], j, ft_itoa(g_status));
else if (!ft_isspace(tmp[i][j + 1]))
return (not_env(cmds, i, j, new_envp));
*cmds = tmp;
j = j + 1;
return (0);
}
char **expand_dir(char **cmds)
{
int i;
int j;
i = 0;
while (cmds[i])
{
if (!is_quote(cmds[i]))
{
j = 0;
while (cmds[i][j])
{
if (cmds[i][j] == '~')
{
if (cmds[i][j + 1] == ' ' || (!cmds[i][j + 1]))
cmds[i] = change_var(cmds[i], "", getenv("HOME"), j);
else if (cmds[i][j + 1] == '/')
cmds[i] = change_var(cmds[i], "/", getenv("HOME"), j);
}
j++;
}
}
i++;
}
return (cmds);
}
void set_oldpwd(t_env *envp)
{
char *old_pwd;
old_pwd = ft_strjoin("OLDPWD=", ft_get_env(envp->env, "PWD"));
exec_exports(old_pwd, envp);
}