s
This commit is contained in:
parent
5fd959eeb8
commit
613f066547
51 changed files with 0 additions and 1746 deletions
|
@ -1,30 +0,0 @@
|
||||||
NAME = libft.a
|
|
||||||
|
|
||||||
SRC = 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_memchr.c ft_memcmp.c ft_memcpy.c ft_memmove.c \
|
|
||||||
ft_memset.c ft_strchr.c ft_strdup.c ft_strlcat.c ft_strlcpy.c ft_strlen.c \
|
|
||||||
ft_strncmp.c ft_strrchr.c ft_tolower.c ft_toupper.c ft_strnstr.c ft_substr.c\
|
|
||||||
ft_strjoin.c ft_strtrim.c ft_itoa.c ft_strmapi.c ft_striteri.c ft_putchar_fd.c\
|
|
||||||
ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_split.c 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 ft_hexa.c ft_printf.c\
|
|
||||||
ft_put.c get_next_line.c get_next_line_utils.c
|
|
||||||
|
|
||||||
OBJS = ${SRC:.c=.o}
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
CFLAGS = -Wall -Werror -Wextra
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
$(NAME): ${OBJS}
|
|
||||||
ar rc ${NAME} ${OBJS}
|
|
||||||
|
|
||||||
clean :
|
|
||||||
rm -f ${OBJS}
|
|
||||||
|
|
||||||
fclean : clean
|
|
||||||
rm -f $(NAME)
|
|
||||||
|
|
||||||
re : fclean all
|
|
|
@ -1,34 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_atoi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/04 14:30:22 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/04 14:30:24 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_atoi(const char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int is_neg;
|
|
||||||
int number;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
is_neg = 1;
|
|
||||||
number = 0;
|
|
||||||
while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32)
|
|
||||||
i++;
|
|
||||||
if (str[i] == '-' || str[i] == '+')
|
|
||||||
{
|
|
||||||
if (str[i] == '-')
|
|
||||||
is_neg *= -1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (str [i] >= '0' && str[i] <= '9')
|
|
||||||
number = (number * 10) + str[i++] - 48;
|
|
||||||
return (number * is_neg);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_bzero.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 14:32:10 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/08 14:32:22 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_bzero(void *s, size_t n)
|
|
||||||
{
|
|
||||||
unsigned char *str;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = s;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
str[i] = 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_calloc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 19:35:13 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/08 19:35:23 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_calloc(size_t count, size_t size)
|
|
||||||
{
|
|
||||||
void *str;
|
|
||||||
size_t tmp;
|
|
||||||
|
|
||||||
tmp = size * count;
|
|
||||||
if (size == 0 || count == 0)
|
|
||||||
return (malloc(0));
|
|
||||||
if (tmp / count != size)
|
|
||||||
return (NULL);
|
|
||||||
str = malloc(size * count);
|
|
||||||
if (str == NULL)
|
|
||||||
return (NULL);
|
|
||||||
ft_bzero (str, size * count);
|
|
||||||
return (str);
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_hexa.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/04/04 09:38:27 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/04/04 09:38:28 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_hexa(unsigned int args, char format, int count)
|
|
||||||
{
|
|
||||||
char *base;
|
|
||||||
char *shiftbase;
|
|
||||||
|
|
||||||
base = "0123456789abcdef";
|
|
||||||
shiftbase = "0123456789ABCDEF";
|
|
||||||
if (format == 'x')
|
|
||||||
{
|
|
||||||
if (args >= 16)
|
|
||||||
count = ft_hexa(args / 16, format, count);
|
|
||||||
count = ft_putcharf(base[args % 16], count);
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
if (format == 'X')
|
|
||||||
{
|
|
||||||
if (args >= 16)
|
|
||||||
count = ft_hexa(args / 16, format, count);
|
|
||||||
count = ft_putcharf(shiftbase[args % 16], count);
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_starthexa(unsigned int args, char format, int count)
|
|
||||||
{
|
|
||||||
if (!args && (format == 'x' || format == 'X'))
|
|
||||||
return (ft_putcharf('0', count));
|
|
||||||
count = ft_hexa(args, format, count);
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_startpointer(unsigned long long int args, char format, int count)
|
|
||||||
{
|
|
||||||
if (!args)
|
|
||||||
return (ft_putstrf("(nil)", count));
|
|
||||||
count = ft_putstrf("0x", count);
|
|
||||||
count = ft_pointer(args, format, count);
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_pointer(unsigned long long int args, char format, int count)
|
|
||||||
{
|
|
||||||
char *base;
|
|
||||||
|
|
||||||
base = "0123456789abcdef";
|
|
||||||
if (args >= 16)
|
|
||||||
count = ft_pointer(args / 16, format, count);
|
|
||||||
count = ft_putcharf(base[args % 16], count);
|
|
||||||
return (count);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalnum.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 18:17:39 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 18:17:41 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalnum(int c)
|
|
||||||
{
|
|
||||||
if (ft_isalpha(c) || ft_isdigit(c))
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalpha.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 17:36:30 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 17:36:34 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalpha(int c)
|
|
||||||
{
|
|
||||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isascii.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 18:20:38 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 18:20:40 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isascii(int c)
|
|
||||||
{
|
|
||||||
if (c >= 0 && c <= 127)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isdigit.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 17:48:20 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 17:48:22 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isdigit(int c)
|
|
||||||
{
|
|
||||||
if (c >= '0' && c <= '9')
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isprint.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 18:27:24 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 18:27:25 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isprint(int c)
|
|
||||||
{
|
|
||||||
if (c >= 32 && c <= 126)
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,62 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_itoa.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/19 19:32:47 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/19 19:32:48 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int countsize(int nb)
|
|
||||||
{
|
|
||||||
long int temp;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
size = 0;
|
|
||||||
temp = nb;
|
|
||||||
if (nb < 0)
|
|
||||||
{
|
|
||||||
temp = -nb;
|
|
||||||
size = size +1;
|
|
||||||
}
|
|
||||||
while (temp > 9)
|
|
||||||
{
|
|
||||||
temp = (temp / 10);
|
|
||||||
size++;
|
|
||||||
}
|
|
||||||
size++;
|
|
||||||
return (size);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_itoa(int nb)
|
|
||||||
{
|
|
||||||
long int temp;
|
|
||||||
char *res;
|
|
||||||
int size;
|
|
||||||
|
|
||||||
if (nb == -2147483648)
|
|
||||||
return (ft_strdup("-2147483648"));
|
|
||||||
temp = nb;
|
|
||||||
size = countsize(nb);
|
|
||||||
res = ft_calloc(size + 1, sizeof (char));
|
|
||||||
if (!res)
|
|
||||||
return (NULL);
|
|
||||||
if (nb < 0)
|
|
||||||
{
|
|
||||||
res[0] = '-';
|
|
||||||
temp *= -1;
|
|
||||||
}
|
|
||||||
if (nb == 0)
|
|
||||||
res[0] = '0';
|
|
||||||
while (temp > 0)
|
|
||||||
{
|
|
||||||
res[size - 1] = (temp % 10 + 48);
|
|
||||||
size--;
|
|
||||||
temp /= 10;
|
|
||||||
}
|
|
||||||
return (res);
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_back.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 11:38:44 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 11:38:46 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
|
||||||
{
|
|
||||||
t_list *temp;
|
|
||||||
|
|
||||||
if (!new)
|
|
||||||
return ;
|
|
||||||
if (!*lst)
|
|
||||||
{
|
|
||||||
*lst = new;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
temp = ft_lstlast(*lst);
|
|
||||||
temp->next = new;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,18 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_front.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/21 23:42:28 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 23:42:30 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
|
||||||
{
|
|
||||||
new->next = *lst;
|
|
||||||
*lst = new;
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstclear.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 22:05:11 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 22:05:12 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void*))
|
|
||||||
{
|
|
||||||
t_list *next;
|
|
||||||
t_list *current;
|
|
||||||
|
|
||||||
if (lst == NULL || del == NULL || *lst == NULL)
|
|
||||||
return ;
|
|
||||||
current = *lst;
|
|
||||||
while (current != NULL)
|
|
||||||
{
|
|
||||||
next = current->next;
|
|
||||||
del(current->content);
|
|
||||||
free(current);
|
|
||||||
current = next;
|
|
||||||
}
|
|
||||||
*lst = NULL;
|
|
||||||
}
|
|
|
@ -1,22 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstdelone.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 20:15:05 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 20:15:06 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
|
||||||
{
|
|
||||||
if (!lst)
|
|
||||||
return ;
|
|
||||||
if (!del)
|
|
||||||
return ;
|
|
||||||
del(lst->content);
|
|
||||||
free(lst);
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstiter.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 22:42:44 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 22:42:45 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
|
||||||
{
|
|
||||||
t_list *node;
|
|
||||||
|
|
||||||
node = lst;
|
|
||||||
if (lst == NULL || f == NULL)
|
|
||||||
return ;
|
|
||||||
node = lst;
|
|
||||||
while (node != NULL)
|
|
||||||
{
|
|
||||||
f(node->content);
|
|
||||||
node = node->next;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstlast.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 10:27:02 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 10:27:07 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstlast(t_list *lst)
|
|
||||||
{
|
|
||||||
if (!lst)
|
|
||||||
return (NULL);
|
|
||||||
while (lst->next)
|
|
||||||
lst = lst->next;
|
|
||||||
return (lst);
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstmap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/24 11:59:12 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/24 11:59:13 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *))
|
|
||||||
{
|
|
||||||
t_list *new;
|
|
||||||
t_list *current;
|
|
||||||
|
|
||||||
if (!lst || !f ||!del)
|
|
||||||
return (NULL);
|
|
||||||
new = ft_lstnew(NULL);
|
|
||||||
if (!new)
|
|
||||||
return (NULL);
|
|
||||||
current = new;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
current->content = f(lst->content);
|
|
||||||
if (lst->next)
|
|
||||||
{
|
|
||||||
current->next = ft_lstnew(NULL);
|
|
||||||
if (!current)
|
|
||||||
{
|
|
||||||
ft_lstclear(&new, del);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
current = current ->next;
|
|
||||||
}
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (new);
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstnew.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/21 19:40:32 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 22:58:42 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content)
|
|
||||||
{
|
|
||||||
t_list *new;
|
|
||||||
|
|
||||||
new = malloc(sizeof(t_list));
|
|
||||||
if (new == 0)
|
|
||||||
return (NULL);
|
|
||||||
new->content = content;
|
|
||||||
new->next = NULL;
|
|
||||||
return (new);
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstsize.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/23 10:14:39 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/23 10:14:41 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_lstsize(t_list *lst)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
lst = lst->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 20:08:44 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/08 20:08:45 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memchr(const void *str, int c, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
if ((((unsigned char *)str)[i]) == (unsigned char)c)
|
|
||||||
return ((void *)str + i);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 20:15:03 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/08 20:15:05 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
if (((unsigned char *)s1)[i] != ((unsigned char *)s2)[i])
|
|
||||||
return (((unsigned char *)s1)[i] - ((unsigned char *)s2)[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 15:04:22 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/08 15:04:24 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!dest && !src)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
while (n != 0)
|
|
||||||
{
|
|
||||||
((unsigned char *)dest)[i] = ((unsigned char *)src)[i];
|
|
||||||
i++;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
return ((void *)dest);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memmove.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/10 10:32:23 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/10 10:32:25 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!dest && !src)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
if (dest < src)
|
|
||||||
{
|
|
||||||
while (n--)
|
|
||||||
{
|
|
||||||
(((unsigned char *)dest)[i]) = (((unsigned char *)src)[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i = i + n - 1;
|
|
||||||
while (n--)
|
|
||||||
{
|
|
||||||
(((unsigned char *)dest)[i]) = (((unsigned char *)src)[i]);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ((void *)dest);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memset.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 18:40:30 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 18:40:33 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memset(void *str, int c, size_t n)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (n != 0)
|
|
||||||
{
|
|
||||||
(((unsigned char *)str)[i]) = c;
|
|
||||||
i++;
|
|
||||||
n--;
|
|
||||||
}
|
|
||||||
return ((void *)str);
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_printf.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/03/13 10:48:34 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/03/13 10:48:35 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_format(const char format, va_list args, int count)
|
|
||||||
{
|
|
||||||
if (format == 'c')
|
|
||||||
count = ft_putcharf((char)va_arg(args, int), count);
|
|
||||||
else if (format == 's')
|
|
||||||
count = ft_putstrf(va_arg(args, char *), count);
|
|
||||||
else if (format == 'd')
|
|
||||||
count = ft_putnbrf(va_arg(args, int), count);
|
|
||||||
else if (format == 'i')
|
|
||||||
count = ft_putnbrf(va_arg(args, int), count);
|
|
||||||
else if (format == 'u')
|
|
||||||
count = ft_putnbrposf(va_arg(args, unsigned int), count);
|
|
||||||
else if (format == 'x')
|
|
||||||
count = ft_starthexa (va_arg(args, unsigned int), 'x', count);
|
|
||||||
else if (format == 'X')
|
|
||||||
count = ft_starthexa (va_arg(args, unsigned int), 'X', count);
|
|
||||||
else if (format == 'p')
|
|
||||||
count = ft_startpointer
|
|
||||||
(va_arg(args, unsigned long long int), 'p', count);
|
|
||||||
else if (format == '%')
|
|
||||||
count = ft_putcharf('%', count);
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_printf(const char *format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
int i;
|
|
||||||
int count;
|
|
||||||
|
|
||||||
va_start(args, format);
|
|
||||||
i = 0;
|
|
||||||
count = 0;
|
|
||||||
while (format[i])
|
|
||||||
{
|
|
||||||
if (format[i] != '%')
|
|
||||||
{
|
|
||||||
write(1, &format[i], 1);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
count = ft_format(format[i], args, count);
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
va_end(args);
|
|
||||||
return (count);
|
|
||||||
}
|
|
|
@ -1,75 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_put.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/04/13 10:26:43 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/04/13 10:26:45 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_putcharf(char c, int count)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
count++;
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_putnbrf(int n, int count)
|
|
||||||
{
|
|
||||||
if (n == -2147483648)
|
|
||||||
{
|
|
||||||
(write(1, "-2147483648", 11));
|
|
||||||
count += 11;
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
if (n < 0)
|
|
||||||
{
|
|
||||||
count = ft_putcharf('-', count);
|
|
||||||
n *= -1;
|
|
||||||
count = ft_putnbrf(n, count);
|
|
||||||
}
|
|
||||||
else if (n >= 10)
|
|
||||||
{
|
|
||||||
count = ft_putnbrf(n / 10, count);
|
|
||||||
count = ft_putnbrf(n % 10, count);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
count = ft_putcharf(n + '0', count);
|
|
||||||
}
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_putnbrposf(unsigned int n, int count)
|
|
||||||
{
|
|
||||||
if (n >= 10)
|
|
||||||
{
|
|
||||||
count = ft_putnbrposf(n / 10, count);
|
|
||||||
count = ft_putnbrposf(n % 10, count);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
count = ft_putcharf(n + '0', count);
|
|
||||||
}
|
|
||||||
return (count);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ft_putstrf(char *s, int count)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return (ft_putstrf("(null)", count));
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
write(1, &s[i], 1);
|
|
||||||
i++;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return (count);
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/20 23:21:04 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 23:21:05 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putchar_fd(char c, int fd)
|
|
||||||
{
|
|
||||||
write(fd, &c, 1);
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putendl_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/20 23:36:08 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 23:36:09 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putendl_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return ;
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
write(fd, &s[i], 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
ft_putchar_fd('\n', fd);
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/20 23:43:01 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 23:43:02 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putnbr_fd(int n, int fd)
|
|
||||||
{
|
|
||||||
if (n == -2147483648)
|
|
||||||
{
|
|
||||||
write(fd, "-2147483648", 11);
|
|
||||||
}
|
|
||||||
else if (n < 0)
|
|
||||||
{
|
|
||||||
ft_putchar_fd('-', fd);
|
|
||||||
n *= -1;
|
|
||||||
ft_putnbr_fd(n, fd);
|
|
||||||
}
|
|
||||||
else if (n >= 10)
|
|
||||||
{
|
|
||||||
ft_putnbr_fd(n / 10, fd);
|
|
||||||
ft_putnbr_fd(n % 10, fd);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_putchar_fd(n + '0', fd);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/20 23:29:21 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 23:29:26 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putstr_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return ;
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
write(fd, &s[i], 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_split.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/21 11:11:19 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/21 18:03:11 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_countword(const char *s, char c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
while (s[i] == c)
|
|
||||||
i++;
|
|
||||||
if (s[i] != '\0')
|
|
||||||
j++;
|
|
||||||
while (s[i] != c && s[i])
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (j);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strdup_modif(const char *s, char c, size_t i)
|
|
||||||
{
|
|
||||||
size_t k;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
k = 0;
|
|
||||||
while (s[i + k] && s[i + k] != c)
|
|
||||||
k++;
|
|
||||||
dest = ft_calloc(sizeof(char), (k + 1));
|
|
||||||
k = 0;
|
|
||||||
if (dest == 0)
|
|
||||||
return (NULL);
|
|
||||||
while (s[i + k] && s[i + k] != c)
|
|
||||||
{
|
|
||||||
dest[k] = s[i + k];
|
|
||||||
k++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **ft_split(const char *s, char c)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
char **res;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return (NULL);
|
|
||||||
res = ft_calloc(sizeof (char *), (ft_countword(s, c) + 1));
|
|
||||||
if (!res)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
while (s[i] == c)
|
|
||||||
i++;
|
|
||||||
if (s[i] == '\0')
|
|
||||||
break ;
|
|
||||||
res[j] = ft_strdup_modif(s, c, i);
|
|
||||||
j++;
|
|
||||||
while (s[i] != c && s[i])
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (res);
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/04 12:59:29 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/04 12:59:31 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strchr(const char *str, int tofind)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
if ((unsigned char)str[i] == (unsigned char)tofind)
|
|
||||||
return ((char *)&str[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (tofind == '\0')
|
|
||||||
return ((char *)&str[i]);
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strdup.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/08 20:55:55 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/13 21:30:44 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strdup(const char *src)
|
|
||||||
{
|
|
||||||
size_t size;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
size = ft_strlen(src);
|
|
||||||
dest = (char *)malloc(size + 1);
|
|
||||||
if (dest == 0)
|
|
||||||
return (NULL);
|
|
||||||
ft_strlcpy(dest, src, size + 1);
|
|
||||||
return (dest);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_striteri.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/20 22:29:06 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 22:29:07 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!s || !(*f))
|
|
||||||
return ;
|
|
||||||
i = 0;
|
|
||||||
while (i < ft_strlen(s))
|
|
||||||
{
|
|
||||||
(*f)(i, &s[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strjoin.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/14 16:41:00 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/14 16:41:02 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
if (!s1 || !s2)
|
|
||||||
return (NULL);
|
|
||||||
dest = ft_calloc ((ft_strlen(s1) + ft_strlen(s2) + 1), sizeof (char));
|
|
||||||
if (dest == 0)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while (s1[i] || s2[j])
|
|
||||||
{
|
|
||||||
while (i < ft_strlen(s1))
|
|
||||||
{
|
|
||||||
dest[i] = s1[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (j < ft_strlen(s2))
|
|
||||||
{
|
|
||||||
dest[i + j] = s2[j];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlcat.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 19:33:00 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 19:33:01 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strlcat(char *dest, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
unsigned int j;
|
|
||||||
unsigned int dlen;
|
|
||||||
unsigned int slen;
|
|
||||||
|
|
||||||
if ((dest == NULL || src == NULL) && size == 0)
|
|
||||||
return (0);
|
|
||||||
i = 0;
|
|
||||||
j = ft_strlen(dest);
|
|
||||||
dlen = j;
|
|
||||||
slen = ft_strlen(src);
|
|
||||||
if (size <= dlen)
|
|
||||||
return (slen + size);
|
|
||||||
while (src[i] != '\0' && i < size - dlen - 1)
|
|
||||||
{
|
|
||||||
dest[j] = src[i];
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
dest[j] = '\0';
|
|
||||||
return (dlen + slen);
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 19:33:21 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 19:33:24 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int 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 - 1)
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (ft_strlen(src));
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 18:31:38 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 18:31:39 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strlen(const char *str)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strmapi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/20 21:51:01 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/20 21:51:02 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t dlen;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
if (!s || !(*f))
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
dlen = ft_strlen(s);
|
|
||||||
dest = ft_calloc(dlen + 1, sizeof (char));
|
|
||||||
if (!dest)
|
|
||||||
return (NULL);
|
|
||||||
while (i < ft_strlen(s))
|
|
||||||
{
|
|
||||||
dest[i] = (*f)(i, s[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strncmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/04 14:33:04 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/04 14:33:06 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((s1[i] || s2[i]) && (i < size))
|
|
||||||
{
|
|
||||||
if (s1[i] != s2[i])
|
|
||||||
return (((unsigned char)(s1[i]) - ((unsigned char)s2[i])));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,38 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strnstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/13 22:07:12 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/13 22:07:14 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
if ((big == NULL || little == NULL) && !len)
|
|
||||||
return (0);
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
if (little[i] == '\0')
|
|
||||||
return ((char *)big);
|
|
||||||
while (big[i] && i < len)
|
|
||||||
{
|
|
||||||
if (big[i] == little[j])
|
|
||||||
{
|
|
||||||
while (big[i + j] == little[j] && (i + j) < len && little[j])
|
|
||||||
j++;
|
|
||||||
if (little[j] == '\0')
|
|
||||||
return ((char *)&big[i]);
|
|
||||||
j = 0;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
|
@ -1,28 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strrchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/04 14:00:32 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/13 21:32:54 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strrchr(const char *str, int tofind)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
i++;
|
|
||||||
while (i >= 0)
|
|
||||||
{
|
|
||||||
if ((unsigned char)str[i] == (unsigned char)tofind)
|
|
||||||
return ((char *)&str[i]);
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
|
@ -1,40 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strtrim.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/18 18:34:05 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/18 18:34:08 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strtrim(const char *s1, const char *set)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
size_t k;
|
|
||||||
size_t dlen;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
if (!s1)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
j = ft_strlen(s1);
|
|
||||||
k = -1;
|
|
||||||
while (ft_strchr(set, s1[i]) != 0 && s1[i])
|
|
||||||
i++;
|
|
||||||
if (!s1[i])
|
|
||||||
return (ft_strdup(""));
|
|
||||||
while (ft_strchr(set, s1[j]) != 0 && j > 0)
|
|
||||||
j--;
|
|
||||||
dlen = (j - i);
|
|
||||||
dest = ft_calloc ((dlen + 2), sizeof (char));
|
|
||||||
if (dest == 0)
|
|
||||||
return (NULL);
|
|
||||||
while (++k <= dlen)
|
|
||||||
dest[k] = s1[i + k];
|
|
||||||
return (dest);
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_substr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/14 14:52:48 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/14 14:52:51 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_substr(const char *s, unsigned int start, size_t len)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return (NULL);
|
|
||||||
i = start;
|
|
||||||
j = 0;
|
|
||||||
if (start >= ft_strlen(s))
|
|
||||||
return (ft_calloc(1, 1));
|
|
||||||
if (ft_strlen(s + start) < len)
|
|
||||||
dest = (char *)ft_calloc((ft_strlen(s + start) + 1), sizeof(char));
|
|
||||||
else
|
|
||||||
dest = (char *)ft_calloc((len + 1), sizeof(char));
|
|
||||||
if (dest == 0)
|
|
||||||
return (NULL);
|
|
||||||
while (j < len && s[i])
|
|
||||||
{
|
|
||||||
dest[j] = s[i];
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_tolower.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 20:49:29 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 20:49:30 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_tolower(int c)
|
|
||||||
{
|
|
||||||
if (c >= 65 && c <= 90)
|
|
||||||
c += 32;
|
|
||||||
return (c);
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_toupper.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/02 20:19:23 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/02 20:19:25 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_toupper(int c)
|
|
||||||
{
|
|
||||||
if (c >= 97 && c <= 122)
|
|
||||||
c -= 32;
|
|
||||||
return (c);
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/05/05 20:41:22 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/05/05 20:41:25 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_join( char *buffer, char *buff_read)
|
|
||||||
{
|
|
||||||
char *temp;
|
|
||||||
|
|
||||||
temp = ft_strjoing(buffer, buff_read);
|
|
||||||
free (buffer);
|
|
||||||
return (temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_nextline(char *buffer)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
char *nextline;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (buffer[i] && buffer[i] != '\n')
|
|
||||||
i++;
|
|
||||||
if (buffer[i] == '\n')
|
|
||||||
i++;
|
|
||||||
if (!buffer[i])
|
|
||||||
{
|
|
||||||
free (buffer);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
j = 0;
|
|
||||||
nextline = ft_calloc(ft_strleng(buffer) - i + 1, sizeof(char));
|
|
||||||
while (buffer[i])
|
|
||||||
{
|
|
||||||
nextline[j++] = buffer[i++];
|
|
||||||
}
|
|
||||||
free (buffer);
|
|
||||||
return (nextline);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_line(char *buffer)
|
|
||||||
{
|
|
||||||
char *line;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!buffer)
|
|
||||||
return (NULL);
|
|
||||||
while (buffer[i] && buffer[i] != '\n')
|
|
||||||
i++;
|
|
||||||
line = ft_calloc(i + 2, sizeof(char));
|
|
||||||
i = 0;
|
|
||||||
while (buffer[i] && buffer[i] != '\n')
|
|
||||||
{
|
|
||||||
line[i] = buffer[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (buffer[i] && buffer[i] == '\n')
|
|
||||||
line[i] = '\n';
|
|
||||||
return (line);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_readfile(int fd, char *buffer)
|
|
||||||
{
|
|
||||||
int byte_read;
|
|
||||||
char *buff_read;
|
|
||||||
|
|
||||||
buff_read = ft_calloc(BUFFER_SIZE + 1, sizeof(char));
|
|
||||||
byte_read = 1;
|
|
||||||
while (byte_read > 0)
|
|
||||||
{
|
|
||||||
byte_read = read(fd, buff_read, BUFFER_SIZE);
|
|
||||||
if (byte_read == 0)
|
|
||||||
break ;
|
|
||||||
if (byte_read == -1)
|
|
||||||
{
|
|
||||||
free(buff_read);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
buff_read[byte_read] = 0;
|
|
||||||
buffer = ft_join(buffer, buff_read);
|
|
||||||
if (ft_strrchr(buff_read, '\n'))
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
free (buff_read);
|
|
||||||
return (buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_next_line(int fd)
|
|
||||||
{
|
|
||||||
char *line;
|
|
||||||
static char *buffer = NULL;
|
|
||||||
|
|
||||||
if (fd < 0 || BUFFER_SIZE <= 0 || read(fd, 0, 0) < 0)
|
|
||||||
return (NULL);
|
|
||||||
buffer = ft_readfile(fd, buffer);
|
|
||||||
if (!buffer)
|
|
||||||
return (NULL);
|
|
||||||
line = ft_line(buffer);
|
|
||||||
buffer = ft_nextline(buffer);
|
|
||||||
return (line);
|
|
||||||
}
|
|
|
@ -1,53 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line_utils.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/05/05 20:41:39 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/05/05 20:41:41 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strleng(const char *str)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str && str[i])
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strjoing(char const *s1, char const *s2)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
if (!s2)
|
|
||||||
return (NULL);
|
|
||||||
dest = ft_calloc ((ft_strleng(s1) + ft_strleng(s2) + 1), sizeof (char));
|
|
||||||
if (dest == 0)
|
|
||||||
return (NULL);
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while (s2[j])
|
|
||||||
{
|
|
||||||
while (i < ft_strleng(s1))
|
|
||||||
{
|
|
||||||
dest[i] = s1[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (j < ft_strleng(s2))
|
|
||||||
{
|
|
||||||
dest[i + j] = s2[j];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
|
@ -1,89 +0,0 @@
|
||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* libft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: grobledo <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2023/02/10 12:14:34 by grobledo #+# #+# */
|
|
||||||
/* Updated: 2023/02/13 21:31:19 by grobledo ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
#ifndef LIBFT_H
|
|
||||||
# define LIBFT_H
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <strings.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <stdarg.h>
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <sys/stat.h>
|
|
||||||
# include <fcntl.h>
|
|
||||||
|
|
||||||
# ifndef BUFFER_SIZE
|
|
||||||
# define BUFFER_SIZE 10000
|
|
||||||
# endif
|
|
||||||
|
|
||||||
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);
|
|
||||||
void *ft_calloc(size_t count, size_t size);
|
|
||||||
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 *str, 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 *str, int c, size_t n);
|
|
||||||
char *ft_strchr(const char *str, int tofind);
|
|
||||||
char *ft_strdup(const char *src);
|
|
||||||
int ft_strlcat(char *dest, const char *src, size_t size);
|
|
||||||
int 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 size);
|
|
||||||
char *ft_strrchr(const char *str, int tofind);
|
|
||||||
int ft_tolower(int c);
|
|
||||||
int ft_toupper(int c);
|
|
||||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
char *ft_strtrim(const char *s1, const char *set);
|
|
||||||
char *ft_itoa(int nb);
|
|
||||||
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);
|
|
||||||
char **ft_split(const char *s, char c);
|
|
||||||
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_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 *));
|
|
||||||
int ft_hexa(unsigned int args, char format, int count);
|
|
||||||
int ft_format(const char format, va_list args, int count);
|
|
||||||
int ft_printf(const char *format, ...);
|
|
||||||
int ft_putstrf(char *s, int count);
|
|
||||||
int ft_putcharf(char c, int count);
|
|
||||||
int ft_putnbrposf(unsigned int n, int count);
|
|
||||||
int ft_putnbrf(int n, int count);
|
|
||||||
int ft_starthexa(unsigned int args, char format, int count);
|
|
||||||
int ft_pointer(unsigned long long int args, char format, int count);
|
|
||||||
int ft_startpointer(unsigned long long int args, char format, int count);
|
|
||||||
char *get_next_line(int fd);
|
|
||||||
size_t ft_strleng(const char *str);
|
|
||||||
char *ft_strjoing(char const *s1, char const *s2);
|
|
||||||
#endif
|
|
1
Minilibx
1
Minilibx
|
@ -1 +0,0 @@
|
||||||
Subproject commit 7dc53a411a7d4ae286c60c6229bd1e395b0efb82
|
|
Loading…
Add table
Reference in a new issue