diff options
Diffstat (limited to '')
54 files changed, 2027 insertions, 0 deletions
| diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..fbe5c6e --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,124 @@ +# **************************************************************************** # +#                                                           LE - /             # +#                                                               /              # +#    Makefile                                         .::    .:/ .      .::    # +#                                                  +:+:+   +:    +:  +:+:+     # +#    By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+      # +#                                                  #+#   #+    #+    #+#       # +#    Created: 2019/10/08 15:04:55 by rbousset     #+#   ##    ##    #+#        # +#    Updated: 2019/10/13 14:01:21 by rbousset    ###    #+. /#+    ###.fr      # +#                                                          /                   # +#                                                         /                    # +# **************************************************************************** # + +SRCS_DIR		= ./ + +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 + +CFLAGS			= -Wall -Wextra -Werror + +NAME			= libft.a + +RM				= rm -rf + +AR				= ar rcs + +%.o:		%.c +	${CC} ${CFLAGS} -I${INCS_DIR} -c $< -o $@ + +$(NAME):	${OBJS} +	${AR} ${NAME} ${OBJS} + +all:		${NAME} + +bonus: 		all ${B_OBJS}  +	${AR} ${NAME} ${B_OBJS} + +clean:  +	${RM} ${OBJS} ${B_OBJS} + +fclean:		clean +	${RM} ${NAME} + +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 diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100644 index 0000000..8903606 --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,79 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_atoi.c                                        .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/10 05:32:13 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/15 02:16:20 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <inttypes.h> + +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 new file mode 100644 index 0000000..05ff6b7 --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_bzero.c                                       .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 14:04:55 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:45:28 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..49383da --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_calloc.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/11 02:47:15 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:43:53 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> +#include <stdlib.h> + +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 new file mode 100644 index 0000000..e9e1134 --- /dev/null +++ b/libft/ft_isalnum.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_isalnum.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..9e95bd6 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_isalpha.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..937ead5 --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_isascii.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..52ededc --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_isdigit.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..d82ded0 --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_isprint.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..c9cf255 --- /dev/null +++ b/libft/ft_isspace_bonus.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_isspace.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/10 05:57:19 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:44:18 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <inttypes.h> + +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 new file mode 100644 index 0000000..bf3c0c8 --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,62 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_itoa.c                                        .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 02:22:48 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 13:35:46 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <inttypes.h> +#include <stdlib.h> + +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 new file mode 100644 index 0000000..58b3a72 --- /dev/null +++ b/libft/ft_lstadd_back_bonus.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstadd_back.c                                 .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 10:04:16 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 10:11:08 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..c9515ea --- /dev/null +++ b/libft/ft_lstadd_front_bonus.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstadd_front.c                                .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..8d97b9c --- /dev/null +++ b/libft/ft_lstclear_bonus.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstclear.c                                    .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 10:19:53 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 13:52:03 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stdlib.h> + +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 new file mode 100644 index 0000000..42a1da8 --- /dev/null +++ b/libft/ft_lstdelone_bonus.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstdelone.c                                   .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 10:11:20 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 10:18:40 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stdlib.h> + +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 new file mode 100644 index 0000000..3129ab5 --- /dev/null +++ b/libft/ft_lstiter_bonus.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstiter.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 10:30:22 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 11:01:22 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..a685322 --- /dev/null +++ b/libft/ft_lstlast_bonus.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstlast.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 09:53:13 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 10:11:09 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..474b1bc --- /dev/null +++ b/libft/ft_lstmap_bonus.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstmap.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 10:36:15 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 11:06:32 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> +#include <stdlib.h> + +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 new file mode 100644 index 0000000..a5e1c0a --- /dev/null +++ b/libft/ft_lstnew_bonus.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstnew.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..1742a5f --- /dev/null +++ b/libft/ft_lstsize_bonus.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_lstsize.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..a029e7d --- /dev/null +++ b/libft/ft_memccpy.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_memccpy.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 14:59:46 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:40:44 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> +#include <stdio.h> + +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 new file mode 100644 index 0000000..c2578aa --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_memchr.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 19:14:54 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:40:23 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> + +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 new file mode 100644 index 0000000..59a99bd --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_memcmp.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 19:23:43 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:40:10 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> + +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 new file mode 100644 index 0000000..548ea95 --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_memcpy.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 14:17:11 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:39:01 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> +#include <stdio.h> + +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 new file mode 100644 index 0000000..000a2b7 --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_memmove.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 18:57:44 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:38:47 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..b94c6fa --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_memset.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 13:41:09 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:38:10 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> + +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 new file mode 100644 index 0000000..b558ead --- /dev/null +++ b/libft/ft_putchar_bonus.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putchar.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/12 15:02:55 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/15 01:10:32 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <unistd.h> + +int +	ft_putchar(int c) +{ +	return (write(1, &c, 1)); +} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100644 index 0000000..f57a4f9 --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putchar_fd.c                                  .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 08:27:19 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:49:34 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <unistd.h> + +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 new file mode 100644 index 0000000..26dc80b --- /dev/null +++ b/libft/ft_putendl_bonus.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putendl.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/15 05:19:52 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/15 05:19:53 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <unistd.h> + +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 new file mode 100644 index 0000000..39fe7c1 --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putendl_fd.c                                  .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..5220151 --- /dev/null +++ b/libft/ft_putnbr_bonus.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putnbr.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/08/08 12:22:48 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/08/12 17:54:48 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <unistd.h> + +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 new file mode 100644 index 0000000..b240f43 --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putnbr_fd.c                                   .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..d29a940 --- /dev/null +++ b/libft/ft_putstr_bonus.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putstr.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 09:05:27 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 09:07:45 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <unistd.h> + +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 new file mode 100644 index 0000000..b90c078 --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_putstr_fd.c                                   .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 08:48:25 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 09:00:42 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <unistd.h> + +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 new file mode 100644 index 0000000..7c706cf --- /dev/null +++ b/libft/ft_split.c @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_split.c                                       .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/12 19:24:20 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:37:16 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> +#include <stdlib.h> +#include <inttypes.h> + +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 new file mode 100644 index 0000000..3003e6d --- /dev/null +++ b/libft/ft_sqrt_bonus.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_sqrt.c                                        .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/08/10 21:34:14 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/14 23:26:06 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <limits.h> + +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 new file mode 100644 index 0000000..59084c2 --- /dev/null +++ b/libft/ft_strcat_bonus.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strcat.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..86bd41d --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strchr.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/07 18:39:17 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:36:43 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> + +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 new file mode 100644 index 0000000..2e9ffe9 --- /dev/null +++ b/libft/ft_strcmp_bonus.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strcmp.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/13 13:55:24 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 13:56:42 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> + +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 new file mode 100644 index 0000000..ce74fb5 --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strdup.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/11 05:45:32 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:36:24 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stdlib.h> + +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 new file mode 100644 index 0000000..f666781 --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strjoin.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/12 16:35:23 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:36:17 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stdlib.h> + +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 new file mode 100644 index 0000000..98fa3e8 --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strlcat.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/09 06:44:30 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:36:04 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..bba4263 --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strlcpy.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/08 20:44:40 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:35:51 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..68c7614 --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strlen.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/07 16:32:28 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:35:37 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> + +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 new file mode 100644 index 0000000..7a38ca9 --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strmapi.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..c8a0b87 --- /dev/null +++ b/libft/ft_strncmp.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strncmp.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/07 20:25:31 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:35:01 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include <stddef.h> + +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 new file mode 100644 index 0000000..583026e --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strnstr.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/10 00:23:15 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:34:35 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> +#include <inttypes.h> + +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 new file mode 100644 index 0000000..47ba95b --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strrchr.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/07 19:07:53 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:34:19 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..c691815 --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_strtrim.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..87c2568 --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_substr.c                                      .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   Created: 2019/10/12 15:37:02 by rbousset     #+#   ##    ##    #+#       */ +/*   Updated: 2019/10/13 08:33:09 by rbousset    ###    #+. /#+    ###.fr     */ +/*                                                         /                  */ +/*                                                        /                   */ +/* ************************************************************************** */ + +#include "libft.h" +#include <stddef.h> + +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 new file mode 100644 index 0000000..48c065e --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_tolower.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 new file mode 100644 index 0000000..3346cc3 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   ft_toupper.c                                     .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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/libft.h b/libft/libft.h new file mode 100644 index 0000000..3ce9b07 --- /dev/null +++ b/libft/libft.h @@ -0,0 +1,99 @@ +/* ************************************************************************** */ +/*                                                          LE - /            */ +/*                                                              /             */ +/*   libft.h                                          .::    .:/ .      .::   */ +/*                                                 +:+:+   +:    +:  +:+:+    */ +/*   By: rbousset <marvin@le-101.fr>                +:+   +:    +:    +:+     */ +/*                                                 #+#   #+    #+    #+#      */ +/*   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 <stddef.h> +#include <inttypes.h> + +/* +** 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 new file mode 100644 index 0000000..d0cacd5 --- /dev/null +++ b/libft/main.c @@ -0,0 +1,122 @@ +#include "libft.h" +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <string.h> +#include <limits.h> +#include <inttypes.h> + +/* +** 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 <unistd.h> +** 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); +} | 
