version 1.8, 2013/09/02 11:26:36
|
version 1.8.2.1, 2013/10/08 08:45:34
|
Line 88 clrscrEOL(linebuffer_t * __restrict buf)
|
Line 88 clrscrEOL(linebuffer_t * __restrict buf)
|
{ |
{ |
register int i; |
register int i; |
|
|
if (buf) { | if (buf && buf->line_prompt) { |
write(buf->line_out, K_CR, 1); |
write(buf->line_out, K_CR, 1); |
|
|
for (i = 0; i < buf->line_len; i++) |
for (i = 0; i < buf->line_len; i++) |
Line 100 static inline void
|
Line 100 static inline void
|
printfEOL(linebuffer_t * __restrict buf, int len, int prompt) |
printfEOL(linebuffer_t * __restrict buf, int len, int prompt) |
{ |
{ |
if (buf) { |
if (buf) { |
write(buf->line_out, K_CR, 1); | if (prompt && buf->line_prompt) { |
| write(buf->line_out, K_CR, 1); |
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); |
|
} |
|
|
write(buf->line_out, buf->line_buf, len == -1 ? buf->line_eol - buf->line_bol: len); | write(buf->line_out, buf->line_buf, len == -1 ? |
| buf->line_eol - buf->line_bol: len); |
} |
} |
} |
} |
|
|
static inline void |
static inline void |
printfCR(linebuffer_t * __restrict buf, int prompt) |
printfCR(linebuffer_t * __restrict buf, int prompt) |
{ |
{ |
if (buf) { | if (buf && 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); |
if (prompt) | |
if (prompt && buf->line_prompt) | |
write(buf->line_out, buf->line_prompt, buf->line_bol); | |
} |
} |
} |
} |
|
|
Line 422 bufComp(int idx, void * __restrict cli_buffer)
|
Line 420 bufComp(int idx, void * __restrict cli_buffer)
|
memset(szLine, 0, STRSIZ); |
memset(szLine, 0, STRSIZ); |
if (*s) { |
if (*s) { |
memset(items, 0, sizeof(char*) * MAX_PROMPT_ITEMS); |
memset(items, 0, sizeof(char*) * MAX_PROMPT_ITEMS); |
for (app = items, i = 0; app < items + MAX_PROMPT_ITEMS - 1 && (*app = strsep(&s, " \t")); | for (app = items, i = 0; app < items + MAX_PROMPT_ITEMS - 1 && |
| (*app = strsep(&s, " \t")); |
*app ? i++ : i, *app ? app++ : app); |
*app ? i++ : i, *app ? app++ : app); |
|
|
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 == buf->line_level && |
!strncmp(cmd->cmd_name, items[0], strlen(items[0]))) { | !strncmp(cmd->cmd_name, items[0], |
if (strncmp(cmd->cmd_name, CLI_CMD_SEP, strlen(CLI_CMD_SEP))) { | strlen(items[0]))) { |
| if (strncmp(cmd->cmd_name, CLI_CMD_SEP, |
| strlen(CLI_CMD_SEP))) { |
j++; |
j++; |
c = cmd; |
c = cmd; |
strlcat(szLine, " ", STRSIZ); |
strlcat(szLine, " ", STRSIZ); |
Line 982 cliInit(int fin, int fout, const char *prompt)
|
Line 983 cliInit(int fin, int fout, const char *prompt)
|
} else |
} else |
cli_buffer->line_eol = cli_buffer->line_bol = |
cli_buffer->line_eol = cli_buffer->line_bol = |
strlen(cli_buffer->line_prompt); |
strlen(cli_buffer->line_prompt); |
} | } else |
| cli_buffer->line_mode = LINEMODE_OVER; |
} |
} |
cli_buffer->line_buf = e_malloc(BUFSIZ); |
cli_buffer->line_buf = e_malloc(BUFSIZ); |
if (!cli_buffer->line_buf) { |
if (!cli_buffer->line_buf) { |
Line 1021 cliInit(int fin, int fout, const char *prompt)
|
Line 1023 cliInit(int fin, int fout, const char *prompt)
|
keys[i].key_func = bufEOF; |
keys[i].key_func = bufEOF; |
if (i == *K_CTRL_M || i == *K_CTRL_J) |
if (i == *K_CTRL_M || i == *K_CTRL_J) |
keys[i].key_func = bufEOL; |
keys[i].key_func = bufEOL; |
if (i == *K_CTRL_H || i == *K_BACKSPACE) | if (cli_buffer->line_prompt && (i == *K_CTRL_H || i == *K_BACKSPACE)) |
keys[i].key_func = bufBS; |
keys[i].key_func = bufBS; |
if (i == *K_CTRL_C) | if (cli_buffer->line_prompt && i == *K_CTRL_C) |
keys[i].key_func = bufCLR; |
keys[i].key_func = bufCLR; |
if (i == *K_CTRL_A) | if (cli_buffer->line_prompt && i == *K_CTRL_A) |
keys[i].key_func = bufBEGIN; |
keys[i].key_func = bufBEGIN; |
if (i == *K_CTRL_E) | if (cli_buffer->line_prompt && i == *K_CTRL_E) |
keys[i].key_func = bufEND; |
keys[i].key_func = bufEND; |
if (i == *K_TAB) | if (cli_buffer->line_prompt && i == *K_TAB) |
keys[i].key_func = bufComp; |
keys[i].key_func = bufComp; |
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) |
keys[i].key_func = bufCHAR; |
keys[i].key_func = bufCHAR; |
if (i == '?') | if (cli_buffer->line_prompt && i == '?') |
keys[i].key_func = bufHelp; |
keys[i].key_func = bufHelp; |
} |
} |
/* alt+chars */ |
/* alt+chars */ |
Line 1131 cliInit(int fin, int fout, const char *prompt)
|
Line 1133 cliInit(int fin, int fout, const char *prompt)
|
memcpy(keys[i].key_ch, K_CTRL_F12, keys[i].key_len); |
memcpy(keys[i].key_ch, K_CTRL_F12, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_HOME - 1; |
keys[i].key_len = sizeof K_HOME - 1; |
keys[i].key_func = bufBEGIN; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufBEGIN; |
memcpy(keys[i].key_ch, K_HOME, keys[i].key_len); |
memcpy(keys[i].key_ch, K_HOME, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_END - 1; |
keys[i].key_len = sizeof K_END - 1; |
keys[i].key_func = bufEND; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufEND; |
memcpy(keys[i].key_ch, K_END, keys[i].key_len); |
memcpy(keys[i].key_ch, K_END, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_UP - 1; |
keys[i].key_len = sizeof K_UP - 1; |
keys[i].key_func = bufUP; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufUP; |
memcpy(keys[i].key_ch, K_UP, keys[i].key_len); |
memcpy(keys[i].key_ch, K_UP, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_DOWN - 1; |
keys[i].key_len = sizeof K_DOWN - 1; |
keys[i].key_func = bufDOWN; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufDOWN; |
memcpy(keys[i].key_ch, K_DOWN, keys[i].key_len); |
memcpy(keys[i].key_ch, K_DOWN, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_RIGHT - 1; |
keys[i].key_len = sizeof K_RIGHT - 1; |
keys[i].key_func = bufRIGHT; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufRIGHT; |
memcpy(keys[i].key_ch, K_RIGHT, keys[i].key_len); |
memcpy(keys[i].key_ch, K_RIGHT, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_LEFT - 1; |
keys[i].key_len = sizeof K_LEFT - 1; |
keys[i].key_func = bufLEFT; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufLEFT; |
memcpy(keys[i].key_ch, K_LEFT, keys[i].key_len); |
memcpy(keys[i].key_ch, K_LEFT, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_BTAB - 1; |
keys[i].key_len = sizeof K_BTAB - 1; |
keys[i].key_func = bufBTAB; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufBTAB; |
memcpy(keys[i].key_ch, K_BTAB, keys[i].key_len); |
memcpy(keys[i].key_ch, K_BTAB, keys[i].key_len); |
i++; |
i++; |
/* 4 bytes */ |
/* 4 bytes */ |
keys[i].key_len = sizeof K_INS - 1; |
keys[i].key_len = sizeof K_INS - 1; |
keys[i].key_func = bufMODE; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufMODE; |
memcpy(keys[i].key_ch, K_INS, keys[i].key_len); |
memcpy(keys[i].key_ch, K_INS, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_DEL - 1; |
keys[i].key_len = sizeof K_DEL - 1; |
keys[i].key_func = bufDEL; | if (cli_buffer->line_prompt) |
| keys[i].key_func = bufDEL; |
memcpy(keys[i].key_ch, K_DEL, keys[i].key_len); |
memcpy(keys[i].key_ch, K_DEL, keys[i].key_len); |
i++; |
i++; |
keys[i].key_len = sizeof K_PGUP - 1; |
keys[i].key_len = sizeof K_PGUP - 1; |
Line 1216 cliInitLine(linebuffer_t * __restrict cli_buffer)
|
Line 1227 cliInitLine(linebuffer_t * __restrict cli_buffer)
|
|
|
memset(&t, 0, sizeof t); |
memset(&t, 0, sizeof t); |
tcgetattr(cli_buffer->line_in, &t); |
tcgetattr(cli_buffer->line_in, &t); |
t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); | t.c_lflag &= ~(ICANON | ISIG | IEXTEN | ECHO | |
| ECHOCTL | ECHOE | ECHOK | ECHOKE | ECHONL | ECHOPRT); |
t.c_iflag |= IGNBRK; |
t.c_iflag |= IGNBRK; |
t.c_cc[VMIN] = 1; |
t.c_cc[VMIN] = 1; |
t.c_cc[VTIME] = 0; |
t.c_cc[VTIME] = 0; |
Line 1451 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
Line 1463 cliLoop(linebuffer_t * __restrict cli_buffer, const ch
|
|
|
if (*s) { |
if (*s) { |
memset(items, 0, sizeof(char*) * MAX_PROMPT_ITEMS); |
memset(items, 0, sizeof(char*) * MAX_PROMPT_ITEMS); |
for (app = items; app < items + MAX_PROMPT_ITEMS - 1 && (*app = strsep(&s, " \t")); | for (app = items; app < items + MAX_PROMPT_ITEMS - 1 && |
*app ? app++ : app); | (*app = strsep(&s, " \t")); *app ? app++ : app); |
|
|
// exec_cmd ... |
// exec_cmd ... |
i = 0; |
i = 0; |