commit 55d1e1a9b84a48a5bdf19fd1628bef2de99af896
parent 2da9cbf1a146ac1a97e5cc6bd935ab7e3b717bec
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Fri, 8 May 2015 19:35:47 +0000
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
Diffstat:
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -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.
diff --git a/src/browser.c b/src/browser.c
@@ -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. */