From 60acac0231e852a079af823ae6660d55da518bc1 Mon Sep 17 00:00:00 2001 From: tomoron Date: Mon, 2 Dec 2024 12:32:14 +0100 Subject: [PATCH] remove inputs --- .gitignore | 2 + 2022/2/Makefile | 69 ++++++ 2022/2/libft/Makefile | 101 +++++++++ 2022/2/libft/ft_atoi.c | 35 +++ 2022/2/libft/ft_atoi.o | Bin 0 -> 1384 bytes 2022/2/libft/ft_bzero.c | 26 +++ 2022/2/libft/ft_bzero.o | Bin 0 -> 1280 bytes 2022/2/libft/ft_calloc.c | 31 +++ 2022/2/libft/ft_calloc.o | Bin 0 -> 1512 bytes 2022/2/libft/ft_free_str_arr.c | 27 +++ 2022/2/libft/ft_free_str_arr.o | Bin 0 -> 1480 bytes 2022/2/libft/ft_isalnum.c | 19 ++ 2022/2/libft/ft_isalnum.o | Bin 0 -> 1280 bytes 2022/2/libft/ft_isalpha.c | 18 ++ 2022/2/libft/ft_isalpha.o | Bin 0 -> 1272 bytes 2022/2/libft/ft_isascii.c | 18 ++ 2022/2/libft/ft_isascii.o | Bin 0 -> 1256 bytes 2022/2/libft/ft_isdigit.c | 18 ++ 2022/2/libft/ft_isdigit.o | Bin 0 -> 1256 bytes 2022/2/libft/ft_isprint.c | 18 ++ 2022/2/libft/ft_isprint.o | Bin 0 -> 1256 bytes 2022/2/libft/ft_itoa.c | 60 +++++ 2022/2/libft/ft_itoa.o | Bin 0 -> 1824 bytes 2022/2/libft/ft_lstadd_back.c | 27 +++ 2022/2/libft/ft_lstadd_front.c | 19 ++ 2022/2/libft/ft_lstclear.c | 27 +++ 2022/2/libft/ft_lstdelone.c | 20 ++ 2022/2/libft/ft_lstiter.c | 21 ++ 2022/2/libft/ft_lstlast.c | 19 ++ 2022/2/libft/ft_lstmap.c | 41 ++++ 2022/2/libft/ft_lstnew.c | 25 +++ 2022/2/libft/ft_lstsize.c | 26 +++ 2022/2/libft/ft_memchr.c | 28 +++ 2022/2/libft/ft_memchr.o | Bin 0 -> 1304 bytes 2022/2/libft/ft_memcmp.c | 28 +++ 2022/2/libft/ft_memcmp.o | Bin 0 -> 1360 bytes 2022/2/libft/ft_memcpy.c | 29 +++ 2022/2/libft/ft_memcpy.o | Bin 0 -> 1312 bytes 2022/2/libft/ft_memmove.c | 32 +++ 2022/2/libft/ft_memmove.o | Bin 0 -> 1384 bytes 2022/2/libft/ft_memset.c | 27 +++ 2022/2/libft/ft_memset.o | Bin 0 -> 1280 bytes 2022/2/libft/ft_printf/Makefile | 52 +++++ 2022/2/libft/ft_printf/ft_convert.c | 85 +++++++ 2022/2/libft/ft_printf/ft_convert.o | Bin 0 -> 3944 bytes 2022/2/libft/ft_printf/ft_isdigit.c | 18 ++ 2022/2/libft/ft_printf/ft_isdigit.o | Bin 0 -> 1256 bytes 2022/2/libft/ft_printf/ft_parse_arg.c | 89 ++++++++ 2022/2/libft/ft_printf/ft_parse_arg.o | Bin 0 -> 3408 bytes 2022/2/libft/ft_printf/ft_print_hex_ptr.c | 97 ++++++++ 2022/2/libft/ft_printf/ft_print_hex_ptr.o | Bin 0 -> 3504 bytes 2022/2/libft/ft_printf/ft_print_int.c | 99 ++++++++ 2022/2/libft/ft_printf/ft_print_int.o | Bin 0 -> 3312 bytes .../2/libft/ft_printf/ft_print_unsigned_int.c | 55 +++++ .../2/libft/ft_printf/ft_print_unsigned_int.o | Bin 0 -> 2048 bytes 2022/2/libft/ft_printf/ft_printf.c | 67 ++++++ 2022/2/libft/ft_printf/ft_printf.h | 46 ++++ 2022/2/libft/ft_printf/ft_printf.o | Bin 0 -> 2400 bytes 2022/2/libft/ft_printf/ft_protected_atoi.c | 37 +++ 2022/2/libft/ft_printf/ft_protected_atoi.o | Bin 0 -> 1432 bytes 2022/2/libft/ft_printf/ft_putchar.c | 18 ++ 2022/2/libft/ft_printf/ft_putchar.o | Bin 0 -> 1384 bytes 2022/2/libft/ft_printf/ft_putstr.c | 19 ++ 2022/2/libft/ft_printf/ft_putstr.o | Bin 0 -> 1488 bytes 2022/2/libft/ft_printf/ft_strlen.c | 22 ++ 2022/2/libft/ft_printf/ft_strlen.o | Bin 0 -> 1256 bytes 2022/2/libft/ft_printf/ft_write_str_part.c | 26 +++ 2022/2/libft/ft_printf/ft_write_str_part.o | Bin 0 -> 1488 bytes 2022/2/libft/ft_printf/libftprintf.a | Bin 0 -> 28418 bytes 2022/2/libft/ft_putchar_fd.c | 17 ++ 2022/2/libft/ft_putchar_fd.o | Bin 0 -> 1392 bytes 2022/2/libft/ft_putendl_fd.c | 21 ++ 2022/2/libft/ft_putendl_fd.o | Bin 0 -> 1632 bytes 2022/2/libft/ft_putnbr_fd.c | 33 +++ 2022/2/libft/ft_putnbr_fd.o | Bin 0 -> 1912 bytes 2022/2/libft/ft_putstr_fd.c | 18 ++ 2022/2/libft/ft_putstr_fd.o | Bin 0 -> 1464 bytes 2022/2/libft/ft_set_color.c | 23 ++ 2022/2/libft/ft_set_color.o | Bin 0 -> 1712 bytes 2022/2/libft/ft_split.c | 73 ++++++ 2022/2/libft/ft_split.o | Bin 0 -> 2200 bytes 2022/2/libft/ft_split_set.c | 84 +++++++ 2022/2/libft/ft_split_set.o | Bin 0 -> 2648 bytes 2022/2/libft/ft_strchr.c | 30 +++ 2022/2/libft/ft_strchr.o | Bin 0 -> 1360 bytes 2022/2/libft/ft_strcmp.c | 34 +++ 2022/2/libft/ft_strcmp.o | Bin 0 -> 1576 bytes 2022/2/libft/ft_strdup.c | 36 +++ 2022/2/libft/ft_strdup.o | Bin 0 -> 1520 bytes 2022/2/libft/ft_striteri.c | 23 ++ 2022/2/libft/ft_striteri.o | Bin 0 -> 1312 bytes 2022/2/libft/ft_strjoin.c | 63 ++++++ 2022/2/libft/ft_strjoin.o | Bin 0 -> 1792 bytes 2022/2/libft/ft_strlcat.c | 38 ++++ 2022/2/libft/ft_strlcat.o | Bin 0 -> 1648 bytes 2022/2/libft/ft_strlcpy.c | 32 +++ 2022/2/libft/ft_strlcpy.o | Bin 0 -> 1536 bytes 2022/2/libft/ft_strlen.c | 22 ++ 2022/2/libft/ft_strlen.o | Bin 0 -> 1256 bytes 2022/2/libft/ft_strmapi.c | 33 +++ 2022/2/libft/ft_strmapi.o | Bin 0 -> 1592 bytes 2022/2/libft/ft_strnstr.c | 39 ++++ 2022/2/libft/ft_strnstr.o | Bin 0 -> 1480 bytes 2022/2/libft/ft_strrchr.c | 30 +++ 2022/2/libft/ft_strrchr.o | Bin 0 -> 1336 bytes 2022/2/libft/ft_strtrim.c | 78 +++++++ 2022/2/libft/ft_strtrim.o | Bin 0 -> 2008 bytes 2022/2/libft/ft_substr.c | 37 +++ 2022/2/libft/ft_substr.o | Bin 0 -> 1608 bytes 2022/2/libft/ft_swap.c | 20 ++ 2022/2/libft/ft_tolower.c | 18 ++ 2022/2/libft/ft_tolower.o | Bin 0 -> 1248 bytes 2022/2/libft/ft_toupper.c | 18 ++ 2022/2/libft/ft_toupper.o | Bin 0 -> 1248 bytes 2022/2/libft/gnl/Makefile | 42 ++++ 2022/2/libft/gnl/get_next_line_bonus.c | 113 ++++++++++ 2022/2/libft/gnl/get_next_line_bonus.h | 46 ++++ 2022/2/libft/gnl/get_next_line_bonus.o | Bin 0 -> 3208 bytes 2022/2/libft/gnl/get_next_line_utils_bonus.c | 119 ++++++++++ 2022/2/libft/gnl/get_next_line_utils_bonus.o | Bin 0 -> 2992 bytes 2022/2/libft/gnl/gnl.a | Bin 0 -> 34956 bytes 2022/2/libft/libft.a | Bin 0 -> 91092 bytes 2022/2/libft/libft.h | 77 +++++++ 2022/2/main.c | 51 +++++ 2022/2/part1.c | 68 ++++++ 2022/2/part2.c | 81 +++++++ 2022/3/Makefile | 69 ++++++ 2022/3/main.c | 66 ++++++ 2022/3/part1.c | 58 +++++ 2022/3/part2.c | 54 +++++ 2022/3/test | 6 + 2022/4/Makefile | 69 ++++++ 2022/4/main.c | 66 ++++++ 2022/4/part1.c | 55 +++++ 2022/4/part2.c | 61 +++++ 2022/4/test | 6 + 2022/5/Makefile | 69 ++++++ 2022/5/main.c | 67 ++++++ 2022/5/part1.c | 210 +++++++++++++++++ 2022/5/part2.c | 211 ++++++++++++++++++ 2022/5/structs.h | 23 ++ 2022/5/test | 9 + 2022/6/Makefile | 69 ++++++ 2022/6/main.c | 67 ++++++ 2022/6/part1.c | 53 +++++ 2022/6/part2.c | 53 +++++ 2022/6/test | 1 + 2022/7/Makefile | 69 ++++++ 2022/7/main.c | 67 ++++++ 2022/7/part1.c | 198 ++++++++++++++++ 2022/7/part2.c | 198 ++++++++++++++++ 2022/7/structs.h | 33 +++ 2022/7/test | 23 ++ 2022/8/Makefile | 69 ++++++ 2022/8/main.c | 67 ++++++ 2022/8/part1.c | 58 +++++ 2022/8/part2.c | 68 ++++++ 2022/8/test | 5 + 2022/9/Makefile | 69 ++++++ 2022/9/main.c | 67 ++++++ 2022/9/part1.c | 83 +++++++ 2022/9/part2.c | 22 ++ 2022/9/structs.h | 23 ++ 2022/9/test | 8 + 2022/Makefile | 69 ++++++ 2024/1/Makefile | 69 ++++++ 2024/1/main.c | 67 ++++++ 2024/1/part1.c | 98 ++++++++ 2024/1/part2.c | 86 +++++++ 2024/1/test | 6 + 2024/2/Makefile | 69 ++++++ 2024/2/main.c | 67 ++++++ 2024/2/part1.c | 65 ++++++ 2024/2/part2.c | 105 +++++++++ 2024/2/test | 7 + 2024/Makefile | 69 ++++++ Makefile | 69 ++++++ libft/Makefile | 101 +++++++++ libft/ft_atoi.c | 35 +++ libft/ft_bzero.c | 26 +++ libft/ft_calloc.c | 31 +++ libft/ft_free_str_arr.c | 27 +++ libft/ft_isalnum.c | 19 ++ libft/ft_isalpha.c | 18 ++ libft/ft_isascii.c | 18 ++ libft/ft_isdigit.c | 18 ++ libft/ft_isprint.c | 18 ++ libft/ft_itoa.c | 60 +++++ libft/ft_lstadd_back.c | 27 +++ libft/ft_lstadd_front.c | 19 ++ libft/ft_lstclear.c | 27 +++ libft/ft_lstdelone.c | 20 ++ libft/ft_lstiter.c | 21 ++ libft/ft_lstlast.c | 19 ++ libft/ft_lstmap.c | 41 ++++ libft/ft_lstnew.c | 25 +++ libft/ft_lstsize.c | 26 +++ libft/ft_memchr.c | 28 +++ libft/ft_memcmp.c | 28 +++ libft/ft_memcpy.c | 29 +++ libft/ft_memmove.c | 32 +++ libft/ft_memset.c | 27 +++ libft/ft_printf/Makefile | 52 +++++ libft/ft_printf/ft_convert.c | 85 +++++++ libft/ft_printf/ft_isdigit.c | 18 ++ libft/ft_printf/ft_parse_arg.c | 89 ++++++++ libft/ft_printf/ft_print_hex_ptr.c | 97 ++++++++ libft/ft_printf/ft_print_int.c | 99 ++++++++ libft/ft_printf/ft_print_unsigned_int.c | 55 +++++ libft/ft_printf/ft_printf.c | 67 ++++++ libft/ft_printf/ft_printf.h | 46 ++++ libft/ft_printf/ft_protected_atoi.c | 37 +++ libft/ft_printf/ft_putchar.c | 18 ++ libft/ft_printf/ft_putstr.c | 19 ++ libft/ft_printf/ft_strlen.c | 22 ++ libft/ft_printf/ft_write_str_part.c | 26 +++ libft/ft_putchar_fd.c | 17 ++ libft/ft_putendl_fd.c | 21 ++ libft/ft_putnbr_fd.c | 33 +++ libft/ft_putstr_fd.c | 18 ++ libft/ft_set_color.c | 23 ++ libft/ft_split.c | 73 ++++++ libft/ft_split_set.c | 84 +++++++ libft/ft_strchr.c | 30 +++ libft/ft_strcmp.c | 34 +++ libft/ft_strdup.c | 36 +++ libft/ft_striteri.c | 23 ++ libft/ft_strjoin.c | 63 ++++++ libft/ft_strlcat.c | 38 ++++ libft/ft_strlcpy.c | 32 +++ libft/ft_strlen.c | 22 ++ libft/ft_strmapi.c | 33 +++ libft/ft_strnstr.c | 39 ++++ libft/ft_strrchr.c | 30 +++ libft/ft_strtrim.c | 78 +++++++ libft/ft_substr.c | 37 +++ libft/ft_swap.c | 20 ++ libft/ft_tolower.c | 18 ++ libft/ft_toupper.c | 18 ++ libft/gnl/Makefile | 42 ++++ libft/gnl/get_next_line_bonus.c | 113 ++++++++++ libft/gnl/get_next_line_bonus.h | 46 ++++ libft/gnl/get_next_line_utils_bonus.c | 119 ++++++++++ libft/libft.h | 77 +++++++ main.c | 67 ++++++ part1.c | 22 ++ part2.c | 22 ++ 247 files changed, 9071 insertions(+) create mode 100644 .gitignore create mode 100644 2022/2/Makefile create mode 100755 2022/2/libft/Makefile create mode 100755 2022/2/libft/ft_atoi.c create mode 100644 2022/2/libft/ft_atoi.o create mode 100755 2022/2/libft/ft_bzero.c create mode 100644 2022/2/libft/ft_bzero.o create mode 100755 2022/2/libft/ft_calloc.c create mode 100644 2022/2/libft/ft_calloc.o create mode 100755 2022/2/libft/ft_free_str_arr.c create mode 100644 2022/2/libft/ft_free_str_arr.o create mode 100755 2022/2/libft/ft_isalnum.c create mode 100644 2022/2/libft/ft_isalnum.o create mode 100755 2022/2/libft/ft_isalpha.c create mode 100644 2022/2/libft/ft_isalpha.o create mode 100755 2022/2/libft/ft_isascii.c create mode 100644 2022/2/libft/ft_isascii.o create mode 100755 2022/2/libft/ft_isdigit.c create mode 100644 2022/2/libft/ft_isdigit.o create mode 100755 2022/2/libft/ft_isprint.c create mode 100644 2022/2/libft/ft_isprint.o create mode 100755 2022/2/libft/ft_itoa.c create mode 100644 2022/2/libft/ft_itoa.o create mode 100755 2022/2/libft/ft_lstadd_back.c create mode 100755 2022/2/libft/ft_lstadd_front.c create mode 100755 2022/2/libft/ft_lstclear.c create mode 100755 2022/2/libft/ft_lstdelone.c create mode 100755 2022/2/libft/ft_lstiter.c create mode 100755 2022/2/libft/ft_lstlast.c create mode 100755 2022/2/libft/ft_lstmap.c create mode 100755 2022/2/libft/ft_lstnew.c create mode 100755 2022/2/libft/ft_lstsize.c create mode 100755 2022/2/libft/ft_memchr.c create mode 100644 2022/2/libft/ft_memchr.o create mode 100755 2022/2/libft/ft_memcmp.c create mode 100644 2022/2/libft/ft_memcmp.o create mode 100755 2022/2/libft/ft_memcpy.c create mode 100644 2022/2/libft/ft_memcpy.o create mode 100755 2022/2/libft/ft_memmove.c create mode 100644 2022/2/libft/ft_memmove.o create mode 100755 2022/2/libft/ft_memset.c create mode 100644 2022/2/libft/ft_memset.o create mode 100755 2022/2/libft/ft_printf/Makefile create mode 100755 2022/2/libft/ft_printf/ft_convert.c create mode 100644 2022/2/libft/ft_printf/ft_convert.o create mode 100755 2022/2/libft/ft_printf/ft_isdigit.c create mode 100644 2022/2/libft/ft_printf/ft_isdigit.o create mode 100755 2022/2/libft/ft_printf/ft_parse_arg.c create mode 100644 2022/2/libft/ft_printf/ft_parse_arg.o create mode 100755 2022/2/libft/ft_printf/ft_print_hex_ptr.c create mode 100644 2022/2/libft/ft_printf/ft_print_hex_ptr.o create mode 100755 2022/2/libft/ft_printf/ft_print_int.c create mode 100644 2022/2/libft/ft_printf/ft_print_int.o create mode 100755 2022/2/libft/ft_printf/ft_print_unsigned_int.c create mode 100644 2022/2/libft/ft_printf/ft_print_unsigned_int.o create mode 100755 2022/2/libft/ft_printf/ft_printf.c create mode 100755 2022/2/libft/ft_printf/ft_printf.h create mode 100644 2022/2/libft/ft_printf/ft_printf.o create mode 100755 2022/2/libft/ft_printf/ft_protected_atoi.c create mode 100644 2022/2/libft/ft_printf/ft_protected_atoi.o create mode 100755 2022/2/libft/ft_printf/ft_putchar.c create mode 100644 2022/2/libft/ft_printf/ft_putchar.o create mode 100755 2022/2/libft/ft_printf/ft_putstr.c create mode 100644 2022/2/libft/ft_printf/ft_putstr.o create mode 100755 2022/2/libft/ft_printf/ft_strlen.c create mode 100644 2022/2/libft/ft_printf/ft_strlen.o create mode 100755 2022/2/libft/ft_printf/ft_write_str_part.c create mode 100644 2022/2/libft/ft_printf/ft_write_str_part.o create mode 100644 2022/2/libft/ft_printf/libftprintf.a create mode 100755 2022/2/libft/ft_putchar_fd.c create mode 100644 2022/2/libft/ft_putchar_fd.o create mode 100755 2022/2/libft/ft_putendl_fd.c create mode 100644 2022/2/libft/ft_putendl_fd.o create mode 100755 2022/2/libft/ft_putnbr_fd.c create mode 100644 2022/2/libft/ft_putnbr_fd.o create mode 100755 2022/2/libft/ft_putstr_fd.c create mode 100644 2022/2/libft/ft_putstr_fd.o create mode 100755 2022/2/libft/ft_set_color.c create mode 100644 2022/2/libft/ft_set_color.o create mode 100755 2022/2/libft/ft_split.c create mode 100644 2022/2/libft/ft_split.o create mode 100755 2022/2/libft/ft_split_set.c create mode 100644 2022/2/libft/ft_split_set.o create mode 100755 2022/2/libft/ft_strchr.c create mode 100644 2022/2/libft/ft_strchr.o create mode 100755 2022/2/libft/ft_strcmp.c create mode 100644 2022/2/libft/ft_strcmp.o create mode 100755 2022/2/libft/ft_strdup.c create mode 100644 2022/2/libft/ft_strdup.o create mode 100755 2022/2/libft/ft_striteri.c create mode 100644 2022/2/libft/ft_striteri.o create mode 100755 2022/2/libft/ft_strjoin.c create mode 100644 2022/2/libft/ft_strjoin.o create mode 100755 2022/2/libft/ft_strlcat.c create mode 100644 2022/2/libft/ft_strlcat.o create mode 100755 2022/2/libft/ft_strlcpy.c create mode 100644 2022/2/libft/ft_strlcpy.o create mode 100755 2022/2/libft/ft_strlen.c create mode 100644 2022/2/libft/ft_strlen.o create mode 100755 2022/2/libft/ft_strmapi.c create mode 100644 2022/2/libft/ft_strmapi.o create mode 100755 2022/2/libft/ft_strnstr.c create mode 100644 2022/2/libft/ft_strnstr.o create mode 100755 2022/2/libft/ft_strrchr.c create mode 100644 2022/2/libft/ft_strrchr.o create mode 100755 2022/2/libft/ft_strtrim.c create mode 100644 2022/2/libft/ft_strtrim.o create mode 100755 2022/2/libft/ft_substr.c create mode 100644 2022/2/libft/ft_substr.o create mode 100755 2022/2/libft/ft_swap.c create mode 100755 2022/2/libft/ft_tolower.c create mode 100644 2022/2/libft/ft_tolower.o create mode 100755 2022/2/libft/ft_toupper.c create mode 100644 2022/2/libft/ft_toupper.o create mode 100755 2022/2/libft/gnl/Makefile create mode 100755 2022/2/libft/gnl/get_next_line_bonus.c create mode 100755 2022/2/libft/gnl/get_next_line_bonus.h create mode 100644 2022/2/libft/gnl/get_next_line_bonus.o create mode 100755 2022/2/libft/gnl/get_next_line_utils_bonus.c create mode 100644 2022/2/libft/gnl/get_next_line_utils_bonus.o create mode 100644 2022/2/libft/gnl/gnl.a create mode 100644 2022/2/libft/libft.a create mode 100755 2022/2/libft/libft.h create mode 100644 2022/2/main.c create mode 100644 2022/2/part1.c create mode 100644 2022/2/part2.c create mode 100644 2022/3/Makefile create mode 100644 2022/3/main.c create mode 100644 2022/3/part1.c create mode 100644 2022/3/part2.c create mode 100644 2022/3/test create mode 100644 2022/4/Makefile create mode 100644 2022/4/main.c create mode 100644 2022/4/part1.c create mode 100644 2022/4/part2.c create mode 100644 2022/4/test create mode 100644 2022/5/Makefile create mode 100644 2022/5/main.c create mode 100644 2022/5/part1.c create mode 100644 2022/5/part2.c create mode 100644 2022/5/structs.h create mode 100644 2022/5/test create mode 100644 2022/6/Makefile create mode 100644 2022/6/main.c create mode 100644 2022/6/part1.c create mode 100644 2022/6/part2.c create mode 100644 2022/6/test create mode 100644 2022/7/Makefile create mode 100644 2022/7/main.c create mode 100644 2022/7/part1.c create mode 100644 2022/7/part2.c create mode 100644 2022/7/structs.h create mode 100644 2022/7/test create mode 100644 2022/8/Makefile create mode 100644 2022/8/main.c create mode 100644 2022/8/part1.c create mode 100644 2022/8/part2.c create mode 100644 2022/8/test create mode 100644 2022/9/Makefile create mode 100644 2022/9/main.c create mode 100644 2022/9/part1.c create mode 100644 2022/9/part2.c create mode 100644 2022/9/structs.h create mode 100644 2022/9/test create mode 100644 2022/Makefile create mode 100644 2024/1/Makefile create mode 100644 2024/1/main.c create mode 100644 2024/1/part1.c create mode 100644 2024/1/part2.c create mode 100644 2024/1/test create mode 100644 2024/2/Makefile create mode 100644 2024/2/main.c create mode 100644 2024/2/part1.c create mode 100644 2024/2/part2.c create mode 100644 2024/2/test create mode 100644 2024/Makefile create mode 100644 Makefile create mode 100755 libft/Makefile create mode 100755 libft/ft_atoi.c create mode 100755 libft/ft_bzero.c create mode 100755 libft/ft_calloc.c create mode 100755 libft/ft_free_str_arr.c create mode 100755 libft/ft_isalnum.c create mode 100755 libft/ft_isalpha.c create mode 100755 libft/ft_isascii.c create mode 100755 libft/ft_isdigit.c create mode 100755 libft/ft_isprint.c create mode 100755 libft/ft_itoa.c create mode 100755 libft/ft_lstadd_back.c create mode 100755 libft/ft_lstadd_front.c create mode 100755 libft/ft_lstclear.c create mode 100755 libft/ft_lstdelone.c create mode 100755 libft/ft_lstiter.c create mode 100755 libft/ft_lstlast.c create mode 100755 libft/ft_lstmap.c create mode 100755 libft/ft_lstnew.c create mode 100755 libft/ft_lstsize.c create mode 100755 libft/ft_memchr.c create mode 100755 libft/ft_memcmp.c create mode 100755 libft/ft_memcpy.c create mode 100755 libft/ft_memmove.c create mode 100755 libft/ft_memset.c create mode 100755 libft/ft_printf/Makefile create mode 100755 libft/ft_printf/ft_convert.c create mode 100755 libft/ft_printf/ft_isdigit.c create mode 100755 libft/ft_printf/ft_parse_arg.c create mode 100755 libft/ft_printf/ft_print_hex_ptr.c create mode 100755 libft/ft_printf/ft_print_int.c create mode 100755 libft/ft_printf/ft_print_unsigned_int.c create mode 100755 libft/ft_printf/ft_printf.c create mode 100755 libft/ft_printf/ft_printf.h create mode 100755 libft/ft_printf/ft_protected_atoi.c create mode 100755 libft/ft_printf/ft_putchar.c create mode 100755 libft/ft_printf/ft_putstr.c create mode 100755 libft/ft_printf/ft_strlen.c create mode 100755 libft/ft_printf/ft_write_str_part.c create mode 100755 libft/ft_putchar_fd.c create mode 100755 libft/ft_putendl_fd.c create mode 100755 libft/ft_putnbr_fd.c create mode 100755 libft/ft_putstr_fd.c create mode 100755 libft/ft_set_color.c create mode 100755 libft/ft_split.c create mode 100755 libft/ft_split_set.c create mode 100755 libft/ft_strchr.c create mode 100755 libft/ft_strcmp.c create mode 100755 libft/ft_strdup.c create mode 100755 libft/ft_striteri.c create mode 100755 libft/ft_strjoin.c create mode 100755 libft/ft_strlcat.c create mode 100755 libft/ft_strlcpy.c create mode 100755 libft/ft_strlen.c create mode 100755 libft/ft_strmapi.c create mode 100755 libft/ft_strnstr.c create mode 100755 libft/ft_strrchr.c create mode 100755 libft/ft_strtrim.c create mode 100755 libft/ft_substr.c create mode 100755 libft/ft_swap.c create mode 100755 libft/ft_tolower.c create mode 100755 libft/ft_toupper.c create mode 100755 libft/gnl/Makefile create mode 100755 libft/gnl/get_next_line_bonus.c create mode 100755 libft/gnl/get_next_line_bonus.h create mode 100755 libft/gnl/get_next_line_utils_bonus.c create mode 100755 libft/libft.h create mode 100644 main.c create mode 100644 part1.c create mode 100644 part2.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a4f24ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +input +cur_input diff --git a/2022/2/Makefile b/2022/2/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/2/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/2/libft/Makefile b/2022/2/libft/Makefile new file mode 100755 index 0000000..1a9a683 --- /dev/null +++ b/2022/2/libft/Makefile @@ -0,0 +1,101 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# 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 + +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/2022/2/libft/ft_atoi.c b/2022/2/libft/ft_atoi.c new file mode 100755 index 0000000..3b0badd --- /dev/null +++ b/2022/2/libft/ft_atoi.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_atoi.o b/2022/2/libft/ft_atoi.o new file mode 100644 index 0000000000000000000000000000000000000000..1c0cb35f21e7cab0a91252a4e496413ee53e13e9 GIT binary patch literal 1384 zcmbVL&1(};5TCc{M>MUe9|xfxRuEJ)&m^?aiby1^%|Sc}0WYC$(`_S~4>m8*3dTc0 z2)X!QcoDpLl!#!jIeYRVEYyRZ%pssN$(zmc*i#24^PAtyZ)Wq}?i=UPLrVx?6L249 z8M6R2YlaIGSb!x+LAliXS?awGj-3&)$Ih74C-bEvClIB+6Qn=EJzM=|nCzw)E_c5( zyrn`m)7fM;(@FfTj3<*$uJy~K-tfy0OAN)J=Zthu`t#r@$O_D(`|iw^Y<9o(ol*Lu zGp>Avtzz-6ePio!`KFy)lR25Q^V$4bc0HemIecmxeI6YfzydKKj!o#C&*qXYh*wWQ z9IS}drN!hsEM7sLoa_VrJUF-V)+#P9Snsiehev6m%Z`f1UF^ar;#S z#3h)}@t2WvYU;0Jfv)eg`rD|bnOXFx@qT`1xW@ZAu492Q_fSm6kukjva*ODZ<0r z-h3|eRjptztupl+djAFui +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_bzero.o b/2022/2/libft/ft_bzero.o new file mode 100644 index 0000000000000000000000000000000000000000..fd854f8e7f0d47afbee4269e75cf1678c4a27ea8 GIT binary patch literal 1280 zcmbtT&r2IY6n+z}KWZxegn~V6Pqm;!5)_JpO$l4~ARdH3FJd=wHK0jkGlB++LZJ}6 z|TY} z?e^w(S}hcooY~d&;%g_nAhR;-RSQG5ZOo$W0z??%VIqzcalnrLABi1EJt^yjWuxv$4frO`N%;GP#%Q!gCJDLB*S3emqBG~C-kd9H2S}m8L0V=2CQB38ppq1WA07bO91Bj zk|gpI3ma(bU!lP7_pkanXnD^JJZWaW`DRSb%r|in1(TZ|j^{~`$n9PiwL$n_Zx4I{ zXS2^`f2*75;XQ5rC5vHix*=X|{RdR||CEnAy2+_N=yS~vBl0 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_calloc.o b/2022/2/libft/ft_calloc.o new file mode 100644 index 0000000000000000000000000000000000000000..f246291c4f8781b71ba4f4c7942483e674aae760 GIT binary patch literal 1512 zcmbtSL2DCH5S~qIV>QuK1%-<2K}10xNob+=Ad#^4Aw@(8c#*PMw-(GMCD}kC6c0gR zsR#WR-n@FVAXvQBlh<5?fC}p^2cgbvXH2rL6m(!RGvCZNvzd8Mt<_s8!vGNjZonuK z6ySAg_)XZu!efq3ZwLCyu# zhm~@9*}S}Rr*g$CEU1Din8kc?A-`BGQom_b6ZHrx)<6o39l}Hmj%5dDIAJ`w2Sz7n z%xBU^Ut;n+;-n<6=;!8%-1Ag9JCk~W6$B&;^__+v`$^fUgw1EM@YEO{%|h%fYA&hC zy1(YwwOYeb4*d4Piy*AO$Q=65q(Ao$sMxA&=7>CS>f0yi!(@;f+ zddB%C4_cB!wsHOg#FOr4aznWj-H*7!7d&Y;jk?eCI~1TCN2MFZ`Lm3pnUFo^UzkAu S-1Qvh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_free_str_arr.o b/2022/2/libft/ft_free_str_arr.o new file mode 100644 index 0000000000000000000000000000000000000000..a7051c177a87397b163554dfe67a9a5d66fa4a46 GIT binary patch literal 1480 zcmbtSPiqrV5TCcLt$$jH+C!lp77C?;K9W#TdMJ^w_95aysJ9X}aoa+hr0l*zDijaF zVhBQyegqGGh>A${)-NFh>cyLfK%Lpn(B!#A(1F>R`OW-h_Pu$pgQt%@r9ec%5}ZeZ z0=)Ik{Zi_dU=k)^#dN-#_7C55_Ijqh*8}_FDCkqc$!s_1oA>73)E5d(H|QC4Y`S1N zM?FH?L0?@|^5$^oQ_A4l6Ls+IGc1?Oi~jubvz0r3VL=yk!7t{E3;FxSB8*}~AN3L{ z7JvupkT4O&v7Bv+6YAA-P_3MrnHax(fXUm4lag%F=h5}tzE_?c^VYF~fNY_@qww=I zD?5^Lqqnf|<^Z0~LTnZ_m(^s=R@UMusw6h9gmJ8E;2=P0c)(mbJ8A#)OllY4KI63B zffWPjWVdd^Dq0(#*$wgHXe-nWkOdP5is-~BJSKWSM-hkCmFUtI7|3fa2+Rm8LQCkrujnt_I`f@0*#H| literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_isalnum.c b/2022/2/libft/ft_isalnum.c new file mode 100755 index 0000000..a1fe540 --- /dev/null +++ b/2022/2/libft/ft_isalnum.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_isalnum.o b/2022/2/libft/ft_isalnum.o new file mode 100644 index 0000000000000000000000000000000000000000..349a4011985b21ba8b6c975596823a38ee25161e GIT binary patch literal 1280 zcmbVL&nrYx6h3b-1SZww#Vl9RK>+O+0u*N)>`OR))AI&uNFRY(o6fpIh zSfKyPkp{*qK4?GlHbgq7=q2B1??}S>LPP-C5$TOgJj2h`5 MxUp34{0>b07ZdGYJOBUy literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_isalpha.c b/2022/2/libft/ft_isalpha.c new file mode 100755 index 0000000..6a8b074 --- /dev/null +++ b/2022/2/libft/ft_isalpha.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_isalpha.o b/2022/2/libft/ft_isalpha.o new file mode 100644 index 0000000000000000000000000000000000000000..131c4ec90dbc1729ddc1008a67065792143b3768 GIT binary patch literal 1272 zcmbVLJ4*vW5S~jk@e##Wp~T{>RL~^}3SuEA!ABt$f*^v#GoD8Dl5n>|3?vqUkS;$b zWx(HJWo2g}=*(s3JeSxwFpqC$zL{nB?s4Z}H)a^XV!#&sAkG4OM3PpJwjc$gaJ=7o zZ8bih8lUIQ1loFY8m$$?r_E%CTHgjc#6Ek0y?lPtT-rN4UN*C9A}g|HE|Xi!tmksU zNHhbeCh8z6_CXAcF6CGZh50x$s$kTQz^F|a=~Qy4jm3G)laj2G*&d&Gj^)P^C2S!4 zhtS*sc>n5Gj`z8lacrE5(`=Y;aEh8gPoMJ&)e{+GXkT$-6djSBDQZ-;BV zpZz)(IOZPmttg1ZdhZU_lBmDl9&uZ7^mFOo>>2jaOr76V{0-&V>HHHc(0^rdgYq?X z&{>6t(bGAZ&-s44iSj`Pz)g( G&i@A3ms +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_isascii.o b/2022/2/libft/ft_isascii.o new file mode 100644 index 0000000000000000000000000000000000000000..b4d302e2fc66b80e4d9ba0ed6a67f7666e9e52ef GIT binary patch literal 1256 zcmbVLJxc>Y5S_ai<3}PY7D_D6N(Eh#LqRMg5@J$_g&I4eMhe$~w#l3@NE4#+BENj^rdo8nW+e8>bx6tG0 z$N>|KSHh$jqL$-lM8mk-2ct1*q?3t}Cv46mPENK!%l5?NgPBhaA0dJ2e~k7Wg3s@$ zb}Zs1CXhI-;JsNSzThX7zzN(+g}F*0_q9Y~Vk8fZ1Rm zI|~9}ZoOLdYKYb9++%oMs{wc1D^Xw8ZrP1rzwvzD1m=6!4)e+<7rs;V!f691X;ji( z4Qo5(L>=CPsEMl@^$ClqAm)x%%Tm`bVuRjsQ2h#OY0nJ0YI45(c4SY^mvJ2%GM5~R zEwxZ`om;?O0{ze1W8Fa~)6b=Uv&YDxJ$3yviP1LtAzXF+A$I7$%7u)6QWgiD75FGd zI;Yf2JZd&cy0oC3_Evx~jPypjp7zz>jwB^9e~t>p1RNq$m__M3f_ND+`-!gq0g}R0 AF8}}l literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_isdigit.c b/2022/2/libft/ft_isdigit.c new file mode 100755 index 0000000..fe77533 --- /dev/null +++ b/2022/2/libft/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_isdigit.o b/2022/2/libft/ft_isdigit.o new file mode 100644 index 0000000000000000000000000000000000000000..e3110471fb80f7c3e1873e86b7be053b6449cb51 GIT binary patch literal 1256 zcmbVLJxc>Y5S@!A@gqtU3ndn3rGl=>p`aEL2{9I8AqWAE}ex048#6* z>#f!7JTyB?w=rDTZsTn#e?;4)IC_ObF1K#Z6?XUM&CD{(u#9P?t>yHJWl>*0x``e| z#~z4)@j{$5Ltr_6LKKXfJut44Mk)~>c*5c|^5kSQv}}$hA0xSu*daC${=;bBe)#L1;AamJ6 zv8e(j*L(9=i=+Q~d&KwXWcs=EZ}td#Xir`LOk%XvAcU)~Kfnt8SJ|*5NUGwXlY$?_ zNavJ#$@iK~l6P9rPP!|=5Jq| BR3-ob literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_isprint.c b/2022/2/libft/ft_isprint.c new file mode 100755 index 0000000..7b5ceb6 --- /dev/null +++ b/2022/2/libft/ft_isprint.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_isprint.o b/2022/2/libft/ft_isprint.o new file mode 100644 index 0000000000000000000000000000000000000000..89a950777270795c332aa05a5be17313f82eed1f GIT binary patch literal 1256 zcmbVL&r1S96n<-#{ZcGC6b5al3TjYMhz_wKW{2ny2ptmJY*Q(JuseYTRuBZ<`cpb~ z4EkFFp;LFE-qV?F8tl@8H}Adgec!xcX7?_;zZ)O({8SPJ=qjMqhb@?fDah}2 z-aGByL%X+h8^-naF7!gwkI@%m72Y71$!wXcxr6+gnMkn&OPI-cG8IoJlSBxjo9LtH z$bkSDuY^f6L@me9iH31=2u3Sv#HK^zPuN^UoSbZ#mYqoSF^~z59V3D2KaBPb!spkp z_Q;T%h#+xR!TYmFe9ntiujy9noRyS9?rVx9fRWrc=3UpgeG1Iu?jTlV#+?=ic4l)M z*s13MD>Z60r;b>?!5xOzwc&BQbRp_;{faf+M$>WmH89t?w3$;Wp1XF<@u&SeiJ_A2 zYE0X~619I1q9(3t)F*621u?g^T9&$g1sn8^|JARfmiCOJt0w2mZ%6jzd>PZ&kh$bg zY^#Nm>)b5%Lg>HV9_xE_GW}foH(Njs?WyaZNsP8R2>z<;kFZ1kmE|)ANktrVUf>fL z>6}t8@nN$`(xnCMq`v}8Vx%|H^|Y`4b|l#o^B1U4Ou#-egV`|sy&#r-<{;7a-#Q3X An*aa+ literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_itoa.c b/2022/2/libft/ft_itoa.c new file mode 100755 index 0000000..e076598 --- /dev/null +++ b/2022/2/libft/ft_itoa.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_itoa.o b/2022/2/libft/ft_itoa.o new file mode 100644 index 0000000000000000000000000000000000000000..ebe51b250ff30d245f859ee0438af65c5a3f4d2d GIT binary patch literal 1824 zcmbtU&1(}u6o0#|ty=%Iv7+_qvqO0vaPh&=>~ z%TnyIe~TbA78)%ca#echMObYQ@zf}V_}*m3gw1-<2XE)S-|v0R%KX* zzcahWDh-uYevUJHhlOj*)?LaDtbB6xqnRyUxO@<`OS_J~%Qld&3#00;Hk(abKXCMe z@}@#u)uov*rhzpYuoz&D-uU(fv8vvp%B4CC*$zb^wG9!RufG3^IaBqn*($$OnzGUu zXW{pJ(mj)r#`}n7I%|yl*?31 z@;w(79>AII2Zi>+k7hRm(Btzap2R@h!=G?I3wq~K&mb;+J_BNxP=lylGHWHDS$RWC z!<=a)bBo!OSx9Eg90&rkMkbR_%RE~cbar%>M|fo2-p z(0B!NJ~>-3vZfs6zt#|D(`om4sw9M8YF`CMJT43)N@tefZ2K`H{wL=IbOKk(#aD@o z#IK-7c*pOD^Y6TkINFL8CSR`MlWP8JehhP|RTQ;TWPkZhNKTF=*D)ldEn{f?><9Y9 z-bJh*we#IV7xqNHcP@E;6ho3irBH8vPyml9s6)K@GsyYfUqT$H>`(VcxiVkgpI>ik sH!u3HlY>IvHTCi42N3h#9YW9$`C)Q8#Cxo#k@L%65MZVwmrQT|Z#@_mdH?_b literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_lstadd_back.c b/2022/2/libft/ft_lstadd_back.c new file mode 100755 index 0000000..3aa43d7 --- /dev/null +++ b/2022/2/libft/ft_lstadd_back.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstadd_front.c b/2022/2/libft/ft_lstadd_front.c new file mode 100755 index 0000000..4e6a56a --- /dev/null +++ b/2022/2/libft/ft_lstadd_front.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstclear.c b/2022/2/libft/ft_lstclear.c new file mode 100755 index 0000000..fc79c03 --- /dev/null +++ b/2022/2/libft/ft_lstclear.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstdelone.c b/2022/2/libft/ft_lstdelone.c new file mode 100755 index 0000000..80bbcfb --- /dev/null +++ b/2022/2/libft/ft_lstdelone.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstiter.c b/2022/2/libft/ft_lstiter.c new file mode 100755 index 0000000..0430cfd --- /dev/null +++ b/2022/2/libft/ft_lstiter.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstlast.c b/2022/2/libft/ft_lstlast.c new file mode 100755 index 0000000..6fa8909 --- /dev/null +++ b/2022/2/libft/ft_lstlast.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstmap.c b/2022/2/libft/ft_lstmap.c new file mode 100755 index 0000000..7715da4 --- /dev/null +++ b/2022/2/libft/ft_lstmap.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstnew.c b/2022/2/libft/ft_lstnew.c new file mode 100755 index 0000000..8e78fb4 --- /dev/null +++ b/2022/2/libft/ft_lstnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_lstsize.c b/2022/2/libft/ft_lstsize.c new file mode 100755 index 0000000..4fdfadf --- /dev/null +++ b/2022/2/libft/ft_lstsize.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_memchr.c b/2022/2/libft/ft_memchr.c new file mode 100755 index 0000000..1691bba --- /dev/null +++ b/2022/2/libft/ft_memchr.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_memchr.o b/2022/2/libft/ft_memchr.o new file mode 100644 index 0000000000000000000000000000000000000000..cb3efb152dd0535b072fc87a9bb5e150d06f86bf GIT binary patch literal 1304 zcmbtT&ubG=5T3WKtv?#ArC^~R)>9Sqk%SgX3la%y-$8m17xYl-Hf|fJo0QE9w1QL+ zge4b``d@faJPIB>+GGEK76QG*TW>m(eY05~d(wf~neUtV-tRs19zAq~05$>lVT70k zm~%#XZJ5?z3a)^!l2etu?kC+7mH5Z%hc}?A>Un*Yc;{yes^_008Yppe?F;n$ljWms zDMy~os<+-i3|m&cX-*GF8vLY*PwOm~+FIB75Fpln`UqHtm za6o(`j!hWMdzm!_@#-;%{b?~jHF@zp7H=X?PWFsG53WwXbLyoD=LvQYQEW8sIQ;ru zR2?fg!4fvk0U<%ja`FxT3xvpxA($WAApR*mw^nMo7-^^g*5a3**wbW zj3%sMY6fTfH<<5<+izh)+!zxkezY({Tfcw>y1swa-$gBrSw_zr&(Cj$Ydk;4B`k2x zJrqCZK`ys@J*-Wl|8@6>hkpk~dtLTZ-M}6i)7JNqBU?^G_OVYYxK_vpj}3%JF@jOu6=h%!5gE$K_F*_&Y0_%73n{j#+|G)O>F%i DCI4?3 literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_memcmp.c b/2022/2/libft/ft_memcmp.c new file mode 100755 index 0000000..dc57e59 --- /dev/null +++ b/2022/2/libft/ft_memcmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_memcmp.o b/2022/2/libft/ft_memcmp.o new file mode 100644 index 0000000000000000000000000000000000000000..39c1f8b05d106105375e91b841dc7e52eb6da75c GIT binary patch literal 1360 zcmbtTL2DCH5T3WKt+lO*B2=h{^<)eBNJ0zMgG9pGcTf>A&`W8zaod7!5;hxXh2kL~ zE7Ko` z{-nHY=T~H2=IuhRu##IX6lgHnB)W}$0Udc@fjFibo6wl=;F@lT*Uvy4WX0m#^u-U@ zyn%IcviJ1!;Bxk@Rhpl&-XVhu=|<;H!tXz6-HDW&pGV@=MEz_QiFd;--}5VeT~@~V z@ZG3Q>q@K)KsFBj(A~ip2E(||S?C>vAYZtl3v#E?09mQ|zE{OswHA63ujx)BbSp14 z-m5lcJ*d^aAUp&ac&}XP?QiV{uJ6(0|FcDu(;ZD2#}qXly}!o1C#K)TglZF9(DAE* z8JhZA*r4_OtNu1>>C7B@(s(|9Gu-3(99OZyIddrfOoBviavkhVqo3P7;(^wf&t-n9 zo5-UxO}(uLt?6?(nEDND(Eq8(1RZ0ozpn8NMtV-xb3JV~Nj9{8n*iD+blQ=rr*qBS dVF^BJ{Q`l6>GG&@1+z5$i6-uin8U=>{{?)Lh-?4= literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_memcpy.c b/2022/2/libft/ft_memcpy.c new file mode 100755 index 0000000..7e1aced --- /dev/null +++ b/2022/2/libft/ft_memcpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_memcpy.o b/2022/2/libft/ft_memcpy.o new file mode 100644 index 0000000000000000000000000000000000000000..d61dd5cb7586d10e6037fb6bde75bd39b5f25c91 GIT binary patch literal 1312 zcmbtT&ui2`6n>M|u0PsZMNp_hJXt}9-K7PoAS=t*Ij9FA;HB0yrY*GDU6NVo7K(?0 zblHo4g5duk-Yj^qh=(5i2Ryllc-x!4*UV(&kdr=mdEfiq`(`HdlGoz#BZo0C#^3>r zGs6P7&KNgNVFRY&0(i3jL-zN-%YOGn_Pt{{5Qs&J5pyy6B8Jrc^Txm%A~%xkWbg!$ zmrC~a;s-c%4#bcR#8BQB$H}Zb*iS)KFpQx44F&1yXIN=Am)(Vxr`~P1w#aL|=GLqA z#p+VM4ls#}yXa@ou>%}nN5mOpIydihMHkrKGhn-OY<{|O_AM5#BTr5i(Bt9k+#9Dk zGv&O%4kF5p)}4f3zssr0Tt>P-{^b1)Uxb#yER7D%15BMgYK*UZnhW zj4ICJmO(1qRlr~Q$_KulB*24q6ooD1T5T0_yr#Q}@`G)iZ??L;6Sq5Ita`xXaL4E2 z*4jqwMRVDx}zy;nTF2u_t&|ZlWD(+fVc@m==k2sO=|0JVS&c?ulhTvr8TSQ zMKk-GZ^qQj{w6MA!C=!v@l!D=V7pgft%Cm7>@hz=C$rCGf2yn4Lu=all*DNFvXDP* z{d26)|J2AkGVo3x^qS_+VWe{!z2VFDCdq= +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_memmove.o b/2022/2/libft/ft_memmove.o new file mode 100644 index 0000000000000000000000000000000000000000..fe87f34647ba13bab082843e5537a08eb76f5b2e GIT binary patch literal 1384 zcmbVL&ubG=5T3WKjXz>q#e=0D;zMS?a;ysmIf2dFwrT=m-I90`9{} z#VA0{Imt_dv;@SfL+bE>u7 z1D(OphvqH{4wpW|V!3=be{=CkWj0@&lSNs~y9IZyFz>p9F9G8i^5|#Kkp&KjPlT}v zQ}df#F%9wNDTvJ}F_X=l-NoiL#L3A%(#M0`)H|nqal-k43<5?Q%^inde@1o3MrP@5VPhkZ)l|WA^CqD+rdA0cEpD;RZj9BZ8EU{iy9>1!Y4N*sf% zHo`EdBUW$dK;m=Vj5FN50hYUGCj-{SOf2Bq{?6V`~5 zsfX`iYTg&quVX^k7y~ALvuZAF{S9o;8c(agg<6_fKu;T=&%Yh+@%bF*vB5cWDE>|t zsodsz*vp{*vwPwjqJ1y>C%a^*w!UEWcW741Z2dFr(f_KH;!yg-=&u_597eh)>lr7S ueKtvIM*o5ewDah+BU?{%?cE^+9iyM7B4q|1B9|~5rRPhn4VlM@t^W(zb&!Do literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_memset.c b/2022/2/libft/ft_memset.c new file mode 100755 index 0000000..a8408d0 --- /dev/null +++ b/2022/2/libft/ft_memset.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_memset.o b/2022/2/libft/ft_memset.o new file mode 100644 index 0000000000000000000000000000000000000000..6bf15574390fbbaf06660dd5b6707d67842f3fe1 GIT binary patch literal 1280 zcmbtT&ubGw6rM?ITeX$=0~G2Zp4vhklF))ENHnb7gLn`YdMWKToi?DGl-((`LQxdN zB^QsL#6Lyw;I+s80TBwGgdBR)?{(*G)*)W(gSYR!?|t8!*_qwf-qR-~DFvGp55=%z z6tOhS8)s=lOpD7R@Y5fDdU%rV_5CzB_IuumpL(a?y#bMaUhf41V5h!3>IMA|<#*md z_Pl}rz&nonL|*$QR+`QGmHCxt!9u0Bq-v^GsaNYu)#Z8}6UN~c_yss9*oOQ{7@M>; z@A-yp$XCyW+%L=7>B*^&Xx;`+PWG4{kFJ#8mzpyZhagb>52Lx`;@9s{?XeLjH3Qw zN%&uPkNOLo%-xs!t*(JXGhO`=iDCD$kUw4hDmwH(HF8Flys;a-W$}xMv`^MEK5A`} rOj-Q~6|hTix+7OlbKScGB-&PglZt{_I7hA`8>Rnbi90znOI-aQWb0;E literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/Makefile b/2022/2/libft/ft_printf/Makefile new file mode 100755 index 0000000..ecba3b8 --- /dev/null +++ b/2022/2/libft/ft_printf/Makefile @@ -0,0 +1,52 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/04 08:03:00 by tomoron #+# #+# # +# Updated: 2023/11/15 14:42:45 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +NAME = libftprintf.a + +CC = gcc + +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/2022/2/libft/ft_printf/ft_convert.c b/2022/2/libft/ft_printf/ft_convert.c new file mode 100755 index 0000000..61cc97c --- /dev/null +++ b/2022/2/libft/ft_printf/ft_convert.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_convert.o b/2022/2/libft/ft_printf/ft_convert.o new file mode 100644 index 0000000000000000000000000000000000000000..c6c25febdc11b5e0690e72074bc17ce2f6c5dd1d GIT binary patch literal 3944 zcmc&%O>7%Q6rOc{nl^uK6rrF7$r34~0!$LMs6`cW8f`PGDkzmKaiFBGPwkOo_o>V+~88jFr0^FS#|E0VU*^}MyXh4D;3w=;!d zbP2s}_wv;atb#jcxia8!x;2c`^0}(Vta(vZAL&zOZMl=Q1GG_|Sl}bOA~rxzAlBD9L6r8WW^CviO^d8?$KG_JRmxoJ|DK(W+aJr@r?zEv@;Rk3I(1 zuh`0PsaOqIyWox=CDQyjLgUB7i%Er{%gQV4x&KiZ)z*&;47Y3Ghrtre%GUUYo+lSdYa`ydp5%_ z5{~>|V}T@MPe@;)ry2j<7Wi@t{PPz0mo0EMXU)X3nfDWUD;$S0mrAE+7E-fT5?0Q( z;>lQE4D+cBad%h+OSnj-6B)LUPgw~qVIwN%@p2+XA$2vAn4O_)4T7C%h9(n>f?`{k zNXUzx68(?U-rDvgtKn!fh2PY0o&T+d>-;|@PVal_r$(Mmd0q;K5Au}6kpuTd&HILi z>-lpUeo*7%E<(W7`LAF?iFJ}z`PVf3fQFxyg&_z2G*tXwG`vT{FM&t`)k}}!KhkjA zA%$n<6@y#HKbE-K9~sU*)%g8do-bPPziPn`Q7i=c<=JV^)lXuM`R_oX>hjJUc(1pk5AVvQ{EY@8XvV zRxJLWw6A9Da4w(C(fwMY7-UK$XXf&;`GlPVT4j$u?6aJ3=Fz zRiuu1gCR60NlgZzmoP++Lxw!Xo+Axh-3JM?zkKs5+&@3=Gjjgl_;HFwPQ53{tj~W4 zh9>^`PmvGUn8v~IA6Y-X6S}B)rO%L4jdkAB{sWOtKNsHv++TnFAsO$lOYOg!3*QIi z^v7S2@wXIFYJWVsu-W+s<^PqJWgJYjgo;<^-)wG#l;!-_<%03f!94zW$kL64E^!{0xZ~dBLDyZ literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_isdigit.c b/2022/2/libft/ft_printf/ft_isdigit.c new file mode 100755 index 0000000..fe77533 --- /dev/null +++ b/2022/2/libft/ft_printf/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_isdigit.o b/2022/2/libft/ft_printf/ft_isdigit.o new file mode 100644 index 0000000000000000000000000000000000000000..e3110471fb80f7c3e1873e86b7be053b6449cb51 GIT binary patch literal 1256 zcmbVLJxc>Y5S@!A@gqtU3ndn3rGl=>p`aEL2{9I8AqWAE}ex048#6* z>#f!7JTyB?w=rDTZsTn#e?;4)IC_ObF1K#Z6?XUM&CD{(u#9P?t>yHJWl>*0x``e| z#~z4)@j{$5Ltr_6LKKXfJut44Mk)~>c*5c|^5kSQv}}$hA0xSu*daC${=;bBe)#L1;AamJ6 zv8e(j*L(9=i=+Q~d&KwXWcs=EZ}td#Xir`LOk%XvAcU)~Kfnt8SJ|*5NUGwXlY$?_ zNavJ#$@iK~l6P9rPP!|=5Jq| BR3-ob literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_parse_arg.c b/2022/2/libft/ft_printf/ft_parse_arg.c new file mode 100755 index 0000000..09af1e2 --- /dev/null +++ b/2022/2/libft/ft_printf/ft_parse_arg.c @@ -0,0 +1,89 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_parse_arg.o b/2022/2/libft/ft_printf/ft_parse_arg.o new file mode 100644 index 0000000000000000000000000000000000000000..1e0557c09f43aae376ca1fe65cd108b85ca9a2dc GIT binary patch literal 3408 zcmb_ePe>eB7=N>B+!~ErS*TzR3u>EcoUW2WNTqCICV5B=Htm9khH>0ob%^e6XWura zB(z{tIt&JnJ?7AW$IwHN9%N|*4fG&Alu~j?!NQj9!9ovvklOEi^WOTLUE7lOgE#Yi zzwdp2-uJ$5c0V!Rxf0SeB1t1}lS4_Oghbj7`2=SZq=U4RBz1qG?%lGx_l2>$W$dG> z67!6Gn%beBQKs5X=VNl-*e$lMqu&mU@FbUii$S7Q>K6B?n=Dgz;yEN(r5=FFiB*3cdUW!(_B)&4K zan?l>kwxc5No>DYD*kYYj}EYHkjh($ZaCC|qR@-eLZZth?f*YWcO`Wsnte2ynlL-9 z=#Cz{yK)kAn7&^MzcPmvc)_aZyehRDWZz&AFA-g?{>j>Xz8m;r8}QG!ND~BKefm$$ zurY+UrQTWy%rVGDJgB+UELDSbD(DH{Dpse$+_=NuI#uNFO96ADHf@}JFI?fx_p(hz zim}IvG|1MdhYb&n@4*0I0^*FdicG_JtiyObg7H{OQ?I%I4A0M~4wvYbu?+$N!*ww+ z{hjw-fr%Cf^=}jGp`Rz#=t^=20zKl|S}~0^oUf*08=uQxpZN~gF2k5`zvsCLAJm@# z0T0O^sjE@9Vr6ll&q%dV3gO9weWnOJ|S1f#xBIpT)mcj zJvMw!AJ&IsBk_@Q@i#|CpdQVzVz63Z!4?uCS_v^pnvmr;Iw};}$JdFr6w!LxTf?iM zJPkN5q=)#pcq;OFXsqKz=mG5Tb)$#_b%fv{^-bXrZa~`)Pzlt9!D{*rP3rG(Eg{(> zdYkKos_unbo5}A7bqWBQ8vOD^0Pj+8eip#`1TJNM2Eg8eg*HK&0H6^*1vvWu8f$<& zCJ2;)h4?0ZHGudT;qAa`D&C{usvldy)%`yyIF?k#{o@$CQ`8;f zs{03y!Hr|^4FyMEGVW_A0O6|@mc;KU_)7|Y77q!8YWyoC_s4)o!efY|a5=%BhxkJw zPX}<>cb^7u*>^-Q++JkX47{1+zvm_AWEL!)WtJGx(-yOcK2s4OJ;<{}*fB1`z-N literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_print_hex_ptr.c b/2022/2/libft/ft_printf/ft_print_hex_ptr.c new file mode 100755 index 0000000..c957134 --- /dev/null +++ b/2022/2/libft/ft_printf/ft_print_hex_ptr.c @@ -0,0 +1,97 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_print_hex_ptr.o b/2022/2/libft/ft_printf/ft_print_hex_ptr.o new file mode 100644 index 0000000000000000000000000000000000000000..b2f12b4b02783805ba4e0fc5084676932bd8eba3 GIT binary patch literal 3504 zcmbtWPfQ$D7=N=Mr3zhYQLDweiKIfR(*>a|Mwbhe$n1nCv%`x%p+fg<+=W=81FMr!6-Y zooD9J@zHZ0*i4`1&3pN3lfej1(dmai-MV_8$9sha$Wde)H|ZuA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Z_9#gzI;K4Ke&T zrOIi+AAiqOk@0fu0i&F&egpel{{RGGtHb=Si1;us*?(CJzqeRF9Dh^9&r3%!hU4)R zqN^e7axm}`gNV;M!Tm=_#>@S$R2$uY-&@(NyZ`_I literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_print_int.c b/2022/2/libft/ft_printf/ft_print_int.c new file mode 100755 index 0000000..b710860 --- /dev/null +++ b/2022/2/libft/ft_printf/ft_print_int.c @@ -0,0 +1,99 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_print_int.o b/2022/2/libft/ft_printf/ft_print_int.o new file mode 100644 index 0000000000000000000000000000000000000000..99e059c05da01658235de172f5a67e80fb790314 GIT binary patch literal 3312 zcmbtWO>7%Q6rOed8sQ|SL~5WBTA>1tLX4fJg`&2&q(kRGK~&0(YH=Lrhd55^tV;s8 zjbs%xS}IkXdH{(-&m1^Zg#&R2A_NsFoVer=svucS4n~R;BUyy^W@k2&jf*09((cUr z-uvEr^X6rp>-3G+1BOAA800M3)f7s|RP*jWF1B&fN?OPO!xMcchd@| zRXo$Re#i}xPCK+6mPXOYHlf&IAQmb+w&~C+|8e(-P}>@F4m0C>sC13-kdv!8aHazt z#yiTsD59K`ZaFXRsURmSh^m(E<2tkq75h(Xwc;3C~t0o)(CgYd;uCVO~Vk}B^ zj4!!`iplZpI5`j4!b7mb^sEJ#vBHcZ>sr7Oy4iqDZ@XI`X#1`x`M12RQJ!BNVov?D zVQ|7(ixr*R>cM)Z4S<;Xl0#R;rVImHCbRW0>ScB_S902 z7>)HF?>lkwrI$|;a-qNf6*GL{&4Dg6))$FIVrFl&w=a64w--Xz!-Ju*$>2f)#3&-B z#E`oBrnF0g@xdix%!G`i!KOpEz}N{mJ}6i4b*?q^aiG7YF^~oi*LE6lkW2XT>=!-z zJBWkKVKQZ}`_MoKjQtTBL9XIU*#lQR{^y8;JiUkiq~N=j{cm)wCx7njw-8cS^Gk}j z7|A`95NL-rf6)WLo|m}N#n}PF-Xq5^X8^!Bi_#!^0ekFCE&unVe}BLwh~B_4gya&^X z%($SVd3Y?Hw%#8bvPUJ)O6RQ1U`;BqtZ6%u9Ji9A%#l+zcm~=D$XZ32q1{TxO(`qhU2X(|7O`&zkk;w@T`X8PqB(~N8-5DY53Qg zzkc2w4cF^`3&|jeHNm6ePinZH_cIOG&->LQ@Lx6jF)h9cdlW27mL~MLc<VbRPC~W^57}O4tb!8JwObk?f?aBqt{( zQW>yiChb%NzIi=j+N3^`$wj8JlT)dzJqsL+lp3{$vx$k6tmOYKCeU%D@J@A!OXWA& zXJwP)r&Mwjc6i5e4{?-r%QUC48=BJN8=j$qIl;?MsA_+ZTc%8vmT zW9qX4s+S+@*2SM6e$NCysyo5{8CgI6PUxceYJCliYOnj9J>dEA`;C8J{`%vR@2^Ys zU**E@HRkv8rzBtePph0^_49EG(KQZ_E_2cmzxycINBnzNe0Be|a-)A({-l|*IYGcM jkDre*{dW%#VRHVyKt&UOuOA0nEq+BNvNbMl{rrCb!u`B5 literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_print_unsigned_int.c b/2022/2/libft/ft_printf/ft_print_unsigned_int.c new file mode 100755 index 0000000..e324164 --- /dev/null +++ b/2022/2/libft/ft_printf/ft_print_unsigned_int.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_print_unsigned_int.o b/2022/2/libft/ft_printf/ft_print_unsigned_int.o new file mode 100644 index 0000000000000000000000000000000000000000..bcf366d601445df1efe8588f77150082484e285f GIT binary patch literal 2048 zcmbtU-Afcv6u+};ex%k`8(10)Xkl5y?xGJ##ERXVBBBqBUS!#i(OuddW%mwhuoVmj z!@Ts^pWs`szU4YQnEw5~cEm{M9+w3=+?oF&=A=RwKtm>w1Y{E`ftskmQBdR^#rCO3| zJ#K}t2f{wp8tH&IYW?2E9;*3CwrJg^b@jb!(Z)KhAq>a3N$b@%@B_3C-E7)7Kx@u^ z*R1Z6R|8NUPTFVF=)y9)1Vpp3Z=AR3uJ!q23`)4=CED1L9l=FcaL#4OUIsp*PvqW1 zvsv9Ftlg%YsI7Bi0m4^4Xcgh+D{sk@`4^&KR80Khiq*A_idXuy96xeH+KY9kK`?Xzmbt^sdi9-amVkJmTjs9;5#Q DS2RZ% literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_printf.c b/2022/2/libft/ft_printf/ft_printf.c new file mode 100755 index 0000000..19a0964 --- /dev/null +++ b/2022/2/libft/ft_printf/ft_printf.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_printf.h b/2022/2/libft/ft_printf/ft_printf.h new file mode 100755 index 0000000..dfffefe --- /dev/null +++ b/2022/2/libft/ft_printf/ft_printf.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_printf.o b/2022/2/libft/ft_printf/ft_printf.o new file mode 100644 index 0000000000000000000000000000000000000000..311e012048b74f4a0fe4cd606d12a998ec211aa8 GIT binary patch literal 2400 zcmbtVPiP!f7=M#L-PkrxEIkORI8ak|s2z4=gi=CT3EMukiin}{P{zsbB)fJuS!UnR zZ6UR?8F5$^f{?psFXp0nQ5Gx2Ueue#lb1kBdWZ+XLva1RH}Bh-Oj8v6;O+N&zwh_G z_q{*!_M_spD?^&b$TW7D#XVvfGmgc$AYp-xvy*I|hdaFe*x=#X?soA2BadE$0eHK( ztMN{8SO1!=_rwVWXQ%v~0n~#(K`xbhqsfHX3u2#CIWb5$D}E!^5I++E>G-x;g*3Zr<3^O}D3;^QbwvU`Z+noQo~yt^5NyEyeg^%GawO4yNuwEr3w=LVYSoRvULDzBRV#h$i78QR^9 zT;N^?Bv>%-Y~l`-`T5gwN5rVSFAwgst8;UgjO^97=S?F&W96;9F`b*9$-O!~jf-R> z&PaVS z1MVWUqx5e)g}?q3o-GNx;Z;|}l2t-ns<@?_cBAH$+{$XL?0QXPtIcwCxhi5YqFY{7 zxOP)`cEj}gbtobAxQ$>M-pr!a_l&G%*DM$dp>gP9C+mMOp`X2 zCR8vz|I5JRm}&Wc&Cf$Fj)|{n(kP$a0*cZ6 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_printf/ft_protected_atoi.o b/2022/2/libft/ft_printf/ft_protected_atoi.o new file mode 100644 index 0000000000000000000000000000000000000000..a899f1550290e16cddc3eafa119e6fd0c45f35b2 GIT binary patch literal 1432 zcmbtTL2DCH5T3Vbo7A?ZibA0t)`M8lJd@CZ6_IFI`wrqk2=o%-Hr=+ONy_F0TG1#J zgwTt}{tIu?ixN>N-g@@rMF`|lAz)6%ndH4>eeOvIW@qM``DWg}*?sBUzh^N9S{U4h zQKV6T18d}G`fdiMVG44h@m(}tw8W9qCHTnc5WPJv_M8?I`%WwV4sO}IDt`?;=Y9E*?NEWwTiYl?=`Rh97%&AnDq90-O`aPalf zwB`EyLp<3lvFvo8M-PAXdcAfG`Q7+ir<4B#E7|N#dtv24?uwmS$^Lr671PSU^}yHemWX^gUJhslahR)$DPx&udVFNg!LIK z2nZMII|e^`VcAH?#?E8m*#O?3MdS@x*!C;ZD@t#@;L6HlUi=#yyepN{+5@Wx;MLud zbl1>Ie_*$?C%qjBeBG5U@U?0cc(GC{d1b`PIFRGDC92XbK2h;zxyJD*+nz6Xf&1Q5 zmwQ`<4c{$!H2MEz9_e&v6Goeiiih{1V!bzAei0qQA{tP3(kxWC313E>*7>jeYsjUZ zNz|a|`T85uIXz$7B}`~v*O0vw28Pr+h(%HV*geJzif^9F{B-lGr^#Pc{2Q1LipgKa zB>i8RU=jLrs^Of%C(+V5HDBX2#+*$Q`UgoK^`8Kz(9(`fKJ_(sN0bxAr~L*+!9(Z_ QdSU#eI@IQ{a^RT!-)$kE@c;k- literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_putchar.c b/2022/2/libft/ft_printf/ft_putchar.c new file mode 100755 index 0000000..84bbe70 --- /dev/null +++ b/2022/2/libft/ft_printf/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_putchar.o b/2022/2/libft/ft_printf/ft_putchar.o new file mode 100644 index 0000000000000000000000000000000000000000..2e948f68389cb256a255ba7eff8f674682a1ac33 GIT binary patch literal 1384 zcmb_cO-mbL5T1=Oe#H=r2PJ}gDpuN;Bv>dOBobnR6b}WDBAd8rs^){uD~(<}2$CEG ze}X?Fcxgcp{2_t|4|?k%U}ut~u1{lKhxXV?2y%qmH6t3WUJ=Nt}qqKJ_A*9ROG-U%+a`tweNe{1Sr;$di&R)5m%& zejdtBM_f!G|1Uy)!|?nP6dnoKNDLF-`1t-TeZ@SL#|fW zuEHIEXlkc)!2Z|Tk!pDLhU@8LQ2h>WWw-1(ReZSrAU5`(9Y>5_8TMs=5|%rQpFo55 zk`aQj&53jDPa+Z}w-){_^CO%murG#z=KS{pTb(|nMC!A%$IjoVlrQF6$4^R z4&k}q@!4kXCdS54U%f-nE7!v_DYc`SSad0Mp{a3|i*xDcJvWLp&tMCuaR`@~C8@ literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_putstr.c b/2022/2/libft/ft_printf/ft_putstr.c new file mode 100755 index 0000000..c742ffc --- /dev/null +++ b/2022/2/libft/ft_printf/ft_putstr.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_putstr.o b/2022/2/libft/ft_printf/ft_putstr.o new file mode 100644 index 0000000000000000000000000000000000000000..8e810d0d81b732fe8b3dc92b42ebbba3385f77e2 GIT binary patch literal 1488 zcmb_b&1(};5T8xIqBatXpimF%rB%>p5-LcAk`mf3A|47oma>UkE9Q&cSK5k2q#%S| za_pth|D>gb7H|F&f(I|&auC{?-5K)oToJ^9*_rvx%fkU>sJw&NpxGN8an~_Po8_9%$FwU+8(Ai|)<6cF6T(Csj^)m`IpMrt24_3(OpcFb zyO_L(I4Q||{J5F_oT=nSKVU(Oray>x7=B)+WrtEGmBYdb1CP%_><(%^h2;Jpa9G!C z?M)r&P}TZAc?i{mCTxXobpSBQoHP^CUzdqIF>sol;Li=*tallwH5;o2P|;39`&G0$ zOzehuVNmy#4z@L@*S_{aRig-0t<`7*O~jfl9Vpz{<4F6pcO1WIZmM?JY6qd-0TnX@ z8*A&K-@upo58@&R?QGQIDswFRkTlhrLi41#luZ!*6E5@^zmAq5`F8FyKE?PD$6`K- zV_EzBN0=whf9)?~FL4%7O_B5EACR1!FLo9a;!6$LLo+aZyY>a<#!v^oA&ieuN$h*c z{E{p{6&>QV`@eF*Gbvsy$&cTX)Y-@pEs{wo%HgLD7@ literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_strlen.c b/2022/2/libft/ft_printf/ft_strlen.c new file mode 100755 index 0000000..e9f507f --- /dev/null +++ b/2022/2/libft/ft_printf/ft_strlen.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_strlen.o b/2022/2/libft/ft_printf/ft_strlen.o new file mode 100644 index 0000000000000000000000000000000000000000..8ffc1e64554c6e190eabeeb7777b7e56ff4caa29 GIT binary patch literal 1256 zcmbVLJxc>Y5S@+j`&$HsSj0+2U6P<677__(QizBUun|4u#egP}yA@Or1w{>M{54`3 zu(0({2mu@I13HuJ#AAt#19LO)&Agqx-McGmeJvmaunAa!U&Jgx)kntbbR7Di7t*QH zd#ZFw*UeUPYX z#2jbJIa44HY-NMo_dJl9Vm|K_kSi3GBk`E#J!NN(G(Iex$`iME;<)M@r0X2p(#h>+ zT|4jau>Z#pO6iO`j3we4H{V}lz9(*<#DusuCUiV9Fhf&6g$265|LW&ZOKV2Z{l@e8 zo8cPI=eURk&bf!;y&w2;v)95}Cpz7~-ySqD_ho*oJJ?5Sn)+w0U(%6-so%x|{ZDaj z&@rbsI<9dyM%pLqnQt|lB%ky^+p9kTdN9%*nR;5+ygQO?>iJ^?e5UCpGmKd){k3j9 KY<4yhQ~v`uQCm3x literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_printf/ft_write_str_part.c b/2022/2/libft/ft_printf/ft_write_str_part.c new file mode 100755 index 0000000..3dc57ff --- /dev/null +++ b/2022/2/libft/ft_printf/ft_write_str_part.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_printf/ft_write_str_part.o b/2022/2/libft/ft_printf/ft_write_str_part.o new file mode 100644 index 0000000000000000000000000000000000000000..f72dde4467c2fd565be728df8e3fcffee2c99e50 GIT binary patch literal 1488 zcmbtS&1(};5TCdGR9jueLZKe^;uqLQ5-La$iGP~^cWvWg<+_(&lX;o<3c12s?q;Dt zOn_-r4|N6=tH1#+E3# z0og)*r{ULeR(2|5(@R)*A%!Qi5W9-%W;NN=)tBLO9aJM7R@;84WgR9kNJ@zQ#PpyY zkp4a%iDz&+bL!LpGTLouzlK(aBfG_37;O7e2OSOasjq#IwI~8vZ#5c06R~DX2NHL_ z8fm}&!o<&-JF*?N+CivyK_(r7t?FjzHv;p5|1%!aY3H+6o1%$%pPc5qbG(8M?WM?o zu|G}WvWZWlC5TVY_!WasnL0K{>{!;Ge*^Q>^I!RSB-<~L*dH?ob_YC~x4L;-dw)mQ9ZMQx#UXAab=>?Li*4Sr zfhpRSIF7T@apuvz`e()0ir;gb8@^L~)o*Yd``UV=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6u0>sxA0F0miZ0$CtxqfFi+Bt?&P7W`bRH${n>W5 zMw!QIw%oSHyGG5OCP;4xexy$PdnZ zbMMorq|CilPh58LMPF57Z(l?7=6e8D7Gby2RYO-v@V`=|*;xHQB5hw=oA7L1J5C!5 z`2T7zOM6N?+Rsv$y*$N)GM7|pFTW}UT6eqrFnhUN{xEx4_-9%R!pRP|E-S literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_putchar_fd.c b/2022/2/libft/ft_putchar_fd.c new file mode 100755 index 0000000..e9fe3be --- /dev/null +++ b/2022/2/libft/ft_putchar_fd.c @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/01 04:10:53 by tomoron #+# #+# */ +/* Updated: 2023/11/01 14:27:29 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/2022/2/libft/ft_putchar_fd.o b/2022/2/libft/ft_putchar_fd.o new file mode 100644 index 0000000000000000000000000000000000000000..85ff9b926cc05e3d5556a7ce761bf881ea3bc2d3 GIT binary patch literal 1392 zcmbVLO-mbL5T1=z>sN{5L9oz8Xi=~)Nl*|EB_*T=Q4a-=C2W$75zPmiHyFKmC>56? z_%r+o(v#3b>81Zd@ZdpjIRxxXb|$Vb>&1cDXXcr&ci-7P&Tf2(Sr&*`@ChD0VF41c zM?2j!(=Y+!u$}X-bKh^{e#dWhPP5(I*=F}=w)2a6rzq)OVUL~1FqoJvu~AgYb}3Ker82G$jEA{P5{wrLJnM_<8e$F14%;n(LFe2Y9O z$pSq-zlop3G8023Od$Ump}vD~{}2@(h`5nSOq>ewy;;b;Lybo@DeHWrrHd8E%a=>4 z2v2-C@OHIJWpi9h?@ro%2*hTd)(~0+fNCCAwNpUUUVs&`Ja^ww+HGr4B}Y4;3e6^{ zV!c{*Ysl5=+EsYhADh}K?y6*|+$!Xwbc+gqCX-zwa}F!E~Rc|K8j^1+O@9 Kzn>WxX8nIM=4(>` literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_putendl_fd.c b/2022/2/libft/ft_putendl_fd.c new file mode 100755 index 0000000..1f3cd0d --- /dev/null +++ b/2022/2/libft/ft_putendl_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */ +/* Updated: 2023/11/01 14:25:27 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/2022/2/libft/ft_putendl_fd.o b/2022/2/libft/ft_putendl_fd.o new file mode 100644 index 0000000000000000000000000000000000000000..8bd0317589568c4169b90f86ca69b87cafddce85 GIT binary patch literal 1632 zcmb_c&ubG=5S~qH>yM_y;-OH{J&6TflhA_oAgLjCK`T<|Ic}4UQIk#BeZf{J9ty$| zgd+YC9zA<1dJr%E4ZR2+JSg;#gHUI(GwsV`y@&&^Gv7Dg%=3ElXkJ6IbIs)ug; zl{o|-XczZ&E|ExL@5`sN0IQYCE&J-~gN+5dxabs}qFpMK77I(I5=@}p#&rr83Lpd4 zK5=3eW4XfxPFOG2!P?4O^V3tO_b_=8d0J%a^k-!z|0+|-O=i|mK}5Py-wF72l$On= zz8pYyblUNX^9W}({pbwHUB;CkmyXcFUwCM$TCcDCpwX^18%}*36N*&W_5*kxK2biv zCGJgcMsN80D6x{pPip)M^ECdf#@}O}`sjL_dD3g241g1Dca*n@UWJKoNfi2R&r$xC z0;l0A51h>?0w?Sypx*6t`~Y)7SNRUk{CcFk`ZLClgTB)XyFEWt+gL-L{8p_QdL6v% ze=r++(9G$Mx|JEo+$2X@-R2R{8i#QZt*M9HT&$NUxM>FsrUqXR8A_rHcY z>iMtrMXaTsW3xmo`;C{}7@QLT literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_putnbr_fd.c b/2022/2/libft/ft_putnbr_fd.c new file mode 100755 index 0000000..2b3059d --- /dev/null +++ b/2022/2/libft/ft_putnbr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/07/11 23:27:29 by tomoron #+# #+# */ +/* Updated: 2023/11/01 14:06:01 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/2022/2/libft/ft_putnbr_fd.o b/2022/2/libft/ft_putnbr_fd.o new file mode 100644 index 0000000000000000000000000000000000000000..67760f81cb92202fda010a916999e205e9aa8d65 GIT binary patch literal 1912 zcmbVMO=uHQ5T4!C*3uuNco3?%C$VUkB&J$DlxT@vP&^cZ$FfN`P1Gc1cY}#gtrWyZ z6ngUPu~)AiG+RaMMOqK)u@|9QFP@ANs586orJH3B(t+8X`R1FSym^}k>FZZzNdh4f zOv0WgP=Hos&rZ2!3Wi|_G8+4)E&q(N#Wt(9mKWRo_X~}5Tgz=|#ZUA3d|q>YD9&Hm zX`LKhYouH39s9CP`Hc*c*0f^NBW)|pasJ3`gNP1WceZ3{U23vTa+aI1L$8{ROpASH z@7?V0Pp|}bgSz$*p8!kM5v=}l08Q=b5I#X;A31p^>o$HphN#y&-TwWRb&az#`F{hA zuCdLqfmS}e8B4^I7m^d_&L<}Trl+PZDW|7zWJZ;EQjM!|B@s&`W8;Yg%?8kes-PY~ zMHa{)H3<_UabN7>C=W>YWa; znnl|Xb;r3uXGhxJ^~CbwbjAXI#&H?nbfpFUoa0oZ*N4CG;r=>reYn4G4__Eze!jx_ z)R(j)s#P!9dKOg6HobR2Sf+7DS8bzagF2_%I;dI80@bW|POefa8D)%>E4HEH9U8N2 zJ$IY?^X00#U{)3k)2?FIDbrW +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */ +/* Updated: 2023/11/01 14:25:39 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/2022/2/libft/ft_putstr_fd.o b/2022/2/libft/ft_putstr_fd.o new file mode 100644 index 0000000000000000000000000000000000000000..edc1934058ccb59aa97fe7178447685a4caabfe7 GIT binary patch literal 1464 zcmbtU&1(};5T8wJTeX$6co3?xCqKYGlF&l!K_VgcA?iWsQNkwOSTSGhzR;vlJQRc_ zms|w@oT3Ny;(sA{@SxB`4nm!InMu>fdeMQ|ncr_d-ecymZ^};|Wjqf=Ja_p=dPb$S9z893%SC2Zlh43s##PY^#Us9KnA>H;zT^ga@VUI@D84X*UNgV zi}MRZ3|>c`l;l2r9$v}5&6Jkr3?>l%i%{QL_;s2Vo=KTd786&dczYIdH&7|&%55al zc&M97r)y#pRqDH{b`BE2KqG9ye)P(O)bl1crrD7GJ{^l4B6BoD;eGT;Xq{6l1yFIn zX@V+R6OHYjcv090lnHwV)NWt`P}MjFRckk!VGFrd+k^^tv=*D7_L}j_R#$bRb|;KX zAC&D7?p5kh(6raKcle)=kHxg3Ij2dHvCLn>@=gS=qC@j43c>c66LX9&p(RS*$~ES1 zF+amtOkW(wy64}+IQ9J3`aITBPq`<$R^)tn^TNydVz)3LzT}X7Hw~tIH}^5d=26eR zA;j;w#=V!!kHb(!hkCm8pE+Su64|=-FOW~$-%q}%?1}bAwNfv9+S&Fft{++ea2YM_ l$gRJ~Jf}?z{c}jx#%A(mdV-hHb9Ya{1s+Iak~wzV`ag~Nem(#I literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_set_color.c b/2022/2/libft/ft_set_color.c new file mode 100755 index 0000000..f44b6e6 --- /dev/null +++ b/2022/2/libft/ft_set_color.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_set_color.o b/2022/2/libft/ft_set_color.o new file mode 100644 index 0000000000000000000000000000000000000000..5ac5da9874f861d4aa7fbf5d1659bb4c929c5bec GIT binary patch literal 1712 zcmbtT&ubG=5S~qHtJst%B0?1RqE^r)Nvmip5)CyuXb**mP$X{Cja9qZu-QT@hzCJj zg3>?2gMUJgg@WQAB6#pnp@$vGrXwI^^xleDi&8-mko$d;BP47$j!UeLBnp zB`RhQ<4P1(Xo7OosE5DmAO7UScY|k#}@o=d^UgX zM3S`9^PR%t)ScP#?3LyC=Tc#@=n~bc)fscLHs82zmZq(eRWi%P@^tZ5xlAKGr^y4I zm_Qjawtpa+8Y}8OMN4;qzc3|1nd|jdqy8DQfqCvlZ}> z`qQ`$D9zA!g#I3+)v~E4O_Ysxb5xP%^lXA3t&y=yJW$i^8Ux@9FIqE5?V#Cnf@aHG z^?a*!Bt_EoUv+{uBHtPESaum&whRwEg~35=HvqEX%y9>T&j4f-elAX_ro7HK6%Iaz zSVaYb%YMk}ZMcEG#6Iw2zao+EtlC!KtOsN*+ks8iQm;pr@5M>Wb6uyywT>4!7QdOB zy})k0QTfZxn$`8auHy$AtiepqO0(_Tt|LqOFK@CMZ(>xNrK0kA4VQN-Fzyj&R}nz@ zNp)y1RDPO0w0OI)3$dfC?13l#&Qaxys_RbgkNd`)$JLiui#d~b%qdC#^GFh=_rJ?E zV8sLn;a8Q*e^|<*7ypn85(@`@JDDV6ox8xbF&_H*x0Oa;mz=*U(`yber>@^sgl9rj zUf1IlrrrN1HKFv!{h#6?db$6!-e^@<8~uiaZJY=C=z7el-#tULtMs>#Buv3W +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_split.o b/2022/2/libft/ft_split.o new file mode 100644 index 0000000000000000000000000000000000000000..640144d16bc488445d5a601eb5dab87bb8c5e24b GIT binary patch literal 2200 zcmbtTO=uHA6rM?Jtv1>!qC$JfK}1EDHYn60B~r!?^#@S`9xOGD>ksCSWP+_w6p~7p zHQ+_)(WBs5@gNduHPMrZ6%Rpjh_F(@pOc5$_}*rwS=SXrAI!XY-+SMCZ{F-)XUC5C zC?!fL86qu9p@f`iYn{XPF-$g)0Euwp12?8EUu~9SUq=C zo(rX1eQC($6`P&j-?*I)Z=Nlyw2S#0?2CJK_&gb~knjbL?B2Pte_Li7y=7?r~ ztiXkFTB66ZKp7isc4&@$e=$!+hKC1(yGBk#b_e_SYyDb(Fw_^?-*+GsvLn~P9)yLT zEd&uCp(VtWP-&}geT#I^Yo`dE?4~_|wH>#?*$X%>lo{L(Z|uJ58{W|Fy8#hR-yy_7 zhHz8y`B~oYzfYS%w%2<@${O;u;pO#v{HXy5guAYW+dYHTBXMQh zy#lry)@F#G2aRI)2pXr@jeuJ&i1BPXepzTS0>@Y?mlWgaXhvkw%!*80PmX8xv~6J= zNkrrER7|Dmkgefcw8L7)zXjy#AMl_g`at7S5|#&rt9zYu;p$#Q%T6UkbON--w(NpuinqAHd1C~{d;JD nbi!(b<>s#g%>8x%kv>`fAQ}#F&w3O1y!e*n#~oZey7@l=i4%ok literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_split_set.c b/2022/2/libft/ft_split_set.c new file mode 100755 index 0000000..023f0ce --- /dev/null +++ b/2022/2/libft/ft_split_set.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_split_set.o b/2022/2/libft/ft_split_set.o new file mode 100644 index 0000000000000000000000000000000000000000..ccf60b565f6460f7400ded6e596b8a9d1acd0f78 GIT binary patch literal 2648 zcmbtUU1(fI6h5=tG_6TZTB-z-hkX#WpqFH+m==-MICiL2{9)frlg)Z-OZJc5S!uptm{Wi>pf$S7}gEm*JWU;FMQr_wAk%k>pmFT8?|3<$*G4NW8Dn+ zE_PxTJF$kHpcCWbC~pXLY>#(+-WAux&2Ca-!s9`kceatjrma!6YlEh>%%;`v{xO8p zh>d*D=l8@lKid)cJEA%I3$+;y1JRs1ypt>0=9{GH&4#5l-(tecuElt7>xHIF-q|(#rG=*yj7g|69Sc@=COzriXJE|1yqj!K^9A}fG!w0US zatd);L?`I;@}uLQCFTz8muP@n(!EGHQuxBOKJj&EK>GJWEx_Bv2l_Li{z-&BR{EP% zjMno;GWjiwk|=!~BbR+}e>+Z>jQOLCqu~()56^_y6AIV+@GOWOQ}})4MBy2bzkrM4 zyrLQy){fY#xG2ZJ=$u@rRSFmI>q;jNxV=zAxk6IDTrbImO0Ftvw5`c%!7XX!zzd4G zLZO_GA}^~1G}9!mKD|ez&v(J2%M;xT(>|^0x8p1sIO%l!4-K4t%^JUM;AZ^q44m$w zw*Sq*%{Xo%I)GizSG(Y;$QRFt_TV0N_L_&s!hjc(WJc2Tb^ba7Kh!{MD zoNy}*%-MjlxAQ-XIK{Nh|EvED`clkkTqbFM`X8C3^J{(*m0C9K7VLtQ(zZQ~INfJ; zT?Zi+mA_q=?w>YXLV;r1{#TX%b#17)?LUur-28;P5R1x>=10ETU(YWtH@QqxP^4D) l1sFk2CE5N56|T$%Y)kpSK0qSD?%!dA<68Zts=u&@|3Cg>7$E=v literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strchr.c b/2022/2/libft/ft_strchr.c new file mode 100755 index 0000000..978f990 --- /dev/null +++ b/2022/2/libft/ft_strchr.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strchr.o b/2022/2/libft/ft_strchr.o new file mode 100644 index 0000000000000000000000000000000000000000..d9ebbc82ebb2257259b6585922be916c4f597f35 GIT binary patch literal 1360 zcmbtT&r2Io5T3XG>JM#f5n9m0deVY@BtfC=p`?VZTPQ^Y!Hej+T@7dw*?j>mlpb1y z5GaNIFXEw;P!C=M{TCDh9;%RoH=QwWlFei3!4AC4eBaDBv-@WA*?ITI5(3x+yn-%b z7GS~Z#<`m?2g7h5mfY&8Tm96mR!)wc7A4%8({!uOY)DOcO})6JbU}aX^9>R>%Z13KTYl*Jq8YG{K^r`=kqV^>G}6dPwmXC%*c$LO=oA* zbJ;9FKbF{d2Jm17SRm@eu?da&4#spsd|U*vJ1WM9hwgmGj$IzR(@pA z`i2!mBpdbZhl{JEY+u67k6_`W7=JU1#2acgQlVc6rQeO)??!1_S8QbfGTJLDZymh~ z+rGe&3U(F951#Tsu166_zg#Q^CFDwF6-d0MXOZ&!EsZxz6}c0ZcY;vufeeFfPX>k6 zjnFFwH2ME*9OZOJgGQU2#+~=qnD@lxlNb=!$AtEO49w8fPho=AcU%1oYN=-$PuzGu ze>0rp`RwN~!7S^k2J?Oda!_L$%V}kxq zIWEw?q4iHRzKfooll9Ce%_hmR)~^vjyN8E%Wa_D}xjUrbQ0pHPh?%B4%tMTl^i5s3 K*{N&?rv4g^8;(W* literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strcmp.c b/2022/2/libft/ft_strcmp.c new file mode 100755 index 0000000..6157587 --- /dev/null +++ b/2022/2/libft/ft_strcmp.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strcmp.o b/2022/2/libft/ft_strcmp.o new file mode 100644 index 0000000000000000000000000000000000000000..71b3811e8be25442606f4f20bd9730684aaba109 GIT binary patch literal 1576 zcmbVL&1(}u6n~S(R!!?h=|QN6)Qc_Xkc1XgL?U7BfFB1T;H8vp+$K=-!Da)g5IjVL zB_KWem*gN=LKN&V#~ynT0=?)xpzm#FlF6{A{^0Gr_j{i^A0O?P&tr^%0)wY8vlI)k zu`ttfp_+qbNI*dZzeUgLt6c z$T%15)at>*L33UA!l%BUoDgTCGh*V=!23QIVD*M`6|7!=a}W%7f9TW5NiO1HcY7>~ zLu~-EPv>S>?as&G7|ow1XPpc~N=vm)WOLZb=O3pwc3u}YQ<*KE;h9u6o!v@rXR`ot z+=vv)6%>qs7_dHZ3QXE+?^mUReRu<`m1JwnOIMH4c?WqC!Wa5HyOI1H%dafP0*sjW zo)C{{(`V{$g?^%u}?VBjr{4`)H{w&ax^&Ok*E{Jn z@faR7e5ZIQ?NYVL>t3zydj1h`&wcN3x4d`YITcq;art!(Q)!PEjS@L&C&;P6Fku~i z#A(kkjDBGT${Hqp4|%*Em(IVBxl}WaqC@ppcT)LOf30H15o;s2ghKa1 zM_J~ZbJ4%**hPav&HS%2|E(U3x|vUYdapSY9mleu>VFNLG^fg^_dtm1P5d9(zeNV( mItrb!nNM}ivquWbvj1H&G{~}3<|b-U`F)vRnnq3(Gygweama=M literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strdup.c b/2022/2/libft/ft_strdup.c new file mode 100755 index 0000000..8a968e4 --- /dev/null +++ b/2022/2/libft/ft_strdup.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strdup.o b/2022/2/libft/ft_strdup.o new file mode 100644 index 0000000000000000000000000000000000000000..70c3fa527d39a18e80094b6b82e70c7cc9cd5023 GIT binary patch literal 1520 zcmbtS&1(};5TCcLtshN{A}Ca3Pf|r6NvKeIkd?6Zp`sw-UO+MBIK?ml|%x~s5v-{>fvme|wga8%+w_y@7 z3h>UD_}0+1AO=g2Rn0G|@!eF-gKpdIQKoJ8$*9Ib7i#g3hdw}Et)UFT7-|h!?f5Hl~7#yh}J5b^XTf8zFb{`v0 zm5dr6jxnt4e8$FsJvjUX8=1_yxw7#vd(BL(%9Ko*>128}c`Kd9;q#~_>IqaV0Ru#f zFczU>zM~5|A@(1Gs3*ko(&EY2n7oWQDam^}?!*%>jZAF8c#9PTL<{wuhabmL*|~_# z#IW%E6h54V*hSPtRFiFgv+8?WwTjHc*oUH1D3tS9|44J_pGkimkHpkCJ%g#I03fS- zMc>Jx^}UhZWzTa9j`ZES4|2=#9gw+d6=c3#EV?DcN@d@bc*i%ZzLS5d z_53}M!w&B5=CyuYZ~G_0=Y*C{|bgGxIJ f^G|6U&5ZOk|H=&d=Utz}e0cXnvGn&B{=)waVw|Ee literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_striteri.c b/2022/2/libft/ft_striteri.c new file mode 100755 index 0000000..488b17e --- /dev/null +++ b/2022/2/libft/ft_striteri.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_striteri.o b/2022/2/libft/ft_striteri.o new file mode 100644 index 0000000000000000000000000000000000000000..15e3a57081f3116b5f54880ff273a6ab0a1c73f0 GIT binary patch literal 1312 zcmbVL&ubGw6n?X=|QN6=}840lF)*9kVsfN2k}q{^&)i}w?C*!%I*YOp;(9r zOAvbV>i-}}j|Gw9MT&nxFNJ_!ya(!gn|bLn?5PjlzW2TNeQ$PWX5ahIpLs$6n}8>9 zfw&4Fy^Fk(rWGi_B-C_rraOP7PWE~_X`deZed_*^UB9pEC%WtR^rwPHs9QVL$*<)2 z{CCIi3*Fi4ftktB#L3h*_;A$zaq#myELN+J<-NrhwfnL(uS%*U%f<41aiLsJ7l%;{ z68#D~vcLmzL^U>HF@MX9ZHRYEAacW8M-nsE}_o zcNG4e=XFPNc5n)bw=(r~EfTMpmDog^CX6;!J&OjDn$r8pI9G zOt@n}y$MVJYBi2Q)mx25*u+}1WkQA9^)NO;eaqtYW?OAXt?e)}yP%@*ZJ@%9m9;2n zgu~S?oy?+=_G-+TP_cNp4;J%zF?|jbs*P~L#?KCB=<4rcgO2gC`Uj|`nML%h@%nss zxX0^rT)+nB%%S)-3o^OO^|3dOp85S!_Mz3d@8w?ESIDE8uD)mWk8I@N>R)1m{;LWT zZ2V$h^tQ!UG17aop6hvQlSEqmYXWH3(CLg^Jn|oX3N9UP0aH2hnBcL JWDXKn{~v3obBh1~ literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strjoin.c b/2022/2/libft/ft_strjoin.c new file mode 100755 index 0000000..cec1deb --- /dev/null +++ b/2022/2/libft/ft_strjoin.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strjoin.o b/2022/2/libft/ft_strjoin.o new file mode 100644 index 0000000000000000000000000000000000000000..029af384b58b9be7c2bf57b43e2521fbb5de2bcf GIT binary patch literal 1792 zcmbtU&1(}u6n~S}Cf2q_=|QN61;G!nOA_j(h(yBJMMOjhcrcXhx^2~blw<>~P&`D$ zu$Laa`zHwENrMH0J?%+y>_H)t93u3vhd_L9cP3f4=|vyRzIng*dml4zl9&A6od{zf zg~2TtSrP?kOpNwvZ<~f$n1QTT|Ebk?+giPP*yJvGn!Hb{6RYt)t8tgvyssIKX7jej zoUXTn3KCFT*IA7^3-2Ju>E1Ar)a&_f?_L`Dh zQj=;@NhMNCi5saDz$A8{;5vm184v;1AWRAqww&p_aIhB-fo;dx!b~)_ht7+L(;``; z&+WPR>qusHDw0En@4HDjiuYWG{=Vn;J;%RPcM^UNj(Y$m#=NvSB;px{bgvh*7I2+M zT-x%gss=Z104YgJF^`_jF&AhH!=C%du6W!85U8__;HA;noSwyT@vP>0c zxLC1tu@Q{${&4unv z@ +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_strlcat.o b/2022/2/libft/ft_strlcat.o new file mode 100644 index 0000000000000000000000000000000000000000..ae69c7471cf70b43fb31c9e1bcc11fea80ffd686 GIT binary patch literal 1648 zcmbtT-D?v;5Z}GlMr#{WQBdl`sUQlvBq4%UD3Ne>5%odHqtr`!wP3!u+dwK5g@||@ zf`3N;01+P#1&coAF)u<9gp~Rs^dS#{I&<00$9X}}f!W#l&HQHecJ`hd_wHzv5+#%@ zlcA?jLXuO%eKy!;$vl}OdG7w;&7Vo`Zgsd@-{o$;&6`^tB4S{6NqzPMX79a&g?k3% z>~s)tjRT0cNqqrOVD-_xHxTk5bkk@%r$-~)gSxb}U)?df$RCZlAAv$!uF=~+@8!Ee zh_<}@2SDm@`t`(n@>**eUD|}SVFJJ}eGvz4)2FV_Zy9ad_wvAkW75`VJW21%C$f^u zE$Nq69^|j+sSHc8l%7teGs)}eG@N4^R0ll*3MoV*)JIGSmA<;uQ!+rGJtVY|po?>{ zqi-R24scYI@3`EKCthi}`5EmSWFQbNSa+KII*f`=MNBddi6=+!pci0gK@(9$*2StL z>{8JbtVo8A+FF%9DI>Y~?Wn!OzTBOFuT8*TOu%)CYhY0a!ko>rFbjmiDf@Oq?QE-L zGGR3YVQZ!^2`e}bVZ~~>Y*hfORE5Q0X4f2H7N1K0Nu|zecC}{NVw13-g0-=_ZkuIm z(DHvaI*@T@God0`>8p9DuzEMjUxW?bZ&m@)a(O9_r9TT6x$5bhk@zKvkNnO-?2+P2e(5j#-*O$%#sB~S literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strlcpy.c b/2022/2/libft/ft_strlcpy.c new file mode 100755 index 0000000..9b82fdd --- /dev/null +++ b/2022/2/libft/ft_strlcpy.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strlcpy.o b/2022/2/libft/ft_strlcpy.o new file mode 100644 index 0000000000000000000000000000000000000000..096874367d359544e333e808072e5b4463ff515e GIT binary patch literal 1536 zcmbtS&1(};5TCcL{m`aH=|QQ71ws5=l2D;mkVsg&h!qiXl(I>;2Fw?m7f6KSAtHuc zyz0gO!gElt)KibS*^3ac7taRjOfr*fmi3|ovorIX`OUn2^IqAH9vDi2h=O}Ci3A1c z8WTS~bkh)nCCEDMA5QBy;k5VqPP=~Ow6nc^dq5RVYp)0O8&1bYbiYr~&r&Bl7y|0B zvxQ!^@2GEQKfzn0We?OOiO}n=UhLQd=dRuJ56HP=_v$O?wEC+38Ji&W@GJI=jc6PO z#~plu%}i#)yt?@~d(BL)SxGBtrV^>O#O+jy&I2%uYNDP(#VRmBbqNzu9Lt@oa6-L& z3aSxTt4s3>?=X1@aZ-|x^trzre`91~bH)d(ARt<(?=1W}iOSAIY+@M;&j;|~EW|FN z#-p0->g}5Li}`BP%EKfO*DH@m*O^QIPC7Ul$@{h53t&qnVN; d=3kyd$Ja7O&!HFIJtd#;`HSPqk;84r=pQ!#sA2#B literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strlen.c b/2022/2/libft/ft_strlen.c new file mode 100755 index 0000000..0e7d7dc --- /dev/null +++ b/2022/2/libft/ft_strlen.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strlen.o b/2022/2/libft/ft_strlen.o new file mode 100644 index 0000000000000000000000000000000000000000..8ffc1e64554c6e190eabeeb7777b7e56ff4caa29 GIT binary patch literal 1256 zcmbVLJxc>Y5S@+j`&$HsSj0+2U6P<677__(QizBUun|4u#egP}yA@Or1w{>M{54`3 zu(0({2mu@I13HuJ#AAt#19LO)&Agqx-McGmeJvmaunAa!U&Jgx)kntbbR7Di7t*QH zd#ZFw*UeUPYX z#2jbJIa44HY-NMo_dJl9Vm|K_kSi3GBk`E#J!NN(G(Iex$`iME;<)M@r0X2p(#h>+ zT|4jau>Z#pO6iO`j3we4H{V}lz9(*<#DusuCUiV9Fhf&6g$265|LW&ZOKV2Z{l@e8 zo8cPI=eURk&bf!;y&w2;v)95}Cpz7~-ySqD_ho*oJJ?5Sn)+w0U(%6-so%x|{ZDaj z&@rbsI<9dyM%pLqnQt|lB%ky^+p9kTdN9%*nR;5+ygQO?>iJ^?e5UCpGmKd){k3j9 KY<4yhQ~v`uQCm3x literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strmapi.c b/2022/2/libft/ft_strmapi.c new file mode 100755 index 0000000..ac725ae --- /dev/null +++ b/2022/2/libft/ft_strmapi.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strmapi.o b/2022/2/libft/ft_strmapi.o new file mode 100644 index 0000000000000000000000000000000000000000..8ad9a0f9ed610d4fbd5824f6d894d9a035eecb79 GIT binary patch literal 1592 zcmbtS&ubG=5T2LRR%@F^@u0Ma1x2dpl7xB*C@W#@BG!Y_o26{x))uo#*leH`ib7Pn z1fhS2XOW&HAQ-%@7wI1mVMQ+m4?PHRX8Wc|)-8e^c<-C}=GSB9J=gEuNeBTf0&YRy zVisUO(bu(5)nF1PVA1ftJv5p>XAN(2*YFyCNAHr`Xm0L8V|<77@2`kx>FDnSL>SGs zIMh8oz~BHHc?=1DJZkA(qvVI-!k>B%Qy+Y!S_{bT8LfrDcr%ki^u4cMr}t$m+0?rt zn)9;V*g50^L-?P<2LwiIY5(&_m@gFa%Iy68#Vbm7PR*)WC6~#~Wp3nhFoMrh@SMPd z0gwRECXPi&n`d-RI>fUFAlB1jdSdM4HaagMKO=qb2yds-uM>sIQN5W=yu~2tI|``& z2<-LZ{K=RNr7-a903Y^5?gE~4Op%L6@UY@8*ImapYinw0z>sR$s(@{l%hi&snUzR0 zqVv0VAU6kinkDm!krJ>fGYRz)o4N$`h*6Q+#W7?K{!SO)BblTBqq>LtQo8sKCU-)dm;O8lYw#?5A7(Le@gNQLz0&LuMV+)&-x7dqr0b+Ety~bNB$px CBD2l_ literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strnstr.c b/2022/2/libft/ft_strnstr.c new file mode 100755 index 0000000..02c8a18 --- /dev/null +++ b/2022/2/libft/ft_strnstr.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strnstr.o b/2022/2/libft/ft_strnstr.o new file mode 100644 index 0000000000000000000000000000000000000000..3723de4bc383fc6426cee5b2d405d445321e996b GIT binary patch literal 1480 zcmbVL&ubGw6n>k=)*oq;iU*}d(vuZ*NJ0x$p+v&iJ*Wp^L4?w5(`^fyr0hd)b+7I_#+r-oE#~_r7n2nb}YL<%^hMfHDKt z;i6I~Ks$Dk=f`Ot5^xJFv-!(x*1Kl2)-jt_`;7Ofd&UP8OrK+i56|NbJ}}Hiy#r$2 zw+4uJOrw)Lf#X)~XQMuV)$Sp=UDjQ~;QFR2KF&M&Sl=UuD8M6u@?DVFTOtJYc12x$IOB zt5k)<@VFj(!Y;j+^Y}YnL6hi>t>4q|#YUYZ7@`hvy(` zbzf?H2@}Gm6d>ceJ}7Y=etNg2 +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/ft_strrchr.o b/2022/2/libft/ft_strrchr.o new file mode 100644 index 0000000000000000000000000000000000000000..a1b113be6521f431369dd672f6a28d941b8eaab0 GIT binary patch literal 1336 zcmbVL&ubG=5T3V`uG|3fG}NzjAf#r-2H1acDg(3{SrZ_@2!PaT-d%s1aR@8wN$;J$cn2?1;Zp2Ath zC_v3R%j=W04)bsg*1i58ufIR)caFV*JM#MO$xk;U!no9PGcj;8FGwdXk=lpwao8D+ z%Tx5ko1pf$bl@J_hr`wH9s68!Z1nk7RR+4}W+EEm?5NownDDk--C&~}r>3XNtk-KqwH;h#mWE{Tt zW!T)@j{PX)TUPM$M(EzmE-C<3;t4P)jq* z=y~Jw`M1M8KA+(mXr`&>OV#uo4yOJ! zHt2s?%6#$kfwZb9V^A7p=cTMb0!lMQ&hL Oq)#<*XUaTHO#OdCc7AvO literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_strtrim.c b/2022/2/libft/ft_strtrim.c new file mode 100755 index 0000000..1f6bb08 --- /dev/null +++ b/2022/2/libft/ft_strtrim.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_strtrim.o b/2022/2/libft/ft_strtrim.o new file mode 100644 index 0000000000000000000000000000000000000000..fd99dae0054831d7372ade6db47ea0f46fe9729e GIT binary patch literal 2008 zcmbtU&1(}u6rW9NQ)_GM$3dxuJ!u79l2D=4B9St7kt!(UW{KN%YpeMvn_Xzd;9*s| z7Ik;Gui>x!1h#!*7dnAyJj>9lKO} z&}y}w70s{pel)eH)5*rnA=`H=-4wtARx5qbVqd`1Za|~Y$~TGm*~&X)EzGJaQ0F7B zI06+{pyIM@&h>NqtP6=1*b99h_g8(9xobQh+B zL3c0Hy~kf*_kx2(`8}44&5_xenJIC6_GaR|7@d%!QdEpZViS=|u^46{_$)-=L%?7} zLPRL~o(jArPv&pxB-kMdk8TrTbwn5)4EJw<@(f_eNVjmgdUWJ@XlAG{GzS)*ZW?i* zSGctGFWdS%hy#7YrLC{HdW5W z_b?Z?Ho&65Bftk}(MaYD-O!iQl1i3yNp(rllgpW8PBVzAq|{_e%aD!{Nh_&TRwXxB ze4KqBa1&k^lE@N-U`OT@X9te+y6*;XUN@0)YiUDSfE}uH_a%PPwUiZmbc>ji4c<+cab59AY=)Z(E>e>24 zasdR4`LF)?zA%3T*iSq^|JJyU_s{n!Q1COi!F~EK>%R`RVc?*7oB_eQ`1~*j(gHB% z5Bje#U=@vg6!f15UAOzIvVqFX7w->!xj(F0q6)Y{`-RdhXD)T9YAD* afs-isC^+k5pzG#8&VH^bpD!MR{(k_hj7i=A literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_substr.c b/2022/2/libft/ft_substr.c new file mode 100755 index 0000000..aae0351 --- /dev/null +++ b/2022/2/libft/ft_substr.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_substr.o b/2022/2/libft/ft_substr.o new file mode 100644 index 0000000000000000000000000000000000000000..17251a26a519a1033b71bfe1330ba4b50f4beadd GIT binary patch literal 1608 zcmbtT&ubG=5T2LDw${c*5iHch3ZfBpNn!MN~xCqts2@S};G#{(x2}3K4PH zOOHMKM~KHz!C)`u;Gy8PLL?p{u5-<&#>V8#g-_xqQ)pDH!)z$VJN|y@M+Expksdp5AdqaSyv{bjz zBEZuQ)Em3jg?7BAbeX4g)kS6Bnnf66)^vCMV%D5_3oq-=7X)i{=GFyWb(J3K_rMv) z!d`o+p>#;Lea=_t1Qfix9o5r%D%(S?*Rh(?!FHWRrE7lnG)$ooYku(GuJ`dhEa&qJ zQfm30c2UaA%NaQ%Wz*UD^tEi3^a0}N68aHztb!P@I$^>Xzl#~3;tBTb0kDlEo131P z+{WY?#L3A%(c{+fjFe*D1vAF~mo($lAFT_rxCnH48{sD(o zd&P1JmTk(#VeCh?Su!e6)=Q;o5w3DgnhE*O!@ijToMtC*iQ_Rm$p8 zep5d)6K=%o!|-LqN%LR%8RU|tcux#{6aB@vE^yIboC}x`v8bW*QWO|bdmFI{^pS4} z?`h5tzn7RFmiSh{CzXczk2wE&zijXf^B-a+YJV@dpx6`bkGO&_@TlI@Y=`&XrVH9J iblOpvf0W~Rj97~IPmQ3z&-w)B!@DQS4(FHt!v6)PcD(BV literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_swap.c b/2022/2/libft/ft_swap.c new file mode 100755 index 0000000..851ca4e --- /dev/null +++ b/2022/2/libft/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_tolower.c b/2022/2/libft/ft_tolower.c new file mode 100755 index 0000000..44cdea6 --- /dev/null +++ b/2022/2/libft/ft_tolower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_tolower.o b/2022/2/libft/ft_tolower.o new file mode 100644 index 0000000000000000000000000000000000000000..73d1c974301a33c84e57b335a1c68c70047e9d40 GIT binary patch literal 1248 zcmbVL%}T>S5T4Xp|D}otMGx_$f-Y^bARZ)Asvg9HAc|OOtZ4;pQ<4>1K|Kh9c=0iO z48a%i;sbau=uEQ{;}S0p%+Aa=^UVyq$z5@KBVic8V!#^wM2rHwM?k9!TQCemu($R2 z@p#j@zv)=FgLod^CGU$J^QqV=y}@Rouxie4?(8j?*=3OxSu>Z(Eobt%93-)aiQ0>b z1&{#al`s}V#XNRGC5-D`Fj{G2dbqFu8Iv=Jlah4p`e^zgQ5Z?>V?hANp42x9pI>pw zo|qdL#lrCj&NHDZ%hJ7YuN+TQA_4a`m6JeA8jA4Sb!ne~@TC{nGxns@k|0iPX@fZN zeGnD5UUwRZHC*Wkysjl*+Ldz^*BY0i>A6kElWh>5b72eTtX%c%x)VZ7e^B#F5u^;8PqCv#h zYm1ocL;dyk7&BkrOaEp|SW7*1{tIFxD}f15oqvEC`me08B5;n?qLT_AKudcvpYgca tM0uwJ<+ytS45Fns()rX^e>hpsSQ$7v{~OUSRfhlo literal 0 HcmV?d00001 diff --git a/2022/2/libft/ft_toupper.c b/2022/2/libft/ft_toupper.c new file mode 100755 index 0000000..e6e06b3 --- /dev/null +++ b/2022/2/libft/ft_toupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/ft_toupper.o b/2022/2/libft/ft_toupper.o new file mode 100644 index 0000000000000000000000000000000000000000..5577081cb8063e204c90ecc6ff5cccc6369c4015 GIT binary patch literal 1248 zcmbVL%}T>S5T4X({YS-vQV;Q@f-Y^bARZ)Asvg9HAbL=2tkHs|Dai^|P!ED2UVIE6 zL-0j<@d3OCbf(#fafufPW@qM``DTXQ>}@@L zJl%#5w_)vW5YLuG2)U=}AZ6bu9(bu3xD5ym=*BzK0vgYY@J3X$z-ueCFG(6HoiMlSd}qRiDz5U>tR6ILoMb|=g(n+-toWuMdVV?0%}rt{$Km^9%Ur4pX9fbLBiK- ztC-87{(5_inXm7qf3rteOFeb|D`F%ok%>>8e}EbKudKKta%yVPDTNQ9r9GL?c-m~D sbm%~-bx(jnwDd+gpZe-=M-)rVpQa!o3XYL+^wRikRd^m(Mvl(^2Elw)^#A|> literal 0 HcmV?d00001 diff --git a/2022/2/libft/gnl/Makefile b/2022/2/libft/gnl/Makefile new file mode 100755 index 0000000..42150c1 --- /dev/null +++ b/2022/2/libft/gnl/Makefile @@ -0,0 +1,42 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2023/11/04 08:03:00 by tomoron #+# #+# # +# Updated: 2023/12/04 09:49:24 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +NAME = gnl.a + +CC = gcc + +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/2022/2/libft/gnl/get_next_line_bonus.c b/2022/2/libft/gnl/get_next_line_bonus.c new file mode 100755 index 0000000..658e574 --- /dev/null +++ b/2022/2/libft/gnl/get_next_line_bonus.c @@ -0,0 +1,113 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/gnl/get_next_line_bonus.h b/2022/2/libft/gnl/get_next_line_bonus.h new file mode 100755 index 0000000..28facee --- /dev/null +++ b/2022/2/libft/gnl/get_next_line_bonus.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/2022/2/libft/gnl/get_next_line_bonus.o b/2022/2/libft/gnl/get_next_line_bonus.o new file mode 100644 index 0000000000000000000000000000000000000000..f3d3a74d07597994b3805a8dccfb044bc6f47e18 GIT binary patch literal 3208 zcmb_eUuauZ7(X}dTCM$)jfs;DjEG~-?vj=Y?HD7Y-1Q>e2x4Buk=`UXYiOE`n|q-v z28Xf2>V|B zYCGN)4tj{|bo5QFB}sjw?wkN{2V43MKay&{R;%tX=b8V=&rk3qH=Pi>-l$K!SJ~U! zqh(9?Qj~Da5BxyJCbXN=Up&qWX&>SBxqpvW*{#y%oMuDYpTMBr5?G-8EB2fB=+m8 zajEK!#4Pl!gJ(s>DNmD4yzRlMR&9}b3o4ZwC7|B4rB3B&kJ6%}%fm{Ytj70=Ij!aV zPAfVHuLZ>Unv?)eN8)mtevbv>@Y)bIBk-0eEI%`03pAoM!m>yJ z;z)m9L&9FA(a%0}2wpq{Uq1v#Q}>JiKH=EU2N6<8_?^)F5e?u!3!L8tVV}|H7l&Op z?R3dpv(v>w$xLU;C8wfhS;oodO)Fio4a-*J2aQObO`M6NtJj9APMjh z8WJBD{S%IVN#NmqE(YwM2*gjX#=yko#aY1p@60LCQY{P?6I zX4t$g0GSWIknnnnFvN_542bkU6~Lg%{Bp+oB=w-_c6dXA4BNg;I7$`lQJ6M`e|TTv z{b$G)F~j~*TndSN5B$}?&wq`Ge)qQ|60HeG+#evBU*2E8+;I6( +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/libft/gnl/get_next_line_utils_bonus.o b/2022/2/libft/gnl/get_next_line_utils_bonus.o new file mode 100644 index 0000000000000000000000000000000000000000..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ip#Mbn{mi$)CkN G{r?4HW@9e^ literal 0 HcmV?d00001 diff --git a/2022/2/libft/gnl/gnl.a b/2022/2/libft/gnl/gnl.a new file mode 100644 index 0000000000000000000000000000000000000000..79c258257ec2dc498a2778ff735d974cc5780a64 GIT binary patch literal 34956 zcmd^oe{kH#b>H_uQUWPbfMhD7Vp={$lthXm2~v~dTo`jaafj1!J?zBxsBTkh(pJN$H3d<&AUUy1r%BAFY=dU#%qhn| z(3TlpW>~YI&+dEQ+uOS@aiHPIRd(ikyZiRNw{L%Zci-FH@7^styGMEs-oIi?y4tll zQ5$xD)9L%RwF^eqiXaGX4}vAgT2>g5c(f>gTSNLEt|-%0b{i53dUXKA-He z&)$nc@Ega2p!eSdLI3F>7&=?~ynyuTXMfZ=JTesZ^+bKWo!!w;e*nn-{(*tcXZw4j zgNzN2^bbazJqNo-DzVYXM0$n>pXnQk2=5>5?LW{jL4)1dKiIi{p!>imlMnPomLu5p z_4JSS4-G0f#u@G&8SU%r9y!32p6-F3&VzkpodbOab2t|<$|Nh$uodCik^ZQ!bKgMs z;8T?}K{Px@`wtAFY%D{C6@e9W2gNYzjFXY+K(2FepIh{pUo2*B(BYt&m|AmF4En*o zo~Js82fBOu4h{|U_KldzF$LOh%S0R0(HHFcYi{t_eEA{Ex%@crl#G;vElynd}9UmzIT-*1MyDYsjpn{rFud-8(eRN534I?7@Gboj<>Q1!Q5ty-NP7wp9?mR^bK@x?mO7If28~AKIZ(>xetS! zb#|4`;ew-{_5X@ z1Pv<={oCpR>)>VqyBbeb+atbS=zY2TuKT3$^y&8seLK=!=hN>+BHyo!i-hnRVYo)% z%i&W_rB^t!@$)7L-$A-A^BV+IZrDaXJ^A`=N0K?AXZyNNz%l4LgzC|^iBJb(OdIg& z@tTTqg7F`N^?YOc-8*D(Pd7fM7q6)ZkukwcaBZ;4j_H%<)A@2fS3I0Ok3l@2y*N33 zF?epxO!gu%OD!!Yv*+_OMMfr{E~X~Oi@}SfLiS>K?438wq(BDa=LNrzT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IPfLaI-DHt8|24ulN!Ks)<%gTJ SUi_=|uYe?7Uo)Cd*Z+Tz@SMs3 literal 0 HcmV?d00001 diff --git a/2022/2/libft/libft.a b/2022/2/libft/libft.a new file mode 100644 index 0000000000000000000000000000000000000000..310cc180e65e5b58f7970ede0403814b87423c28 GIT binary patch literal 91092 zcmeIb3w)f%bszcx)Ps^p0kY+oiY03qQ5Gp$B>0d7+O)EIti6#Xhjz?_Nu&@Df+S=R zK!9C~R746X#DrUf32$!PGOcgQ-Z;6uPE)H%qq1%+fs`!LZk)i5W3#DJ_cE=(VpLaJ2PkI%$#|A=bU+d%QttA^zOdz+O?^2)8ToY z+y76c)@|6(>7sO98%5DaqUfq^QMBZ}<(XLb!4LlS@BU>t;XAmAf6Cm%%XQJp+(^2&4E28LMrlaV$b5Zm=Nc*`z zjG`0EqUa0A|I}O*o%whaeFgTPZj7R{i2tppqv-$Xh@$_tB8vV8;D7&Y)Y9@?)N=Kb zsO9=>)NCg3T?-}SG{6r~CBT5>h{ksNHHkP536oIAa zUKB}admM~R2lCqod;Fru>BVH`2fY+56R9;nM56ER>;1&`;eqbnzTHCuJNibXa-={z zg`RvauIPMDYZ;a%>Iw`0cGOiaVxo7e}^^FWk`ML)NhI;AhAMG9(%-i)2bE|*ORhoqNE|FLGh`x_Gn((w@Z8YA z(35O5)^L7!*g5-0w~zJ-UA;qj^kFuR2-D=KtcPrCPbzRHqF5?_)hSoYDUp2nDctguz{>z{N&RigR@yhIYW~L=Ok(p_GKH8kh z&6;!Zf$Pk<^uV8+b9F9;-j#pApm*gLef#kXl2Y-m?8Mf&Y+)*Ua=JC!GL>za%oZ|p z8nf+%$?=(v?9prsKz_z+OSx@2@P!kgY%IGeGxzk>C%*Ig>#r9V1AngVbD0Z|zZ8Aw z!3W=$TKS=mY+aRFw{gw7HS1FAJJxUPxO@G2mJ7lxO5wQ@58_0vQOhJ@W?Iy5bqC=n zrsb)RMJ;>VTi&(g>cvM8cr&1UXuib1`>${Rh1Lg`Ue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+W=3Jr8`IZ`s8-H?h*aMfe(r35gCmn zL>Ka9STBJvg!%9kfiP@duZicqll85*r^4!23X8w+9ZXu!vVCsG!y1(V|H?89>@ffL zBAk3FWAZ&n7J3FtO&NPm(HFnp^&!#5sm{vJ4(W?3JEe@-KGs%=(?pCkh; zLF4soKjIp`!K>xXylg#gFFi1g%7EiqQ7avK{2$g|k_=d;6*3TGI!B04Rl6^@y%%d* zvZ7T}2He~Dz1h|7r@J1zDs+=!yZhF9Ve1843x_Mc|Mng3wB%U-Ke>o%@gw`N^xeaHHZ9e1x^ zFZ?WpbQhBM%f0~P{koN%@6cvEG~^fYxb4U16%Ep_8<7o6dXbcdu9Bf#@MVVWUAP7C zYBJ*vjc@UUW+qqGS={yr>pKh^9_b&w?2_bDHVz{1qM=-28yK8= zC5^@B-VT}%IjbUmO5u#J-CiK+0B+@Je4H{ew4*!M9j*E9{>H;cw7h18?|PD~vbFOr zMI^5xZpiDB_W#9ak`>>qFn_i;(+p)*z4#`p{5ED@hW`WfcqYuB<66Q(nerLMsU_ x< +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* 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/2022/2/main.c b/2022/2/main.c new file mode 100644 index 0000000..4dbef12 --- /dev/null +++ b/2022/2/main.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +long int resolve(char *input); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + return(res); +} + +int main(void) +{ + char *input; + + input = get_input("input"); + if(!input) + { + printf("file read error\n"); + return(1); + } + printf("result: %ld\n", resolve(input)); + free(input); + return(0); +} diff --git a/2022/2/part1.c b/2022/2/part1.c new file mode 100644 index 0000000..e6ae887 --- /dev/null +++ b/2022/2/part1.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* res.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 16:02:52 by tomoron #+# #+# */ +/* Updated: 2024/07/17 21:13:02 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft/libft.h" + +int get_score(int a, int b) +{ + if(a == b) + return(b + 3); + if((a == 1 && b == 2) || (a == 2 && b == 3) || (a == 3 && b == 1)) + return(b + 6); + return(b); + +} + +long int resolve(char *input) +{ + char **split; + int i; + long int res; + + split = ft_split(input, '\n'); + i = 0; + res = 0; + while(split[i]) + { + printf("round : %s\n", split[i]); + switch(split[i][0]) + { + case 'A': + split[i][0] = 1; + break; + case 'B': + split[i][0] = 2; + break; + case 'C': + split[i][0] = 3; + break; + } + switch(split[i][2]) + { + case 'X': + split[i][2] = 1; + break; + case 'Y': + split[i][2] = 2; + break; + case 'Z': + split[i][2] = 3; + break; + } + res += get_score(split[i][0], split[i][2]); + printf("%d vs %d\n", split[i][0], split[i][2]); + printf("round : %d, score : %d\n", i + 1, get_score(split[i][0], split[i][2])); + i++; + } + return(res); +} diff --git a/2022/2/part2.c b/2022/2/part2.c new file mode 100644 index 0000000..814c73c --- /dev/null +++ b/2022/2/part2.c @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* res.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 16:02:52 by tomoron #+# #+# */ +/* Updated: 2024/07/17 22:58:17 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "libft/libft.h" + +int get_score(int a, int b) +{ + if(b == 1) + { + if(a == 1) + return(3); + if(a == 2) + return(1); + if(a == 3) + return(2); + } + + if(b == 2) + return(a + 3); + + if(a == 1) + return(2 + 6); + if(a == 2) + return(3 + 6); + return(1 + 6); + +} + +long int resolve(char *input) +{ + char **split; + int i; + long int res; + + split = ft_split(input, '\n'); + i = 0; + res = 0; + while(split[i]) + { + printf("round : %s\n", split[i]); + switch(split[i][0]) + { + case 'A': + split[i][0] = 1; + break; + case 'B': + split[i][0] = 2; + break; + case 'C': + split[i][0] = 3; + break; + } + switch(split[i][2]) + { + case 'X': + split[i][2] = 1; + break; + case 'Y': + split[i][2] = 2; + break; + case 'Z': + split[i][2] = 3; + break; + } + res += get_score(split[i][0], split[i][2]); + printf("%d vs %d\n", split[i][0], split[i][2]); + printf("round : %d, score : %d\n", i + 1, get_score(split[i][0], split[i][2])); + i++; + } + return(res); +} diff --git a/2022/3/Makefile b/2022/3/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/3/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/3/main.c b/2022/3/main.c new file mode 100644 index 0000000..b716777 --- /dev/null +++ b/2022/3/main.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + return(0); +} diff --git a/2022/3/part1.c b/2022/3/part1.c new file mode 100644 index 0000000..442a8bd --- /dev/null +++ b/2022/3/part1.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/07/18 00:06:18 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static long int char_value(char c) +{ + if(c >= 'A' && c <= 'Z') + return((c - 'A') + 27); + return((c - 'a') + 1); +} + +static long int resline(char *line) +{ + char *ptr; + char *found; + int len; + int i; + + len = ft_strlen(line); + ptr = line + (len / 2); + i = 0; + while(i < len /2) + { + found = ft_strchr(ptr, line[i]); + if(found) + return(char_value(*found)); + i++; + } + return(0); +} + +long int resolve_part1(char *input, char **split) +{ + (void)input; + long int res; + int i; + + res = 0; + i = 0; + while(split[i]) + { + res += resline(split[i]); + i++; + } + return(res); +} diff --git a/2022/3/part2.c b/2022/3/part2.c new file mode 100644 index 0000000..e084a0c --- /dev/null +++ b/2022/3/part2.c @@ -0,0 +1,54 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/28 23:10:24 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static long int char_value(char c) +{ + if(c >= 'A' && c <= 'Z') + return((c - 'A') + 27); + return((c - 'a') + 1); +} + +static long int reslines(char *e1, char *e2, char *e3) +{ + int i; + + i = 0; + while(e1[i]) + { + if(ft_strchr(e2, e1[i]) && ft_strchr(e3, e1[i])) + return(char_value(e1[i])); + i++; + } + return(0); +} + +long int resolve_part2(char *input, char **split) +{ + (void)input; + long int res; + int i; + + res = 0; + i = 0; + while(split[i]) + { + int tmp; + tmp = reslines(split[i], split[i + 1], split[i + 2]); + res += tmp; + i += 3; + } + return(res); +} diff --git a/2022/3/test b/2022/3/test new file mode 100644 index 0000000..f17e726 --- /dev/null +++ b/2022/3/test @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw diff --git a/2022/4/Makefile b/2022/4/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/4/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/4/main.c b/2022/4/main.c new file mode 100644 index 0000000..2db4d73 --- /dev/null +++ b/2022/4/main.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + return(0); +} diff --git a/2022/4/part1.c b/2022/4/part1.c new file mode 100644 index 0000000..ef553cb --- /dev/null +++ b/2022/4/part1.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/28 23:37:04 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +void parse_range(int *start, int *end, char *range) +{ + *start = ft_atoi(range); + while(*range && *range != '-') + range++; + *end = ft_atoi(range); +} + +int range_contains_next(char **ranges) +{ + int r1_start; + int r1_end; + int r2_start; + int r2_end; + + if(!ranges) + return(0); + parse_range(&r1_start, &r1_end, ranges[0]); + parse_range(&r2_start, &r2_end, ranges[1]); + return((r1_start <= r2_start && r1_end <= r2_end) || (r2_start <= r1_start && r2_end <= r1_end)); +} + +long int resolve_part1(char *input, char **split) +{ + (void)input; + (void)split; + int i; + int res; + + i = 0; + res = 0; + while(split[i]) + { + if(range_contains_next(ft_split(split[i], ','))) + res++; + i++; + } + return(res); +} diff --git a/2022/4/part2.c b/2022/4/part2.c new file mode 100644 index 0000000..8a1e928 --- /dev/null +++ b/2022/4/part2.c @@ -0,0 +1,61 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/28 23:46:30 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static void parse_range(int *start, int *end, char *range) +{ + *start = ft_atoi(range); + while(*range && *range != '-') + range++; + if(*range) + range++; + *end = ft_atoi(range); +} + +static int range_contains_next(char **ranges) +{ + int r1_start; + int r1_end; + int r2_start; + int r2_end; + + if(!ranges) + return(0); + parse_range(&r1_start, &r1_end, ranges[0]); + parse_range(&r2_start, &r2_end, ranges[1]); + if(r1_end < r2_start) + return(0); + if(r2_end < r1_start) + return(0); + return(1); +} + +long int resolve_part2(char *input, char **split) +{ + (void)input; + (void)split; + int i; + int res; + + i = 0; + res = 0; + while(split[i]) + { + if(range_contains_next(ft_split(split[i], ','))) + res++; + i++; + } + return(res); +} diff --git a/2022/4/test b/2022/4/test new file mode 100644 index 0000000..9f9e9cf --- /dev/null +++ b/2022/4/test @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 diff --git a/2022/5/Makefile b/2022/5/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/5/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/5/main.c b/2022/5/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/2022/5/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/2022/5/part1.c b/2022/5/part1.c new file mode 100644 index 0000000..e652079 --- /dev/null +++ b/2022/5/part1.c @@ -0,0 +1,210 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 02:51:51 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include "libft/libft.h" +#include "structs.h" + +static t_stack_list *get_next_stack_node(t_stack_list **stacks, t_stack_list *cur) +{ + if(!*stacks) + *stacks = ft_calloc(1, sizeof(t_stack_list)); + if(!cur) + return(*stacks); + if(!cur->next) + cur->next = ft_calloc(1, sizeof(t_stack_list)); + return(cur->next); +} + +static void add_crate(t_stack_list *node, char letter) +{ + t_crate *bottom; + t_crate *tmp; + + bottom = node->crate; + while(bottom && bottom->prev) + bottom = bottom->prev; + + tmp = ft_calloc(1, sizeof(t_crate)); + tmp->letter = letter; + tmp->prev = 0; + + if(bottom) + bottom->prev = tmp; + else + node->crate = tmp; +} + +static void get_line_crates(char *line, t_stack_list **stacks) +{ + int i; + int len; + t_stack_list *cur; + + i = 1; + len = ft_strlen(line); + cur = get_next_stack_node(stacks, 0); + while(i < len) + { + if(line[i] >= 'A' && line[i] <= 'Z') + add_crate(cur, line[i]); + i += 4; + cur = get_next_stack_node(stacks, cur); + } +} + +static t_stack_list *parse_input_stacks(char **split) +{ + t_stack_list *stacks; + int i; + + i = 0; + stacks = 0; + while(split[i] && ft_strlen(split[i]) > 2 && !(split[i][1] >= '0' && split[i][1] <= '9')) + { + get_line_crates(split[i], &stacks); + i++; + } + return(stacks); +} + +static t_instruction parse_instruction(char *line) +{ + t_instruction res; + + res.nb = 1; + res.from = 1; + res.to = 1; + if(line && ft_strlen(line) >= 18) + { + line += 5; + res.nb = ft_atoi(line); + while(*line >= '0' && *line <='9') + line++; + line += 6; + res.from = ft_atoi(line); + while(*line >= '0' && *line <='9') + line++; + line += 4; + res.to = ft_atoi(line); + } + return(res); +} + +static t_stack_list *stack_from_index(t_stack_list *stacks, int index) +{ + int i; + + i = 1; + while(stacks->next && i < index) + { + stacks = stacks->next; + i++; + } + return(stacks); +} + +static void print_stack(t_stack_list *stack) +{ + if(!stack->crate) + return; + printf("%c", stack->crate->letter); + return; + t_crate *tmp; + + tmp = stack->crate; + while(tmp) + { + printf("%c",tmp->letter); + tmp = tmp->prev; + } + printf("\n"); +} + +static void print_result(t_stack_list *stacks) +{ + while(stacks) + { + print_stack(stacks); + stacks = stacks->next; + } + printf("\n"); +} + +static void exec_instruction(int rep, t_stack_list *from, t_stack_list *to) +{ + int i; + t_crate *tmp; + + i = 0; + while(i < rep) + { + i++; + if(!from->crate) + break; + tmp = from->crate; + from->crate = from->crate->prev; + tmp->prev = to->crate; + to->crate = tmp; + } +} + +static void do_all_instructions(char **split,t_stack_list *stacks) +{ + int i; + t_instruction instr; + + (void)stacks; + i = 0; + while(split[i] && (split[i][0] == ' ' || split[i][0] == '[')) + i++; + while(split[i]) + { + instr = parse_instruction(split[i]); + exec_instruction(instr.nb, stack_from_index(stacks, instr.from), stack_from_index(stacks, instr.to)); + i++; + } +} + +static void free_stacks(t_stack_list *stacks) +{ + void *tmp; + + while(stacks) + { + while(stacks->crate) + { + tmp = stacks->crate->prev; + free(stacks->crate); + stacks->crate = tmp; + } + tmp = stacks->next; + free(stacks); + stacks = tmp; + } +} + + +long int resolve_part1(char *input, char **split) +{ + (void)input; + (void)split; + t_stack_list *stacks; + + stacks = parse_input_stacks(split); + do_all_instructions(split, stacks); + print_result(stacks); + free_stacks(stacks); + return(0); +} diff --git a/2022/5/part2.c b/2022/5/part2.c new file mode 100644 index 0000000..8066c81 --- /dev/null +++ b/2022/5/part2.c @@ -0,0 +1,211 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 02:54:08 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include "libft/libft.h" +#include "structs.h" + +static t_stack_list *get_next_stack_node(t_stack_list **stacks, t_stack_list *cur) +{ + if(!*stacks) + *stacks = ft_calloc(1, sizeof(t_stack_list)); + if(!cur) + return(*stacks); + if(!cur->next) + cur->next = ft_calloc(1, sizeof(t_stack_list)); + return(cur->next); +} + +static void add_crate(t_stack_list *node, char letter) +{ + t_crate *bottom; + t_crate *tmp; + + bottom = node->crate; + while(bottom && bottom->prev) + bottom = bottom->prev; + + tmp = ft_calloc(1, sizeof(t_crate)); + tmp->letter = letter; + tmp->prev = 0; + + if(bottom) + bottom->prev = tmp; + else + node->crate = tmp; +} + +static void get_line_crates(char *line, t_stack_list **stacks) +{ + int i; + int len; + t_stack_list *cur; + + i = 1; + len = ft_strlen(line); + cur = get_next_stack_node(stacks, 0); + while(i < len) + { + if(line[i] >= 'A' && line[i] <= 'Z') + add_crate(cur, line[i]); + i += 4; + cur = get_next_stack_node(stacks, cur); + } +} + +static t_stack_list *parse_input_stacks(char **split) +{ + t_stack_list *stacks; + int i; + + i = 0; + stacks = 0; + while(split[i] && ft_strlen(split[i]) > 2 && !(split[i][1] >= '0' && split[i][1] <= '9')) + { + get_line_crates(split[i], &stacks); + i++; + } + return(stacks); +} + +static t_instruction parse_instruction(char *line) +{ + t_instruction res; + + res.nb = 1; + res.from = 1; + res.to = 1; + if(line && ft_strlen(line) >= 18) + { + line += 5; + res.nb = ft_atoi(line); + while(*line >= '0' && *line <='9') + line++; + line += 6; + res.from = ft_atoi(line); + while(*line >= '0' && *line <='9') + line++; + line += 4; + res.to = ft_atoi(line); + } + return(res); +} + +static t_stack_list *stack_from_index(t_stack_list *stacks, int index) +{ + int i; + + i = 1; + while(stacks->next && i < index) + { + stacks = stacks->next; + i++; + } + return(stacks); +} + +static void print_stack(t_stack_list *stack) +{ + if(!stack->crate) + return; + printf("%c", stack->crate->letter); + return; + t_crate *tmp; + + tmp = stack->crate; + while(tmp) + { + printf("%c",tmp->letter); + tmp = tmp->prev; + } + printf("\n"); +} + +static void print_result(t_stack_list *stacks) +{ + while(stacks) + { + print_stack(stacks); + stacks = stacks->next; + } + printf("\n"); +} + +static void exec_instruction(int rep, t_stack_list *from, t_stack_list *to) +{ + int i; + t_crate *tmp; + t_crate *top; + + i = 1; + top = from->crate; + tmp = top; + while(i < rep && tmp->prev) + { + tmp = tmp->prev; + i++; + } + from->crate = tmp->prev; + tmp->prev = to->crate; + to->crate = top; +} + +static void do_all_instructions(char **split,t_stack_list *stacks) +{ + int i; + t_instruction instr; + + (void)stacks; + i = 0; + while(split[i] && (split[i][0] == ' ' || split[i][0] == '[')) + i++; + while(split[i]) + { + instr = parse_instruction(split[i]); + exec_instruction(instr.nb, stack_from_index(stacks, instr.from), stack_from_index(stacks, instr.to)); + i++; + } +} + +static void free_stacks(t_stack_list *stacks) +{ + void *tmp; + + while(stacks) + { + while(stacks->crate) + { + tmp = stacks->crate->prev; + free(stacks->crate); + stacks->crate = tmp; + } + tmp = stacks->next; + free(stacks); + stacks = tmp; + } +} + + +long int resolve_part2(char *input, char **split) +{ + (void)input; + (void)split; + t_stack_list *stacks; + + stacks = parse_input_stacks(split); + do_all_instructions(split, stacks); + print_result(stacks); + free_stacks(stacks); + return(0); +} diff --git a/2022/5/structs.h b/2022/5/structs.h new file mode 100644 index 0000000..cbebe2d --- /dev/null +++ b/2022/5/structs.h @@ -0,0 +1,23 @@ +#ifndef STRUCTS_H +# define STRUCTS_H + +typedef struct s_crate +{ + char letter; + struct s_crate *prev; +} t_crate; + +typedef struct s_stack_list +{ + t_crate *crate; + struct s_stack_list *next; +} t_stack_list; + +typedef struct s_instruction +{ + int nb; + int from; + int to; +} t_instruction; + +#endif diff --git a/2022/5/test b/2022/5/test new file mode 100644 index 0000000..84933bb --- /dev/null +++ b/2022/5/test @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 diff --git a/2022/6/Makefile b/2022/6/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/6/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/6/main.c b/2022/6/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/2022/6/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/2022/6/part1.c b/2022/6/part1.c new file mode 100644 index 0000000..0e85c5f --- /dev/null +++ b/2022/6/part1.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 14:10:49 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static int check_repeat(char *str) +{ + int i; + int j; + + i = 0; + while(str[i]) + { + j = 0; + while(str[j]) + { + if(i != j && str[i] == str[j]) + return(1); + j++; + } + i++; + } + return(0); +} + +long int resolve_part1(char *input, char **split) +{ + (void)split; + char hist[5]; + int i; + + i = 0; + hist[4] = 0; + while(input[i]) + { + ft_memcpy(hist, input + i, 4); + if(!check_repeat(hist)) + return(i + 4); + i++; + } + return(0); +} diff --git a/2022/6/part2.c b/2022/6/part2.c new file mode 100644 index 0000000..ea94115 --- /dev/null +++ b/2022/6/part2.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 14:10:19 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static int check_repeat(char *str) +{ + int i; + int j; + + i = 0; + while(str[i]) + { + j = 0; + while(str[j]) + { + if(i != j && str[i] == str[j]) + return(1); + j++; + } + i++; + } + return(0); +} + +long int resolve_part2(char *input, char **split) +{ + (void)split; + char hist[15]; + int i; + + i = 0; + hist[14] = 0; + while(input[i]) + { + ft_memcpy(hist, input + i, 14); + if(!check_repeat(hist)) + return(i + 14); + i++; + } + return(0); +} diff --git a/2022/6/test b/2022/6/test new file mode 100644 index 0000000..e1d0a43 --- /dev/null +++ b/2022/6/test @@ -0,0 +1 @@ +zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw diff --git a/2022/7/Makefile b/2022/7/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/7/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/7/main.c b/2022/7/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/2022/7/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/2022/7/part1.c b/2022/7/part1.c new file mode 100644 index 0000000..4f4ba69 --- /dev/null +++ b/2022/7/part1.c @@ -0,0 +1,198 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 20:32:22 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" +#include "structs.h" + +static t_directory *create_directory(char *name, t_directory *parent, void *next) +{ + t_directory *res; + + res = malloc(sizeof(t_directory)); + res->is_dir = 1; + res->name = name; + res->next = next; + res->elements = 0; + res->parent = parent; + return(res); +} + +static char *get_word(char *input) +{ + int len; + char *res; + + len = 0; + while(input[len] != ' ' && input[len]) + len++; + res = malloc(len + 1); + res[len] = 0; + ft_memcpy(res, input, len); + return(res); +} + +static void change_directory(char *arg, t_directory *root, t_directory **current) +{ + t_directory *tmp; + + if(!ft_strcmp(arg, "/")) + *current = root; + else if (!ft_strcmp(arg, "..")) + { + if((*current)->parent) + *current = (*current)->parent; + } + else + { + tmp = (*current)->elements; + while(tmp) + { + if(tmp->is_dir && !ft_strcmp(tmp->name, arg)) + { + *current = tmp; + break; + } + tmp = tmp->next; + } + } +} + +static t_file *create_file(char *name, int size, t_file *next) +{ + t_file *res; + + res = malloc(sizeof(t_file)); + res->is_dir = 0; + res->name = name; + res->size = size; + res->next = next; + return(res); +} + +static char **list(char **input, t_directory *dir) +{ + char *first_arg; + char *second_arg; + + (void)dir; + while(*input && **input != '$') + { + first_arg = get_word(*input); + second_arg = *input + ft_strlen(first_arg) + 1; + if(!ft_strcmp(first_arg, "dir")) + dir->elements = create_directory(second_arg, dir, dir->elements); + else + dir->elements = create_file(second_arg, ft_atoi(first_arg), dir->elements); + free(first_arg); + input++; + } + return(input); +} + +static char **exec_command(char **input, t_directory *root, t_directory **current) +{ + char *cmd; + + if(**input != '$') + return(input + 1); + cmd = get_word(*input + 2); + if(!ft_strcmp(cmd, "cd")) + { + change_directory(*input + 5 , root, current); + free(cmd); + return(input + 1); + } + else if (!ft_strcmp(cmd, "ls")) + { + free(cmd); + return(list(input + 1, *current)); + } + free(cmd); + return(input + 1); +} + +static t_directory *parse_input(char **input) +{ + t_directory *root; + t_directory *current; + + root = create_directory("/", 0, 0); + current = root; + while(*input) + { + input = exec_command(input, root, ¤t); + } + return(root); +} + +static long int dir_size(t_directory *dir,int depth, long int *res) +{ + long int tmp_dir_size; + long int size; + t_file *tmp; + + tmp = dir->elements; + size = 0; + while(tmp) + { + if(tmp->is_dir) + { + tmp_dir_size = dir_size((t_directory *)tmp, depth + 1, res); + if(tmp_dir_size <= 100000) + { + *res += tmp_dir_size; + } + size += tmp_dir_size; + } + else + size += tmp->size; + tmp = tmp->next; + } + return(size); +} + +static void free_dir(t_directory *dir) +{ + void *tmp; + + while(dir->elements) + { + if(((t_directory *)dir->elements)->is_dir) + { + tmp = ((t_directory*)dir->elements)->next; + free_dir(dir->elements); + dir->elements = tmp; + } + else + { + tmp = ((t_directory*)dir->elements)->next; + free(dir->elements); + dir->elements = tmp; + } + } + free(dir); +} + +long int resolve_part1(char *input, char **split) +{ + (void)input; + t_directory *dir; + long int res; + + res = 0; + dir = parse_input(split); + dir_size(dir, 0, &res); + free_dir(dir); + return(res); +} diff --git a/2022/7/part2.c b/2022/7/part2.c new file mode 100644 index 0000000..86e2c56 --- /dev/null +++ b/2022/7/part2.c @@ -0,0 +1,198 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 20:32:14 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" +#include "structs.h" + +static t_directory *create_directory(char *name, t_directory *parent, void *next) +{ + t_directory *res; + + res = malloc(sizeof(t_directory)); + res->is_dir = 1; + res->name = name; + res->next = next; + res->elements = 0; + res->parent = parent; + return(res); +} + +static char *get_word(char *input) +{ + int len; + char *res; + + len = 0; + while(input[len] != ' ' && input[len]) + len++; + res = malloc(len + 1); + res[len] = 0; + ft_memcpy(res, input, len); + return(res); +} + +static void change_directory(char *arg, t_directory *root, t_directory **current) +{ + t_directory *tmp; + + if(!ft_strcmp(arg, "/")) + *current = root; + else if (!ft_strcmp(arg, "..")) + { + if((*current)->parent) + *current = (*current)->parent; + } + else + { + tmp = (*current)->elements; + while(tmp) + { + if(tmp->is_dir && !ft_strcmp(tmp->name, arg)) + { + *current = tmp; + break; + } + tmp = tmp->next; + } + } +} + +static t_file *create_file(char *name, int size, t_file *next) +{ + t_file *res; + + res = malloc(sizeof(t_file)); + res->is_dir = 0; + res->name = name; + res->size = size; + res->next = next; + return(res); +} + +static char **list(char **input, t_directory *dir) +{ + char *first_arg; + char *second_arg; + + (void)dir; + while(*input && **input != '$') + { + first_arg = get_word(*input); + second_arg = *input + ft_strlen(first_arg) + 1; + if(!ft_strcmp(first_arg, "dir")) + dir->elements = create_directory(second_arg, dir, dir->elements); + else + dir->elements = create_file(second_arg, ft_atoi(first_arg), dir->elements); + free(first_arg); + input++; + } + return(input); +} + +static char **exec_command(char **input, t_directory *root, t_directory **current) +{ + char *cmd; + + if(**input != '$') + return(input + 1); + cmd = get_word(*input + 2); + if(!ft_strcmp(cmd, "cd")) + { + change_directory(*input + 5 , root, current); + free(cmd); + return(input + 1); + } + else if (!ft_strcmp(cmd, "ls")) + { + free(cmd); + return(list(input + 1, *current)); + } + free(cmd); + return(input + 1); +} + +static t_directory *parse_input(char **input) +{ + t_directory *root; + t_directory *current; + + root = create_directory("/", 0, 0); + current = root; + while(*input) + { + input = exec_command(input, root, ¤t); + } + return(root); +} + +static long int dir_size(t_directory *dir, long int *res , int space_needed) +{ + long int tmp_dir_size; + long int size; + t_file *tmp; + + tmp = dir->elements; + size = 0; + while(tmp) + { + if(tmp->is_dir) + { + tmp_dir_size = dir_size((t_directory *)tmp, res, space_needed); + if(res && tmp_dir_size >= space_needed && (tmp_dir_size < *res || *res == 0)) + *res = tmp_dir_size; + size += tmp_dir_size; + } + else + size += tmp->size; + tmp = tmp->next; + } + return(size); +} + +static void free_dir(t_directory *dir) +{ + void *tmp; + + while(dir->elements) + { + if(((t_directory *)dir->elements)->is_dir) + { + tmp = ((t_directory*)dir->elements)->next; + free_dir(dir->elements); + dir->elements = tmp; + } + else + { + tmp = ((t_directory*)dir->elements)->next; + free(dir->elements); + dir->elements = tmp; + } + } + free(dir); +} + +long int resolve_part2(char *input, char **split) +{ + (void)input; + t_directory *dir; + long int res; + int free_space; + + res = 0; + dir = parse_input(split); + free_space = 70000000 - dir_size(dir, 0, 0); + dir_size(dir, &res, 30000000 - free_space); + free_dir(dir); + return(res); +} diff --git a/2022/7/structs.h b/2022/7/structs.h new file mode 100644 index 0000000..f4ab9eb --- /dev/null +++ b/2022/7/structs.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* structs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/10/29 14:20:26 by tomoron #+# #+# */ +/* Updated: 2024/10/29 18:10:36 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef STRUCTS_H +# define STRUCTS_H + +typedef struct s_file +{ + int is_dir; + void *next; + char *name; + int size; +} t_file; + +typedef struct s_directory +{ + int is_dir; + void *next; + char *name; + void *elements; + struct s_directory *parent; +} t_directory; + +#endif diff --git a/2022/7/test b/2022/7/test new file mode 100644 index 0000000..09a921e --- /dev/null +++ b/2022/7/test @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k diff --git a/2022/8/Makefile b/2022/8/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/8/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/8/main.c b/2022/8/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/2022/8/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/2022/8/part1.c b/2022/8/part1.c new file mode 100644 index 0000000..3d38cec --- /dev/null +++ b/2022/8/part1.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 21:11:32 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static int check_dir(char **map, int pos[2], int dir[2]) +{ + char height; + + height = map[pos[1]][pos[0]]; + pos[0] += dir[0]; + pos[1] += dir[1]; + while(pos[1] >= 0 && map[pos[1]] && pos[0] >= 0 && map[pos[1]][pos[0]]) + { + if(map[pos[1]][pos[0]] >= height) + return(0); + pos[0] += dir[0]; + pos[1] += dir[1]; + } + return(1); +} + +long int resolve_part1(char *input, char **split) +{ + (void)input; + int x; + int y; + int res; + + res = 0; + y = 0; + while(split[y]) + { + x = 0; + while(split[y][x]) + { + if(check_dir(split, (int[2]){x, y},(int[2]){1,0}) || + check_dir(split, (int[2]){x, y},(int[2]){-1,0}) || + check_dir(split, (int[2]){x, y},(int[2]){0,1}) || + check_dir(split, (int[2]){x, y},(int[2]){0,-1})) + res++; + x++; + } + y++; + } + return(res); +} diff --git a/2022/8/part2.c b/2022/8/part2.c new file mode 100644 index 0000000..86f44f9 --- /dev/null +++ b/2022/8/part2.c @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/10/29 21:21:44 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static int check_dir(char **map, int pos[2], int dir[2]) +{ + char height; + int dist; + + height = map[pos[1]][pos[0]]; + pos[0] += dir[0]; + pos[1] += dir[1]; + dist = 1; + while(pos[1] >= 0 && map[pos[1]] && pos[0] >= 0 && map[pos[1]][pos[0]]) + { + if(map[pos[1]][pos[0]] >= height) + return(dist); + pos[0] += dir[0]; + pos[1] += dir[1]; + dist++; + } + return(dist - 1); +} + +static int get_score(char **map,int x, int y) +{ + return(check_dir(map, (int[2]){x, y},(int[2]){1,0}) * + check_dir(map, (int[2]){x, y},(int[2]){-1,0}) * + check_dir(map, (int[2]){x, y},(int[2]){0,1}) * + check_dir(map, (int[2]){x, y},(int[2]){0,-1})); +} + +long int resolve_part2(char *input, char **split) +{ + (void)input; + int x; + int y; + int res; + int score; + + res = 0; + y = 0; + while(split[y]) + { + x = 0; + while(split[y][x]) + { + score = get_score(split, x, y); + if(score > res) + res = score; + x++; + } + y++; + } + return(res); +} diff --git a/2022/8/test b/2022/8/test new file mode 100644 index 0000000..16d6fbd --- /dev/null +++ b/2022/8/test @@ -0,0 +1,5 @@ +30373 +25512 +65332 +33549 +35390 diff --git a/2022/9/Makefile b/2022/9/Makefile new file mode 100644 index 0000000..09374f6 --- /dev/null +++ b/2022/9/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/11/01 13:13:44 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g -lm -Wno-unused-command-line-argument + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2022/9/main.c b/2022/9/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/2022/9/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/2022/9/part1.c b/2022/9/part1.c new file mode 100644 index 0000000..b63f903 --- /dev/null +++ b/2022/9/part1.c @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/11/04 13:32:41 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include +#include "libft/libft.h" +#include "structs.h" + +t_instruction get_instruction(char *line) +{ + t_instruction res; + + res.dir[0] = 0; + res.dir[1] = 0; + res.rep = 0; + if(!line[0]) + return(res); + + if(line[0] == 'U') + res.dir[1] = -1; + if(line[0] == 'D') + res.dir[1] = 1; + if(line[0] == 'L') + res.dir[0] = -1; + if(line[0] == 'R') + res.dir[0] = 1; + res.rep = ft_atoi(line + 2); + return(res); +} + +static void move_tail(int tail[2], int head[2]) +{ + int dist_up; + int dist_side; + + dist_up = tail[0] - head[0]; + dist_side = tail[1] - head[1]; + if(dist_up == -2) + tail[0] = head[0] - 1; + if(dist_up == 2) + tail[0] = head[0] + 1; + if(dist_side == -2) + tail[1] = head[1] - 1; + if(dist_side == 2) + tail[1] = head[1] + 1; +} + +long int resolve_part1(char *input, char **split) +{ + (void)input; + int i; + int head[2]; + int tail[2]; + t_instruction instr; + + i = 0; + ft_bzero(head, sizeof(int) * 2); + ft_bzero(tail, sizeof(int) * 2); + while(split[i]) + { + instr = get_instruction(split[i]); + while(instr.rep > 0) + { + head[0] += instr.dir[0]; + head[1] += instr.dir[1]; + printf("%d, %d\n", head[0], head[1]); + move_tail(tail, head); + instr.rep--; + } + i++; + } + return(0); +} diff --git a/2022/9/part2.c b/2022/9/part2.c new file mode 100644 index 0000000..35dff46 --- /dev/null +++ b/2022/9/part2.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/07/17 23:18:02 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +long int resolve_part2(char *input, char **split) +{ + (void)input; + (void)split; + return(0); +} diff --git a/2022/9/structs.h b/2022/9/structs.h new file mode 100644 index 0000000..a5414d8 --- /dev/null +++ b/2022/9/structs.h @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* structs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/01 12:50:02 by tomoron #+# #+# */ +/* Updated: 2024/11/01 13:01:52 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef STRUCTS_H +# define STRUCTS_H + +#include + +typedef struct s_instruction +{ + int dir[2]; + int rep; +} t_instruction; +#endif diff --git a/2022/9/test b/2022/9/test new file mode 100644 index 0000000..9874df2 --- /dev/null +++ b/2022/9/test @@ -0,0 +1,8 @@ +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 diff --git a/2022/Makefile b/2022/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2022/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2024/1/Makefile b/2024/1/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2024/1/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2024/1/main.c b/2024/1/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/2024/1/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/2024/1/part1.c b/2024/1/part1.c new file mode 100644 index 0000000..9bdaf67 --- /dev/null +++ b/2024/1/part1.c @@ -0,0 +1,98 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/12/01 12:36:03 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static void ft_sort(int *list, int len) +{ + int i; + int j; + int tmp; + + i = 0; + while(i < len - 1) + { + j = 0; + while(j < len - 1) + { + if(list[j] > list[j + 1]) + { + tmp = list[j]; + list[j] = list[j + 1]; + list[j + 1] = tmp; + } + j++; + } + i++; + } +} + +static void get_numbers(int *left, int *right, char **split) +{ + int i; + int j; + + i = 0; + while(*split) + { + j = 0; + *(left + i) = ft_atoi(*split); + while((*split)[j] >= '0' && (*split)[j] <= '9') + j++; + while((*split)[j] == ' ') + j++; + *(right + i) = ft_atoi(*split + j); + i++; + split++; + } +} + +long int resolve_part1(char *input, char **split) +{ + int len; + int *left; + int *right; + long int res; + int i; + int tmp; + + len = 0; + i = 0; + while(split[len]) + len++; + left = malloc(sizeof(int) * len); + right = malloc(sizeof(int) * len); + if(!left || !right) + { + free(left); + free(right); + return(-1); + } + get_numbers(left, right, split); + ft_sort(left, len); + ft_sort(right, len); + res = 0; + while(i < len) + { + tmp = left[i] - right[i]; + if(tmp < 0) + tmp *= -1; + res += tmp; + i++; + } + free(left); + free(right); + (void)input; + return(res); +} diff --git a/2024/1/part2.c b/2024/1/part2.c new file mode 100644 index 0000000..099ab50 --- /dev/null +++ b/2024/1/part2.c @@ -0,0 +1,86 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/12/01 12:36:05 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static void get_numbers(int *left, int *right, char **split) +{ + int i; + int j; + + i = 0; + while(*split) + { + j = 0; + *(left + i) = ft_atoi(*split); + while((*split)[j] >= '0' && (*split)[j] <= '9') + j++; + while((*split)[j] == ' ') + j++; + *(right + i) = ft_atoi(*split + j); + i++; + split++; + } +} + +int count_nb(int nb, int *list, int len) +{ + int i; + int res; + + i = 0; + res = 0; + while(i < len) + { + if(list[i] == nb) + res++; + i++; + } + return(res); +} + +long int resolve_part2(char *input, char **split) +{ + int len; + int *left; + int *right; + long int res; + int i; + int tmp; + + len = 0; + i = 0; + while(split[len]) + len++; + left = malloc(sizeof(int) * len); + right = malloc(sizeof(int) * len); + if(!left || !right) + { + free(left); + free(right); + return(-1); + } + get_numbers(left, right, split); + res = 0; + while(i < len) + { + tmp = count_nb(left[i], right, len); + res += left[i] * tmp; + i++; + } + free(left); + free(right); + (void)input; + return(res); +} diff --git a/2024/1/test b/2024/1/test new file mode 100644 index 0000000..b8af9ad --- /dev/null +++ b/2024/1/test @@ -0,0 +1,6 @@ +3 4 +4 3 +2 5 +1 3 +3 9 +3 3 diff --git a/2024/2/Makefile b/2024/2/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2024/2/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/2024/2/main.c b/2024/2/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/2024/2/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/2024/2/part1.c b/2024/2/part1.c new file mode 100644 index 0000000..0748761 --- /dev/null +++ b/2024/2/part1.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/12/02 11:22:15 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static void skip_nbr(char **line) +{ + while(ft_isdigit(**line)) + (*line)++; + while(**line == ' ') + (*line)++; +} + +static long int check_line(char *line) +{ + int left; + int right; + int asc; + + left = ft_atoi(line); + skip_nbr(&line); + asc = -1; + while(*line) + { + right = ft_atoi(line); + skip_nbr(&line); + if(right == left || (left > right && asc == 1) || (left < right && asc == 0)) + return(0); + if(left > right) + asc = 0; + if(left < right) + asc = 1; + if(left - right > 3 || left - right < -3) + return(0); + left = right; + } + return(1); +} + +long int resolve_part1(char *input, char **split) +{ + (void)input; + long int res; + int i; + + i = 0; + res = 0; + while(split[i]) + { + res += check_line(split[i]); + i++; + } + return(res); +} diff --git a/2024/2/part2.c b/2024/2/part2.c new file mode 100644 index 0000000..ea7ddce --- /dev/null +++ b/2024/2/part2.c @@ -0,0 +1,105 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/12/02 12:20:40 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +static void skip_nbr(char **line) +{ + while(ft_isdigit(**line)) + (*line)++; + while(**line == ' ') + (*line)++; +} + +static long int check_line(char *line, int ignore) +{ + int left; + int right; + int asc; + int i; + + if(ignore == 0) + skip_nbr(&line); + left = ft_atoi(line); + skip_nbr(&line); + asc = -1; + i = 1; + while(*line) + { + if(i == ignore) + skip_nbr(&line); + if(!*line) + break; + right = ft_atoi(line); + skip_nbr(&line); + if(right == left || (left > right && asc == 1) || (left < right && asc == 0)) + return(0); + if(left > right) + asc = 0; + if(left < right) + asc = 1; + if(left - right > 3 || left - right < -3) + return(0); + left = right; + i++; + } + return(1); +} + +static int count_char(char *str, char c) +{ + int res; + + res = 0; + while(*str) + { + if(*str == c) + res++; + str++; + } + return(res); +} + +long int resolve_part2(char *input, char **split) +{ + (void)input; + long int res; + int i; + int j; + int len; + + i = 0; + res = 0; + while(split[i]) + { + if(check_line(split[i], -1)) + res++; + else + { + len = count_char(split[i], ' ') + 1; + j = 0; + while(j < len) + { + if(check_line(split[i], j)) + { + res++; + break; + } + j++; + } + } + i++; + } + return(res); +} diff --git a/2024/2/test b/2024/2/test new file mode 100644 index 0000000..3f0b9ef --- /dev/null +++ b/2024/2/test @@ -0,0 +1,7 @@ +7 6 4 2 1 +1 2 7 8 9 +9 7 6 2 1 +1 3 2 4 5 +8 6 4 4 1 +1 3 6 7 9 +1 1 5 6 7 9 diff --git a/2024/Makefile b/2024/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/2024/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..808a501 --- /dev/null +++ b/Makefile @@ -0,0 +1,69 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tomoron +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # +# Updated: 2024/10/29 20:43:12 by tomoron ### ########.fr # +# # +# **************************************************************************** # + +SRCS = main.c\ + part1.c\ + part2.c + +OBJS = $(SRCS:.c=.o) + +FLAGS = -Wextra -Werror -Wall -g + +LIB = libft/libft.a + +all: $(LIB) a.out test + cp test cur_input + ./a.out + +f: $(LIB) a.out input + cp input cur_input + ./a.out + +test: + touch test + +input: + touch input + +cp: + cp part1.c part2.c + sed -i 's/resolve_part1/resolve_part2/g' part2.c + +$(LIB): libft + make -C libft + +libft: + cp -r ~/Desktop/aoc/libft . + +main.c: + cp ~/Desktop/aoc/main.c . + +part1.c: + cp ~/Desktop/aoc/part1.c . + +part2.c: + cp ~/Desktop/aoc/part2.c . + +a.out: main.c $(OBJS) $(LIB) + clang $(FLAGS) $(OBJS) $(LIB) + +clean: + rm -rf $(OBJS) + rm -rf libft + +fclean: clean + rm -rf a.out + +.c.o: + clang $(FLAGS) -c $< -o $@ + +.PHONY: t all clean fclean cp diff --git a/libft/Makefile b/libft/Makefile new file mode 100755 index 0000000..1a9a683 --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,101 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# 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 + +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/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100755 index 0000000..3b0badd --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100755 index 0000000..8e328c6 --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_calloc.c b/libft/ft_calloc.c new file mode 100755 index 0000000..9314306 --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_free_str_arr.c b/libft/ft_free_str_arr.c new file mode 100755 index 0000000..c4bd417 --- /dev/null +++ b/libft/ft_free_str_arr.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_isalnum.c b/libft/ft_isalnum.c new file mode 100755 index 0000000..a1fe540 --- /dev/null +++ b/libft/ft_isalnum.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100755 index 0000000..6a8b074 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100755 index 0000000..5b85ccc --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100755 index 0000000..fe77533 --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100755 index 0000000..7b5ceb6 --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100755 index 0000000..e076598 --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstadd_back.c b/libft/ft_lstadd_back.c new file mode 100755 index 0000000..3aa43d7 --- /dev/null +++ b/libft/ft_lstadd_back.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstadd_front.c b/libft/ft_lstadd_front.c new file mode 100755 index 0000000..4e6a56a --- /dev/null +++ b/libft/ft_lstadd_front.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstclear.c b/libft/ft_lstclear.c new file mode 100755 index 0000000..fc79c03 --- /dev/null +++ b/libft/ft_lstclear.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstdelone.c b/libft/ft_lstdelone.c new file mode 100755 index 0000000..80bbcfb --- /dev/null +++ b/libft/ft_lstdelone.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstiter.c b/libft/ft_lstiter.c new file mode 100755 index 0000000..0430cfd --- /dev/null +++ b/libft/ft_lstiter.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstlast.c b/libft/ft_lstlast.c new file mode 100755 index 0000000..6fa8909 --- /dev/null +++ b/libft/ft_lstlast.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstmap.c b/libft/ft_lstmap.c new file mode 100755 index 0000000..7715da4 --- /dev/null +++ b/libft/ft_lstmap.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstnew.c b/libft/ft_lstnew.c new file mode 100755 index 0000000..8e78fb4 --- /dev/null +++ b/libft/ft_lstnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_lstsize.c b/libft/ft_lstsize.c new file mode 100755 index 0000000..4fdfadf --- /dev/null +++ b/libft/ft_lstsize.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100755 index 0000000..1691bba --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100755 index 0000000..dc57e59 --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100755 index 0000000..7e1aced --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100755 index 0000000..2f1c08b --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_memset.c b/libft/ft_memset.c new file mode 100755 index 0000000..a8408d0 --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/Makefile b/libft/ft_printf/Makefile new file mode 100755 index 0000000..e691c80 --- /dev/null +++ b/libft/ft_printf/Makefile @@ -0,0 +1,52 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# 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/libft/ft_printf/ft_convert.c b/libft/ft_printf/ft_convert.c new file mode 100755 index 0000000..61cc97c --- /dev/null +++ b/libft/ft_printf/ft_convert.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_isdigit.c b/libft/ft_printf/ft_isdigit.c new file mode 100755 index 0000000..fe77533 --- /dev/null +++ b/libft/ft_printf/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_parse_arg.c b/libft/ft_printf/ft_parse_arg.c new file mode 100755 index 0000000..09af1e2 --- /dev/null +++ b/libft/ft_printf/ft_parse_arg.c @@ -0,0 +1,89 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_print_hex_ptr.c b/libft/ft_printf/ft_print_hex_ptr.c new file mode 100755 index 0000000..c957134 --- /dev/null +++ b/libft/ft_printf/ft_print_hex_ptr.c @@ -0,0 +1,97 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_print_int.c b/libft/ft_printf/ft_print_int.c new file mode 100755 index 0000000..b710860 --- /dev/null +++ b/libft/ft_printf/ft_print_int.c @@ -0,0 +1,99 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_print_unsigned_int.c b/libft/ft_printf/ft_print_unsigned_int.c new file mode 100755 index 0000000..e324164 --- /dev/null +++ b/libft/ft_printf/ft_print_unsigned_int.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_printf.c b/libft/ft_printf/ft_printf.c new file mode 100755 index 0000000..19a0964 --- /dev/null +++ b/libft/ft_printf/ft_printf.c @@ -0,0 +1,67 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_printf.h b/libft/ft_printf/ft_printf.h new file mode 100755 index 0000000..dfffefe --- /dev/null +++ b/libft/ft_printf/ft_printf.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_protected_atoi.c b/libft/ft_printf/ft_protected_atoi.c new file mode 100755 index 0000000..09dcfc9 --- /dev/null +++ b/libft/ft_printf/ft_protected_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_putchar.c b/libft/ft_printf/ft_putchar.c new file mode 100755 index 0000000..84bbe70 --- /dev/null +++ b/libft/ft_printf/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_putstr.c b/libft/ft_printf/ft_putstr.c new file mode 100755 index 0000000..c742ffc --- /dev/null +++ b/libft/ft_printf/ft_putstr.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_strlen.c b/libft/ft_printf/ft_strlen.c new file mode 100755 index 0000000..e9f507f --- /dev/null +++ b/libft/ft_printf/ft_strlen.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_printf/ft_write_str_part.c b/libft/ft_printf/ft_write_str_part.c new file mode 100755 index 0000000..3dc57ff --- /dev/null +++ b/libft/ft_printf/ft_write_str_part.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100755 index 0000000..f63e488 --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c new file mode 100755 index 0000000..8d6b9c5 --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c new file mode 100755 index 0000000..6a3a8a1 --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100755 index 0000000..f2b20e2 --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_set_color.c b/libft/ft_set_color.c new file mode 100755 index 0000000..f44b6e6 --- /dev/null +++ b/libft/ft_set_color.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_split.c b/libft/ft_split.c new file mode 100755 index 0000000..000e1b4 --- /dev/null +++ b/libft/ft_split.c @@ -0,0 +1,73 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_split_set.c b/libft/ft_split_set.c new file mode 100755 index 0000000..023f0ce --- /dev/null +++ b/libft/ft_split_set.c @@ -0,0 +1,84 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strchr.c b/libft/ft_strchr.c new file mode 100755 index 0000000..978f990 --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strcmp.c b/libft/ft_strcmp.c new file mode 100755 index 0000000..6157587 --- /dev/null +++ b/libft/ft_strcmp.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strdup.c b/libft/ft_strdup.c new file mode 100755 index 0000000..8a968e4 --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_striteri.c b/libft/ft_striteri.c new file mode 100755 index 0000000..488b17e --- /dev/null +++ b/libft/ft_striteri.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strjoin.c b/libft/ft_strjoin.c new file mode 100755 index 0000000..cec1deb --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100755 index 0000000..2444604 --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strlcpy.c b/libft/ft_strlcpy.c new file mode 100755 index 0000000..9b82fdd --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100755 index 0000000..0e7d7dc --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100755 index 0000000..ac725ae --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100755 index 0000000..02c8a18 --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strrchr.c b/libft/ft_strrchr.c new file mode 100755 index 0000000..56fae39 --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_strtrim.c b/libft/ft_strtrim.c new file mode 100755 index 0000000..1f6bb08 --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_substr.c b/libft/ft_substr.c new file mode 100755 index 0000000..aae0351 --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_swap.c b/libft/ft_swap.c new file mode 100755 index 0000000..851ca4e --- /dev/null +++ b/libft/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100755 index 0000000..44cdea6 --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/ft_toupper.c b/libft/ft_toupper.c new file mode 100755 index 0000000..e6e06b3 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/gnl/Makefile b/libft/gnl/Makefile new file mode 100755 index 0000000..4fe8f9d --- /dev/null +++ b/libft/gnl/Makefile @@ -0,0 +1,42 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# 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/libft/gnl/get_next_line_bonus.c b/libft/gnl/get_next_line_bonus.c new file mode 100755 index 0000000..658e574 --- /dev/null +++ b/libft/gnl/get_next_line_bonus.c @@ -0,0 +1,113 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/gnl/get_next_line_bonus.h b/libft/gnl/get_next_line_bonus.h new file mode 100755 index 0000000..28facee --- /dev/null +++ b/libft/gnl/get_next_line_bonus.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/gnl/get_next_line_utils_bonus.c b/libft/gnl/get_next_line_utils_bonus.c new file mode 100755 index 0000000..1233d60 --- /dev/null +++ b/libft/gnl/get_next_line_utils_bonus.c @@ -0,0 +1,119 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/libft/libft.h b/libft/libft.h new file mode 100755 index 0000000..87fa052 --- /dev/null +++ b/libft/libft.h @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 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/main.c b/main.c new file mode 100644 index 0000000..4f9b609 --- /dev/null +++ b/main.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split); +long int resolve_part2(char *input, char **split); + +char *get_input(char *file) +{ + int fd; + int rd_len; + char buffer[1000]; + int len; + char *res; + + fd = open(file, O_RDONLY); + len = 0; + if(fd < 0) + return(0); + rd_len = -1; + while(rd_len) + { + rd_len = read(fd, buffer, 1000); + len+= rd_len; + } + close(fd); + res = malloc(len + 1); + if(!res) + return(0); + fd = open(file, O_RDONLY); + if(fd < 0) + return(0); + rd_len = read(fd,res, len); + res[len] = 0; + close(fd); + return(res); +} + +int main(void) +{ + char *input; + char *input_cpy; + char **split; + + input = get_input("cur_input"); + input_cpy = ft_strdup(input); + if(!input || !input_cpy) + { + fprintf(stderr, "file read error\n"); + return(1); + } + split = ft_split(input, '\n'); + if(!split) + return(1); + printf("result part 1: %ld\n", resolve_part1(input, split)); + ft_free_str_arr(split); + split = ft_split(input_cpy, '\n'); + if(!split) + return(1); + printf("result part 2: %ld\n", resolve_part2(input, split)); + ft_free_str_arr(split); + free(input); + free(input_cpy); + return(0); +} diff --git a/part1.c b/part1.c new file mode 100644 index 0000000..a9826c9 --- /dev/null +++ b/part1.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part1.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/07/17 23:17:57 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +long int resolve_part1(char *input, char **split) +{ + (void)input; + (void)split; + return(0); +} diff --git a/part2.c b/part2.c new file mode 100644 index 0000000..35dff46 --- /dev/null +++ b/part2.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* part2.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/17 23:03:36 by tomoron #+# #+# */ +/* Updated: 2024/07/17 23:18:02 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "libft/libft.h" + +long int resolve_part2(char *input, char **split) +{ + (void)input; + (void)split; + return(0); +}