Commit dc5b0465 authored by Adam Wujek's avatar Adam Wujek 💬 Committed by Grzegorz Daniluk

pp-printf: add support for precision greather than 9

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent cbe72cab
...@@ -13,6 +13,9 @@ static int number(char *out, unsigned value, int base, int lead, int wid) ...@@ -13,6 +13,9 @@ static int number(char *out, unsigned value, int base, int lead, int wid)
char tmp[16]; char tmp[16];
int i = 16, ret, negative = 0; int i = 16, ret, negative = 0;
if (wid == 0)
wid = 1;
/* No error checking at all: it is as ugly as possible */ /* No error checking at all: it is as ugly as possible */
if ((signed)value < 0 && base == 10) { if ((signed)value < 0 && base == 10) {
negative = 1; negative = 1;
...@@ -51,23 +54,27 @@ int pp_vsprintf(char *buf, const char *fmt, va_list args) ...@@ -51,23 +54,27 @@ int pp_vsprintf(char *buf, const char *fmt, va_list args)
base = 10; base = 10;
lead = ' '; lead = ' ';
wid = 1; wid = 0;
repeat: repeat:
fmt++; /* Skip '%' initially, other stuff later */ fmt++; /* Skip '%' initially, other stuff later */
switch(*fmt) { switch(*fmt) {
case '\0': case '\0':
goto ret; goto ret;
case '0':
lead = '0';
goto repeat;
case '*': case '*':
/* should be precision, just eat it */ /* should be precision, just eat it */
base = va_arg(args, int); base = va_arg(args, int);
/* fall through: discard unknown stuff */ /* fall through: discard unknown stuff */
case '0':
if (wid == 0) {
lead = '0';
goto repeat;
} /* else go to default */
default: default:
if (*fmt >= '1' && *fmt <= '9') if (*fmt >= '0' && *fmt <= '9') {
wid = *fmt - '0'; /* decimal shift left */
wid *= 10;
wid += *fmt - '0';
}
goto repeat; goto repeat;
/* Special cases for conversions */ /* Special cases for conversions */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment