--- libaitcli/src/aitcli.c 2010/06/07 11:32:50 1.2.2.6 +++ libaitcli/src/aitcli.c 2010/06/07 12:30:28 1.2.2.8 @@ -3,10 +3,11 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcli.c,v 1.2.2.6 2010/06/07 11:32:50 misho Exp $ +* $Id: aitcli.c,v 1.2.2.8 2010/06/07 12:30:28 misho Exp $ * *************************************************************************/ #include "global.h" +#include "cli.h" #pragma GCC visibility push(hidden) @@ -383,6 +384,30 @@ bufDEL(int idx, void * __restrict buffer) return RETCODE_OK; } +static int +bufComp(int idx, void * __restrict buffer) +{ + linebuffer_t *buf = buffer; + + if (!buffer || idx < 0 || idx > MAX_BINDKEY) + return RETCODE_ERR; + + return RETCODE_OK; +} + +static int +bufHelp(int idx, void * __restrict buffer) +{ + linebuffer_t *buf = buffer; + + if (!buffer || idx < 0 || idx > MAX_BINDKEY) + return RETCODE_ERR; + + cli_Cmd_Help(buf, -1, NULL); + printfCR(buf, 1); + return RETCODE_OK; +} + // --------------------------------------------------------------- /* @@ -853,6 +878,10 @@ cliInit(int fin, int fout, const char *prompt) } else memset(keys, 0, sizeof(bindkey_t) * (MAX_BINDKEY + 1)); + /* add helper functions */ + cli_addCommand(buffer, "exit", 0, cli_Cmd_Exit, "exit ", "Exit from console"); + cli_addCommand(buffer, "help", 0, cli_Cmd_Help, "help [command] ", "Help screen"); + /* fill key bindings */ // ascii chars & ctrl+chars for (i = 0; i < 256; i++) { @@ -871,10 +900,14 @@ cliInit(int fin, int fout, const char *prompt) keys[i].key_func = bufBEGIN; if (i == *K_CTRL_E) keys[i].key_func = bufEND; + if (i == *K_TAB) + keys[i].key_func = bufComp; if (i >= *K_SPACE && i < *K_BACKSPACE) keys[i].key_func = bufCHAR; if (i > *K_BACKSPACE && i < 0xff) keys[i].key_func = bufCHAR; + if (i == '?') + keys[i].key_func = bufHelp; } // alt+chars for (i = 256; i < 512; i++) { @@ -1148,14 +1181,12 @@ cliNetLoop(linebuffer_t * __restrict buffer, const cha case 0: close(sock); -// buffer = cliInit(STDIN_FILENO, STDOUT_FILENO, csPrompt); -// if (!buffer) -// return RETCODE_ERR; + if (buffer) { + ret = cliLoop(buffer, csHistFile) < 0 ? 1 : 0; + cliEnd(buffer); + } else + cli_SetErr(EINVAL, "Error:: invalid input parameters ..."); - ret = cliLoop(buffer, csHistFile) < 0 ? 1 : 0; - -// cliEnd(buffer); - /* spawn Shell mode */ /* execl("/bin/tcsh", "tcsh", NULL); @@ -1250,12 +1281,6 @@ cliLoop(linebuffer_t * __restrict buffer, const char * struct tagCommand *cmd; /* - inline int inline_help() - { - cli_Cmd_Help(cmdList ? cmdList : cli_stdCmds, -1, out, NULL); - rl_on_new_line(); - return 0; - } char **cli_stdCompletion(const char *text, int start, int end) {