day 14 done

This commit is contained in:
2024-12-14 16:20:47 +01:00
parent 7dfe1cb9f3
commit 6f1b66db46
129 changed files with 68 additions and 2770 deletions

View File

@ -6,7 +6,7 @@
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ # # By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/07/17 15:48:36 by tomoron #+# #+# # # Created: 2024/07/17 15:48:36 by tomoron #+# #+# #
# Updated: 2024/12/14 14:02:58 by tomoron ### ########.fr # # Updated: 2024/12/14 15:46:23 by tomoron ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -16,7 +16,7 @@ SRCS = main.c\
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
FLAGS = -Wextra -Werror -Wall -g FLAGS = -Wextra -Werror -Wall -g -O0
LIB = libft/libft.a LIB = libft/libft.a
@ -54,7 +54,7 @@ part2.c:
cp ~/Desktop/aoc/part2.c . cp ~/Desktop/aoc/part2.c .
a.out: main.c $(OBJS) $(LIB) a.out: main.c $(OBJS) $(LIB)
clang $(FLAGS) $(OBJS) $(LIB) -Lmlx -lmlx -lX11 -lXext clang $(FLAGS) $(OBJS) $(LIB)
clean: clean:
rm -rf $(OBJS) rm -rf $(OBJS)

Binary file not shown.

View File

@ -1,99 +0,0 @@
# **************************************************************************** #
# # ::: :::::::: # Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
# Updated: 2024/07/17 23:19:01 by tomoron ### ########.fr #
# #
# **************************************************************************** #
NAME = libft.a
CC = cc
SRCS = 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_itoa.c\
ft_memchr.c\
ft_memcmp.c\
ft_memcpy.c\
ft_memmove.c\
ft_memset.c\
ft_putchar_fd.c\
ft_putendl_fd.c\
ft_putnbr_fd.c\
ft_putstr_fd.c\
ft_split.c\
ft_strchr.c\
ft_strdup.c\
ft_striteri.c\
ft_strjoin.c\
ft_strlcat.c\
ft_strlcpy.c\
ft_strlen.c\
ft_strmapi.c\
ft_strcmp.c\
ft_strnstr.c\
ft_strrchr.c\
ft_strtrim.c\
ft_substr.c\
ft_tolower.c\
ft_toupper.c\
ft_split_set.c\
ft_free_str_arr.c\
ft_set_color.c
SRCS_BONUS = 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\
OBJS = $(SRCS:.c=.o)
OBJS_BONUS = $(SRCS_BONUS:.c=.o)
FLAGS = -Wall -Wextra -Werror -g
all: $(NAME)
$(NAME): ft_printf $(OBJS)
make --no-print-directory -C ./ft_printf
cp ./ft_printf/libftprintf.a ./gnl/gnl.a
make --no-print-directory -C ./gnl
cp ./gnl/gnl.a ./$(NAME)
ar rcs $(NAME) $(OBJS)
.c.o:
$(CC) $(FLAGS) -c $< -o $@
bonus: $(OBJS) $(OBJS_BONUS)
ar rcs $(NAME) $(OBJS) $(OBJS_BONUS)
clean:
rm -f $(OBJS) $(OBJS_BONUS)
make --no-print-directory -C ./ft_printf fclean
make --no-print-directory -C ./gnl fclean
fclean: clean
rm -f $(NAME)
re: fclean all
so:
$(CC) -nostartfiles -fPIC $(FLAGS) $(SRCS)
gcc -nostartfiles -shared -o libft.so $(OBJS) $(OBJS_BONUS)
.PHONY: bonus so clean all re fclean

View File

@ -1,35 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 13:41:15 by tomoron #+# #+# */
/* Updated: 2023/10/31 15:35:21 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int res;
int inv;
res = 0;
inv = 1;
while (*str == ' ' || (*str >= '\t' && *str <= '\r'))
str++;
if (*str == '+' || *str == '-')
{
if (*str == '-')
inv *= -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
res *= 10;
res += *str - '0';
str++;
}
return (res * inv);
}

Binary file not shown.

View File

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:39:29 by tomoron #+# #+# */
/* Updated: 2023/11/02 10:41:24 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
unsigned long int i;
char *ptr;
ptr = (char *)s;
i = 0;
while (i < n)
{
ptr[i] = 0;
i++;
}
}

Binary file not shown.

View File

@ -1,31 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 02:38:46 by tomoron #+# #+# */
/* Updated: 2023/10/31 18:15:42 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nb, size_t size)
{
char *res;
unsigned long int i;
if (nb == 0 || size == 0)
return (malloc(1));
if ((long long)nb < 0 || (long long) size < 0)
return (0);
res = malloc(nb * size);
i = 0;
while (i < (nb * size) && res)
{
res[i] = 0;
i++;
}
return ((void *)res);
}

Binary file not shown.

View File

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_free_str_arr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/10 14:42:28 by tomoron #+# #+# */
/* Updated: 2023/12/10 14:53:07 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_free_str_arr(char **arr)
{
int i;
if (!arr)
return ;
i = 0;
while (arr[i])
{
free(arr[i]);
i++;
}
free(arr);
}

Binary file not shown.

View File

@ -1,19 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:09:17 by tomoron #+# #+# */
/* Updated: 2023/10/30 23:17:18 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalnum(int c)
{
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9'))
return (1);
return (0);
}

Binary file not shown.

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 18:10:01 by tomoron #+# #+# */
/* Updated: 2023/10/30 12:14:17 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isalpha(int c)
{
if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
return (0);
return (1);
}

Binary file not shown.

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:15:36 by tomoron #+# #+# */
/* Updated: 2023/10/30 12:31:38 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
}

Binary file not shown.

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 18:10:01 by tomoron #+# #+# */
/* Updated: 2023/10/30 12:13:53 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
if (!(c >= '0' && c <= '9'))
return (0);
return (1);
}

Binary file not shown.

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:31:55 by tomoron #+# #+# */
/* Updated: 2023/10/30 12:34:32 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
return (0);
}

Binary file not shown.

View File

@ -1,60 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 02:36:12 by tomoron #+# #+# */
/* Updated: 2023/11/02 10:16:45 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int get_number_len(long int n)
{
int res;
res = 1;
if (n < 0)
{
res++;
n *= -1;
}
while (n > 9)
{
res++;
n /= 10;
}
return (res);
}
char *ft_itoa(int n)
{
char *res;
int nb_len;
int i;
long int temp_nb;
temp_nb = (long int)n;
nb_len = get_number_len(n);
res = malloc((nb_len + 1) * sizeof(char));
if (!res)
return (res);
i = 0;
if (temp_nb < 0)
{
res[0] = '-';
temp_nb *= -1;
}
while (temp_nb > 9)
{
res[nb_len - i - 1] = (temp_nb % 10) + '0';
temp_nb /= 10;
i++;
}
res[nb_len - i - 1] = temp_nb + '0';
res[nb_len] = 0;
return (res);
}

Binary file not shown.

View File

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:44:09 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:13:03 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *current;
if (!lst)
return ;
current = *lst;
while (current && current->next)
current = current->next;
if (!current)
*lst = new;
else
current->next = new;
}

View File

@ -1,19 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:51:22 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:12:41 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
new->next = *lst;
*lst = new;
}

View File

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:52:45 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:12:06 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *next;
if (!lst || !del)
return ;
while (*lst)
{
next = (*lst)-> next;
del((*lst)-> content);
free(*lst);
*lst = next;
}
}

View File

@ -1,20 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:56:36 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:13:47 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void*))
{
if (!lst || !del)
return ;
del(lst->content);
free(lst);
}

View File

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 16:35:30 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:13:21 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
while (lst)
{
f(lst->content);
lst = lst->next;
}
}

View File

@ -1,19 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:47:49 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:13:36 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
while (lst && lst -> next)
lst = lst -> next;
return (lst);
}

View File

@ -1,41 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 17:29:05 by tomoron #+# #+# */
/* Updated: 2023/11/02 11:47:05 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *res;
t_list *current;
if (!lst)
return (0);
res = malloc(sizeof(t_list));
if (!res)
return (0);
res -> content = f(lst->content);
lst = lst->next;
current = res;
while (lst)
{
current->next = malloc(sizeof(t_list));
if (!current->next)
{
ft_lstclear(&res, del);
return (0);
}
current = current->next;
current->content = f(lst->content);
lst = lst->next;
}
current->next = NULL;
return (res);
}

View File

@ -1,25 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:39:52 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:11:12 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *res;
res = malloc (sizeof(t_list));
if (!res)
return (0);
res->content = content;
res->next = NULL;
return (res);
}

View File

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 15:46:36 by tomoron #+# #+# */
/* Updated: 2023/11/02 01:12:32 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int res;
res = 0;
while (lst)
{
res++;
lst = lst->next;
}
return (res);
}

View File

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 13:35:44 by tomoron #+# #+# */
/* Updated: 2023/11/02 11:28:37 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *s, int c, size_t n)
{
unsigned long int i;
unsigned char *p;
i = 0;
p = (unsigned char *) s;
while (i < n)
{
if (p[i] == (unsigned char)c)
return ((char *)p + i);
i++;
}
return (0);
}

Binary file not shown.

View File

@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 13:59:31 by tomoron #+# #+# */
/* Updated: 2023/11/02 10:23:04 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *s1, const void *s2, size_t n)
{
unsigned int i;
unsigned char *str1;
unsigned char *str2;
str1 = (unsigned char *)s1;
str2 = (unsigned char *)s2;
i = 0;
if (!n)
return (0);
while (str1[i] == str2[i] && i < n - 1)
i++;
return (str1[i] - str2[i]);
}

Binary file not shown.

View File

@ -1,29 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:42:28 by tomoron #+# #+# */
/* Updated: 2023/11/02 11:05:58 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *dest, const void *src, size_t n)
{
unsigned int i;
char *d;
char *s;
d = (char *)dest;
s = (char *)src;
i = 0;
while (i < n && d && s)
{
d[i] = s[i];
i++;
}
return (d);
}

Binary file not shown.

View File

@ -1,32 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 13:20:17 by tomoron #+# #+# */
/* Updated: 2023/11/02 10:23:24 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
unsigned int i;
unsigned char *d;
unsigned char *s;
d = (unsigned char *) dest;
s = (unsigned char *) src;
i = 0;
while (i < n && d && s)
{
if (d > s)
d[n - i - 1] = s[n - i - 1];
else
d[i] = s[i];
i++;
}
return (dest);
}

Binary file not shown.

View File

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:36:09 by tomoron #+# #+# */
/* Updated: 2023/11/02 10:23:45 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
unsigned int i;
char *p;
p = (char *)s;
i = 0;
while (i < n)
{
p[i] = c;
i++;
}
return (s);
}

Binary file not shown.

View File

@ -1,52 +0,0 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/04 08:03:00 by tomoron #+# #+# #
# Updated: 2024/10/28 23:08:30 by tomoron ### ########.fr #
# #
# **************************************************************************** #
NAME = libftprintf.a
CC = cc
SRCS = ft_protected_atoi.c\
ft_convert.c\
ft_isdigit.c\
ft_parse_arg.c\
ft_print_hex_ptr.c\
ft_print_int.c\
ft_print_unsigned_int.c\
ft_printf.c\
ft_putchar.c\
ft_putstr.c\
ft_strlen.c\
ft_write_str_part.c
OBJS = $(SRCS:.c=.o)
FLAGS = -Wall -Wextra -Werror
$(NAME): $(OBJS)
ar rcs $(NAME) $(OBJS)
.c.o:
$(CC) $(FLAGS) -c $< -o $@
all: $(NAME)
bonus: all
clean:
rm -f $(OBJS)
fclean: clean
rm -f $(NAME)
re: fclean all
.PHONY: bonus clean all re fclean

View File

@ -1,85 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_convert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 23:24:31 by tomoron #+# #+# */
/* Updated: 2023/11/07 23:55:33 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_fill_width(char c, int n)
{
int res;
res = n;
if (res < 0)
res = 0;
while (n > 0)
{
ft_putchar(c);
n--;
}
return (res);
}
size_t ft_print_char(int c, t_flags flags)
{
int res;
res = 0;
if (flags.min_width && !flags.left_justify)
res += ft_fill_width(' ', flags.min_width - 1);
res += ft_putchar((char)c);
if (flags.min_width && flags.left_justify)
res += ft_fill_width(' ', flags.min_width - 1);
return (res);
}
size_t ft_print_str(char *s, t_flags flags)
{
int nb_to_print;
int res;
res = 0;
if (!s && (flags.precision >= 6 || flags.precision == -1))
s = "(null)";
else if (!s)
s = "";
nb_to_print = ft_strlen(s);
if (flags.precision != -1 && nb_to_print > flags.precision)
nb_to_print = flags.precision;
if (flags.min_width && !flags.left_justify)
res += ft_fill_width(' ', flags.min_width - nb_to_print);
write(1, s, nb_to_print);
if (flags.min_width && flags.left_justify)
res += ft_fill_width(' ', flags.min_width - nb_to_print);
return (res + nb_to_print);
}
size_t ft_convert(char *s, t_flags flags, va_list args, int err)
{
if (*s == 'c')
return (ft_print_char(va_arg(args, int), flags));
else if (*s == 's')
return (ft_print_str(va_arg(args, char *), flags));
else if (*s == 'p')
return (ft_print_ptr(va_arg(args, void *), flags));
else if (*s == 'd' || *s == 'i')
return (ft_print_signed_int(va_arg(args, int), flags));
else if (*s == 'u')
return (ft_print_unsigned_int(va_arg(args, unsigned int), flags));
else if (*s == 'x')
return (ft_print_hex(va_arg(args, unsigned int), flags, 'L'));
else if (*s == 'X')
return (ft_print_hex(va_arg(args, unsigned int), flags, 'U'));
else if (*s == '%')
return (ft_putstr("%"));
else if (err != 2)
return (ft_putstr("%"));
else
return (0);
}

Binary file not shown.

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/13 18:10:01 by tomoron #+# #+# */
/* Updated: 2023/10/30 12:13:53 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_isdigit(int c)
{
if (!(c >= '0' && c <= '9'))
return (0);
return (1);
}

Binary file not shown.

View File

@ -1,89 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_parse_arg.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 11:43:10 by tomoron #+# #+# */
/* Updated: 2023/11/15 14:32:59 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_is_char_in_flags(char *s, char c)
{
int i;
i = 0;
while (s[i] == '-' || s[i] == '0' || s[i] == '#'
|| s[i] == ' ' || s[i] == '+')
{
if (s[i] == c)
return (1);
i++;
}
return (0);
}
void ft_get_width_precision(char **s, va_list args, t_flags *flags, int *err)
{
if (**s == '*')
flags->min_width = va_arg(args, int);
else
flags->min_width = ft_protected_atoi(*s);
while (ft_isdigit(**s) || **s == '*')
(*s)++;
flags->precision = -1;
if (**s == '.' && *(*s + 1) == '*')
flags->precision = va_arg(args, int);
else if (**s == '.')
{
if (ft_isdigit(*(*s + 1)))
flags->precision = ft_protected_atoi(*s + 1);
else
flags->precision = 0;
(*s)++;
}
while (ft_isdigit(**s) || **s == '.' || **s == '*')
(*s)++;
if (flags->min_width == -2 || flags->precision == -2)
*err = 3;
}
void ft_get_flags(char **s, va_list args, t_flags *flags, int *err)
{
flags->left_justify = ft_is_char_in_flags(*s, '-');
flags->zero_padding = ft_is_char_in_flags(*s, '0');
flags->always_sign_number = ft_is_char_in_flags(*s, '+');
flags->blank_positive = ft_is_char_in_flags(*s, ' ');
flags->zero_x_prefix = ft_is_char_in_flags(*s, '#');
while (**s == '-' || **s == '0' || **s == '#'
|| **s == ' ' || **s == '+')
{
(*s)++;
}
return (ft_get_width_precision(s, args, flags, err));
}
size_t ft_parse_arg(char **s, va_list args, int *err)
{
t_flags flags;
size_t res;
res = 0;
if (**s == '%')
{
(*s)++;
ft_get_flags(s, args, &flags, err);
if (*err == 3)
return (0);
res += ft_convert(*s, flags, args, *err);
if (**s == 'c' || **s == 's' || **s == 'p' || **s == 'd'
|| **s == 'i' || **s == 'u' || **s == 'x'
|| **s == 'X' || **s == '%')
(*s)++;
}
return (res);
}

View File

@ -1,97 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_hex_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 15:58:57 by tomoron #+# #+# */
/* Updated: 2023/11/05 15:58:58 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_calc_hex_len(long unsigned int n, t_flags flags)
{
int res;
res = 1;
if (n == 0 && flags.precision == 0)
return (0);
while (n > 15)
{
res++;
n /= 16;
}
return (res);
}
void ft_put_hex(unsigned long int n, char mode)
{
if (n > 15)
ft_put_hex(n / 16, mode);
if (mode == 'L')
write(1, &"0123456789abcdef"[n % 16], 1);
if (mode == 'U')
write(1, &"0123456789ABCDEF"[n % 16], 1);
}
size_t ft_print_ptr(void *ptr, t_flags flags)
{
int len;
int res;
res = 0;
if (!ptr)
return (ft_print_str("(nil)", flags));
len = ft_calc_hex_len((long unsigned int)ptr, flags) + 2;
if (flags.min_width && !flags.left_justify)
res += ft_fill_width(' ', flags.min_width - len);
ft_putstr("0x");
ft_put_hex((unsigned long int)ptr, 'L');
if (flags.min_width && flags.left_justify)
res += ft_fill_width(' ', flags.min_width - len);
return (res + len);
}
size_t ft_write_blank(int blank_len, t_flags flags, char mode)
{
size_t res;
res = 0;
if (blank_len > 0 && ((flags.left_justify && mode == 'A')
|| (!flags.left_justify && mode == 'B')))
{
if (flags.zero_padding && flags.precision == -1)
res += ft_fill_width('0', blank_len);
else
res += ft_fill_width(' ', blank_len);
}
return (res);
}
size_t ft_print_hex(unsigned int nb, t_flags flags, char mode)
{
int blank_len;
int zero_len;
int number_len;
size_t res;
number_len = ft_calc_hex_len(nb, flags);
res = number_len;
zero_len = 0;
if (flags.precision > number_len)
zero_len = flags.precision - number_len;
blank_len = flags.min_width - zero_len - number_len;
blank_len -= flags.zero_x_prefix * 2;
res += ft_write_blank(blank_len, flags, 'B');
if (flags.zero_x_prefix && nb && mode == 'L')
res += ft_putstr("0x");
if (flags.zero_x_prefix && nb && mode == 'U')
res += ft_putstr("0X");
res += ft_fill_width('0', zero_len);
if (flags.precision != 0 || nb != 0)
ft_put_hex(nb, mode);
res += ft_write_blank(blank_len, flags, 'A');
return (res);
}

View File

@ -1,99 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_int.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 15:52:46 by tomoron #+# #+# */
/* Updated: 2023/11/05 15:53:56 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_calc_signed_int_len(int nb, t_flags flags)
{
int res;
long int n;
res = 1;
n = (long int) nb;
if (flags.precision == 0 && nb == 0)
return (0);
if (n < 0)
{
n = n * -1;
}
while (n > 9)
{
res++;
n /= 10;
}
return (res);
}
size_t ft_putsign(int nb, t_flags flags, int sign)
{
if (nb < 0)
return (ft_putchar('-'));
if (sign && flags.blank_positive)
return (ft_putchar(' '));
if (sign)
return (ft_putchar('+'));
return (0);
}
int ft_print_signed_int_blank_sign(int nb, t_flags flags, size_t *res)
{
int blank_len;
int zero_len;
int number_len;
int sign;
number_len = ft_calc_signed_int_len(nb, flags);
sign = (nb < 0) || flags.always_sign_number || flags.blank_positive;
zero_len = 0;
if (flags.precision > number_len)
zero_len = flags.precision - number_len;
blank_len = flags.min_width - zero_len - number_len - sign;
if (blank_len > 0 && !flags.left_justify && ((!flags.zero_padding
&& nb != 0) || (flags.zero_padding && flags.precision != -1)))
*res += ft_fill_width(' ', blank_len);
*res += ft_putsign(nb, flags, sign);
if (blank_len > 0 && !flags.left_justify && flags.zero_padding
&& flags.precision == -1)
*res += ft_fill_width('0', blank_len);
*res += ft_fill_width('0', zero_len);
return (blank_len);
}
void ft_put_lu_nbr(long unsigned int nb)
{
if (nb > 9)
ft_put_lu_nbr(nb / 10);
ft_putchar("0123456789"[nb % 10]);
}
size_t ft_print_signed_int(int nb, t_flags flags)
{
int blank_len;
long int n;
size_t res;
res = ft_calc_signed_int_len(nb, flags);
n = (long int)nb;
if (n < 0)
n *= -1;
blank_len = ft_print_signed_int_blank_sign(nb, flags, &res);
if (flags.precision != 0 || nb != 0)
ft_put_lu_nbr((long unsigned int)n);
if (blank_len > 0 && flags.left_justify)
{
if (flags.zero_padding)
res += ft_fill_width('0', blank_len);
else
res += ft_fill_width(' ', blank_len);
}
return (res);
}

View File

@ -1,55 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_unsigned_int.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/05 16:06:48 by tomoron #+# #+# */
/* Updated: 2023/11/05 16:06:49 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_calc_unsigned_int_len(unsigned int nb, t_flags flags)
{
int res;
res = 1;
if (nb == 0 && flags.precision == 0)
return (0);
while (nb > 9)
{
res++;
nb /= 10;
}
return (res);
}
size_t ft_print_unsigned_int(unsigned int nb, t_flags flags)
{
int blank_len;
int zero_len;
int number_len;
size_t res;
number_len = ft_calc_unsigned_int_len(nb, flags);
res = number_len;
zero_len = 0;
if (flags.precision > number_len)
zero_len = flags.precision - number_len;
blank_len = flags.min_width - zero_len - number_len;
if (blank_len > 0 && !flags.left_justify && flags.zero_padding
&& flags.precision == -1)
res += ft_fill_width('0', blank_len);
else if (blank_len > 0 && !flags.left_justify)
res += ft_fill_width(' ', blank_len);
res += ft_fill_width('0', zero_len);
if (flags.precision != 0 || nb != 0)
ft_put_lu_nbr(nb);
if (blank_len > 0 && flags.left_justify && flags.zero_padding)
res += ft_fill_width('0', blank_len);
else if (blank_len > 0 && flags.left_justify)
res += ft_fill_width(' ', blank_len);
return (res);
}

View File

@ -1,67 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 23:41:38 by tomoron #+# #+# */
/* Updated: 2023/11/08 14:51:19 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_check_placeholders(const char *str)
{
int err;
err = 0;
while (*str)
{
while (*str && *str != '%')
str++;
if (*str == '%')
{
str++;
while (*str == '-' || *str == '0' || *str == '#'
|| *str == ' ' || *str == '+' || ft_isdigit(*str))
str++;
if (*str != 'c' && *str != 's' && *str != 'p' && *str != 'd'
&& *str && *str != 'i' && *str != 'u' && *str != 'x'
&& *str != 'X' && *str != '%')
err = 1;
if (!*str && err == 0)
err = 2;
if (*str == '%')
str++;
}
}
return (err);
}
int ft_printf(const char *str, ...)
{
va_list args;
size_t res;
char *s;
int err;
if (!str)
return (-1);
va_start(args, str);
res = 0;
s = (char *)str;
err = ft_check_placeholders(s);
res += ft_write_str_part(&s);
while (*s)
{
res += ft_parse_arg(&s, args, &err);
if (err == 3)
break ;
res += ft_write_str_part(&s);
}
va_end(args);
if (err >= 2)
return (-1);
return (res);
}

View File

@ -1,46 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/02 23:42:00 by tomoron #+# #+# */
/* Updated: 2023/11/15 14:31:34 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <stdarg.h>
# include <unistd.h>
typedef struct s_flags
{
int left_justify;
int zero_padding;
int always_sign_number;
int blank_positive;
int zero_x_prefix;
int min_width;
int precision;
} t_flags;
int ft_printf(const char *str, ...);
size_t ft_write_str_part(char **s);
size_t ft_parse_arg(char **s, va_list args, int *err);
size_t ft_convert(char *s, t_flags flags, va_list args, int err);
size_t ft_putchar(char c);
size_t ft_putstr(char *s);
size_t ft_strlen(char const *s);
int ft_protected_atoi(const char *s);
int ft_isdigit(int c);
size_t ft_print_unsigned_int(unsigned int nb, t_flags flags);
size_t ft_print_signed_int(int nb, t_flags flags);
size_t ft_fill_width(char c, int n);
size_t ft_print_hex(unsigned int nb, t_flags flags, char mode);
size_t ft_print_ptr(void *ptr, t_flags flags);
size_t ft_print_str(char *s, t_flags flags);
void ft_put_lu_nbr(long unsigned int nb);
#endif

Binary file not shown.

View File

@ -1,37 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/17 13:41:15 by tomoron #+# #+# */
/* Updated: 2023/11/15 14:31:19 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
int ft_protected_atoi(const char *str)
{
long long res;
int inv;
res = 0;
inv = 1;
while (*str == ' ' || (*str >= '\t' && *str <= '\r'))
str++;
if (*str == '+' || *str == '-')
{
if (*str == '-')
inv *= -1;
str++;
}
while (*str >= '0' && *str <= '9')
{
res *= 10;
res += *str - '0';
str++;
}
if (res > 2147483647)
return (-2);
return ((int)res * inv);
}

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 04:10:53 by tomoron #+# #+# */
/* Updated: 2023/11/05 15:51:33 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_putchar(char c)
{
write(1, &c, 1);
return (1);
}

Binary file not shown.

View File

@ -1,19 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */
/* Updated: 2023/11/05 14:42:32 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_putstr(char *s)
{
if (s)
write(1, s, ft_strlen(s));
return (ft_strlen(s));
}

Binary file not shown.

View File

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:34:41 by tomoron #+# #+# */
/* Updated: 2023/11/04 08:19:20 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_strlen(const char *str)
{
unsigned int n;
n = 0;
while (str[n])
n++;
return (n);
}

Binary file not shown.

View File

@ -1,26 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_write_str_part.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 11:16:38 by tomoron #+# #+# */
/* Updated: 2023/11/05 15:50:41 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_write_str_part(char **s)
{
size_t i;
i = 0;
while ((*s)[i] != '%' && (*s)[i])
i++;
if (i)
write(1, *s, i);
*s += i;
return (i);
}

View File

@ -1,17 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 04:10:53 by tomoron #+# #+# */
/* Updated: 2024/10/29 20:36:57 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
(void) write(fd, &c, 1);
}

Binary file not shown.

View File

@ -1,21 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */
/* Updated: 2024/10/29 20:39:37 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
if (s)
{
write(fd, s, ft_strlen(s));
write(fd, "\n", 1);
}
}

Binary file not shown.

View File

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/11 23:27:29 by tomoron #+# #+# */
/* Updated: 2024/10/29 20:40:28 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int nb, int fd)
{
if (nb >= 10)
{
ft_putnbr_fd(nb / 10, fd);
ft_putchar_fd((nb % 10) + 48, fd);
}
else if (nb < 0)
{
if (nb == -2147483648)
write(fd, "-2147483648", 11);
else
{
ft_putchar_fd('-', fd);
ft_putnbr_fd(nb * -1, fd);
}
}
else
ft_putchar_fd((nb % 10) + 48, fd);
}

Binary file not shown.

View File

@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 04:13:29 by tomoron #+# #+# */
/* Updated: 2024/10/29 20:40:22 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
if (s)
write(fd, s, ft_strlen(s));
}

Binary file not shown.

View File

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_set_color.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/10 10:56:11 by tomoron #+# #+# */
/* Updated: 2024/01/10 14:10:42 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_set_color(int r, int g, int b)
{
ft_printf("\033[38;2;%d;%d;%dm", r, g, b);
}
void ft_reset_color(void)
{
ft_printf("\033[0m");
}

Binary file not shown.

View File

@ -1,73 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/25 10:30:03 by tomoron #+# #+# */
/* Updated: 2023/11/01 15:18:57 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_count_parts(char *str, char charset)
{
int res;
res = 0;
while (*str == charset && *str)
str++;
while (*str)
{
while (!(*str == charset) && *str)
str++;
while (*str == charset && *str)
str++;
res++;
}
return (res + 1);
}
static int ft_strlen_sep(char *str, char charset)
{
int res;
res = 0;
while (*str && !(*str == charset))
{
res++;
str++;
}
return (res + 1);
}
char **ft_split(const char *str, char charset)
{
int nb_str;
char **res;
int i;
int j;
if (!str)
return (0);
nb_str = ft_count_parts((char *)str, charset);
res = (char **)malloc(nb_str * sizeof(char *));
i = -1;
while (res && *str && *str == charset)
str++;
while (++i < nb_str - 1 && *str && res)
{
res[i] = malloc(ft_strlen_sep((char *)str, charset));
j = 0;
while (res[i] && *str && !(*str == charset))
res[i][j++] = *(str++);
res[i][j] = 0;
while (*str == charset)
str++;
}
if (res)
res[i] = 0;
return (res);
}

Binary file not shown.

View File

@ -1,84 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split_set.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/25 10:30:03 by tomoron #+# #+# */
/* Updated: 2023/11/21 15:37:48 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_is_sep(char c, char *sep)
{
while (*sep)
{
if (*sep == c)
return (1);
sep++;
}
return (0);
}
int ft_count_parts(char *str, char *charset)
{
int res;
res = 0;
while (ft_is_sep(*str, charset) && *str)
str++;
while (*str)
{
while (!ft_is_sep(*str, charset) && *str)
str++;
while (ft_is_sep(*str, charset) && *str)
str++;
res++;
}
return (res + 1);
}
int ft_strlen_sep(char *str, char *charset)
{
int res;
res = 0;
while (*str && !ft_is_sep(*str, charset))
{
res++;
str++;
}
return (res + 1);
}
char **ft_split_set(char *str, char *charset)
{
int str_len;
int nb_str;
char **res;
int i;
int j;
nb_str = ft_count_parts(str, charset);
res = (char **)malloc(nb_str * sizeof(char *));
i = -1;
while (ft_is_sep(*str, charset))
str++;
while (++i < nb_str - 1 && *str && res)
{
str_len = ft_strlen_sep(str, charset);
res[i] = malloc(str_len * sizeof(char));
j = 0;
while (res[i] && *str && !ft_is_sep(*str, charset))
res[i][j++] = *(str++);
res[i][j] = 0;
while (ft_is_sep(*str, charset))
str++;
}
if (res)
res[i] = 0;
return (res);
}

Binary file not shown.

View File

@ -1,30 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 13:35:44 by tomoron #+# #+# */
/* Updated: 2023/11/02 11:08:17 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *s, int c)
{
int i;
char *res;
i = 0;
res = (char *)s;
while (res[i])
{
if (res[i] == (unsigned char)c)
return (res + i);
i++;
}
if (res[i] == (unsigned char)c)
return (res + i);
return (NULL);
}

Binary file not shown.

View File

@ -1,34 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/15 21:47:47 by tomoron #+# #+# */
/* Updated: 2023/12/03 17:06:39 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t n)
{
unsigned int i;
i = 0;
if (!n)
return (0);
while (s1[i] == s2[i] && s1[i] && i < n - 1)
i++;
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
}
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && s1[i])
i++;
return (s1[i] - s2[i]);
}

Binary file not shown.

View File

@ -1,36 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/24 14:55:26 by tomoron #+# #+# */
/* Updated: 2023/11/02 11:13:46 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *src)
{
char *res;
int len;
int i;
len = 0;
i = 0;
if (!src)
return (0);
while (src[len])
len++;
res = (char *)malloc((len + 1) * sizeof(char));
if (!res)
return (0);
while (src[i])
{
res[i] = src[i];
i++;
}
res[i] = 0;
return (res);
}

Binary file not shown.

View File

@ -1,23 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_striteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 04:08:53 by tomoron #+# #+# */
/* Updated: 2023/11/01 14:04:59 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
void ft_striteri(char *s, void (*f)(unsigned int, char*))
{
int i;
i = 0;
while (s && s[i])
{
f(i, s + i);
i++;
}
}

Binary file not shown.

View File

@ -1,63 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/24 18:06:14 by tomoron #+# #+# */
/* Updated: 2023/11/02 10:26:09 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int calc_str_len(char const *s1, char const *s2)
{
int res;
int i;
res = 0;
i = 0;
while (s1[i])
{
i++;
res++;
}
i = 0;
while (s2[i])
{
i++;
res++;
}
return (res);
}
char *ft_strjoin(char const *s1, char const *s2)
{
char *res;
int len;
int i;
int j;
j = 0;
if (!s1 || !s2)
return (0);
len = calc_str_len(s1, s2);
res = malloc((len + 1) * sizeof(char));
while (res && s1[j])
{
res[j] = s1[j];
j++;
}
i = 0;
while (res && s2[i])
{
res[j] = s2[i];
i++;
j++;
}
if (res)
res[j] = 0;
return (res);
}

Binary file not shown.

View File

@ -1,38 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/16 03:16:22 by tomoron #+# #+# */
/* Updated: 2023/11/02 10:47:42 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
unsigned int dst_len;
unsigned int i;
unsigned int ret_val;
if (!dst || !src)
return (0);
dst_len = ft_strlen(dst);
if (!size)
return (ft_strlen(src));
if (size < dst_len)
return (ft_strlen(src) + size);
i = 0;
ret_val = dst_len + ft_strlen(src);
while (src[i] && size > dst_len + 1)
{
dst[dst_len] = src[i];
i++;
dst_len++;
}
dst[dst_len] = 0;
return (ret_val);
}

Binary file not shown.

View File

@ -1,32 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/14 01:08:34 by tomoron #+# #+# */
/* Updated: 2023/10/31 18:26:25 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t 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)
{
dest[i] = src[i];
i++;
}
if (i == size)
dest[i - 1] = 0;
else
dest[i] = 0;
return (ft_strlen(src));
}

Binary file not shown.

View File

@ -1,22 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/30 12:34:41 by tomoron #+# #+# */
/* Updated: 2023/10/31 14:53:10 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlen(const char *str)
{
unsigned int n;
n = 0;
while (str[n])
n++;
return (n);
}

Binary file not shown.

View File

@ -1,33 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tomoron <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/01 03:54:38 by tomoron #+# #+# */
/* Updated: 2023/11/01 14:06:34 by tomoron ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
char *res;
i = 0;
if (!s)
return (0);
res = malloc((ft_strlen(s) + 1) * sizeof(char));
if (!res)
return (res);
while (s[i])
{
res[i] = f(i, s[i]);
i++;
}
res[i] = 0;
return (res);
}

Some files were not shown because too many files have changed in this diff Show More