Ticket #268: kilobyte-git.5.patch

File kilobyte-git.5.patch, 5.9 KB (added by bilbo, 15 years ago)

Added configuration for this option into dialog

  • doc/man/mc.1.in

    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 
    31393139before attempting to reconnect to an FTP server that has denied the 
    31403140login.  If the value is zero, the login will no be retried. 
    31413141.TP 
     3142.I kilobyte_si 
     3143If 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 ...) 
     3145are shown in lowercase. 
     3146If unset (default), Midnight Commander will use binary units (powers of 1024) 
     3147and the suffixes are shown in upper case (K, M ...) 
     3148.TP 
    31423149.I max_dirt_limit 
    31433150Specifies how many screen updates can be skipped at most in the internal 
    31443151file viewer.  Normally this value is not significant, because the code 
  • src/dir.c

    diff --git a/src/dir.c b/src/dir.c
    index 9bd371f..181140c 100644
    a b int show_backups = 1; 
    4545/* If false then directories are shown separately from files */ 
    4646int mix_all_files = 0; 
    4747 
     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 */ 
     53int kilobyte_si = 0; 
     54 
    4855/* Reverse flag */ 
    4956static int reverse = 1; 
    5057 
  • src/dir.h

    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); 
    8383extern int show_backups; 
    8484extern int show_dot_files; 
    8585extern int mix_all_files; 
     86extern int kilobyte_si; 
    8687 
    8788#endif 
  • src/main.c

    diff --git a/src/main.c b/src/main.c
    index 04f8d5a..7fc028b 100644
    a b toggle_show_hidden (void) 
    883883    update_panels (UP_RELOAD, UP_KEEPSEL); 
    884884} 
    885885 
     886void 
     887toggle_kilobyte_si (void) 
     888{ 
     889    kilobyte_si = !kilobyte_si; 
     890    update_panels (UP_RELOAD, UP_KEEPSEL); 
     891} 
     892 
    886893/* 
    887894 * Just a hack for allowing url-like pathnames to be accepted from the 
    888895 * command line. 
  • src/main.h

    diff --git a/src/main.h b/src/main.h
    index 6e1fe2c..aac3ec0 100644
    a b void toggle_fast_reload (void); 
    1111void toggle_mix_all_files (void); 
    1212void toggle_show_backup (void); 
    1313void toggle_show_hidden (void); 
     14void toggle_kilobyte_si (void); 
    1415 
    1516extern int quote; 
    1617extern volatile int quit; 
  • src/option.c

    diff --git a/src/option.c b/src/option.c
    index 64aad7b..1815bcc 100644
    a b static struct { 
    7878   {N_("ma&Rk moves down"),   &mark_moves_down,   TOGGLE_VARIABLE,       0 }, 
    7979   {N_("show &Hidden files"), &show_dot_files,    toggle_show_hidden,    0 }, 
    8080   {N_("show &Backup files"), &show_backups,      toggle_show_backup,    0 }, 
     81   {N_("SI si&ze prefixes"),  &kilobyte_si,       toggle_kilobyte_si,    0 }, 
    8182   { 0, 0, 0, 0 } 
    8283}; 
    8384 
    8485/* Make sure this corresponds to the check_options structure */ 
    8586#define OTHER_OPTIONS 13 
    86 #define PANEL_OPTIONS 6 
     87#define PANEL_OPTIONS 7 
    8788 
    8889static WRadio *pause_radio; 
    8990 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 66b1e23..256cca1 100644
    a b static const struct { 
    148148    int  *opt_addr; 
    149149} int_options [] = { 
    150150    { "show_backups", &show_backups }, 
     151    { "kilobyte_si", &kilobyte_si }, 
    151152    { "show_dot_files", &show_dot_files }, 
    152153    { "verbose", &verbose }, 
    153154    { "mark_moves_down", &mark_moves_down }, 
  • src/util.c

    diff --git a/src/util.c b/src/util.c
    index 2649182..3d5a5c8 100644
    a b  
    5353#include "strutil.h" 
    5454#include "fileopctx.h" 
    5555#include "file.h"               /* copy_file_file() */ 
     56#include "dir.h" 
    5657 
    5758#ifdef HAVE_CHARSET 
    5859#include "charsets.h" 
    size_trunc (double size) 
    271272    const char *xtra = ""; 
    272273     
    273274    if (size > 999999999L){ 
    274         divisor = 1024; 
    275         xtra = "K"; 
     275        divisor = kilobyte_si?1000:1024; 
     276        xtra = kilobyte_si?"k":"K"; 
    276277        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"; 
    279280        } 
    280281    } 
    281282    g_snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); 
    size_trunc_len (char *buffer, int len, off_t size, int units) 
    327328         1000000000}; 
    328329    static const char * const suffix [] = 
    329330        {"", "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}; 
    330333    int j = 0; 
     334    int size_remain; 
    331335 
    332336    /* Don't print more than 9 digits - use suffix.  */ 
    333337    if (len == 0 || len > 9) 
    334338        len = 9; 
    335339 
     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 
    336354    for (j = units; suffix [j] != NULL; j++) { 
    337355        if (size == 0) { 
    338356            if (j == units) { 
    size_trunc_len (char *buffer, int len, off_t size, int units) 
    343361 
    344362            /* Use "~K" or just "K" if len is 1.  Use "B" for bytes.  */ 
    345363            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"); 
    347365            break; 
    348366        } 
    349367 
    350368        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]); 
    352370            break; 
    353371        } 
    354372 
    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        } 
    357379    } 
    358380} 
    359381