This repository has been archived by the owner on Oct 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prod_set.c
55 lines (48 loc) · 1.85 KB
/
prod_set.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* prod_set.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgautier <mgautier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/11 20:15:17 by mgautier #+# #+# */
/* Updated: 2017/11/14 15:26:18 by mgautier ### ########.fr */
/* */
/* ************************************************************************** */
#include "prods_defs.h"
#include <stdlib.h>
t_bool append_to_prod(t_prod *prod, t_symbol const *type)
{
return (NULL == f_pushend_lst(&prod->sym_list, (t_symbol*)type));
}
t_bool prefix_to_prod(t_prod *prod, t_symbol const *type)
{
return (NULL != f_lstpush(type, &prod->sym_list));
}
t_prod *join_prods(t_prod const *prod_1, t_prod const *prod_2)
{
t_prod *new_prod;
t_lst *new_sym_list;
new_sym_list = lst_join(prod_1->sym_list, prod_2->sym_list);
new_prod = create_prod();
if (new_prod != NULL
&& (new_sym_list != NULL
|| (prod_1->sym_list == NULL && prod_2->sym_list == NULL)))
new_prod->sym_list = new_sym_list;
else
{
f_lstdel(&new_sym_list, no_destroy);
destroy_prod(&new_prod);
}
return (new_prod);
}
void remove_symbols_tail(t_prod *prod, size_t nb_sym)
{
while (nb_sym != 0 && NULL != f_popend_lst(&prod->sym_list))
nb_sym--;
}
void remove_symbols_head(t_prod *prod, size_t nb_sym)
{
while (nb_sym != 0 && NULL != f_lstpop(&prod->sym_list))
nb_sym--;
}