adding lib, need to edit and delete cringe 42 things
:
This commit is contained in:
commit
6daf0df08a
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
build
|
||||||
|
*.a
|
27
Makefile
Normal file
27
Makefile
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
CC := gcc
|
||||||
|
LIB := libft/libft.a ft_printf/libft_printf.a
|
||||||
|
DIR := .
|
||||||
|
NAME := lib.a
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
@make --no-print -C libft
|
||||||
|
@make --no-print -C ft_printf
|
||||||
|
@ar -rcT $(NAME) $(LIB)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@make --no-print -C libft clean
|
||||||
|
@make --no-print -C ft_printf clean
|
||||||
|
@rm -rf $(OBJ_DIR)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@make --no-print -C libft fclean
|
||||||
|
@make --no-print -C ft_printf fclean
|
||||||
|
@rm -f $(DIR)/$(NAME)
|
||||||
|
|
||||||
|
re:
|
||||||
|
@make --no-print fclean
|
||||||
|
@make --no-print all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re
|
28
ft_printf/Makefile
Normal file
28
ft_printf/Makefile
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
CC := gcc
|
||||||
|
CFLAGS := $(shell cat compile_flags.txt | sed -z "s/\n/ /g")
|
||||||
|
SRC := $(wildcard *.c)
|
||||||
|
OBJ_DIR := build
|
||||||
|
OBJ := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(SRC)))
|
||||||
|
DIR := .
|
||||||
|
NAME := libft_printf.a
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
@ar -rcT $(NAME) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: %.c
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf $(OBJ_DIR)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(DIR)/$(NAME)
|
||||||
|
|
||||||
|
re:
|
||||||
|
@make --no-print clean
|
||||||
|
@make --no-print all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re
|
4
ft_printf/compile_flags.txt
Normal file
4
ft_printf/compile_flags.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
-include../libft/libft.h
|
||||||
|
-includeft_printf.h
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
62
ft_printf/ft_printf.c
Normal file
62
ft_printf/ft_printf.c
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
static u32
|
||||||
|
ft_is_format(const char c) {
|
||||||
|
return (c == 'c' || c == 's' || c == 'p' || c == 'i' || c == 'd'
|
||||||
|
|| c == 'u' || c == 'x' || c == 'X' || c == '%' || c == 'b');
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32
|
||||||
|
ft_post_character(u32 fd, char format, va_list args) {
|
||||||
|
if (format == 'c')
|
||||||
|
return ft_putchar_fd(va_arg(args, int), fd);
|
||||||
|
else if (format == 's')
|
||||||
|
return ft_putstr_fd(va_arg(args, char *), fd);
|
||||||
|
else if (format == 'd' || format == 'i' || format == 'u')
|
||||||
|
return ft_putnbr_fd(va_arg(args, i64), fd);
|
||||||
|
else if (format == 'x')
|
||||||
|
return ft_putnbrhex_fd(va_arg(args, u32), fd);
|
||||||
|
else if (format == 'X')
|
||||||
|
return ft_putnbrhex_upper_fd(va_arg(args, u32), fd);
|
||||||
|
else if (format == '%')
|
||||||
|
return ft_putchar_fd('%', fd);
|
||||||
|
else if (format == 'p')
|
||||||
|
return ft_putvd_fd(va_arg(args, void *), fd);
|
||||||
|
else if (format == 'b')
|
||||||
|
return ft_putstr_fd(va_arg(args, i32) ? "true" : "false", fd);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32
|
||||||
|
ft_vdprintf(u32 fd, const char *str, va_list args) {
|
||||||
|
u32 count = 0;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
|
return (-1);
|
||||||
|
for (u32 i = 0; str[i]; i++) {
|
||||||
|
if (str[i] == '%' && ft_is_format(str[i + 1]))
|
||||||
|
count += ft_post_character(fd, str[(i++) + 1], args);
|
||||||
|
else {
|
||||||
|
ft_putchar_fd(str[i], fd);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
|
|
||||||
|
u32
|
||||||
|
ft_printf_fd(u32 fd, const char *str, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, str);
|
||||||
|
u32 count = ft_vdprintf(fd, str, args);
|
||||||
|
va_end(args);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
u32
|
||||||
|
ft_printf(const char *str, ...) {
|
||||||
|
va_list args;
|
||||||
|
va_start(args, str);
|
||||||
|
u32 count = ft_vdprintf(1, str, args);
|
||||||
|
va_end(args);
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
12
ft_printf/ft_printf.h
Normal file
12
ft_printf/ft_printf.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# pragma once
|
||||||
|
|
||||||
|
# include <stddef.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
u32 ft_printf(const char *str, ...);
|
||||||
|
u32 ft_printf_fd(u32 fd, const char *str, ...);
|
||||||
|
u32 ft_vdprintf(u32 fd, const char *str, va_list args);
|
||||||
|
u32 ft_putnbrhex_fd(u32 v, u32 fd);
|
||||||
|
u32 ft_putnbrhex_upper_fd(u32 v, u32 fd);
|
||||||
|
u32 ft_putvd_fd(void *v, u32 fd);
|
20
ft_printf/ft_putnbrhex_fd.c
Normal file
20
ft_printf/ft_putnbrhex_fd.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
u32
|
||||||
|
ft_putnbrhex_fd(u32 v, u32 fd) {
|
||||||
|
i32 tmp = 0, count = 0;
|
||||||
|
char hex[100];
|
||||||
|
|
||||||
|
if (v == 0)
|
||||||
|
return ft_putchar_fd('0', fd);
|
||||||
|
while (v > 0) {
|
||||||
|
tmp = v % 16;
|
||||||
|
if (tmp < 10)
|
||||||
|
hex[count++] = (tmp + 48);
|
||||||
|
else
|
||||||
|
hex[count++] = (tmp + 87);
|
||||||
|
v = v / 16;
|
||||||
|
}
|
||||||
|
tmp = count;
|
||||||
|
while (--tmp >= 0)
|
||||||
|
ft_putchar_fd(hex[tmp], fd);
|
||||||
|
return (count);
|
||||||
|
}
|
21
ft_printf/ft_putnbrhex_upper_fd.c
Normal file
21
ft_printf/ft_putnbrhex_upper_fd.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
u32
|
||||||
|
ft_putnbrhex_upper_fd(u32 v, u32 fd)
|
||||||
|
{
|
||||||
|
i32 tmp = 0, count = 0;
|
||||||
|
char hex[100];
|
||||||
|
|
||||||
|
if (v == 0)
|
||||||
|
return ft_putchar_fd('0', fd);
|
||||||
|
while (v > 0) {
|
||||||
|
tmp = v % 16;
|
||||||
|
if (tmp < 10)
|
||||||
|
hex[count++] = (tmp + 48);
|
||||||
|
else
|
||||||
|
hex[count++] = (tmp + 55);
|
||||||
|
v = v / 16;
|
||||||
|
}
|
||||||
|
tmp = count;
|
||||||
|
while (--tmp >= 0)
|
||||||
|
ft_putchar_fd(hex[tmp], fd);
|
||||||
|
return (count);
|
||||||
|
}
|
13
ft_printf/ft_putvd_fd.c
Normal file
13
ft_printf/ft_putvd_fd.c
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
u32
|
||||||
|
ft_putvd_fd(void *v, u32 fd) {
|
||||||
|
u32 count;
|
||||||
|
u64 u;
|
||||||
|
|
||||||
|
if (v == NULL)
|
||||||
|
return (ft_putstr_fd("(nil)", fd));
|
||||||
|
u = (u64)v;
|
||||||
|
count = 2;
|
||||||
|
ft_putstr_fd("0x", fd);
|
||||||
|
count += ft_putnbrhex_fd(u, fd);
|
||||||
|
return (count);
|
||||||
|
}
|
28
libft/Makefile
Normal file
28
libft/Makefile
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
CC := gcc
|
||||||
|
CFLAGS := $(shell cat compile_flags.txt | sed -z "s/\n/ /g")
|
||||||
|
SRC := $(wildcard *.c)
|
||||||
|
OBJ_DIR := build
|
||||||
|
OBJ := $(addprefix $(OBJ_DIR)/, $(patsubst %.c,%.o,$(SRC)))
|
||||||
|
DIR := .
|
||||||
|
NAME := libft.a
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJ)
|
||||||
|
@ar -rc $(NAME) $(OBJ)
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: %.c
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -rf $(OBJ_DIR)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(DIR)/$(NAME)
|
||||||
|
|
||||||
|
re:
|
||||||
|
@make --no-pri32 clean
|
||||||
|
@make --no-pri32 all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re
|
3
libft/compile_flags.txt
Normal file
3
libft/compile_flags.txt
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
-includelibft.h
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
48
libft/ft_atoi.c
Normal file
48
libft/ft_atoi.c
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 22:44:20 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static i32 ft_isspace(char c)
|
||||||
|
{
|
||||||
|
if (c == ' ' || c == '\f'
|
||||||
|
||c == '\n' || c == '\r' || c == '\t' || c == '\v')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 ft_atoi(const char *nptr)
|
||||||
|
{
|
||||||
|
i64 result;
|
||||||
|
i32 sign;
|
||||||
|
|
||||||
|
while (ft_isspace(*nptr))
|
||||||
|
nptr++;
|
||||||
|
sign = 1;
|
||||||
|
if (*nptr == '+' || *nptr == '-')
|
||||||
|
{
|
||||||
|
if (*nptr == '-')
|
||||||
|
sign = -1;
|
||||||
|
nptr++;
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
while (*nptr >= '0' && *nptr <= '9')
|
||||||
|
{
|
||||||
|
if (result >= 2147483647 && sign == 1)
|
||||||
|
return (-1);
|
||||||
|
else if (result >= 2147483647)
|
||||||
|
return (0);
|
||||||
|
result = result * 10 + *nptr - '0';
|
||||||
|
nptr++;
|
||||||
|
}
|
||||||
|
return (result * sign);
|
||||||
|
}
|
50
libft/ft_atoi_check.c
Normal file
50
libft/ft_atoi_check.c
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoi_check.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/21 08:21:05 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/12/08 16:37:19 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static i32 ft_isspace(char c)
|
||||||
|
{
|
||||||
|
if (c == ' ' || c == '\f'
|
||||||
|
||c == '\n' || c == '\r' || c == '\t' || c == '\v')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
i32 ft_atoi_check(const char *nptr)
|
||||||
|
{
|
||||||
|
i64 result;
|
||||||
|
i32 sign;
|
||||||
|
|
||||||
|
while (ft_isspace(*nptr))
|
||||||
|
nptr++;
|
||||||
|
sign = 1;
|
||||||
|
if (*nptr == '+' || *nptr == '-')
|
||||||
|
{
|
||||||
|
if (*nptr == '-')
|
||||||
|
sign = -1;
|
||||||
|
nptr++;
|
||||||
|
}
|
||||||
|
result = 0;
|
||||||
|
while (*nptr >= '0' && *nptr <= '9')
|
||||||
|
{
|
||||||
|
result = result * 10 + *nptr++ - '0';
|
||||||
|
if ((result > 2147483647 && sign == 1)
|
||||||
|
|| (result > 2147483648 && sign == -1))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (*nptr--)
|
||||||
|
return (0);
|
||||||
|
if (*nptr == '-' || *nptr == '+')
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
18
libft/ft_bzero.c
Normal file
18
libft/ft_bzero.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_bzero.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/26 15:21:33 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/26 15:31:11 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_bzero(void *s, unsigned i32 n)
|
||||||
|
{
|
||||||
|
ft_memset(s, 0, n);
|
||||||
|
}
|
28
libft/ft_calloc.c
Normal file
28
libft/ft_calloc.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_calloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/28 16:21:44 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 14:17:31 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_calloc(size_t nitems, size_t size)
|
||||||
|
{
|
||||||
|
size_t *tmp;
|
||||||
|
|
||||||
|
if (nitems == 0 || size == 0)
|
||||||
|
return (malloc(0));
|
||||||
|
if (nitems * size < nitems)
|
||||||
|
return (NULL);
|
||||||
|
tmp = malloc(nitems * size);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return (NULL);
|
||||||
|
ft_bzero(tmp, nitems * size);
|
||||||
|
return (tmp);
|
||||||
|
}
|
29
libft/ft_get_size.c
Normal file
29
libft/ft_get_size.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_get_size.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/10 22:50:35 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 22:14:29 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
i32 ft_get_size(i64 n)
|
||||||
|
{
|
||||||
|
i64 i;
|
||||||
|
|
||||||
|
if (n == 0)
|
||||||
|
return (1);
|
||||||
|
i = 0;
|
||||||
|
n *= (n > 0) - (n < 0);
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
n = n / 10;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
20
libft/ft_isalnum.c
Normal file
20
libft/ft_isalnum.c
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalnum.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/26 16:47:30 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/26 16:50:25 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
i32 ft_isalnum(i32 c)
|
||||||
|
{
|
||||||
|
if (!(c >= 'A' && c <= 'Z'))
|
||||||
|
if (!(c >= 'a' && c <= 'z'))
|
||||||
|
if (!(c >= '0' && c <= '9'))
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
19
libft/ft_isalpha.c
Normal file
19
libft/ft_isalpha.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalpha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/17 17:34:33 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/26 14:40:50 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
i32 ft_isalpha(i32 c)
|
||||||
|
{
|
||||||
|
if (!(c >= 'A' && c <= 'Z'))
|
||||||
|
if (!(c >= 'a' && c <= 'z'))
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
18
libft/ft_isascii.c
Normal file
18
libft/ft_isascii.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isascii.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/17 18:06:14 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/26 14:36:18 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
i32 ft_isascii(i32 c)
|
||||||
|
{
|
||||||
|
if (c >= 0 && c <= 127)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
18
libft/ft_isdigit.c
Normal file
18
libft/ft_isdigit.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isdigit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/17 18:06:14 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/26 14:41:48 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
i32 ft_isdigit(i32 c)
|
||||||
|
{
|
||||||
|
if (c > 47 && c < 58)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
18
libft/ft_isprint.c
Normal file
18
libft/ft_isprint.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_ispri32.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/17 18:24:36 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/07/17 18:27:27 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
i32 ft_ispri32(i32 c)
|
||||||
|
{
|
||||||
|
if (c >= 32 && c <= 126)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
54
libft/ft_itoa.c
Normal file
54
libft/ft_itoa.c
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_itoa.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/04 17:12:52 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/26 16:00:48 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static void ft_itoa_bis(char *str, i32 len, i32 i, i64 nl)
|
||||||
|
{
|
||||||
|
while (len > 1)
|
||||||
|
{
|
||||||
|
len--;
|
||||||
|
str[i] = (nl / ft_power(10, len) % 10) + 48;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
str[i] = nl % 10 + 48;
|
||||||
|
i++;
|
||||||
|
str[i] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_itoa(i32 n)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
i32 len;
|
||||||
|
i32 i;
|
||||||
|
i64 nl;
|
||||||
|
|
||||||
|
nl = n;
|
||||||
|
if (nl < 0)
|
||||||
|
nl *= -1;
|
||||||
|
len = ft_get_size(nl);
|
||||||
|
i = 0;
|
||||||
|
if (n < 0)
|
||||||
|
{
|
||||||
|
str = malloc(len + 2);
|
||||||
|
if (str == NULL)
|
||||||
|
return (NULL);
|
||||||
|
str[i] = '-';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
str = malloc(len + 1);
|
||||||
|
if (str == NULL)
|
||||||
|
return (NULL);
|
||||||
|
ft_itoa_bis(str, len, i, nl);
|
||||||
|
return (str);
|
||||||
|
}
|
21
libft/ft_lstadd_back.c
Normal file
21
libft/ft_lstadd_back.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_back.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/09 23:14:10 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/09 23:22:24 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||||
|
{
|
||||||
|
if (*lst != NULL)
|
||||||
|
ft_lstlast(*lst)->next = new;
|
||||||
|
else
|
||||||
|
*lst = new;
|
||||||
|
}
|
19
libft/ft_lstadd_front.c
Normal file
19
libft/ft_lstadd_front.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_front.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/09 21:43:39 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/09 22:02:22 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||||
|
{
|
||||||
|
new->next = *lst;
|
||||||
|
*lst = new;
|
||||||
|
}
|
27
libft/ft_lstclear.c
Normal file
27
libft/ft_lstclear.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstclear.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/09 23:56:15 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 22:13:45 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstclear(t_list **lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
t_list *temp;
|
||||||
|
|
||||||
|
if (lst == NULL || del == NULL)
|
||||||
|
return ;
|
||||||
|
while (*lst != NULL)
|
||||||
|
{
|
||||||
|
temp = (*lst)->next;
|
||||||
|
ft_lstdelone(*lst, del);
|
||||||
|
*lst = temp;
|
||||||
|
}
|
||||||
|
}
|
21
libft/ft_lstdelone.c
Normal file
21
libft/ft_lstdelone.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstdelone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/09 23:22:38 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 22:15:03 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
if (lst == NULL || del == NULL)
|
||||||
|
return ;
|
||||||
|
del(lst->content);
|
||||||
|
free(lst);
|
||||||
|
}
|
22
libft/ft_lstiter.c
Normal file
22
libft/ft_lstiter.c
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstiter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/10 00:42:33 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/10 00:56:30 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||||
|
{
|
||||||
|
while (lst != NULL)
|
||||||
|
{
|
||||||
|
f(lst->content);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
}
|
25
libft/ft_lstlast.c
Normal file
25
libft/ft_lstlast.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstlast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/09 23:03:50 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 22:14:51 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstlast(t_list *lst)
|
||||||
|
{
|
||||||
|
t_list *current;
|
||||||
|
|
||||||
|
current = lst;
|
||||||
|
if (current == NULL)
|
||||||
|
return (NULL);
|
||||||
|
while (current->next != NULL)
|
||||||
|
current = current->next;
|
||||||
|
return (current);
|
||||||
|
}
|
42
libft/ft_lstmap.c
Normal file
42
libft/ft_lstmap.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstmap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/10 01:03:28 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/10 14:55:38 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *head;
|
||||||
|
t_list *new;
|
||||||
|
|
||||||
|
if (lst == NULL || f == NULL || del == NULL)
|
||||||
|
return (NULL);
|
||||||
|
new = ft_lstnew(f(lst->content));
|
||||||
|
if (new == NULL)
|
||||||
|
{
|
||||||
|
ft_lstclear(&new, del);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
head = new;
|
||||||
|
lst = lst->next;
|
||||||
|
while (lst != NULL)
|
||||||
|
{
|
||||||
|
new->next = ft_lstnew(f(lst->content));
|
||||||
|
if (new == NULL)
|
||||||
|
{
|
||||||
|
ft_lstclear(&head, del);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
new = new->next;
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (head);
|
||||||
|
}
|
25
libft/ft_lstnew.c
Normal file
25
libft/ft_lstnew.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstnew.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/09 21:34:58 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 22:13:33 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstnew(void *content)
|
||||||
|
{
|
||||||
|
t_list *list;
|
||||||
|
|
||||||
|
list = malloc(sizeof(t_list));
|
||||||
|
if (list == NULL)
|
||||||
|
return (NULL);
|
||||||
|
list->content = content;
|
||||||
|
list->next = NULL;
|
||||||
|
return (list);
|
||||||
|
}
|
25
libft/ft_lstremove_back.c
Normal file
25
libft/ft_lstremove_back.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static void delete(t_list **deleted, void (*del)(void*));
|
||||||
|
|
||||||
|
void ft_lstremove_back(t_list **lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
if (lst == NULL || del == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ((*lst)->next == NULL)
|
||||||
|
return delete(lst, del);
|
||||||
|
|
||||||
|
t_list *cur = *lst;
|
||||||
|
while (cur->next != NULL && cur->next->next != NULL)
|
||||||
|
cur = cur->next;
|
||||||
|
|
||||||
|
delete(&(cur->next), del);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void delete(t_list **deleted, void (*del)(void*)) {
|
||||||
|
del(*deleted);
|
||||||
|
free(*deleted);
|
||||||
|
*deleted = NULL;
|
||||||
|
}
|
13
libft/ft_lstremove_front.c
Normal file
13
libft/ft_lstremove_front.c
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstremove_front(t_list **lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
if (lst == NULL || del == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
t_list *next = (*lst)->next;
|
||||||
|
del(*lst);
|
||||||
|
free(*lst);
|
||||||
|
*lst = next;
|
||||||
|
}
|
26
libft/ft_lstsize.c
Normal file
26
libft/ft_lstsize.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstsize.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/09 22:59:07 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 22:14:41 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
i32 ft_lstsize(t_list *lst)
|
||||||
|
{
|
||||||
|
i32 size;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
while (lst != NULL)
|
||||||
|
{
|
||||||
|
size++;
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (size);
|
||||||
|
}
|
29
libft/ft_memchr.c
Normal file
29
libft/ft_memchr.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/27 19:02:18 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 02:19:17 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memchr(const void *memory_block, i32 searched_char, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
unsigned char *tmp;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
tmp = (unsigned char *)memory_block;
|
||||||
|
while (i < size)
|
||||||
|
{
|
||||||
|
if (tmp[i] == (unsigned char)searched_char)
|
||||||
|
return (&tmp[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
29
libft/ft_memcmp.c
Normal file
29
libft/ft_memcmp.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/27 19:18:16 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/05 14:45:03 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
i32 ft_memcmp(const void *poi32er1, const void *poi32er2, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
unsigned char *tmp1;
|
||||||
|
unsigned char *tmp2;
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
|
return (0);
|
||||||
|
tmp1 = (unsigned char *)poi32er1;
|
||||||
|
tmp2 = (unsigned char *)poi32er2;
|
||||||
|
i = 0;
|
||||||
|
while (i < size - 1 && tmp1[i] == tmp2[i])
|
||||||
|
i++;
|
||||||
|
return (tmp1[i] - tmp2[i]);
|
||||||
|
}
|
32
libft/ft_memcpy.c
Normal file
32
libft/ft_memcpy.c
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/26 15:32:11 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/27 06:36:02 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t s)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *tmp_dest;
|
||||||
|
const char *tmp_src;
|
||||||
|
|
||||||
|
if (dest == NULL && src == NULL)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
tmp_dest = dest;
|
||||||
|
tmp_src = src;
|
||||||
|
while (i < s)
|
||||||
|
{
|
||||||
|
tmp_dest[i] = tmp_src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
37
libft/ft_memmove.c
Normal file
37
libft/ft_memmove.c
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memmove.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/27 06:50:08 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/05 14:35:27 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t s)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *d;
|
||||||
|
const char *sc;
|
||||||
|
|
||||||
|
if (dest == NULL && src == NULL)
|
||||||
|
return (dest);
|
||||||
|
d = dest;
|
||||||
|
sc = src;
|
||||||
|
if (d < sc)
|
||||||
|
ft_memcpy(d, sc, s);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
i = s;
|
||||||
|
while (i > 0)
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
d[i] = sc[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
28
libft/ft_memset.c
Normal file
28
libft/ft_memset.c
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/26 14:46:33 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/15 23:31:18 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memset(void *ptr, i32 v, size_t count)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
tmp = ptr;
|
||||||
|
while (i < count)
|
||||||
|
{
|
||||||
|
tmp[i] = v;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (ptr);
|
||||||
|
}
|
30
libft/ft_power.c
Normal file
30
libft/ft_power.c
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_power.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/10 22:50:22 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/10 22:50:31 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
i32 ft_power(i32 nb, i32 power)
|
||||||
|
{
|
||||||
|
i32 i;
|
||||||
|
i32 new_nb;
|
||||||
|
|
||||||
|
if (power < 0)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
new_nb = 1;
|
||||||
|
while (i < power)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
new_nb *= nb;
|
||||||
|
}
|
||||||
|
return (new_nb);
|
||||||
|
}
|
18
libft/ft_putchar_fd.c
Normal file
18
libft/ft_putchar_fd.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putchar_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/05 00:21:56 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/05 00:31:51 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
i32 ft_putchar_fd(char c, i32 fd)
|
||||||
|
{
|
||||||
|
return write(fd, &c, 1);
|
||||||
|
}
|
25
libft/ft_putendl_fd.c
Normal file
25
libft/ft_putendl_fd.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putendl_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/05 00:48:29 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/10 22:14:10 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putendl_fd(char *s, i32 fd)
|
||||||
|
{
|
||||||
|
if (s == NULL)
|
||||||
|
return ;
|
||||||
|
while (*s)
|
||||||
|
{
|
||||||
|
ft_putchar_fd(*s, fd);
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
ft_putchar_fd('\n', fd);
|
||||||
|
}
|
25
libft/ft_putnbr_fd.c
Normal file
25
libft/ft_putnbr_fd.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/05 10:22:16 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/18 17:32:20 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
u32 ft_putnbr_fd(i64 n, i32 fd)
|
||||||
|
{
|
||||||
|
if (n < 0)
|
||||||
|
ft_putchar_fd('-', fd);
|
||||||
|
n = ABS(n);
|
||||||
|
i32 len = ft_get_size(n);
|
||||||
|
while (--len > 0)
|
||||||
|
ft_putchar_fd(n / ft_power(10, len) % 10 + 48, fd);
|
||||||
|
ft_putchar_fd(n % 10 + 48, fd);
|
||||||
|
return ft_get_size(n);
|
||||||
|
}
|
21
libft/ft_putstr_fd.c
Normal file
21
libft/ft_putstr_fd.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putstr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/05 00:32:38 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/10 22:13:50 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
i32 ft_putstr_fd(char *s, i32 fd)
|
||||||
|
{
|
||||||
|
i32 i = 0;
|
||||||
|
for (; s != NULL && s[i]; i++)
|
||||||
|
ft_putchar_fd(s[i], fd);
|
||||||
|
return i;
|
||||||
|
}
|
117
libft/ft_split.c
Normal file
117
libft/ft_split.c
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/28 09:52:05 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/12 16:14:08 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static i32 get_len_all(char const *s, char c)
|
||||||
|
{
|
||||||
|
i32 i;
|
||||||
|
i32 check;
|
||||||
|
i32 count;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
check = 0;
|
||||||
|
count = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
if (s[i] != c && check == 0)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
check = 1;
|
||||||
|
}
|
||||||
|
else if (s[i] == c && check == 1)
|
||||||
|
check = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static i32 get_len_next(char const *s, char c, i32 i)
|
||||||
|
{
|
||||||
|
i32 y;
|
||||||
|
i32 count;
|
||||||
|
|
||||||
|
y = i;
|
||||||
|
count = 0;
|
||||||
|
while (s[y] == c)
|
||||||
|
y++;
|
||||||
|
while (s[y] && s[y++] != c)
|
||||||
|
count++;
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void *ft_malloc_split(char **strs, i32 *iyx, char const *s, char c)
|
||||||
|
{
|
||||||
|
iyx[1]++;
|
||||||
|
strs[iyx[1]] = malloc(get_len_next(s, c, iyx[0]) + 1);
|
||||||
|
if (strs[iyx[1]] == NULL)
|
||||||
|
{
|
||||||
|
iyx[1]--;
|
||||||
|
while (iyx[1] >= 0)
|
||||||
|
{
|
||||||
|
free(strs[iyx[1]]);
|
||||||
|
iyx[1]--;
|
||||||
|
}
|
||||||
|
free(strs);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return ("");
|
||||||
|
}
|
||||||
|
|
||||||
|
static char **ft_split_bis(char const *s, char c, char **strs, i32 *iyx)
|
||||||
|
{
|
||||||
|
i32 boo;
|
||||||
|
|
||||||
|
boo = 0;
|
||||||
|
while (s[iyx[0]])
|
||||||
|
{
|
||||||
|
if (s[iyx[0]] != c)
|
||||||
|
{
|
||||||
|
if (boo == 0)
|
||||||
|
if (ft_malloc_split(strs, iyx, s, c) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
boo = 1;
|
||||||
|
strs[iyx[1]][iyx[2]] = s[iyx[0]];
|
||||||
|
iyx[2]++;
|
||||||
|
}
|
||||||
|
else if (boo == 1)
|
||||||
|
{
|
||||||
|
strs[iyx[1]][iyx[2]] = '\0';
|
||||||
|
iyx[2] = 0;
|
||||||
|
boo = 0;
|
||||||
|
}
|
||||||
|
iyx[0]++;
|
||||||
|
}
|
||||||
|
if (boo == 1)
|
||||||
|
strs[iyx[1]][iyx[2]] = '\0';
|
||||||
|
return (strs);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_split(char const *s, char c)
|
||||||
|
{
|
||||||
|
char **strs;
|
||||||
|
i32 iyx[3];
|
||||||
|
|
||||||
|
iyx[0] = 0;
|
||||||
|
iyx[1] = -1;
|
||||||
|
iyx[2] = 0;
|
||||||
|
if (s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
strs = malloc(sizeof(char *) * (get_len_all(s, c) + 1));
|
||||||
|
if (strs == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (ft_split_bis(s, c, strs, iyx) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
iyx[1]++;
|
||||||
|
strs[iyx[1]] = NULL;
|
||||||
|
return (strs);
|
||||||
|
}
|
6
libft/ft_strcat.c
Normal file
6
libft/ft_strcat.c
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strcat(char *dest, const char *src) {
|
||||||
|
ft_strcpy(dest + ft_strlen(dest), src);
|
||||||
|
return dest;
|
||||||
|
}
|
29
libft/ft_strchr.c
Normal file
29
libft/ft_strchr.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/09/27 10:05:58 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 02:22:26 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strchr(const char *str, i32 search)
|
||||||
|
{
|
||||||
|
i32 i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (str[i] || str[i] == (unsigned char)search)
|
||||||
|
{
|
||||||
|
if (str[i] == (unsigned char)search)
|
||||||
|
{
|
||||||
|
return ((char *)&str[i]);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
7
libft/ft_strcmp.c
Normal file
7
libft/ft_strcmp.c
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
i32 ft_strcmp(const char *s1, const char *s2) {
|
||||||
|
i32 i = 0;
|
||||||
|
for (; s1[i] != '\0' && s2[i] != '\0'; i++)
|
||||||
|
if (s1[i] != s2[i])
|
||||||
|
return s1[i] - s2[i];
|
||||||
|
return s1[i] - s2[i];
|
||||||
|
}
|
11
libft/ft_strcpy.c
Normal file
11
libft/ft_strcpy.c
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strcpy(char *dest, const char *src) {
|
||||||
|
while (*src) {
|
||||||
|
char c = *src++;
|
||||||
|
*dest++ = c;
|
||||||
|
if (c == '\0')
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
}
|
31
libft/ft_strdup.c
Normal file
31
libft/ft_strdup.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strdup.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/26 14:25:30 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/28 16:32:55 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strdup(const char *src)
|
||||||
|
{
|
||||||
|
char *src_copy;
|
||||||
|
i32 i;
|
||||||
|
|
||||||
|
src_copy = (char *)malloc(sizeof(char) * ft_strlen(src) + 1);
|
||||||
|
if (src_copy == NULL)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (src[i])
|
||||||
|
{
|
||||||
|
src_copy[i] = src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
src_copy[i] = '\0';
|
||||||
|
return (src_copy);
|
||||||
|
}
|
27
libft/ft_striteri.c
Normal file
27
libft/ft_striteri.c
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_striteri.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/04 23:17:51 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/10 22:14:20 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned i32, char*))
|
||||||
|
{
|
||||||
|
unsigned i32 i;
|
||||||
|
|
||||||
|
if (f == NULL || s == NULL)
|
||||||
|
return ;
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
f(i, &s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
29
libft/ft_strjoin.c
Normal file
29
libft/ft_strjoin.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/27 14:47:27 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/11 14:19:45 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
char *tmp;
|
||||||
|
i32 size;
|
||||||
|
|
||||||
|
if (s1 == NULL || s2 == NULL)
|
||||||
|
return (NULL);
|
||||||
|
size = ft_strlen(s1) + ft_strlen(s2) + 1;
|
||||||
|
tmp = malloc(size);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return (NULL);
|
||||||
|
ft_strlcpy(tmp, s1, size);
|
||||||
|
ft_strlcat(tmp, s2, size);
|
||||||
|
return (tmp);
|
||||||
|
}
|
26
libft/ft_strlcat.c
Normal file
26
libft/ft_strlcat.c
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcat.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/19 13:02:39 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/14 17:49:58 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t len_dest, len_src;
|
||||||
|
|
||||||
|
if (size == 0)
|
||||||
|
return (ft_strlen(src));
|
||||||
|
len_dest = ft_strlen(dest);
|
||||||
|
if (len_dest >= size)
|
||||||
|
return (ft_strlen(src) + (size));
|
||||||
|
len_src = ft_strlcpy(dest + len_dest, src, size - len_dest);
|
||||||
|
return (len_dest + len_src);
|
||||||
|
}
|
19
libft/ft_strlcats.c
Normal file
19
libft/ft_strlcats.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strlcats(u32 nbr_str, ...) {
|
||||||
|
va_list args;
|
||||||
|
u32 len = 0;
|
||||||
|
|
||||||
|
va_start(args, nbr_str);
|
||||||
|
for (u32 i = 0; i < nbr_str; i++)
|
||||||
|
len += ft_strlen(va_arg(args, char *));
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
va_start(args, nbr_str);
|
||||||
|
char *new_str = ft_calloc(len + 1, sizeof(char));
|
||||||
|
for (u32 i = 0; i < nbr_str; i++)
|
||||||
|
ft_strcat(new_str, va_arg(args, char *));
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
return new_str;
|
||||||
|
}
|
25
libft/ft_strlcpy.c
Normal file
25
libft/ft_strlcpy.c
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/17 19:03:49 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/05 14:37:25 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
u32 ft_strlcpy(char *dest, const char *src, u32 size)
|
||||||
|
{
|
||||||
|
if (!size)
|
||||||
|
return (ft_strlen(src));
|
||||||
|
|
||||||
|
u32 i = 0;
|
||||||
|
for (; i < size && src[i] != '\0'; i++)
|
||||||
|
dest[i] = src[i];
|
||||||
|
dest[i] = '\0';
|
||||||
|
return (ft_strlen(src));
|
||||||
|
}
|
23
libft/ft_strlen.c
Normal file
23
libft/ft_strlen.c
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlen.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/07/15 11:46:17 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/09/27 08:52:38 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *str)
|
||||||
|
{
|
||||||
|
i32 i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (str[i] != '\0')
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
32
libft/ft_strmapi.c
Normal file
32
libft/ft_strmapi.c
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmapi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/10/04 22:55:32 by erey-bet #+# #+# */
|
||||||
|
/* Updated: 2022/10/10 15:43:18 by erey-bet ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned i32, char))
|
||||||
|
{
|
||||||
|
unsigned i32 i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (s == NULL || f == NULL)
|
||||||
|
return (NULL);
|
||||||
|
str = ft_strdup(s);
|
||||||
|
if (str == NULL)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
str[i] = f(i, s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
17
libft/ft_strncmp.c
Normal file
17
libft/ft_strncmp.c
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
i32
|
||||||
|
ft_strncmp(const char *s1, const char *s2, u32 n) {
|
||||||
|
unsigned char *tmp_s1;
|
||||||
|
unsigned char *tmp_s2;
|
||||||
|
|
||||||
|
if (n <= 0)
|
||||||
|
return (0);
|
||||||
|
tmp_s1 = (unsigned char *)s1;
|
||||||
|
tmp_s2 = (unsigned char *)s2;
|
||||||
|
for (u32 i = 1; *tmp_s1 != '\0' && *tmp_s2 != '\0' && i < n; i ++) {
|
||||||
|
if (*tmp_s1 == *tmp_s2)
|
||||||
|
return 0;
|
||||||
|
tmp_s1++;
|
||||||
|
tmp_s2++;
|
||||||
|
}
|
||||||
|
return (*tmp_s1 - *tmp_s2);
|
||||||
|
}
|
19
libft/ft_strnstr.c
Normal file
19
libft/ft_strnstr.c
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
char *
|
||||||
|
ft_strnstr(const char *big, const char *little, size_t len) {
|
||||||
|
char *b;
|
||||||
|
|
||||||
|
b = (char *)big;
|
||||||
|
if (!*little || (little == big && ft_strlen(little) <= len))
|
||||||
|
return (b);
|
||||||
|
u32 y;
|
||||||
|
for (u32 i = 0; i < len && big[i]; i++) {
|
||||||
|
y = 0;
|
||||||
|
while (b[i + y] == little[y] && i + y < len)
|
||||||
|
{
|
||||||
|
y++;
|
||||||
|
if (little[y] == '\0')
|
||||||
|
return (&b[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
13
libft/ft_strrchr.c
Normal file
13
libft/ft_strrchr.c
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
char *
|
||||||
|
ft_strrchr(const char *str, i32 search) {
|
||||||
|
char *last = NULL;
|
||||||
|
for (i32 i = 0; str[i] || str[i] == (unsigned char)search; i++) {
|
||||||
|
if (str[i] == (unsigned char)search)
|
||||||
|
{
|
||||||
|
last = (char *)&str[i];
|
||||||
|
if (str[i] == 0)
|
||||||
|
return (last);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (last);
|
||||||
|
}
|
6
libft/ft_strslen.c
Normal file
6
libft/ft_strslen.c
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
u32
|
||||||
|
ft_strslen(char **strs) {
|
||||||
|
u32 count = 0;
|
||||||
|
for(; strs[count] ;count++);
|
||||||
|
return count;
|
||||||
|
}
|
50
libft/ft_strtrim.c
Normal file
50
libft/ft_strtrim.c
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
static i32
|
||||||
|
get_start(const char *str, char const *set) {
|
||||||
|
i32 check;
|
||||||
|
|
||||||
|
for (i32 i = 0; str[i]; i++) {
|
||||||
|
check = 0;
|
||||||
|
for (i32 y = 0; set[y]; y++)
|
||||||
|
if (str[i] == set[y])
|
||||||
|
check = 1;
|
||||||
|
if (check == 0)
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static i32
|
||||||
|
get_end(const char *str, char const *set) {
|
||||||
|
i32 check;
|
||||||
|
|
||||||
|
for (i32 i = ft_strlen(str) - 1; i > 0; i--) {
|
||||||
|
check = 0;
|
||||||
|
for (i32 y = 0; set[y]; y++)
|
||||||
|
if (str[i] == set[y])
|
||||||
|
check = 1;
|
||||||
|
if (check == 0)
|
||||||
|
return (i + 1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
ft_strtrim(char const *s1, char const *set) {
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (s1 == NULL || set == NULL)
|
||||||
|
return (NULL);
|
||||||
|
i32 start = get_start(s1, set);
|
||||||
|
i32 end = get_end(s1, set);
|
||||||
|
str = malloc(end - start + 1);
|
||||||
|
if (str == NULL)
|
||||||
|
return (NULL);
|
||||||
|
i32 i = 0;
|
||||||
|
for (; start < end; i++) {
|
||||||
|
str[i] = s1[start];
|
||||||
|
i++;
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
str[i] = '\0';
|
||||||
|
return (str);
|
||||||
|
}
|
21
libft/ft_substr.c
Normal file
21
libft/ft_substr.c
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
char *
|
||||||
|
ft_substr(char const *s, u32 start, size_t len) {
|
||||||
|
i64 size;
|
||||||
|
char *new_s;
|
||||||
|
|
||||||
|
if (s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
size = ft_strlen(s) - start;
|
||||||
|
if (size < 0)
|
||||||
|
size = 0;
|
||||||
|
else if ((u64)size > len)
|
||||||
|
size = len;
|
||||||
|
new_s = ft_calloc(size + 2, 1);
|
||||||
|
if (new_s == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (start <= ft_strlen(s))
|
||||||
|
ft_strlcpy(new_s, s + start, len + 1);
|
||||||
|
else
|
||||||
|
new_s[0] = '\0';
|
||||||
|
return (new_s);
|
||||||
|
}
|
7
libft/ft_tolower.c
Normal file
7
libft/ft_tolower.c
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
i32
|
||||||
|
ft_tolower(char c)
|
||||||
|
{
|
||||||
|
if (c >= 'A' && c <= 'Z')
|
||||||
|
c = c + 32;
|
||||||
|
return (c);
|
||||||
|
}
|
7
libft/ft_toupper.c
Normal file
7
libft/ft_toupper.c
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
i32
|
||||||
|
ft_toupper(char c)
|
||||||
|
{
|
||||||
|
if (c >= 'a' && c <= 'z')
|
||||||
|
c = c - 32;
|
||||||
|
return (c);
|
||||||
|
}
|
82
libft/libft.h
Normal file
82
libft/libft.h
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdint.h>
|
||||||
|
# include <inttypes.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
typedef struct s_list
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
struct s_list *next;
|
||||||
|
} t_list;
|
||||||
|
|
||||||
|
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
|
||||||
|
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
|
||||||
|
#define ABS(X) ((X) >= 0 ? (X) : -(X))
|
||||||
|
|
||||||
|
typedef uint8_t u8;
|
||||||
|
typedef uint16_t u16;
|
||||||
|
typedef uint32_t u32;
|
||||||
|
typedef uint64_t u64;
|
||||||
|
typedef int8_t i8;
|
||||||
|
typedef int16_t i16;
|
||||||
|
typedef int32_t i32;
|
||||||
|
typedef int64_t i64;
|
||||||
|
typedef float f32;
|
||||||
|
typedef double f64;
|
||||||
|
|
||||||
|
i32 ft_isalpha(char c);
|
||||||
|
i32 ft_isdigit(char c);
|
||||||
|
i32 ft_isalnum(char c);
|
||||||
|
i32 ft_isascii(char c);
|
||||||
|
i32 ft_isprint(char c);
|
||||||
|
i32 ft_toupper(char c);
|
||||||
|
i32 ft_tolower(char c);
|
||||||
|
size_t ft_strlen(const char *str);
|
||||||
|
void *ft_memset(void *ptr, i32 v, size_t count);
|
||||||
|
void ft_bzero(void *s, u32 n);
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t s);
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t s);
|
||||||
|
void *ft_memchr(const void *memory_block, i32 searched_char, size_t size);
|
||||||
|
i32 ft_memcmp(const void *pointer1, const void *pointer2, size_t size);
|
||||||
|
char *ft_strcpy(char *dest, const char *src);
|
||||||
|
u32 ft_strlcpy(char *dest, const char *src, u32 size);
|
||||||
|
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||||
|
char *ft_strchr(const char *str, i32 search);
|
||||||
|
char *ft_strrchr(const char *str, i32 search);
|
||||||
|
i32 ft_strcmp(const char *s1, const char *s2);
|
||||||
|
i32 ft_strncmp(const char *s1, const char *s2, u32 n);
|
||||||
|
char * ft_strcat(char *dest, const char *src);
|
||||||
|
size_t ft_strlcat(char *dest, const char *src, size_t size);
|
||||||
|
char *ft_strlcats(u32 nbr_str, ...);
|
||||||
|
char *ft_strdup(const char *src);
|
||||||
|
i32 ft_atoi(const char *nptr);
|
||||||
|
char **ft_split(char const *s, char c);
|
||||||
|
void *ft_calloc(size_t nitems, size_t size);
|
||||||
|
char *ft_itoa(i32 n);
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(u32, char));
|
||||||
|
void ft_striteri(char *s, void (*f)(u32, char*));
|
||||||
|
i32 ft_putchar_fd(char c, i32 fd);
|
||||||
|
i32 ft_putstr_fd(char *s, i32 fd);
|
||||||
|
void ft_putendl_fd(char *s, i32 fd);
|
||||||
|
u32 ft_putnbr_fd(i64 n, i32 fd);
|
||||||
|
i32 ft_get_size(i64 n);
|
||||||
|
i32 ft_power(i32 nb, i32 power);
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
char *ft_strtrim(char const *s1, char const *set);
|
||||||
|
char *ft_substr(char const *s, u32 start, size_t len);
|
||||||
|
t_list *ft_lstnew(void *content);
|
||||||
|
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||||
|
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||||
|
i32 ft_lstsize(t_list *lst);
|
||||||
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
void ft_lstdelone(t_list *lst, void (*del)(void*));
|
||||||
|
void ft_lstclear(t_list **lst, void (*del)(void*));
|
||||||
|
void ft_lstiter(t_list *lst, void (*f)(void *));
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *));
|
||||||
|
void ft_lstremove_front(t_list **lst, void (*del)(void*));
|
||||||
|
void ft_lstremove_back(t_list **lst, void (*del)(void*));
|
||||||
|
i32 ft_atoi_check(const char *nptr);
|
||||||
|
u32 ft_strslen(char **strs);
|
Loading…
Reference in a new issue