-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_exp_unset.c
86 lines (78 loc) · 1.75 KB
/
ft_exp_unset.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
#include "minishell.h"
void built_in_export(t_struct *d, t_list *l, t_list *exp)
{
int i;
int j;
t_elem *count;
count = l->first;
d->l.str1 = NULL;
i = 1;
j = -1;
while (d->l.arg[i])
{
if (isin('=', d->l.arg[i]) == 1)
built_in_export_10(d, l, count, i);
i++;
}
built_in_export_2(d, exp);
}
void built_in_export_4(t_struct *d, int i)
{
printf("bash: export: `%s': not a valid identifier\n", d->l.arg[i]);
g_global.g_build_error_exec = 1;
}
void built_in_export_3(t_struct *d, t_list *l, t_elem *count, int i)
{
built_in_export_6(d, l, count, i);
if (isin('\"', d->l.arg[i]) == 1)
{
d->l.str1 = ft_strtrim(d->l.arg[i], "\"");
pushfront_one(l, d->l.str1);
}
else if (isin('\'', d->l.arg[i]) == 1)
{
d->l.str1 = ft_strtrim(d->l.arg[i], "\'");
pushfront_one(l, d->l.str1);
}
else if (is_char_c(d->l.arg[i][0]) == 0)
built_in_export_4(d, i);
else if (get_pos_env(l, d->l.arg[i]) == -1)
pushfront_one(l, ft_strdup(d->l.arg[i]));
}
void built_in_export_1(t_struct *d, t_list *l, t_elem *count, int i)
{
int j;
int k;
j = -1;
d->l.str1 = del_plus_egal(d->l.arg[i]);
if (is_in_env(l, d->l.str1) == 1)
{
k = get_pos_env(l, d->l.str1);
while (++j < k)
count = count->next;
free_str(d->l.str1);
d->l.str1 = ft_substr(d->l.arg[i], d->l.pos + 1,
ft_strlen(d->l.arg[i]));
d->l.tmp = ft_strdup(count->data);
free_str(count->data);
count->data = cat_export(d->l.tmp, d->l.str1);
free_str(d->l.str1);
free_str(d->l.tmp);
}
else if (is_char_c(d->l.arg[i][0]) == 0)
built_in_export_4(d, i);
else
pushfront_one(l, d->l.str1);
}
void built_in_export_2(t_struct *d, t_list *exp)
{
int i;
i = 1;
d->l.str1 = NULL;
while (d->l.arg[i])
{
if (isin('=', d->l.arg[i]) == 0)
built_in_export_11(d, exp, i);
i++;
}
}