diff --git a/Makefile b/Makefile index c8e62e1..884e77a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: rparodi +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/11/12 11:05:05 by rparodi #+# #+# # -# Updated: 2024/10/30 16:48:22 by rparodi ### ########.fr # +# Updated: 2024/10/31 11:16:34 by rparodi ### ########.fr # # # # **************************************************************************** # @@ -31,6 +31,7 @@ CFLAGS += -g3 -MMD INCLUDES = ./includes/ SRC = sources/main.c \ + sources/error.c \ parsing/arguments.c # Objects diff --git a/includes/cub3d.h b/includes/cub3d.h index cfd9621..a793ece 100644 --- a/includes/cub3d.h +++ b/includes/cub3d.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */ -/* Updated: 2024/10/30 17:01:03 by rparodi ### ########.fr */ +/* Updated: 2024/10/31 11:17:40 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ # define BONUS 0 # endif +void print_error(char *msg); bool ft_parse_args(int argc, char *argv[]); int main(int argc, char *argv[]); diff --git a/includes/message_error.h b/includes/message_error.h index 2984478..b6d778d 100644 --- a/includes/message_error.h +++ b/includes/message_error.h @@ -6,14 +6,17 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:43:20 by rparodi #+# #+# */ -/* Updated: 2024/10/31 10:38:21 by rparodi ### ########.fr */ +/* Updated: 2024/10/31 11:23:20 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MESSAGE_ERROR_H # define MESSAGE_ERROR_H -# define ERR_ARGS_COUNT "Error:\nYou have to give only the map on arguments !\n" -# define INV_NAME_MAP "Error:\nThe name of the map have to finish by `.cub` !\n" +# define ERR_ARGS_COUNT "You have to give only the map on arguments !\n" +# define INV_NAME_MAP "The name of the map have to finish by `.cub` !\n" +# define RED "\x1b[31m" +# define BOLD_RED "\033[1;31m" +# define RESET "\x1b[K\x1b[0m" #endif diff --git a/parsing/arguments.c b/parsing/arguments.c index 1b7035f..d807fed 100644 --- a/parsing/arguments.c +++ b/parsing/arguments.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/30 16:41:32 by rparodi #+# #+# */ -/* Updated: 2024/10/31 10:37:56 by rparodi ### ########.fr */ +/* Updated: 2024/10/31 11:23:05 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,9 +24,9 @@ bool ft_parse_args(int argc, char *argv[]) { if (argc != 2) - return (write(2, ERR_ARGS_COUNT, strlen(ERR_ARGS_COUNT)), false); + return (print_error(ERR_ARGS_COUNT), false); if (strlen(argv[1]) < 4 || \ strcmp((argv[1] + (strlen(argv[1]) - 4)), ".cub") != 0) - return (write(2, INV_NAME_MAP, strlen(INV_NAME_MAP)), false); + return (print_error(INV_NAME_MAP), false); return (true); } diff --git a/sources/error.c b/sources/error.c new file mode 100644 index 0000000..cdbe9b8 --- /dev/null +++ b/sources/error.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/31 11:09:00 by rparodi #+# #+# */ +/* Updated: 2024/10/31 11:21:59 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" + +#include + +void print_error(char *msg) +{ + write(2, BOLD_RED, strlen(BOLD_RED)); + write(2, "Error:\n", strlen("Error:\n")); + write(2, RESET, strlen(RESET)); + write(2, RED, strlen(RED)); + write(2, msg, strlen(msg)); + write(2, RESET, strlen(RESET)); +}