-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
59 lines (55 loc) · 1.02 KB
/
main.c
File metadata and controls
59 lines (55 loc) · 1.02 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
59
#include "fillit.h"
void error_message(void)
{
ft_putstr("error\n");
exit(1);
}
void free_list(t_lst *list)
{
list->current = list->head;
while (list->current)
{
free(list->current);
list->current = list->current->next;
}
list->current = NULL;
free(list);
list = NULL;
}
int main(int argc, char **argv)
{
t_lst *list;
t_map *map;
int size;
int solved;
int fd;
solved = 0;
if (!(list = (t_lst *)malloc(sizeof(t_lst))))
return (0);
if (!(list->current = (t_tet *)malloc(sizeof(t_tet))))
return (0);
if (!(list->head = (t_tet *)malloc(sizeof(t_tet))))
return (0);
map = NULL;
if (argc == 2)
{
fd = open(argv[1], O_RDONLY);
if (fd > 0)
list = read_in(fd, 'A', list, NULL);
if (!list->size)
error_message();
size = ceil_sqrt(list->size);
map = new_map(size);
list->current = list->head;
while (!solve(list->head, map) && list->current != NULL)
{
list->current = list->head;
map = new_map(size++);
}
print_map(map);
close(fd);
}
free_map(map);
free_list(list);
return (0);
}