fix relink libft make

This commit is contained in:
Matthos Denys 2021-01-10 20:26:19 +03:00
parent e507504526
commit bc87a8a9fa
145 changed files with 3073 additions and 0 deletions

View File

@ -0,0 +1,51 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/10/28 11:52:03 by mdenys #+# #+# #
# Updated: 2021/01/10 20:23:03 by mdenys ### ########.fr #
# #
# **************************************************************************** #
LIBFT = ./libft/libft.a
N_TEMP = temp.a
NAME = libftprintf.a
SRCS = ft_printf.c parser/ft_parser.c parser/ft_parser_utils.c \
putchar_maker/ft_put_c.c putchar_maker/put_d/ft_put_d.c putchar_maker/put_d/ft_put_d_utilc.c putchar_maker/ft_put_p.c putchar_maker/ft_put_s.c putchar_maker/ft_put_u.c putchar_maker/ft_put_x.c \
putchar_maker/put_u/ft_put_u.c putchar_maker/put_u/ft_put_u_utilc.c\
putchar_maker/put_x/ft_put_x.c putchar_maker/put_x/ft_put_x_utilc.c\
putchar_maker/put_p/ft_put_p.c putchar_maker/put_p/ft_put_p_utilc.c\
putchar_maker/putmaket_utils.c putchar_maker/put_d/ft_put_d_undersize.c
SURPL_O = *.o
CC = gcc
FLAGS = -c -Wall -Wextra -Werror
OBJS = $(SRCS:.c=.o)
$(NAME): $(OBJS)
$(MAKE) bonus -C ./libft
cp libft/libft.a $(NAME)
$(CC) $(FLAGS) $(SRCS) ft_printf.h
ar -rcs $(NAME) $(OBJS)
all : $(NAME)
clean :
$(MAKE) clean -C ./libft
rm -rf $(SURPL_O)
rm -rf $(OBJS)
fclean : clean
$(MAKE) fclean -C ./libft
rm -rf $(NAME)
re : fclean all

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/19 16:46:57 by mdenys #+# #+# */
/* Updated: 2020/12/14 21:59:53 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar_fd_count(t_printf *list, char c, int fd)
{
write(fd, &c, 1);
list->count += 1;
}
int ft_printf(const char *format, ...)
{
int i;
char *ptr;
va_list name;
i = 0;
va_start(name, format);
ptr = (char *)format;
while (*ptr)
{
if (*ptr == '%')
{
ptr++;
i += ft_parser(&ptr, &name);
}
else
{
ft_putchar_fd(*ptr, 1);
i++;
ptr++;
}
}
va_end(name);
return (i);
}

View File

@ -0,0 +1,98 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/19 16:50:07 by mdenys #+# #+# */
/* Updated: 2020/12/16 06:00:04 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_PRINTF_H
# define FT_PRINTF_H
# include <stdarg.h>
# include "libft/libft.h"
# include <stdlib.h>
typedef struct s_printf
{
int wh;
int prec;
unsigned is_left:1;
unsigned is_zero:1;
unsigned is_prec:1;
unsigned rec_prec:1;
unsigned to_up:1;
unsigned v_min:1;
unsigned count;
} t_printf;
void ft_putnbr_fd_count(t_printf *list, long int n, int fd);
void ft_putnbr_u_fd_count(t_printf *list, unsigned int n, int fd);
void ft_putchar_fd_count(t_printf *list, char c, int fd);
int ft_printf(const char *format, ...);
int ft_parser(char **str, va_list *name);
void while_c(t_printf *list, char c, int i);
void d_isprec(t_printf *list, int value);
int lennbr(long int n);
int is_flag(char **str, t_printf *params);
int is_star(char **str, va_list *arg, t_printf *params);
int is_digit(char **str, t_printf *params);
int is_type(char **str, int *cout, va_list *arg, t_printf *params);
int len_value(t_printf *list, long int value);
void d_isleft(t_printf *list, int value);
void d_isleft_2(t_printf *list, int value);
void ft_write_d(t_printf *list, int value);
void ft_write_d_2(t_printf *list, int value);
void for_min_diszero(t_printf *list, int value, int tmp, int *c);
void for_diszero(t_printf *list, int value, int tmp, int c);
void printf_value(t_printf *list, int value);
int len_u_value(t_printf *list, unsigned int value);
void u_isleft(t_printf *list, unsigned int value);
void u_iszero(t_printf *list, unsigned int value);
void u_isprec(t_printf *list, unsigned int value);
void ft_write_u(t_printf *list, unsigned int value);
int u_lennbr(unsigned int n);
void printf_u_value(t_printf *list, unsigned int value);
void for_uiszero(t_printf *list, unsigned int value, int tmp, \
unsigned int c);
void for_min_uiszero(t_printf *list, unsigned int value, int tmp,\
unsigned int *c);
void u_isleft_ext(t_printf *list, unsigned int value);
void x_isleft(t_printf *list, unsigned int value);
void x_iszero(t_printf *list, unsigned int value);
void x_isprec(t_printf *list, unsigned int value);
int len_x_value(t_printf *list, unsigned int value);
void ft_write_x(t_printf *list, unsigned int value);
void printf_x_value(t_printf *list, unsigned int value);
void print_hex(unsigned int value, t_printf *list);
int len_hex(unsigned int value);
void for_xiszero(t_printf *list, unsigned int value, int \
tmp, unsigned int c);
void for_min_xiszero(t_printf *list, unsigned int value, int tmp,\
unsigned int *c);
void print_hep(t_printf *list, long int value);
int len_hep(long int value);
void for_piszero(t_printf *list, long int value, long int tmp, \
long int c);
void for_min_piszero(t_printf *list, long int value, long int tmp,\
long int *c);
void printf_p_value(t_printf *list, long int value);
void p_isleft(t_printf *list, long int value);
void p_iszero(t_printf *list, long int value);
void p_isprec(t_printf *list, long int value);
int len_hep(long int value);
void ft_write_p(t_printf *list, long int value);
void printf_p_value_2(t_printf *list, long int value, int b);
int ft_put_percent(t_printf *list);
int ft_put_c(t_printf *list, va_list *name);
int ft_put_d(t_printf *list, va_list *name);
int ft_put_p(t_printf *list, va_list *name);
int ft_put_s(t_printf *list, va_list *name);
int ft_put_u(t_printf *list, va_list *name);
int ft_put_x(t_printf *list, va_list *name);
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,49 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# Makefile :+: :+: :+: #
# +:+ +:+ +:+ #
# By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/10/28 11:52:03 by mdenys #+# #+# #
# Updated: 2021/01/10 20:24:38 by mdenys ### ########.fr #
# #
# **************************************************************************** #
SRCS = ft_isalnum.c ft_isprint.c ft_memcmp.c ft_putchar_fd.c ft_split.c \
ft_strlcat.c ft_strncmp.c ft_substr.c ft_atoi.c ft_isalpha.c \
ft_itoa.c ft_memcpy.c ft_putendl_fd.c ft_strchr.c ft_strlcpy.c \
ft_strnstr.c ft_tolower.c ft_bzero.c ft_isascii.c ft_memccpy.c \
ft_memmove.c ft_putnbr_fd.c ft_strdup.c ft_strlen.c ft_strrchr.c \
ft_toupper.c ft_calloc.c ft_isdigit.c ft_memchr.c ft_memset.c \
ft_putstr_fd.c ft_strjoin.c ft_strmapi.c ft_strtrim.c ft_putchar.c
OBJS = $(SRCS:.c=.o)
BONUS = 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
BONUS_OBJS = $(BONUS:.c=.o)
CC = gcc
RM = rm -f
CFLAGS = -Wall -Wextra -Werror -I.
NAME = libft.a
all: $(NAME)
$(NAME): $(OBJS) libft.h
ar rcs $(NAME) $(OBJS)
clean:
$(RM) $(OBJS) $(BONUS_OBJS)
fclean: clean
$(RM) $(NAME)
re: fclean $(NAME)
bonus: $(OBJS) $(BONUS_OBJS) libft.h
ar rcs $(NAME) $(OBJS) $(BONUS_OBJS)
.PHONY: all clean fclean re bonus

View File

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 13:36:13 by mdenys #+# #+# */
/* Updated: 2020/11/05 17:22:30 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ch(char ch)
{
if (ch == '\t' || ch == '\n' || ch == ' ' || \
ch == '\v' || ch == '\f' || ch == '\r')
return (1);
else
return (0);
}
int ft_atoi(const char *str)
{
int i;
unsigned long int result;
int operator;
i = 0;
operator = 1;
result = 0;
while (ch(str[i]))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
operator *= -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
if (result > 922337203685477580 && operator == -1)
return (0);
else if (result > 922337203685477580 && operator == 1)
return (-1);
result = result * 10 + str[i] - '0';
i++;
}
return (result * operator);
}

Binary file not shown.

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 12:19:35 by mdenys #+# #+# */
/* Updated: 2020/10/29 18:24:02 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_bzero(void *s, size_t num)
{
char *tmp;
size_t i;
i = 0;
if (num)
{
tmp = s;
while (i < num)
{
tmp[i] = '\0';
i++;
}
}
}

Binary file not shown.

View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/01 19:59:31 by mdenys #+# #+# */
/* Updated: 2020/11/01 20:41:24 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t num, size_t size)
{
void *addr;
unsigned int nbytes;
nbytes = num * size;
addr = malloc(nbytes);
if (!size || !num || (size == 0 && num == 0))
return ((void *)addr);
if (!addr)
return (NULL);
else
{
ft_memset(addr, '\0', nbytes);
}
return ((void *)addr);
}

Binary file not shown.

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalnum.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 16:43:05 by mdenys #+# #+# */
/* Updated: 2020/10/29 19:50:43 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalnum(int c)
{
return (ft_isalpha(c) || ft_isdigit(c));
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 14:03:52 by mdenys #+# #+# */
/* Updated: 2020/10/30 11:46:57 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isalpha(int c)
{
if ((c > 64 && c < 91) || (c > 96 && c < 123))
return (1);
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isascii.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 18:53:32 by mdenys #+# #+# */
/* Updated: 2020/10/30 11:54:20 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isascii(int c)
{
if (c >= 0 && c <= 127)
return (1);
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isdigit.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 14:29:08 by mdenys #+# #+# */
/* Updated: 2020/10/30 11:52:05 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isdigit(int ch)
{
if (ch >= '0' && ch <= '9')
return (1);
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isprint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 18:53:32 by mdenys #+# #+# */
/* Updated: 2020/10/30 11:53:10 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_isprint(int c)
{
if (c >= 32 && c <= 126)
return (1);
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/03 20:26:38 by mdenys #+# #+# */
/* Updated: 2020/11/04 13:20:27 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int nbleng(unsigned int n)
{
unsigned int i;
i = 0;
while (n >= 10)
{
n /= 10;
i++;
}
return (i + 1);
}
char *ft_itoa(int n)
{
char *dst;
unsigned int leng;
unsigned int nbr;
unsigned int i;
nbr = (n < 0 ? -n : n);
leng = nbleng(nbr);
i = 0;
if (!(dst = (char *)malloc(sizeof(char) * leng + 1 + (n < 0 ? 1 : 0))))
return (NULL);
if (n < 0)
{
dst[i] = '-';
leng++;
}
i = leng - 1;
while (nbr >= 10)
{
dst[i] = nbr % 10 + '0';
nbr /= 10;
i--;
}
dst[i] = nbr % 10 + '0';
dst[leng] = '\0';
return (dst);
}

Binary file not shown.

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_back.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 18:15:55 by mdenys #+# #+# */
/* Updated: 2020/11/04 18:36:49 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_back(t_list **lst, t_list *new)
{
t_list *temp;
temp = *lst;
if (*lst)
{
while (temp->next != NULL)
temp = temp->next;
temp->next = new;
}
else if (*lst == NULL)
{
*lst = new;
}
}

Binary file not shown.

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstadd_front.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 17:29:57 by mdenys #+# #+# */
/* Updated: 2020/11/04 17:54:55 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstadd_front(t_list **lst, t_list *new)
{
if (new)
{
new->next = *lst;
*lst = new;
}
}

Binary file not shown.

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstclear.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 20:53:46 by mdenys #+# #+# */
/* Updated: 2020/11/04 21:34:51 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstclear(t_list **lst, void (*del)(void*))
{
t_list *new;
if (*lst)
{
while (*lst)
{
del((*lst)->content);
new = *lst;
*lst = new->next;
free(new);
}
}
*lst = NULL;
}

Binary file not shown.

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstdelone.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 18:37:58 by mdenys #+# #+# */
/* Updated: 2020/11/04 20:49:50 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstdelone(t_list *lst, void (*del)(void *))
{
if (lst)
{
del(lst->content);
free(lst);
}
}

Binary file not shown.

View File

@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 21:10:38 by mdenys #+# #+# */
/* Updated: 2020/11/04 21:24:22 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (!lst || !f)
return ;
while (lst)
{
f(lst->content);
lst = lst->next;
}
}

Binary file not shown.

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstlast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 18:07:26 by mdenys #+# #+# */
/* Updated: 2020/11/04 18:14:43 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstlast(t_list *lst)
{
t_list *new;
new = lst;
if (lst)
{
while (new->next != NULL)
new = new->next;
return (new);
}
return (NULL);
}

Binary file not shown.

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 21:25:01 by mdenys #+# #+# */
/* Updated: 2020/11/05 16:46:12 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *nlst;
t_list *new;
if (!lst)
return (NULL);
nlst = NULL;
while (lst)
{
new = ft_lstnew(f(lst->content));
if (!new)
{
ft_lstclear(&nlst, del);
return (NULL);
}
ft_lstadd_back(&nlst, new);
lst = lst->next;
}
return (nlst);
}

Binary file not shown.

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstnew.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 17:06:10 by mdenys #+# #+# */
/* Updated: 2020/11/04 17:29:10 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstnew(void *content)
{
t_list *str;
str = (t_list*)malloc(sizeof(t_list));
if (str)
{
str->content = content;
str->next = NULL;
return (str);
}
return (NULL);
}

Binary file not shown.

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstsize.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 17:57:03 by mdenys #+# #+# */
/* Updated: 2020/11/04 18:06:42 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_lstsize(t_list *lst)
{
int i;
t_list *new;
i = 0;
new = lst;
while (new)
{
new = new->next;
i++;
}
return (i);
}

Binary file not shown.

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/30 15:35:27 by mdenys #+# #+# */
/* Updated: 2020/11/04 17:38:29 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int ch, size_t n)
{
unsigned char *d;
unsigned char *s;
unsigned int i;
i = 0;
d = dst;
s = (unsigned char *)src;
if (!n)
return (0);
while (i < n)
{
d[i] = s[i];
if (s[i] == (unsigned char)ch)
return (dst + i + 1);
i++;
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/30 19:55:27 by mdenys #+# #+# */
/* Updated: 2020/11/04 17:40:00 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memchr(const void *arr, int c, size_t n)
{
unsigned char *d;
unsigned int i;
i = 0;
d = (unsigned char*)arr;
while (i < n)
{
if (d[i] == (unsigned char)c)
{
return (void*)(d + i);
}
i++;
}
return (NULL);
}

Binary file not shown.

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/31 12:46:41 by mdenys #+# #+# */
/* Updated: 2020/11/04 17:41:43 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_memcmp(const void *buf1, const void *buf2, size_t n)
{
unsigned int i;
unsigned char *d;
unsigned char *s;
if (!n)
return (0);
i = 0;
d = (unsigned char*)buf1;
s = (unsigned char*)buf2;
while (d[i] == s[i] && n - 1 > i)
i++;
if (d[i] != s[i])
return (d[i] - s[i]);
else
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/30 14:43:54 by mdenys #+# #+# */
/* Updated: 2020/10/31 13:33:48 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memcpy(void *destination, const void *source, size_t n)
{
unsigned char *d;
unsigned char *s;
int i;
i = 0;
d = (unsigned char *)destination;
s = (unsigned char *)source;
if (!n || destination == source)
return (destination);
while (n--)
{
d[i] = s[i];
i++;
}
return (destination);
}

Binary file not shown.

View File

@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/30 17:04:51 by mdenys #+# #+# */
/* Updated: 2020/11/04 18:41:12 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dst, const void *source, size_t n)
{
unsigned char *d;
unsigned char *s;
unsigned int i;
i = 0;
d = dst;
s = (unsigned char *)source;
if (!n)
return (dst);
else if (s < d)
{
while (++i <= n)
d[n - i] = s[n - i];
}
else if (s)
{
while (i < n)
{
d[i] = s[i];
i++;
}
}
return (dst);
}

Binary file not shown.

View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 10:24:40 by mdenys #+# #+# */
/* Updated: 2020/10/29 17:01:59 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *dest, int val, size_t num)
{
char *tmp;
size_t i;
i = 0;
if (num)
{
tmp = dest;
while (i < num)
{
tmp[i] = val;
i++;
}
}
return (dest);
}

Binary file not shown.

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/12/04 22:44:21 by mdenys #+# #+# */
/* Updated: 2020/12/04 22:49:12 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar(char c)
{
write(1, &c, 1);
}

Binary file not shown.

View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putchar_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 13:02:20 by mdenys #+# #+# */
/* Updated: 2020/11/04 15:47:39 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
if (fd)
write(fd, &c, 1);
}

Binary file not shown.

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putendl_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 14:53:54 by mdenys #+# #+# */
/* Updated: 2020/11/04 14:57:01 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
int i;
i = 0;
if (s)
{
while (s[i])
{
ft_putchar_fd(s[i], fd);
i++;
}
ft_putchar_fd('\n', fd);
}
}

Binary file not shown.

View File

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 15:04:13 by mdenys #+# #+# */
/* Updated: 2020/12/16 05:49:18 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(long int n, int fd)
{
long int nbr;
if (n < 0)
{
ft_putchar_fd('-', fd);
nbr = (unsigned int)(n * -1);
}
else
nbr = (unsigned int)n;
if (nbr >= 10)
ft_putnbr_fd(nbr / 10, fd);
ft_putchar_fd((char)(nbr % 10 + '0'), fd);
}
void ft_putnbr_u_fd(unsigned int n, int fd)
{
unsigned int nbr;
if (n < 0)
{
ft_putchar_fd('-', fd);
nbr = (unsigned int)(n * -1);
}
else
nbr = (unsigned int)n;
if (nbr >= 10)
ft_putnbr_fd(nbr / 10, fd);
ft_putchar_fd((char)(nbr % 10 + '0'), fd);
}

Binary file not shown.

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 13:45:44 by mdenys #+# #+# */
/* Updated: 2020/11/04 13:48:29 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
int i;
i = 0;
if (s)
{
while (s[i])
{
ft_putchar_fd(s[i], fd);
i++;
}
}
}

Binary file not shown.

View File

@ -0,0 +1,84 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/03 13:48:14 by mdenys #+# #+# */
/* Updated: 2020/11/03 20:34:46 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
static int ft_isspace(char c, char b)
{
return (c == b);
}
static int count_words(char *str, char c)
{
int count;
count = 0;
while (*str)
{
while (*str && ft_isspace(*str, c))
str++;
if (*str && !ft_isspace(*str, c))
{
count++;
while (*str && !ft_isspace(*str, c))
str++;
}
}
return (count);
}
static char *malloc_word(char *str, char c)
{
char *word;
int i;
i = 0;
while (str[i] && !ft_isspace(str[i], c))
i++;
word = (char *)malloc(sizeof(char) * (i + 1));
i = 0;
while (str[i] && !ft_isspace(str[i], c))
{
word[i] = str[i];
i++;
}
word[i] = '\0';
return (word);
}
char **ft_split(const char *str, char c)
{
char **arr;
int i;
i = 0;
arr = NULL;
if (str && (arr = malloc(sizeof(char *) * \
(count_words((char*)str, c) + 1))))
{
while (*str)
{
while (*str && ft_isspace(*str, c))
str++;
if (*str && !ft_isspace(*str, c))
{
arr[i] = malloc_word((char*)str, c);
i++;
while (*str && !ft_isspace(*str, c))
str++;
}
}
arr[i] = NULL;
}
return (arr);
}

Binary file not shown.

View File

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/01 13:44:25 by mdenys #+# #+# */
/* Updated: 2020/11/05 18:00:06 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strchr(const char *str, int ch)
{
unsigned char *d;
unsigned int i;
unsigned int len;
len = ft_strlen((char *)str);
i = 0;
d = (unsigned char *)str;
if (str)
{
while (d[i] != (unsigned char)ch && i < len)
{
i++;
}
if (d[i] == (unsigned char)ch)
{
return (void *)(d + i);
}
return (0);
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/01 20:43:44 by mdenys #+# #+# */
/* Updated: 2020/11/01 21:11:41 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strdup(const char *str)
{
char *test;
int len;
len = ft_strlen((char *)str) + 1;
test = malloc(len * sizeof(char));
if (test == NULL)
return (NULL);
ft_strlcpy(test, str, (unsigned int)len);
return (test);
}

Binary file not shown.

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/02 17:18:40 by mdenys #+# #+# */
/* Updated: 2020/11/02 17:56:57 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strjoin(char const *s1, char const *s2)
{
int len1;
int len2;
char *new;
if (s1 && s2)
{
len1 = ft_strlen((char*)s1);
len2 = ft_strlen((char*)s2);
new = malloc(sizeof(char *) * len1 + len2 + 1);
if (new)
{
ft_strlcpy(new, s1, len1 + 1);
ft_strlcat(new, s2, len1 + len2 + 1);
return (void *)(new);
}
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/31 17:10:24 by mdenys #+# #+# */
/* Updated: 2020/11/05 16:58:02 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcat(char *dst, const char *src, size_t size)
{
unsigned int i;
unsigned int len;
len = 0;
if (!dst && !src)
return (0);
len = ft_strlen(dst);
i = 0;
if (size < len)
return (ft_strlen((char *)src) + size);
if (size)
{
while (src[i] && len + 1 < size)
dst[len++] = src[i++];
dst[len] = '\0';
}
while (src[i])
{
i++;
len++;
}
return (len);
}

Binary file not shown.

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/28 19:26:31 by mdenys #+# #+# */
/* Updated: 2020/11/05 16:57:58 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
unsigned int i;
unsigned int count;
count = 0;
if (!dst && !src)
return (0);
while (src[count] != '\0')
{
++count;
}
i = 0;
if (size > 0)
{
while (src[i] != '\0' && i < (size - 1) && src[i])
{
dst[i] = src[i];
++i;
}
dst[i] = '\0';
}
return (count);
}

Binary file not shown.

View File

@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/28 19:10:44 by mdenys #+# #+# */
/* Updated: 2020/11/23 18:40:34 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strlen(char *str)
{
int i;
i = 0;
if (*str)
{
while (str[i] != '\0')
{
i++;
}
}
return (i);
}

Binary file not shown.

View File

@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strmapi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 12:41:12 by mdenys #+# #+# */
/* Updated: 2020/11/04 13:01:25 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
{
int i;
int len;
char *str;
i = 0;
str = NULL;
if (s)
{
len = ft_strlen((char*)s);
str = (char*)malloc(sizeof(char) * len + 1);
if (str)
{
while (s[i])
{
str[i] = f(i, s[i]);
++i;
}
str[i] = '\0';
return (str);
}
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/29 12:22:15 by mdenys #+# #+# */
/* Updated: 2020/11/05 17:52:29 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_strncmp(const char *s1, const char *s2, size_t a)
{
unsigned int i;
unsigned char *d;
unsigned char *s;
d = (unsigned char *)s1;
s = (unsigned char *)s2;
i = 0;
while (d[i] && s[i] && i < a)
{
if (d[i] != s[i])
return (d[i] - s[i]);
i++;
}
if (i != a)
{
return (d[i] - s[i]);
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strnstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/01 18:43:20 by mdenys #+# #+# */
/* Updated: 2020/11/04 18:41:20 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strnstr(const char *hst, const char *ndl, size_t size)
{
unsigned int i;
unsigned int j;
if (ndl[0] == '\0')
return ((char *)hst);
i = 0;
while (hst[i])
{
j = 0;
if (hst[i] == ndl[j])
{
while (hst[i + j] == ndl[j] && i + j < size)
{
j++;
if (!ndl[j])
return ((void *)(hst + i));
}
}
i++;
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strrchr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/01 16:14:36 by mdenys #+# #+# */
/* Updated: 2020/11/05 17:56:32 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strrchr(const char *str, int ch)
{
unsigned char *d;
unsigned int i;
unsigned int len;
len = ft_strlen((char *)str);
i = 0;
d = (unsigned char *)str;
if (str)
{
while (d[len] != (unsigned char)ch && 0 < len)
{
--len;
}
if (d[len] == (unsigned char)ch)
{
return (void *)(d + len);
}
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strtrim.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mdenys <mdenys@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/02 17:58:31 by mdenys #+# #+# */
/* Updated: 2020/11/03 11:18:41 by mdenys ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
char *ft_strtrim(char const *s1, char const *set)
{
char *new;
int len;
len = 0;
if (!s1 || !set)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
s1++;
len = ft_strlen((char*)s1);
while (len && ft_strchr(set, s1[len]))
len--;
new = ft_substr((char *)(s1), 0, len + 1);
return (new);
}

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