makefile organise

This commit is contained in:
Hugo LAMY
2019-11-19 21:13:55 +01:00
parent 966241a6df
commit 32356ba7a0
85 changed files with 2052 additions and 116 deletions

35
srcs/part2/ft_itoa.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:10:25 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:36:38 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_itoa(int n)
{
char *str;
int len;
long int nbis;
len = (n < 0) ? 2 : 1;
nbis = n;
while (nbis /= 10)
len++;
nbis = n;
nbis *= (nbis < 0) ? -1 : 1;
if (!(str = ft_strnew(len)))
return (NULL);
str[--len] = nbis % 10 + '0';
while (nbis /= 10)
str[--len] = nbis % 10 + '0';
if (n < 0)
str[0] = '-';
return (str);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:14:14 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:14:15 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}

View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 18:38:05 by hulamy #+# #+# */
/* Updated: 2019/11/19 18:39:05 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** write the string s on the given file descriptor fd, followed by a newline
*/
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
ft_putstr_fd(s, fd);
ft_putchar_fd('\n', fd);
}

28
srcs/part2/ft_putnbr_fd.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:15:09 by hulamy #+# #+# */
/* Updated: 2018/11/14 21:15:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_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);
}

23
srcs/part2/ft_putstr_fd.c Normal file
View File

@@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 18:35:48 by hulamy #+# #+# */
/* Updated: 2019/11/19 18:37:07 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** write the string s on the given file descritor fd
*/
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
while (s && *s)
ft_putchar_fd(*s++, fd);
}

62
srcs/part2/ft_split.c Normal file
View File

@@ -0,0 +1,62 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 18:22:41 by hulamy #+# #+# */
/* Updated: 2019/11/19 18:28:01 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** return an array of string with each word found in str, with c as separator
*/
#include "libft.h"
static int ft_count_word(char const *s, char c)
{
int i;
int len;
i = -1;
len = 0;
while (s[++i])
if (s[i] != c)
{
len++;
while (s[i] && s[i] != c)
i++;
}
return (len);
}
char **ft_strsplit(char const *s, char c)
{
char **array;
int i;
int j;
int len;
i = -1;
j = 0;
if (!s || !c)
return (0);
if (!(array = (char **)malloc(sizeof(char *) * (ft_count_word(s, c) + 1))))
return (NULL);
while (s[++i])
{
if (s[i] != c)
{
len = 0;
while (s[i + len] && s[i + len] != c)
len++;
array[j++] = ft_strsub(s, i, len);
i = i + len - 1;
}
}
array[j] = 0;
return (array);
}

54
srcs/part2/ft_strjoin.c Normal file
View File

@@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:17:12 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:31:03 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a new string by concatenating the two strings s1 and s2
*/
#include "libft.h"
static char *ft_doit(char const *s1, char const *s2, char *dest)
{
int j;
int i;
j = 0;
i = 0;
while (s1[j] != '\0')
{
dest[i] = s1[j];
i++;
j++;
}
j = 0;
while (s2[j] != '\0')
{
dest[i] = s2[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *str;
if (!s1 || !s2)
return (NULL);
if (!(str = (char *)malloc(sizeof(char) *
(ft_strlen(s1) + ft_strlen(s2) + 1))))
return (NULL);
str = ft_doit(s1, s2, str);
return (str);
}

33
srcs/part2/ft_strmapi.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/14 21:18:03 by hulamy #+# #+# */
/* Updated: 2019/03/25 15:28:21 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a new array with the result of function f
** on every element of s by index i
*/
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, 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(i, s[i]);
return (str);
}

59
srcs/part2/ft_strtrim.c Normal file
View File

@@ -0,0 +1,59 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 17:26:06 by hulamy #+# #+# */
/* Updated: 2019/11/19 18:15:32 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a copy of s without the firsts and lasts empty characters
*/
/*
** #include <libc.h>
**
** char *ft_strtrim(char const *s1, char const *set);
**
** int main(int ac, char **av)
** {
** if (ac == 3)
** printf("%s\n",ft_strtrim(av[1], av[2]));
**
** return (0);
** }
*/
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
int len;
char *str;
(void)set;
if (!s1)
return (NULL);
while (s1[0] && ft_strchr(set, s1[0]))
s1++;
len = ft_strlen(s1) - 1;
while (len >= 0 && ft_strchr(set, s1[len]))
len--;
len++;
if (!(str = ft_strsub(s1, 0, len)))
return (NULL);
return (str);
}

32
srcs/part2/ft_substr.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_substr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/19 17:20:51 by hulamy #+# #+# */
/* Updated: 2019/11/19 17:24:10 by hulamy ### ########.fr */
/* */
/* ************************************************************************** */
/*
** create a copy of a portion of s, begining at start and of length len
*/
#include "libft.h"
char *ft_substr(char const *s, unsigned int start, size_t len)
{
char *str;
size_t i;
if (!s)
return (NULL);
if (!(str = ft_strnew(len)))
return (NULL);
i = 0;
while (i < len)
str[i++] = s[start++];
return (str);
}