Skip to content

Instantly share code, notes, and snippets.

@dagon666
Created December 31, 2013 16:22
Show Gist options
  • Save dagon666/8199096 to your computer and use it in GitHub Desktop.
Save dagon666/8199096 to your computer and use it in GitHub Desktop.
history handling
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