-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_env2.c
92 lines (82 loc) · 1.23 KB
/
ft_env2.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
#include "minishell.h"
char *cat_export(char *dest, char *src)
{
int i;
int j;
char *res;
i = 0;
j = 0;
res = malloc(sizeof(char) * ft_strlen(dest) + ft_strlen(src));
while (dest[i] != '\0')
{
res[i] = dest[i];
i++;
}
while (src[j] != '\0')
{
res[i] = src[j];
i++;
j++;
}
res[i] = '\0';
return (res);
}
void env_export(char **envp, t_list *l)
{
int i;
i = 0;
while (envp[i] != NULL)
i++;
i = 0;
while (envp[i] != NULL)
{
pushfront(l, ft_strdup(envp[i]));
i++;
}
}
char *str_cat_remake(char *dest)
{
int len;
int i;
int j;
char *res;
len = ft_strlen_egal(dest) + 1;
i = 0;
j = 0;
res = malloc(sizeof(char) * ft_strlen(dest) + 3);
while (i < len)
res[i++] = dest[j++];
res[i] = '"';
i++;
while (dest[j])
res[i++] = dest[j++];
res[i] = '"';
res[++i] = '\0';
return (res);
}
void export_env_declare(t_list *l)
{
t_elem *count;
char *res;
char *tmp;
count = l->first;
res = NULL;
while (count != NULL)
{
tmp = str_cat_remake(count->data);
free_str(count->data);
res = cat_export("declare -x ", tmp);
free_str(tmp);
count->data = ft_strdup(res);
free_str(res);
count = count->next;
}
}
void ft_swap(char **a, char **b)
{
char *c;
c = NULL;
c = *a;
*a = *b;
*b = c;
}