-
Notifications
You must be signed in to change notification settings - Fork 0
/
lst.c
82 lines (73 loc) · 1.89 KB
/
lst.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* lst.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cdelicia <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/26 01:02:03 by cdelicia #+# #+# */
/* Updated: 2019/11/11 00:34:58 by cdelicia ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void ft_lstclear_env(t_env **lst, void (*del)(void*))
{
t_env *list;
t_env *next;
if (lst == NULL)
return ;
list = *lst;
while (list != NULL)
{
next = list->next;
del(list->key);
del(list->value);
free(list);
list = next;
}
*lst = NULL;
}
void ft_lstclear_cmd(t_cmd_list **lst, void (*del)(void*))
{
t_cmd_list *list;
t_cmd_list *next;
if (lst == NULL)
return ;
list = *lst;
while (list != NULL)
{
next = list->next;
del(list->content);
free(list);
list = next;
}
*lst = NULL;
}
void clear_parced_env_list(t_main *main)
{
if (main->env)
ft_lstclear_env(&main->env, free);
main->env = NULL;
}
void clear_parced_cmd_list(t_main *main)
{
if (main->list)
ft_lstclear_cmd(&main->list, free);
main->list = NULL;
}
void ft_cmd_lstadd_back(t_cmd_list **lst, t_cmd_list *new)
{
t_cmd_list *tmp;
if (lst == NULL)
return ;
if (*lst == NULL)
*lst = new;
else
{
tmp = *lst;
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = new;
new->prev = tmp;
}
}