Skip to content
Snippets Groups Projects
Commit e5f290d7 authored by Ing. Michal Svamberg's avatar Ing. Michal Svamberg
Browse files

Uprava jednotek a pouziti apparent size pro pocitani souboru

parent aa8bf925
No related branches found
Tags v2.1.1
No related merge requests found
......@@ -291,7 +291,7 @@ fn tryReadArgsFile(path: [:0]const u8) void {
}
fn version() noreturn {
std.io.getStdOut().writer().writeAll("ncdu " ++ program_version ++ "\n") catch {};
std.io.getStdOut().writer().writeAll("nccf " ++ program_version ++ "\n") catch {};
std.process.exit(0);
}
......
......@@ -8,7 +8,7 @@ const ui = @import("ui.zig");
const util = @import("util.zig");
const exclude = @import("exclude.zig");
const c_statfs = @cImport(@cInclude("sys/vfs.h"));
var countsize : u8 = 1;
var sizeone: u8 = 1;
// Concise stat struct for fields we're interested in, with the types used by the model.
const Stat = struct {
......@@ -34,8 +34,8 @@ const Stat = struct {
fn read(parent: std.fs.Dir, name: [:0]const u8, follow: bool) !Stat {
const stat = try std.os.fstatatZ(parent.fd, name, if (follow) 0 else std.os.AT.SYMLINK_NOFOLLOW);
return Stat{
.blocks = clamp(Stat, .blocks, countsize),
.size = clamp(Stat, .size, countsize),
.blocks = clamp(Stat, .blocks, stat.blocks),
.size = clamp(Stat, .size, sizeone),
.dev = truncate(Stat, .dev, stat.dev),
.ino = truncate(Stat, .ino, stat.ino),
.nlink = clamp(Stat, .nlink, stat.nlink),
......@@ -787,7 +787,7 @@ const Import = struct {
},
'd' => {
if (eq(u8, key, "dsize")) {
self.ctx.stat.blocks = @intCast(model.Blocks, self.uint(u64));
self.ctx.stat.blocks = @intCast(model.Blocks, self.uint(u64)>>9);
return;
}
if (eq(u8, key, "dev")) {
......
......@@ -421,22 +421,22 @@ pub const FmtSize = struct {
var r: @This() = undefined;
var f = @intToFloat(f32, v);
if (main.config.si) {
if(f < 1000.0) { r.unit = " B"; }
else if(f < 1e6) { r.unit = " KB"; f /= 1e3; }
else if(f < 1e9) { r.unit = " MB"; f /= 1e6; }
else if(f < 1e12) { r.unit = " GB"; f /= 1e9; }
else if(f < 1e15) { r.unit = " TB"; f /= 1e12; }
else if(f < 1e18) { r.unit = " PB"; f /= 1e15; }
else { r.unit = " EB"; f /= 1e18; }
if(f < 1000.0) { r.unit = " "; }
else if(f < 1e6) { r.unit = " K"; f /= 1e3; }
else if(f < 1e9) { r.unit = " M"; f /= 1e6; }
else if(f < 1e12) { r.unit = " G"; f /= 1e9; }
else if(f < 1e15) { r.unit = " T"; f /= 1e12; }
else if(f < 1e18) { r.unit = " P"; f /= 1e15; }
else { r.unit = " E"; f /= 1e18; }
}
else {
if(f < 1000.0) { r.unit = " B"; }
else if(f < 1023e3) { r.unit = " KiB"; f /= 1024.0; }
else if(f < 1023e6) { r.unit = " MiB"; f /= 1048576.0; }
else if(f < 1023e9) { r.unit = " GiB"; f /= 1073741824.0; }
else if(f < 1023e12) { r.unit = " TiB"; f /= 1099511627776.0; }
else if(f < 1023e15) { r.unit = " PiB"; f /= 1125899906842624.0; }
else { r.unit = " EiB"; f /= 1152921504606846976.0; }
if(f < 1000.0) { r.unit = " "; }
else if(f < 1023e3) { r.unit = " Ki"; f /= 1024.0; }
else if(f < 1023e6) { r.unit = " Mi"; f /= 1048576.0; }
else if(f < 1023e9) { r.unit = " Gi"; f /= 1073741824.0; }
else if(f < 1023e12) { r.unit = " Ti"; f /= 1099511627776.0; }
else if(f < 1023e15) { r.unit = " Pi"; f /= 1125899906842624.0; }
else { r.unit = " Ei"; f /= 1152921504606846976.0; }
}
_ = std.fmt.bufPrintZ(&r.buf, "{d:>5.1}", .{f}) catch unreachable;
return r;
......@@ -454,6 +454,7 @@ pub fn addsize(bg: Bg, v: u64) void {
addstr(r.num());
bg.fg(.default);
addstr(r.unit);
addch(if (main.config.show_blocks) 'B' else ' ');
}
// Print a full decimal number with thousand separators.
......
......@@ -25,8 +25,7 @@ pub fn castTruncate(comptime T: type, x: anytype) T {
// Multiplies by 512, saturating.
pub fn blocksToSize(b: u64) u64 {
//return if (b & 0xFF80000000000000 > 0) std.math.maxInt(u64) else b << 9;
return b;
return if (b & 0xFF80000000000000 > 0) std.math.maxInt(u64) else b << 9;
}
// Ensure the given arraylist buffer gets zero-terminated and returns a slice
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment