intra to gitea

This commit is contained in:
lfirmin
2025-11-16 09:58:07 +01:00
commit 50c15b30e1
163 changed files with 12672 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: lfirmin <[email protected]> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/05/19 12:59:31 by lfirmin #+# #+# #
# Updated: 2024/05/22 15:18:38 by lfirmin ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
HEADER = ./
SRC = ft_isalnum.c ft_isprint.c ft_memcmp.c ft_putchar_fd.c ft_split.c \
ft_strlcat.c ft_strncmp.c ft_substr.c ft_atoi.c ft_isalpha.c \
ft_itoa.c ft_memcpy.c ft_putendl_fd.c ft_strchr.c ft_strlcpy.c \
ft_strnstr.c ft_tolower.c ft_bzero.c ft_isascii.c ft_strtrim.c \
ft_memmove.c ft_putnbr_fd.c ft_strdup.c ft_strlen.c ft_strrchr.c \
ft_toupper.c ft_calloc.c ft_isdigit.c ft_memchr.c ft_memset.c \
ft_putstr_fd.c ft_strjoin.c ft_strmapi.c ft_striteri.c \
ft_lstnew_bonus.c ft_lstadd_front_bonus.c ft_lstsize_bonus.c \
ft_lstlast_bonus.c ft_lstadd_back_bonus.c ft_lstdelone_bonus.c \
ft_lstclear_bonus.c ft_lstiter_bonus.c ft_lstmap_bonus.c ft_strcmp.c \
ft_atoll.c ft_print_array.c ft_strcat.c
CC = cc
CFLAGS = -Wall -Wextra -Werror -g3
INCLUDE = -I $(HEADER)
OBJ_DIR = obj/
OBJ = $(addprefix $(OBJ_DIR), $(SRC:.c=.o))
GREEN = \033[0;32m
YELLOW = \033[0;33m
RESET = \033[0m
WHITE = \033[0;97m
LOADING_CHARS = ⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏
all: $(NAME)
$(NAME): $(OBJ)
@printf "$(YELLOW)Compiling libft, Please wait...$(RESET)"
@for char in $(LOADING_CHARS); do \
printf "\r$(YELLOW)Compiling libft, Please wait... $$char$(RESET)"; \
sleep 0.1; \
done
@ar rc $(NAME) $(OBJ)
@ranlib $(NAME)
@printf "\r$(GREEN)Great news ! $(WHITE)Libft compiled successfully ! $(RESET)\n"
$(OBJ_DIR)%.o: %.c
@mkdir -p $(OBJ_DIR)
@$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
clean:
@rm -rf $(OBJ_DIR)
@printf "$(WHITE)Clean process completed for $(GREEN)Libft.$(RESET)\n"
fclean: clean
@rm -f $(NAME)
@printf "$(WHITE)Full clean process completed for $(GREEN)Libft.$(RESET)\n"
re: fclean all
.PHONY: all clean fclean re
+40
View File
@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 10:09:46 by lfirmin #+# #+# */
/* Updated: 2024/06/03 21:02:02 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int i;
int s;
int m;
i = 0;
s = 0;
m = 0;
while ((str[i] <= 13 && str[i] >= 9) || str[i] == 32)
i++;
while (str[i] == '-' || str[i] == '+')
{
s++;
if (s >= 2)
return (0);
if (str[i] == '-')
m++;
i++;
}
s = 0;
while (str[i] >= 48 && str[i] <= 57)
s = s * 10 + (str[i++] - 48);
if (m % 2 == 1)
s = s * -1;
return (s);
}
+38
View File
@@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/03 17:25:06 by lfirmin #+# #+# */
/* Updated: 2024/11/03 17:25:33 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long long ft_atoll(const char *str)
{
long long result;
int sign;
result = 0;
sign = 1;
while (*str == ' ' || (*str >= 9 && *str <= 13))
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
if (result > INT_MAX || result < INT_MIN)
return (2147483648);
result = result * 10 + (*str - '0');
str++;
}
return (result * sign);
}
+24
View File
@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 00:20:00 by lfirmin #+# #+# */
/* Updated: 2024/05/30 19:49:23 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_bzero(void *b, size_t len)
{
size_t i;
unsigned char *r;
r = (unsigned char *)b;
i = 0;
while (i < len)
r[i++] = '\0';
return (b);
}
+31
View File
@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 11:14:02 by lfirmin #+# #+# */
/* Updated: 2024/06/03 18:15:05 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t c, size_t s)
{
void *ptr;
long long int tmp1;
long long int tmp2;
tmp1 = (long long int)c;
tmp2 = (long long int)s;
if ((c > 4294967295 || s > 4294967295) && (tmp1 < 0 && tmp2 < 0))
return (NULL);
if (tmp1 * tmp2 < 0)
return (NULL);
ptr = malloc(c * s);
if (!ptr)
return (NULL);
ft_bzero(ptr, c * s);
return (ptr);
}
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:29:49 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
if ((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || (c >= 65 && c <= 90))
return (1);
return (0);
}
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 01:55:52 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
if ((c >= 97 && c <= 122) || (c >= 65 && c <= 90))
return (1);
return (0);
}
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:36:17 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
}
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:31:51 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isdigit(int c)
{
if (c >= 48 && c <= 57)
return (1);
return (0);
}
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:38:24 by lfirmin #+# #+# */
/* Updated: 2024/05/23 06:21:54 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isprint(int c)
{
if (((c >= 0 && c <= 31) || c >= 127 || c == EOF))
return (0);
return (1);
}
+51
View File
@@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/24 12:59:00 by lfirmin #+# #+# */
/* Updated: 2024/05/29 10:31:36 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t ft_count(long int n)
{
size_t c;
c = 0;
if (n <= 0)
c = 1;
while (n != 0)
{
n = n / 10;
c++;
}
return (c);
}
char *ft_itoa(int n)
{
char *str;
size_t size;
long int num;
num = n;
size = ft_count(num);
str = (char *)malloc(size + 1);
if (!str)
return (NULL);
str[size] = '\0';
if (num < 0)
num = -num;
while (size--)
{
str[size] = num % 10 + '0';
num = num / 10;
if (n < 0 && size == 0)
str[size] = '-';
}
return (str);
}
+27
View File
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 02:01:18 by lfirmin #+# #+# */
/* Updated: 2024/06/03 15:59:33 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *last;
if (!new)
return ;
if (!lst || !*lst)
{
*lst = new;
return ;
}
last = ft_lstlast(*lst);
last->next = new;
}
+21
View File
@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 20:34:57 by lfirmin #+# #+# */
/* Updated: 2024/05/31 20:41:34 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (lst && new)
{
new->next = *lst;
*lst = new;
}
}
+28
View File
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 20:46:07 by lfirmin #+# #+# */
/* Updated: 2024/06/01 20:51:07 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *t;
if (lst)
{
while (*lst)
{
t = (*lst)->next;
ft_lstdelone(*lst, del);
(*lst) = t;
}
(*lst) = NULL;
}
}
+20
View File
@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 20:32:56 by lfirmin #+# #+# */
/* Updated: 2024/06/01 20:32:56 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void*))
{
if (!lst || !del)
return ;
del(lst->content);
free(lst);
}
+23
View File
@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 21:05:12 by lfirmin #+# #+# */
/* Updated: 2024/06/01 21:05:12 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}
+23
View File
@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/01 01:52:09 by lfirmin #+# #+# */
/* Updated: 2024/06/01 01:57:22 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
while (lst)
{
if (!lst->next)
return (lst);
lst = lst->next;
}
return (lst);
}
+41
View File
@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/02 18:21:09 by lfirmin #+# #+# */
/* Updated: 2024/06/03 15:53:13 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new;
t_list *save;
if (!lst || !del || !f)
return (NULL);
new = ft_lstnew(lst->content);
if (!new)
return (NULL);
new->content = f(new->content);
save = new;
lst = lst->next;
while (lst)
{
new->next = ft_lstnew(lst->content);
if (!new->next)
{
ft_lstclear(&save, del);
return (NULL);
}
new->next->content = f(new->next->content);
new = new->next;
lst = lst->next;
}
new->next = NULL;
return (save);
}
+24
View File
@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 18:41:23 by lfirmin #+# #+# */
/* Updated: 2024/05/31 20:33:26 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *new;
new = (t_list *)malloc(sizeof(*new));
if (!new)
return (NULL);
new->content = content;
new->next = NULL;
return (new);
}
+27
View File
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/31 22:00:49 by lfirmin #+# #+# */
/* Updated: 2024/05/31 22:12:17 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
t_list *count;
count = lst;
i = 0;
while (count)
{
count = count->next;
i++;
}
return (i);
}
+26
View File
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 07:40:39 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned char *str;
str = (unsigned char *)s;
while (n--)
{
if (*str == (unsigned char)c)
return (str);
str++;
}
return (NULL);
}
+30
View File
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 07:57:58 by lfirmin #+# #+# */
/* Updated: 2024/05/22 11:34:35 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num)
{
unsigned char *pt1;
unsigned char *pt2;
size_t i;
pt1 = (unsigned char *)ptr1;
pt2 = (unsigned char *)ptr2;
i = 0;
while (i < num)
{
if (pt1[i] != pt2[i])
return (pt1[i] - pt2[i]);
i++;
}
return (0);
}
+31
View File
@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 01:08:31 by lfirmin #+# #+# */
/* Updated: 2024/05/30 18:46:00 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t len)
{
size_t i;
unsigned char *r;
unsigned char *s;
i = 0;
r = (unsigned char *)dest;
s = (unsigned char *)src;
if (dest == (void *)0 && src == (void *)0)
return (dest);
while (i < len)
{
r[i] = s[i];
i++;
}
return (dest);
}
+39
View File
@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmov.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 01:26:13 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *s1, const void *s2, size_t len)
{
unsigned char *dest;
unsigned char *src;
unsigned int i;
dest = (unsigned char *)s1;
src = (unsigned char *)s2;
i = 0;
if (dest == NULL && src == NULL)
return (NULL);
if (dest < src)
{
while (i < len)
{
dest[i] = src[i];
i++;
}
}
else
{
while (0 < len--)
dest[len] = src[len];
}
return (dest);
}
+24
View File
@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/20 02:42:40 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
size_t i;
unsigned char *r;
i = 0;
r = (unsigned char *)b;
while (i < len)
r[i++] = (unsigned char)c;
return (b);
}
+39
View File
@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_array.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 02:29:54 by lfirmin #+# #+# */
/* Updated: 2024/11/05 02:29:54 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void put_str(char *str)
{
if (!str)
return ;
while (*str)
write(1, str++, 1);
}
void ft_print_str_array(char **array)
{
int i;
if (array == NULL)
{
put_str("Tableau invalide\n");
return ;
}
i = 0;
put_str("Contenu du tableau:\n");
while (array[i])
{
put_str(array[i]);
write(1, "\n", 1);
i++;
}
}
+17
View File
@@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:17:45 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:20:42 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}
+18
View File
@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:35:44 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:38:36 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}
+31
View File
@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:42:38 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:56:04 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
long int nb;
nb = n;
if (nb < 0)
{
nb = -nb;
ft_putchar_fd('-', fd);
}
if (nb >= 10)
{
ft_putnbr_fd(nb / 10, fd);
ft_putnbr_fd(nb % 10, fd);
}
else
ft_putchar_fd(nb + '0', fd);
}
+24
View File
@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 11:27:05 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:33:18 by lfirmin ### ########.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++;
}
}
+59
View File
@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 05:56:37 by lfirmin #+# #+# */
/* Updated: 2024/06/04 12:08:51 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static size_t ft_countword(char const *s, char c)
{
size_t count;
if (!*s)
return (0);
count = 0;
while (*s)
{
while (*s == c)
s++;
if (*s)
count++;
while (*s != c && *s)
s++;
}
return (count);
}
char **ft_split(char const *s, char c)
{
char **lst;
size_t word_len;
int i;
lst = (char **)malloc((ft_countword(s, c) + 1) * sizeof(char *));
if (!s || !lst)
return (0);
i = 0;
while (*s)
{
while (*s == c && *s)
s++;
if (*s)
{
if (!ft_strchr(s, c))
word_len = ft_strlen(s);
else
word_len = ft_strchr(s, c) - s;
lst[i++] = ft_substr(s, 0, word_len);
s += word_len;
}
}
lst[i] = NULL;
return (lst);
}
+82
View File
@@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/05 02:21:14 by lfirmin #+# #+# */
/* Updated: 2024/11/05 08:19:47 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int should_add_space(char *dest, char *src)
{
size_t dest_len;
size_t src_len;
dest_len = ft_strlen(dest);
src_len = ft_strlen(src);
if (dest_len > 0 && src_len > 0)
{
if (dest[dest_len - 1] != ' ' && src[0] != ' ')
return (1);
}
return (0);
}
char *create_new_str(char *dest, char *src, int add_space)
{
size_t dest_len;
size_t src_len;
char *new_str;
dest_len = ft_strlen(dest);
src_len = ft_strlen(src);
if (add_space == 1)
new_str = malloc(sizeof(char) * (dest_len + src_len + 2));
else
new_str = malloc(sizeof(char) * (dest_len + src_len + 1));
if (!new_str)
return (NULL);
return (new_str);
}
void fill_new_str(char *new_str, char *dest, char *src, int add_space)
{
size_t dest_len;
size_t src_len;
dest_len = ft_strlen(dest);
src_len = ft_strlen(src);
if (add_space == 1)
{
ft_memset(new_str, 0, dest_len + src_len + 2);
ft_strlcpy(new_str, dest, dest_len + 1);
new_str[dest_len] = ' ';
ft_strlcpy(new_str + dest_len + 1, src, src_len + 1);
}
else
{
ft_memset(new_str, 0, dest_len + src_len + 1);
ft_strlcpy(new_str, dest, dest_len + 1);
ft_strlcpy(new_str + dest_len, src, src_len + 1);
}
}
char *ft_strcat(char *dest, char *src)
{
char *new_str;
int add_space;
if (!dest || !src)
return (NULL);
add_space = should_add_space(dest, src);
new_str = create_new_str(dest, src, add_space);
if (!new_str)
return (NULL);
fill_new_str(new_str, dest, src, add_space);
free(dest);
return (new_str);
}
+26
View File
@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 06:46:40 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:51:25 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(char const *str, int c)
{
while (*str)
{
if (*str == (char)c)
return ((char *)str);
str++;
}
if (*str == (char)c)
return ((char *)str);
else
return (NULL);
}
+22
View File
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/19 21:01:26 by lfirmin #+# #+# */
/* Updated: 2024/10/19 21:01:26 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0')
i++;
return (s1[i] - s2[i]);
}
+34
View File
@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/15 05:28:24 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
char *dest;
int i;
int size;
size = 0;
while (src[size] != '\0')
size++;
dest = malloc(sizeof(char) * (size + 1));
if (dest == NULL)
return (NULL);
i = 0;
while (i != size)
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
+27
View File
@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/29 10:54:40 by lfirmin #+# #+# */
/* Updated: 2024/05/29 11:12:05 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
int i;
i = 0;
if (s)
{
while (s[i])
{
f(i, &s[i]);
++i;
}
}
}
+34
View File
@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 01:00:14 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:49:06 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(const char *s1, const char *s2)
{
char *res;
int i;
int j;
i = 0;
j = 0;
if (s1 == NULL && s2 == NULL)
return (NULL);
res = (char *) malloc((ft_strlen(s1) + ft_strlen(s2) + 1) * sizeof(char));
if (!res)
return (NULL);
while (s1[i])
res[j++] = s1[i++];
i = 0;
while (s2[i])
res[j++] = s2[i++];
res[j] = 0;
return (res);
}
+32
View File
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 03:55:25 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
size_t i;
size_t r;
size_t s;
i = 0;
r = ft_strlen(dst);
s = ft_strlen(src);
if (size <= r)
return (s + size);
while (r + i < size - 1 && src[i] != '\0')
{
dst[r + i] = src[i];
i++;
}
dst[r + i] = '\0';
return (r + s);
}
+34
View File
@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 02:18:17 by lfirmin #+# #+# */
/* Updated: 2024/05/30 18:36:18 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t dsts)
{
size_t srcs;
size_t i;
ft_strlen(src);
if (!src || !dst)
return (0);
srcs = ft_strlen(src);
i = 0;
if (dsts != 0)
{
while (src[i] != '\0' && i < (dsts - 1))
{
dst[i] = src[i];
i++;
}
dst[i] = '\0';
}
return (srcs);
}
+22
View File
@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/19 23:16:45 by lfirmin #+# #+# */
/* Updated: 2024/05/23 07:36:59 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *s)
{
int i;
i = 0;
while (s[i])
i++;
return ((size_t)i);
}
+32
View File
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/28 15:10:42 by lfirmin #+# #+# */
/* Updated: 2024/05/28 17:00:27 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
char *str;
int i;
if (!s)
return (NULL);
str = (char *)malloc(ft_strlen(s) + 1);
if (!str)
return (NULL);
i = 0;
while (s[i])
{
str[i] = f(i, s[i]);
++i;
}
str[i] = '\0';
return (str);
}
+32
View File
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 06:55:09 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:47:59 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, unsigned int n)
{
unsigned int i;
unsigned char c1;
unsigned char c2;
i = 0;
if (n == 0)
return (0);
while (i < n)
{
c1 = (unsigned char)s1[i];
c2 = (unsigned char)s2[i];
if (c1 != c2 || c1 == '\0' || c2 == '\0')
return (c1 - c2);
i++;
}
return (0);
}
+36
View File
@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 08:22:59 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *hay, const char *need, size_t len)
{
size_t i;
size_t n;
i = 0;
if (need[0] == '\0')
return ((char *)hay);
while (hay[i] != '\0')
{
n = 0;
while (hay[i + n] == need[n] && (i + n) < len)
{
if (hay[i + n] == '\0' && need[n] == '\0')
return ((char *)&hay[i]);
n++;
}
if (need[n] == '\0')
return ((char *)hay + i);
i++;
}
return (0);
}
+35
View File
@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 06:42:38 by lfirmin #+# #+# */
/* Updated: 2024/05/30 18:30:00 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *str, int c)
{
int i;
int last_occurrence;
ft_strlen(str);
i = 0;
last_occurrence = -1;
if (str == NULL)
return (NULL);
while (str[i])
{
if (str[i] == (char)c)
last_occurrence = i;
i++;
}
if ((char)c == '\0')
return ((char *)&str[i]);
if (last_occurrence != -1)
return ((char *)&str[last_occurrence]);
return (NULL);
}
+68
View File
@@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/23 21:32:01 by lfirmin #+# #+# */
/* Updated: 2024/05/31 02:04:11 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int is_in_set(char c, const char *set)
{
while (*set)
{
if (c == *set)
{
return (1);
}
set++;
}
return (0);
}
static char *ft_strncpy(char *dest, const char *src, unsigned int n)
{
unsigned int i;
i = 0;
while (src[i] != '\0' && i < n)
{
dest[i] = src[i];
++i;
}
while (i < n)
{
dest[i] = '\0';
i++;
}
return (dest);
}
char *ft_strtrim(const char *s1, const char *set)
{
size_t s;
size_t e;
size_t len;
char *str;
if (!s1 || !set)
return (NULL);
s = 0;
while (s1[s] && is_in_set(s1[s], set))
s++;
e = ft_strlen(s1);
while (e > s && is_in_set(s1[e - 1], set))
e--;
len = e - s;
str = (char *)malloc(sizeof(char) * (len + 1));
if (!str)
return (NULL);
ft_strncpy(str, s1 + s, len);
str[len] = '\0';
return (str);
}
+34
View File
@@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/22 00:15:54 by lfirmin #+# #+# */
/* Updated: 2024/05/24 08:28:01 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *sub;
size_t i;
if ((ft_strlen(s) - start) < len)
len = ft_strlen(s) - start;
if (ft_strlen(s) < start)
return (ft_strdup(""));
i = 0;
sub = (char *) malloc(len + 1);
if (!sub)
return (NULL);
while (len > 0)
{
sub[i++] = s[start++];
len--;
}
sub[i] = '\0';
return (sub);
}
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_tolower.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 04:50:40 by lfirmin #+# #+# */
/* Updated: 2024/05/22 11:09:36 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_tolower(int c)
{
if (c >= 65 && c <= 90)
return (c + 32);
return (c);
}
+19
View File
@@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_toupper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 04:50:40 by lfirmin #+# #+# */
/* Updated: 2024/05/22 09:59:44 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_toupper(int c)
{
if (c >= 97 && c <= 122)
return (c - 32);
return (c);
}
+82
View File
@@ -0,0 +1,82 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* libft.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lfirmin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/21 11:19:08 by lfirmin #+# #+# */
/* Updated: 2024/06/02 21:12:47 by lfirmin ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef LIBFT_H
# define LIBFT_H
# include <stdlib.h>
# include <string.h>
# include <stddef.h>
# include <stdio.h>
# include <unistd.h>
# include <limits.h>
typedef struct s_list
{
void *content;
struct s_list *next;
} t_list;
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);
int ft_atoi(const char *str);
int ft_memcmp(const void *ptr1, const void *ptr2, size_t num);
int ft_strncmp(const char *s1, const char *s2, unsigned int n);
int ft_toupper(int c);
int ft_tolower(int c);
int ft_lstsize(t_list *lst);
int ft_strcmp(char *s1, char *s2);
long long ft_atoll(const char *str);
size_t ft_strlen(const char *s);
size_t ft_strlcat(char *dst, const char *src, size_t size);
size_t ft_strlcpy(char *dst, const char *src, size_t dsts);
void *ft_bzero(void *s, size_t n);
void *ft_calloc(size_t count, size_t n);
void *ft_memchr(const void *s, int c, size_t n);
void *ft_memcpy(void *dest, const void *src, size_t len);
void *ft_memset(void *b, int c, size_t len);
void *ft_memmove(void *s1, const void *s2, size_t len);
void *ft_memset(void *str, int c, size_t n);
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);
void ft_striteri(char *s, void (*f)(unsigned int, char*));
void ft_lstadd_front(t_list **lst, t_list *new);
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_print_str_array(char **array);
void ft_lstiter(t_list *lst, void (*f)(void *));
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), \
void (*del)(void *));
char *ft_strchr(char const *str, int c);
char *ft_strdup(const char *src);
char *ft_strjoin(const char *s1, const char *s2);
char *ft_strnstr(const char *hay, const char *need, size_t len);
char *ft_strrchr(const char *str, int c);
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 *s, char c);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
char *ft_itoa(int n);
char *ft_strcat(char *dest, char *src);
t_list *ft_lstnew(void *content);
t_list *ft_lstlast(t_list *lst);
#endif