From 79c063c1f773e826b46eeebe311878708a18cb08 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 28 Jun 2020 04:40:33 +0200 Subject: Shell: added support for command arguments. Added support for command arguments by using strtok. Also fixed deleting bug. --- src/pOS/arch/x86/kernel/shell/cmd.cpp | 20 ++++++++++---------- src/pOS/arch/x86/kernel/shell/cmds/clear.cpp | 13 +++++++++++-- src/pOS/arch/x86/kernel/shell/cmds/date.cpp | 13 +++++++++++-- src/pOS/arch/x86/kernel/shell/cmds/halt.cpp | 12 ++++++++++-- src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp | 12 ++++++++++-- src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp | 12 ++++++++++-- src/pOS/arch/x86/kernel/shell/cmds/test.cpp | 12 ++++++++++-- src/pOS/arch/x86/kernel/shell/shell.cpp | 2 +- src/pOS/include/kernel/shell/cmd.h | 4 ++-- 9 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/pOS/arch/x86/kernel/shell/cmd.cpp b/src/pOS/arch/x86/kernel/shell/cmd.cpp index 13b99ba..7c1fb00 100644 --- a/src/pOS/arch/x86/kernel/shell/cmd.cpp +++ b/src/pOS/arch/x86/kernel/shell/cmd.cpp @@ -6,36 +6,36 @@ int CMD_MANAGER::execute(char* cmd) { - //char* arg = strtok(cmd, " "); - dbgprintf("cmd: %s\n", cmd); - switch(str2int(cmd)) + char* args = strtok(cmd, " "); + + switch(str2int(args)) { case str2int("clear"): case str2int("cls"): case str2int("c"): - return CMD_Clear().execute(cmd); + return CMD_Clear().execute(); case str2int("date"): case str2int("time"): - return CMD_Date().execute(cmd); + return CMD_Date().execute(); case str2int("halt"): case str2int("hlt"): - return CMD_Halt().execute(cmd); + return CMD_Halt().execute(); case str2int("shutdown"): - return CMD_Shutdown().execute(cmd); + return CMD_Shutdown().execute(); case str2int("reboot"): - return CMD_Reboot().execute(cmd); + return CMD_Reboot().execute(); case str2int("test"): case str2int("t"): - return CMD_Test().execute(cmd); + return CMD_Test().execute(); } - printf("Unknown cmd: %s\n", cmd); + printf("Unknown cmd: %s\n", args); return -1; } diff --git a/src/pOS/arch/x86/kernel/shell/cmds/clear.cpp b/src/pOS/arch/x86/kernel/shell/cmds/clear.cpp index 1919a3a..871c59b 100644 --- a/src/pOS/arch/x86/kernel/shell/cmds/clear.cpp +++ b/src/pOS/arch/x86/kernel/shell/cmds/clear.cpp @@ -1,9 +1,18 @@ #include #include +#include -int CMD_Clear::execute(const char* args) +int CMD_Clear::execute() { - UNUSED_VARIABLE(args); + dbgprintf("args: "); + char* arg = strtok(NULL, " "); + do + { + dbgprintf("%s, ", arg); + arg = strtok(NULL, " "); + } while(arg); + dbgprintf("\n"); + TTY::tty_initialize(); return 0; } diff --git a/src/pOS/arch/x86/kernel/shell/cmds/date.cpp b/src/pOS/arch/x86/kernel/shell/cmds/date.cpp index 3a0431b..74330aa 100644 --- a/src/pOS/arch/x86/kernel/shell/cmds/date.cpp +++ b/src/pOS/arch/x86/kernel/shell/cmds/date.cpp @@ -1,9 +1,18 @@ #include #include +#include -int CMD_Date::execute(const char* args) +int CMD_Date::execute() { - UNUSED_VARIABLE(args); + dbgprintf("args: "); + char* arg = strtok(NULL, " "); + do + { + dbgprintf("%s, ", arg); + arg = strtok(NULL, " "); + } while(arg); + dbgprintf("\n"); + printf("%s\n", Time::get_date_formatted()); return 0; } diff --git a/src/pOS/arch/x86/kernel/shell/cmds/halt.cpp b/src/pOS/arch/x86/kernel/shell/cmds/halt.cpp index 2993af3..c68ee9d 100644 --- a/src/pOS/arch/x86/kernel/shell/cmds/halt.cpp +++ b/src/pOS/arch/x86/kernel/shell/cmds/halt.cpp @@ -1,9 +1,17 @@ #include #include +#include -int CMD_Halt::execute(const char* args) +int CMD_Halt::execute() { - UNUSED_VARIABLE(args); + dbgprintf("args: "); + char* arg = strtok(NULL, " "); + do + { + dbgprintf("%s, ", arg); + arg = strtok(NULL, " "); + } while(arg); + dbgprintf("\n"); ACPI::halt(); return 0; } diff --git a/src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp b/src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp index bf2dac3..19e09a4 100644 --- a/src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp +++ b/src/pOS/arch/x86/kernel/shell/cmds/reboot.cpp @@ -1,9 +1,17 @@ #include #include +#include -int CMD_Reboot::execute(const char* args) +int CMD_Reboot::execute() { - UNUSED_VARIABLE(args); + dbgprintf("args: "); + char* arg = strtok(NULL, " "); + do + { + dbgprintf("%s, ", arg); + arg = strtok(NULL, " "); + } while(arg); + dbgprintf("\n"); ACPI::reboot(); return 0; } diff --git a/src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp b/src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp index e0939d9..943c313 100644 --- a/src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp +++ b/src/pOS/arch/x86/kernel/shell/cmds/shutdown.cpp @@ -1,9 +1,17 @@ #include #include +#include -int CMD_Shutdown::execute(const char* args) +int CMD_Shutdown::execute() { - UNUSED_VARIABLE(args); + dbgprintf("args: "); + char* arg = strtok(NULL, " "); + do + { + dbgprintf("%s, ", arg); + arg = strtok(NULL, " "); + } while(arg); + dbgprintf("\n"); ACPI::shutdown(); return 0; } diff --git a/src/pOS/arch/x86/kernel/shell/cmds/test.cpp b/src/pOS/arch/x86/kernel/shell/cmds/test.cpp index 0c9a32c..f312d26 100644 --- a/src/pOS/arch/x86/kernel/shell/cmds/test.cpp +++ b/src/pOS/arch/x86/kernel/shell/cmds/test.cpp @@ -1,9 +1,17 @@ #include #include +#include -int CMD_Test::execute(const char* args) +int CMD_Test::execute() { - UNUSED_VARIABLE(args); + dbgprintf("args: "); + char* arg = strtok(NULL, " "); + do + { + dbgprintf("%s, ", arg); + arg = strtok(NULL, " "); + } while(arg); + dbgprintf("\n"); printf("Test!\n"); return 0; } diff --git a/src/pOS/arch/x86/kernel/shell/shell.cpp b/src/pOS/arch/x86/kernel/shell/shell.cpp index d11e206..143fe8e 100644 --- a/src/pOS/arch/x86/kernel/shell/shell.cpp +++ b/src/pOS/arch/x86/kernel/shell/shell.cpp @@ -51,7 +51,7 @@ int Shell::run(void) if(c == '\b') { - cmd[indx] = c; + cmd[--indx] = 0; } else if(c == '\n') { diff --git a/src/pOS/include/kernel/shell/cmd.h b/src/pOS/include/kernel/shell/cmd.h index 42855a1..85f57a8 100644 --- a/src/pOS/include/kernel/shell/cmd.h +++ b/src/pOS/include/kernel/shell/cmd.h @@ -5,7 +5,7 @@ class name : public CMD \ { \ public: \ - int execute(const char* args); \ + int execute(); \ }; class CMD_MANAGER @@ -17,7 +17,7 @@ public: class CMD { public: - virtual int execute(const char* args); + virtual int execute(); }; /* SHELL CMDS */ -- cgit 1.4.1