diff options
Diffstat (limited to 'src/ninep/events.zig')
| -rw-r--r-- | src/ninep/events.zig | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/src/ninep/events.zig b/src/ninep/events.zig index bc43dbfd..e67deb1d 100644 --- a/src/ninep/events.zig +++ b/src/ninep/events.zig @@ -195,13 +195,6 @@ pub fn noteMessage(p: *Pardes, serial: u32, said_stamped: []const u8) void { std.fmt.bufPrint(&buf, "msg {d} {s}{s}\n", .{ serial, kept, cut })) catch return, said); } -/// Records `err <serial|-> <file>: <why>` for a write that was refused or -/// failed: through a mount a shell sees only the errno the -/// kernel mapped the reply to (`Invalid argument`), and here is the reason. -/// The log is the one place for it, as acme's `errors` file takes text and -/// answers nothing: a per-pane readable error file would be a second. -/// `dump <path>` when a Dump is written, `restore <path>` first in a -/// Restore's replacement. /// `notePath` for an `err` record: the same one again straight after is /// counted, `(x2)`, as every err is. pub fn noteErrCounted(p: *Pardes, text: []const u8) void { @@ -210,12 +203,19 @@ pub fn noteErrCounted(p: *Pardes, text: []const u8) void { pushCounting(p, std.fmt.bufPrint(&buf, "err {s}\n", .{text}) catch return, text); } +/// Records `<what> <path>`: `dump <path>` when a Dump is written, +/// `restore <path>` first in a Restore's replacement. pub fn notePath(p: *Pardes, what: []const u8, path: []const u8) void { bootFirst(p); var buf: [pardes.memory.limits.host_path_cap + 16]u8 = undefined; pushLog(p, std.fmt.bufPrint(&buf, "{s} {s}\n", .{ what, path }) catch return); } +/// Records `err <serial|-> <file>: <why>` for a write that was refused or +/// failed: through a mount a shell sees only the errno the kernel mapped +/// the reply to (`Invalid argument`), and here is the reason. The log is +/// the one place for it, as acme's `errors` file takes text and answers +/// nothing: a per-pane readable error file would be a second. pub fn noteError(p: *Pardes, req: Req, reply: Reply) void { const why = if (reply.ename.len > 0) reply.ename else cloud9.fs.errString(reply.errno); var name: [32]u8 = undefined; @@ -354,9 +354,8 @@ pub fn shown(text: []const u8, out: []u8) []u8 { fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 { var w: usize = 0; var i: usize = 0; - const body = text; - while (i < body.len and w + 4 <= out.len) { - const c = body[i]; + while (i < text.len and w + 4 <= out.len) { + const c = text[i]; // A name's own backslash is `\\`, so `\n` and `\xNN` read back as // the escapes they are, never as a name that held them. if (c == '\\' and escape_newline) { @@ -385,16 +384,16 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 { continue; } const n = std.unicode.utf8ByteSequenceLength(c) catch 0; - if (n == 0 or i + n > body.len or !std.unicode.utf8ValidateSlice(body[i .. i + n])) { + if (n == 0 or i + n > text.len or !std.unicode.utf8ValidateSlice(text[i .. i + n])) { _ = std.fmt.bufPrint(out[w..], "\\x{x:0>2}", .{c}) catch break; w += 4; i += 1; continue; } - if (n == 2 and c == 0xC2 and body[i + 1] <= 0x9F) { + if (n == 2 and c == 0xC2 and text[i + 1] <= 0x9F) { if (escape_newline) { if (w + 8 > out.len) break; - _ = std.fmt.bufPrint(out[w..], "\\xc2\\x{x:0>2}", .{body[i + 1]}) catch break; + _ = std.fmt.bufPrint(out[w..], "\\xc2\\x{x:0>2}", .{text[i + 1]}) catch break; w += 8; i += 2; continue; @@ -405,7 +404,7 @@ fn shownAs(text: []const u8, out: []u8, escape_newline: bool) []u8 { continue; } if (w + n > out.len) break; - @memcpy(out[w..][0..n], body[i..][0..n]); + @memcpy(out[w..][0..n], text[i..][0..n]); w += n; i += n; } @@ -555,7 +554,6 @@ pub const Action = enum(u8) { }; pub const flag_builtin: u32 = 1; -pub const flag_expansion: u32 = 2; pub const flag_filename: u32 = 4; pub const flag_chorded: u32 = 8; @@ -722,14 +720,11 @@ fn scanNumber(data: []const u8, i: *usize, overflow: *bool) ?u32 { return @intCast(n); } -/// Writing a Look or Exec record back performs the action it names. -/// The word a click at `at` expands to: the file name or word run under it -/// on its line (look.expandedWord), else nothing. -/// An empty range written back: what a click at `at` takes, as the mouse's -/// does (exec.operandAt). In a diff pane's body that is look.diffClick's -/// answer, the line's address or its code's words. -/// `for_look`: only a look in a body takes a diff line's address -/// (exec.operandAt); an exec takes the word there, as anywhere. +/// What a click at `at` takes, as the mouse's does (exec.operandAt), +/// for an empty range written back: the file name or word under it on its +/// line (look.expandedWord), else nothing; in a diff pane's body, for a +/// look alone (`for_look`, exec.operandAt), look.diffClick's answer, the +/// line's address or its code's words. pub fn expandAt(p: *Pardes, pane: *Pane, whole: []const u8, at: usize, in_body: bool, for_look: bool) []const u8 { const start = if (std.mem.lastIndexOfScalar(u8, whole[0..at], '\n')) |nl| nl + 1 else 0; const end = std.mem.indexOfScalarPos(u8, whole, at, '\n') orelse whole.len; @@ -750,6 +745,7 @@ pub fn expandAt(p: *Pardes, pane: *Pane, whole: []const u8, at: usize, in_body: return whole[start + word_from + b.lo .. start + word_from + b.hi]; } +/// Writing a Look or Exec record back performs the action it names. pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply { const pane0 = p.panes[id] orelse return Reply.fail(asked.tag, E.NOENT); // Its last record needs no newline, as every other line file's last |
