commit c671539661fe2d38c8be894430da51ff56ac7888 Author: Maelys Date: Tue Sep 10 16:27:06 2024 +0200 wip_parsing diff --git a/MacroLibX b/MacroLibX new file mode 160000 index 0000000..5a09ebb --- /dev/null +++ b/MacroLibX @@ -0,0 +1 @@ +Subproject commit 5a09ebb179f8f20afa8405a6d1e29845f0952c46 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c6c2120 --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +NAME = cub3D + +CC = cc + +OBJSDIR = obj/ + +SRCDIR = src/ + +I_DIR = includes/ + +LIBFT_DIR = libft/ + +INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR) + +SRCS = src/main.c \ + src/parsing/check_arg.c \ + src/utils/mess_error.c + +OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o)) + +FLAGS = -Wall -Werror -Wextra +LIB = libft/libft.a + +$(NAME): $(OBJS) + @make -s -C libft + @$(CC) $(FLAGS) $(OBJS) $(LIB) -o $(NAME) + @echo "✅ Compiled" + +$(OBJSDIR)%.o: %.c + @mkdir -p $(@D) + @$(CC) $(INCLUDE) $(FLAGS) $< -c -o $@ + +all: $(NAME) + +clean: + @make -s -C libft clean + @rm -f $(OBJS) + +fclean: clean + @make -s -C libft fclean + @rm -f $(NAME) + @rm -Rf $(OBJSDIR) + @echo "🧹 Cleaned" + +re: fclean all + +.PHONY: clean all re fclean diff --git a/cub3D b/cub3D new file mode 100755 index 0000000..01dbd1f Binary files /dev/null and b/cub3D differ diff --git a/include/cub3d.h b/include/cub3d.h new file mode 100644 index 0000000..ab90609 --- /dev/null +++ b/include/cub3d.h @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cub3d.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */ +/* Updated: 2024/09/07 17:48:56 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CUB3D_H +# define CUB3D_H + +# include "../libft/includes/libft.h" +# include "mess_err.h" +# include +# include +# include +# include + +int check_format_file(char *file); +int check_err_arg(int argc, char **argv); + +int err_mess(char *str); + +#endif diff --git a/include/mess_err.h b/include/mess_err.h new file mode 100644 index 0000000..5dc0585 --- /dev/null +++ b/include/mess_err.h @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mess_err.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */ +/* Updated: 2024/09/07 19:13:20 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +//for argurments + +#define ERR_ARGS "Wrong number of arguments" +#define ERR_TYPE "Wrong type of file" +#define EMPTY "Empty file" + +//for map + +#define NOT_CLOSE "The map isn't closed" +#define ERR_PLAYER "Incorrect number of players" + +//for permission diff --git a/libft/Ft_Printf/ft_printf.c b/libft/Ft_Printf/ft_printf.c new file mode 100644 index 0000000..faf9baa --- /dev/null +++ b/libft/Ft_Printf/ft_printf.c @@ -0,0 +1,66 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/13 14:38:09 by madumerg #+# #+# */ +/* Updated: 2024/07/09 17:54:17 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +static int ft_conversions(va_list args, char c) +{ + int print; + + print = 0; + if (c == 'c') + print += ft_putchar(va_arg(args, int)); + else if (c == 's') + print += ft_putstr(va_arg(args, char *)); + else if (c == 'p') + print += ft_print_ptr(va_arg(args, void *)); + else if (c == 'd') + print += ft_putnbr(va_arg(args, int)); + else if (c == 'i') + print += ft_putnbr(va_arg(args, int)); + else if (c == 'u') + print += ft_putnbr_uns_int(va_arg(args, unsigned int)); + else if (c == 'x') + print += ft_putnbr_hexa_low(va_arg(args, unsigned int)); + else if (c == 'X') + print += ft_putnbr_hexa_upp(va_arg(args, unsigned int)); + else if (c == '%') + print += ft_putchar('%'); + return (print); +} + +int ft_printf(const char *str, ...) +{ + va_list args; + int print; + + if (!str) + return (-1); + va_start(args, str); + print = 0; + while (*str) + { + if (*str == '%') + { + ++str; + if (*str) + print += ft_conversions(args, *str); + else + return (-1); + } + else + print += ft_putchar(*str); + str++; + } + va_end(args); + return (print); +} diff --git a/libft/Ft_Printf/ft_printf_utils.c b/libft/Ft_Printf/ft_printf_utils.c new file mode 100644 index 0000000..fc73f4d --- /dev/null +++ b/libft/Ft_Printf/ft_printf_utils.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 10) + { + i += ft_putnbr(n / 10); + i += ft_putnbr(n % 10); + } + return (i); +} + +int ft_putstr(char *str) +{ + int i; + + i = 0; + if (!str) + return (ft_putstr("(null)")); + while (str[i] != '\0') + { + write(1, &str[i], 1); + i++; + } + return (i); +} diff --git a/libft/Ft_Printf/ft_putnbr_hexa.c b/libft/Ft_Printf/ft_putnbr_hexa.c new file mode 100644 index 0000000..0cd72dd --- /dev/null +++ b/libft/Ft_Printf/ft_putnbr_hexa.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_hexa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 10) + { + i += ft_putnbr_hexa_low(n / 16); + i += ft_putnbr_hexa_low(n % 16); + } + return (i); +} + +int ft_putnbr_hexa_upp(unsigned int n) +{ + unsigned int i; + + i = 0; + if (n < 16) + { + i += ft_putchar("0123456789ABCDEF"[n % 16]); + return (i); + } + else if (n >= 10) + { + i += ft_putnbr_hexa_upp(n / 16); + i += ft_putnbr_hexa_upp(n % 16); + } + return (i); +} + +int ft_print_ptr(void *ptr) +{ + int i; + + if (!ptr) + i = ft_putstr("(nil)"); + else + i = ft_putstr("0x") + ft_putnbr_hexa_low((size_t)ptr); + return (i); +} diff --git a/libft/Ft_Printf/ft_putnbr_uns_int.c b/libft/Ft_Printf/ft_putnbr_uns_int.c new file mode 100644 index 0000000..2340bb0 --- /dev/null +++ b/libft/Ft_Printf/ft_putnbr_uns_int.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_uns_int.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/17 13:18:12 by madumerg #+# #+# */ +/* Updated: 2023/11/28 12:16:03 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_printf.h" + +int ft_putnbr_uns_int(unsigned int n) +{ + unsigned int i; + + i = 0; + if (n < 10) + { + i += ft_putchar(n + '0'); + return (i); + } + else if (n >= 10) + { + i += ft_putnbr(n / 10); + i += ft_putnbr(n % 10); + } + return (i); +} diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..fbb39b2 --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,67 @@ +NAME = libft.a + +SRCS = is/ft_isalpha.c \ + is/ft_isalnum.c \ + is/ft_isascii.c \ + is/ft_isdigit.c \ + is/ft_isprint.c \ + is/ft_is_space.c \ + str/ft_strlen.c \ + str/ft_toupper.c \ + str/ft_tolower.c \ + str/ft_strchr.c \ + str/ft_strrchr.c \ + str/ft_strncmp.c \ + str/ft_strnstr.c \ + str/ft_atoi.c \ + mem/ft_memset.c \ + mem/ft_memmove.c \ + mem/ft_memcpy.c \ + mem/ft_memchr.c \ + mem/ft_memcmp.c \ + mem/ft_bzero.c \ + mem/ft_calloc.c \ + str/ft_strlcpy.c \ + str/ft_strlcat.c \ + put/ft_putchar_fd.c \ + put/ft_putendl_fd.c \ + put/ft_putstr_fd.c \ + put/ft_putnbr_fd.c \ + str/ft_strdup.c \ + str/ft_strjoin.c \ + str/ft_substr.c \ + str/ft_strtrim.c \ + str/ft_itoa.c \ + str/ft_striteri.c \ + str/ft_strmapi.c \ + str/ft_split.c \ + str/ft_atoll.c \ + Ft_Printf/ft_printf_utils.c \ + Ft_Printf/ft_printf.c \ + Ft_Printf/ft_putnbr_hexa.c \ + Ft_Printf/ft_putnbr_uns_int.c \ + gnl/get_next_line.c \ + str/ft_count_word.c \ + str/ft_strcmp.c + +OBJS = ${SRCS:.c=.o} + +HEADERS = includes/ + +all : ${NAME} + +${OBJS} : + @gcc -Wall -Wextra -Werror -I ${HEADERS} -c ${@:.o=.c} -o $@ + +${NAME} : ${OBJS} + @ar rcs ${NAME} ${OBJS} + +clean : + @rm -f ${OBJS} + +fclean : clean + @rm -f ${NAME} + +re : fclean all + +.PHONY : all clean fclean re diff --git a/libft/compile_commands.json b/libft/compile_commands.json new file mode 100644 index 0000000..e69de29 diff --git a/libft/gnl/get_next_line.c b/libft/gnl/get_next_line.c new file mode 100644 index 0000000..8827b3c --- /dev/null +++ b/libft/gnl/get_next_line.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* get_next_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/24 11:51:12 by madumerg #+# #+# */ +/* Updated: 2024/09/04 15:59:19 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/libft.h" + +char ft_end_of_line(char *line, char *buffer) +{ + int i; + int j; + + i = 0; + j = 0; + while (line[i] && line[i] != '\n') + i++; + if (line[i] == '\n') + { + i++; + while (line[i]) + { + buffer[j] = line[i]; + i++; + j++; + } + buffer[j] = '\0'; + line[i - j] = '\0'; + return (1); + } + return (0); +} + +char *ft_verif(char **buffer, char *line) +{ + free(*buffer); + *buffer = NULL; + if (line[0] != '\0') + return (line); + free(line); + return (NULL); +} + +char *get_next_line(int fd) +{ + static char *buffer; + char *line; + int read_nb; + + if (fd < 0 || fd > 1023 || BUFFER_SIZE <= 0) + return (NULL); + line = ft_calloc(1, 1); + if (!buffer) + buffer = ft_calloc(sizeof(char), (BUFFER_SIZE + 1)); + while (buffer && line) + { + line = ft_strjoin(line, buffer); + if (!line) + return (NULL); + if (ft_end_of_line(line, buffer) == 1) + return (line); + read_nb = read(fd, buffer, BUFFER_SIZE); + if (read_nb < 1) + return (ft_verif(&buffer, line)); + buffer[read_nb] = '\0'; + } + return (NULL); +} diff --git a/libft/includes/ft_printf.h b/libft/includes/ft_printf.h new file mode 100644 index 0000000..c4cd386 --- /dev/null +++ b/libft/includes/ft_printf.h @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +# include +# include +# include + +int ft_printf(const char *str, ...); +int ft_putchar(char c); +int ft_putstr(char *str); +int ft_putnbr(int n); +int ft_putnbr_uns_int(unsigned int n); +int ft_putnbr_hexa_low(size_t n); +int ft_putnbr_hexa_upp(unsigned int n); +int ft_print_ptr(void *ptr); + +#endif diff --git a/libft/includes/libft.h b/libft/includes/libft.h new file mode 100644 index 0000000..f5bf4db --- /dev/null +++ b/libft/includes/libft.h @@ -0,0 +1,69 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 13:02:45 by madumerg #+# #+# */ +/* Updated: 2024/09/04 16:24:48 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include +# include +# include +# include + +# ifndef BUFFER_SIZE +# define BUFFER_SIZE 1 +# endif + +int ft_atoi(const char *str); +int ft_isalnum(int i); +int ft_isalpha(int i); +int ft_isascii(int i); +int ft_isdigit(int i); +int ft_isprint(int i); +char *ft_strchr(const char *str, int p); +char *ft_strdup(const char *s); +size_t ft_strlen(const char *str); +int ft_strncmp(const char *s1, const char *s2, size_t n); +char *ft_strrchr(const char *str, int p); +int ft_tolower(int i); +int ft_toupper(int i); +char *ft_strnstr(const char *str, const char *to_find, size_t len); +char *ft_strjoin(char const *s1, char const *s2); +void *ft_memset(void *ptr, int v, size_t count); +void *ft_memmove(void *dest, const void *src, size_t n); +void ft_bzero(void *s, size_t count); +void *ft_memcpy(void *dest, const void *src, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +void *ft_memchr(const void *s, int c, size_t n); +size_t ft_strlcpy(char *dest, const char *src, size_t size); +void *ft_calloc(size_t nmemb, size_t size); +size_t ft_strlcat(char *dest, const char *src, size_t destsize); +char *ft_strtrim(char const *s1, char const *set); +char **ft_split(char const *s, char c); +char *ft_itoa(int n); +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); +void ft_striteri(char *s, void (*f)(unsigned int, char*)); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char *s, int fd); +void ft_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); +long long int ft_atoll(const char *str); +int ft_is_space(char c); +char ft_end_of_line(char *line, char *buffer); +char *ft_verif(char **buffer, char *line); +char *get_next_line(int fd); +int ft_count_word(const char *str, char sep); +int ft_count_len(const char *str, char sep); +void *ft_free(char **s); +int ft_strcmp(char *s1, char *s2); + +#endif diff --git a/libft/is/ft_is_space.c b/libft/is/ft_is_space.c new file mode 100644 index 0000000..9905b93 --- /dev/null +++ b/libft/is/ft_is_space.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_space.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 9 && c <= 13)) + return (1); + return (0); +} diff --git a/libft/is/ft_isalnum.c b/libft/is/ft_isalnum.c new file mode 100644 index 0000000..cbc5ce4 --- /dev/null +++ b/libft/is/ft_isalnum.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 13:03:43 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:15 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int i) +{ + if ((i >= '0' && i <= '9') || (i >= 'a' && i <= 'z') + || (i >= 'A' && i <= 'Z')) + return (1); + return (0); +} diff --git a/libft/is/ft_isalpha.c b/libft/is/ft_isalpha.c new file mode 100644 index 0000000..3168959 --- /dev/null +++ b/libft/is/ft_isalpha.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 12:35:26 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:21 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalpha(int i) +{ + if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')) + return (1); + return (0); +} diff --git a/libft/is/ft_isascii.c b/libft/is/ft_isascii.c new file mode 100644 index 0000000..6939b4b --- /dev/null +++ b/libft/is/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 13:32:37 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:27 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isascii(int i) +{ + if (i >= 0 && i <= 127) + return (1); + return (0); +} diff --git a/libft/is/ft_isdigit.c b/libft/is/ft_isdigit.c new file mode 100644 index 0000000..cf0edb7 --- /dev/null +++ b/libft/is/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = '0' && i <= '9') + return (1); + return (0); +} diff --git a/libft/is/ft_isprint.c b/libft/is/ft_isprint.c new file mode 100644 index 0000000..0e3708c --- /dev/null +++ b/libft/is/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:08:46 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:58:37 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isprint(int i) +{ + if (i < 32 || i > 126) + return (0); + return (1); +} diff --git a/libft/mem/ft_bzero.c b/libft/mem/ft_bzero.c new file mode 100644 index 0000000..69b71a4 --- /dev/null +++ b/libft/mem/ft_bzero.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 17:15:50 by madumerg #+# #+# */ +/* Updated: 2023/11/02 13:48:10 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft.h" + +void ft_bzero(void *s, size_t count) +{ + ft_memset(s, 0, count); +} diff --git a/libft/mem/ft_calloc.c b/libft/mem/ft_calloc.c new file mode 100644 index 0000000..7291b9b --- /dev/null +++ b/libft/mem/ft_calloc.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:41:05 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:18:08 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t ct, size_t size) +{ + char *str; + + if (size == 0 || ct == 0) + return (malloc(1)); + if ((int)size < 0 && (int)ct < 0) + return (NULL); + if ((unsigned long long)(size * ct) > UINT_MAX) + return (NULL); + str = malloc(size * ct); + if (!str) + return (NULL); + ft_bzero(str, size * ct); + return (str); +} diff --git a/libft/mem/ft_memchr.c b/libft/mem/ft_memchr.c new file mode 100644 index 0000000..a60e616 --- /dev/null +++ b/libft/mem/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:41:18 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:24:27 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + + i = 0; + if (!s) + return (0); + while (i < n) + { + if (*(unsigned char *)(s + i) == (unsigned char)c) + return ((void *)(s + i)); + i++; + } + return (0); +} diff --git a/libft/mem/ft_memcmp.c b/libft/mem/ft_memcmp.c new file mode 100644 index 0000000..aa1de19 --- /dev/null +++ b/libft/mem/ft_memcmp.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:37 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:11:43 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + unsigned char *ptr1; + unsigned char *ptr2; + + ptr1 = (unsigned char *) s1; + ptr2 = (unsigned char *) s2; + i = 0; + while (i < n) + { + if (ptr1[i] != ptr2[i]) + return (ptr1[i] - ptr2[i]); + i++; + } + return (0); +} diff --git a/libft/mem/ft_memcpy.c b/libft/mem/ft_memcpy.c new file mode 100644 index 0000000..876bb95 --- /dev/null +++ b/libft/mem/ft_memcpy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:45 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:21:18 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + size_t i; + + i = 0; + if (!dest) + return (NULL); + while (i != n) + { + *(unsigned char *)(dest + i) = *(unsigned char *)(src + i); + i++; + } + return (dest); +} diff --git a/libft/mem/ft_memmove.c b/libft/mem/ft_memmove.c new file mode 100644 index 0000000..d1e2c2f --- /dev/null +++ b/libft/mem/ft_memmove.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:41:28 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:24:06 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dest, const void *src, size_t size) +{ + size_t i; + + i = 0; + if (!dest && !src) + return (NULL); + if (dest > src) + { + i = size; + while (i > 0) + { + i--; + *(unsigned char *)(dest + i) = *(unsigned char *)(src + i); + } + } + else + { + while (i != size) + { + *(unsigned char *)(dest + i) = *(unsigned char *)(src + i); + i++; + } + } + return (dest); +} diff --git a/libft/mem/ft_memset.c b/libft/mem/ft_memset.c new file mode 100644 index 0000000..641f9c0 --- /dev/null +++ b/libft/mem/ft_memset.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:15 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:11:59 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *ptr, int v, size_t count) +{ + size_t i; + + i = 0; + while (i != count) + { + *(unsigned char *)(ptr + i) = (unsigned char)v; + i++; + } + return (ptr); +} diff --git a/libft/put/ft_putchar_fd.c b/libft/put/ft_putchar_fd.c new file mode 100644 index 0000000..cf6738b --- /dev/null +++ b/libft/put/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:32:56 by madumerg #+# #+# */ +/* Updated: 2023/11/03 14:52:19 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/put/ft_putendl_fd.c b/libft/put/ft_putendl_fd.c new file mode 100644 index 0000000..54d1ea4 --- /dev/null +++ b/libft/put/ft_putendl_fd.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:33:06 by madumerg #+# #+# */ +/* Updated: 2024/04/04 17:11:24 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + int i; + + i = 0; + if (!s) + return ; + while (s[i] != '\0') + { + write(fd, &s[i], 1); + i++; + } + write(fd, "\n", 1); +} diff --git a/libft/put/ft_putnbr_fd.c b/libft/put/ft_putnbr_fd.c new file mode 100644 index 0000000..53845e7 --- /dev/null +++ b/libft/put/ft_putnbr_fd.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:33:42 by madumerg #+# #+# */ +/* Updated: 2023/11/03 14:58:11 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + if (n == -2147483648) + { + ft_putchar_fd('-', fd); + ft_putchar_fd('2', fd); + n = 147483648; + } + if (n < 0) + { + ft_putchar_fd('-', fd); + n *= -1; + } + if (n < 10) + { + ft_putchar_fd((n + '0'), fd); + return ; + } + else if (n >= 10) + { + ft_putnbr_fd((n / 10), fd); + ft_putnbr_fd((n % 10), fd); + } +} diff --git a/libft/put/ft_putstr_fd.c b/libft/put/ft_putstr_fd.c new file mode 100644 index 0000000..a352e32 --- /dev/null +++ b/libft/put/ft_putstr_fd.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/03 14:33:15 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:26:33 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + int i; + + i = 0; + if (!s) + return ; + while (s[i] != '\0') + { + write(fd, &s[i], 1); + i++; + } +} diff --git a/libft/str/ft_atoi.c b/libft/str/ft_atoi.c new file mode 100644 index 0000000..4d11419 --- /dev/null +++ b/libft/str/ft_atoi.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 9 && str[i] <= 13)) + i++; + if (str[i] == '-' || str[i] == '+') + { + if (str[i] == '-') + s = -1; + i++; + } + while (str[i] >= '0' && str[i] <= '9') + { + r = r * 10 + str[i] - '0'; + i++; + } + return (r *= s); +} diff --git a/libft/str/ft_atoll.c b/libft/str/ft_atoll.c new file mode 100644 index 0000000..6fee091 --- /dev/null +++ b/libft/str/ft_atoll.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoll.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg = 9 && str[i] <= 13)) + i++; + if (str[i] == '-' || str[i] == '+') + { + if (str[i] == '-') + s = -1; + i++; + } + while (str[i] >= '0' && str[i] <= '9') + { + r = r * 10 + str[i] - '0'; + i++; + } + return (r *= s); +} diff --git a/libft/str/ft_count_word.c b/libft/str/ft_count_word.c new file mode 100644 index 0000000..11ac9ef --- /dev/null +++ b/libft/str/ft_count_word.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_count_word.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/29 00:04:58 by madumerg #+# #+# */ +/* Updated: 2024/05/29 00:05:09 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_count_word(const char *str, char sep) +{ + int i; + int count; + + i = 0; + count = 0; + if (!str || !str[0]) + return (0); + if (str[i++] != sep) + count++; + while (str[i]) + { + if (str[i - 1] == sep && str[i] != sep) + count++; + i++; + } + return (count); +} diff --git a/libft/str/ft_itoa.c b/libft/str/ft_itoa.c new file mode 100644 index 0000000..dbc432e --- /dev/null +++ b/libft/str/ft_itoa.c @@ -0,0 +1,64 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:14:32 by madumerg #+# #+# */ +/* Updated: 2023/11/08 10:22:00 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_len(int n) +{ + int cpt; + unsigned int nb; + + cpt = 0; + if (n < 0) + { + cpt++; + nb = -n; + } + else + nb = n; + while (nb >= 10) + { + nb /= 10; + cpt++; + } + cpt++; + return (cpt); +} + +char *ft_itoa(int n) +{ + char *str; + int cpt; + long long int nb; + int i; + + i = 0; + nb = n; + cpt = ft_len(n); + str = ft_calloc((cpt + 1), sizeof(char)); + if (!str) + return (NULL); + if (n < 0) + { + str[0] = '-'; + i = 1; + nb *= -1; + } + cpt--; + while (cpt >= i) + { + str[cpt] = (nb % 10) + '0'; + nb /= 10; + cpt--; + } + return (str); +} diff --git a/libft/str/ft_split.c b/libft/str/ft_split.c new file mode 100644 index 0000000..fbf3889 --- /dev/null +++ b/libft/str/ft_split.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/08 12:11:54 by gadelbes #+# #+# */ +/* Updated: 2024/05/29 00:04:26 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_free(char **s) +{ + int i; + + i = 0; + while (s[i]) + { + free(s[i]); + i++; + } + free(s); + return (NULL); +} + +int ft_count_len(const char *str, char sep) +{ + int i; + int len; + + i = 0; + len = 0; + while (str[i] && str[i] != sep) + { + len++; + i++; + } + return (len); +} + +char **ft_split(char const *s, char c) +{ + char **str; + int i; + int w; + int l; + + i = 0; + w = 0; + if (!s) + return (NULL); + str = ft_calloc((ft_count_word((char *)s, c) + 1), sizeof(char *)); + if (!str) + return (NULL); + while (w < ft_count_word(s, c)) + { + while (s[i] == c) + i++; + l = ft_count_len((s + i), c); + str[w] = ft_calloc(l + 1, sizeof(char)); + if (!str[w]) + return (ft_free(str)); + ft_strlcpy(str[w], s + i, l + 1); + w++; + i += l; + } + return (str); +} diff --git a/libft/str/ft_strchr.c b/libft/str/ft_strchr.c new file mode 100644 index 0000000..78e91b0 --- /dev/null +++ b/libft/str/ft_strchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 16:16:43 by madumerg #+# #+# */ +/* Updated: 2023/11/07 17:50:18 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(const char *str, int p) +{ + int i; + + i = 0; + if (!str) + return (NULL); + while (str[i] != '\0') + { + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + i++; + } + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + return (0); +} diff --git a/libft/str/ft_strcmp.c b/libft/str/ft_strcmp.c new file mode 100644 index 0000000..aa3c328 --- /dev/null +++ b/libft/str/ft_strcmp.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/06/06 12:58:01 by madumerg #+# #+# */ +/* Updated: 2024/06/24 14:42:39 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strcmp(char *s1, char *s2) +{ + int i; + + i = 0; + while (s1[i] != '\0' || s2[i] != '\0') + { + if (s2[i] != s1[i]) + return (s1[i] - s2[i]); + i++; + } + return (0); +} diff --git a/libft/str/ft_strdup.c b/libft/str/ft_strdup.c new file mode 100644 index 0000000..ebac695 --- /dev/null +++ b/libft/str/ft_strdup.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 10:11:13 by madumerg #+# #+# */ +/* Updated: 2024/07/11 20:14:23 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *src) +{ + int size; + char *dest; + + size = 0; + dest = ft_calloc(sizeof(char), (ft_strlen(src) + 1)); + if (dest == NULL) + return (NULL); + while (src[size]) + { + dest[size] = src[size]; + size++; + } + dest[size] = '\0'; + return (dest); +} diff --git a/libft/str/ft_striteri.c b/libft/str/ft_striteri.c new file mode 100644 index 0000000..eced53f --- /dev/null +++ b/libft/str/ft_striteri.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:34:05 by madumerg #+# #+# */ +/* Updated: 2023/11/07 18:13:31 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + unsigned int i; + + i = 0; + if (!s || !f) + return ; + while (s[i]) + { + f(i, &s[i]); + i++; + } +} diff --git a/libft/str/ft_strjoin.c b/libft/str/ft_strjoin.c new file mode 100644 index 0000000..5ad80ab --- /dev/null +++ b/libft/str/ft_strjoin.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/27 17:26:43 by madumerg #+# #+# */ +/* Updated: 2024/07/09 15:36:26 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + size_t len; + size_t i; + size_t j; + char *str; + + if (!s1) + return (ft_strdup(s2)); + if (!s2) + return (ft_strdup(s1)); + len = ft_strlen(s1) + ft_strlen(s2); + str = malloc(sizeof(char) * (len + 1)); + if (!str) + return (NULL); + i = 0; + while (s1[i] != '\0') + { + str[i] = s1[i]; + i++; + } + j = 0; + while (s2[j] != '\0') + str[i++] = s2[j++]; + str[i] = '\0'; + return (str); +} diff --git a/libft/str/ft_strlcat.c b/libft/str/ft_strlcat.c new file mode 100644 index 0000000..301c50a --- /dev/null +++ b/libft/str/ft_strlcat.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 14:42:26 by madumerg #+# #+# */ +/* Updated: 2023/11/03 14:21:31 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t sdst; + size_t ssrc; + size_t i; + size_t j; + + sdst = ft_strlen(dest); + ssrc = ft_strlen(src); + i = 0; + j = sdst; + if (sdst > size || size == 0) + return (ssrc + size); + while (src[i] && (i < size) && (sdst < size - 1)) + { + dest[sdst] = src[i]; + i++; + sdst++; + } + dest[sdst] = '\0'; + return (ssrc + j); +} diff --git a/libft/str/ft_strlcpy.c b/libft/str/ft_strlcpy.c new file mode 100644 index 0000000..5276331 --- /dev/null +++ b/libft/str/ft_strlcpy.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 10:08:10 by madumerg #+# #+# */ +/* Updated: 2023/11/03 12:30:11 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t destsize) +{ + size_t i; + + i = 0; + if (destsize > 0) + { + while (src[i] && i < destsize - 1) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + } + return (ft_strlen(src)); +} diff --git a/libft/str/ft_strlen.c b/libft/str/ft_strlen.c new file mode 100644 index 0000000..12a6ce0 --- /dev/null +++ b/libft/str/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:07:38 by madumerg #+# #+# */ +/* Updated: 2024/07/09 17:00:57 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *str) +{ + size_t i; + + i = 0; + while (str && str[i]) + i++; + return (i); +} diff --git a/libft/str/ft_strmapi.c b/libft/str/ft_strmapi.c new file mode 100644 index 0000000..46118e2 --- /dev/null +++ b/libft/str/ft_strmapi.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:33:40 by madumerg #+# #+# */ +/* Updated: 2023/11/08 09:42:37 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + unsigned int i; + char *str; + + i = 0; + if (!s || !f) + return (NULL); + str = ft_calloc(ft_strlen(s) + 1, sizeof(char)); + if (!str) + return (NULL); + while (s[i]) + { + str[i] = f(i, s[i]); + i++; + } + return (str); +} diff --git a/libft/str/ft_strncmp.c b/libft/str/ft_strncmp.c new file mode 100644 index 0000000..eb22cb1 --- /dev/null +++ b/libft/str/ft_strncmp.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/31 10:15:03 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:25:39 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *str, const char *to_find, size_t len) +{ + size_t i; + int j; + + i = 0; + j = 0; + if (!str) + return (NULL); + if (to_find[0] == '\0') + return ((char *) &str[i]); + while (str[i] && i < len) + { + while (str[i + j] == to_find[j] && i + j < len) + { + j++; + if (to_find[j] == '\0') + return ((char *) &str[i]); + } + j = 0; + i++; + } + return (0); +} diff --git a/libft/str/ft_strrchr.c b/libft/str/ft_strrchr.c new file mode 100644 index 0000000..2749134 --- /dev/null +++ b/libft/str/ft_strrchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 16:42:24 by madumerg #+# #+# */ +/* Updated: 2023/11/03 15:59:52 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *str, int p) +{ + int i; + + i = 0; + while (str[i] != '\0') + i++; + while (i > 0) + { + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + i--; + } + if (str[i] == (unsigned char)p) + return ((char *) &str[i]); + return (0); +} diff --git a/libft/str/ft_strtrim.c b/libft/str/ft_strtrim.c new file mode 100644 index 0000000..c24a76f --- /dev/null +++ b/libft/str/ft_strtrim.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:33:52 by madumerg #+# #+# */ +/* Updated: 2023/11/07 17:51:00 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t start; + size_t len; + char *str; + + if (!s1) + return (NULL); + len = ft_strlen(s1); + start = 0; + while (ft_strchr(set, s1[start]) != 0) + start++; + while (ft_strrchr(set, s1[len]) != 0) + len--; + str = ft_substr(s1, start, (len - start) + 1); + return (str); +} diff --git a/libft/str/ft_substr.c b/libft/str/ft_substr.c new file mode 100644 index 0000000..3db5abc --- /dev/null +++ b/libft/str/ft_substr.c @@ -0,0 +1,47 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/06 11:14:21 by madumerg #+# #+# */ +/* Updated: 2023/11/09 16:27:51 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_min(int lenb, int len) +{ + if (len < lenb) + return (len); + return (lenb); +} + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *str; + size_t lenb; + size_t i; + size_t j; + + if (!s) + return (NULL); + if (start > ft_strlen(s)) + return (ft_calloc(1, 1)); + lenb = ft_strlen(s) - start; + str = malloc(sizeof(char) * ft_min(lenb, len) + 1); + if (!str) + return (NULL); + i = start; + j = 0; + while (s[i] && j < len) + { + str[j] = s[i]; + i++; + j++; + } + str[j] = '\0'; + return (str); +} diff --git a/libft/str/ft_tolower.c b/libft/str/ft_tolower.c new file mode 100644 index 0000000..3edc7c8 --- /dev/null +++ b/libft/str/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:21:25 by madumerg #+# #+# */ +/* Updated: 2023/11/02 14:59:56 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_tolower(int i) +{ + if (i >= 'A' && i <= 'Z') + i += 32; + return (i); +} diff --git a/libft/str/ft_toupper.c b/libft/str/ft_toupper.c new file mode 100644 index 0000000..199bfd1 --- /dev/null +++ b/libft/str/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/10/30 14:21:13 by madumerg #+# #+# */ +/* Updated: 2023/11/02 15:00:00 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int i) +{ + if (i >= 'a' && i <= 'z') + i -= 32; + return (i); +} diff --git a/obj/src/main.o b/obj/src/main.o new file mode 100644 index 0000000..9fd5597 Binary files /dev/null and b/obj/src/main.o differ diff --git a/obj/src/parsing/check_arg.o b/obj/src/parsing/check_arg.o new file mode 100644 index 0000000..251970b Binary files /dev/null and b/obj/src/parsing/check_arg.o differ diff --git a/obj/src/utils/mess_error.o b/obj/src/utils/mess_error.o new file mode 100644 index 0000000..c957862 Binary files /dev/null and b/obj/src/utils/mess_error.o differ diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..816e15b --- /dev/null +++ b/src/main.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */ +/* Updated: 2024/09/07 19:12:04 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../include/cub3d.h" + +char **ft_parse_map(char *map) +{ + int fd; + char **parse_map; + char *save; + char *join; + + fd = open(map, O_RDONLY); + save = get_next_line(fd); + join = ft_calloc(1, 1); + if (!join) + return (NULL); + while (save != NULL) + { + join = ft_strjoin(join, save); + free(save); + save = get_next_line(fd); + } + parse_map = ft_split(join, '\n'); + free(join); + close(fd); + return (parse_map); +} + +int main(int ac, char **av) +{ + if (check_err_arg(ac, av) == 1) + return (1); + return (0); +} diff --git a/src/parsing/check_arg.c b/src/parsing/check_arg.c new file mode 100644 index 0000000..f17f593 --- /dev/null +++ b/src/parsing/check_arg.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* check_arg.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/04 21:33:35 by madumerg #+# #+# */ +/* Updated: 2024/09/07 17:57:29 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../include/cub3d.h" + +int check_err_arg(int ac, char **av) +{ + int fd; + int rd; + char buf[10]; + + if (ac != 2) + return (err_mess(ERR_ARGS)); + if (check_format_file(av[1]) == 0) + return (err_mess(ERR_TYPE)); + fd = open(av[1], O_RDONLY); + if (fd == -1) + { + close(fd); + return (err_mess(EMPTY)); + } + rd = read(fd, buf, 10); + close(fd); + return (rd); +} + +int check_format_file(char *file) +{ + int len; + + len = ft_strlen(file) - 1; + if (file[len] == 'b' && file[len - 1] == 'u' && \ + file[len - 2] == 'c' && file[len - 3] == '.') + return (1); + return (0); +} + diff --git a/src/parsing/check_id_text.c b/src/parsing/check_id_text.c new file mode 100644 index 0000000..e69de29 diff --git a/src/parsing/check_map.c b/src/parsing/check_map.c new file mode 100644 index 0000000..e69de29 diff --git a/src/parsing/check_rgb.c b/src/parsing/check_rgb.c new file mode 100644 index 0000000..e69de29 diff --git a/src/parsing/memo_parsing b/src/parsing/memo_parsing new file mode 100644 index 0000000..41fa973 --- /dev/null +++ b/src/parsing/memo_parsing @@ -0,0 +1,18 @@ + char **map = ft_parse_map(av[1]); + int i = 0; + while (map[i]) + { + ft_putchar_fd('*', 2); + ft_putstr_fd(map[i], 2); + ft_putchar_fd('*', 2); + ft_putchar_fd('\n', 2); + i++; + } + //envoyer de 0 a 3 inclus dans check id texture + //envoyer de 4 a 5 inclus dans check rgb format + //envoyer de 6 a jusqu a la fin dans check map + + struct typedef s_pars + { + + } t_pars; diff --git a/src/utils/mess_error.c b/src/utils/mess_error.c new file mode 100644 index 0000000..41446eb --- /dev/null +++ b/src/utils/mess_error.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* mess_error.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: madumerg +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/09/07 17:35:14 by madumerg #+# #+# */ +/* Updated: 2024/09/07 17:40:57 by madumerg ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../include/cub3d.h" + +int err_mess(char *str) +{ + ft_putendl_fd("Error\n", 2); + ft_putendl_fd(str, 2); + return (1); +}