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; }