-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv.c
81 lines (71 loc) · 1.82 KB
/
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hchairi <hchairi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/27 12:20:01 by hchairi #+# #+# */
/* Updated: 2023/07/22 15:08:02 by hchairi ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void lstclear_env(void)
{
t_env *tmp;
t_env *tmp_next;
if (!g_all.env)
return ;
tmp = g_all.env;
while (tmp)
{
tmp_next = tmp->next;
free (tmp->s);
free (tmp);
tmp = tmp_next;
}
g_all.env = NULL;
}
t_env *ft_lstnew(char *content)
{
t_env *node;
node = malloc(sizeof(t_env));
if (!node)
return (NULL);
node->s = ft_strdup(content);
node->next = NULL;
return (node);
}
t_nodes *lstnew_expand(char *content)
{
t_nodes *node;
node = malloc(sizeof(t_nodes));
if (!node)
return (NULL);
node->type = EXPANDED;
node->quotes = 0;
node->valeur = ft_strdup(content);
node->next = NULL;
return (node);
}
void lstaddback_env(t_env **node, t_env *new)
{
if (*node == NULL)
{
*node = new;
return ;
}
while ((*node)->next)
node = &(*node)->next;
(*node)->next = new;
}
void save_env(t_env **node, char **envr)
{
int i;
i = 0;
while (envr[i])
{
lstaddback_env(node, ft_lstnew(envr[i]));
i++;
}
}