-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_operator.c
62 lines (59 loc) · 1.79 KB
/
list_operator.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_operator.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jemartel <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/15 02:42:10 by jemartel #+# #+# */
/* Updated: 2022/02/01 15:55:00 by jemartel ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
//Cette fonction ajoute un nouvelle element a la liste "export"
char **add_to_list(char *new_exprt, char **old_list, int type)
{
char **new_list;
int i;
new_list = NULL;
new_list = malloc(sizeof(char *) * (ft_tab_len(old_list) + 2));
i = 0;
while (old_list[i])
{
new_list[i] = ft_strdup(old_list[i]);
i++;
}
new_list[i] = ft_strdup(new_exprt);
i++;
new_list[i] = NULL;
freelist(old_list);
if (type)
return (ft_sort_tab(new_list));
return (new_list);
}
char **remove_of_list(char *to_remove, char **old_list)
{
char **new_list;
int i;
int j;
new_list = NULL;
new_list = malloc(sizeof(char **) * (ft_tab_len(old_list) + 1));
i = 0;
j = 0;
while (old_list[i])
{
if (!ft_strncmp(old_list[i], to_remove, ft_strlen(to_remove)))
{
i++;
}
else
{
new_list[j] = ft_strdup(old_list[i]);
i++;
j++;
}
}
new_list[j] = NULL;
freelist(old_list);
return (new_list);
}