more xxd upgrades

This commit is contained in:
Peterino 2026-11-19 21:08:31 -07:00 committed by Peterino2
parent 0d3e175890
commit a4a2f73d89
4 changed files with 18 additions and 8 deletions

View File

@ -34,6 +34,7 @@ const ColorOp = struct {
count: u32 = 0, count: u32 = 0,
pub const reset = @This(){ .count = 0, .color = .default }; pub const reset = @This(){ .count = 0, .color = .default };
pub const green = @This(){ .count = 0, .color = .green };
pub fn colorAscii(self: @This()) []const u8 { pub fn colorAscii(self: @This()) []const u8 {
switch (self.color) { switch (self.color) {
@ -115,8 +116,11 @@ pub fn xxdWrite2(writer: *std.Io.Writer, bytes: []const u8, options: XxdOptions)
} }
if (i % bytesPerWord == 0) word += 1; if (i % bytesPerWord == 0) word += 1;
if (word % options.wordsPerGroup == 0) group += 1; if (word % options.wordsPerGroup == 0) group += 1;
const op = if (i % 2 == 0) ColorOp.reset else ColorOp.green;
try writer.writeAll(op.colorAscii());
try writeByteAsHex2(@intCast(i), writer, true); try writeByteAsHex2(@intCast(i), writer, true);
} }
try writer.writeAll(ColorOp.reset.colorAscii());
} }
try writer.writeByte('\n'); try writer.writeByte('\n');
@ -277,8 +281,8 @@ inline fn writeByteAsHex(byte: u8, writer: *std.Io.Writer, options: XxdOptions,
try writer.writeAll(&.{ digits[byte >> 4], digits[byte & 0xf] }); try writer.writeAll(&.{ digits[byte >> 4], digits[byte & 0xf] });
} }
/// warning, needs 64k on your stack /// warning! needs 64k on your stack
pub fn debug_printBytes(bytes: []const u8, options: XxdOptions) void { pub fn printBytes(bytes: []const u8, options: XxdOptions) void {
var workBuffer: [64 * 1024]u8 = undefined; var workBuffer: [64 * 1024]u8 = undefined;
var fba = std.heap.FixedBufferAllocator.init(&workBuffer); var fba = std.heap.FixedBufferAllocator.init(&workBuffer);
@ -290,5 +294,11 @@ pub fn debug_printBytes(bytes: []const u8, options: XxdOptions) void {
} }
pub inline fn print(bytes: []const u8, baseAddress: usize) void { pub inline fn print(bytes: []const u8, baseAddress: usize) void {
debug_printBytes(bytes, XxdOptions{ .baseAddress = baseAddress }); printBytes(bytes, XxdOptions{ .baseAddress = baseAddress });
}
pub inline fn printStruct(s: anytype) void {
std.debug.print("{s}: size:{d} bytes\n\n", .{ @typeName(@TypeOf(s)), @sizeOf(@TypeOf(s)) });
print(std.mem.asBytes(&s), 0);
} }

View File

@ -1,6 +1,7 @@
pub fn sluggerReaderTest(dir: *std.Io.Dir, pathname: []const u8) !void { pub fn sluggerReaderTest(dir: *const std.Io.Dir, pathname: []const u8) !void {
const io = std.testing.io; const io = std.testing.io;
std.debug.print("starting reader test... \n", .{});
const f = try dir.openFile(io, pathname, .{}); const f = try dir.openFile(io, pathname, .{});
_ = f; _ = f;
} }

View File

@ -1190,11 +1190,11 @@ test "testing" {
defer loggerFile.destroy(); defer loggerFile.destroy();
// new decode from log file test // new decode from log file test
const f = try tdir.openFile(io, "test2.slg", .{}); try reader.sluggerReaderTest(&tdir, "test2.slg");
_ = f;
} }
} }
pub const reader = @import("reader.zig");
pub const sluggerformat = @import("sluggerformat.zig"); pub const sluggerformat = @import("sluggerformat.zig");
const p2 = @import("p2"); const p2 = @import("p2");
const std = @import("std"); const std = @import("std");

View File

@ -279,9 +279,8 @@ const SlugOutput = struct {
try entry.marshalToWriter(&frame.writer); try entry.marshalToWriter(&frame.writer);
// const end = frame.written().len; // const end = frame.written().len;
// xxd.print(frame.written()[start..end], start); // xxd.print(frame.written()[start..end], start);
// std.debug.print("\n", .{}); // xxd.printStruct(self.*);
self.entriesWritten += 1; self.entriesWritten += 1;
} }