-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_pars_all.c
65 lines (58 loc) · 1.67 KB
/
ft_pars_all.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pars_all.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/03/16 12:28:39 by lbrandy #+# #+# */
/* Updated: 2021/04/02 19:23:27 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static int open_file(char *file)
{
int fd;
fd = open(file, O_RDONLY);
if (fd < 0)
{
close(fd);
fd = -1;
}
return (fd);
}
static t_list *file_read(int fd)
{
char *line;
t_list *list;
int i;
line = NULL;
list = NULL;
i = get_next_line(fd, &line);
while (i > 0)
{
ft_lstadd_back(&list, ft_lstnew(line));
i = get_next_line(fd, &line);
}
ft_lstadd_back(&list, ft_lstnew(line));
if (i < 0)
return (NULL);
return (list);
}
t_all *pars_all(char *name_of_file)
{
int fd;
t_all *all;
t_list *list;
all = (t_all *)malloc(sizeof(t_all));
if (!all)
error_handler("malloc error\n");
fd = open_file(name_of_file);
if (fd < 0)
error_handler("opening error\n");
list = file_read(fd);
if (!list)
error_handler("reading error\n");
pars_file(&list, all);
return (all);
}