Add ft_vprintf_precision_bonus and define HEXA_LOWER HEXA_UPPER
This commit is contained in:
5
Makefile
5
Makefile
@@ -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/29 09:33:14 by gbaconni ### ########.fr #
|
# Updated: 2022/04/29 10:12:47 by gbaconni ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
#
|
#
|
||||||
@@ -41,6 +41,9 @@ 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 ($(BONUS), 1)
|
||||||
|
CFLAGS += -D BONUS=1
|
||||||
|
endif
|
||||||
|
|
||||||
VALGRIND = valgrind
|
VALGRIND = valgrind
|
||||||
VALGRINDFLAGS = --quiet --leak-check=full --show-leak-kinds=all
|
VALGRINDFLAGS = --quiet --leak-check=full --show-leak-kinds=all
|
||||||
|
|||||||
@@ -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/29 09:33:55 by gbaconni ### ########.fr #
|
# Updated: 2022/04/29 10:20:22 by gbaconni ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
#
|
#
|
||||||
@@ -50,7 +50,8 @@ SRC = \
|
|||||||
ft_printf.c
|
ft_printf.c
|
||||||
|
|
||||||
SRC_BONUS = \
|
SRC_BONUS = \
|
||||||
ft_vprintf_flags_bonus.c
|
ft_vprintf_flags_bonus.c \
|
||||||
|
ft_vprintf_precision_bonus.c
|
||||||
|
|
||||||
OBJ = ${SRC:.c=.o}
|
OBJ = ${SRC:.c=.o}
|
||||||
OBJ_BONUS = ${SRC_BONUS:.c=.o}
|
OBJ_BONUS = ${SRC_BONUS:.c=.o}
|
||||||
@@ -67,6 +68,9 @@ 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 ($(BONUS), 1)
|
||||||
|
CFLAGS += -D BONUS=1
|
||||||
|
endif
|
||||||
|
|
||||||
VALGRIND = valgrind
|
VALGRIND = valgrind
|
||||||
VALGRINDFLAGS = --quiet --leak-check=full --show-leak-kinds=all
|
VALGRINDFLAGS = --quiet --leak-check=full --show-leak-kinds=all
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/01/20 11:55:02 by gbaconni #+# #+# */
|
/* Created: 2022/01/20 11:55:02 by gbaconni #+# #+# */
|
||||||
/* Updated: 2022/04/29 09:09:08 by gbaconni ### lausanne.ch */
|
/* Updated: 2022/04/29 10:59:23 by gbaconni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -32,22 +32,10 @@ int ft_vprintf_decimal(const char *format, va_list ap)
|
|||||||
d = va_arg(ap, int);
|
d = va_arg(ap, int);
|
||||||
s = ft_itoa(d);
|
s = ft_itoa(d);
|
||||||
}
|
}
|
||||||
|
#ifdef BONUS
|
||||||
const char *f;
|
|
||||||
int flags;
|
|
||||||
int precision;
|
int precision;
|
||||||
int len;
|
int len;
|
||||||
precision = 0;
|
precision = ft_vprintf_precision_bonus(format, ap);
|
||||||
flags = ft_vprintf_flags_bonus(format, ap);
|
|
||||||
f = format;
|
|
||||||
while (*f != '\0')
|
|
||||||
{
|
|
||||||
if (ft_isdigit(*f))
|
|
||||||
precision = precision * 10 + *f - '0';
|
|
||||||
if (ft_strchr(SPECIFIERS, *f) != NULL)
|
|
||||||
break ;
|
|
||||||
f++;
|
|
||||||
}
|
|
||||||
len = 0;
|
len = 0;
|
||||||
if (precision > 0)
|
if (precision > 0)
|
||||||
{
|
{
|
||||||
@@ -60,7 +48,7 @@ int ft_vprintf_decimal(const char *format, va_list ap)
|
|||||||
ret += ft_putchar(' ');
|
ret += ft_putchar(' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
ret += ft_puts(s);
|
ret += ft_puts(s);
|
||||||
free(s);
|
free(s);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/01/20 11:55:33 by gbaconni #+# #+# */
|
/* Created: 2022/01/20 11:55:33 by gbaconni #+# #+# */
|
||||||
/* Updated: 2022/04/26 17:33:12 by gbaconni ### ########.fr */
|
/* Updated: 2022/04/29 10:58:24 by gbaconni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -18,18 +18,18 @@ int ft_vprintf_hexadecimal(const char *format, va_list ap)
|
|||||||
long l;
|
long l;
|
||||||
char *s;
|
char *s;
|
||||||
char c;
|
char c;
|
||||||
int flags;
|
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
l = va_arg(ap, long);
|
l = va_arg(ap, long);
|
||||||
c = *format;
|
c = *format;
|
||||||
if (c == 'x')
|
if (c == 'x')
|
||||||
s = ft_ltoa_base(l, "0123456789abcdef");
|
s = ft_ltoa_base(l, HEXA_LOWER);
|
||||||
else
|
else
|
||||||
s = ft_ltoa_base(l, "0123456789ABCDEF");
|
s = ft_ltoa_base(l, HEXA_UPPER);
|
||||||
flags = ft_vprintf_flags_bonus(format, ap);
|
#ifdef BONUS
|
||||||
if (flags & F_HASH)
|
if (ft_vprintf_flags_bonus(format, ap) & F_HASH)
|
||||||
ret += ft_puts("0x");
|
ret += ft_puts("0x");
|
||||||
|
#endif
|
||||||
ret += ft_puts(s);
|
ret += ft_puts(s);
|
||||||
free(s);
|
free(s);
|
||||||
return (ret);
|
return (ret);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/01/20 11:56:16 by gbaconni #+# #+# */
|
/* Created: 2022/01/20 11:56:16 by gbaconni #+# #+# */
|
||||||
/* Updated: 2022/04/26 13:53:06 by gbaconni ### ########.fr */
|
/* Updated: 2022/04/29 10:59:11 by gbaconni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ int ft_vprintf_pointer(const char *format, va_list ap)
|
|||||||
ret = ft_puts(NIL);
|
ret = ft_puts(NIL);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
s = ft_ltoa_base((long) p, "0123456789abcdef");
|
s = ft_ltoa_base((long) p, HEXA_LOWER);
|
||||||
ret += ft_puts("0x");
|
ret += ft_puts("0x");
|
||||||
ret += ft_puts(s);
|
ret += ft_puts(s);
|
||||||
free(s);
|
free(s);
|
||||||
|
|||||||
31
libftprintf/ft_vprintf_precision_bonus.c
Normal file
31
libftprintf/ft_vprintf_precision_bonus.c
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_vprintf_string.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
|
||||||
|
/* Updated: 2022/04/29 10:21:31 by gbaconni ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libftprintf.h"
|
||||||
|
|
||||||
|
int ft_vprintf_precision_bonus(const char *format, va_list ap)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
const char *f;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
f = format;
|
||||||
|
while (*f != '\0')
|
||||||
|
{
|
||||||
|
if (ft_isdigit(*f))
|
||||||
|
ret = ret * 10 + *f - '0';
|
||||||
|
if (ft_strchr(SPECIFIERS, *f) != NULL)
|
||||||
|
break ;
|
||||||
|
f++;
|
||||||
|
}
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
/* By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
|
/* Created: 2022/01/20 11:56:37 by gbaconni #+# #+# */
|
||||||
/* Updated: 2022/04/29 09:03:47 by gbaconni ### lausanne.ch */
|
/* Updated: 2022/04/29 10:52:32 by gbaconni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -25,29 +25,17 @@ int ft_vprintf_string(const char *format, va_list ap)
|
|||||||
ret = ft_puts("(null)");
|
ret = ft_puts("(null)");
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
#ifdef BONUS
|
||||||
const char *f;
|
|
||||||
int precision;
|
int precision;
|
||||||
int len;
|
int len;
|
||||||
int flags;
|
precision = ft_vprintf_precision_bonus(format, ap);
|
||||||
precision = 0;
|
|
||||||
flags = ft_vprintf_flags_bonus(format, ap);
|
|
||||||
(void) flags;
|
|
||||||
f = format;
|
|
||||||
while (*f != '\0')
|
|
||||||
{
|
|
||||||
if (ft_isdigit(*f))
|
|
||||||
precision = precision * 10 + *f - '0';
|
|
||||||
if (ft_strchr(SPECIFIERS, *f) != NULL)
|
|
||||||
break ;
|
|
||||||
f++;
|
|
||||||
}
|
|
||||||
if (precision > 0)
|
if (precision > 0)
|
||||||
{
|
{
|
||||||
len = precision - ft_strlen(s);
|
len = precision - ft_strlen(s);
|
||||||
while (len-- > 0)
|
while (len-- > 0)
|
||||||
ret += ft_putchar(' ');
|
ret += ft_putchar(' ');
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
ret += ft_puts(s);
|
ret += ft_puts(s);
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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/29 08:56:40 by gbaconni ### lausanne.ch */
|
/* Updated: 2022/04/29 10:58:37 by gbaconni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -17,13 +17,17 @@
|
|||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
|
||||||
# if defined (__APPLE__)
|
/* Constants */
|
||||||
|
|
||||||
|
# ifdef __APPLE__
|
||||||
# define NIL "0x0"
|
# define NIL "0x0"
|
||||||
# else
|
# else
|
||||||
# define NIL "(nil)"
|
# define NIL "(nil)"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# define SPECIFIERS "cspdiuxX%"
|
# define SPECIFIERS "cspdiuxX%"
|
||||||
|
# define HEXA_LOWER "0123456789abcdef"
|
||||||
|
# define HEXA_UPPER "0123456789ABCDEF"
|
||||||
|
|
||||||
/* Helper */
|
/* Helper */
|
||||||
|
|
||||||
@@ -48,6 +52,7 @@ int ft_vprintf_percent(const char *format, va_list ap);
|
|||||||
int ft_vprintf_escape(const char *format, va_list ap);
|
int ft_vprintf_escape(const char *format, va_list ap);
|
||||||
int ft_vprintf_other(const char *format, va_list ap);
|
int ft_vprintf_other(const char *format, va_list ap);
|
||||||
|
|
||||||
|
# ifdef BONUS
|
||||||
/* Bonus */
|
/* Bonus */
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -58,6 +63,8 @@ enum {
|
|||||||
F_PLUS = 1 << 4
|
F_PLUS = 1 << 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int ft_vprintf_precision_bonus(const char *format, va_list ap);
|
||||||
int ft_vprintf_flags_bonus(const char *format, va_list ap);
|
int ft_vprintf_flags_bonus(const char *format, va_list ap);
|
||||||
|
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,26 +6,58 @@
|
|||||||
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
|
# By: gbaconni@student.42lausanne.ch +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2022/04/16 20:12:38 by gbaconni #+# #+# #
|
# Created: 2022/04/16 20:12:38 by gbaconni #+# #+# #
|
||||||
# Updated: 2022/04/16 20:22:22 by gbaconni ### lausanne.ch #
|
# Updated: 2022/04/29 10:00:15 by gbaconni ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
UNAME_S = $(shell uname -s)
|
KERNEL = $(shell uname -s)
|
||||||
|
MACHINE = $(shell uname -m)
|
||||||
|
|
||||||
all: test
|
all: test
|
||||||
|
|
||||||
libftprintf.a:
|
libftprintf.a: libftprintf
|
||||||
@ln -snf ../libftprintf/libftprintf.a libftprintf.a
|
@ln -snf ../libftprintf/libftprintf.a libftprintf.a
|
||||||
|
|
||||||
|
libftprintf:
|
||||||
|
@make -C ../libftprintf bonus
|
||||||
|
|
||||||
|
bonus: test-pft
|
||||||
|
|
||||||
test: test-pft
|
test: test-pft
|
||||||
|
|
||||||
test-pft: libftprintf.a
|
test2: test-pft2
|
||||||
|
|
||||||
|
test3: test-pft3
|
||||||
|
|
||||||
|
test-pft:
|
||||||
|
@cd pft && ./test mix
|
||||||
|
|
||||||
|
test-pft2:
|
||||||
|
@cd pft && ./test
|
||||||
|
|
||||||
|
test-pft3:
|
||||||
|
@cd pft && ./test c
|
||||||
|
@cd pft && ./test s
|
||||||
|
@cd pft && ./test p
|
||||||
|
@cd pft && ./test d
|
||||||
|
@cd pft && ./test i
|
||||||
|
@cd pft && ./test u
|
||||||
|
@cd pft && ./test x
|
||||||
|
@cd pft && ./test X
|
||||||
|
|
||||||
|
pft: libftprintf.a
|
||||||
@test -d pft || git clone https://github.com/gavinfielder/pft.git pft
|
@test -d pft || git clone https://github.com/gavinfielder/pft.git pft
|
||||||
ifeq ($(UNAME_S),Linux)
|
ifeq ($(KERNEL),Linux)
|
||||||
@which php >/dev/null 2>&1 || sudo apt-get install -qq -y php-cli
|
@which php >/dev/null 2>&1 || sudo apt-get install -qq -y php-cli
|
||||||
@sed -i -r 's/^(INCLUDE_LIBPTHREAD)=.*/\1=1/' pft/options-config.ini
|
@sed -i -r 's/^(INCLUDE_LIBPTHREAD)=.*/\1=1/' pft/options-config.ini
|
||||||
|
endif
|
||||||
|
ifeq ($(KERNEL),Darwin)
|
||||||
endif
|
endif
|
||||||
@make -C pft
|
@make -C pft
|
||||||
@cd pft && ./test
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@make -C pft clean
|
||||||
|
|
||||||
|
fclean:
|
||||||
|
@rm -fr pft
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user