|
|
| version 1.8.2.2, 2013/10/08 09:18:45 | version 1.9, 2013/10/08 12:04:42 |
|---|---|
| Line 93 clrscrEOL(linebuffer_t * __restrict buf) | Line 93 clrscrEOL(linebuffer_t * __restrict buf) |
| for (i = 0; i < buf->line_len; i++) | for (i = 0; i < buf->line_len; i++) |
| write(buf->line_out, K_SPACE, 1); | write(buf->line_out, K_SPACE, 1); |
| buf->line_level ^= buf->line_level; | |
| } | } |
| } | } |
| Line 105 printfEOL(linebuffer_t * __restrict buf, int len, int | Line 103 printfEOL(linebuffer_t * __restrict buf, int len, int |
| if (prompt && buf->line_prompt) { | if (prompt && buf->line_prompt) { |
| write(buf->line_out, K_CR, 1); | write(buf->line_out, K_CR, 1); |
| write(buf->line_out, buf->line_prompt, buf->line_bol); | write(buf->line_out, buf->line_prompt, buf->line_bol); |
| buf->line_level ^= buf->line_level; | |
| } | } |
| write(buf->line_out, buf->line_buf, len == -1 ? | write(buf->line_out, buf->line_buf, len == -1 ? |
| Line 128 printfNL(linebuffer_t * __restrict buf, int prompt) | Line 125 printfNL(linebuffer_t * __restrict buf, int prompt) |
| if (buf) { | if (buf) { |
| write(buf->line_out, K_ENTER, 1); | write(buf->line_out, K_ENTER, 1); |
| if (prompt) { | if (prompt) |
| if (prompt && buf->line_prompt) | if (prompt && buf->line_prompt) |
| write(buf->line_out, buf->line_prompt, buf->line_bol); | write(buf->line_out, buf->line_prompt, buf->line_bol); |
| buf->line_level ^= buf->line_level; | |
| } | |
| } | } |
| } | } |
| Line 431 bufComp(int idx, void * __restrict cli_buffer) | Line 426 bufComp(int idx, void * __restrict cli_buffer) |
| if (i) { | if (i) { |
| SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next) { | SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next) { |
| if (cmd->cmd_level == buf->line_level && | if (cmd->cmd_level & (1 << buf->line_level) && |
| !strncmp(cmd->cmd_name, items[0], | !strncmp(cmd->cmd_name, items[0], |
| strlen(items[0]))) { | strlen(items[0]))) { |
| if (strncmp(cmd->cmd_name, CLI_CMD_SEP, | if (strncmp(cmd->cmd_name, CLI_CMD_SEP, |
| Line 440 bufComp(int idx, void * __restrict cli_buffer) | Line 435 bufComp(int idx, void * __restrict cli_buffer) |
| c = cmd; | c = cmd; |
| strlcat(szLine, " ", STRSIZ); | strlcat(szLine, " ", STRSIZ); |
| strlcat(szLine, cmd->cmd_name, STRSIZ); | strlcat(szLine, cmd->cmd_name, STRSIZ); |
| buf->line_level++; | |
| } | } |
| } | } |
| } | } |
| Line 458 bufComp(int idx, void * __restrict cli_buffer) | Line 452 bufComp(int idx, void * __restrict cli_buffer) |
| } else { | } else { |
| /* we on 0 position of prompt, show commands for this level */ | /* we on 0 position of prompt, show commands for this level */ |
| SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next) { | SLIST_FOREACH(cmd, &buf->line_cmds, cmd_next) { |
| if (cmd->cmd_level == buf->line_level) | if (cmd->cmd_level & (1 << buf->line_level)) |
| if (strncmp(cmd->cmd_name, CLI_CMD_SEP, strlen(CLI_CMD_SEP))) { | if (strncmp(cmd->cmd_name, CLI_CMD_SEP, strlen(CLI_CMD_SEP))) { |
| j++; | j++; |
| c = cmd; | c = cmd; |
| strlcat(szLine, " ", STRSIZ); | strlcat(szLine, " ", STRSIZ); |
| strlcat(szLine, cmd->cmd_name, STRSIZ); | strlcat(szLine, cmd->cmd_name, STRSIZ); |
| buf->line_level++; | |
| } | } |
| } | } |
| } | } |
| Line 506 bufHelp(int idx, void * __restrict cli_buffer) | Line 499 bufHelp(int idx, void * __restrict cli_buffer) |
| if (!cli_buffer || idx < 0 || idx > MAX_BINDKEY) | if (!cli_buffer || idx < 0 || idx > MAX_BINDKEY) |
| return RETCODE_ERR; | return RETCODE_ERR; |
| cli_Cmd_Help(buf, -1, NULL); | cli_Cmd_Help(buf, buf->line_level, NULL); |
| printfEOL(buf, buf->line_len - 1, 1); | printfEOL(buf, buf->line_len - 1, 1); |
| printfEOL(buf, -1, 1); | printfEOL(buf, -1, 1); |
| return RETCODE_OK; | return RETCODE_OK; |
| } | } |
| static int | |
| bufEndNode(int idx, void * __restrict cli_buffer) | |
| { | |
| linebuffer_t *buf = cli_buffer; | |
| if (!cli_buffer || idx < 0 || idx > MAX_BINDKEY) | |
| return RETCODE_ERR; | |
| if (buf->line_level > 0) { | |
| printfNL(cli_buffer, 0); | |
| buf->line_level--; | |
| cli_Printf(buf, "Enter to config level %d\n", buf->line_level); | |
| } | |
| return bufCLR(idx, cli_buffer); | |
| } | |
| /* | /* |
| * cli_Printf() - Send message to CLI session | * cli_Printf() - Send message to CLI session |
| * | * |
| Line 593 cli_BindKey(bindkey_t * __restrict key, linebuffer_t * | Line 603 cli_BindKey(bindkey_t * __restrict key, linebuffer_t * |
| * | * |
| * @cli_buffer = CLI buffer | * @cli_buffer = CLI buffer |
| * @csCmd = Command name | * @csCmd = Command name |
| * @cliLevel = Level in CLI, -1 unprivi(view from all), 0 main config, 1 sub config ... | * @cliLevel = Level in CLI, -1 view from all levels, 0 hidden, >0 mask levels |
| * @funcCmd = Callback function when user call command | * @funcCmd = Callback function when user call command |
| * @csInfo = Inline information for command | * @csInfo = Inline information for command |
| * @csHelp = Help line when call help | * @csHelp = Help line when call help |
| Line 634 cli_addCommand(linebuffer_t * __restrict cli_buffer, c | Line 644 cli_addCommand(linebuffer_t * __restrict cli_buffer, c |
| * | * |
| * @cli_buffer = CLI buffer | * @cli_buffer = CLI buffer |
| * @csCmd = Command name | * @csCmd = Command name |
| * @cliLevel = Level in CLI, -1 unprivi(view from all), 0 main config, 1 sub config ... | * @cliLevel = Level in CLI, -1 view from all levels, 0 hidden, >0 mask levels |
| * return: RETCODE_ERR error, RETCODE_OK ok | * return: RETCODE_ERR error, RETCODE_OK ok |
| */ | */ |
| int | int |
| Line 664 cli_delCommand(linebuffer_t * __restrict cli_buffer, c | Line 674 cli_delCommand(linebuffer_t * __restrict cli_buffer, c |
| * | * |
| * @cli_buffer = CLI buffer | * @cli_buffer = CLI buffer |
| * @csCmd = Command name | * @csCmd = Command name |
| * @cliLevel = Level in CLI, -1 unprivi(view from all), 0 main config, 1 sub config ... | * @cliLevel = Level in CLI, -1 view from all levels, 0 hidden, >0 mask levels |
| * @funcCmd = Callback function when user call command | * @funcCmd = Callback function when user call command |
| * @csInfo = Inline information for command | * @csInfo = Inline information for command |
| * @csHelp = Help line when call help | * @csHelp = Help line when call help |
| Line 683 cli_updCommand(linebuffer_t * __restrict cli_buffer, c | Line 693 cli_updCommand(linebuffer_t * __restrict cli_buffer, c |
| return RETCODE_ERR; | return RETCODE_ERR; |
| } | } |
| SLIST_FOREACH(cmd, &cli_buffer->line_cmds, cmd_next) | SLIST_FOREACH(cmd, &cli_buffer->line_cmds, cmd_next) |
| if (cmd->cmd_level == cliLevel && !strcmp(cmd->cmd_name, csCmd)) { | if ((!cmd->cmd_level || cmd->cmd_level == cliLevel) && |
| ret = 1; | !strcmp(cmd->cmd_name, csCmd)) { |
| if (!cmd->cmd_level) | |
| cmd->cmd_level = cliLevel; | |
| if (funcCmd) | if (funcCmd) |
| cmd->cmd_func = funcCmd; | cmd->cmd_func = funcCmd; |
| if (csInfo) | if (csInfo) |
| Line 1016 cliInit(int fin, int fout, const char *prompt) | Line 1027 cliInit(int fin, int fout, const char *prompt) |
| memset(keys, 0, sizeof(bindkey_t) * (MAX_BINDKEY + 1)); | memset(keys, 0, sizeof(bindkey_t) * (MAX_BINDKEY + 1)); |
| /* add helper functions */ | /* add helper functions */ |
| cli_addCommand(cli_buffer, "exit", 0, cli_Cmd_Exit, "exit <cr>", "Exit from console"); | cli_addCommand(cli_buffer, "exit", 1, cli_Cmd_Exit, "exit <cr>", "Exit from console"); |
| cli_addCommand(cli_buffer, "help", 0, cli_Cmd_Help, "help [command] <cr>", "Help screen"); | cli_addCommand(cli_buffer, "help", -1, cli_Cmd_Help, "help [command] <cr>", "Help screen"); |
| cli_addCommand(cli_buffer, "-------", 0, NULL, "-------------------------", NULL); | cli_addCommand(cli_buffer, "-------", -1, NULL, "-------------------------", NULL); |
| cli_addCommand(cli_buffer, "where", -1, cli_Cmd_WhereAmI, "where <cr>", | |
| "Query current level of console"); | |
| cli_addCommand(cli_buffer, "top", -1, cli_Cmd_Top, "top <cr>", "Top level of console"); | |
| cli_addCommand(cli_buffer, "end", -1, cli_Cmd_End, "end <cr>", "End level of console"); | |
| cli_addCommand(cli_buffer, "config", -1, cli_Cmd_Config, "config <cr>", | |
| "Config next level of console"); | |
| cli_addCommand(cli_buffer, "-------", -1, NULL, "-------------------------", NULL); | |
| /* fill key bindings */ | /* fill key bindings */ |
| /* ascii chars & ctrl+chars */ | /* ascii chars & ctrl+chars */ |
| Line 1040 cliInit(int fin, int fout, const char *prompt) | Line 1058 cliInit(int fin, int fout, const char *prompt) |
| keys[i].key_func = bufEND; | keys[i].key_func = bufEND; |
| if (cli_buffer->line_prompt && i == *K_TAB) | if (cli_buffer->line_prompt && i == *K_TAB) |
| keys[i].key_func = bufComp; | keys[i].key_func = bufComp; |
| if (cli_buffer->line_prompt && i == *K_CTRL_Z) | |
| keys[i].key_func = bufEndNode; | |
| if (i >= *K_SPACE && i < *K_BACKSPACE) | if (i >= *K_SPACE && i < *K_BACKSPACE) |
| keys[i].key_func = bufCHAR; | keys[i].key_func = bufCHAR; |
| if (i > *K_BACKSPACE && i < 0xff) | if (i > *K_BACKSPACE && i < 0xff) |
| Line 1476 cliLoop(linebuffer_t * __restrict cli_buffer, const ch | Line 1496 cliLoop(linebuffer_t * __restrict cli_buffer, const ch |
| // exec_cmd ... | // exec_cmd ... |
| i = 0; | i = 0; |
| SLIST_FOREACH(cmd, &cli_buffer->line_cmds, cmd_next) { | SLIST_FOREACH(cmd, &cli_buffer->line_cmds, cmd_next) { |
| if (!(cmd->cmd_level & (1 << cli_buffer->line_level))) | |
| continue; | |
| if (*items[0] && !strncmp(cmd->cmd_name, items[0], strlen(items[0]))) | if (*items[0] && !strncmp(cmd->cmd_name, items[0], strlen(items[0]))) |
| break; | break; |
| else | else |
| Line 1488 cliLoop(linebuffer_t * __restrict cli_buffer, const ch | Line 1510 cliLoop(linebuffer_t * __restrict cli_buffer, const ch |
| } else | } else |
| if (cmd->cmd_func) { | if (cmd->cmd_func) { |
| cli_Printf(cli_buffer, "\n"); | cli_Printf(cli_buffer, "\n"); |
| ret = cmd->cmd_func(cli_buffer, i, items); | ret = cmd->cmd_func(cli_buffer, |
| cli_buffer->line_level, items); | |
| } else { | } else { |
| clrscrEOL(cli_buffer); | clrscrEOL(cli_buffer); |
| printfCR(cli_buffer, 1); | printfCR(cli_buffer, 1); |