diff --git a/ChangeLog b/ChangeLog
index e395d88..bcc8586 100644
a
|
b
|
|
| 1 | 2009-02-07 Martin Petricek <tux@centrum.cz> |
| 2 | |
| 3 | * doc/mc.1.in: Added help about config file option to use SI or binary |
| 4 | byte size prefixes (powers of 1000 or 1024) |
| 5 | |
diff --git a/doc/mc.1.in b/doc/mc.1.in
index 9e908e6..f65ba14 100644
a
|
b
|
This value is the number of seconds the Midnight Commander will wait |
3125 | 3125 | before attempting to reconnect to an FTP server that has denied the |
3126 | 3126 | login. If the value is zero, the login will no be retried. |
3127 | 3127 | .TP |
| 3128 | .I kilobyte_si |
| 3129 | If this option is set (kilobyte_si=1), Midnight Commander will use SI units |
| 3130 | (powers of 1000) when displaying any byte sizes. The suffixes (k, m ...) |
| 3131 | are shown in lowercase. |
| 3132 | If unset (default), Midnight Commander will use binary units (powers of 1024) |
| 3133 | and the suffixes are shown in upper case (K, M ...) |
| 3134 | .TP |
3128 | 3135 | .I max_dirt_limit |
3129 | 3136 | Specifies how many screen updates can be skipped at most in the internal |
3130 | 3137 | file viewer. Normally this value is not significant, because the code |
diff --git a/src/ChangeLog b/src/ChangeLog
index d17dd69..1a48495 100644
a
|
b
|
|
| 1 | 2009-02-07 Martin Petricek <tux@centrum.cz> |
| 2 | |
| 3 | * setup.c: added option to modify size format used to display |
| 4 | byte sizes - in adition to current binary size prefixes, SI |
| 5 | (1000 based) size prefixes are now also possible. |
| 6 | * util.c: modified size_trunc() and size_trunc_len() to |
| 7 | allow using SI size prefixes. |
diff --git a/src/setup.c b/src/setup.c
index eaa86a7..312b17e 100644
a
|
b
|
|
65 | 65 | |
66 | 66 | extern char *find_ignore_dirs; |
67 | 67 | |
| 68 | extern bool kilobyte_si; /* util.c */ |
| 69 | |
68 | 70 | extern int num_history_items_recorded; |
69 | 71 | |
70 | 72 | char *profile_name; /* .mc/ini */ |
… |
… |
load_setup (void) |
566 | 568 | load_string ("Colors", "color_terminals", "", |
567 | 569 | color_terminal_string, sizeof (color_terminal_string)); |
568 | 570 | |
| 571 | kilobyte_si = load_int ("Misc", "kilobyte_si", 0); |
569 | 572 | /* Load the directory history */ |
570 | 573 | /* directory_history_load (); */ |
571 | 574 | /* Remove the temporal entries */ |
diff --git a/src/util.c b/src/util.c
index dc03468..d3d34bb 100644
a
|
b
|
path_trunc (const char *path, size_t trunc_len) { |
276 | 276 | return ret; |
277 | 277 | } |
278 | 278 | |
| 279 | /* |
| 280 | * If true, SI units (1000 based) will be used for |
| 281 | * larger units (kilobyte, megabyte, ...). |
| 282 | * If false binary units (1024 based) will be used. |
| 283 | */ |
| 284 | bool kilobyte_si = 0; |
| 285 | |
279 | 286 | const char * |
280 | 287 | size_trunc (double size) |
281 | 288 | { |
… |
… |
size_trunc (double size) |
284 | 291 | const char *xtra = ""; |
285 | 292 | |
286 | 293 | if (size > 999999999L){ |
287 | | divisor = 1024; |
288 | | xtra = "K"; |
| 294 | divisor = kilobyte_si?1000:1024; |
| 295 | xtra = kilobyte_si?"k":"K"; |
289 | 296 | if (size/divisor > 999999999L){ |
290 | | divisor = 1024*1024; |
291 | | xtra = "M"; |
| 297 | divisor = kilobyte_si?(1000*1000):(1024*1024); |
| 298 | xtra = kilobyte_si?"m":"M"; |
292 | 299 | } |
293 | 300 | } |
294 | 301 | snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
340 | 347 | 1000000000}; |
341 | 348 | static const char * const suffix [] = |
342 | 349 | {"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL}; |
| 350 | static const char * const suffix_lc [] = |
| 351 | {"", "k", "m", "g", "t", "p", "e", "z", "y", NULL}; |
343 | 352 | int j = 0; |
| 353 | int size_remain; |
344 | 354 | |
345 | 355 | /* Don't print more than 9 digits - use suffix. */ |
346 | 356 | if (len == 0 || len > 9) |
347 | 357 | len = 9; |
348 | 358 | |
| 359 | /* |
| 360 | * recalculate from 1024 base to 1000 base if units>0 |
| 361 | * We can't just multiply by 1024 - that might cause overflow |
| 362 | * if off_t type is too small |
| 363 | */ |
| 364 | if (units && kilobyte_si) { |
| 365 | for (j = 0; j < units; j++) { |
| 366 | size_remain=((size % 125)*1024)/1000; /* size mod 125, recalculated */ |
| 367 | size = size / 125; /* 128/125 = 1024/1000 */ |
| 368 | size = size * 128; /* This will convert size from multiple of 1024 to multiple of 1000 */ |
| 369 | size += size_remain; /* Re-add remainder lost by division/multiplication */ |
| 370 | } |
| 371 | } |
| 372 | |
349 | 373 | for (j = units; suffix [j] != NULL; j++) { |
350 | 374 | if (size == 0) { |
351 | 375 | if (j == units) { |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
356 | 380 | |
357 | 381 | /* Use "~K" or just "K" if len is 1. Use "B" for bytes. */ |
358 | 382 | snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s", |
359 | | (j > 1) ? suffix[j - 1] : "B"); |
| 383 | (j > 1) ? (kilobyte_si ? suffix_lc[j - 1] : suffix[j - 1]) : "B"); |
360 | 384 | break; |
361 | 385 | } |
362 | 386 | |
363 | 387 | if (size < power10 [len - (j > 0)]) { |
364 | | snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, suffix[j]); |
| 388 | snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, kilobyte_si ? suffix_lc[j] : suffix[j]); |
365 | 389 | break; |
366 | 390 | } |
367 | 391 | |
368 | | /* Powers of 1024, with rounding. */ |
369 | | size = (size + 512) >> 10; |
| 392 | /* Powers of 1000 or 1024, with rounding. */ |
| 393 | if (kilobyte_si) { |
| 394 | size = (size + 512) >> 10; |
| 395 | } else { |
| 396 | size = (size + 500) / 1000; |
| 397 | } |
370 | 398 | } |
371 | 399 | } |
372 | 400 | |