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/dir.c b/src/dir.c
index 9bd371f..181140c 100644
a
|
b
|
int show_backups = 1; |
45 | 45 | /* If false then directories are shown separately from files */ |
46 | 46 | int mix_all_files = 0; |
47 | 47 | |
| 48 | /* |
| 49 | * If true, SI units (1000 based) will be used for |
| 50 | * larger units (kilobyte, megabyte, ...). |
| 51 | * If false binary units (1024 based) will be used. |
| 52 | */ |
| 53 | int kilobyte_si = 0; |
| 54 | |
48 | 55 | /* Reverse flag */ |
49 | 56 | static int reverse = 1; |
50 | 57 | |
diff --git a/src/dir.h b/src/dir.h
index 2a4d92a..9ee0096 100644
a
|
b
|
int if_link_is_exe (const char *full_name, const file_entry *file); |
83 | 83 | extern int show_backups; |
84 | 84 | extern int show_dot_files; |
85 | 85 | extern int mix_all_files; |
| 86 | extern int kilobyte_si; |
86 | 87 | |
87 | 88 | #endif |
diff --git a/src/main.c b/src/main.c
index 04f8d5a..7fc028b 100644
a
|
b
|
toggle_show_hidden (void) |
883 | 883 | update_panels (UP_RELOAD, UP_KEEPSEL); |
884 | 884 | } |
885 | 885 | |
| 886 | void |
| 887 | toggle_kilobyte_si (void) |
| 888 | { |
| 889 | kilobyte_si = !kilobyte_si; |
| 890 | update_panels (UP_RELOAD, UP_KEEPSEL); |
| 891 | } |
| 892 | |
886 | 893 | /* |
887 | 894 | * Just a hack for allowing url-like pathnames to be accepted from the |
888 | 895 | * command line. |
diff --git a/src/main.h b/src/main.h
index 6e1fe2c..aac3ec0 100644
a
|
b
|
void toggle_fast_reload (void); |
11 | 11 | void toggle_mix_all_files (void); |
12 | 12 | void toggle_show_backup (void); |
13 | 13 | void toggle_show_hidden (void); |
| 14 | void toggle_kilobyte_si (void); |
14 | 15 | |
15 | 16 | extern int quote; |
16 | 17 | extern volatile int quit; |
diff --git a/src/option.c b/src/option.c
index 64aad7b..1815bcc 100644
a
|
b
|
static struct { |
78 | 78 | {N_("ma&Rk moves down"), &mark_moves_down, TOGGLE_VARIABLE, 0 }, |
79 | 79 | {N_("show &Hidden files"), &show_dot_files, toggle_show_hidden, 0 }, |
80 | 80 | {N_("show &Backup files"), &show_backups, toggle_show_backup, 0 }, |
| 81 | {N_("SI si&ze prefixes"), &kilobyte_si, toggle_kilobyte_si, 0 }, |
81 | 82 | { 0, 0, 0, 0 } |
82 | 83 | }; |
83 | 84 | |
84 | 85 | /* Make sure this corresponds to the check_options structure */ |
85 | 86 | #define OTHER_OPTIONS 13 |
86 | | #define PANEL_OPTIONS 6 |
| 87 | #define PANEL_OPTIONS 7 |
87 | 88 | |
88 | 89 | static WRadio *pause_radio; |
89 | 90 | |
diff --git a/src/setup.c b/src/setup.c
index 66b1e23..256cca1 100644
a
|
b
|
static const struct { |
148 | 148 | int *opt_addr; |
149 | 149 | } int_options [] = { |
150 | 150 | { "show_backups", &show_backups }, |
| 151 | { "kilobyte_si", &kilobyte_si }, |
151 | 152 | { "show_dot_files", &show_dot_files }, |
152 | 153 | { "verbose", &verbose }, |
153 | 154 | { "mark_moves_down", &mark_moves_down }, |
diff --git a/src/util.c b/src/util.c
index 2649182..3d5a5c8 100644
a
|
b
|
|
53 | 53 | #include "strutil.h" |
54 | 54 | #include "fileopctx.h" |
55 | 55 | #include "file.h" /* copy_file_file() */ |
| 56 | #include "dir.h" |
56 | 57 | |
57 | 58 | #ifdef HAVE_CHARSET |
58 | 59 | #include "charsets.h" |
… |
… |
size_trunc (double size) |
271 | 272 | const char *xtra = ""; |
272 | 273 | |
273 | 274 | if (size > 999999999L){ |
274 | | divisor = 1024; |
275 | | xtra = "K"; |
| 275 | divisor = kilobyte_si?1000:1024; |
| 276 | xtra = kilobyte_si?"k":"K"; |
276 | 277 | if (size/divisor > 999999999L){ |
277 | | divisor = 1024*1024; |
278 | | xtra = "M"; |
| 278 | divisor = kilobyte_si?(1000*1000):(1024*1024); |
| 279 | xtra = kilobyte_si?"m":"M"; |
279 | 280 | } |
280 | 281 | } |
281 | 282 | g_snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
327 | 328 | 1000000000}; |
328 | 329 | static const char * const suffix [] = |
329 | 330 | {"", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL}; |
| 331 | static const char * const suffix_lc [] = |
| 332 | {"", "k", "m", "g", "t", "p", "e", "z", "y", NULL}; |
330 | 333 | int j = 0; |
| 334 | int size_remain; |
331 | 335 | |
332 | 336 | /* Don't print more than 9 digits - use suffix. */ |
333 | 337 | if (len == 0 || len > 9) |
334 | 338 | len = 9; |
335 | 339 | |
| 340 | /* |
| 341 | * recalculate from 1024 base to 1000 base if units>0 |
| 342 | * We can't just multiply by 1024 - that might cause overflow |
| 343 | * if off_t type is too small |
| 344 | */ |
| 345 | if (units && kilobyte_si) { |
| 346 | for (j = 0; j < units; j++) { |
| 347 | size_remain=((size % 125)*1024)/1000; /* size mod 125, recalculated */ |
| 348 | size = size / 125; /* 128/125 = 1024/1000 */ |
| 349 | size = size * 128; /* This will convert size from multiple of 1024 to multiple of 1000 */ |
| 350 | size += size_remain; /* Re-add remainder lost by division/multiplication */ |
| 351 | } |
| 352 | } |
| 353 | |
336 | 354 | for (j = units; suffix [j] != NULL; j++) { |
337 | 355 | if (size == 0) { |
338 | 356 | if (j == units) { |
… |
… |
size_trunc_len (char *buffer, int len, off_t size, int units) |
343 | 361 | |
344 | 362 | /* Use "~K" or just "K" if len is 1. Use "B" for bytes. */ |
345 | 363 | g_snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s", |
346 | | (j > 1) ? suffix[j - 1] : "B"); |
| 364 | (j > 1) ? (kilobyte_si ? suffix_lc[j - 1] : suffix[j - 1]) : "B"); |
347 | 365 | break; |
348 | 366 | } |
349 | 367 | |
350 | 368 | if (size < power10 [len - (j > 0)]) { |
351 | | g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, suffix[j]); |
| 369 | g_snprintf (buffer, len + 1, "%lu%s", (unsigned long) size, kilobyte_si ? suffix_lc[j] : suffix[j]); |
352 | 370 | break; |
353 | 371 | } |
354 | 372 | |
355 | | /* Powers of 1024, with rounding. */ |
356 | | size = (size + 512) >> 10; |
| 373 | /* Powers of 1000 or 1024, with rounding. */ |
| 374 | if (kilobyte_si) { |
| 375 | size = (size + 500) / 1000; |
| 376 | } else { |
| 377 | size = (size + 512) >> 10; |
| 378 | } |
357 | 379 | } |
358 | 380 | } |
359 | 381 | |