-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit_env.c
executable file
·97 lines (86 loc) · 2.2 KB
/
init_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
97
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* init_env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mazaroua <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/17 02:19:42 by mazaroua #+# #+# */
/* Updated: 2023/05/12 19:41:18 by mazaroua ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
t_export *addnew1(char *var, char *value)
{
t_export *new;
new = malloc(sizeof(t_export));
if (!new)
return (NULL);
new->var = var;
new->value = value;
new->next = NULL;
return (new);
}
void addback_export1(t_export **a, t_export *new)
{
t_export *head;
if ((*a) == NULL)
(*a) = new;
else
{
head = (*a);
new->next = NULL;
head = (*a);
while (head->next)
head = head->next;
head->next = new;
}
}
t_env_list *addnew2_1(char *var, char *value)
{
t_env_list *new;
new = malloc(sizeof(t_env_list));
if (!new)
return (NULL);
new->name = var;
new->value = value;
new->next = NULL;
return (new);
}
void addback_env2(t_env_list **a, t_env_list *new)
{
t_env_list *head;
new->next = NULL;
head = (*a);
if (head == NULL)
(*a) = new;
else
{
head = (*a);
while (head->next)
head = head->next;
head->next = new;
}
}
void init_env(t_export **export, t_env_list **env_list, char **env)
{
int i;
char **var_val;
char **var_val2;
t_export *new;
t_env_list *new1;
i = 0;
while (env && env[i])
{
var_val = split_env_var(env[i]);
var_val2 = split_env_var(env[i]);
new = addnew1(var_val[0], var_val[1]);
addback_export1(export, new);
new1 = addnew2_1(var_val2[0], var_val2[1]);
addback_env2(env_list, new1);
free(var_val);
free(var_val2);
i++;
}
sort(export);
}