added run command function

master
bx 2022-04-03 21:35:16 +01:00
parent 866f407472
commit 9639dfc19e
2 changed files with 23 additions and 8 deletions

3
efn.c
View File

@ -3,7 +3,6 @@
#include "consts.h"
#include "types.h"
#include "efn.h"
#include "main.c"
@ -25,5 +24,3 @@
#include "commands.c"

28
main.c
View File

@ -18,9 +18,24 @@ parse_command(char *input) {
return &starts[0];
}
void
run_command(char *c) {
char **com = parse_command(c);
if(com[0] == NULL) return;
if(commands[com[0][0]] != NULL)
commands[com[0][0]](c, com);
else
puts("invalid command");
}
int
main(int argc, char **argv) {
static char buf[COM_BUF_SIZE];
if (argc >= 2) {
// todo, open file
}
while(1) {
memset(buf, 0, sizeof(buf));
printf(" > ");
@ -30,12 +45,15 @@ main(int argc, char **argv) {
if (buf[i] == '\n')
buf[i] = '\0';
if (com != NULL) {
if (commands[com[0]] != NULL) commands[com[0]](buf, parse_command(com));
else puts("invalid command.");
}
}
return 0;
run_command(com);
}
}
return 0;
}