diff options
| author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-05 00:44:39 +0000 |
|---|---|---|
| committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-05 00:44:39 +0000 |
| commit | aae0311356b4458e3a62fb19af656e00323e3bf1 (patch) | |
| tree | 95ef467494c3178ffb308b95f8743886d9c9a5ae /miscutils/nmeter.c | |
| parent | 459e4d6cf77940977a064edab60c7162731554fb (diff) | |
| download | busybox-w32-aae0311356b4458e3a62fb19af656e00323e3bf1.tar.gz busybox-w32-aae0311356b4458e3a62fb19af656e00323e3bf1.tar.bz2 busybox-w32-aae0311356b4458e3a62fb19af656e00323e3bf1.zip | |
smart_ulltoa5: make available in libbb
Diffstat (limited to 'miscutils/nmeter.c')
| -rw-r--r-- | miscutils/nmeter.c | 36 |
1 files changed, 1 insertions, 35 deletions
diff --git a/miscutils/nmeter.c b/miscutils/nmeter.c index d71bd6add..326d7b85f 100644 --- a/miscutils/nmeter.c +++ b/miscutils/nmeter.c | |||
| @@ -214,42 +214,8 @@ static int rdval_diskstats(const char* p, ullong *vec) | |||
| 214 | 214 | ||
| 215 | static void scale(ullong ul) | 215 | static void scale(ullong ul) |
| 216 | { | 216 | { |
| 217 | char *fmt; | ||
| 218 | char buf[5]; | 217 | char buf[5]; |
| 219 | char c; | 218 | smart_ulltoa5(ul, buf); |
| 220 | unsigned v,idx = 0; | ||
| 221 | ul *= 10; | ||
| 222 | if (ul > 9999*10) { // do not scale if 9999 or less | ||
| 223 | while (ul >= 10000) { | ||
| 224 | ul /= 1024; | ||
| 225 | idx++; | ||
| 226 | } | ||
| 227 | } | ||
| 228 | v = ul; // ullong divisions are expensive, avoid them | ||
| 229 | |||
| 230 | fmt = " 123456789"; | ||
| 231 | if (!idx) { // 9999 or less: use 1234 format | ||
| 232 | c = buf[0] = " 123456789"[v/10000]; | ||
| 233 | if (c!=' ') fmt = "0123456789"; | ||
| 234 | c = buf[1] = fmt[v/1000%10]; | ||
| 235 | if (c!=' ') fmt = "0123456789"; | ||
| 236 | buf[2] = fmt[v/100%10]; | ||
| 237 | buf[3] = "0123456789"[v/10%10]; | ||
| 238 | } else { | ||
| 239 | if (v>=10*10) { // scaled value is >=10: use 123M format | ||
| 240 | c = buf[0] = " 123456789"[v/1000]; | ||
| 241 | if (c!=' ') fmt = "0123456789"; | ||
| 242 | buf[1] = fmt[v/100%10]; | ||
| 243 | buf[2] = "0123456789"[v/10%10]; | ||
| 244 | } else { // scaled value is <10: use 1.2M format | ||
| 245 | buf[0] = "0123456789"[v/10]; | ||
| 246 | buf[1] = '.'; | ||
| 247 | buf[2] = "0123456789"[v%10]; | ||
| 248 | } | ||
| 249 | // see http://en.wikipedia.org/wiki/Tera | ||
| 250 | buf[3] = " kMGTPEZY"[idx]; | ||
| 251 | } | ||
| 252 | buf[4] = '\0'; | ||
| 253 | put(buf); | 219 | put(buf); |
| 254 | } | 220 | } |
| 255 | 221 | ||
