Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fortune command #24

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions kernel/advanced_cmds/fortune.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include "../io.h"
#include "../../lib/rand.h"
#include "../../drivers/display.h"

void ksh_fortune() {
const char fortunes[3] = {"Pohl's Law: Nothing is so good that somebody, somewhere, will not hate it.", "You either die a smart fella, or live long enough to become a fart smella", "Everyone asked you about your favorite dinosaur as a kid, now, nobody cares", "Even stock traders want to arrest hatred", "Generically, fiery liquors that produce madness in total abstainers.", "Our remedies oft in ourselves do lie,? Which we ascribe to heaven.", "One of the most conspicuous qualities of a man in security."};
kprintc('\n');
int RandIndex = rand() % sizeof(fortunes);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// We write all libraries from scratch, so no rand() function is available. You will need to write a rand.c and rand.h file in lib/.

kprints(arrayNum[RandIndex]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// What variable is arrayNum? You have not declared it in this file.

kprintc('\n');
}
8 changes: 7 additions & 1 deletion kernel/ksh.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ char* theme;
#include "advanced_cmds/write_to_file.h"
#include "advanced_cmds/make_file.h"
#include "advanced_cmds/remove_file.h"
#include "advanced_cmds/fortune.h"

#define KSH_OK 0x0
#define KSH_EXIT 0x1
Expand All @@ -42,7 +43,8 @@ byte ksh_interpret(char* command)
"mk",
"rm",
"in",
"to"
"to",
"fortune"
};

for (int i = 0; i < sizeof(ListOfOwnCmds) / sizeof(char*); i++) {
Expand Down Expand Up @@ -74,6 +76,7 @@ byte ksh_interpret(char* command)
kprints("mk create new file\n");
kprints("rm delete file\n");
kprints("in read file content\n");
kprints("fortune fortune cookie\n");
break;
case 2:
kprints("Hello World!\n");
Expand Down Expand Up @@ -140,6 +143,9 @@ byte ksh_interpret(char* command)
case 18:
ksh_write_to_file();
break;
case 19:
ksh_fortune();
break;
default:
kprints(KERNEL_INFO_SHELL_UNKNOWN_COMMAND);
break;
Expand Down