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 =
|
LDFLAGS =
|
||||||
|
|
||||||
DISK_IMG_FILES = kernel.bin hello.bin print.bin boot32.bin kernel32.bin
|
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
|
run: disk.img
|
||||||
qemu-system-x86_64 disk.img
|
qemu-system-x86_64 disk.img
|
||||||
|
24
kernel32.c
24
kernel32.c
@ -4,15 +4,7 @@
|
|||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
|
|
||||||
bool strcmp(char* a, char* b, int max) {
|
#include "strings.h"
|
||||||
int index = 0;
|
|
||||||
while (index < max) {
|
|
||||||
if (a[index] != b[index])
|
|
||||||
return false;
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
init_idt();
|
init_idt();
|
||||||
@ -33,8 +25,11 @@ int main() {
|
|||||||
buffer[i] = 0;
|
buffer[i] = 0;
|
||||||
readline(128, buffer);
|
readline(128, buffer);
|
||||||
|
|
||||||
//printf("%s\n", buffer);
|
char* argv[32];
|
||||||
if (strcmp(buffer, "help", 4)) {
|
int argc = string_split(' ', buffer, argv);
|
||||||
|
|
||||||
|
|
||||||
|
if (strcmp(argv[0], "help", 4)) {
|
||||||
printf(
|
printf(
|
||||||
"XnoeOS 32 Bit Mode Help.\n"
|
"XnoeOS 32 Bit Mode Help.\n"
|
||||||
"------------------------\n"
|
"------------------------\n"
|
||||||
@ -43,9 +38,14 @@ int main() {
|
|||||||
"- clear\n"
|
"- clear\n"
|
||||||
": Clears the screen\n"
|
": Clears the screen\n"
|
||||||
);
|
);
|
||||||
} else if (strcmp(buffer, "clear", 5)) {
|
} else if (strcmp(argv[0], "clear", 5)) {
|
||||||
clear_screen();
|
clear_screen();
|
||||||
set_curpos(0, 0);
|
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