cleanup
This commit is contained in:
parent
1c6b660be0
commit
8a24fc42c8
46
Makefile
46
Makefile
@ -12,40 +12,52 @@
|
||||
|
||||
NAME = minitalk
|
||||
|
||||
SRC_PATH = src
|
||||
INC_PATH = inc
|
||||
LIBFT_INC_PATH = libft/inc
|
||||
LIBFT = libft/libft.a
|
||||
OBJ_PATH = obj
|
||||
|
||||
VPATH = $(SRC_PATH)
|
||||
SOURCES = server.c client.c
|
||||
OBJECTS = $(SOURCES:.c=.o)
|
||||
OBJECTS = $(addprefix $(OBJ_PATH)/, $(SOURCES:.c=.o))
|
||||
|
||||
CC = cc
|
||||
RM = rm -rf
|
||||
INCLUDES = -I./$(LIBFT_INC_PATH) -I./$(INC_PATH)
|
||||
CFLAGS = -Wall -Werror -Wextra
|
||||
LDFLAGS = -L./libft
|
||||
LDLIBS = -lft
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): client server
|
||||
|
||||
client: client.o libft.a
|
||||
$(CC) $(CFLAGS) -o client client.o libft.a
|
||||
client: obj/client.o $(LIBFT)
|
||||
$(CC) $(CFLAGS) obj/client.o $(LDFLAGS) $(LDLIBS) -o client
|
||||
|
||||
server: server.o libft.a
|
||||
$(CC) $(CFLAGS) -o server server.o libft.a
|
||||
server: obj/server.o $(LIBFT)
|
||||
$(CC) $(CFLAGS) obj/server.o $(LDFLAGS) $(LDLIBS) -o server
|
||||
|
||||
libft.a:
|
||||
make -C libft
|
||||
mv libft/libft.a libft.a
|
||||
$(OBJ_PATH):
|
||||
mkdir -p $@
|
||||
|
||||
client.o: client.c
|
||||
$(CC) $(CFLAGS) -c client.c
|
||||
$(LIBFT):
|
||||
$(MAKE) -C libft
|
||||
|
||||
server.o: server.c
|
||||
$(CC) $(CFLAGS) -c server.c
|
||||
$(OBJ_PATH)/%.o: %.c $(LIBFT) | $(OBJ_PATH)
|
||||
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -f $(OBJECTS)
|
||||
make -C libft clean
|
||||
$(RM) $(OBJ_PATH)
|
||||
$(MAKE) -C libft clean
|
||||
|
||||
fclean: clean
|
||||
rm -f client server libft.a
|
||||
make -C libft fclean
|
||||
$(RM) client server libft.a
|
||||
$(MAKE) -C libft fclean
|
||||
|
||||
re: fclean all
|
||||
|
||||
.PHONY: $(NAME) all clean fclean re
|
||||
bonus: all
|
||||
|
||||
.PHONY: $(NAME) all clean fclean re bonus
|
||||
|
||||
77
libft/Makefile
Normal file
77
libft/Makefile
Normal file
@ -0,0 +1,77 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: o_ :::::: ::: #
|
||||
# Makefile :+: / :+::+: :+: #
|
||||
# +:+ > +:++:+ +:+ #
|
||||
# By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ #
|
||||
# +#+ +#+#+ +#++#+ +#+ \o/ #
|
||||
# Created: 2024/10/10 16:44:36 by whaffman #+#+# #+#+# #+# #+# | #
|
||||
# Updated: 2024/10/10 18:00:05 by whaffman ### ### ### ### / \ #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
|
||||
INC_DIR = inc
|
||||
|
||||
OBJ_DIR = obj
|
||||
|
||||
CC = cc
|
||||
|
||||
WARNINGS = -Wall -Wextra -Werror
|
||||
|
||||
CFLAGS = $(WARNINGS)
|
||||
|
||||
VPATH = src:src/conversion:src/ft_printf:src/list:src/memory:src/output:\
|
||||
src/string:src/get_next_line
|
||||
|
||||
SRC_CONVERSION = ft_atoi.c ft_itoa.c ft_tolower.c ft_toupper.c \
|
||||
|
||||
SRC_MEMORY = ft_memchr.c ft_memcmp.c ft_memcpy.c ft_memmove.c ft_memset.c \
|
||||
ft_bzero.c ft_calloc.c
|
||||
|
||||
SRC_STRING = ft_isalnum.c ft_isalpha.c ft_isascii.c ft_isdigit.c ft_isprint.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_strncmp.c \
|
||||
ft_strnstr.c ft_strrchr.c ft_strtrim.c ft_substr.c ft_strcmp.c
|
||||
|
||||
SRC_LIST = ft_lstadd_back.c ft_lstadd_front.c ft_lstclear.c ft_lstdelone.c \
|
||||
ft_lstiter.c ft_lstlast.c ft_lstmap.c ft_lstnew.c ft_lstsize.c
|
||||
|
||||
SRC_OUTPUT = ft_putchar_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_putstr_fd.c
|
||||
|
||||
SRC_FT_PRINTF = ft_isbase.c ft_putnbr_base.c ft_write_str.c parse_placeholder.c \
|
||||
print_hex.c print_pointer.c print_unumber.c ft_printf.c \
|
||||
ft_putnbr_signed.c parse_conversion.c print_char.c \
|
||||
print_number.c print_string.c
|
||||
|
||||
SRC_GET_NEXT_LINE = get_next_line.c
|
||||
|
||||
SOURCES = $(SRC_CONVERSION) $(SRC_MEMORY) $(SRC_STRING) \
|
||||
$(SRC_LIST) $(SRC_OUTPUT) $(SRC_FT_PRINTF) $(SRC_GET_NEXT_LINE)
|
||||
|
||||
OBJECTS = $(addprefix $(OBJ_DIR)/, $(SOURCES:.c=.o))
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJECTS)
|
||||
$(AR) rcs $@ $^
|
||||
|
||||
$(OBJ_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
$(OBJ_DIR)/%.o: %.c | $(OBJ_DIR)
|
||||
$(CC) $(CFLAGS) -I $(INC_DIR) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR)
|
||||
|
||||
fclean: clean
|
||||
rm -f $(NAME)
|
||||
|
||||
re: fclean all
|
||||
|
||||
debug: CFLAGS += -DDEBUG -g
|
||||
debug: $(NAME)
|
||||
|
||||
.PHONY: all clean fclean re
|
||||
31
libft/inc/ft_printf.h
Normal file
31
libft/inc/ft_printf.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_printf.h :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/15 13:04:31 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/15 13:07:34 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_PRINTF_H
|
||||
# define FT_PRINTF_H
|
||||
|
||||
# include <stdarg.h>
|
||||
|
||||
int ft_isbase(char *str);
|
||||
void ft_write_str(char c, char *str);
|
||||
void ft_putnbr_base(unsigned long nbr, char *base, char *result);
|
||||
void ft_putnbr_signed(long nbr, char *base, char *result);
|
||||
int print_char(va_list args);
|
||||
int print_string(va_list args);
|
||||
int print_number(va_list args);
|
||||
int print_unumber(va_list args);
|
||||
int print_hex(va_list args, int uppercase);
|
||||
int print_pointer(va_list args);
|
||||
int parse_conversion(const char **format, va_list args);
|
||||
int parse_placeholder(const char **format, va_list args);
|
||||
|
||||
#endif
|
||||
87
libft/inc/libft.h
Normal file
87
libft/inc/libft.h
Normal file
@ -0,0 +1,87 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/07/06 11:15:10 by whaffman #+# #+# */
|
||||
/* Updated: 2024/07/10 16:27:58 by whaffman ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
# include <stddef.h>
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
size_t ft_strlen(const char *s);
|
||||
void *ft_memset(void *s, int c, size_t n);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
int ft_toupper(int c);
|
||||
int ft_tolower(int c);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
void *ft_memchr(const void *s, int c, size_t n);
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||
int ft_atoi(const char *nptr);
|
||||
void *ft_calloc(size_t nmemb, size_t size);
|
||||
char *ft_strdup(const char *s);
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s1, char const *set);
|
||||
char **ft_split(char const *s, char c);
|
||||
char *ft_itoa(int n);
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char *s, int fd);
|
||||
void ft_putendl_fd(char *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
|
||||
/*
|
||||
* Lists
|
||||
*/
|
||||
|
||||
t_list *ft_lstnew(void *content);
|
||||
void ft_lstadd_front(t_list **lst, t_list *new);
|
||||
int ft_lstsize(t_list *lst);
|
||||
t_list *ft_lstlast(t_list *lst);
|
||||
void ft_lstadd_back(t_list **lst, t_list *new);
|
||||
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 *));
|
||||
|
||||
/*
|
||||
* Printf
|
||||
*/
|
||||
|
||||
int ft_printf(const char *format, ...);
|
||||
|
||||
/*
|
||||
* get_next_line
|
||||
*/
|
||||
# define OPEN_MAX 1024
|
||||
# define BUFFER_SIZE 256
|
||||
|
||||
char *get_next_line(int fd);
|
||||
|
||||
#endif
|
||||
40
libft/src/conversion/ft_atoi.c
Normal file
40
libft/src/conversion/ft_atoi.c
Normal file
@ -0,0 +1,40 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_atoi.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:13 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:13 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static int ft_isspace(int c)
|
||||
{
|
||||
return (' ' == c || '\f' == c || \
|
||||
'\n' == c || '\r' == c || \
|
||||
'\t' == c || '\v' == c);
|
||||
}
|
||||
|
||||
int ft_atoi(const char *nptr)
|
||||
{
|
||||
int sign;
|
||||
int res;
|
||||
|
||||
while (ft_isspace(*nptr))
|
||||
nptr++;
|
||||
res = 0;
|
||||
sign = 1;
|
||||
if (*nptr == '-' || *nptr == '+')
|
||||
{
|
||||
if (*nptr == '-')
|
||||
sign *= -1;
|
||||
nptr++;
|
||||
}
|
||||
while (ft_isdigit(*nptr))
|
||||
res = 10 * res + sign * (*nptr++ - '0');
|
||||
return (res);
|
||||
}
|
||||
58
libft/src/conversion/ft_itoa.c
Normal file
58
libft/src/conversion/ft_itoa.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_itoa.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:17 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:17 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
static char *itoa_stralloc(int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (n <= 0)
|
||||
i++;
|
||||
while (n)
|
||||
{
|
||||
i++;
|
||||
n /= 10;
|
||||
}
|
||||
return (ft_calloc((i + 1), sizeof(char)));
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
int i;
|
||||
long ln;
|
||||
long divider;
|
||||
char *result;
|
||||
|
||||
result = itoa_stralloc(n);
|
||||
if (!result)
|
||||
return (NULL);
|
||||
ln = n;
|
||||
i = 0;
|
||||
divider = 1;
|
||||
if (ln < 0)
|
||||
{
|
||||
ln *= -1;
|
||||
result[i++] = '-';
|
||||
}
|
||||
while (divider * 10 <= ln)
|
||||
divider *= 10;
|
||||
while (divider)
|
||||
{
|
||||
result[i++] = ln / divider + '0';
|
||||
ln %= divider;
|
||||
divider /= 10;
|
||||
}
|
||||
return (result);
|
||||
}
|
||||
20
libft/src/conversion/ft_tolower.c
Normal file
20
libft/src/conversion/ft_tolower.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_tolower.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:33 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:33 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if ('A' <= c && 'Z' >= c)
|
||||
return (c - 'A' + 'a');
|
||||
return (c);
|
||||
}
|
||||
20
libft/src/conversion/ft_toupper.c
Normal file
20
libft/src/conversion/ft_toupper.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_toupper.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:33 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:33 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if ('a' <= c && 'z' >= c)
|
||||
return (c - 'a' + 'A');
|
||||
return (c);
|
||||
}
|
||||
33
libft/src/ft_printf/ft_isbase.c
Normal file
33
libft/src/ft_printf/ft_isbase.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_isbase.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:18:39 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:19:43 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_isbase(char *str)
|
||||
{
|
||||
int i;
|
||||
int n;
|
||||
|
||||
n = 0;
|
||||
while (str[n])
|
||||
{
|
||||
i = 1;
|
||||
if (str[n] == '-' || str[n] == '+')
|
||||
return (0);
|
||||
while (str[n + i])
|
||||
{
|
||||
if (str[n] == str[n + i])
|
||||
return (0);
|
||||
i++;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
42
libft/src/ft_printf/ft_printf.c
Normal file
42
libft/src/ft_printf/ft_printf.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_printf.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/11 14:49:07 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:37:46 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int ft_printf(const char *format, ...)
|
||||
{
|
||||
int wrote;
|
||||
int result;
|
||||
va_list args;
|
||||
|
||||
result = 0;
|
||||
va_start(args, format);
|
||||
while (*format && result >= 0)
|
||||
{
|
||||
if (*format == '%')
|
||||
wrote = parse_placeholder(&format, args);
|
||||
else
|
||||
wrote = write(1, format, 1);
|
||||
if (wrote < 0)
|
||||
{
|
||||
result = wrote;
|
||||
break ;
|
||||
}
|
||||
result += wrote;
|
||||
format++;
|
||||
}
|
||||
va_end(args);
|
||||
return (result);
|
||||
}
|
||||
29
libft/src/ft_printf/ft_putnbr_base.c
Normal file
29
libft/src/ft_printf/ft_putnbr_base.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_putnbr_base.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:21:37 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:22:22 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
void ft_putnbr_base(unsigned long nbr, char *base, char *result)
|
||||
{
|
||||
unsigned int b;
|
||||
|
||||
b = ft_isbase(base);
|
||||
if (b < 2)
|
||||
return ;
|
||||
if (nbr < b)
|
||||
ft_write_str(base[nbr], result);
|
||||
else if (nbr >= b)
|
||||
{
|
||||
ft_putnbr_base(nbr / b, base, result);
|
||||
ft_putnbr_base(nbr % b, base, result);
|
||||
}
|
||||
}
|
||||
24
libft/src/ft_printf/ft_putnbr_signed.c
Normal file
24
libft/src/ft_printf/ft_putnbr_signed.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_putnbr_signed.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:22:39 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:23:02 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "ft_printf.h"
|
||||
|
||||
void ft_putnbr_signed(long nbr, char *base, char *result)
|
||||
{
|
||||
if (nbr < 0)
|
||||
{
|
||||
*result = '-';
|
||||
ft_putnbr_base((unsigned long)(-nbr), base, result);
|
||||
}
|
||||
else
|
||||
ft_putnbr_base((unsigned long) nbr, base, result);
|
||||
}
|
||||
24
libft/src/ft_printf/ft_write_str.c
Normal file
24
libft/src/ft_printf/ft_write_str.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_write_str.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:19:20 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:19:53 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
void ft_write_str(char c, char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
{
|
||||
i++;
|
||||
}
|
||||
str[i++] = c;
|
||||
str[i] = '\0';
|
||||
}
|
||||
39
libft/src/ft_printf/parse_conversion.c
Normal file
39
libft/src/ft_printf/parse_conversion.c
Normal file
@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* parse_conversion.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:34:43 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:34:49 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int parse_conversion(const char **format, va_list args)
|
||||
{
|
||||
int wrote;
|
||||
|
||||
if (**format == 'c')
|
||||
wrote = print_char(args);
|
||||
else if (**format == 's')
|
||||
wrote = print_string(args);
|
||||
else if (ft_strchr("di", **format))
|
||||
wrote = print_number(args);
|
||||
else if (ft_strchr("u", **format))
|
||||
wrote = print_unumber(args);
|
||||
else if (ft_strchr("p", **format))
|
||||
wrote = print_pointer(args);
|
||||
else if (ft_strchr("x", **format))
|
||||
wrote = print_hex(args, 0);
|
||||
else if (ft_strchr("X", **format))
|
||||
wrote = print_hex(args, 1);
|
||||
else
|
||||
wrote = -1;
|
||||
return (wrote);
|
||||
}
|
||||
31
libft/src/ft_printf/parse_placeholder.c
Normal file
31
libft/src/ft_printf/parse_placeholder.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* parse_placeholder.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:34:28 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:35:09 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int parse_placeholder(const char **format, va_list args)
|
||||
{
|
||||
const char conversions[] = "cspdiuxX%";
|
||||
int wrote;
|
||||
|
||||
(*format)++;
|
||||
while (**format && !ft_strchr(conversions, **format))
|
||||
(*format)++;
|
||||
if (**format == '%')
|
||||
wrote = write(1, *format, 1);
|
||||
else
|
||||
wrote = parse_conversion(format, args);
|
||||
return (wrote);
|
||||
}
|
||||
22
libft/src/ft_printf/print_char.c
Normal file
22
libft/src/ft_printf/print_char.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* print_char.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:28:10 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:28:12 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int print_char(va_list args)
|
||||
{
|
||||
char c;
|
||||
|
||||
c = va_arg(args, int);
|
||||
return (write(1, &c, 1));
|
||||
}
|
||||
38
libft/src/ft_printf/print_hex.c
Normal file
38
libft/src/ft_printf/print_hex.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* print_hex.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:29:01 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:30:00 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int print_hex(va_list args, int uppercase)
|
||||
{
|
||||
long n;
|
||||
size_t len;
|
||||
char *str;
|
||||
int wrote;
|
||||
|
||||
str = ft_calloc(sizeof(char), 20);
|
||||
if (!str)
|
||||
return (-1);
|
||||
n = va_arg(args, unsigned int);
|
||||
if (uppercase)
|
||||
ft_putnbr_base(n, "0123456789ABCDEF", str);
|
||||
else
|
||||
ft_putnbr_base(n, "0123456789abcdef", str);
|
||||
len = ft_strlen(str);
|
||||
wrote = write(1, str, len);
|
||||
free(str);
|
||||
return (wrote);
|
||||
}
|
||||
35
libft/src/ft_printf/print_number.c
Normal file
35
libft/src/ft_printf/print_number.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* print_number.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:31:23 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:31:37 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int print_number(va_list args)
|
||||
{
|
||||
long n;
|
||||
size_t len;
|
||||
char *str;
|
||||
int wrote;
|
||||
|
||||
str = ft_calloc(sizeof(char), 12);
|
||||
if (!str)
|
||||
return (-1);
|
||||
n = va_arg(args, int);
|
||||
ft_putnbr_signed(n, "0123456789", str);
|
||||
len = ft_strlen(str);
|
||||
wrote = write(1, str, len);
|
||||
free(str);
|
||||
return (wrote);
|
||||
}
|
||||
38
libft/src/ft_printf/print_pointer.c
Normal file
38
libft/src/ft_printf/print_pointer.c
Normal file
@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* print_pointer.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:26:58 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:31:19 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int print_pointer(va_list args)
|
||||
{
|
||||
long n;
|
||||
size_t len;
|
||||
char *str;
|
||||
int wrote;
|
||||
|
||||
n = va_arg(args, unsigned long);
|
||||
if (!n)
|
||||
return (write(1, "(nil)", 5));
|
||||
str = ft_calloc(sizeof(char), 20);
|
||||
if (!str)
|
||||
return (-1);
|
||||
ft_strlcpy(str, "0x", 3);
|
||||
ft_putnbr_base(n, "0123456789abcdef", str);
|
||||
len = ft_strlen(str);
|
||||
wrote = write(1, str, len);
|
||||
free(str);
|
||||
return (wrote);
|
||||
}
|
||||
28
libft/src/ft_printf/print_string.c
Normal file
28
libft/src/ft_printf/print_string.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* print_string.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:31:48 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:32:23 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int print_string(va_list args)
|
||||
{
|
||||
char *str;
|
||||
size_t len;
|
||||
|
||||
str = va_arg(args, char *);
|
||||
if (!str)
|
||||
return (write(1, "(null)", 6));
|
||||
len = ft_strlen(str);
|
||||
return (write(1, str, len));
|
||||
}
|
||||
36
libft/src/ft_printf/print_unumber.c
Normal file
36
libft/src/ft_printf/print_unumber.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* print_unumber.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/27 16:32:36 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/27 16:32:49 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
#include "ft_printf.h"
|
||||
|
||||
int print_unumber(va_list args)
|
||||
{
|
||||
long n;
|
||||
size_t len;
|
||||
char *str;
|
||||
int wrote;
|
||||
|
||||
wrote = 0;
|
||||
str = ft_calloc(sizeof(char), 12);
|
||||
if (!str)
|
||||
return (-1);
|
||||
n = va_arg(args, unsigned int);
|
||||
ft_putnbr_base(n, "0123456789", str);
|
||||
len = ft_strlen(str);
|
||||
wrote = write(1, str, len);
|
||||
free(str);
|
||||
return (wrote);
|
||||
}
|
||||
124
libft/src/get_next_line/get_next_line.c
Normal file
124
libft/src/get_next_line/get_next_line.c
Normal file
@ -0,0 +1,124 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* get_next_line.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/07/15 16:59:55 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/07/15 17:00:24 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void gnl_clean(void **ptr)
|
||||
{
|
||||
if (*ptr)
|
||||
{
|
||||
free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int gnl_check_and_extract(char **line, char **stock)
|
||||
{
|
||||
char *temp1;
|
||||
char *temp2;
|
||||
|
||||
if (!stock || !*stock)
|
||||
return (0);
|
||||
temp1 = *stock;
|
||||
while (temp1 && *temp1 != '\n')
|
||||
if (!*temp1++)
|
||||
return (0);
|
||||
if (temp1)
|
||||
temp1++;
|
||||
temp2 = ft_strdup(temp1);
|
||||
*temp1 = '\0';
|
||||
*line = ft_strdup(*stock);
|
||||
free(*stock);
|
||||
*stock = temp2;
|
||||
if (!*line || !*stock)
|
||||
{
|
||||
gnl_clean((void **)line);
|
||||
gnl_clean((void **)stock);
|
||||
return (-1);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int gnl_read(int fd, char **buffer, size_t size)
|
||||
{
|
||||
int bytes_read;
|
||||
|
||||
if (!*buffer)
|
||||
{
|
||||
*buffer = malloc(sizeof(char) * (BUFFER_SIZE + 1));
|
||||
if (!*buffer)
|
||||
return (-1);
|
||||
}
|
||||
bytes_read = read(fd, *buffer, size);
|
||||
if (bytes_read >= 0)
|
||||
(*buffer)[bytes_read] = '\0';
|
||||
return (bytes_read);
|
||||
}
|
||||
|
||||
static int gnl_read_file(int fd, char **stock, char **line)
|
||||
{
|
||||
char *buffer;
|
||||
char *temp;
|
||||
int bytes_read;
|
||||
|
||||
buffer = NULL;
|
||||
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
|
||||
while (bytes_read > 0)
|
||||
{
|
||||
if (!*stock)
|
||||
*stock = ft_strdup(buffer);
|
||||
else
|
||||
{
|
||||
temp = *stock;
|
||||
*stock = ft_strjoin(temp, buffer);
|
||||
free(temp);
|
||||
}
|
||||
if (gnl_check_and_extract(line, stock))
|
||||
break ;
|
||||
bytes_read = gnl_read(fd, &buffer, BUFFER_SIZE);
|
||||
}
|
||||
free(buffer);
|
||||
if (!*stock)
|
||||
return (-1);
|
||||
return (bytes_read);
|
||||
}
|
||||
|
||||
char *get_next_line(int fd)
|
||||
{
|
||||
static char *stock[OPEN_MAX];
|
||||
char *line;
|
||||
int status;
|
||||
|
||||
if (fd < 0 || fd >= OPEN_MAX || BUFFER_SIZE <= 0)
|
||||
return (NULL);
|
||||
if (stock[fd] && gnl_check_and_extract(&line, &stock[fd]))
|
||||
return (line);
|
||||
status = gnl_read_file(fd, &stock[fd], &line);
|
||||
if (status > 0)
|
||||
return (line);
|
||||
else if (status < 0)
|
||||
{
|
||||
gnl_clean((void **)&stock[fd]);
|
||||
return (NULL);
|
||||
}
|
||||
if (stock[fd] && *stock[fd])
|
||||
{
|
||||
line = ft_strdup(stock[fd]);
|
||||
gnl_clean((void **)&stock[fd]);
|
||||
if (line)
|
||||
return (line);
|
||||
}
|
||||
gnl_clean((void **)&stock[fd]);
|
||||
return (NULL);
|
||||
}
|
||||
28
libft/src/list/ft_lstadd_back.c
Normal file
28
libft/src/list/ft_lstadd_back.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstadd_back.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:18 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:18 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **lst, t_list *new)
|
||||
{
|
||||
t_list *last;
|
||||
|
||||
if (!new)
|
||||
return ;
|
||||
if (!*lst)
|
||||
{
|
||||
*lst = new;
|
||||
return ;
|
||||
}
|
||||
last = ft_lstlast(*lst);
|
||||
last->next = new;
|
||||
}
|
||||
22
libft/src/list/ft_lstadd_front.c
Normal file
22
libft/src/list/ft_lstadd_front.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstadd_front.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:18 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:18 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_front(t_list **lst, t_list *new)
|
||||
{
|
||||
if (new)
|
||||
{
|
||||
new->next = *lst;
|
||||
*lst = new;
|
||||
}
|
||||
}
|
||||
32
libft/src/list/ft_lstclear.c
Normal file
32
libft/src/list/ft_lstclear.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstclear.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:19 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:19 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
||||
{
|
||||
t_list *next;
|
||||
|
||||
if (!del || !lst)
|
||||
return ;
|
||||
while (*lst)
|
||||
{
|
||||
if ((*lst)->next)
|
||||
next = (*lst)->next;
|
||||
else
|
||||
next = NULL;
|
||||
del((*lst)->content);
|
||||
free(*lst);
|
||||
*lst = next;
|
||||
}
|
||||
}
|
||||
22
libft/src/list/ft_lstdelone.c
Normal file
22
libft/src/list/ft_lstdelone.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstdelone.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:19 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:19 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list *lst, void (*del)(void *))
|
||||
{
|
||||
if (!lst || !del)
|
||||
return ;
|
||||
del(lst->content);
|
||||
free(lst);
|
||||
}
|
||||
24
libft/src/list/ft_lstiter.c
Normal file
24
libft/src/list/ft_lstiter.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstiter.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:19 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:19 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||
{
|
||||
if (!lst || !f)
|
||||
return ;
|
||||
while (lst)
|
||||
{
|
||||
(*f)(lst->content);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
||||
22
libft/src/list/ft_lstlast.c
Normal file
22
libft/src/list/ft_lstlast.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstlast.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:20 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:20 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstlast(t_list *lst)
|
||||
{
|
||||
if (!lst)
|
||||
return (NULL);
|
||||
while (lst->next)
|
||||
lst = lst->next;
|
||||
return (lst);
|
||||
}
|
||||
37
libft/src/list/ft_lstmap.c
Normal file
37
libft/src/list/ft_lstmap.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstmap.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:20 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:20 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *new_list;
|
||||
t_list *new_elem;
|
||||
void *new_content;
|
||||
|
||||
new_list = NULL;
|
||||
while (lst)
|
||||
{
|
||||
new_content = f(lst->content);
|
||||
new_elem = ft_lstnew(new_content);
|
||||
if (!new_elem)
|
||||
{
|
||||
del(new_content);
|
||||
ft_lstclear(&new_list, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&new_list, new_elem);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (new_list);
|
||||
}
|
||||
27
libft/src/list/ft_lstnew.c
Normal file
27
libft/src/list/ft_lstnew.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstnew.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:21 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:21 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void *content)
|
||||
{
|
||||
t_list *node;
|
||||
|
||||
node = malloc(sizeof(t_list));
|
||||
if (node)
|
||||
{
|
||||
node->content = content;
|
||||
node->next = NULL;
|
||||
}
|
||||
return (node);
|
||||
}
|
||||
28
libft/src/list/ft_lstsize.c
Normal file
28
libft/src/list/ft_lstsize.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_lstsize.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:21 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:21 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_lstsize(t_list *lst)
|
||||
{
|
||||
int count;
|
||||
|
||||
count = 1;
|
||||
if (!lst)
|
||||
return (0);
|
||||
while (lst->next)
|
||||
{
|
||||
lst = lst->next;
|
||||
count++;
|
||||
}
|
||||
return (count);
|
||||
}
|
||||
18
libft/src/memory/ft_bzero.c
Normal file
18
libft/src/memory/ft_bzero.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_bzero.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:14 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:14 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, 0, n);
|
||||
}
|
||||
28
libft/src/memory/ft_calloc.c
Normal file
28
libft/src/memory/ft_calloc.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_calloc.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:14 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:14 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *ptr;
|
||||
|
||||
if (nmemb && size > (size_t) -1 / nmemb)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
ptr = malloc(nmemb * size);
|
||||
if (ptr)
|
||||
ft_bzero(ptr, nmemb * size);
|
||||
return (ptr);
|
||||
}
|
||||
24
libft/src/memory/ft_memchr.c
Normal file
24
libft/src/memory/ft_memchr.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_memchr.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:22 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:22 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
while (0 < n--)
|
||||
{
|
||||
if (*(unsigned char *)s == (unsigned char) c)
|
||||
return ((void *) s);
|
||||
s++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
31
libft/src/memory/ft_memcmp.c
Normal file
31
libft/src/memory/ft_memcmp.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_memcmp.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:22 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:22 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *str1;
|
||||
unsigned char *str2;
|
||||
size_t i;
|
||||
|
||||
str1 = (unsigned char *)s1;
|
||||
str2 = (unsigned char *)s2;
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
if (str1[i] != str2[i])
|
||||
return (str1[i] - str2[i]);
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
22
libft/src/memory/ft_memcpy.c
Normal file
22
libft/src/memory/ft_memcpy.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_memcpy.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:23 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:23 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||
{
|
||||
if (dest == NULL && src == NULL)
|
||||
return (NULL);
|
||||
while (0 < n--)
|
||||
((unsigned char *)dest)[n] = ((unsigned char *)src)[n];
|
||||
return (dest);
|
||||
}
|
||||
35
libft/src/memory/ft_memmove.c
Normal file
35
libft/src/memory/ft_memmove.c
Normal file
@ -0,0 +1,35 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_memmove.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:23 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:23 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||
{
|
||||
unsigned char *dest_ptr;
|
||||
unsigned char *src_ptr;
|
||||
|
||||
dest_ptr = (unsigned char *)dest;
|
||||
src_ptr = (unsigned char *)src;
|
||||
if (dest_ptr == src_ptr)
|
||||
return (dest);
|
||||
else if (dest_ptr < src_ptr)
|
||||
{
|
||||
while (n-- > 0)
|
||||
*dest_ptr++ = *src_ptr++;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (n-- > 0)
|
||||
dest_ptr[n] = src_ptr[n];
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
20
libft/src/memory/ft_memset.c
Normal file
20
libft/src/memory/ft_memset.c
Normal file
@ -0,0 +1,20 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_memset.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:24 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:24 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *s, int c, size_t n)
|
||||
{
|
||||
while (0 < n--)
|
||||
((unsigned char *)s)[n] = (unsigned char) c;
|
||||
return (s);
|
||||
}
|
||||
21
libft/src/output/ft_putchar_fd.c
Normal file
21
libft/src/output/ft_putchar_fd.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_putchar_fd.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:24 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:24 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
if (fd < 0)
|
||||
return ;
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
22
libft/src/output/ft_putendl_fd.c
Normal file
22
libft/src/output/ft_putendl_fd.c
Normal file
@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_putendl_fd.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:25 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:25 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char *s, int fd)
|
||||
{
|
||||
if (fd < 0 || s == NULL)
|
||||
return ;
|
||||
ft_putstr_fd(s, fd);
|
||||
write(fd, "\n", 1);
|
||||
}
|
||||
42
libft/src/output/ft_putnbr_fd.c
Normal file
42
libft/src/output/ft_putnbr_fd.c
Normal file
@ -0,0 +1,42 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_putnbr_fd.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:25 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:25 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putnbr_fd(int n, int fd)
|
||||
{
|
||||
long ln;
|
||||
long divider;
|
||||
char c;
|
||||
|
||||
if (fd < 0)
|
||||
return ;
|
||||
ln = n;
|
||||
divider = 1;
|
||||
if (n < 0)
|
||||
{
|
||||
if (!write(fd, "-", 1))
|
||||
return ;
|
||||
ln *= -1;
|
||||
}
|
||||
while (divider * 10 <= ln)
|
||||
divider *= 10;
|
||||
while (divider)
|
||||
{
|
||||
c = ln / divider + '0';
|
||||
if (!write(fd, &c, 1))
|
||||
return ;
|
||||
ln %= divider;
|
||||
divider /= 10;
|
||||
}
|
||||
}
|
||||
24
libft/src/output/ft_putstr_fd.c
Normal file
24
libft/src/output/ft_putstr_fd.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_putstr_fd.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:26 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:26 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char *s, int fd)
|
||||
{
|
||||
size_t length;
|
||||
|
||||
if (s == NULL || fd < 0)
|
||||
return ;
|
||||
length = ft_strlen(s);
|
||||
write(fd, s, length);
|
||||
}
|
||||
26
libft/src/string/ft_isalnum.c
Normal file
26
libft/src/string/ft_isalnum.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_isalnum.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:15 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:15 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief ft_isalnum() checks if a character is a digit or an
|
||||
* alphabetical character.
|
||||
*
|
||||
* @param c contains an integer of the character to be tested.
|
||||
* @return int returns c if the int codes for an digit or an alphabetical
|
||||
* character.
|
||||
*/
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
return (ft_isdigit(c) || ft_isalpha(c));
|
||||
}
|
||||
24
libft/src/string/ft_isalpha.c
Normal file
24
libft/src/string/ft_isalpha.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_isalpha.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:15 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:15 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief ft_isalpha() checks if a character is an alphabetical character.
|
||||
*
|
||||
* @param c contains an integer of the character to be tested.
|
||||
* @return int returns c if the int codes for an alphabetical character.
|
||||
*/
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
return (('A' <= c && 'Z' >= c) || ('a' <= c && 'z' >= c));
|
||||
}
|
||||
25
libft/src/string/ft_isascii.c
Normal file
25
libft/src/string/ft_isascii.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_isascii.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:16 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:16 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief ft_isalnum() checks if a character is an ascii character
|
||||
*
|
||||
* @param c contains an integer of the character to be tested.
|
||||
* @return int returns c if the int codes for an digit or an ascii
|
||||
* character.
|
||||
*/
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
return (0 <= c && 127 >= c);
|
||||
}
|
||||
24
libft/src/string/ft_isdigit.c
Normal file
24
libft/src/string/ft_isdigit.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_isdigit.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:16 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:16 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief ft_isdigit() checks if a character is a digit.
|
||||
*
|
||||
* @param c contains an integer of the character to be tested.
|
||||
* @return int returns c if the int codes for an digit.
|
||||
*/
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
return ('0' <= c && '9' >= c);
|
||||
}
|
||||
24
libft/src/string/ft_isprint.c
Normal file
24
libft/src/string/ft_isprint.c
Normal file
@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_isprint.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:17 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:17 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief ft_isprint() checks if a character is a printable character.
|
||||
*
|
||||
* @param c contains an integer of the character to be tested.
|
||||
* @return int returns c if the int codes for aprintable character.
|
||||
*/
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
return (32 <= c && 126 >= c);
|
||||
}
|
||||
77
libft/src/string/ft_split.c
Normal file
77
libft/src/string/ft_split.c
Normal file
@ -0,0 +1,77 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_split.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:26 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:26 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "libft.h"
|
||||
|
||||
static int count_words(char const *s, char c)
|
||||
{
|
||||
int n;
|
||||
int i;
|
||||
|
||||
n = 0;
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
if (s[i] != c && (s[i + 1] == c || s[i + 1] == '\0'))
|
||||
n++;
|
||||
i++;
|
||||
}
|
||||
return (n);
|
||||
}
|
||||
|
||||
static void *free_arr(int n, char ***arr)
|
||||
{
|
||||
while (n-- > 0)
|
||||
{
|
||||
free((*arr)[n]);
|
||||
}
|
||||
free(*arr);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ft_split() splits an array based on a seperator.
|
||||
*
|
||||
* @param s is a string.
|
||||
* @param c is the seperator.
|
||||
* @return char** an array of string where the last element is NULL.
|
||||
*/
|
||||
char **ft_split(char const *s, char c)
|
||||
{
|
||||
char **result;
|
||||
int n;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
result = malloc((count_words(s, c) + 1) * sizeof(char *));
|
||||
if (!result)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
n = 0;
|
||||
while (s[i])
|
||||
{
|
||||
j = 0;
|
||||
while (s[i] == c)
|
||||
i++;
|
||||
while (s[i + j] && s[i + j] != c)
|
||||
j++;
|
||||
if (j)
|
||||
result[n] = ft_substr(s, i, j);
|
||||
if (j && !result[n++])
|
||||
return (free_arr(n, &result));
|
||||
i += j;
|
||||
}
|
||||
result[n] = NULL;
|
||||
return (result);
|
||||
}
|
||||
33
libft/src/string/ft_strchr.c
Normal file
33
libft/src/string/ft_strchr.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strchr.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:27 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:27 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
/**
|
||||
* @brief ft_strchr() return a pointer to the first char found in the string.
|
||||
*
|
||||
* @param s the string to be searched.
|
||||
* @param c the character searched for.
|
||||
* @return char* the pointer to the first char found in the string if
|
||||
* nothing is foun ft_strchr() NULL.
|
||||
*/
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
while (*s)
|
||||
{
|
||||
if (*(unsigned char *) s == (unsigned char) c)
|
||||
return ((char *) s);
|
||||
s++;
|
||||
}
|
||||
if (*(unsigned char *) s == (unsigned char) c)
|
||||
return ((char *) s);
|
||||
return (NULL);
|
||||
}
|
||||
23
libft/src/string/ft_strcmp.c
Normal file
23
libft/src/string/ft_strcmp.c
Normal file
@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strcmp.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/11/24 20:06:19 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/11/24 20:07:08 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (s1[i] && s2[i] && s1[i] == s2[i])
|
||||
i++;
|
||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||
}
|
||||
26
libft/src/string/ft_strdup.c
Normal file
26
libft/src/string/ft_strdup.c
Normal file
@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strdup.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:27 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:27 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s)
|
||||
{
|
||||
size_t size;
|
||||
char *d;
|
||||
|
||||
size = ft_strlen(s) + 1;
|
||||
d = (char *) malloc(size * sizeof(char));
|
||||
if (d)
|
||||
ft_strlcpy(d, s, size);
|
||||
return (d);
|
||||
}
|
||||
27
libft/src/string/ft_striteri.c
Normal file
27
libft/src/string/ft_striteri.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_striteri.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:28 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:28 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (!s)
|
||||
return ;
|
||||
while (s[i])
|
||||
{
|
||||
f(i, &s[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
33
libft/src/string/ft_strjoin.c
Normal file
33
libft/src/string/ft_strjoin.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strjoin.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:28 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:28 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *str;
|
||||
size_t len_s1;
|
||||
size_t len_s2;
|
||||
|
||||
if (!s1 || !s2)
|
||||
return (NULL);
|
||||
len_s1 = ft_strlen(s1);
|
||||
len_s2 = ft_strlen(s2);
|
||||
str = (char *)malloc(len_s1 + len_s2 + 1);
|
||||
if (!str)
|
||||
return (NULL);
|
||||
ft_memcpy(str, s1, len_s1);
|
||||
ft_memcpy(str + len_s1, s2, len_s2);
|
||||
str[len_s1 + len_s2] = '\0';
|
||||
return (str);
|
||||
}
|
||||
43
libft/src/string/ft_strlcat.c
Normal file
43
libft/src/string/ft_strlcat.c
Normal file
@ -0,0 +1,43 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strlcat.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:29 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:29 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
/**
|
||||
* @brief ft_strlcat() concatenates size bytes from src into dst
|
||||
*
|
||||
* @param dst the destination string.
|
||||
* @param src the source string.
|
||||
* @param size the amount of bytes to be copied into dst
|
||||
* @return size_t the amount of bytes that should havebeen copied.
|
||||
*/
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t src_len;
|
||||
size_t dst_len;
|
||||
size_t i;
|
||||
|
||||
src_len = ft_strlen(src);
|
||||
if (size == 0)
|
||||
return (src_len);
|
||||
dst_len = ft_strlen(dst);
|
||||
if (dst_len >= size)
|
||||
return (size + src_len);
|
||||
i = 0;
|
||||
while (src[i] && i < size - dst_len - 1)
|
||||
{
|
||||
dst[dst_len + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dst[dst_len + i] = '\0';
|
||||
return (src_len + dst_len);
|
||||
}
|
||||
31
libft/src/string/ft_strlcpy.c
Normal file
31
libft/src/string/ft_strlcpy.c
Normal file
@ -0,0 +1,31 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strlcpy.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:29 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:29 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcpy(char *dest, const char *src, size_t size)
|
||||
{
|
||||
size_t i;
|
||||
size_t result;
|
||||
|
||||
i = 0;
|
||||
if (size == 0)
|
||||
return (ft_strlen(src));
|
||||
while (src[i] && i < size - 1)
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
result = ft_strlen(src);
|
||||
return (result);
|
||||
}
|
||||
28
libft/src/string/ft_strlen.c
Normal file
28
libft/src/string/ft_strlen.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strlen.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:30 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:30 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
/**
|
||||
* @brief ft_strlen() return the length of a null-terminated string.
|
||||
*
|
||||
* @param s the string.
|
||||
* @return size_t the length of the string.
|
||||
*/
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t length;
|
||||
|
||||
length = 0;
|
||||
while (*s++)
|
||||
length++;
|
||||
return (length);
|
||||
}
|
||||
34
libft/src/string/ft_strmapi.c
Normal file
34
libft/src/string/ft_strmapi.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strmapi.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:30 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:30 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
int i;
|
||||
char *result;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
result = malloc((ft_strlen(s) + 1) * sizeof(char));
|
||||
if (!result)
|
||||
return (NULL);
|
||||
i = 0;
|
||||
while (s[i])
|
||||
{
|
||||
result[i] = f(i, s[i]);
|
||||
i++;
|
||||
}
|
||||
result[i] = '\0';
|
||||
return (result);
|
||||
}
|
||||
29
libft/src/string/ft_strncmp.c
Normal file
29
libft/src/string/ft_strncmp.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strncmp.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:31 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:31 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
if (n == 0)
|
||||
return (0);
|
||||
while (*s1 && *s1 == *s2 && i < n - 1)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
i++;
|
||||
}
|
||||
return ((unsigned char) *s1 - (unsigned char) *s2);
|
||||
}
|
||||
33
libft/src/string/ft_strnstr.c
Normal file
33
libft/src/string/ft_strnstr.c
Normal file
@ -0,0 +1,33 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strnstr.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:31 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:31 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
size_t j;
|
||||
|
||||
i = 0;
|
||||
if (*little == '\0')
|
||||
return ((char *) big);
|
||||
while (big[i] && i < len)
|
||||
{
|
||||
j = 0;
|
||||
while (little[j] && big[i + j] == little [j] && i + j < len)
|
||||
j++;
|
||||
if (little[j] == '\0')
|
||||
return ((char *) &big[i]);
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
29
libft/src/string/ft_strrchr.c
Normal file
29
libft/src/string/ft_strrchr.c
Normal file
@ -0,0 +1,29 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strrchr.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:32 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:32 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
char *result;
|
||||
|
||||
result = NULL;
|
||||
while (*s)
|
||||
{
|
||||
if (*s == (char) c)
|
||||
result = (char *) s;
|
||||
s++;
|
||||
}
|
||||
if ('\0' == (char) c)
|
||||
result = (char *) s;
|
||||
return (result);
|
||||
}
|
||||
34
libft/src/string/ft_strtrim.c
Normal file
34
libft/src/string/ft_strtrim.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_strtrim.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:32 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:32 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s1, char const *set)
|
||||
{
|
||||
char *front;
|
||||
char *back;
|
||||
|
||||
if (!s1)
|
||||
return (NULL);
|
||||
if (!ft_strlen(set))
|
||||
return (ft_strdup(s1));
|
||||
front = (char *) s1;
|
||||
back = (char *) s1;
|
||||
while (*back)
|
||||
back++;
|
||||
back--;
|
||||
while (ft_strchr(set, *front))
|
||||
front++;
|
||||
while (ft_strchr(set, *back))
|
||||
back--;
|
||||
return (ft_substr(s1, front - s1, back - front + 1));
|
||||
}
|
||||
34
libft/src/string/ft_substr.c
Normal file
34
libft/src/string/ft_substr.c
Normal file
@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: o_ :::::: ::: */
|
||||
/* ft_substr.c :+: / :+::+: :+: */
|
||||
/* +:+ > +:++:+ +:+ */
|
||||
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#++#++:++#++ */
|
||||
/* +#+ +#+#+ +#++#+ +#+ \o/ */
|
||||
/* Created: 2024/10/10 17:00:33 by whaffman #+#+# #+#+# #+# #+# | */
|
||||
/* Updated: 2024/10/10 17:00:33 by whaffman ### ### ### ### / \ */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *substr;
|
||||
size_t len_s;
|
||||
|
||||
if (!s)
|
||||
return (NULL);
|
||||
len_s = ft_strlen(s);
|
||||
if (start >= len_s)
|
||||
return (ft_strdup(""));
|
||||
if (len_s - start < len)
|
||||
len = len_s - start;
|
||||
substr = malloc(len * sizeof(char) + 1);
|
||||
if (!substr)
|
||||
return (NULL);
|
||||
ft_memcpy(substr, &s[start], len);
|
||||
substr[len] = '\0';
|
||||
return (substr);
|
||||
}
|
||||
@ -12,7 +12,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include "libft/libft.h"
|
||||
#include "libft.h"
|
||||
|
||||
#define SLEEP 300
|
||||
|
||||
@ -61,7 +61,10 @@ int main(int argc, char *argv[])
|
||||
int pid;
|
||||
|
||||
if (argc != 3)
|
||||
ft_putstr("Usage: ./client <pid> <message>");
|
||||
{
|
||||
ft_printf("Usage: ./client <pid> <message>");
|
||||
return (1);
|
||||
}
|
||||
pid = ft_atoi(argv[1]);
|
||||
if (pid <= 1)
|
||||
return (1);
|
||||
@ -12,8 +12,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "libft/libft.h"
|
||||
#include "libft.h"
|
||||
|
||||
void signal_handler(int signum, siginfo_t *info, void *context)
|
||||
{
|
||||
@ -48,9 +47,7 @@ int main(void)
|
||||
{
|
||||
struct sigaction sa;
|
||||
|
||||
ft_putstr("MiniTalk Server started on pid: ");
|
||||
ft_putnbr(getpid());
|
||||
ft_putstr("\n");
|
||||
ft_printf("MiniTalk Server started on pid: %d\n", getpid());
|
||||
sa.sa_sigaction = signal_handler;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
Loading…
Reference in New Issue
Block a user