diff --git a/Makefile b/Makefile index e03c67f..435e4cb 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ CFLAGS = -m32 -mgeneral-regs-only -nostdlib -fno-builtin -fno-exceptions -fno-le LDFLAGS = DISK_IMG_FILES = kernel.bin hello.bin print.bin boot32.bin kernel32.bin -KERNEL32_OBJS = screenstuff.o io.o idt.o keyboard.o kernel32_strap.o kernel32.o +KERNEL32_OBJS = screenstuff.o io.o idt.o keyboard.o strings.o kernel32_strap.o kernel32.o run: disk.img qemu-system-x86_64 disk.img diff --git a/kernel32.c b/kernel32.c index 552267e..5631edd 100644 --- a/kernel32.c +++ b/kernel32.c @@ -4,15 +4,7 @@ #include "idt.h" #include "keyboard.h" -bool strcmp(char* a, char* b, int max) { - int index = 0; - while (index < max) { - if (a[index] != b[index]) - return false; - index++; - } - return true; -} +#include "strings.h" int main() { init_idt(); @@ -33,8 +25,11 @@ int main() { buffer[i] = 0; readline(128, buffer); - //printf("%s\n", buffer); - if (strcmp(buffer, "help", 4)) { + char* argv[32]; + int argc = string_split(' ', buffer, argv); + + + if (strcmp(argv[0], "help", 4)) { printf( "XnoeOS 32 Bit Mode Help.\n" "------------------------\n" @@ -43,9 +38,14 @@ int main() { "- clear\n" ": Clears the screen\n" ); - } else if (strcmp(buffer, "clear", 5)) { + } else if (strcmp(argv[0], "clear", 5)) { clear_screen(); set_curpos(0, 0); + } else if (strcmp(argv[0], "echo", 4)) { + int index = 0; + while (++index <= argc) + printf("%s ", argv[index]); + printf("\n"); } } } \ No newline at end of file diff --git a/strings.c b/strings.c new file mode 100644 index 0000000..373e057 --- /dev/null +++ b/strings.c @@ -0,0 +1,33 @@ +#include "strings.h" + +bool strcmp(char* a, char* b, int max) { + int index = 0; + while (index < max) { + if (a[index] != b[index]) + return false; + index++; + } + return true; +} + +int string_split(char delimeter, char* string, char** pointer_array) { + int index = 0; + int last_split_index = 0; + int split_count = 0; + + char current; + + while (current = string[index]) { + if (current == delimeter) { + string[index] = 0; + pointer_array[split_count++] = (string+last_split_index); + last_split_index = (index+1); + } + index++; + } + + // Add remaining part of the string to the pointer_array + pointer_array[split_count] = (string+last_split_index); + + return split_count; +} \ No newline at end of file diff --git a/strings.h b/strings.h new file mode 100644 index 0000000..8045227 --- /dev/null +++ b/strings.h @@ -0,0 +1,9 @@ +#ifndef STRINGS_H +#define STRINGS_H + +#include + +bool strcmp(char* a, char* b, int max); +int string_split(char delimeter, char* string, char** pointer_array); + +#endif \ No newline at end of file