-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
85 lines (78 loc) · 1.8 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
75
76
77
78
79
80
81
82
83
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tduval <tduval@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/18 02:30:48 by tduval #+# #+# */
/* Updated: 2018/11/24 03:19:38 by tduval ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <fcntl.h>
#include "fillit.h"
static void free_all(char **map, char ***tetri)
{
int i;
int j;
i = 0;
j = 0;
while (map[i])
{
free(map[i]);
i++;
}
free(map);
i = 0;
while (tetri[i])
{
j = 0;
while (j < 4)
{
free(tetri[i][j]);
j++;
}
free(tetri[i]);
i++;
}
free(tetri);
}
static int print_all(char ***tetri)
{
int i;
char **map;
map = 0;
i = 0;
sort_tetri(tetri);
if (!(map = create_map(tetri, map)))
return (0);
if (!(map = fill_map(tetri, map)))
return (0);
print_map(map);
free_all(map, tetri);
return (1);
}
int main(int ac, char **av)
{
char ***tetri;
int i;
int fd;
tetri = 0;
fd = open(av[1], O_RDONLY);
if (ac == 2 && fd != -1)
{
if ((tetri = read_tetri(fd)))
{
if (!(print_all(tetri)))
ft_putstr("error\n");
}
else
ft_putstr("error\n");
}
else
ft_putstr("usage: ./fillit description_file\n");
i = 0;
close(fd);
return (0);
}