about summary refs log tree commit diff
path: root/mscan.c
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-08-09 21:16:09 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-08-09 21:16:09 +0200
commit4c5a0070309768c422163c81ceccd754c1b94d64 (patch)
treee6b4e8aabdb451b9fc29302fa14b3b1d61ae2358 /mscan.c
parent56e87c6a10ebd301e4dbea42b2def926f5571df6 (diff)
downloadmblaze-4c5a0070309768c422163c81ceccd754c1b94d64.tar.gz
mblaze-4c5a0070309768c422163c81ceccd754c1b94d64.tar.xz
mblaze-4c5a0070309768c422163c81ceccd754c1b94d64.zip
mscan: add width to %b
Diffstat (limited to 'mscan.c')
-rw-r--r--mscan.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/mscan.c b/mscan.c
index 2035838..6163f24 100644
--- a/mscan.c
+++ b/mscan.c
@@ -221,8 +221,8 @@ fmt_to_flag(struct message *msg)
 		return " ";
 }
 
-static void
-print_human(intmax_t i)
+static ssize_t
+print_human(intmax_t i, int w)
 {
 	double d = i / 1024.0;
 	const char *u = "\0\0M\0G\0T\0P\0E\0Z\0Y\0";
@@ -232,13 +232,13 @@ print_human(intmax_t i)
 	}
 
 	if (d < 1.0)
-		printf("%4.2f", d);
+		return printf("%*.2f", w, d);
 	else if (!*u)
-		printf("%4.0f", d);
+		return printf("%*.0f", w, d);
 	else if (d < 10.0)
-		printf("%3.1f%s", d, u);
+		return printf("%*.1f%s", w-1, d, u);
 	else
-		printf("%3.0f%s", d, u);
+		return printf("%*.0f%s", w-1, d, u);
 }
 
 void
@@ -395,11 +395,10 @@ oneline(char *file)
 				if (msg) {
 					if (stat(file, &st) != 0)
 						st.st_size = 0;
-					print_human(st.st_size);
+					wleft -= print_human(st.st_size, w);
 				} else {
-					printf("    ");
+					wleft -= printf("%.*s", w, "");
 				}
-				wleft -= 5;
 			}
 			break;
 		case 'F':