From 4a51ad74f8398d1608a7fc991f57a55c94510bbe Mon Sep 17 00:00:00 2001 From: Iipal Date: Wed, 6 Feb 2019 15:09:42 +0200 Subject: [PATCH] init wolf3d_mlx --- .gitignore | 7 ++++ Makefile | 66 +++++++++++++++++++++++++++++ author | 1 + includes/linux_keys.h | 46 ++++++++++++++++++++ includes/macos_keys.h | 46 ++++++++++++++++++++ includes/wolf3d.h | 77 ++++++++++++++++++++++++++++++++++ includes/wolf3d_defines.h | 75 +++++++++++++++++++++++++++++++++ includes/wolf3d_errno.h | 24 +++++++++++ libft/Makefile | 65 ++++++++++++++++++++++++++++ libft/includes/lft_ctype.h | 27 ++++++++++++ libft/includes/lft_lst.h | 32 ++++++++++++++ libft/includes/lft_mem.h | 35 ++++++++++++++++ libft/includes/lft_put.h | 27 ++++++++++++ libft/includes/lft_str.h | 68 ++++++++++++++++++++++++++++++ libft/includes/libft.h | 26 ++++++++++++ libft/srcs/ctype/ft_isalnum.c | 18 ++++++++ libft/srcs/ctype/ft_isalpha.c | 18 ++++++++ libft/srcs/ctype/ft_isascii.c | 18 ++++++++ libft/srcs/ctype/ft_isblank.c | 18 ++++++++ libft/srcs/ctype/ft_isdigit.c | 18 ++++++++ libft/srcs/ctype/ft_islower.c | 18 ++++++++ libft/srcs/ctype/ft_isprint.c | 18 ++++++++ libft/srcs/ctype/ft_isupper.c | 18 ++++++++ libft/srcs/ctype/ft_tolower.c | 18 ++++++++ libft/srcs/ctype/ft_toupper.c | 18 ++++++++ libft/srcs/lft/ft_gnl.c | 70 +++++++++++++++++++++++++++++++ libft/srcs/lst/ft_lstadd.c | 22 ++++++++++ libft/srcs/lst/ft_lstdel.c | 31 ++++++++++++++ libft/srcs/lst/ft_lstdelone.c | 23 ++++++++++ libft/srcs/lst/ft_lstiter.c | 22 ++++++++++ libft/srcs/lst/ft_lstmap.c | 35 ++++++++++++++++ libft/srcs/lst/ft_lstnew.c | 36 ++++++++++++++++ libft/srcs/mem/ft_bzero.c | 18 ++++++++ libft/srcs/mem/ft_memalloc.c | 27 ++++++++++++ libft/srcs/mem/ft_memccpy.c | 37 ++++++++++++++++ libft/srcs/mem/ft_memchr.c | 32 ++++++++++++++ libft/srcs/mem/ft_memcmp.c | 36 ++++++++++++++++ libft/srcs/mem/ft_memcpy.c | 31 ++++++++++++++ libft/srcs/mem/ft_memdel.c | 22 ++++++++++ libft/srcs/mem/ft_memmove.c | 32 ++++++++++++++ libft/srcs/mem/ft_memset.c | 24 +++++++++++ libft/srcs/put/ft_putchar.c | 18 ++++++++ libft/srcs/put/ft_putchar_fd.c | 18 ++++++++ libft/srcs/put/ft_putendl.c | 22 ++++++++++ libft/srcs/put/ft_putendl_fd.c | 22 ++++++++++ libft/srcs/put/ft_putnbr.c | 36 ++++++++++++++++ libft/srcs/put/ft_putnbr_fd.c | 36 ++++++++++++++++ libft/srcs/put/ft_putstr.c | 24 +++++++++++ libft/srcs/put/ft_putstr_fd.c | 24 +++++++++++ libft/srcs/str/ft_atoi.c | 30 +++++++++++++ libft/srcs/str/ft_atoi_base.c | 60 ++++++++++++++++++++++++++ libft/srcs/str/ft_atol.c | 30 +++++++++++++ libft/srcs/str/ft_count_if.c | 28 +++++++++++++ libft/srcs/str/ft_itoa.c | 51 ++++++++++++++++++++++ libft/srcs/str/ft_ltoa.c | 51 ++++++++++++++++++++++ libft/srcs/str/ft_strcat.c | 29 +++++++++++++ libft/srcs/str/ft_strchr.c | 21 ++++++++++ libft/srcs/str/ft_strclr.c | 19 +++++++++ libft/srcs/str/ft_strcmp.c | 24 +++++++++++ libft/srcs/str/ft_strcpy.c | 24 +++++++++++ libft/srcs/str/ft_strdel.c | 22 ++++++++++ libft/srcs/str/ft_strdup.c | 30 +++++++++++++ libft/srcs/str/ft_strequ.c | 20 +++++++++ libft/srcs/str/ft_striter.c | 25 +++++++++++ libft/srcs/str/ft_striteri.c | 25 +++++++++++ libft/srcs/str/ft_strjoin.c | 32 ++++++++++++++ libft/srcs/str/ft_strlcat.c | 44 +++++++++++++++++++ libft/srcs/str/ft_strlcpy.c | 31 ++++++++++++++ libft/srcs/str/ft_strlen.c | 23 ++++++++++ libft/srcs/str/ft_strmap.c | 32 ++++++++++++++ libft/srcs/str/ft_strmapi.c | 32 ++++++++++++++ libft/srcs/str/ft_strncat.c | 29 +++++++++++++ libft/srcs/str/ft_strncmp.c | 30 +++++++++++++ libft/srcs/str/ft_strncpy.c | 26 ++++++++++++ libft/srcs/str/ft_strndup.c | 26 ++++++++++++ libft/srcs/str/ft_strnequ.c | 21 ++++++++++ libft/srcs/str/ft_strnew.c | 25 +++++++++++ libft/srcs/str/ft_strnstr.c | 31 ++++++++++++++ libft/srcs/str/ft_strrchr.c | 25 +++++++++++ libft/srcs/str/ft_strsplit.c | 70 +++++++++++++++++++++++++++++++ libft/srcs/str/ft_strstr.c | 38 +++++++++++++++++ libft/srcs/str/ft_strsub.c | 41 ++++++++++++++++++ libft/srcs/str/ft_strtrim.c | 35 ++++++++++++++++ maps/map01.w3d | 6 +++ srcs/main.c | 30 +++++++++++++ srcs/wolf_free.c | 22 ++++++++++ srcs/wolf_init.c | 29 +++++++++++++ srcs/wolf_key_hooks.c | 28 +++++++++++++ 88 files changed, 2695 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 author create mode 100644 includes/linux_keys.h create mode 100644 includes/macos_keys.h create mode 100644 includes/wolf3d.h create mode 100644 includes/wolf3d_defines.h create mode 100644 includes/wolf3d_errno.h create mode 100644 libft/Makefile create mode 100644 libft/includes/lft_ctype.h create mode 100644 libft/includes/lft_lst.h create mode 100644 libft/includes/lft_mem.h create mode 100644 libft/includes/lft_put.h create mode 100644 libft/includes/lft_str.h create mode 100644 libft/includes/libft.h create mode 100644 libft/srcs/ctype/ft_isalnum.c create mode 100644 libft/srcs/ctype/ft_isalpha.c create mode 100644 libft/srcs/ctype/ft_isascii.c create mode 100644 libft/srcs/ctype/ft_isblank.c create mode 100644 libft/srcs/ctype/ft_isdigit.c create mode 100644 libft/srcs/ctype/ft_islower.c create mode 100644 libft/srcs/ctype/ft_isprint.c create mode 100644 libft/srcs/ctype/ft_isupper.c create mode 100644 libft/srcs/ctype/ft_tolower.c create mode 100644 libft/srcs/ctype/ft_toupper.c create mode 100644 libft/srcs/lft/ft_gnl.c create mode 100644 libft/srcs/lst/ft_lstadd.c create mode 100644 libft/srcs/lst/ft_lstdel.c create mode 100644 libft/srcs/lst/ft_lstdelone.c create mode 100644 libft/srcs/lst/ft_lstiter.c create mode 100644 libft/srcs/lst/ft_lstmap.c create mode 100644 libft/srcs/lst/ft_lstnew.c create mode 100644 libft/srcs/mem/ft_bzero.c create mode 100644 libft/srcs/mem/ft_memalloc.c create mode 100644 libft/srcs/mem/ft_memccpy.c create mode 100644 libft/srcs/mem/ft_memchr.c create mode 100644 libft/srcs/mem/ft_memcmp.c create mode 100644 libft/srcs/mem/ft_memcpy.c create mode 100644 libft/srcs/mem/ft_memdel.c create mode 100644 libft/srcs/mem/ft_memmove.c create mode 100644 libft/srcs/mem/ft_memset.c create mode 100644 libft/srcs/put/ft_putchar.c create mode 100644 libft/srcs/put/ft_putchar_fd.c create mode 100644 libft/srcs/put/ft_putendl.c create mode 100644 libft/srcs/put/ft_putendl_fd.c create mode 100644 libft/srcs/put/ft_putnbr.c create mode 100644 libft/srcs/put/ft_putnbr_fd.c create mode 100644 libft/srcs/put/ft_putstr.c create mode 100644 libft/srcs/put/ft_putstr_fd.c create mode 100644 libft/srcs/str/ft_atoi.c create mode 100644 libft/srcs/str/ft_atoi_base.c create mode 100644 libft/srcs/str/ft_atol.c create mode 100644 libft/srcs/str/ft_count_if.c create mode 100644 libft/srcs/str/ft_itoa.c create mode 100644 libft/srcs/str/ft_ltoa.c create mode 100644 libft/srcs/str/ft_strcat.c create mode 100644 libft/srcs/str/ft_strchr.c create mode 100644 libft/srcs/str/ft_strclr.c create mode 100644 libft/srcs/str/ft_strcmp.c create mode 100644 libft/srcs/str/ft_strcpy.c create mode 100644 libft/srcs/str/ft_strdel.c create mode 100644 libft/srcs/str/ft_strdup.c create mode 100644 libft/srcs/str/ft_strequ.c create mode 100644 libft/srcs/str/ft_striter.c create mode 100644 libft/srcs/str/ft_striteri.c create mode 100644 libft/srcs/str/ft_strjoin.c create mode 100644 libft/srcs/str/ft_strlcat.c create mode 100644 libft/srcs/str/ft_strlcpy.c create mode 100644 libft/srcs/str/ft_strlen.c create mode 100644 libft/srcs/str/ft_strmap.c create mode 100644 libft/srcs/str/ft_strmapi.c create mode 100644 libft/srcs/str/ft_strncat.c create mode 100644 libft/srcs/str/ft_strncmp.c create mode 100644 libft/srcs/str/ft_strncpy.c create mode 100644 libft/srcs/str/ft_strndup.c create mode 100644 libft/srcs/str/ft_strnequ.c create mode 100644 libft/srcs/str/ft_strnew.c create mode 100644 libft/srcs/str/ft_strnstr.c create mode 100644 libft/srcs/str/ft_strrchr.c create mode 100644 libft/srcs/str/ft_strsplit.c create mode 100644 libft/srcs/str/ft_strstr.c create mode 100644 libft/srcs/str/ft_strsub.c create mode 100644 libft/srcs/str/ft_strtrim.c create mode 100644 maps/map01.w3d create mode 100644 srcs/main.c create mode 100644 srcs/wolf_free.c create mode 100644 srcs/wolf_init.c create mode 100644 srcs/wolf_key_hooks.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebc6588 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +#ignore object files in source folders +srcs/*.o +libft/srcs/*/*.o +libft/libft.a +wolf3d +**.DS_Store +.VScode \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a8e62fb --- /dev/null +++ b/Makefile @@ -0,0 +1,66 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tmaluh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2019/02/06 14:43:13 by tmaluh #+# #+# # +# Updated: 2019/02/06 15:02:38 by tmaluh ### ########.fr # +# # +# **************************************************************************** # + +NAME = wolf3d + +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) + MLXFLAGS := -L /usr/local/lib -I /usr/local/lib -lmlx -lXext -lX11 -lm +endif +ifeq ($(UNAME_S),Darwin) + MLXFLAGS := -L /usr/local/lib -lmlx -lm -framework OpenGL -framework AppKit +endif + +CC = gcc -march=native +CFLAGS = -Wall -Wextra -Werror -Ofast + +SRC = srcs/main.c srcs/wolf_init.c srcs/wolf_key_hooks.c srcs/wolf_free.c + +OBJ = $(SRC:.c=.o) + +LIBFT = libft/libft.a +LMAKE = make -C libft + +WHITE=\033[0m +GREEN=\033[32m +RED=\033[31m + +DEL = rm -rf + +all: $(NAME) + +$(OBJ): %.o: %.c + @echo -n '+' + @$(CC) -c $(CFLAGS) $< -o $@ + +$(LIBFT): + @$(LMAKE) + +$(NAME): $(LIBFT) $(OBJ) + @$(CC) $(OBJ) $(MLXFLAGS) $(LIBFT) -o $(NAME) + @echo "> $(NAME) $(GREEN)Compiled$(WHITE)" + +del: + @$(DEL) $(OBJ) + +clean: + @$(DEL) $(OBJ) + @$(LMAKE) clean + +fclean: clean + @$(LMAKE) fclean + @$(DEL) $(NAME) + @echo "$(RED)deleted$(WHITE): ./wolf3d" + +re: fclean all + +.PHONY: all fclean clean re diff --git a/author b/author new file mode 100644 index 0000000..8d37e05 --- /dev/null +++ b/author @@ -0,0 +1 @@ +tmaluh diff --git a/includes/linux_keys.h b/includes/linux_keys.h new file mode 100644 index 0000000..891267f --- /dev/null +++ b/includes/linux_keys.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* linux_keys.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/12/14 12:46:50 by tmaluh #+# #+# */ +/* Updated: 2019/01/17 17:15:41 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LINUX_KEYS_H +# define LINUX_KEYS_H + +# define KEY_PRESSED 2 +# define KEY_RELEASE 3 + +# define ESC 65307 + +# define KEY_C 99 + +# define KEY_W 119 +# define KEY_A 97 +# define KEY_S 115 +# define KEY_D 100 + +# define KEY_T 116 +# define KEY_G 103 +# define KEY_Y 121 +# define KEY_H 104 + +# define KEY_I 105 +# define KEY_P 112 + +# define ARROW_UP 65362 +# define ARROW_DOWN 65364 +# define ARROW_RIGHT 65363 +# define ARROW_LEFT 65361 + +# define PLUS_NUMPAD 65451 +# define PLUS_KEYBOARD 61 +# define MINUS_NUMPAD 65453 +# define MINUS_KEYBOARD 45 + +#endif diff --git a/includes/macos_keys.h b/includes/macos_keys.h new file mode 100644 index 0000000..548d2bd --- /dev/null +++ b/includes/macos_keys.h @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* macos_keys.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/12/14 12:46:42 by tmaluh #+# #+# */ +/* Updated: 2019/01/17 17:15:45 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef MACOS_KEYS_H +# define MACOS_KEYS_H + +# define KEY_PRESSED 2 +# define KEY_RELEASE 2 + +# define ESC 53 + +# define KEY_C 8 + +# define KEY_W 13 +# define KEY_A 0 +# define KEY_S 1 +# define KEY_D 2 + +# define KEY_T 17 +# define KEY_G 5 +# define KEY_Y 16 +# define KEY_H 4 + +# define KEY_I 34 +# define KEY_P 35 + +# define ARROW_UP 126 +# define ARROW_DOWN 125 +# define ARROW_RIGHT 124 +# define ARROW_LEFT 123 + +# define PLUS_NUMPAD 69 +# define PLUS_KEYBOARD 24 +# define MINUS_NUMPAD 78 +# define MINUS_KEYBOARD 27 + +#endif diff --git a/includes/wolf3d.h b/includes/wolf3d.h new file mode 100644 index 0000000..594cb46 --- /dev/null +++ b/includes/wolf3d.h @@ -0,0 +1,77 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* wolf3d.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/06 14:30:10 by tmaluh #+# #+# */ +/* Updated: 2019/02/06 15:09:09 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef WOLF3D_H +# define WOLF3D_H + +# ifdef __APPLE__ +# include "macos_keys.h" +# endif + +# ifdef __linux__ +# include "linux_keys.h" +# endif + +# include "wolf3d_defines.h" +# include "wolf3d_errno.h" +# include "../libft/includes/libft.h" +# include +# include +# include +# include + +enum e_bool {false, true} __attribute__((packed)); + +typedef struct s_point +{ + short y; + short x; +} t_p; + +typedef struct s_fpoint +{ + float y; + float x; +} t_fp; + +_FPOINT; +_POINT; +_BOOL; +_IARR; + +typedef struct s_isrender +{ + bool is_render; +} t_isr; + +typedef struct s_mlx +{ + pvoid mlx; + pvoid win; + pvoid img; + iarr screen; +} t_mlx; + +typedef struct s_fdf_environment +{ + t_mlx *mlx; + t_isr *isr; +} t_env; + +bool wolf_init(t_env *env); + +int wolf_key_hooks(int key, t_env *env); +int wolf_killwindow_hook(t_env *env); + +void wolf_free(t_env *env); + +#endif diff --git a/includes/wolf3d_defines.h b/includes/wolf3d_defines.h new file mode 100644 index 0000000..cef8ca4 --- /dev/null +++ b/includes/wolf3d_defines.h @@ -0,0 +1,75 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* wolf3d_defines.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/06 14:34:31 by tmaluh #+# #+# */ +/* Updated: 2019/02/06 15:09:33 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef WOLF3D_DEFINES_H +# define WOLF3D_DEFINES_H + +# define WIN_X 2000 +# define WIN_Y 1000 +# define WIN_TITTLE "Wolfenstein 3D" + +# define WIN_EXT 17 +# define WIN_EXTM (1L << 17) + +# define MOUSE_MASK 0 +# define MOUSE_DOWN 4 +# define MOUSE_UP 5 +# define MOUSE_MOVE 6 + +# define MLEFT_BUTTON 1 +# define MRIGHT_BUTTON 2 +# define MTHIRD_BUTTON 3 +# define MSCROLL_DOWN 4 +# define MSCROLL_UPS 5 +# define MSCROLL_LEFT 6 +# define MSCROLL_RIGHT 7 + +# define PI 3.141592 + +# define INT_MAX 2147483647 +# define INT_MIN (-INT_MAX-1) + +# define SHIFT_INC 15 + +# define ROT_MIN 0.0 +# define ROT_INC 5.0 +# define ROT_MAX 360.0 + +# define ZOOM_INC 1 +# define ZOOM_MIN 1 +# define ZOOM_DEF 15 +# define ZOOM_MAX 127 + +# define _MSG(msg) ft_putstr(msg); +# define _MSGN(msg) ft_putendl(msg); +# define _NOTIS(msg, ex, do, ret) if (!(ex)) {_MSGN(msg);do;return (ret);} +# define _NOTIS_N(ex) if (!(ex)) return (NULL) +# define _NOTIS_F(ex) if (!(ex)) return (false) + +# define _ISARGS(ac, av) {--ac;++av;_NOTIS(E_USAGE, !(ac != 1), exit(-1), 0);} + +# define _ABS(var) ((var) < 0) ? -(var) : (var) +# define _RAD(deg) (((deg) * PI) / 180.0) +# define _COSR(angle) cos(_RAD(angle)) +# define _SINR(angle) sin(_RAD(angle)) + +# define _BOOL typedef enum e_bool bool +# define _IARR typedef int* iarr +# define _POINT typedef t_p point +# define _FPOINT typedef t_fp fpoint + +# define MPTR env->mlx->mlx +# define WPTR env->mlx->win +# define IPTR env->mlx->img +# define SPTR env->mlx->screen + +#endif diff --git a/includes/wolf3d_errno.h b/includes/wolf3d_errno.h new file mode 100644 index 0000000..21cae6a --- /dev/null +++ b/includes/wolf3d_errno.h @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* wolf3d_errno.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/06 14:39:47 by tmaluh #+# #+# */ +/* Updated: 2019/02/06 14:40:21 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef WOLF3D_ERRNO_H +# define WOLF3D_ERRNO_H + +# define E_USAGE "Usage: ./wolf3d .w3d" +# define E_ALLOC "Where is memory, pal ?" +# define E_FILER "File reading error" + +# define E_EMAP "\tERROR: Empty map \\ " +# define E_IMAP "\tERROR: Invalid map \\ " +# define E_HEX "\tERROR: Invalid HEX code or you put black color \\ " + +#endif diff --git a/libft/Makefile b/libft/Makefile new file mode 100644 index 0000000..c1e545b --- /dev/null +++ b/libft/Makefile @@ -0,0 +1,65 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: tmaluh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2018/10/25 11:27:37 by tmaluh #+# #+# # +# Updated: 2019/01/11 14:22:53 by tmaluh ### ########.fr # +# # +# **************************************************************************** # + +NAME = libft.a + +CC = gcc +LC = ar rcs + +CFLAGS = -Wall -Wextra -Werror + +WHITE=\033[0m +GREEN=\033[32m +RED=\033[31m + +DEL = rm -rf +# 69 +SRCS = srcs/ctype/ft_isalnum.c srcs/ctype/ft_isalpha.c srcs/ctype/ft_isascii.c \ + srcs/ctype/ft_isblank.c srcs/ctype/ft_isdigit.c srcs/ctype/ft_islower.c \ + srcs/ctype/ft_isprint.c srcs/ctype/ft_isupper.c srcs/ctype/ft_toupper.c \ + srcs/ctype/ft_tolower.c srcs/mem/ft_bzero.c srcs/mem/ft_memset.c srcs/mem/ft_memalloc.c \ + srcs/mem/ft_memcpy.c srcs/mem/ft_memccpy.c srcs/mem/ft_memmove.c \ + srcs/mem/ft_memchr.c srcs/mem/ft_memcmp.c srcs/mem/ft_memdel.c \ + srcs/put/ft_putchar.c srcs/put/ft_putchar_fd.c srcs/put/ft_putendl.c \ + srcs/put/ft_putendl_fd.c srcs/put/ft_putnbr.c srcs/put/ft_putnbr_fd.c \ + srcs/put/ft_putstr.c srcs/put/ft_putstr_fd.c srcs/lst/ft_lstadd.c srcs/lst/ft_lstdel.c srcs/lst/ft_lstdelone.c \ + srcs/lst/ft_lstiter.c srcs/lst/ft_lstmap.c srcs/lst/ft_lstnew.c srcs/str/ft_atoi.c \ + srcs/str/ft_atoi_base.c srcs/str/ft_count_if.c srcs/str/ft_itoa.c srcs/str/ft_strcat.c \ + srcs/str/ft_strchr.c srcs/str/ft_strclr.c srcs/str/ft_strcmp.c srcs/str/ft_strcpy.c srcs/str/ft_strdel.c \ + srcs/str/ft_strdup.c srcs/str/ft_strequ.c srcs/str/ft_striter.c srcs/str/ft_striteri.c \ + srcs/str/ft_strjoin.c srcs/str/ft_strlcat.c srcs/str/ft_strlcpy.c srcs/str/ft_strlen.c \ + srcs/str/ft_strmap.c srcs/str/ft_strmapi.c srcs/str/ft_strncat.c srcs/str/ft_strncmp.c \ + srcs/str/ft_strncpy.c srcs/str/ft_strndup.c srcs/str/ft_strnequ.c srcs/str/ft_strnew.c \ + srcs/str/ft_strnstr.c srcs/str/ft_strrchr.c srcs/str/ft_strsplit.c srcs/str/ft_strstr.c \ + srcs/str/ft_strsub.c srcs/str/ft_strtrim.c srcs/lft/ft_gnl.c + +OBJS = $(SRCS:%.c=%.o) + +all: $(NAME) + +$(NAME): $(OBJS) + @$(LC) $(NAME) $(OBJS) + @echo "> $(GREEN)libft$(WHITE) compiled." + +$(OBJS): %.o: %.c + @echo -n '+' + @$(CC) -c $(CFLAGS) $< -o $@ +clean: + @$(DEL) $(OBJS) + +fclean: clean + @$(DEL) $(NAME) + @echo "$(RED)deleted$(WHITE): libft.a" + +re: fclean all + +.PHONY: re fclean clean all diff --git a/libft/includes/lft_ctype.h b/libft/includes/lft_ctype.h new file mode 100644 index 0000000..a8ee9f9 --- /dev/null +++ b/libft/includes/lft_ctype.h @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lft_ctype.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/15 09:29:06 by tmaluh #+# #+# */ +/* Updated: 2018/11/15 09:29:08 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LFT_CTYPE_H +# define LFT_CTYPE_H + +int ft_isalpha(int c); +int ft_isdigit(int c); +int ft_isalnum(int c); +int ft_isascii(int c); +int ft_isprint(int c); +int ft_islower(int c); +int ft_isupper(int c); +int ft_isblank(int c); +int ft_toupper(int c); +int ft_tolower(int c); + +#endif diff --git a/libft/includes/lft_lst.h b/libft/includes/lft_lst.h new file mode 100644 index 0000000..282a30b --- /dev/null +++ b/libft/includes/lft_lst.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lft_lst.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/15 09:19:14 by tmaluh #+# #+# */ +/* Updated: 2018/11/15 09:19:15 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LFT_LST_H +# define LFT_LST_H + +# include + +typedef struct s_list +{ + void *content; + size_t content_size; + struct s_list *next; +} t_list; + +t_list *ft_lstnew(void const *content, size_t content_size); +void ft_lstdelone(t_list **alst, void (*del)(void*, size_t)); +void ft_lstdel(t_list **alst, void (*del)(void*, size_t)); +void ft_lstadd(t_list **alst, t_list *new); +void ft_lstiter(t_list *lst, void (*f)(t_list *elem)); +t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)); + +#endif diff --git a/libft/includes/lft_mem.h b/libft/includes/lft_mem.h new file mode 100644 index 0000000..aa01abd --- /dev/null +++ b/libft/includes/lft_mem.h @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lft_mem.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/15 09:15:42 by tmaluh #+# #+# */ +/* Updated: 2018/11/15 09:15:43 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LFT_MEM_H +# define LFT_MEM_H + +# include "lft_str.h" + +# define _PVOID typedef void* pvoid + +_PVOID; + +void ft_bzero(pvoid s, size_t n); +void ft_memdel(pvoid *ap); + +pvoid ft_memset(pvoid b, int c, size_t len); +pvoid ft_memcpy(pvoid dest, const pvoid src, size_t n); +pvoid ft_memccpy(pvoid dest, const pvoid src, + int c, size_t n); +pvoid ft_memmove(pvoid dest, void const *src, size_t len); +pvoid ft_memchr(const pvoid s, int c, size_t n); +pvoid ft_memalloc(size_t size); + +int ft_memcmp(const pvoid s1, const pvoid s2, size_t n); + +#endif diff --git a/libft/includes/lft_put.h b/libft/includes/lft_put.h new file mode 100644 index 0000000..2abbe44 --- /dev/null +++ b/libft/includes/lft_put.h @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lft_put.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/15 09:20:16 by tmaluh #+# #+# */ +/* Updated: 2018/11/15 09:20:17 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LFT_PUT_H +# define LFT_PUT_H + +# include + +void ft_putchar(char c); +void ft_putstr(char const *s); +void ft_putendl(char const *s); +void ft_putnbr(int n); +void ft_putchar_fd(char c, int fd); +void ft_putstr_fd(char const *s, int fd); +void ft_putendl_fd(char const *s, int fd); +void ft_putnbr_fd(int n, int fd); + +#endif diff --git a/libft/includes/lft_str.h b/libft/includes/lft_str.h new file mode 100644 index 0000000..f062623 --- /dev/null +++ b/libft/includes/lft_str.h @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* lft_str.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/15 09:09:02 by tmaluh #+# #+# */ +/* Updated: 2018/12/19 20:34:14 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LFT_STR_H +# define LFT_STR_H + +# include +# include + +# define _STR typedef char* string +# define _CSTR typedef const char* cstring +# define _USTR typedef unsigned char* ustring +# define _UCHAR typedef unsigned char uchar +# define _STRTAB typedef char** strtab + +_STR; +_CSTR; +_USTR; +_UCHAR; +_STRTAB; + +void ft_strdel(string *as); +void ft_strclr(string s); +void ft_striter(string s, void (*f)(string)); +void ft_striteri(string s, void (*f)(unsigned int, string)); + +int ft_atoi(string str); +int ft_atoi_base(cstring str, int base); +int ft_strcmp(cstring s1, cstring s2); +int ft_strncmp(cstring s1, cstring s2, size_t n); +int ft_strequ(char const *s1, char const *s2); +int ft_strnequ(char const *s1, char const *s2, size_t n); +int ft_count_if(char const *str, char const ch); + +size_t ft_strlen(cstring str); +size_t ft_strlcat(string dest, cstring src, + size_t dstsize); +size_t ft_strlcpy(string dest, cstring str, size_t dstsize); + +string ft_itoa(int n); +string ft_strdup(cstring src); +string ft_strndup(cstring s1, size_t n); +string ft_strcpy(string dest, cstring str); +string ft_strncpy(string dest, cstring src, size_t len); +string ft_strcat(string dest, cstring src); +string ft_strncat(string dest, cstring src, size_t n); +string ft_strchr(cstring s, int c); +string ft_strrchr(cstring s, int c); +string ft_strstr(cstring str, cstring to_find); +string ft_strnstr(cstring str, cstring to_find, size_t len); +string ft_strnew(size_t size); +string ft_strmap(char const *s, char (*f)(char)); +string ft_strmapi(char const *s, char (*f)(unsigned int, char)); +string ft_strsub(char const *s, unsigned int start, size_t len); +string ft_strjoin(char const *s1, char const *s2); +string ft_strtrim(char const *s); +strtab ft_strsplit(char const *s, char c); + +#endif diff --git a/libft/includes/libft.h b/libft/includes/libft.h new file mode 100644 index 0000000..7b7d3f0 --- /dev/null +++ b/libft/includes/libft.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* libft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 10:04:13 by tmaluh #+# #+# */ +/* Updated: 2018/12/28 15:18:43 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef LIBFT_H +# define LIBFT_H + +# include "lft_str.h" +# include "lft_lst.h" +# include "lft_mem.h" +# include "lft_put.h" +# include "lft_ctype.h" + +# define BUFF_SIZE 2048 + +int ft_gnl(const int fd, char **line); + +#endif diff --git a/libft/srcs/ctype/ft_isalnum.c b/libft/srcs/ctype/ft_isalnum.c new file mode 100644 index 0000000..6ee5927 --- /dev/null +++ b/libft/srcs/ctype/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/25 10:00:46 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:27:15 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_isalnum(int c) +{ + return (ft_isdigit(c) || ft_isalpha(c)); +} diff --git a/libft/srcs/ctype/ft_isalpha.c b/libft/srcs/ctype/ft_isalpha.c new file mode 100644 index 0000000..ed3b861 --- /dev/null +++ b/libft/srcs/ctype/ft_isalpha.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/25 09:37:17 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:27:27 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_isalpha(int c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} diff --git a/libft/srcs/ctype/ft_isascii.c b/libft/srcs/ctype/ft_isascii.c new file mode 100644 index 0000000..586ddbf --- /dev/null +++ b/libft/srcs/ctype/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/25 10:08:07 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:27:38 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_isascii(int c) +{ + return (c >= 0 && c < 128); +} diff --git a/libft/srcs/ctype/ft_isblank.c b/libft/srcs/ctype/ft_isblank.c new file mode 100644 index 0000000..58bb331 --- /dev/null +++ b/libft/srcs/ctype/ft_isblank.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isblank.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/28 10:13:34 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 10:14:20 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_isblank(int c) +{ + return ((c >= 9 && c <= 13) || c == 32); +} diff --git a/libft/srcs/ctype/ft_isdigit.c b/libft/srcs/ctype/ft_isdigit.c new file mode 100644 index 0000000..92fda2c --- /dev/null +++ b/libft/srcs/ctype/ft_isdigit.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/25 09:47:57 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:27:47 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/libft/srcs/ctype/ft_islower.c b/libft/srcs/ctype/ft_islower.c new file mode 100644 index 0000000..72f477b --- /dev/null +++ b/libft/srcs/ctype/ft_islower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_islower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/28 10:04:05 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 10:04:58 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_islower(int c) +{ + return (c >= 'a' && c <= 'z'); +} diff --git a/libft/srcs/ctype/ft_isprint.c b/libft/srcs/ctype/ft_isprint.c new file mode 100644 index 0000000..ab2fbee --- /dev/null +++ b/libft/srcs/ctype/ft_isprint.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/25 10:44:51 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:27:54 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_isprint(int c) +{ + return (c >= 32 && c <= 126); +} diff --git a/libft/srcs/ctype/ft_isupper.c b/libft/srcs/ctype/ft_isupper.c new file mode 100644 index 0000000..3b746dd --- /dev/null +++ b/libft/srcs/ctype/ft_isupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/28 10:05:14 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 10:05:42 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_isupper(int c) +{ + return (c >= 'A' && c <= 'Z'); +} diff --git a/libft/srcs/ctype/ft_tolower.c b/libft/srcs/ctype/ft_tolower.c new file mode 100644 index 0000000..0578d61 --- /dev/null +++ b/libft/srcs/ctype/ft_tolower.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_tolower.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/25 11:21:52 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:35:32 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_tolower(int c) +{ + return ((c >= 'A' && c <= 'Z') ? c += 32 : c); +} diff --git a/libft/srcs/ctype/ft_toupper.c b/libft/srcs/ctype/ft_toupper.c new file mode 100644 index 0000000..04a3506 --- /dev/null +++ b/libft/srcs/ctype/ft_toupper.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_toupper.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/25 11:14:14 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:35:38 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_ctype.h" + +int ft_toupper(int c) +{ + return ((c >= 'a' && c <= 'z') ? c -= 32 : c); +} diff --git a/libft/srcs/lft/ft_gnl.c b/libft/srcs/lft/ft_gnl.c new file mode 100644 index 0000000..6d452f6 --- /dev/null +++ b/libft/srcs/lft/ft_gnl.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_gnl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/03 12:31:02 by tmaluh #+# #+# */ +/* Updated: 2018/12/30 00:35:45 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/libft.h" +#include "../../includes/lft_str.h" + +static int catline_recursive(int fd, string *data, string *line, int nbytes) +{ + int to_nl; + string temp_nl; + + to_nl = -1; + while (data[fd][++to_nl] != '\n' && + data[fd][to_nl] != '\0') + ; + if (data[fd][to_nl] == '\n') + { + *line = ft_strndup(data[fd], to_nl); + temp_nl = ft_strdup(data[fd] + ++to_nl); + free(data[fd]); + data[fd] = temp_nl; + if (data[fd][0] == '\0') + ft_strdel(&data[fd]); + } + else if (data[fd][to_nl] == '\0') + { + if (nbytes == BUFF_SIZE) + return (ft_gnl(fd, line)); + *line = ft_strdup(data[fd]); + ft_strdel(&data[fd]); + } + return (1); +} + +int ft_gnl(const int fd, string *line) +{ + static string data[255]; + string temp; + char buff[BUFF_SIZE + 1]; + int nbytes; + + if (fd < 0 || !line) + return (-1); + while ((nbytes = read(fd, buff, BUFF_SIZE)) > 0) + { + buff[nbytes] = '\0'; + if (!data[fd]) + data[fd] = ft_strnew(0); + temp = ft_strjoin(data[fd], buff); + free(data[fd]); + data[fd] = temp; + if (ft_strchr(buff, '\n')) + break ; + } + if (nbytes < 0) + return (-1); + if (nbytes == 0 && + (!data[fd] || data[fd][0] == '\0')) + return (0); + return (catline_recursive(fd, data, line, nbytes)); +} diff --git a/libft/srcs/lst/ft_lstadd.c b/libft/srcs/lst/ft_lstadd.c new file mode 100644 index 0000000..43eaab8 --- /dev/null +++ b/libft/srcs/lst/ft_lstadd.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstadd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 18:34:26 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 18:42:31 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_lst.h" + +void ft_lstadd(t_list **alst, t_list *new) +{ + if (alst && new) + { + new->next = *alst; + *alst = new; + } +} diff --git a/libft/srcs/lst/ft_lstdel.c b/libft/srcs/lst/ft_lstdel.c new file mode 100644 index 0000000..1d9a7da --- /dev/null +++ b/libft/srcs/lst/ft_lstdel.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 18:20:31 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 18:33:53 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_lst.h" +#include "../../includes/lft_mem.h" + +void ft_lstdel(t_list **alst, void (*del)(void*, size_t)) +{ + t_list *temp; + + if (alst && del) + { + while (*alst) + { + temp = (*alst)->next; + del((*alst)->content, (*alst)->content_size); + free(*alst); + *alst = temp; + } + *alst = NULL; + } +} diff --git a/libft/srcs/lst/ft_lstdelone.c b/libft/srcs/lst/ft_lstdelone.c new file mode 100644 index 0000000..ea19bd9 --- /dev/null +++ b/libft/srcs/lst/ft_lstdelone.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstdelone.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 18:15:09 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 18:31:32 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_lst.h" +#include "../../includes/lft_mem.h" + +void ft_lstdelone(t_list **alst, void (*del)(void*, size_t)) +{ + if (alst && del) + { + del((*alst)->content, (*alst)->content_size); + *alst = NULL; + } +} diff --git a/libft/srcs/lst/ft_lstiter.c b/libft/srcs/lst/ft_lstiter.c new file mode 100644 index 0000000..5c95798 --- /dev/null +++ b/libft/srcs/lst/ft_lstiter.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstiter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 18:43:02 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 18:48:18 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_lst.h" + +void ft_lstiter(t_list *lst, void (*f)(t_list *elem)) +{ + while (lst) + { + f(lst); + lst = lst->next; + } +} diff --git a/libft/srcs/lst/ft_lstmap.c b/libft/srcs/lst/ft_lstmap.c new file mode 100644 index 0000000..93cca49 --- /dev/null +++ b/libft/srcs/lst/ft_lstmap.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 18:48:56 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 18:56:14 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_lst.h" + +t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem)) +{ + t_list *out; + t_list *tmp; + + if (lst == NULL) + return (NULL); + tmp = f(lst); + out = tmp; + while (lst->next) + { + lst = lst->next; + if (!(tmp->next = f(lst))) + { + free(tmp->next); + return (NULL); + } + tmp = tmp->next; + } + return (out); +} diff --git a/libft/srcs/lst/ft_lstnew.c b/libft/srcs/lst/ft_lstnew.c new file mode 100644 index 0000000..492c634 --- /dev/null +++ b/libft/srcs/lst/ft_lstnew.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_lstnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 17:56:10 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 18:14:38 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_lst.h" +#include "../../includes/lft_mem.h" + +t_list *ft_lstnew(void const *content, size_t content_size) +{ + t_list *out; + + if ((out = (t_list*)malloc(sizeof(t_list))) == NULL) + return (NULL); + if (content == NULL) + { + out->content = NULL; + out->content_size = 0; + } + else + { + if ((out->content = malloc(content_size)) == NULL) + return (NULL); + ft_memmove(out->content, content, content_size); + out->content_size = content_size; + } + out->next = NULL; + return (out); +} diff --git a/libft/srcs/mem/ft_bzero.c b/libft/srcs/mem/ft_bzero.c new file mode 100644 index 0000000..805fb45 --- /dev/null +++ b/libft/srcs/mem/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 11:21:20 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:27:03 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" + +void ft_bzero(pvoid s, size_t n) +{ + ft_memset(s, 0, n); +} diff --git a/libft/srcs/mem/ft_memalloc.c b/libft/srcs/mem/ft_memalloc.c new file mode 100644 index 0000000..71798db --- /dev/null +++ b/libft/srcs/mem/ft_memalloc.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memalloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 15:33:11 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:28:13 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" + +pvoid ft_memalloc(size_t size) +{ + pvoid out; + + out = NULL; + if (size) + { + if ((out = malloc(size)) == NULL) + return (NULL); + ft_memset(out, 0, size); + } + return (out); +} diff --git a/libft/srcs/mem/ft_memccpy.c b/libft/srcs/mem/ft_memccpy.c new file mode 100644 index 0000000..964ab44 --- /dev/null +++ b/libft/srcs/mem/ft_memccpy.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memccpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 17:43:45 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:28:23 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" +#include "../../includes/lft_str.h" + +pvoid ft_memccpy(pvoid dest, + const pvoid src, + int c, size_t n) +{ + unsigned char ch; + ustring dst; + ustring sc; + size_t i; + + dst = (ustring)dest; + sc = (ustring)src; + i = 0; + ch = c; + while (i < n) + { + dst[i] = sc[i]; + if (sc[i] == ch) + return (dst + i + 1); + i++; + } + return (NULL); +} diff --git a/libft/srcs/mem/ft_memchr.c b/libft/srcs/mem/ft_memchr.c new file mode 100644 index 0000000..54df80f --- /dev/null +++ b/libft/srcs/mem/ft_memchr.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 15:04:22 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 14:52:20 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" +#include "../../includes/lft_str.h" + +pvoid ft_memchr(const pvoid s, int c, size_t n) +{ + ustring out; + unsigned char ch; + int i; + + i = 0; + ch = (unsigned char)c; + out = (ustring)s; + while (n--) + { + if (out[i] == ch) + return (out + i); + i++; + } + return (NULL); +} diff --git a/libft/srcs/mem/ft_memcmp.c b/libft/srcs/mem/ft_memcmp.c new file mode 100644 index 0000000..dc92a94 --- /dev/null +++ b/libft/srcs/mem/ft_memcmp.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 15:13:55 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:28:47 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" +#include "../../includes/lft_str.h" + +int ft_memcmp(const pvoid s1, const pvoid s2, size_t n) +{ + ustring str1; + ustring str2; + + str2 = (ustring)s2; + str1 = (ustring)s1; + if (str1 == str2 || n == 0) + return (0); + while (n--) + { + if (*str1 != *str2) + return (*str1 - *str2); + if (n) + { + str1++; + str2++; + } + } + return (0); +} diff --git a/libft/srcs/mem/ft_memcpy.c b/libft/srcs/mem/ft_memcpy.c new file mode 100644 index 0000000..d1cca2e --- /dev/null +++ b/libft/srcs/mem/ft_memcpy.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 11:04:50 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:28:56 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" +#include "../../includes/lft_str.h" + +pvoid ft_memcpy(pvoid dest, const pvoid src, size_t n) +{ + size_t i; + string dst; + string sc; + + dst = (string)dest; + sc = (string)src; + i = 0; + while (i < n) + { + dst[i] = sc[i]; + i++; + } + return (dest); +} diff --git a/libft/srcs/mem/ft_memdel.c b/libft/srcs/mem/ft_memdel.c new file mode 100644 index 0000000..fa4e623 --- /dev/null +++ b/libft/srcs/mem/ft_memdel.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 15:45:49 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:29:06 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" + +void ft_memdel(pvoid *ap) +{ + if (ap && *ap) + { + free(*ap); + *ap = NULL; + } +} diff --git a/libft/srcs/mem/ft_memmove.c b/libft/srcs/mem/ft_memmove.c new file mode 100644 index 0000000..2e709c0 --- /dev/null +++ b/libft/srcs/mem/ft_memmove.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 13:43:44 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:29:16 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" +#include "../../includes/lft_str.h" + +pvoid ft_memmove(pvoid dest, void const *src, size_t len) +{ + size_t i; + ustring dst; + ustring sc; + + dst = (ustring)dest; + sc = (ustring)src; + i = -1; + if (sc < dst) + while ((int)(--len) >= 0) + dst[len] = sc[len]; + else + while (++i < len) + dst[i] = sc[i]; + return (dest); +} diff --git a/libft/srcs/mem/ft_memset.c b/libft/srcs/mem/ft_memset.c new file mode 100644 index 0000000..a5c1e65 --- /dev/null +++ b/libft/srcs/mem/ft_memset.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 11:17:58 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:29:25 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_mem.h" +#include "../../includes/lft_str.h" + +pvoid ft_memset(pvoid b, int c, size_t len) +{ + ustring out; + + out = (ustring)b; + while (len-- > 0) + *out++ = c; + return (b); +} diff --git a/libft/srcs/put/ft_putchar.c b/libft/srcs/put/ft_putchar.c new file mode 100644 index 0000000..7c912b3 --- /dev/null +++ b/libft/srcs/put/ft_putchar.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 20:03:19 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 20:09:12 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/libft/srcs/put/ft_putchar_fd.c b/libft/srcs/put/ft_putchar_fd.c new file mode 100644 index 0000000..eadaedb --- /dev/null +++ b/libft/srcs/put/ft_putchar_fd.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 13:34:25 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:36:04 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putchar_fd(char c, int fd) +{ + write(fd, &c, 1); +} diff --git a/libft/srcs/put/ft_putendl.c b/libft/srcs/put/ft_putendl.c new file mode 100644 index 0000000..0fe16fb --- /dev/null +++ b/libft/srcs/put/ft_putendl.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 13:39:47 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:39:49 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putendl(char const *s) +{ + if (s) + { + ft_putstr(s); + ft_putchar('\n'); + } +} diff --git a/libft/srcs/put/ft_putendl_fd.c b/libft/srcs/put/ft_putendl_fd.c new file mode 100644 index 0000000..0cc02a3 --- /dev/null +++ b/libft/srcs/put/ft_putendl_fd.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putendl_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 13:39:54 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:40:20 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putendl_fd(char const *s, int fd) +{ + if (s) + { + ft_putstr_fd(s, fd); + ft_putchar_fd('\n', fd); + } +} diff --git a/libft/srcs/put/ft_putnbr.c b/libft/srcs/put/ft_putnbr.c new file mode 100644 index 0000000..1481de0 --- /dev/null +++ b/libft/srcs/put/ft_putnbr.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 10:24:50 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:33:43 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putnbr(int n) +{ + if (n == -2147483648) + ft_putstr("-2147483648"); + else if (n == 2147483647) + ft_putstr("2147483647"); + else + { + if (n < 0) + { + ft_putchar('-'); + n = -n; + } + if (n >= 10) + { + ft_putnbr(n / 10); + ft_putchar(n % 10 + '0'); + } + if (n < 10) + ft_putchar(n % 10 + '0'); + } +} diff --git a/libft/srcs/put/ft_putnbr_fd.c b/libft/srcs/put/ft_putnbr_fd.c new file mode 100644 index 0000000..a495de0 --- /dev/null +++ b/libft/srcs/put/ft_putnbr_fd.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 13:45:17 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:46:34 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putnbr_fd(int n, int fd) +{ + if (n == -2147483648) + ft_putstr_fd("-2147483648", fd); + else if (n == 2147483647) + ft_putstr_fd("2147483647", fd); + else + { + if (n < 0) + { + ft_putchar_fd('-', fd); + n = -n; + } + if (n >= 10) + { + ft_putnbr_fd(n / 10, fd); + ft_putchar_fd(n % 10 + '0', fd); + } + if (n < 10) + ft_putchar_fd(n % 10 + '0', fd); + } +} diff --git a/libft/srcs/put/ft_putstr.c b/libft/srcs/put/ft_putstr.c new file mode 100644 index 0000000..48799d4 --- /dev/null +++ b/libft/srcs/put/ft_putstr.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 13:36:48 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:37:42 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putstr(char const *s) +{ + unsigned int i; + + i = -1; + if (s == NULL) + return ; + while (s[++i]) + ft_putchar(s[i]); +} diff --git a/libft/srcs/put/ft_putstr_fd.c b/libft/srcs/put/ft_putstr_fd.c new file mode 100644 index 0000000..f32b177 --- /dev/null +++ b/libft/srcs/put/ft_putstr_fd.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr_fd.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 13:39:34 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:39:35 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_put.h" + +void ft_putstr_fd(char const *s, int fd) +{ + unsigned int i; + + i = -1; + if (s == NULL) + return ; + while (s[++i]) + ft_putchar_fd(s[i], fd); +} diff --git a/libft/srcs/str/ft_atoi.c b/libft/srcs/str/ft_atoi.c new file mode 100644 index 0000000..86146b0 --- /dev/null +++ b/libft/srcs/str/ft_atoi.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 11:11:40 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:26:47 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_ctype.h" + +int ft_atoi(string str) +{ + int num; + int sign; + + sign = 0; + num = 0; + while (ft_isblank(*str)) + ++str; + sign = (*str == '-') ? -1 : 1; + (*str == '-' || *str == '+') ? ++str : 0; + while (ft_isdigit(*str)) + num = num * 10 + *(str++) - 48; + return (num * sign); +} diff --git a/libft/srcs/str/ft_atoi_base.c b/libft/srcs/str/ft_atoi_base.c new file mode 100644 index 0000000..5bce72c --- /dev/null +++ b/libft/srcs/str/ft_atoi_base.c @@ -0,0 +1,60 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi_base.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/11/21 16:46:01 by tmaluh #+# #+# */ +/* Updated: 2018/11/21 16:46:02 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_ctype.h" + +static int isvalid(int c, int base) +{ + char *valid_lower; + char *valid_upper; + int is; + + is = 0; + valid_lower = ft_strdup("0123456789abcdef"); + valid_upper = ft_strdup("0123456789ABCDEF"); + while (base--) + if (valid_lower[base] == c || valid_upper[base] == c) + { + is = 1; + break ; + } + ft_strdel(&valid_lower); + ft_strdel(&valid_upper); + return (is); +} + +static int value_of(int c) +{ + if (ft_isdigit(c)) + return (c - '0'); + else if (ft_islower(c)) + return (c - 'a' + 10); + else if (ft_isupper(c)) + return (c - 'A' + 10); + return (0); +} + +int ft_atoi_base(cstring str, int base) +{ + int result; + int sign; + + result = 0; + while (ft_isblank(*str)) + ++str; + sign = (*str == '-') ? -1 : 1; + (*str == '-' || *str == '+') ? ++str : 0; + while (isvalid(*str, base)) + result = result * base + value_of(*str++); + return (result * sign); +} diff --git a/libft/srcs/str/ft_atol.c b/libft/srcs/str/ft_atol.c new file mode 100644 index 0000000..ea09502 --- /dev/null +++ b/libft/srcs/str/ft_atol.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atol.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 11:11:40 by tmaluh #+# #+# */ +/* Updated: 2019/01/16 10:43:46 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_ctype.h" + +long ft_atol(string str) +{ + long num; + int sign; + + sign = 0; + num = 0; + while (ft_isblank(*str)) + ++str; + sign = (*str == '-') ? -1 : 1; + (*str == '-' || *str == '+') ? ++str : 0; + while (ft_isdigit(*str)) + num = num * 10 + *(str++) - 48; + return (num * sign); +} diff --git a/libft/srcs/str/ft_count_if.c b/libft/srcs/str/ft_count_if.c new file mode 100644 index 0000000..b058895 --- /dev/null +++ b/libft/srcs/str/ft_count_if.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_count_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/29 10:33:21 by tmaluh #+# #+# */ +/* Updated: 2018/10/29 10:52:18 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +int ft_count_if(cstring str, char const ch) +{ + int counter; + int i; + + i = -1; + counter = 0; + if (!str || !ch) + return (0); + while (str[++i] != '\0') + if (str[i] == ch) + counter++; + return (counter); +} diff --git a/libft/srcs/str/ft_itoa.c b/libft/srcs/str/ft_itoa.c new file mode 100644 index 0000000..bc0443a --- /dev/null +++ b/libft/srcs/str/ft_itoa.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 10:33:26 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 13:28:54 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +static inline int ft_slen(int *in, int n) +{ + int out; + + out = 1; + if (n < 0) + *in = 1; + while (n /= 10) + out++; + return (out); +} + +string ft_itoa(int n) +{ + int len; + int sign; + string out; + + if (!n) + { + out = ft_strnew(1); + out[0] = '0'; + return (out); + } + sign = 0; + len = ft_slen(&sign, n); + if ((out = ft_strnew(len + sign)) == NULL) + return (NULL); + if (sign) + out[0] = '-'; + while (len--) + { + out[len + sign] = (sign ? -(n % 10) : n % 10) + '0'; + n /= 10; + } + return (out); +} diff --git a/libft/srcs/str/ft_ltoa.c b/libft/srcs/str/ft_ltoa.c new file mode 100644 index 0000000..924ecc5 --- /dev/null +++ b/libft/srcs/str/ft_ltoa.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ltoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 10:33:26 by tmaluh #+# #+# */ +/* Updated: 2019/01/16 10:46:45 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +static inline long ft_slen(long *in, long n) +{ + long out; + + out = 1; + if (n < 0) + *in = 1; + while (n /= 10) + out++; + return (out); +} + +string ft_ltoa(long n) +{ + long len; + long sign; + string out; + + if (!n) + { + out = ft_strnew(1); + out[0] = '0'; + return (out); + } + sign = 0; + len = ft_slen(&sign, n); + if ((out = ft_strnew(len + sign)) == NULL) + return (NULL); + if (sign) + out[0] = '-'; + while (len--) + { + out[len + sign] = (sign ? -(n % 10) : n % 10) + '0'; + n /= 10; + } + return (out); +} diff --git a/libft/srcs/str/ft_strcat.c b/libft/srcs/str/ft_strcat.c new file mode 100644 index 0000000..3fc8eea --- /dev/null +++ b/libft/srcs/str/ft_strcat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 10:35:28 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:29:41 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strcat(string dest, cstring src) +{ + size_t i; + size_t j; + + i = ft_strlen(dest); + j = 0; + while (src[j] != '\0') + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = '\0'; + return (dest); +} diff --git a/libft/srcs/str/ft_strchr.c b/libft/srcs/str/ft_strchr.c new file mode 100644 index 0000000..cd03b86 --- /dev/null +++ b/libft/srcs/str/ft_strchr.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 16:37:20 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:29:52 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strchr(cstring s, int c) +{ + while (*s != (char)c) + if (!*s++) + return (0); + return ((string)s); +} diff --git a/libft/srcs/str/ft_strclr.c b/libft/srcs/str/ft_strclr.c new file mode 100644 index 0000000..40f213d --- /dev/null +++ b/libft/srcs/str/ft_strclr.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strclr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:26:28 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:30:00 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_mem.h" + +void ft_strclr(string s) +{ + s != NULL ? ft_memset(s, '\0', ft_strlen(s)) : 0; +} diff --git a/libft/srcs/str/ft_strcmp.c b/libft/srcs/str/ft_strcmp.c new file mode 100644 index 0000000..87f7965 --- /dev/null +++ b/libft/srcs/str/ft_strcmp.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/23 13:26:04 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 19:03:09 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +int ft_strcmp(cstring s1, cstring s2) +{ + while (*s1 && (*s1 == *s2)) + { + s1++; + s2++; + } + return (*(ustring)s1 - + *(ustring)s2); +} diff --git a/libft/srcs/str/ft_strcpy.c b/libft/srcs/str/ft_strcpy.c new file mode 100644 index 0000000..74430b9 --- /dev/null +++ b/libft/srcs/str/ft_strcpy.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 10:03:08 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 09:44:48 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strcpy(string dest, cstring str) +{ + size_t i; + + i = -1; + while (str[++i] != '\0') + dest[i] = str[i]; + dest[i] = '\0'; + return (dest); +} diff --git a/libft/srcs/str/ft_strdel.c b/libft/srcs/str/ft_strdel.c new file mode 100644 index 0000000..d54d62e --- /dev/null +++ b/libft/srcs/str/ft_strdel.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:21:54 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:30:32 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +void ft_strdel(string *as) +{ + if (as && *as) + { + free(*as); + *as = NULL; + } +} diff --git a/libft/srcs/str/ft_strdup.c b/libft/srcs/str/ft_strdup.c new file mode 100644 index 0000000..421b718 --- /dev/null +++ b/libft/srcs/str/ft_strdup.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 10:03:47 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:30:47 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strdup(cstring src) +{ + string out; + size_t i; + + i = 0; + if ((out = (string)malloc(sizeof(char) * ft_strlen(src) + 1)) == NULL) + return (NULL); + while (src[i] != '\0') + { + out[i] = src[i]; + i++; + } + out[i] = '\0'; + return (out); +} diff --git a/libft/srcs/str/ft_strequ.c b/libft/srcs/str/ft_strequ.c new file mode 100644 index 0000000..1e46fe3 --- /dev/null +++ b/libft/srcs/str/ft_strequ.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:55:16 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:30:59 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +int ft_strequ(char const *s1, char const *s2) +{ + if (s1 == NULL || s2 == NULL) + return (0); + return (!ft_strcmp(s1, s2) ? 1 : 0); +} diff --git a/libft/srcs/str/ft_striter.c b/libft/srcs/str/ft_striter.c new file mode 100644 index 0000000..491ac78 --- /dev/null +++ b/libft/srcs/str/ft_striter.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striter.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:30:32 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 15:12:12 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +void ft_striter(string s, void (*f)(string)) +{ + size_t i; + + if (!s || !f) + return ; + i = -1; + if (s) + while (s[++i]) + f(&s[i]); +} diff --git a/libft/srcs/str/ft_striteri.c b/libft/srcs/str/ft_striteri.c new file mode 100644 index 0000000..b3fdf17 --- /dev/null +++ b/libft/srcs/str/ft_striteri.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_striteri.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:35:59 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 15:03:25 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +void ft_striteri(string s, void (*f)(unsigned int, string)) +{ + unsigned int i; + + if (!s || !f) + return ; + i = -1; + if (s) + while (s[++i]) + f(i, &s[i]); +} diff --git a/libft/srcs/str/ft_strjoin.c b/libft/srcs/str/ft_strjoin.c new file mode 100644 index 0000000..9283d0e --- /dev/null +++ b/libft/srcs/str/ft_strjoin.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strjoin.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 19:11:48 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 14:37:00 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strjoin(char const *s1, char const *s2) +{ + string out; + size_t len1; + size_t len2; + + out = NULL; + if (s1 == NULL || s2 == NULL) + return (NULL); + len1 = ft_strlen(s1); + len2 = ft_strlen(s2); + if ((out = ft_strnew((len1 ? len1 : 1) + + (len2 ? len2 : 1))) == NULL) + return (NULL); + out = ft_strcpy(out, s1); + out = ft_strcpy(out + len1, s2); + return (out - len1); +} diff --git a/libft/srcs/str/ft_strlcat.c b/libft/srcs/str/ft_strlcat.c new file mode 100644 index 0000000..137fc4c --- /dev/null +++ b/libft/srcs/str/ft_strlcat.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 17:43:23 by tmaluh #+# #+# */ +/* Updated: 2018/10/30 17:10:30 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +size_t ft_strlcat(string dest, + cstring src, + size_t dstsize) +{ + string dst; + cstring sc; + size_t n; + size_t dlen; + + dst = dest; + sc = src; + n = dstsize; + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - dest; + n = dstsize - dlen; + if (n == 0) + return (dlen + ft_strlen(sc)); + while (*sc != '\0') + { + if (n != 1) + { + *dst++ = *sc; + n--; + } + sc++; + } + *dst = '\0'; + return (dlen + (sc - src)); +} diff --git a/libft/srcs/str/ft_strlcpy.c b/libft/srcs/str/ft_strlcpy.c new file mode 100644 index 0000000..2b96306 --- /dev/null +++ b/libft/srcs/str/ft_strlcpy.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 19:20:57 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 10:01:24 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_mem.h" + +size_t ft_strlcpy(string dest, cstring str, size_t dstsize) +{ + size_t strsize; + + if (str == NULL) + return (0); + strsize = ft_strlen(str); + if (strsize < dstsize) + ft_memcpy(dest, (pvoid)str, strsize + 1); + else if (dstsize != 0) + { + ft_memcpy(dest, (pvoid)str, dstsize - 1); + dest[dstsize - 1] = '\0'; + } + return (strsize); +} diff --git a/libft/srcs/str/ft_strlen.c b/libft/srcs/str/ft_strlen.c new file mode 100644 index 0000000..489e07b --- /dev/null +++ b/libft/srcs/str/ft_strlen.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 10:05:59 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:31:48 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +size_t ft_strlen(cstring str) +{ + size_t i; + + i = 0; + while (str[i] != '\0') + i++; + return (i); +} diff --git a/libft/srcs/str/ft_strmap.c b/libft/srcs/str/ft_strmap.c new file mode 100644 index 0000000..da5f6c0 --- /dev/null +++ b/libft/srcs/str/ft_strmap.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:41:28 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:31:56 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strmap(char const *s, char (*f)(char)) +{ + string src; + string out; + unsigned int len; + unsigned int i; + + i = -1; + if (!s) + return (NULL); + src = (string)s; + len = ft_strlen(s); + if ((out = ft_strnew(len)) == NULL) + return (NULL); + while (s[++i]) + out[i] = f(src[i]); + return (out); +} diff --git a/libft/srcs/str/ft_strmapi.c b/libft/srcs/str/ft_strmapi.c new file mode 100644 index 0000000..2942944 --- /dev/null +++ b/libft/srcs/str/ft_strmapi.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strmapi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:53:34 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:32:06 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strmapi(char const *s, char (*f)(unsigned int, char)) +{ + string src; + string out; + unsigned int len; + unsigned int i; + + i = -1; + if (!s) + return (NULL); + src = (string)s; + len = ft_strlen(s); + if ((out = ft_strnew(len)) == NULL) + return (NULL); + while (s[++i]) + out[i] = f(i, src[i]); + return (out); +} diff --git a/libft/srcs/str/ft_strncat.c b/libft/srcs/str/ft_strncat.c new file mode 100644 index 0000000..0ac8c11 --- /dev/null +++ b/libft/srcs/str/ft_strncat.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 17:43:02 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:32:17 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strncat(string dest, cstring src, size_t n) +{ + size_t i; + size_t j; + + i = ft_strlen(dest); + j = 0; + while (src[j] != '\0' && j < n) + { + dest[i + j] = src[j]; + j++; + } + dest[i + j] = '\0'; + return (dest); +} diff --git a/libft/srcs/str/ft_strncmp.c b/libft/srcs/str/ft_strncmp.c new file mode 100644 index 0000000..47ed172 --- /dev/null +++ b/libft/srcs/str/ft_strncmp.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 18:41:43 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:32:36 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +int ft_strncmp(cstring s1, cstring s2, size_t n) +{ + unsigned char u1; + unsigned char u2; + + while (n-- > 0) + { + u1 = (unsigned char)*s1++; + u2 = (unsigned char)*s2++; + if (u1 != u2) + return (u1 - u2); + if (u1 == '\0') + return (0); + } + return (0); +} diff --git a/libft/srcs/str/ft_strncpy.c b/libft/srcs/str/ft_strncpy.c new file mode 100644 index 0000000..4c63baa --- /dev/null +++ b/libft/srcs/str/ft_strncpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 17:45:55 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:32:47 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strncpy(string dest, cstring str, size_t len) +{ + string temp; + + temp = dest; + while (len--) + if (*str == '\0') + *temp++ = 0; + else + *temp++ = *str++; + return (dest); +} diff --git a/libft/srcs/str/ft_strndup.c b/libft/srcs/str/ft_strndup.c new file mode 100644 index 0000000..2eb7ffa --- /dev/null +++ b/libft/srcs/str/ft_strndup.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strndup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 19:01:32 by tmaluh #+# #+# */ +/* Updated: 2018/10/27 19:08:49 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strndup(cstring src, size_t n) +{ + string out; + size_t i; + + i = -1; + if ((out = ft_strnew(n)) == NULL) + return (NULL); + while (src[++i] != '\0' && i < n) + out[i] = src[i]; + return (out); +} diff --git a/libft/srcs/str/ft_strnequ.c b/libft/srcs/str/ft_strnequ.c new file mode 100644 index 0000000..fa273f5 --- /dev/null +++ b/libft/srcs/str/ft_strnequ.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnequ.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 18:06:05 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:33:01 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_mem.h" + +int ft_strnequ(char const *s1, char const *s2, size_t n) +{ + if (s1 == NULL || s2 == NULL) + return (0); + return (!ft_memcmp((pvoid)s1, (pvoid)s2, n) ? 1 : 0); +} diff --git a/libft/srcs/str/ft_strnew.c b/libft/srcs/str/ft_strnew.c new file mode 100644 index 0000000..4875842 --- /dev/null +++ b/libft/srcs/str/ft_strnew.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnew.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 17:06:41 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 14:39:00 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_mem.h" + +string ft_strnew(size_t size) +{ + string out; + + out = NULL; + if ((out = (string)ft_memalloc(sizeof(char) * size + 1)) == NULL) + return (NULL); + ft_memset(out, '\0', size + 1); + return (out); +} diff --git a/libft/srcs/str/ft_strnstr.c b/libft/srcs/str/ft_strnstr.c new file mode 100644 index 0000000..ba3052a --- /dev/null +++ b/libft/srcs/str/ft_strnstr.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strnstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 17:41:32 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 14:14:37 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" +#include "../../includes/lft_mem.h" + +string ft_strnstr(cstring str, cstring to_find, size_t len) +{ + size_t n; + + if (*to_find == '\0') + return ((string)str); + n = ft_strlen(to_find); + while (*str && len-- >= n) + { + if (*str && *to_find && + !ft_memcmp((pvoid)str, (pvoid)to_find, n)) + return ((string)str); + str++; + } + return (NULL); +} diff --git a/libft/srcs/str/ft_strrchr.c b/libft/srcs/str/ft_strrchr.c new file mode 100644 index 0000000..0620b7e --- /dev/null +++ b/libft/srcs/str/ft_strrchr.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 17:07:43 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 14:55:21 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strrchr(cstring s, int c) +{ + int len; + + len = ft_strlen((string)s); + while (len > 0 && s[len] != c) + len--; + if (s[len] == c) + return ((string)&s[len]); + return (NULL); +} diff --git a/libft/srcs/str/ft_strsplit.c b/libft/srcs/str/ft_strsplit.c new file mode 100644 index 0000000..915d28d --- /dev/null +++ b/libft/srcs/str/ft_strsplit.c @@ -0,0 +1,70 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsplit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/27 13:58:29 by tmaluh #+# #+# */ +/* Updated: 2018/12/19 20:34:41 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +static inline int ft_ss_words(cstring str, string ch) +{ + int counter; + int is_word; + + counter = 0; + is_word = 0; + while (*str) + { + if (is_word && *str == *ch) + is_word = 0; + if (!is_word && *str != *ch) + { + counter++; + is_word = 1; + } + str++; + } + return (counter); +} + +static inline int ft_ss_wlen(cstring str, char ch) +{ + int len; + + len = 0; + while (*str != ch && *str++ != '\0') + len++; + return (len); +} + +strtab ft_strsplit(char const *s, char c) +{ + strtab out; + int w_counter; + int i; + + i = 0; + if (s == NULL) + return (NULL); + w_counter = ft_ss_words(s, &c); + if ((out = (string*)malloc(sizeof(string) * w_counter + 1)) == NULL) + return (NULL); + while (w_counter--) + { + while (*s == c && *s != '\0') + s++; + out[i] = ft_strsub(s, 0, ft_ss_wlen(s, c)); + if (out[i] == NULL) + return (NULL); + s = s + ft_ss_wlen(s, c); + i++; + } + out[i] = NULL; + return (out); +} diff --git a/libft/srcs/str/ft_strstr.c b/libft/srcs/str/ft_strstr.c new file mode 100644 index 0000000..66a8744 --- /dev/null +++ b/libft/srcs/str/ft_strstr.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/24 18:19:30 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 19:33:46 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strstr(cstring str, cstring to_find) +{ + string cp; + string s1; + string s2; + + cp = (string)str; + if (!*to_find) + return ((string)str); + while (*cp) + { + s1 = cp; + s2 = (string)to_find; + while (*s1 && *s2 && !(*s1 - *s2)) + { + s1++; + s2++; + } + if (!*s2) + return (cp); + cp++; + } + return (0); +} diff --git a/libft/srcs/str/ft_strsub.c b/libft/srcs/str/ft_strsub.c new file mode 100644 index 0000000..e8a15f7 --- /dev/null +++ b/libft/srcs/str/ft_strsub.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strsub.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 18:07:51 by tmaluh #+# #+# */ +/* Updated: 2018/10/28 14:44:38 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strsub(char const *s, unsigned int start, size_t len) +{ + string src; + string out; + unsigned int i; + unsigned int j; + + out = NULL; + if (s == NULL) + return (NULL); + if ((out = ft_strnew(len ? len : 1)) == NULL) + return (NULL); + if (len == 0) + { + out[0] = '\0'; + return (out); + } + src = (string)s; + i = start - 1; + j = -1; + while (++j < len) + { + ++i; + out[j] = src[i]; + } + return (out); +} diff --git a/libft/srcs/str/ft_strtrim.c b/libft/srcs/str/ft_strtrim.c new file mode 100644 index 0000000..50950b4 --- /dev/null +++ b/libft/srcs/str/ft_strtrim.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strtrim.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2018/10/26 19:26:18 by tmaluh #+# #+# */ +/* Updated: 2018/10/26 20:03:00 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../../includes/lft_str.h" + +string ft_strtrim(char const *s) +{ + size_t start; + size_t len; + + if (s == NULL) + return (NULL); + start = 0; + while (s[start] == ' ' || + s[start] == '\n' || + s[start] == '\t') + start++; + if (s[start] == '\0') + return (ft_strdup(s + start)); + len = ft_strlen(s) - 1; + while ((s[len] == ' ' || + s[len] == '\t' || + s[len] == '\n') && len > 0) + len--; + return (ft_strsub(s, start, len - start + 1)); +} diff --git a/maps/map01.w3d b/maps/map01.w3d new file mode 100644 index 0000000..8261f50 --- /dev/null +++ b/maps/map01.w3d @@ -0,0 +1,6 @@ +5 5 +1 1 1 1 1 +1 0 0 0 1 +1 0 0 0 1 +1 0 0 0 1 +1 1 1 1 1 \ No newline at end of file diff --git a/srcs/main.c b/srcs/main.c new file mode 100644 index 0000000..48228c0 --- /dev/null +++ b/srcs/main.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/06 14:19:04 by tmaluh #+# #+# */ +/* Updated: 2019/02/06 15:08:39 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/wolf3d.h" + +static void add_mlx_hooks(t_env *env) +{ + mlx_hook(WPTR, KEY_PRESSED, KEY_RELEASE, wolf_key_hooks, env); + mlx_hook(WPTR, WIN_EXT, WIN_EXTM, wolf_killwindow_hook, env); + mlx_loop(MPTR); +} + +int main(int argc, string argv[]) +{ + t_env *env; + + _ISARGS(argc, argv); + _NOTIS(E_ALLOC, env = malloc(sizeof(t_env)), exit(EXIT_FAILURE), 0); + _NOTIS(E_ALLOC, wolf_init(env), wolf_free(env), 0); + add_mlx_hooks(env); +} diff --git a/srcs/wolf_free.c b/srcs/wolf_free.c new file mode 100644 index 0000000..7453950 --- /dev/null +++ b/srcs/wolf_free.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* wolf_free.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/06 14:43:13 by tmaluh #+# #+# */ +/* Updated: 2019/02/06 15:05:31 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/wolf3d.h" + +void wolf_free(t_env *env) +{ + IPTR ? mlx_destroy_image(MPTR, IPTR) : 0; + WPTR ? mlx_destroy_window(MPTR, WPTR) : 0; + env->mlx ? free(env->mlx) : NULL; + env->isr ? free(env->isr) : NULL; + env ? free(env) : NULL; +} diff --git a/srcs/wolf_init.c b/srcs/wolf_init.c new file mode 100644 index 0000000..20b40fb --- /dev/null +++ b/srcs/wolf_init.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* wolf_init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/06 14:38:13 by tmaluh #+# #+# */ +/* Updated: 2019/02/06 15:03:00 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/wolf3d.h" + +bool wolf_init(t_env *env) +{ + int bps; + int sz; + int end; + + *env = (t_env){NULL, NULL}; + _NOTIS_F(env->mlx = malloc(sizeof(t_mlx))); + _NOTIS_F(env->isr = malloc(sizeof(t_isr))); + _NOTIS_F(MPTR = mlx_init()); + _NOTIS_F(WPTR = mlx_new_window(MPTR, WIN_X, WIN_Y, WIN_TITTLE)); + _NOTIS_F(IPTR = mlx_new_image(MPTR, WIN_X, WIN_Y)); + _NOTIS_F(SPTR = (iarr)mlx_get_data_addr(IPTR, &bps, &sz, &end)); + return (true); +} diff --git a/srcs/wolf_key_hooks.c b/srcs/wolf_key_hooks.c new file mode 100644 index 0000000..ac71ee8 --- /dev/null +++ b/srcs/wolf_key_hooks.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* wolf_key_hooks.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tmaluh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/02/06 14:44:03 by tmaluh #+# #+# */ +/* Updated: 2019/02/06 15:07:27 by tmaluh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/wolf3d.h" + +int wolf_killwindow_hook(t_env *env) +{ + wolf_free(env); + system("leaks wolf3d"); + exit(EXIT_SUCCESS); + return (0); +} + +int wolf_key_hooks(int key, t_env *env) +{ + if (key == ESC) + wolf_killwindow_hook(env); + return (0); +}