#include "fxBoot/terminal.h" #include "fxBoot/parser.h" #include "fxBoot/builtin.h" #include "fxBoot/fs/smemfs.h" #include #include #include /* internal builtin list */ struct { const char *name; int (*f)(int argc, char **argv); } cmd_list[] = { {.name = "mnt", &mnt_main}, {.name = "ls", &ls_main}, {.name = "hyp", &hyp_main}, {.name = NULL, NULL} }; /* try to find the appropriate command */ static int (*check_cmd(char *cmd))(int, char**) { for (int i = 0; cmd_list[i].name != NULL; ++i) { if (strcmp(cmd, cmd_list[i].name) != 0) continue; if (cmd_list[i].f == NULL) terminal_write("command exist but not implemented\n"); return (cmd_list[i].f); } return (NULL); } int main(void) { int (*builtin)(int, char**); const char *usrline; char buff[128]; char **argv; int argc; int ret; /* automated hook */ /* TODO: better way to execute early command */ smemfs_mount(); ret = 0; terminal_open(); terminal_write("Welcome to fxBoot!\n"); while (1) { /* get user command */ usrline = "/>"; if (ret != 0) { usrline = "/[%d]>"; } terminal_write(usrline, ret); ret = 0; if (terminal_read(buff, 128) <= 1) continue; /* parse and try to find the command */ if (parser_strtotab(&argc, &argv, buff) != 0) { terminal_write("error when processing \"%s\"", buff); ret = 255; continue; } builtin = check_cmd(argv[0]); if (builtin == NULL) { terminal_write("command \"%s\" not found...\n", argv[0]); ret = 127; continue; } /* execute the command and free'd allocated memories */ ret = builtin(argc, argv); parser_strtotab_quit(&argc, &argv); } return (1); }