aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile6
-rw-r--r--convert_str.c4
-rw-r--r--extract.c10
-rw-r--r--ft_printf.c126
-rw-r--r--header.h46
-rw-r--r--length_modifier.c6
-rw-r--r--main.c129
-rw-r--r--parse.c8
-rw-r--r--printer.c22
-rwxr-xr-xtestbin23228 -> 28784 bytes
-rw-r--r--utils.c27
11 files changed, 219 insertions, 165 deletions
diff --git a/Makefile b/Makefile
index 372da0b..9c7dbc1 100644
--- a/Makefile
+++ b/Makefile
@@ -6,14 +6,14 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/28 17:41:14 by cacharle #+# #+# #
-# Updated: 2019/11/06 00:00:19 by cacharle ### ########.fr #
+# Updated: 2019/11/09 01:06:42 by cacharle ### ########.fr #
# #
# **************************************************************************** #
LIBFT_ROOT = ./libft
CC = gcc
-CCFLAGS = -Wall -Wextra #-Werror
+CCFLAGS = -Wall -Wextra -g #-Werror
LDFLAGS = -L. -lftprintf
INCFLAGS = -I$(LIBFT_ROOT)
@@ -25,7 +25,7 @@ NAME = libftprintf.a
SRC = ft_printf.c utils.c printer.c parse.c list.c extract.c \
convert_int.c convert_uint.c convert_char.c convert_str.c \
convert_ptr.c convert_hex.c convert_percent.c convert_written.c \
- convert_none.c length_modifier.c
+ convert_none.c length_modifier.c parse_double.c convert_double.c
OBJ = $(SRC:.c=.o)
INCLUDE = header.h
diff --git a/convert_str.c b/convert_str.c
index 5bba1b1..42bf851 100644
--- a/convert_str.c
+++ b/convert_str.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/30 23:22:25 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:43:57 by cacharle ### ########.fr */
+/* Updated: 2019/11/09 01:07:24 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,7 @@ char *convert_str(va_list ap, t_pformat *pformat)
str = va_arg(ap, char*);
str = str == NULL ? ft_strdup("(null)") : ft_strdup(str);
- if (pformat->precision != -1 && pformat->precision < (int)ft_strlen(str))
+ if (pformat->precision >= 0 && pformat->precision < (int)ft_strlen(str))
str[pformat->precision] = '\0';
str = handle_width(pformat, str);
return (str);
diff --git a/extract.c b/extract.c
index 365f73f..d906536 100644
--- a/extract.c
+++ b/extract.c
@@ -6,13 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:10:36 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:43:33 by cacharle ### ########.fr */
+/* Updated: 2019/11/10 10:33:33 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
-char *extract_flags(t_pformat *pformat, char *fmt)
+const char *extract_flags(t_pformat *pformat, const char *fmt)
{
if (*fmt == '\0')
return (fmt);
@@ -37,7 +37,7 @@ char *extract_flags(t_pformat *pformat, char *fmt)
return (fmt);
}
-char *extract_width(t_pformat *pformat, char *fmt)
+const char *extract_width(t_pformat *pformat, const char *fmt)
{
if (*fmt == '\0')
return (fmt);
@@ -56,7 +56,7 @@ char *extract_width(t_pformat *pformat, char *fmt)
return (fmt);
}
-char *extract_precision(t_pformat *pformat, char *fmt)
+const char *extract_precision(t_pformat *pformat, const char *fmt)
{
if (*fmt == '\0' || *fmt != '.')
return (fmt);
@@ -72,7 +72,7 @@ char *extract_precision(t_pformat *pformat, char *fmt)
return (fmt);
}
-char *extract_length_modifier(t_pformat *pformat, char *fmt)
+const char *extract_length_modifier(t_pformat *pformat, const char *fmt)
{
if (fmt[0] && fmt[0] == 'l')
{
diff --git a/ft_printf.c b/ft_printf.c
index da9a14a..c4df9b7 100644
--- a/ft_printf.c
+++ b/ft_printf.c
@@ -6,67 +6,87 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:15:28 by cacharle #+# #+# */
-/* Updated: 2019/11/06 00:01:32 by cacharle ### ########.fr */
+/* Updated: 2019/11/13 08:56:49 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
-int ft_printf(const char *format, ...)
+int ft_printf(const char *format, ...)
{
- va_list ap;
- t_flist *flist;
- char *str;
- int print_len;
- int i;
+ t_printf_status status;
if (format == NULL)
- return (-1);
- str = ft_strdup(format);
- if (!parse(str, &flist))
- return (-1);
- free(str);
- va_start(ap, format);
- print_len = 0;
- i = -1;
- while (format[++i])
+ return (STATUS_ERROR);
+ if (!parse(format, &status.flist))
+ return (STATUS_ERROR);
+ va_start(status.ap, format);
+ status.format = format;
+ status.out = NULL;
+ status.out_size = 0;
+ while (*status.format)
{
- if (format[i] != '%')
- {
- write(STDOUT_FILENO, format + i, 1);
- print_len++;
- continue ;
- }
- str = convert(flist->content, ap);
- if (str == NULL && flist->content->specifier == 'n')
- {
- if (flist->content->written != NULL)
- *flist->content->written = print_len;
- i += flist->content->fmt_len;
- list_pop_front(&flist);
- continue;
- }
- if (str == NULL)
- {
- list_destroy(&flist);
- return (-1);
- }
- if (flist->content->specifier == 'c')
- {
- write(1, str, flist->content->size);
- print_len++;
- free(str);
- }
- else
- {
- ft_putstr(str);
- print_len += ft_strlen(str);
- free(str);
- }
- i += flist->content->fmt_len;
- list_pop_front(&flist);
+ if (*status.format == '%'
+ && (status.format =
+ add_conversion(&status, status.flist->content)) == NULL)
+ return (destroy_status_error(&status));
+ else if ((status.format = add_between(&status)) == NULL)
+ return (destroy_status_error(&status));
}
- list_destroy(&flist);
- va_end(ap);
- return (print_len);
+ va_end(status.ap);
+ list_destroy(&status.flist);
+ write(STDOUT_FILENO, status.out, status.out_size);
+ free(status.out);
+ return (status.out_size);
+}
+
+const char *add_conversion(t_printf_status *status, t_pformat *pformat)
+{
+ char *conversion_str;
+
+ conversion_str = convert(pformat, status->ap);
+ if (pformat->specifier == 'n')
+ {
+ if (pformat->written != NULL)
+ *pformat->written = status->out_size;
+ status->format += pformat->fmt_len;
+ list_pop_front(&status->flist);
+ return (status->format + 1);
+ }
+ if (conversion_str == NULL)
+ return (NULL);
+ if (pformat->specifier != 'c')
+ pformat->size = ft_strlen(conversion_str);
+ if ((status->out = ft_memjoin_free(status->out, status->out_size,
+ conversion_str, pformat->size)) == NULL)
+ return (NULL);
+ status->out_size += pformat->size;
+ free(conversion_str);
+ status->format += pformat->fmt_len;
+ list_pop_front(&status->flist);
+ return (status->format + 1);
+}
+
+const char *add_between(t_printf_status *status)
+{
+ int i;
+
+ i = 0;
+ while (status->format[i] && status->format[i] != '%')
+ i++;
+ if ((status->out = ft_memjoin_free(status->out, status->out_size,
+ (void*)status->format, i)) == NULL)
+ return (NULL);
+ status->out_size += i;
+ return (status->format + i);
+}
+
+int destroy_status_error(t_printf_status *status)
+{
+ if (status == NULL)
+ return (STATUS_ERROR);
+ va_end(status->ap);
+ list_destroy(&status->flist);
+ free(status->out);
+ return (STATUS_ERROR);
}
diff --git a/header.h b/header.h
index cb1789f..e76884a 100644
--- a/header.h
+++ b/header.h
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:06:46 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:58:48 by cacharle ### ########.fr */
+/* Updated: 2019/11/13 08:57:56 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,7 +18,9 @@
# include <stdarg.h>
# include "libft.h"
-# define SPECIFIERS_STR "ncspdiuxX%"
+# define STATUS_ERROR -1
+
+# define SPECIFIERS_STR "nfcspdiuxX%"
# define FLAGS_STR "#0- +'"
# define IS_STANDALONE_FLAG(c) (ft_strchr(FLAGS_STR, c) != NULL)
@@ -40,8 +42,10 @@
# define ITOA_HEX_UP(x) (ft_itoa_unsigned_base(x, "0123456789ABCDEF"))
# define ITOA_DEC(x) (ft_itoa_base(x, "0123456789"))
-typedef int t_bool;
-typedef short t_flags;
+typedef int t_bool;
+typedef short t_flags;
+typedef long long int t_big_int;
+typedef long long unsigned int t_big_uint;
typedef struct
{
@@ -60,18 +64,31 @@ typedef struct s_flist
t_pformat *content;
} t_flist;
+typedef struct
+{
+ va_list ap;
+ t_flist *flist;
+ const char *format;
+ char *out;
+ int out_size;
+} t_printf_status;
+
/*
** ft_printf.c
*/
int ft_printf(const char *format, ...);
+const char *add_conversion(t_printf_status *status,
+ t_pformat *pformat);
+const char *add_between(t_printf_status *status);
+int destroy_status_error(t_printf_status *status);
/*
** parse.c
*/
-int parse(char *format, t_flist **flist);
-t_pformat *parse_reduced(char *fmt);
+int parse(const char *format, t_flist **flist);
+t_pformat *parse_reduced(const char *fmt);
/*
** printer.c
@@ -89,16 +106,18 @@ char *handle_precision(t_pformat *pformat, char *str);
char *ft_itoa_base(long long int n, char *base);
char *ft_itoa_unsigned_base(long long unsigned int n,
char *base);
-char *ft_strtoupper(char *str);
+void *ft_memjoin_free(void *dst, int dst_size, void *src,
+ int src_size);
/*
** extract.c
*/
-char *extract_flags(t_pformat *pformat, char *fmt);
-char *extract_width(t_pformat *pformat, char *fmt);
-char *extract_precision(t_pformat *pformat, char *fmt);
-char *extract_length_modifier(t_pformat *pformat, char *fmt);
+const char *extract_flags(t_pformat *pformat, const char *fmt);
+const char *extract_width(t_pformat *pformat, const char *fmt);
+const char *extract_precision(t_pformat *pformat, const char *fmt);
+const char *extract_length_modifier(t_pformat *pformat,
+ const char *fmt);
/*
** list.c
@@ -122,14 +141,15 @@ char *convert_uint(va_list ap, t_pformat *pformat);
char *convert_hex(va_list ap, t_pformat *pformat);
char *convert_percent(va_list ap, t_pformat *pformat);
char *convert_written(va_list ap, t_pformat *pformat);
+char *convert_double(va_list ap, t_pformat *pformat);
char *convert_none(va_list ap, t_pformat *pformat);
/*
** length_modifier.c
*/
-long long unsigned int length_modifier_unsigned_int(
+t_big_uint length_modifier_unsigned_int(
va_list ap, t_pformat *pformat);
-long long int length_modifier_int(va_list ap, t_pformat *pformat);
+t_big_int length_modifier_int(va_list ap, t_pformat *pformat);
#endif
diff --git a/length_modifier.c b/length_modifier.c
index f39fde3..a725cfb 100644
--- a/length_modifier.c
+++ b/length_modifier.c
@@ -6,13 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/05 23:56:07 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:58:24 by cacharle ### ########.fr */
+/* Updated: 2019/11/09 00:50:06 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
-long long unsigned int length_modifier_unsigned_int(va_list ap, t_pformat *pformat)
+t_big_uint length_modifier_unsigned_int(va_list ap, t_pformat *pformat)
{
if (pformat->flags & FLAG_SHORT)
return ((unsigned short)va_arg(ap, int));
@@ -25,7 +25,7 @@ long long unsigned int length_modifier_unsigned_int(va_list ap, t_pformat *pform
return (va_arg(ap, unsigned int));
}
-long long int length_modifier_int(va_list ap, t_pformat *pformat)
+t_big_int length_modifier_int(va_list ap, t_pformat *pformat)
{
if (pformat->flags & FLAG_SHORT)
return ((short)va_arg(ap, int));
diff --git a/main.c b/main.c
index a39ad5f..bb0be59 100644
--- a/main.c
+++ b/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/28 04:25:09 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:45:26 by cacharle ### ########.fr */
+/* Updated: 2019/11/13 08:50:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,21 +15,7 @@
int main()
{
- int test = 42;
-
- /* ft_printf("% 63.108d%14p%03.i%106.19u%*.31s% 84.i%-122.78i%*c%32c%035.d" ,541752262,(void*)9603300624406182979lu,-346423835,2885566767u,-54,"0BG\td~l%",-1237089009,1122784046,-158,-7,66,1034929054); */
- /* printf("% 63.108d%14p%03.i%106.19u%*.31s% 84.i%-122.78i%*c%32c%035.d" ,541752262,(void*)9603300624406182979lu,-346423835,2885566767u,-54,"0BG\td~l%",-1237089009,1122784046,-158,-7,66,1034929054); */
- /* printf("{%*3d}", 5, 0); */
- /* printf("{%*c}\n", -15, 0); */
- /* ft_printf("{%*c}\n", -15, 0); */
- /* ft_printf("%-72.170%%183.84x%174.189x%0+0'191.159s%107.*i%0#0+ 12.162c%#.38s%+'# 197.161i%'+#138.189s%#-0+'45.16X%' #+.71X%#-058.*d%0 +#137.30x%+16.145u%'23.72u" ,800115413,3199362515,"l$l%H6",-84514175,10,"fF(@Ju",795959316,";",3064849260,1535631011,-706426049,3490703638,3859198544,2268674351); */
- /* printf("%#26.49p%'*.96c%-+-+ 37.180%%0#141.85i% 146.152X%91.199x%58.77i%0+'+'.140p%#67.141i%- 151.136d%101.187%%#*.56X%'+ 116.169x%69.74X%#0 #7.176%" ,16318453712790348322lu,46,814074579,1778514580,2425607191,1566569696,9615815307080556729lu,935162517,-447393454,385385973,3774990313,589711275); */
- /* ft_printf("%'+-+ 115.57d%#+0#115.33p%0--198.37x%77.42s%#+0+118.*X% 62.25i%0+#0#21.164i%+''157.91x%0 -0179.107c%++ 70.100i%126.119d%118.182p%175.10i%''+-28.c%#167.153X" ,-812555527,8065328576609463455lu,2102650417,"Pw\tOVtwS",2307405425,1290938377,-351008211,3819076396,-51,-101089464,267730313,5298290595841494834lu,-911149367,-70,485455641); */
- /* printf("%#+0#115.33p\n", 54); */
- /* ft_printf("%#+0#115.33p\n", 54); */
- /* ft_printf("%"); */
-
- /* printf("%"); */
+ /* printf("%"); */
/* ft_printf("32 This is an int : %0d\n\n", 0); */
/* printf("32 This is an int : %0d\n\n", 0); */
/* ft_printf("{%05.*d}\n", -15, 42); */
@@ -44,58 +30,71 @@ int main()
/* ft_printf("%hi\n", 32768); */
/* printf("%hi\n", 32768); */
/* ft_printf("%.37ld", -22337203685477l); */
+ /* */
+ /* ft_printf("[%]\n"); */
+ /* printf("[%]\n"); */
+ /* ft_printf("[%5]\n"); */
+ /* printf("[%5]\n"); */
+ /* ft_printf("[%05]\n"); */
+ /* printf("[%05]\n"); */
+ int test = 42;
+ ft_printf("bonjour\n");
+ ft_printf("char: %c\n", 'r');
+ ft_printf("string: %s\n", "bonjour");
+ ft_printf("pointer: %p\n", &test);
+ ft_printf("int: %d or %i\n", 45, 54);
+ ft_printf("uint: %u\n", 1 << 31);
+ ft_printf("hex lower: %x\n", 0xabcf012);
+ ft_printf("hex upper: %X\n", 0xabcf012);
+ ft_printf("percent: %%\n");
+ ft_printf("multiple stuff: %d %u %d %x %d\n", 1, -2, 3, 0xa, 5);
- ft_printf("[%]\n");
- printf("[%]\n");
- ft_printf("[%5]\n");
- printf("[%5]\n");
- ft_printf("[%05]\n");
- printf("[%05]\n");
+ ft_printf("precision |%.9d|\n", 43);
+ printf("precision |%.9d|\n", 43);
+ ft_printf("string precision |%.9s|\n", "jesuisbonjourbonjour");
+ printf("string precision |%.9s|\n", "jesuisbonjourbonjour");
+ ft_printf("min width |%9d|\n", 43);
+ printf("min width |%9d|\n", 43);
+ ft_printf("zero padding |%09d|\n", 43);
+ printf("zero padding |%09d|\n", 43);
+ ft_printf("left adjusted |%-9d|\n", 43);
+ printf("left adjusted |%-9d|\n", 43);
+ ft_printf("string padding |%9s|\n", "bon");
+ printf("string padding |%9s|\n", "bon");
+ ft_printf("width wildcard |%*d|\n", 5, 43);
+ printf("width wildcard |%*d|\n", 5, 43);
+ ft_printf("precision wildcard |%.*d|\n", 5, 43);
+ printf("precision wildcard |%.*d|\n", 5, 43);
+ ft_printf("precision/width wildcard |%*.*d|\n", 5, 3, 43);
+ printf("precision/width wildcard |%*.*d|\n", 5, 3, 43);
+ ft_printf("left adjusted |%*d|\n", -5, 43);
+ printf("left adjusted |%*d|\n", -5, 43);
- /* ft_printf("char: %c\n", 'r'); */
- /* ft_printf("string: %s\n", "bonjour"); */
- /* ft_printf("pointer: %p\n", &test); */
- /* ft_printf("int: %d or %i\n", 45, 54); */
- /* ft_printf("uint: %u\n", 1 << 31); */
- /* ft_printf("hex lower: %x\n", 0xabcf012); */
- /* ft_printf("hex upper: %X\n", 0xabcf012); */
- /* ft_printf("percent: %%\n"); */
- /* ft_printf("multiple stuff: %d %u %d %x %d\n", 1, -2, 3, 0xa, 5); */
- /* */
- /* ft_printf("precision |%.9d|\n", 43); */
- /* printf("precision |%.9d|\n", 43); */
- /* ft_printf("string precision |%.9s|\n", "jesuisbonjourbonjour"); */
- /* printf("string precision |%.9s|\n", "jesuisbonjourbonjour"); */
- /* ft_printf("min width |%9d|\n", 43); */
- /* printf("min width |%9d|\n", 43); */
- /* ft_printf("zero padding |%09d|\n", 43); */
- /* printf("zero padding |%09d|\n", 43); */
- /* ft_printf("left adjusted |%-9d|\n", 43); */
- /* printf("left adjusted |%-9d|\n", 43); */
- /* ft_printf("string padding |%9s|\n", "bon"); */
- /* printf("string padding |%9s|\n", "bon"); */
- /* */
- /* ft_printf("width wildcard |%*d|\n", 5, 43); */
- /* printf("width wildcard |%*d|\n", 5, 43); */
- /* ft_printf("precision wildcard |%.*d|\n", 5, 43); */
- /* printf("precision wildcard |%.*d|\n", 5, 43); */
- /* ft_printf("precision/width wildcard |%*.*d|\n", 5, 3, 43); */
- /* printf("precision/width wildcard |%*.*d|\n", 5, 3, 43); */
- /* ft_printf("left adjusted |%*d|\n", -5, 43); */
- /* printf("left adjusted |%*d|\n", -5, 43); */
- /* */
- /* ft_printf("overwrite |%*3d|\n", 5, 43); */
- /* printf("overwrite |%*3d|\n", 5, 43); */
- /* ft_printf("overwrite neg |%*-1d|\n", 0, 43); */
- /* printf("overwrite neg |%*-1d|\n", 0, 43); */
- /* */
- /* ft_printf("pointer field width |%15p|\n", &test); */
- /* printf("pointer field width |%15p|\n", &test); */
- /* ft_printf("pointer precision |%.15p|\n", &test); */
- /* printf("pointer precision |%.15p|\n", &test); */
- /* ft_printf("pointer precision/width |%20.15p|\n", &test); */
- /* printf("pointer precision/width |%20.15p|\n", &test); */
+ ft_printf("overwrite |%*3d|\n", 5, 43);
+ printf("overwrite |%*3d|\n", 5, 43);
+ ft_printf("overwrite neg |%*-1d|\n", 0, 43);
+ printf("overwrite neg |%*-1d|\n", 0, 43);
+
+ ft_printf("pointer field width |%15p|\n", &test);
+ printf("pointer field width |%15p|\n", &test);
+ ft_printf("pointer precision |%.15p|\n", &test);
+ printf("pointer precision |%.15p|\n", &test);
+ ft_printf("pointer precision/width |%20.15p|\n", &test);
+ printf("pointer precision/width |%20.15p|\n", &test);
+
+ ft_printf("bonjour%n", &test);
+ printf("%d\n", test);
+
+ /* ft_printf("%f\n", 0.14159); */
+ /* printf("%f\n", 0.14159); */
+ /* ft_printf("%f\n", 3.14159); */
+ /* printf("%f\n", 3.14159); */
+ /* ft_printf("%f\n", -3.14159); */
+ /* ft_printf("%f\n", 334.141519); */
+ /* ft_printf("%lf\n", 212.0); */
+ /* printf("%lf\n", 212.0); */
+ /* printf("%f\n", 212.0); */
return 0;
}
diff --git a/parse.c b/parse.c
index 42c192a..beb48e5 100644
--- a/parse.c
+++ b/parse.c
@@ -6,13 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:46:02 by cacharle ### ########.fr */
+/* Updated: 2019/11/13 08:13:02 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "header.h"
-int parse(char *format, t_flist **flist)
+int parse(const char *format, t_flist **flist)
{
t_flist *tmp;
t_pformat *parsed;
@@ -34,10 +34,10 @@ int parse(char *format, t_flist **flist)
return (1);
}
-t_pformat *parse_reduced(char *fmt)
+t_pformat *parse_reduced(const char *fmt)
{
t_pformat *pformat;
- char *start;
+ const char *start;
if ((pformat = (t_pformat*)malloc(sizeof(t_pformat))) == NULL)
return (NULL);
diff --git a/printer.c b/printer.c
index d349276..f4f80a0 100644
--- a/printer.c
+++ b/printer.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/28 23:19:24 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:40:12 by cacharle ### ########.fr */
+/* Updated: 2019/11/09 01:00:20 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,22 +43,24 @@ char *convert_specifier(va_list ap, t_pformat *pformat)
{
if (pformat->specifier == 'c')
return (convert_char(ap, pformat));
- else if (pformat->specifier == 's')
+ if (pformat->specifier == 's')
return (convert_str(ap, pformat));
- else if (pformat->specifier == 'p')
+ if (pformat->specifier == 'p')
return (convert_ptr(ap, pformat));
- else if (pformat->specifier == 'd' || pformat->specifier == 'i')
+ if (pformat->specifier == 'd' || pformat->specifier == 'i')
return (convert_int(ap, pformat));
- else if (pformat->specifier == 'u')
+ if (pformat->specifier == 'u')
return (convert_uint(ap, pformat));
- else if (pformat->specifier == 'x')
+ if (pformat->specifier == 'x')
return (convert_hex(ap, pformat));
- else if (pformat->specifier == 'X')
+ if (pformat->specifier == 'X')
return (convert_hex(ap, pformat));
- else if (pformat->specifier == '%')
+ if (pformat->specifier == '%')
return (convert_percent(ap, pformat));
- else if (pformat->specifier == 'n')
+ if (pformat->specifier == 'n')
return (convert_written(ap, pformat));
+ if (pformat->specifier == 'f')
+ return (convert_double(ap, pformat));
else
return (convert_none(ap, pformat));
return (NULL);
@@ -98,7 +100,7 @@ char *handle_precision(t_pformat *pformat, char *str)
int len;
char *tmp;
- if (ft_strchr("diuxX", pformat->specifier) && pformat->precision > 0)
+ if (ft_strchr("diuxX", pformat->specifier) && pformat->precision >= 0)
pformat->flags &= ~FLAG_ZERO;
len = ft_strlen(str);
if (pformat->precision == 0 && str[0] == '0')
diff --git a/test b/test
index c13fc4a..79835f6 100755
--- a/test
+++ b/test
Binary files differ
diff --git a/utils.c b/utils.c
index faa6751..02baaa8 100644
--- a/utils.c
+++ b/utils.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:12:40 by cacharle #+# #+# */
-/* Updated: 2019/11/05 23:46:14 by cacharle ### ########.fr */
+/* Updated: 2019/11/13 08:49:58 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -91,12 +91,25 @@ char *ft_itoa_unsigned_base(long long unsigned int n, char *base)
return (str);
}
-char *ft_strtoupper(char *str)
+void *ft_memjoin_free(void *dst, int dst_size, void *src, int src_size)
{
- int i;
+ void *clone;
- i = -1;
- while (str[++i])
- str[i] = ft_toupper(str[i]);
- return (str);
+ if (dst == NULL)
+ {
+ if ((dst = malloc(src_size)) == NULL)
+ return (NULL);
+ ft_memcpy(dst, src, src_size);
+ return (dst);
+ }
+ if ((clone = malloc(dst_size)) == NULL)
+ return (NULL);
+ ft_memcpy(clone, dst, dst_size);
+ free(dst);
+ if ((dst = malloc(dst_size + src_size)) == NULL)
+ return (NULL);
+ ft_memcpy(dst, clone, dst_size);
+ free(clone);
+ ft_memcpy(dst + dst_size, src, src_size);
+ return (dst);
}