From a3f3fc742daa4b28094b5ebe9be60263c41979d1 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Wed, 30 Oct 2019 15:00:17 +0100 Subject: New libft, feelsgoodman --- libft/Makefile | 174 ++++++++++++++++++++---------------------- libft/ft_atoi.c | 79 ------------------- libft/ft_bzero.c | 23 ------ libft/ft_calloc.c | 29 ------- libft/ft_isalnum.c | 22 ------ libft/ft_isalpha.c | 36 --------- libft/ft_isascii.c | 20 ----- libft/ft_isdigit.c | 20 ----- libft/ft_isprint.c | 20 ----- libft/ft_isspace_bonus.c | 27 ------- libft/ft_itoa.c | 62 --------------- libft/ft_lstadd_back_bonus.c | 31 -------- libft/ft_lstadd_front_bonus.c | 23 ------ libft/ft_lstclear_bonus.c | 34 --------- libft/ft_lstdelone_bonus.c | 25 ------ libft/ft_lstiter_bonus.c | 27 ------- libft/ft_lstlast_bonus.c | 25 ------ libft/ft_lstmap_bonus.c | 40 ---------- libft/ft_lstnew_bonus.c | 27 ------- libft/ft_lstsize_bonus.c | 30 -------- libft/ft_memccpy.c | 37 --------- libft/ft_memchr.c | 33 -------- libft/ft_memcmp.c | 35 --------- libft/ft_memcpy.c | 36 --------- libft/ft_memmove.c | 27 ------- libft/ft_memset.c | 33 -------- libft/ft_putchar_bonus.c | 20 ----- libft/ft_putchar_fd.c | 20 ----- libft/ft_putendl_bonus.c | 21 ----- libft/ft_putendl_fd.c | 21 ----- libft/ft_putnbr_bonus.c | 36 --------- libft/ft_putnbr_fd.c | 34 --------- libft/ft_putstr_bonus.c | 21 ----- libft/ft_putstr_fd.c | 21 ----- libft/ft_split.c | 109 -------------------------- libft/ft_sqrt_bonus.c | 27 ------- libft/ft_strcat_bonus.c | 32 -------- libft/ft_strchr.c | 31 -------- libft/ft_strcmp_bonus.c | 27 ------- libft/ft_strdup.c | 31 -------- libft/ft_strjoin.c | 68 ----------------- libft/ft_strlcat.c | 41 ---------- libft/ft_strlcpy.c | 33 -------- libft/ft_strlen.c | 27 ------- libft/ft_strmapi.c | 34 --------- libft/ft_strncmp.c | 31 -------- libft/ft_strnstr.c | 45 ----------- libft/ft_strrchr.c | 32 -------- libft/ft_strtrim.c | 30 -------- libft/ft_substr.c | 33 -------- libft/ft_tolower.c | 28 ------- libft/ft_toupper.c | 28 ------- libft/inc/libft.h | 98 ++++++++++++++++++++++++ libft/libft.h | 99 ------------------------ libft/main.c | 122 ----------------------------- libft/src/ft_atoi.c | 79 +++++++++++++++++++ libft/src/ft_bzero.c | 23 ++++++ libft/src/ft_calloc.c | 29 +++++++ libft/src/ft_isalnum.c | 22 ++++++ libft/src/ft_isalpha.c | 36 +++++++++ libft/src/ft_isascii.c | 20 +++++ libft/src/ft_isdigit.c | 20 +++++ libft/src/ft_isprint.c | 20 +++++ libft/src/ft_isspace.c | 27 +++++++ libft/src/ft_itoa.c | 62 +++++++++++++++ libft/src/ft_lstadd_back.c | 31 ++++++++ libft/src/ft_lstadd_front.c | 23 ++++++ libft/src/ft_lstclear.c | 34 +++++++++ libft/src/ft_lstdelone.c | 25 ++++++ libft/src/ft_lstiter.c | 27 +++++++ libft/src/ft_lstlast.c | 25 ++++++ libft/src/ft_lstmap.c | 40 ++++++++++ libft/src/ft_lstnew.c | 27 +++++++ libft/src/ft_lstsize.c | 30 ++++++++ libft/src/ft_memccpy.c | 37 +++++++++ libft/src/ft_memchr.c | 33 ++++++++ libft/src/ft_memcmp.c | 35 +++++++++ libft/src/ft_memcpy.c | 36 +++++++++ libft/src/ft_memmove.c | 27 +++++++ libft/src/ft_memset.c | 33 ++++++++ libft/src/ft_putchar.c | 20 +++++ libft/src/ft_putchar_fd.c | 20 +++++ libft/src/ft_putendl.c | 21 +++++ libft/src/ft_putendl_fd.c | 21 +++++ libft/src/ft_putnbr.c | 36 +++++++++ libft/src/ft_putnbr_fd.c | 34 +++++++++ libft/src/ft_putstr.c | 21 +++++ libft/src/ft_putstr_fd.c | 21 +++++ libft/src/ft_split.c | 109 ++++++++++++++++++++++++++ libft/src/ft_sqrt.c | 27 +++++++ libft/src/ft_strcat.c | 32 ++++++++ libft/src/ft_strchr.c | 31 ++++++++ libft/src/ft_strcmp.c | 27 +++++++ libft/src/ft_strdup.c | 31 ++++++++ libft/src/ft_strjoin.c | 68 +++++++++++++++++ libft/src/ft_strlcat.c | 41 ++++++++++ libft/src/ft_strlcpy.c | 33 ++++++++ libft/src/ft_strlen.c | 27 +++++++ libft/src/ft_strmapi.c | 34 +++++++++ libft/src/ft_strncmp.c | 31 ++++++++ libft/src/ft_strnlen.c | 27 +++++++ libft/src/ft_strnstr.c | 45 +++++++++++ libft/src/ft_strrchr.c | 32 ++++++++ libft/src/ft_strtrim.c | 30 ++++++++ libft/src/ft_substr.c | 33 ++++++++ libft/src/ft_tolower.c | 28 +++++++ libft/src/ft_toupper.c | 28 +++++++ 107 files changed, 1890 insertions(+), 1994 deletions(-) delete mode 100644 libft/ft_atoi.c delete mode 100644 libft/ft_bzero.c delete mode 100644 libft/ft_calloc.c delete mode 100644 libft/ft_isalnum.c delete mode 100644 libft/ft_isalpha.c delete mode 100644 libft/ft_isascii.c delete mode 100644 libft/ft_isdigit.c delete mode 100644 libft/ft_isprint.c delete mode 100644 libft/ft_isspace_bonus.c delete mode 100644 libft/ft_itoa.c delete mode 100644 libft/ft_lstadd_back_bonus.c delete mode 100644 libft/ft_lstadd_front_bonus.c delete mode 100644 libft/ft_lstclear_bonus.c delete mode 100644 libft/ft_lstdelone_bonus.c delete mode 100644 libft/ft_lstiter_bonus.c delete mode 100644 libft/ft_lstlast_bonus.c delete mode 100644 libft/ft_lstmap_bonus.c delete mode 100644 libft/ft_lstnew_bonus.c delete mode 100644 libft/ft_lstsize_bonus.c delete mode 100644 libft/ft_memccpy.c delete mode 100644 libft/ft_memchr.c delete mode 100644 libft/ft_memcmp.c delete mode 100644 libft/ft_memcpy.c delete mode 100644 libft/ft_memmove.c delete mode 100644 libft/ft_memset.c delete mode 100644 libft/ft_putchar_bonus.c delete mode 100644 libft/ft_putchar_fd.c delete mode 100644 libft/ft_putendl_bonus.c delete mode 100644 libft/ft_putendl_fd.c delete mode 100644 libft/ft_putnbr_bonus.c delete mode 100644 libft/ft_putnbr_fd.c delete mode 100644 libft/ft_putstr_bonus.c delete mode 100644 libft/ft_putstr_fd.c delete mode 100644 libft/ft_split.c delete mode 100644 libft/ft_sqrt_bonus.c delete mode 100644 libft/ft_strcat_bonus.c delete mode 100644 libft/ft_strchr.c delete mode 100644 libft/ft_strcmp_bonus.c delete mode 100644 libft/ft_strdup.c delete mode 100644 libft/ft_strjoin.c delete mode 100644 libft/ft_strlcat.c delete mode 100644 libft/ft_strlcpy.c delete mode 100644 libft/ft_strlen.c delete mode 100644 libft/ft_strmapi.c delete mode 100644 libft/ft_strncmp.c delete mode 100644 libft/ft_strnstr.c delete mode 100644 libft/ft_strrchr.c delete mode 100644 libft/ft_strtrim.c delete mode 100644 libft/ft_substr.c delete mode 100644 libft/ft_tolower.c delete mode 100644 libft/ft_toupper.c create mode 100644 libft/inc/libft.h delete mode 100644 libft/libft.h delete mode 100644 libft/main.c create mode 100644 libft/src/ft_atoi.c create mode 100644 libft/src/ft_bzero.c create mode 100644 libft/src/ft_calloc.c create mode 100644 libft/src/ft_isalnum.c create mode 100644 libft/src/ft_isalpha.c create mode 100644 libft/src/ft_isascii.c create mode 100644 libft/src/ft_isdigit.c create mode 100644 libft/src/ft_isprint.c create mode 100644 libft/src/ft_isspace.c create mode 100644 libft/src/ft_itoa.c create mode 100644 libft/src/ft_lstadd_back.c create mode 100644 libft/src/ft_lstadd_front.c create mode 100644 libft/src/ft_lstclear.c create mode 100644 libft/src/ft_lstdelone.c create mode 100644 libft/src/ft_lstiter.c create mode 100644 libft/src/ft_lstlast.c create mode 100644 libft/src/ft_lstmap.c create mode 100644 libft/src/ft_lstnew.c create mode 100644 libft/src/ft_lstsize.c create mode 100644 libft/src/ft_memccpy.c create mode 100644 libft/src/ft_memchr.c create mode 100644 libft/src/ft_memcmp.c create mode 100644 libft/src/ft_memcpy.c create mode 100644 libft/src/ft_memmove.c create mode 100644 libft/src/ft_memset.c create mode 100644 libft/src/ft_putchar.c create mode 100644 libft/src/ft_putchar_fd.c create mode 100644 libft/src/ft_putendl.c create mode 100644 libft/src/ft_putendl_fd.c create mode 100644 libft/src/ft_putnbr.c create mode 100644 libft/src/ft_putnbr_fd.c create mode 100644 libft/src/ft_putstr.c create mode 100644 libft/src/ft_putstr_fd.c create mode 100644 libft/src/ft_split.c create mode 100644 libft/src/ft_sqrt.c create mode 100644 libft/src/ft_strcat.c create mode 100644 libft/src/ft_strchr.c create mode 100644 libft/src/ft_strcmp.c create mode 100644 libft/src/ft_strdup.c create mode 100644 libft/src/ft_strjoin.c create mode 100644 libft/src/ft_strlcat.c create mode 100644 libft/src/ft_strlcpy.c create mode 100644 libft/src/ft_strlen.c create mode 100644 libft/src/ft_strmapi.c create mode 100644 libft/src/ft_strncmp.c create mode 100644 libft/src/ft_strnlen.c create mode 100644 libft/src/ft_strnstr.c create mode 100644 libft/src/ft_strrchr.c create mode 100644 libft/src/ft_strtrim.c create mode 100644 libft/src/ft_substr.c create mode 100644 libft/src/ft_tolower.c create mode 100644 libft/src/ft_toupper.c (limited to 'libft') diff --git a/libft/Makefile b/libft/Makefile index fbe5c6e..83c4b54 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -11,114 +11,106 @@ # / # # **************************************************************************** # -SRCS_DIR = ./ - +SRCS_DIR = src/ SRCS = \ - ft_memset.c \ - ft_bzero.c \ - ft_memcpy.c \ - ft_memccpy.c \ - ft_memmove.c \ - ft_memchr.c \ - ft_memcmp.c \ - ft_strlen.c \ - ft_isalpha.c \ - ft_isdigit.c \ - ft_isalnum.c \ - ft_isascii.c \ - ft_isprint.c \ - ft_tolower.c \ - ft_toupper.c \ - ft_strchr.c \ - ft_strrchr.c \ - ft_strncmp.c \ - ft_strlcpy.c \ - ft_strlcat.c \ - ft_strnstr.c \ - ft_atoi.c \ - ft_calloc.c \ - ft_strdup.c \ - \ - ft_substr.c \ - ft_strjoin.c \ - ft_strtrim.c \ - ft_split.c \ - ft_itoa.c \ - ft_strmapi.c \ - ft_putchar_fd.c \ - ft_putstr_fd.c \ - ft_putendl_fd.c \ - ft_putnbr_fd.c - -BONUS_SRCS_DIR = ./ - -BONUS_SRCS = \ - ft_lstnew_bonus.c \ - ft_lstadd_front_bonus.c \ - ft_lstsize_bonus.c \ - ft_lstlast_bonus.c \ - ft_lstadd_back_bonus.c \ - ft_lstdelone_bonus.c \ - ft_lstclear_bonus.c \ - ft_lstiter_bonus.c \ - ft_lstmap_bonus.c \ - ft_putchar_bonus.c \ - ft_putstr_bonus.c \ - ft_putendl_bonus.c \ - ft_putnbr_bonus.c \ - ft_strcat_bonus.c \ - ft_strcmp_bonus.c \ - ft_isspace_bonus.c \ - ft_sqrt_bonus.c - -OBJS_DIR = ./ - -#OBJS = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS}) - -OBJS = ${SRCS:.c=.o} - -BONUS_OBJS_DIR = ./ - -B_OBJS = ${BONUS_SRCS:.c=.o} - -#B_OBJS = \ - $(patsubst ${SRCS_DIR}bonus/%.c,${OBJS_DIR}bonus/%.o,${BONUS_SRCS}) - -INCS_DIR = ./ - -CC = gcc - + ${SRCS_DIR}ft_memset.c \ + ${SRCS_DIR}ft_bzero.c \ + ${SRCS_DIR}ft_memcpy.c \ + ${SRCS_DIR}ft_memccpy.c \ + ${SRCS_DIR}ft_memmove.c \ + ${SRCS_DIR}ft_memchr.c \ + ${SRCS_DIR}ft_memcmp.c \ + ${SRCS_DIR}ft_strlen.c \ + ${SRCS_DIR}ft_isalpha.c \ + ${SRCS_DIR}ft_isdigit.c \ + ${SRCS_DIR}ft_isalnum.c \ + ${SRCS_DIR}ft_isascii.c \ + ${SRCS_DIR}ft_isprint.c \ + ${SRCS_DIR}ft_tolower.c \ + ${SRCS_DIR}ft_toupper.c \ + ${SRCS_DIR}ft_strchr.c \ + ${SRCS_DIR}ft_strrchr.c \ + ${SRCS_DIR}ft_strncmp.c \ + ${SRCS_DIR}ft_strlcpy.c \ + ${SRCS_DIR}ft_strlcat.c \ + ${SRCS_DIR}ft_strnstr.c \ + ${SRCS_DIR}ft_atoi.c \ + ${SRCS_DIR}ft_calloc.c \ + ${SRCS_DIR}ft_strdup.c \ + \ + ${SRCS_DIR}ft_substr.c \ + ${SRCS_DIR}ft_strjoin.c \ + ${SRCS_DIR}ft_strtrim.c \ + ${SRCS_DIR}ft_split.c \ + ${SRCS_DIR}ft_itoa.c \ + ${SRCS_DIR}ft_strmapi.c \ + ${SRCS_DIR}ft_putchar_fd.c \ + ${SRCS_DIR}ft_putstr_fd.c \ + ${SRCS_DIR}ft_putendl_fd.c \ + ${SRCS_DIR}ft_putnbr_fd.c \ + \ + ${SRCS_DIR}ft_lstnew.c \ + ${SRCS_DIR}ft_lstadd_front.c \ + ${SRCS_DIR}ft_lstsize.c \ + ${SRCS_DIR}ft_lstlast.c \ + ${SRCS_DIR}ft_lstadd_back.c \ + ${SRCS_DIR}ft_lstdelone.c \ + ${SRCS_DIR}ft_lstclear.c \ + ${SRCS_DIR}ft_lstiter.c \ + ${SRCS_DIR}ft_lstmap.c \ + ${SRCS_DIR}ft_putchar.c \ + ${SRCS_DIR}ft_putstr.c \ + ${SRCS_DIR}ft_putendl.c \ + ${SRCS_DIR}ft_putnbr.c \ + ${SRCS_DIR}ft_strnlen.c \ + ${SRCS_DIR}ft_strcat.c \ + ${SRCS_DIR}ft_strcmp.c \ + ${SRCS_DIR}ft_isspace.c \ + ${SRCS_DIR}ft_sqrt.c + +OBJS_DIR = obj/ +OBJS = $(patsubst ${SRCS_DIR}%.c,${OBJS_DIR}%.o,${SRCS}) + +INCS_DIR = inc/ +INCS = libft.h + +CC = clang CFLAGS = -Wall -Wextra -Werror +DEBUG = -g3 +FSANITIZE = -fsanitize=address + +AR = ar rcs NAME = libft.a +MKDIR = mkdir -p RM = rm -rf -AR = ar rcs - -%.o: %.c - ${CC} ${CFLAGS} -I${INCS_DIR} -c $< -o $@ +${OBJS_DIR}%.o: ${SRCS_DIR}%.c ${INCS_DIR}${INCS} + @if [ ! -a ${OBJS_DIR} ]; then \ + ${MKDIR} ${OBJS_DIR}; \ + fi + @${CC} ${CFLAGS} -I${INCS_DIR} -c $< -o $@ + @echo "Compiled $(subst ${OBJS_DIR},,$@)!" $(NAME): ${OBJS} - ${AR} ${NAME} ${OBJS} + @${AR} ${NAME} ${OBJS} + @echo + @echo "libft.a linked!" all: ${NAME} -bonus: all ${B_OBJS} - ${AR} ${NAME} ${B_OBJS} - clean: - ${RM} ${OBJS} ${B_OBJS} + @${RM} ${OBJS} + @echo "Removed obj files!" fclean: clean - ${RM} ${NAME} + @${RM} ${OBJS_DIR} + @${RM} ${NAME} + @echo "Removed everything!" re: fclean all -build: ${OBJS} ${B_OBJS} - ${CC} ${CFLAGS} -g3 -fsanitize=address -I./ -o a.out \ - ${OBJS} ${B_OBJS} main.c - default: all -.PHONY: all clean clean fclean re bonus run +.PHONY: all clean clean fclean re diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c deleted file mode 100644 index 8903606..0000000 --- a/libft/ft_atoi.c +++ /dev/null @@ -1,79 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_atoi.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/10 05:32:13 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/15 02:16:20 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -static uint8_t - ft_isaspace(int c) -{ - if (c == '\t' || - c == '\n' || - c == '\v' || - c == '\f' || - c == '\r' || - c == ' ') - return (1); - return (0); -} - -static int8_t - ft_setsign(const char c) -{ - int8_t sign; - - sign = 1; - if (c == '-') - sign = -1; - return (sign); -} - -static uint8_t - ft_seti(const char *str) -{ - uint8_t i; - - i = 0; - while (ft_isaspace(str[i])) - i++; - return (i); -} - -int - ft_atoi(const char *str) -{ - uint8_t i; - int8_t sign; - long nb; - - if (!str || !*str) - return (0); - i = ft_seti(str); - nb = 0; - sign = 1; - if (str[i] == '+' || str[i] == '-') - sign = ft_setsign(str[i++]); - while (ft_isdigit(str[i])) - { - if (nb * 10 + (str[i] - 48) < nb) - { - if (sign < 0) - return (0); - return (-1); - } - nb = nb * 10 + (str[i] - 48); - i++; - } - nb *= sign; - return ((int)nb); -} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c deleted file mode 100644 index 05ff6b7..0000000 --- a/libft/ft_bzero.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_bzero.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 14:04:55 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:45:28 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -void - ft_bzero(void *s, size_t n) -{ - if (!s) - return ; - ft_memset(s, 0, n); -} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c deleted file mode 100644 index 49383da..0000000 --- a/libft/ft_calloc.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_calloc.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/11 02:47:15 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:43:53 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include -#include - -void - *ft_calloc(size_t count, size_t size) -{ - void *ptr; - - ptr = 0; - ptr = malloc(count * size); - if (!ptr) - return (NULL); - ft_bzero(ptr, count * size); - return (ptr); -} diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c deleted file mode 100644 index e9e1134..0000000 --- a/libft/ft_isalnum.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_isalnum.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 18:07:44 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:45:57 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -int - ft_isalnum(int c) -{ - if (ft_isalpha(c) || ft_isdigit(c)) - return (1); - return (0); -} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c deleted file mode 100644 index 9e95bd6..0000000 --- a/libft/ft_isalpha.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_isalpha.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 16:45:42 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:42:03 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -static int - ft_isupper(int c) -{ - if (c >= 65 && c <= 90) - return (1); - return (0); -} - -static int - ft_islower(int c) -{ - if (c >= 97 && c <= 122) - return (1); - return (0); -} - -int - ft_isalpha(int c) -{ - if (ft_isupper(c) || ft_islower(c)) - return (1); - return (0); -} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c deleted file mode 100644 index 937ead5..0000000 --- a/libft/ft_isascii.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_isascii.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 18:18:31 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:41:32 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -int - ft_isascii(int c) -{ - if (c >= 0 && c <= 127) - return (1); - return (0); -} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c deleted file mode 100644 index 52ededc..0000000 --- a/libft/ft_isdigit.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_isdigit.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 17:46:41 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:41:27 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -int - ft_isdigit(int c) -{ - if (c >= 48 && c <= 57) - return (1); - return (0); -} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c deleted file mode 100644 index d82ded0..0000000 --- a/libft/ft_isprint.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_isprint.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 18:23:39 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:41:21 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -int - ft_isprint(int c) -{ - if (c >= 32 && c <= 126) - return (1); - return (0); -} diff --git a/libft/ft_isspace_bonus.c b/libft/ft_isspace_bonus.c deleted file mode 100644 index c9cf255..0000000 --- a/libft/ft_isspace_bonus.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_isspace.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/10 05:57:19 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:44:18 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -uint8_t - ft_isspace(int c) -{ - if (c == '\t' || - c == '\n' || - c == '\v' || - c == '\f' || - c == '\r' || - c == ' ') - return (1); - return (0); -} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c deleted file mode 100644 index bf3c0c8..0000000 --- a/libft/ft_itoa.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_itoa.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 02:22:48 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 13:35:46 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include -#include - -static uint8_t - ft_intlen(int n) -{ - uint8_t len; - - len = 0; - if (!n) - return (1); - if (n < 0) - len = 1; - while (n != 0) - { - n /= 10; - len++; - } - return (len); -} - -char - *ft_itoa(int n) -{ - char *s; - unsigned int nb; - uint8_t i; - - i = ft_intlen(n) - 1; - if (!(s = (char*)malloc((i + 2) * sizeof(char)))) - return (NULL); - if (!n) - s[i] = '0'; - nb = n; - if (n < 0) - { - s[0] = '-'; - nb = -n; - } - s[i + 1] = '\0'; - while (nb > 0) - { - s[i] = 48 + (nb % 10); - nb = nb / 10; - i--; - } - return (s); -} diff --git a/libft/ft_lstadd_back_bonus.c b/libft/ft_lstadd_back_bonus.c deleted file mode 100644 index 58b3a72..0000000 --- a/libft/ft_lstadd_back_bonus.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstadd_back.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 10:04:16 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 10:11:08 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -void - ft_lstadd_back(t_list **alst, t_list *new) -{ - t_list *tmp; - - if (!alst || !new) - return ; - if (!*alst) - *alst = new; - else - { - tmp = ft_lstlast(*alst); - tmp->next = new; - } -} diff --git a/libft/ft_lstadd_front_bonus.c b/libft/ft_lstadd_front_bonus.c deleted file mode 100644 index c9515ea..0000000 --- a/libft/ft_lstadd_front_bonus.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstadd_front.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 09:31:45 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 10:11:10 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -void - ft_lstadd_front(t_list **alst, t_list *new) -{ - if (!alst || !new) - return ; - new->next = *alst; - *alst = new; -} diff --git a/libft/ft_lstclear_bonus.c b/libft/ft_lstclear_bonus.c deleted file mode 100644 index 8d97b9c..0000000 --- a/libft/ft_lstclear_bonus.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstclear.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 10:19:53 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 13:52:03 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -void - ft_lstclear(t_list **lst, void (*del)(void *)) -{ - t_list *tmp; - t_list *renext; - - if (!lst) - return ; - tmp = *lst; - while (tmp) - { - renext = tmp->next; - del(tmp->content); - free(tmp); - tmp = renext; - } - *lst = NULL; -} diff --git a/libft/ft_lstdelone_bonus.c b/libft/ft_lstdelone_bonus.c deleted file mode 100644 index 42a1da8..0000000 --- a/libft/ft_lstdelone_bonus.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstdelone.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 10:11:20 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 10:18:40 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -void - ft_lstdelone(t_list *lst, void (*del)(void *)) -{ - if (lst) - { - del(lst->content); - free(lst); - } -} diff --git a/libft/ft_lstiter_bonus.c b/libft/ft_lstiter_bonus.c deleted file mode 100644 index 3129ab5..0000000 --- a/libft/ft_lstiter_bonus.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstiter.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 10:30:22 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 11:01:22 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -void - ft_lstiter(t_list *lst, void (*f)(void *)) -{ - if (!lst) - return ; - while (lst != NULL) - { - (*f)(lst->content); - lst = lst->next; - } -} diff --git a/libft/ft_lstlast_bonus.c b/libft/ft_lstlast_bonus.c deleted file mode 100644 index a685322..0000000 --- a/libft/ft_lstlast_bonus.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstlast.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 09:53:13 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 10:11:09 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -t_list - *ft_lstlast(t_list *lst) -{ - if (!lst) - return (NULL); - while (lst->next != NULL) - lst = lst->next; - return (lst); -} diff --git a/libft/ft_lstmap_bonus.c b/libft/ft_lstmap_bonus.c deleted file mode 100644 index 474b1bc..0000000 --- a/libft/ft_lstmap_bonus.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstmap.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 10:36:15 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 11:06:32 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include -#include - -t_list - *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) -{ - t_list *nlst; - t_list *new; - - if (!lst) - return (NULL); - nlst = ft_lstnew((*f)(lst->content)); - if (!nlst) - return (NULL); - lst = lst->next; - while (lst != NULL) - { - new = ft_lstnew((*f)(lst->content)); - (*del)(lst->content); - if (!new) - return (NULL); - lst = lst->next; - ft_lstadd_back(&nlst, new); - } - return (nlst); -} diff --git a/libft/ft_lstnew_bonus.c b/libft/ft_lstnew_bonus.c deleted file mode 100644 index a5e1c0a..0000000 --- a/libft/ft_lstnew_bonus.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstnew.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 09:25:56 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 10:56:17 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list - *ft_lstnew(void *content) -{ - t_list *nlst; - - nlst = (t_list*)ft_calloc(1, sizeof(t_list)); - if (!nlst) - return (NULL); - nlst->content = content; - nlst->next = NULL; - return (nlst); -} diff --git a/libft/ft_lstsize_bonus.c b/libft/ft_lstsize_bonus.c deleted file mode 100644 index 1742a5f..0000000 --- a/libft/ft_lstsize_bonus.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_lstsize.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 09:45:10 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 09:51:16 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -int - ft_lstsize(t_list *lst) -{ - int i; - - if (!lst) - return (0); - i = 0; - while (lst != NULL) - { - lst = lst->next; - i++; - } - return (i); -} diff --git a/libft/ft_memccpy.c b/libft/ft_memccpy.c deleted file mode 100644 index a029e7d..0000000 --- a/libft/ft_memccpy.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_memccpy.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 14:59:46 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:40:44 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include -#include - -void - *ft_memccpy(void *dst, const void *src, int c, size_t n) -{ - unsigned char *dst_ptr; - const unsigned char *src_ptr; - - dst_ptr = (unsigned char*)dst; - src_ptr = (unsigned char*)src; - if (!*dst_ptr && !*src_ptr && n) - return (NULL); - if (n) - { - while (n) - { - if ((*dst_ptr++ = *src_ptr++) == (unsigned char)c) - return (dst_ptr); - n--; - } - } - return (NULL); -} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c deleted file mode 100644 index c2578aa..0000000 --- a/libft/ft_memchr.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_memchr.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 19:14:54 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:40:23 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -void - *ft_memchr(const void *s, int c, size_t n) -{ - unsigned char *s_ptr; - size_t i; - - if (!s) - return (NULL); - i = 0; - s_ptr = (unsigned char*)s; - while (i < n) - { - if (s_ptr[i] == (unsigned char)c) - return ((char*)&s[i]); - i++; - } - return (NULL); -} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c deleted file mode 100644 index 59a99bd..0000000 --- a/libft/ft_memcmp.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_memcmp.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 19:23:43 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:40:10 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -int - ft_memcmp(const void *s1, const void *s2, size_t n) -{ - const unsigned char *s1_ptr; - const unsigned char *s2_ptr; - - s1_ptr = (unsigned char*)s1; - s2_ptr = (unsigned char*)s2; - if (!s1 || !s2) - return (0); - while (n) - { - if (*s1_ptr != *s2_ptr) - return (*s1_ptr - *s2_ptr); - s1_ptr++; - s2_ptr++; - n--; - } - return (0); -} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c deleted file mode 100644 index 548ea95..0000000 --- a/libft/ft_memcpy.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_memcpy.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 14:17:11 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:39:01 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include -#include - -void - *ft_memcpy(void *dst, const void *src, size_t n) -{ - unsigned char *dst_ptr; - unsigned char *src_ptr; - size_t i; - - dst_ptr = (unsigned char*)dst; - src_ptr = (unsigned char*)src; - i = 0; - if (src_ptr == NULL && dst_ptr == NULL && n != 0) - return (NULL); - while (i < n) - { - dst_ptr[i] = src_ptr[i]; - i++; - } - return (dst_ptr); -} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c deleted file mode 100644 index 000a2b7..0000000 --- a/libft/ft_memmove.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_memmove.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 18:57:44 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:38:47 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -void - *ft_memmove(void *dst, const void *src, size_t len) -{ - char buff[len]; - - if (src == NULL && dst == NULL && len != 0) - return (NULL); - ft_memcpy(buff, src, len); - ft_memcpy(dst, buff, len); - return (dst); -} diff --git a/libft/ft_memset.c b/libft/ft_memset.c deleted file mode 100644 index b94c6fa..0000000 --- a/libft/ft_memset.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_memset.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 13:41:09 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:38:10 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -void - *ft_memset(void *b, int c, size_t len) -{ - unsigned char *str; - - str = b; - if (!b) - return (NULL); - if (!len) - return (b); - while (len > 0) - { - *str = (unsigned char)c; - str++; - len--; - } - return (b); -} diff --git a/libft/ft_putchar_bonus.c b/libft/ft_putchar_bonus.c deleted file mode 100644 index b558ead..0000000 --- a/libft/ft_putchar_bonus.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putchar.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/12 15:02:55 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/15 01:10:32 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -int - ft_putchar(int c) -{ - return (write(1, &c, 1)); -} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c deleted file mode 100644 index f57a4f9..0000000 --- a/libft/ft_putchar_fd.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putchar_fd.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 08:27:19 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:49:34 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -void - ft_putchar_fd(char c, int fd) -{ - write(fd, &c, 1); -} diff --git a/libft/ft_putendl_bonus.c b/libft/ft_putendl_bonus.c deleted file mode 100644 index 26dc80b..0000000 --- a/libft/ft_putendl_bonus.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putendl.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/15 05:19:52 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/15 05:19:53 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -int - ft_putendl(const char *s) -{ - return (write(1, s, ft_strlen(s)) + ft_putchar('\n')); -} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c deleted file mode 100644 index 39fe7c1..0000000 --- a/libft/ft_putendl_fd.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putendl_fd.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 08:52:34 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 09:01:41 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -void - ft_putendl_fd(char *s, int fd) -{ - ft_putstr_fd(s, fd); - ft_putchar_fd('\n', fd); -} diff --git a/libft/ft_putnbr_bonus.c b/libft/ft_putnbr_bonus.c deleted file mode 100644 index 5220151..0000000 --- a/libft/ft_putnbr_bonus.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putnbr.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/08/08 12:22:48 by rbousset #+# ## ## #+# */ -/* Updated: 2019/08/12 17:54:48 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -int - ft_putnbr(int nb) -{ - unsigned int i; - - i = nb; - if (nb < 0) - { - ft_putchar('-'); - i = -nb; - } - if (i > 9) - { - ft_putnbr(i / 10); - ft_putchar((i % 10) + '0'); - } - else - ft_putchar(i + '0'); - return (0); -} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c deleted file mode 100644 index b240f43..0000000 --- a/libft/ft_putnbr_fd.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putnbr_fd.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 08:57:19 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 12:13:09 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -void - ft_putnbr_fd(int n, int fd) -{ - unsigned int i; - - i = n; - if (n < 0) - { - ft_putchar_fd('-', fd); - i = -n; - } - if (i > 9) - { - ft_putnbr_fd(i / 10, fd); - ft_putchar_fd((i % 10) + 48, fd); - } - else - ft_putchar_fd(i + 48, fd); -} diff --git a/libft/ft_putstr_bonus.c b/libft/ft_putstr_bonus.c deleted file mode 100644 index d29a940..0000000 --- a/libft/ft_putstr_bonus.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putstr.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 09:05:27 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 09:07:45 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -int - ft_putstr(const char *s) -{ - return (write(1, s, ft_strlen(s))); -} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c deleted file mode 100644 index b90c078..0000000 --- a/libft/ft_putstr_fd.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_putstr_fd.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 08:48:25 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 09:00:42 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -void - ft_putstr_fd(char *s, int fd) -{ - write(fd, s, ft_strlen(s)); -} diff --git a/libft/ft_split.c b/libft/ft_split.c deleted file mode 100644 index 7c706cf..0000000 --- a/libft/ft_split.c +++ /dev/null @@ -1,109 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_split.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/12 19:24:20 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:37:16 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include -#include -#include - -static uint8_t - ft_check(int c, char sep) -{ - if (c == sep) - return (1); - return (0); -} - -static size_t - ft_strlen_plus(const char *str, char c) -{ - size_t i; - size_t count; - uint8_t ibool; - - i = 0; - count = 0; - ibool = 1; - while (str[i]) - { - while (ft_check(str[i], c) && str[i]) - i++; - while (!ft_check(str[i], c) && str[i]) - { - if (ibool == 1) - count++; - ibool = 0; - i++; - } - ibool = 1; - } - return (count); -} - -static size_t - ft_strlen_again(const char *str, char c) -{ - size_t i; - - i = 0; - while (!ft_check(str[i], c) && str[i]) - i++; - return (i); -} - -static char - *ft_strdup_plus(const char *src, char c) -{ - size_t i; - size_t slen; - char *nstr; - - i = 0; - slen = ft_strlen_again(src, c) + 1; - if (!(nstr = (char*)ft_calloc(slen, sizeof(char)))) - return (NULL); - while (!ft_check(src[i], c) && src[i]) - { - nstr[i] = src[i]; - i++; - } - nstr[i] = '\0'; - return (nstr); -} - -char - **ft_split(const char *s, char c) -{ - size_t i; - size_t j; - char **best_split; - - i = 0; - j = 0; - if (!(best_split = (char **)ft_calloc(ft_strlen_plus(s, c) + 1, - sizeof(char *)))) - return (NULL); - while (s[i]) - { - while (ft_check(s[i], c) && s[i]) - i++; - while (!ft_check(s[i], c) && s[i]) - { - best_split[j] = ft_strdup_plus(&s[i], c); - i += ft_strlen_again(&s[i], c); - j++; - } - } - best_split[j] = 0; - return (best_split); -} diff --git a/libft/ft_sqrt_bonus.c b/libft/ft_sqrt_bonus.c deleted file mode 100644 index 3003e6d..0000000 --- a/libft/ft_sqrt_bonus.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_sqrt.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/08/10 21:34:14 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/14 23:26:06 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -double - ft_sqrt(double x) -{ - double i; - - i = 0.0000001; - while (i * i < x && i * i < INT_MAX) - { - i += 0.0000001; - } - return (i); -} diff --git a/libft/ft_strcat_bonus.c b/libft/ft_strcat_bonus.c deleted file mode 100644 index 59084c2..0000000 --- a/libft/ft_strcat_bonus.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strcat.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/12 16:31:34 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:44:34 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -char - *ft_strcat(char *s1, const char *s2) -{ - int i; - int j; - - i = 0; - j = 0; - while (s1[i] != '\0') - i++; - while (s2[j] != '\0') - { - s1[i] = s2[j]; - i++; - j++; - } - s1[i] = '\0'; - return (s1); -} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c deleted file mode 100644 index 86bd41d..0000000 --- a/libft/ft_strchr.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strchr.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 18:39:17 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:36:43 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -char - *ft_strchr(const char *s, int c) -{ - size_t i; - - i = 0; - if (!s) - return (NULL); - while (s[i] != c) - { - if (!s[i]) - return (NULL); - i++; - } - return ((char*)&s[i]); -} diff --git a/libft/ft_strcmp_bonus.c b/libft/ft_strcmp_bonus.c deleted file mode 100644 index 2e9ffe9..0000000 --- a/libft/ft_strcmp_bonus.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strcmp.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 13:55:24 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 13:56:42 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -int - ft_strcmp(const char *s1, const char *s2) -{ - size_t i; - int diff; - - i = 0; - while (s1[i] == s2[i]) - i++; - diff = s1[i] - s2[i]; - return (diff); -} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c deleted file mode 100644 index ce74fb5..0000000 --- a/libft/ft_strdup.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strdup.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/11 05:45:32 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:36:24 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -char - *ft_strdup(const char *s1) -{ - size_t slen; - char *new_str; - - new_str = ""; - slen = ft_strlen(s1); - new_str = (char *)malloc((slen + 1) * sizeof(char)); - if (new_str == NULL) - return (NULL); - ft_memcpy(new_str, s1, slen); - new_str[slen] = '\0'; - return (new_str); -} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c deleted file mode 100644 index f666781..0000000 --- a/libft/ft_strjoin.c +++ /dev/null @@ -1,68 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strjoin.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/12 16:35:23 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:36:17 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -size_t - ft_strleen(const char *s) -{ - size_t i; - - i = 0; - while (s[i] != '\0') - i++; - return (i); -} - -static char - *ft_recalloc(size_t size) -{ - char *str; - - str = 0; - str = malloc((size + 1) * sizeof(char)); - if (!str) - return (NULL); - ft_bzero(str, size); - return (str); -} - -char - *ft_strjoin(const char *s1, const char *s2) -{ - char *str; - size_t i; - size_t j; - size_t size; - - size = (ft_strleen(s1) + ft_strleen(s2)); - str = (char*)ft_recalloc(ft_strleen(s1) + ft_strleen(s2)); - i = 0; - j = 0; - if (!str) - return (NULL); - while (i < ft_strleen(s1)) - { - str[i] = s1[i]; - i++; - } - while (i < size) - { - str[i] = s2[j]; - i++; - j++; - } - str[i] = '\0'; - return (str); -} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c deleted file mode 100644 index 98fa3e8..0000000 --- a/libft/ft_strlcat.c +++ /dev/null @@ -1,41 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strlcat.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/09 06:44:30 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:36:04 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -static size_t - ft_strlen_size(const char *s, size_t size) -{ - const char *ptr = s; - - while (size > 0 && *ptr) - { - size--; - ptr++; - } - return (ptr - s); -} - -size_t - ft_strlcat(char *dst, const char *src, size_t size) -{ - size_t dst_len; - - if (!dst || !src) - return (0); - dst_len = ft_strlen_size(dst, size); - if (dst_len == size) - return (dst_len + ft_strlen(src)); - return (dst_len + ft_strlcpy(dst + dst_len, src, size - dst_len)); -} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c deleted file mode 100644 index bba4263..0000000 --- a/libft/ft_strlcpy.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strlcpy.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/08 20:44:40 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:35:51 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -size_t - ft_strlcpy(char *dst, const char *src, size_t size) -{ - size_t src_len; - - if (!dst || !src) - return (0); - src_len = ft_strlen(src); - if (src_len + 1 < size) - ft_memcpy(dst, src, src_len + 1); - else if (size != 0) - { - ft_memcpy(dst, src, size - 1); - dst[size - 1] = 0; - } - return (src_len); -} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c deleted file mode 100644 index 68c7614..0000000 --- a/libft/ft_strlen.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strlen.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 16:32:28 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:35:37 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -size_t - ft_strlen(const char *s) -{ - size_t i; - - i = 0; - if (!s) - return (0); - while (s[i] != '\0') - i++; - return (i); -} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c deleted file mode 100644 index 7a38ca9..0000000 --- a/libft/ft_strmapi.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strmapi.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/13 05:57:35 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:35:12 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -char - *ft_strmapi(const char *s, char (*f)(unsigned int, char)) -{ - unsigned int i; - char *nstr; - - if (!s) - return (NULL); - i = 0; - nstr = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char)); - if (!nstr) - return (NULL); - while (s[i]) - { - nstr[i] = (*f)(i, s[i]); - i++; - } - return (nstr); -} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c deleted file mode 100644 index c8a0b87..0000000 --- a/libft/ft_strncmp.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strncmp.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 20:25:31 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:35:01 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include - -int - ft_strncmp(const char *s1, const char *s2, size_t n) -{ - size_t i; - - i = 0; - if (!s1 || !s2 || !n) - return (0); - while (s1[i] == s2[i] && i < n - 1) - { - if (s1[i] == '\0' && s2[i] == '\0') - return (0); - i++; - } - return ((unsigned char)s1[i] - (unsigned char)s2[i]); -} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c deleted file mode 100644 index 583026e..0000000 --- a/libft/ft_strnstr.c +++ /dev/null @@ -1,45 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strnstr.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/10 00:23:15 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:34:35 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include -#include - -char - *ft_strnstr(const char *haystack, const char *needle, size_t len) -{ - unsigned long i; - unsigned long j; - char *hay_ptr; - char *nee_ptr; - - hay_ptr = (char*)haystack; - nee_ptr = (char*)needle; - i = 0; - if (!nee_ptr[0]) - return (hay_ptr); - while (hay_ptr[i] && i < len) - { - j = 0; - while (nee_ptr[j] == hay_ptr[i + j] && (i + j) < len) - { - if (!nee_ptr[j + 1]) - return (hay_ptr + i); - j++; - } - if (!hay_ptr[i + 1] && !j) - return (0); - i++; - } - return (0); -} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c deleted file mode 100644 index 47ba95b..0000000 --- a/libft/ft_strrchr.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strrchr.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 19:07:53 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:34:19 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -char - *ft_strrchr(const char *s, int c) -{ - size_t i; - - if (!s) - return (NULL); - i = ft_strlen(s); - while (s[i] != c) - { - if (!i) - return (NULL); - i--; - } - return ((char*)&s[i]); -} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c deleted file mode 100644 index c691815..0000000 --- a/libft/ft_strtrim.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_strtrim.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/12 17:30:33 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:34:03 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" - -char - *ft_strtrim(const char *s1, const char *set) -{ - size_t len; - - len = 0; - if (!s1 || !set) - return (NULL); - while (*s1 && ft_strchr(set, *s1)) - s1++; - len = ft_strlen(s1); - while (len > 0 && ft_strchr(set, s1[len - 1])) - len--; - return (ft_substr(s1, 0, len)); -} diff --git a/libft/ft_substr.c b/libft/ft_substr.c deleted file mode 100644 index 87c2568..0000000 --- a/libft/ft_substr.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_substr.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/12 15:37:02 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:33:09 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -#include "libft.h" -#include - -char - *ft_substr(const char *s, unsigned int start, size_t len) -{ - char *nstr; - - if (start > ft_strlen(s) - 1) - { - nstr = (char*)ft_calloc(1, sizeof(char)); - if (!nstr) - return (NULL); - return (nstr); - } - nstr = (char*)ft_calloc(len + 1, sizeof(char)); - if (!nstr) - return (NULL); - return ((char*)ft_memcpy(nstr, s + start, len)); -} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c deleted file mode 100644 index 48c065e..0000000 --- a/libft/ft_tolower.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_tolower.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 18:32:59 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:32:22 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -static int - ft_isupper(int c) -{ - if (c >= 65 && c <= 90) - return (1); - return (0); -} - -int - ft_tolower(int c) -{ - if (ft_isupper(c)) - return (c + 32); - return (c); -} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c deleted file mode 100644 index 3346cc3..0000000 --- a/libft/ft_toupper.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* ft_toupper.c .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 18:25:57 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 08:32:15 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -static int - ft_islower(int c) -{ - if (c >= 97 && c <= 122) - return (1); - return (0); -} - -int - ft_toupper(int c) -{ - if (ft_islower(c)) - return (c - 32); - return (c); -} diff --git a/libft/inc/libft.h b/libft/inc/libft.h new file mode 100644 index 0000000..83a0177 --- /dev/null +++ b/libft/inc/libft.h @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* libft.h .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 18:15:13 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 14:17:02 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +# ifndef LIBFT_H +# define LIBFT_H + +#include +#include + +/* +** Part 1 +*/ + +void *ft_memset(void *b, int c, size_t len); +void ft_bzero(void *s, size_t n); +void *ft_memcpy(void *dst, const void *src, size_t n); +void *ft_memccpy(void *dst, const void *src, + int c, size_t n); +void *ft_memmove(void *dst, const void *src, size_t len); +void *ft_memchr(const void *s, int c, size_t n); +int ft_memcmp(const void *s1, const void *s2, size_t n); +size_t ft_strlen(const char *s); +int ft_isalpha(int c); +int ft_isdigit(int c); +int ft_isalnum(int c); +int ft_isascii(int c); +int ft_isprint(int c); +int ft_toupper(int c); +int ft_tolower(int c); +char *ft_strchr(const char *s, int c); +char *ft_strrchr(const char *s, int c); +int ft_strncmp(const char *s1, const char *s2, size_t n); +size_t ft_strlcpy(char *dst, const char *src, size_t size); +size_t ft_strlcat(char *dst, const char *src, size_t size); +char *ft_strnstr(const char *haystack, const char *needle, + size_t len); +int ft_atoi(const char *str); +void *ft_calloc(size_t count, size_t size); +char *ft_strdup(const char *s1); + +/* +** Part 2 +*/ + +char *ft_substr(const char *s, unsigned int start, + size_t len); +char *ft_strjoin(const char *s1, const char *s2); +char *ft_strtrim(const char *s1, const char *set); +char **ft_split(const char *s, char c); +char *ft_itoa(int n); +char *ft_strmapi(const char *s, + char (*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); + +/* +** Bonus +*/ + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; + +t_list *ft_lstnew(void *content); +void ft_lstadd_front(t_list **alst, t_list *new); +int ft_lstsize(t_list *lst); +t_list *ft_lstlast(t_list *lst); +void ft_lstadd_back(t_list **alst, t_list *new); +void ft_lstdelone(t_list *lst, void (*del)(void *)); +void ft_lstclear(t_list **lst, void (*del)(void *)); +void ft_lstiter(t_list *lst, void (*f)(void *)); +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), + void (*del)(void *)); +int ft_putchar(int c); +int ft_putstr(const char *s); +int ft_putendl(const char *s); +int ft_putnbr(int nb); +char *ft_strcat(char *s1, const char *s2); +uint8_t ft_isspace(int c); +int ft_strcmp(const char *s1, const char *s2); +double ft_sqrt(double x); +size_t ft_strnlen(const char *s, size_t size); + +# endif diff --git a/libft/libft.h b/libft/libft.h deleted file mode 100644 index 3ce9b07..0000000 --- a/libft/libft.h +++ /dev/null @@ -1,99 +0,0 @@ -/* ************************************************************************** */ -/* LE - / */ -/* / */ -/* libft.h .:: .:/ . .:: */ -/* +:+:+ +: +: +:+:+ */ -/* By: rbousset +:+ +: +: +:+ */ -/* #+# #+ #+ #+# */ -/* Created: 2019/10/07 18:15:13 by rbousset #+# ## ## #+# */ -/* Updated: 2019/10/13 14:17:02 by rbousset ### #+. /#+ ###.fr */ -/* / */ -/* / */ -/* ************************************************************************** */ - -# ifndef LIBFT_H -# define LIBFT_H - -#include -#include - -/* -** Part 1 -*/ - -void *ft_memset(void *b, int c, size_t len); -void ft_bzero(void *s, size_t n); -void *ft_memcpy(void *dst, const void *src, size_t n); -void *ft_memccpy(void *dst, const void *src, - int c, size_t n); -void *ft_memmove(void *dst, const void *src, size_t len); -void *ft_memchr(const void *s, int c, size_t n); -int ft_memcmp(const void *s1, const void *s2, size_t n); -size_t ft_strlen(const char *s); -int ft_isalpha(int c); -int ft_isdigit(int c); -int ft_isalnum(int c); -int ft_isascii(int c); -int ft_isprint(int c); -int ft_toupper(int c); -int ft_tolower(int c); -char *ft_strchr(const char *s, int c); -char *ft_strrchr(const char *s, int c); -int ft_strncmp(const char *s1, const char *s2, size_t n); -size_t ft_strlcpy(char *dst, const char *src, size_t size); -size_t ft_strlcat(char *dst, const char *src, size_t size); -char *ft_strnstr(const char *haystack, const char *needle, - size_t len); -int ft_atoi(const char *str); -void *ft_calloc(size_t count, size_t size); -char *ft_strdup(const char *s1); - -/* -** Part 2 -*/ - -char *ft_substr(const char *s, unsigned int start, - size_t len); -char *ft_strjoin(const char *s1, const char *s2); -char *ft_strtrim(const char *s1, const char *set); -char **ft_split(const char *s, char c); -char *ft_itoa(int n); -char *ft_strmapi(const char *s, - char (*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); - -/* -** Bonus -*/ - -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -# define BUFFER_SIZE 30 - -t_list *ft_lstnew(void *content); -void ft_lstadd_front(t_list **alst, t_list *new); -int ft_lstsize(t_list *lst); -t_list *ft_lstlast(t_list *lst); -void ft_lstadd_back(t_list **alst, t_list *new); -void ft_lstdelone(t_list *lst, void (*del)(void *)); -void ft_lstclear(t_list **lst, void (*del)(void *)); -void ft_lstiter(t_list *lst, void (*f)(void *)); -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), - void (*del)(void *)); -int ft_putchar(int c); -int ft_putstr(const char *s); -int ft_putendl(const char *s); -int ft_putnbr(int nb); -char *ft_strcat(char *s1, const char *s2); -uint8_t ft_isspace(int c); -int ft_strcmp(const char *s1, const char *s2); -double ft_sqrt(double x); - -# endif diff --git a/libft/main.c b/libft/main.c deleted file mode 100644 index d0cacd5..0000000 --- a/libft/main.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "libft.h" -#include -#include -#include -#include -#include -#include - -/* -** static void -** putlst(t_list *lst, t_list *init) -** { -** uint8_t i; -** -** i = 0; -** printf("list:\n"); -** while (lst != NULL) -** { -** printf("lst[%d] (%s)\n", i, (char*)lst->content); -** lst = lst->next; -** i++; -** } -** lst = init; -** } -** -** static void -** delfunc(void *content) -** { -** free(content); -** } -** -** #include -** int main(void) { -** t_list *lst = NULL; -** t_list *init = NULL; -** -** char *c0; -** char *c1; -** char *c2; -** char *c3; -** char *c4; -** char *c5; -** char *c6; -** char *c7; -** -** c0 = (char *)ft_calloc(6, sizeof(char)); -** c1 = (char *)ft_calloc(6, sizeof(char)); -** c2 = (char *)ft_calloc(6, sizeof(char)); -** c3 = (char *)ft_calloc(6, sizeof(char)); -** c4 = (char *)ft_calloc(6, sizeof(char)); -** c5 = (char *)ft_calloc(6, sizeof(char)); -** c6 = (char *)ft_calloc(6, sizeof(char)); -** c7 = (char *)ft_calloc(6, sizeof(char)); -** if (!c0 || !c1 || !c2 || !c3 || !c4 || !c5 || !c6 || !c7) -** return 1; -** memcpy(c0, "first", 6); -** memcpy(c1, "secon", 6); -** memcpy(c2, "third", 6); -** memcpy(c3, "fooba", 6); -** memcpy(c4, "qweqw", 6); -** memcpy(c5, "AAAAA", 6); -** memcpy(c6, "front", 6); -** memcpy(c7, "_back", 6); -** -** // INIT -** printf("INIT\n"); -** lst = ft_lstnew(c0); -** init = lst; -** lst->next = ft_lstnew(c1); -** lst = lst->next; -** lst->next = ft_lstnew(c2); -** lst = lst->next; -** lst->next = ft_lstnew(c3); -** lst = lst->next; -** lst->next = ft_lstnew(c4); -** lst = lst->next; -** lst->next = ft_lstnew(c5); -** lst = lst->next; -** lst = init; -** putlst(lst, init); -** -*/ /* ADD FRONT */ -/* printf("\n\nft_lstadd_front\n"); -** ft_lstadd_front(&lst, ft_lstnew(c6)); -** putlst(lst, init); -** -*/ /* ADD BACK */ -/* printf("\n\nft_lstadd_back\n"); -** ft_lstadd_back(&lst, ft_lstnew(c7)); -** putlst(lst, init); -** -*/ /* DELONE */ -/* printf("\n\nft_lstdelone\n"); -** ft_lstdelone(lst->next->next, &delfunc); -** putlst(lst, init); -** lst->next->next = ft_lstnew(c3); -** -*/ /* CLEAR */ -/* printf("\n\nft_lstclear\n"); -** ft_lstclear(&lst, &delfunc); -** putlst(lst, init); -** -** char dst[40] = "foo"; -** char src[40] = "foo"; -** size_t len = 4; -** printf("%s\n", ft_strnstr(dst, src, len)); -** return 0; -** } -*/ - -int main(void) { - char dst[40] = "bar"; - char src[40] = "Foobar"; - - char dst2[40] = "bar"; - char src2[40] = "Foobar"; - - size_t len = 8; - printf("FT_RETURN (%s)\n", ft_memmove(dst, src, len)); - printf("C__RETURN (%s)\n", memmove(dst2, src2, len)); - return (0); -} diff --git a/libft/src/ft_atoi.c b/libft/src/ft_atoi.c new file mode 100644 index 0000000..8903606 --- /dev/null +++ b/libft/src/ft_atoi.c @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_atoi.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/10 05:32:13 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/15 02:16:20 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +static uint8_t + ft_isaspace(int c) +{ + if (c == '\t' || + c == '\n' || + c == '\v' || + c == '\f' || + c == '\r' || + c == ' ') + return (1); + return (0); +} + +static int8_t + ft_setsign(const char c) +{ + int8_t sign; + + sign = 1; + if (c == '-') + sign = -1; + return (sign); +} + +static uint8_t + ft_seti(const char *str) +{ + uint8_t i; + + i = 0; + while (ft_isaspace(str[i])) + i++; + return (i); +} + +int + ft_atoi(const char *str) +{ + uint8_t i; + int8_t sign; + long nb; + + if (!str || !*str) + return (0); + i = ft_seti(str); + nb = 0; + sign = 1; + if (str[i] == '+' || str[i] == '-') + sign = ft_setsign(str[i++]); + while (ft_isdigit(str[i])) + { + if (nb * 10 + (str[i] - 48) < nb) + { + if (sign < 0) + return (0); + return (-1); + } + nb = nb * 10 + (str[i] - 48); + i++; + } + nb *= sign; + return ((int)nb); +} diff --git a/libft/src/ft_bzero.c b/libft/src/ft_bzero.c new file mode 100644 index 0000000..05ff6b7 --- /dev/null +++ b/libft/src/ft_bzero.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_bzero.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 14:04:55 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:45:28 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +void + ft_bzero(void *s, size_t n) +{ + if (!s) + return ; + ft_memset(s, 0, n); +} diff --git a/libft/src/ft_calloc.c b/libft/src/ft_calloc.c new file mode 100644 index 0000000..49383da --- /dev/null +++ b/libft/src/ft_calloc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_calloc.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/11 02:47:15 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:43:53 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +void + *ft_calloc(size_t count, size_t size) +{ + void *ptr; + + ptr = 0; + ptr = malloc(count * size); + if (!ptr) + return (NULL); + ft_bzero(ptr, count * size); + return (ptr); +} diff --git a/libft/src/ft_isalnum.c b/libft/src/ft_isalnum.c new file mode 100644 index 0000000..e9e1134 --- /dev/null +++ b/libft/src/ft_isalnum.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_isalnum.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 18:07:44 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:45:57 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +int + ft_isalnum(int c) +{ + if (ft_isalpha(c) || ft_isdigit(c)) + return (1); + return (0); +} diff --git a/libft/src/ft_isalpha.c b/libft/src/ft_isalpha.c new file mode 100644 index 0000000..9e95bd6 --- /dev/null +++ b/libft/src/ft_isalpha.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_isalpha.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 16:45:42 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:42:03 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +static int + ft_isupper(int c) +{ + if (c >= 65 && c <= 90) + return (1); + return (0); +} + +static int + ft_islower(int c) +{ + if (c >= 97 && c <= 122) + return (1); + return (0); +} + +int + ft_isalpha(int c) +{ + if (ft_isupper(c) || ft_islower(c)) + return (1); + return (0); +} diff --git a/libft/src/ft_isascii.c b/libft/src/ft_isascii.c new file mode 100644 index 0000000..937ead5 --- /dev/null +++ b/libft/src/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_isascii.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 18:18:31 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:41:32 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +int + ft_isascii(int c) +{ + if (c >= 0 && c <= 127) + return (1); + return (0); +} diff --git a/libft/src/ft_isdigit.c b/libft/src/ft_isdigit.c new file mode 100644 index 0000000..52ededc --- /dev/null +++ b/libft/src/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_isdigit.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 17:46:41 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:41:27 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +int + ft_isdigit(int c) +{ + if (c >= 48 && c <= 57) + return (1); + return (0); +} diff --git a/libft/src/ft_isprint.c b/libft/src/ft_isprint.c new file mode 100644 index 0000000..d82ded0 --- /dev/null +++ b/libft/src/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_isprint.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 18:23:39 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:41:21 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +int + ft_isprint(int c) +{ + if (c >= 32 && c <= 126) + return (1); + return (0); +} diff --git a/libft/src/ft_isspace.c b/libft/src/ft_isspace.c new file mode 100644 index 0000000..c9cf255 --- /dev/null +++ b/libft/src/ft_isspace.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_isspace.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/10 05:57:19 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:44:18 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +uint8_t + ft_isspace(int c) +{ + if (c == '\t' || + c == '\n' || + c == '\v' || + c == '\f' || + c == '\r' || + c == ' ') + return (1); + return (0); +} diff --git a/libft/src/ft_itoa.c b/libft/src/ft_itoa.c new file mode 100644 index 0000000..bf3c0c8 --- /dev/null +++ b/libft/src/ft_itoa.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_itoa.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 02:22:48 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 13:35:46 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +static uint8_t + ft_intlen(int n) +{ + uint8_t len; + + len = 0; + if (!n) + return (1); + if (n < 0) + len = 1; + while (n != 0) + { + n /= 10; + len++; + } + return (len); +} + +char + *ft_itoa(int n) +{ + char *s; + unsigned int nb; + uint8_t i; + + i = ft_intlen(n) - 1; + if (!(s = (char*)malloc((i + 2) * sizeof(char)))) + return (NULL); + if (!n) + s[i] = '0'; + nb = n; + if (n < 0) + { + s[0] = '-'; + nb = -n; + } + s[i + 1] = '\0'; + while (nb > 0) + { + s[i] = 48 + (nb % 10); + nb = nb / 10; + i--; + } + return (s); +} diff --git a/libft/src/ft_lstadd_back.c b/libft/src/ft_lstadd_back.c new file mode 100644 index 0000000..58b3a72 --- /dev/null +++ b/libft/src/ft_lstadd_back.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstadd_back.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 10:04:16 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 10:11:08 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +void + ft_lstadd_back(t_list **alst, t_list *new) +{ + t_list *tmp; + + if (!alst || !new) + return ; + if (!*alst) + *alst = new; + else + { + tmp = ft_lstlast(*alst); + tmp->next = new; + } +} diff --git a/libft/src/ft_lstadd_front.c b/libft/src/ft_lstadd_front.c new file mode 100644 index 0000000..c9515ea --- /dev/null +++ b/libft/src/ft_lstadd_front.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstadd_front.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 09:31:45 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 10:11:10 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +void + ft_lstadd_front(t_list **alst, t_list *new) +{ + if (!alst || !new) + return ; + new->next = *alst; + *alst = new; +} diff --git a/libft/src/ft_lstclear.c b/libft/src/ft_lstclear.c new file mode 100644 index 0000000..8d97b9c --- /dev/null +++ b/libft/src/ft_lstclear.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstclear.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 10:19:53 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 13:52:03 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +void + ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *tmp; + t_list *renext; + + if (!lst) + return ; + tmp = *lst; + while (tmp) + { + renext = tmp->next; + del(tmp->content); + free(tmp); + tmp = renext; + } + *lst = NULL; +} diff --git a/libft/src/ft_lstdelone.c b/libft/src/ft_lstdelone.c new file mode 100644 index 0000000..42a1da8 --- /dev/null +++ b/libft/src/ft_lstdelone.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstdelone.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 10:11:20 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 10:18:40 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +void + ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + if (lst) + { + del(lst->content); + free(lst); + } +} diff --git a/libft/src/ft_lstiter.c b/libft/src/ft_lstiter.c new file mode 100644 index 0000000..3129ab5 --- /dev/null +++ b/libft/src/ft_lstiter.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstiter.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 10:30:22 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 11:01:22 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +void + ft_lstiter(t_list *lst, void (*f)(void *)) +{ + if (!lst) + return ; + while (lst != NULL) + { + (*f)(lst->content); + lst = lst->next; + } +} diff --git a/libft/src/ft_lstlast.c b/libft/src/ft_lstlast.c new file mode 100644 index 0000000..a685322 --- /dev/null +++ b/libft/src/ft_lstlast.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstlast.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 09:53:13 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 10:11:09 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +t_list + *ft_lstlast(t_list *lst) +{ + if (!lst) + return (NULL); + while (lst->next != NULL) + lst = lst->next; + return (lst); +} diff --git a/libft/src/ft_lstmap.c b/libft/src/ft_lstmap.c new file mode 100644 index 0000000..474b1bc --- /dev/null +++ b/libft/src/ft_lstmap.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstmap.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 10:36:15 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 11:06:32 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +t_list + *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *nlst; + t_list *new; + + if (!lst) + return (NULL); + nlst = ft_lstnew((*f)(lst->content)); + if (!nlst) + return (NULL); + lst = lst->next; + while (lst != NULL) + { + new = ft_lstnew((*f)(lst->content)); + (*del)(lst->content); + if (!new) + return (NULL); + lst = lst->next; + ft_lstadd_back(&nlst, new); + } + return (nlst); +} diff --git a/libft/src/ft_lstnew.c b/libft/src/ft_lstnew.c new file mode 100644 index 0000000..a5e1c0a --- /dev/null +++ b/libft/src/ft_lstnew.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstnew.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 09:25:56 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 10:56:17 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list + *ft_lstnew(void *content) +{ + t_list *nlst; + + nlst = (t_list*)ft_calloc(1, sizeof(t_list)); + if (!nlst) + return (NULL); + nlst->content = content; + nlst->next = NULL; + return (nlst); +} diff --git a/libft/src/ft_lstsize.c b/libft/src/ft_lstsize.c new file mode 100644 index 0000000..1742a5f --- /dev/null +++ b/libft/src/ft_lstsize.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_lstsize.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 09:45:10 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 09:51:16 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +int + ft_lstsize(t_list *lst) +{ + int i; + + if (!lst) + return (0); + i = 0; + while (lst != NULL) + { + lst = lst->next; + i++; + } + return (i); +} diff --git a/libft/src/ft_memccpy.c b/libft/src/ft_memccpy.c new file mode 100644 index 0000000..a029e7d --- /dev/null +++ b/libft/src/ft_memccpy.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_memccpy.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 14:59:46 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:40:44 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include +#include + +void + *ft_memccpy(void *dst, const void *src, int c, size_t n) +{ + unsigned char *dst_ptr; + const unsigned char *src_ptr; + + dst_ptr = (unsigned char*)dst; + src_ptr = (unsigned char*)src; + if (!*dst_ptr && !*src_ptr && n) + return (NULL); + if (n) + { + while (n) + { + if ((*dst_ptr++ = *src_ptr++) == (unsigned char)c) + return (dst_ptr); + n--; + } + } + return (NULL); +} diff --git a/libft/src/ft_memchr.c b/libft/src/ft_memchr.c new file mode 100644 index 0000000..c2578aa --- /dev/null +++ b/libft/src/ft_memchr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_memchr.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 19:14:54 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:40:23 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +void + *ft_memchr(const void *s, int c, size_t n) +{ + unsigned char *s_ptr; + size_t i; + + if (!s) + return (NULL); + i = 0; + s_ptr = (unsigned char*)s; + while (i < n) + { + if (s_ptr[i] == (unsigned char)c) + return ((char*)&s[i]); + i++; + } + return (NULL); +} diff --git a/libft/src/ft_memcmp.c b/libft/src/ft_memcmp.c new file mode 100644 index 0000000..59a99bd --- /dev/null +++ b/libft/src/ft_memcmp.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_memcmp.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 19:23:43 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:40:10 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +int + ft_memcmp(const void *s1, const void *s2, size_t n) +{ + const unsigned char *s1_ptr; + const unsigned char *s2_ptr; + + s1_ptr = (unsigned char*)s1; + s2_ptr = (unsigned char*)s2; + if (!s1 || !s2) + return (0); + while (n) + { + if (*s1_ptr != *s2_ptr) + return (*s1_ptr - *s2_ptr); + s1_ptr++; + s2_ptr++; + n--; + } + return (0); +} diff --git a/libft/src/ft_memcpy.c b/libft/src/ft_memcpy.c new file mode 100644 index 0000000..548ea95 --- /dev/null +++ b/libft/src/ft_memcpy.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_memcpy.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 14:17:11 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:39:01 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +void + *ft_memcpy(void *dst, const void *src, size_t n) +{ + unsigned char *dst_ptr; + unsigned char *src_ptr; + size_t i; + + dst_ptr = (unsigned char*)dst; + src_ptr = (unsigned char*)src; + i = 0; + if (src_ptr == NULL && dst_ptr == NULL && n != 0) + return (NULL); + while (i < n) + { + dst_ptr[i] = src_ptr[i]; + i++; + } + return (dst_ptr); +} diff --git a/libft/src/ft_memmove.c b/libft/src/ft_memmove.c new file mode 100644 index 0000000..000a2b7 --- /dev/null +++ b/libft/src/ft_memmove.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_memmove.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 18:57:44 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:38:47 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +void + *ft_memmove(void *dst, const void *src, size_t len) +{ + char buff[len]; + + if (src == NULL && dst == NULL && len != 0) + return (NULL); + ft_memcpy(buff, src, len); + ft_memcpy(dst, buff, len); + return (dst); +} diff --git a/libft/src/ft_memset.c b/libft/src/ft_memset.c new file mode 100644 index 0000000..b94c6fa --- /dev/null +++ b/libft/src/ft_memset.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_memset.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 13:41:09 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:38:10 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +void + *ft_memset(void *b, int c, size_t len) +{ + unsigned char *str; + + str = b; + if (!b) + return (NULL); + if (!len) + return (b); + while (len > 0) + { + *str = (unsigned char)c; + str++; + len--; + } + return (b); +} diff --git a/libft/src/ft_putchar.c b/libft/src/ft_putchar.c new file mode 100644 index 0000000..b558ead --- /dev/null +++ b/libft/src/ft_putchar.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putchar.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/12 15:02:55 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/15 01:10:32 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +int + ft_putchar(int c) +{ + return (write(1, &c, 1)); +} diff --git a/libft/src/ft_putchar_fd.c b/libft/src/ft_putchar_fd.c new file mode 100644 index 0000000..f57a4f9 --- /dev/null +++ b/libft/src/ft_putchar_fd.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putchar_fd.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 08:27:19 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:49:34 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +void + ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/src/ft_putendl.c b/libft/src/ft_putendl.c new file mode 100644 index 0000000..26dc80b --- /dev/null +++ b/libft/src/ft_putendl.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putendl.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/15 05:19:52 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/15 05:19:53 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +int + ft_putendl(const char *s) +{ + return (write(1, s, ft_strlen(s)) + ft_putchar('\n')); +} diff --git a/libft/src/ft_putendl_fd.c b/libft/src/ft_putendl_fd.c new file mode 100644 index 0000000..39fe7c1 --- /dev/null +++ b/libft/src/ft_putendl_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putendl_fd.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 08:52:34 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 09:01:41 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +void + ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + ft_putchar_fd('\n', fd); +} diff --git a/libft/src/ft_putnbr.c b/libft/src/ft_putnbr.c new file mode 100644 index 0000000..5220151 --- /dev/null +++ b/libft/src/ft_putnbr.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putnbr.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/08/08 12:22:48 by rbousset #+# ## ## #+# */ +/* Updated: 2019/08/12 17:54:48 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +int + ft_putnbr(int nb) +{ + unsigned int i; + + i = nb; + if (nb < 0) + { + ft_putchar('-'); + i = -nb; + } + if (i > 9) + { + ft_putnbr(i / 10); + ft_putchar((i % 10) + '0'); + } + else + ft_putchar(i + '0'); + return (0); +} diff --git a/libft/src/ft_putnbr_fd.c b/libft/src/ft_putnbr_fd.c new file mode 100644 index 0000000..b240f43 --- /dev/null +++ b/libft/src/ft_putnbr_fd.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putnbr_fd.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 08:57:19 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 12:13:09 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +void + ft_putnbr_fd(int n, int fd) +{ + unsigned int i; + + i = n; + if (n < 0) + { + ft_putchar_fd('-', fd); + i = -n; + } + if (i > 9) + { + ft_putnbr_fd(i / 10, fd); + ft_putchar_fd((i % 10) + 48, fd); + } + else + ft_putchar_fd(i + 48, fd); +} diff --git a/libft/src/ft_putstr.c b/libft/src/ft_putstr.c new file mode 100644 index 0000000..d29a940 --- /dev/null +++ b/libft/src/ft_putstr.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putstr.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 09:05:27 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 09:07:45 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +int + ft_putstr(const char *s) +{ + return (write(1, s, ft_strlen(s))); +} diff --git a/libft/src/ft_putstr_fd.c b/libft/src/ft_putstr_fd.c new file mode 100644 index 0000000..b90c078 --- /dev/null +++ b/libft/src/ft_putstr_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_putstr_fd.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 08:48:25 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 09:00:42 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +void + ft_putstr_fd(char *s, int fd) +{ + write(fd, s, ft_strlen(s)); +} diff --git a/libft/src/ft_split.c b/libft/src/ft_split.c new file mode 100644 index 0000000..7c706cf --- /dev/null +++ b/libft/src/ft_split.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_split.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/12 19:24:20 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:37:16 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include +#include + +static uint8_t + ft_check(int c, char sep) +{ + if (c == sep) + return (1); + return (0); +} + +static size_t + ft_strlen_plus(const char *str, char c) +{ + size_t i; + size_t count; + uint8_t ibool; + + i = 0; + count = 0; + ibool = 1; + while (str[i]) + { + while (ft_check(str[i], c) && str[i]) + i++; + while (!ft_check(str[i], c) && str[i]) + { + if (ibool == 1) + count++; + ibool = 0; + i++; + } + ibool = 1; + } + return (count); +} + +static size_t + ft_strlen_again(const char *str, char c) +{ + size_t i; + + i = 0; + while (!ft_check(str[i], c) && str[i]) + i++; + return (i); +} + +static char + *ft_strdup_plus(const char *src, char c) +{ + size_t i; + size_t slen; + char *nstr; + + i = 0; + slen = ft_strlen_again(src, c) + 1; + if (!(nstr = (char*)ft_calloc(slen, sizeof(char)))) + return (NULL); + while (!ft_check(src[i], c) && src[i]) + { + nstr[i] = src[i]; + i++; + } + nstr[i] = '\0'; + return (nstr); +} + +char + **ft_split(const char *s, char c) +{ + size_t i; + size_t j; + char **best_split; + + i = 0; + j = 0; + if (!(best_split = (char **)ft_calloc(ft_strlen_plus(s, c) + 1, + sizeof(char *)))) + return (NULL); + while (s[i]) + { + while (ft_check(s[i], c) && s[i]) + i++; + while (!ft_check(s[i], c) && s[i]) + { + best_split[j] = ft_strdup_plus(&s[i], c); + i += ft_strlen_again(&s[i], c); + j++; + } + } + best_split[j] = 0; + return (best_split); +} diff --git a/libft/src/ft_sqrt.c b/libft/src/ft_sqrt.c new file mode 100644 index 0000000..3003e6d --- /dev/null +++ b/libft/src/ft_sqrt.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_sqrt.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/08/10 21:34:14 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/14 23:26:06 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +double + ft_sqrt(double x) +{ + double i; + + i = 0.0000001; + while (i * i < x && i * i < INT_MAX) + { + i += 0.0000001; + } + return (i); +} diff --git a/libft/src/ft_strcat.c b/libft/src/ft_strcat.c new file mode 100644 index 0000000..59084c2 --- /dev/null +++ b/libft/src/ft_strcat.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strcat.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/12 16:31:34 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:44:34 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +char + *ft_strcat(char *s1, const char *s2) +{ + int i; + int j; + + i = 0; + j = 0; + while (s1[i] != '\0') + i++; + while (s2[j] != '\0') + { + s1[i] = s2[j]; + i++; + j++; + } + s1[i] = '\0'; + return (s1); +} diff --git a/libft/src/ft_strchr.c b/libft/src/ft_strchr.c new file mode 100644 index 0000000..86bd41d --- /dev/null +++ b/libft/src/ft_strchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strchr.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 18:39:17 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:36:43 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +char + *ft_strchr(const char *s, int c) +{ + size_t i; + + i = 0; + if (!s) + return (NULL); + while (s[i] != c) + { + if (!s[i]) + return (NULL); + i++; + } + return ((char*)&s[i]); +} diff --git a/libft/src/ft_strcmp.c b/libft/src/ft_strcmp.c new file mode 100644 index 0000000..2e9ffe9 --- /dev/null +++ b/libft/src/ft_strcmp.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strcmp.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 13:55:24 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 13:56:42 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +int + ft_strcmp(const char *s1, const char *s2) +{ + size_t i; + int diff; + + i = 0; + while (s1[i] == s2[i]) + i++; + diff = s1[i] - s2[i]; + return (diff); +} diff --git a/libft/src/ft_strdup.c b/libft/src/ft_strdup.c new file mode 100644 index 0000000..ce74fb5 --- /dev/null +++ b/libft/src/ft_strdup.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strdup.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/11 05:45:32 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:36:24 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +char + *ft_strdup(const char *s1) +{ + size_t slen; + char *new_str; + + new_str = ""; + slen = ft_strlen(s1); + new_str = (char *)malloc((slen + 1) * sizeof(char)); + if (new_str == NULL) + return (NULL); + ft_memcpy(new_str, s1, slen); + new_str[slen] = '\0'; + return (new_str); +} diff --git a/libft/src/ft_strjoin.c b/libft/src/ft_strjoin.c new file mode 100644 index 0000000..f666781 --- /dev/null +++ b/libft/src/ft_strjoin.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strjoin.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/12 16:35:23 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:36:17 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +size_t + ft_strleen(const char *s) +{ + size_t i; + + i = 0; + while (s[i] != '\0') + i++; + return (i); +} + +static char + *ft_recalloc(size_t size) +{ + char *str; + + str = 0; + str = malloc((size + 1) * sizeof(char)); + if (!str) + return (NULL); + ft_bzero(str, size); + return (str); +} + +char + *ft_strjoin(const char *s1, const char *s2) +{ + char *str; + size_t i; + size_t j; + size_t size; + + size = (ft_strleen(s1) + ft_strleen(s2)); + str = (char*)ft_recalloc(ft_strleen(s1) + ft_strleen(s2)); + i = 0; + j = 0; + if (!str) + return (NULL); + while (i < ft_strleen(s1)) + { + str[i] = s1[i]; + i++; + } + while (i < size) + { + str[i] = s2[j]; + i++; + j++; + } + str[i] = '\0'; + return (str); +} diff --git a/libft/src/ft_strlcat.c b/libft/src/ft_strlcat.c new file mode 100644 index 0000000..98fa3e8 --- /dev/null +++ b/libft/src/ft_strlcat.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strlcat.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/09 06:44:30 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:36:04 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +static size_t + ft_strlen_size(const char *s, size_t size) +{ + const char *ptr = s; + + while (size > 0 && *ptr) + { + size--; + ptr++; + } + return (ptr - s); +} + +size_t + ft_strlcat(char *dst, const char *src, size_t size) +{ + size_t dst_len; + + if (!dst || !src) + return (0); + dst_len = ft_strlen_size(dst, size); + if (dst_len == size) + return (dst_len + ft_strlen(src)); + return (dst_len + ft_strlcpy(dst + dst_len, src, size - dst_len)); +} diff --git a/libft/src/ft_strlcpy.c b/libft/src/ft_strlcpy.c new file mode 100644 index 0000000..bba4263 --- /dev/null +++ b/libft/src/ft_strlcpy.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strlcpy.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/08 20:44:40 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:35:51 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +size_t + ft_strlcpy(char *dst, const char *src, size_t size) +{ + size_t src_len; + + if (!dst || !src) + return (0); + src_len = ft_strlen(src); + if (src_len + 1 < size) + ft_memcpy(dst, src, src_len + 1); + else if (size != 0) + { + ft_memcpy(dst, src, size - 1); + dst[size - 1] = 0; + } + return (src_len); +} diff --git a/libft/src/ft_strlen.c b/libft/src/ft_strlen.c new file mode 100644 index 0000000..68c7614 --- /dev/null +++ b/libft/src/ft_strlen.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strlen.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 16:32:28 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:35:37 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +size_t + ft_strlen(const char *s) +{ + size_t i; + + i = 0; + if (!s) + return (0); + while (s[i] != '\0') + i++; + return (i); +} diff --git a/libft/src/ft_strmapi.c b/libft/src/ft_strmapi.c new file mode 100644 index 0000000..7a38ca9 --- /dev/null +++ b/libft/src/ft_strmapi.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strmapi.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/13 05:57:35 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:35:12 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +char + *ft_strmapi(const char *s, char (*f)(unsigned int, char)) +{ + unsigned int i; + char *nstr; + + if (!s) + return (NULL); + i = 0; + nstr = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char)); + if (!nstr) + return (NULL); + while (s[i]) + { + nstr[i] = (*f)(i, s[i]); + i++; + } + return (nstr); +} diff --git a/libft/src/ft_strncmp.c b/libft/src/ft_strncmp.c new file mode 100644 index 0000000..c8a0b87 --- /dev/null +++ b/libft/src/ft_strncmp.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strncmp.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 20:25:31 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:35:01 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +int + ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + + i = 0; + if (!s1 || !s2 || !n) + return (0); + while (s1[i] == s2[i] && i < n - 1) + { + if (s1[i] == '\0' && s2[i] == '\0') + return (0); + i++; + } + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +} diff --git a/libft/src/ft_strnlen.c b/libft/src/ft_strnlen.c new file mode 100644 index 0000000..88bd437 --- /dev/null +++ b/libft/src/ft_strnlen.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strnlen.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/30 14:28:01 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/30 14:28:03 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include + +size_t + ft_strlen_size(const char *s, size_t size) +{ + const char *ptr = s; + + while (size > 0 && *ptr) + { + size--; + ptr++; + } + return (ptr - s); +} diff --git a/libft/src/ft_strnstr.c b/libft/src/ft_strnstr.c new file mode 100644 index 0000000..583026e --- /dev/null +++ b/libft/src/ft_strnstr.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strnstr.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/10 00:23:15 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:34:35 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include +#include + +char + *ft_strnstr(const char *haystack, const char *needle, size_t len) +{ + unsigned long i; + unsigned long j; + char *hay_ptr; + char *nee_ptr; + + hay_ptr = (char*)haystack; + nee_ptr = (char*)needle; + i = 0; + if (!nee_ptr[0]) + return (hay_ptr); + while (hay_ptr[i] && i < len) + { + j = 0; + while (nee_ptr[j] == hay_ptr[i + j] && (i + j) < len) + { + if (!nee_ptr[j + 1]) + return (hay_ptr + i); + j++; + } + if (!hay_ptr[i + 1] && !j) + return (0); + i++; + } + return (0); +} diff --git a/libft/src/ft_strrchr.c b/libft/src/ft_strrchr.c new file mode 100644 index 0000000..47ba95b --- /dev/null +++ b/libft/src/ft_strrchr.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strrchr.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 19:07:53 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:34:19 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +char + *ft_strrchr(const char *s, int c) +{ + size_t i; + + if (!s) + return (NULL); + i = ft_strlen(s); + while (s[i] != c) + { + if (!i) + return (NULL); + i--; + } + return ((char*)&s[i]); +} diff --git a/libft/src/ft_strtrim.c b/libft/src/ft_strtrim.c new file mode 100644 index 0000000..c691815 --- /dev/null +++ b/libft/src/ft_strtrim.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_strtrim.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/12 17:30:33 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:34:03 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" + +char + *ft_strtrim(const char *s1, const char *set) +{ + size_t len; + + len = 0; + if (!s1 || !set) + return (NULL); + while (*s1 && ft_strchr(set, *s1)) + s1++; + len = ft_strlen(s1); + while (len > 0 && ft_strchr(set, s1[len - 1])) + len--; + return (ft_substr(s1, 0, len)); +} diff --git a/libft/src/ft_substr.c b/libft/src/ft_substr.c new file mode 100644 index 0000000..87c2568 --- /dev/null +++ b/libft/src/ft_substr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_substr.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/12 15:37:02 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:33:09 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +#include "libft.h" +#include + +char + *ft_substr(const char *s, unsigned int start, size_t len) +{ + char *nstr; + + if (start > ft_strlen(s) - 1) + { + nstr = (char*)ft_calloc(1, sizeof(char)); + if (!nstr) + return (NULL); + return (nstr); + } + nstr = (char*)ft_calloc(len + 1, sizeof(char)); + if (!nstr) + return (NULL); + return ((char*)ft_memcpy(nstr, s + start, len)); +} diff --git a/libft/src/ft_tolower.c b/libft/src/ft_tolower.c new file mode 100644 index 0000000..48c065e --- /dev/null +++ b/libft/src/ft_tolower.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_tolower.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 18:32:59 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:32:22 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +static int + ft_isupper(int c) +{ + if (c >= 65 && c <= 90) + return (1); + return (0); +} + +int + ft_tolower(int c) +{ + if (ft_isupper(c)) + return (c + 32); + return (c); +} diff --git a/libft/src/ft_toupper.c b/libft/src/ft_toupper.c new file mode 100644 index 0000000..3346cc3 --- /dev/null +++ b/libft/src/ft_toupper.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* LE - / */ +/* / */ +/* ft_toupper.c .:: .:/ . .:: */ +/* +:+:+ +: +: +:+:+ */ +/* By: rbousset +:+ +: +: +:+ */ +/* #+# #+ #+ #+# */ +/* Created: 2019/10/07 18:25:57 by rbousset #+# ## ## #+# */ +/* Updated: 2019/10/13 08:32:15 by rbousset ### #+. /#+ ###.fr */ +/* / */ +/* / */ +/* ************************************************************************** */ + +static int + ft_islower(int c) +{ + if (c >= 97 && c <= 122) + return (1); + return (0); +} + +int + ft_toupper(int c) +{ + if (ft_islower(c)) + return (c - 32); + return (c); +} -- cgit v1.2.3