version 1.8, 2000/02/28 17:41:04 |
version 1.9, 2000/09/04 22:06:28 |
Line 57 __RCSID("$NetBSD$"); |
|
Line 57 __RCSID("$NetBSD$"); |
|
* Handle state for the vi undo command |
* Handle state for the vi undo command |
*/ |
*/ |
protected void |
protected void |
cv_undo(el, action, size, ptr) |
cv_undo(EditLine *el,int action, size_t size, char *ptr) |
EditLine *el; |
{ |
int action; |
c_undo_t *vu = &el->el_chared.c_undo; |
size_t size; |
vu->action = action; |
char *ptr; |
vu->ptr = ptr; |
{ |
vu->isize = size; |
c_undo_t *vu = &el->el_chared.c_undo; |
(void) memcpy(vu->buf, vu->ptr, size); |
vu->action = action; |
|
vu->ptr = ptr; |
|
vu->isize = size; |
|
(void) memcpy(vu->buf, vu->ptr, size); |
|
#ifdef DEBUG_UNDO |
#ifdef DEBUG_UNDO |
(void) fprintf(el->el_errfile, "Undo buffer \"%s\" size = +%d -%d\n", |
(void) fprintf(el->el_errfile, "Undo buffer \"%s\" size = +%d -%d\n", |
vu->ptr, vu->isize, vu->dsize); |
vu->ptr, vu->isize, vu->dsize); |
#endif |
#endif |
} |
} |
|
|
Line 79 cv_undo(el, action, size, ptr) |
|
Line 75 cv_undo(el, action, size, ptr) |
|
* Insert num characters |
* Insert num characters |
*/ |
*/ |
protected void |
protected void |
c_insert(el, num) |
c_insert(EditLine *el, int num) |
EditLine *el; |
{ |
int num; |
char *cp; |
{ |
|
char *cp; |
if (el->el_line.lastchar + num >= el->el_line.limit) |
|
return; /* can't go past end of buffer */ |
if (el->el_line.lastchar + num >= el->el_line.limit) |
|
return; /* can't go past end of buffer */ |
if (el->el_line.cursor < el->el_line.lastchar) { |
|
/* if I must move chars */ |
if (el->el_line.cursor < el->el_line.lastchar) { |
for (cp = el->el_line.lastchar; cp >= el->el_line.cursor; cp--) |
/* if I must move chars */ |
cp[num] = *cp; |
for (cp = el->el_line.lastchar; cp >= el->el_line.cursor; cp--) |
} |
cp[num] = *cp; |
el->el_line.lastchar += num; |
} |
} |
el->el_line.lastchar += num; |
|
} /* end c_insert */ |
|
|
|
|
|
/* c_delafter(): |
/* c_delafter(): |
* Delete num characters after the cursor |
* Delete num characters after the cursor |
*/ |
*/ |
protected void |
protected void |
c_delafter(el, num) |
c_delafter(EditLine *el, int num) |
EditLine *el; |
|
int num; |
|
{ |
{ |
|
|
if (el->el_line.cursor + num > el->el_line.lastchar) |
if (el->el_line.cursor + num > el->el_line.lastchar) |
num = el->el_line.lastchar - el->el_line.cursor; |
num = el->el_line.lastchar - el->el_line.cursor; |
|
|
if (num > 0) { |
if (num > 0) { |
char *cp; |
char *cp; |
|
|
if (el->el_map.current != el->el_map.emacs) |
if (el->el_map.current != el->el_map.emacs) |
cv_undo(el, INSERT, (size_t)num, el->el_line.cursor); |
cv_undo(el, INSERT, (size_t)num, el->el_line.cursor); |
|
|
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++) |
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++) |
*cp = cp[num]; |
*cp = cp[num]; |
|
|
el->el_line.lastchar -= num; |
el->el_line.lastchar -= num; |
} |
} |
} |
} |
|
|
|
|
Line 127 c_delafter(el, num) |
|
Line 119 c_delafter(el, num) |
|
* Delete num characters before the cursor |
* Delete num characters before the cursor |
*/ |
*/ |
protected void |
protected void |
c_delbefore(el, num) |
c_delbefore(EditLine *el, int num) |
EditLine *el; |
|
int num; |
|
{ |
{ |
|
|
if (el->el_line.cursor - num < el->el_line.buffer) |
if (el->el_line.cursor - num < el->el_line.buffer) |
num = el->el_line.cursor - el->el_line.buffer; |
num = el->el_line.cursor - el->el_line.buffer; |
|
|
if (num > 0) { |
if (num > 0) { |
char *cp; |
char *cp; |
|
|
if (el->el_map.current != el->el_map.emacs) |
if (el->el_map.current != el->el_map.emacs) |
cv_undo(el, INSERT, (size_t)num, el->el_line.cursor - num); |
cv_undo(el, INSERT, (size_t)num, |
|
el->el_line.cursor - num); |
|
|
for (cp = el->el_line.cursor - num; cp <= el->el_line.lastchar; cp++) |
for (cp = el->el_line.cursor - num; |
*cp = cp[num]; |
cp <= el->el_line.lastchar; |
|
cp++) |
|
*cp = cp[num]; |
|
|
el->el_line.lastchar -= num; |
el->el_line.lastchar -= num; |
} |
} |
} |
} |
|
|
|
|
Line 153 c_delbefore(el, num) |
|
Line 146 c_delbefore(el, num) |
|
* Return if p is part of a word according to emacs |
* Return if p is part of a word according to emacs |
*/ |
*/ |
protected int |
protected int |
ce__isword(p) |
ce__isword(int p) |
int p; |
|
{ |
{ |
return isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL; |
return (isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL); |
} |
} |
|
|
|
|
|
|
* Return if p is part of a word according to vi |
* Return if p is part of a word according to vi |
*/ |
*/ |
protected int |
protected int |
cv__isword(p) |
cv__isword(int p) |
int p; |
|
{ |
{ |
return !isspace(p); |
return (!isspace(p)); |
} |
} |
|
|
|
|
|
|
* Find the previous word |
* Find the previous word |
*/ |
*/ |
protected char * |
protected char * |
c__prev_word(p, low, n, wtest) |
c__prev_word(char *p, char *low, int n, int (*wtest)(int)) |
char *p, *low; |
{ |
int n; |
p--; |
int (*wtest) __P((int)); |
|
{ |
while (n--) { |
p--; |
while ((p >= low) && !(*wtest)((unsigned char) *p)) |
|
p--; |
while (n--) { |
while ((p >= low) && (*wtest)((unsigned char) *p)) |
while ((p >= low) && !(*wtest)((unsigned char) *p)) |
p--; |
p--; |
} |
while ((p >= low) && (*wtest)((unsigned char) *p)) |
|
p--; |
/* cp now points to one character before the word */ |
} |
p++; |
|
if (p < low) |
/* cp now points to one character before the word */ |
p = low; |
p++; |
/* cp now points where we want it */ |
if (p < low) |
return (p); |
p = low; |
|
/* cp now points where we want it */ |
|
return p; |
|
} |
} |
|
|
|
|
Line 202 c__prev_word(p, low, n, wtest) |
|
Line 190 c__prev_word(p, low, n, wtest) |
|
* Find the next word |
* Find the next word |
*/ |
*/ |
protected char * |
protected char * |
c__next_word(p, high, n, wtest) |
c__next_word(char *p, char *high, int n, int (*wtest)(int)) |
char *p, *high; |
{ |
int n; |
while (n--) { |
int (*wtest) __P((int)); |
while ((p < high) && !(*wtest)((unsigned char) *p)) |
{ |
p++; |
while (n--) { |
while ((p < high) && (*wtest)((unsigned char) *p)) |
while ((p < high) && !(*wtest)((unsigned char) *p)) |
p++; |
p++; |
} |
while ((p < high) && (*wtest)((unsigned char) *p)) |
if (p > high) |
p++; |
p = high; |
} |
/* p now points where we want it */ |
if (p > high) |
return (p); |
p = high; |
|
/* p now points where we want it */ |
|
return p; |
|
} |
} |
|
|
/* cv_next_word(): |
/* cv_next_word(): |
* Find the next word vi style |
* Find the next word vi style |
*/ |
*/ |
protected char * |
protected char * |
cv_next_word(el, p, high, n, wtest) |
cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int)) |
EditLine *el; |
{ |
char *p, *high; |
int test; |
int n; |
|
int (*wtest) __P((int)); |
|
{ |
|
int test; |
|
|
|
while (n--) { |
|
test = (*wtest)((unsigned char) *p); |
|
while ((p < high) && (*wtest)((unsigned char) *p) == test) |
|
p++; |
|
/* |
|
* vi historically deletes with cw only the word preserving the |
|
* trailing whitespace! This is not what 'w' does.. |
|
*/ |
|
if (el->el_chared.c_vcmd.action != (DELETE|INSERT)) |
|
while ((p < high) && isspace((unsigned char) *p)) |
|
p++; |
|
} |
|
|
|
/* p now points where we want it */ |
while (n--) { |
if (p > high) |
test = (*wtest)((unsigned char) *p); |
return high; |
while ((p < high) && (*wtest)((unsigned char) *p) == test) |
else |
p++; |
return p; |
/* |
|
* vi historically deletes with cw only the word preserving the |
|
* trailing whitespace! This is not what 'w' does.. |
|
*/ |
|
if (el->el_chared.c_vcmd.action != (DELETE|INSERT)) |
|
while ((p < high) && isspace((unsigned char) *p)) |
|
p++; |
|
} |
|
|
|
/* p now points where we want it */ |
|
if (p > high) |
|
return (high); |
|
else |
|
return (p); |
} |
} |
|
|
|
|
Line 256 cv_next_word(el, p, high, n, wtest) |
|
Line 237 cv_next_word(el, p, high, n, wtest) |
|
* Find the previous word vi style |
* Find the previous word vi style |
*/ |
*/ |
protected char * |
protected char * |
cv_prev_word(el, p, low, n, wtest) |
cv_prev_word(EditLine *el, char *p, char *low, int n, int (*wtest)(int)) |
EditLine *el; |
|
char *p, *low; |
|
int n; |
|
int (*wtest) __P((int)); |
|
{ |
{ |
int test; |
int test; |
|
|
while (n--) { |
while (n--) { |
p--; |
|
/* |
|
* vi historically deletes with cb only the word preserving the |
|
* leading whitespace! This is not what 'b' does.. |
|
*/ |
|
if (el->el_chared.c_vcmd.action != (DELETE|INSERT)) |
|
while ((p > low) && isspace((unsigned char) *p)) |
|
p--; |
p--; |
test = (*wtest)((unsigned char) *p); |
/* |
while ((p >= low) && (*wtest)((unsigned char) *p) == test) |
* vi historically deletes with cb only the word preserving the |
p--; |
* leading whitespace! This is not what 'b' does.. |
p++; |
*/ |
while (isspace((unsigned char) *p)) |
if (el->el_chared.c_vcmd.action != (DELETE|INSERT)) |
|
while ((p > low) && isspace((unsigned char) *p)) |
|
p--; |
|
test = (*wtest)((unsigned char) *p); |
|
while ((p >= low) && (*wtest)((unsigned char) *p) == test) |
|
p--; |
p++; |
p++; |
} |
while (isspace((unsigned char) *p)) |
|
p++; |
|
} |
|
|
/* p now points where we want it */ |
/* p now points where we want it */ |
if (p < low) |
if (p < low) |
return low; |
return (low); |
else |
else |
return p; |
return (p); |
} |
} |
|
|
|
|
Line 296 cv_prev_word(el, p, low, n, wtest) |
|
Line 273 cv_prev_word(el, p, low, n, wtest) |
|
* Return p pointing to last char used. |
* Return p pointing to last char used. |
*/ |
*/ |
protected char * |
protected char * |
c__number(p, num, dval) |
c__number( |
char *p; /* character position */ |
char *p, /* character position */ |
int *num; /* Return value */ |
int *num, /* Return value */ |
int dval; /* dval is the number to subtract from like $-3 */ |
int dval) /* dval is the number to subtract from like $-3 */ |
{ |
{ |
int i; |
int i; |
int sign = 1; |
int sign = 1; |
|
|
if (*++p == '^') { |
if (*++p == '^') { |
*num = 1; |
*num = 1; |
return p; |
return (p); |
} |
} |
if (*p == '$') { |
if (*p == '$') { |
if (*++p != '-') { |
if (*++p != '-') { |
*num = 0x7fffffff; /* Handle $ */ |
*num = 0x7fffffff; /* Handle $ */ |
return --p; |
return (--p); |
} |
} |
sign = -1; /* Handle $- */ |
sign = -1; /* Handle $- */ |
++p; |
++p; |
} |
} |
for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0') |
for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0') |
continue; |
continue; |
*num = (sign < 0 ? dval - i : i); |
*num = (sign < 0 ? dval - i : i); |
return --p; |
return (--p); |
} |
} |
#endif |
#endif |
|
|
Line 327 c__number(p, num, dval) |
|
Line 304 c__number(p, num, dval) |
|
* Finish vi delete action |
* Finish vi delete action |
*/ |
*/ |
protected void |
protected void |
cv_delfini(el) |
cv_delfini(EditLine *el) |
EditLine *el; |
|
{ |
{ |
int size; |
int size; |
int oaction; |
int oaction; |
|
|
if (el->el_chared.c_vcmd.action & INSERT) |
if (el->el_chared.c_vcmd.action & INSERT) |
el->el_map.current = el->el_map.key; |
el->el_map.current = el->el_map.key; |
|
|
oaction = el->el_chared.c_vcmd.action; |
oaction = el->el_chared.c_vcmd.action; |
el->el_chared.c_vcmd.action = NOP; |
el->el_chared.c_vcmd.action = NOP; |
|
|
if (el->el_chared.c_vcmd.pos == 0) |
if (el->el_chared.c_vcmd.pos == 0) |
return; |
return; |
|
|
|
|
if (el->el_line.cursor > el->el_chared.c_vcmd.pos) { |
if (el->el_line.cursor > el->el_chared.c_vcmd.pos) { |
size = (int) (el->el_line.cursor - el->el_chared.c_vcmd.pos); |
size = (int) (el->el_line.cursor - el->el_chared.c_vcmd.pos); |
c_delbefore(el, size); |
c_delbefore(el, size); |
el->el_line.cursor = el->el_chared.c_vcmd.pos; |
el->el_line.cursor = el->el_chared.c_vcmd.pos; |
re_refresh_cursor(el); |
re_refresh_cursor(el); |
} |
} else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) { |
else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) { |
size = (int)(el->el_chared.c_vcmd.pos - el->el_line.cursor); |
size = (int)(el->el_chared.c_vcmd.pos - el->el_line.cursor); |
c_delafter(el, size); |
c_delafter(el, size); |
} else { |
} |
size = 1; |
else { |
c_delafter(el, size); |
size = 1; |
} |
c_delafter(el, size); |
switch (oaction) { |
} |
case DELETE|INSERT: |
switch (oaction) { |
el->el_chared.c_undo.action = DELETE|INSERT; |
case DELETE|INSERT: |
break; |
el->el_chared.c_undo.action = DELETE|INSERT; |
case DELETE: |
break; |
el->el_chared.c_undo.action = INSERT; |
case DELETE: |
break; |
el->el_chared.c_undo.action = INSERT; |
case NOP: |
break; |
case INSERT: |
case NOP: |
default: |
case INSERT: |
abort(); |
default: |
break; |
abort(); |
} |
break; |
|
} |
|
|
|
|
|
el->el_chared.c_undo.ptr = el->el_line.cursor; |
el->el_chared.c_undo.ptr = el->el_line.cursor; |
el->el_chared.c_undo.dsize = size; |
el->el_chared.c_undo.dsize = size; |
} |
} |
|
|
|
|
|
|
* Go to the end of this word according to emacs |
* Go to the end of this word according to emacs |
*/ |
*/ |
protected char * |
protected char * |
ce__endword(p, high, n) |
ce__endword(char *p, char *high, int n) |
char *p, *high; |
{ |
int n; |
p++; |
{ |
|
p++; |
|
|
|
while (n--) { |
|
while ((p < high) && isspace((unsigned char) *p)) |
|
p++; |
|
while ((p < high) && !isspace((unsigned char) *p)) |
|
p++; |
|
} |
|
|
|
p--; |
while (n--) { |
return p; |
while ((p < high) && isspace((unsigned char) *p)) |
|
p++; |
|
while ((p < high) && !isspace((unsigned char) *p)) |
|
p++; |
|
} |
|
|
|
p--; |
|
return (p); |
} |
} |
#endif |
#endif |
|
|
Line 405 ce__endword(p, high, n) |
|
Line 377 ce__endword(p, high, n) |
|
* Go to the end of this word according to vi |
* Go to the end of this word according to vi |
*/ |
*/ |
protected char * |
protected char * |
cv__endword(p, high, n) |
cv__endword(char *p, char *high, int n) |
char *p, *high; |
{ |
int n; |
p++; |
{ |
|
p++; |
|
|
|
while (n--) { |
|
while ((p < high) && isspace((unsigned char) *p)) |
|
p++; |
|
|
|
if (isalnum((unsigned char) *p)) |
while (n--) { |
while ((p < high) && isalnum((unsigned char) *p)) |
while ((p < high) && isspace((unsigned char) *p)) |
p++; |
p++; |
else |
|
while ((p < high) && !(isspace((unsigned char) *p) || |
if (isalnum((unsigned char) *p)) |
isalnum((unsigned char) *p))) |
while ((p < high) && isalnum((unsigned char) *p)) |
p++; |
p++; |
} |
else |
p--; |
while ((p < high) && !(isspace((unsigned char) *p) || |
return p; |
isalnum((unsigned char) *p))) |
|
p++; |
|
} |
|
p--; |
|
return (p); |
} |
} |
|
|
/* ch_init(): |
/* ch_init(): |
* Initialize the character editor |
* Initialize the character editor |
*/ |
*/ |
protected int |
protected int |
ch_init(el) |
ch_init(EditLine *el) |
EditLine *el; |
|
{ |
{ |
el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ); |
el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ); |
(void) memset(el->el_line.buffer, 0, EL_BUFSIZ); |
(void) memset(el->el_line.buffer, 0, EL_BUFSIZ); |
el->el_line.cursor = el->el_line.buffer; |
el->el_line.cursor = el->el_line.buffer; |
el->el_line.lastchar = el->el_line.buffer; |
el->el_line.lastchar = el->el_line.buffer; |
el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - 2]; |
el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - 2]; |
|
|
el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ); |
el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ); |
(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ); |
(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ); |
el->el_chared.c_undo.action = NOP; |
el->el_chared.c_undo.action = NOP; |
el->el_chared.c_undo.isize = 0; |
el->el_chared.c_undo.isize = 0; |
el->el_chared.c_undo.dsize = 0; |
el->el_chared.c_undo.dsize = 0; |
el->el_chared.c_undo.ptr = el->el_line.buffer; |
el->el_chared.c_undo.ptr = el->el_line.buffer; |
|
|
el->el_chared.c_vcmd.action = NOP; |
el->el_chared.c_vcmd.action = NOP; |
el->el_chared.c_vcmd.pos = el->el_line.buffer; |
el->el_chared.c_vcmd.pos = el->el_line.buffer; |
el->el_chared.c_vcmd.ins = el->el_line.buffer; |
el->el_chared.c_vcmd.ins = el->el_line.buffer; |
|
|
el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ); |
el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ); |
(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ); |
(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ); |
el->el_chared.c_kill.mark = el->el_line.buffer; |
el->el_chared.c_kill.mark = el->el_line.buffer; |
el->el_chared.c_kill.last = el->el_chared.c_kill.buf; |
el->el_chared.c_kill.last = el->el_chared.c_kill.buf; |
|
|
el->el_map.current = el->el_map.key; |
el->el_map.current = el->el_map.key; |
|
|
el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */ |
el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */ |
el->el_state.doingarg = 0; |
el->el_state.doingarg = 0; |
el->el_state.metanext = 0; |
el->el_state.metanext = 0; |
el->el_state.argument = 1; |
el->el_state.argument = 1; |
el->el_state.lastcmd = ED_UNASSIGNED; |
el->el_state.lastcmd = ED_UNASSIGNED; |
|
|
el->el_chared.c_macro.nline = NULL; |
el->el_chared.c_macro.nline = NULL; |
el->el_chared.c_macro.level = -1; |
el->el_chared.c_macro.level = -1; |
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO * |
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO * |
sizeof(char *)); |
sizeof(char *)); |
return 0; |
return (0); |
} |
} |
|
|
/* ch_reset(): |
/* ch_reset(): |
* Reset the character editor |
* Reset the character editor |
*/ |
*/ |
protected void |
protected void |
ch_reset(el) |
ch_reset(EditLine *el) |
EditLine *el; |
|
{ |
{ |
el->el_line.cursor = el->el_line.buffer; |
el->el_line.cursor = el->el_line.buffer; |
el->el_line.lastchar = el->el_line.buffer; |
el->el_line.lastchar = el->el_line.buffer; |
|
|
el->el_chared.c_undo.action = NOP; |
el->el_chared.c_undo.action = NOP; |
el->el_chared.c_undo.isize = 0; |
el->el_chared.c_undo.isize = 0; |
el->el_chared.c_undo.dsize = 0; |
el->el_chared.c_undo.dsize = 0; |
el->el_chared.c_undo.ptr = el->el_line.buffer; |
el->el_chared.c_undo.ptr = el->el_line.buffer; |
|
|
el->el_chared.c_vcmd.action = NOP; |
el->el_chared.c_vcmd.action = NOP; |
el->el_chared.c_vcmd.pos = el->el_line.buffer; |
el->el_chared.c_vcmd.pos = el->el_line.buffer; |
el->el_chared.c_vcmd.ins = el->el_line.buffer; |
el->el_chared.c_vcmd.ins = el->el_line.buffer; |
|
|
el->el_chared.c_kill.mark = el->el_line.buffer; |
el->el_chared.c_kill.mark = el->el_line.buffer; |
|
|
el->el_map.current = el->el_map.key; |
el->el_map.current = el->el_map.key; |
|
|
el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */ |
el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */ |
el->el_state.doingarg = 0; |
el->el_state.doingarg = 0; |
el->el_state.metanext = 0; |
el->el_state.metanext = 0; |
el->el_state.argument = 1; |
el->el_state.argument = 1; |
el->el_state.lastcmd = ED_UNASSIGNED; |
el->el_state.lastcmd = ED_UNASSIGNED; |
|
|
el->el_chared.c_macro.level = -1; |
el->el_chared.c_macro.level = -1; |
|
|
el->el_history.eventno = 0; |
el->el_history.eventno = 0; |
} |
} |
|
|
|
|
|
|
* Free the data structures used by the editor |
* Free the data structures used by the editor |
*/ |
*/ |
protected void |
protected void |
ch_end(el) |
ch_end(EditLine *el) |
EditLine *el; |
|
{ |
{ |
el_free((ptr_t) el->el_line.buffer); |
el_free((ptr_t) el->el_line.buffer); |
el->el_line.buffer = NULL; |
el->el_line.buffer = NULL; |
el->el_line.limit = NULL; |
el->el_line.limit = NULL; |
el_free((ptr_t) el->el_chared.c_undo.buf); |
el_free((ptr_t) el->el_chared.c_undo.buf); |
el->el_chared.c_undo.buf = NULL; |
el->el_chared.c_undo.buf = NULL; |
el_free((ptr_t) el->el_chared.c_kill.buf); |
el_free((ptr_t) el->el_chared.c_kill.buf); |
el->el_chared.c_kill.buf = NULL; |
el->el_chared.c_kill.buf = NULL; |
el_free((ptr_t) el->el_chared.c_macro.macro); |
el_free((ptr_t) el->el_chared.c_macro.macro); |
el->el_chared.c_macro.macro = NULL; |
el->el_chared.c_macro.macro = NULL; |
ch_reset(el); |
ch_reset(el); |
} |
} |
|
|
|
|
|
|
* Insert string at cursorI |
* Insert string at cursorI |
*/ |
*/ |
public int |
public int |
el_insertstr(el, s) |
el_insertstr(EditLine *el, const char *s) |
EditLine *el; |
{ |
const char *s; |
int len; |
{ |
|
int len; |
if ((len = strlen(s)) == 0) |
|
return (-1); |
if ((len = strlen(s)) == 0) |
if (el->el_line.lastchar + len >= el->el_line.limit) |
return -1; |
return (-1); |
if (el->el_line.lastchar + len >= el->el_line.limit) |
|
return -1; |
c_insert(el, len); |
|
while (*s) |
c_insert(el, len); |
*el->el_line.cursor++ = *s++; |
while (*s) |
return (0); |
*el->el_line.cursor++ = *s++; |
|
return 0; |
|
} |
} |
|
|
|
|
Line 552 el_insertstr(el, s) |
|
Line 517 el_insertstr(el, s) |
|
* Delete num characters before the cursor |
* Delete num characters before the cursor |
*/ |
*/ |
public void |
public void |
el_deletestr(el, n) |
el_deletestr(EditLine *el, int n) |
EditLine *el; |
{ |
int n; |
if (n <= 0) |
{ |
return; |
if (n <= 0) |
|
return; |
if (el->el_line.cursor < &el->el_line.buffer[n]) |
|
return; |
if (el->el_line.cursor < &el->el_line.buffer[n]) |
|
return; |
c_delbefore(el, n); /* delete before dot */ |
|
el->el_line.cursor -= n; |
c_delbefore(el, n); /* delete before dot */ |
if (el->el_line.cursor < el->el_line.buffer) |
el->el_line.cursor -= n; |
el->el_line.cursor = el->el_line.buffer; |
if (el->el_line.cursor < el->el_line.buffer) |
|
el->el_line.cursor = el->el_line.buffer; |
|
} |
} |
|
|
/* c_gets(): |
/* c_gets(): |
* Get a string |
* Get a string |
*/ |
*/ |
protected int |
protected int |
c_gets(el, buf) |
c_gets(EditLine *el, char *buf) |
EditLine *el; |
{ |
char *buf; |
char ch; |
{ |
int len = 0; |
char ch; |
|
int len = 0; |
|
|
|
for (ch = 0; ch == 0;) { |
|
if (el_getc(el, &ch) != 1) |
|
return ed_end_of_file(el, 0); |
|
switch (ch) { |
|
case 0010: /* Delete and backspace */ |
|
case 0177: |
|
if (len > 1) { |
|
*el->el_line.cursor-- = '\0'; |
|
el->el_line.lastchar = el->el_line.cursor; |
|
buf[len--] = '\0'; |
|
} |
|
else { |
|
el->el_line.buffer[0] = '\0'; |
|
el->el_line.lastchar = el->el_line.buffer; |
|
el->el_line.cursor = el->el_line.buffer; |
|
return CC_REFRESH; |
|
} |
|
re_refresh(el); |
|
ch = 0; |
|
break; |
|
|
|
case 0033: /* ESC */ |
|
case '\r': /* Newline */ |
|
case '\n': |
|
break; |
|
|
|
default: |
for (ch = 0; ch == 0;) { |
if (len >= EL_BUFSIZ) |
if (el_getc(el, &ch) != 1) |
term_beep(el); |
return (ed_end_of_file(el, 0)); |
else { |
switch (ch) { |
buf[len++] = ch; |
case 0010: /* Delete and backspace */ |
*el->el_line.cursor++ = ch; |
case 0177: |
el->el_line.lastchar = el->el_line.cursor; |
if (len > 1) { |
} |
*el->el_line.cursor-- = '\0'; |
re_refresh(el); |
el->el_line.lastchar = el->el_line.cursor; |
ch = 0; |
buf[len--] = '\0'; |
break; |
} else { |
} |
el->el_line.buffer[0] = '\0'; |
} |
el->el_line.lastchar = el->el_line.buffer; |
buf[len] = ch; |
el->el_line.cursor = el->el_line.buffer; |
return len; |
return (CC_REFRESH); |
|
} |
|
re_refresh(el); |
|
ch = 0; |
|
break; |
|
|
|
case 0033: /* ESC */ |
|
case '\r': /* Newline */ |
|
case '\n': |
|
break; |
|
|
|
default: |
|
if (len >= EL_BUFSIZ) |
|
term_beep(el); |
|
else { |
|
buf[len++] = ch; |
|
*el->el_line.cursor++ = ch; |
|
el->el_line.lastchar = el->el_line.cursor; |
|
} |
|
re_refresh(el); |
|
ch = 0; |
|
break; |
|
} |
|
} |
|
buf[len] = ch; |
|
return (len); |
} |
} |
|
|
|
|
|
|
* Return the current horizontal position of the cursor |
* Return the current horizontal position of the cursor |
*/ |
*/ |
protected int |
protected int |
c_hpos(el) |
c_hpos(EditLine *el) |
EditLine *el; |
|
{ |
{ |
char *ptr; |
char *ptr; |
|
|
/* |
/* |
* Find how many characters till the beginning of this line. |
* Find how many characters till the beginning of this line. |
*/ |
*/ |
if (el->el_line.cursor == el->el_line.buffer) |
if (el->el_line.cursor == el->el_line.buffer) |
return 0; |
return (0); |
else { |
else { |
for (ptr = el->el_line.cursor - 1; |
for (ptr = el->el_line.cursor - 1; |
ptr >= el->el_line.buffer && *ptr != '\n'; |
ptr >= el->el_line.buffer && *ptr != '\n'; |
ptr--) |
ptr--) |
continue; |
continue; |
return el->el_line.cursor - ptr - 1; |
return (el->el_line.cursor - ptr - 1); |
} |
} |
} |
} |