aboutsummaryrefslogtreecommitdiff
path: root/src/io/ft_printf
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-17 10:56:16 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-17 10:56:16 +0100
commitfe37597119353ce183fc404417b81bd4702f64b7 (patch)
treefaa20a8352092c062e2fd272fff2104d9f2ddb3f /src/io/ft_printf
parent2e5ca2ab6276b7b24895ade28e1533356ef523dc (diff)
downloadlibft-fe37597119353ce183fc404417b81bd4702f64b7.tar.gz
libft-fe37597119353ce183fc404417b81bd4702f64b7.tar.bz2
libft-fe37597119353ce183fc404417b81bd4702f64b7.zip
Splited include like src/, Adding feature toggle protection in header
Diffstat (limited to 'src/io/ft_printf')
-rw-r--r--src/io/ft_printf/ft_asprintf.c24
-rw-r--r--src/io/ft_printf/ft_dprintf.c24
-rw-r--r--src/io/ft_printf/ft_printf.c88
-rw-r--r--src/io/ft_printf/ft_snprintf.c24
-rw-r--r--src/io/ft_printf/ft_sprintf.c24
-rw-r--r--src/io/ft_printf/ft_vasprintf.c21
-rw-r--r--src/io/ft_printf/ft_vdprintf.c24
-rw-r--r--src/io/ft_printf/ft_vprintf.c18
-rw-r--r--src/io/ft_printf/ft_vsnprintf.c26
-rw-r--r--src/io/ft_printf/ft_vsprintf.c18
-rw-r--r--src/io/ft_printf/internals/convert.c (renamed from src/io/ft_printf/convert.c)0
-rw-r--r--src/io/ft_printf/internals/convert_char.c (renamed from src/io/ft_printf/convert_char.c)0
-rw-r--r--src/io/ft_printf/internals/convert_hex.c (renamed from src/io/ft_printf/convert_hex.c)0
-rw-r--r--src/io/ft_printf/internals/convert_int.c (renamed from src/io/ft_printf/convert_int.c)0
-rw-r--r--src/io/ft_printf/internals/convert_none.c (renamed from src/io/ft_printf/convert_none.c)0
-rw-r--r--src/io/ft_printf/internals/convert_percent.c (renamed from src/io/ft_printf/convert_percent.c)0
-rw-r--r--src/io/ft_printf/internals/convert_ptr.c (renamed from src/io/ft_printf/convert_ptr.c)0
-rw-r--r--src/io/ft_printf/internals/convert_str.c (renamed from src/io/ft_printf/convert_str.c)0
-rw-r--r--src/io/ft_printf/internals/convert_uint.c (renamed from src/io/ft_printf/convert_uint.c)0
-rw-r--r--src/io/ft_printf/internals/convert_written.c (renamed from src/io/ft_printf/convert_written.c)0
-rw-r--r--src/io/ft_printf/internals/extract.c (renamed from src/io/ft_printf/extract.c)0
-rw-r--r--src/io/ft_printf/internals/length_modifier.c (renamed from src/io/ft_printf/length_modifier.c)0
-rw-r--r--src/io/ft_printf/internals/list.c (renamed from src/io/ft_printf/list.c)0
-rw-r--r--src/io/ft_printf/internals/parse.c (renamed from src/io/ft_printf/parse.c)0
-rw-r--r--src/io/ft_printf/internals/utils.c (renamed from src/io/ft_printf/utils.c)0
25 files changed, 213 insertions, 78 deletions
diff --git a/src/io/ft_printf/ft_asprintf.c b/src/io/ft_printf/ft_asprintf.c
new file mode 100644
index 0000000..5eb62d9
--- /dev/null
+++ b/src/io/ft_printf/ft_asprintf.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_asprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:30:33 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:43:08 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_asprintf(char **ret, const char *format, ...)
+{
+ int vret;
+ va_list ap;
+
+ va_start(ap, format);
+ vret = ft_vasprintf(ret, format, ap);
+ va_end(ap);
+ return (vret);
+}
diff --git a/src/io/ft_printf/ft_dprintf.c b/src/io/ft_printf/ft_dprintf.c
new file mode 100644
index 0000000..8e60970
--- /dev/null
+++ b/src/io/ft_printf/ft_dprintf.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_dprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:29:11 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:42:05 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_dprintf(int fd, const char *format, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, format);
+ ret = ft_vdprintf(fd, format, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/src/io/ft_printf/ft_printf.c b/src/io/ft_printf/ft_printf.c
index daa0cf2..1b92bb2 100644
--- a/src/io/ft_printf/ft_printf.c
+++ b/src/io/ft_printf/ft_printf.c
@@ -5,88 +5,20 @@
/* +:+ +:+ +:+ */
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/10/29 00:15:28 by cacharle #+# #+# */
-/* Updated: 2019/11/13 08:56:49 by cacharle ### ########.fr */
+/* Created: 2019/11/21 02:31:32 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:41:54 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include "ft_vasprintf.h"
+#include "libft.h"
-int ft_printf(const char *format, ...)
+int ft_printf(const char *format, ...)
{
- t_printf_status status;
+ int ret;
+ va_list ap;
- if (format == NULL)
- 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 (*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));
- }
- 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);
+ va_start(ap, format);
+ ret = ft_vprintf(format, ap);
+ va_end(ap);
+ return (ret);
}
diff --git a/src/io/ft_printf/ft_snprintf.c b/src/io/ft_printf/ft_snprintf.c
new file mode 100644
index 0000000..e1fdfbd
--- /dev/null
+++ b/src/io/ft_printf/ft_snprintf.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_snprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:27:55 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:41:49 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_snprintf(char *str, size_t size, const char *format, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, format);
+ ret = ft_vsnprintf(str, size, format, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/src/io/ft_printf/ft_sprintf.c b/src/io/ft_printf/ft_sprintf.c
new file mode 100644
index 0000000..31da75e
--- /dev/null
+++ b/src/io/ft_printf/ft_sprintf.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_sprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:17:21 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:42:28 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_sprintf(char *str, const char *format, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, format);
+ ret = ft_vsprintf(str, format, ap);
+ va_end(ap);
+ return (ret);
+}
diff --git a/src/io/ft_printf/ft_vasprintf.c b/src/io/ft_printf/ft_vasprintf.c
new file mode 100644
index 0000000..85f66bc
--- /dev/null
+++ b/src/io/ft_printf/ft_vasprintf.c
@@ -0,0 +1,21 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_vasprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:49:56 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:45:39 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_vasprintf(char **ret, const char *format, va_list ap)
+{
+ (void)ret;
+ (void)format;
+ (void)ap;
+ return (0);
+}
diff --git a/src/io/ft_printf/ft_vdprintf.c b/src/io/ft_printf/ft_vdprintf.c
new file mode 100644
index 0000000..a5e5ebf
--- /dev/null
+++ b/src/io/ft_printf/ft_vdprintf.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_vdprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:40:03 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:46:00 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_vdprintf(int fd, const char *format, va_list ap)
+{
+ int out_len;
+ char *out;
+
+ if ((out_len = ft_vasprintf(&out, format, ap)) == -1)
+ return (-1);
+ write(fd, out, out_len);
+ return (out_len);
+}
diff --git a/src/io/ft_printf/ft_vprintf.c b/src/io/ft_printf/ft_vprintf.c
new file mode 100644
index 0000000..b98670b
--- /dev/null
+++ b/src/io/ft_printf/ft_vprintf.c
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_vprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:32:44 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:44:11 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_vprintf(const char *format, va_list ap)
+{
+ return (ft_vdprintf(STDOUT_FILENO, format, ap));
+}
diff --git a/src/io/ft_printf/ft_vsnprintf.c b/src/io/ft_printf/ft_vsnprintf.c
new file mode 100644
index 0000000..7db988c
--- /dev/null
+++ b/src/io/ft_printf/ft_vsnprintf.c
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_vsnprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:36:32 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:45:14 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_vsnprintf(char *str, size_t size, const char *format, va_list ap)
+{
+ int ret;
+ int full_out_len;
+ char *full_out;
+
+ full_out_len = ft_vasprintf(&full_out, format, ap);
+ ft_strncpy(str, full_out, size);
+ ret = MIN((size_t)full_out_len, size);
+ free(full_out);
+ return (ret);
+}
diff --git a/src/io/ft_printf/ft_vsprintf.c b/src/io/ft_printf/ft_vsprintf.c
new file mode 100644
index 0000000..91b4815
--- /dev/null
+++ b/src/io/ft_printf/ft_vsprintf.c
@@ -0,0 +1,18 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_vsprintf.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/11/21 02:34:17 by cacharle #+# #+# */
+/* Updated: 2019/11/21 03:44:24 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+int ft_vsprintf(char *str, const char *format, va_list ap)
+{
+ return (ft_vsnprintf(str, INT_MAX + 1, format, ap));
+}
diff --git a/src/io/ft_printf/convert.c b/src/io/ft_printf/internals/convert.c
index 398c754..398c754 100644
--- a/src/io/ft_printf/convert.c
+++ b/src/io/ft_printf/internals/convert.c
diff --git a/src/io/ft_printf/convert_char.c b/src/io/ft_printf/internals/convert_char.c
index c5f3a93..c5f3a93 100644
--- a/src/io/ft_printf/convert_char.c
+++ b/src/io/ft_printf/internals/convert_char.c
diff --git a/src/io/ft_printf/convert_hex.c b/src/io/ft_printf/internals/convert_hex.c
index 0464dc7..0464dc7 100644
--- a/src/io/ft_printf/convert_hex.c
+++ b/src/io/ft_printf/internals/convert_hex.c
diff --git a/src/io/ft_printf/convert_int.c b/src/io/ft_printf/internals/convert_int.c
index 2345f76..2345f76 100644
--- a/src/io/ft_printf/convert_int.c
+++ b/src/io/ft_printf/internals/convert_int.c
diff --git a/src/io/ft_printf/convert_none.c b/src/io/ft_printf/internals/convert_none.c
index 358ef1b..358ef1b 100644
--- a/src/io/ft_printf/convert_none.c
+++ b/src/io/ft_printf/internals/convert_none.c
diff --git a/src/io/ft_printf/convert_percent.c b/src/io/ft_printf/internals/convert_percent.c
index 813bb77..813bb77 100644
--- a/src/io/ft_printf/convert_percent.c
+++ b/src/io/ft_printf/internals/convert_percent.c
diff --git a/src/io/ft_printf/convert_ptr.c b/src/io/ft_printf/internals/convert_ptr.c
index 63babb9..63babb9 100644
--- a/src/io/ft_printf/convert_ptr.c
+++ b/src/io/ft_printf/internals/convert_ptr.c
diff --git a/src/io/ft_printf/convert_str.c b/src/io/ft_printf/internals/convert_str.c
index 7d51a5e..7d51a5e 100644
--- a/src/io/ft_printf/convert_str.c
+++ b/src/io/ft_printf/internals/convert_str.c
diff --git a/src/io/ft_printf/convert_uint.c b/src/io/ft_printf/internals/convert_uint.c
index 4207165..4207165 100644
--- a/src/io/ft_printf/convert_uint.c
+++ b/src/io/ft_printf/internals/convert_uint.c
diff --git a/src/io/ft_printf/convert_written.c b/src/io/ft_printf/internals/convert_written.c
index 4beeaef..4beeaef 100644
--- a/src/io/ft_printf/convert_written.c
+++ b/src/io/ft_printf/internals/convert_written.c
diff --git a/src/io/ft_printf/extract.c b/src/io/ft_printf/internals/extract.c
index c56a777..c56a777 100644
--- a/src/io/ft_printf/extract.c
+++ b/src/io/ft_printf/internals/extract.c
diff --git a/src/io/ft_printf/length_modifier.c b/src/io/ft_printf/internals/length_modifier.c
index 88226da..88226da 100644
--- a/src/io/ft_printf/length_modifier.c
+++ b/src/io/ft_printf/internals/length_modifier.c
diff --git a/src/io/ft_printf/list.c b/src/io/ft_printf/internals/list.c
index 99491f4..99491f4 100644
--- a/src/io/ft_printf/list.c
+++ b/src/io/ft_printf/internals/list.c
diff --git a/src/io/ft_printf/parse.c b/src/io/ft_printf/internals/parse.c
index 33928a0..33928a0 100644
--- a/src/io/ft_printf/parse.c
+++ b/src/io/ft_printf/internals/parse.c
diff --git a/src/io/ft_printf/utils.c b/src/io/ft_printf/internals/utils.c
index ad44980..ad44980 100644
--- a/src/io/ft_printf/utils.c
+++ b/src/io/ft_printf/internals/utils.c