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 "consts.h"
#include "types.h" #include "types.h"
#include "efn.h" #include "efn.h"
#include "main.c" #include "main.c"
@ -25,5 +24,3 @@
#include "commands.c" #include "commands.c"

28
main.c
View File

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