From 459016417094600407756ebe7d387cdc5e4ca6d2 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Sun, 1 Mar 2020 22:54:56 +0100 Subject: Norme --- Makefile | 1 + inc/cub3d.h | 6 ++++++ src/ft_treat_args.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 29 ++++------------------------- 4 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 src/ft_treat_args.c diff --git a/Makefile b/Makefile index 4e155d4..87f9309 100644 --- a/Makefile +++ b/Makefile @@ -67,6 +67,7 @@ SRCS_NAME += ft_music.c SRCS_NAME += ft_draw_sprite.c SRCS_NAME += ft_warp_level.c SRCS_NAME += ft_save_to_bmp.c +SRCS_NAME += ft_treat_args.c #--------------------------------------------------------------------------------------------------# SRCS = $(addprefix ${SRCS_DIR},${SRCS_NAME}) #--------------------------------------------------------------------------------------------------# diff --git a/inc/cub3d.h b/inc/cub3d.h index 739972e..0b3e21c 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -113,5 +113,11 @@ int8_t ft_warp_level(t_cub *cl); int ft_exit(uint8_t exit_code, t_cub *clist); uint32_t ft_rgb_to_hex(t_rgb rgb); +/* +** ====== ARGS ====== +*/ + +uint8_t ft_check_map_arg(int argc, const char *argv[]); +uint8_t ft_use_args(int argc, const char *argv[], t_cub *clist); # endif diff --git a/src/ft_treat_args.c b/src/ft_treat_args.c new file mode 100644 index 0000000..fae81a0 --- /dev/null +++ b/src/ft_treat_args.c @@ -0,0 +1,52 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_treat_args.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:29:00 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:29:08 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include + +uint8_t + ft_check_map_arg(int argc, const char *argv[]) +{ + (void)argv; + if (argc < 2) + { + ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mNo map selected\n\033[0m"); + return (FT_RET_BAD_ARGV); + } + return (0); +} + +uint8_t + ft_use_args(int argc, const char *argv[], t_cub *clist) +{ + if (argc < 3) + { + if (ft_init_winptr(clist) < 0) + return (ft_exit(FT_RET_FAILED_MLX, clist)); + ft_draw_scene(clist); + ft_hooks_and_loops(clist->wlist, clist); + /* ft_music(clist); */ + } + else if (argc == 3 && !ft_strncmp("--save", argv[2], 7)) + { + ft_draw_scene_bmp(clist); + return (ft_exit(FT_RET_FINE, clist)); + } + else + { + ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mBad arguments\n\033[0m"); + return (ft_exit(FT_RET_BAD_ARGV, clist)); + } + return (FT_RET_FINE); +} diff --git a/src/main.c b/src/main.c index 3585626..74c9b45 100644 --- a/src/main.c +++ b/src/main.c @@ -13,42 +13,21 @@ #include #include #include -#include -#include int main(int argc, const char *argv[]) { t_cub *clist; - if (argc < 2) - { - ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mNo map selected\n\033[0m"); + if (ft_check_map_arg(argc, argv) == FT_RET_BAD_ARGV) return (FT_RET_BAD_ARGV); - } if (ft_init_cub3d(&clist) < 0) return (FT_RET_FAILED_STRUCTS); ft_parse_map(argv[1], clist); if (ft_init_winlx(clist) < 0) return (ft_exit(FT_RET_FAILED_MLX, clist)); ft_wall_tex_init(clist); - if (argc < 3) - { - if (ft_init_winptr(clist) < 0) - return (ft_exit(FT_RET_FAILED_MLX, clist)); - ft_draw_scene(clist); - ft_hooks_and_loops(clist->wlist, clist); - } - else if (argc == 3 && !ft_strncmp("--save", argv[2], 7)) - { - ft_draw_scene_bmp(clist); - return (ft_exit(FT_RET_FINE, clist)); - } - else - { - ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mBad arguments\n\033[0m"); - return (ft_exit(FT_RET_BAD_ARGV, clist)); - } - /* ft_music(clist); */ - return (0); + if (ft_use_args(argc, argv, clist) == FT_RET_FINE) + return (FT_RET_FINE); + return (FT_RET_FINE); } -- cgit v1.2.3