first
This commit is contained in:
commit
d572e07e85
39
Makefile
Normal file
39
Makefile
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: apommier <apommier@student.42.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2021/11/13 13:06:47 by apommier #+# #+# #
|
||||||
|
# Updated: 2021/11/25 23:57:06 by apommier ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = push_swap
|
||||||
|
SRCS = push_swap.c \
|
||||||
|
utils.c \
|
||||||
|
main.c
|
||||||
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
CFLAGS = -Wall -Wextra -Werror
|
||||||
|
RM = rm -rf
|
||||||
|
LIBFT = ./libft
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
gcc ${CFLAGS} -c $< -o ${<:.c=.o}
|
||||||
|
|
||||||
|
${NAME}:${OBJS}
|
||||||
|
make bonus -C ${LIBFT}
|
||||||
|
|
||||||
|
all: ${NAME}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
${RM} ${OBJS}
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
${RM} ${NAME}
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re bonus
|
||||||
|
|
||||||
66
libft/Makefile
Normal file
66
libft/Makefile
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
NAME = libft.a
|
||||||
|
SRCS = ft_memset.c \
|
||||||
|
ft_bzero.c \
|
||||||
|
ft_memcpy.c \
|
||||||
|
ft_memccpy.c \
|
||||||
|
ft_memmove.c \
|
||||||
|
ft_memchr.c \
|
||||||
|
ft_memcmp.c \
|
||||||
|
ft_strlen.c \
|
||||||
|
ft_isalpha.c \
|
||||||
|
ft_isdigit.c \
|
||||||
|
ft_isalnum.c \
|
||||||
|
ft_isascii.c \
|
||||||
|
ft_isprint.c \
|
||||||
|
ft_toupper.c \
|
||||||
|
ft_tolower.c \
|
||||||
|
ft_strchr.c \
|
||||||
|
ft_strrchr.c \
|
||||||
|
ft_strncmp.c \
|
||||||
|
ft_strlcpy.c \
|
||||||
|
ft_strlcat.c \
|
||||||
|
ft_strnstr.c \
|
||||||
|
ft_atoi.c \
|
||||||
|
ft_calloc.c \
|
||||||
|
ft_strdup.c \
|
||||||
|
ft_substr.c \
|
||||||
|
ft_strjoin.c \
|
||||||
|
ft_strtrim.c \
|
||||||
|
ft_split.c \
|
||||||
|
ft_itoa.c \
|
||||||
|
ft_strmapi.c \
|
||||||
|
ft_putchar_fd.c \
|
||||||
|
ft_putstr_fd.c \
|
||||||
|
ft_putendl_fd.c \
|
||||||
|
ft_putnbr_fd.c
|
||||||
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
BONUS_C = ft_lstnew.c ft_lstadd_front.c ft_lstsize.c ft_lstlast.c ft_lstadd_back.c \
|
||||||
|
ft_lstdelone.c ft_lstclear.c ft_lstiter.c ft_lstmap.c
|
||||||
|
BONUS_O = ${BONUS_C:.c=.o}
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS = -Wall -Wextra -Werror
|
||||||
|
RM = rm -rf
|
||||||
|
|
||||||
|
.c.o:
|
||||||
|
${CC} ${CFLAGS} -c $< -o ${<:.c=.o}
|
||||||
|
|
||||||
|
${NAME}:${OBJS}
|
||||||
|
ar -rcs ${NAME} ${OBJS}
|
||||||
|
|
||||||
|
all: ${NAME}
|
||||||
|
|
||||||
|
bonus: all
|
||||||
|
${CC} ${CFLAGS} -c ${BONUS_C}
|
||||||
|
ar -rcs ${NAME} ${BONUS_O}
|
||||||
|
|
||||||
|
clean:
|
||||||
|
${RM} ${OBJS}
|
||||||
|
${RM} ${BONUS_O}
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
${RM} ${NAME}
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: all clean fclean re bonus
|
||||||
|
|
||||||
39
libft/ft_atoi.c
Normal file
39
libft/ft_atoi.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:09:17 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 12:05:13 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_atoi(const char *nptr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int nbr;
|
||||||
|
int minus;
|
||||||
|
|
||||||
|
minus = 1;
|
||||||
|
nbr = 0;
|
||||||
|
i = 0;
|
||||||
|
while ((nptr[i] >= 9 && nptr[i] <= 13) || nptr[i] == 32)
|
||||||
|
i++;
|
||||||
|
if (nptr[i] == '+')
|
||||||
|
i++;
|
||||||
|
else if (nptr[i] == '-')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
minus = -1;
|
||||||
|
}
|
||||||
|
while (nptr[i] >= '0' && nptr[i] <= '9')
|
||||||
|
{
|
||||||
|
nbr = nbr * 10 + nptr[i] - '0';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (minus * nbr);
|
||||||
|
}
|
||||||
28
libft/ft_bzero.c
Normal file
28
libft/ft_bzero.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_bzero.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:09:48 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/11/29 17:02:33 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_bzero(void *s, size_t n)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
p = (char*)s;
|
||||||
|
i = 0;
|
||||||
|
while (n != 0)
|
||||||
|
{
|
||||||
|
p[i] = 0;
|
||||||
|
i++;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
}
|
||||||
31
libft/ft_calloc.c
Normal file
31
libft/ft_calloc.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_calloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:09:57 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/16 16:13:27 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_calloc(size_t nmemb, size_t size)
|
||||||
|
{
|
||||||
|
char *new;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
new = malloc(size * nmemb);
|
||||||
|
if (new)
|
||||||
|
{
|
||||||
|
while (size * nmemb - i)
|
||||||
|
{
|
||||||
|
new[i] = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ((void*)new);
|
||||||
|
}
|
||||||
23
libft/ft_isalnum.c
Normal file
23
libft/ft_isalnum.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalnum.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:10:08 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 09:26:43 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalnum(int c)
|
||||||
|
{
|
||||||
|
if (c <= '9' && c >= '0')
|
||||||
|
return (1);
|
||||||
|
else if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
21
libft/ft_isalpha.c
Normal file
21
libft/ft_isalpha.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalpha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:10:17 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 09:28:12 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalpha(int c)
|
||||||
|
{
|
||||||
|
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
21
libft/ft_isascii.c
Normal file
21
libft/ft_isascii.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isascii.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:10:30 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 18:11:18 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isascii(int c)
|
||||||
|
{
|
||||||
|
if (c >= 0 && c <= 127)
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
21
libft/ft_isdigit.c
Normal file
21
libft/ft_isdigit.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isdigit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:10:39 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 09:27:06 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isdigit(int c)
|
||||||
|
{
|
||||||
|
if (c <= '9' && c >= '0')
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
21
libft/ft_isprint.c
Normal file
21
libft/ft_isprint.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isprint.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:10:55 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 18:11:43 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isprint(int c)
|
||||||
|
{
|
||||||
|
if (c > 31 && c < 127)
|
||||||
|
return (1);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
59
libft/ft_itoa.c
Normal file
59
libft/ft_itoa.c
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_itoa.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/08 18:20:19 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/20 11:52:40 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static char *fill(long n, int j, int minus)
|
||||||
|
{
|
||||||
|
char *dest;
|
||||||
|
|
||||||
|
j += minus;
|
||||||
|
dest = (char*)malloc(sizeof(char) * (j + 1));
|
||||||
|
if (dest == 0)
|
||||||
|
return (0);
|
||||||
|
dest[j] = 0;
|
||||||
|
if (n == 0)
|
||||||
|
dest[j - 1] = '0';
|
||||||
|
while (n)
|
||||||
|
{
|
||||||
|
dest[j - 1] = n % 10 + '0';
|
||||||
|
j--;
|
||||||
|
n /= 10;
|
||||||
|
}
|
||||||
|
if (minus)
|
||||||
|
dest[j - 1] = '-';
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_itoa(int n)
|
||||||
|
{
|
||||||
|
long i;
|
||||||
|
long k;
|
||||||
|
int j;
|
||||||
|
int minus;
|
||||||
|
|
||||||
|
k = n;
|
||||||
|
minus = 0;
|
||||||
|
j = 1;
|
||||||
|
if (k < 0)
|
||||||
|
{
|
||||||
|
minus = 1;
|
||||||
|
k = k * -1;
|
||||||
|
}
|
||||||
|
i = k;
|
||||||
|
while (k >= 10)
|
||||||
|
{
|
||||||
|
k /= 10;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
return (fill(i, j, minus));
|
||||||
|
}
|
||||||
21
libft/ft_lstadd_back.c
Normal file
21
libft/ft_lstadd_back.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_back.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 19:30:14 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 15:32:53 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstadd_back(t_list **alst, t_list *new)
|
||||||
|
{
|
||||||
|
if (*alst == 0)
|
||||||
|
*alst = new;
|
||||||
|
else
|
||||||
|
ft_lstlast(*alst)->next = new;
|
||||||
|
}
|
||||||
19
libft/ft_lstadd_front.c
Normal file
19
libft/ft_lstadd_front.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstadd_front.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 01:31:45 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 17:34:24 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstadd_front(t_list **alst, t_list *new)
|
||||||
|
{
|
||||||
|
new->next = *alst;
|
||||||
|
*alst = new;
|
||||||
|
}
|
||||||
28
libft/ft_lstclear.c
Normal file
28
libft/ft_lstclear.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstclear.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 19:58:04 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 09:15:23 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstclear(t_list **lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
t_list *chr;
|
||||||
|
|
||||||
|
chr = *lst;
|
||||||
|
while (*lst)
|
||||||
|
{
|
||||||
|
chr = (*lst)->next;
|
||||||
|
del((*lst)->content);
|
||||||
|
free(*lst);
|
||||||
|
*lst = chr;
|
||||||
|
}
|
||||||
|
lst = 0;
|
||||||
|
}
|
||||||
21
libft/ft_lstdelone.c
Normal file
21
libft/ft_lstdelone.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstdelone.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 19:54:40 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 09:10:11 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
||||||
|
{
|
||||||
|
if (!lst)
|
||||||
|
return ;
|
||||||
|
del(lst->content);
|
||||||
|
free(lst);
|
||||||
|
}
|
||||||
22
libft/ft_lstiter.c
Normal file
22
libft/ft_lstiter.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstiter.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 20:14:47 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 17:47:39 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_lstiter(t_list *lst, void (*f)(void *))
|
||||||
|
{
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
f(lst->content);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
22
libft/ft_lstlast.c
Normal file
22
libft/ft_lstlast.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstlast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 19:16:55 by apommier #+# #+# */
|
||||||
|
/* Updated: 2021/11/26 01:21:39 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstlast(t_list *lst)
|
||||||
|
{
|
||||||
|
if (!lst)
|
||||||
|
return (0);
|
||||||
|
while (lst->next)
|
||||||
|
lst = lst->next;
|
||||||
|
return (lst);
|
||||||
|
}
|
||||||
33
libft/ft_lstmap.c
Normal file
33
libft/ft_lstmap.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstmap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/11 00:10:12 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/13 22:37:30 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
||||||
|
{
|
||||||
|
t_list *new;
|
||||||
|
t_list *begin;
|
||||||
|
|
||||||
|
begin = 0;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
new = ft_lstnew(f(lst->content));
|
||||||
|
if (!new)
|
||||||
|
{
|
||||||
|
ft_lstclear(&begin, *del);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
ft_lstadd_back(&begin, new);
|
||||||
|
lst = lst->next;
|
||||||
|
}
|
||||||
|
return (begin);
|
||||||
|
}
|
||||||
25
libft/ft_lstnew.c
Normal file
25
libft/ft_lstnew.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstnew.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 01:06:20 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 17:46:20 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
t_list *ft_lstnew(void *content)
|
||||||
|
{
|
||||||
|
t_list *new;
|
||||||
|
|
||||||
|
new = (t_list*)malloc(sizeof(t_list));
|
||||||
|
if (!new)
|
||||||
|
return (0);
|
||||||
|
new->content = content;
|
||||||
|
new->next = 0;
|
||||||
|
return (new);
|
||||||
|
}
|
||||||
26
libft/ft_lstsize.c
Normal file
26
libft/ft_lstsize.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_lstsize.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/09 03:24:50 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 15:33:49 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_lstsize(t_list *lst)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (lst)
|
||||||
|
{
|
||||||
|
lst = lst->next;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
32
libft/ft_memccpy.c
Normal file
32
libft/ft_memccpy.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memccpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:11:04 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 14:07:04 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
const char *p1;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
p = (char*)dest;
|
||||||
|
p1 = (const char*)src;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
p[i] = p1[i];
|
||||||
|
if ((unsigned char)p[i] == (unsigned char)c)
|
||||||
|
return (dest + i + 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
28
libft/ft_memchr.c
Normal file
28
libft/ft_memchr.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:11:39 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 13:53:45 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n)
|
||||||
|
{
|
||||||
|
unsigned char *str;
|
||||||
|
|
||||||
|
str = (unsigned char*)s;
|
||||||
|
while (n)
|
||||||
|
{
|
||||||
|
if ((unsigned char)c == *str)
|
||||||
|
return (str);
|
||||||
|
n--;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
28
libft/ft_memcmp.c
Normal file
28
libft/ft_memcmp.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:11:51 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 14:14:51 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (n)
|
||||||
|
{
|
||||||
|
if (((unsigned char*)s1)[i] != ((unsigned char*)s2)[i])
|
||||||
|
return (((unsigned char*)s1)[i] - ((unsigned char*)s2)[i]);
|
||||||
|
n--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
32
libft/ft_memcpy.c
Normal file
32
libft/ft_memcpy.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:12:03 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/16 16:14:24 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
char *p;
|
||||||
|
const char *p1;
|
||||||
|
|
||||||
|
if (!dest && !src)
|
||||||
|
return (dest);
|
||||||
|
p = (char*)dest;
|
||||||
|
p1 = (const char*)src;
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
p[i] = p1[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
39
libft/ft_memmove.c
Normal file
39
libft/ft_memmove.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memmove.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:12:14 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/13 21:15:13 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!dest && !src)
|
||||||
|
return (dest);
|
||||||
|
if (dest > src)
|
||||||
|
{
|
||||||
|
while (n)
|
||||||
|
{
|
||||||
|
((unsigned char*)dest)[n - 1] = ((unsigned char*)src)[n - 1];
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
((unsigned char*)dest)[i] = ((unsigned char*)src)[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
29
libft/ft_memset.c
Normal file
29
libft/ft_memset.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:12:24 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 15:48:06 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memset(void *s, int c, size_t n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
unsigned char *p;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
p = (unsigned char*)s;
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
p[i] = (unsigned char)c;
|
||||||
|
i++;
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
return (s);
|
||||||
|
}
|
||||||
18
libft/ft_putchar_fd.c
Normal file
18
libft/ft_putchar_fd.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putchar_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/08 23:11:29 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 17:02:13 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putchar_fd(char c, int fd)
|
||||||
|
{
|
||||||
|
write(fd, &c, 1);
|
||||||
|
}
|
||||||
21
libft/ft_putendl_fd.c
Normal file
21
libft/ft_putendl_fd.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putendl_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/08 23:22:10 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 17:14:52 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putendl_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
if (s == 0)
|
||||||
|
return ;
|
||||||
|
write(fd, s, ft_strlen(s));
|
||||||
|
ft_putchar_fd('\n', fd);
|
||||||
|
}
|
||||||
28
libft/ft_putnbr_fd.c
Normal file
28
libft/ft_putnbr_fd.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/08 23:25:57 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 09:42:09 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putnbr_fd(int n, int fd)
|
||||||
|
{
|
||||||
|
long nbr;
|
||||||
|
|
||||||
|
nbr = n;
|
||||||
|
if (nbr < 0)
|
||||||
|
{
|
||||||
|
ft_putchar_fd('-', fd);
|
||||||
|
nbr *= -1;
|
||||||
|
}
|
||||||
|
if (nbr >= 10)
|
||||||
|
ft_putnbr_fd(nbr / 10, fd);
|
||||||
|
ft_putchar_fd(nbr % 10 + '0', fd);
|
||||||
|
}
|
||||||
20
libft/ft_putstr_fd.c
Normal file
20
libft/ft_putstr_fd.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putstr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/08 23:15:25 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 17:15:10 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putstr_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
if (s == 0)
|
||||||
|
return ;
|
||||||
|
write(fd, s, ft_strlen(s));
|
||||||
|
}
|
||||||
79
libft/ft_split.c
Normal file
79
libft/ft_split.c
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/07 00:54:12 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/13 23:07:09 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int fill_tab(char *s, char c, char **dest, size_t index)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i] != c && s[i])
|
||||||
|
i++;
|
||||||
|
dest[index] = (char*)ft_calloc(i + 1, sizeof(char));
|
||||||
|
if (dest[index] == 0)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (s[i] != c && s[i])
|
||||||
|
{
|
||||||
|
dest[index][i] = s[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void call(char *s, char c, char **dest, int j)
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
int k;
|
||||||
|
|
||||||
|
k = 0;
|
||||||
|
index = 0;
|
||||||
|
while (j > index)
|
||||||
|
{
|
||||||
|
while (s[k] == c && s[k])
|
||||||
|
k++;
|
||||||
|
if (!s[k])
|
||||||
|
return ;
|
||||||
|
fill_tab(s + k, c, dest, index);
|
||||||
|
index++;
|
||||||
|
while (s[k] != c && s[k])
|
||||||
|
k++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_split(char const *s, char c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
char **dest;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
i = 0;
|
||||||
|
if (!s)
|
||||||
|
return (0);
|
||||||
|
while (s[i] == c && s[i])
|
||||||
|
i++;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
while (s[i] != c && s[i])
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
while (s[i] == c && s[i])
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (!(dest = (char**)malloc(sizeof(char*) * (i + j))))
|
||||||
|
return (0);
|
||||||
|
dest[j] = 0;
|
||||||
|
call((char*)s, c, dest, j);
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
26
libft/ft_strchr.c
Normal file
26
libft/ft_strchr.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/12 13:57:59 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 13:58:05 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strchr(const char *s, int c)
|
||||||
|
{
|
||||||
|
unsigned char *str;
|
||||||
|
|
||||||
|
str = (unsigned char*)s;
|
||||||
|
while ((*str != c) && (*str != 0))
|
||||||
|
str++;
|
||||||
|
if (*str == c)
|
||||||
|
return ((char*)str);
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
34
libft/ft_strdup.c
Normal file
34
libft/ft_strdup.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strdup.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:12:43 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 18:35:10 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strdup(const char *s)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char *sdup;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
i++;
|
||||||
|
sdup = malloc(sizeof(char) * (i + 1));
|
||||||
|
if (sdup == 0)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
sdup[i] = s[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
sdup[i] = 0;
|
||||||
|
return (sdup);
|
||||||
|
}
|
||||||
42
libft/ft_strjoin.c
Normal file
42
libft/ft_strjoin.c
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/11 15:38:13 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/16 17:00:44 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
char *dest;
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
if (!s1 || !s2)
|
||||||
|
return (0);
|
||||||
|
if (!(dest = (char*)malloc(ft_strlen(s1) + ft_strlen(s2) + 1)))
|
||||||
|
return (0);
|
||||||
|
while (s1[i] && s1)
|
||||||
|
{
|
||||||
|
dest[j] = s1[i];
|
||||||
|
j++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
i = 0;
|
||||||
|
while (s2[i] && s2)
|
||||||
|
{
|
||||||
|
dest[j] = s2[i];
|
||||||
|
j++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest[j] = 0;
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
34
libft/ft_strlcat.c
Normal file
34
libft/ft_strlcat.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcat.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:12:57 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 15:40:58 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
size_t k;
|
||||||
|
|
||||||
|
if (!size)
|
||||||
|
return (ft_strlen(src));
|
||||||
|
i = 0;
|
||||||
|
k = ft_strlen(dst);
|
||||||
|
if (k >= size)
|
||||||
|
return (ft_strlen(src) + size);
|
||||||
|
while (size - k - 1 && src[i])
|
||||||
|
{
|
||||||
|
dst[k + i] = src[i];
|
||||||
|
i++;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
dst[k + i] = 0;
|
||||||
|
return (k + ft_strlen(src));
|
||||||
|
}
|
||||||
36
libft/ft_strlcpy.c
Normal file
36
libft/ft_strlcpy.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:13:07 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/12 16:07:05 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcpy(char *dst, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
j = 0;
|
||||||
|
i = 0;
|
||||||
|
if (!src || !dst)
|
||||||
|
return (0);
|
||||||
|
while (src[i])
|
||||||
|
i++;
|
||||||
|
if (!size)
|
||||||
|
return (i);
|
||||||
|
while (size - 1 && src[j] != 0)
|
||||||
|
{
|
||||||
|
dst[j] = src[j];
|
||||||
|
j++;
|
||||||
|
size--;
|
||||||
|
}
|
||||||
|
dst[j] = 0;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
23
libft/ft_strlen.c
Normal file
23
libft/ft_strlen.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlen.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:13:19 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/11/29 17:12:23 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *s)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i] != 0)
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
32
libft/ft_strmapi.c
Normal file
32
libft/ft_strmapi.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmapi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/08 19:03:09 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/16 16:52:49 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||||
|
{
|
||||||
|
char *dest;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
dest = (char*)ft_calloc(ft_strlen(s) + 1, sizeof(char));
|
||||||
|
if (!dest)
|
||||||
|
return (0);
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
dest[i] = f(i, s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
28
libft/ft_strncmp.c
Normal file
28
libft/ft_strncmp.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strncmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:13:31 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/13 20:44:39 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (n && (s1[i] || s2[i]))
|
||||||
|
{
|
||||||
|
if (s1[i] != s2[i])
|
||||||
|
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||||
|
n--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
41
libft/ft_strnstr.c
Normal file
41
libft/ft_strnstr.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strnstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:13:42 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/13 22:55:27 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!little[i])
|
||||||
|
return ((char*)big);
|
||||||
|
if (!little[i])
|
||||||
|
return ((char*)big);
|
||||||
|
while (big[i] && len - i)
|
||||||
|
{
|
||||||
|
j = 0;
|
||||||
|
if (little[j] != big[i])
|
||||||
|
i++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (little[j] == big[i + j] && little[j] && len - i - j)
|
||||||
|
j++;
|
||||||
|
if (little[j] == 0)
|
||||||
|
return ((char*)&big[i]);
|
||||||
|
else
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
35
libft/ft_strrchr.c
Normal file
35
libft/ft_strrchr.c
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strrchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:13:52 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/16 16:14:41 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strrchr(const char *s, int c)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
char *last;
|
||||||
|
|
||||||
|
str = (char*)s;
|
||||||
|
if (c == 0)
|
||||||
|
{
|
||||||
|
while (*str)
|
||||||
|
str++;
|
||||||
|
return (str);
|
||||||
|
}
|
||||||
|
last = 0;
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
if (*str == c)
|
||||||
|
last = str;
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
return (last);
|
||||||
|
}
|
||||||
71
libft/ft_strtrim.c
Normal file
71
libft/ft_strtrim.c
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strtrim.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 23:52:05 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/16 18:06:01 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int is_set(char const *set, char c)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (set[i])
|
||||||
|
{
|
||||||
|
if (set[i] == c)
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int len_dest(const char *s1, char const *set)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
int j;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
len = ft_strlen(s1);
|
||||||
|
while (is_set(set, s1[i]))
|
||||||
|
i++;
|
||||||
|
while (is_set(set, s1[len - j - 1]))
|
||||||
|
j++;
|
||||||
|
len = len - j - i;
|
||||||
|
if (len < 0)
|
||||||
|
len = 0;
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_strtrim(char const *s1, char const *set)
|
||||||
|
{
|
||||||
|
int j;
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
char *dest;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
if (!s1)
|
||||||
|
return (0);
|
||||||
|
len = len_dest(s1, set);
|
||||||
|
if (!(dest = ft_calloc(len + 1, 1)))
|
||||||
|
return (0);
|
||||||
|
while (is_set(set, s1[i]))
|
||||||
|
i++;
|
||||||
|
while (s1[i] && len - j && len > 0)
|
||||||
|
{
|
||||||
|
dest[j] = s1[i];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
39
libft/ft_substr.c
Normal file
39
libft/ft_substr.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_substr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 22:54:40 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/16 16:45:34 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||||
|
{
|
||||||
|
char *dest;
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (0);
|
||||||
|
i = 0;
|
||||||
|
dest = malloc(1 * len + 1);
|
||||||
|
if (dest == 0)
|
||||||
|
return (0);
|
||||||
|
if (start > ft_strlen(s) || len == 0)
|
||||||
|
{
|
||||||
|
dest[i] = 0;
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
|
while (len && s[i + start])
|
||||||
|
{
|
||||||
|
dest[i] = s[i + start];
|
||||||
|
len--;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest[i] = 0;
|
||||||
|
return (dest);
|
||||||
|
}
|
||||||
20
libft/ft_tolower.c
Normal file
20
libft/ft_tolower.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tolower.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:14:05 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/11/29 17:20:51 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_tolower(int c)
|
||||||
|
{
|
||||||
|
if (c >= 65 && c <= 90)
|
||||||
|
c = c + 32;
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
20
libft/ft_toupper.c
Normal file
20
libft/ft_toupper.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_toupper.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/11/29 00:14:15 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/11/29 17:21:12 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_toupper(int c)
|
||||||
|
{
|
||||||
|
if (c >= 'a' && c <= 'z')
|
||||||
|
c = c - 32;
|
||||||
|
return (c);
|
||||||
|
}
|
||||||
72
libft/libft.h
Normal file
72
libft/libft.h
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <alexpomms@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2020/12/11 03:21:27 by apommier #+# #+# */
|
||||||
|
/* Updated: 2020/12/11 15:43:19 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_H
|
||||||
|
# define LIBFT_H
|
||||||
|
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct s_list
|
||||||
|
{
|
||||||
|
void *content;
|
||||||
|
struct s_list *next;
|
||||||
|
} t_list;
|
||||||
|
|
||||||
|
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_memccpy(void *dest, const void *src, int c, size_t n);
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
size_t ft_strlen(const char *s);
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
size_t ft_strlcpy(char *dst, const char *src, size_t size);
|
||||||
|
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||||
|
char *ft_strnstr(const char *big, const char *little, size_t len);
|
||||||
|
int ft_atoi(const char *nptr);
|
||||||
|
void *ft_calloc(size_t nmenb, 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_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);
|
||||||
|
|
||||||
|
t_list *ft_lstnew(void *content);
|
||||||
|
void ft_lstadd_front(t_list **alst, t_list *new);
|
||||||
|
int ft_lstsize(t_list *lst);
|
||||||
|
t_list *ft_lstlast(t_list *lst);
|
||||||
|
void ft_lstadd_back(t_list **alst, 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 *));
|
||||||
|
|
||||||
|
#endif
|
||||||
19
main.c
Normal file
19
main.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2021/11/25 23:15:43 by apommier #+# #+# */
|
||||||
|
/* Updated: 2021/11/25 23:57:06 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
push_swap(argc, argv);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
46
process.c
Normal file
46
process.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* process.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2021/11/25 23:15:09 by apommier #+# #+# */
|
||||||
|
/* Updated: 2021/11/25 23:15:09 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
void ft_sa_sb(t_list **list, t_list **process)
|
||||||
|
{
|
||||||
|
t_list *swap;
|
||||||
|
|
||||||
|
swap = (*list)->next->next;
|
||||||
|
(*list)->next->next = *list;
|
||||||
|
*list = (*list)->next;
|
||||||
|
(*list)->next->next = swap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_ra_rb(t_list **list, t_list **process)
|
||||||
|
{
|
||||||
|
t_list *swap;
|
||||||
|
|
||||||
|
swap = *list;
|
||||||
|
(ft_lstlast(*list))->next = *list;
|
||||||
|
*list = (*list)->next;
|
||||||
|
swap->next = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_pa(t_list **list_a, t_list **list_b, t_list **process)
|
||||||
|
{
|
||||||
|
ft_lstadd_front(list_a, *list_b);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ft_pb(t_list **list_a, t_list **list_b, t_list **process)
|
||||||
|
{
|
||||||
|
t_list *swap;
|
||||||
|
|
||||||
|
}
|
||||||
74
push_swap.c
Normal file
74
push_swap.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* push_swap.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2021/11/25 23:10:37 by apommier #+# #+# */
|
||||||
|
/* Updated: 2021/11/26 00:00:53 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "push_swap.h"
|
||||||
|
|
||||||
|
int is_nbr(int nbrarg, char **list)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (nbrarg)
|
||||||
|
{
|
||||||
|
i = 0;
|
||||||
|
*list++;
|
||||||
|
while ((*list)[i])
|
||||||
|
{
|
||||||
|
if (((*list)[i] < '0' || (*list)[i] > '9') && (*list)[i] != '-')
|
||||||
|
return (0);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
nbrarg--;
|
||||||
|
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int push_swap(int nbrarg, char **list)
|
||||||
|
{
|
||||||
|
t_list *start;
|
||||||
|
|
||||||
|
if (is_nbr(nbrarg++, list) == 0)
|
||||||
|
{
|
||||||
|
ft_putstr_fd("Error\n", 2);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
start = set_list(nbrarg++, list++)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int set_list(int nbrarg, char **list)
|
||||||
|
{
|
||||||
|
t_list *start;
|
||||||
|
|
||||||
|
start = ft_lstnew(&ft_atoi(*list))
|
||||||
|
while (nbrarg)
|
||||||
|
{
|
||||||
|
*list++;
|
||||||
|
ft_lstadd_back(&start, ft_lstnew(&ft_atoi(*list)));
|
||||||
|
}
|
||||||
|
return (start);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int is_sorted(t_list *list)
|
||||||
|
{
|
||||||
|
while (list->next)
|
||||||
|
{
|
||||||
|
if (list->content > list->next->content)
|
||||||
|
return (0);
|
||||||
|
else
|
||||||
|
list = list->next;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
23
push_swap.h
Normal file
23
push_swap.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* push_swap.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2021/11/25 23:15:17 by apommier #+# #+# */
|
||||||
|
/* Updated: 2021/11/25 23:48:20 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_PRINTF_H
|
||||||
|
# define FT_PRINTF_H
|
||||||
|
|
||||||
|
# include <stdio.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include "./libft/libft.h"
|
||||||
|
|
||||||
|
int push_swap(int nbrarg, char **list);
|
||||||
|
int is_nbr(int nbrarg, char **list);
|
||||||
|
|
||||||
|
#endif
|
||||||
12
sort3.c
Normal file
12
sort3.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sort3.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2021/11/25 23:15:22 by apommier #+# #+# */
|
||||||
|
/* Updated: 2021/11/25 23:15:22 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
12
sort5.c
Normal file
12
sort5.c
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sort5.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2021/11/25 23:15:27 by apommier #+# #+# */
|
||||||
|
/* Updated: 2021/11/25 23:15:27 by apommier ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user