-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
74 lines (67 loc) · 1.99 KB
/
main.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: staeter <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/12/05 15:25:20 by staeter #+# #+# */
/* Updated: 2019/01/12 13:41:57 by nraziano ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
static int usage(const char *s)
{
write(1, "Usage:\t", 7);
ft_putstr(s);
write(1, " req_filename\n", 14);
return (0);
}
static int error(char **imp, t_grid **g)
{
free(*imp);
*imp = NULL;
free_grid(g);
write(1, "error\n", 6);
return (1);
}
static void valid_gsize_sub(t_grid *g, t_node *n)
{
if (!n)
return ;
if (g->gsize == 2 && (n->te->tab[0] != 3 || n->te->tab[1] != 3))
g->gsize = 3;
if (g->gsize == 3 && ((
n->te->tab[0] == 1 &&
n->te->tab[1] == 1 &&
n->te->tab[2] == 1 &&
n->te->tab[3] == 1) || (n->te->tab[0] == 15)))
g->gsize = 4;
valid_gsize_sub(g, n->next);
}
static void valid_gsize(t_grid *g)
{
if (g->gsize <= 3)
valid_gsize_sub(g, g->incr);
}
int main(int argc, char const *argv[])
{
char *imp;
t_grid *g;
short a;
if (argc != 2)
return (usage(argv[0]));
if (!(imp = file_reader(argv[1])) ||
!(g = new_grid(0)) ||
!(g->incr = get_tetrilist(imp)))
return (error(&imp, &g));
free(imp);
a = len_tetrilist(g->incr) * 4;
g->gsize = ft_sqrt(a);
valid_gsize(g);
g->maxgap = ft_pow(g->gsize, 2) - a;
backtrack(g);
print_grid(g);
free_grid(&g);
return (0);
}