#define lineBegin "LF OS #>" #include #include #include char *commands[1024]; char *descriptions[1024]; void *callbacks[1024]; int lastCommandID = -1; #include "commands.c" int printf_res; int strcmp(const char*a,const char*b) {while(*a==*b&&*a)a++,++b;return*(const unsigned char*)a-*(const unsigned char*)b;} char *strcpy(char *target, const char *source) {char *orig_target = target;while(*source)*target++ = *source++;*target = '\0'; return orig_target;} char *strtolower(char *s) { int i = 0; while(s[i]) { s[i] = tolower(s[i]); i++; } return s; } int register_command(char *command, char *description, void * callback) { lastCommandID++; int i; for(i = 0; i < lastCommandID; i++) { if(strcmp(commands[i], command) == 0) { /* this command is already registered! */ return 1; } } commands[lastCommandID] = command; descriptions[lastCommandID] = description; callbacks[lastCommandID] = callback; return 0; } void init_shell() { clear_screen(); register_command("help", " prints this help on the screen", help); register_command("about", " gives you some informations about this version of LF OS", about); register_command("halt", " shuts down the computer.", poweroff); register_command("poweroff", " shuts down the computer.", poweroff); register_command("reboot", " restarts the computer.", reboot); register_command("cls", " empties the content of the shell", cls); register_command("time", " prints the current system time.", time); register_command("paging", "", pagingtest); } void parse_command(char *cmdline) { printf("\n"); int i; int cmdFound = 0; for(i = 0; i <= lastCommandID; i++) { if(strcmp(commands[i], cmdline) == 0) { if(callbacks[i] != NULL) { void (*callback)(); callback = callbacks[i]; callback(); } cmdFound = 1; break; } } if(!cmdFound) printf("Command or File not found: '%s'!", cmdline); set_color(0x0E); printf("\n%s ", lineBegin, "/" /* current folder */); set_color(0x07); } int _start(void) { init_shell(); set_color(0x0E); printf("Welcome to the LittleFox' Operating System 1.0 Alpha 5!\n\n%s ", lineBegin, "/" /* current folder */); set_color(0x07); char *command; while(1) { command = strtolower(getline()); parse_command(command); command = ""; } return 0; }