-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildin_unset.c
58 lines (53 loc) · 1.66 KB
/
buildin_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* buildin_unset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ggiannit <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/13 19:27:21 by ggiannit #+# #+# */
/* Updated: 2023/04/17 21:57:00 by ggiannit ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_unset_list(t_mish *meta, t_cmd *node)
{
int k;
t_exenv *ino;
k = 0;
while (node->pot[++k])
{
ino = meta->ext_env;
while (ino)
{
if (!ft_strncmp(ino->key, node->pot[k],
ft_findchar(node->pot[k], '='))
&& !ft_strncmp(ino->key, node->pot[k], ft_strlen(ino->key)))
{
ft_free((void **) &(ino->key));
ft_free((void **) &(ino->value));
break ;
}
ino = ino->next;
}
}
}
void ft_unset(t_mish *meta, t_cmd *node)
{
int i;
int j;
int len;
i = -1;
while (meta->env[++i])
{
j = 0;
while (node->pot[++j])
{
len = ft_strlen(node->pot[j]);
if (!ft_strncmp(meta->env[i], node->pot[j], len))
if (meta->env[i][len] == '=')
meta->env = ft_matrixdel(meta->env, node->pot[j]);
}
}
ft_unset_list(meta, node);
}