Started from buttom go to the sky

This commit is contained in:
Raphaël 2024-04-28 19:59:01 +02:00
parent 96215449bd
commit f811e55dea
4781 changed files with 10121 additions and 1743 deletions

18
libft/ft_bzero.c Normal file
View file

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:43:13 by rparodi #+# #+# */
/* Updated: 2024/03/31 22:29:48 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
void ft_bzero(void *s, t_usize n)
{
ft_memset(s, 0, n);
}

31
libft/ft_calloc.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:47:17 by rparodi #+# #+# */
/* Updated: 2024/03/31 22:32:48 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
void *ft_calloc(t_usize nmemb, t_usize size)
{
t_usize total;
t_str to_return;
if (nmemb == 0 || size == 0)
return ((void *)malloc(1));
total = nmemb * size;
if (total / nmemb != size && total / size != nmemb)
return (NULL);
to_return = (char *)malloc(total);
if (to_return == NULL)
to_return = NULL;
else
ft_bzero(to_return, total);
return (to_return);
}

28
libft/ft_memset.c Normal file
View file

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:50:29 by rparodi #+# #+# */
/* Updated: 2024/03/31 22:32:32 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
void *ft_memset(void *s, t_i32 c, t_usize n)
{
t_str str;
t_usize i;
i = 0;
str = (t_str)s;
while (i < n)
{
str[i] = c;
i++;
}
return (str);
}

93
libft/ft_split.c Normal file
View file

@ -0,0 +1,93 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */
/* Updated: 2024/03/31 21:07:40 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
static t_i32 count_words(t_const_str str, t_i8 sep)
{
t_i32 i;
t_i32 count;
i = 0;
count = 0;
while (str[i])
{
while (str[i] == sep && str[i])
i++;
if (str[i] != sep && str[i])
{
while (str[i] != sep && str[i])
i++;
count++;
}
}
return (count);
}
static t_str ft_strndup(t_const_str s, t_i32 j)
{
t_i32 i;
t_str str;
i = 0;
str = (t_str)malloc((j + 1));
if (!str)
return (NULL);
while (s[i] && i < j)
{
str[i] = s[i];
i++;
}
str[i] = '\0';
return (str);
}
static t_str *ext_w(t_str *words_array, t_const_str str, t_i8 sep, t_i32 size)
{
t_i32 i;
t_i32 j;
i = 0;
j = 0;
while (j < size)
{
while (str[i] == sep && str[i])
i++;
str = str + i;
i = 0;
while (str[i] != sep && str[i])
i++;
words_array[j++] = ft_strndup(str, i);
str = str + i;
i = 0;
}
words_array[j] = 0;
return (words_array);
}
t_str *ft_split(t_const_str s, t_i8 c)
{
t_i32 size;
t_str *words_array;
size = count_words(s, c);
words_array = (t_str *)malloc(sizeof(char *) * (size + 1));
if (!words_array)
return (NULL);
if (size == 0)
{
words_array[0] = NULL;
return (words_array);
}
words_array = ext_w(words_array, s, c, size);
return (words_array);
}

31
libft/ft_strcmp.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */
/* Updated: 2024/03/31 21:57:48 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
int ft_strcmp(const char *s1, const char *s2)
{
size_t i;
int diff;
i = 0;
while ((s1[i] || s2[i]))
{
if (s1[i] != s2[i] && s1 && s2)
{
diff = (unsigned char)s1[i] - (unsigned char)s2[i];
return (diff);
}
i++;
}
return (0);
}

26
libft/ft_strdup.c Normal file
View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:53:59 by rparodi #+# #+# */
/* Updated: 2024/04/01 01:41:35 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
t_str ft_strdup(t_const_str s)
{
t_usize len;
t_str to_return;
len = ft_strlen(s) + 1;
to_return = (t_str)malloc(sizeof(t_i8) * len);
if (!to_return)
return (NULL);
ft_strlcpy(to_return, s, len);
return (to_return);
}

39
libft/ft_strjoin.c Normal file
View file

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/09 13:55:15 by rparodi #+# #+# */
/* Updated: 2024/04/13 20:16:50 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
char *ft_strjoin(char const *s1, char const *s2)
{
size_t i;
size_t save_i;
char *str;
i = 0;
str = (char *)malloc((ft_strlen(s1) + ft_strlen(s2)) + 1);
if (!str)
return (NULL);
while (s1[i] != '\0')
{
str[i] = s1[i];
i++;
}
save_i = i;
i = 0;
while (s2[i] != '\0')
{
str[save_i + i] = s2[i];
i++;
}
str[i + save_i] = '\0';
return (str);
}

31
libft/ft_strlcpy.c Normal file
View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */
/* Updated: 2024/04/01 01:38:28 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
t_usize ft_strlcpy(t_str dst, t_const_str src, t_usize size)
{
t_usize i;
i = 0;
while (src[i] && i + 1 < size)
{
dst[i] = src[i];
i++;
}
if (size > 0)
{
dst[i] = '\0';
i++;
}
return (ft_strlen(src));
}

23
libft/ft_strlen.c Normal file
View file

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/07 16:56:24 by rparodi #+# #+# */
/* Updated: 2024/04/01 01:37:04 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/minishell.h"
size_t ft_strlen(t_const_str s)
{
t_usize i;
i = 0;
while (s[i] != '\0')
i++;
return (i);
}