From 942b4fa88e671c430384a82536c2501fee57032a Mon Sep 17 00:00:00 2001 From: xamidev <121681048+xamidev@users.noreply.github.com> Date: Sat, 24 Aug 2024 21:50:20 +0200 Subject: [PATCH] Add: cowsay, splash --- docs/USERS.md | 6 +++- src/kernel/shell.c | 24 ++++++++++++-- src/libc/string.c | 17 ++++++++++ src/libc/string.h | 2 ++ src/programs/cowsay.c | 72 +++++++++++++++++++++++++++++++++++++++++ src/programs/primes.c | 17 ++++++++-- src/programs/programs.h | 2 ++ 7 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 src/programs/cowsay.c diff --git a/docs/USERS.md b/docs/USERS.md index 0d503b8..a43f3bc 100644 --- a/docs/USERS.md +++ b/docs/USERS.md @@ -51,7 +51,11 @@ Options: #### `primes` -Computes prime numbers up to `PRIMES_MAX`, defined in `src/programs/primes.c`. +Computes prime numbers. + +Options: +- `` will default to `PRIMES_MAX` (a million) +- `` will compute primes up to that number #### `rainbow` diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 28b8c2c..d154f1c 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -7,12 +7,15 @@ #include "../libc/stdio.h" #include "../libc/string.h" #include "../programs/programs.h" +#include "../libc/crypto.h" #include #define BUFFER_SIZE 256 #define MAX_COMMANDS 16 #define MAX_ARGS 64 +// Splash screen: esthetic stuff. + char* ascii_title = "\n" "----------------------------------------------\n" @@ -21,6 +24,22 @@ char* ascii_title = "----------------------------------------------\n" "\n"; +char* motd[] = +{ + "Now in 2D!", + "Supercalifragilisticexpialidocious!", + "Tylko jedno w głowie mam!", +}; +int motd_size = sizeof(motd)/sizeof(motd[0]); + +void splash() +{ // Change that seed to something RTC-related (need RTC driver) + int random = randint(global_ticks); + char* motd_pick = motd[random%motd_size]; + cowsay(motd_pick, red, black); + puts("\n"); +} + typedef void (*command_func_t)(int argc, char *argv[]); typedef struct @@ -66,8 +85,8 @@ int parse_input(char* input, char* argv[], int max_args) } void shell_install() -{ - colorputs(ascii_title, yellow, black); +{ + splash(); register_command("help", program_help); register_command("panic", program_panic); @@ -83,6 +102,7 @@ void shell_install() register_command("conway", program_conway); register_command("rot13", program_rot13); register_command("morse", program_morse); + register_command("cowsay", program_cowsay); for (;;) { diff --git a/src/libc/string.c b/src/libc/string.c index 6f079b3..91f07f1 100644 --- a/src/libc/string.c +++ b/src/libc/string.c @@ -86,3 +86,20 @@ int atoi(char* str) return result; } + +void strcat(char* dest, const char* src) +{ + while (*dest) + { + dest++; + } + + while (*src) + { + *dest = *src; + dest++; + src++; + } + + *dest = '\0'; +} diff --git a/src/libc/string.h b/src/libc/string.h index 130c2b6..496950a 100644 --- a/src/libc/string.h +++ b/src/libc/string.h @@ -10,5 +10,7 @@ int strlen(const char* str); int strcmp(const char* str1, const char* str2); char* strtok(char* str, const char* delimiter); int atoi(char* str); +void strcat(char* dest, const char* src); + #endif diff --git a/src/programs/cowsay.c b/src/programs/cowsay.c new file mode 100644 index 0000000..5b1f5c2 --- /dev/null +++ b/src/programs/cowsay.c @@ -0,0 +1,72 @@ +// Cowsay-like program +// Author: xamidev +// Licensed under the Unlicense. See the repo below. +// https://github.com/xamidev/blankos + +#include "../libc/stdio.h" +#include "../libc/string.h" + +#define MAX_MSG_LEN 128 + +const char* cow = +" \\ ^__^\n" +" \\ (oo)\\_______\n" +" (__)\\ )\\/\\\n" +" ||----w |\n" +" || ||\n"; + +void print_bubble(const char* message) +{ + int len = strlen(message); + puts(" "); + for (int i=0; i\n", message); + + puts(" "); + for (int i=0; i\n", argv[0]); + return; + } + + char message[MAX_MSG_LEN]; + message[0] = '\0'; + + for (int i=1; i #include "../libc/stdio.h" #include "../kernel/system.h" +#include "../libc/string.h" #define PRIMES_MAX 1000000 @@ -16,15 +17,25 @@ bool isPrime(int n) return true; } -void program_primes() +void program_primes(int argc, char* argv[]) { - for (long long x=0; x