X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/71458b3b2492943349f7693a46792756d5013c69..5be8db81:/sbr/fmt_scan.c?ds=inline diff --git a/sbr/fmt_scan.c b/sbr/fmt_scan.c index e4d79d57..c8cdece5 100644 --- a/sbr/fmt_scan.c +++ b/sbr/fmt_scan.c @@ -490,6 +490,41 @@ fmt_scan (struct format *format, char *scanl, size_t max, int width, int *dat, cp += n; } break; + case FT_LS_UNITS: + { + char *unitcp; + unsigned int whole, tenths; + + if (value < 1000) { + snprintf(buffer, sizeof(buffer), "%u", value); + } else { + + /* find correct scale for size (Kilo/Mega/Giga/Tera) */ + for (unitcp = "KMGT"; value > 999999; value /= 1000) { + if (!*++unitcp) + break; + } + + if (!*unitcp) { + strcpy(buffer, "huge"); + } else { + /* round up to next higer tenth of kilo-/mega-/giga- */ + value += 99; value /= 100; + + /* want one digit after decimal, avoid float */ + whole = value / 10; + tenths = value - (whole * 10); + + if (tenths) { + snprintf(buffer, sizeof(buffer), "%u.%u%c", whole, tenths, *unitcp); + } else { + snprintf(buffer, sizeof(buffer), "%u%c", whole, *unitcp); + } + } + } + str = buffer; + } + break; case FT_NUMF: cpnumber (&cp, value, fmt->f_width, fmt->f_fill, ep - cp); break;