fix leak and invalid read when not in map
This commit is contained in:
parent
99c3b6376b
commit
a2ecf32195
@ -1,34 +0,0 @@
|
|||||||
NAME = parser
|
|
||||||
|
|
||||||
CC = clang
|
|
||||||
|
|
||||||
# FLAGS = -Wall -Wextra -Werror -g
|
|
||||||
|
|
||||||
DEL = /bin/rm -f
|
|
||||||
|
|
||||||
SRCS = ./srcs/main.c\
|
|
||||||
./gnl/get_next_line.c\
|
|
||||||
./gnl/get_next_line_utils.c\
|
|
||||||
|
|
||||||
SRCS_O = ${SRCS:.c=.o}
|
|
||||||
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
LIBC = ar -rcs
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
${CC} ${FLAGS} -c $< -o ${<:.c=.o}
|
|
||||||
|
|
||||||
$(NAME): ${SRCS_O}
|
|
||||||
make bonus -C ./libft/
|
|
||||||
$(CC) $(FLAGS) $(SRCS_O) -o $(NAME) -L ./libft/ -lft
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
$(DEL) $(NAME)
|
|
||||||
make fclean -C ./libft/
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(DEL) $(SRCS_O)
|
|
||||||
make clean -C ./libft/
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
@ -1,75 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/10/14 15:42:32 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/21 23:01:15 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "get_next_line.h"
|
|
||||||
|
|
||||||
static char *find_return(char **str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *s1;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((*str)[i] != '\n' && (*str)[i] != '\0')
|
|
||||||
i++;
|
|
||||||
s1 = ft_substr(*str, 0, i + 1);
|
|
||||||
if ((*str)[i] == '\n' && (*str)[i + 1] != '\0')
|
|
||||||
tmp = ft_strdup(&(*str)[i + 1]);
|
|
||||||
else
|
|
||||||
tmp = NULL;
|
|
||||||
free(*str);
|
|
||||||
*str = tmp;
|
|
||||||
if (!*str && s1[0] == '\0')
|
|
||||||
{
|
|
||||||
free(s1);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
return (s1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void find_line(int fd, char **str, char **buf)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *tmp;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while (i > 0)
|
|
||||||
{
|
|
||||||
i = read(fd, *buf, BUFFER_SIZE);
|
|
||||||
if (i == -1)
|
|
||||||
{
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
(*buf)[i] = '\0';
|
|
||||||
tmp = ft_strjoin(*str, *buf);
|
|
||||||
free(*str);
|
|
||||||
*str = tmp;
|
|
||||||
if (ft_check (*str, '\n'))
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_next_line(int fd)
|
|
||||||
{
|
|
||||||
char *buf;
|
|
||||||
static char *str;
|
|
||||||
|
|
||||||
if (fd < 0 || BUFFER_SIZE < 1 || read(fd, "", 0) == -1)
|
|
||||||
return (NULL);
|
|
||||||
buf = malloc(sizeof(char) * (BUFFER_SIZE + 1));
|
|
||||||
if (!buf)
|
|
||||||
return (NULL);
|
|
||||||
find_line(fd, &str, &buf);
|
|
||||||
free (buf);
|
|
||||||
return (find_return(&str));
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/10/14 15:43:40 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/21 17:47:29 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef GET_NEXT_LINE_H
|
|
||||||
# define GET_NEXT_LINE_H
|
|
||||||
|
|
||||||
#define BUFFER_SIZE 4096
|
|
||||||
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <fcntl.h>
|
|
||||||
|
|
||||||
char *get_next_line(int fd);
|
|
||||||
char *ft_strdup(const char *src);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
size_t ft_strlen(const char *str);
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
|
||||||
char *ft_check(char *s, char c);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,108 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* get_next_line_utils.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/28 15:54:00 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/28 16:04:36 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "get_next_line.h"
|
|
||||||
|
|
||||||
size_t ft_strlen(const char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!str)
|
|
||||||
return (0);
|
|
||||||
while (str[i])
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strdup(char const *s1)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
dest = malloc(sizeof(char) * ft_strlen(s1) + 1);
|
|
||||||
if (!dest)
|
|
||||||
return (0);
|
|
||||||
i = 0;
|
|
||||||
while (s1[i] != 0)
|
|
||||||
{
|
|
||||||
dest[i] = s1[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dest[i] = 0;
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
if (!s)
|
|
||||||
return (NULL);
|
|
||||||
j = ft_strlen(s);
|
|
||||||
if (!len || j <= start)
|
|
||||||
return (ft_strdup(""));
|
|
||||||
str = (char *)malloc(sizeof(char) * len + 1);
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
j = 0;
|
|
||||||
while (s[++i] && j < len)
|
|
||||||
{
|
|
||||||
if (i >= start)
|
|
||||||
str[j++] = s[i];
|
|
||||||
}
|
|
||||||
str[j] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = malloc(sizeof(char) * (ft_strlen(s1) + ft_strlen(s2) + 1));
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
if (s1)
|
|
||||||
{
|
|
||||||
while (s1[i])
|
|
||||||
{
|
|
||||||
str[i] = s1[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (*s2)
|
|
||||||
{
|
|
||||||
str[i] = *s2++;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_check(char *s, char c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
if (s[i] == c)
|
|
||||||
return ((char *)&s[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
#ifndef PARSERCUB3D
|
|
||||||
# define PARSERCUB3D
|
|
||||||
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include "../libft/libft.h"
|
|
||||||
# include "../gnl/get_next_line.h"
|
|
||||||
# include <sys/types.h>
|
|
||||||
|
|
||||||
typedef struct s_root {
|
|
||||||
int size;
|
|
||||||
int height;
|
|
||||||
int error;
|
|
||||||
} t_root;
|
|
||||||
|
|
||||||
int main(int ac, char **av);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,78 +0,0 @@
|
|||||||
NAME = libft.a
|
|
||||||
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
FLAGS = -Wall -Wextra -Werror
|
|
||||||
|
|
||||||
DEL = /bin/rm -f
|
|
||||||
|
|
||||||
SRCS = ft_atoi.c \
|
|
||||||
ft_bzero.c \
|
|
||||||
ft_calloc.c \
|
|
||||||
ft_isalnum.c \
|
|
||||||
ft_isalpha.c \
|
|
||||||
ft_isascii.c \
|
|
||||||
ft_isdigit.c \
|
|
||||||
ft_isprint.c \
|
|
||||||
ft_itoa.c \
|
|
||||||
ft_memccpy.c \
|
|
||||||
ft_memchr.c \
|
|
||||||
ft_memcmp.c \
|
|
||||||
ft_memcpy.c \
|
|
||||||
ft_memmove.c \
|
|
||||||
ft_memset.c \
|
|
||||||
ft_split.c \
|
|
||||||
ft_strchr.c \
|
|
||||||
ft_strdup.c \
|
|
||||||
ft_strjoin.c \
|
|
||||||
ft_strlcat.c \
|
|
||||||
ft_strlcpy.c \
|
|
||||||
ft_strlen.c \
|
|
||||||
ft_strmapi.c \
|
|
||||||
ft_strncmp.c \
|
|
||||||
ft_strnstr.c \
|
|
||||||
ft_strrchr.c \
|
|
||||||
ft_strtrim.c \
|
|
||||||
ft_substr.c \
|
|
||||||
ft_putchar_fd.c \
|
|
||||||
ft_putstr_fd.c \
|
|
||||||
ft_putendl_fd.c \
|
|
||||||
ft_putnbr_fd.c \
|
|
||||||
ft_tolower.c \
|
|
||||||
ft_toupper.c \
|
|
||||||
|
|
||||||
BONUS = ft_lstnew.c \
|
|
||||||
ft_lstsize.c \
|
|
||||||
ft_lstlast.c \
|
|
||||||
ft_lstadd_front.c \
|
|
||||||
ft_lstadd_back.c \
|
|
||||||
ft_lstdelone.c \
|
|
||||||
ft_lstiter.c \
|
|
||||||
ft_lstmap.c \
|
|
||||||
ft_lstclear.c \
|
|
||||||
ft_putchar.c \
|
|
||||||
ft_putstr.c \
|
|
||||||
ft_strcmp.c \
|
|
||||||
|
|
||||||
SRCS_O = ${SRCS:.c=.o}
|
|
||||||
BONUS_O = ${BONUS:.c=.o}
|
|
||||||
all: $(NAME)
|
|
||||||
|
|
||||||
LIBC = ar -rcs
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
${CC} ${FLAGS} -c $< -o ${<:.c=.o}
|
|
||||||
|
|
||||||
$(NAME): ${SRCS_O}
|
|
||||||
${LIBC} $(NAME) $(SRCS_O)
|
|
||||||
|
|
||||||
bonus: $(SRCS_O) $(BONUS_O)
|
|
||||||
$(LIBC) $(NAME) $(SRCS_O) $(BONUS_O)
|
|
||||||
|
|
||||||
fclean: clean
|
|
||||||
$(DEL) $(NAME)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(DEL) $(SRCS_O) $(BONUS_O)
|
|
||||||
|
|
||||||
re: fclean all
|
|
||||||
@ -1,49 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_atoi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 12:44:41 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:13:51 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static int ft_space(const char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((str[i] == 32) || (str[i] >= 9 && str[i] <= 13))
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
long ft_atoi(const char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int sign;
|
|
||||||
long result;
|
|
||||||
|
|
||||||
result = 0;
|
|
||||||
i = ft_space(str);
|
|
||||||
sign = 0;
|
|
||||||
if (str[i] == '-' || str[i] == '+')
|
|
||||||
{
|
|
||||||
if (str[i] == '-')
|
|
||||||
sign = 1;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
while (str[i] >= '0' && str[i] <= '9')
|
|
||||||
{
|
|
||||||
result = result * 10 + str[i] - 48;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (sign == 1)
|
|
||||||
return (-result);
|
|
||||||
else
|
|
||||||
return (result);
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_bzero.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 12:54:03 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 16:52:41 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_bzero(void *str, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < n)
|
|
||||||
{
|
|
||||||
*(char *)(str + i) = 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_calloc.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 12:55:08 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/22 12:55:45 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_calloc(size_t count, size_t size)
|
|
||||||
{
|
|
||||||
void *trace;
|
|
||||||
|
|
||||||
trace = malloc(count * size);
|
|
||||||
if (!trace)
|
|
||||||
return (NULL);
|
|
||||||
if (trace)
|
|
||||||
ft_bzero(trace, count * size);
|
|
||||||
return (trace);
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isacii.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/20 12:08:41 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 12:49:44 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_isascii(int c)
|
|
||||||
{
|
|
||||||
if (c >= 0 && c <= 127)
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalnum.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 12:56:29 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/22 13:06:39 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalnum(int i)
|
|
||||||
{
|
|
||||||
if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z')
|
|
||||||
|| (i >= '0' && i <= '9'))
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isalpha.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 13:07:14 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/22 13:08:24 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isalpha(int i)
|
|
||||||
{
|
|
||||||
if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z'))
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isascii.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 13:08:54 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/22 13:10:00 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isascii(int i)
|
|
||||||
{
|
|
||||||
if (i >= 0 && i <= 127)
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isdigit.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 13:10:25 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:18:53 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isdigit(int c)
|
|
||||||
{
|
|
||||||
return (c >= '0' && c <= '9');
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_isprint.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 13:11:25 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/22 13:12:26 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_isprint(int i)
|
|
||||||
{
|
|
||||||
if (i >= 32 && i <= 126)
|
|
||||||
return (1);
|
|
||||||
else
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_itoa.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 13:13:20 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 17:09:12 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int base_len(long nb)
|
|
||||||
{
|
|
||||||
int len;
|
|
||||||
|
|
||||||
len = 1;
|
|
||||||
if (nb < 0)
|
|
||||||
{
|
|
||||||
nb = -nb;
|
|
||||||
len++;
|
|
||||||
}
|
|
||||||
while (nb >= 10)
|
|
||||||
{
|
|
||||||
nb /= 10;
|
|
||||||
len++;
|
|
||||||
}
|
|
||||||
return (len);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void filler(char *str, int i, long n)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
{
|
|
||||||
str[0] = '-';
|
|
||||||
n = -n;
|
|
||||||
}
|
|
||||||
while (n > 0)
|
|
||||||
{
|
|
||||||
str[i] = 48 + (n % 10);
|
|
||||||
n /= 10;
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_itoa(int nb)
|
|
||||||
{
|
|
||||||
long n;
|
|
||||||
int i;
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
n = nb;
|
|
||||||
i = base_len(n);
|
|
||||||
str = (char *)malloc(sizeof(char) * i + 1);
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
str[i] = '\0';
|
|
||||||
i--;
|
|
||||||
if (n == 0)
|
|
||||||
{
|
|
||||||
str[0] = 48;
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
filler(str, i, n);
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_back.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 15:05:04 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 11:37:08 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_back(t_list **alst, t_list *new)
|
|
||||||
{
|
|
||||||
t_list *yup;
|
|
||||||
|
|
||||||
if (alst)
|
|
||||||
{
|
|
||||||
if (*alst)
|
|
||||||
{
|
|
||||||
yup = ft_lstlast(*alst);
|
|
||||||
yup->next = new;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstadd_front.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 14:47:57 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:18:16 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstadd_front(t_list **alst, t_list *new)
|
|
||||||
{
|
|
||||||
if (!alst)
|
|
||||||
return ;
|
|
||||||
new->next = *alst;
|
|
||||||
*alst = new;
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstclear.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 16:03:18 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 12:13:31 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstclear(t_list **lst, void (*del)(void *))
|
|
||||||
{
|
|
||||||
t_list *nap;
|
|
||||||
|
|
||||||
if (!lst || !del || !*lst)
|
|
||||||
return ;
|
|
||||||
while (lst && *lst)
|
|
||||||
{
|
|
||||||
nap = (*lst)->next;
|
|
||||||
ft_lstdelone(*lst, del);
|
|
||||||
*lst = nap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,21 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstdelone.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 15:56:45 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 16:02:20 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstdelone(t_list *lst, void (*del)(void*))
|
|
||||||
{
|
|
||||||
if (!del || !lst)
|
|
||||||
return ;
|
|
||||||
(del)(lst->content);
|
|
||||||
free (lst);
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstiter.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/07 11:34:11 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 11:48:46 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_lstiter(t_list *lst, void (*f)(void *))
|
|
||||||
{
|
|
||||||
if (!f || !lst)
|
|
||||||
return ;
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
(*f)(lst->content);
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstlast.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 15:00:53 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 16:09:33 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstlast(t_list *lst)
|
|
||||||
{
|
|
||||||
if (!lst)
|
|
||||||
return (NULL);
|
|
||||||
if (lst)
|
|
||||||
{
|
|
||||||
while (lst->next)
|
|
||||||
lst = lst->next;
|
|
||||||
}
|
|
||||||
return (lst);
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstmap.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/07 12:31:29 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 12:37:22 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
|
|
||||||
{
|
|
||||||
(void)*f;
|
|
||||||
(void)*del;
|
|
||||||
return (lst);
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstnew.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 12:53:17 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 11:49:54 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
t_list *ft_lstnew(void *content)
|
|
||||||
{
|
|
||||||
t_list *new;
|
|
||||||
|
|
||||||
new = malloc(sizeof(t_list));
|
|
||||||
if (!new)
|
|
||||||
return (NULL);
|
|
||||||
new->content = content;
|
|
||||||
new->next = NULL;
|
|
||||||
return (new);
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_lstsize.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 14:58:00 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 16:10:11 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_lstsize(t_list *lst)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (lst)
|
|
||||||
{
|
|
||||||
while (lst)
|
|
||||||
{
|
|
||||||
lst = lst->next;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memccpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/31 17:10:05 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 17:10:57 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memccpy(void *dest, const void *src, int ch, size_t maxSize)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < maxSize)
|
|
||||||
{
|
|
||||||
*(unsigned char *)(dest + i) = *(unsigned char *)(src + i);
|
|
||||||
if (*(unsigned char *)(src + i) == (unsigned char)ch)
|
|
||||||
return (dest + i + 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/25 14:48:34 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/25 15:57:53 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memchr(const void *mem, int ch, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
if (*(unsigned char *)(mem + i) == (unsigned char)ch)
|
|
||||||
return ((unsigned char *)(mem + i));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/31 17:11:51 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 17:11:55 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_memcmp(const void *p1, const void *p2, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
if (!(*(unsigned char *)(p1 + i) == *(unsigned char *)(p2 + i)))
|
|
||||||
return (*(unsigned char *)(p1 + i) - *(unsigned char *)(p2 + i));
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/31 17:46:43 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 17:47:17 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memcpy(void *dest, const void *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!dest && !src)
|
|
||||||
return (NULL);
|
|
||||||
while (size > 0)
|
|
||||||
{
|
|
||||||
*(unsigned char *)(dest + i) = *(unsigned char *)(src + i);
|
|
||||||
size--;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memmove.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/31 17:14:39 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:22:11 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memmove(void *dest, const void *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (src == dest)
|
|
||||||
return (dest);
|
|
||||||
if (dest > src)
|
|
||||||
{
|
|
||||||
while (size > 0)
|
|
||||||
{
|
|
||||||
*(char *)(dest + (size - 1)) = *(char *)(src + (size - 1));
|
|
||||||
size--;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
while (i < size)
|
|
||||||
{
|
|
||||||
*(char *)(dest + i) = *(char *)(src + i);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
@ -1,26 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_memset.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/25 15:58:25 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 17:17:00 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void *ft_memset(void *pointer, int value, size_t count)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < count)
|
|
||||||
{
|
|
||||||
*(char *)(pointer + i) = (char)value;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (pointer);
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/12/08 19:22:52 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:22:56 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putchar(int c)
|
|
||||||
{
|
|
||||||
write(1, &c, 1);
|
|
||||||
}
|
|
||||||
@ -1,19 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putchar_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 14:44:48 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 17:18:07 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putchar_fd(char c, int fd)
|
|
||||||
{
|
|
||||||
if (fd >= 0)
|
|
||||||
write(fd, &c, 1);
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putendl_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 14:46:41 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/31 17:19:23 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putendl_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!s)
|
|
||||||
return ;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
write(fd, &s[i], 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
write(fd, "\n", 1);
|
|
||||||
}
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putnbr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 14:48:10 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:11:58 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putnbr_fd(int n, int fd)
|
|
||||||
{
|
|
||||||
if (n < 0)
|
|
||||||
{
|
|
||||||
ft_putchar_fd('-', fd);
|
|
||||||
if (n == -2147483648)
|
|
||||||
write(fd, "2147483648", 10);
|
|
||||||
n = -n;
|
|
||||||
}
|
|
||||||
if (n >= 10)
|
|
||||||
{
|
|
||||||
ft_putnbr_fd(n / 10, fd);
|
|
||||||
ft_putnbr_fd(n % 10, fd);
|
|
||||||
}
|
|
||||||
else if (n >= 0 && n <= 9)
|
|
||||||
ft_putchar_fd(n + '0', fd);
|
|
||||||
}
|
|
||||||
@ -1,24 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/12/08 19:23:23 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:23:28 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putstr(char const *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (!str)
|
|
||||||
return ;
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
write(1, &str[i++], 1);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_putstr_fd.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 14:51:56 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 12:41:49 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
void ft_putstr_fd(char *s, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (!s || fd <= 0)
|
|
||||||
return ;
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
write(fd, &s[i], 1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,91 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_split.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 14:53:23 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 12:10:50 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static size_t ft_wordcount(char const *s, char c)
|
|
||||||
{
|
|
||||||
size_t word;
|
|
||||||
size_t state;
|
|
||||||
|
|
||||||
state = 1;
|
|
||||||
word = 0;
|
|
||||||
while (*s)
|
|
||||||
{
|
|
||||||
if (*s == c)
|
|
||||||
state = 1;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (state == 1)
|
|
||||||
word++;
|
|
||||||
state = 0;
|
|
||||||
}
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
return (word);
|
|
||||||
}
|
|
||||||
|
|
||||||
static size_t ft_word_length(char const *s, char c)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (*s && *s != c)
|
|
||||||
{
|
|
||||||
i++;
|
|
||||||
s++;
|
|
||||||
}
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **ft_free(char **str)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
{
|
|
||||||
free(str[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
free(str);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **ft_split(char const *s, char c)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
char **splited;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
if (s == 0)
|
|
||||||
return (NULL);
|
|
||||||
splited = (char **)malloc(sizeof(char *) * (ft_wordcount(s, c) + 1));
|
|
||||||
if (!splited)
|
|
||||||
return (NULL);
|
|
||||||
while (ft_wordcount(s, c))
|
|
||||||
{
|
|
||||||
while (*s && *s == c)
|
|
||||||
s++;
|
|
||||||
splited[i] = (char *)malloc(sizeof(char) * (ft_word_length(s, c) + 1));
|
|
||||||
if (!splited[i])
|
|
||||||
return (ft_free(splited));
|
|
||||||
j = 0;
|
|
||||||
while (*s != c && *s)
|
|
||||||
splited[i][j++] = *s++;
|
|
||||||
splited[i][j] = 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
splited[i] = 0;
|
|
||||||
return (splited);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/20 13:33:40 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/21 17:41:05 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strchr(const char *s, int c)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
str = (char *)s;
|
|
||||||
while (*str || c == '\0')
|
|
||||||
{
|
|
||||||
if (*str == c)
|
|
||||||
return (str);
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strcmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/12/08 19:23:07 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/08 19:23:11 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
int ft_strcmp(const char *s1, const char *s2)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (s1[i] || s2[i])
|
|
||||||
{
|
|
||||||
if (s1[i] != s2[i])
|
|
||||||
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,41 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strdup.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 15:05:42 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 12:38:05 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static char *ft_strcpy(char *dest, const char *src)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (src[i])
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strdup(const char *src)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
char *copy;
|
|
||||||
|
|
||||||
copy = NULL;
|
|
||||||
i = ft_strlen(src);
|
|
||||||
copy = malloc(sizeof(char) * i + 1);
|
|
||||||
if (!copy)
|
|
||||||
return (NULL);
|
|
||||||
copy = ft_strcpy(copy, src);
|
|
||||||
return (copy);
|
|
||||||
}
|
|
||||||
@ -1,57 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strjoin.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 15:26:12 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/23 15:27:29 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
static char *ft_strcat_j(char const *s1, char const *s2, char *dest)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
while (s1[i])
|
|
||||||
{
|
|
||||||
dest[j] = s1[i];
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
i = 0;
|
|
||||||
while (s2[i])
|
|
||||||
{
|
|
||||||
dest[j] = s2[i];
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
dest[j] = '\0';
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char *dest;
|
|
||||||
|
|
||||||
dest = NULL;
|
|
||||||
if (!(s1 && s2))
|
|
||||||
return (0);
|
|
||||||
if (!s1)
|
|
||||||
{
|
|
||||||
dest = ft_strdup(s2);
|
|
||||||
}
|
|
||||||
i = ft_strlen(s1) + ft_strlen(s2);
|
|
||||||
dest = malloc(sizeof(char) * i + 1);
|
|
||||||
if (!dest)
|
|
||||||
return (NULL);
|
|
||||||
dest = ft_strcat_j(s1, s2, dest);
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlcat.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/25 15:07:11 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 11:46:21 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
size_t res;
|
|
||||||
|
|
||||||
j = 0;
|
|
||||||
i = ft_strlen(dest);
|
|
||||||
res = ft_strlen(src);
|
|
||||||
if (size <= i)
|
|
||||||
res = size + res;
|
|
||||||
else
|
|
||||||
res = i + res;
|
|
||||||
while (src[j] && i + 1 < size)
|
|
||||||
{
|
|
||||||
dest[i] = src[j];
|
|
||||||
i++;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
if (i < size)
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (res);
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlcpy.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/22 15:43:29 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 12:34:12 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strlcpy(char *dest, const char *src, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if (!size)
|
|
||||||
return (ft_strlen(src));
|
|
||||||
i = 0;
|
|
||||||
if (!dest && !src)
|
|
||||||
return (0);
|
|
||||||
if (size == 0)
|
|
||||||
return (0);
|
|
||||||
while (src[i] && i < size - 1)
|
|
||||||
{
|
|
||||||
dest[i] = src[i];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (size > 0)
|
|
||||||
dest[i] = '\0';
|
|
||||||
return (ft_strlen(src));
|
|
||||||
}
|
|
||||||
@ -1,23 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strlen.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 12:31:43 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 12:32:28 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
size_t ft_strlen(const char *str)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
i++;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strmapi.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/25 16:09:10 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/03 16:14:11 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
char *dest;
|
|
||||||
int a;
|
|
||||||
|
|
||||||
if (!s)
|
|
||||||
return (0);
|
|
||||||
a = ft_strlen(s);
|
|
||||||
dest = NULL;
|
|
||||||
i = 0;
|
|
||||||
if (!s || !f)
|
|
||||||
return (NULL);
|
|
||||||
dest = malloc(sizeof(char) * a + 1);
|
|
||||||
if (!dest)
|
|
||||||
return (NULL);
|
|
||||||
while (s[i])
|
|
||||||
{
|
|
||||||
dest[i] = (*f)(i, (char)s[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
dest[i] = 0;
|
|
||||||
return (dest);
|
|
||||||
}
|
|
||||||
@ -1,27 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strncmp.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 12:29:18 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/09 12:28:28 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while ((s1[i] || s2[i]) && i < n)
|
|
||||||
{
|
|
||||||
if (!(s1[i] == s2[i]))
|
|
||||||
return ((unsigned char)s1[i] - s2[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,39 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strnstr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/25 14:58:49 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/25 16:30:00 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strnstr(const char *str, const char *to_find, size_t size)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
j = 0;
|
|
||||||
if (*to_find == '\0')
|
|
||||||
return ((char *)str);
|
|
||||||
while (i < size && str[i])
|
|
||||||
{
|
|
||||||
if ((i + j) > size)
|
|
||||||
return (NULL);
|
|
||||||
if (to_find[j] == '\0')
|
|
||||||
return ((char *)&str[i]);
|
|
||||||
if (str[i + j] == to_find[j])
|
|
||||||
j++;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strrchr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/20 13:38:42 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/09 12:59:30 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strrchr(const char *str, int c)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = ft_strlen(str) - 1;
|
|
||||||
if (c == '\0')
|
|
||||||
return ((char *)&(str[i + 1]));
|
|
||||||
while (i >= 0)
|
|
||||||
{
|
|
||||||
if (str[i] == (char)c)
|
|
||||||
return ((char *)&(str[i]));
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_strtrim.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 12:17:01 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/09 13:45:13 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_strtrim(char const *s1, char const *set)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
if (!s1 || !set)
|
|
||||||
return (NULL);
|
|
||||||
while (*s1 && ft_strchr(set, *s1))
|
|
||||||
s1++;
|
|
||||||
j = ft_strlen((char *)s1);
|
|
||||||
while (j && ft_strchr(set, s1[j]))
|
|
||||||
j--;
|
|
||||||
++j;
|
|
||||||
str = ft_substr(s1, 0, j);
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@ -1,38 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_substr.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/03 12:11:04 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/06/07 11:33:45 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
size_t i;
|
|
||||||
size_t j;
|
|
||||||
|
|
||||||
i = -1;
|
|
||||||
if (!s)
|
|
||||||
return (NULL);
|
|
||||||
j = ft_strlen(s);
|
|
||||||
if (!len || j <= start)
|
|
||||||
return (ft_strdup(""));
|
|
||||||
str = (char *)malloc(sizeof(char) * len + 1);
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
j = 0;
|
|
||||||
while (s[++i] && j < len)
|
|
||||||
{
|
|
||||||
if (i >= start)
|
|
||||||
str[j++] = s[i];
|
|
||||||
}
|
|
||||||
str[j] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_tolower.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/25 16:34:58 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/25 16:35:45 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_tolower(int i)
|
|
||||||
{
|
|
||||||
if (i >= 'A' && i <= 'Z')
|
|
||||||
i += 32;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* ft_toupper.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <marvin@42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/05/25 16:36:03 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/05/25 16:36:32 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "libft.h"
|
|
||||||
|
|
||||||
int ft_toupper(int i)
|
|
||||||
{
|
|
||||||
if (i >= 'a' && i <= 'z')
|
|
||||||
i -= 32;
|
|
||||||
return (i);
|
|
||||||
}
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* libft.h :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2021/06/07 12:34:41 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2021/12/21 18:17:10 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#ifndef LIBFT_H
|
|
||||||
# define LIBFT_H
|
|
||||||
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <stdlib.h>
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <fcntl.h>
|
|
||||||
|
|
||||||
typedef struct s_list
|
|
||||||
{
|
|
||||||
void *content;
|
|
||||||
struct s_list *next;
|
|
||||||
} t_list;
|
|
||||||
|
|
||||||
void ft_putchar(int c);
|
|
||||||
void ft_putstr(char const *str);
|
|
||||||
int ft_strcmp(const char *s1, const char *s2);
|
|
||||||
long ft_atoi(const char *str);
|
|
||||||
void ft_bzero(void *str, size_t n);
|
|
||||||
void *ft_calloc(size_t count, size_t size);
|
|
||||||
int ft_isalnum(int i);
|
|
||||||
int ft_isalpha(int i);
|
|
||||||
int ft_isascii(int i);
|
|
||||||
int ft_isdigit(int i);
|
|
||||||
int ft_isprint(int i);
|
|
||||||
char *ft_itoa(int n);
|
|
||||||
void *ft_memccpy(void *dest, const void *src, int ch, size_t maxSize);
|
|
||||||
void *ft_memcpy(void *destination, const void *source, size_t size);
|
|
||||||
void *ft_memmove(void *dest, const void *src, size_t size);
|
|
||||||
void *ft_memchr(const void *mem, int ch, size_t size);
|
|
||||||
void *ft_memset(void *pointer, int value, size_t count);
|
|
||||||
int ft_memcmp(const void *p1, const void *p2, size_t size);
|
|
||||||
void ft_putchar_fd(char c, int fd);
|
|
||||||
void ft_putendl_fd(char *s, int fd);
|
|
||||||
void ft_putnbr_fd(int n, int fd);
|
|
||||||
void ft_putstr_fd(char *s, int fd);
|
|
||||||
char **ft_split(char const *s, char c);
|
|
||||||
char *ft_strdup(const char *src);
|
|
||||||
char *ft_strjoin(char const *s1, char const *s2);
|
|
||||||
size_t ft_strlcpy(char *dest, const char *src, size_t size);
|
|
||||||
size_t ft_strlen(const char *str);
|
|
||||||
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
|
||||||
char *ft_strtrim(char const *s1, char const *set);
|
|
||||||
char *ft_substr(char const *s, unsigned int start, size_t len);
|
|
||||||
int ft_tolower(int i);
|
|
||||||
int ft_toupper(int i);
|
|
||||||
char *ft_strchr(const char *str, int c);
|
|
||||||
char *ft_strrchr(const char *str, int c);
|
|
||||||
size_t ft_strlcpy(char *dest, const char *src, size_t size);
|
|
||||||
size_t ft_strlcat(char *dest, const char *src, size_t size);
|
|
||||||
char *ft_strmapi(const char *s, char (*f)(unsigned int, char));
|
|
||||||
char *ft_strnstr(const char *str, const char *to_find, size_t size);
|
|
||||||
|
|
||||||
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 *));
|
|
||||||
|
|
||||||
// int ft_check(char *s, char c);
|
|
||||||
// void find_line(int fd, char **str, char **buf);
|
|
||||||
// char *get_next_line(int fd);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
#include "libft.h"
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
// __attribute__((no_sanitize_address))
|
|
||||||
//__attribute__((destructor)) void destructeur()
|
|
||||||
//{
|
|
||||||
// while (1);
|
|
||||||
//}
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
(void)ac;
|
|
||||||
int fd = open(av[1], O_RDONLY);
|
|
||||||
char *line = NULL;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
while ((line = get_next_line(fd)) != NULL)
|
|
||||||
{
|
|
||||||
printf("Ligne %d: %s\n", i, line);
|
|
||||||
free(line);
|
|
||||||
line = NULL;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
printf("Ligne %d: %s\n", i, line);
|
|
||||||
free(line);
|
|
||||||
close(fd);
|
|
||||||
system("leaks a.out");
|
|
||||||
// destructeur();
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
111111111111111111
|
|
||||||
100000000000000001
|
|
||||||
100000000000000001
|
|
||||||
100000000000000001
|
|
||||||
100000000000000001
|
|
||||||
111111111111111111
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
11111111111111111111111111111111111111111111111111
|
|
||||||
11111111111111111111111111111111111111111111111111
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
111111111111111111
|
|
||||||
100000000000000001
|
|
||||||
100000000000000000
|
|
||||||
1000000000e0000001
|
|
||||||
10000000E000000001
|
|
||||||
111111111111111111
|
|
||||||
@ -1,276 +0,0 @@
|
|||||||
/* ************************************************************************** */
|
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* main.c :+: :+: :+: */
|
|
||||||
/* +:+ +:+ +:+ */
|
|
||||||
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
|
||||||
/* +#+#+#+#+#+ +#+ */
|
|
||||||
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
|
||||||
/* Updated: 2022/06/08 16:40:08 by sadjigui ### ########.fr */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
#include "../includes/parsercub3D.h"
|
|
||||||
|
|
||||||
void ft_exit(char *str)
|
|
||||||
{
|
|
||||||
ft_putstr_fd(str, 2);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void error_msg(t_root *global)
|
|
||||||
{
|
|
||||||
if (global->error == 1)
|
|
||||||
ft_putstr_fd("Error: Map isn't closed\n", 2);
|
|
||||||
if (global->error == 2)
|
|
||||||
ft_putstr_fd("Error: Missing player\n", 2);
|
|
||||||
if (global->error == 3)
|
|
||||||
ft_putstr_fd("Error: Too many players\n", 2);
|
|
||||||
if (global->error == -1)
|
|
||||||
ft_putstr_fd("Error: Bad character in map\n", 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void free_tab(char **tab)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (tab[i])
|
|
||||||
{
|
|
||||||
free(tab[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
free(tab);
|
|
||||||
tab = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void size_line(char *str, t_root *global)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (str[i])
|
|
||||||
i++;
|
|
||||||
if (i > global->size)
|
|
||||||
global->size = i;
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *charge_new(t_root *global)
|
|
||||||
{
|
|
||||||
char *str;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
str = malloc(sizeof(char) * (global->size + 3));
|
|
||||||
if (!str)
|
|
||||||
return (NULL);
|
|
||||||
while (i < global->size + 2)
|
|
||||||
{
|
|
||||||
str[i] = '3';
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
str[i] = '\0';
|
|
||||||
return (str);
|
|
||||||
}
|
|
||||||
|
|
||||||
int reverse_comp(char *s1, char *s2)
|
|
||||||
{
|
|
||||||
int size_s1;
|
|
||||||
int size_s2;
|
|
||||||
|
|
||||||
size_s1 = ft_strlen(s1);
|
|
||||||
size_s2 = ft_strlen(s2);
|
|
||||||
while (size_s2 >= 0)
|
|
||||||
{
|
|
||||||
if (!(s2[size_s2] == s1[size_s1]))
|
|
||||||
return (1);
|
|
||||||
size_s1--;
|
|
||||||
size_s2--;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void inter_map(char **split, char **tmp)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (split[i])
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
while(split[i][j])
|
|
||||||
{
|
|
||||||
if (ft_isalnum(split[i][j]))
|
|
||||||
tmp[i + 1][j + 1] = split[i][j];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void close_or_not(char **tab, int i, int j, t_root *global)
|
|
||||||
{
|
|
||||||
if(tab[i + 1][j] == '3' || tab[i - 1][j] == '3')
|
|
||||||
global->error = 1;
|
|
||||||
if(tab[i][j + 1] == '3' || tab[i][j - 1] == '3')
|
|
||||||
global->error = 1;
|
|
||||||
if(tab[i + 1][j + 1] == '3' || tab[i + 1][j - 1] == '3')
|
|
||||||
global->error = 1;
|
|
||||||
if(tab[i - 1][j + 1] == '3' || tab[i - 1][j - 1] == '3')
|
|
||||||
global->error = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int check_inner_utils(char *line)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int player;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
player = 0;
|
|
||||||
while (line[i])
|
|
||||||
{
|
|
||||||
// if (line[i] == '0' || line[i] == '1' || line[i] == '3' || line[i] == '\n')
|
|
||||||
// i++;
|
|
||||||
if (line[i] == 'N' || line[i] == 'S' || line[i] == 'E' || line[i] == 'W')
|
|
||||||
player++;
|
|
||||||
else if (line[i] != 'W' && line[i] != 'N' && line[i] != 'S' && line[i] != 'E'
|
|
||||||
&& line[i] != '3' && line[i] != '0' && line[i] != '1')
|
|
||||||
return (100);
|
|
||||||
// else
|
|
||||||
// return (2);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (player);
|
|
||||||
}
|
|
||||||
|
|
||||||
void check_inner(char **map, t_root *global)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int player;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
player = 0;
|
|
||||||
while (map[i])
|
|
||||||
{
|
|
||||||
player += check_inner_utils(map[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
if (player == 0)
|
|
||||||
global->error = 2;
|
|
||||||
if (player > 1 && player < 100)
|
|
||||||
global->error = 3;
|
|
||||||
if (player >= 100)
|
|
||||||
global->error = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void check_border(char **tab, t_root *global)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (tab[i])
|
|
||||||
{
|
|
||||||
j = 0;
|
|
||||||
while (tab[i][j])
|
|
||||||
{
|
|
||||||
if (tab[i][j] == '0')
|
|
||||||
close_or_not(tab, i, j, global);
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void check_zero_one(char **split, t_root *global)
|
|
||||||
{
|
|
||||||
char **tmp;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (split[i])
|
|
||||||
i++;
|
|
||||||
global->height = i;
|
|
||||||
tmp = malloc(sizeof(char *) * (i + 3));
|
|
||||||
if (!tmp)
|
|
||||||
return ;
|
|
||||||
i = 0;
|
|
||||||
while(i < global->height + 2)
|
|
||||||
{
|
|
||||||
tmp[i] = charge_new(global);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
tmp[i] = NULL;
|
|
||||||
inter_map(split, tmp);
|
|
||||||
check_border(tmp, global);
|
|
||||||
check_inner(tmp, global);
|
|
||||||
free_tab(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
char **isafile(char **av, t_root *global)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
char *line;
|
|
||||||
char *str;
|
|
||||||
char *tmp;
|
|
||||||
char **split;
|
|
||||||
|
|
||||||
fd = open(av[1], O_RDONLY);
|
|
||||||
str = NULL;
|
|
||||||
tmp = NULL;
|
|
||||||
if (fd == - 1)
|
|
||||||
ft_exit("Error: File doesn't exist\n");
|
|
||||||
while ((line = get_next_line(fd)) != NULL)
|
|
||||||
{
|
|
||||||
tmp = ft_strjoin(str, line);
|
|
||||||
if (str != NULL)
|
|
||||||
free(str);
|
|
||||||
str = tmp;
|
|
||||||
size_line(line, global);
|
|
||||||
free(line);
|
|
||||||
line = NULL;
|
|
||||||
}
|
|
||||||
split = ft_split(str, '\n');
|
|
||||||
free(line);
|
|
||||||
free(str);
|
|
||||||
close(fd);
|
|
||||||
check_zero_one(split, global);
|
|
||||||
return (split);
|
|
||||||
}
|
|
||||||
|
|
||||||
int check_map(char **av, t_root *global)
|
|
||||||
{
|
|
||||||
char **map;
|
|
||||||
|
|
||||||
global->size = 0;
|
|
||||||
global->height = 0;
|
|
||||||
global->error = 0;
|
|
||||||
|
|
||||||
map = NULL;
|
|
||||||
if (reverse_comp(av[1], ".cub") || (ft_strlen(av[1]) == ft_strlen(".cub")))
|
|
||||||
{
|
|
||||||
ft_putstr_fd("Error: Not a valid file \".cub\"\n", 2);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
map = isafile(av, global);
|
|
||||||
free_tab(map);
|
|
||||||
if (global->error != 0)
|
|
||||||
{
|
|
||||||
error_msg(global);
|
|
||||||
return (1);
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int ac, char **av)
|
|
||||||
{
|
|
||||||
t_root global;
|
|
||||||
|
|
||||||
if (check_map(av, &global))
|
|
||||||
return (0);
|
|
||||||
else
|
|
||||||
printf("map is clean\n");
|
|
||||||
}
|
|
||||||
@ -4,8 +4,8 @@ EA ./sprite/brick_wall.ppm
|
|||||||
WE ./sprite/brick_wall.ppm
|
WE ./sprite/brick_wall.ppm
|
||||||
|
|
||||||
111111111111111111
|
111111111111111111
|
||||||
110000000000000001
|
11110000000001111
|
||||||
100000000000000011
|
1100000000000111111111
|
||||||
100000000000000001
|
1111000000000000000000001
|
||||||
11000000E000000001
|
11000000E0000000011111111
|
||||||
111111111111111111
|
111111111111111111
|
||||||
|
|||||||
@ -1,7 +1,13 @@
|
|||||||
1111111111111111111111111
|
NO ./sprite/brick_wall.ppm
|
||||||
1000000000110000000000001
|
SO ./sprite/brick_wall.ppm
|
||||||
1011000001110000000000001
|
EA ./sprite/brick_wall.ppm
|
||||||
1001000000000000000000001
|
WE ./sprite/brick_wall.ppm
|
||||||
|
|
||||||
|
|
||||||
|
1111111111111111111111111
|
||||||
|
1000000000110000000000001
|
||||||
|
1011000001110000000000001
|
||||||
|
1001000000000000000000001
|
||||||
111111111011000001110000000000001
|
111111111011000001110000000000001
|
||||||
100000000011000001110111111111111
|
100000000011000001110111111111111
|
||||||
11110111111111011100000010001
|
11110111111111011100000010001
|
||||||
@ -11,4 +17,4 @@
|
|||||||
10000000000000001101010010001
|
10000000000000001101010010001
|
||||||
11000001110101011111011110N0111
|
11000001110101011111011110N0111
|
||||||
11110111 1110101 101111010001
|
11110111 1110101 101111010001
|
||||||
11111111 1111111 111111111111
|
11111111 1111111 111111111111
|
||||||
@ -148,9 +148,9 @@ void draw_ray3d(t_data *img, ray ray)
|
|||||||
my = (int)myy;//gap;
|
my = (int)myy;//gap;
|
||||||
ray.pixel = ((my) * 64 + mx)* 3 + 1;
|
ray.pixel = ((my) * 64 + mx)* 3 + 1;
|
||||||
x = -1;
|
x = -1;
|
||||||
if (ray.pixel > 12185)//here read
|
if (ray.pixel >= 12290)//here read
|
||||||
color = 0;
|
color = 0;
|
||||||
else if (ray.pixel != 0)
|
else if (ray.pixel > 0)
|
||||||
color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]);//here read
|
color = get_color(img->map.texture.north[ray.pixel], img->map.texture.north[ray.pixel + 1], img->map.texture.north[ray.pixel + 2]);//here read
|
||||||
else
|
else
|
||||||
color = 0;
|
color = 0;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
/* Created: 2022/06/11 01:00:17 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/11 17:33:45 by apommier ### ########.fr */
|
/* Updated: 2022/06/13 12:12:48 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -52,11 +52,13 @@ char *transform_map(char **double_map, t_data *img)
|
|||||||
while (double_map[i][++j])
|
while (double_map[i][++j])
|
||||||
{
|
{
|
||||||
//printf("INDEX= %d\n", i * img->map.x + j);
|
//printf("INDEX= %d\n", i * img->map.x + j);
|
||||||
|
//if ()
|
||||||
map[i * img->map.x + j] = double_map[i][j];
|
map[i * img->map.x + j] = double_map[i][j];
|
||||||
map[index] = double_map[i][j];
|
//map[index] = double_map[i][j];
|
||||||
//printf("index= %d\n", index);
|
//printf("index= %d\n", index);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
img->map.simple_map = map;
|
img->map.simple_map = map;
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
||||||
/* Updated: 2022/06/12 01:46:29 by apommier ### ########.fr */
|
/* Updated: 2022/06/13 12:25:51 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -241,7 +241,6 @@ char **isafile(char **av, t_data *img)
|
|||||||
free(line);
|
free(line);
|
||||||
free(str);
|
free(str);
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
int pass = 0;
|
int pass = 0;
|
||||||
pass = check_texture_color(split, img);
|
pass = check_texture_color(split, img);
|
||||||
check_zero_one(split + pass, img);
|
check_zero_one(split + pass, img);
|
||||||
|
|||||||
17
srcs/utils.c
17
srcs/utils.c
@ -6,20 +6,33 @@
|
|||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
/* Created: 2022/02/13 23:37:02 by apommier #+# #+# */
|
||||||
/* Updated: 2022/06/11 20:39:44 by apommier ### ########.fr */
|
/* Updated: 2022/06/13 12:39:15 by apommier ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "../includes/Cub3D.h"
|
#include "../includes/Cub3D.h"
|
||||||
|
|
||||||
|
void free_texture(t_data *img)
|
||||||
|
{
|
||||||
|
if (img->map.texture.north)
|
||||||
|
free(img->map.texture.north);
|
||||||
|
if (img->map.texture.south)
|
||||||
|
free(img->map.texture.south);
|
||||||
|
if (img->map.texture.east)
|
||||||
|
free(img->map.texture.east);
|
||||||
|
if (img->map.texture.west)
|
||||||
|
free(img->map.texture.west);
|
||||||
|
}
|
||||||
|
|
||||||
int quit_game(t_data *img)
|
int quit_game(t_data *img)
|
||||||
{
|
{
|
||||||
mlx_destroy_window(img->mlx, img->mlx_win);
|
mlx_destroy_window(img->mlx, img->mlx_win);
|
||||||
mlx_destroy_display(img->mlx);
|
mlx_destroy_display(img->mlx);
|
||||||
if (img->mlx)
|
if (img->mlx)
|
||||||
free(img->mlx);
|
free(img->mlx);
|
||||||
|
free_texture(img);
|
||||||
free(img->map.simple_map);
|
free(img->map.simple_map);
|
||||||
free(img->map.texture.north);
|
//free(img->map.texture.north);
|
||||||
//free_double(img->map);
|
//free_double(img->map);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user