fxBoot/src/main.c

67 lines
1.4 KiB
C

#include "fxBoot/terminal.h"
#include "fxBoot/parser.h"
#include <gint/std/string.h>
#include <gint/keyboard.h>
#include <gint/display.h>
/* internal builtin list */
struct {
const char *name;
int (*f)(int argc, char **argv);
} cmd_list[] = {
{.name = "ls", NULL},
{.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;
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);
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);
}
builtin = check_cmd(argv[0]);
if (builtin == NULL) {
terminal_write("command \"%s\" not found...\n", argv[0]);
continue;
}
/* execute the command and free'd allocated memories */
ret = builtin(argc, argv);
parser_strtotab_quit(&argc, &argv);
}
return (1);
}