Ticket #268: kilobyte-git.3.patch

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

Updated to current git master

  • ChangeLog

    diff --git a/ChangeLog b/ChangeLog
    index b001a2c..d25c091 100644
    a b  
     12009-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 
  • doc/man/mc.1.in

    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 
    31253125before attempting to reconnect to an FTP server that has denied the 
    31263126login.  If the value is zero, the login will no be retried. 
    31273127.TP 
     3128.I kilobyte_si 
     3129If 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 ...) 
     3131are shown in lowercase. 
     3132If unset (default), Midnight Commander will use binary units (powers of 1024) 
     3133and the suffixes are shown in upper case (K, M ...) 
     3134.TP 
    31283135.I max_dirt_limit 
    31293136Specifies how many screen updates can be skipped at most in the internal 
    31303137file viewer.  Normally this value is not significant, because the code 
  • src/ChangeLog

    diff --git a/src/ChangeLog b/src/ChangeLog
    index d17dd69..1a48495 100644
    a b  
     12009-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. 
  • src/setup.c

    diff --git a/src/setup.c b/src/setup.c
    index 6359281..0b5207c 100644
    a b  
    6868 
    6969extern char *find_ignore_dirs; 
    7070 
     71extern int kilobyte_si; /* util.c */ 
     72 
    7173extern int num_history_items_recorded; 
    7274 
    7375char *profile_name;             /* .mc/ini */ 
    load_setup (void) 
    574576    load_string ("Colors", "color_terminals", "", 
    575577                             color_terminal_string, sizeof (color_terminal_string)); 
    576578 
     579    kilobyte_si = load_int ("Misc", "kilobyte_si", 0); 
    577580    /* Load the directory history */ 
    578581/*    directory_history_load (); */ 
    579582    /* Remove the temporal entries */ 
  • src/util.c

    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) { 
    252252    return ret; 
    253253} 
    254254 
     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 */ 
     260int kilobyte_si = 0; 
     261 
    255262const char * 
    256263size_trunc (double size) 
    257264{ 
    size_trunc (double size) 
    260267    const char *xtra = ""; 
    261268     
    262269    if (size > 999999999L){ 
    263         divisor = 1024; 
    264         xtra = "K"; 
     270        divisor = kilobyte_si?1000:1024; 
     271        xtra = kilobyte_si?"k":"K"; 
    265272        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"; 
    268275        } 
    269276    } 
    270277    g_snprintf (x, sizeof (x), "%.0f%s", (size/divisor), xtra); 
    size_trunc_len (char *buffer, int len, off_t size, int units) 
    316323         1000000000}; 
    317324    static const char * const suffix [] = 
    318325        {"", "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}; 
    319328    int j = 0; 
     329    int size_remain; 
    320330 
    321331    /* Don't print more than 9 digits - use suffix.  */ 
    322332    if (len == 0 || len > 9) 
    323333        len = 9; 
    324334 
     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 
    325349    for (j = units; suffix [j] != NULL; j++) { 
    326350        if (size == 0) { 
    327351            if (j == units) { 
    size_trunc_len (char *buffer, int len, off_t size, int units) 
    332356 
    333357            /* Use "~K" or just "K" if len is 1.  Use "B" for bytes.  */ 
    334358            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"); 
    336360            break; 
    337361        } 
    338362 
    339363        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]); 
    341365            break; 
    342366        } 
    343367 
    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        } 
    346374    } 
    347375} 
    348376