diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 519ef6b..4abba8b 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/src/kernel/shell.c b/src/kernel/shell.c index 340f623..9b69bfa 100644 --- a/src/kernel/shell.c +++ b/src/kernel/shell.c @@ -2,11 +2,13 @@ #include "../libc/stdio.h" #include "../libc/string.h" #include "../programs/programs.h" +#include "../libc/stdint.h" #define BUFFER_SIZE 256 #define MAX_COMMANDS 16 +#define MAX_ARGS 64 -typedef void (*command_func_t)(); +typedef void (*command_func_t)(int argc, char *argv[]); typedef struct { @@ -37,6 +39,19 @@ command_func_t find_command(const char* name) return 0; } +int parse_input(char* input, char* argv[], int max_args) +{ + int argc = 0; + char* token = strtok(input, " "); + while (token != NULL && argc < max_args - 1) + { + argv[argc++] = token; + token = strtok(NULL, " "); + } + argv[argc] = NULL; + return argc; +} + void shell_install() { register_command("help", program_help); @@ -48,24 +63,26 @@ void shell_install() register_command("math", program_math); register_command("bf", program_bf); register_command("uptime", program_uptime); + register_command("echo", program_echo); for (;;) { char input_buffer[BUFFER_SIZE]; + char* argv[MAX_ARGS]; colorputs("blankos> ", 9); get_input(input_buffer, BUFFER_SIZE); puts("\n"); + + int argc = parse_input(input_buffer, argv, MAX_ARGS); - if (strcmp(input_buffer, "") == 0) { - continue; - } + if (argc == 0) continue; - command_func_t command = find_command(input_buffer); + command_func_t command = find_command(argv[0]); if (command) { - command(); + command(argc, argv); } else { - printf("Unknown command %s\n", input_buffer); + printf("Unknown command %s\n", argv[0]); } } } diff --git a/src/libc/stdint.h b/src/libc/stdint.h index 1da6019..657cf76 100644 --- a/src/libc/stdint.h +++ b/src/libc/stdint.h @@ -17,4 +17,6 @@ typedef uint8_t bool; #define true 1 #define false 0 +#define NULL ((void*)0) + #endif diff --git a/src/libc/string.c b/src/libc/string.c index 3e2de92..5c79755 100644 --- a/src/libc/string.c +++ b/src/libc/string.c @@ -1,3 +1,5 @@ +#include "stdint.h" + int strlen(const char* str) { int len = 0; @@ -17,3 +19,52 @@ int strcmp(const char* str1, const char* str2) } return *(const unsigned char*)str1 - *(const unsigned char*)str2; } + +char* strchr(const char* str, int c) +{ + while (*str) + { + if (*str == (char)c) + { + return (char*)str; + } + str++; + } + if (c == '\0') + { + return (char*)str; + } + return NULL; +} + +char* strtok(char* str, const char* delimiter) +{ + static char* last; + if (str) + { + last = str; + } else { + str = last; + } + + if (!str || *str == '\0') + { + return NULL; + } + + char* token_start = str; + while (*str && !strchr(delimiter, *str)) + { + str++; + } + + if (*str) + { + *str = '\0'; + last = str + 1; + } else { + last = NULL; + } + + return token_start; +} diff --git a/src/libc/string.h b/src/libc/string.h index 0f64804..384507e 100644 --- a/src/libc/string.h +++ b/src/libc/string.h @@ -3,5 +3,6 @@ int strlen(const char* str); int strcmp(const char* str1, const char* str2); +char* strtok(char* str, const char* delimiter); #endif diff --git a/src/programs/misc.c b/src/programs/misc.c index 7b3c959..0fa54ac 100644 --- a/src/programs/misc.c +++ b/src/programs/misc.c @@ -2,6 +2,7 @@ #include "../libc/stdio.h" #include "../kernel/system.h" +#include "../libc/string.h" // Print a rainbow colorful text for testing @@ -44,10 +45,26 @@ void program_uptime() void program_help() { - printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\tuptime\n"); + printf("help\tpanic\twords\tprimes\trainbow\tclear\nmath\tbf\tuptime\techo\n"); } +// Panic + void program_panic() { asm volatile("int $0x13"); } + +// Output input + +void program_echo(int argc, char* argv[]) +{ + for (int i=1; i