nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit afa1542b7634260cc2073e4f13b908daaf07fb08
parent 9f2e3f7654fc8136c62fac27ecc0f7a7be202c2c
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date:   Tue,  4 Jul 2006 22:17:39 +0000

simplify


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3734 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

Diffstat:
Msrc/browser.c | 28+++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/browser.c b/src/browser.c @@ -633,23 +633,29 @@ void browser_refresh(void) } else foo = mallocstrcpy(NULL, _("(dir)")); } else { + unsigned long result = st.st_size; + char modifier; + foo = charalloc(uimax_digits + 4); /* Bytes. */ - if (st.st_size < (1 << 10)) - sprintf(foo, "%4u B", (unsigned int)st.st_size); + if (st.st_size < (1 << 10)) + modifier = ' '; /* Kilobytes. */ - else if (st.st_size < (1 << 20)) - sprintf(foo, "%4u KB", - (unsigned int)(st.st_size >> 10)); + else if (st.st_size < (1 << 20)) { + result >>= 10; + modifier = 'K'; /* Megabytes. */ - else if (st.st_size < (1 << 30)) - sprintf(foo, "%4u MB", - (unsigned int)(st.st_size >> 20)); + } else if (st.st_size < (1 << 30)) { + result >>= 20; + modifier = 'M'; /* Gigabytes. */ - else - sprintf(foo, "%4u GB", - (unsigned int)(st.st_size >> 30)); + } else { + result >>= 30; + modifier = 'G'; + } + + sprintf(foo, "%4lu %cB", result, modifier); } /* Make sure foo takes up no more than foomaxlen columns. */