-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_map.c
More file actions
69 lines (62 loc) · 1.62 KB
/
Copy pathmake_map.c
File metadata and controls
69 lines (62 loc) · 1.62 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* make_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rovillar <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/06 18:13:46 by rovillar #+# #+# */
/* Updated: 2022/05/25 17:56:13 by rovillar ### ########.fr */
/* */
/* ************************************************************************** */
#include "so_long.h"
static void check_map_rl(char *str)
{
int i;
i = 0;
while (str[i])
{
if (str[i] == '\n' && str[i + 1] == '\n')
{
ft_printf("ERROR RETURN LINE\n");
free(str);
exit(1);
}
i++;
}
}
static char *convert_map(char **map)
{
int fd;
char *str;
char *line;
fd = open(*map, O_RDONLY);
str = ft_strdup("");
if (fd < 0)
return (0);
line = get_next_line(fd);
if (!line)
return (0);
while (line)
{
str = ft_strjoin(str, line);
if (!str)
return (0);
free(line);
line = get_next_line(fd);
}
return (str);
}
char **make_map(char **av)
{
char *str;
char **map;
str = convert_map(av);
check_map_rl(str);
map = ft_split(str, '\n');
if (!map)
return (0);
free(str);
check_map(map);
return (map);
}