aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--inc/cub3d.h2
-rw-r--r--src/ft_get_map_redo.c48
-rw-r--r--src/ft_parse_map.c25
3 files changed, 69 insertions, 6 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 60bcd58..01dcd76 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -41,6 +41,7 @@ typedef struct s_cub
char **map;
size_t map_w;
size_t line_chk;
+ uint8_t nsew;
struct s_win *wlist;
} t_cub;
@@ -59,6 +60,7 @@ int ft_get_tex_we(char **words, t_cub *clist);
int ft_get_sprite(char **words, t_cub *clist);
int ft_get_f_color(char **words, t_cub *clist);
int ft_get_c_color(char **words, t_cub *clist);
+int ft_get_first_line(char *line, t_cub *clist);
int ft_get_map(int fd, t_cub *clist);
int ft_check_missing(t_cub *clist);
int ft_missing_error(const char *err, t_cub *clist);
diff --git a/src/ft_get_map_redo.c b/src/ft_get_map_redo.c
index 9b7793b..004dd3d 100644
--- a/src/ft_get_map_redo.c
+++ b/src/ft_get_map_redo.c
@@ -3,10 +3,58 @@
#include <stddef.h>
#include <stdlib.h>
+static int8_t
+ft_check_line(char *line, uint8_t l, t_cub *clist)
+{
+ size_t i;
+
+ i = 0;
+ while (line[i])
+ {
+ if (l != 1)
+ {
+ if (!ft_ischarset("012NSEW ", line[i]))
+ return (-1);
+ if (ft_ischarset("NSEW", line[i]))
+ clist->nsew += 1;
+ if (clist->nsew > 1)
+ return (-1);
+ }
+ else
+ {
+ if (!ft_ischarset("1 ", line[i]))
+ return (-1);
+ }
+ i++;
+ }
+ if (line[0] != '1' || line[i - 1] != '1')
+ return (-1);
+ return (0);
+}
+
+int
+ft_get_first_line(char *line, t_cub *clist)
+{
+ if (!line[0])
+ {
+ ft_memdel(line);
+ return (-1);
+ }
+ if (ft_check_line(line, 1, clist) < 0)
+ {
+ ft_memdel(line);
+ return (-1);
+ }
+ return (1);
+}
+
int
ft_get_map(int fd, t_cub *clist)
{
+ int ret;
+
(void)fd;
+ (void)ret;
(void)clist;
return (0);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 0be76bc..af11e2f 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -48,14 +48,17 @@ ft_check_cub(const char *map_path, t_cub *clist)
/* } */
/* } */
-static int
+static int8_t
ft_parse_it(int fd, t_cub *clist)
{
char *line;
char **words;
+ int ret;
clist->line_chk += 1;
- if (get_next_line(fd, &line) <= 0)
+ if ((ret = get_next_line(fd, &line)) < 0)
+ return (ft_map_error(clist));
+ if (ret == 0)
{
ft_memdel(line);
return (ft_map_error(clist));
@@ -70,15 +73,22 @@ ft_parse_it(int fd, t_cub *clist)
ft_memdel(line);
return (ft_map_error(clist));
}
+ ft_printf("%s\n", line);
+ if ((ret = ft_select_get(words, clist)) == 12)
+ {
+ if (ft_get_first_line(line, clist) < 0)
+ return (-1);
+ return (12);
+ }
ft_memdel(line);
- return (ft_select_get(words, clist));
+ return (ret);
}
void
ft_parse_map(const char *map_path, t_cub *clist)
{
int fd;
- uint8_t ret;
+ int8_t ret;
ft_check_cub(map_path, clist);
fd = open(map_path, O_RDONLY);
@@ -89,11 +99,14 @@ ft_parse_map(const char *map_path, t_cub *clist)
ft_exit(2, clist);
}
ret = 1;
- while (ret != 12)
+ while (ret != 12 && ret != -1)
ret = ft_parse_it(fd, clist);
- ft_check_missing(clist);
+ if (ret == -1)
+ ft_map_error(clist);
+ clist->nsew = 0;
if (ft_get_map(fd, clist) < 0)
ft_map_error(clist);
+ ft_check_missing(clist);
/* if (ft_get_tex(fd, clist) < 0) */
/* return ; */
/* ft_check_empty_line(fd, 6, clist); */