-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_remove.c
More file actions
58 lines (53 loc) · 1.57 KB
/
ft_remove.c
File metadata and controls
58 lines (53 loc) · 1.57 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_remove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sid-bell <sid-bell@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/26 19:56:51 by sid-bell #+# #+# */
/* Updated: 2019/04/28 15:41:28 by sid-bell ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_select.h"
static void ft_delete(t_params *params, t_list *list, t_list **new, int i)
{
t_elem *elem;
t_list *node;
if (i == params->pos)
{
params->pos = params->pos > 1 ? params->pos - 1 : 1;
elem = (t_elem *)list->content;
free(elem->name);
free(elem);
}
else
{
node = ft_lstnew(NULL, 0);
node->content = list->content;
ft_lstadd(new, node);
}
}
void ft_remove(t_params *params)
{
t_list *list;
t_list *new;
t_list *tmp;
int i;
i = 1;
new = NULL;
list = params->list;
if (ft_init_draw(params))
return ;
while (list)
{
ft_delete(params, list, &new, i);
i++;
tmp = list;
list = list->next;
free(tmp);
}
if (!new)
ft_exit(params);
params->list = new;
}