From 45a5ecc72d8e700614a0751f0e7ec68199885b77 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 29 May 2020 23:47:29 +0200 Subject: Added more printf features --- src/kernel/lib/stdio/vsprintf.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/kernel/lib/stdio') diff --git a/src/kernel/lib/stdio/vsprintf.c b/src/kernel/lib/stdio/vsprintf.c index 6584ed1..61f4323 100644 --- a/src/kernel/lib/stdio/vsprintf.c +++ b/src/kernel/lib/stdio/vsprintf.c @@ -27,20 +27,30 @@ int vsprintf(char *str, const char *fmt, va_list args) } buf = *fmt; + + // TODO: Improve this repetitive code if (buf == 's') { char *string = va_arg(args, char *); append(str, string, i); i = strlen(str); } else if (buf == 'x') { - itoa_base((u32)va_arg(args, int), format_buffer, 16); + itoa_base(va_arg(args, u32), format_buffer, 16, 0); + append(str, format_buffer, i); + i = strlen(str); + } else if (buf == 'd' || buf == 'i') { + itoa_base(va_arg(args, s32), format_buffer, 10, 1); append(str, format_buffer, i); i = strlen(str); - } else if (buf == 'd') { - itoa_base(va_arg(args, int), format_buffer, 10); + } else if (buf == 'u') { + itoa_base(va_arg(args, u32), format_buffer, 10, 0); append(str, format_buffer, i); i = strlen(str); } else if (buf == 'o') { - itoa_base(va_arg(args, int), format_buffer, 8); + itoa_base(va_arg(args, u32), format_buffer, 8, 0); + append(str, format_buffer, i); + i = strlen(str); + } else if (buf == 'b') { + itoa_base(va_arg(args, u32), format_buffer, 2, 0); append(str, format_buffer, i); i = strlen(str); } else if (buf == 'c') { -- cgit v1.2.3