forked from Spencer/math_shell
add STUPID nomorenumbers impl
This commit is contained in:
18
src/main.zig
18
src/main.zig
@@ -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;
|
||||
_ = allocator;
|
||||
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 {
|
||||
const builtins = comptime .{.{ "exit", exitFn }};
|
||||
const builtins = comptime .{ .{ "exit", exitFn }, .{ "nomorenumbers", nomorenumbersFn } };
|
||||
const builtinMap = StaticStringMap(BuiltinCommand).initComptime(builtins);
|
||||
|
||||
if (builtinMap.has(command[0])) {
|
||||
try builtinMap.get(command[0]).?(shell_state, command);
|
||||
try builtinMap.get(command[0]).?(shell_state, command, allocator);
|
||||
return 0;
|
||||
} else {
|
||||
return runCommand(command, allocator);
|
||||
|
||||
Reference in New Issue
Block a user