wip_parsing
This commit is contained in:
1
MacroLibX
Submodule
1
MacroLibX
Submodule
Submodule MacroLibX added at 5a09ebb179
47
Makefile
Normal file
47
Makefile
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
NAME = cub3D
|
||||||
|
|
||||||
|
CC = cc
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
|
||||||
|
SRCDIR = src/
|
||||||
|
|
||||||
|
I_DIR = includes/
|
||||||
|
|
||||||
|
LIBFT_DIR = libft/
|
||||||
|
|
||||||
|
INCLUDE = -I $(I_DIR) -I $(LIBFT_DIR)/$(I_DIR)
|
||||||
|
|
||||||
|
SRCS = src/main.c \
|
||||||
|
src/parsing/check_arg.c \
|
||||||
|
src/utils/mess_error.c
|
||||||
|
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.c=.o))
|
||||||
|
|
||||||
|
FLAGS = -Wall -Werror -Wextra
|
||||||
|
LIB = libft/libft.a
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@make -s -C libft
|
||||||
|
@$(CC) $(FLAGS) $(OBJS) $(LIB) -o $(NAME)
|
||||||
|
@echo "✅ Compiled"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.c
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(INCLUDE) $(FLAGS) $< -c -o $@
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@make -s -C libft clean
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@make -s -C libft fclean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@echo "🧹 Cleaned"
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: clean all re fclean
|
28
include/cub3d.h
Normal file
28
include/cub3d.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* cub3d.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/04 17:01:05 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/07 17:48:56 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef CUB3D_H
|
||||||
|
# define CUB3D_H
|
||||||
|
|
||||||
|
# include "../libft/includes/libft.h"
|
||||||
|
# include "mess_err.h"
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <math.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <fcntl.h>
|
||||||
|
|
||||||
|
int check_format_file(char *file);
|
||||||
|
int check_err_arg(int argc, char **argv);
|
||||||
|
|
||||||
|
int err_mess(char *str);
|
||||||
|
|
||||||
|
#endif
|
24
include/mess_err.h
Normal file
24
include/mess_err.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* mess_err.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/04 21:59:56 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/07 19:13:20 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
//for argurments
|
||||||
|
|
||||||
|
#define ERR_ARGS "Wrong number of arguments"
|
||||||
|
#define ERR_TYPE "Wrong type of file"
|
||||||
|
#define EMPTY "Empty file"
|
||||||
|
|
||||||
|
//for map
|
||||||
|
|
||||||
|
#define NOT_CLOSE "The map isn't closed"
|
||||||
|
#define ERR_PLAYER "Incorrect number of players"
|
||||||
|
|
||||||
|
//for permission
|
66
libft/Ft_Printf/ft_printf.c
Normal file
66
libft/Ft_Printf/ft_printf.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/13 14:38:09 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/07/09 17:54:17 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
static int ft_conversions(va_list args, char c)
|
||||||
|
{
|
||||||
|
int print;
|
||||||
|
|
||||||
|
print = 0;
|
||||||
|
if (c == 'c')
|
||||||
|
print += ft_putchar(va_arg(args, int));
|
||||||
|
else if (c == 's')
|
||||||
|
print += ft_putstr(va_arg(args, char *));
|
||||||
|
else if (c == 'p')
|
||||||
|
print += ft_print_ptr(va_arg(args, void *));
|
||||||
|
else if (c == 'd')
|
||||||
|
print += ft_putnbr(va_arg(args, int));
|
||||||
|
else if (c == 'i')
|
||||||
|
print += ft_putnbr(va_arg(args, int));
|
||||||
|
else if (c == 'u')
|
||||||
|
print += ft_putnbr_uns_int(va_arg(args, unsigned int));
|
||||||
|
else if (c == 'x')
|
||||||
|
print += ft_putnbr_hexa_low(va_arg(args, unsigned int));
|
||||||
|
else if (c == 'X')
|
||||||
|
print += ft_putnbr_hexa_upp(va_arg(args, unsigned int));
|
||||||
|
else if (c == '%')
|
||||||
|
print += ft_putchar('%');
|
||||||
|
return (print);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_printf(const char *str, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
int print;
|
||||||
|
|
||||||
|
if (!str)
|
||||||
|
return (-1);
|
||||||
|
va_start(args, str);
|
||||||
|
print = 0;
|
||||||
|
while (*str)
|
||||||
|
{
|
||||||
|
if (*str == '%')
|
||||||
|
{
|
||||||
|
++str;
|
||||||
|
if (*str)
|
||||||
|
print += ft_conversions(args, *str);
|
||||||
|
else
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
print += ft_putchar(*str);
|
||||||
|
str++;
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
return (print);
|
||||||
|
}
|
63
libft/Ft_Printf/ft_printf_utils.c
Normal file
63
libft/Ft_Printf/ft_printf_utils.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/26 15:52:39 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/02/02 14:25:22 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_putchar(char c)
|
||||||
|
{
|
||||||
|
write(1, &c, 1);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_putnbr(int n)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (n == -2147483648)
|
||||||
|
{
|
||||||
|
i += ft_putchar('-');
|
||||||
|
i += ft_putchar('2');
|
||||||
|
n = 147483648;
|
||||||
|
}
|
||||||
|
if (n < 0)
|
||||||
|
{
|
||||||
|
i += ft_putchar('-');
|
||||||
|
n *= -1;
|
||||||
|
}
|
||||||
|
if (n < 10)
|
||||||
|
{
|
||||||
|
i += ft_putchar(n + '0');
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
else if (n >= 10)
|
||||||
|
{
|
||||||
|
i += ft_putnbr(n / 10);
|
||||||
|
i += ft_putnbr(n % 10);
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_putstr(char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!str)
|
||||||
|
return (ft_putstr("(null)"));
|
||||||
|
while (str[i] != '\0')
|
||||||
|
{
|
||||||
|
write(1, &str[i], 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
60
libft/Ft_Printf/ft_putnbr_hexa.c
Normal file
60
libft/Ft_Printf/ft_putnbr_hexa.c
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr_hexa.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/15 13:11:42 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/02/22 10:35:30 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_putnbr_hexa_low(size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (n < 16)
|
||||||
|
{
|
||||||
|
i += ft_putchar("0123456789abcdef"[n % 16]);
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
else if (n >= 10)
|
||||||
|
{
|
||||||
|
i += ft_putnbr_hexa_low(n / 16);
|
||||||
|
i += ft_putnbr_hexa_low(n % 16);
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_putnbr_hexa_upp(unsigned int n)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (n < 16)
|
||||||
|
{
|
||||||
|
i += ft_putchar("0123456789ABCDEF"[n % 16]);
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
else if (n >= 10)
|
||||||
|
{
|
||||||
|
i += ft_putnbr_hexa_upp(n / 16);
|
||||||
|
i += ft_putnbr_hexa_upp(n % 16);
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_print_ptr(void *ptr)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (!ptr)
|
||||||
|
i = ft_putstr("(nil)");
|
||||||
|
else
|
||||||
|
i = ft_putstr("0x") + ft_putnbr_hexa_low((size_t)ptr);
|
||||||
|
return (i);
|
||||||
|
}
|
31
libft/Ft_Printf/ft_putnbr_uns_int.c
Normal file
31
libft/Ft_Printf/ft_putnbr_uns_int.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr_uns_int.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/17 13:18:12 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/28 12:16:03 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ft_printf.h"
|
||||||
|
|
||||||
|
int ft_putnbr_uns_int(unsigned int n)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (n < 10)
|
||||||
|
{
|
||||||
|
i += ft_putchar(n + '0');
|
||||||
|
return (i);
|
||||||
|
}
|
||||||
|
else if (n >= 10)
|
||||||
|
{
|
||||||
|
i += ft_putnbr(n / 10);
|
||||||
|
i += ft_putnbr(n % 10);
|
||||||
|
}
|
||||||
|
return (i);
|
||||||
|
}
|
67
libft/Makefile
Normal file
67
libft/Makefile
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
NAME = libft.a
|
||||||
|
|
||||||
|
SRCS = is/ft_isalpha.c \
|
||||||
|
is/ft_isalnum.c \
|
||||||
|
is/ft_isascii.c \
|
||||||
|
is/ft_isdigit.c \
|
||||||
|
is/ft_isprint.c \
|
||||||
|
is/ft_is_space.c \
|
||||||
|
str/ft_strlen.c \
|
||||||
|
str/ft_toupper.c \
|
||||||
|
str/ft_tolower.c \
|
||||||
|
str/ft_strchr.c \
|
||||||
|
str/ft_strrchr.c \
|
||||||
|
str/ft_strncmp.c \
|
||||||
|
str/ft_strnstr.c \
|
||||||
|
str/ft_atoi.c \
|
||||||
|
mem/ft_memset.c \
|
||||||
|
mem/ft_memmove.c \
|
||||||
|
mem/ft_memcpy.c \
|
||||||
|
mem/ft_memchr.c \
|
||||||
|
mem/ft_memcmp.c \
|
||||||
|
mem/ft_bzero.c \
|
||||||
|
mem/ft_calloc.c \
|
||||||
|
str/ft_strlcpy.c \
|
||||||
|
str/ft_strlcat.c \
|
||||||
|
put/ft_putchar_fd.c \
|
||||||
|
put/ft_putendl_fd.c \
|
||||||
|
put/ft_putstr_fd.c \
|
||||||
|
put/ft_putnbr_fd.c \
|
||||||
|
str/ft_strdup.c \
|
||||||
|
str/ft_strjoin.c \
|
||||||
|
str/ft_substr.c \
|
||||||
|
str/ft_strtrim.c \
|
||||||
|
str/ft_itoa.c \
|
||||||
|
str/ft_striteri.c \
|
||||||
|
str/ft_strmapi.c \
|
||||||
|
str/ft_split.c \
|
||||||
|
str/ft_atoll.c \
|
||||||
|
Ft_Printf/ft_printf_utils.c \
|
||||||
|
Ft_Printf/ft_printf.c \
|
||||||
|
Ft_Printf/ft_putnbr_hexa.c \
|
||||||
|
Ft_Printf/ft_putnbr_uns_int.c \
|
||||||
|
gnl/get_next_line.c \
|
||||||
|
str/ft_count_word.c \
|
||||||
|
str/ft_strcmp.c
|
||||||
|
|
||||||
|
OBJS = ${SRCS:.c=.o}
|
||||||
|
|
||||||
|
HEADERS = includes/
|
||||||
|
|
||||||
|
all : ${NAME}
|
||||||
|
|
||||||
|
${OBJS} :
|
||||||
|
@gcc -Wall -Wextra -Werror -I ${HEADERS} -c ${@:.o=.c} -o $@
|
||||||
|
|
||||||
|
${NAME} : ${OBJS}
|
||||||
|
@ar rcs ${NAME} ${OBJS}
|
||||||
|
|
||||||
|
clean :
|
||||||
|
@rm -f ${OBJS}
|
||||||
|
|
||||||
|
fclean : clean
|
||||||
|
@rm -f ${NAME}
|
||||||
|
|
||||||
|
re : fclean all
|
||||||
|
|
||||||
|
.PHONY : all clean fclean re
|
0
libft/compile_commands.json
Normal file
0
libft/compile_commands.json
Normal file
74
libft/gnl/get_next_line.c
Normal file
74
libft/gnl/get_next_line.c
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* get_next_line.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/24 11:51:12 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/04 15:59:19 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../includes/libft.h"
|
||||||
|
|
||||||
|
char ft_end_of_line(char *line, char *buffer)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
while (line[i] && line[i] != '\n')
|
||||||
|
i++;
|
||||||
|
if (line[i] == '\n')
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
while (line[i])
|
||||||
|
{
|
||||||
|
buffer[j] = line[i];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
buffer[j] = '\0';
|
||||||
|
line[i - j] = '\0';
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_verif(char **buffer, char *line)
|
||||||
|
{
|
||||||
|
free(*buffer);
|
||||||
|
*buffer = NULL;
|
||||||
|
if (line[0] != '\0')
|
||||||
|
return (line);
|
||||||
|
free(line);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_next_line(int fd)
|
||||||
|
{
|
||||||
|
static char *buffer;
|
||||||
|
char *line;
|
||||||
|
int read_nb;
|
||||||
|
|
||||||
|
if (fd < 0 || fd > 1023 || BUFFER_SIZE <= 0)
|
||||||
|
return (NULL);
|
||||||
|
line = ft_calloc(1, 1);
|
||||||
|
if (!buffer)
|
||||||
|
buffer = ft_calloc(sizeof(char), (BUFFER_SIZE + 1));
|
||||||
|
while (buffer && line)
|
||||||
|
{
|
||||||
|
line = ft_strjoin(line, buffer);
|
||||||
|
if (!line)
|
||||||
|
return (NULL);
|
||||||
|
if (ft_end_of_line(line, buffer) == 1)
|
||||||
|
return (line);
|
||||||
|
read_nb = read(fd, buffer, BUFFER_SIZE);
|
||||||
|
if (read_nb < 1)
|
||||||
|
return (ft_verif(&buffer, line));
|
||||||
|
buffer[read_nb] = '\0';
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
30
libft/includes/ft_printf.h
Normal file
30
libft/includes/ft_printf.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_printf.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/13 14:34:51 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/02/02 14:25:30 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef FT_PRINTF_H
|
||||||
|
# define FT_PRINTF_H
|
||||||
|
|
||||||
|
# include <stddef.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <stdarg.h>
|
||||||
|
|
||||||
|
int ft_printf(const char *str, ...);
|
||||||
|
int ft_putchar(char c);
|
||||||
|
int ft_putstr(char *str);
|
||||||
|
int ft_putnbr(int n);
|
||||||
|
int ft_putnbr_uns_int(unsigned int n);
|
||||||
|
int ft_putnbr_hexa_low(size_t n);
|
||||||
|
int ft_putnbr_hexa_upp(unsigned int n);
|
||||||
|
int ft_print_ptr(void *ptr);
|
||||||
|
|
||||||
|
#endif
|
69
libft/includes/libft.h
Normal file
69
libft/includes/libft.h
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* libft.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 13:02:45 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/04 16:24:48 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef LIBFT_H
|
||||||
|
# define LIBFT_H
|
||||||
|
|
||||||
|
# include <stddef.h>
|
||||||
|
# include <stdlib.h>
|
||||||
|
# include <unistd.h>
|
||||||
|
# include <limits.h>
|
||||||
|
|
||||||
|
# ifndef BUFFER_SIZE
|
||||||
|
# define BUFFER_SIZE 1
|
||||||
|
# endif
|
||||||
|
|
||||||
|
int ft_atoi(const char *str);
|
||||||
|
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_strchr(const char *str, int p);
|
||||||
|
char *ft_strdup(const char *s);
|
||||||
|
size_t ft_strlen(const char *str);
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
char *ft_strrchr(const char *str, int p);
|
||||||
|
int ft_tolower(int i);
|
||||||
|
int ft_toupper(int i);
|
||||||
|
char *ft_strnstr(const char *str, const char *to_find, size_t len);
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2);
|
||||||
|
void *ft_memset(void *ptr, int v, size_t count);
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t n);
|
||||||
|
void ft_bzero(void *s, size_t count);
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t n);
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n);
|
||||||
|
size_t ft_strlcpy(char *dest, const char *src, size_t size);
|
||||||
|
void *ft_calloc(size_t nmemb, size_t size);
|
||||||
|
size_t ft_strlcat(char *dest, const char *src, size_t destsize);
|
||||||
|
char *ft_strtrim(char const *s1, char const *set);
|
||||||
|
char **ft_split(char const *s, char c);
|
||||||
|
char *ft_itoa(int n);
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len);
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char*));
|
||||||
|
void ft_putchar_fd(char c, int fd);
|
||||||
|
void ft_putstr_fd(char *s, int fd);
|
||||||
|
void ft_putendl_fd(char *s, int fd);
|
||||||
|
void ft_putnbr_fd(int n, int fd);
|
||||||
|
long long int ft_atoll(const char *str);
|
||||||
|
int ft_is_space(char c);
|
||||||
|
char ft_end_of_line(char *line, char *buffer);
|
||||||
|
char *ft_verif(char **buffer, char *line);
|
||||||
|
char *get_next_line(int fd);
|
||||||
|
int ft_count_word(const char *str, char sep);
|
||||||
|
int ft_count_len(const char *str, char sep);
|
||||||
|
void *ft_free(char **s);
|
||||||
|
int ft_strcmp(char *s1, char *s2);
|
||||||
|
|
||||||
|
#endif
|
20
libft/is/ft_is_space.c
Normal file
20
libft/is/ft_is_space.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_is_space.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/02/14 12:49:51 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/02/18 16:08:06 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_is_space(char c)
|
||||||
|
{
|
||||||
|
if (c == ' ' || (c >= 9 && c <= 13))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
21
libft/is/ft_isalnum.c
Normal file
21
libft/is/ft_isalnum.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalnum.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 13:03:43 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 14:58:15 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalnum(int i)
|
||||||
|
{
|
||||||
|
if ((i >= '0' && i <= '9') || (i >= 'a' && i <= 'z')
|
||||||
|
|| (i >= 'A' && i <= 'Z'))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
20
libft/is/ft_isalpha.c
Normal file
20
libft/is/ft_isalpha.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isalpha.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 12:35:26 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 14:58:21 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isalpha(int i)
|
||||||
|
{
|
||||||
|
if ((i >= 'a' && i <= 'z') || (i >= 'A' && i <= 'Z'))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
20
libft/is/ft_isascii.c
Normal file
20
libft/is/ft_isascii.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isascii.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 13:32:37 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 14:58:27 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isascii(int i)
|
||||||
|
{
|
||||||
|
if (i >= 0 && i <= 127)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
20
libft/is/ft_isdigit.c
Normal file
20
libft/is/ft_isdigit.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isdigit.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 12:47:04 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/02/06 13:04:37 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isdigit(int i)
|
||||||
|
{
|
||||||
|
if (i >= '0' && i <= '9')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
20
libft/is/ft_isprint.c
Normal file
20
libft/is/ft_isprint.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_isprint.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 14:08:46 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 14:58:37 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_isprint(int i)
|
||||||
|
{
|
||||||
|
if (i < 32 || i > 126)
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
19
libft/mem/ft_bzero.c
Normal file
19
libft/mem/ft_bzero.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_bzero.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 17:15:50 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 13:48:10 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_bzero(void *s, size_t count)
|
||||||
|
{
|
||||||
|
ft_memset(s, 0, count);
|
||||||
|
}
|
30
libft/mem/ft_calloc.c
Normal file
30
libft/mem/ft_calloc.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_calloc.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 14:41:05 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/09 16:18:08 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_calloc(size_t ct, size_t size)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (size == 0 || ct == 0)
|
||||||
|
return (malloc(1));
|
||||||
|
if ((int)size < 0 && (int)ct < 0)
|
||||||
|
return (NULL);
|
||||||
|
if ((unsigned long long)(size * ct) > UINT_MAX)
|
||||||
|
return (NULL);
|
||||||
|
str = malloc(size * ct);
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
ft_bzero(str, size * ct);
|
||||||
|
return (str);
|
||||||
|
}
|
29
libft/mem/ft_memchr.c
Normal file
29
libft/mem/ft_memchr.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 14:41:18 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/09 16:24:27 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memchr(const void *s, int c, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!s)
|
||||||
|
return (0);
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
if (*(unsigned char *)(s + i) == (unsigned char)c)
|
||||||
|
return ((void *)(s + i));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
31
libft/mem/ft_memcmp.c
Normal file
31
libft/mem/ft_memcmp.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 14:42:37 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 14:11:43 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_memcmp(const void *s1, const void *s2, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
unsigned char *ptr1;
|
||||||
|
unsigned char *ptr2;
|
||||||
|
|
||||||
|
ptr1 = (unsigned char *) s1;
|
||||||
|
ptr2 = (unsigned char *) s2;
|
||||||
|
i = 0;
|
||||||
|
while (i < n)
|
||||||
|
{
|
||||||
|
if (ptr1[i] != ptr2[i])
|
||||||
|
return (ptr1[i] - ptr2[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
28
libft/mem/ft_memcpy.c
Normal file
28
libft/mem/ft_memcpy.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 14:42:45 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/09 16:21:18 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memcpy(void *dest, const void *src, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!dest)
|
||||||
|
return (NULL);
|
||||||
|
while (i != n)
|
||||||
|
{
|
||||||
|
*(unsigned char *)(dest + i) = *(unsigned char *)(src + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
40
libft/mem/ft_memmove.c
Normal file
40
libft/mem/ft_memmove.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memmove.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 14:41:28 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/09 16:24:06 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memmove(void *dest, const void *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!dest && !src)
|
||||||
|
return (NULL);
|
||||||
|
if (dest > src)
|
||||||
|
{
|
||||||
|
i = size;
|
||||||
|
while (i > 0)
|
||||||
|
{
|
||||||
|
i--;
|
||||||
|
*(unsigned char *)(dest + i) = *(unsigned char *)(src + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (i != size)
|
||||||
|
{
|
||||||
|
*(unsigned char *)(dest + i) = *(unsigned char *)(src + i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (dest);
|
||||||
|
}
|
26
libft/mem/ft_memset.c
Normal file
26
libft/mem/ft_memset.c
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_memset.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 14:42:15 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 14:11:59 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_memset(void *ptr, int v, size_t count)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i != count)
|
||||||
|
{
|
||||||
|
*(unsigned char *)(ptr + i) = (unsigned char)v;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (ptr);
|
||||||
|
}
|
18
libft/put/ft_putchar_fd.c
Normal file
18
libft/put/ft_putchar_fd.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putchar_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/03 14:32:56 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/03 14:52:19 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putchar_fd(char c, int fd)
|
||||||
|
{
|
||||||
|
write(fd, &c, 1);
|
||||||
|
}
|
28
libft/put/ft_putendl_fd.c
Normal file
28
libft/put/ft_putendl_fd.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putendl_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/03 14:33:06 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/04/04 17:11:24 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putendl_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!s)
|
||||||
|
return ;
|
||||||
|
while (s[i] != '\0')
|
||||||
|
{
|
||||||
|
write(fd, &s[i], 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
write(fd, "\n", 1);
|
||||||
|
}
|
38
libft/put/ft_putnbr_fd.c
Normal file
38
libft/put/ft_putnbr_fd.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putnbr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/03 14:33:42 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/03 14:58:11 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putnbr_fd(int n, int fd)
|
||||||
|
{
|
||||||
|
if (n == -2147483648)
|
||||||
|
{
|
||||||
|
ft_putchar_fd('-', fd);
|
||||||
|
ft_putchar_fd('2', fd);
|
||||||
|
n = 147483648;
|
||||||
|
}
|
||||||
|
if (n < 0)
|
||||||
|
{
|
||||||
|
ft_putchar_fd('-', fd);
|
||||||
|
n *= -1;
|
||||||
|
}
|
||||||
|
if (n < 10)
|
||||||
|
{
|
||||||
|
ft_putchar_fd((n + '0'), fd);
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
else if (n >= 10)
|
||||||
|
{
|
||||||
|
ft_putnbr_fd((n / 10), fd);
|
||||||
|
ft_putnbr_fd((n % 10), fd);
|
||||||
|
}
|
||||||
|
}
|
27
libft/put/ft_putstr_fd.c
Normal file
27
libft/put/ft_putstr_fd.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_putstr_fd.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/03 14:33:15 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/09 16:26:33 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_putstr_fd(char *s, int fd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!s)
|
||||||
|
return ;
|
||||||
|
while (s[i] != '\0')
|
||||||
|
{
|
||||||
|
write(fd, &s[i], 1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
40
libft/str/ft_atoi.c
Normal file
40
libft/str/ft_atoi.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 15:05:03 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/03/26 16:17:58 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_atoi(const char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int r;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
r = 0;
|
||||||
|
s = 1;
|
||||||
|
if (!str)
|
||||||
|
return (0);
|
||||||
|
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
|
||||||
|
i++;
|
||||||
|
if (str[i] == '-' || str[i] == '+')
|
||||||
|
{
|
||||||
|
if (str[i] == '-')
|
||||||
|
s = -1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (str[i] >= '0' && str[i] <= '9')
|
||||||
|
{
|
||||||
|
r = r * 10 + str[i] - '0';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (r *= s);
|
||||||
|
}
|
40
libft/str/ft_atoll.c
Normal file
40
libft/str/ft_atoll.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_atoll.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/02/09 18:54:27 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/03/26 16:18:08 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
long long int ft_atoll(const char *str)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
long long int r;
|
||||||
|
int s;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
r = 0;
|
||||||
|
s = 1;
|
||||||
|
if (!str)
|
||||||
|
return (0);
|
||||||
|
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
|
||||||
|
i++;
|
||||||
|
if (str[i] == '-' || str[i] == '+')
|
||||||
|
{
|
||||||
|
if (str[i] == '-')
|
||||||
|
s = -1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (str[i] >= '0' && str[i] <= '9')
|
||||||
|
{
|
||||||
|
r = r * 10 + str[i] - '0';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (r *= s);
|
||||||
|
}
|
33
libft/str/ft_count_word.c
Normal file
33
libft/str/ft_count_word.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_count_word.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/05/29 00:04:58 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/05/29 00:05:09 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_count_word(const char *str, char sep)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
count = 0;
|
||||||
|
if (!str || !str[0])
|
||||||
|
return (0);
|
||||||
|
if (str[i++] != sep)
|
||||||
|
count++;
|
||||||
|
while (str[i])
|
||||||
|
{
|
||||||
|
if (str[i - 1] == sep && str[i] != sep)
|
||||||
|
count++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (count);
|
||||||
|
}
|
64
libft/str/ft_itoa.c
Normal file
64
libft/str/ft_itoa.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_itoa.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/06 11:14:32 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/08 10:22:00 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
static int ft_len(int n)
|
||||||
|
{
|
||||||
|
int cpt;
|
||||||
|
unsigned int nb;
|
||||||
|
|
||||||
|
cpt = 0;
|
||||||
|
if (n < 0)
|
||||||
|
{
|
||||||
|
cpt++;
|
||||||
|
nb = -n;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
nb = n;
|
||||||
|
while (nb >= 10)
|
||||||
|
{
|
||||||
|
nb /= 10;
|
||||||
|
cpt++;
|
||||||
|
}
|
||||||
|
cpt++;
|
||||||
|
return (cpt);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_itoa(int n)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
int cpt;
|
||||||
|
long long int nb;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
nb = n;
|
||||||
|
cpt = ft_len(n);
|
||||||
|
str = ft_calloc((cpt + 1), sizeof(char));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
if (n < 0)
|
||||||
|
{
|
||||||
|
str[0] = '-';
|
||||||
|
i = 1;
|
||||||
|
nb *= -1;
|
||||||
|
}
|
||||||
|
cpt--;
|
||||||
|
while (cpt >= i)
|
||||||
|
{
|
||||||
|
str[cpt] = (nb % 10) + '0';
|
||||||
|
nb /= 10;
|
||||||
|
cpt--;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
71
libft/str/ft_split.c
Normal file
71
libft/str/ft_split.c
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_split.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/08 12:11:54 by gadelbes #+# #+# */
|
||||||
|
/* Updated: 2024/05/29 00:04:26 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void *ft_free(char **s)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
free(s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
free(s);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ft_count_len(const char *str, char sep)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
len = 0;
|
||||||
|
while (str[i] && str[i] != sep)
|
||||||
|
{
|
||||||
|
len++;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char **ft_split(char const *s, char c)
|
||||||
|
{
|
||||||
|
char **str;
|
||||||
|
int i;
|
||||||
|
int w;
|
||||||
|
int l;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
w = 0;
|
||||||
|
if (!s)
|
||||||
|
return (NULL);
|
||||||
|
str = ft_calloc((ft_count_word((char *)s, c) + 1), sizeof(char *));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
while (w < ft_count_word(s, c))
|
||||||
|
{
|
||||||
|
while (s[i] == c)
|
||||||
|
i++;
|
||||||
|
l = ft_count_len((s + i), c);
|
||||||
|
str[w] = ft_calloc(l + 1, sizeof(char));
|
||||||
|
if (!str[w])
|
||||||
|
return (ft_free(str));
|
||||||
|
ft_strlcpy(str[w], s + i, l + 1);
|
||||||
|
w++;
|
||||||
|
i += l;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
31
libft/str/ft_strchr.c
Normal file
31
libft/str/ft_strchr.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 16:16:43 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/07 17:50:18 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strchr(const char *str, int p)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
while (str[i] != '\0')
|
||||||
|
{
|
||||||
|
if (str[i] == (unsigned char)p)
|
||||||
|
return ((char *) &str[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (str[i] == (unsigned char)p)
|
||||||
|
return ((char *) &str[i]);
|
||||||
|
return (0);
|
||||||
|
}
|
27
libft/str/ft_strcmp.c
Normal file
27
libft/str/ft_strcmp.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strcmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/06/06 12:58:01 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/06/24 14:42:39 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strcmp(char *s1, char *s2)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (s1[i] != '\0' || s2[i] != '\0')
|
||||||
|
{
|
||||||
|
if (s2[i] != s1[i])
|
||||||
|
return (s1[i] - s2[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
31
libft/str/ft_strdup.c
Normal file
31
libft/str/ft_strdup.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strdup.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 10:11:13 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/07/11 20:14:23 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strdup(const char *src)
|
||||||
|
{
|
||||||
|
int size;
|
||||||
|
char *dest;
|
||||||
|
|
||||||
|
size = 0;
|
||||||
|
dest = ft_calloc(sizeof(char), (ft_strlen(src) + 1));
|
||||||
|
if (dest == NULL)
|
||||||
|
return (NULL);
|
||||||
|
while (src[size])
|
||||||
|
{
|
||||||
|
dest[size] = src[size];
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
dest[size] = '\0';
|
||||||
|
return (dest);
|
||||||
|
}
|
27
libft/str/ft_striteri.c
Normal file
27
libft/str/ft_striteri.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_striteri.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/06 11:34:05 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/07 18:13:31 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
void ft_striteri(char *s, void (*f)(unsigned int, char*))
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!s || !f)
|
||||||
|
return ;
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
f(i, &s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
41
libft/str/ft_strjoin.c
Normal file
41
libft/str/ft_strjoin.c
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strjoin.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/07/27 17:26:43 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/07/09 15:36:26 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strjoin(char const *s1, char const *s2)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!s1)
|
||||||
|
return (ft_strdup(s2));
|
||||||
|
if (!s2)
|
||||||
|
return (ft_strdup(s1));
|
||||||
|
len = ft_strlen(s1) + ft_strlen(s2);
|
||||||
|
str = malloc(sizeof(char) * (len + 1));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
i = 0;
|
||||||
|
while (s1[i] != '\0')
|
||||||
|
{
|
||||||
|
str[i] = s1[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
j = 0;
|
||||||
|
while (s2[j] != '\0')
|
||||||
|
str[i++] = s2[j++];
|
||||||
|
str[i] = '\0';
|
||||||
|
return (str);
|
||||||
|
}
|
36
libft/str/ft_strlcat.c
Normal file
36
libft/str/ft_strlcat.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcat.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 14:42:26 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/03 14:21:31 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcat(char *dest, const char *src, size_t size)
|
||||||
|
{
|
||||||
|
size_t sdst;
|
||||||
|
size_t ssrc;
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
sdst = ft_strlen(dest);
|
||||||
|
ssrc = ft_strlen(src);
|
||||||
|
i = 0;
|
||||||
|
j = sdst;
|
||||||
|
if (sdst > size || size == 0)
|
||||||
|
return (ssrc + size);
|
||||||
|
while (src[i] && (i < size) && (sdst < size - 1))
|
||||||
|
{
|
||||||
|
dest[sdst] = src[i];
|
||||||
|
i++;
|
||||||
|
sdst++;
|
||||||
|
}
|
||||||
|
dest[sdst] = '\0';
|
||||||
|
return (ssrc + j);
|
||||||
|
}
|
30
libft/str/ft_strlcpy.c
Normal file
30
libft/str/ft_strlcpy.c
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlcpy.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 10:08:10 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/03 12:30:11 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlcpy(char *dest, const char *src, size_t destsize)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (destsize > 0)
|
||||||
|
{
|
||||||
|
while (src[i] && i < destsize - 1)
|
||||||
|
{
|
||||||
|
dest[i] = src[i];
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
dest[i] = '\0';
|
||||||
|
}
|
||||||
|
return (ft_strlen(src));
|
||||||
|
}
|
23
libft/str/ft_strlen.c
Normal file
23
libft/str/ft_strlen.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strlen.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 14:07:38 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/07/09 17:00:57 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
size_t ft_strlen(const char *str)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (str && str[i])
|
||||||
|
i++;
|
||||||
|
return (i);
|
||||||
|
}
|
32
libft/str/ft_strmapi.c
Normal file
32
libft/str/ft_strmapi.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strmapi.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/06 11:33:40 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/08 09:42:37 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strmapi(char const *s, char (*f)(unsigned int, char))
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
if (!s || !f)
|
||||||
|
return (NULL);
|
||||||
|
str = ft_calloc(ft_strlen(s) + 1, sizeof(char));
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
while (s[i])
|
||||||
|
{
|
||||||
|
str[i] = f(i, s[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (str);
|
||||||
|
}
|
27
libft/str/ft_strncmp.c
Normal file
27
libft/str/ft_strncmp.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strncmp.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42angouleme. +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 16:12:37 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/03/29 11:43:32 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_strncmp(const char *s1, const char *s2, size_t n)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while ((s1[i] != '\0' || s2[i] != '\0') && i < n)
|
||||||
|
{
|
||||||
|
if (s1[i] != s2[i])
|
||||||
|
return ((unsigned char)s1[i] - (unsigned char)s2[i]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
38
libft/str/ft_strnstr.c
Normal file
38
libft/str/ft_strnstr.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strnstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/31 10:15:03 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/09 16:25:39 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strnstr(const char *str, const char *to_find, size_t len)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
j = 0;
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
if (to_find[0] == '\0')
|
||||||
|
return ((char *) &str[i]);
|
||||||
|
while (str[i] && i < len)
|
||||||
|
{
|
||||||
|
while (str[i + j] == to_find[j] && i + j < len)
|
||||||
|
{
|
||||||
|
j++;
|
||||||
|
if (to_find[j] == '\0')
|
||||||
|
return ((char *) &str[i]);
|
||||||
|
}
|
||||||
|
j = 0;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
31
libft/str/ft_strrchr.c
Normal file
31
libft/str/ft_strrchr.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strrchr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 16:42:24 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/03 15:59:52 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strrchr(const char *str, int p)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (str[i] != '\0')
|
||||||
|
i++;
|
||||||
|
while (i > 0)
|
||||||
|
{
|
||||||
|
if (str[i] == (unsigned char)p)
|
||||||
|
return ((char *) &str[i]);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
if (str[i] == (unsigned char)p)
|
||||||
|
return ((char *) &str[i]);
|
||||||
|
return (0);
|
||||||
|
}
|
31
libft/str/ft_strtrim.c
Normal file
31
libft/str/ft_strtrim.c
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_strtrim.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/06 11:33:52 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/07 17:51:00 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
char *ft_strtrim(char const *s1, char const *set)
|
||||||
|
{
|
||||||
|
size_t start;
|
||||||
|
size_t len;
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
if (!s1)
|
||||||
|
return (NULL);
|
||||||
|
len = ft_strlen(s1);
|
||||||
|
start = 0;
|
||||||
|
while (ft_strchr(set, s1[start]) != 0)
|
||||||
|
start++;
|
||||||
|
while (ft_strrchr(set, s1[len]) != 0)
|
||||||
|
len--;
|
||||||
|
str = ft_substr(s1, start, (len - start) + 1);
|
||||||
|
return (str);
|
||||||
|
}
|
47
libft/str/ft_substr.c
Normal file
47
libft/str/ft_substr.c
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_substr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/11/06 11:14:21 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/09 16:27:51 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_min(int lenb, int len)
|
||||||
|
{
|
||||||
|
if (len < lenb)
|
||||||
|
return (len);
|
||||||
|
return (lenb);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *ft_substr(char const *s, unsigned int start, size_t len)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
size_t lenb;
|
||||||
|
size_t i;
|
||||||
|
size_t j;
|
||||||
|
|
||||||
|
if (!s)
|
||||||
|
return (NULL);
|
||||||
|
if (start > ft_strlen(s))
|
||||||
|
return (ft_calloc(1, 1));
|
||||||
|
lenb = ft_strlen(s) - start;
|
||||||
|
str = malloc(sizeof(char) * ft_min(lenb, len) + 1);
|
||||||
|
if (!str)
|
||||||
|
return (NULL);
|
||||||
|
i = start;
|
||||||
|
j = 0;
|
||||||
|
while (s[i] && j < len)
|
||||||
|
{
|
||||||
|
str[j] = s[i];
|
||||||
|
i++;
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
str[j] = '\0';
|
||||||
|
return (str);
|
||||||
|
}
|
20
libft/str/ft_tolower.c
Normal file
20
libft/str/ft_tolower.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tolower.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 14:21:25 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 14:59:56 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_tolower(int i)
|
||||||
|
{
|
||||||
|
if (i >= 'A' && i <= 'Z')
|
||||||
|
i += 32;
|
||||||
|
return (i);
|
||||||
|
}
|
20
libft/str/ft_toupper.c
Normal file
20
libft/str/ft_toupper.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_toupper.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2023/10/30 14:21:13 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2023/11/02 15:00:00 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int ft_toupper(int i)
|
||||||
|
{
|
||||||
|
if (i >= 'a' && i <= 'z')
|
||||||
|
i -= 32;
|
||||||
|
return (i);
|
||||||
|
}
|
BIN
obj/src/main.o
Normal file
BIN
obj/src/main.o
Normal file
Binary file not shown.
BIN
obj/src/parsing/check_arg.o
Normal file
BIN
obj/src/parsing/check_arg.o
Normal file
Binary file not shown.
BIN
obj/src/utils/mess_error.o
Normal file
BIN
obj/src/utils/mess_error.o
Normal file
Binary file not shown.
44
src/main.c
Normal file
44
src/main.c
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/04 16:58:27 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/07 19:12:04 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../include/cub3d.h"
|
||||||
|
|
||||||
|
char **ft_parse_map(char *map)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char **parse_map;
|
||||||
|
char *save;
|
||||||
|
char *join;
|
||||||
|
|
||||||
|
fd = open(map, O_RDONLY);
|
||||||
|
save = get_next_line(fd);
|
||||||
|
join = ft_calloc(1, 1);
|
||||||
|
if (!join)
|
||||||
|
return (NULL);
|
||||||
|
while (save != NULL)
|
||||||
|
{
|
||||||
|
join = ft_strjoin(join, save);
|
||||||
|
free(save);
|
||||||
|
save = get_next_line(fd);
|
||||||
|
}
|
||||||
|
parse_map = ft_split(join, '\n');
|
||||||
|
free(join);
|
||||||
|
close(fd);
|
||||||
|
return (parse_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int ac, char **av)
|
||||||
|
{
|
||||||
|
if (check_err_arg(ac, av) == 1)
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
46
src/parsing/check_arg.c
Normal file
46
src/parsing/check_arg.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* check_arg.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/04 21:33:35 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/07 17:57:29 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../include/cub3d.h"
|
||||||
|
|
||||||
|
int check_err_arg(int ac, char **av)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
int rd;
|
||||||
|
char buf[10];
|
||||||
|
|
||||||
|
if (ac != 2)
|
||||||
|
return (err_mess(ERR_ARGS));
|
||||||
|
if (check_format_file(av[1]) == 0)
|
||||||
|
return (err_mess(ERR_TYPE));
|
||||||
|
fd = open(av[1], O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
return (err_mess(EMPTY));
|
||||||
|
}
|
||||||
|
rd = read(fd, buf, 10);
|
||||||
|
close(fd);
|
||||||
|
return (rd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int check_format_file(char *file)
|
||||||
|
{
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = ft_strlen(file) - 1;
|
||||||
|
if (file[len] == 'b' && file[len - 1] == 'u' && \
|
||||||
|
file[len - 2] == 'c' && file[len - 3] == '.')
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
0
src/parsing/check_id_text.c
Normal file
0
src/parsing/check_id_text.c
Normal file
0
src/parsing/check_map.c
Normal file
0
src/parsing/check_map.c
Normal file
0
src/parsing/check_rgb.c
Normal file
0
src/parsing/check_rgb.c
Normal file
18
src/parsing/memo_parsing
Normal file
18
src/parsing/memo_parsing
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
char **map = ft_parse_map(av[1]);
|
||||||
|
int i = 0;
|
||||||
|
while (map[i])
|
||||||
|
{
|
||||||
|
ft_putchar_fd('*', 2);
|
||||||
|
ft_putstr_fd(map[i], 2);
|
||||||
|
ft_putchar_fd('*', 2);
|
||||||
|
ft_putchar_fd('\n', 2);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
//envoyer de 0 a 3 inclus dans check id texture
|
||||||
|
//envoyer de 4 a 5 inclus dans check rgb format
|
||||||
|
//envoyer de 6 a jusqu a la fin dans check map
|
||||||
|
|
||||||
|
struct typedef s_pars
|
||||||
|
{
|
||||||
|
|
||||||
|
} t_pars;
|
20
src/utils/mess_error.c
Normal file
20
src/utils/mess_error.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* mess_error.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: madumerg <madumerg@42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/09/07 17:35:14 by madumerg #+# #+# */
|
||||||
|
/* Updated: 2024/09/07 17:40:57 by madumerg ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../include/cub3d.h"
|
||||||
|
|
||||||
|
int err_mess(char *str)
|
||||||
|
{
|
||||||
|
ft_putendl_fd("Error\n", 2);
|
||||||
|
ft_putendl_fd(str, 2);
|
||||||
|
return (1);
|
||||||
|
}
|
Reference in New Issue
Block a user