aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-01-29 16:41:06 +0100
committerRudy Bousset <rbousset@z2r5p2.le-101.fr>2020-01-29 16:41:06 +0100
commite51748b78bd082d3f781930ba9eba619f0342bf6 (patch)
tree81871b5c1b6325bc20a2999e3bbd80f418973688
parentGot colors (diff)
download42-cub3d-e51748b78bd082d3f781930ba9eba619f0342bf6.tar.gz
42-cub3d-e51748b78bd082d3f781930ba9eba619f0342bf6.tar.bz2
42-cub3d-e51748b78bd082d3f781930ba9eba619f0342bf6.tar.xz
42-cub3d-e51748b78bd082d3f781930ba9eba619f0342bf6.tar.zst
42-cub3d-e51748b78bd082d3f781930ba9eba619f0342bf6.zip
Better error management
-rw-r--r--Makefile2
-rw-r--r--inc/cub3d.h9
-rw-r--r--src/ft_check_missing.c32
-rw-r--r--src/ft_get_map_redo.c12
-rw-r--r--src/ft_init_lists.c15
-rw-r--r--src/ft_parse_map.c4
6 files changed, 64 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index f167cda..817049f 100644
--- a/Makefile
+++ b/Makefile
@@ -28,6 +28,8 @@ SRCS_NAME += ft_get_tex.c
SRCS_NAME += ft_get_sprite.c
SRCS_NAME += ft_get_colors.c
# SRCS_NAME += ft_get_map.c
+SRCS_NAME += ft_get_map_redo.c
+SRCS_NAME += ft_check_missing.c
# SRCS_NAME += ft_check_empty_line.c
SRCS_NAME += ft_free_words.c
SRCS_NAME += ft_map_error.c
diff --git a/inc/cub3d.h b/inc/cub3d.h
index b33d040..60bcd58 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -25,8 +25,8 @@ typedef struct s_win
void *wlx;
void *winptr;
uint8_t inited;
- uint16_t x_size;
- uint16_t y_size;
+ int16_t x_size;
+ int16_t y_size;
} t_win;
typedef struct s_cub
@@ -60,9 +60,8 @@ 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_map(int fd, t_cub *clist);
-void ft_check_empty_line(int fd,
- unsigned int linum,
- t_cub *clist);
+int ft_check_missing(t_cub *clist);
+int ft_missing_error(const char *err, t_cub *clist);
void ft_free_words(char **words);
int ft_map_error(t_cub *clist);
int ft_init_winlx(t_cub *clist);
diff --git a/src/ft_check_missing.c b/src/ft_check_missing.c
new file mode 100644
index 0000000..ed86a32
--- /dev/null
+++ b/src/ft_check_missing.c
@@ -0,0 +1,32 @@
+#include <libft.h>
+#include <cub3d.h>
+#include <unistd.h>
+
+int
+ft_missing_error(const char *err, t_cub *clist)
+{
+ ft_dprintf(STDERR_FILENO, "Error\n");
+ ft_dprintf(STDERR_FILENO,
+ "\033[1;31mMissing element: %s\033[0m\n", err);
+ return (ft_exit(1, clist));
+}
+
+int
+ft_check_missing(t_cub *clist)
+{
+ if (!clist->no_tex_path)
+ return (ft_missing_error("north side texture", clist));
+ else if (!clist->so_tex_path)
+ return (ft_missing_error("south side texture", clist));
+ else if (!clist->ea_tex_path)
+ return (ft_missing_error("east side texture", clist));
+ else if (!clist->we_tex_path)
+ return (ft_missing_error("west side texture", clist));
+ else if (clist->wlist->x_size < 0 || clist->wlist->y_size < 0)
+ return (ft_missing_error("resolution", clist));
+ else if (clist->f_color < 0)
+ return (ft_missing_error("floor color", clist));
+ else if (clist->c_color < 0)
+ return (ft_missing_error("ceiling color", clist));
+ return (0);
+}
diff --git a/src/ft_get_map_redo.c b/src/ft_get_map_redo.c
new file mode 100644
index 0000000..9b7793b
--- /dev/null
+++ b/src/ft_get_map_redo.c
@@ -0,0 +1,12 @@
+#include <libft.h>
+#include <cub3d.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+int
+ft_get_map(int fd, t_cub *clist)
+{
+ (void)fd;
+ (void)clist;
+ return (0);
+}
diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c
index f9c5c6c..4fb5256 100644
--- a/src/ft_init_lists.c
+++ b/src/ft_init_lists.c
@@ -14,9 +14,11 @@ t_win
if (!(wlist->wlx = ft_calloc(1, 1)) ||
!(wlist->winptr = ft_calloc(1, 1)))
return (NULL);
+ wlist->wlx = NULL;
+ wlist->winptr = NULL;
wlist->inited = 0;
- wlist->x_size = 0;
- wlist->y_size = 0;
+ wlist->x_size = -1;
+ wlist->y_size = -1;
return (wlist);
}
@@ -33,8 +35,8 @@ t_cub
!(clist->we_tex_path = (char*)ft_calloc(1, sizeof(char))) ||
!(clist->sprite_path = (char*)ft_calloc(1, sizeof(char))))
return (NULL);
- clist->f_color = 0;
- clist->c_color = 0;
+ clist->f_color = -1;
+ clist->c_color = -1;
if (!(clist->map = (char**)ft_calloc(2, sizeof(char*))))
return (NULL);
if (!(clist->map[0] = (char*)ft_calloc(1, sizeof(char))))
@@ -42,5 +44,10 @@ t_cub
clist->map[1] = 0;
clist->map_w = 0;
clist->line_chk = 0;
+ clist->no_tex_path = NULL;
+ clist->so_tex_path = NULL;
+ clist->ea_tex_path = NULL;
+ clist->we_tex_path = NULL;
+ clist->sprite_path = NULL;
return (clist);
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 52c6316..0be76bc 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -91,7 +91,9 @@ ft_parse_map(const char *map_path, t_cub *clist)
ret = 1;
while (ret != 12)
ret = ft_parse_it(fd, clist);
- ft_get_map(fd, clist);
+ ft_check_missing(clist);
+ if (ft_get_map(fd, clist) < 0)
+ ft_map_error(clist);
/* if (ft_get_tex(fd, clist) < 0) */
/* return ; */
/* ft_check_empty_line(fd, 6, clist); */