diff --git a/ChangeLog b/ChangeLog
index b001a2c..d25c091 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/man/mc.1.in b/doc/man/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 6359281..0b5207c 100644
a
|
b
|
|
68 | 68 | |
69 | 69 | extern char *find_ignore_dirs; |
70 | 70 | |
| 71 | extern int kilobyte_si; /* util.c */ |
| 72 | |
71 | 73 | extern int num_history_items_recorded; |
72 | 74 | |
73 | 75 | char *profile_name; /* .mc/ini */ |
… |
… |
load_setup (void) |
574 | 576 | load_string ("Colors", "color_terminals", "", |
575 | 577 | color_terminal_string, sizeof (color_terminal_string)); |
576 | 578 | |
| 579 | kilobyte_si = load_int ("Misc", "kilobyte_si", 0); |
577 | 580 | /* Load the directory history */ |
578 | 581 | /* directory_history_load (); */ |
579 | 582 | /* Remove the temporal entries */ |
diff --git a/src/util.c b/src/util.c
index 5195a24..b2d3d89 100644
a
|
b
|
path_trunc (const char *path, size_t trunc_len) { |
252 | 252 | return ret; |
253 | 253 | } |
254 | 254 | |
| 255 | /* |
| 256 | * If true, SI units (1000 based) will be used for |
| 257 | * larger units (kilobyte, megabyte, ...). |
| 258 | * If false binary units (1024 based) will be used. |
| 259 | */ |
| 260 | int kilobyte_si = 0; |
| 261 | |
255 | 262 | const char * |
256 | 263 | size_trunc (double size) |
257 | 264 | { |
… |
… |
size_trunc (double size) |
260 | 267 | const char *xtra = ""; |
261 | 268 | |
262 | 269 | if (size > 999999999L){ |
263 | | divisor = 1024; |
264 | | xtra = "K"; |
| 270 | divisor = kilobyte_si?1000:1024; |
| 271 | xtra = kilobyte_si?"k":"K"; |
265 | 272 | if (size/divisor > 999999999L){ |
266 | | divisor = 1024*1024; |
267 | | xtra = "M"; |
| 273 | divisor = kilobyte_si?(1000*1000):(1024*1024); |
| 274 | xtra = kilobyte_si?"m":"M"; |
268 | 275 | } |
269 | 276 | } |
270 | 277 | g_snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
316 | 323 | 1000000000}; |
317 | 324 | static const char * const suffix [] = |
318 | 325 | {"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL}; |
| 326 | static const char * const suffix_lc [] = |
| 327 | {"", "k", "m", "g", "t", "p", "e", "z", "y", NULL}; |
319 | 328 | int j = 0; |
| 329 | int size_remain; |
320 | 330 | |
321 | 331 | /* Don't print more than 9 digits - use suffix. */ |
322 | 332 | if (len == 0 || len > 9) |
323 | 333 | len = 9; |
324 | 334 | |
| 335 | /* |
| 336 | * recalculate from 1024 base to 1000 base if units>0 |
| 337 | * We can't just multiply by 1024 - that might cause overflow |
| 338 | * if off_t type is too small |
| 339 | */ |
| 340 | if (units && kilobyte_si) { |
| 341 | for (j = 0; j < units; j++) { |
| 342 | size_remain=((size % 125)*1024)/1000; /* size mod 125, recalculated */ |
| 343 | size = size / 125; /* 128/125 = 1024/1000 */ |
| 344 | size = size * 128; /* This will convert size from multiple of 1024 to multiple of 1000 */ |
| 345 | size += size_remain; /* Re-add remainder lost by division/multiplication */ |
| 346 | } |
| 347 | } |
| 348 | |
325 | 349 | for (j = units; suffix [j] != NULL; j++) { |
326 | 350 | if (size == 0) { |
327 | 351 | if (j == units) { |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
332 | 356 | |
333 | 357 | /* Use "~K" or just "K" if len is 1. Use "B" for bytes. */ |
334 | 358 | g_snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s", |
335 | | (j > 1) ? suffix[j - 1] : "B"); |
| 359 | (j > 1) ? (kilobyte_si ? suffix_lc[j - 1] : suffix[j - 1]) : "B"); |
336 | 360 | break; |
337 | 361 | } |
338 | 362 | |
339 | 363 | if (size < power10 [len - (j > 0)]) { |
340 | | g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, suffix[j]); |
| 364 | g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, kilobyte_si ? suffix_lc[j] : suffix[j]); |
341 | 365 | break; |
342 | 366 | } |
343 | 367 | |
344 | | /* Powers of 1024, with rounding. */ |
345 | | size = (size + 512) >> 10; |
| 368 | /* Powers of 1000 or 1024, with rounding. */ |
| 369 | if (kilobyte_si) { |
| 370 | size = (size + 500) / 1000; |
| 371 | } else { |
| 372 | size = (size + 512) >> 10; |
| 373 | } |
346 | 374 | } |
347 | 375 | } |
348 | 376 | |