From a9744a89d31759cf9d5a03beede475ff18a9bf2b Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 5 Feb 2020 20:29:27 +0100 Subject: Changed return values --- inc/cub3d.h | 10 ++++++++++ src/ft_map_error.c | 2 +- src/ft_parse_map.c | 6 +++--- src/main.c | 15 +++++++++++---- 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 #include #include +#include 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); -- cgit v1.2.3