id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	blockedby	blocking	branch_state	votes
3165	Display human readable sizes in panels	wentasah		"When midnight commander displays the size of a file, it tries to
display as much digits as fits into the size column (7 characters
wide). The result is that for a 3 MB file it shows, for example, 3010050.
In many cases, it is not important to know the exact number
of bytes in a file, but only an approximate size (3 MB). Short numbers
are more ""human friendly"".

This patch adds a configuration option that enables displaying such
human readable sizes in panels. The ""human readable"" means that at
most three digits are displayed for each file size. This is
accomplished by modifying function size_trunc_len(). Since the comment
of this function says that floating point should be avoided by any
means, the implementation is not as trivial as it could be. It
displays floating point numbers by displaying integer and fractional
parts separately as integers.

The effect of this patch is shown in the following table. ""si"" and
""hr"" denote the values use_si and human_readable parameters of the
size_trunc_len() function. The table shows the results of the function
for different sizes.

{{{
                 CURRENT        THIS PATCH
      size |  !si!hr   si!hr  !si hr   si hr
-----------|--------------------------------
       950 |     950     950     950     950
      1001 |    1001    1001   0.97K   1.00k
      1005 |    1005    1005   0.98K   1.01k
      1023 |    1023    1023   0.99K   1.02k
      1024 |    1024    1024   0.99K   1.02k
      9849 |    9849    9849   9.61K   9.85k
     12050 |   12050   12050   11.8K   12.1k
     99940 |   99940   99940   97.5K   99.9k
    100000 |  100000  100000   97.6K    100k
    102399 |  102399  102399    100K    102k
    102400 |  102400  102400    100K    102k
    210050 |  210050  210050    205K    210k
   3010050 | 3010050 3010050   2.87M   3.01m
  43010050 |  42002K  43010k   41.0M   43.0m
1072693248 |   1023M   1073m   0.99G   1.07g
}}}

Currently, the decimal separator (""."") is hardcoded and independent of
user's locale.

If anyone wants to test the patch, the table was created with the code
below.

{{{
void print(uintmax_t size)
{
	char buffer[50];
	int units = 0;
	gboolean use_si = TRUE;
	gboolean human_readable = TRUE;
	int len = 7;

	printf(""%10ld"", size);
	size_trunc_len (buffer, len, size, units, !use_si, !human_readable);
	printf(""%8s"", buffer);
	size_trunc_len (buffer, len, size, units,  use_si, !human_readable);
	printf(""%8s"", buffer);
	size_trunc_len (buffer, len, size, units, !use_si,  human_readable);
	printf(""%8s"", buffer);
	size_trunc_len (buffer, len, size, units,  use_si,  human_readable);
	printf(""%8s"", buffer);
	printf(""\n"");
}

int main(int argc, char *argv[])
{
	print(950);
	print(1001);
	// ...
}
}}}"	enhancement	new	major	Future Releases	mc-core	master			gotar@…			no branch	
