2020-03-30 00:40:59 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2019-12-20 11:31:34 +01:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
//TODO: documentation.
|
|
|
|
int main(void)
|
|
|
|
{
|
2020-01-05 09:00:43 +01:00
|
|
|
char input[12];
|
2019-12-20 11:31:34 +01:00
|
|
|
int cmd_size;
|
2020-03-30 00:40:59 +02:00
|
|
|
char **argv;
|
|
|
|
int argc;
|
2020-03-18 17:48:53 +01:00
|
|
|
|
2019-12-20 11:31:34 +01:00
|
|
|
// Shell main loop.
|
2020-03-20 22:47:05 +01:00
|
|
|
write(STDOUT_FILENO, "Boot Complete !\n", 16);
|
2019-12-20 11:31:34 +01:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
// Get user command.
|
2020-03-20 22:47:05 +01:00
|
|
|
write(STDOUT_FILENO, ">", 1);
|
2020-03-30 00:40:59 +02:00
|
|
|
memset(input, 0x00, 12);
|
2020-03-20 22:47:05 +01:00
|
|
|
cmd_size = read(STDIN_FILENO, input, 12);
|
2019-12-20 11:31:34 +01:00
|
|
|
|
2020-03-23 15:58:48 +01:00
|
|
|
// Check no char
|
|
|
|
if (cmd_size == 1)
|
|
|
|
continue;
|
|
|
|
|
2020-03-30 00:40:59 +02:00
|
|
|
// Generate argc / argv.
|
|
|
|
if (strtotab(&argc, &argv, input) != 0) {
|
|
|
|
printf("parser: internal error\n");
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-20 11:31:34 +01:00
|
|
|
|
|
|
|
// Check buit-in.
|
2020-03-30 00:40:59 +02:00
|
|
|
if (check_builtin(argc, argv) != 0 &&
|
|
|
|
manual_proc_call(argv) != 0)
|
|
|
|
printf("%s: command not found\n", argv[0]);
|
|
|
|
|
|
|
|
// Free argc /argv
|
|
|
|
// TODO: way better way
|
|
|
|
strtotab_quit(&argc, &argv);
|
2019-12-20 11:31:34 +01:00
|
|
|
}
|
2020-01-05 09:00:43 +01:00
|
|
|
return (0);
|
2019-12-20 11:31:34 +01:00
|
|
|
}
|