From 0e15b1ec6b1991473ec8482f748f55e1125db3be Mon Sep 17 00:00:00 2001 From: gbrochar Date: Tue, 22 Dec 2020 19:15:25 +0100 Subject: [PATCH] parser started, norm ok, valgrind ok --- Makefile | 26 ++++---- inc/scop.h | 109 ++++++++++++++++++++++++++++++++++ libft/Makefile | 122 -------------------------------------- libft/ft_atof.c | 36 ----------- libft/ft_atoi.c | 32 ---------- libft/ft_atoi_color.c | 33 ----------- libft/ft_atoi_len.c | 35 ----------- libft/ft_atoi_split.c | 34 ----------- libft/ft_bzero.c | 25 -------- libft/ft_error.c | 19 ------ libft/ft_get_last_node.c | 23 ------- libft/ft_isalnum.c | 18 ------ libft/ft_isalpha.c | 18 ------ libft/ft_isascii.c | 18 ------ libft/ft_isdigit.c | 18 ------ libft/ft_ishexdigit.c | 20 ------- libft/ft_isprint.c | 18 ------ libft/ft_isspace.c | 21 ------- libft/ft_itoa.c | 37 ------------ libft/ft_lstadd.c | 23 ------- libft/ft_lstadd_preview.c | 19 ------ libft/ft_lstdel.c | 25 -------- libft/ft_lstdelone.c | 19 ------ libft/ft_lstiter.c | 29 --------- libft/ft_lstmap.c | 31 ---------- libft/ft_lstnew.c | 40 ------------- libft/ft_memalloc.c | 27 --------- libft/ft_memccpy.c | 37 ------------ libft/ft_memchr.c | 31 ---------- libft/ft_memcmp.c | 33 ----------- libft/ft_memcpy.c | 30 ---------- libft/ft_memdel.c | 19 ------ libft/ft_memmove.c | 39 ------------ libft/ft_memset.c | 28 --------- libft/ft_power.c | 25 -------- libft/ft_putchar.c | 18 ------ libft/ft_putchar_fd.c | 18 ------ libft/ft_putendl.c | 19 ------ libft/ft_putendl_fd.c | 19 ------ libft/ft_putnbr.c | 31 ---------- libft/ft_putnbr_fd.c | 31 ---------- libft/ft_putstr.c | 19 ------ libft/ft_putstr_fd.c | 19 ------ libft/ft_sort_int.c | 33 ----------- libft/ft_sqrt.c | 23 ------- libft/ft_strcat.c | 32 ---------- libft/ft_strchr.c | 23 ------- libft/ft_strclr.c | 19 ------ libft/ft_strcmp.c | 21 ------- libft/ft_strcpy.c | 30 ---------- libft/ft_strdel.c | 18 ------ libft/ft_strdup.c | 29 --------- libft/ft_strequ.c | 27 --------- libft/ft_striter.c | 25 -------- libft/ft_striteri.c | 25 -------- libft/ft_strjoin.c | 34 ----------- libft/ft_strlcat.c | 32 ---------- libft/ft_strlen.c | 23 ------- libft/ft_strmap.c | 33 ----------- libft/ft_strmapi.c | 31 ---------- libft/ft_strncat.c | 30 ---------- libft/ft_strncmp.c | 21 ------- libft/ft_strncpy.c | 31 ---------- libft/ft_strnequ.c | 27 --------- libft/ft_strnew.c | 23 ------- libft/ft_strnstr.c | 40 ------------- libft/ft_strrchr.c | 28 --------- libft/ft_strsplit.c | 85 -------------------------- libft/ft_strstr.c | 38 ------------ libft/ft_strsub.c | 28 --------- libft/ft_strtab_isdigit.c | 33 ----------- libft/ft_strtrim.c | 40 ------------- libft/ft_swap.c | 22 ------- libft/ft_tolower.c | 20 ------- libft/ft_toupper.c | 20 ------- libft/get_next_line.c | 93 ----------------------------- libft/get_next_line.h | 22 ------- libft/libft.h | 103 -------------------------------- resources/mlx_README | 11 ---- resources/mlx_opengl.h | 21 ------- resources/mlx_opengl.m | 57 ------------------ src/env.c | 55 +++++++++++++++++ src/main.c | 36 +++++++++-- src/parse_file.c | 53 +++++++++++++++++ src/parse_line.c | 82 +++++++++++++++++++++++++ 85 files changed, 346 insertions(+), 2422 deletions(-) create mode 100644 inc/scop.h delete mode 100644 libft/Makefile delete mode 100644 libft/ft_atof.c delete mode 100644 libft/ft_atoi.c delete mode 100644 libft/ft_atoi_color.c delete mode 100644 libft/ft_atoi_len.c delete mode 100644 libft/ft_atoi_split.c delete mode 100644 libft/ft_bzero.c delete mode 100644 libft/ft_error.c delete mode 100644 libft/ft_get_last_node.c delete mode 100644 libft/ft_isalnum.c delete mode 100644 libft/ft_isalpha.c delete mode 100644 libft/ft_isascii.c delete mode 100644 libft/ft_isdigit.c delete mode 100644 libft/ft_ishexdigit.c delete mode 100644 libft/ft_isprint.c delete mode 100644 libft/ft_isspace.c delete mode 100644 libft/ft_itoa.c delete mode 100644 libft/ft_lstadd.c delete mode 100644 libft/ft_lstadd_preview.c delete mode 100644 libft/ft_lstdel.c delete mode 100644 libft/ft_lstdelone.c delete mode 100644 libft/ft_lstiter.c delete mode 100644 libft/ft_lstmap.c delete mode 100644 libft/ft_lstnew.c delete mode 100644 libft/ft_memalloc.c delete mode 100644 libft/ft_memccpy.c delete mode 100644 libft/ft_memchr.c delete mode 100644 libft/ft_memcmp.c delete mode 100644 libft/ft_memcpy.c delete mode 100644 libft/ft_memdel.c delete mode 100644 libft/ft_memmove.c delete mode 100644 libft/ft_memset.c delete mode 100644 libft/ft_power.c delete mode 100644 libft/ft_putchar.c delete mode 100644 libft/ft_putchar_fd.c delete mode 100644 libft/ft_putendl.c delete mode 100644 libft/ft_putendl_fd.c delete mode 100644 libft/ft_putnbr.c delete mode 100644 libft/ft_putnbr_fd.c delete mode 100644 libft/ft_putstr.c delete mode 100644 libft/ft_putstr_fd.c delete mode 100644 libft/ft_sort_int.c delete mode 100644 libft/ft_sqrt.c delete mode 100644 libft/ft_strcat.c delete mode 100644 libft/ft_strchr.c delete mode 100644 libft/ft_strclr.c delete mode 100644 libft/ft_strcmp.c delete mode 100644 libft/ft_strcpy.c delete mode 100644 libft/ft_strdel.c delete mode 100644 libft/ft_strdup.c delete mode 100644 libft/ft_strequ.c delete mode 100644 libft/ft_striter.c delete mode 100644 libft/ft_striteri.c delete mode 100644 libft/ft_strjoin.c delete mode 100644 libft/ft_strlcat.c delete mode 100644 libft/ft_strlen.c delete mode 100644 libft/ft_strmap.c delete mode 100644 libft/ft_strmapi.c delete mode 100644 libft/ft_strncat.c delete mode 100644 libft/ft_strncmp.c delete mode 100644 libft/ft_strncpy.c delete mode 100644 libft/ft_strnequ.c delete mode 100644 libft/ft_strnew.c delete mode 100644 libft/ft_strnstr.c delete mode 100644 libft/ft_strrchr.c delete mode 100644 libft/ft_strsplit.c delete mode 100644 libft/ft_strstr.c delete mode 100644 libft/ft_strsub.c delete mode 100644 libft/ft_strtab_isdigit.c delete mode 100644 libft/ft_strtrim.c delete mode 100644 libft/ft_swap.c delete mode 100644 libft/ft_tolower.c delete mode 100644 libft/ft_toupper.c delete mode 100644 libft/get_next_line.c delete mode 100644 libft/get_next_line.h delete mode 100644 libft/libft.h delete mode 100644 resources/mlx_README delete mode 100644 resources/mlx_opengl.h delete mode 100644 resources/mlx_opengl.m create mode 100644 src/env.c create mode 100644 src/parse_file.c create mode 100644 src/parse_line.c diff --git a/Makefile b/Makefile index 46ba7ae..c890c46 100644 --- a/Makefile +++ b/Makefile @@ -6,23 +6,30 @@ # By: gbrochar +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/12/17 19:47:03 by gbrochar #+# #+# # -# Updated: 2020/12/17 20:06:15 by gbrochar ### ########.fr # +# Updated: 2020/12/22 18:57:00 by gbrochar ### ########.fr # # # # **************************************************************************** # NAME = scop SRC_FILE = main.c \ + parse_file.c \ + parse_line.c \ + env.c \ OBJ_FILE = $(SRC_FILE:.c=.o) +INC_FILE = scop.h \ + SRC_DIR = src/ OBJ_DIR = obj/ +INC_DIR = inc/ SRC = $(addprefix $(SRC_DIR), $(SRC_FILE)) OBJ = $(addprefix $(OBJ_DIR), $(OBJ_FILE)) +INC = $(addprefix $(INC_DIR), $(INC_FILE)) -LIB = libft/libft.a +LIB = CC = gcc @@ -38,26 +45,25 @@ WHITE = \033[0m all: $(NAME) $(NAME): $(OBJ) - @make -C libft - @$(CC) $(CFLAGS) -c $(SRC) + @$(CC) $(CFLAGS) -c $(SRC) -I $(INC_DIR) @mv $(OBJ_FILE) $(OBJ_DIR) @$(CC) $(CFLAGS) $(OBJ) -o $(NAME) $(LIB) - @echo "$(GREEN)[OK]$(WHITE) $(NAME)" + @echo -e "$(GREEN)[OK]$(WHITE) $(NAME)" -$(OBJ_DIR)%.o: $(SRC_DIR)%.c libft/ +$(OBJ_DIR)%.o: $(SRC_DIR)%.c inc/ @if [ ! -d ./obj ]; then \ mkdir -p ./obj; \ fi; - @$(CC) $(CFLAGS) -I libft/ -o $@ -c $< - @echo "$(CYAN)[CC]$(WHITE) $<" + @$(CC) $(CFLAGS) -I $(INC_DIR) -o $@ -c $< + @echo -e "$(CYAN)[CC]$(WHITE) $<" clean: - @make -C libft clean @rm -rf $(OBJ_DIR) + @echo -e "$(RED)[REMOVED]$(WHITE) obj files" fclean: clean - @make -C libft fclean @rm -f $(NAME) + @echo -e "$(RED)[REMOVED]$(WHITE) $(NAME)" re: fclean all diff --git a/inc/scop.h b/inc/scop.h new file mode 100644 index 0000000..793d48b --- /dev/null +++ b/inc/scop.h @@ -0,0 +1,109 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* scop.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbrochar +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/12/22 12:08:22 by gbrochar #+# #+# */ +/* Updated: 2020/12/22 19:13:41 by gbrochar ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SCOP_H +# define SCOP_H + +# include +# include +# include + +# define SUCCESS 0 +# define FAILURE -1 +# define BREAK 1 +# define TRUE 1 +# define FALSE 0 + +typedef enum e_gl_buf_type t_gl_buf_type; + +enum e_gl_buf_type +{ + VERTEX, + UV, + NORMAL, + INDEX, + OTHER +}; + +typedef struct s_cam t_cam; +typedef struct s_window t_window; +typedef struct s_buf_d t_buf_d; +typedef struct s_buf_i t_buf_i; +typedef struct s_buf_s t_buf_s; +typedef struct s_obj t_obj; +typedef struct s_env t_env; + +struct s_cam +{ + double fov; + double aspect; + double near; + double far; +}; + +struct s_window +{ + int width; + int height; +}; + +struct s_buf_d +{ + double *data; +}; + +struct s_buf_i +{ + int *data; +}; + +struct s_buf_s +{ + short *data; +}; + +struct s_obj +{ + t_buf_d vertices; + t_buf_d uvs; + t_buf_d normals; + t_buf_s indices; + int vertices_ptr; + int uvs_ptr; + int normals_ptr; + int indices_ptr; +}; + +struct s_env +{ + char *file_name; + t_cam camera; + t_window window; + t_obj object; +}; + +int parse(t_env *e, int argc, char **argv); +void set_params(t_env *e, int argc, char **argv); +int parse_file(t_env *e); + +int parse_line(t_env *e, char *line); +t_gl_buf_type parse_gl_buf_type(char *token); +int parse_append_data_d(t_buf_d *buffer, char *token); +int parse_append_data_s(t_buf_s *buffer, char *token); + +void free_env(t_env *e); +void init_window(t_env *e); +void init_camera(t_env *e); +void init_object(t_env *e); +void init_env(t_env *e); + +#endif diff --git a/libft/Makefile b/libft/Makefile deleted file mode 100644 index 3d2ef03..0000000 --- a/libft/Makefile +++ /dev/null @@ -1,122 +0,0 @@ -# **************************************************************************** # -# # -# ::: :::::::: # -# Makefile :+: :+: :+: # -# +:+ +:+ +:+ # -# By: gbrochar +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2015/11/27 19:26:17 by gbrochar #+# #+# # -# Updated: 2020/12/17 20:06:52 by gbrochar ### ########.fr # -# # -# **************************************************************************** # - -NAME = libft.a - -SRC = ft_atoi.c \ - ft_atof.c \ - ft_bzero.c \ - ft_isalnum.c \ - ft_isalpha.c \ - ft_isascii.c \ - ft_isdigit.c \ - ft_isprint.c \ - ft_isspace.c \ - ft_itoa.c \ - ft_lstadd.c \ - ft_lstdel.c \ - ft_lstdelone.c \ - ft_lstiter.c \ - ft_lstmap.c \ - ft_lstnew.c \ - ft_memalloc.c \ - ft_memccpy.c \ - ft_memchr.c \ - ft_memcmp.c \ - ft_memcpy.c \ - ft_memdel.c \ - ft_memmove.c \ - ft_memset.c \ - ft_power.c \ - ft_putchar.c \ - ft_putchar_fd.c \ - ft_putendl.c \ - ft_putendl_fd.c \ - ft_putnbr.c \ - ft_putnbr_fd.c \ - ft_putstr.c \ - ft_putstr_fd.c \ - ft_sort_int.c \ - ft_sqrt.c \ - ft_strcat.c \ - ft_strchr.c \ - ft_strclr.c \ - ft_strcmp.c \ - ft_strcpy.c \ - ft_strdel.c \ - ft_strdup.c \ - ft_strequ.c \ - ft_striter.c \ - ft_striteri.c \ - ft_strjoin.c \ - ft_strlcat.c \ - ft_strlen.c \ - ft_strmap.c \ - ft_strmapi.c \ - ft_strncat.c \ - ft_strncmp.c \ - ft_strncpy.c \ - ft_strnequ.c \ - ft_strnew.c \ - ft_strnstr.c \ - ft_strrchr.c \ - ft_strsplit.c \ - ft_strstr.c \ - ft_strsub.c \ - ft_strtrim.c \ - ft_swap.c \ - ft_tolower.c \ - ft_toupper.c \ - ft_lstadd_preview.c \ - ft_get_last_node.c \ - ft_ishexdigit.c \ - ft_atoi_len.c \ - ft_atoi_color.c \ - ft_error.c \ - get_next_line.c \ - ft_strtab_isdigit.c \ - ft_atoi_split.c \ - -OBJ = $(SRC:.c=.o) - -CC = gcc - -CFLAGS = -Wall -Werror -Wextra - -RED = \033[31m -GREEN = \033[32m -YELLOW = \033[33m -BLUE = \033[34m -CYAN = \033[36m -WHITE= \033[0m - -all: $(NAME) - -$(NAME): $(OBJ) libft.h get_next_line.h - @$(CC) $(CFLAGS) -c $(SRC) - @ar rc $(NAME) $(OBJ) - @ranlib $(NAME) - @echo "$(GREEN)[OK]$(WHITE) Libft.a" - -%.o: %.c libft.h get_next_line.h - @$(CC) $(CFLAGS) -o $@ -c $< - @echo "$(CYAN)[OK]$(WHITE) $<" - -clean: - @rm -f $(OBJ) - -fclean: clean - @rm -f $(NAME) - -re: fclean all - -.PHONY: all clean fclean re diff --git a/libft/ft_atof.c b/libft/ft_atof.c deleted file mode 100644 index cbd3fe0..0000000 --- a/libft/ft_atof.c +++ /dev/null @@ -1,36 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atof.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/02/06 14:47:22 by gbrochar #+# #+# */ -/* Updated: 2019/02/21 15:34:04 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -double ft_atof(const char *str) -{ - char *tmp; - double floating_part; - double integer_part; - - integer_part = ft_atoi(str); - floating_part = 0; - tmp = ft_strchr(str, '.'); - if (tmp) - { - floating_part = ft_atoi(++tmp); - while (*tmp >= '0' && *tmp <= '9') - { - floating_part /= (double)10; - tmp++; - } - } - if (integer_part < 0) - return (-1.0 * (fabs(integer_part) + floating_part)); - return (integer_part + floating_part); -} diff --git a/libft/ft_atoi.c b/libft/ft_atoi.c deleted file mode 100644 index fc7ac10..0000000 --- a/libft/ft_atoi.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */ -/* Updated: 2019/02/06 16:16:54 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_atoi(const char *str) -{ - long result; - long sign; - - result = 0; - while (ft_isspace(*str)) - str++; - sign = (*str == '-') ? -1 : 1; - if (*str == '-' || *str == '+') - str++; - while (*str >= '0' && *str <= '9') - { - result = (result * 10) + (*str - '0'); - str++; - } - return ((int)(result * sign)); -} diff --git a/libft/ft_atoi_color.c b/libft/ft_atoi_color.c deleted file mode 100644 index 598c3cb..0000000 --- a/libft/ft_atoi_color.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi_color.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */ -/* Updated: 2016/05/06 10:25:37 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_atoi_color(char *hexa_color) -{ - int i; - int result; - - result = 0; - i = 5; - while (i >= 0) - { - if (hexa_color[i] >= '0' && hexa_color[i] <= '9') - result += (hexa_color[i] - '0') * ft_power(16, (6 - i)); - else if (hexa_color[i] >= 'A' && hexa_color[i] <= 'F') - result += (hexa_color[i] - '0') * ft_power(16, (6 - i)); - else - return (-1); - i--; - } - return (result); -} diff --git a/libft/ft_atoi_len.c b/libft/ft_atoi_len.c deleted file mode 100644 index b52b7ce..0000000 --- a/libft/ft_atoi_len.c +++ /dev/null @@ -1,35 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi_len.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 19:18:43 by gbrochar #+# #+# */ -/* Updated: 2016/05/06 11:45:55 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_atoi_len(char *str, int *len) -{ - int result; - int sign; - - result = 0; - *len = 0; - sign = (*str == '-') ? -1 : 1; - if (*str == '-' || *str == '+') - { - str++; - len++; - } - while (*str >= '0' && *str <= '9') - { - result = (result * 10) + (*str - '0'); - str++; - len++; - } - return (result * sign); -} diff --git a/libft/ft_atoi_split.c b/libft/ft_atoi_split.c deleted file mode 100644 index fab103c..0000000 --- a/libft/ft_atoi_split.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_atoi_split.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/05/31 08:52:54 by gbrochar #+# #+# */ -/* Updated: 2016/05/31 09:15:51 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int *ft_atoi_split(char *str, char c, int *tab_len) -{ - int *tab; - char **str_tab; - int i; - - if (!str || ft_isdigit(c)) - return (NULL); - str_tab = ft_strsplit(str, c); - i = 0; - while (str_tab[i]) - ++i; - if (!(tab = (int *)malloc((i + 1) * sizeof(int)))) - return (NULL); - *tab_len = i; - i = -1; - while (str_tab[++i]) - tab[i] = atoi(str_tab[i]); - return (tab); -} diff --git a/libft/ft_bzero.c b/libft/ft_bzero.c deleted file mode 100644 index e2131b2..0000000 --- a/libft/ft_bzero.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_bzero.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/24 11:39:18 by gbrochar #+# #+# */ -/* Updated: 2015/11/24 20:46:21 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_bzero(void *s, size_t n) -{ - char *byte; - - byte = s; - while (n-- > 0) - { - *byte = 0; - byte++; - } -} diff --git a/libft/ft_error.c b/libft/ft_error.c deleted file mode 100644 index e96e1ef..0000000 --- a/libft/ft_error.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_error.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/05/10 02:34:40 by gbrochar #+# #+# */ -/* Updated: 2016/05/11 10:55:43 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_error(char *str) -{ - ft_putstr_fd(str, 2); - exit(0); -} diff --git a/libft/ft_get_last_node.c b/libft/ft_get_last_node.c deleted file mode 100644 index ef59d02..0000000 --- a/libft/ft_get_last_node.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_get_last_node.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/02/28 07:10:21 by gbrochar #+# #+# */ -/* Updated: 2016/02/28 07:12:12 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_get_last_node(t_list **alst) -{ - t_list *tmp; - - tmp = *alst; - while (tmp->next) - tmp = tmp->next; - return (tmp); -} diff --git a/libft/ft_isalnum.c b/libft/ft_isalnum.c deleted file mode 100644 index f21a2cc..0000000 --- a/libft/ft_isalnum.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalnum.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:51:03 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 15:22:14 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isalnum(int c) -{ - return (ft_isalpha(c) || ft_isdigit(c)); -} diff --git a/libft/ft_isalpha.c b/libft/ft_isalpha.c deleted file mode 100644 index e4f61d6..0000000 --- a/libft/ft_isalpha.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalpha.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:59:08 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 15:42:21 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isalpha(int c) -{ - return (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') ? 1 : 0)); -} diff --git a/libft/ft_isascii.c b/libft/ft_isascii.c deleted file mode 100644 index c7daff9..0000000 --- a/libft/ft_isascii.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isascii.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:48:25 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 15:32:54 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isascii(int c) -{ - return ((c >= 0 && c <= 127) ? 1 : 0); -} diff --git a/libft/ft_isdigit.c b/libft/ft_isdigit.c deleted file mode 100644 index e850324..0000000 --- a/libft/ft_isdigit.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:53:19 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 14:41:12 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isdigit(int c) -{ - return ((c >= '0' && c <= '9') ? 1 : 0); -} diff --git a/libft/ft_ishexdigit.c b/libft/ft_ishexdigit.c deleted file mode 100644 index e4b4691..0000000 --- a/libft/ft_ishexdigit.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_ishexdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/05/05 23:22:51 by gbrochar #+# #+# */ -/* Updated: 2016/05/05 23:24:26 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_ishexdigit(int c) -{ - if (ft_isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) - return (1); - return (0); -} diff --git a/libft/ft_isprint.c b/libft/ft_isprint.c deleted file mode 100644 index 72badb5..0000000 --- a/libft/ft_isprint.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isprint.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:44:48 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 15:33:24 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isprint(int c) -{ - return ((c >= 32 && c <= 126) ? 1 : 0); -} diff --git a/libft/ft_isspace.c b/libft/ft_isspace.c deleted file mode 100644 index 89eb16a..0000000 --- a/libft/ft_isspace.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isspace.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 14:37:03 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 14:39:18 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_isspace(int c) -{ - if (c == '\t' || c == '\n' || c == '\f' || c == '\v' || c == '\r' - || c == ' ') - return (1); - return (0); -} diff --git a/libft/ft_itoa.c b/libft/ft_itoa.c deleted file mode 100644 index 26ee52e..0000000 --- a/libft/ft_itoa.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_itoa.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:56:59 by gbrochar #+# #+# */ -/* Updated: 2019/02/06 16:17:43 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_itoa(int n) -{ - char *str; - size_t str_size; - int n_mem; - - n_mem = n; - str_size = (n < 0) ? 3 : 2; - while ((n > 9 || n < -9) && str_size++) - n /= 10; - str = (char *)malloc((str_size--) * sizeof(char)); - if (!str) - return (NULL); - str[str_size--] = '\0'; - while (n_mem > 9 || n_mem < -9) - { - str[str_size--] = (n_mem < 0) ? -(n_mem % 10) + '0' : n_mem % 10 + '0'; - n_mem = n_mem / 10; - } - str[0] = (n_mem < 0) ? '-' : ((char)n_mem + '0'); - str[1] = (n_mem < 0) ? ((char)-n_mem + '0') : str[1]; - return (str); -} diff --git a/libft/ft_lstadd.c b/libft/ft_lstadd.c deleted file mode 100644 index 104dee9..0000000 --- a/libft/ft_lstadd.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/01 14:24:17 by gbrochar #+# #+# */ -/* Updated: 2016/02/26 14:02:54 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstadd(t_list **alst, t_list *new) -{ - t_list *tmp; - - tmp = *alst; - while (tmp->next != NULL) - tmp = tmp->next; - tmp->next = new; -} diff --git a/libft/ft_lstadd_preview.c b/libft/ft_lstadd_preview.c deleted file mode 100644 index 6fd80c0..0000000 --- a/libft/ft_lstadd_preview.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstadd_preview.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/01 14:24:17 by gbrochar #+# #+# */ -/* Updated: 2016/02/26 14:01:33 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstadd_preview(t_list **alst, t_list *new) -{ - new->next = *alst; - *alst = new; -} diff --git a/libft/ft_lstdel.c b/libft/ft_lstdel.c deleted file mode 100644 index 9c02c08..0000000 --- a/libft/ft_lstdel.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstdel.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/30 21:34:50 by gbrochar #+# #+# */ -/* Updated: 2015/12/05 15:10:37 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstdel(t_list **alst, void (*del)(void *, size_t)) -{ - t_list *tmp; - - while (*alst) - { - tmp = *alst; - ft_lstdelone(alst, del); - *alst = tmp->next; - } -} diff --git a/libft/ft_lstdelone.c b/libft/ft_lstdelone.c deleted file mode 100644 index 3448e9a..0000000 --- a/libft/ft_lstdelone.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstdelone.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/30 21:27:05 by gbrochar #+# #+# */ -/* Updated: 2015/12/02 13:28:32 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)) -{ - del((*alst)->content, (*alst)->content_size); - ft_memdel((void **)alst); -} diff --git a/libft/ft_lstiter.c b/libft/ft_lstiter.c deleted file mode 100644 index 5cddff7..0000000 --- a/libft/ft_lstiter.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstiter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/02 13:38:16 by gbrochar #+# #+# */ -/* Updated: 2015/12/04 16:41:19 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_lstiter(t_list *lst, void (*f)(t_list *elem)) -{ - t_list *start; - t_list *tmp; - - start = lst; - while (lst->next) - { - tmp = lst; - f(lst); - lst = tmp->next; - } - f(lst); - lst = start; -} diff --git a/libft/ft_lstmap.c b/libft/ft_lstmap.c deleted file mode 100644 index 8341e24..0000000 --- a/libft/ft_lstmap.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstmap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/02 14:33:07 by gbrochar #+# #+# */ -/* Updated: 2015/12/02 16:17:18 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) -{ - t_list *lst_begin; - t_list *lst_new; - - lst_begin = ft_lstnew((f(lst))->content, (f(lst))->content_size); - lst_new = lst_begin; - lst = lst->next; - while (lst->next) - { - lst_new->next = ft_lstnew((f(lst))->content, (f(lst))->content_size); - lst_new = lst_new->next; - lst = lst->next; - } - lst_new->next = ft_lstnew((f(lst))->content, (f(lst))->content_size); - return (lst_begin); -} diff --git a/libft/ft_lstnew.c b/libft/ft_lstnew.c deleted file mode 100644 index 9413638..0000000 --- a/libft/ft_lstnew.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_lstnew.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/30 21:21:09 by gbrochar #+# #+# */ -/* Updated: 2016/02/27 21:04:51 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -t_list *ft_lstnew(void const *content, size_t content_size) -{ - t_list *lst; - - lst = (t_list *)malloc(sizeof(t_list)); - if (!lst) - return (NULL); - if (!content) - { - lst->content = NULL; - lst->content_size = 0; - } - else - { - lst->content = ft_memalloc(content_size); - if (!lst->content) - { - free(lst); - return (NULL); - } - ft_memmove(lst->content, content, content_size); - lst->content_size = content_size; - } - lst->next = NULL; - return (lst); -} diff --git a/libft/ft_memalloc.c b/libft/ft_memalloc.c deleted file mode 100644 index 374edbf..0000000 --- a/libft/ft_memalloc.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memalloc.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 18:11:36 by gbrochar #+# #+# */ -/* Updated: 2016/02/27 21:04:55 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memalloc(size_t size) -{ - unsigned char *ptr; - size_t i; - - i = 0; - ptr = (unsigned char *)malloc(size); - if (!ptr) - return (NULL); - while (i < size) - ptr[i++] = 0; - return (ptr); -} diff --git a/libft/ft_memccpy.c b/libft/ft_memccpy.c deleted file mode 100644 index af8cfb1..0000000 --- a/libft/ft_memccpy.c +++ /dev/null @@ -1,37 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memccpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/24 14:40:00 by gbrochar #+# #+# */ -/* Updated: 2019/02/06 16:20:23 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memccpy(void *dst, const void *src, int c, size_t n) -{ - size_t i; - unsigned char to_find; - unsigned char *dst_byte; - const unsigned char *src_byte; - - to_find = (unsigned char)c; - i = 0; - dst_byte = (unsigned char *)dst; - src_byte = (const unsigned char *)src; - while (i != n && src_byte[i] != to_find) - { - dst_byte[i] = src_byte[i]; - i++; - } - if (src_byte[i] == to_find) - { - dst_byte[i] = to_find; - return ((void *)&dst_byte[i + 1]); - } - return (NULL); -} diff --git a/libft/ft_memchr.c b/libft/ft_memchr.c deleted file mode 100644 index 6a8893d..0000000 --- a/libft/ft_memchr.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 13:03:54 by gbrochar #+# #+# */ -/* Updated: 2020/12/17 20:08:39 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memchr(const void *s, int c, size_t n) -{ - unsigned char to_find; - unsigned char *str; - size_t i; - - i = 0; - to_find = c; - str = (unsigned char *)s; - while (i < n) - { - if (str[i] == to_find) - return ((void *)&((unsigned char *)s)[i]); - i++; - } - return (NULL); -} diff --git a/libft/ft_memcmp.c b/libft/ft_memcmp.c deleted file mode 100644 index 18aa48e..0000000 --- a/libft/ft_memcmp.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 14:13:46 by gbrochar #+# #+# */ -/* Updated: 2015/11/30 14:46:05 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_memcmp(const void *s1, const void *s2, size_t n) -{ - unsigned char *s1_byte; - unsigned char *s2_byte; - size_t i; - - s1_byte = (unsigned char *)s1; - s2_byte = (unsigned char *)s2; - i = 0; - if (n <= 0) - return (0); - while (s1_byte[i] == s2_byte[i]) - { - if (i + 1 == n) - return (0); - i++; - } - return (s1_byte[i] - s2_byte[i]); -} diff --git a/libft/ft_memcpy.c b/libft/ft_memcpy.c deleted file mode 100644 index 8a42505..0000000 --- a/libft/ft_memcpy.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 14:42:55 by gbrochar #+# #+# */ -/* Updated: 2015/11/25 14:43:02 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memcpy(void *dst, const void *src, size_t n) -{ - size_t i; - unsigned char *dst_byte; - const unsigned char *src_byte; - - i = 0; - dst_byte = dst; - src_byte = src; - while (i < n) - { - dst_byte[i] = src_byte[i]; - i++; - } - return (dst); -} diff --git a/libft/ft_memdel.c b/libft/ft_memdel.c deleted file mode 100644 index cd84e74..0000000 --- a/libft/ft_memdel.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memdel.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 18:23:10 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 18:25:10 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_memdel(void **ap) -{ - free(*ap); - *ap = NULL; -} diff --git a/libft/ft_memmove.c b/libft/ft_memmove.c deleted file mode 100644 index ce42e2a..0000000 --- a/libft/ft_memmove.c +++ /dev/null @@ -1,39 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memmove.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 12:36:04 by gbrochar #+# #+# */ -/* Updated: 2015/11/25 13:03:31 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memmove(void *dst, const void *src, size_t len) -{ - unsigned char *dst_byte; - const unsigned char *src_byte; - size_t index; - - dst_byte = dst; - src_byte = src; - if (dst_byte > src_byte) - { - index = len; - while (index-- > 0) - dst_byte[index] = src_byte[index]; - } - else - { - index = 0; - while (index < len) - { - dst_byte[index] = src_byte[index]; - index++; - } - } - return (dst); -} diff --git a/libft/ft_memset.c b/libft/ft_memset.c deleted file mode 100644 index 8606775..0000000 --- a/libft/ft_memset.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_memset.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/23 17:53:16 by gbrochar #+# #+# */ -/* Updated: 2015/11/25 12:18:32 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void *ft_memset(void *b, int c, size_t len) -{ - unsigned char *byte; - size_t i; - - byte = b; - i = 0; - while (i++ < len) - { - *byte = c; - byte++; - } - return (b); -} diff --git a/libft/ft_power.c b/libft/ft_power.c deleted file mode 100644 index 130d4a4..0000000 --- a/libft/ft_power.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_power.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/05 15:23:07 by gbrochar #+# #+# */ -/* Updated: 2015/12/07 11:03:41 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_power(int nb, int pow) -{ - int ret; - - ret = 1; - if (pow < 0) - return (-1); - while (pow--) - ret *= nb; - return (ret); -} diff --git a/libft/ft_putchar.c b/libft/ft_putchar.c deleted file mode 100644 index 82125ba..0000000 --- a/libft/ft_putchar.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/24 12:01:00 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 16:47:24 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putchar(char c) -{ - write(1, &c, 1); -} diff --git a/libft/ft_putchar_fd.c b/libft/ft_putchar_fd.c deleted file mode 100644 index 4fc2ee7..0000000 --- a/libft/ft_putchar_fd.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putchar_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:01:19 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 09:02:06 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putchar_fd(char c, int fd) -{ - write(fd, &c, 1); -} diff --git a/libft/ft_putendl.c b/libft/ft_putendl.c deleted file mode 100644 index 52a3be5..0000000 --- a/libft/ft_putendl.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:04:13 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 09:04:50 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putendl(char const *s) -{ - ft_putstr(s); - ft_putchar('\n'); -} diff --git a/libft/ft_putendl_fd.c b/libft/ft_putendl_fd.c deleted file mode 100644 index de5409b..0000000 --- a/libft/ft_putendl_fd.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putendl_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:04:58 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 09:05:51 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putendl_fd(char const *s, int fd) -{ - ft_putstr_fd(s, fd); - ft_putchar_fd('\n', fd); -} diff --git a/libft/ft_putnbr.c b/libft/ft_putnbr.c deleted file mode 100644 index 7e6ab30..0000000 --- a/libft/ft_putnbr.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putnbr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 08:58:30 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 10:49:28 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putnbr(int n) -{ - if (n == -2147483648) - ft_putstr("-2147483648"); - else if (n < 0) - { - ft_putchar('-'); - ft_putnbr(-n); - } - else if (n > 9) - { - ft_putnbr(n / 10); - ft_putchar(n % 10 + '0'); - } - else - ft_putchar(n + '0'); -} diff --git a/libft/ft_putnbr_fd.c b/libft/ft_putnbr_fd.c deleted file mode 100644 index 070cfd2..0000000 --- a/libft/ft_putnbr_fd.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putnbr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:10:52 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 10:49:38 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putnbr_fd(int n, int fd) -{ - if (n == -2147483648) - ft_putstr_fd("-2147483648", fd); - else if (n < 0) - { - ft_putchar_fd('-', fd); - ft_putnbr_fd(-n, fd); - } - else if (n > 9) - { - ft_putnbr_fd(n / 10, fd); - ft_putchar_fd(n % 10 + '0', fd); - } - else - ft_putchar_fd(n + '0', fd); -} diff --git a/libft/ft_putstr.c b/libft/ft_putstr.c deleted file mode 100644 index a21c751..0000000 --- a/libft/ft_putstr.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:23:12 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 09:06:37 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putstr(char const *s) -{ - while (*s) - write(1, s++, 1); -} diff --git a/libft/ft_putstr_fd.c b/libft/ft_putstr_fd.c deleted file mode 100644 index a7d909a..0000000 --- a/libft/ft_putstr_fd.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_putstr_fd.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:02:48 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 09:04:05 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_putstr_fd(char const *s, int fd) -{ - while (*s) - write(fd, s++, 1); -} diff --git a/libft/ft_sort_int.c b/libft/ft_sort_int.c deleted file mode 100644 index 9ed36cd..0000000 --- a/libft/ft_sort_int.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_sort_int.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/05 18:36:08 by gbrochar #+# #+# */ -/* Updated: 2015/12/07 11:04:19 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_sort_int(int *tab, int size) -{ - int i; - int tmp; - - i = 0; - while ((i + 1) < size) - { - if (tab[i] > tab[i + 1]) - { - tmp = tab[i]; - tab[i] = tab[i + 1]; - tab[i + 1] = tmp; - i = 0; - } - else - i++; - } -} diff --git a/libft/ft_sqrt.c b/libft/ft_sqrt.c deleted file mode 100644 index 7d71faf..0000000 --- a/libft/ft_sqrt.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_sqrt.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/07 08:28:11 by gbrochar #+# #+# */ -/* Updated: 2015/12/07 08:50:43 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -long ft_sqrt(long n) -{ - long sqrt; - - sqrt = 0; - while ((sqrt * sqrt) != n && (sqrt * sqrt) < n) - sqrt++; - return (((sqrt * sqrt) == n) ? (sqrt) : (-1)); -} diff --git a/libft/ft_strcat.c b/libft/ft_strcat.c deleted file mode 100644 index b0b3df0..0000000 --- a/libft/ft_strcat.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 16:26:53 by gbrochar #+# #+# */ -/* Updated: 2016/04/09 21:24:58 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strcat(char *s1, const char *s2) -{ - char *p_s1; - const char *p_s2; - - p_s2 = s2; - p_s1 = s1; - while (*p_s1) - p_s1++; - while (*p_s2) - { - *p_s1 = *p_s2; - p_s1++; - p_s2++; - } - *p_s1 = '\0'; - return (s1); -} diff --git a/libft/ft_strchr.c b/libft/ft_strchr.c deleted file mode 100644 index c257f96..0000000 --- a/libft/ft_strchr.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 09:50:37 by gbrochar #+# #+# */ -/* Updated: 2019/02/08 11:50:45 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strchr(const char *s, int c) -{ - if (s == NULL) - return (0); - while (*s != (char)c) - if (!*s++) - return (0); - return ((char *)s); -} diff --git a/libft/ft_strclr.c b/libft/ft_strclr.c deleted file mode 100644 index 6f9dc0a..0000000 --- a/libft/ft_strclr.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strclr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 20:22:52 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 21:09:55 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_strclr(char *s) -{ - while (*s) - *s++ = '\0'; -} diff --git a/libft/ft_strcmp.c b/libft/ft_strcmp.c deleted file mode 100644 index 1d70b10..0000000 --- a/libft/ft_strcmp.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 14:52:37 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 15:34:12 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strcmp(const char *s1, const char *s2) -{ - while (*s1 || *s2) - if (*s1++ != *s2++) - return ((unsigned char)*--s1 - (unsigned char)*--s2); - return (0); -} diff --git a/libft/ft_strcpy.c b/libft/ft_strcpy.c deleted file mode 100644 index 93f2ec1..0000000 --- a/libft/ft_strcpy.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strcpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 15:10:54 by gbrochar #+# #+# */ -/* Updated: 2016/04/09 16:49:30 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strcpy(char *dst, const char *src) -{ - char *p_dest; - const char *p_src; - - p_src = src; - p_dest = dst; - while (*p_src) - { - *p_dest = *p_src; - p_dest++; - p_src++; - } - *p_dest = '\0'; - return (dst); -} diff --git a/libft/ft_strdel.c b/libft/ft_strdel.c deleted file mode 100644 index 75872b1..0000000 --- a/libft/ft_strdel.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdel.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 20:21:47 by gbrochar #+# #+# */ -/* Updated: 2015/12/08 15:21:50 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_strdel(char **as) -{ - ft_memdel((void **)as); -} diff --git a/libft/ft_strdup.c b/libft/ft_strdup.c deleted file mode 100644 index 4b12a2d..0000000 --- a/libft/ft_strdup.c +++ /dev/null @@ -1,29 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strdup.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 14:47:23 by gbrochar #+# #+# */ -/* Updated: 2016/04/09 21:27:37 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strdup(const char *s1) -{ - char *dest; - int i; - - i = 0; - dest = ft_strnew(ft_strlen(s1)); - while (s1[i]) - { - dest[i] = s1[i]; - i++; - } - dest[i] = '\0'; - return (dest); -} diff --git a/libft/ft_strequ.c b/libft/ft_strequ.c deleted file mode 100644 index 0e229a6..0000000 --- a/libft/ft_strequ.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strequ.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 08:35:37 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 15:47:45 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strequ(char const *s1, char const *s2) -{ - int i; - - i = 0; - while (s1[i] == s2[i]) - { - if (s1[i] == '\0' && s2[i] == '\0') - return (1); - i++; - } - return (0); -} diff --git a/libft/ft_striter.c b/libft/ft_striter.c deleted file mode 100644 index 4748141..0000000 --- a/libft/ft_striter.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_striter.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 20:37:55 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 10:51:54 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_striter(char *s, void (*f)(char *)) -{ - int i; - - i = 0; - while (s[i]) - { - f(&s[i]); - i++; - } -} diff --git a/libft/ft_striteri.c b/libft/ft_striteri.c deleted file mode 100644 index bb633d0..0000000 --- a/libft/ft_striteri.c +++ /dev/null @@ -1,25 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_striteri.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 21:02:16 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 10:30:40 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_striteri(char *s, void (*f)(unsigned int, char *s)) -{ - unsigned int i; - - i = 0; - while (s[i]) - { - f(i, &s[i]); - i++; - } -} diff --git a/libft/ft_strjoin.c b/libft/ft_strjoin.c deleted file mode 100644 index 6bd8cf1..0000000 --- a/libft/ft_strjoin.c +++ /dev/null @@ -1,34 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strjoin.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:48:11 by gbrochar #+# #+# */ -/* Updated: 2016/04/09 16:30:06 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strjoin(char const *s1, const char *s2) -{ - size_t i; - char *new; - - s1 = (s1 == NULL) ? "" : s1; - s2 = (s2 == NULL) ? "" : s2; - if (s1 && s2) - { - i = ft_strlen(s1) + ft_strlen(s2); - new = ft_strnew(i); - if (new) - { - new = ft_strcpy(new, s1); - new = ft_strcat(new, s2); - return (new); - } - } - return (NULL); -} diff --git a/libft/ft_strlcat.c b/libft/ft_strlcat.c deleted file mode 100644 index 9823fd5..0000000 --- a/libft/ft_strlcat.c +++ /dev/null @@ -1,32 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlcat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/26 08:00:59 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 15:48:23 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlcat(char *dst, const char *src, size_t size) -{ - size_t dst_len; - size_t src_len; - size_t i_src; - size_t i_dst; - - dst_len = ft_strlen(dst); - src_len = ft_strlen(src); - i_src = 0; - i_dst = dst_len; - if (dst_len >= size) - return (size + src_len); - while (src[i_src] && (size-- - (dst_len + 1)) > 0) - dst[i_dst++] = src[i_src++]; - dst[i_dst] = '\0'; - return (dst_len + src_len); -} diff --git a/libft/ft_strlen.c b/libft/ft_strlen.c deleted file mode 100644 index 52e4f06..0000000 --- a/libft/ft_strlen.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strlen.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 14:43:32 by gbrochar #+# #+# */ -/* Updated: 2016/04/09 16:57:01 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -size_t ft_strlen(const char *s) -{ - size_t i; - - i = 0; - while (s && s[i]) - i++; - return (i); -} diff --git a/libft/ft_strmap.c b/libft/ft_strmap.c deleted file mode 100644 index fac7843..0000000 --- a/libft/ft_strmap.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strmap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 21:30:34 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 16:53:26 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strmap(char const *s, char (*f)(char)) -{ - char *str; - int i; - int len; - - len = ft_strlen(s); - i = 0; - str = (char *)malloc((len + 1) * sizeof(char)); - if (!str) - return (NULL); - while (i < len) - { - str[i] = f(s[i]); - i++; - } - str[len] = '\0'; - return (str); -} diff --git a/libft/ft_strmapi.c b/libft/ft_strmapi.c deleted file mode 100644 index a83e346..0000000 --- a/libft/ft_strmapi.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strmapi.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 21:39:30 by gbrochar #+# #+# */ -/* Updated: 2015/12/02 16:22:05 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) -{ - char *str; - unsigned int i; - - i = 0; - str = (char *)malloc((ft_strlen(s) + 1) * sizeof(char)); - if (!str) - return (NULL); - while (s[i]) - { - str[i] = f(i, s[i]); - i++; - } - str[i] = '\0'; - return (str); -} diff --git a/libft/ft_strncat.c b/libft/ft_strncat.c deleted file mode 100644 index 9a4b9eb..0000000 --- a/libft/ft_strncat.c +++ /dev/null @@ -1,30 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncat.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 19:29:04 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 12:33:35 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strncat(char *s1, const char *s2, size_t n) -{ - size_t i_dst; - size_t i_src; - - i_dst = ft_strlen(s1); - i_src = 0; - while (i_src < n && s2[i_src] != '\0') - { - s1[i_dst] = s2[i_src]; - i_dst++; - i_src++; - } - s1[i_dst] = '\0'; - return (s1); -} diff --git a/libft/ft_strncmp.c b/libft/ft_strncmp.c deleted file mode 100644 index db3be20..0000000 --- a/libft/ft_strncmp.c +++ /dev/null @@ -1,21 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncmp.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 14:57:36 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 15:34:45 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strncmp(const char *s1, const char *s2, size_t n) -{ - while ((*s1 || *s2) && n--) - if (*s1++ != *s2++) - return ((unsigned char)*--s1 - (unsigned char)*--s2); - return (0); -} diff --git a/libft/ft_strncpy.c b/libft/ft_strncpy.c deleted file mode 100644 index 173165b..0000000 --- a/libft/ft_strncpy.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strncpy.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/25 16:18:18 by gbrochar #+# #+# */ -/* Updated: 2015/11/25 16:21:09 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strncpy(char *dst, const char *src, size_t n) -{ - size_t i; - - i = 0; - while (i != n && src[i] != '\0') - { - dst[i] = src[i]; - i++; - } - while (i != n) - { - dst[i] = '\0'; - i++; - } - return (dst); -} diff --git a/libft/ft_strnequ.c b/libft/ft_strnequ.c deleted file mode 100644 index ece7ced..0000000 --- a/libft/ft_strnequ.c +++ /dev/null @@ -1,27 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnequ.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 08:37:07 by gbrochar #+# #+# */ -/* Updated: 2015/12/05 16:24:50 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strnequ(char const *s1, char const *s2, size_t n) -{ - size_t i; - - i = 0; - while (s1[i] == s2[i] || i == n) - { - if ((s1[i] == '\0' && s2[i] == '\0') || i == n) - return (1); - i++; - } - return (0); -} diff --git a/libft/ft_strnew.c b/libft/ft_strnew.c deleted file mode 100644 index 2c8ca40..0000000 --- a/libft/ft_strnew.c +++ /dev/null @@ -1,23 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnew.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/28 18:26:56 by gbrochar #+# #+# */ -/* Updated: 2016/04/09 16:25:44 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strnew(size_t size) -{ - char *str; - - str = (char *)malloc(sizeof(char) * (size + 1)); - if (!str) - return (NULL); - return (str); -} diff --git a/libft/ft_strnstr.c b/libft/ft_strnstr.c deleted file mode 100644 index 1982911..0000000 --- a/libft/ft_strnstr.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strnstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 12:49:32 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 16:39:13 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strnstr(const char *s1, char *s2, size_t n) -{ - size_t i; - size_t i_mem; - size_t i_tofind; - - i_mem = 0; - if (s2[0] == '\0') - return ((char *)s1); - while (s1[i_mem] != '\0' && i_mem < n) - { - i_tofind = 0; - while (s1[i_mem] != s2[i_tofind] && s1[i_mem] != '\0') - i_mem++; - if (s1[i_mem] == '\0') - return (NULL); - i = i_mem; - while ((s1[i] == s2[i_tofind] || s2[i_tofind] == '\0') && i++ <= n) - if (s2[i_tofind++] == '\0') - return ((char *)&s1[i_mem]); - if (i > n) - return (NULL); - i_mem++; - } - return (NULL); -} diff --git a/libft/ft_strrchr.c b/libft/ft_strrchr.c deleted file mode 100644 index e295607..0000000 --- a/libft/ft_strrchr.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strrchr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 10:05:56 by gbrochar #+# #+# */ -/* Updated: 2015/11/27 10:24:37 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strrchr(const char *s, int c) -{ - int i; - - i = ft_strlen(s); - if (c) - { - while (i--) - if (s[i] == (char)c) - return ((char *)&s[i]); - return (NULL); - } - return ((char *)&s[i]); -} diff --git a/libft/ft_strsplit.c b/libft/ft_strsplit.c deleted file mode 100644 index 153201e..0000000 --- a/libft/ft_strsplit.c +++ /dev/null @@ -1,85 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strsplit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:55:10 by gbrochar #+# #+# */ -/* Updated: 2020/12/17 20:09:12 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -static int ft_wordcount(char const *s, char c) -{ - int word_count; - int i; - - i = 0; - word_count = 0; - while (s[i] != '\0') - { - while (s[i] == c) - i++; - if (s[i] != '\0') - word_count++; - while (s[i] != c && s[i] != '\0') - i++; - } - return (word_count); -} - -static void *ft_taballoc(char const *s, char **str_tab, char c) -{ - int i; - int wl; - - i = 0; - while (s[i]) - { - wl = 0; - while (s[i] == c && s[i] != '\0') - i++; - while (s[i] != c && s[i] != '\0') - { - wl++; - i++; - } - if (wl != 0) - *str_tab++ = (char *)malloc((wl + 1) * sizeof(char)); - if (!(str_tab - 1)) - return (NULL); - } - return (*str_tab); -} - -char **ft_strsplit(char const *s, char c) -{ - char **str_tab; - int i; - int i2; - int i3; - int wc; - - i = 0; - i3 = 0; - wc = ft_wordcount(s, c); - str_tab = (char **)malloc((wc + 1) * sizeof(char *)); - if (!str_tab) - return (NULL); - ft_taballoc(s, str_tab, c); - while (i != wc) - { - i2 = 0; - while (s[i3] == c && s[i3] != '\0') - i3++; - while (s[i3] != c && s[i3] != '\0') - str_tab[i][i2++] = s[i3++]; - str_tab[i][i2] = '\0'; - i++; - } - str_tab[i] = NULL; - return (str_tab); -} diff --git a/libft/ft_strstr.c b/libft/ft_strstr.c deleted file mode 100644 index 5f985f0..0000000 --- a/libft/ft_strstr.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strstr.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 10:24:53 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 16:38:40 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strstr(const char *s1, char *s2) -{ - int i; - int i_mem; - int i_tofind; - - i_mem = 0; - if (s2[0] == '\0') - return ((char *)s1); - while (s1[i_mem] != '\0') - { - i_tofind = 0; - while (s1[i_mem] != s2[i_tofind] && s1[i_mem] != '\0') - i_mem++; - if (s1[i_mem] == '\0') - return (NULL); - i = i_mem; - while (s1[i++] == s2[i_tofind] || s2[i_tofind] == '\0') - if (s2[i_tofind++] == '\0') - return ((char *)&s1[i_mem]); - i_mem++; - } - return (NULL); -} diff --git a/libft/ft_strsub.c b/libft/ft_strsub.c deleted file mode 100644 index 4434689..0000000 --- a/libft/ft_strsub.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strsub.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:14:36 by gbrochar #+# #+# */ -/* Updated: 2015/12/08 15:34:26 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strsub(char const *s, unsigned int start, size_t len) -{ - char *str; - size_t i; - - i = 0; - str = (char *)malloc((len + 1) * sizeof(char)); - if (!str) - return (NULL); - while (i < len) - str[i++] = s[start++]; - str[i] = '\0'; - return (str); -} diff --git a/libft/ft_strtab_isdigit.c b/libft/ft_strtab_isdigit.c deleted file mode 100644 index 4bca658..0000000 --- a/libft/ft_strtab_isdigit.c +++ /dev/null @@ -1,33 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtab_isdigit.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/05/31 08:48:47 by gbrochar #+# #+# */ -/* Updated: 2016/05/31 08:50:05 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_strtab_isdigit(char **strtab) -{ - int i; - int j; - - i = 0; - while (strtab[i]) - { - j = 0; - while (strtab[i][j]) - { - if (strtab[i][j] != ' ' && ft_isdigit(strtab[i][j] == 0)) - return (0); - j++; - } - i++; - } - return (1); -} diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c deleted file mode 100644 index c3480c6..0000000 --- a/libft/ft_strtrim.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_strtrim.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/29 09:54:12 by gbrochar #+# #+# */ -/* Updated: 2015/12/07 11:00:33 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -char *ft_strtrim(char const *s) -{ - char *str; - size_t i; - size_t i2; - size_t ws; - - i = ft_strlen(s) - 1; - i2 = 0; - ws = 0; - while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t') && i--) - ws++; - i = 0; - while ((s[i] == ' ' || s[i] == '\n' || s[i] == '\t') && ws < ft_strlen(s)) - { - i++; - ws++; - } - str = (char *)malloc((ft_strlen(s) + 1 - ws) * sizeof(char)); - if (!str) - return (NULL); - while (i2 < (ft_strlen(s) - ws)) - str[i2++] = s[i++]; - str[i2] = '\0'; - return (str); -} diff --git a/libft/ft_swap.c b/libft/ft_swap.c deleted file mode 100644 index 5a99a20..0000000 --- a/libft/ft_swap.c +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_swap.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/12/07 09:44:07 by gbrochar #+# #+# */ -/* Updated: 2015/12/07 11:01:13 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -void ft_swap(int *a, int *b) -{ - int c; - - c = *a; - *a = *b; - *b = c; -} diff --git a/libft/ft_tolower.c b/libft/ft_tolower.c deleted file mode 100644 index 22b7a20..0000000 --- a/libft/ft_tolower.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_tolower.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:39:55 by gbrochar #+# #+# */ -/* Updated: 2015/11/29 08:40:07 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_tolower(int c) -{ - if ((int)c >= 'A' && (int)c <= 'Z') - c += 32; - return (c); -} diff --git a/libft/ft_toupper.c b/libft/ft_toupper.c deleted file mode 100644 index f0f24ec..0000000 --- a/libft/ft_toupper.c +++ /dev/null @@ -1,20 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_toupper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/27 18:43:24 by gbrochar #+# #+# */ -/* Updated: 2015/11/28 16:01:01 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "libft.h" - -int ft_toupper(int c) -{ - if ((int)c >= 'a' && (int)c <= 'z') - c -= 32; - return (c); -} diff --git a/libft/get_next_line.c b/libft/get_next_line.c deleted file mode 100644 index 4706e86..0000000 --- a/libft/get_next_line.c +++ /dev/null @@ -1,93 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/03/22 00:00:51 by gbrochar #+# #+# */ -/* Updated: 2019/02/22 10:11:53 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "get_next_line.h" - -char *ft_strjoin2(char *str, char *str2) -{ - char *tmp; - - tmp = ft_strjoin(str, str2); - free(str); - return (tmp); -} - -int gnl_manage_return(char **line, char **stock) -{ - char *tmp; - char *tmp2; - - if ((tmp = ft_strchr(*stock, '\n'))) - { - *tmp = '\0'; - tmp2 = ft_strdup(tmp + 1); - *line = ft_strdup(*stock); - ft_memdel((void **)stock); - *stock = ft_strdup(tmp2); - free(tmp2); - tmp2 = NULL; - tmp = NULL; - return (1); - } - if (ft_strlen(*stock) == 0) - { - ft_memdel((void **)stock); - return (0); - } - *line = ft_strdup(*stock); - ft_memdel((void **)stock); - return (1); -} - -int gnl_manage_read(char **line, char **stock) -{ - char *tmp; - char *tmp2; - - if ((tmp = ft_strchr(*stock, '\n'))) - { - *tmp = '\0'; - tmp2 = ft_strdup(tmp + 1); - *line = ft_strdup(*stock); - ft_memdel((void **)stock); - *stock = ft_strdup(tmp2); - free(tmp2); - tmp2 = NULL; - tmp = NULL; - return (1); - } - return (0); -} - -int get_next_line(int fd, char **line, int error) -{ - static char *stock = NULL; - char buffer[BUFF_SIZE + 1]; - int ret; - - if (stock && error) - ft_memdel((void **)&stock); - if (error) - return (-1); - buffer[0] = '\0'; - if (stock) - if (gnl_manage_read(line, &stock)) - return (1); - while ((ret = read(fd, buffer, BUFF_SIZE)) > 0) - { - buffer[ret] = '\0'; - stock = ft_strjoin2(stock, buffer); - if (gnl_manage_read(line, &stock)) - return (1); - } - return (ret < 0 ? ret : gnl_manage_return(line, &stock)); -} diff --git a/libft/get_next_line.h b/libft/get_next_line.h deleted file mode 100644 index 1da072b..0000000 --- a/libft/get_next_line.h +++ /dev/null @@ -1,22 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* get_next_line.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2016/02/28 22:19:58 by gbrochar #+# #+# */ -/* Updated: 2019/02/22 10:03:10 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef GET_NEXT_LINE_H -# define GET_NEXT_LINE_H - -# include "libft.h" - -# define BUFF_SIZE 512 - -int get_next_line(int const fd, char **line, int error); - -#endif diff --git a/libft/libft.h b/libft/libft.h deleted file mode 100644 index 7518939..0000000 --- a/libft/libft.h +++ /dev/null @@ -1,103 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* libft.h :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: gbrochar +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2015/11/24 12:52:28 by gbrochar #+# #+# */ -/* Updated: 2019/02/22 14:24:19 by gbrochar ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#ifndef LIBFT_H -# define LIBFT_H - -# include -# include -# include -# include -# include "get_next_line.h" -# include - -typedef struct s_list -{ - void *content; - size_t content_size; - struct s_list *next; -} t_list; - -t_list *ft_get_last_node(t_list **alst); -void ft_lstadd(t_list **alst, t_list *new); -void ft_lstadd_preview(t_list **alst, t_list *new); -void ft_lstdel(t_list **alst, void (*del)(void *, size_t)); -void ft_lstdelone(t_list **alst, void (*del)(void *, size_t)); -t_list *ft_lstnew(void const *content, size_t content_size); -void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); -t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); -int ft_atoi(const char *str); -double ft_atof(const char *str); -int ft_atoi_color(char *hexa_color); -int ft_atoi_len(char *str, int *len); -int *ft_atoi_split(char *str, char c, int *tab_len); -void ft_bzero(void *s, size_t n); -int ft_isalnum(int c); -int ft_isalpha(int c); -int ft_isascii(int c); -int ft_isdigit(int c); -int ft_strtab_isdigit(char **strtab); -int ft_isprint(int c); -int ft_isspace(int c); -char *ft_itoa(int n); -void *ft_memalloc(size_t size); -void *ft_memccpy(void *dst, const void *src, int c, size_t n); -void *ft_memchr(const void *s, int c, size_t n); -int ft_memcmp(const void *s1, const void *s2, size_t n); -void *ft_memcpy(void *dst, const void *src, size_t n); -void ft_memdel(void **ap); -void *ft_memmove(void *dst, const void *src, size_t len); -void *ft_memset(void *b, int c, size_t len); -int ft_power(int nb, int pow); -void ft_putchar(char c); -void ft_putchar_fd(char c, int fd); -void ft_putendl(char const *s); -void ft_putendl_fd(char const *s, int fd); -void ft_putnbr(int n); -void ft_putnbr_fd(int n, int fd); -void ft_putstr(char const *s); -void ft_putstr_fd(char const *s, int fd); -void ft_sort_int(int *tab, int size); -long ft_sqrt(long n); -char *ft_strcat(char *s1, const char *s2); -char *ft_strchr(const char *s, int c); -void ft_strclr(char *s); -int ft_strcmp(const char *s1, const char *s2); -char *ft_strcpy(char *dst, const char *src); -void ft_strdel(char **as); -char *ft_strdup(const char *s1); -int ft_strequ(char const *s1, char const *s2); -void ft_striter(char *s, void (*f)(char *)); -void ft_striteri(char *s, void (*f)(unsigned int, char *s)); -char *ft_strjoin(char const *s1, char const *s2); -size_t ft_strlcat(char *dst, const char *src, size_t size); -size_t ft_strlen(const char *s); -char *ft_strmap(char const *s, char (*f)(char)); -char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); -char *ft_strncat(char *s1, const char *s2, size_t n); -int ft_strncmp(const char *s1, const char *s2, size_t n); -char *ft_strncpy(char *dst, const char *src, size_t n); -int ft_strnequ(char const *s1, char const *s2, size_t n); -char *ft_strnew(size_t size); -char *ft_strnstr(const char *s1, char *s2, size_t n); -char *ft_strrchr(const char *s, int c); -char **ft_strsplit(char const *s, char c); -char *ft_strstr(const char *s1, char *s2); -char *ft_strsub(char const *s, unsigned int start, size_t len); -char *ft_strtrim(char const *s); -void ft_swap(int *a, int *b); -int ft_tolower(int c); -int ft_toupper(int c); -int ft_ishexdigit(int c); -void ft_error(char *str); - -#endif diff --git a/resources/mlx_README b/resources/mlx_README deleted file mode 100644 index 1424a28..0000000 --- a/resources/mlx_README +++ /dev/null @@ -1,11 +0,0 @@ - - - Pour utiliser la minilibX MACOS (only !) en mode OpenGL, - copiez donc les sources de la mlx ici, avec mlx_opengl.m . - Rajoutez mlx_opengl.m dans le Makefile et compilez le tout. - - Utilisation: - dans votre code, utilisez classiquement mlx.h, et ajoutez - a la suite mlx_opengl.h pour utiliser les fonctions specifiques. - - Lisez les commentaires de mlx_opengl.h . diff --git a/resources/mlx_opengl.h b/resources/mlx_opengl.h deleted file mode 100644 index bb39267..0000000 --- a/resources/mlx_opengl.h +++ /dev/null @@ -1,21 +0,0 @@ -/* -** -** mlx_opengl.h -** -** public include, use it after mlx.h -** designed only for minilibx_macos -** -*/ - -void *mlx_new_opengl_window(void *mlx_ptr, int size_x, int size_y, char *title); - -/* create an opengl window. put_image & pixel_put & string_put do not work there. */ - -int mlx_opengl_swap_buffers(void *win_ptr); - -/* the created window is double buffered. Use this funct to swap buffers */ -/* this funct will call glFlush(). Don't call it. */ - -int mlx_opengl_window_set_context(void *win_ptr); - -/* in case multiple opengl windows are present, change opengl active context */ diff --git a/resources/mlx_opengl.m b/resources/mlx_opengl.m deleted file mode 100644 index 554d79b..0000000 --- a/resources/mlx_opengl.m +++ /dev/null @@ -1,57 +0,0 @@ -// mlx_opengl.m - -#import -#import -#import - -#include - -#include "mlx_int.h" -#include "mlx_new_window.h" - - - - - -NSOpenGLPixelFormatAttribute pfa_attrs_opengl[] = - { - NSOpenGLPFADepthSize, 32, - NSOpenGLPFADoubleBuffer, - NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion4_1Core, - 0 - }; - - - -void *mlx_new_opengl_window(mlx_ptr_t *mlx_ptr, int size_x, int size_y, char *title) -{ - mlx_win_list_t *newwin; - NSString *str; - - if ((newwin = malloc(sizeof(*newwin))) == NULL) - return ((void *)0); - newwin->img_list = NULL; - newwin->next = mlx_ptr->win_list; - newwin->nb_flush = 0; - newwin->pixmgt = 0; - mlx_ptr->win_list = newwin; - - NSRect windowRect = NSMakeRect(100, 100, size_x, size_y); - str = [NSString stringWithCString:title encoding:NSASCIIStringEncoding]; - newwin->winid = [[MlxWin alloc] initWithRect:windowRect andTitle:str pfaAttrs:pfa_attrs_opengl]; - - return ((void *)newwin); -} - - -int mlx_opengl_swap_buffers(mlx_win_list_t *win_ptr) -{ - [(id)(win_ptr->winid) flushGLContext]; - return (0); -} - -int mlx_opengl_window_set_context(mlx_win_list_t *win_ptr) -{ - [(id)(win_ptr->winid) selectGLContext]; - return (0); -} diff --git a/src/env.c b/src/env.c new file mode 100644 index 0000000..2e99296 --- /dev/null +++ b/src/env.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* env.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbrochar +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/12/22 18:56:21 by gbrochar #+# #+# */ +/* Updated: 2020/12/22 19:07:24 by gbrochar ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "scop.h" + +void free_env(t_env *e) +{ + free(e->file_name); + free(e->object.vertices.data); + free(e->object.uvs.data); + free(e->object.normals.data); + free(e->object.indices.data); +} + +void init_window(t_env *e) +{ + e->window.width = 640; + e->window.height = 480; +} + +void init_camera(t_env *e) +{ + e->camera.fov = 45; + e->camera.near = 0.001; + e->camera.far = 1000; + e->camera.aspect = 1; +} + +void init_object(t_env *e) +{ + e->object.vertices.data = (double *)malloc(sizeof(double) * 4096); + e->object.uvs.data = (double *)malloc(sizeof(double) * 4096); + e->object.normals.data = (double *)malloc(sizeof(double) * 4096); + e->object.indices.data = (short *)malloc(sizeof(short) * 4096); + e->object.vertices_ptr = 0; + e->object.uvs_ptr = 0; + e->object.normals_ptr = 0; + e->object.indices_ptr = 0; +} + +void init_env(t_env *e) +{ + init_window(e); + init_camera(e); + init_object(e); +} diff --git a/src/main.c b/src/main.c index 313d73c..0a3fde6 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,31 @@ -int main(int argc, char **argv) { - (void)argc; - (void)argv; - return (0); -} \ No newline at end of file +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbrochar +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/12/22 12:02:14 by gbrochar #+# #+# */ +/* Updated: 2020/12/22 19:14:00 by gbrochar ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "scop.h" + +int main(int argc, char **argv) +{ + t_env e; + + init_env(&e); + if (parse(&e, argc, argv) == SUCCESS) + { + } + else + { + free_env(&e); + printf("file reading error\n"); + return (FAILURE); + } + free_env(&e); + return (SUCCESS); +} diff --git a/src/parse_file.c b/src/parse_file.c new file mode 100644 index 0000000..9a88ae9 --- /dev/null +++ b/src/parse_file.c @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_file.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbrochar +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/12/22 12:38:27 by gbrochar #+# #+# */ +/* Updated: 2020/12/22 18:59:30 by gbrochar ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "scop.h" + +int parse_file(t_env *e) +{ + FILE *fp; + char *buffer; + + fp = fopen(e->file_name, "r"); + if (!fp) + return (FAILURE); + buffer = (char *)malloc(sizeof(char) * 4096); + while (fgets(buffer, 4096, fp)) + { + if (parse_line(e, buffer) == FAILURE) + return (FAILURE); + } + free(buffer); + fclose(fp); + return (SUCCESS); +} + +void set_params(t_env *e, int argc, char **argv) +{ + if (argc >= 2) + e->file_name = strdup(argv[1]); + else + e->file_name = strdup("resources/42.obj"); + if (argc >= 3) + e->window.width = atof(argv[2]); + if (argc >= 4) + e->window.height = atof(argv[3]); + if (argc >= 5) + e->camera.fov = atof(argv[4]); + e->camera.aspect = (double)e->window.width / (double)e->window.height; +} + +int parse(t_env *e, int argc, char **argv) +{ + set_params(e, argc, argv); + return (parse_file(e)); +} diff --git a/src/parse_line.c b/src/parse_line.c new file mode 100644 index 0000000..efd6a01 --- /dev/null +++ b/src/parse_line.c @@ -0,0 +1,82 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* parse_line.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbrochar +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/12/22 18:41:28 by gbrochar #+# #+# */ +/* Updated: 2020/12/22 19:13:07 by gbrochar ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "scop.h" + +int parse_append_data_d(t_buf_d *buffer, char *token) +{ + (void)buffer; + (void)token; + return (SUCCESS); +} + +int parse_append_data_s(t_buf_s *buffer, char *token) +{ + (void)buffer; + (void)token; + return (SUCCESS); +} + +t_gl_buf_type parse_gl_buf_type(char *token) +{ + if (strstr(token, "v")) + return (VERTEX); + if (strstr(token, "vt")) + return (UV); + if (strstr(token, "vn")) + return (NORMAL); + if (strstr(token, "f")) + return (INDEX); + return (OTHER); +} + +int parse_token( + t_env *e, + char *token, + t_gl_buf_type gl_buf_type) +{ + int ret; + + if (gl_buf_type == OTHER) + ret = BREAK; + if (gl_buf_type == VERTEX) + ret = parse_append_data_d(&(e->object.vertices), token); + if (gl_buf_type == UV) + ret = parse_append_data_d(&(e->object.uvs), token); + if (gl_buf_type == NORMAL) + ret = parse_append_data_d(&(e->object.normals), token); + if (gl_buf_type == INDEX) + ret = parse_append_data_s(&(e->object.indices), token); + return (ret); +} + +int parse_line(t_env *e, char *line) +{ + char *token; + t_gl_buf_type gl_buf_type; + int token_count; + int ret; + + token_count = 0; + ret = SUCCESS; + while ((token = strtok_r(line, " ", &line))) + { + if (token_count == 0) + gl_buf_type = parse_gl_buf_type(token); + else + ret = parse_token(e, token, gl_buf_type); + if (ret == FAILURE) + return (FAILURE); + token_count++; + } + return (SUCCESS); +}