aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--convert_char.c2
-rw-r--r--convert_written.c20
-rw-r--r--ft_printf.c11
-rw-r--r--header.h16
-rw-r--r--main.c92
-rw-r--r--parse.c2
-rw-r--r--printer.c4
-rwxr-xr-xtestbin27596 -> 27916 bytes
9 files changed, 88 insertions, 63 deletions
diff --git a/Makefile b/Makefile
index 4463e44..a0a45d6 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@
# By: cacharle <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/10/28 17:41:14 by cacharle #+# #+# #
-# Updated: 2019/10/30 23:06:05 by cacharle ### ########.fr #
+# Updated: 2019/10/30 23:58:39 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -24,7 +24,7 @@ MAKE = make -j4
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_ptr.c convert_hex.c convert_percent.c convert_written.c
OBJ = $(SRC:.c=.o)
INCLUDE = header.h
diff --git a/convert_char.c b/convert_char.c
index 083a6e9..e15457e 100644
--- a/convert_char.c
+++ b/convert_char.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/30 23:22:29 by cacharle #+# #+# */
-/* Updated: 2019/10/30 23:33:44 by cacharle ### ########.fr */
+/* Updated: 2019/10/30 23:37:29 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/convert_written.c b/convert_written.c
new file mode 100644
index 0000000..f2cdc2b
--- /dev/null
+++ b/convert_written.c
@@ -0,0 +1,20 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* convert_written.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/10/30 23:38:28 by cacharle #+# #+# */
+/* Updated: 2019/10/30 23:59:05 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stdarg.h>
+#include "header.h"
+
+char *convert_written(va_list ap, t_pformat *pformat)
+{
+ pformat->written = va_arg(ap, int*);
+ return (NULL);
+}
diff --git a/ft_printf.c b/ft_printf.c
index 0352b52..d71f397 100644
--- a/ft_printf.c
+++ b/ft_printf.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:15:28 by cacharle #+# #+# */
-/* Updated: 2019/10/30 19:58:36 by cacharle ### ########.fr */
+/* Updated: 2019/10/31 00:10:04 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -38,14 +38,23 @@ int ft_printf(const char *format, ...)
if (format[i] != '%')
{
write(STDOUT_FILENO, format + i, 1);
+ print_len++;
continue ;
}
str = convert(flist->content, ap);
+ if (str == NULL && flist->content->type == 'n')
+ {
+ *flist->content->written = print_len;
+ i += flist->content->fmt_len;
+ list_pop_front(&flist);
+ continue;
+ }
if (str == NULL)
{
list_destroy(&flist);
return (-1);
}
+ printf("\n%c\n", flist->content->type);
if (flist->content->type == 'c')
{
write(1, str, flist->content->size);
diff --git a/header.h b/header.h
index 9667772..1a562cd 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/10/30 23:13:41 by cacharle ### ########.fr */
+/* Updated: 2019/10/31 00:04:28 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,17 +25,7 @@
# define IN_STR(str, c) (ft_strchr(str, c) != NULL)
# define IS_STANDALONE_FLAG(c) (IN_STR("0-+ #'", c))
-# define CONVERSIONS_STR "cspdiuxX%"
-
-# define CONVERSION_CHAR 'c'
-# define CONVERSION_STR 's'
-# define CONVERSION_PTR 'p'
-# define CONVERSION_DECIMAL 'd'
-# define CONVERSION_INT 'i'
-# define CONVERSION_UINT 'u'
-# define CONVERSION_HEX_LOWER 'x'
-# define CONVERSION_HEX_UPPER 'X'
-# define CONVERSION_PERCENT '%'
+# define CONVERSIONS_STR "ncspdiuxX%"
# define FLAG_LEFT_ADJUSTED (1 << 0)
# define FLAG_ZERO_PADDING (1 << 1)
@@ -67,6 +57,7 @@ typedef struct
char type;
int fmt_len;
int size;
+ int *written;
} t_pformat;
typedef struct s_flist
@@ -138,5 +129,6 @@ char *convert_int(va_list ap, t_pformat *pformat);
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);
#endif
diff --git a/main.c b/main.c
index 5da44fe..d4b2907 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/10/30 23:31:28 by cacharle ### ########.fr */
+/* Updated: 2019/10/31 00:08:11 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,49 +18,51 @@ int main()
{
int test;
- ft_printf("%.37ld", -22337203685477l);
- 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("bonjour%nyi", &test);
+ ft_printf("%d\n", test);
+ /* ft_printf("%.37ld", -22337203685477l); */
+ /* 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); */
return 0;
}
diff --git a/parse.c b/parse.c
index 48ae6f3..4108d93 100644
--- a/parse.c
+++ b/parse.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/29 00:11:33 by cacharle #+# #+# */
-/* Updated: 2019/10/30 23:31:12 by cacharle ### ########.fr */
+/* Updated: 2019/10/31 00:08:04 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/printer.c b/printer.c
index 4b5ae43..cfbf429 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/10/30 23:30:58 by cacharle ### ########.fr */
+/* Updated: 2019/10/30 23:56:21 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -57,6 +57,8 @@ char *convert_type(va_list ap, t_pformat *pformat)
return (convert_hex(ap, pformat));
if (pformat->type == '%')
return (convert_percent(ap, pformat));
+ if (pformat->type == 'n')
+ return (convert_written(ap, pformat));
return (NULL);
}
diff --git a/test b/test
index 2caf91e..414ee67 100755
--- a/test
+++ b/test
Binary files differ