1
1

Taking the distant possibility of terabyte files into account,

and in the bargain getting rid of the need to calculate the
number of digits in UINT_MAX.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5224 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Этот коммит содержится в:
Benno Schulenberg 2015-05-08 19:35:47 +00:00
родитель 2da9cbf1a1
Коммит 55d1e1a9b8
2 изменённых файлов: 18 добавлений и 14 удалений

Просмотреть файл

@ -1,3 +1,8 @@
2015-05-08 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (browser_refresh): Take the distant possibility of
terabyte files into account, and in the bargain get rid of the need
to calculate the number of digits in UINT_MAX.
2015-05-03 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (browser_refresh): Display an ellipsis only when the
filename is longer than the available space, not when it still fits.

Просмотреть файл

@ -541,16 +541,12 @@ functionptrtype parse_browser_input(int *kbinput)
* necessary, and display the list of files. */
void browser_refresh(void)
{
static int uimax_digits = -1;
size_t i;
int line = 0, col = 0;
/* The current line and column while the list is getting displayed. */
char *foo;
/* The additional information that we'll display about a file. */
if (uimax_digits == -1)
uimax_digits = digits(UINT_MAX);
blank_edit();
wmove(edit, 0, 0);
@ -621,26 +617,29 @@ void browser_refresh(void)
unsigned long result = st.st_size;
char modifier;
foo = charalloc(uimax_digits + 4);
foo = charalloc(foomaxlen + 1);
/* Bytes. */
if (st.st_size < (1 << 10))
modifier = ' ';
/* Kilobytes. */
modifier = ' '; /* bytes */
else if (st.st_size < (1 << 20)) {
result >>= 10;
modifier = 'K';
/* Megabytes. */
modifier = 'K'; /* kilobytes */
} else if (st.st_size < (1 << 30)) {
result >>= 20;
modifier = 'M';
/* Gigabytes. */
modifier = 'M'; /* megabytes */
} else {
result >>= 30;
modifier = 'G';
modifier = 'G'; /* gigabytes */
}
sprintf(foo, "%4lu %cB", result, modifier);
/* If less than a terabyte, or if numbers can't even go
* that high, show the size, otherwise show "(huge)". */
if (st.st_size < (1 << 40) || (1 << 40) == 0)
sprintf(foo, "%4lu %cB", result, modifier);
else
/* TRANSLATORS: Try to keep this at most 7 characters.
* If necessary, you can leave out the parentheses. */
foo = mallocstrcpy(foo, _("(huge)"));
}
/* Make sure foo takes up no more than foomaxlen columns. */