summaryrefslogtreecommitdiff
path: root/src/upgrade.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 12:14:58 -0300
committerGabriel Schneider <[email protected]>2026-11-06 14:56:36 -0300
commit4c194047d210ad9cf571c6019731d00d1e3615a4 (patch)
tree257b994e471db3011589acd0cfb4a9168f803019 /src/upgrade.zig
parent60dd9514c8676e79c625948b5e9d2c6d745e8e87 (diff)
downloadpardes-4c194047d210ad9cf571c6019731d00d1e3615a4.tar.gz
pardes-4c194047d210ad9cf571c6019731d00d1e3615a4.zip
idioms #4, string chains are an enum and a switch: main's flags (each exact one a Flag, the prefixed ones as they were), --ps's rows and manage's verb, the daemon's verbs on both ends and its registry's rows, an upgrade record's words, the window driver's mouse kinds and finger names, a frame script's click target and a mount name's reserved words go through std.meta.stringToEnum; with them main asks std.Io for its working directory, its chdir, a directory's access and /proc's comm, not libc
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/upgrade.zig')
-rw-r--r--src/upgrade.zig79
1 files changed, 37 insertions, 42 deletions
diff --git a/src/upgrade.zig b/src/upgrade.zig
index 626751ff..0f4532a5 100644
--- a/src/upgrade.zig
+++ b/src/upgrade.zig
@@ -177,49 +177,44 @@ pub const Record = struct {
const word = line[0..sp];
const rest = line[sp + 1 ..];
var it = std.mem.tokenizeScalar(u8, rest, ' ');
- if (std.mem.eql(u8, word, "link")) {
- rec.link = try std.fmt.parseInt(c_int, rest, 10);
- } else if (std.mem.eql(u8, word, "stub")) {
- rec.stub = try std.fmt.parseInt(c_int, rest, 10);
- } else if (std.mem.eql(u8, word, "old")) {
- rec.old = try std.fmt.parseInt(c_int, rest, 10);
- } else if (std.mem.eql(u8, word, "window")) {
- rec.window = std.mem.eql(u8, rest, "1");
- } else if (std.mem.eql(u8, word, "pty")) {
- if (rec.nptys == rec.ptys.len) return error.BadRecord;
- const pane = try std.fmt.parseInt(u8, it.next() orelse return error.BadRecord, 10);
- if (pane >= pardes.MAX_PANES) return error.BadRecord;
- rec.ptys[rec.nptys] = .{
- .pane = pane,
- .pid = try std.fmt.parseInt(libc.pid_t, it.next() orelse return error.BadRecord, 10),
- .fd = try std.fmt.parseInt(c_int, it.next() orelse return error.BadRecord, 10),
- };
- rec.nptys += 1;
- } else if (std.mem.eql(u8, word, "tty")) {
- if (rec.nttys == rec.ttys.len) return error.BadRecord;
- var t: Tty = .{
- .view = try std.fmt.parseInt(u8, it.next() orelse return error.BadRecord, 10),
- .fd = try std.fmt.parseInt(c_int, it.next() orelse return error.BadRecord, 10),
- .stub = try std.fmt.parseInt(c_int, it.next() orelse return error.BadRecord, 10),
- .primary = std.mem.eql(u8, it.next() orelse return error.BadRecord, "1"),
- .termios = undefined,
- };
- const hex = it.next() orelse return error.BadRecord;
- // Another build's termios is the kernel's, of one size.
- if (hex.len != 2 * @sizeOf(posix.termios) or t.view >= pardes.views.max) return error.BadRecord;
- _ = try std.fmt.hexToBytes(std.mem.asBytes(&t.termios), hex);
- rec.ttys[rec.nttys] = t;
- rec.nttys += 1;
- } else if (std.mem.eql(u8, word, "refused")) {
- rec.refused = rest;
- } else if (std.mem.eql(u8, word, "label")) {
- rec.label = rest;
- } else if (std.mem.eql(u8, word, "exe")) {
- rec.exe = rest;
- } else if (std.mem.eql(u8, word, "dump")) {
- rec.dump = rest;
- }
// A word of a later build's record is passed over.
+ switch (std.meta.stringToEnum(enum { link, stub, old, window, pty, tty, refused, label, exe, dump }, word) orelse continue) {
+ .link => rec.link = try std.fmt.parseInt(c_int, rest, 10),
+ .stub => rec.stub = try std.fmt.parseInt(c_int, rest, 10),
+ .old => rec.old = try std.fmt.parseInt(c_int, rest, 10),
+ .window => rec.window = std.mem.eql(u8, rest, "1"),
+ .pty => {
+ if (rec.nptys == rec.ptys.len) return error.BadRecord;
+ const pane = try std.fmt.parseInt(u8, it.next() orelse return error.BadRecord, 10);
+ if (pane >= pardes.MAX_PANES) return error.BadRecord;
+ rec.ptys[rec.nptys] = .{
+ .pane = pane,
+ .pid = try std.fmt.parseInt(libc.pid_t, it.next() orelse return error.BadRecord, 10),
+ .fd = try std.fmt.parseInt(c_int, it.next() orelse return error.BadRecord, 10),
+ };
+ rec.nptys += 1;
+ },
+ .tty => {
+ if (rec.nttys == rec.ttys.len) return error.BadRecord;
+ var t: Tty = .{
+ .view = try std.fmt.parseInt(u8, it.next() orelse return error.BadRecord, 10),
+ .fd = try std.fmt.parseInt(c_int, it.next() orelse return error.BadRecord, 10),
+ .stub = try std.fmt.parseInt(c_int, it.next() orelse return error.BadRecord, 10),
+ .primary = std.mem.eql(u8, it.next() orelse return error.BadRecord, "1"),
+ .termios = undefined,
+ };
+ const hex = it.next() orelse return error.BadRecord;
+ // Another build's termios is the kernel's, of one size.
+ if (hex.len != 2 * @sizeOf(posix.termios) or t.view >= pardes.views.max) return error.BadRecord;
+ _ = try std.fmt.hexToBytes(std.mem.asBytes(&t.termios), hex);
+ rec.ttys[rec.nttys] = t;
+ rec.nttys += 1;
+ },
+ .refused => rec.refused = rest,
+ .label => rec.label = rest,
+ .exe => rec.exe = rest,
+ .dump => rec.dump = rest,
+ }
}
if (rec.dump.len == 0) return error.BadRecord;
return rec;