Created
December 31, 2013 10:13
-
-
Save dagon666/8194909 to your computer and use it in GitHub Desktop.
cli command interpretation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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