From ef75ad874dcf7061df3f47c8ed1ac4e287d3200f Mon Sep 17 00:00:00 2001 From: starnakin Date: Wed, 18 Sep 2024 21:45:18 +0200 Subject: [PATCH] add: date cmd to shell --- headers/shell.h | 2 ++ src/shell/date.c | 22 ++++++++++++++++++++++ src/shell/exec.c | 5 +++++ 3 files changed, 29 insertions(+) create mode 100644 src/shell/date.c diff --git a/headers/shell.h b/headers/shell.h index e676f0f..97bdb9c 100644 --- a/headers/shell.h +++ b/headers/shell.h @@ -53,6 +53,7 @@ typedef enum { ECHO, COLOR, MERDELLA, + DATE, ERROR } CMD_TOK; @@ -60,3 +61,4 @@ void shell_init(void); void reboot(void); void halt(void); void print_stack(void); +void date(void); diff --git a/src/shell/date.c b/src/shell/date.c new file mode 100644 index 0000000..078e489 --- /dev/null +++ b/src/shell/date.c @@ -0,0 +1,22 @@ +#include "kprintf.h" +#include "rtc.h" + +void date() +{ + static const char *months[12] = { + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December" }; + struct rtc_date date = get_date(); + + kprintf(0, "%s. %d %s. %d %d:%d:%d\n", "mer", date.day, months[date.month], date.year, date.hour, date.minute, date.second); +} \ No newline at end of file diff --git a/src/shell/exec.c b/src/shell/exec.c index 4924047..9751424 100644 --- a/src/shell/exec.c +++ b/src/shell/exec.c @@ -39,6 +39,8 @@ static CMD_TOK find_command(char *line) command = COLOR; else if (!strcmp(line, "merdella")) command = MERDELLA; + else if (!strcmp(line, "date")) + command = DATE; else kprintf(0, "invalid command: %s\n", line); if (uwu) @@ -120,6 +122,9 @@ void shell_init(void) "by Targon (/)\n"); break; } + case DATE: + date(); + break; case ERROR: break; default: