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
/
sym_compute_first_test_tools.c
82 lines (74 loc) · 2.33 KB
/
sym_compute_first_test_tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* sym_compute_first_test_tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mgautier <mgautier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/01/05 18:19:51 by mgautier #+# #+# */
/* Updated: 2018/01/10 21:22:26 by mgautier ### ########.fr */
/* */
/* ************************************************************************** */
#include "sym_interface.h"
#include "test_interface.h"
#include "libft.h"
#include <stddef.h>
#include <unistd.h>
static t_bool equ(void const *str, void const *sym)
{
return (ft_strequ(str, get_name(sym)));
}
static void print(void const *sym, va_list args)
{
ft_dprintf(va_arg(args, int), "%s ", get_name(sym));
}
t_bool compute_first_sets(
t_symbol **syms, size_t nb_sym)
{
size_t index;
t_bool sym_added;
t_bool redundant;
sym_added = TRUE;
while (sym_added == TRUE)
{
index = 0;
sym_added = FALSE;
while (index < nb_sym)
{
redundant = FALSE;
compute_sym_first_set(syms[index], &sym_added);
compute_sym_first_set(syms[index], &redundant);
if (redundant)
{
ft_dprintf(STDERR_FILENO,
"Two add to first in %s\n", get_name(syms[index]));
return (FALSE);
}
index++;
}
}
return (TRUE);
}
void print_symbol_first_set(t_symbol const *sym, int const fd)
{
f_lstiter_va(get_first_set(sym), print, fd);
}
t_bool check_first_sets(
t_symbol **syms, t_lst **first_sets, size_t nb_sym)
{
size_t index;
index = 0;
while (index < nb_sym
&& lst_same_contents(first_sets[index],
get_first_set(syms[index]), equ))
index++;
if (index != nb_sym)
{
ft_dprintf(STDERR_FILENO,
"expected for symbol %s :\n", get_name(syms[index]));
print_first_set_comp(first_sets[index], STDERR_FILENO);
ft_dprintf(STDERR_FILENO, "\nresult :\n");
print_symbol_first_set((syms[index]), STDERR_FILENO);
}
return (index == nb_sym);
}