version 1.1.2.2, 2010/06/03 23:29:32
|
version 1.1.2.3, 2010/06/04 09:16:59
|
Line 5
|
Line 5
|
#include <termios.h> |
#include <termios.h> |
#include <poll.h> |
#include <poll.h> |
#include <aitio.h> |
#include <aitio.h> |
|
#include <sys/types.h> |
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#include <sys/queue.h> |
#include <sys/queue.h> |
Line 36 printfEOL(linebuffer_t * __restrict buf, int len, int
|
Line 37 printfEOL(linebuffer_t * __restrict buf, int len, int
|
if (prompt && buf->line_prompt) |
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); |
|
|
// printf("buf=%s eol=%d bol=%d len=%d\n", buf->line_buf, buf->line_eol, buf->line_bol, buf->line_len); |
|
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); |
} |
} |
} |
} |
Line 70 catCh2Buf(int idx, void * __restrict buffer)
|
Line 70 catCh2Buf(int idx, void * __restrict buffer)
|
{ |
{ |
linebuffer_t *buf = buffer; |
linebuffer_t *buf = buffer; |
int pos; |
int pos; |
|
unsigned char b[BUFSIZ]; |
|
|
if (!buffer || idx < 0 || idx > MAX_BINDKEY) |
if (!buffer || idx < 0 || idx > MAX_BINDKEY) |
return RETCODE_ERR; |
return RETCODE_ERR; |
|
|
pos = buf->line_eol - buf->line_bol; |
pos = buf->line_eol - buf->line_bol; |
|
|
if (buf->line_eol == buf->line_len - 1) | if (buf->line_mode == LINEMODE_INS) |
| memmove(buf->line_buf + pos + buf->line_keys[idx].key_len, buf->line_buf + pos, |
| buf->line_len - buf->line_eol); |
| if (buf->line_mode == LINEMODE_INS || buf->line_eol == buf->line_len - 1) |
buf->line_len += buf->line_keys[idx].key_len; |
buf->line_len += buf->line_keys[idx].key_len; |
buf->line_eol += buf->line_keys[idx].key_len; |
buf->line_eol += buf->line_keys[idx].key_len; |
|
|
Line 84 catCh2Buf(int idx, void * __restrict buffer)
|
Line 88 catCh2Buf(int idx, void * __restrict buffer)
|
buf->line_buf[buf->line_len - 1] = 0; |
buf->line_buf[buf->line_len - 1] = 0; |
|
|
write(buf->line_out, buf->line_keys[idx].key_ch, buf->line_keys[idx].key_len); |
write(buf->line_out, buf->line_keys[idx].key_ch, buf->line_keys[idx].key_len); |
|
|
|
if (buf->line_mode == LINEMODE_INS) { |
|
printfCLI(buf, (const u_char*) buf->line_buf + pos + buf->line_keys[idx].key_len, |
|
buf->line_len - buf->line_eol, 0); |
|
printfEOL(buf, -1, 1); |
|
} |
return RETCODE_OK; |
return RETCODE_OK; |
} |
} |
|
|
Line 211 bufBS(int idx, void * __restrict buffer)
|
Line 221 bufBS(int idx, void * __restrict buffer)
|
|
|
buf->line_eol--; |
buf->line_eol--; |
buf->line_len--; |
buf->line_len--; |
|
memmove(buf->line_buf + buf->line_eol, buf->line_buf + buf->line_eol + 1, |
|
buf->line_len - buf->line_eol); |
|
buf->line_buf[buf->line_len - 1] = 0; |
|
|
|
printfEOL(buf, buf->line_len - 1, 1); |
|
printfEOL(buf, -1, 1); |
|
} |
|
|
|
return RETCODE_OK; |
|
} |
|
|
|
static int |
|
bufBTAB(int idx, void * __restrict buffer) |
|
{ |
|
linebuffer_t *buf = buffer; |
|
|
|
if (!buffer || idx < 0 || idx > MAX_BINDKEY) |
|
return RETCODE_ERR; |
|
|
|
if (buf->line_bol < buf->line_eol) { |
|
clrscrEOL(buf); |
|
|
|
buf->line_eol--; |
|
buf->line_len--; |
buf->line_buf[buf->line_eol - buf->line_bol] = 0; |
buf->line_buf[buf->line_eol - buf->line_bol] = 0; |
|
|
printfEOL(buf, -1, 1); |
printfEOL(buf, -1, 1); |
Line 295 bufDel(int idx, void * __restrict buffer)
|
Line 329 bufDel(int idx, void * __restrict buffer)
|
if (!buffer || idx < 0 || idx > MAX_BINDKEY) |
if (!buffer || idx < 0 || idx > MAX_BINDKEY) |
return RETCODE_ERR; |
return RETCODE_ERR; |
|
|
if (buf->line_bol < buf->line_eol) { | clrscrEOL(buf); |
clrscrEOL(buf); | |
|
|
buf->line_eol--; | buf->line_len--; |
buf->line_len--; | memmove(buf->line_buf + buf->line_eol, buf->line_buf + buf->line_eol + 1, |
buf->line_buf[buf->line_eol] = 0; | buf->line_len - buf->line_eol); |
| buf->line_buf[buf->line_len - 1] = 0; |
|
|
printfEOL(buf, -1, 1); | printfEOL(buf, buf->line_len - 1, 1); |
} | printfEOL(buf, -1, 1); |
|
|
return RETCODE_OK; |
return RETCODE_OK; |
} |
} |
Line 485 initCLI(int fin, int fout, const char *prompt)
|
Line 519 initCLI(int fin, int fout, const char *prompt)
|
keys[i].key_func = bufLEFT; |
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); |
keys[i].key_len = sizeof K_BTAB - 1; |
keys[i].key_len = sizeof K_BTAB - 1; |
keys[i].key_func = bufBS; | 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); |
// 4 bytes |
// 4 bytes |
keys[i].key_len = sizeof K_INS - 1; |
keys[i].key_len = sizeof K_INS - 1; |