diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in
index 22f354e..6a56a7b 100644
a
|
b
|
This value is the number of seconds the Midnight Commander will wait |
3139 | 3139 | before attempting to reconnect to an FTP server that has denied the |
3140 | 3140 | login. If the value is zero, the login will no be retried. |
3141 | 3141 | .TP |
| 3142 | .I kilobyte_si |
| 3143 | If this option is set (kilobyte_si=1), Midnight Commander will use SI units |
| 3144 | (powers of 1000) when displaying any byte sizes. The suffixes (k, m ...) |
| 3145 | are shown in lowercase. |
| 3146 | If unset (default), Midnight Commander will use binary units (powers of 1024) |
| 3147 | and the suffixes are shown in upper case (K, M ...) |
| 3148 | .TP |
3142 | 3149 | .I max_dirt_limit |
3143 | 3150 | Specifies how many screen updates can be skipped at most in the internal |
3144 | 3151 | file viewer. Normally this value is not significant, because the code |
diff --git a/src/setup.c b/src/setup.c
index 66b1e23..83d8b21 100644
a
|
b
|
|
70 | 70 | |
71 | 71 | extern char *find_ignore_dirs; |
72 | 72 | |
| 73 | extern int kilobyte_si; /* util.c */ |
| 74 | |
73 | 75 | extern int num_history_items_recorded; |
74 | 76 | |
75 | 77 | char *profile_name; /* .mc/ini */ |
… |
… |
load_setup (void) |
649 | 651 | term_color_string = mc_config_get_string(mc_main_config, "Colors", getenv ("TERM"), ""); |
650 | 652 | color_terminal_string = mc_config_get_string(mc_main_config, "Colors", "color_terminals", ""); |
651 | 653 | |
| 654 | kilobyte_si = mc_config_get_int(mc_main_config, "Misc", "kilobyte_si", 0); |
652 | 655 | /* Load the directory history */ |
653 | 656 | /* directory_history_load (); */ |
654 | 657 | /* Remove the temporal entries */ |
diff --git a/src/util.c b/src/util.c
index 2649182..a0140c8 100644
a
|
b
|
path_trunc (const char *path, size_t trunc_len) { |
263 | 263 | return ret; |
264 | 264 | } |
265 | 265 | |
| 266 | /* |
| 267 | * If true, SI units (1000 based) will be used for |
| 268 | * larger units (kilobyte, megabyte, ...). |
| 269 | * If false binary units (1024 based) will be used. |
| 270 | */ |
| 271 | int kilobyte_si = 0; |
| 272 | |
266 | 273 | const char * |
267 | 274 | size_trunc (double size) |
268 | 275 | { |
… |
… |
size_trunc (double size) |
271 | 278 | const char *xtra = ""; |
272 | 279 | |
273 | 280 | if (size > 999999999L){ |
274 | | divisor = 1024; |
275 | | xtra = "K"; |
| 281 | divisor = kilobyte_si?1000:1024; |
| 282 | xtra = kilobyte_si?"k":"K"; |
276 | 283 | if (size/divisor > 999999999L){ |
277 | | divisor = 1024*1024; |
278 | | xtra = "M"; |
| 284 | divisor = kilobyte_si?(1000*1000):(1024*1024); |
| 285 | xtra = kilobyte_si?"m":"M"; |
279 | 286 | } |
280 | 287 | } |
281 | 288 | g_snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
327 | 334 | 1000000000}; |
328 | 335 | static const char * const suffix [] = |
329 | 336 | {"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL}; |
| 337 | static const char * const suffix_lc [] = |
| 338 | {"", "k", "m", "g", "t", "p", "e", "z", "y", NULL}; |
330 | 339 | int j = 0; |
| 340 | int size_remain; |
331 | 341 | |
332 | 342 | /* Don't print more than 9 digits - use suffix. */ |
333 | 343 | if (len == 0 || len > 9) |
334 | 344 | len = 9; |
335 | 345 | |
| 346 | /* |
| 347 | * recalculate from 1024 base to 1000 base if units>0 |
| 348 | * We can't just multiply by 1024 - that might cause overflow |
| 349 | * if off_t type is too small |
| 350 | */ |
| 351 | if (units && kilobyte_si) { |
| 352 | for (j = 0; j < units; j++) { |
| 353 | size_remain=((size % 125)*1024)/1000; /* size mod 125, recalculated */ |
| 354 | size = size / 125; /* 128/125 = 1024/1000 */ |
| 355 | size = size * 128; /* This will convert size from multiple of 1024 to multiple of 1000 */ |
| 356 | size += size_remain; /* Re-add remainder lost by division/multiplication */ |
| 357 | } |
| 358 | } |
| 359 | |
336 | 360 | for (j = units; suffix [j] != NULL; j++) { |
337 | 361 | if (size == 0) { |
338 | 362 | if (j == units) { |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
343 | 367 | |
344 | 368 | /* Use "~K" or just "K" if len is 1. Use "B" for bytes. */ |
345 | 369 | g_snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s", |
346 | | (j > 1) ? suffix[j - 1] : "B"); |
| 370 | (j > 1) ? (kilobyte_si ? suffix_lc[j - 1] : suffix[j - 1]) : "B"); |
347 | 371 | break; |
348 | 372 | } |
349 | 373 | |
350 | 374 | if (size < power10 [len - (j > 0)]) { |
351 | | g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, suffix[j]); |
| 375 | g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, kilobyte_si ? suffix_lc[j] : suffix[j]); |
352 | 376 | break; |
353 | 377 | } |
354 | 378 | |
355 | | /* Powers of 1024, with rounding. */ |
356 | | size = (size + 512) >> 10; |
| 379 | /* Powers of 1000 or 1024, with rounding. */ |
| 380 | if (kilobyte_si) { |
| 381 | size = (size + 500) / 1000; |
| 382 | } else { |
| 383 | size = (size + 512) >> 10; |
| 384 | } |
357 | 385 | } |
358 | 386 | } |
359 | 387 | |