From f600c79559892b73b019102478af501cf71fe6a4 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 28 May 2020 23:02:51 +0200 Subject: Added vsprintf support for serial connections --- src/kernel/lib/stdio/debug.c | 47 ++++++-------------------------------------- 1 file changed, 6 insertions(+), 41 deletions(-) (limited to 'src/kernel/lib/stdio/debug.c') diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c index 3acb987..879329e 100644 --- a/src/kernel/lib/stdio/debug.c +++ b/src/kernel/lib/stdio/debug.c @@ -1,8 +1,7 @@ #include +#include +#include #include -#include -#include -#include #include void serial_print(const char *data) @@ -13,44 +12,10 @@ void serial_print(const char *data) void serial_vprintf(const char *fmt, va_list args) { - u8 readyToFormat = 0; - - char buff = 0; - - for (; *fmt; fmt++) { - if (readyToFormat) { - if (*fmt == '%') { - serial_put('%'); - readyToFormat = 0; - continue; - } - - buff = *fmt; - if (buff == 's') { - const char *str = va_arg(args, const char *); - serial_print(str); - readyToFormat = 0; - } else if (buff == 'x') { - char *p = htoa((u32)va_arg(args, int)); - serial_print(p); - free(p); - readyToFormat = 0; - } else if (buff == 'd') { - char *p = itoa(va_arg(args, int)); - serial_print(p); - free(p); - readyToFormat = 0; - } else if (buff == 'c') { - serial_put((char)va_arg(args, int)); - readyToFormat = 0; - } - } else { - if (*fmt == '%') - readyToFormat = 1; - else - serial_put(*fmt); - } - } + char buf[1024]; + memset(buf, 0, 1024); + vsprintf(buf, fmt, args); + serial_print(buf); } void serial_printf(const char *fmt, ...) -- cgit v1.2.3