|
|
| version 1.8.2.6, 2013/10/08 09:41:20 | version 1.8.2.8, 2013/10/08 12:01:59 |
|---|---|
| Line 426 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 452 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; |
| Line 506 bufHelp(int idx, void * __restrict cli_buffer) | Line 506 bufHelp(int idx, void * __restrict cli_buffer) |
| 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 586 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 627 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 657 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 676 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 1009 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 1033 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 1469 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 != cli_buffer->line_level) | if (!(cmd->cmd_level & (1 << cli_buffer->line_level))) |
| continue; | 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; |