aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-05 20:29:27 +0100
committerRudy Bousset <rbousset@z2r4p3.le-101.fr>2020-02-05 20:29:27 +0100
commita9744a89d31759cf9d5a03beede475ff18a9bf2b (patch)
tree4792abe0a77bafafd11456d95440ff7648cec563
parentint16_tamer (diff)
download42-cub3d-a9744a89d31759cf9d5a03beede475ff18a9bf2b.tar.gz
42-cub3d-a9744a89d31759cf9d5a03beede475ff18a9bf2b.tar.bz2
42-cub3d-a9744a89d31759cf9d5a03beede475ff18a9bf2b.tar.xz
42-cub3d-a9744a89d31759cf9d5a03beede475ff18a9bf2b.tar.zst
42-cub3d-a9744a89d31759cf9d5a03beede475ff18a9bf2b.zip
Changed return values
-rw-r--r--inc/cub3d.h10
-rw-r--r--src/ft_map_error.c2
-rw-r--r--src/ft_parse_map.c6
-rw-r--r--src/main.c15
4 files changed, 25 insertions, 8 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h
index 7ea11d6..7b6cfc5 100644
--- a/inc/cub3d.h
+++ b/inc/cub3d.h
@@ -100,6 +100,16 @@ typedef struct s_cub
struct s_rgb c_rgb;
} t_cub;
+/*
+** ret vals:
+** 1: no argv[1]
+** 2: failed structs init
+** 3: failed mlx init
+** 4: map error
+** 5: no map
+** 6: not a .cub
+*/
+
t_win *ft_init_win(void);
t_cub *ft_init_cub(void);
int ft_key_event(int keycode, void *param);
diff --git a/src/ft_map_error.c b/src/ft_map_error.c
index 3413bbb..1adc34b 100644
--- a/src/ft_map_error.c
+++ b/src/ft_map_error.c
@@ -21,5 +21,5 @@ int
ft_dprintf(STDERR_FILENO, "Error\n");
ft_dprintf(STDERR_FILENO,
"\033[1;31mMap error: line %zu\033[0m\n", clist->line_chk);
- return (ft_exit(1, clist));
+ return (ft_exit(4, clist));
}
diff --git a/src/ft_parse_map.c b/src/ft_parse_map.c
index 64b590b..9112b5b 100644
--- a/src/ft_parse_map.c
+++ b/src/ft_parse_map.c
@@ -29,7 +29,7 @@ static void
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, clist);
+ ft_exit(6, clist);
}
i = 0;
while (words[i])
@@ -39,7 +39,7 @@ static void
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, clist);
+ ft_exit(6, clist);
}
ft_free_words(words);
}
@@ -107,7 +107,7 @@ void
{
ft_dprintf(STDERR_FILENO, "Error\n");
ft_dprintf(STDERR_FILENO, "\033[31;1mNo map\033[0m\n");
- ft_exit(2, clist);
+ ft_exit(5, clist);
}
ret = 1;
while (ret != 12 && ret != -1)
diff --git a/src/main.c b/src/main.c
index 5de43e5..e0a4742 100644
--- a/src/main.c
+++ b/src/main.c
@@ -14,25 +14,32 @@
#include <libft.h>
#include <mlx.h>
#include <cub3d.h>
+#include <unistd.h>
int
- main(void)
+ main(int argc, const char *argv[])
{
t_cub *clist;
+ (void)argv;
+ if (argc < 2)
+ {
+ ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mNo map selected\n\033[0m");
+ return (1);
+ }
if (!(clist = ft_init_cub()))
{
ft_memdel((void**)&clist);
- return (1);
+ return (2);
}
if (!(clist->wlist = ft_init_win()))
{
ft_memdel((void**)&clist->wlist);
ft_memdel((void**)&clist);
- return (1);
+ return (2);
}
ft_print_list(clist);
- ft_parse_map("map/map_one.cub", clist);
+ ft_parse_map(argv[1], clist);
if (ft_init_winlx(clist) < 0)
return (ft_exit(3, clist));
mlx_key_hook(clist->wlist->winptr, ft_key_event, clist);