Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
01c3cb94d2
70 changed files with 2094 additions and 0 deletions
42
color_letters.c
Normal file
42
color_letters.c
Normal file
|
@ -0,0 +1,42 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* color_letters.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kyork <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/04 16:44:50 by kyork #+# #+# */
|
||||
/* Updated: 2016/10/05 15:41:53 by kyork ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#define CSI "\033["
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int g_colors[] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14,
|
||||
16 + 5, 16 + 12, 16 + 23, 16 + 30, 52 + 0, 52 + 5, 52 + 6, 52 + 12, 52 + 20,
|
||||
88 + 1, 88 + 6, 88 + 12, 160 + 12, 196 + 30, 160 + 21};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char c;
|
||||
ssize_t read_size;
|
||||
|
||||
while (1)
|
||||
{
|
||||
read_size = read(0, &c, 1);
|
||||
if (read_size == 0)
|
||||
break ;
|
||||
if ('A' <= c && c <= 'Z')
|
||||
{
|
||||
printf("%s48;5;%dm%c", CSI, g_colors[c - 'A'], c);
|
||||
}
|
||||
else if (c == '.')
|
||||
printf("%sm%c", CSI, c);
|
||||
else if (c == '\n')
|
||||
printf("%sm%c", CSI, c);
|
||||
else
|
||||
printf("%c", c);
|
||||
}
|
||||
}
|
0
libft/.depend
Normal file
0
libft/.depend
Normal file
101
libft/Makefile
Normal file
101
libft/Makefile
Normal file
|
@ -0,0 +1,101 @@
|
|||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gtertysh <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2016/11/28 11:42:56 by gtertysh #+# #+# #
|
||||
# Updated: 2016/12/06 20:21:16 by gtertysh ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
NAME = libft.a
|
||||
SRC = 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_strdup.c \
|
||||
ft_strcpy.c \
|
||||
ft_strncpy.c \
|
||||
ft_strcat.c \
|
||||
ft_strncat.c \
|
||||
ft_strlcat.c \
|
||||
ft_strchr.c \
|
||||
ft_strrchr.c \
|
||||
ft_strstr.c \
|
||||
ft_strnstr.c \
|
||||
ft_strcmp.c \
|
||||
ft_strncmp.c \
|
||||
ft_atoi.c \
|
||||
ft_isalpha.c \
|
||||
ft_isdigit.c \
|
||||
ft_isalnum.c \
|
||||
ft_isascii.c \
|
||||
ft_isprint.c \
|
||||
ft_toupper.c \
|
||||
ft_tolower.c \
|
||||
\
|
||||
ft_memalloc.c \
|
||||
ft_memdel.c \
|
||||
ft_strnew.c \
|
||||
ft_strdel.c \
|
||||
ft_strclr.c \
|
||||
ft_striter.c \
|
||||
ft_striteri.c \
|
||||
ft_strmap.c \
|
||||
ft_strmap.c \
|
||||
ft_strmapi.c \
|
||||
ft_strequ.c \
|
||||
ft_strnequ.c \
|
||||
ft_strsub.c \
|
||||
ft_strjoin.c \
|
||||
ft_strtrim.c \
|
||||
ft_strsplit.c \
|
||||
ft_itoa.c \
|
||||
ft_putchar.c \
|
||||
ft_putstr.c \
|
||||
ft_putendl.c \
|
||||
ft_putnbr.c \
|
||||
ft_putchar_fd.c \
|
||||
ft_putstr_fd.c \
|
||||
ft_putendl_fd.c \
|
||||
ft_putnbr_fd.c \
|
||||
\
|
||||
ft_lstnew.c \
|
||||
ft_lstdelone.c \
|
||||
ft_lstdel.c \
|
||||
ft_lstadd.c \
|
||||
ft_lstiter.c \
|
||||
ft_lstmap.c \
|
||||
ft_lststrsplit.c \
|
||||
ft_lstfind.c \
|
||||
ft_lst_at.c \
|
||||
ft_lstadd_back.c \
|
||||
\
|
||||
ft_realloc.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
INC = -I libft.h
|
||||
CC = clang
|
||||
FLAGS = -Werror -Wextra -Wall
|
||||
|
||||
all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJ)
|
||||
ar rcs $(NAME) $(OBJ)
|
||||
|
||||
%.o: %.c libft.h
|
||||
$(CC) $(FLAGS) $(INC) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ)
|
||||
|
||||
fclean: clean
|
||||
rm -rf $(NAME)
|
||||
|
||||
re: clean all
|
1
libft/author
Normal file
1
libft/author
Normal file
|
@ -0,0 +1 @@
|
|||
gtertysh
|
35
libft/ft_atoi.c
Normal file
35
libft/ft_atoi.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 19:51:54 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_atoi(const char *str)
|
||||
{
|
||||
int numb;
|
||||
int is_negative;
|
||||
|
||||
numb = 0;
|
||||
is_negative = 0;
|
||||
while (*str == ' ' || *str == '\n' || *str == '\t' ||
|
||||
*str == '\r' || *str == '\f' || *str == '\v')
|
||||
str++;
|
||||
if (*str == '-' && str++)
|
||||
is_negative = 1;
|
||||
else if (*str == '+')
|
||||
str++;
|
||||
while (*str >= '0' && *str <= '9' && *str != '\0')
|
||||
{
|
||||
numb = numb * 10 + *str - '0';
|
||||
str++;
|
||||
}
|
||||
if (is_negative)
|
||||
return (-numb);
|
||||
return (numb);
|
||||
}
|
18
libft/ft_bzero.c
Normal file
18
libft/ft_bzero.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_bzero.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 16:19:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/28 16:39:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_bzero(void *s, size_t n)
|
||||
{
|
||||
ft_memset(s, 0, n);
|
||||
}
|
20
libft/ft_isalnum.c
Normal file
20
libft/ft_isalnum.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalnum.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:11:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:17:24 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalnum(int c)
|
||||
{
|
||||
if (ft_isalpha(c) || ft_isdigit(c))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
21
libft/ft_isalpha.c
Normal file
21
libft/ft_isalpha.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isalpha.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 14:58:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:05:30 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isalpha(int c)
|
||||
{
|
||||
if ((c >= 'A' && c <= 'Z') ||
|
||||
(c >= 'a' && c <= 'z'))
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
20
libft/ft_isascii.c
Normal file
20
libft/ft_isascii.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isascii.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:18:01 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:21:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isascii(int c)
|
||||
{
|
||||
if (c >= 0 && c <= 127)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
20
libft/ft_isdigit.c
Normal file
20
libft/ft_isdigit.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isdigit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:08:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:09:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isdigit(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
20
libft/ft_isprint.c
Normal file
20
libft/ft_isprint.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_isprint.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:22:01 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:24:46 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_isprint(int c)
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
73
libft/ft_itoa.c
Normal file
73
libft/ft_itoa.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/02 19:59:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:12:59 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void help_help(int *n, char *ret, int *i)
|
||||
{
|
||||
if (*n < 0)
|
||||
{
|
||||
ret[0] = '-';
|
||||
*i = *i + 1;
|
||||
*n = -(*n);
|
||||
}
|
||||
if (*n == 0)
|
||||
ret[0] = '0';
|
||||
}
|
||||
|
||||
static char *help(int n, long *div)
|
||||
{
|
||||
int len;
|
||||
char *ret;
|
||||
|
||||
ret = NULL;
|
||||
len = 0;
|
||||
while (n)
|
||||
{
|
||||
n /= 10;
|
||||
*div = *div * 10;
|
||||
len++;
|
||||
}
|
||||
if (n < 0 || n == 0)
|
||||
len++;
|
||||
ret = ft_strnew(len);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
char *ft_itoa(int n)
|
||||
{
|
||||
char *ret;
|
||||
long div;
|
||||
int i;
|
||||
int exception;
|
||||
|
||||
exception = 0;
|
||||
div = 1;
|
||||
i = 0;
|
||||
if (n == -2147483648)
|
||||
{
|
||||
n = n / 10;
|
||||
exception = 1;
|
||||
}
|
||||
if (!(ret = help(n, &div)))
|
||||
return (NULL);
|
||||
help_help(&n, ret, &i);
|
||||
while (div > 1)
|
||||
{
|
||||
div /= 10;
|
||||
ret[i++] = n / div + '0';
|
||||
n = n % div;
|
||||
}
|
||||
if (exception)
|
||||
ret[i] = '8';
|
||||
return (ret);
|
||||
}
|
20
libft/ft_lst_at.c
Normal file
20
libft/ft_lst_at.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lst_at.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 17:17:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:49:09 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lst_at(t_list *l, unsigned int at)
|
||||
{
|
||||
while (at-- && l)
|
||||
l = l->next;
|
||||
return (l);
|
||||
}
|
22
libft/ft_lstadd.c
Normal file
22
libft/ft_lstadd.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 19:01:42 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 19:12:10 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd(t_list **alst, t_list *new)
|
||||
{
|
||||
if (alst)
|
||||
{
|
||||
new->next = *alst;
|
||||
*alst = new;
|
||||
}
|
||||
}
|
27
libft/ft_lstadd_back.c
Normal file
27
libft/ft_lstadd_back.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstadd_back.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 17:45:28 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 20:06:23 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstadd_back(t_list **l, void *content, size_t size)
|
||||
{
|
||||
if (!l)
|
||||
return ;
|
||||
if (*l == NULL)
|
||||
(*l) = ft_lstnew(content, size);
|
||||
else
|
||||
{
|
||||
while ((*l)->next)
|
||||
l = &(*l)->next;
|
||||
(*l)->next = ft_lstnew(content, size);
|
||||
}
|
||||
}
|
31
libft/ft_lstdel.c
Normal file
31
libft/ft_lstdel.c
Normal file
|
@ -0,0 +1,31 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 18:48:08 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/05 18:50:39 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
t_list *tmp;
|
||||
|
||||
tmp = NULL;
|
||||
if (alst)
|
||||
{
|
||||
while (*alst)
|
||||
{
|
||||
tmp = (*alst)->next;
|
||||
del((*alst)->content, (*alst)->content_size);
|
||||
free(*alst);
|
||||
*alst = tmp;
|
||||
}
|
||||
*alst = NULL;
|
||||
}
|
||||
}
|
23
libft/ft_lstdelone.c
Normal file
23
libft/ft_lstdelone.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstdelone.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 18:30:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:46:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t))
|
||||
{
|
||||
if (alst && *alst && del)
|
||||
{
|
||||
del((*alst)->content, (*alst)->content_size);
|
||||
free(*alst);
|
||||
*alst = NULL;
|
||||
}
|
||||
}
|
24
libft/ft_lstfind.c
Normal file
24
libft/ft_lstfind.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstfind.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 16:56:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:47:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstfind(t_list *lst, void *data, size_t size)
|
||||
{
|
||||
while (lst)
|
||||
{
|
||||
if ((ft_memcmp(lst->content, data, size) == 0))
|
||||
return (lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (0);
|
||||
}
|
22
libft/ft_lstiter.c
Normal file
22
libft/ft_lstiter.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstiter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 19:13:25 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:47:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem))
|
||||
{
|
||||
while (lst && f)
|
||||
{
|
||||
f(lst);
|
||||
lst = lst->next;
|
||||
}
|
||||
}
|
26
libft/ft_lstmap.c
Normal file
26
libft/ft_lstmap.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 19:18:15 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 18:08:53 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = NULL;
|
||||
if (lst && f)
|
||||
{
|
||||
new = f(lst);
|
||||
new->next = ft_lstmap(lst->next, f);
|
||||
}
|
||||
return (new);
|
||||
}
|
40
libft/ft_lstnew.c
Normal file
40
libft/ft_lstnew.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:59:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:45:44 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size)
|
||||
{
|
||||
t_list *new;
|
||||
|
||||
new = NULL;
|
||||
if ((new = (t_list *)malloc(sizeof(t_list))))
|
||||
{
|
||||
if (!content)
|
||||
{
|
||||
new->content = NULL;
|
||||
new->content_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!(new->content = (char *)malloc(content_size)))
|
||||
{
|
||||
free(new);
|
||||
return (NULL);
|
||||
}
|
||||
ft_memcpy(new->content, content, content_size);
|
||||
new->content_size = content_size;
|
||||
}
|
||||
new->next = NULL;
|
||||
}
|
||||
return (new);
|
||||
}
|
38
libft/ft_lststrsplit.c
Normal file
38
libft/ft_lststrsplit.c
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lststrsplit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 15:32:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 20:07:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lststrsplit(const char *s, char c)
|
||||
{
|
||||
char **arr_table;
|
||||
t_list *lst_table;
|
||||
t_list *tmp;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
lst_table = NULL;
|
||||
arr_table = ft_strsplit(s, c);
|
||||
if (arr_table[i])
|
||||
{
|
||||
lst_table = ft_lstnew(arr_table[i], ft_strlen(arr_table[i]) + 1);
|
||||
tmp = lst_table;
|
||||
i++;
|
||||
while (arr_table[i])
|
||||
{
|
||||
tmp->next = ft_lstnew(arr_table[i], ft_strlen(arr_table[i]) + 1);
|
||||
tmp = tmp->next;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (lst_table);
|
||||
}
|
23
libft/ft_memalloc.c
Normal file
23
libft/ft_memalloc.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memalloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 16:07:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 16:49:22 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memalloc(size_t size)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
ret = NULL;
|
||||
if ((ret = malloc(size)))
|
||||
ft_bzero(ret, size);
|
||||
return (ret);
|
||||
}
|
28
libft/ft_memccpy.c
Normal file
28
libft/ft_memccpy.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memccpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 13:35:32 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/05 13:12:20 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
*((char *)dst + i) = *((const char *)src + i);
|
||||
if (*((unsigned char *)src + i) == (unsigned char)c)
|
||||
return ((dst + i + 1));
|
||||
i++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
24
libft/ft_memchr.c
Normal file
24
libft/ft_memchr.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 15:55:30 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:51:40 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memchr(const void *s, int c, size_t n)
|
||||
{
|
||||
while (n--)
|
||||
{
|
||||
if (*(unsigned char *)s == (unsigned char)c)
|
||||
return ((unsigned char *)s);
|
||||
s++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
25
libft/ft_memcmp.c
Normal file
25
libft/ft_memcmp.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 16:31:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:07:47 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||
{
|
||||
while ((int)n--)
|
||||
{
|
||||
if ((*(unsigned char *)s1 != *(unsigned char *)s2))
|
||||
return (*(unsigned char *)s1 - *(unsigned char *)s2);
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return (0);
|
||||
}
|
26
libft/ft_memcpy.c
Normal file
26
libft/ft_memcpy.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 17:19:13 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/29 14:52:27 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memcpy(void *dst, const void *src, size_t len)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
*((char *)dst + i) = *((const char *)src + i);
|
||||
i++;
|
||||
}
|
||||
return (dst);
|
||||
}
|
22
libft/ft_memdel.c
Normal file
22
libft/ft_memdel.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 16:50:09 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:18:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_memdel(void **ap)
|
||||
{
|
||||
if (ap)
|
||||
{
|
||||
free(*ap);
|
||||
*ap = NULL;
|
||||
}
|
||||
}
|
33
libft/ft_memmove.c
Normal file
33
libft/ft_memmove.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memmove.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/29 14:55:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 16:38:06 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memmove(void *dst, const void *src, size_t len)
|
||||
{
|
||||
unsigned char *tmp;
|
||||
|
||||
tmp = dst;
|
||||
if (src < dst)
|
||||
{
|
||||
src += len;
|
||||
dst += len;
|
||||
while (len--)
|
||||
*((char *)--dst) = *((const char *)--src);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (len--)
|
||||
*(char *)dst++ = *(const char *)src++;
|
||||
}
|
||||
return (tmp);
|
||||
}
|
23
libft/ft_memset.c
Normal file
23
libft/ft_memset.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_memset.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 12:06:20 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/28 16:47:35 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len)
|
||||
{
|
||||
unsigned char *s;
|
||||
|
||||
s = (unsigned char *)b;
|
||||
while (len--)
|
||||
*s++ = (unsigned char)c;
|
||||
return (b);
|
||||
}
|
18
libft/ft_putchar.c
Normal file
18
libft/ft_putchar.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 14:29:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:04:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
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: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:03:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:04:30 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putchar_fd(char c, int fd)
|
||||
{
|
||||
write(fd, &c, 1);
|
||||
}
|
21
libft/ft_putendl.c
Normal file
21
libft/ft_putendl.c
Normal file
|
@ -0,0 +1,21 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putendl.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 14:57:59 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:24:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl(char const *s)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(1, s++, 1);
|
||||
write(1, "\n", 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: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:17:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:24:55 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putendl_fd(char const *s, int fd)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(fd, s++, 1);
|
||||
write(fd, "\n", 1);
|
||||
}
|
58
libft/ft_putnbr.c
Normal file
58
libft/ft_putnbr.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:26:28 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void ft_putnbr_print(int nb, long div, int exeption)
|
||||
{
|
||||
if (nb < 0)
|
||||
{
|
||||
nb = -nb;
|
||||
ft_putchar('-');
|
||||
}
|
||||
if (div == 1)
|
||||
ft_putchar('0');
|
||||
else
|
||||
{
|
||||
while (div > 1)
|
||||
{
|
||||
div = div / 10;
|
||||
ft_putchar(nb / div + '0');
|
||||
nb = nb % div;
|
||||
}
|
||||
}
|
||||
if (exeption)
|
||||
ft_putchar('8');
|
||||
}
|
||||
|
||||
void ft_putnbr(int nb)
|
||||
{
|
||||
int temp;
|
||||
long div;
|
||||
int exeption;
|
||||
|
||||
div = 1;
|
||||
exeption = 0;
|
||||
temp = nb;
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
nb = nb / 10;
|
||||
temp = temp / 10;
|
||||
exeption = 1;
|
||||
}
|
||||
while (temp)
|
||||
{
|
||||
temp = temp / 10;
|
||||
div = div * 10;
|
||||
}
|
||||
ft_putnbr_print(nb, div, exeption);
|
||||
}
|
58
libft/ft_putnbr_fd.c
Normal file
58
libft/ft_putnbr_fd.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:19:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:25:42 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
static void ft_putnbr_print(int nb, long div, int exeption, int fd)
|
||||
{
|
||||
if (nb < 0)
|
||||
{
|
||||
nb = -nb;
|
||||
ft_putchar_fd('-', fd);
|
||||
}
|
||||
if (div == 1)
|
||||
ft_putchar_fd('0', fd);
|
||||
else
|
||||
{
|
||||
while (div > 1)
|
||||
{
|
||||
div = div / 10;
|
||||
ft_putchar_fd(nb / div + '0', fd);
|
||||
nb = nb % div;
|
||||
}
|
||||
}
|
||||
if (exeption)
|
||||
ft_putchar_fd('8', fd);
|
||||
}
|
||||
|
||||
void ft_putnbr_fd(int nb, int fd)
|
||||
{
|
||||
int temp;
|
||||
long div;
|
||||
int exeption;
|
||||
|
||||
div = 1;
|
||||
exeption = 0;
|
||||
temp = nb;
|
||||
if (nb == -2147483648)
|
||||
{
|
||||
nb = nb / 10;
|
||||
temp = temp / 10;
|
||||
exeption = 1;
|
||||
}
|
||||
while (temp)
|
||||
{
|
||||
temp = temp / 10;
|
||||
div = div * 10;
|
||||
}
|
||||
ft_putnbr_print(nb, div, exeption, fd);
|
||||
}
|
20
libft/ft_putstr.c
Normal file
20
libft/ft_putstr.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 14:55:00 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:25:12 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr(char const *s)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(1, s++, 1);
|
||||
}
|
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: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/04 15:14:02 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/04 15:26:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_putstr_fd(char const *s, int fd)
|
||||
{
|
||||
if (s)
|
||||
while (*s)
|
||||
write(fd, s++, 1);
|
||||
}
|
32
libft/ft_realloc.c
Normal file
32
libft/ft_realloc.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_realloc.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/06 18:57:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/07 17:16:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void *ft_realloc(void *old, unsigned int new_size, unsigned int old_size)
|
||||
{
|
||||
void *new;
|
||||
|
||||
new = NULL;
|
||||
if ((new = ft_memalloc(new_size)))
|
||||
{
|
||||
if (old)
|
||||
{
|
||||
if (old_size)
|
||||
ft_memcpy(new, old, old_size);
|
||||
free(old);
|
||||
old = NULL;
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
return (old);
|
||||
}
|
26
libft/ft_strcat.c
Normal file
26
libft/ft_strcat.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 14:58:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 15:02:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcat(char *s1, const char *s2)
|
||||
{
|
||||
char *s;
|
||||
|
||||
s = s1;
|
||||
while (*s1)
|
||||
s1++;
|
||||
while (*s2)
|
||||
*s1++ = *s2++;
|
||||
*s1 = '\0';
|
||||
return (s);
|
||||
}
|
22
libft/ft_strchr.c
Normal file
22
libft/ft_strchr.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strchr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 18:14:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:29:27 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strchr(const char *s, int c)
|
||||
{
|
||||
while (*s && *s != (char)c)
|
||||
s++;
|
||||
if (*s == (char)c)
|
||||
return ((char *)s);
|
||||
return (NULL);
|
||||
}
|
19
libft/ft_strclr.c
Normal file
19
libft/ft_strclr.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strclr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:21:04 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:30:26 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strclr(char *s)
|
||||
{
|
||||
if (s)
|
||||
ft_bzero(s, ft_strlen(s));
|
||||
}
|
25
libft/ft_strcmp.c
Normal file
25
libft/ft_strcmp.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 13:40:16 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:52:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strcmp(const char *s1, const char *s2)
|
||||
{
|
||||
while (*s1 && *s2 && *(unsigned char *)s1 == *(unsigned char *)s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (*(unsigned char *)s1 != *(unsigned char *)s2)
|
||||
return (*(unsigned char *)s1 - *(unsigned char *)s2);
|
||||
return (0);
|
||||
}
|
24
libft/ft_strcpy.c
Normal file
24
libft/ft_strcpy.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 13:03:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 13:09:52 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strcpy(char *dst, const char *src)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (*src)
|
||||
*(dst + i++) = *src++;
|
||||
*(dst + i) = '\0';
|
||||
return (dst);
|
||||
}
|
18
libft/ft_strdel.c
Normal file
18
libft/ft_strdel.c
Normal file
|
@ -0,0 +1,18 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdel.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:15:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:17:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_strdel(char **as)
|
||||
{
|
||||
ft_memdel((void **)as);
|
||||
}
|
26
libft/ft_strdup.c
Normal file
26
libft/ft_strdup.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 12:51:34 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:31:11 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strdup(const char *s1)
|
||||
{
|
||||
char *new;
|
||||
size_t size;
|
||||
|
||||
size = ft_strlen(s1);
|
||||
if (!(new = (char *)malloc(sizeof(char) * (size + 1))))
|
||||
return (0);
|
||||
ft_memcpy(new, s1, size);
|
||||
*(new + size) = '\0';
|
||||
return (new);
|
||||
}
|
28
libft/ft_strequ.c
Normal file
28
libft/ft_strequ.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 18:51:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 19:00:02 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strequ(char const *s1, char const *s2)
|
||||
{
|
||||
if (s1 && s2)
|
||||
{
|
||||
while (*s1 && *s2 && *s1 == *s2)
|
||||
{
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
if (*s1 != *s2)
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
20
libft/ft_striter.c
Normal file
20
libft/ft_striter.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striter.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:36:39 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:37:33 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striter(char *s, void (*f)(char *))
|
||||
{
|
||||
if (s && f)
|
||||
while (*s)
|
||||
f(s++);
|
||||
}
|
23
libft/ft_striteri.c
Normal file
23
libft/ft_striteri.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_striteri.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:31:23 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:38:48 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *))
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
if (s && f)
|
||||
while (*s)
|
||||
f(i++, s++);
|
||||
}
|
32
libft/ft_strjoin.c
Normal file
32
libft/ft_strjoin.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 19:53:30 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:18:10 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strjoin(char const *s1, char const *s2)
|
||||
{
|
||||
char *ret;
|
||||
char *tmp;
|
||||
|
||||
ret = NULL;
|
||||
if (s1 &&
|
||||
s2 &&
|
||||
(ret = ft_strnew(ft_strlen(s1) + ft_strlen(s2))) &&
|
||||
(tmp = ret))
|
||||
{
|
||||
while (*s1)
|
||||
*tmp++ = *s1++;
|
||||
while (*s2)
|
||||
*tmp++ = *s2++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
32
libft/ft_strlcat.c
Normal file
32
libft/ft_strlcat.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 15:16:55 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 18:13:07 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size)
|
||||
{
|
||||
size_t dst_size;
|
||||
size_t src_size;
|
||||
|
||||
dst_size = ft_strlen(dst);
|
||||
src_size = ft_strlen(src);
|
||||
while (*dst)
|
||||
dst++;
|
||||
if (size > dst_size)
|
||||
{
|
||||
while (*src && (size-- - dst_size - 1))
|
||||
*dst++ = *src++;
|
||||
*dst = '\0';
|
||||
return (src_size + dst_size);
|
||||
}
|
||||
return (src_size + size);
|
||||
}
|
23
libft/ft_strlen.c
Normal file
23
libft/ft_strlen.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 12:37:23 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 12:48:50 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
size_t ft_strlen(const char *s)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
len = 0;
|
||||
while (*(unsigned char *)s++)
|
||||
len++;
|
||||
return (len);
|
||||
}
|
30
libft/ft_strmap.c
Normal file
30
libft/ft_strmap.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:39:51 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 19:53:31 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmap(char const *s, char (*f)(char))
|
||||
{
|
||||
char *ret;
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
ret = NULL;
|
||||
if (s)
|
||||
if ((ret = (char *)ft_strnew(ft_strlen(s))))
|
||||
while (*(s + i))
|
||||
{
|
||||
*(ret + i) = f(*(s + i));
|
||||
i++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
30
libft/ft_strmapi.c
Normal file
30
libft/ft_strmapi.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strmapi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 18:47:40 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:18:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||
{
|
||||
char *ret;
|
||||
unsigned int i;
|
||||
|
||||
i = 0;
|
||||
ret = NULL;
|
||||
if (s)
|
||||
if ((ret = (char *)ft_strnew(ft_strlen(s))))
|
||||
while (*(s + i))
|
||||
{
|
||||
*(ret + i) = f(i, *(s + i));
|
||||
i++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
28
libft/ft_strncat.c
Normal file
28
libft/ft_strncat.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 15:03:18 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 15:11:23 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncat(char *s1, const char *s2, size_t n)
|
||||
{
|
||||
char *s;
|
||||
size_t s1_size;
|
||||
|
||||
s = s1;
|
||||
s1_size = sizeof(s1);
|
||||
while (*s1)
|
||||
s1++;
|
||||
while (*s2 && s1_size - 1 && n--)
|
||||
*s1++ = *s2++;
|
||||
*s1 = '\0';
|
||||
return (s);
|
||||
}
|
29
libft/ft_strncmp.c
Normal file
29
libft/ft_strncmp.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 14:33:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:23:45 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < n && (*s1 || *s2))
|
||||
{
|
||||
if (*(unsigned char *)s1 != *(unsigned char *)s2)
|
||||
return (*(unsigned char *)s1 - *(unsigned char *)s2);
|
||||
s1++;
|
||||
s2++;
|
||||
i++;
|
||||
}
|
||||
return (0);
|
||||
}
|
30
libft/ft_strncpy.c
Normal file
30
libft/ft_strncpy.c
Normal file
|
@ -0,0 +1,30 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strncpy.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 13:12:41 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/11/30 14:39:28 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strncpy(char *dst, const char *src, size_t len)
|
||||
{
|
||||
char *new_dest;
|
||||
|
||||
new_dest = dst;
|
||||
while (len && *src)
|
||||
{
|
||||
*new_dest++ = *src++;
|
||||
if (!len)
|
||||
return (dst);
|
||||
len--;
|
||||
}
|
||||
while (len-- > 0)
|
||||
*(new_dest++) = '\0';
|
||||
return (dst);
|
||||
}
|
22
libft/ft_strnequ.c
Normal file
22
libft/ft_strnequ.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnequ.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 19:00:40 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 19:00:55 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n)
|
||||
{
|
||||
if (s1 && s2)
|
||||
while (n--)
|
||||
if (ft_tolower(*s1++) != ft_tolower(*s2++))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
25
libft/ft_strnew.c
Normal file
25
libft/ft_strnew.c
Normal file
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnew.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 17:09:46 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 17:14:53 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnew(size_t size)
|
||||
{
|
||||
char *ret;
|
||||
|
||||
ret = NULL;
|
||||
if ((ret = (char *)malloc(size + 1)))
|
||||
{
|
||||
ft_bzero(ret, size + 1);
|
||||
}
|
||||
return (ret);
|
||||
}
|
33
libft/ft_strnstr.c
Normal file
33
libft/ft_strnstr.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strnstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 20:26:05 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 13:22:59 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strnstr(const char *big, const char *little, size_t len)
|
||||
{
|
||||
size_t l;
|
||||
size_t b;
|
||||
|
||||
l = ft_strlen(little);
|
||||
b = ft_strlen(big);
|
||||
if (*little == '\0')
|
||||
return ((char *)big);
|
||||
while (len >= l && b)
|
||||
{
|
||||
if (ft_memcmp(big, little, l) == 0)
|
||||
return ((char *)big);
|
||||
big++;
|
||||
len--;
|
||||
b--;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
27
libft/ft_strrchr.c
Normal file
27
libft/ft_strrchr.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strrchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 18:32:21 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:19:20 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strrchr(const char *s, int c)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
str = s;
|
||||
while (*s)
|
||||
s++;
|
||||
while (s != str && *s != (char)c)
|
||||
s--;
|
||||
if (*s == (char)c)
|
||||
return ((char *)s);
|
||||
return (NULL);
|
||||
}
|
85
libft/ft_strsplit.c
Normal file
85
libft/ft_strsplit.c
Normal file
|
@ -0,0 +1,85 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsplit.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/02 17:36:40 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/07 17:24:37 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
static int count_words(char const *str, char c)
|
||||
{
|
||||
int words;
|
||||
int has_word;
|
||||
|
||||
words = 0;
|
||||
has_word = 0;
|
||||
while (*str)
|
||||
{
|
||||
while (*str == c)
|
||||
str++;
|
||||
while (*str != c && *str)
|
||||
{
|
||||
str++;
|
||||
has_word = 1;
|
||||
}
|
||||
if (has_word)
|
||||
words++;
|
||||
has_word = 0;
|
||||
}
|
||||
return (words);
|
||||
}
|
||||
|
||||
static int fill_table(char const *str, char **table, char c)
|
||||
{
|
||||
int chars;
|
||||
int char_position;
|
||||
int word_position;
|
||||
|
||||
word_position = 0;
|
||||
while (*str)
|
||||
{
|
||||
chars = 0;
|
||||
char_position = 0;
|
||||
while (*str == c)
|
||||
str++;
|
||||
while (*str != c && *str && ++chars)
|
||||
str++;
|
||||
if (chars != 0)
|
||||
{
|
||||
if (!(table[word_position] = malloc(sizeof(char) * (chars + 1))))
|
||||
return (1);
|
||||
while (chars)
|
||||
table[word_position][char_position++] = *(str - chars--);
|
||||
table[word_position++][char_position] = '\0';
|
||||
}
|
||||
}
|
||||
table[word_position] = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
char **ft_strsplit(char const *s, char c)
|
||||
{
|
||||
char **table;
|
||||
int words;
|
||||
|
||||
table = NULL;
|
||||
if (!s)
|
||||
return (NULL);
|
||||
words = count_words(s, c);
|
||||
if (!words)
|
||||
{
|
||||
if (!(table = (char **)malloc(sizeof(char *))))
|
||||
return (NULL);
|
||||
}
|
||||
else if (!(table = (char **)malloc(sizeof(char *) * (words + 1))))
|
||||
return (NULL);
|
||||
if (fill_table(s, table, c))
|
||||
return (table);
|
||||
return (table);
|
||||
}
|
29
libft/ft_strstr.c
Normal file
29
libft/ft_strstr.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/30 19:32:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:23:54 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strstr(const char *big, const char *little)
|
||||
{
|
||||
size_t l;
|
||||
|
||||
l = ft_strlen(little);
|
||||
if (!*little)
|
||||
return ((char *)big);
|
||||
while (*big)
|
||||
{
|
||||
if (!(ft_memcmp(big, little, l)))
|
||||
return ((char *)big);
|
||||
big++;
|
||||
}
|
||||
return (NULL);
|
||||
}
|
27
libft/ft_strsub.c
Normal file
27
libft/ft_strsub.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strsub.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 19:02:56 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/02 16:21:00 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len)
|
||||
{
|
||||
char *ret;
|
||||
char *tmp;
|
||||
|
||||
ret = NULL;
|
||||
if (s)
|
||||
if ((ret = ft_strnew(len)) &&
|
||||
(tmp = ret))
|
||||
while (len--)
|
||||
*tmp++ = *(s++ + start);
|
||||
return (ret);
|
||||
}
|
40
libft/ft_strtrim.c
Normal file
40
libft/ft_strtrim.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strtrim.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 20:25:11 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 14:24:05 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
char *ft_strtrim(char const *s)
|
||||
{
|
||||
char *ret;
|
||||
char *tmp;
|
||||
const char *start;
|
||||
const char *end;
|
||||
|
||||
ret = NULL;
|
||||
if (s)
|
||||
{
|
||||
while (*s == ' ' || *s == '\n' || *s == '\t')
|
||||
s++;
|
||||
start = s;
|
||||
while (*s && *(s + 1))
|
||||
s++;
|
||||
while (*s == ' ' || *s == '\n' || *s == '\t')
|
||||
s--;
|
||||
end = s;
|
||||
if (!(ret = ft_strnew(end - start + 1)))
|
||||
return (ret);
|
||||
tmp = ret;
|
||||
while (start <= end)
|
||||
*tmp++ = *start++;
|
||||
}
|
||||
return (ret);
|
||||
}
|
20
libft/ft_tolower.c
Normal file
20
libft/ft_tolower.c
Normal file
|
@ -0,0 +1,20 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_tolower.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:58:52 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:59:14 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_tolower(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
return (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: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/12/01 15:26:03 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/01 15:58:00 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
int ft_toupper(int c)
|
||||
{
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c - 32);
|
||||
return (c);
|
||||
}
|
97
libft/libft.h
Normal file
97
libft/libft.h
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* libft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2016/11/28 12:21:43 by gtertysh #+# #+# */
|
||||
/* Updated: 2016/12/06 20:08:35 by gtertysh ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef LIBFT_H
|
||||
# define LIBFT_H
|
||||
|
||||
# include <string.h>
|
||||
# include <stdlib.h>
|
||||
# include <unistd.h>
|
||||
|
||||
typedef struct s_list
|
||||
{
|
||||
void *content;
|
||||
size_t content_size;
|
||||
struct s_list *next;
|
||||
} t_list;
|
||||
|
||||
void *ft_memset(void *b, int c, size_t len);
|
||||
void ft_bzero(void *s, size_t n);
|
||||
void *ft_memcpy(void *dst, const void *src, size_t len);
|
||||
void *ft_memccpy(void *dst, const void *src, int c, size_t n);
|
||||
void *ft_memmove(void *dst, const void *src, size_t len);
|
||||
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);
|
||||
char *ft_strdup(const char *s1);
|
||||
char *ft_strcpy(char *dst, const char *src);
|
||||
char *ft_strncpy(char *dst, const char *src, size_t len);
|
||||
char *ft_strcat(char *s1, const char *s2);
|
||||
char *ft_strncat(char *s1, const char *s2, size_t n);
|
||||
size_t ft_strlcat(char *dst, const char *src, size_t size);
|
||||
char *ft_strchr(const char *s, int c);
|
||||
char *ft_strrchr(const char *s, int c);
|
||||
char *ft_strstr(const char *big, const char *little);
|
||||
char *ft_strnstr(const char *big, const char *little,
|
||||
size_t len);
|
||||
int ft_strcmp(const char *s1, const char *s2);
|
||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int ft_atoi(const char *str);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
int ft_isalpha(int c);
|
||||
int ft_isalnum(int c);
|
||||
int ft_isascii(int c);
|
||||
int ft_isprint(int c);
|
||||
int ft_tolower(int c);
|
||||
int ft_toupper(int c);
|
||||
|
||||
void *ft_memalloc(size_t size);
|
||||
void ft_memdel(void **ap);
|
||||
char *ft_strnew(size_t size);
|
||||
void ft_strdel(char **as);
|
||||
void ft_strclr(char *s);
|
||||
void ft_striter(char *s, void (*f)(char *));
|
||||
void ft_striteri(char *s, void (*f)(unsigned int, char *));
|
||||
char *ft_strmap(char const *s, char (*f)(char));
|
||||
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||
int ft_strequ(char const *s1, char const *s2);
|
||||
int ft_strnequ(char const *s1, char const *s2, size_t n);
|
||||
char *ft_strsub(char const *s, unsigned int start, size_t len);
|
||||
char *ft_strjoin(char const *s1, char const *s2);
|
||||
char *ft_strtrim(char const *s);
|
||||
char **ft_strsplit(char const *s, char c);
|
||||
char *ft_itoa(int c);
|
||||
void ft_putchar(char c);
|
||||
void ft_putstr(char const *s);
|
||||
void ft_putendl(char const *s);
|
||||
void ft_putnbr(int n);
|
||||
void ft_putchar_fd(char c, int fd);
|
||||
void ft_putstr_fd(char const *s, int fd);
|
||||
void ft_putendl_fd(char const *s, int fd);
|
||||
void ft_putnbr_fd(int n, int fd);
|
||||
|
||||
t_list *ft_lstnew(void const *content, size_t content_size);
|
||||
void ft_lstdelone(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstdel(t_list **alst, void (*del)(void *, size_t));
|
||||
void ft_lstadd(t_list **alst, t_list *new);
|
||||
void ft_lstiter(t_list *lst, void (*f)(t_list *elem));
|
||||
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem));
|
||||
|
||||
t_list *ft_lststrsplit(const char *s, char c);
|
||||
t_list *ft_lstfind(t_list *lst, void *data, size_t size);
|
||||
t_list *ft_lst_at(t_list *l, unsigned int at);
|
||||
void ft_lstadd_back(t_list **l, void *data, size_t size);
|
||||
void *ft_realloc(void *old, unsigned int new_size,
|
||||
unsigned int old_size);
|
||||
|
||||
#endif
|
46
rand_test.py
Executable file
46
rand_test.py
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/env python
|
||||
from __future__ import print_function
|
||||
|
||||
tet_shapes = [
|
||||
'####\n....\n....\n....\n',
|
||||
'#...\n#...\n#...\n#...\n',
|
||||
'#...\n###.\n....\n....\n',
|
||||
'##..\n#...\n#...\n....\n',
|
||||
'###.\n..#.\n....\n....\n',
|
||||
'.#..\n.#..\n##..\n....\n',
|
||||
'..#.\n###.\n....\n....\n',
|
||||
'#...\n#...\n##..\n....\n',
|
||||
'###.\n#...\n....\n....\n',
|
||||
'##..\n.#..\n.#..\n....\n',
|
||||
'##..\n##..\n....\n....\n',
|
||||
'.##.\n##..\n....\n....\n',
|
||||
'#...\n##..\n.#..\n....\n',
|
||||
'.#..\n###.\n....\n....\n',
|
||||
'#...\n##..\n#...\n....\n',
|
||||
'###.\n.#..\n....\n....\n',
|
||||
'.#..\n##..\n.#..\n....\n',
|
||||
'##..\n.##.\n....\n....\n',
|
||||
'.#..\n##..\n#...\n....\n',
|
||||
]
|
||||
|
||||
import argparse
|
||||
import random
|
||||
import os
|
||||
|
||||
parser = argparse.ArgumentParser(description="Generate random fillit problems")
|
||||
parser.add_argument('count', metavar="count", type=int, default=10, nargs='?',
|
||||
help="number of tetrominoes to output")
|
||||
parser.add_argument('--seed', type=int, default=None,
|
||||
help="mt_rand seed (to reproduce problems)")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
seed = args.seed
|
||||
if seed is None:
|
||||
seed = random.SystemRandom().randint(0, 2**19937-1)
|
||||
|
||||
random.seed(seed)
|
||||
|
||||
tets = [tet_shapes[random.randrange(len(tet_shapes))] for x in range(args.count)]
|
||||
|
||||
[print(x, end=("" if i == len(tets) - 1 else "\n")) for i, x in enumerate(tets)]
|
44
sample.fillit
Normal file
44
sample.fillit
Normal file
|
@ -0,0 +1,44 @@
|
|||
....
|
||||
##..
|
||||
.#..
|
||||
.#..
|
||||
|
||||
....
|
||||
####
|
||||
....
|
||||
....
|
||||
|
||||
#...
|
||||
###.
|
||||
....
|
||||
....
|
||||
|
||||
....
|
||||
##..
|
||||
.##.
|
||||
....
|
||||
|
||||
....
|
||||
..#.
|
||||
.##.
|
||||
.#..
|
||||
|
||||
....
|
||||
....
|
||||
.##.
|
||||
##..
|
||||
|
||||
....
|
||||
....
|
||||
..##
|
||||
.##.
|
||||
|
||||
....
|
||||
...#
|
||||
...#
|
||||
..##
|
||||
|
||||
....
|
||||
....
|
||||
...#
|
||||
.###
|
Loading…
Reference in a new issue