aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ft_get_tex.c3
-rw-r--r--src/ft_init_lists.c3
-rw-r--r--src/ft_init_winlx.c2
-rw-r--r--src/ft_parse_map.c29
-rw-r--r--src/main.c2
5 files changed, 37 insertions, 2 deletions
diff --git a/src/ft_get_tex.c b/src/ft_get_tex.c
index 65c8441..6bd2b7c 100644
--- a/src/ft_get_tex.c
+++ b/src/ft_get_tex.c
@@ -14,7 +14,10 @@ ft_get_tex_no(int fd, t_win *wlist)
return (ft_exit(5, wlist));
if (!(*words) || ft_strcmp(*words, "NO")
|| !(*(words + 1)) || (*(words + 2)))
+ {
+ ft_free_words(words);
return (ft_map_error(2, wlist));
+ }
ft_memdel(wlist->clist->no_tex_path);
len = ft_strlen(*(words + 1));
if (!(wlist->clist->no_tex_path = (char*)malloc((len + 1) * sizeof(char))))
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index 4aa2d81..799204b 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -11,6 +11,9 @@ t_win
if (!(wlist = (t_win*)malloc(sizeof(t_win))))
return (NULL);
+ if (!(wlist->wlx = ft_calloc(1, 1)) ||
+ !(wlist->winptr = ft_calloc(1, 1)))
+ return (NULL);
return (wlist);
}
diff --git a/src/ft_init_winlx.c b/src/ft_init_winlx.c
index 0e272fd..a4b7208 100644
--- a/src/ft_init_winlx.c
+++ b/src/ft_init_winlx.c
@@ -6,8 +6,10 @@
int
ft_init_winlx(t_win *wlist)
{
+ ft_memdel(wlist->wlx);
if (!(wlist->wlx = mlx_init()))
return (-1);
+ ft_memdel(wlist->winptr);
if (!(wlist->winptr = (void*)malloc(wlist->x_size * wlist->y_size)))
return (-1);
if (!(wlist->winptr = mlx_new_window(wlist->wlx, wlist->x_size,\
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index f4eb4f0..0a4aa45 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -4,15 +4,42 @@
#include <fcntl.h>
#include <unistd.h>
+static void
+ft_check_cub(const char *map_path, t_win *wlist)
+{
+ char **words;
+ size_t i;
+
+ if (!(words = ft_split(map_path, '.')))
+ {
+ ft_dprintf(STDERR_FILENO, "Error\n");
+ ft_dprintf(STDERR_FILENO, "\033[31;1mMap is not a .cub\033[0m\n");
+ ft_free_words(words);
+ ft_exit(2, wlist);
+ }
+ i = 0;
+ while (words[i])
+ i++;
+ if (ft_strcmp(words[i - 1], "cub"))
+ {
+ ft_dprintf(STDERR_FILENO, "Error\n");
+ ft_dprintf(STDERR_FILENO, "\033[31;1mMap is not a .cub\033[0m\n");
+ ft_free_words(words);
+ ft_exit(2, wlist);
+ }
+ ft_free_words(words);
+}
+
/*
** I can't close fd
*/
void
-ft_parse_map(t_win *wlist, const char *map_path)
+ft_parse_map(const char *map_path, t_win *wlist)
{
int fd;
+ ft_check_cub(map_path, wlist);
fd = open(map_path, O_RDONLY);
if (fd < 0)
{
diff --git a/src/main.c b/src/main.c
index b47b36f..0f2c93c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,7 +15,7 @@ int
ft_memdel(wlist);
return (1);
}
- ft_parse_map(wlist, "map/map_one.cub");
+ ft_parse_map("map/map_two.cub", wlist);
if (ft_init_winlx(wlist) < 0)
return (ft_exit(3, wlist));
mlx_key_hook(wlist->winptr, ft_key_event, wlist);