diff options
Diffstat (limited to 'cmd-line-utils/libedit/common.c')
-rw-r--r-- | cmd-line-utils/libedit/common.c | 165 |
1 files changed, 69 insertions, 96 deletions
diff --git a/cmd-line-utils/libedit/common.c b/cmd-line-utils/libedit/common.c index 9ac6af9ac1b..f290057568a 100644 --- a/cmd-line-utils/libedit/common.c +++ b/cmd-line-utils/libedit/common.c @@ -1,4 +1,4 @@ -/* $NetBSD: common.c,v 1.10 2001/01/10 07:45:41 jdolecek Exp $ */ +/* $NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -36,12 +36,18 @@ * SUCH DAMAGE. */ -#include "compat.h" +#include "config.h" +#if !defined(lint) && !defined(SCCSID) +#if 0 +static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: common.c,v 1.14 2002/11/20 16:50:08 christos Exp $"); +#endif +#endif /* not lint && not SCCSID */ /* * common.c: Common Editor functions */ -#include "sys.h" #include "el.h" /* ed_end_of_file(): @@ -66,7 +72,7 @@ ed_end_of_file(EditLine *el, int c __attribute__((unused))) protected el_action_t ed_insert(EditLine *el, int c) { - int i; + int count = el->el_state.argument; if (c == '\0') return (CC_ERROR); @@ -74,42 +80,28 @@ ed_insert(EditLine *el, int c) if (el->el_line.lastchar + el->el_state.argument >= el->el_line.limit) { /* end of buffer space, try to allocate more */ - if (!ch_enlargebufs(el, (size_t) el->el_state.argument)) + if (!ch_enlargebufs(el, (size_t) count)) return CC_ERROR; /* error allocating more */ } - if (el->el_state.argument == 1) { - if (el->el_state.inputmode != MODE_INSERT) { - el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = - *el->el_line.cursor; - el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = - '\0'; - c_delafter(el, 1); - } - c_insert(el, 1); + if (count == 1) { + if (el->el_state.inputmode == MODE_INSERT + || el->el_line.cursor >= el->el_line.lastchar) + c_insert(el, 1); *el->el_line.cursor++ = c; - el->el_state.doingarg = 0; /* just in case */ re_fastaddc(el); /* fast refresh for one char. */ } else { - if (el->el_state.inputmode != MODE_INSERT) { - for (i = 0; i < el->el_state.argument; i++) - el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = - el->el_line.cursor[i]; - - el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = - '\0'; - c_delafter(el, el->el_state.argument); - } - c_insert(el, el->el_state.argument); + if (el->el_state.inputmode != MODE_REPLACE_1) + c_insert(el, el->el_state.argument); - while (el->el_state.argument--) + while (count-- && el->el_line.cursor < el->el_line.lastchar) *el->el_line.cursor++ = c; re_refresh(el); } if (el->el_state.inputmode == MODE_REPLACE_1) - (void) vi_command_mode(el, 0); + return vi_command_mode(el, 0); return (CC_NORM); } @@ -229,7 +221,7 @@ ed_move_to_end(EditLine *el, int c __attribute__((unused))) #ifdef VI_MOVE el->el_line.cursor--; #endif - if (el->el_chared.c_vcmd.action & DELETE) { + if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } @@ -253,7 +245,7 @@ ed_move_to_beg(EditLine *el, int c __attribute__((unused))) /* We want FIRST non space character */ while (isspace((unsigned char) *el->el_line.cursor)) el->el_line.cursor++; - if (el->el_chared.c_vcmd.action & DELETE) { + if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } @@ -295,16 +287,20 @@ protected el_action_t /*ARGSUSED*/ ed_next_char(EditLine *el, int c __attribute__((unused))) { + char *lim = el->el_line.lastchar; - if (el->el_line.cursor >= el->el_line.lastchar) + if (el->el_line.cursor >= lim || + (el->el_line.cursor == lim - 1 && + el->el_map.type == MAP_VI && + el->el_chared.c_vcmd.action == NOP)) return (CC_ERROR); el->el_line.cursor += el->el_state.argument; - if (el->el_line.cursor > el->el_line.lastchar) - el->el_line.cursor = el->el_line.lastchar; + if (el->el_line.cursor > lim) + el->el_line.cursor = lim; if (el->el_map.type == MAP_VI) - if (el->el_chared.c_vcmd.action & DELETE) { + if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } @@ -330,7 +326,7 @@ ed_prev_word(EditLine *el, int c __attribute__((unused))) ce__isword); if (el->el_map.type == MAP_VI) - if (el->el_chared.c_vcmd.action & DELETE) { + if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } @@ -353,7 +349,7 @@ ed_prev_char(EditLine *el, int c __attribute__((unused))) el->el_line.cursor = el->el_line.buffer; if (el->el_map.type == MAP_VI) - if (el->el_chared.c_vcmd.action & DELETE) { + if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); return (CC_REFRESH); } @@ -405,25 +401,9 @@ ed_digit(EditLine *el, int c) (el->el_state.argument * 10) + (c - '0'); } return (CC_ARGHACK); - } else { - if (el->el_line.lastchar + 1 >= el->el_line.limit) { - if (!ch_enlargebufs(el, 1)) - return (CC_ERROR); - } - - if (el->el_state.inputmode != MODE_INSERT) { - el->el_chared.c_undo.buf[el->el_chared.c_undo.isize++] = - *el->el_line.cursor; - el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] = - '\0'; - c_delafter(el, 1); - } - c_insert(el, 1); - *el->el_line.cursor++ = c; - el->el_state.doingarg = 0; - re_fastaddc(el); } - return (CC_NORM); + + return ed_insert(el, c); } @@ -457,12 +437,11 @@ ed_argument_digit(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_unassigned(EditLine *el, int c __attribute__((unused))) +ed_unassigned(EditLine *el __attribute__((unused)), + int c __attribute__((unused))) { - term_beep(el); - term__flush(); - return (CC_NORM); + return (CC_ERROR); } @@ -490,7 +469,7 @@ ed_tty_sigint(EditLine *el __attribute__((unused)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_dsusp(EditLine *el __attribute__((unused)), +ed_tty_dsusp(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -504,7 +483,7 @@ ed_tty_dsusp(EditLine *el __attribute__((unused)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_flush_output(EditLine *el __attribute__((unused)), +ed_tty_flush_output(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -518,7 +497,7 @@ ed_tty_flush_output(EditLine *el __attribute__((unused)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigquit(EditLine *el __attribute__((unused)), +ed_tty_sigquit(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -532,7 +511,7 @@ ed_tty_sigquit(EditLine *el __attribute__((unused)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigtstp(EditLine *el __attribute__((unused)), +ed_tty_sigtstp(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -546,7 +525,7 @@ ed_tty_sigtstp(EditLine *el __attribute__((unused)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_stop_output(EditLine *el __attribute__((unused)), +ed_tty_stop_output(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -560,7 +539,7 @@ ed_tty_stop_output(EditLine *el __attribute__((unused)), */ protected el_action_t /*ARGSUSED*/ -ed_tty_start_output(EditLine *el __attribute__((unused)), +ed_tty_start_output(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -580,8 +559,6 @@ ed_newline(EditLine *el, int c __attribute__((unused))) re_goto_bottom(el); *el->el_line.lastchar++ = '\n'; *el->el_line.lastchar = '\0'; - if (el->el_map.type == MAP_VI) - el->el_chared.c_vcmd.ins = el->el_line.buffer; return (CC_NEWLINE); } @@ -627,7 +604,7 @@ ed_clear_screen(EditLine *el, int c __attribute__((unused))) */ protected el_action_t /*ARGSUSED*/ -ed_redisplay(EditLine *el __attribute__((unused)), +ed_redisplay(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -655,7 +632,7 @@ ed_start_over(EditLine *el, int c __attribute__((unused))) */ protected el_action_t /*ARGSUSED*/ -ed_sequence_lead_in(EditLine *el __attribute__((unused)), +ed_sequence_lead_in(EditLine *el __attribute__((unused)), int c __attribute__((unused))) { @@ -672,8 +649,9 @@ protected el_action_t ed_prev_history(EditLine *el, int c __attribute__((unused))) { char beep = 0; + int sv_event = el->el_history.eventno; - el->el_chared.c_undo.action = NOP; + el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) { /* save the current buffer @@ -686,15 +664,17 @@ ed_prev_history(EditLine *el, int c __attribute__((unused))) el->el_history.eventno += el->el_state.argument; if (hist_get(el) == CC_ERROR) { + if (el->el_map.type == MAP_VI) { + el->el_history.eventno = sv_event; + return CC_ERROR; + } beep = 1; /* el->el_history.eventno was fixed by first call */ (void) hist_get(el); } - re_refresh(el); if (beep) - return (CC_ERROR); - else - return (CC_NORM); /* was CC_UP_HIST */ + return CC_REFRESH_BEEP; + return CC_REFRESH; } @@ -706,17 +686,22 @@ protected el_action_t /*ARGSUSED*/ ed_next_history(EditLine *el, int c __attribute__((unused))) { + el_action_t beep = CC_REFRESH, rval; - el->el_chared.c_undo.action = NOP; + el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ el->el_history.eventno -= el->el_state.argument; if (el->el_history.eventno < 0) { el->el_history.eventno = 0; - return (CC_ERROR);/* make it beep */ + beep = CC_REFRESH_BEEP; } - return (hist_get(el)); + rval = hist_get(el); + if (rval == CC_REFRESH) + return beep; + return rval; + } @@ -733,7 +718,7 @@ ed_search_prev_history(EditLine *el, int c __attribute__((unused))) bool_t found = 0; el->el_chared.c_vcmd.action = NOP; - el->el_chared.c_undo.action = NOP; + el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno < 0) { #ifdef DEBUG_EDIT @@ -801,7 +786,7 @@ ed_search_next_history(EditLine *el, int c __attribute__((unused))) bool_t found = 0; el->el_chared.c_vcmd.action = NOP; - el->el_chared.c_undo.action = NOP; + el->el_chared.c_undo.len = -1; *el->el_line.lastchar = '\0'; /* just in case */ if (el->el_history.eventno == 0) @@ -930,25 +915,13 @@ ed_command(EditLine *el, int c __attribute__((unused))) char tmpbuf[EL_BUFSIZ]; int tmplen; - el->el_line.buffer[0] = '\0'; - el->el_line.lastchar = el->el_line.buffer; - el->el_line.cursor = el->el_line.buffer; - - c_insert(el, 3); /* prompt + ": " */ - *el->el_line.cursor++ = '\n'; - *el->el_line.cursor++ = ':'; - *el->el_line.cursor++ = ' '; - re_refresh(el); + tmplen = c_gets(el, tmpbuf, "\n: "); + term__putc('\n'); - tmplen = c_gets(el, tmpbuf); - tmpbuf[tmplen] = '\0'; - - el->el_line.buffer[0] = '\0'; - el->el_line.lastchar = el->el_line.buffer; - el->el_line.cursor = el->el_line.buffer; + if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1) + term_beep(el); - if (parse_line(el, tmpbuf) == -1) - return (CC_ERROR); - else - return (CC_REFRESH); + el->el_map.current = el->el_map.key; + re_clear_display(el); + return CC_REFRESH; } |