|
version 1.16.2.1, 2020/09/01 23:17:03
|
version 1.19.4.2, 2024/10/29 01:00:09
|
|
Line 12 terms:
|
Line 12 terms:
|
| All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
| Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
| |
|
| Copyright 2004 - 2020 | Copyright 2004 - 2024 |
| by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
| |
|
| Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
|
Line 87 static inline void
|
Line 87 static inline void
|
| clrscrEOL(linebuffer_t * __restrict buf) |
clrscrEOL(linebuffer_t * __restrict buf) |
| { |
{ |
| register int i; |
register int i; |
| |
int ign __attribute__((unused)); |
| |
|
| if (buf && buf->line_prompt) { |
if (buf && buf->line_prompt) { |
| write(buf->line_out, K_CR, 1); | ign = write(buf->line_out, K_CR, 1); |
| |
|
| for (i = 0; i < buf->line_len; i++) |
for (i = 0; i < buf->line_len; i++) |
| write(buf->line_out, K_SPACE, 1); | ign = write(buf->line_out, K_SPACE, 1); |
| } |
} |
| } |
} |
| |
|
| static inline void |
static inline void |
| printfEOL(linebuffer_t * __restrict buf, int len, int prompt) |
printfEOL(linebuffer_t * __restrict buf, int len, int prompt) |
| { |
{ |
| |
int ign __attribute__((unused)); |
| |
|
| if (buf) { |
if (buf) { |
| if (prompt && buf->line_prompt) { |
if (prompt && buf->line_prompt) { |
| write(buf->line_out, K_CR, 1); | ign = write(buf->line_out, K_CR, 1); |
| write(buf->line_out, buf->line_prompt, buf->line_bol); | ign = write(buf->line_out, buf->line_prompt, buf->line_bol); |
| } |
} |
| |
|
| write(buf->line_out, buf->line_buf, len == -1 ? | ign = write(buf->line_out, buf->line_buf, len == -1 ? |
| buf->line_eol - buf->line_bol : len); |
buf->line_eol - buf->line_bol : len); |
| } |
} |
| } |
} |
|
Line 113 printfEOL(linebuffer_t * __restrict buf, int len, int
|
Line 116 printfEOL(linebuffer_t * __restrict buf, int len, int
|
| static inline void |
static inline void |
| printfCR(linebuffer_t * __restrict buf, int prompt) |
printfCR(linebuffer_t * __restrict buf, int prompt) |
| { |
{ |
| |
int ign __attribute__((unused)); |
| |
|
| if (buf && prompt && buf->line_prompt) { |
if (buf && prompt && buf->line_prompt) { |
| write(buf->line_out, K_CR, 1); | ign = write(buf->line_out, K_CR, 1); |
| write(buf->line_out, buf->line_prompt, buf->line_bol); | ign = write(buf->line_out, buf->line_prompt, buf->line_bol); |
| } |
} |
| } |
} |
| |
|
| static inline void |
static inline void |
| printfNL(linebuffer_t * __restrict buf, int prompt) |
printfNL(linebuffer_t * __restrict buf, int prompt) |
| { |
{ |
| |
int ign __attribute__((unused)); |
| |
|
| if (buf) { |
if (buf) { |
| write(buf->line_out, K_ENTER, 1); | ign = 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); | ign = write(buf->line_out, buf->line_prompt, buf->line_bol); |
| } |
} |
| } |
} |
| |
|
|
Line 138 bufCHAR(int idx, void * __restrict cli_buffer)
|
Line 145 bufCHAR(int idx, void * __restrict cli_buffer)
|
| { |
{ |
| linebuffer_t *buf = cli_buffer; |
linebuffer_t *buf = cli_buffer; |
| int pos; |
int pos; |
| |
int ign __attribute__((unused)); |
| |
|
| if (!cli_buffer || idx < 0 || idx > MAX_BINDKEY) |
if (!cli_buffer || idx < 0 || idx > MAX_BINDKEY) |
| return RETCODE_ERR; |
return RETCODE_ERR; |
|
Line 155 bufCHAR(int idx, void * __restrict cli_buffer)
|
Line 163 bufCHAR(int idx, void * __restrict cli_buffer)
|
| buf->line_buf[buf->line_len - 1] = 0; |
buf->line_buf[buf->line_len - 1] = 0; |
| |
|
| if (buf->line_prompt) |
if (buf->line_prompt) |
| write(buf->line_out, buf->line_keys[idx].key_ch, buf->line_keys[idx].key_len); | ign = write(buf->line_out, buf->line_keys[idx].key_ch, buf->line_keys[idx].key_len); |
| |
|
| if (buf->line_mode == LINEMODE_INS) { |
if (buf->line_mode == LINEMODE_INS) { |
| write(buf->line_out, (const u_char*) buf->line_buf + pos + buf->line_keys[idx].key_len, | ign = write(buf->line_out, (const u_char*) buf->line_buf + pos + buf->line_keys[idx].key_len, |
| buf->line_len - buf->line_eol); |
buf->line_len - buf->line_eol); |
| printfEOL(buf, -1, 1); |
printfEOL(buf, -1, 1); |
| } |
} |
|
Line 404 bufComp(int idx, void * __restrict cli_buffer)
|
Line 412 bufComp(int idx, void * __restrict cli_buffer)
|
| register int i, j; |
register int i, j; |
| struct tagCommand *cmd, *c; |
struct tagCommand *cmd, *c; |
| int pos, ret = RETCODE_OK; |
int pos, ret = RETCODE_OK; |
| |
int ign __attribute__((unused)); |
| |
|
| if (!cli_buffer || idx < 0 || idx > MAX_BINDKEY) |
if (!cli_buffer || idx < 0 || idx > MAX_BINDKEY) |
| return RETCODE_ERR; |
return RETCODE_ERR; |
|
Line 416 bufComp(int idx, void * __restrict cli_buffer)
|
Line 425 bufComp(int idx, void * __restrict cli_buffer)
|
| str_Trim(s); |
str_Trim(s); |
| } |
} |
| |
|
| i = j = 0; | j = 0; |
| c = NULL; |
c = NULL; |
| memset(szLine, 0, STRSIZ); |
memset(szLine, 0, STRSIZ); |
| if (*s) { |
if (*s) { |
|
Line 466 bufComp(int idx, void * __restrict cli_buffer)
|
Line 475 bufComp(int idx, void * __restrict cli_buffer)
|
| /* completion show actions ... */ |
/* completion show actions ... */ |
| if (j > 1 && c) { |
if (j > 1 && c) { |
| printfNL(buf, 0); |
printfNL(buf, 0); |
| write(buf->line_out, szLine, strlen(szLine)); | ign = write(buf->line_out, szLine, strlen(szLine)); |
| printfNL(buf, 1); |
printfNL(buf, 1); |
| printfEOL(buf, buf->line_len - 1, 1); |
printfEOL(buf, buf->line_len - 1, 1); |
| printfEOL(buf, -1, 1); |
printfEOL(buf, -1, 1); |
|
Line 978 cliInit(int fin, int fout, const char *prompt)
|
Line 987 cliInit(int fin, int fout, const char *prompt)
|
| linebuffer_t *cli_buffer; |
linebuffer_t *cli_buffer; |
| bindkey_t *keys; |
bindkey_t *keys; |
| register int i; |
register int i; |
| char szPrompt[STRSIZ] = {[0 ... STRSIZ - 1] = 0}; | char szPrompt[STRSIZ + 16] = {[0 ... STRSIZ + 15] = 0}; |
| |
|
| /* init buffer */ |
/* init buffer */ |
| cli_buffer = e_malloc(sizeof(linebuffer_t)); |
cli_buffer = e_malloc(sizeof(linebuffer_t)); |
|
Line 1246 cliInit(int fin, int fout, const char *prompt)
|
Line 1255 cliInit(int fin, int fout, const char *prompt)
|
| } |
} |
| |
|
| /* |
/* |
| * cliInitLine() - Init CLI input line terminal | * cliSetLine() - Set CLI input line terminal |
| * |
* |
| * @cli_buffer = CLI buffer |
* @cli_buffer = CLI buffer |
| * return: none | * @old = Old terminal settings |
| | * return: -1 error or 0 ok |
| */ |
*/ |
| int |
int |
| cliInitLine(linebuffer_t * __restrict cli_buffer) | cliSetLine(linebuffer_t * __restrict cli_buffer, struct termios * __restrict old) |
| { |
{ |
| struct termios t; |
struct termios t; |
| |
|
| memset(&t, 0, sizeof t); |
memset(&t, 0, sizeof t); |
| tcgetattr(cli_buffer->line_in, &t); |
tcgetattr(cli_buffer->line_in, &t); |
| |
if (old) |
| |
memcpy(old, &t, sizeof(struct termios)); |
| t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | |
t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | |
| ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
| t.c_iflag |= IGNBRK; |
t.c_iflag |= IGNBRK; |
|
Line 1267 cliInitLine(linebuffer_t * __restrict cli_buffer)
|
Line 1279 cliInitLine(linebuffer_t * __restrict cli_buffer)
|
| } |
} |
| |
|
| /* |
/* |
| |
* cliResetLine() - Reset CLI input line terminal |
| |
* |
| |
* @cli_buffer = CLI buffer |
| |
* @old = Original terminal settings |
| |
* return: -1 error or 0 ok |
| |
*/ |
| |
int |
| |
cliResetLine(linebuffer_t * __restrict cli_buffer, struct termios * __restrict orig) |
| |
{ |
| |
return tcsetattr(cli_buffer->line_in, TCSANOW, orig); |
| |
} |
| |
|
| |
/* |
| * cliReadLine() - Read line from opened CLI session |
* cliReadLine() - Read line from opened CLI session |
| * |
* |
| * @cli_buffer = CLI buffer |
* @cli_buffer = CLI buffer |
|
Line 1474 int
|
Line 1499 int
|
| cliRun(linebuffer_t * __restrict cli_buffer, char *psInput, int prompt) |
cliRun(linebuffer_t * __restrict cli_buffer, char *psInput, int prompt) |
| { |
{ |
| char *line, *s, *t, **app, *items[MAX_PROMPT_ITEMS]; |
char *line, *s, *t, **app, *items[MAX_PROMPT_ITEMS]; |
| register int i; |
|
| int ret = RETCODE_OK; |
int ret = RETCODE_OK; |
| struct tagCommand *cmd; |
struct tagCommand *cmd; |
| |
|
|
Line 1496 cliRun(linebuffer_t * __restrict cli_buffer, char *psI
|
Line 1520 cliRun(linebuffer_t * __restrict cli_buffer, char *psI
|
| (*app = strsep(&s, " \t")); *app ? app++ : app); |
(*app = strsep(&s, " \t")); *app ? app++ : app); |
| |
|
| // exec_cmd ... |
// exec_cmd ... |
| 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))) |
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; |
| else |
|
| i++; |
|
| } |
} |
| |
|
| if (!cmd) { |
if (!cmd) { |
|
Line 1538 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
Line 1559 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
| { |
{ |
| char *line; |
char *line; |
| int ret = RETCODE_OK; |
int ret = RETCODE_OK; |
| |
struct termios t; |
| |
|
| /* --- main body of CLI --- */ |
/* --- main body of CLI --- */ |
| cliInitLine(cli_buffer); | cliSetLine(cli_buffer, &t); |
| |
|
| if (cli_loadHistory(cli_buffer, csHistFile) == RETCODE_ERR) |
if (cli_loadHistory(cli_buffer, csHistFile) == RETCODE_ERR) |
| return RETCODE_ERR; |
return RETCODE_ERR; |
|
Line 1558 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
Line 1580 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
| cli_freeLine(cli_buffer); |
cli_freeLine(cli_buffer); |
| cli_resetHistory(cli_buffer); |
cli_resetHistory(cli_buffer); |
| e_free(line); |
e_free(line); |
| } while (cli_buffer->line_kill || ret < 1); | } while (!cli_buffer->line_kill); |
| |
|
| cli_saveHistory(cli_buffer, csHistFile, HISTORY_LINES); |
cli_saveHistory(cli_buffer, csHistFile, HISTORY_LINES); |
| |
|
| |
/* --- restore tty --- */ |
| |
cliResetLine(cli_buffer, &t); |
| |
|
| return ret; |
return ret; |
| } |
} |