aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_parse_map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ft_parse_map.c')
-rw-r--r--src/ft_parse_map.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index cc4d920..3ca2052 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -1,3 +1,16 @@
+/* ************************************************************************** */
+/* LE - / */
+/* / */
+/* ft_parse_map.c .:: .:/ . .:: */
+/* +:+:+ +: +: +:+:+ */
+/* By: rbousset <marvin@le-101.fr> +:+ +: +: +:+ */
+/* #+# #+ #+ #+# */
+/* Created: 2020/02/02 17:19:31 by rbousset #+# ## ## #+# */
+/* Updated: 2020/02/02 17:19:31 by rbousset ### #+. /#+ ###.fr */
+/* / */
+/* / */
+/* ************************************************************************** */
+
#include <libft.h>
#include <cub3d.h>
#include <stdlib.h>
@@ -5,7 +18,7 @@
#include <unistd.h>
static void
-ft_check_cub(const char *map_path, t_cub *clist)
+ ft_check_cub(const char *map_path, t_cub *clist)
{
char **words;
size_t i;
@@ -31,7 +44,7 @@ ft_check_cub(const char *map_path, t_cub *clist)
}
static void
-ft_check_map_last_line(t_cub *clist)
+ ft_check_map_last_line(t_cub *clist)
{
size_t i;
size_t j;
@@ -49,7 +62,7 @@ ft_check_map_last_line(t_cub *clist)
}
static int8_t
-ft_parse_it(int fd, t_cub *clist)
+ ft_parse_it(int fd, t_cub *clist)
{
char *line;
char **words;
@@ -58,33 +71,25 @@ ft_parse_it(int fd, t_cub *clist)
clist->line_chk += 1;
if ((ret = get_next_line(fd, &line)) < 0)
return (ft_map_error(clist));
- if (ret == 0)
- {
- ft_memdel((void**)&line);
- return (ft_map_error(clist));
- }
if (!line[0])
{
ft_memdel((void**)&line);
return (ft_parse_it(fd, clist));
}
- if (!(words = ft_split(line, ' ')))
+ if (ret == 0 || !ft_ischarset("RNSEWFC1\0", line[0])
+ || !(words = ft_split(line, ' ')))
{
ft_memdel((void**)&line);
return (ft_map_error(clist));
}
if ((ret = ft_select_get(words, clist)) == 12)
- {
- if (ft_get_map_first_line(line, clist) < 0)
- return (-1);
- return (12);
- }
+ return ((ft_get_map_first_line(line, clist) < 0) ? (-1) : (12));
ft_memdel((void**)&line);
return (ret);
}
void
-ft_parse_map(const char *map_path, t_cub *clist)
+ ft_parse_map(const char *map_path, t_cub *clist)
{
int fd;
int8_t ret;