From afa1542b7634260cc2073e4f13b908daaf07fb08 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 4 Jul 2006 22:17:39 +0000
Subject: [PATCH] simplify

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3734 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 src/browser.c | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index d0eb60d9..a8042bbd 100644
--- 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. */
-- 
GitLab