srctree

Gregory Mullen parent 09acc54d 3fe7054e
update to zig v0.14.0-dev

src/builtins.zig added: 80, removed: 80, total 0
@@ -113,10 +113,10 @@ pub fn execOpt(self: BuiltinOptionals) BuiltinFn {
 
/// Caller must ensure this builtin exists by calling exists, or optionalExists
pub fn strExec(str: []const u8) BuiltinFn {
inline for (@typeInfo(Builtins).Enum.fields[0..]) |f| {
inline for (@typeInfo(Builtins).@"enum".fields[0..]) |f| {
if (std.mem.eql(u8, f.name, str)) return exec(@enumFromInt(f.value));
}
inline for (@typeInfo(BuiltinOptionals).Enum.fields[0..]) |f| {
inline for (@typeInfo(BuiltinOptionals).@"enum".fields[0..]) |f| {
if (std.mem.eql(u8, f.name, str)) return execOpt(@enumFromInt(f.value));
}
log.err("strExec panic on {s}\n", .{str});
@@ -124,7 +124,7 @@ pub fn strExec(str: []const u8) BuiltinFn {
}
 
pub fn exists(str: []const u8) bool {
inline for (@typeInfo(Builtins).Enum.fields[0..]) |f| {
inline for (@typeInfo(Builtins).@"enum".fields[0..]) |f| {
if (std.mem.eql(u8, f.name, str)) return true;
}
return false;
@@ -133,7 +133,7 @@ pub fn exists(str: []const u8) bool {
/// Optional builtins "exist" only if they don't already exist on the system.
/// this is not enforced internally callers are expected to behave
pub fn existsOptional(str: []const u8) bool {
inline for (@typeInfo(BuiltinOptionals).Enum.fields[0..]) |f| {
inline for (@typeInfo(BuiltinOptionals).@"enum".fields[0..]) |f| {
if (std.mem.eql(u8, f.name, str)) return true;
}
return false;
@@ -238,13 +238,13 @@ fn noimpl(_: *HSH, i: *ParsedIterator) Err!u8 {
test "builtins" {
const str = @tagName(Builtins.alias);
var bi: bool = false;
inline for (@typeInfo(Builtins).Enum.fields[0..]) |f| {
inline for (@typeInfo(Builtins).@"enum".fields[0..]) |f| {
if (std.mem.eql(u8, f.name, str)) bi = true;
}
try std.testing.expect(bi);
var bi2 = false;
const never = "pleasegodletthisneverbecomeabuiltin";
inline for (@typeInfo(Builtins).Enum.fields[0..]) |f| {
inline for (@typeInfo(Builtins).@"enum".fields[0..]) |f| {
if (std.mem.eql(u8, f.name, never)) bi2 = true;
}
try std.testing.expect(!bi2);
 
src/builtins/alias.zig added: 80, removed: 80, total 0
@@ -52,7 +52,7 @@ fn save(h: *HSH, _: *anyopaque) ?[][]const u8 {
for (aliases.items, 0..) |a, i| {
list[i] = std.fmt.allocPrint(h.alloc, "{save}\n", .{a}) catch continue;
}
return list;
return @ptrCast(list);
}
 
pub fn alias(h: *HSH, titr: *ParsedIterator) Err!u8 {
 
src/builtins/export.zig added: 80, removed: 80, total 0
@@ -58,7 +58,7 @@ fn save(h: *HSH, _: *anyopaque) ?[][]const u8 {
for (export_list.items, 0..) |ex, i| {
list[i] = std.fmt.allocPrint(h.alloc, "{save}\n", .{ex}) catch continue;
}
return list;
return @ptrCast(list);
}
 
/// print the list of known exports to whatever builtin suggests
@@ -81,7 +81,7 @@ pub fn exports(h: *HSH, pitr: *ParsedIterator) Err!u8 {
}
 
if (std.mem.indexOf(u8, name.?.cannon(), "=")) |_| {
var keyitr = std.mem.split(u8, name.?.cannon(), "=");
var keyitr = std.mem.splitAny(u8, name.?.cannon(), "=");
const key = keyitr.first();
const value = keyitr.rest();
Variables.put(key, value) catch {
 
src/builtins/set.zig added: 80, removed: 80, total 0
@@ -26,7 +26,7 @@ pub const Opts = enum(u8) {
Trace = 'x',
 
pub fn find(c: u8) Err!Opts {
inline for (@typeInfo(Opts).Enum.fields) |field| {
inline for (@typeInfo(Opts).@"enum".fields) |field| {
if (field.value == c) return @enumFromInt(field.value);
}
return Err.InvalidToken;
@@ -140,7 +140,7 @@ fn option(_: std.mem.Allocator, opt: []const u8, titr: *ParsedIterator) Err!u8 {
}
 
fn dump() Err!u8 {
inline for (@typeInfo(PosixOpts).Enum.fields) |o| {
inline for (@typeInfo(PosixOpts).@"enum".fields) |o| {
const name = o.name;
const truthy = if (Vars.get(name)) |str|
std.mem.eql(u8, "true", str)
 
src/completion.zig added: 80, removed: 80, total 0
@@ -66,7 +66,7 @@ pub const Flavors = enum(u3) {
file_system,
};
 
const flavors_len = @typeInfo(Flavors).Enum.fields.len;
const flavors_len = @typeInfo(Flavors).@"enum".fields.len;
 
pub const Kind = union(Flavors) {
any: void,
@@ -525,7 +525,7 @@ fn completeDirBase(cs: *CompSet, cwdi: Dir, base: []const u8) !void {
fn completePath(cs: *CompSet, _: *HSH, target: []const u8) !void {
if (target.len < 1) return;
 
var whole = std.mem.splitBackwards(u8, target, "/");
var whole = std.mem.splitBackwardsAny(u8, target, "/");
const base = whole.first();
const path = whole.rest();
 
 
src/fs.zig added: 80, removed: 80, total 0
@@ -77,7 +77,7 @@ watches: [1]?INotify,
pub fn init(a: mem.Allocator, env: std.process.EnvMap) !fs {
var paths = std.ArrayList([]const u8).init(a);
if (env.get("PATH")) |penv| {
var mpaths = std.mem.tokenize(u8, penv, ":");
var mpaths = std.mem.tokenizeAny(u8, penv, ":");
while (mpaths.next()) |mpath| {
try paths.append(mpath);
}
 
src/hsh.zig added: 80, removed: 80, total 0
@@ -46,9 +46,9 @@ pub const hshFeature = struct {
// Until tagged structs are a thing, enforce these to be equal at compile time
// it's probably not important for the order to be equal... but here we are :)
comptime {
std.debug.assert(@typeInfo(Features).Enum.fields.len == @typeInfo(hshFeature).Struct.fields.len);
for (@typeInfo(Features).Enum.fields, 0..) |field, i| {
std.debug.assert(std.mem.eql(u8, field.name, @typeInfo(hshFeature).Struct.fields[i].name));
std.debug.assert(@typeInfo(Features).@"enum".fields.len == @typeInfo(hshFeature).@"struct".fields.len);
for (@typeInfo(Features).@"enum".fields, 0..) |field, i| {
std.debug.assert(std.mem.eql(u8, field.name, @typeInfo(hshFeature).@"struct".fields[i].name));
//@compileLog("{s}\n", .{field.name});
}
}
 
src/keys.zig added: 80, removed: 80, total 0
@@ -69,7 +69,7 @@ pub const Event = union(enum) {
keysm: KeyMod,
mouse: Mouse,
 
pub fn key(k: Key) Event {
pub fn fromKey(k: Key) Event {
return .{
.keysm = .{
.evt = .{
@@ -78,7 +78,8 @@ pub const Event = union(enum) {
},
};
}
pub fn ascii(a: ASCII) Event {
 
pub fn fromAscii(a: ASCII) Event {
return .{
.keysm = .{
.evt = .{
@@ -100,9 +101,9 @@ pub fn esc(io: i32) Error!Event {
var buffer: [1]u8 = .{0x1B};
_ = std.posix.read(io, &buffer) catch return Error.IO;
switch (buffer[0]) {
0x1B => return Event.key(.esc),
0x1B => return Event.fromKey(.esc),
'[' => return csi(io),
'O' => return Event.key(try sst(io)),
'O' => return Event.fromKey(try sst(io)),
else => {
log.warn("\n\nunknown input: escape {s} {}\n", .{ buffer, buffer[0] });
return Event{ .keysm = .{
@@ -147,7 +148,7 @@ fn csi(io: i32) Error!Event {
}
std.debug.assert(i != buffer.len);
switch (buffer[i]) {
'~' => return Event.key(try csi_vt(buffer[0..i])), // intentionally dropping ~
'~' => return Event.fromKey(try csi_vt(buffer[0..i])), // intentionally dropping ~
'a'...'z', 'A'...'Z' => return csi_xterm(buffer[0 .. i + 1]),
else => std.debug.print("\n\nunknown\n{any}\n\n\n", .{buffer}),
}
@@ -156,12 +157,12 @@ fn csi(io: i32) Error!Event {
 
fn csi_xterm(buffer: []const u8) Error!Event {
switch (buffer[0]) {
'A' => return Event.key(.up),
'B' => return Event.key(.down),
'C' => return Event.key(.right),
'D' => return Event.key(.left),
'H' => return Event.key(.home),
'F' => return Event.key(.end),
'A' => return Event.fromKey(.up),
'B' => return Event.fromKey(.down),
'C' => return Event.fromKey(.right),
'D' => return Event.fromKey(.left),
'H' => return Event.fromKey(.home),
'F' => return Event.fromKey(.end),
'I' => return .{ .mouse = .in },
'O' => return .{ .mouse = .out },
'0'...'9' => {
@@ -169,7 +170,7 @@ fn csi_xterm(buffer: []const u8) Error!Event {
log.debug("\n\n{s} [{any}] key {}\n\n", .{ buffer, buffer, key });
std.debug.assert(std.mem.count(u8, buffer, ";") == 1);
 
var mods = std.mem.split(u8, buffer, ";");
var mods = std.mem.splitAny(u8, buffer, ";");
// Yes, I know hacky af, but I don't know all the other combos I
// care about yet. :/
if (!std.mem.eql(u8, "1", mods.first())) @panic("xterm is unable to parse given string");
 
src/logic.zig added: 80, removed: 80, total 0
@@ -34,7 +34,7 @@ pub const Reserved = enum {
pub fn fromStr(str: []const u8) ?Reserved {
std.debug.assert(str.len <= 5);
var lower: [6]u8 = undefined;
inline for (@typeInfo(Reserved).Enum.fields) |f| {
inline for (@typeInfo(Reserved).@"enum".fields) |f| {
const name = std.ascii.lowerString(&lower, f.name);
if (std.mem.eql(u8, str, name)) return @enumFromInt(f.value);
}
 
src/main.zig added: 80, removed: 80, total 0
@@ -193,15 +193,20 @@ pub fn main() !void {
}
}
 
pub fn panic(msg: []const u8, trace: ?*std.builtin.StackTrace, retaddr: ?usize) noreturn {
@setCold(true);
 
log.err("Panic reached... your TTY is likely broken now.\n\n ...sorry about that!\n\n", .{});
std.debug.print("\n\r\x1B[J", .{});
std.builtin.default_panic(msg, trace, retaddr);
if (TTY.current_tty) |*t| {
TTY.current_tty = null;
t.raze();
}
std.time.sleep(1000 * 1000 * 1000 * 30);
}
// TODO determine if hsh still needs a custom panic the answer is probably yes,
// to capture/save state, but that's a much later TODO
//pub fn panic(msg: []const u8, trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
// @branchHint(.cold);
//
// log.err("Panic reached... your TTY is likely broken now.\n\n ...sorry about that!\n\n", .{});
// std.debug.print("\n\r\x1B[J", .{});
// _ = msg;
// _ = trace;
// //std.debug.defaultPanic(msg, trace);
// if (TTY.current_tty) |*t| {
// TTY.current_tty = null;
// t.raze();
// }
// std.time.sleep(1000 * 1000 * 1000 * 30);
// unreachable;
//}
 
src/parse.zig added: 80, removed: 80, total 0
@@ -261,7 +261,7 @@ pub const ParsedIterator = struct {
 
var tokens = ArrayList(Token).init(self.alloc);
if (std.mem.indexOf(u8, token.cannon(), "/")) |_| {
var bitr = std.mem.splitBackwards(u8, token.cannon(), "/");
var bitr = std.mem.splitBackwardsAny(u8, token.cannon(), "/");
const glob = bitr.first();
const dir = bitr.rest();
if (Parser.globAt(self.alloc, dir, glob)) |names| {
@@ -315,7 +315,7 @@ pub const ParsedIterator = struct {
if (self.aliases.len > 0) {
self.alloc.free(self.aliases);
}
self.aliases = self.alloc.alloc([]u8, 0) catch @panic("Alloc 0 can't fail");
self.aliases = self.alloc.alloc([]const u8, 0) catch @panic("Alloc 0 can't fail");
for (self.resolved) |*token| {
token.raze();
}
@@ -343,7 +343,7 @@ pub const Parser = struct {
.alloc = a,
.resolved = a.alloc(Parsed, 0) catch return Error.Memory,
.tokens = tokens[start..],
.aliases = a.alloc([]u8, 0) catch return Error.Memory,
.aliases = a.alloc([]const u8, 0) catch return Error.Memory,
};
}
 
 
src/prompt.zig added: 80, removed: 80, total 0
@@ -18,12 +18,15 @@ const Spinners = enum {
corners,
dots2t3,
 
const dots = [_][]const u8{ "⡄", "⡆", "⠆", "⠇", "⠃", "⠋", "⠉", "⠙", "⠘", "⠸", "⠰", "⢰", "⢠", "⣠", "⣀", "⣄" };
const corners = [_][]const u8{ "◢", "◣", "◤", "◥" };
pub const glyphs = struct {
const dots = [_][]const u8{ "⡄", "⡆", "⠆", "⠇", "⠃", "⠋", "⠉", "⠙", "⠘", "⠸", "⠰", "⢰", "⢠", "⣠", "⣀", "⣄" };
const corners = [_][]const u8{ "◢", "◣", "◤", "◥" };
};
 
pub fn spin(s: Spinners, pos: usize) []const u8 {
const art = switch (s) {
.corners => &[_][]const u8{ "◢", "◣", "◤", "◥" },
.dots2t3 => &[_][]const u8{ "⡄", "⡆", "⠆", "⠇", "⠃", "⠋", "⠉", "⠙", "⠘", "⠸", "⠰", "⢰", "⢠", "⣠", "⣀", "⣄" },
.corners => &glyphs.corners,
.dots2t3 => &glyphs.dots,
};
return art[pos % art.len];
}
 
src/signals.zig added: 80, removed: 80, total 0
@@ -1,6 +1,6 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const Queue = std.TailQueue;
const Queue = std.DoublyLinkedList;
const HSH = @import("hsh.zig").HSH;
const log = @import("log");
const jobs = @import("jobs.zig");
@@ -102,7 +102,7 @@ pub fn init(a: Allocator) !void {
};
 
for (wanted) |sig| {
try std.posix.sigaction(sig, &std.posix.Sigaction{
std.posix.sigaction(sig, &std.posix.Sigaction{
.handler = .{ .sigaction = sig_cb },
.mask = std.posix.empty_sigset,
.flags = SA.SIGINFO | SA.RESTART,
@@ -114,7 +114,7 @@ pub fn init(a: Allocator) !void {
std.posix.SIG.TTOU,
};
for (ignored) |sig| {
try std.posix.sigaction(sig, &std.posix.Sigaction{
std.posix.sigaction(sig, &std.posix.Sigaction{
.handler = .{ .handler = std.posix.SIG.IGN },
.mask = std.posix.empty_sigset,
.flags = SA.RESTART,
 
src/syscalls.zig added: 80, removed: 80, total 0
@@ -9,9 +9,6 @@ comptime {
 
if (@hasDecl(std.os.linux, "getsid"))
@compileError("Os already provides custom getsid");
 
if (@hasDecl(std.os.linux, "setpgid"))
@compileError("Os already provides custom setpgid");
}
 
pub fn getsid(pid: pid_t) pid_t {
@@ -27,9 +24,3 @@ pub fn getpgid(pid: pid_t) pid_t {
std.os.linux.syscall1(.getpgid, @bitCast(@as(isize, pid))),
)));
}
 
pub fn setpgid(pid: pid_t, pgid: pid_t) usize {
return @bitCast(
std.os.linux.syscall2(.setpgid, @bitCast(@as(isize, pid)), @bitCast(@as(isize, pgid))),
);
}
 
src/tty.zig added: 80, removed: 80, total 0
@@ -128,7 +128,7 @@ pub fn pwnTTY(self: *TTY) void {
self.pid = std.os.linux.getpid();
const ssid = custom_syscalls.getsid(0);
log.debug("pwnTTY {} and {} \n", .{ self.pid, ssid });
if (ssid != self.pid) _ = custom_syscalls.setpgid(self.pid, self.pid);
if (ssid != self.pid) _ = std.os.linux.setpgid(self.pid, self.pid);
 
const res = std.posix.tcsetpgrp(self.dev, self.pid) catch |err| {
self.owner = self.pid;
@@ -211,8 +211,8 @@ pub fn geom(self: *TTY) !Cord {
return std.posix.unexpectedErrno(@enumFromInt(err));
}
return .{
.x = size.ws_col,
.y = size.ws_row,
.x = size.col,
.y = size.row,
};
}
 
@@ -230,7 +230,7 @@ pub fn raze(self: *TTY) void {
const expect = std.testing.expect;
test "split" {
var s = "\x1B[86;1R";
var splits = std.mem.split(u8, s[2..], ";");
var splits = std.mem.splitAny(u8, s[2..], ";");
const x: usize = std.fmt.parseInt(usize, splits.next().?, 10) catch 0;
var y: usize = 0;
if (splits.next()) |thing| {