diff --git a/include/cub3d.h b/include/cub3d.h new file mode 100644 index 0000000..a92b16c --- /dev/null +++ b/include/cub3d.h @@ -0,0 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* cub3d.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/08/14 18:13:07 by jteissie #+# #+# */ +/* Updated: 2024/08/14 18:13:26 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CUB3D_H +# define CUB3D_H +#endif diff --git a/libft/.gitignore b/libft/.gitignore new file mode 100644 index 0000000..2e9577e --- /dev/null +++ b/libft/.gitignore @@ -0,0 +1,17 @@ +**/*.out +**/*.a +**/*.o +**/.vscode +**/.gch +**/main +**/*.swp +srcs/libftTester/ +./libtest/ +srcs/libft.h +srcs/libft.h.gch +srcs/libft.so +srcs/Makefile +srcs/libft.a +libft-war-machine/* +test_dump.c +test_main.c diff --git a/libft/Makefile b/libft/Makefile index 50827d3..d84040e 100644 --- a/libft/Makefile +++ b/libft/Makefile @@ -83,4 +83,4 @@ fclean: clean re: fclean all -.PHONY: all clean fclean re bonus +.PHONY: all clean fclean re bonus \ No newline at end of file diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c new file mode 100644 index 0000000..b1bad40 --- /dev/null +++ b/libft/ft_atoi.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/22 19:28:31 by jteissie #+# #+# */ +/* Updated: 2024/03/23 16:31:12 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(const char *nptr) +{ + int i; + int result; + int minus; + + i = 0; + result = 0; + minus = 0; + while (nptr[i] == ' ' || (nptr[i] >= 9 && nptr[i] <= 13)) + i++; + if (nptr[i] == '-' || nptr[i] == '+') + { + if (nptr[i] == '-') + minus = 1; + i++; + } + while (nptr[i] >= '0' && nptr[i] <= '9') + { + result = result * 10 + (nptr[i] - '0'); + i++; + } + if (minus) + result *= -1; + return (result); +} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c new file mode 100644 index 0000000..dbde44c --- /dev/null +++ b/libft/ft_bzero.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:41:46 by jteissie #+# #+# */ +/* Updated: 2024/05/15 15:00:35 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + unsigned int i; + unsigned char *str; + + i = 0; + str = s; + while (i < n) + { + str[i] = '\0'; + i++; + } +} diff --git a/libft/ft_calloc.c b/libft/ft_calloc.c new file mode 100644 index 0000000..7732477 --- /dev/null +++ b/libft/ft_calloc.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:05:28 by jteissie #+# #+# */ +/* Updated: 2024/05/22 15:40:09 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t nmemb, size_t size) +{ + void *ptr; + size_t total_size; + + total_size = size * nmemb; + if (total_size < size && total_size != 0) + return (NULL); + ptr = malloc(total_size); + if (!ptr) + return (NULL); + ft_memset(ptr, 0, total_size); + return (ptr); +} diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c new file mode 100644 index 0000000..0bf36bf --- /dev/null +++ b/libft/ft_isalnum.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:31:49 by jteissie #+# #+# */ +/* Updated: 2024/05/22 14:57:58 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isalnum(int c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + return (1); + if (c >= '0' && c <= '9') + return (1); + return (0); +} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c new file mode 100644 index 0000000..d8c9152 --- /dev/null +++ b/libft/ft_isalpha.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:42:26 by jteissie #+# #+# */ +/* Updated: 2024/05/22 14:58:03 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) + return (1); + return (0); +} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c new file mode 100644 index 0000000..6f95061 --- /dev/null +++ b/libft/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:06:25 by jteissie #+# #+# */ +/* Updated: 2024/05/22 14:58:10 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isascii(int c) +{ + if (c > 127 || c < 0) + return (0); + return (1); +} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c new file mode 100644 index 0000000..427b606 --- /dev/null +++ b/libft/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:33:38 by jteissie #+# #+# */ +/* Updated: 2024/05/22 14:58:16 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + if (c >= '0' && c <= '9') + return (1); + return (0); +} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c new file mode 100644 index 0000000..ace4dcd --- /dev/null +++ b/libft/ft_isprint.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:43:06 by jteissie #+# #+# */ +/* Updated: 2024/03/24 18:13:36 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int c) +{ + if (c >= 32 && c <= 126) + return (c); + return (0); +} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c new file mode 100644 index 0000000..40ebafc --- /dev/null +++ b/libft/ft_itoa.c @@ -0,0 +1,63 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:10:20 by jteissie #+# #+# */ +/* Updated: 2024/05/19 11:34:35 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_array(char *str, int nb, int *index) +{ + long int number; + + number = nb; + if (number < 0) + { + str[0] = '-'; + number *= -1; + *index = *index + 1; + } + if (number > 9) + { + ft_putnbr_array(str, number / 10, index); + str[*index] = number % 10 + '0'; + *index = *index + 1; + return ; + } + str[*index] = number + '0'; + *index = *index + 1; + return ; +} + +char *ft_itoa(int n) +{ + int digits; + char *string; + int digits_count; + int i; + + digits = n; + digits_count = 0; + i = 0; + if (n == 0) + digits_count = 1; + while (digits != 0) + { + digits /= 10; + digits_count++; + } + if (n < 0) + digits_count++; + string = malloc(sizeof(char) * (digits_count + 1)); + if (!string) + return (NULL); + ft_putnbr_array(string, n, &i); + string[i] = '\0'; + return (string); +} diff --git a/libft/ft_lstadd_back_bonus.c b/libft/ft_lstadd_back_bonus.c new file mode 100644 index 0000000..dabea03 --- /dev/null +++ b/libft/ft_lstadd_back_bonus.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_back_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 14:45:13 by jteissie #+# #+# */ +/* Updated: 2024/05/20 14:08:42 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstadd_back(t_list **lst, t_list *new) +{ + t_list *last; + + if (lst == NULL || new == NULL) + return ; + if (*lst == NULL) + *lst = new; + else + { + last = ft_lstlast(*lst); + last->next = new; + } +} diff --git a/libft/ft_lstadd_front_bonus.c b/libft/ft_lstadd_front_bonus.c new file mode 100644 index 0000000..5bd9ec2 --- /dev/null +++ b/libft/ft_lstadd_front_bonus.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd_front_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/17 16:46:06 by jteissie #+# #+# */ +/* Updated: 2024/05/20 16:40:39 by jteissie ### ########.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_bonus.c b/libft/ft_lstclear_bonus.c new file mode 100644 index 0000000..0d412f7 --- /dev/null +++ b/libft/ft_lstclear_bonus.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstclear_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 18:10:45 by jteissie #+# #+# */ +/* Updated: 2024/05/20 16:57:50 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstclear(t_list **lst, void (*del)(void *)) +{ + t_list *temp; + + while (*lst != NULL) + { + temp = *lst; + *lst = (*lst)->next; + del(temp->content); + free(temp); + } + lst = NULL; +} diff --git a/libft/ft_lstdelone_bonus.c b/libft/ft_lstdelone_bonus.c new file mode 100644 index 0000000..fe8207b --- /dev/null +++ b/libft/ft_lstdelone_bonus.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 15:18:30 by jteissie #+# #+# */ +/* Updated: 2024/05/20 15:32:18 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_lstdelone(t_list *lst, void (*del)(void *)) +{ + del(lst->content); + free(lst); +} diff --git a/libft/ft_lstiter_bonus.c b/libft/ft_lstiter_bonus.c new file mode 100644 index 0000000..97b4a4f --- /dev/null +++ b/libft/ft_lstiter_bonus.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 19:08:59 by jteissie #+# #+# */ +/* Updated: 2024/05/20 15:32:26 by jteissie ### ########.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_bonus.c b/libft/ft_lstlast_bonus.c new file mode 100644 index 0000000..05a9f93 --- /dev/null +++ b/libft/ft_lstlast_bonus.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstlast_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 14:36:42 by jteissie #+# #+# */ +/* Updated: 2024/05/18 18:59:01 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstlast(t_list *lst) +{ + t_list *temp; + t_list *last; + + if (lst == NULL) + return (NULL); + temp = lst; + while (temp != NULL) + { + last = temp; + temp = temp->next; + } + return (last); +} diff --git a/libft/ft_lstmap_bonus.c b/libft/ft_lstmap_bonus.c new file mode 100644 index 0000000..efe918f --- /dev/null +++ b/libft/ft_lstmap_bonus.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 19:13:05 by jteissie #+# #+# */ +/* Updated: 2024/05/21 19:10:37 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *)) +{ + t_list *new_list; + t_list *new_node; + void *temp_content; + + new_list = NULL; + while (lst) + { + temp_content = f(lst->content); + new_node = ft_lstnew(temp_content); + if (!new_node) + { + del(temp_content); + ft_lstclear(&new_list, del); + return (NULL); + } + ft_lstadd_back(&new_list, new_node); + lst = lst->next; + } + return (new_list); +} diff --git a/libft/ft_lstnew_bonus.c b/libft/ft_lstnew_bonus.c new file mode 100644 index 0000000..fdbdabf --- /dev/null +++ b/libft/ft_lstnew_bonus.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/17 15:52:52 by jteissie #+# #+# */ +/* Updated: 2024/05/17 16:52:12 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +t_list *ft_lstnew(void *content) +{ + t_list *new_list; + + new_list = malloc(sizeof(t_list)); + if (!new_list) + return (NULL); + new_list->content = content; + new_list->next = NULL; + return (new_list); +} diff --git a/libft/ft_lstsize_bonus.c b/libft/ft_lstsize_bonus.c new file mode 100644 index 0000000..4fcb334 --- /dev/null +++ b/libft/ft_lstsize_bonus.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstsize_bonus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/18 14:25:01 by jteissie #+# #+# */ +/* Updated: 2024/05/18 14:35:30 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_lstsize(t_list *lst) +{ + t_list *temp; + int counter; + + counter = 0; + temp = lst; + while (temp != NULL) + { + temp = temp->next; + counter++; + } + return (counter); +} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c new file mode 100644 index 0000000..1f8e57e --- /dev/null +++ b/libft/ft_memchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:34:32 by jteissie #+# #+# */ +/* Updated: 2024/05/20 10:58:24 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + unsigned int i; + const unsigned char *str; + + i = 0; + str = s; + while (i < n) + { + if (str[i] == (unsigned char) c) + return ((void *)&str[i]); + i++; + } + return (NULL); +} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c new file mode 100644 index 0000000..7955734 --- /dev/null +++ b/libft/ft_memcmp.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:43:43 by jteissie #+# #+# */ +/* Updated: 2024/05/15 18:49:16 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + unsigned int i; + unsigned const char *str_1; + unsigned const char *str_2; + + i = 0; + str_1 = s1; + str_2 = s2; + while (i < n) + { + if (str_1[i] != str_2[i]) + return (str_1[i] - str_2[i]); + i++; + } + return (0); +} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c new file mode 100644 index 0000000..4d2bbf3 --- /dev/null +++ b/libft/ft_memcpy.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:12:25 by jteissie #+# #+# */ +/* Updated: 2024/05/18 16:13:24 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + unsigned int i; + const char *src_str; + char *dest_str; + + i = 0; + if (dest == NULL && src == NULL) + return (NULL); + src_str = src; + dest_str = dest; + while (i < n) + { + dest_str[i] = src_str[i]; + i++; + } + return ((void *)dest_str); +} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c new file mode 100644 index 0000000..91079f1 --- /dev/null +++ b/libft/ft_memmove.c @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:35:42 by jteissie #+# #+# */ +/* Updated: 2024/05/20 10:58:00 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static char *backward_copy(char *to, const char *from, size_t index) +{ + while (index > 0) + { + to[index - 1] = from[index - 1]; + index--; + } + to[index] = from[index]; + return (to); +} + +static char *normal_copy(char *to, const char *from, size_t index, size_t n) +{ + while (index < n) + { + to[index] = from[index]; + index++; + } + return (to); +} + +void *ft_memmove(void *dest, const void *src, size_t n) +{ + size_t i; + const char *from; + char *to; + + if ((dest == NULL && src == NULL) || n == 0) + return (dest); + from = src; + to = dest; + if (to > from) + { + i = n; + to = backward_copy(to, from, i); + } + else + { + i = 0; + to = normal_copy(to, from, i, n); + } + return (dest); +} diff --git a/libft/ft_memset.c b/libft/ft_memset.c new file mode 100644 index 0000000..2d739a4 --- /dev/null +++ b/libft/ft_memset.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:44:33 by jteissie #+# #+# */ +/* Updated: 2024/05/20 10:57:36 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + size_t i; + unsigned char *str; + + i = 0; + str = s; + while (i < n) + { + str[i] = (unsigned char)c; + i++; + } + return (s); +} diff --git a/libft/ft_printf/format_triage.c b/libft/ft_printf/format_triage.c new file mode 100644 index 0000000..bfb18b7 --- /dev/null +++ b/libft/ft_printf/format_triage.c @@ -0,0 +1,86 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* format_triage.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/24 14:09:31 by jteissie #+# #+# */ +/* Updated: 2024/06/06 13:39:12 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int triage_format(char f, va_list args) +{ + int print_count; + + print_count = 0; + if (f == 'c' || f == 's') + print_char(args, &print_count, f); + else if (f == 'u') + print_unsigned(args, &print_count); + else if (f == 'p') + print_ptr(args, &print_count); + else if (f == 'd' || f == 'i' || f == 'x' || f == 'X') + print_nbr(args, &print_count, f); + else if (f == '%') + print_count = print_putchar_fd('%', 1); + return (print_count); +} + +void print_unsigned(va_list args, int *count) +{ + unsigned long u_int; + + u_int = va_arg(args, unsigned int); + ft_putnbr_base(u_int, "0123456789", count); +} + +void print_nbr(va_list args, int *count, char format) +{ + int number; + + number = va_arg(args, int); + if (format == 'd' || format == 'i') + { + if (number < 0) + { + number *= -1; + ft_putchar_fd('-', 1); + *count = *count + 1; + } + ft_putnbr_base(number, "0123456789", count); + } + if (format == 'x') + ft_putnbr_base(number, "0123456789abcdef", count); + if (format == 'X') + ft_putnbr_base(number, "0123456789ABCDEF", count); +} + +void print_ptr(va_list args, int *count) +{ + unsigned long cast; + + cast = va_arg(args, unsigned long); + if (!cast) + { + *count = *count + 5; + ft_putstr_fd("(nil)", 1); + } + else + { + *count = *count + print_putchar_fd('0', 1); + *count = *count + print_putchar_fd('x', 1); + ft_putptr(cast, count); + } +} + +void print_char(va_list args, int *count, char format) +{ + if (format == 'c') + *count = *count + print_putchar_fd((char)va_arg(args, int), 1); + else + *count = *count + print_putstr_fd(va_arg(args, char *), 1); +} diff --git a/libft/ft_printf/ft_printf.c b/libft/ft_printf/ft_printf.c new file mode 100644 index 0000000..57433fb --- /dev/null +++ b/libft/ft_printf/ft_printf.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_printf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/04/07 16:42:23 by jteissie #+# #+# */ +/* Updated: 2024/06/06 13:39:05 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int process_string(const char *str, va_list args) +{ + int i; + int print_count; + + i = 0; + print_count = 0; + if (!str) + return (-1); + while (str[i]) + { + if (str[i] == '%') + { + print_count += triage_format(str[i + 1], args); + i++; + } + else + { + ft_putchar_fd(str[i], 1); + print_count++; + } + i++; + } + return (print_count); +} + +int ft_printf(const char *fmt, ...) +{ + va_list args; + int print_count; + + va_start(args, fmt); + print_count = process_string(fmt, args); + va_end(args); + return (print_count); +} diff --git a/libft/ft_printf/write_utils.c b/libft/ft_printf/write_utils.c new file mode 100644 index 0000000..4b51c35 --- /dev/null +++ b/libft/ft_printf/write_utils.c @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* write_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/23 16:21:14 by jteissie #+# #+# */ +/* Updated: 2024/06/06 13:39:20 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int print_strlen(const char *s) +{ + int i; + + i = 0; + while (s[i]) + i++; + return (i); +} + +int print_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); + return (1); +} + +int print_putstr_fd(char *s, int fd) +{ + int i; + + i = 0; + if (!s) + { + ft_putstr_fd("(null)", 1); + return (6); + } + while (s[i]) + { + ft_putchar_fd(s[i], fd); + i++; + } + return (print_strlen(s)); +} + +void ft_putnbr_base(unsigned int number, char *base, int *print) +{ + unsigned int base_len; + + base_len = 0; + while (base[base_len]) + base_len++; + if (number >= base_len) + { + ft_putnbr_base(number / base_len, base, print); + ft_putchar_fd(base[number % base_len], 1); + *print = *print + 1; + return ; + } + ft_putchar_fd(base[number], 1); + *print = *print + 1; + return ; +} + +void ft_putptr(unsigned long ptr, int *print) +{ + char *hexa; + + hexa = "0123456789abcdef"; + if (ptr >= 16) + { + ft_putptr(ptr / 16, print); + ft_putchar_fd(hexa[ptr % 16], 1); + *print = *print + 1; + return ; + } + ft_putchar_fd(hexa[ptr], 1); + *print = *print + 1; + return ; +} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c new file mode 100644 index 0000000..211f6f1 --- /dev/null +++ b/libft/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:48:56 by jteissie #+# #+# */ +/* Updated: 2024/05/15 15:04:12 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c new file mode 100644 index 0000000..2878e04 --- /dev/null +++ b/libft/ft_putendl_fd.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:55:16 by jteissie #+# #+# */ +/* Updated: 2024/03/23 17:58:22 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putendl_fd(char *s, int fd) +{ + ft_putstr_fd(s, fd); + ft_putchar_fd('\n', fd); +} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c new file mode 100644 index 0000000..1d1eccb --- /dev/null +++ b/libft/ft_putnbr_fd.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:59:07 by jteissie #+# #+# */ +/* Updated: 2024/05/17 14:46:54 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putnbr_fd(int n, int fd) +{ + long int number; + + number = n; + if (number < 0) + { + ft_putchar_fd('-', fd); + number *= -1; + } + if (number > 9) + { + ft_putnbr_fd(number / 10, fd); + ft_putchar_fd(number % 10 + 48, fd); + return ; + } + ft_putchar_fd(number + 48, fd); + return ; +} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c new file mode 100644 index 0000000..bd6a258 --- /dev/null +++ b/libft/ft_putstr_fd.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:52:53 by jteissie #+# #+# */ +/* Updated: 2024/05/15 15:05:54 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_putstr_fd(char *s, int fd) +{ + int i; + + i = 0; + while (s[i]) + { + ft_putchar_fd(s[i], fd); + i++; + } +} diff --git a/libft/ft_split.c b/libft/ft_split.c new file mode 100644 index 0000000..fe98d92 --- /dev/null +++ b/libft/ft_split.c @@ -0,0 +1,119 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:14:10 by jteissie #+# #+# */ +/* Updated: 2024/07/18 16:34:59 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int check_sep(char c, char sep) +{ + if (c == sep || c == '\0') + return (1); + return (0); +} + +static int count_words(char const *str, char sep) +{ + int i; + int words; + + i = 0; + words = 0; + if (!str || str[0] == '\0') + return (0); + if (check_sep(str[i], sep)) + i++; + while (str[i]) + { + if (check_sep(str[i], sep) + && !check_sep(str[i - 1], sep)) + words++; + i++; + } + if (check_sep(str[i], sep) && !check_sep(str[i - 1], sep)) + words++; + return (words); +} + +static char *build_str(char const *str, int index, int word_index) +{ + char *split_str; + int i; + + i = 0; + split_str = ft_calloc(word_index + 1, sizeof(char)); + if (!split_str) + return (NULL); + while (word_index > 0) + { + split_str[i] = str[index - word_index]; + i++; + word_index--; + } + split_str[i] = '\0'; + return (split_str); +} + +static char **assemble(char **split, char const *s, char c, int slots) +{ + int i; + int word_index; + int split_index; + + i = 0; + word_index = 0; + split_index = 0; + while (split_index < slots && s && s[i]) + { + while (!check_sep(s[i], c)) + { + word_index++; + i++; + } + if (check_sep(s[i], c) && !check_sep(s[i - 1], c)) + { + split[split_index] = build_str(s, i, word_index); + split_index++; + word_index = 0; + } + i++; + } + split[split_index] = NULL; + return (split); +} + +char **ft_split(char const *s, char c) +{ + char **split; + int words; + int safety_check; + + words = 0; + words = count_words(s, c); + split = ft_calloc(words + 1, sizeof(char *)); + if (!split) + return (NULL); + split = assemble(split, s, c, words); + safety_check = 0; + while (split[safety_check]) + safety_check++; + if (safety_check < words) + { + safety_check = 0; + while (safety_check <= words) + { + free(split[safety_check]); + safety_check++; + } + free(split); + return (NULL); + } + return (split); +} diff --git a/libft/ft_strarrjoin.c b/libft/ft_strarrjoin.c new file mode 100644 index 0000000..45c8ed6 --- /dev/null +++ b/libft/ft_strarrjoin.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strarrjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/29 11:32:23 by bthomas #+# #+# */ +/* Updated: 2024/07/29 11:40:58 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static size_t total_len(char **arr, size_t num_entries) +{ + size_t len; + size_t i; + + if (!arr || !*arr) + return (0); + len = 0; + i = 0; + while (i < num_entries && arr[i]) + { + len += ft_strlen(arr[i]); + i++; + } + return (len); +} + +char *ft_strarrjoin(char **arr, size_t num_entries) +{ + char *ret; + size_t ret_len; + size_t i; + + ret_len = total_len(arr, num_entries); + if (!ret_len) + return (NULL); + ret = (char *)ft_calloc(ret_len + 1, 1); + if (!ret) + return (NULL); + i = 0; + while (arr[i]) + { + ft_strlcat(ret, arr[i], ft_strlen(arr[i])); + i++; + } + return (ret); +} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c new file mode 100644 index 0000000..1feed62 --- /dev/null +++ b/libft/ft_strchr.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:37:23 by jteissie #+# #+# */ +/* Updated: 2024/05/21 15:19:06 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strchr(char const *str, int c) +{ + int i; + + i = 0; + while (str[i]) + { + if (str[i] == (char)c) + return ((char *)&str[i]); + i++; + } + if (str[i] == (char)c) + return ((char *)&str[i]); + return (0); +} diff --git a/libft/ft_strcmp.c b/libft/ft_strcmp.c new file mode 100644 index 0000000..6f8c766 --- /dev/null +++ b/libft/ft_strcmp.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/13 16:35:10 by bthomas #+# #+# */ +/* Updated: 2024/07/14 13:25:51 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strcmp(const char *s1, const char *s2) +{ + size_t s1len; + size_t s2len; + + if (!s1 && !s2) + return (0); + else if (!s1 || !s2) + return (1); + s1len = ft_strlen(s1); + s2len = ft_strlen(s2); + if (s1len != s2len) + return (1); + return (ft_strncmp(s1, s2, s1len)); +} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c new file mode 100644 index 0000000..7c93db6 --- /dev/null +++ b/libft/ft_strdup.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:46:49 by jteissie #+# #+# */ +/* Updated: 2024/07/21 13:29:01 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strdup(const char *s) +{ + char *cpy; + size_t len; + + len = ft_strlen(s); + cpy = malloc(len + 1); + if (cpy != NULL) + ft_strlcpy(cpy, s, len + 1); + return (cpy); +} diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c new file mode 100644 index 0000000..b480f1f --- /dev/null +++ b/libft/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:41:41 by jteissie #+# #+# */ +/* Updated: 2024/05/20 15:33:42 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_striteri(char *s, void (*f)(unsigned int, char*)) +{ + size_t i; + + i = 0; + while (s[i]) + { + (*f)(i, &s[i]); + i++; + } +} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c new file mode 100644 index 0000000..b60c4a7 --- /dev/null +++ b/libft/ft_strjoin.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:35:02 by jteissie #+# #+# */ +/* Updated: 2024/07/18 11:04:26 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin(char const *s1, char const *s2) +{ + char *joined; + int i; + int parse_index; + + i = 0; + parse_index = 0; + if (!s1 && !s2) + return (NULL); + if (!s1) + return (ft_strdup(s2)); + if (!s2) + return (ft_strdup(s1)); + joined = malloc (sizeof(char) * ft_strlen(s1) + ft_strlen(s2) + 1); + if (!joined) + return (NULL); + while (s1[parse_index]) + joined[i++] = s1[parse_index++]; + parse_index = 0; + while (s2[parse_index]) + joined[i++] = s2[parse_index++]; + joined[i] = '\0'; + return (joined); +} diff --git a/libft/ft_strjoin3.c b/libft/ft_strjoin3.c new file mode 100644 index 0000000..79fcae5 --- /dev/null +++ b/libft/ft_strjoin3.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin3.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/19 10:31:28 by bthomas #+# #+# */ +/* Updated: 2024/07/26 14:14:56 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strjoin3(char *s1, char *s2, char *s3) +{ + char *result; + size_t len; + + len = ft_strlen(s1) + ft_strlen(s2) + ft_strlen(s3); + if (!len) + return (ft_strdup("")); + result = (char *)malloc(sizeof(char) * (len + 1)); + if (!result) + return (NULL); + ft_strlcpy(result, s1, len + 1); + ft_strlcat(result, s2, len + 1); + ft_strlcat(result, s3, len + 1); + return (result); +} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c new file mode 100644 index 0000000..afdce27 --- /dev/null +++ b/libft/ft_strlcat.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:38:32 by jteissie #+# #+# */ +/* Updated: 2024/05/18 17:07:13 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcat(char *dest, const char *src, size_t size) +{ + size_t i; + size_t dest_len; + size_t total_len; + + i = 0; + if ((!dest) && size == 0) + return (ft_strlen(src)); + dest_len = ft_strlen(dest); + total_len = ft_strlen(dest) + ft_strlen(src); + if (dest_len >= size || size == 0) + return (ft_strlen(src) + size); + while (i < size - dest_len - 1 && src[i]) + { + dest[dest_len + i] = src[i]; + i++; + } + dest[dest_len + i] = '\0'; + return (total_len); +} diff --git a/libft/ft_strlcpy.c b/libft/ft_strlcpy.c new file mode 100644 index 0000000..10c77b5 --- /dev/null +++ b/libft/ft_strlcpy.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:47:51 by jteissie #+# #+# */ +/* Updated: 2024/05/17 11:51:14 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlcpy(char *dest, const char *src, size_t size) +{ + size_t i; + + i = 0; + if (size == 1) + { + dest[i] = '\0'; + return (ft_strlen(src)); + } + if (size == 0) + return (ft_strlen(src)); + while (i < size - 1 && src[i]) + { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + return (ft_strlen(src)); +} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c new file mode 100644 index 0000000..16c26ff --- /dev/null +++ b/libft/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:36:02 by jteissie #+# #+# */ +/* Updated: 2024/07/28 17:37:26 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +size_t ft_strlen(const char *str) +{ + int i; + + i = 0; + while (str && *str && str[i]) + i++; + return (i); +} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c new file mode 100644 index 0000000..487b704 --- /dev/null +++ b/libft/ft_strmapi.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/22 18:36:04 by jteissie #+# #+# */ +/* Updated: 2024/03/24 17:25:48 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strmapi(char const *s, char (*f) (unsigned int, char)) +{ + int i; + char *str; + + i = 0; + str = malloc(sizeof(char) * ft_strlen(s) + 1); + if (!str) + return (NULL); + while (s[i]) + { + str[i] = f(i, s[i]); + i++; + } + str[i] = 0; + return (str); +} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c new file mode 100644 index 0000000..e907238 --- /dev/null +++ b/libft/ft_strncmp.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:48:57 by jteissie #+# #+# */ +/* Updated: 2024/05/18 16:35:31 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + + i = 0; + while (i < n && (s1[i] || s2[i])) + { + if (s1[i] != s2[i]) + return ((unsigned char)s1[i] - (unsigned char)s2[i]); + i++; + } + return (0); +} + +/* +int ft_strncmp(const char *s1, const char *s2, size_t n) +{ + size_t i; + + i = 0; + if (n == 0) + return (0); + while (s1[i] == s2[i] && s1[i] && s2[i] && i < n - 1) + i++; + return ((unsigned char)s1[i] - (unsigned char)s2[i]); +}*/ \ No newline at end of file diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c new file mode 100644 index 0000000..4ce07b5 --- /dev/null +++ b/libft/ft_strnstr.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:36:54 by jteissie #+# #+# */ +/* Updated: 2024/05/22 11:10:33 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strnstr(const char *big, const char *little, size_t len) +{ + size_t i; + size_t little_i; + + i = 0; + if (little[0] == '\0') + return ((char *)big); + while (i < len && big[i]) + { + little_i = 0; + while (big[i + little_i] == little[little_i]) + { + if (i + little_i == len) + return (NULL); + little_i++; + if (little[little_i] == '\0') + return ((char *)&big[i]); + } + i++; + } + return (NULL); +} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c new file mode 100644 index 0000000..d974f2a --- /dev/null +++ b/libft/ft_strrchr.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:40:16 by jteissie #+# #+# */ +/* Updated: 2024/05/16 16:19:45 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strrchr(const char *s, int c) +{ + int i; + + i = ft_strlen(s); + while (i >= 0) + { + if (s[i] == (char) c) + return ((char *)&s[i]); + i--; + } + return (NULL); +} diff --git a/libft/ft_strreplacejoin.c b/libft/ft_strreplacejoin.c new file mode 100644 index 0000000..d423b4c --- /dev/null +++ b/libft/ft_strreplacejoin.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strreplacejoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/07/27 13:59:00 by bthomas #+# #+# */ +/* Updated: 2024/07/28 17:10:06 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_strreplacejoin(char **s1, char **s2) +{ + char *result; + + result = ft_strjoin(*s1, *s2); + if (*s1) + { + free(*s1); + *s1 = NULL; + } + if (*s2) + { + free(*s2); + *s2 = NULL; + } + if (!result) + return (NULL); + return (result); +} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c new file mode 100644 index 0000000..8a2db75 --- /dev/null +++ b/libft/ft_strtrim.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/22 14:37:51 by jteissie #+# #+# */ +/* Updated: 2024/03/24 17:30:04 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +static int ft_isset(char c, char const *set) +{ + size_t i; + + i = 0; + while (set[i]) + { + if (set[i] == c) + return (1); + i++; + } + return (0); +} + +char *ft_strtrim(char const *s1, char const *set) +{ + size_t start; + size_t end; + size_t i; + char *str; + + start = 0; + end = ft_strlen(s1); + while (s1[start] && ft_isset(s1[start], set)) + start++; + while (end > start && ft_isset(s1[end - 1], set)) + end--; + str = malloc(sizeof(char) * (end - start) + 1); + if (!str) + return (NULL); + i = 0; + while (start < end) + str[i++] = s1[start++]; + str[i] = 0; + return (str); +} diff --git a/libft/ft_substr.c b/libft/ft_substr.c new file mode 100644 index 0000000..662744b --- /dev/null +++ b/libft/ft_substr.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_substr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:37:49 by jteissie #+# #+# */ +/* Updated: 2024/07/26 13:04:03 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_substr(char const *s, unsigned int start, size_t len) +{ + char *sub_str; + unsigned int i; + + i = 0; + if (s && len > ft_strlen(s)) + len = ft_strlen(s); + if (s && start >= ft_strlen(s)) + len = 0; + if (s && start < ft_strlen(s) && len > ft_strlen(s) - start) + len = ft_strlen(s) - start; + sub_str = (char *)malloc(sizeof(char) * len + 1); + if (!sub_str) + return (NULL); + if (start < ft_strlen(s)) + { + while (s[start] && i < len) + { + sub_str[i] = s[start]; + start++; + i++; + } + } + sub_str[i] = '\0'; + return (sub_str); +} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c new file mode 100644 index 0000000..5f6b553 --- /dev/null +++ b/libft/ft_tolower.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 16:41:04 by jteissie #+# #+# */ +/* Updated: 2024/03/23 16:41:22 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +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 100644 index 0000000..c76d959 --- /dev/null +++ b/libft/ft_toupper.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: jteissie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/23 17:04:49 by jteissie #+# #+# */ +/* Updated: 2024/03/23 17:05:07 by jteissie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_toupper(int c) +{ + if (c >= 'a' && c <= 'z') + c -= 32; + return (c); +} diff --git a/libft/libft.h b/libft/libft.h new file mode 100644 index 0000000..aab4460 --- /dev/null +++ b/libft/libft.h @@ -0,0 +1,88 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: bthomas +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/03/24 16:02:39 by jteissie #+# #+# */ +/* Updated: 2024/07/29 11:40:30 by bthomas ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H +# include +# include +# include + +int ft_isdigit(int c); +int ft_isalpha(int c); +int ft_isalnum(int c); +int ft_isascii(int c); +int ft_isprint(int c); +int ft_toupper(int c); +int ft_atoi(const char *nptr); +int ft_tolower(int c); +char *ft_strchr(const char *s, int c); +int ft_strncmp(const char *s1, const char *s2, size_t size); +int ft_strcmp(const char *s1, const char *s2); +char *ft_strdup(const char *s); +char *ft_itoa(int n); +void ft_bzero(void *s, size_t n); +void *ft_calloc(size_t nmemb, size_t t); +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_split(char const *s, char c); +char *ft_strjoin(char const *s1, char const *s2); +size_t ft_strlen(const char *str); +size_t ft_strlcat(char *dest, const char *src, size_t size); +size_t ft_strlcpy(char *dest, const char *src, size_t size); +char *ft_strnstr(const char *big, const char *little, size_t n); +char *ft_strrchr(const char *s, int c); +char *ft_substr(char const *s, unsigned int start, size_t len); +char *ft_strtrim(char const *s1, char const *set); +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_putendl_fd(char *s, int fd); +void ft_putnbr_fd(int n, int fd); +void ft_putstr_fd(char *s, int fd); + +char *ft_strjoin3(char *s1, char *s2, char *s3); +char *ft_strreplacejoin(char **s1, char **s2); +char *ft_strarrjoin(char **arr, size_t num_entries); + +typedef struct s_list +{ + void *content; + struct s_list *next; +} t_list; +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 *)); + +// ft_printf +int ft_printf(const char *fmt, ...) + __attribute__((format (printf, 1, 2))); +int triage_format(char format, va_list args); +int process_string(const char *str, va_list args); +int print_putchar_fd(char c, int fd); +int print_strlen(char const *s); +int print_putstr_fd(char *s, int fd); +void ft_putnbr_base(unsigned int n, char *base, int *print); +void print_unsigned(va_list args, int *count); +void print_ptr(va_list args, int *count); +void ft_putptr(unsigned long ptr, int *print); +void print_char(va_list args, int *count, char format); +void print_nbr(va_list args, int *count, char format); +#endif diff --git a/map.c b/map.c new file mode 100644 index 0000000..e69de29 diff --git a/parser.c b/parser.c new file mode 100644 index 0000000..e69de29