-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_env.c
96 lines (86 loc) · 1.46 KB
/
ft_env.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
#include "minishell.h"
int get_pos_env(t_list *l, char *env)
{
t_elem *count;
int i;
count = l->first;
i = 0;
while (count != NULL)
{
if (ft_strncmp(count->data, env, ft_strlen_egal(count->data)) == 0
&& ft_strncmp(count->data, env, ft_strlen_egal(env)) == 0)
return (i);
count = count->next;
i++;
}
return (-1);
}
int get_pos_env_exp(t_list *exp, char *str)
{
t_elem *count;
int i;
char *tmp;
count = exp->first;
i = 0;
tmp = ft_strjoin("declare -x ", str);
while (count != NULL)
{
if (ft_strncmp(count->data, tmp, ft_strlen_egal(tmp)) == 0
&& ft_strncmp(count->data, tmp, ft_strlen_egal(count->data)) == 0)
{
free_str(tmp);
return (i);
}
count = count->next;
i++;
}
free_str(tmp);
return (-1);
}
void fill_env(t_struct *d, char **envp)
{
int i;
i = 0;
while (envp[i] != NULL)
i++;
d->env = malloc(sizeof(char *) * i + 1);
i = 0;
while (envp[i] != NULL)
{
d->env[i] = ft_strdup(envp[i]);
i++;
}
d->env[i] = NULL;
}
void fill_env_struct(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++;
}
}
int is_in_env(t_list *l, char *str)
{
int i;
int j;
t_elem *count;
count = l->first;
i = ft_strlen_egal(str);
while (count != NULL)
{
if (ft_strncmp(str, count->data, ft_strlen_egal(str)) == 0)
{
j = ft_strlen_egal(count->data);
if (i == j)
return (1);
}
count = count->next;
}
return (0);
}