summaryrefslogtreecommitdiff
path: root/src/host/probe.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 21:34:41 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:22:02 -0300
commit2348776791e9dd17afeb12a06ba42a4a71917bcf (patch)
tree780c4b12b76c8b97a28408dd40944d65f159fdc7 /src/host/probe.zig
parent590ba7b9b579b97e34b51ab7e3460ebc85713343 (diff)
downloadsketchbook-2348776791e9dd17afeb12a06ba42a4a71917bcf.tar.gz
sketchbook-2348776791e9dd17afeb12a06ba42a4a71917bcf.zip
sketchbook: a drawing layer on top, host fixes for replay and migration
Diffstat (limited to 'src/host/probe.zig')
-rw-r--r--src/host/probe.zig26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/host/probe.zig b/src/host/probe.zig
index 4a693ec..d8ed166 100644
--- a/src/host/probe.zig
+++ b/src/host/probe.zig
@@ -30,6 +30,8 @@ pub fn main(init: std.process.Init) !void {
const file = path orelse fatal("no state file given");
const map = memory.mapReadOnly(file);
if (map.len < memory.header_len) fatal("not a sketchbook state file");
+ const magic = map[0..8];
+ if (!std.mem.eql(u8, magic, &memory.file_magic) and !std.mem.eql(u8, magic, &memory.file_magic_v1)) fatal("not a sketchbook state file");
defer std.posix.munmap(map);
var arena: std.heap.ArenaAllocator = .init(init.gpa);
defer arena.deinit();
@@ -52,9 +54,29 @@ fn show(path: []const u8, layout: memory.Layout, live: []const u8) void {
var w: std.Io.Writer = .fixed(&buf);
std.debug.print("{s}: {d} bytes, layout {x:0>16}\n", .{ path, live.len, layout.hash });
for (layout.fields) |leaf| {
+ // Whole arrays are shown by their elements' leaves.
+ if (leaf.whole()) continue;
w.end = 0;
- fields.format(leaf, live, &w) catch {};
- std.debug.print(" +0x{x:0>4} {s:<28} {s}\n", .{ leaf.offset, leaf.path, w.buffered() });
+ if (leaf.dims.len == 0) {
+ fields.format(leaf, live, &w) catch {};
+ } else {
+ // Elements in index order, the first few.
+ var it = leaf.elements();
+ var n: usize = 0;
+ while (it.next()) |offset| : (n += 1) {
+ if (n == 8) {
+ w.writeAll(" ...") catch {};
+ break;
+ }
+ if (n > 0) w.writeAll(" ") catch {};
+ fields.format(leaf.at(offset), live, &w) catch {};
+ }
+ }
+ var name: [128]u8 = undefined;
+ var nw: std.Io.Writer = .fixed(&name);
+ nw.writeAll(leaf.path) catch {};
+ for (leaf.dims) |d| nw.print(" [{d}]", .{d.count}) catch {};
+ std.debug.print(" +0x{x:0>4} {s:<28} {s}\n", .{ leaf.offset, nw.buffered(), w.buffered() });
}
}