From 966eb29634a84496e0851ef2b5a7d64f413d33ed Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 12 May 2020 19:10:14 +0200 Subject: Added ft_veciter_ret --- Makefile | 17 +++++++++-------- include/libft_io.h | 4 ++-- include/libft_vec.h | 3 ++- src/io/ft_getline.c | 4 ++-- src/vec/ft_veciter_ret.c | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/vec/ft_veciter_ret.c diff --git a/Makefile b/Makefile index 14b556d..7ab6fe8 100644 --- a/Makefile +++ b/Makefile @@ -6,17 +6,17 @@ # By: cacharle +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/10/08 15:45:53 by cacharle #+# #+# # -# Updated: 2020/05/09 12:28:11 by charles ### ########.fr # +# Updated: 2020/05/12 18:00:00 by charles ### ########.fr # # # # **************************************************************************** # LIB = ar rcs RM = rm -f NORM = norminette -MAKE = make -MAKE_ARGS = --no-print-directory +MAKE = make --no-print-directory DOXYGEN = doxygen DOXYGEN_FILE = Doxyfile +JOBS = 4 SRC_DIR = src INCLUDE_DIR = include @@ -48,14 +48,15 @@ OBJ = $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o) INCLUDE = $(shell find $(INCLUDE_DIR) -name "*.h") -# export LIBFT_SRC = $(SRC) +all: prebuild + @$(MAKE) -j$(JOBS) allnopre -all: prebuild $(NAME) +allnopre: $(NAME) .PHONY: test test: all @echo "Testing" - @$(MAKE) $(MAKE_ARGS) -C $(TEST_DIR) run + @$(MAKE) -C $(TEST_DIR) run norm: @if [ `command -v $(NORM)` ]; \ @@ -75,7 +76,7 @@ $(NAME): $(OBJ) $(INCLUDE) @echo "Linking: $@" @$(LIB) $@ $(OBJ) -$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c +$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INCLUDE) @echo "Compiling: $@" @$(CC) $(CCFLAGS) -c -o $@ $< @@ -84,7 +85,7 @@ clean: @$(RM) -r $(OBJ_DIR) fclean: clean - @echo "Removing library" + @echo "Removing $(NAME)" @$(RM) $(NAME) re: fclean all diff --git a/include/libft_io.h b/include/libft_io.h index b64603b..faeade4 100644 --- a/include/libft_io.h +++ b/include/libft_io.h @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:35:43 by cacharle #+# #+# */ -/* Updated: 2020/05/11 16:12:41 by charles ### ########.fr */ +/* Updated: 2020/05/12 18:00:55 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -43,7 +43,7 @@ typedef struct s_ftmem int ft_getfile(int fd, t_ftmem *mem); # ifndef FT_GETLINE_BUFFER_SIZE -# define FT_GETLINE_BUFFER_SIZE 64 +# define FT_GETLINE_BUFFER_SIZE 1 # endif # define FT_LINE 1 diff --git a/include/libft_vec.h b/include/libft_vec.h index a5f22dd..c31b36e 100644 --- a/include/libft_vec.h +++ b/include/libft_vec.h @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/01 18:57:16 by charles #+# #+# */ -/* Updated: 2020/05/10 21:09:25 by charles ### ########.fr */ +/* Updated: 2020/05/12 18:36:00 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,6 +44,7 @@ t_ftvec *ft_vecpush(t_ftvec *vec, void *pushed); t_ftvec *ft_vecpush_safe(t_ftvec *vec, void *pushed); void ft_vecpop(t_ftvec *vec, void (*del)(void *elem)); void ft_veciter(t_ftvec *vec, void (*f)(void *elem)); +void ft_veciter_ret(t_ftvec *vec, void *(*f)(void *elem)); void ft_vecremove(t_ftvec *vec, size_t i, void (*del)(void *elem)); t_ftvec *ft_vecinsert(t_ftvec *vec, size_t i, void *elem); void ft_vecsort(t_ftvec *vec, t_ftcompar_func cmp); diff --git a/src/io/ft_getline.c b/src/io/ft_getline.c index 4cf3962..d59aa63 100644 --- a/src/io/ft_getline.c +++ b/src/io/ft_getline.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/01/31 10:39:38 by cacharle #+# #+# */ -/* Updated: 2020/05/09 11:19:12 by charles ### ########.fr */ +/* Updated: 2020/05/12 17:56:59 by charles ### ########.fr */ /* */ /* ************************************************************************** */ @@ -88,7 +88,7 @@ int ft_getline(int fd, char **line) int split_at; static char rest[OPEN_MAX][FT_GETLINE_BUFFER_SIZE + 1] = {{0}}; - if (fd < 0 || fd > OPEN_MAX || line == NULL || FT_GETLINE_BUFFER_SIZE <= 0) + if (fd < 0 || fd > OPEN_MAX || line == NULL) return (FT_ERROR); if ((*line = ft_strdup("")) == NULL) return (FT_ERROR); diff --git a/src/vec/ft_veciter_ret.c b/src/vec/ft_veciter_ret.c new file mode 100644 index 0000000..ddeedcf --- /dev/null +++ b/src/vec/ft_veciter_ret.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_veciter_ret.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: charles +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/05/12 18:33:34 by charles #+# #+# */ +/* Updated: 2020/05/12 18:35:48 by charles ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_vec.h" + +/* +** \brief Iterate a function over elements of a vector, +** pointer can be changed +** \param vec Iterated vector +** \param f Function applied to each elements, +** returned value is the new pointer value +*/ + +void ft_veciter_ret(t_ftvec *vec, void *(*f)(void *elem)) +{ + size_t i; + + i = 0; + while (i < vec->size) + { + vec->data[i] = f(vec->data[i]); + i++; + } +} -- cgit