diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..7baccd0 --- /dev/null +++ b/.clangd @@ -0,0 +1,5 @@ +CompilerFlags: + Add: + - "-xc" + - "-I/Users/raphael/Documents/42_cursus/circle4/Cub3D//sources" + - "-I/Users/raphael/Documents/42_cursus/circle4/Cub3D/includes" diff --git a/Cub3D b/Cub3D new file mode 100755 index 0000000..65880c2 Binary files /dev/null and b/Cub3D differ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c8e62e1 --- /dev/null +++ b/Makefile @@ -0,0 +1,122 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: rparodi +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/12 11:05:05 by rparodi #+# #+# # +# Updated: 2024/10/30 16:48:22 by rparodi ### ########.fr # +# # +# **************************************************************************** # + + +# Variables + +# Name +NAME = Cub3D + +# Commands +CC = cc +RM = rm -rf + +# Flags +CFLAGS = -Werror -Wextra -Wall +CFLAGS += -g3 -MMD +#-lm + +# CFLAGS += -fsanitize=address +# CFLAGS += -fsanitize=thread + +INCLUDES = ./includes/ + +SRC = sources/main.c \ + parsing/arguments.c + +# Objects +OBJDIRNAME = ./objects +OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.c=.o)) + +# Colors +GREEN = \033[32m +GREY = \033[0;90m +RED = \033[0;31m +GOLD = \033[38;5;220m +END = \033[0m + +# Rules + +# All (make all) +all: header $(NAME) footer + +# Bonus (make bonus) +bonus: header $(OBJ) $(LIB_OBJ) footer + @mkdir -p $(OBJDIRNAME) + @mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @printf '$(GREY) Be Carefull ur in $(END)$(GREEN)Debug Mode$(END)\n' + @cc $(CFLAGS) -D BONUS=1 -o $(NAME) $(OBJ) $(LIB_OBJ) + +# Clean (make clean) +clean: + @printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n' + @printf '$(GREY) Removing $(END)$(RED)Objects Folder$(END)\n' + @$(RM) $(OBJDIRNAME) + +# Clean (make fclean) +fclean: clean + @printf '$(GREY) Removing $(END)$(RED)Program$(END)\n' + @$(RM) $(NAME) + @echo "" + +# Restart (make re) +re: header fclean all + +# Dependences for all +$(NAME): $(OBJ) + @mkdir -p $(OBJDIRNAME) + @mkdir -p $(OBJDIRNAME)/$(SRCDIRNAME) + @printf '$(GREY) Creating $(END)$(GREEN)$(OBJDIRNAME)$(END)\n' + @cc $(CFLAGS) -o $(NAME) $(OBJ) + +# Creating the objects +$(OBJDIRNAME)/%.o: %.c + @mkdir -p $(dir $@) + @printf '$(GREY) Compiling $(END)$(GREEN)$<$(END)\n' + @cc $(CFLAGS) -o $@ -c $< -I$(INCLUDES) + +# Header +header: + @clear + @printf '\n\n' + @printf '$(GOLD) ******* ****** ******* $(END)\n' + @printf '$(GOLD) ****** *** ******* $(END)\n' + @printf '$(GOLD) ******* * ******* $(END)\n' + @printf '$(GOLD) ****** ******* $(END)\n' + @printf '$(GOLD) ******* ******* $(END)\n' + @printf '$(GOLD) ******************* ******* * $(END)\n' + @printf '$(GOLD) ******************* ******* *** $(END)\n' + @printf '$(GOLD) ****** ******* ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GOLD) ****** $(END)\n' + @printf '$(GREY) Made by rparodi$(END)\n\n' + +# Footer +footer: + @printf "\n" + @printf "$(GOLD) ,_ _,$(END)\n" + @printf "$(GOLD) | \\___//|$(END)\n" + @printf "$(GOLD) |=6 6=|$(END)\n" + @printf "$(GOLD) \\=._Y_.=/$(END)\n" + @printf "$(GOLD) ) \` ( ,$(END)\n" + @printf "$(GOLD) / \\ (('$(END)\n" + @printf "$(GOLD) | | ))$(END)\n" + @printf "$(GOLD) /| | | |\\_//$(END)\n" + @printf "$(GOLD) \\| |._.| |/-\`$(END)\n" + @printf "$(GOLD) '\"' '\"'$(END)\n" + @printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n' + +# Phony +.PHONY: all bonus clean fclean re + +-include ${OBJ:.o=.d} diff --git a/includes/cub3d.h b/includes/cub3d.h new file mode 100644 index 0000000..cfd9621 --- /dev/null +++ b/includes/cub3d.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cub3d.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/30 16:30:26 by rparodi #+# #+# */ +/* Updated: 2024/10/30 17:01:03 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CUB3D_H +# define CUB3D_H + +# include +# include +# include +# include +# include +# include +# include + +# include "message_error.h" + +# ifndef BONUS +# define BONUS 0 +# endif + +bool ft_parse_args(int argc, char *argv[]); +int main(int argc, char *argv[]); + +#endif diff --git a/includes/message_error.h b/includes/message_error.h new file mode 100644 index 0000000..9106469 --- /dev/null +++ b/includes/message_error.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* message_error.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/30 16:43:20 by rparodi #+# #+# */ +/* Updated: 2024/10/30 16:46:28 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 !" + +#endif diff --git a/parsing/arguments.c b/parsing/arguments.c new file mode 100644 index 0000000..2342e28 --- /dev/null +++ b/parsing/arguments.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* arguments.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/30 16:41:32 by rparodi #+# #+# */ +/* Updated: 2024/10/30 17:26:17 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" + +#include + +/** + * @brief checking if the args given to the executable is valid + * + * @param argc the arguments count + * @param argv the arguments value + * @return false if an error / true if no error + */ +bool ft_parse_args(int argc, char *argv[]) +{ + if (argc != 2) + return (write(2, ERR_ARGS_COUNT, strlen(ERR_ARGS_COUNT)), false); + if (strlen(argv[1]) < 4 || \ + strcmp((argv[1] + (strlen(argv[1]) - 4)), ".cub") != 0) + return (write(2, "PB\n", 3), false); + return (true); +} diff --git a/sources/main.c b/sources/main.c new file mode 100644 index 0000000..94fd133 --- /dev/null +++ b/sources/main.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/30 16:30:03 by rparodi #+# #+# */ +/* Updated: 2024/10/30 17:00:20 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" + +int main(int argc, char *argv[]) +{ + if (!ft_parse_args(argc, argv)) + return (1); + return (0); +}