Add string manipulation functions. Update Makefile accordingly. Add echo command to kernel32.
This commit is contained in:
parent
26d231a7c9
commit
290794b885
2
Makefile
2
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
|
||||
|
24
kernel32.c
24
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");
|
||||
}
|
||||
}
|
||||
}
|
33
strings.c
Normal file
33
strings.c
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user