From 5cb8d465bf1f436e4f72bca642433d313ab7a9c3 Mon Sep 17 00:00:00 2001 From: gbaconni Date: Tue, 26 Apr 2022 12:13:32 +0200 Subject: [PATCH] Add ft_eoflags to replace ft_skipchars. Improve Makefile --- Makefile | 21 ++++++++++++-------- libftprintf/Makefile | 3 ++- libftprintf/ft_eoflags.c | 40 +++++++++++++++++++++++++++++++++++++++ libftprintf/ft_vprintf.c | 4 ++-- libftprintf/libftprintf.h | 3 ++- 5 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 libftprintf/ft_eoflags.c diff --git a/Makefile b/Makefile index e12e00b..1e1f1ce 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/01/18 15:11:16 by gbaconni #+# #+# # -# Updated: 2022/04/25 22:39:57 by gbaconni ### lausanne.ch # +# Updated: 2022/04/26 12:11:46 by gbaconni ### ########.fr # # # # **************************************************************************** # # @@ -41,15 +41,15 @@ endif ifeq ($(DEBUG), 1) CFLAGS += -g -O0 -fsanitize=address -fsanitize=undefined -fsanitize=signed-integer-overflow endif -ifeq ($(LEAK), 1) - CFLAGS += -g -O0 -endif VALGRIND = valgrind VALGRINDFLAGS = --quiet --leak-check=full --show-leak-kinds=all ifeq ($(LEAK), 1) + CFLAGS += -g -O0 PREFIX += $(VALGRIND) $(VALGRINDFLAGS) endif +KERNEL = $(shell uname -s) +MACHINE = $(shell uname -m) RM = rm RMFLAGS = -f @@ -103,13 +103,15 @@ test: clean $(NAME) @$(PREFIX) ./$(NAME) "\t\r\n" "" @$(PREFIX) ./$(NAME) "%1d" 42 +ifeq ($(KERNEL),Linux) test2: leak @$(MAKE) test LEAK=1 - -test3: debug +else +test2: debug @$(MAKE) test DEBUG=1 +endif -test4: fast +test3: fast @$(MAKE) test FAST=1 test42: clean $(NAME) @@ -122,7 +124,10 @@ test42: clean $(NAME) @$(PREFIX) ./$(NAME) "floats: %4.2f %+.0e %E \n" 3.1416 3.1416 3.1416 @$(PREFIX) ./$(NAME) "Width trick: %*d \n" 5 10 @$(PREFIX) ./$(NAME) "%s \n" "A string" - + +watch: + @read -p "cmd: " cmd; while :; do clear; date "+%F %T"; echo; $${cmd} 2>&1 | tail -n 20; sleep 2; done + doc: @curl -s -L -z fr.subject.pdf -o fr.subject.pdf $(PDF_FR) @curl -s -L -z en.subject.pdf -o en.subject.pdf $(PDF_EN) diff --git a/libftprintf/Makefile b/libftprintf/Makefile index 75acaee..c39a0e7 100644 --- a/libftprintf/Makefile +++ b/libftprintf/Makefile @@ -6,7 +6,7 @@ # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2022/01/18 15:11:16 by gbaconni #+# #+# # -# Updated: 2022/04/25 22:40:27 by gbaconni ### lausanne.ch # +# Updated: 2022/04/26 10:42:02 by gbaconni ### ########.fr # # # # **************************************************************************** # # @@ -30,6 +30,7 @@ SRC = \ $(LIBFT)/ft_calloc.c \ $(LIBFT)/ft_strlen.c \ $(LIBFT)/ft_itoa.c \ + ft_eoflags.c \ ft_skipchars.c \ ft_strrev.c \ ft_ltoa_base.c \ diff --git a/libftprintf/ft_eoflags.c b/libftprintf/ft_eoflags.c new file mode 100644 index 0000000..8809ac8 --- /dev/null +++ b/libftprintf/ft_eoflags.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_eoflags.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/04/26 10:13:59 by gbaconni #+# #+# */ +/* Updated: 2022/04/26 12:00:16 by gbaconni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libftprintf.h" + +int ft_eoflags(const char *s) +{ + int ret; + int i; + const char *chars = "cspdiuxX%"; + + ret = 0; + if (s == NULL) + return (ret); + while (*s != '\0') + { + i = 0; + while (chars[i] != '\0') + { + if (chars[i] == *s) + break ; + i++; + } + if (chars[i] != *s) + ret++; + else + break ; + s++; + } + return (ret); +} diff --git a/libftprintf/ft_vprintf.c b/libftprintf/ft_vprintf.c index 7824431..3ff920f 100644 --- a/libftprintf/ft_vprintf.c +++ b/libftprintf/ft_vprintf.c @@ -6,7 +6,7 @@ /* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/20 11:43:52 by gbaconni #+# #+# */ -/* Updated: 2022/04/25 12:48:04 by gbaconni ### lausanne.ch */ +/* Updated: 2022/04/26 12:04:14 by gbaconni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,7 +24,7 @@ int ft_vprintf(char const *format, va_list ap) if (*fmt == '%') { fmt++; - fmt += ft_skipchars(fmt, "0123456789+-.# +"); + fmt += ft_eoflags(fmt); ret += ft_vprintf_percent(fmt, ap); } else diff --git a/libftprintf/libftprintf.h b/libftprintf/libftprintf.h index d4632bb..38c3877 100644 --- a/libftprintf/libftprintf.h +++ b/libftprintf/libftprintf.h @@ -6,7 +6,7 @@ /* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/01/18 15:26:06 by gbaconni #+# #+# */ -/* Updated: 2022/04/25 13:18:21 by gbaconni ### lausanne.ch */ +/* Updated: 2022/04/26 10:41:36 by gbaconni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,6 +25,7 @@ /* Helper */ +int ft_eoflags(const char *s); int ft_skipchars(const char *s, char *chars); char *ft_strrev(char *s); char *ft_ltoa_base(long n, char *base);