diff --git a/2024/14/Makefile b/2024/14/Makefile index 0aa7ff9..22de7c4 100644 --- a/2024/14/Makefile +++ b/2024/14/Makefile @@ -6,7 +6,7 @@ # By: tomoron +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/07/17 15:48:36 by tomoron #+# #+# # -# Updated: 2024/12/14 14:02:58 by tomoron ### ########.fr # +# Updated: 2024/12/14 15:46:23 by tomoron ### ########.fr # # # # **************************************************************************** # @@ -16,7 +16,7 @@ SRCS = main.c\ OBJS = $(SRCS:.c=.o) -FLAGS = -Wextra -Werror -Wall -g +FLAGS = -Wextra -Werror -Wall -g -O0 LIB = libft/libft.a @@ -54,7 +54,7 @@ part2.c: cp ~/Desktop/aoc/part2.c . a.out: main.c $(OBJS) $(LIB) - clang $(FLAGS) $(OBJS) $(LIB) -Lmlx -lmlx -lX11 -lXext + clang $(FLAGS) $(OBJS) $(LIB) clean: rm -rf $(OBJS) diff --git a/2024/14/a.out b/2024/14/a.out deleted file mode 100755 index 67e58c4..0000000 Binary files a/2024/14/a.out and /dev/null differ diff --git a/2024/14/libft/Makefile b/2024/14/libft/Makefile deleted file mode 100755 index 437ea4c..0000000 --- a/2024/14/libft/Makefile +++ /dev/null @@ -1,99 +0,0 @@ -# **************************************************************************** # -# # ::: :::::::: # Makefile :+: :+: :+: # -# +:+ +:+ +:+ # -# By: tomoron +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2023/07/28 00:35:01 by tomoron #+# #+# # -# Updated: 2024/07/17 23:19:01 by tomoron ### ########.fr # -# # -# **************************************************************************** # - -NAME = libft.a - -CC = cc - -SRCS = ft_atoi.c\ - ft_bzero.c\ - ft_calloc.c\ - ft_isalnum.c\ - ft_isalpha.c\ - ft_isascii.c\ - ft_isdigit.c\ - ft_isprint.c\ - ft_itoa.c\ - ft_memchr.c\ - ft_memcmp.c\ - ft_memcpy.c\ - ft_memmove.c\ - ft_memset.c\ - ft_putchar_fd.c\ - ft_putendl_fd.c\ - ft_putnbr_fd.c\ - ft_putstr_fd.c\ - ft_split.c\ - ft_strchr.c\ - ft_strdup.c\ - ft_striteri.c\ - ft_strjoin.c\ - ft_strlcat.c\ - ft_strlcpy.c\ - ft_strlen.c\ - ft_strmapi.c\ - ft_strcmp.c\ - ft_strnstr.c\ - ft_strrchr.c\ - ft_strtrim.c\ - ft_substr.c\ - ft_tolower.c\ - ft_toupper.c\ - ft_split_set.c\ - ft_free_str_arr.c\ - ft_set_color.c - -SRCS_BONUS = ft_lstnew.c\ - ft_lstadd_front.c\ - ft_lstsize.c\ - ft_lstlast.c\ - ft_lstadd_back.c\ - ft_lstdelone.c\ - ft_lstclear.c\ - ft_lstiter.c\ - ft_lstmap.c\ - -OBJS = $(SRCS:.c=.o) -OBJS_BONUS = $(SRCS_BONUS:.c=.o) - -FLAGS = -Wall -Wextra -Werror -g - -all: $(NAME) - - -$(NAME): ft_printf $(OBJS) - make --no-print-directory -C ./ft_printf - cp ./ft_printf/libftprintf.a ./gnl/gnl.a - make --no-print-directory -C ./gnl - cp ./gnl/gnl.a ./$(NAME) - ar rcs $(NAME) $(OBJS) - -.c.o: - $(CC) $(FLAGS) -c $< -o $@ - -bonus: $(OBJS) $(OBJS_BONUS) - ar rcs $(NAME) $(OBJS) $(OBJS_BONUS) - -clean: - rm -f $(OBJS) $(OBJS_BONUS) - make --no-print-directory -C ./ft_printf fclean - make --no-print-directory -C ./gnl fclean - -fclean: clean - rm -f $(NAME) - -re: fclean all - -so: - $(CC) -nostartfiles -fPIC $(FLAGS) $(SRCS) - gcc -nostartfiles -shared -o libft.so $(OBJS) $(OBJS_BONUS) - - -.PHONY: bonus so clean all re fclean diff --git a/2024/14/libft/ft_atoi.c b/2024/14/libft/ft_atoi.c deleted file mode 100755 index 3b0badd..0000000 --- a/2024/14/libft/ft_atoi.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/17 13:41:15 by tomoron #+# #+# */ -/* Updated: 2023/10/31 15:35:21 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_atoi(const char *str) -{ - int res; - int inv; - - res = 0; - inv = 1; - while (*str == ' ' || (*str >= '\t' && *str <= '\r')) - str++; - if (*str == '+' || *str == '-') - { - if (*str == '-') - inv *= -1; - str++; - } - while (*str >= '0' && *str <= '9') - { - res *= 10; - res += *str - '0'; - str++; - } - return (res * inv); -} diff --git a/2024/14/libft/ft_atoi.o b/2024/14/libft/ft_atoi.o deleted file mode 100644 index 423cb72..0000000 Binary files a/2024/14/libft/ft_atoi.o and /dev/null differ diff --git a/2024/14/libft/ft_bzero.c b/2024/14/libft/ft_bzero.c deleted file mode 100755 index 8e328c6..0000000 --- a/2024/14/libft/ft_bzero.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_bzero.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:39:29 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:41:24 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_bzero(void *s, size_t n) -{ - unsigned long int i; - char *ptr; - - ptr = (char *)s; - i = 0; - while (i < n) - { - ptr[i] = 0; - i++; - } -} diff --git a/2024/14/libft/ft_bzero.o b/2024/14/libft/ft_bzero.o deleted file mode 100644 index 44a4e43..0000000 Binary files a/2024/14/libft/ft_bzero.o and /dev/null differ diff --git a/2024/14/libft/ft_calloc.c b/2024/14/libft/ft_calloc.c deleted file mode 100755 index 9314306..0000000 --- a/2024/14/libft/ft_calloc.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_calloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/31 02:38:46 by tomoron #+# #+# */ -/* Updated: 2023/10/31 18:15:42 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_calloc(size_t nb, size_t size) -{ - char *res; - unsigned long int i; - - if (nb == 0 || size == 0) - return (malloc(1)); - if ((long long)nb < 0 || (long long) size < 0) - return (0); - res = malloc(nb * size); - i = 0; - while (i < (nb * size) && res) - { - res[i] = 0; - i++; - } - return ((void *)res); -} diff --git a/2024/14/libft/ft_calloc.o b/2024/14/libft/ft_calloc.o deleted file mode 100644 index 1261a0d..0000000 Binary files a/2024/14/libft/ft_calloc.o and /dev/null differ diff --git a/2024/14/libft/ft_free_str_arr.c b/2024/14/libft/ft_free_str_arr.c deleted file mode 100755 index c4bd417..0000000 --- a/2024/14/libft/ft_free_str_arr.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_free_str_arr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/10 14:42:28 by tomoron #+# #+# */ -/* Updated: 2023/12/10 14:53:07 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_free_str_arr(char **arr) -{ - int i; - - if (!arr) - return ; - i = 0; - while (arr[i]) - { - free(arr[i]); - i++; - } - free(arr); -} diff --git a/2024/14/libft/ft_free_str_arr.o b/2024/14/libft/ft_free_str_arr.o deleted file mode 100644 index 437e392..0000000 Binary files a/2024/14/libft/ft_free_str_arr.o and /dev/null differ diff --git a/2024/14/libft/ft_isalnum.c b/2024/14/libft/ft_isalnum.c deleted file mode 100755 index a1fe540..0000000 --- a/2024/14/libft/ft_isalnum.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalnum.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:09:17 by tomoron #+# #+# */ -/* Updated: 2023/10/30 23:17:18 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isalnum(int c) -{ - if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9')) - return (1); - return (0); -} diff --git a/2024/14/libft/ft_isalnum.o b/2024/14/libft/ft_isalnum.o deleted file mode 100644 index 8fb3cb6..0000000 Binary files a/2024/14/libft/ft_isalnum.o and /dev/null differ diff --git a/2024/14/libft/ft_isalpha.c b/2024/14/libft/ft_isalpha.c deleted file mode 100755 index 6a8b074..0000000 --- a/2024/14/libft/ft_isalpha.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalpha.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/13 18:10:01 by tomoron #+# #+# */ -/* Updated: 2023/10/30 12:14:17 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isalpha(int c) -{ - if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))) - return (0); - return (1); -} diff --git a/2024/14/libft/ft_isalpha.o b/2024/14/libft/ft_isalpha.o deleted file mode 100644 index c409c1f..0000000 Binary files a/2024/14/libft/ft_isalpha.o and /dev/null differ diff --git a/2024/14/libft/ft_isascii.c b/2024/14/libft/ft_isascii.c deleted file mode 100755 index 5b85ccc..0000000 --- a/2024/14/libft/ft_isascii.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isascii.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:15:36 by tomoron #+# #+# */ -/* Updated: 2023/10/30 12:31:38 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isascii(int c) -{ - if (c >= 0 && c <= 127) - return (1); - return (0); -} diff --git a/2024/14/libft/ft_isascii.o b/2024/14/libft/ft_isascii.o deleted file mode 100644 index 2117f1e..0000000 Binary files a/2024/14/libft/ft_isascii.o and /dev/null differ diff --git a/2024/14/libft/ft_isdigit.c b/2024/14/libft/ft_isdigit.c deleted file mode 100755 index fe77533..0000000 --- a/2024/14/libft/ft_isdigit.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/13 18:10:01 by tomoron #+# #+# */ -/* Updated: 2023/10/30 12:13:53 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isdigit(int c) -{ - if (!(c >= '0' && c <= '9')) - return (0); - return (1); -} diff --git a/2024/14/libft/ft_isdigit.o b/2024/14/libft/ft_isdigit.o deleted file mode 100644 index adcec86..0000000 Binary files a/2024/14/libft/ft_isdigit.o and /dev/null differ diff --git a/2024/14/libft/ft_isprint.c b/2024/14/libft/ft_isprint.c deleted file mode 100755 index 7b5ceb6..0000000 --- a/2024/14/libft/ft_isprint.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isprint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:31:55 by tomoron #+# #+# */ -/* Updated: 2023/10/30 12:34:32 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isprint(int c) -{ - if (c >= 32 && c <= 126) - return (1); - return (0); -} diff --git a/2024/14/libft/ft_isprint.o b/2024/14/libft/ft_isprint.o deleted file mode 100644 index bb26982..0000000 Binary files a/2024/14/libft/ft_isprint.o and /dev/null differ diff --git a/2024/14/libft/ft_itoa.c b/2024/14/libft/ft_itoa.c deleted file mode 100755 index e076598..0000000 --- a/2024/14/libft/ft_itoa.c +++ /dev/null @@ -1,60 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 02:36:12 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:16:45 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int get_number_len(long int n) -{ - int res; - - res = 1; - if (n < 0) - { - res++; - n *= -1; - } - while (n > 9) - { - res++; - n /= 10; - } - return (res); -} - -char *ft_itoa(int n) -{ - char *res; - int nb_len; - int i; - long int temp_nb; - - temp_nb = (long int)n; - nb_len = get_number_len(n); - res = malloc((nb_len + 1) * sizeof(char)); - if (!res) - return (res); - i = 0; - if (temp_nb < 0) - { - res[0] = '-'; - temp_nb *= -1; - } - while (temp_nb > 9) - { - res[nb_len - i - 1] = (temp_nb % 10) + '0'; - temp_nb /= 10; - i++; - } - res[nb_len - i - 1] = temp_nb + '0'; - res[nb_len] = 0; - return (res); -} diff --git a/2024/14/libft/ft_itoa.o b/2024/14/libft/ft_itoa.o deleted file mode 100644 index ded9f9a..0000000 Binary files a/2024/14/libft/ft_itoa.o and /dev/null differ diff --git a/2024/14/libft/ft_lstadd_back.c b/2024/14/libft/ft_lstadd_back.c deleted file mode 100755 index 3aa43d7..0000000 --- a/2024/14/libft/ft_lstadd_back.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_back.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 15:44:09 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:13:03 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstadd_back(t_list **lst, t_list *new) -{ - t_list *current; - - if (!lst) - return ; - current = *lst; - while (current && current->next) - current = current->next; - if (!current) - *lst = new; - else - current->next = new; -} diff --git a/2024/14/libft/ft_lstadd_front.c b/2024/14/libft/ft_lstadd_front.c deleted file mode 100755 index 4e6a56a..0000000 --- a/2024/14/libft/ft_lstadd_front.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_front.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 15:51:22 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:12:41 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstadd_front(t_list **lst, t_list *new) -{ - new->next = *lst; - *lst = new; -} diff --git a/2024/14/libft/ft_lstclear.c b/2024/14/libft/ft_lstclear.c deleted file mode 100755 index fc79c03..0000000 --- a/2024/14/libft/ft_lstclear.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstclear.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 15:52:45 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:12:06 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstclear(t_list **lst, void (*del)(void*)) -{ - t_list *next; - - if (!lst || !del) - return ; - while (*lst) - { - next = (*lst)-> next; - del((*lst)-> content); - free(*lst); - *lst = next; - } -} diff --git a/2024/14/libft/ft_lstdelone.c b/2024/14/libft/ft_lstdelone.c deleted file mode 100755 index 80bbcfb..0000000 --- a/2024/14/libft/ft_lstdelone.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstdelone.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 15:56:36 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:13:47 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstdelone(t_list *lst, void (*del)(void*)) -{ - if (!lst || !del) - return ; - del(lst->content); - free(lst); -} diff --git a/2024/14/libft/ft_lstiter.c b/2024/14/libft/ft_lstiter.c deleted file mode 100755 index 0430cfd..0000000 --- a/2024/14/libft/ft_lstiter.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstiter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 16:35:30 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:13:21 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_lstiter(t_list *lst, void (*f)(void *)) -{ - while (lst) - { - f(lst->content); - lst = lst->next; - } -} diff --git a/2024/14/libft/ft_lstlast.c b/2024/14/libft/ft_lstlast.c deleted file mode 100755 index 6fa8909..0000000 --- a/2024/14/libft/ft_lstlast.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstlast.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 15:47:49 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:13:36 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -t_list *ft_lstlast(t_list *lst) -{ - while (lst && lst -> next) - lst = lst -> next; - return (lst); -} diff --git a/2024/14/libft/ft_lstmap.c b/2024/14/libft/ft_lstmap.c deleted file mode 100755 index 7715da4..0000000 --- a/2024/14/libft/ft_lstmap.c +++ /dev/null @@ -1,41 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstmap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 17:29:05 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:47:05 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) -{ - t_list *res; - t_list *current; - - if (!lst) - return (0); - res = malloc(sizeof(t_list)); - if (!res) - return (0); - res -> content = f(lst->content); - lst = lst->next; - current = res; - while (lst) - { - current->next = malloc(sizeof(t_list)); - if (!current->next) - { - ft_lstclear(&res, del); - return (0); - } - current = current->next; - current->content = f(lst->content); - lst = lst->next; - } - current->next = NULL; - return (res); -} diff --git a/2024/14/libft/ft_lstnew.c b/2024/14/libft/ft_lstnew.c deleted file mode 100755 index 8e78fb4..0000000 --- a/2024/14/libft/ft_lstnew.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstnew.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 15:39:52 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:11:12 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstnew(void *content) -{ - t_list *res; - - res = malloc (sizeof(t_list)); - if (!res) - return (0); - res->content = content; - res->next = NULL; - return (res); -} diff --git a/2024/14/libft/ft_lstsize.c b/2024/14/libft/ft_lstsize.c deleted file mode 100755 index 4fdfadf..0000000 --- a/2024/14/libft/ft_lstsize.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstsize.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 15:46:36 by tomoron #+# #+# */ -/* Updated: 2023/11/02 01:12:32 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_lstsize(t_list *lst) -{ - int res; - - res = 0; - while (lst) - { - res++; - lst = lst->next; - } - return (res); -} diff --git a/2024/14/libft/ft_memchr.c b/2024/14/libft/ft_memchr.c deleted file mode 100755 index 1691bba..0000000 --- a/2024/14/libft/ft_memchr.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 13:35:44 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:28:37 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memchr(const void *s, int c, size_t n) -{ - unsigned long int i; - unsigned char *p; - - i = 0; - p = (unsigned char *) s; - while (i < n) - { - if (p[i] == (unsigned char)c) - return ((char *)p + i); - i++; - } - return (0); -} diff --git a/2024/14/libft/ft_memchr.o b/2024/14/libft/ft_memchr.o deleted file mode 100644 index dbd3464..0000000 Binary files a/2024/14/libft/ft_memchr.o and /dev/null differ diff --git a/2024/14/libft/ft_memcmp.c b/2024/14/libft/ft_memcmp.c deleted file mode 100755 index dc57e59..0000000 --- a/2024/14/libft/ft_memcmp.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 13:59:31 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:23:04 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_memcmp(const void *s1, const void *s2, size_t n) -{ - unsigned int i; - unsigned char *str1; - unsigned char *str2; - - str1 = (unsigned char *)s1; - str2 = (unsigned char *)s2; - i = 0; - if (!n) - return (0); - while (str1[i] == str2[i] && i < n - 1) - i++; - return (str1[i] - str2[i]); -} diff --git a/2024/14/libft/ft_memcmp.o b/2024/14/libft/ft_memcmp.o deleted file mode 100644 index 48c2183..0000000 Binary files a/2024/14/libft/ft_memcmp.o and /dev/null differ diff --git a/2024/14/libft/ft_memcpy.c b/2024/14/libft/ft_memcpy.c deleted file mode 100755 index 7e1aced..0000000 --- a/2024/14/libft/ft_memcpy.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:42:28 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:05:58 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memcpy(void *dest, const void *src, size_t n) -{ - unsigned int i; - char *d; - char *s; - - d = (char *)dest; - s = (char *)src; - i = 0; - while (i < n && d && s) - { - d[i] = s[i]; - i++; - } - return (d); -} diff --git a/2024/14/libft/ft_memcpy.o b/2024/14/libft/ft_memcpy.o deleted file mode 100644 index 45c0881..0000000 Binary files a/2024/14/libft/ft_memcpy.o and /dev/null differ diff --git a/2024/14/libft/ft_memmove.c b/2024/14/libft/ft_memmove.c deleted file mode 100755 index 2f1c08b..0000000 --- a/2024/14/libft/ft_memmove.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memmove.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 13:20:17 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:23:24 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memmove(void *dest, const void *src, size_t n) -{ - unsigned int i; - unsigned char *d; - unsigned char *s; - - d = (unsigned char *) dest; - s = (unsigned char *) src; - i = 0; - while (i < n && d && s) - { - if (d > s) - d[n - i - 1] = s[n - i - 1]; - else - d[i] = s[i]; - i++; - } - return (dest); -} diff --git a/2024/14/libft/ft_memmove.o b/2024/14/libft/ft_memmove.o deleted file mode 100644 index 1b638dd..0000000 Binary files a/2024/14/libft/ft_memmove.o and /dev/null differ diff --git a/2024/14/libft/ft_memset.c b/2024/14/libft/ft_memset.c deleted file mode 100755 index a8408d0..0000000 --- a/2024/14/libft/ft_memset.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:36:09 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:23:45 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void *ft_memset(void *s, int c, size_t n) -{ - unsigned int i; - char *p; - - p = (char *)s; - i = 0; - while (i < n) - { - p[i] = c; - i++; - } - return (s); -} diff --git a/2024/14/libft/ft_memset.o b/2024/14/libft/ft_memset.o deleted file mode 100644 index 4e3655c..0000000 Binary files a/2024/14/libft/ft_memset.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/Makefile b/2024/14/libft/ft_printf/Makefile deleted file mode 100755 index e691c80..0000000 --- a/2024/14/libft/ft_printf/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -# **************************************************************************** # -# # -# ::: :::::::: # -# Makefile :+: :+: :+: # -# +:+ +:+ +:+ # -# By: tomoron +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2023/11/04 08:03:00 by tomoron #+# #+# # -# Updated: 2024/10/28 23:08:30 by tomoron ### ########.fr # -# # -# **************************************************************************** # - -NAME = libftprintf.a - -CC = cc - -SRCS = ft_protected_atoi.c\ - ft_convert.c\ - ft_isdigit.c\ - ft_parse_arg.c\ - ft_print_hex_ptr.c\ - ft_print_int.c\ - ft_print_unsigned_int.c\ - ft_printf.c\ - ft_putchar.c\ - ft_putstr.c\ - ft_strlen.c\ - ft_write_str_part.c - -OBJS = $(SRCS:.c=.o) - -FLAGS = -Wall -Wextra -Werror - -$(NAME): $(OBJS) - ar rcs $(NAME) $(OBJS) - -.c.o: - $(CC) $(FLAGS) -c $< -o $@ - -all: $(NAME) - -bonus: all - -clean: - rm -f $(OBJS) - -fclean: clean - rm -f $(NAME) - -re: fclean all - -.PHONY: bonus clean all re fclean diff --git a/2024/14/libft/ft_printf/ft_convert.c b/2024/14/libft/ft_printf/ft_convert.c deleted file mode 100755 index 61cc97c..0000000 --- a/2024/14/libft/ft_printf/ft_convert.c +++ /dev/null @@ -1,85 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_convert.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 23:24:31 by tomoron #+# #+# */ -/* Updated: 2023/11/07 23:55:33 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "ft_printf.h" - -size_t ft_fill_width(char c, int n) -{ - int res; - - res = n; - if (res < 0) - res = 0; - while (n > 0) - { - ft_putchar(c); - n--; - } - return (res); -} - -size_t ft_print_char(int c, t_flags flags) -{ - int res; - - res = 0; - if (flags.min_width && !flags.left_justify) - res += ft_fill_width(' ', flags.min_width - 1); - res += ft_putchar((char)c); - if (flags.min_width && flags.left_justify) - res += ft_fill_width(' ', flags.min_width - 1); - return (res); -} - -size_t ft_print_str(char *s, t_flags flags) -{ - int nb_to_print; - int res; - - res = 0; - if (!s && (flags.precision >= 6 || flags.precision == -1)) - s = "(null)"; - else if (!s) - s = ""; - nb_to_print = ft_strlen(s); - if (flags.precision != -1 && nb_to_print > flags.precision) - nb_to_print = flags.precision; - if (flags.min_width && !flags.left_justify) - res += ft_fill_width(' ', flags.min_width - nb_to_print); - write(1, s, nb_to_print); - if (flags.min_width && flags.left_justify) - res += ft_fill_width(' ', flags.min_width - nb_to_print); - return (res + nb_to_print); -} - -size_t ft_convert(char *s, t_flags flags, va_list args, int err) -{ - if (*s == 'c') - return (ft_print_char(va_arg(args, int), flags)); - else if (*s == 's') - return (ft_print_str(va_arg(args, char *), flags)); - else if (*s == 'p') - return (ft_print_ptr(va_arg(args, void *), flags)); - else if (*s == 'd' || *s == 'i') - return (ft_print_signed_int(va_arg(args, int), flags)); - else if (*s == 'u') - return (ft_print_unsigned_int(va_arg(args, unsigned int), flags)); - else if (*s == 'x') - return (ft_print_hex(va_arg(args, unsigned int), flags, 'L')); - else if (*s == 'X') - return (ft_print_hex(va_arg(args, unsigned int), flags, 'U')); - else if (*s == '%') - return (ft_putstr("%")); - else if (err != 2) - return (ft_putstr("%")); - else - return (0); -} diff --git a/2024/14/libft/ft_printf/ft_convert.o b/2024/14/libft/ft_printf/ft_convert.o deleted file mode 100644 index 92b117f..0000000 Binary files a/2024/14/libft/ft_printf/ft_convert.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_isdigit.c b/2024/14/libft/ft_printf/ft_isdigit.c deleted file mode 100755 index fe77533..0000000 --- a/2024/14/libft/ft_printf/ft_isdigit.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/13 18:10:01 by tomoron #+# #+# */ -/* Updated: 2023/10/30 12:13:53 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_isdigit(int c) -{ - if (!(c >= '0' && c <= '9')) - return (0); - return (1); -} diff --git a/2024/14/libft/ft_printf/ft_isdigit.o b/2024/14/libft/ft_printf/ft_isdigit.o deleted file mode 100644 index 383482e..0000000 Binary files a/2024/14/libft/ft_printf/ft_isdigit.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_parse_arg.c b/2024/14/libft/ft_printf/ft_parse_arg.c deleted file mode 100755 index 09af1e2..0000000 --- a/2024/14/libft/ft_printf/ft_parse_arg.c +++ /dev/null @@ -1,89 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_parse_arg.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 11:43:10 by tomoron #+# #+# */ -/* Updated: 2023/11/15 14:32:59 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_is_char_in_flags(char *s, char c) -{ - int i; - - i = 0; - while (s[i] == '-' || s[i] == '0' || s[i] == '#' - || s[i] == ' ' || s[i] == '+') - { - if (s[i] == c) - return (1); - i++; - } - return (0); -} - -void ft_get_width_precision(char **s, va_list args, t_flags *flags, int *err) -{ - if (**s == '*') - flags->min_width = va_arg(args, int); - else - flags->min_width = ft_protected_atoi(*s); - while (ft_isdigit(**s) || **s == '*') - (*s)++; - flags->precision = -1; - if (**s == '.' && *(*s + 1) == '*') - flags->precision = va_arg(args, int); - else if (**s == '.') - { - if (ft_isdigit(*(*s + 1))) - flags->precision = ft_protected_atoi(*s + 1); - else - flags->precision = 0; - (*s)++; - } - while (ft_isdigit(**s) || **s == '.' || **s == '*') - (*s)++; - if (flags->min_width == -2 || flags->precision == -2) - *err = 3; -} - -void ft_get_flags(char **s, va_list args, t_flags *flags, int *err) -{ - flags->left_justify = ft_is_char_in_flags(*s, '-'); - flags->zero_padding = ft_is_char_in_flags(*s, '0'); - flags->always_sign_number = ft_is_char_in_flags(*s, '+'); - flags->blank_positive = ft_is_char_in_flags(*s, ' '); - flags->zero_x_prefix = ft_is_char_in_flags(*s, '#'); - while (**s == '-' || **s == '0' || **s == '#' - || **s == ' ' || **s == '+') - { - (*s)++; - } - return (ft_get_width_precision(s, args, flags, err)); -} - -size_t ft_parse_arg(char **s, va_list args, int *err) -{ - t_flags flags; - size_t res; - - res = 0; - if (**s == '%') - { - (*s)++; - ft_get_flags(s, args, &flags, err); - if (*err == 3) - return (0); - res += ft_convert(*s, flags, args, *err); - if (**s == 'c' || **s == 's' || **s == 'p' || **s == 'd' - || **s == 'i' || **s == 'u' || **s == 'x' - || **s == 'X' || **s == '%') - (*s)++; - } - return (res); -} diff --git a/2024/14/libft/ft_printf/ft_parse_arg.o b/2024/14/libft/ft_printf/ft_parse_arg.o deleted file mode 100644 index 7ed91ec..0000000 Binary files a/2024/14/libft/ft_printf/ft_parse_arg.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_print_hex_ptr.c b/2024/14/libft/ft_printf/ft_print_hex_ptr.c deleted file mode 100755 index c957134..0000000 --- a/2024/14/libft/ft_printf/ft_print_hex_ptr.c +++ /dev/null @@ -1,97 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_hex_ptr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/05 15:58:57 by tomoron #+# #+# */ -/* Updated: 2023/11/05 15:58:58 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "ft_printf.h" - -int ft_calc_hex_len(long unsigned int n, t_flags flags) -{ - int res; - - res = 1; - if (n == 0 && flags.precision == 0) - return (0); - while (n > 15) - { - res++; - n /= 16; - } - return (res); -} - -void ft_put_hex(unsigned long int n, char mode) -{ - if (n > 15) - ft_put_hex(n / 16, mode); - if (mode == 'L') - write(1, &"0123456789abcdef"[n % 16], 1); - if (mode == 'U') - write(1, &"0123456789ABCDEF"[n % 16], 1); -} - -size_t ft_print_ptr(void *ptr, t_flags flags) -{ - int len; - int res; - - res = 0; - if (!ptr) - return (ft_print_str("(nil)", flags)); - len = ft_calc_hex_len((long unsigned int)ptr, flags) + 2; - if (flags.min_width && !flags.left_justify) - res += ft_fill_width(' ', flags.min_width - len); - ft_putstr("0x"); - ft_put_hex((unsigned long int)ptr, 'L'); - if (flags.min_width && flags.left_justify) - res += ft_fill_width(' ', flags.min_width - len); - return (res + len); -} - -size_t ft_write_blank(int blank_len, t_flags flags, char mode) -{ - size_t res; - - res = 0; - if (blank_len > 0 && ((flags.left_justify && mode == 'A') - || (!flags.left_justify && mode == 'B'))) - { - if (flags.zero_padding && flags.precision == -1) - res += ft_fill_width('0', blank_len); - else - res += ft_fill_width(' ', blank_len); - } - return (res); -} - -size_t ft_print_hex(unsigned int nb, t_flags flags, char mode) -{ - int blank_len; - int zero_len; - int number_len; - size_t res; - - number_len = ft_calc_hex_len(nb, flags); - res = number_len; - zero_len = 0; - if (flags.precision > number_len) - zero_len = flags.precision - number_len; - blank_len = flags.min_width - zero_len - number_len; - blank_len -= flags.zero_x_prefix * 2; - res += ft_write_blank(blank_len, flags, 'B'); - if (flags.zero_x_prefix && nb && mode == 'L') - res += ft_putstr("0x"); - if (flags.zero_x_prefix && nb && mode == 'U') - res += ft_putstr("0X"); - res += ft_fill_width('0', zero_len); - if (flags.precision != 0 || nb != 0) - ft_put_hex(nb, mode); - res += ft_write_blank(blank_len, flags, 'A'); - return (res); -} diff --git a/2024/14/libft/ft_printf/ft_print_hex_ptr.o b/2024/14/libft/ft_printf/ft_print_hex_ptr.o deleted file mode 100644 index 007b24d..0000000 Binary files a/2024/14/libft/ft_printf/ft_print_hex_ptr.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_print_int.c b/2024/14/libft/ft_printf/ft_print_int.c deleted file mode 100755 index b710860..0000000 --- a/2024/14/libft/ft_printf/ft_print_int.c +++ /dev/null @@ -1,99 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/05 15:52:46 by tomoron #+# #+# */ -/* Updated: 2023/11/05 15:53:56 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -int ft_calc_signed_int_len(int nb, t_flags flags) -{ - int res; - long int n; - - res = 1; - n = (long int) nb; - if (flags.precision == 0 && nb == 0) - return (0); - if (n < 0) - { - n = n * -1; - } - while (n > 9) - { - res++; - n /= 10; - } - return (res); -} - -size_t ft_putsign(int nb, t_flags flags, int sign) -{ - if (nb < 0) - return (ft_putchar('-')); - if (sign && flags.blank_positive) - return (ft_putchar(' ')); - if (sign) - return (ft_putchar('+')); - return (0); -} - -int ft_print_signed_int_blank_sign(int nb, t_flags flags, size_t *res) -{ - int blank_len; - int zero_len; - int number_len; - int sign; - - number_len = ft_calc_signed_int_len(nb, flags); - sign = (nb < 0) || flags.always_sign_number || flags.blank_positive; - zero_len = 0; - if (flags.precision > number_len) - zero_len = flags.precision - number_len; - blank_len = flags.min_width - zero_len - number_len - sign; - if (blank_len > 0 && !flags.left_justify && ((!flags.zero_padding - && nb != 0) || (flags.zero_padding && flags.precision != -1))) - *res += ft_fill_width(' ', blank_len); - *res += ft_putsign(nb, flags, sign); - if (blank_len > 0 && !flags.left_justify && flags.zero_padding - && flags.precision == -1) - *res += ft_fill_width('0', blank_len); - *res += ft_fill_width('0', zero_len); - return (blank_len); -} - -void ft_put_lu_nbr(long unsigned int nb) -{ - if (nb > 9) - ft_put_lu_nbr(nb / 10); - ft_putchar("0123456789"[nb % 10]); -} - -size_t ft_print_signed_int(int nb, t_flags flags) -{ - int blank_len; - long int n; - size_t res; - - res = ft_calc_signed_int_len(nb, flags); - n = (long int)nb; - if (n < 0) - n *= -1; - blank_len = ft_print_signed_int_blank_sign(nb, flags, &res); - if (flags.precision != 0 || nb != 0) - ft_put_lu_nbr((long unsigned int)n); - if (blank_len > 0 && flags.left_justify) - { - if (flags.zero_padding) - res += ft_fill_width('0', blank_len); - else - res += ft_fill_width(' ', blank_len); - } - return (res); -} diff --git a/2024/14/libft/ft_printf/ft_print_int.o b/2024/14/libft/ft_printf/ft_print_int.o deleted file mode 100644 index 941e2d1..0000000 Binary files a/2024/14/libft/ft_printf/ft_print_int.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_print_unsigned_int.c b/2024/14/libft/ft_printf/ft_print_unsigned_int.c deleted file mode 100755 index e324164..0000000 --- a/2024/14/libft/ft_printf/ft_print_unsigned_int.c +++ /dev/null @@ -1,55 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_print_unsigned_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/05 16:06:48 by tomoron #+# #+# */ -/* Updated: 2023/11/05 16:06:49 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "ft_printf.h" - -int ft_calc_unsigned_int_len(unsigned int nb, t_flags flags) -{ - int res; - - res = 1; - if (nb == 0 && flags.precision == 0) - return (0); - while (nb > 9) - { - res++; - nb /= 10; - } - return (res); -} - -size_t ft_print_unsigned_int(unsigned int nb, t_flags flags) -{ - int blank_len; - int zero_len; - int number_len; - size_t res; - - number_len = ft_calc_unsigned_int_len(nb, flags); - res = number_len; - zero_len = 0; - if (flags.precision > number_len) - zero_len = flags.precision - number_len; - blank_len = flags.min_width - zero_len - number_len; - if (blank_len > 0 && !flags.left_justify && flags.zero_padding - && flags.precision == -1) - res += ft_fill_width('0', blank_len); - else if (blank_len > 0 && !flags.left_justify) - res += ft_fill_width(' ', blank_len); - res += ft_fill_width('0', zero_len); - if (flags.precision != 0 || nb != 0) - ft_put_lu_nbr(nb); - if (blank_len > 0 && flags.left_justify && flags.zero_padding) - res += ft_fill_width('0', blank_len); - else if (blank_len > 0 && flags.left_justify) - res += ft_fill_width(' ', blank_len); - return (res); -} diff --git a/2024/14/libft/ft_printf/ft_print_unsigned_int.o b/2024/14/libft/ft_printf/ft_print_unsigned_int.o deleted file mode 100644 index 932f2c1..0000000 Binary files a/2024/14/libft/ft_printf/ft_print_unsigned_int.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_printf.c b/2024/14/libft/ft_printf/ft_printf.c deleted file mode 100755 index 19a0964..0000000 --- a/2024/14/libft/ft_printf/ft_printf.c +++ /dev/null @@ -1,67 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/02 23:41:38 by tomoron #+# #+# */ -/* Updated: 2023/11/08 14:51:19 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "ft_printf.h" - -int ft_check_placeholders(const char *str) -{ - int err; - - err = 0; - while (*str) - { - while (*str && *str != '%') - str++; - if (*str == '%') - { - str++; - while (*str == '-' || *str == '0' || *str == '#' - || *str == ' ' || *str == '+' || ft_isdigit(*str)) - str++; - if (*str != 'c' && *str != 's' && *str != 'p' && *str != 'd' - && *str && *str != 'i' && *str != 'u' && *str != 'x' - && *str != 'X' && *str != '%') - err = 1; - if (!*str && err == 0) - err = 2; - if (*str == '%') - str++; - } - } - return (err); -} - -int ft_printf(const char *str, ...) -{ - va_list args; - size_t res; - char *s; - int err; - - if (!str) - return (-1); - va_start(args, str); - res = 0; - s = (char *)str; - err = ft_check_placeholders(s); - res += ft_write_str_part(&s); - while (*s) - { - res += ft_parse_arg(&s, args, &err); - if (err == 3) - break ; - res += ft_write_str_part(&s); - } - va_end(args); - if (err >= 2) - return (-1); - return (res); -} diff --git a/2024/14/libft/ft_printf/ft_printf.h b/2024/14/libft/ft_printf/ft_printf.h deleted file mode 100755 index dfffefe..0000000 --- a/2024/14/libft/ft_printf/ft_printf.h +++ /dev/null @@ -1,46 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_printf.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/02 23:42:00 by tomoron #+# #+# */ -/* Updated: 2023/11/15 14:31:34 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef FT_PRINTF_H -# define FT_PRINTF_H -# include -# include - -typedef struct s_flags -{ - int left_justify; - int zero_padding; - int always_sign_number; - int blank_positive; - int zero_x_prefix; - int min_width; - int precision; -} t_flags; - -int ft_printf(const char *str, ...); -size_t ft_write_str_part(char **s); -size_t ft_parse_arg(char **s, va_list args, int *err); -size_t ft_convert(char *s, t_flags flags, va_list args, int err); -size_t ft_putchar(char c); -size_t ft_putstr(char *s); -size_t ft_strlen(char const *s); -int ft_protected_atoi(const char *s); -int ft_isdigit(int c); -size_t ft_print_unsigned_int(unsigned int nb, t_flags flags); -size_t ft_print_signed_int(int nb, t_flags flags); -size_t ft_fill_width(char c, int n); -size_t ft_print_hex(unsigned int nb, t_flags flags, char mode); -size_t ft_print_ptr(void *ptr, t_flags flags); -size_t ft_print_str(char *s, t_flags flags); -void ft_put_lu_nbr(long unsigned int nb); - -#endif diff --git a/2024/14/libft/ft_printf/ft_printf.o b/2024/14/libft/ft_printf/ft_printf.o deleted file mode 100644 index 3952800..0000000 Binary files a/2024/14/libft/ft_printf/ft_printf.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_protected_atoi.c b/2024/14/libft/ft_printf/ft_protected_atoi.c deleted file mode 100755 index 09dcfc9..0000000 --- a/2024/14/libft/ft_printf/ft_protected_atoi.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/17 13:41:15 by tomoron #+# #+# */ -/* Updated: 2023/11/15 14:31:19 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_protected_atoi(const char *str) -{ - long long res; - int inv; - - res = 0; - inv = 1; - while (*str == ' ' || (*str >= '\t' && *str <= '\r')) - str++; - if (*str == '+' || *str == '-') - { - if (*str == '-') - inv *= -1; - str++; - } - while (*str >= '0' && *str <= '9') - { - res *= 10; - res += *str - '0'; - str++; - } - if (res > 2147483647) - return (-2); - return ((int)res * inv); -} diff --git a/2024/14/libft/ft_printf/ft_protected_atoi.o b/2024/14/libft/ft_printf/ft_protected_atoi.o deleted file mode 100644 index a70ff37..0000000 Binary files a/2024/14/libft/ft_printf/ft_protected_atoi.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_putchar.c b/2024/14/libft/ft_printf/ft_putchar.c deleted file mode 100755 index 84bbe70..0000000 --- a/2024/14/libft/ft_printf/ft_putchar.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 04:10:53 by tomoron #+# #+# */ -/* Updated: 2023/11/05 15:51:33 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "ft_printf.h" - -size_t ft_putchar(char c) -{ - write(1, &c, 1); - return (1); -} diff --git a/2024/14/libft/ft_printf/ft_putchar.o b/2024/14/libft/ft_printf/ft_putchar.o deleted file mode 100644 index bb8886f..0000000 Binary files a/2024/14/libft/ft_printf/ft_putchar.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_putstr.c b/2024/14/libft/ft_printf/ft_putstr.c deleted file mode 100755 index c742ffc..0000000 --- a/2024/14/libft/ft_printf/ft_putstr.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */ -/* Updated: 2023/11/05 14:42:32 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "ft_printf.h" - -size_t ft_putstr(char *s) -{ - if (s) - write(1, s, ft_strlen(s)); - return (ft_strlen(s)); -} diff --git a/2024/14/libft/ft_printf/ft_putstr.o b/2024/14/libft/ft_printf/ft_putstr.o deleted file mode 100644 index 5809448..0000000 Binary files a/2024/14/libft/ft_printf/ft_putstr.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_strlen.c b/2024/14/libft/ft_printf/ft_strlen.c deleted file mode 100755 index e9f507f..0000000 --- a/2024/14/libft/ft_printf/ft_strlen.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlen.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:34:41 by tomoron #+# #+# */ -/* Updated: 2023/11/04 08:19:20 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "ft_printf.h" - -size_t ft_strlen(const char *str) -{ - unsigned int n; - - n = 0; - while (str[n]) - n++; - return (n); -} diff --git a/2024/14/libft/ft_printf/ft_strlen.o b/2024/14/libft/ft_printf/ft_strlen.o deleted file mode 100644 index 2fefa23..0000000 Binary files a/2024/14/libft/ft_printf/ft_strlen.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/ft_write_str_part.c b/2024/14/libft/ft_printf/ft_write_str_part.c deleted file mode 100755 index 3dc57ff..0000000 --- a/2024/14/libft/ft_printf/ft_write_str_part.c +++ /dev/null @@ -1,26 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_write_str_part.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/03 11:16:38 by tomoron #+# #+# */ -/* Updated: 2023/11/05 15:50:41 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "ft_printf.h" - -size_t ft_write_str_part(char **s) -{ - size_t i; - - i = 0; - while ((*s)[i] != '%' && (*s)[i]) - i++; - if (i) - write(1, *s, i); - *s += i; - return (i); -} diff --git a/2024/14/libft/ft_printf/ft_write_str_part.o b/2024/14/libft/ft_printf/ft_write_str_part.o deleted file mode 100644 index 98ca530..0000000 Binary files a/2024/14/libft/ft_printf/ft_write_str_part.o and /dev/null differ diff --git a/2024/14/libft/ft_printf/libftprintf.a b/2024/14/libft/ft_printf/libftprintf.a deleted file mode 100644 index a188b2a..0000000 Binary files a/2024/14/libft/ft_printf/libftprintf.a and /dev/null differ diff --git a/2024/14/libft/ft_putchar_fd.c b/2024/14/libft/ft_putchar_fd.c deleted file mode 100755 index f63e488..0000000 --- a/2024/14/libft/ft_putchar_fd.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 04:10:53 by tomoron #+# #+# */ -/* Updated: 2024/10/29 20:36:57 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putchar_fd(char c, int fd) -{ - (void) write(fd, &c, 1); -} diff --git a/2024/14/libft/ft_putchar_fd.o b/2024/14/libft/ft_putchar_fd.o deleted file mode 100644 index 645440c..0000000 Binary files a/2024/14/libft/ft_putchar_fd.o and /dev/null differ diff --git a/2024/14/libft/ft_putendl_fd.c b/2024/14/libft/ft_putendl_fd.c deleted file mode 100755 index 8d6b9c5..0000000 --- a/2024/14/libft/ft_putendl_fd.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */ -/* Updated: 2024/10/29 20:39:37 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putendl_fd(char *s, int fd) -{ - if (s) - { - write(fd, s, ft_strlen(s)); - write(fd, "\n", 1); - } -} diff --git a/2024/14/libft/ft_putendl_fd.o b/2024/14/libft/ft_putendl_fd.o deleted file mode 100644 index 594c108..0000000 Binary files a/2024/14/libft/ft_putendl_fd.o and /dev/null differ diff --git a/2024/14/libft/ft_putnbr_fd.c b/2024/14/libft/ft_putnbr_fd.c deleted file mode 100755 index 6a3a8a1..0000000 --- a/2024/14/libft/ft_putnbr_fd.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putnbr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/11 23:27:29 by tomoron #+# #+# */ -/* Updated: 2024/10/29 20:40:28 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putnbr_fd(int nb, int fd) -{ - if (nb >= 10) - { - ft_putnbr_fd(nb / 10, fd); - ft_putchar_fd((nb % 10) + 48, fd); - } - else if (nb < 0) - { - if (nb == -2147483648) - write(fd, "-2147483648", 11); - else - { - ft_putchar_fd('-', fd); - ft_putnbr_fd(nb * -1, fd); - } - } - else - ft_putchar_fd((nb % 10) + 48, fd); -} diff --git a/2024/14/libft/ft_putnbr_fd.o b/2024/14/libft/ft_putnbr_fd.o deleted file mode 100644 index 9df9287..0000000 Binary files a/2024/14/libft/ft_putnbr_fd.o and /dev/null differ diff --git a/2024/14/libft/ft_putstr_fd.c b/2024/14/libft/ft_putstr_fd.c deleted file mode 100755 index f2b20e2..0000000 --- a/2024/14/libft/ft_putstr_fd.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */ -/* Updated: 2024/10/29 20:40:22 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -void ft_putstr_fd(char *s, int fd) -{ - if (s) - write(fd, s, ft_strlen(s)); -} diff --git a/2024/14/libft/ft_putstr_fd.o b/2024/14/libft/ft_putstr_fd.o deleted file mode 100644 index d95dc13..0000000 Binary files a/2024/14/libft/ft_putstr_fd.o and /dev/null differ diff --git a/2024/14/libft/ft_set_color.c b/2024/14/libft/ft_set_color.c deleted file mode 100755 index f44b6e6..0000000 --- a/2024/14/libft/ft_set_color.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_set_color.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/01/10 10:56:11 by tomoron #+# #+# */ -/* Updated: 2024/01/10 14:10:42 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_set_color(int r, int g, int b) -{ - ft_printf("\033[38;2;%d;%d;%dm", r, g, b); -} - -void ft_reset_color(void) -{ - ft_printf("\033[0m"); -} diff --git a/2024/14/libft/ft_set_color.o b/2024/14/libft/ft_set_color.o deleted file mode 100644 index c071402..0000000 Binary files a/2024/14/libft/ft_set_color.o and /dev/null differ diff --git a/2024/14/libft/ft_split.c b/2024/14/libft/ft_split.c deleted file mode 100755 index 000e1b4..0000000 --- a/2024/14/libft/ft_split.c +++ /dev/null @@ -1,73 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_split.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/25 10:30:03 by tomoron #+# #+# */ -/* Updated: 2023/11/01 15:18:57 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int ft_count_parts(char *str, char charset) -{ - int res; - - res = 0; - while (*str == charset && *str) - str++; - while (*str) - { - while (!(*str == charset) && *str) - str++; - while (*str == charset && *str) - str++; - res++; - } - return (res + 1); -} - -static int ft_strlen_sep(char *str, char charset) -{ - int res; - - res = 0; - while (*str && !(*str == charset)) - { - res++; - str++; - } - return (res + 1); -} - -char **ft_split(const char *str, char charset) -{ - int nb_str; - char **res; - int i; - int j; - - if (!str) - return (0); - nb_str = ft_count_parts((char *)str, charset); - res = (char **)malloc(nb_str * sizeof(char *)); - i = -1; - while (res && *str && *str == charset) - str++; - while (++i < nb_str - 1 && *str && res) - { - res[i] = malloc(ft_strlen_sep((char *)str, charset)); - j = 0; - while (res[i] && *str && !(*str == charset)) - res[i][j++] = *(str++); - res[i][j] = 0; - while (*str == charset) - str++; - } - if (res) - res[i] = 0; - return (res); -} diff --git a/2024/14/libft/ft_split.o b/2024/14/libft/ft_split.o deleted file mode 100644 index 05c97f5..0000000 Binary files a/2024/14/libft/ft_split.o and /dev/null differ diff --git a/2024/14/libft/ft_split_set.c b/2024/14/libft/ft_split_set.c deleted file mode 100755 index 023f0ce..0000000 --- a/2024/14/libft/ft_split_set.c +++ /dev/null @@ -1,84 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_split_set.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/25 10:30:03 by tomoron #+# #+# */ -/* Updated: 2023/11/21 15:37:48 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include - -int ft_is_sep(char c, char *sep) -{ - while (*sep) - { - if (*sep == c) - return (1); - sep++; - } - return (0); -} - -int ft_count_parts(char *str, char *charset) -{ - int res; - - res = 0; - while (ft_is_sep(*str, charset) && *str) - str++; - while (*str) - { - while (!ft_is_sep(*str, charset) && *str) - str++; - while (ft_is_sep(*str, charset) && *str) - str++; - res++; - } - return (res + 1); -} - -int ft_strlen_sep(char *str, char *charset) -{ - int res; - - res = 0; - while (*str && !ft_is_sep(*str, charset)) - { - res++; - str++; - } - return (res + 1); -} - -char **ft_split_set(char *str, char *charset) -{ - int str_len; - int nb_str; - char **res; - int i; - int j; - - nb_str = ft_count_parts(str, charset); - res = (char **)malloc(nb_str * sizeof(char *)); - i = -1; - while (ft_is_sep(*str, charset)) - str++; - while (++i < nb_str - 1 && *str && res) - { - str_len = ft_strlen_sep(str, charset); - res[i] = malloc(str_len * sizeof(char)); - j = 0; - while (res[i] && *str && !ft_is_sep(*str, charset)) - res[i][j++] = *(str++); - res[i][j] = 0; - while (ft_is_sep(*str, charset)) - str++; - } - if (res) - res[i] = 0; - return (res); -} diff --git a/2024/14/libft/ft_split_set.o b/2024/14/libft/ft_split_set.o deleted file mode 100644 index 17b7bfa..0000000 Binary files a/2024/14/libft/ft_split_set.o and /dev/null differ diff --git a/2024/14/libft/ft_strchr.c b/2024/14/libft/ft_strchr.c deleted file mode 100755 index 978f990..0000000 --- a/2024/14/libft/ft_strchr.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 13:35:44 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:08:17 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strchr(const char *s, int c) -{ - int i; - char *res; - - i = 0; - res = (char *)s; - while (res[i]) - { - if (res[i] == (unsigned char)c) - return (res + i); - i++; - } - if (res[i] == (unsigned char)c) - return (res + i); - return (NULL); -} diff --git a/2024/14/libft/ft_strchr.o b/2024/14/libft/ft_strchr.o deleted file mode 100644 index cd443db..0000000 Binary files a/2024/14/libft/ft_strchr.o and /dev/null differ diff --git a/2024/14/libft/ft_strcmp.c b/2024/14/libft/ft_strcmp.c deleted file mode 100755 index 6157587..0000000 --- a/2024/14/libft/ft_strcmp.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/15 21:47:47 by tomoron #+# #+# */ -/* Updated: 2023/12/03 17:06:39 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -int ft_strncmp(const char *s1, const char *s2, size_t n) -{ - unsigned int i; - - i = 0; - if (!n) - return (0); - while (s1[i] == s2[i] && s1[i] && i < n - 1) - i++; - return ((unsigned char)s1[i] - (unsigned char)s2[i]); -} - -int ft_strcmp(char *s1, char *s2) -{ - int i; - - i = 0; - while (s1[i] == s2[i] && s1[i]) - i++; - return (s1[i] - s2[i]); -} diff --git a/2024/14/libft/ft_strcmp.o b/2024/14/libft/ft_strcmp.o deleted file mode 100644 index 55cd281..0000000 Binary files a/2024/14/libft/ft_strcmp.o and /dev/null differ diff --git a/2024/14/libft/ft_strdup.c b/2024/14/libft/ft_strdup.c deleted file mode 100755 index 8a968e4..0000000 --- a/2024/14/libft/ft_strdup.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/24 14:55:26 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:13:46 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strdup(const char *src) -{ - char *res; - int len; - int i; - - len = 0; - i = 0; - if (!src) - return (0); - while (src[len]) - len++; - res = (char *)malloc((len + 1) * sizeof(char)); - if (!res) - return (0); - while (src[i]) - { - res[i] = src[i]; - i++; - } - res[i] = 0; - return (res); -} diff --git a/2024/14/libft/ft_strdup.o b/2024/14/libft/ft_strdup.o deleted file mode 100644 index 24d5349..0000000 Binary files a/2024/14/libft/ft_strdup.o and /dev/null differ diff --git a/2024/14/libft/ft_striteri.c b/2024/14/libft/ft_striteri.c deleted file mode 100755 index 488b17e..0000000 --- a/2024/14/libft/ft_striteri.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_striteri.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 04:08:53 by tomoron #+# #+# */ -/* Updated: 2023/11/01 14:04:59 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -void ft_striteri(char *s, void (*f)(unsigned int, char*)) -{ - int i; - - i = 0; - while (s && s[i]) - { - f(i, s + i); - i++; - } -} diff --git a/2024/14/libft/ft_striteri.o b/2024/14/libft/ft_striteri.o deleted file mode 100644 index 2f18f46..0000000 Binary files a/2024/14/libft/ft_striteri.o and /dev/null differ diff --git a/2024/14/libft/ft_strjoin.c b/2024/14/libft/ft_strjoin.c deleted file mode 100755 index cec1deb..0000000 --- a/2024/14/libft/ft_strjoin.c +++ /dev/null @@ -1,63 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strjoin.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/24 18:06:14 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:26:09 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int calc_str_len(char const *s1, char const *s2) -{ - int res; - int i; - - res = 0; - i = 0; - while (s1[i]) - { - i++; - res++; - } - i = 0; - while (s2[i]) - { - i++; - res++; - } - return (res); -} - -char *ft_strjoin(char const *s1, char const *s2) -{ - char *res; - int len; - int i; - int j; - - j = 0; - if (!s1 || !s2) - return (0); - len = calc_str_len(s1, s2); - res = malloc((len + 1) * sizeof(char)); - while (res && s1[j]) - { - res[j] = s1[j]; - j++; - } - i = 0; - while (res && s2[i]) - { - res[j] = s2[i]; - i++; - j++; - } - if (res) - res[j] = 0; - return (res); -} diff --git a/2024/14/libft/ft_strjoin.o b/2024/14/libft/ft_strjoin.o deleted file mode 100644 index b1be606..0000000 Binary files a/2024/14/libft/ft_strjoin.o and /dev/null differ diff --git a/2024/14/libft/ft_strlcat.c b/2024/14/libft/ft_strlcat.c deleted file mode 100755 index 2444604..0000000 --- a/2024/14/libft/ft_strlcat.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/16 03:16:22 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:47:42 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcat(char *dst, const char *src, size_t size) -{ - unsigned int dst_len; - unsigned int i; - unsigned int ret_val; - - if (!dst || !src) - return (0); - dst_len = ft_strlen(dst); - if (!size) - return (ft_strlen(src)); - if (size < dst_len) - return (ft_strlen(src) + size); - i = 0; - ret_val = dst_len + ft_strlen(src); - while (src[i] && size > dst_len + 1) - { - dst[dst_len] = src[i]; - i++; - dst_len++; - } - dst[dst_len] = 0; - return (ret_val); -} diff --git a/2024/14/libft/ft_strlcat.o b/2024/14/libft/ft_strlcat.o deleted file mode 100644 index 3d78a21..0000000 Binary files a/2024/14/libft/ft_strlcat.o and /dev/null differ diff --git a/2024/14/libft/ft_strlcpy.c b/2024/14/libft/ft_strlcpy.c deleted file mode 100755 index 9b82fdd..0000000 --- a/2024/14/libft/ft_strlcpy.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/14 01:08:34 by tomoron #+# #+# */ -/* Updated: 2023/10/31 18:26:25 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcpy(char *dest, const char *src, size_t size) -{ - unsigned int i; - - i = 0; - if (size == 0) - return (ft_strlen(src)); - while (src[i] && i < size) - { - dest[i] = src[i]; - i++; - } - if (i == size) - dest[i - 1] = 0; - else - dest[i] = 0; - return (ft_strlen(src)); -} diff --git a/2024/14/libft/ft_strlcpy.o b/2024/14/libft/ft_strlcpy.o deleted file mode 100644 index 98f2f9d..0000000 Binary files a/2024/14/libft/ft_strlcpy.o and /dev/null differ diff --git a/2024/14/libft/ft_strlen.c b/2024/14/libft/ft_strlen.c deleted file mode 100755 index 0e7d7dc..0000000 --- a/2024/14/libft/ft_strlen.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlen.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 12:34:41 by tomoron #+# #+# */ -/* Updated: 2023/10/31 14:53:10 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -size_t ft_strlen(const char *str) -{ - unsigned int n; - - n = 0; - while (str[n]) - n++; - return (n); -} diff --git a/2024/14/libft/ft_strlen.o b/2024/14/libft/ft_strlen.o deleted file mode 100644 index e6e69fc..0000000 Binary files a/2024/14/libft/ft_strlen.o and /dev/null differ diff --git a/2024/14/libft/ft_strmapi.c b/2024/14/libft/ft_strmapi.c deleted file mode 100755 index ac725ae..0000000 --- a/2024/14/libft/ft_strmapi.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strmapi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/01 03:54:38 by tomoron #+# #+# */ -/* Updated: 2023/11/01 14:06:34 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) -{ - int i; - char *res; - - i = 0; - if (!s) - return (0); - res = malloc((ft_strlen(s) + 1) * sizeof(char)); - if (!res) - return (res); - while (s[i]) - { - res[i] = f(i, s[i]); - i++; - } - res[i] = 0; - return (res); -} diff --git a/2024/14/libft/ft_strmapi.o b/2024/14/libft/ft_strmapi.o deleted file mode 100644 index 551e884..0000000 Binary files a/2024/14/libft/ft_strmapi.o and /dev/null differ diff --git a/2024/14/libft/ft_strnstr.c b/2024/14/libft/ft_strnstr.c deleted file mode 100755 index 02c8a18..0000000 --- a/2024/14/libft/ft_strnstr.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/16 02:50:08 by tomoron #+# #+# */ -/* Updated: 2023/11/01 13:21:17 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strnstr(const char *str, const char *to_find, size_t len) -{ - unsigned int s_i; - unsigned int tf_i; - unsigned int tf_l; - char *res; - - s_i = 0; - tf_l = 0; - res = (char *)str; - while (to_find && to_find[tf_l]) - tf_l++; - if (tf_l == 0) - return (res); - while (str && str[s_i] && s_i <= len) - { - tf_i = 0; - while (str[s_i + tf_i] == to_find[tf_i] - && to_find[tf_i] && s_i + tf_i <= len) - tf_i++; - if (tf_i == tf_l && s_i + tf_i <= len) - return (res + s_i); - s_i++; - } - return (0); -} diff --git a/2024/14/libft/ft_strnstr.o b/2024/14/libft/ft_strnstr.o deleted file mode 100644 index b0ee341..0000000 Binary files a/2024/14/libft/ft_strnstr.o and /dev/null differ diff --git a/2024/14/libft/ft_strrchr.c b/2024/14/libft/ft_strrchr.c deleted file mode 100755 index 56fae39..0000000 --- a/2024/14/libft/ft_strrchr.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strrchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 13:35:44 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:25:44 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_strrchr(const char *s, int c) -{ - int i; - char *p; - - p = (char *)s; - i = 0; - while (s[i]) - i++; - while (i >= 0) - { - if (p[i] == (unsigned char)c) - return (p + i); - i--; - } - return (NULL); -} diff --git a/2024/14/libft/ft_strrchr.o b/2024/14/libft/ft_strrchr.o deleted file mode 100644 index 9a3809a..0000000 Binary files a/2024/14/libft/ft_strrchr.o and /dev/null differ diff --git a/2024/14/libft/ft_strtrim.c b/2024/14/libft/ft_strtrim.c deleted file mode 100755 index 1f6bb08..0000000 --- a/2024/14/libft/ft_strtrim.c +++ /dev/null @@ -1,78 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtrim.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/31 12:07:01 by tomoron #+# #+# */ -/* Updated: 2023/11/02 10:24:37 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -static int is_char_in_set(char c, char const *set) -{ - int i; - - i = 0; - while (set[i]) - { - if (set[i] == c) - return (1); - i++; - } - return (0); -} - -static int calc_len(char const *s1, char const *set) -{ - int len; - int i; - - len = 0; - i = 0; - while (is_char_in_set(s1[i], set)) - i++; - while (s1[i]) - { - i++; - len++; - } - i--; - while (is_char_in_set(s1[i], set) && i) - { - i--; - len--; - } - if (len < 0) - len = 0; - return (len); -} - -char *ft_strtrim(char const *s1, char const *set) -{ - char *res; - int len; - int i; - int res_i; - - if (!s1 || !set) - return (0); - len = calc_len(s1, set); - res = malloc((len + 1) * sizeof(char)); - i = 0; - if (!res) - return (res); - while (is_char_in_set(s1[i], set)) - i++; - res_i = 0; - while (res_i < len) - { - res[res_i] = s1[i]; - res_i++; - i++; - } - res[res_i] = 0; - return (res); -} diff --git a/2024/14/libft/ft_strtrim.o b/2024/14/libft/ft_strtrim.o deleted file mode 100644 index d789523..0000000 Binary files a/2024/14/libft/ft_strtrim.o and /dev/null differ diff --git a/2024/14/libft/ft_substr.c b/2024/14/libft/ft_substr.c deleted file mode 100755 index aae0351..0000000 --- a/2024/14/libft/ft_substr.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_substr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/31 11:59:20 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:00:04 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "libft.h" - -char *ft_substr(char const *s, unsigned int start, size_t len) -{ - unsigned int i; - char *res; - unsigned int res_len; - - res_len = 0; - if (!s) - return (0); - if (ft_strlen(s) > start) - while (res_len < len && s[start + res_len]) - res_len++; - res = malloc((res_len + 1) * sizeof(char)); - if (!res) - return (res); - i = 0; - while (i < res_len) - { - res[i] = s[start + i]; - i++; - } - res[i] = 0; - return (res); -} diff --git a/2024/14/libft/ft_substr.o b/2024/14/libft/ft_substr.o deleted file mode 100644 index 8619b90..0000000 Binary files a/2024/14/libft/ft_substr.o and /dev/null differ diff --git a/2024/14/libft/ft_swap.c b/2024/14/libft/ft_swap.c deleted file mode 100755 index 851ca4e..0000000 --- a/2024/14/libft/ft_swap.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_swap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/12/31 12:44:19 by tomoron #+# #+# */ -/* Updated: 2023/12/31 12:45:27 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -void ft_swap(int *n1, int *n2) -{ - int tmp; - - tmp = *n1; - *n1 = *n2; - *n2 = tmp; -} diff --git a/2024/14/libft/ft_tolower.c b/2024/14/libft/ft_tolower.c deleted file mode 100755 index 44cdea6..0000000 --- a/2024/14/libft/ft_tolower.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_tolower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/13 21:59:21 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:00:47 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_tolower(int c) -{ - if (c >= 'A' && c <= 'Z') - c += 32; - return (c); -} diff --git a/2024/14/libft/ft_tolower.o b/2024/14/libft/ft_tolower.o deleted file mode 100644 index 44161bd..0000000 Binary files a/2024/14/libft/ft_tolower.o and /dev/null differ diff --git a/2024/14/libft/ft_toupper.c b/2024/14/libft/ft_toupper.c deleted file mode 100755 index e6e06b3..0000000 --- a/2024/14/libft/ft_toupper.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_toupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/07/13 21:59:21 by tomoron #+# #+# */ -/* Updated: 2023/11/02 11:00:56 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -int ft_toupper(int c) -{ - if (c >= 'a' && c <= 'z') - c -= 32; - return (c); -} diff --git a/2024/14/libft/ft_toupper.o b/2024/14/libft/ft_toupper.o deleted file mode 100644 index 815af88..0000000 Binary files a/2024/14/libft/ft_toupper.o and /dev/null differ diff --git a/2024/14/libft/gnl/Makefile b/2024/14/libft/gnl/Makefile deleted file mode 100755 index 4fe8f9d..0000000 --- a/2024/14/libft/gnl/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -# **************************************************************************** # -# # -# ::: :::::::: # -# Makefile :+: :+: :+: # -# +:+ +:+ +:+ # -# By: tomoron +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2023/11/04 08:03:00 by tomoron #+# #+# # -# Updated: 2024/10/28 23:09:14 by tomoron ### ########.fr # -# # -# **************************************************************************** # - -NAME = gnl.a - -CC = cc - -SRCS = get_next_line_bonus.c\ - get_next_line_utils_bonus.c - -OBJS = $(SRCS:.c=.o) - -FLAGS = -Wall -Wextra -Werror - -$(NAME): $(OBJS) - ar rcs $(NAME) $(OBJS) - -.c.o: - $(CC) $(FLAGS) -c $< -o $@ - -all: $(NAME) - -bonus: all - -clean: - rm -f $(OBJS) - -fclean: clean - rm -f $(NAME) - -re: fclean all - -.PHONY: bonus clean all re fclean diff --git a/2024/14/libft/gnl/get_next_line_bonus.c b/2024/14/libft/gnl/get_next_line_bonus.c deleted file mode 100755 index 658e574..0000000 --- a/2024/14/libft/gnl/get_next_line_bonus.c +++ /dev/null @@ -1,113 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/05 17:03:11 by tomoron #+# #+# */ -/* Updated: 2023/12/04 09:56:26 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "get_next_line_bonus.h" - -char *get_next_line(int fd) -{ - static t_buffer *buffer_start; - t_buffer *buffer; - int nl_found; - int start; - t_result *result; - - nl_found = 0; - result = 0; - start = 0; - buffer = create_find_buffer(&buffer_start, fd); - if (BUFFER_SIZE < 0 || !buffer) - return (0); - if (fd >= 0 && (buffer->i == 0 || buffer->i == buffer->rd_l)) - buffer->rd_l = read(fd, buffer->str, BUFFER_SIZE); - else - start = buffer->i; - while (fd >= 0 && !nl_found && buffer->rd_l > 0) - { - nl_found = find_nl(buffer, &start); - if (!ft_lstadd_bak(&result, buffer->str, buffer->i, start)) - return (ft_lstclr(&result, NULL, NULL)); - if (!nl_found) - buffer->rd_l = read(fd, buffer->str, BUFFER_SIZE); - } - return (result_to_str(result, &buffer_start, buffer)); -} - -int find_nl(t_buffer *buffer, int *start) -{ - int nl_found; - - nl_found = 0; - if (buffer->i == BUFFER_SIZE) - *start = 0; - buffer->i = *start; - while (buffer->i < buffer->rd_l && !nl_found) - { - if (buffer->str[buffer->i] == '\n') - nl_found = 1; - (buffer->i)++; - } - return (nl_found); -} - -t_buffer *create_find_buffer(t_buffer **buffer_start, int fd) -{ - t_buffer *current; - t_buffer *last; - - current = *buffer_start; - last = 0; - while (current) - { - if (current->fd == fd) - return (current); - last = current; - current = current->next; - } - if (last) - { - last->next = malloc(sizeof(t_buffer)); - last = last->next; - } - else - { - last = malloc(sizeof(t_buffer)); - *buffer_start = last; - } - if (last) - init_buffer(last, fd); - return (last); -} - -void init_buffer(t_buffer *last, int fd) -{ - last->fd = fd; - last->i = 0; - last->rd_l = 0; - last->next = 0; -} - -void ft_lstdelon(t_buffer *node, t_buffer **start) -{ - t_buffer *current; - t_buffer *next; - - if (!start || !node || !*start) - return ; - current = *start; - while (current->next && current->next != node) - current = current->next; - next = node->next; - free(node); - if (node == *start) - *start = next; - else - current->next = next; -} diff --git a/2024/14/libft/gnl/get_next_line_bonus.h b/2024/14/libft/gnl/get_next_line_bonus.h deleted file mode 100755 index 28facee..0000000 --- a/2024/14/libft/gnl/get_next_line_bonus.h +++ /dev/null @@ -1,46 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_bonus.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/05 17:24:39 by tomoron #+# #+# */ -/* Updated: 2023/12/04 09:57:06 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef GET_NEXT_LINE_BONUS_H -# define GET_NEXT_LINE_BONUS_H -# include -# include - -# ifndef BUFFER_SIZE -# define BUFFER_SIZE 42 -# endif - -typedef struct s_result -{ - char part[BUFFER_SIZE + 1]; - struct s_result *next; - -} t_result; - -typedef struct s_buffer -{ - char str[BUFFER_SIZE]; - int i; - int rd_l; - int fd; - struct s_buffer *next; -} t_buffer; - -char *get_next_line(int fd); -char *result_to_str(t_result *lst, t_buffer **buf_st, t_buffer *buffer); -t_result *ft_lstadd_bak(t_result **lst, char *buffer, int n, int start); -char *ft_lstclr(t_result **lst, t_buffer **buf_str, t_buffer *buffer); -int find_nl(t_buffer *buffer, int *start); -t_buffer *create_find_buffer(t_buffer **buffer_start, int fd); -void init_buffer(t_buffer *last, int fd); -void ft_lstdelon(t_buffer *node, t_buffer **start); -#endif diff --git a/2024/14/libft/gnl/get_next_line_bonus.o b/2024/14/libft/gnl/get_next_line_bonus.o deleted file mode 100644 index ed6b7b7..0000000 Binary files a/2024/14/libft/gnl/get_next_line_bonus.o and /dev/null differ diff --git a/2024/14/libft/gnl/get_next_line_utils_bonus.c b/2024/14/libft/gnl/get_next_line_utils_bonus.c deleted file mode 100755 index 1233d60..0000000 --- a/2024/14/libft/gnl/get_next_line_utils_bonus.c +++ /dev/null @@ -1,119 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line_utils_bonus.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/11/05 17:35:15 by tomoron #+# #+# */ -/* Updated: 2023/12/04 09:58:25 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ -#include "get_next_line_bonus.h" - -char *ft_strncpy(char *dest, char *src, size_t n) -{ - size_t i; - - i = 0; - while (i < (n)) - { - dest[i] = src[i]; - i++; - } - dest[i] = 0; - return (dest); -} - -t_result *ft_lstadd_bak(t_result **lst, char *buffer, int n, int start) -{ - t_result *current; - - if (!lst) - return (0); - current = *lst; - while (current && current->next) - current = current->next; - if (!current) - { - *lst = malloc(sizeof(t_result)); - if (!*lst) - return (0); - ft_strncpy((*lst)->part, buffer + start, n - start); - (*lst)->next = 0; - } - else - { - current->next = malloc(sizeof(t_result)); - if (!current->next) - return (0); - ft_strncpy(current->next->part, buffer + start, n - start); - current->next->next = 0; - } - return (*lst); -} - -char *ft_lstclr(t_result **lst, t_buffer **buf_srt, t_buffer *buffer) -{ - t_result *next; - - if (lst) - { - while (*lst) - { - next = (*lst)->next; - free(*lst); - *lst = next; - } - } - if (buf_srt && buffer && (buffer->rd_l == 0 || buffer->i == buffer->rd_l - || buffer->rd_l == -1)) - ft_lstdelon(buffer, buf_srt); - return (0); -} - -int lst_str_len(t_result *lst) -{ - int i; - int res; - - res = 0; - while (lst) - { - i = 0; - while (lst->part[i]) - i++; - res += i; - lst = lst->next; - } - return (res); -} - -char *result_to_str(t_result *lst, t_buffer **buf_srt, t_buffer *buffer) -{ - char *res; - int res_i; - int p_i; - t_result *start; - - if (!lst) - return (ft_lstclr(&lst, buf_srt, buffer)); - res = malloc((lst_str_len(lst) + 1) * sizeof(char)); - start = lst; - res_i = 0; - while (res && lst) - { - p_i = 0; - while (lst->part[p_i]) - { - res[res_i] = lst->part[p_i]; - p_i++; - res_i++; - } - lst = lst->next; - } - if (res) - res[res_i] = 0; - ft_lstclr(&start, buf_srt, buffer); - return (res); -} diff --git a/2024/14/libft/gnl/get_next_line_utils_bonus.o b/2024/14/libft/gnl/get_next_line_utils_bonus.o deleted file mode 100644 index 6235341..0000000 Binary files a/2024/14/libft/gnl/get_next_line_utils_bonus.o and /dev/null differ diff --git a/2024/14/libft/gnl/gnl.a b/2024/14/libft/gnl/gnl.a deleted file mode 100644 index a3407b4..0000000 Binary files a/2024/14/libft/gnl/gnl.a and /dev/null differ diff --git a/2024/14/libft/libft.a b/2024/14/libft/libft.a deleted file mode 100644 index 4d93ea9..0000000 Binary files a/2024/14/libft/libft.a and /dev/null differ diff --git a/2024/14/libft/libft.h b/2024/14/libft/libft.h deleted file mode 100755 index 87fa052..0000000 --- a/2024/14/libft/libft.h +++ /dev/null @@ -1,77 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tomoron +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/10/30 16:55:48 by tomoron #+# #+# */ -/* Updated: 2024/01/10 14:10:51 by tomoron ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIBFT_H -# define LIBFT_H -# include -# include -# include -# include "./ft_printf/ft_printf.h" -# include "./gnl/get_next_line_bonus.h" - -typedef struct s_list -{ - void *content; - struct s_list *next; -} t_list; - -int ft_atoi(const char *str); -void ft_bzero(void *s, size_t n); -int ft_isalnum(int c); -int ft_isalpha(int c); -int ft_isascii(int c); -int ft_isdigit(int c); -int ft_isprint(int c); -void *ft_memchr(const void *s, int c, size_t n); -int ft_memcmp(const void *s1, const void *s2, size_t n); -void *ft_memcpy(void *dest, const void *src, size_t n); -void *ft_memmove(void *dest, const void *src, size_t n); -void *ft_memset(void *s, int c, size_t n); -char *ft_strchr(const char *s, int c); -size_t ft_strlcat(char *dest, const char *src, size_t size); -size_t ft_strlcpy(char *dest, const char *src, size_t size); -size_t ft_strlen(const char *str); -int ft_strncmp(const char *s1, const char *s2, size_t n); -char *ft_strnstr(const char *str, const char *to_find, size_t len); -char *ft_strrchr(const char *s, int c); -int ft_tolower(int c); -int ft_toupper(int c); -void *ft_calloc(size_t nb, size_t size); -char *ft_strdup(const char *src); -char *ft_strjoin(char const *s1, char const *s2); -char *ft_strtrim(char const *s1, char const *set); -char *ft_substr(char const *s, unsigned int start, size_t len); -char **ft_split(char const *str, char charset); -char *ft_itoa(int n); -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); -void ft_striteri(char *s, void (*f)(unsigned int, char*)); -void ft_putchar_fd(char c, int fd); -void ft_putstr_fd(char *s, int fd); -void ft_putendl_fd(char *s, int fd); -void ft_putnbr_fd(int n, int fd); -t_list *ft_lstnew(void *content); -void ft_lstadd_front(t_list **lst, t_list *new); -int ft_lstsize(t_list *lst); -t_list *ft_lstlast(t_list *lst); -void ft_lstadd_back(t_list **lst, 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 *)); -char **ft_split_set(char *str, char *charset); -int ft_strcmp(char *s1, char *s2); -void ft_free_str_arr(char **arr); -void ft_swap(int *n1, int *n2); -void ft_set_color(int r, int g, int b); -void ft_reset_color(void); - -#endif diff --git a/2024/14/main.o b/2024/14/main.o deleted file mode 100644 index 0c4d6a0..0000000 Binary files a/2024/14/main.o and /dev/null differ diff --git a/2024/14/mlx b/2024/14/mlx deleted file mode 160000 index 7dc53a4..0000000 --- a/2024/14/mlx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7dc53a411a7d4ae286c60c6229bd1e395b0efb82 diff --git a/2024/14/part1.o b/2024/14/part1.o deleted file mode 100644 index 812689a..0000000 Binary files a/2024/14/part1.o and /dev/null differ diff --git a/2024/14/part2.c b/2024/14/part2.c index 3fa0ea1..d620ffe 100644 --- a/2024/14/part2.c +++ b/2024/14/part2.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ -/* Updated: 2024/12/14 15:16:48 by tomoron ### ########.fr */ +/* Updated: 2024/12/14 16:20:20 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,10 @@ #include #include #include -#include "mlx/mlx.h" #include "libft/libft.h" #define MAX_UP 103 #define MAX_LEN 101 -#define ROBOT_SIZE 8 typedef struct s_robot { @@ -71,8 +69,8 @@ static void update_pos(t_robot *robot) { while(robot) { - robot->pos_x = (robot->pos_x + (robot->vel_x * 100)); - robot->pos_y = (robot->pos_y + (robot->vel_y * 100)); + robot->pos_x = (robot->pos_x + (robot->vel_x)); + robot->pos_y = (robot->pos_y + (robot->vel_y)); robot->pos_x %= MAX_LEN; robot->pos_y %= MAX_UP; if(robot->pos_x < 0) @@ -83,29 +81,7 @@ static void update_pos(t_robot *robot) } } -static long int get_result(t_robot *robot) -{ - long int tiles[4]; - - bzero(tiles, 4 * sizeof(long int)); - while(robot) - { - robot->pos_x -= (MAX_LEN / 2); - robot->pos_y -= (MAX_UP / 2); - if(robot->pos_x < 0 && robot->pos_y < 0) - tiles[0]++; - else if(robot->pos_x > 0 && robot->pos_y < 0) - tiles[1]++; - else if(robot->pos_x < 0 && robot->pos_y > 0) - tiles[2]++; - else if(robot->pos_x > 0 && robot->pos_y > 0) - tiles[3]++; - robot = robot->next; - } - return(tiles[0] * tiles[1] * tiles[2] * tiles[3]); -} - -static char **create_map(void) +static char **create_map(char fill) { char **res; int i; @@ -116,52 +92,66 @@ static char **create_map(void) while(i < MAX_UP + 1) { res[i] = malloc(MAX_LEN + 2); + memset(res[i], fill, MAX_LEN + 1); + res[i][MAX_LEN + 1] = 0; i++; } return(res); } -void set_pos(unsigned int *img, unsigned long pos, unsigned int color) +void fill_map(char **map, t_robot *robot) { int i; - int j; i = 0; - while(i < ROBOT_SIZE) + while(map[i]) { - j = 0; - while(j < ROBOT_SIZE) - { - img[pos + (i * MAX_LEN * ROBOT_SIZE) + j] = color; - j++; - } + memset(map[i], '.', MAX_LEN + 1); + map[i][MAX_LEN + 1] = 0; i++; } -} - -void fill_map(void *img, t_robot *robot) -{ - unsigned long pos; - int a; - - img = mlx_get_data_addr(img,&a, &a, &a); - bzero(img, (MAX_LEN * ROBOT_SIZE) * (MAX_UP * ROBOT_SIZE) * sizeof(unsigned int)); while(robot) { - pos = robot->pos_x * ROBOT_SIZE + (robot->pos_y * (MAX_LEN * ROBOT_SIZE) * ROBOT_SIZE); - set_pos(img, pos, 0xFFFFFF); + map[robot->pos_y][robot->pos_x] = '#'; robot = robot->next; } } -static int loop_fnc(t_data *data) +static int count_area(char **map, int pos[2], char **locations) { - fill_map(data->img, data->robot); - mlx_put_image_to_window(data->mlx, data->win, data->img, 0 ,0); - printf("res : %d\n", data->res); - update_pos(data->robot); - data->res++; - usleep(20000); + int res; + + res = 0; + if(pos[0] < 0 || pos[1] < 0 || !map[pos[0]] || !map[pos[0]][pos[1]] || locations[pos[0]][pos[1]] != '.' || map[pos[0]][pos[1]] != '#') + return(0); + locations[pos[0]][pos[1]] = '#'; + res += count_area(map, (int [2]){pos[0] + 1, pos[1]}, locations); + res += count_area(map, (int [2]){pos[0] - 1, pos[1]}, locations); + res += count_area(map, (int [2]){pos[0], pos[1] + 1}, locations); + res += count_area(map, (int [2]){pos[0], pos[1] - 1}, locations); + return(res + (map[pos[0]][pos[1]] == '#')); +} + +static int is_easter_egg(char **map) +{ + int i; + int j; + char **locations; + + locations = create_map('.'); + i = 0; + while(map[i]) + { + j = 0; + while(map[i][j]) + { + if(count_area(map, (int [2]){i, j}, locations) > 50) + return(1); + j++; + } + i++; + } + ft_free_str_arr(locations); return(0); } @@ -170,7 +160,7 @@ long int resolve_part2(char *input, char **split) (void)input; t_robot *robot; long int res; - t_data data; + char **map; robot = 0; res = 0; @@ -179,18 +169,13 @@ long int resolve_part2(char *input, char **split) add_robot(&robot, *split); split++; } - data.mlx = mlx_init(); - data.win = mlx_new_window(data.mlx, MAX_LEN * ROBOT_SIZE, MAX_UP * ROBOT_SIZE, "language : eyes"); - data.img = mlx_new_image(data.mlx, MAX_LEN * ROBOT_SIZE, MAX_UP * ROBOT_SIZE); - data.robot = robot; - data.res = 0; - mlx_loop_hook(data.mlx, loop_fnc, &data); - mlx_loop(data.mlx); - while(1) - ;; -// fill_show_map(map, robot); - (void)get_result; - (void)create_map; - (void)update_pos; + map = create_map('.'); + fill_map(map,robot); + while(!is_easter_egg(map)) + { + update_pos(robot); + res++; + fill_map(map,robot); + } return(res); } diff --git a/2024/14/part2.o b/2024/14/part2.o deleted file mode 100644 index f0e6ced..0000000 Binary files a/2024/14/part2.o and /dev/null differ diff --git a/2024/14/test b/2024/14/test index 2455da4..9150157 100644 --- a/2024/14/test +++ b/2024/14/test @@ -1,12 +1,11 @@ -p=0,4 v=3,-3 -p=6,3 v=-1,-3 -p=10,3 v=-1,2 -p=2,0 v=2,-1 -p=0,0 v=1,3 -p=3,0 v=-2,-2 -p=7,6 v=-1,-3 -p=3,0 v=-1,-2 -p=9,3 v=2,3 -p=7,3 v=-1,2 -p=2,4 v=2,-3 -p=9,5 v=-3,-3 +##........................................ +##........................................ +.......................................... +.......................................... +.......................................... +.......................................... +.......................................... +.......................................... +.......................................... +.......................................... +..........................................