Repository navigation
Expand file tree
/
Copy pathparser.c
More file actions
executable file
·98 lines (87 loc) · 2.07 KB
/
Copy pathparser.c
File metadata and controls
executable file
·98 lines (87 loc) · 2.07 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: houlekhi <houlekhi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/01/22 17:59:22 by houlekhi #+# #+# */
/* Updated: 2015/03/04 14:05:15 by houlekhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "wolf3d.h"
int ft_tablen(char **tab)
{
int i;
i = 0;
while (tab[i])
i++;
return (i);
}
int ft_nbline_infile(char const *str, t_env *e)
{
int i;
int fd;
char *line;
i = 0;
if ((fd = open(str, O_RDONLY)) == -1)
return (-1);
while (get_next_line(fd, &line) > 0 || line[0] != '\0')
{
free(line);
i++;
}
free(line);
close(fd);
e->y_max = i;
return (i);
}
void ft_free_tab_c(char **tab)
{
int i;
i = 0;
while (tab[i])
{
free(tab[i]);
i++;
}
free(tab);
}
int *fill_line(int *line, char **tmp)
{
int j;
j = 0;
while (tmp[j])
{
line[j] = ft_atoi(tmp[j]);
j++;
}
return (line);
}
int **get_first_level(char *str, t_env *e)
{
char *line;
char **tmp;
int fd;
int i;
e->map = (int **)malloc(sizeof(int *) * ft_nbline_infile(str, e));
if (!e->map)
return (NULL);
i = 0;
if ((fd = open(str, O_RDONLY)) == -1)
return (NULL);
while (get_next_line(fd, &line) || line[0] != '\0')
{
tmp = ft_strsplit(line, ' ');
e->map[i] = (int *)malloc(sizeof(int) * ft_tablen(tmp));
if (!(e->map[i]))
return (NULL);
e->map[i] = fill_line(e->map[i], tmp);
free(line);
ft_free_tab_c(tmp);
i++;
}
free(line);
close(fd);
return (e->map);
}