From df9475ba490abb5453d854f4e4ff7e90a07dd39e Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sun, 27 Oct 2013 20:17:47 +0100 Subject: [PATCH] Add help command --- kernel/src/kernel.cpp | 46 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 24f9d0ac..5cbe8346 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -66,12 +66,44 @@ bool str_equals(const char* a, const char* b){ return *a == *b; } -void exec_command(){ - if(str_equals("reboot", current_input)){ - interrupt<60>(); - } else { - k_print("The command \""); - k_print(current_input); - k_print_line("\" does not exist"); +#define COMMANDS 2 + +struct command_definition { + const char* name; + void (*function)(); +}; + +void reboot_command(); +void help_command(); + +command_definition commands[COMMANDS] = { + {"reboot", reboot_command}, + {"help", help_command} +}; + +void reboot_command(){ + interrupt<60>(); +} + +void help_command(){ + k_print_line("Available commands:"); + + for(int i = 0; i < COMMANDS; ++i){ + k_print(" "); + k_print_line(commands[i].name); } } + +void exec_command(){ + for(int i = 0; i < COMMANDS; ++i){ + if(str_equals(current_input, commands[i].name)){ + commands[i].function(); + + return; + } + } + + k_print("The command \""); + k_print(current_input); + k_print_line("\" does not exist"); +}