diff options
Diffstat (limited to 'net/tnftp/files/libedit/common.c')
-rw-r--r-- | net/tnftp/files/libedit/common.c | 223 |
1 files changed, 103 insertions, 120 deletions
diff --git a/net/tnftp/files/libedit/common.c b/net/tnftp/files/libedit/common.c index 0fdf7cf805e..3344c3ebaa8 100644 --- a/net/tnftp/files/libedit/common.c +++ b/net/tnftp/files/libedit/common.c @@ -1,4 +1,5 @@ -/* $NetBSD: common.c,v 1.1 2004/03/11 13:01:01 grant Exp $ */ +/* NetBSD: common.c,v 1.4 2005/05/11 01:17:39 lukem Exp */ +/* from NetBSD: common.c,v 1.16 2003/08/07 16:44:30 agc Exp */ /*- * Copyright (c) 1992, 1993 @@ -15,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -39,6 +36,17 @@ #include "tnftp.h" #include "sys.h" +#if 0 +#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.4 2005/05/11 01:17:39 lukem Exp"); +#endif +#endif /* not lint && not SCCSID */ +#endif + /* * common.c: Common Editor functions */ @@ -50,7 +58,7 @@ */ protected el_action_t /*ARGSUSED*/ -ed_end_of_file(EditLine *el, int c) +ed_end_of_file(EditLine *el, int c __attribute__((__unused__))) { re_goto_bottom(el); @@ -66,7 +74,7 @@ ed_end_of_file(EditLine *el, int c) 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 +82,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); } @@ -121,7 +115,7 @@ ed_insert(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_word(EditLine *el, int c) +ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__))) { char *cp, *p, *kp; @@ -149,7 +143,7 @@ ed_delete_prev_word(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_delete_next_char(EditLine *el, int c) +ed_delete_next_char(EditLine *el, int c __attribute__((__unused__))) { #ifdef notdef /* XXX */ #define EL el->el_line @@ -200,7 +194,7 @@ ed_delete_next_char(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_kill_line(EditLine *el, int c) +ed_kill_line(EditLine *el, int c __attribute__((__unused__))) { char *kp, *cp; @@ -221,7 +215,7 @@ ed_kill_line(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_move_to_end(EditLine *el, int c) +ed_move_to_end(EditLine *el, int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.lastchar; @@ -229,7 +223,7 @@ ed_move_to_end(EditLine *el, int c) #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); } @@ -244,7 +238,7 @@ ed_move_to_end(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_move_to_beg(EditLine *el, int c) +ed_move_to_beg(EditLine *el, int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -253,7 +247,7 @@ ed_move_to_beg(EditLine *el, int c) /* 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); } @@ -293,18 +287,22 @@ ed_transpose_chars(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_next_char(EditLine *el, int c) +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); } @@ -318,7 +316,7 @@ ed_next_char(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_word(EditLine *el, int c) +ed_prev_word(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -330,7 +328,7 @@ ed_prev_word(EditLine *el, int c) 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); } @@ -344,7 +342,7 @@ ed_prev_word(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_char(EditLine *el, int c) +ed_prev_char(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor > el->el_line.buffer) { @@ -353,7 +351,7 @@ ed_prev_char(EditLine *el, int c) 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 +403,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 +439,10 @@ ed_argument_digit(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_unassigned(EditLine *el, int c) +ed_unassigned(EditLine *el, int c __attribute__((__unused__))) { - term_beep(el); - term__flush(); - return (CC_NORM); + return (CC_ERROR); } @@ -476,7 +456,8 @@ ed_unassigned(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigint(EditLine *el, int c) +ed_tty_sigint(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -489,7 +470,8 @@ ed_tty_sigint(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_dsusp(EditLine *el, int c) +ed_tty_dsusp(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -502,7 +484,8 @@ ed_tty_dsusp(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_flush_output(EditLine *el, int c) +ed_tty_flush_output(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -515,7 +498,8 @@ ed_tty_flush_output(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigquit(EditLine *el, int c) +ed_tty_sigquit(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -528,7 +512,8 @@ ed_tty_sigquit(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigtstp(EditLine *el, int c) +ed_tty_sigtstp(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -541,7 +526,8 @@ ed_tty_sigtstp(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_stop_output(EditLine *el, int c) +ed_tty_stop_output(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -554,7 +540,8 @@ ed_tty_stop_output(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_start_output(EditLine *el, int c) +ed_tty_start_output(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -567,14 +554,12 @@ ed_tty_start_output(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_newline(EditLine *el, int c) +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); } @@ -585,7 +570,7 @@ ed_newline(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_char(EditLine *el, int c) +ed_delete_prev_char(EditLine *el, int c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) @@ -605,7 +590,7 @@ ed_delete_prev_char(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_clear_screen(EditLine *el, int c) +ed_clear_screen(EditLine *el, int c __attribute__((__unused__))) { term_clear_screen(el); /* clear the whole real screen */ @@ -620,7 +605,8 @@ ed_clear_screen(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_redisplay(EditLine *el, int c) +ed_redisplay(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_REDISPLAY); @@ -633,7 +619,7 @@ ed_redisplay(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_start_over(EditLine *el, int c) +ed_start_over(EditLine *el, int c __attribute__((__unused__))) { ch_reset(el); @@ -647,7 +633,8 @@ ed_start_over(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_sequence_lead_in(EditLine *el, int c) +ed_sequence_lead_in(EditLine *el __attribute__((__unused__)), + int c __attribute__((__unused__))) { return (CC_NORM); @@ -660,11 +647,12 @@ ed_sequence_lead_in(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_history(EditLine *el, int c) +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 @@ -677,15 +665,17 @@ ed_prev_history(EditLine *el, int c) 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; } @@ -695,19 +685,24 @@ ed_prev_history(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_next_history(EditLine *el, int c) +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; + } @@ -717,14 +712,14 @@ ed_next_history(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_search_prev_history(EditLine *el, int c) +ed_search_prev_history(EditLine *el, int c __attribute__((__unused__))) { const char *hp; int h; 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 @@ -785,14 +780,14 @@ ed_search_prev_history(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_search_next_history(EditLine *el, int c) +ed_search_next_history(EditLine *el, int c __attribute__((__unused__))) { const char *hp; int h; 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) @@ -839,7 +834,7 @@ ed_search_next_history(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_line(EditLine *el, int c) +ed_prev_line(EditLine *el, int c __attribute__((__unused__))) { char *ptr; int nchars = c_hpos(el); @@ -882,7 +877,7 @@ ed_prev_line(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_next_line(EditLine *el, int c) +ed_next_line(EditLine *el, int c __attribute__((__unused__))) { char *ptr; int nchars = c_hpos(el); @@ -916,30 +911,18 @@ ed_next_line(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -ed_command(EditLine *el, int c) +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; } |