Add ft_eoflags to replace ft_skipchars. Improve Makefile

This commit is contained in:
gbaconni
2022-04-26 12:13:32 +02:00
parent c20463e27a
commit 5cb8d465bf
5 changed files with 59 additions and 12 deletions

View File

@@ -6,7 +6,7 @@
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/01/18 15:11:16 by gbaconni #+# #+# # # 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) ifeq ($(DEBUG), 1)
CFLAGS += -g -O0 -fsanitize=address -fsanitize=undefined -fsanitize=signed-integer-overflow CFLAGS += -g -O0 -fsanitize=address -fsanitize=undefined -fsanitize=signed-integer-overflow
endif endif
ifeq ($(LEAK), 1)
CFLAGS += -g -O0
endif
VALGRIND = valgrind VALGRIND = valgrind
VALGRINDFLAGS = --quiet --leak-check=full --show-leak-kinds=all VALGRINDFLAGS = --quiet --leak-check=full --show-leak-kinds=all
ifeq ($(LEAK), 1) ifeq ($(LEAK), 1)
CFLAGS += -g -O0
PREFIX += $(VALGRIND) $(VALGRINDFLAGS) PREFIX += $(VALGRIND) $(VALGRINDFLAGS)
endif endif
KERNEL = $(shell uname -s)
MACHINE = $(shell uname -m)
RM = rm RM = rm
RMFLAGS = -f RMFLAGS = -f
@@ -103,13 +103,15 @@ test: clean $(NAME)
@$(PREFIX) ./$(NAME) "\t\r\n" "" @$(PREFIX) ./$(NAME) "\t\r\n" ""
@$(PREFIX) ./$(NAME) "%1d" 42 @$(PREFIX) ./$(NAME) "%1d" 42
ifeq ($(KERNEL),Linux)
test2: leak test2: leak
@$(MAKE) test LEAK=1 @$(MAKE) test LEAK=1
else
test3: debug test2: debug
@$(MAKE) test DEBUG=1 @$(MAKE) test DEBUG=1
endif
test4: fast test3: fast
@$(MAKE) test FAST=1 @$(MAKE) test FAST=1
test42: clean $(NAME) 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) "floats: %4.2f %+.0e %E \n" 3.1416 3.1416 3.1416
@$(PREFIX) ./$(NAME) "Width trick: %*d \n" 5 10 @$(PREFIX) ./$(NAME) "Width trick: %*d \n" 5 10
@$(PREFIX) ./$(NAME) "%s \n" "A string" @$(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: doc:
@curl -s -L -z fr.subject.pdf -o fr.subject.pdf $(PDF_FR) @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) @curl -s -L -z en.subject.pdf -o en.subject.pdf $(PDF_EN)

View File

@@ -6,7 +6,7 @@
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ # # By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2022/01/18 15:11:16 by gbaconni #+# #+# # # 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_calloc.c \
$(LIBFT)/ft_strlen.c \ $(LIBFT)/ft_strlen.c \
$(LIBFT)/ft_itoa.c \ $(LIBFT)/ft_itoa.c \
ft_eoflags.c \
ft_skipchars.c \ ft_skipchars.c \
ft_strrev.c \ ft_strrev.c \
ft_ltoa_base.c \ ft_ltoa_base.c \

40
libftprintf/ft_eoflags.c Normal file
View File

@@ -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);
}

View File

@@ -6,7 +6,7 @@
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */ /* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/20 11:43:52 by gbaconni #+# #+# */ /* 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 == '%') if (*fmt == '%')
{ {
fmt++; fmt++;
fmt += ft_skipchars(fmt, "0123456789+-.# +"); fmt += ft_eoflags(fmt);
ret += ft_vprintf_percent(fmt, ap); ret += ft_vprintf_percent(fmt, ap);
} }
else else

View File

@@ -6,7 +6,7 @@
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */ /* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/18 15:26:06 by gbaconni #+# #+# */ /* 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 */ /* Helper */
int ft_eoflags(const char *s);
int ft_skipchars(const char *s, char *chars); int ft_skipchars(const char *s, char *chars);
char *ft_strrev(char *s); char *ft_strrev(char *s);
char *ft_ltoa_base(long n, char *base); char *ft_ltoa_base(long n, char *base);