1
1

Add --si flag for base 10 prefixes

This is a slightly modified patch contributed at

  http://dev.yorhel.nl/ncdu/bug/35
Этот коммит содержится в:
Yorhel 2013-07-23 10:33:24 +02:00
родитель 30c0b2db00
Коммит 0e9e6d511a
4 изменённых файлов: 34 добавлений и 8 удалений

Просмотреть файл

@ -97,6 +97,12 @@ option has no effect when C<-o> is used, because there will not be a browser
interface in that case. It has no effect when C<-f> is used, either, because interface in that case. It has no effect when C<-f> is used, either, because
the deletion feature is disabled in that case anyway. the deletion feature is disabled in that case anyway.
=item --si
List sizes using base 10 prefixes, that is, powers of 1000 (KB, MB, etc), as
defined in the International System of Units (SI), instead of the usual base 2
prefixes, that is, powers of 1024 (KiB, MiB, etc).
=back =back
=head2 Scan Options =head2 Scan Options

Просмотреть файл

@ -127,10 +127,12 @@ static void argv_parse(int argc, char **argv) {
{ 1, 1, "--exclude" }, { 1, 1, "--exclude" },
{ 'X', 1, "-X,--exclude-from" }, { 'X', 1, "-X,--exclude-from" },
{ 'C', 0, "--exclude-caches" }, { 'C', 0, "--exclude-caches" },
{ 's', 0, "--si" },
{0,0,NULL} {0,0,NULL}
}; };
dir_ui = -1; dir_ui = -1;
si = 0;
yopt_init(&yopt, argc, argv, opts); yopt_init(&yopt, argc, argv, opts);
while((v = yopt_next(&yopt, &val)) != -1) { while((v = yopt_next(&yopt, &val)) != -1) {
@ -146,6 +148,7 @@ static void argv_parse(int argc, char **argv) {
printf(" -o FILE Export scanned directory to FILE\n"); printf(" -o FILE Export scanned directory to FILE\n");
printf(" -f FILE Import scanned directory from FILE\n"); printf(" -f FILE Import scanned directory from FILE\n");
printf(" -0,-1,-2 UI to use when scanning (0=none,2=full ncurses)\n"); printf(" -0,-1,-2 UI to use when scanning (0=none,2=full ncurses)\n");
printf(" --si Use base 10 (SI) prefixes instead of base 2\n");
printf(" --exclude PATTERN Exclude files that match PATTERN\n"); printf(" --exclude PATTERN Exclude files that match PATTERN\n");
printf(" -X, --exclude-from FILE Exclude files that match any pattern in FILE\n"); printf(" -X, --exclude-from FILE Exclude files that match any pattern in FILE\n");
printf(" --exclude-caches Exclude directories containing CACHEDIR.TAG\n"); printf(" --exclude-caches Exclude directories containing CACHEDIR.TAG\n");
@ -156,6 +159,7 @@ static void argv_parse(int argc, char **argv) {
exit(0); exit(0);
case 'x': dir_scan_smfs = 1; break; case 'x': dir_scan_smfs = 1; break;
case 'r': read_only = 1; break; case 'r': read_only = 1; break;
case 's': si = 1; break;
case 'o': export = val; break; case 'o': export = val; break;
case 'f': import = val; break; case 'f': import = val; break;
case '0': dir_ui = 0; break; case '0': dir_ui = 0; break;

Просмотреть файл

@ -32,6 +32,7 @@
int winrows, wincols; int winrows, wincols;
int subwinr, subwinc; int subwinr, subwinc;
int si;
char thou_sep; char thou_sep;
@ -60,6 +61,17 @@ char *formatsize(int64_t from) {
static char dat[9]; /* "xxx.xMiB" */ static char dat[9]; /* "xxx.xMiB" */
float r = from; float r = from;
char c = ' '; char c = ' ';
if (si) {
if(r < 1000.0f) { }
else if(r < 1e6f) { c = 'K'; r/=1e3f; }
else if(r < 1e9f) { c = 'M'; r/=1e6f; }
else if(r < 1e12f){ c = 'G'; r/=1e9f; }
else if(r < 1e15f){ c = 'T'; r/=1e12f; }
else if(r < 1e18f){ c = 'P'; r/=1e15f; }
else { c = 'E'; r/=1e18f; }
sprintf(dat, "%5.1f%cB", r, c);
}
else {
if(r < 1000.0f) { } if(r < 1000.0f) { }
else if(r < 1023e3f) { c = 'K'; r/=1024.0f; } else if(r < 1023e3f) { c = 'K'; r/=1024.0f; }
else if(r < 1023e6f) { c = 'M'; r/=1048576.0f; } else if(r < 1023e6f) { c = 'M'; r/=1048576.0f; }
@ -68,6 +80,7 @@ char *formatsize(int64_t from) {
else if(r < 1023e15f){ c = 'P'; r/=1125899906842624.0f; } else if(r < 1023e15f){ c = 'P'; r/=1125899906842624.0f; }
else { c = 'E'; r/=1152921504606846976.0f; } else { c = 'E'; r/=1152921504606846976.0f; }
sprintf(dat, "%5.1f%c%cB", r, c, c == ' ' ? ' ' : 'i'); sprintf(dat, "%5.1f%c%cB", r, c, c == ' ' ? ' ' : 'i');
}
return dat; return dat;
} }

Просмотреть файл

@ -35,6 +35,9 @@ extern int winrows, wincols;
/* used by the nc* functions and macros */ /* used by the nc* functions and macros */
extern int subwinr, subwinc; extern int subwinr, subwinc;
/* used by formatsize to choose between base 2 or 10 prefixes */
extern int si;
/* Instead of using several ncurses windows, we only draw to stdscr. /* Instead of using several ncurses windows, we only draw to stdscr.
* the functions nccreate, ncprint and the macros ncaddstr and ncaddch * the functions nccreate, ncprint and the macros ncaddstr and ncaddch