Skip to content

Instantly share code, notes, and snippets.

@dagon666
Created December 31, 2013 10:13
Show Gist options
  • Save dagon666/8194909 to your computer and use it in GitHub Desktop.
Save dagon666/8194909 to your computer and use it in GitHub Desktop.
cli command interpretation
typedef enum _t_cmd_status {
E_CMD_OK = 0,
E_CMD_NOT_FOUND,
E_CMD_TOO_SHORT,
E_CMD_EMPTY
} t_cmd_status;
static unsigned char _cli_interpret_cmd(t_cli_ctx *a_ctx) {
unsigned char i = 0;
unsigned char ret = E_CMD_OK;
if (!strlen(a_ctx->cmd)) {
return E_CMD_EMPTY;
}
if (strlen(a_ctx->cmd) < 2) {
return E_CMD_TOO_SHORT;
}
while (a_ctx->cmds[i].fh) {
if (!strncmp(a_ctx->cmds[i].cmd, a_ctx->cmd, strlen(a_ctx->cmds[i].cmd))) {
// call the handler
a_ctx->cmds[i].fh((void *)a_ctx);
break;
}
i++;
}
if (!a_ctx->cmds[i].fh) {
ret = E_CMD_NOT_FOUND;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment