Revert "(size_trunc_len): align to properly use either IEC or SI prefixes with the unit B (byte)."

This reverts commit bae814d0d4.
This commit is contained in:
Andrew Borodin 2016-11-08 13:19:37 +03:00
parent e3d457eb3d
commit 83504f2bb5
4 changed files with 24 additions and 36 deletions

View File

@ -448,26 +448,23 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
*/
#endif
};
static const char *const units_iec[] = { N_("B"), N_("KiB"), N_("MiB"), N_("GiB"), N_("TiB"),
N_("PiB"), N_("EiB"), N_("ZiB"), N_("YiB"), NULL };
static const char *const units_si[] = { N_("B"), N_("kB"), N_("MB"), N_("GB"), N_("TB"),
N_("PB"), N_("EB"), N_("ZB"), N_("YB"), NULL };
/* *INDENT-ON* */
static const char *const suffix[] = { "", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL };
static const char *const suffix_lc[] = { "", "k", "m", "g", "t", "p", "e", "z", "y", NULL };
const char *const *sfx = use_si ? units_si : units_iec;
const char *const *sfx = use_si ? suffix_lc : suffix;
int j = 0;
if (len == 0)
len = 9;
#if SIZEOF_UINTMAX_T == 8
/* 20 decimal digits are required to represent 8 bytes */
else if (len > 21)
len = 21;
else if (len > 19)
len = 19;
#else
/* 10 decimal digits are required to represent 4 bytes */
else if (len > 11)
len = 11;
else if (len > 9)
len = 9;
#endif
/*
@ -492,25 +489,20 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
{
if (j == units)
{
/* Empty files will print "0 B" even with minimal width. */
g_snprintf (buffer, len + 1, "0 %s", _("B"));
/* Empty files will print "0" even with minimal width. */
g_snprintf (buffer, len + 1, "%s", "0");
}
else
{
/* Use "~KiB/kB" or just "KiB/kB" if len is 1. Use "B" for bytes. */
g_snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s",
(j > 1) ? _(sfx[j - 1]) : _("B"));
/* Use "~K" or just "K" if len is 1. Use "B" for bytes. */
g_snprintf (buffer, len + 1, (len > 1) ? "~%s" : "%s", (j > 1) ? sfx[j - 1] : "B");
}
break;
}
/*
* Offset calculation: 1 for space + 2*3 bytes for scaled units as multibyte
* encoding with UTF-8 for non-Latin scripts.
*/
if (size < power10[len - (1 + 6)])
if (size < power10[len - (j > 0 ? 1 : 0)])
{
g_snprintf (buffer, len + 1, "%" PRIuMAX " %s", size, _(sfx[j]));
g_snprintf (buffer, len + 1, "%" PRIuMAX "%s", size, sfx[j]);
break;
}

View File

@ -1013,12 +1013,12 @@ file_progress_show_total (file_op_total_context_t * tctx, file_op_context_t * ct
if (ui->total_bytes_label != NULL)
{
size_trunc_len (buffer2, 11, tctx->copied_bytes, 0, panels_options.kilobyte_si);
size_trunc_len (buffer2, 5, tctx->copied_bytes, 0, panels_options.kilobyte_si);
if (!ctx->progress_totals_computed)
g_snprintf (buffer, sizeof (buffer), _(" Total: %s "), buffer2);
else
{
size_trunc_len (buffer3, 11, ctx->progress_bytes, 0, panels_options.kilobyte_si);
size_trunc_len (buffer3, 5, ctx->progress_bytes, 0, panels_options.kilobyte_si);
g_snprintf (buffer, sizeof (buffer), _(" Total: %s/%s "), buffer2, buffer3);
}

View File

@ -176,12 +176,10 @@ info_show_info (WInfo * info)
tty_print_string (_("No space information"));
else
{
char buffer1[12], buffer2[12];
char buffer1[6], buffer2[6];
size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1,
panels_options.kilobyte_si);
size_trunc_len (buffer2, sizeof (buffer2) - 1, myfs_stats.total, 1,
panels_options.kilobyte_si);
size_trunc_len (buffer1, 5, myfs_stats.avail, 1, panels_options.kilobyte_si);
size_trunc_len (buffer2, 5, myfs_stats.total, 1, panels_options.kilobyte_si);
tty_printf (_("Free space: %s/%s (%d%%)"), buffer1, buffer2,
myfs_stats.total == 0 ? 0 :
(int) (100 * (long double) myfs_stats.avail / myfs_stats.total));
@ -234,9 +232,8 @@ info_show_info (WInfo * info)
else
#endif
{
char buffer[12];
size_trunc_len (buffer, sizeof (buffer) - 1, st.st_size, 0, panels_options.kilobyte_si);
char buffer[10];
size_trunc_len (buffer, 9, st.st_size, 0, panels_options.kilobyte_si);
tty_printf (_("Size: %s"), buffer);
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
tty_printf (ngettext (" (%ld block)", " (%ld blocks)",

View File

@ -195,7 +195,7 @@ static panel_field_t panel_fields[] = {
}
,
{
"size", 8, FALSE, J_RIGHT,
"size", 7, FALSE, J_RIGHT,
/* TRANSLATORS: one single character to represent 'size' sort mode */
/* TRANSLATORS: no need to translate 'sort', it's just a context prefix */
N_("sort|s"),
@ -205,7 +205,7 @@ static panel_field_t panel_fields[] = {
}
,
{
"bsize", 8, FALSE, J_RIGHT,
"bsize", 7, FALSE, J_RIGHT,
"",
N_("Block Size"), FALSE, FALSE,
string_file_size_brief,
@ -515,8 +515,7 @@ string_file_size (file_entry_t * fe, int len)
format_device_number (buffer, len + 1, fe->st.st_rdev);
else
#endif
size_trunc_len (buffer, (unsigned int) (len + 3), fe->st.st_size, 0,
panels_options.kilobyte_si);
size_trunc_len (buffer, (unsigned int) len, fe->st.st_size, 0, panels_options.kilobyte_si);
return buffer;
}
@ -1155,7 +1154,7 @@ show_free_space (const WPanel * panel)
if (myfs_stats.avail != 0 || myfs_stats.total != 0)
{
const Widget *w = CONST_WIDGET (panel);
char buffer1[12], buffer2[12], tmp[BUF_SMALL];
char buffer1[6], buffer2[6], tmp[BUF_SMALL];
size_trunc_len (buffer1, sizeof (buffer1) - 1, myfs_stats.avail, 1,
panels_options.kilobyte_si);