add STUPID nomorenumbers impl

This commit is contained in:
2025-03-30 17:52:42 -04:00
parent ae43f4afbf
commit 8e63cd206f

View File

@@ -109,19 +109,29 @@ fn mathTest(rand: Random, limit: i32, iteration: u32) !bool {
}; };
} }
const BuiltinCommand = *const fn (*ShellState, [][]const u8) anyerror!void; const BuiltinCommand = *const fn (*ShellState, [][]const u8, Allocator) anyerror!void;
fn exitFn(shell_state: *ShellState, command: [][]const u8) !void { fn exitFn(shell_state: *ShellState, command: [][]const u8, allocator: Allocator) !void {
_ = command; _ = command;
_ = allocator;
shell_state.*.should_exit = true; shell_state.*.should_exit = true;
} }
fn nomorenumbersFn(shell_state: *ShellState, command: [][]const u8, allocator: Allocator) !void {
shell_state.*.should_test = false;
if (command.len > 1) {
_ = runCommand(command[1..], allocator) catch |err| {
return err;
};
}
}
fn execCommand(command: [][]const u8, shell_state: *ShellState, allocator: Allocator) !u8 { fn execCommand(command: [][]const u8, shell_state: *ShellState, allocator: Allocator) !u8 {
const builtins = comptime .{.{ "exit", exitFn }}; const builtins = comptime .{ .{ "exit", exitFn }, .{ "nomorenumbers", nomorenumbersFn } };
const builtinMap = StaticStringMap(BuiltinCommand).initComptime(builtins); const builtinMap = StaticStringMap(BuiltinCommand).initComptime(builtins);
if (builtinMap.has(command[0])) { if (builtinMap.has(command[0])) {
try builtinMap.get(command[0]).?(shell_state, command); try builtinMap.get(command[0]).?(shell_state, command, allocator);
return 0; return 0;
} else { } else {
return runCommand(command, allocator); return runCommand(command, allocator);