parsing
This commit is contained in:
parent
4dc99cd0de
commit
099cc193bd
34
ParsingCub3D/Makefile
Normal file
34
ParsingCub3D/Makefile
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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
|
||||||
75
ParsingCub3D/gnl/get_next_line.c
Normal file
75
ParsingCub3D/gnl/get_next_line.c
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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));
|
||||||
|
}
|
||||||
31
ParsingCub3D/gnl/get_next_line.h
Normal file
31
ParsingCub3D/gnl/get_next_line.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
108
ParsingCub3D/gnl/get_next_line_utils.c
Normal file
108
ParsingCub3D/gnl/get_next_line_utils.c
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
18
ParsingCub3D/includes/parsercub3D.h
Normal file
18
ParsingCub3D/includes/parsercub3D.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#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
|
||||||
78
ParsingCub3D/libft/Makefile
Normal file
78
ParsingCub3D/libft/Makefile
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
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
|
||||||
49
ParsingCub3D/libft/ft_atoi.c
Normal file
49
ParsingCub3D/libft/ft_atoi.c
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
25
ParsingCub3D/libft/ft_bzero.c
Normal file
25
ParsingCub3D/libft/ft_bzero.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
ParsingCub3D/libft/ft_calloc.c
Normal file
25
ParsingCub3D/libft/ft_calloc.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
19
ParsingCub3D/libft/ft_isacii.c
Normal file
19
ParsingCub3D/libft/ft_isacii.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
22
ParsingCub3D/libft/ft_isalnum.c
Normal file
22
ParsingCub3D/libft/ft_isalnum.c
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
21
ParsingCub3D/libft/ft_isalpha.c
Normal file
21
ParsingCub3D/libft/ft_isalpha.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
21
ParsingCub3D/libft/ft_isascii.c
Normal file
21
ParsingCub3D/libft/ft_isascii.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
18
ParsingCub3D/libft/ft_isdigit.c
Normal file
18
ParsingCub3D/libft/ft_isdigit.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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');
|
||||||
|
}
|
||||||
21
ParsingCub3D/libft/ft_isprint.c
Normal file
21
ParsingCub3D/libft/ft_isprint.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
69
ParsingCub3D/libft/ft_itoa.c
Normal file
69
ParsingCub3D/libft/ft_itoa.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
29
ParsingCub3D/libft/ft_lstadd_back.c
Normal file
29
ParsingCub3D/libft/ft_lstadd_back.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
ParsingCub3D/libft/ft_lstadd_front.c
Normal file
21
ParsingCub3D/libft/ft_lstadd_front.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
27
ParsingCub3D/libft/ft_lstclear.c
Normal file
27
ParsingCub3D/libft/ft_lstclear.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
21
ParsingCub3D/libft/ft_lstdelone.c
Normal file
21
ParsingCub3D/libft/ft_lstdelone.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
24
ParsingCub3D/libft/ft_lstiter.c
Normal file
24
ParsingCub3D/libft/ft_lstiter.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
25
ParsingCub3D/libft/ft_lstlast.c
Normal file
25
ParsingCub3D/libft/ft_lstlast.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
20
ParsingCub3D/libft/ft_lstmap.c
Normal file
20
ParsingCub3D/libft/ft_lstmap.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
25
ParsingCub3D/libft/ft_lstnew.c
Normal file
25
ParsingCub3D/libft/ft_lstnew.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
29
ParsingCub3D/libft/ft_lstsize.c
Normal file
29
ParsingCub3D/libft/ft_lstsize.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
28
ParsingCub3D/libft/ft_memccpy.c
Normal file
28
ParsingCub3D/libft/ft_memccpy.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
27
ParsingCub3D/libft/ft_memchr.c
Normal file
27
ParsingCub3D/libft/ft_memchr.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
27
ParsingCub3D/libft/ft_memcmp.c
Normal file
27
ParsingCub3D/libft/ft_memcmp.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
29
ParsingCub3D/libft/ft_memcpy.c
Normal file
29
ParsingCub3D/libft/ft_memcpy.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
37
ParsingCub3D/libft/ft_memmove.c
Normal file
37
ParsingCub3D/libft/ft_memmove.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
26
ParsingCub3D/libft/ft_memset.c
Normal file
26
ParsingCub3D/libft/ft_memset.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
18
ParsingCub3D/libft/ft_putchar.c
Normal file
18
ParsingCub3D/libft/ft_putchar.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
19
ParsingCub3D/libft/ft_putchar_fd.c
Normal file
19
ParsingCub3D/libft/ft_putchar_fd.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
28
ParsingCub3D/libft/ft_putendl_fd.c
Normal file
28
ParsingCub3D/libft/ft_putendl_fd.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
31
ParsingCub3D/libft/ft_putnbr_fd.c
Normal file
31
ParsingCub3D/libft/ft_putnbr_fd.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
24
ParsingCub3D/libft/ft_putstr.c
Normal file
24
ParsingCub3D/libft/ft_putstr.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
27
ParsingCub3D/libft/ft_putstr_fd.c
Normal file
27
ParsingCub3D/libft/ft_putstr_fd.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
91
ParsingCub3D/libft/ft_split.c
Normal file
91
ParsingCub3D/libft/ft_split.c
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
27
ParsingCub3D/libft/ft_strchr.c
Normal file
27
ParsingCub3D/libft/ft_strchr.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
25
ParsingCub3D/libft/ft_strcmp.c
Normal file
25
ParsingCub3D/libft/ft_strcmp.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
41
ParsingCub3D/libft/ft_strdup.c
Normal file
41
ParsingCub3D/libft/ft_strdup.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
57
ParsingCub3D/libft/ft_strjoin.c
Normal file
57
ParsingCub3D/libft/ft_strjoin.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
37
ParsingCub3D/libft/ft_strlcat.c
Normal file
37
ParsingCub3D/libft/ft_strlcat.c
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
34
ParsingCub3D/libft/ft_strlcpy.c
Normal file
34
ParsingCub3D/libft/ft_strlcpy.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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));
|
||||||
|
}
|
||||||
23
ParsingCub3D/libft/ft_strlen.c
Normal file
23
ParsingCub3D/libft/ft_strlen.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
38
ParsingCub3D/libft/ft_strmapi.c
Normal file
38
ParsingCub3D/libft/ft_strmapi.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
27
ParsingCub3D/libft/ft_strncmp.c
Normal file
27
ParsingCub3D/libft/ft_strncmp.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
39
ParsingCub3D/libft/ft_strnstr.c
Normal file
39
ParsingCub3D/libft/ft_strnstr.c
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
29
ParsingCub3D/libft/ft_strrchr.c
Normal file
29
ParsingCub3D/libft/ft_strrchr.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
30
ParsingCub3D/libft/ft_strtrim.c
Normal file
30
ParsingCub3D/libft/ft_strtrim.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
38
ParsingCub3D/libft/ft_substr.c
Normal file
38
ParsingCub3D/libft/ft_substr.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
20
ParsingCub3D/libft/ft_tolower.c
Normal file
20
ParsingCub3D/libft/ft_tolower.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
20
ParsingCub3D/libft/ft_toupper.c
Normal file
20
ParsingCub3D/libft/ft_toupper.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
80
ParsingCub3D/libft/libft.h
Normal file
80
ParsingCub3D/libft/libft.h
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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
|
||||||
34
ParsingCub3D/libft/main.c
Normal file
34
ParsingCub3D/libft/main.c
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#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);
|
||||||
|
}
|
||||||
6
ParsingCub3D/map/map.exe
Normal file
6
ParsingCub3D/map/map.exe
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
111111111111111111
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
111111111111111111
|
||||||
8
ParsingCub3D/map/map1.cub
Normal file
8
ParsingCub3D/map/map1.cub
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
111111111111111111
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
111111111111111111
|
||||||
14
ParsingCub3D/map/map2.cub
Normal file
14
ParsingCub3D/map/map2.cub
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
1111111111111111111111111
|
||||||
|
1000000000110000000000001
|
||||||
|
1011000001110000000000001
|
||||||
|
1001000000000000000000001
|
||||||
|
111111111011000001110000000000001
|
||||||
|
100000000011000001110111111111111
|
||||||
|
11110111111111011100000010001
|
||||||
|
11110111111111011101010010001
|
||||||
|
11000000110101011100000010001
|
||||||
|
10000000000000001100000010001
|
||||||
|
10000000000000001101010010001
|
||||||
|
11000001110101011111011110N0111
|
||||||
|
11110111 1110101 101111010001
|
||||||
|
11111111 1111111 111111111111
|
||||||
6
ParsingCub3D/map/map3.cub
Normal file
6
ParsingCub3D/map/map3.cub
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
111111111111111111
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
100000000000000001
|
||||||
|
10000000E000000001
|
||||||
|
111111111111111111
|
||||||
246
ParsingCub3D/srcs/main.c
Normal file
246
ParsingCub3D/srcs/main.c
Normal file
@ -0,0 +1,246 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/05/10 17:54:25 by sadjigui #+# #+# */
|
||||||
|
/* Updated: 2022/06/07 20:09:36 by sadjigui ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../includes/parsercub3D.h"
|
||||||
|
|
||||||
|
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++;
|
||||||
|
if(tab[i][j + 1] == '3' || tab[i][j - 1] == '3')
|
||||||
|
global->error++;
|
||||||
|
if(tab[i + 1][j + 1] == '3' || tab[i + 1][j - 1] == '3')
|
||||||
|
global->error++;
|
||||||
|
if(tab[i - 1][j + 1] == '3' || tab[i - 1][j - 1] == '3')
|
||||||
|
global->error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (2);
|
||||||
|
// else
|
||||||
|
// return (2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
printf("%d\n", player);
|
||||||
|
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 != 1)
|
||||||
|
global->error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 + 3)
|
||||||
|
{
|
||||||
|
tmp[i] = charge_new(global);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
tmp[i] = NULL;
|
||||||
|
inter_map(split, tmp);
|
||||||
|
check_border(tmp, global);
|
||||||
|
check_inner(tmp, global);
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
exit(1);
|
||||||
|
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\n", 2);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
map = isafile(av, global);
|
||||||
|
int i = 0;
|
||||||
|
printf("----------------\n");
|
||||||
|
while (map[i])
|
||||||
|
{
|
||||||
|
printf("%s\n", map[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (global->error != 0)
|
||||||
|
{
|
||||||
|
ft_putstr_fd("Error\n", 2);
|
||||||
|
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");
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user