2015-04-23 11:56:59 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
Make file sizes human readable.
diff --git a/Makefile b/Makefile index 8c1116d..eebdc01 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +CFLAGS=-D_FILE_OFFSET_BITS=64 LDLIBS=-lcurses PREFIX=/usr/local MANPREFIX=$(PREFIX)/man diff --git a/rover.c b/rover.c index 19262fb..8b3e076 100644 --- a/rover.c +++ b/rover.c @@ -324,10 +324,15 @@ update_view() wcolor_set(rover.window, RVC_DIR, NULL); else wcolor_set(rover.window, RVC_FILE, NULL); - if (!isdir) - snprintf(ROW, ROWSZ, "%s%*d", ENAME(j), - (int) (COLS - strlen(ENAME(j)) - 4), (int) ESIZE(j)); - else + if (!isdir) { + char *human_suffix, *suffixes = "BKMGTPEZY"; + off_t human_size = ESIZE(j); + for (human_suffix = suffixes; human_size >= 1024; human_suffix++) + human_size = (human_size + 512) / 1024; + snprintf(ROW, ROWSZ, "%s%*d %c", ENAME(j), + (int) (COLS - strlen(ENAME(j)) - 6), + (int) human_size, *human_suffix); + } else strcpy(ROW, ENAME(j)); mvwhline(rover.window, i + 1, 1, ' ', COLS - 2); if (marking && MARKED(j))