Repository navigation
Expand file tree
/
Copy pathcheck_map_elements_utils.c
More file actions
92 lines (85 loc) · 2.57 KB
/
Copy pathcheck_map_elements_utils.c
File metadata and controls
92 lines (85 loc) · 2.57 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_map_elements_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaesjeon <jaesjeon@student.42seoul.kr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/03 11:56:41 by jaesjeon #+# #+# */
/* Updated: 2022/11/12 10:16:49 by jaesjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
#include "ft_string.h"
char *get_map_first_line(int fd)
{
char *line;
char *cursor;
while (TRUE)
{
line = get_next_line(fd);
if (line == NULL)
exit_with_err("invalid map", E_PERM);
cursor = line;
while (*cursor && (*cursor == NONE || *cursor == '\n'))
cursor++;
if (*cursor == '\0')
{
free(line);
continue ;
}
else if (*cursor != WALL)
exit_with_err("invalid map", E_PERM);
while (*cursor && \
(*cursor == WALL || *cursor == NONE || *cursor == '\n'))
cursor++;
if (*cursor == '\0')
return (line);
exit_with_err("invalid map", E_PERM);
}
}
t_linked_map *add_line_to_list(t_linked_map *linked_map, char *line)
{
const t_linked_map *head = linked_map;
if (linked_map == NULL)
{
linked_map = (t_linked_map *)my_malloc(sizeof(t_linked_map));
linked_map->line = line;
linked_map->next = NULL;
return (linked_map);
}
else
{
while (linked_map->next)
linked_map = linked_map->next;
linked_map->next = (t_linked_map *)my_malloc(sizeof(t_linked_map));
linked_map->next->line = line;
linked_map->next->next = NULL;
return ((t_linked_map *)head);
}
}
void linked_map_to_arr(t_linked_map *linked_map, t_info *info)
{
int x;
int y;
t_linked_map *tmp;
if (info->map_x < 3 || info->map_y < 3)
exit_with_err("invalid map", E_PERM);
info->map = (char **)my_malloc(sizeof(char *) * info->map_y);
y = 0;
while (linked_map)
{
info->map[y] = (char *)my_malloc(sizeof(char) * info->map_x);
ft_memset(info->map[y], NONE, info->map_x);
x = 0;
while (linked_map->line[x])
{
info->map[y][x] = linked_map->line[x];
x++;
}
tmp = linked_map;
linked_map = linked_map->next;
multi_free(tmp->line, tmp, NULL, NULL);
y++;
}
}