From 839891fc580f8deaf8f5b6ef3dece42e96c1acec Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Sat, 23 Dec 2023 04:46:51 +0100 Subject: splash texts --- stage3/shell.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'stage3/shell.c') diff --git a/stage3/shell.c b/stage3/shell.c index 079580e..d64e5be 100644 --- a/stage3/shell.c +++ b/stage3/shell.c @@ -280,6 +280,34 @@ static void cmd_clocktest(str arg) } } +static void cmd_choose(str arg) +{ + str f = fs_read(arg); + + if (f.data == nil) { + print(S("choose: file not found: ")); + print(arg); + print(S("\n")); + } else { + str iter = f; + int choices = 0; + while (str_walk(&iter, S("\n")).len > 0) + choices++; + + if (choices > 0) { + iter = f; + int chosen = rand() % choices; + str line; + for (int i = 0; i < chosen; i++) + line = str_walk(&iter, S("\n")); + print(line); + print_char('\n'); + } + + free(f.data); + } +} + typedef struct { str name; void (*fn)(str arg); @@ -302,6 +330,7 @@ static command registry[] = { { S("cheese"), &cmd_cheese }, { S("watchdog"), &cmd_watchdog }, { S("clocktest"), &cmd_clocktest }, + { S("choose"), &cmd_choose }, }; void shell_run_cmd(str cmd) -- cgit v1.2.3