makefile organise
This commit is contained in:
26
srcs/add/ft_any.c
Normal file
26
srcs/add/ft_any.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_any.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:14:49 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:14:53 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_any(char **tab, int (*f)(char*))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
if (!tab)
|
||||
return (0);
|
||||
while (tab[++i])
|
||||
if (f(tab[i]) == 1)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
28
srcs/add/ft_arraymap.c
Normal file
28
srcs/add/ft_arraymap.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_arraymap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:17:24 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:17:27 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int *ft_arraymap(int *tab, int length, int (*f)(int))
|
||||
{
|
||||
int i;
|
||||
int *newtab;
|
||||
|
||||
i = -1;
|
||||
if (!tab)
|
||||
return (NULL);
|
||||
if (!(newtab = (int*)malloc(sizeof(*newtab) * (length + 1))))
|
||||
return (NULL);
|
||||
while (++i < length)
|
||||
newtab[i] = (*f)(tab[i]);
|
||||
return (newtab);
|
||||
}
|
||||
75
srcs/add/ft_atoibase.c
Normal file
75
srcs/add/ft_atoibase.c
Normal file
@@ -0,0 +1,75 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoibase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:15:31 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:22:34 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int is_valid_base(char *base, int i, int j)
|
||||
{
|
||||
while (base[i])
|
||||
{
|
||||
j = i + 1;
|
||||
while (base[j])
|
||||
{
|
||||
if (base[i] == base[j])
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
if (base[i] == '-' || base[i] == '+')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
if (i >= 2)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int skip(int i, char *str, int *n)
|
||||
{
|
||||
while ((str[i] == 32) || (str[i] > 8 && str[i] < 14))
|
||||
i++;
|
||||
if (str[i] == '+' || str[i] == '-')
|
||||
{
|
||||
if (str[i] == '-')
|
||||
*n = -1;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
int ft_atoibase(char *str, char *base)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int length;
|
||||
int res;
|
||||
int n;
|
||||
|
||||
length = 0;
|
||||
res = 0;
|
||||
n = 1;
|
||||
if (!is_valid_base(base, 0, 0))
|
||||
return (0);
|
||||
while (base[length])
|
||||
length++;
|
||||
i = skip(0, str, &n);
|
||||
while (str[i] && str[i] > 32 && str[i] != '-' && str[i] != '+')
|
||||
{
|
||||
j = 0;
|
||||
while (str[i] != base[j] && base[j])
|
||||
j++;
|
||||
if (base[j] == '\0')
|
||||
return (0);
|
||||
res = (res * length) + j;
|
||||
i++;
|
||||
}
|
||||
return (res * n);
|
||||
}
|
||||
86
srcs/add/ft_convertbase.c
Normal file
86
srcs/add/ft_convertbase.c
Normal file
@@ -0,0 +1,86 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_convertbase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:15:55 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/17 17:09:35 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_malloc_size(int decimal, int length, int i)
|
||||
{
|
||||
if (decimal <= 0)
|
||||
i++;
|
||||
while (decimal)
|
||||
{
|
||||
decimal /= length;
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
static char *ft_decimal_to_base(int decimal, char *base, char *res, int size)
|
||||
{
|
||||
long nb;
|
||||
int i;
|
||||
|
||||
nb = decimal;
|
||||
i = 0;
|
||||
while (base[i])
|
||||
i++;
|
||||
if (nb < 0)
|
||||
nb = -nb;
|
||||
while (--size >= 0)
|
||||
{
|
||||
res[size] = base[nb % i];
|
||||
nb /= i;
|
||||
}
|
||||
return (res);
|
||||
}
|
||||
|
||||
static int ft_base_to_decimal(char *nbr, char *base, int length, int i)
|
||||
{
|
||||
long decimal;
|
||||
int j;
|
||||
|
||||
decimal = 0;
|
||||
if (nbr[i] == '-')
|
||||
i++;
|
||||
while (nbr[i])
|
||||
{
|
||||
j = 0;
|
||||
while (nbr[i] != base[j] && base[j])
|
||||
j++;
|
||||
decimal = (decimal * length) + j;
|
||||
i++;
|
||||
}
|
||||
if (nbr[0] == '-')
|
||||
decimal = -decimal;
|
||||
return (decimal);
|
||||
}
|
||||
|
||||
char *ft_convertbase(char *nbr, char *base_from, char *base_to)
|
||||
{
|
||||
int length;
|
||||
int size;
|
||||
int decimal;
|
||||
char *res;
|
||||
|
||||
res = 0;
|
||||
length = 0;
|
||||
while (base_from[length])
|
||||
length++;
|
||||
decimal = ft_base_to_decimal(nbr, base_from, length, 0);
|
||||
length = 0;
|
||||
while (base_to[length])
|
||||
length++;
|
||||
size = ft_malloc_size(decimal, length, 0);
|
||||
res = (char *)malloc(sizeof(char) * (size + 1));
|
||||
res[size] = '\0';
|
||||
return (ft_decimal_to_base(decimal, base_to, res, size));
|
||||
}
|
||||
22
srcs/add/ft_foreach.c
Normal file
22
srcs/add/ft_foreach.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_foreach.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:16:10 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:16:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_foreach(int *tab, int length, void (*f)(int))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (i < length && tab && tab[i])
|
||||
(*f)(tab[i++]);
|
||||
}
|
||||
26
srcs/add/ft_issort.c
Normal file
26
srcs/add/ft_issort.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_issort.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:18:14 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:18:15 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_issort(int *tab, int length, int (*f)(int, int))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
if (!tab)
|
||||
return (0);
|
||||
while (++i < length - 1)
|
||||
if (f(tab[i], tab[i + 1]) > 0)
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
27
srcs/add/ft_memalloc.c
Normal file
27
srcs/add/ft_memalloc.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memalloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/11/19 15:21:44 by hulamy #+# #+# */
|
||||
/* Updated: 2019/11/19 15:23:17 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** allocate size byte of memory and return a pointer to the allocated memory
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memalloc(size_t size)
|
||||
{
|
||||
void *tmp;
|
||||
|
||||
if (!size || !(tmp = malloc(size)))
|
||||
return (NULL);
|
||||
ft_bzero(tmp, size);
|
||||
return (tmp);
|
||||
}
|
||||
36
srcs/add/ft_memccpy.c
Normal file
36
srcs/add/ft_memccpy.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:12:10 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/03 15:42:41 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy string until character is found and place cursor in dst
|
||||
** after last byte copied
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
unsigned char *dest;
|
||||
unsigned char *sourc;
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
dest = (unsigned char *)dst;
|
||||
sourc = (unsigned char *)src;
|
||||
while (++i < n)
|
||||
{
|
||||
dest[i] = sourc[i];
|
||||
if (sourc[i] == (unsigned char)c)
|
||||
return (dst + i + 1);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
26
srcs/add/ft_memdel.c
Normal file
26
srcs/add/ft_memdel.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:13:26 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/03 15:44:12 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** free memory
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_memdel(void **ap)
|
||||
{
|
||||
if (ap && *ap)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = 0;
|
||||
}
|
||||
}
|
||||
18
srcs/add/ft_putchar.c
Normal file
18
srcs/add/ft_putchar.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:14:00 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:14:01 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
19
srcs/add/ft_putendl.c
Normal file
19
srcs/add/ft_putendl.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:14:32 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:14:33 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl(char const *s)
|
||||
{
|
||||
ft_putstr(s);
|
||||
ft_putchar('\n');
|
||||
}
|
||||
18
srcs/add/ft_putnbr.c
Normal file
18
srcs/add/ft_putnbr.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:14:57 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:14:58 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr(int n)
|
||||
{
|
||||
ft_putnbr_fd(n, 1);
|
||||
}
|
||||
59
srcs/add/ft_putnbrbase.c
Normal file
59
srcs/add/ft_putnbrbase.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrbase.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:17:00 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/16 15:23:43 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int check(char *base)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
while (base[i])
|
||||
{
|
||||
j = i + 1;
|
||||
while (base[j])
|
||||
{
|
||||
if (base[i] == base[j])
|
||||
return (0);
|
||||
j++;
|
||||
}
|
||||
if (base[i] == '-' || base[i] == '+')
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
if (i >= 2)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
void ft_putnbrbase(int nbr, char *base)
|
||||
{
|
||||
int i;
|
||||
long n;
|
||||
|
||||
i = 0;
|
||||
n = nbr;
|
||||
if (check(base))
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
ft_putchar('-');
|
||||
n = -n;
|
||||
}
|
||||
while (base[i])
|
||||
i++;
|
||||
if (n >= i)
|
||||
ft_putnbrbase(n / i, base);
|
||||
ft_putchar(base[n % i]);
|
||||
}
|
||||
}
|
||||
18
srcs/add/ft_putnbrendl.c
Normal file
18
srcs/add/ft_putnbrendl.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/19 10:38:07 by hulamy #+# #+# */
|
||||
/* Updated: 2019/02/19 10:42:46 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbrendl(int n)
|
||||
{
|
||||
ft_putnbrendl_fd(n, 1);
|
||||
}
|
||||
29
srcs/add/ft_putnbrendl_fd.c
Normal file
29
srcs/add/ft_putnbrendl_fd.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbrendl_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/02/19 10:37:58 by hulamy #+# #+# */
|
||||
/* Updated: 2019/02/19 10:42:48 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbrendl_fd(int n, int fd)
|
||||
{
|
||||
long l;
|
||||
|
||||
l = n;
|
||||
if (l < 0)
|
||||
{
|
||||
ft_putchar_fd('-', fd);
|
||||
l *= -1;
|
||||
}
|
||||
if (l >= 10)
|
||||
ft_putnbr_fd(l / 10, fd);
|
||||
ft_putchar_fd((l % 10) + '0', fd);
|
||||
ft_putchar_fd('\n', fd);
|
||||
}
|
||||
22
srcs/add/ft_putstr.c
Normal file
22
srcs/add/ft_putstr.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:15:19 by hulamy #+# #+# */
|
||||
/* Updated: 2018/11/14 21:15:19 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr(char const *s)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s && s[i])
|
||||
ft_putchar(s[i++]);
|
||||
}
|
||||
32
srcs/add/ft_strcat.c
Normal file
32
srcs/add/ft_strcat.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:15:40 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:12:58 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** append src to dest (dest must have sufficient space) and return dest
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcat(char *dest, const char *src)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (dest[i])
|
||||
i++;
|
||||
while (src[j])
|
||||
dest[i++] = src[j++];
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
23
srcs/add/ft_strclr.c
Normal file
23
srcs/add/ft_strclr.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strclr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:15:58 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:17:42 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** fill string with zeros
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strclr(char *s)
|
||||
{
|
||||
if (s)
|
||||
ft_bzero(s, ft_strlen(s));
|
||||
}
|
||||
28
srcs/add/ft_strcmp.c
Normal file
28
srcs/add/ft_strcmp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:16:08 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:18:30 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** compare two null terminated strings and return value
|
||||
** of difference between first two different character
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] && s1[i] == s2[i])
|
||||
i++;
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
}
|
||||
28
srcs/add/ft_strcpy.c
Normal file
28
srcs/add/ft_strcpy.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:16:17 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:19:19 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy string src to dst including '\0' and return dst
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcpy(char *dest, const char *src)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = -1;
|
||||
while (src[++i])
|
||||
dest[i] = src[i];
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
26
srcs/add/ft_strdel.c
Normal file
26
srcs/add/ft_strdel.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:16:25 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:19:54 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** free memory
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strdel(char **as)
|
||||
{
|
||||
if (as && *as)
|
||||
{
|
||||
free(*as);
|
||||
*as = 0;
|
||||
}
|
||||
}
|
||||
24
srcs/add/ft_strequ.c
Normal file
24
srcs/add/ft_strequ.c
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:16:44 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:21:02 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return 0 if strings s1 and s2 are identical and 1 if not
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strequ(char const *s1, char const *s2)
|
||||
{
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
return (ft_strcmp(s1, s2) == 0);
|
||||
}
|
||||
23
srcs/add/ft_striter.c
Normal file
23
srcs/add/ft_striter.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:16:53 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:21:14 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** apply function f to each element of string s
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striter(char *s, void (*f)(char *))
|
||||
{
|
||||
while (s && *s && f)
|
||||
f(s++);
|
||||
}
|
||||
26
srcs/add/ft_striteri.c
Normal file
26
srcs/add/ft_striteri.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:17:04 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:21:27 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** apply function f to each element of string s with index specified
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (s && *s && f)
|
||||
f(i++, s++);
|
||||
}
|
||||
28
srcs/add/ft_strjoinfree.c
Normal file
28
srcs/add/ft_strjoinfree.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoinfree.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/05 15:05:28 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:22:28 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new string by concatenating the two strings s1
|
||||
** and s2 then freeing them
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoinfree(char *s1, char *s2)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (!(str = ft_strjoin(s1, s2)))
|
||||
return (NULL);
|
||||
free(s1);
|
||||
return (str);
|
||||
}
|
||||
32
srcs/add/ft_strmap.c
Normal file
32
srcs/add/ft_strmap.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:17:49 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:23:12 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new array with the result of function f on every element of s
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmap(char const *s, char (*f)(char))
|
||||
{
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
if (!(str = ft_strnew(ft_strlen(s))))
|
||||
return (NULL);
|
||||
i = -1;
|
||||
while (s[++i])
|
||||
str[i] = f(s[i]);
|
||||
return (str);
|
||||
}
|
||||
83
srcs/add/ft_strmultisplit.c
Normal file
83
srcs/add/ft_strmultisplit.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmultisplit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/16 15:18:29 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:23:57 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return an array of string with each word found in str
|
||||
** with any character of charset difining a separator
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_is_separator(char c, char *charset, int i)
|
||||
{
|
||||
while (charset[i])
|
||||
{
|
||||
if (c == charset[i])
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
c = charset[i];
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int ft_count(char *str, int word, char **tab, char *charset)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
k = 0;
|
||||
i = 0;
|
||||
while (ft_is_separator(str[k], charset, 0) == 1)
|
||||
k++;
|
||||
while (str[k] != '\0' && i != word)
|
||||
{
|
||||
j = 0;
|
||||
while (!ft_is_separator(str[k + j], charset, 0) && str[k + j] != '\0')
|
||||
{
|
||||
if (word == -2)
|
||||
tab[i][j] = str[k + j];
|
||||
j++;
|
||||
}
|
||||
k += j;
|
||||
while (ft_is_separator(str[k], charset, 0))
|
||||
k++;
|
||||
i++;
|
||||
}
|
||||
if (word == -1)
|
||||
return (i);
|
||||
return (j);
|
||||
}
|
||||
|
||||
char **ft_strmultisplit(char *str, char *charset)
|
||||
{
|
||||
char **tab;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
|
||||
k = 0;
|
||||
tab = 0;
|
||||
i = ft_count(str, -1, tab, charset);
|
||||
if (!(tab = (char**)malloc(sizeof(tab) * (i + 1))))
|
||||
return (NULL);
|
||||
tab[i] = 0;
|
||||
while (k < i)
|
||||
{
|
||||
j = ft_count(str, k + 1, tab, charset);
|
||||
tab[k] = (char*)malloc(sizeof(*tab) * (j + 1));
|
||||
tab[k][j] = '\0';
|
||||
k++;
|
||||
}
|
||||
ft_count(str, -2, tab, charset);
|
||||
return (tab);
|
||||
}
|
||||
32
srcs/add/ft_strncat.c
Normal file
32
srcs/add/ft_strncat.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:18:24 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:24:11 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** append n character of src to dest and return dest
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncat(char *dest, const char *src, size_t nb)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (dest[i])
|
||||
i++;
|
||||
while (src[j] && j < nb)
|
||||
dest[i++] = src[j++];
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
30
srcs/add/ft_strncpy.c
Normal file
30
srcs/add/ft_strncpy.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:18:44 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:24:59 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** copy n characters from string src to dst including '\0'
|
||||
** if space remain it's filled zith '\0', and return dst
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncpy(char *dest, const char *src, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = -1;
|
||||
while (++i < n && src[i])
|
||||
dest[i] = src[i];
|
||||
while (i < n)
|
||||
dest[i++] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
25
srcs/add/ft_strnequ.c
Normal file
25
srcs/add/ft_strnequ.c
Normal file
@@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:18:55 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:25:20 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** return 0 if n first character of strings s1 and s2 are identical
|
||||
** and 1 if not
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
||||
{
|
||||
if (!s1 || !s2)
|
||||
return (0);
|
||||
return (ft_strncmp(s1, s2, n) == 0);
|
||||
}
|
||||
27
srcs/add/ft_strnew.c
Normal file
27
srcs/add/ft_strnew.c
Normal file
@@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:19:08 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:25:38 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** create a new string of length size, fill with zero, and return pointer to it
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnew(size_t size)
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (!(str = (char *)malloc(sizeof(char) * (size + 1))))
|
||||
return (NULL);
|
||||
ft_bzero(str, size + 1);
|
||||
return (str);
|
||||
}
|
||||
42
srcs/add/ft_strstr.c
Normal file
42
srcs/add/ft_strstr.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2018/11/14 21:19:45 by hulamy #+# #+# */
|
||||
/* Updated: 2019/03/25 15:26:59 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
/*
|
||||
** locate the first occurence of the string little in big
|
||||
** and return a pointer to this occurence if found
|
||||
*/
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strstr(const char *str, const char *to_find)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
j = 0;
|
||||
i = 0;
|
||||
if (!ft_strlen(to_find))
|
||||
return ((char *)str);
|
||||
while (i == 0)
|
||||
{
|
||||
while (to_find[i] && to_find[i] == str[j + i])
|
||||
i++;
|
||||
if (to_find[i])
|
||||
{
|
||||
j++;
|
||||
if (str[j] == '\0' && to_find[i])
|
||||
return (0);
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
return ((char *)str + j);
|
||||
}
|
||||
Reference in New Issue
Block a user