stmbl/shared/commands.c

35 lines
695 B
C
Raw Permalink Normal View History

#include "commands.h"
#include "commandslist.h"
#include <string.h>
#include <stdio.h>
2017-09-06 02:20:06 +00:00
uint32_t call_cmd(char *s) {
char c[64];
char a[64];
uint32_t foo = sscanf(s, " %[a-zA-Z_0-9] %[ -~]", c, a);
switch(foo) {
case 0:
return (0);
case 1:
a[0] = 0;
case 2:
for(uint32_t i = 0; i < sizeof(cmd) / sizeof(cmd_t); i++) {
if(!strcmp(cmd[i].name, c)) {
cmd[i].ptr(a);
return (1);
}
}
default:
return (0);
}
return (0);
}
2017-04-15 17:31:19 +00:00
2017-09-06 02:20:06 +00:00
void listcmd(char *ptr) {
for(uint32_t i = 0; i < sizeof(cmd) / sizeof(cmd_t); i++) {
printf("%s: %s\n", cmd[i].name, cmd[i].doc);
2017-04-15 17:31:19 +00:00
}
}
2017-07-12 20:12:04 +00:00
COMMAND("help", listcmd, "print this");