Ticket #268: kilobyte-git.4.patch

File kilobyte-git.4.patch, 4.2 KB (added by bilbo, 10 years ago)

Update to current master

  • 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/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 66b1e23..83d8b21 100644
    a b  
    7070 
    7171extern char *find_ignore_dirs; 
    7272 
     73extern int kilobyte_si; /* util.c */ 
     74 
    7375extern int num_history_items_recorded; 
    7476 
    7577char *profile_name;             /* .mc/ini */ 
    load_setup (void) 
    649651    term_color_string = mc_config_get_string(mc_main_config, "Colors", getenv ("TERM"), ""); 
    650652    color_terminal_string = mc_config_get_string(mc_main_config, "Colors", "color_terminals", ""); 
    651653 
     654    kilobyte_si = mc_config_get_int(mc_main_config, "Misc", "kilobyte_si", 0); 
    652655    /* Load the directory history */ 
    653656/*    directory_history_load (); */ 
    654657    /* Remove the temporal entries */ 
  • src/util.c

    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) { 
    263263    return ret; 
    264264} 
    265265 
     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 */ 
     271int kilobyte_si = 0; 
     272 
    266273const char * 
    267274size_trunc (double size) 
    268275{ 
    size_trunc (double size) 
    271278    const char *xtra = ""; 
    272279     
    273280    if (size > 999999999L){ 
    274         divisor = 1024; 
    275         xtra = "K"; 
     281        divisor = kilobyte_si?1000:1024; 
     282        xtra = kilobyte_si?"k":"K"; 
    276283        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"; 
    279286        } 
    280287    } 
    281288    g_snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); 
    size_trunc_len (char *buffer, int len, off_t size, int units) 
    327334         1000000000}; 
    328335    static const char * const suffix [] = 
    329336        {"", "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}; 
    330339    int j = 0; 
     340    int size_remain; 
    331341 
    332342    /* Don't print more than 9 digits - use suffix.  */ 
    333343    if (len == 0 || len > 9) 
    334344        len = 9; 
    335345 
     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 
    336360    for (j = units; suffix [j] != NULL; j++) { 
    337361        if (size == 0) { 
    338362            if (j == units) { 
    size_trunc_len (char *buffer, int len, off_t size, int units) 
    343367 
    344368            /* Use "~K" or just "K" if len is 1.  Use "B" for bytes.  */ 
    345369            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"); 
    347371            break; 
    348372        } 
    349373 
    350374        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]); 
    352376            break; 
    353377        } 
    354378 
    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        } 
    357385    } 
    358386} 
    359387