aboutsummaryrefslogtreecommitdiff
path: root/src/io
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
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')
-rw-r--r--src/io/ft_get_next_line.c (renamed from src/io/get_next_line/get_next_line.c)18
-rw-r--r--src/io/ft_printf.c24
-rw-r--r--src/io/ft_printf/ft_asprintf.c (renamed from src/io/ft_asprintf.c)0
-rw-r--r--src/io/ft_printf/ft_dprintf.c (renamed from src/io/ft_dprintf.c)0
-rw-r--r--src/io/ft_printf/ft_printf.c88
-rw-r--r--src/io/ft_printf/ft_snprintf.c (renamed from src/io/ft_snprintf.c)0
-rw-r--r--src/io/ft_printf/ft_sprintf.c (renamed from src/io/ft_sprintf.c)0
-rw-r--r--src/io/ft_printf/ft_vasprintf.c (renamed from src/io/ft_vasprintf.c)0
-rw-r--r--src/io/ft_printf/ft_vdprintf.c (renamed from src/io/ft_vdprintf.c)0
-rw-r--r--src/io/ft_printf/ft_vprintf.c (renamed from src/io/ft_vprintf.c)0
-rw-r--r--src/io/ft_printf/ft_vsnprintf.c (renamed from src/io/ft_vsnprintf.c)0
-rw-r--r--src/io/ft_printf/ft_vsprintf.c (renamed from src/io/ft_vsprintf.c)0
-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
27 files changed, 18 insertions, 112 deletions
diff --git a/src/io/get_next_line/get_next_line.c b/src/io/ft_get_next_line.c
index e51f152..4aecf3c 100644
--- a/src/io/get_next_line/get_next_line.c
+++ b/src/io/ft_get_next_line.c
@@ -6,13 +6,11 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/19 09:08:36 by cacharle #+# #+# */
-/* Updated: 2020/01/15 07:26:50 by cacharle ### ########.fr */
+/* Updated: 2020/01/17 10:53:23 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-#include "get_next_line.h"
-
-#define HAS_NEWLINE(str, split_at) ((split_at = gnl_find_newline(str)) != -1)
+#include "libft.h"
static int gnl_find_newline(char *str)
{
@@ -46,12 +44,12 @@ static int gnl_read_line(int fd, char **line, char *rest)
int split_at;
char *buf;
- if ((buf = malloc(sizeof(char) * (BUFFER_SIZE + 1))) == NULL)
+ if ((buf = malloc(sizeof(char) * (GNL_BUFFER_SIZE + 1))) == NULL)
return (gnl_free_return(line, NULL, GNL_STATUS_ERROR));
- while ((ret = read(fd, buf, BUFFER_SIZE)) > 0)
+ while ((ret = read(fd, buf, GNL_BUFFER_SIZE)) > 0)
{
buf[ret] = '\0';
- if (HAS_NEWLINE(buf, split_at))
+ if ((split_at = gnl_find_newline(buf)) != -1)
{
ft_strcpy(rest, buf + split_at + 1);
buf[split_at] = '\0';
@@ -88,15 +86,15 @@ static int gnl_read_line(int fd, char **line, char *rest)
int get_next_line(int fd, char **line)
{
int split_at;
- static char rest[OPEN_MAX][BUFFER_SIZE + 1] = {{0}};
+ static char rest[OPEN_MAX][GNL_BUFFER_SIZE + 1] = {{0}};
- if (fd < 0 || fd > OPEN_MAX || line == NULL || BUFFER_SIZE <= 0)
+ if (fd < 0 || fd > OPEN_MAX || line == NULL || GNL_BUFFER_SIZE <= 0)
return (GNL_STATUS_ERROR);
if ((*line = ft_strdup("")) == NULL)
return (GNL_STATUS_ERROR);
if (rest[fd][0] == '\0')
return (gnl_read_line(fd, line, rest[fd]));
- if (HAS_NEWLINE(rest[fd], split_at))
+ if ((split_at = gnl_find_newline(rest[fd])) != -1)
{
free(*line);
if ((*line = (char*)malloc(sizeof(char) * (split_at + 1))) == NULL)
diff --git a/src/io/ft_printf.c b/src/io/ft_printf.c
deleted file mode 100644
index 1b92bb2..0000000
--- a/src/io/ft_printf.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* ************************************************************************** */
-/* */
-/* ::: :::::::: */
-/* ft_printf.c :+: :+: :+: */
-/* +:+ +:+ +:+ */
-/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
-/* +#+#+#+#+#+ +#+ */
-/* Created: 2019/11/21 02:31:32 by cacharle #+# #+# */
-/* Updated: 2019/11/21 03:41:54 by cacharle ### ########.fr */
-/* */
-/* ************************************************************************** */
-
-#include "libft.h"
-
-int ft_printf(const char *format, ...)
-{
- int ret;
- va_list ap;
-
- va_start(ap, format);
- ret = ft_vprintf(format, ap);
- va_end(ap);
- return (ret);
-}
diff --git a/src/io/ft_asprintf.c b/src/io/ft_printf/ft_asprintf.c
index 5eb62d9..5eb62d9 100644
--- a/src/io/ft_asprintf.c
+++ b/src/io/ft_printf/ft_asprintf.c
diff --git a/src/io/ft_dprintf.c b/src/io/ft_printf/ft_dprintf.c
index 8e60970..8e60970 100644
--- a/src/io/ft_dprintf.c
+++ b/src/io/ft_printf/ft_dprintf.c
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_snprintf.c b/src/io/ft_printf/ft_snprintf.c
index e1fdfbd..e1fdfbd 100644
--- a/src/io/ft_snprintf.c
+++ b/src/io/ft_printf/ft_snprintf.c
diff --git a/src/io/ft_sprintf.c b/src/io/ft_printf/ft_sprintf.c
index 31da75e..31da75e 100644
--- a/src/io/ft_sprintf.c
+++ b/src/io/ft_printf/ft_sprintf.c
diff --git a/src/io/ft_vasprintf.c b/src/io/ft_printf/ft_vasprintf.c
index 85f66bc..85f66bc 100644
--- a/src/io/ft_vasprintf.c
+++ b/src/io/ft_printf/ft_vasprintf.c
diff --git a/src/io/ft_vdprintf.c b/src/io/ft_printf/ft_vdprintf.c
index a5e5ebf..a5e5ebf 100644
--- a/src/io/ft_vdprintf.c
+++ b/src/io/ft_printf/ft_vdprintf.c
diff --git a/src/io/ft_vprintf.c b/src/io/ft_printf/ft_vprintf.c
index b98670b..b98670b 100644
--- a/src/io/ft_vprintf.c
+++ b/src/io/ft_printf/ft_vprintf.c
diff --git a/src/io/ft_vsnprintf.c b/src/io/ft_printf/ft_vsnprintf.c
index 7db988c..7db988c 100644
--- a/src/io/ft_vsnprintf.c
+++ b/src/io/ft_printf/ft_vsnprintf.c
diff --git a/src/io/ft_vsprintf.c b/src/io/ft_printf/ft_vsprintf.c
index 91b4815..91b4815 100644
--- a/src/io/ft_vsprintf.c
+++ b/src/io/ft_printf/ft_vsprintf.c
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