diff --git a/bdk/utils/sprintf.c b/bdk/utils/sprintf.c index 68e5ad6..a5b8cef 100644 --- a/bdk/utils/sprintf.c +++ b/bdk/utils/sprintf.c @@ -132,4 +132,70 @@ void s_printf(char *out_buf, const char *fmt, ...) out: **sout_buf = '\0'; va_end(ap); -} \ No newline at end of file +} + +void s_vprintf(char *out_buf, const char *fmt, va_list ap) +{ + int fill, fcnt; + + sout_buf = &out_buf; + + while(*fmt) + { + if(*fmt == '%') + { + fmt++; + fill = 0; + fcnt = 0; + if ((*fmt >= '0' && *fmt <= '9') || *fmt == ' ') + { + fcnt = *fmt; + fmt++; + if (*fmt >= '0' && *fmt <= '9') + { + fill = fcnt; + fcnt = *fmt - '0'; + fmt++; + } + else + { + fill = ' '; + fcnt -= '0'; + } + } + switch(*fmt) + { + case 'c': + _s_putc(va_arg(ap, u32)); + break; + case 's': + _s_puts(va_arg(ap, char *)); + break; + case 'd': + _s_putn(va_arg(ap, u32), 10, fill, fcnt); + break; + case 'p': + case 'P': + case 'x': + case 'X': + _s_putn(va_arg(ap, u32), 16, fill, fcnt); + break; + case '%': + _s_putc('%'); + break; + case '\0': + goto out; + default: + _s_putc('%'); + _s_putc(*fmt); + break; + } + } + else + _s_putc(*fmt); + fmt++; + } + +out: + **sout_buf = '\0'; +} diff --git a/bdk/utils/sprintf.h b/bdk/utils/sprintf.h index 845f9b7..412fb41 100644 --- a/bdk/utils/sprintf.h +++ b/bdk/utils/sprintf.h @@ -20,5 +20,6 @@ #include void s_printf(char *out_buf, const char *fmt, ...); +void s_vprintf(char *out_buf, const char *fmt, va_list ap); #endif \ No newline at end of file