diff options
author | Daniel Friesel <derf@finalrewind.org> | 2012-02-26 09:56:01 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2012-02-26 09:56:01 +0100 |
commit | bf52095c2a870571475b6a7731428f5533882ac8 (patch) | |
tree | fb51470c81b8bd1d3b854b4c84c568c6c37e13c1 /src/slideshow.c | |
parent | be7b3df6c008f74b2ebec9a61dda3db7da9a2a9d (diff) |
feh_printf: Fix/Add %S/%P for human-readable sizes, use them in --list
Diffstat (limited to 'src/slideshow.c')
-rw-r--r-- | src/slideshow.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/slideshow.c b/src/slideshow.c index 189357d..a65d95e 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -404,6 +404,19 @@ char *shell_escape(char *input) return ret; } +char *format_size(int size) +{ + static char ret[5]; + char units[] = {' ', 'k', 'M', 'G', 'T'}; + unsigned char postfix = 0; + while (size >= 1000) { + size /= 1000; + postfix++; + } + snprintf(ret, 5, "%3d%c", size, units[postfix]); + return ret; +} + char *feh_printf(char *str, feh_file * file) { char *c; @@ -452,9 +465,7 @@ char *feh_printf(char *str, feh_file * file) break; case 'S': if (file && (file->info || !feh_file_info_load(file, NULL))) { - snprintf(buf, sizeof(buf), - "%.2fkB", ((double)file->info->size / 1000)); - strcat(ret, buf); + strcat(ret, format_size(file->info->size)); } break; case 'p': @@ -463,14 +474,16 @@ char *feh_printf(char *str, feh_file * file) strcat(ret, buf); } break; + case 'P': + if (file && (file->info || !feh_file_info_load(file, NULL))) { + strcat(ret, format_size(file->info->pixels)); + } + break; case 't': if (file && (file->info || !feh_file_info_load(file, NULL))) { strcat(ret, file->info->format); } break; - case 'P': - strcat(ret, PACKAGE); - break; case 'v': strcat(ret, VERSION); break; |