Updated linenoise and printf to better work

This commit is contained in:
Maieul BOYER 2024-07-07 19:50:33 +02:00
parent 0e18e20181
commit 8808f81221
No known key found for this signature in database
28 changed files with 657 additions and 579 deletions

View file

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* callbacks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 18:01:52 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:03:28 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/fs/fs.h"
#include "me/printf/_internal_printf.h"
#include "me/string/string.h"
#include "me/types.h"
void me_printf_append_string(t_const_str to_write, t_usize to_write_len,
void *p_args)
{
t_sprintf_arg *arg;
arg = p_args;
arg->total_print += to_write_len;
string_push(arg->buffer, to_write);
}
void me_printf_write(t_const_str to_write, t_usize to_write_len, void *p_args)
{
t_fprintf_arg *arg;
arg = (t_fprintf_arg *)p_args;
write_fd(arg->fd, (t_u8 *)to_write, to_write_len, NULL);
arg->total_print += to_write_len;
}

View file

@ -6,13 +6,12 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 18:12:11 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:43:13 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:39:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/str/str.h"
#include <stdlib.h>

View file

@ -6,14 +6,13 @@
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 01:44:35 by maix #+# #+# */
/* Updated: 2024/05/14 18:43:24 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:39:44 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/str/str.h"
#include <stdio.h>

View file

@ -6,13 +6,12 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 18:16:16 by maiboyer #+# #+# */
/* Updated: 2023/12/11 19:19:03 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#define HEX_INLINE_BUF 17

View file

@ -6,13 +6,12 @@
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 01:19:18 by maix #+# #+# */
/* Updated: 2023/12/11 19:17:23 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include <stdio.h>
#define OCT_INLINE_BUF 23

View file

@ -6,13 +6,12 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 18:16:16 by maiboyer #+# #+# */
/* Updated: 2023/12/11 19:20:42 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#define PTR_INLINE_BUF 17

View file

@ -6,14 +6,13 @@
/* By: maix <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/18 01:44:35 by maix #+# #+# */
/* Updated: 2024/05/14 18:43:39 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/str/str.h"
#include <stdio.h>

View file

@ -6,16 +6,14 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 17:57:04 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:43:44 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/string/string.h"
#include "me/mem/mem.h"
#include "me/convert/atoi.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/matchers/matchers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/str/str.h"
#include "me/types.h"

View file

@ -6,14 +6,12 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 18:00:07 by maiboyer #+# #+# */
/* Updated: 2023/12/01 21:48:22 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:40:18 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/string/string.h"
#include "me/char/char.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/types.h"
void set_var_for_pad_and_stuff(t_pad_and_stuff_args *a, t_printf_arg *d)

View file

@ -6,16 +6,15 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/01 21:05:47 by maiboyer #+# #+# */
/* Updated: 2024/05/14 18:43:56 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:40:12 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/mem/mem.h"
#include "me/printf/formatter/utils.h"
void handle_weird_precision_stuff(t_printf_arg *data, t_prec_strs strs,
t_usize value)
void handle_weird_precision_stuff(t_printf_arg *data, t_prec_strs strs,
t_usize value)
{
if (!value && data->extra.precision == 0 && (data->flags & PRECISION))
{

View file

@ -6,14 +6,13 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/16 18:07:40 by maiboyer #+# #+# */
/* Updated: 2023/12/11 19:11:51 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 17:39:37 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem.h"
#include "me/printf/formatter/formatter.h"
#include "me/printf/matchers/matchers.h"
#include "me/printf/printf.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

View file

@ -6,85 +6,37 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/11 17:50:56 by maiboyer #+# #+# */
/* Updated: 2024/02/09 14:58:10 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 18:01:58 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/string/string.h"
#include "me/fs/write.h"
#include "me/printf/formatter/formatter.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/matchers/matchers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/fs/fs.h"
#include "me/fs/write.h"
#include "me/printf/_internal_printf.h"
#include "me/types.h"
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
// p_args is an t_string;
static void me_printf_add_to_string(t_const_str to_write, t_usize to_write_len,
void *p_args)
t_usize me_printf(t_const_str fmt, ...)
{
t_string *out_buf;
va_list args;
t_usize res;
out_buf = (t_string *)p_args;
(void)(to_write_len);
string_push(out_buf, to_write);
}
t_str me_printf_str(t_const_str fmt, va_list *arguments)
{
t_string out;
out = string_new(str_len(fmt));
if (out.buf == NULL)
{
return (NULL);
}
me_printf_str_inner(fmt, &me_printf_add_to_string, arguments, (void *)&out);
return (out.buf);
}
void me_printf_write(t_const_str to_write, t_usize to_write_len,
void *p_args)
{
t_fprintf_arg *arg;
arg = (t_fprintf_arg *)p_args;
me_write(arg->fd, (t_u8 *)to_write, to_write_len);
arg->total_print += to_write_len;
}
t_usize me_printf(t_const_str fmt, ...)
{
va_list args;
t_fprintf_arg passthru;
passthru = (t_fprintf_arg){
.fd = 1,
.total_print = 0,
};
va_start(args, fmt);
me_printf_str_inner(fmt, &me_printf_write, &args, (void *)&passthru);
res = me_vprintf(fmt, &args);
va_end(args);
return (passthru.total_print);
return (res);
}
t_usize me_eprintf(t_const_str fmt, ...)
t_usize me_eprintf(t_const_str fmt, ...)
{
va_list args;
t_fprintf_arg passthru;
va_list args;
t_usize res;
passthru = (t_fprintf_arg){
.fd = 2,
.total_print = 0,
};
va_start(args, fmt);
me_printf_str_inner(fmt, &me_printf_write, &args, (void *)&passthru);
res = me_veprintf(fmt, &args);
va_end(args);
return (passthru.total_print);
return (res);
}
/*

View file

@ -17,31 +17,25 @@
#include "me/types.h"
#include <stdarg.h>
void me_printf_write(t_const_str to_write, t_usize to_write_len, void *p_args);
t_usize me_vprintf_fd(t_fd *fd, t_const_str fmt, va_list *args)
{
t_fprintf_arg passthru;
passthru = (t_fprintf_arg){
.fd = fd->fd,
.total_print = 0,
};
if (fd == NULL || fmt == NULL || args == NULL)
return (0);
passthru.fd = fd;
passthru.total_print = 0;
me_printf_str_inner(fmt, &me_printf_write, args, (void *)&passthru);
return (passthru.total_print);
}
t_usize me_printf_fd(t_fd *fd, t_const_str fmt, ...)
{
va_list args;
t_fprintf_arg passthru;
va_list args;
t_usize res;
passthru = (t_fprintf_arg){
.fd = fd->fd,
.total_print = 0,
};
va_start(args, fmt);
me_printf_str_inner(fmt, &me_printf_write, &args, (void *)&passthru);
res = me_vprintf_fd(fd, fmt, &args);
va_end(args);
return (passthru.total_print);
return (res);
}

View file

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* printf_str.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/07 17:27:50 by maiboyer #+# #+# */
/* Updated: 2024/07/07 18:03:40 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/printf/_internal_printf.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/printf.h"
#include "me/string/string.h"
#include "me/types.h"
#include <stdarg.h>
t_usize me_vprintf_str(t_string *buf, t_const_str fmt, va_list *args)
{
t_sprintf_arg passthru;
if (buf == NULL || fmt == NULL || args == NULL)
return (0);
passthru.buffer = buf;
passthru.total_print = 0;
me_printf_str_inner(fmt, &me_printf_append_string, args, &passthru);
return (passthru.total_print);
}
t_usize me_printf_str(t_string *buf, t_const_str fmt, ...)
{
t_usize res;
va_list args;
va_start(args, fmt);
res = me_vprintf_str(buf, fmt, &args);
va_end(args);
return (res);
}

View file

@ -6,46 +6,38 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/02/09 14:57:28 by maiboyer #+# #+# */
/* Updated: 2024/02/09 15:00:39 by maiboyer ### ########.fr */
/* Updated: 2024/07/07 18:00:14 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/string/string.h"
#include "me/fs/write.h"
#include "me/printf/formatter/formatter.h"
#include "me/fs/fs.h"
#include "me/printf/formatter/utils.h"
#include "me/printf/matchers/matchers.h"
#include "me/printf/printf.h"
#include "me/str/str.h"
#include "me/types.h"
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
void me_printf_write(t_const_str to_write, t_usize to_write_len,
void *p_args);
void me_printf_write(t_const_str to_write, t_usize to_write_len, void *p_args);
t_usize me_vprintf(t_const_str fmt, va_list *args)
t_usize me_vprintf(t_const_str fmt, va_list *args)
{
t_fprintf_arg passthru;
t_fprintf_arg passthru;
passthru = (t_fprintf_arg){
.fd = 1,
.total_print = 0,
};
if (fmt == NULL || args == NULL)
return (0);
passthru.fd = get_stdout();
passthru.total_print = 0;
me_printf_str_inner(fmt, &me_printf_write, args, (void *)&passthru);
return (passthru.total_print);
}
t_usize me_veprintf(t_const_str fmt, va_list *args)
t_usize me_veprintf(t_const_str fmt, va_list *args)
{
t_fprintf_arg passthru;
t_fprintf_arg passthru;
passthru = (t_fprintf_arg){
.fd = 2,
.total_print = 0,
};
if (fmt == NULL || args == NULL)
return (0);
passthru.fd = get_stderr();
passthru.total_print = 0;
me_printf_str_inner(fmt, &me_printf_write, args, (void *)&passthru);
return (passthru.total_print);
}