Created
December 31, 2013 16:22
-
-
Save dagon666/8199096 to your computer and use it in GitHub Desktop.
history handling
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
| static void _cli_history_add(t_cli_ctx *a_ctx) { | |
| if (a_ctx->hhead == CLI_CMD_HISTORY_LEN && | |
| a_ctx->htail == CLI_CMD_HISTORY_LEN) { | |
| a_ctx->hhead = 0; | |
| a_ctx->htail = 0; | |
| } | |
| else { | |
| a_ctx->hhead++; | |
| a_ctx->hhead %= CLI_CMD_HISTORY_LEN; | |
| a_ctx->hpos = a_ctx->hhead; | |
| if (a_ctx->htail >= a_ctx->hhead) { | |
| a_ctx->htail = (a_ctx->hhead + 1) % CLI_CMD_HISTORY_LEN; | |
| } | |
| } | |
| memset(a_ctx->history[a_ctx->hhead], 0x00, CLI_CMD_BUFFER_SIZE); | |
| strcpy(a_ctx->history[a_ctx->hhead], a_ctx->cmd); | |
| } | |
| static void _cli_reinterpret_cmd(t_cli_ctx *a_ctx, unsigned char a_response) { | |
| switch(a_response) { | |
| case E_CMD_NOT_FOUND: { | |
| char str[] = "\r\nCommand not found"; | |
| CLI_IO_OUTPUT(str, strlen(str)); | |
| _cli_history_add(a_ctx); | |
| } | |
| break; | |
| case E_CMD_TOO_SHORT: { | |
| char str[] = "\r\nCommand too short"; | |
| CLI_IO_OUTPUT(str, strlen(str)); | |
| } | |
| break; | |
| default: | |
| _cli_history_add(a_ctx); | |
| break; | |
| } // switch | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment