--- libaitcli/src/aitcli.c 2010/06/09 09:32:30 1.2.2.17 +++ libaitcli/src/aitcli.c 2010/12/07 15:09:02 1.2.2.18 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitcli.c,v 1.2.2.17 2010/06/09 09:32:30 misho Exp $ +* $Id: aitcli.c,v 1.2.2.18 2010/12/07 15:09:02 misho Exp $ * *************************************************************************/ #include "global.h" @@ -906,11 +906,9 @@ cliInit(int fin, int fout, const char *prompt) linebuffer_t *buffer; bindkey_t *keys; register int i; - struct termios t; - memset(&t, 0, sizeof t); /* init buffer */ - buffer = malloc(sizeof (linebuffer_t)); + buffer = malloc(sizeof(linebuffer_t)); if (!buffer) { LOGERR; return NULL; @@ -1148,15 +1146,27 @@ cliInit(int fin, int fout, const char *prompt) memcpy(keys[i].key_ch, K_F12, keys[i].key_len); i++; + buffer->line_keys = keys; + return buffer; +} + +/* + * cliInitLine() Init CLI input line terminal + * @buffer = CLI buffer + * return: none +*/ +int +cliInitLine(linebuffer_t * __restrict buffer) +{ + struct termios t; + + memset(&t, 0, sizeof t); tcgetattr(buffer->line_in, &t); t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); t.c_iflag |= IGNBRK; t.c_cc[VMIN] = 1; t.c_cc[VTIME] = 0; - tcsetattr(buffer->line_in, TCSANOW, &t); - - buffer->line_keys = keys; - return buffer; + return tcsetattr(buffer->line_in, TCSANOW, &t); } /* @@ -1190,7 +1200,6 @@ cliReadLine(linebuffer_t * __restrict buffer) memset(buf, 0, sizeof buf); readLen = read(buffer->line_in, buf, BUFSIZ); - printf("+++ %s %d\n", buf, readLen); if (readLen == -1) { LOGERR; return str; @@ -1255,17 +1264,17 @@ cliNetLoop(linebuffer_t * __restrict buffer, const cha LOGERR; return -1; case 0: - close(sock); - - if (buffer) - ret = cliLoop(buffer, csHistFile) < 0 ? 1 : 0; - else + if (!buffer) { cli_SetErr(EINVAL, "Error:: invalid input parameters ..."); + return -1; + } else + close(sock); - /* spawn Shell mode */ - //execl("/bin/tcsh", "tcsh", NULL); + cliInitLine(buffer); + ret = cliLoop(buffer, csHistFile) < 0 ? 1 : 0; + cliEnd(buffer); - _exit(ret); + exit(ret); default: telnet_SetCmd(Attr + 0, DO, TELOPT_TTYPE); telnet_SetCmd(Attr + 1, WILL, TELOPT_ECHO);