Added single split function, added error message to kernel32

This commit is contained in:
Xnoe 2021-09-06 15:52:12 +01:00
parent 290794b885
commit c803f4a38e
Signed by: xnoe
GPG Key ID: 45AC398F44F0DAFE
3 changed files with 24 additions and 9 deletions

View File

@ -25,11 +25,10 @@ int main() {
buffer[i] = 0;
readline(128, buffer);
char* argv[32];
int argc = string_split(' ', buffer, argv);
char* rest = split_on_first(' ', buffer);
if (strcmp(argv[0], "help", 4)) {
if (strcmp(buffer, "help", 4)) {
printf(
"XnoeOS 32 Bit Mode Help.\n"
"------------------------\n"
@ -37,15 +36,16 @@ int main() {
": Shows this message\n"
"- clear\n"
": Clears the screen\n"
" - echo\n"
": Repeats the text written afterwards\n"
);
} else if (strcmp(argv[0], "clear", 5)) {
} else if (strcmp(buffer, "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");
} else if (strcmp(buffer, "echo", 4)) {
printf("%s\n", rest);
} else {
printf("Bad Command or filename!\n");
}
}
}

View File

@ -10,6 +10,20 @@ bool strcmp(char* a, char* b, int max) {
return true;
}
char* split_on_first(char delimeter, char* string) {
int index = 0;
char current;
while (current = string[index++]) {
if (current == delimeter) {
string[index-1] = 0;
return string+index;
}
}
return 0;
}
int string_split(char delimeter, char* string, char** pointer_array) {
int index = 0;
int last_split_index = 0;

View File

@ -4,6 +4,7 @@
#include <stdbool.h>
bool strcmp(char* a, char* b, int max);
char* split_on_first(char delimeter, char* string);
int string_split(char delimeter, char* string, char** pointer_array);
#endif