Created
December 31, 2013 16:19
-
-
Save dagon666/8199064 to your computer and use it in GitHub Desktop.
interpreter2
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
| void cli_read(t_cli_ctx *a_ctx) { | |
| unsigned char i = 0x00; | |
| unsigned char res = E_CMD_OK; | |
| // if no character available - then exit | |
| if (!CLI_IO_INPUT(&i)) return; | |
| /// multi-code matching | |
| if (a_ctx->mc.pos && a_ctx->mc.pos < MULTICODE_INPUT_MAX_LEN) { | |
| unsigned char mi = 0x00; | |
| a_ctx->mc.buf[a_ctx->mc.pos++] = i; | |
| while (a_ctx->mcmds[mi].fh) { | |
| if (!memcmp(a_ctx->mcmds[mi].pattern, | |
| a_ctx->mc.buf, | |
| a_ctx->mcmds[mi].len)) { | |
| a_ctx->mcmds[mi].fh((void *)a_ctx); | |
| a_ctx->mc.pos = 0; | |
| memset(a_ctx->mc.buf, 0x00, MULTICODE_INPUT_MAX_LEN); | |
| break; | |
| } | |
| mi++; | |
| } | |
| return; | |
| } | |
| /// char by char matching | |
| switch(i) { | |
| case KEY_CODE_BACKSPACE: // backspace | |
| case KEY_CODE_DELETE: // del | |
| if (a_ctx->cpos) { | |
| a_ctx->cmd[a_ctx->cpos--] = '\0'; | |
| CLI_IO_OUTPUT("\b \b", 3); | |
| } | |
| break; | |
| case KEY_CODE_ESCAPE: // special characters | |
| a_ctx->mc.pos = 1; | |
| a_ctx->mc.buf[0x00] = i; | |
| break; | |
| case KEY_CODE_ENTER: // new line | |
| a_ctx->cmd[POSINC(a_ctx->cpos)] = '\0'; | |
| CLI_IO_OUTPUT("\r\n", 2); | |
| res = _cli_interpret_cmd(a_ctx); | |
| _cli_reinterpret_cmd(a_ctx, res); | |
| a_ctx->cpos = 0; | |
| memset(a_ctx->cmd, 0x00, CLI_CMD_BUFFER_SIZE); | |
| _cli_prompt(a_ctx, 1); | |
| break; | |
| default: | |
| /* echo */ | |
| if (a_ctx->cpos < (CLI_CMD_BUFFER_SIZE - 1) && isprint(i)) { | |
| a_ctx->cmd[a_ctx->cpos++] = i; | |
| CLI_IO_OUTPUT(&i, 1); | |
| } | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment