diff options
author | David E. O'Brien <obrien@FreeBSD.org> | 2001-10-01 08:41:27 +0000 |
---|---|---|
committer | David E. O'Brien <obrien@FreeBSD.org> | 2001-10-01 08:41:27 +0000 |
commit | 3c195773444850fbd9cf231761a4f76eaf863e5a (patch) | |
tree | f9436ba88ca8f8420af319b0a12dd175381b507b /lib/libedit/common.c | |
parent | c3aa3459b1000cef0734f66507785c13a7083e2a (diff) |
+ Sync with NetBSD, bringing in feature enhancements.
+ Convert to ANSI-C function definitions
+ style(9)
Submitted by: kris
Notes
Notes:
svn path=/head/; revision=84260
Diffstat (limited to 'lib/libedit/common.c')
-rw-r--r-- | lib/libedit/common.c | 1024 |
1 files changed, 491 insertions, 533 deletions
diff --git a/lib/libedit/common.c b/lib/libedit/common.c index 7493fc5b1bbc..386579caa89b 100644 --- a/lib/libedit/common.c +++ b/lib/libedit/common.c @@ -32,6 +32,8 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $NetBSD: common.c,v 1.9 2000/09/04 22:06:29 lukem Exp $ */ #include <sys/cdefs.h> @@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$"); #if !defined(lint) && !defined(SCCSID) static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint && not SCCSID */ +#include <sys/cdefs.h> +__FBSDID("$FreeBSD$"); /* * common.c: Common Editor functions @@ -52,13 +56,12 @@ static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93"; */ protected el_action_t /*ARGSUSED*/ -ed_end_of_file(el, c) - EditLine *el; - int c; +ed_end_of_file(EditLine *el, int c) { - re_goto_bottom(el); - *el->el_line.lastchar = '\0'; - return CC_EOF; + + re_goto_bottom(el); + *el->el_line.lastchar = '\0'; + return (CC_EOF); } @@ -67,58 +70,58 @@ ed_end_of_file(el, c) * Insert a character [bound to all insert keys] */ protected el_action_t -ed_insert(el, c) - EditLine *el; - int c; +ed_insert(EditLine *el, int c) { - int i; - - if (c == '\0') - return CC_ERROR; - - if (el->el_line.lastchar + el->el_state.argument >= - el->el_line.limit) - return CC_ERROR; /* end of buffer space */ + int i; - 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); - } + if (c == '\0') + return (CC_ERROR); - 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); - - while (el->el_state.argument--) - *el->el_line.cursor++ = c; - re_refresh(el); - } + 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)) + return CC_ERROR; /* error allocating more */ + } - if (el->el_state.inputmode == MODE_REPLACE_1 || el->el_state.inputmode == MODE_REPLACE) - el->el_chared.c_undo.action=CHANGE; + 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); + + *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); + + while (el->el_state.argument--) + *el->el_line.cursor++ = c; + re_refresh(el); + } - if (el->el_state.inputmode == MODE_REPLACE_1) - return vi_command_mode(el, 0); + if (el->el_state.inputmode == MODE_REPLACE_1 + || el->el_state.inputmode == MODE_REPLACE) + el->el_chared.c_undo.action=CHANGE; + + if (el->el_state.inputmode == MODE_REPLACE_1) + return (vi_command_mode(el, 0)); - return CC_NORM; + return (CC_NORM); } @@ -128,27 +131,25 @@ ed_insert(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_word(el, c) - EditLine *el; - int c; +ed_delete_prev_word(EditLine *el, int c) { - char *cp, *p, *kp; + char *cp, *p, *kp; - if (el->el_line.cursor == el->el_line.buffer) - return CC_ERROR; + if (el->el_line.cursor == el->el_line.buffer) + return (CC_ERROR); - cp = c__prev_word(el->el_line.cursor, el->el_line.buffer, - el->el_state.argument, ce__isword); + cp = c__prev_word(el->el_line.cursor, el->el_line.buffer, + el->el_state.argument, ce__isword); - for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++) - *kp++ = *p; - el->el_chared.c_kill.last = kp; + for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++) + *kp++ = *p; + el->el_chared.c_kill.last = kp; - c_delbefore(el, el->el_line.cursor - cp); /* delete before dot */ - el->el_line.cursor = cp; - if (el->el_line.cursor < el->el_line.buffer) - el->el_line.cursor = el->el_line.buffer; /* bounds check */ - return CC_REFRESH; + c_delbefore(el, el->el_line.cursor - cp); /* delete before dot */ + el->el_line.cursor = cp; + if (el->el_line.cursor < el->el_line.buffer) + el->el_line.cursor = el->el_line.buffer; /* bounds check */ + return (CC_REFRESH); } @@ -158,46 +159,48 @@ ed_delete_prev_word(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_delete_next_char(el, c) - EditLine *el; - int c; -{ -#ifdef notdef /* XXX */ -#define EL el->el_line -fprintf(stderr, "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n", - EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar, EL.lastchar, EL.limit, EL.limit); +ed_delete_next_char(EditLine *el, int c) +{ +#ifdef notdef /* XXX */ +#define EL el->el_line + (void) fprintf(el->el_errlfile, + "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n", + EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar, + EL.lastchar, EL.limit, EL.limit); #endif - if (el->el_line.cursor == el->el_line.lastchar) {/* if I'm at the end */ - if (el->el_map.type == MAP_VI) { - if (el->el_line.cursor == el->el_line.buffer) { - /* if I'm also at the beginning */ + if (el->el_line.cursor == el->el_line.lastchar) { + /* if I'm at the end */ + if (el->el_map.type == MAP_VI) { + if (el->el_line.cursor == el->el_line.buffer) { + /* if I'm also at the beginning */ #ifdef KSHVI - return CC_ERROR; + return (CC_ERROR); #else - term_overwrite(el, STReof, 4);/* then do a EOF */ - term__flush(); - return CC_EOF; + term_overwrite(el, STReof, 4); + /* then do a EOF */ + term__flush(); + return (CC_EOF); #endif - } - else { + } else { #ifdef KSHVI - el->el_line.cursor--; + el->el_line.cursor--; #else - return CC_ERROR; + return (CC_ERROR); #endif - } + } + } else { + if (el->el_line.cursor != el->el_line.buffer) + el->el_line.cursor--; + else + return (CC_ERROR); + } } - else { - if (el->el_line.cursor != el->el_line.buffer) - el->el_line.cursor--; - else - return CC_ERROR; - } - } - c_delafter(el, el->el_state.argument); /* delete after dot */ - if (el->el_line.cursor >= el->el_line.lastchar && el->el_line.cursor > el->el_line.buffer) - el->el_line.cursor = el->el_line.lastchar - 1; /* bounds check */ - return CC_REFRESH; + c_delafter(el, el->el_state.argument); /* delete after dot */ + if (el->el_line.cursor >= el->el_line.lastchar && + el->el_line.cursor > el->el_line.buffer) + /* bounds check */ + el->el_line.cursor = el->el_line.lastchar - 1; + return (CC_REFRESH); } @@ -207,19 +210,18 @@ fprintf(stderr, "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n", */ protected el_action_t /*ARGSUSED*/ -ed_kill_line(el, c) - EditLine *el; - int c; +ed_kill_line(EditLine *el, int c) { - char *kp, *cp; + char *kp, *cp; - cp = el->el_line.cursor; - kp = el->el_chared.c_kill.buf; - while (cp < el->el_line.lastchar) - *kp++ = *cp++; /* copy it */ - el->el_chared.c_kill.last = kp; - el->el_line.lastchar = el->el_line.cursor; /* zap! -- delete to end */ - return CC_REFRESH; + cp = el->el_line.cursor; + kp = el->el_chared.c_kill.buf; + while (cp < el->el_line.lastchar) + *kp++ = *cp++; /* copy it */ + el->el_chared.c_kill.last = kp; + /* zap! -- delete to end */ + el->el_line.lastchar = el->el_line.cursor; + return (CC_REFRESH); } @@ -229,21 +231,20 @@ ed_kill_line(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_move_to_end(el, c) - EditLine *el; - int c; +ed_move_to_end(EditLine *el, int c) { - el->el_line.cursor = el->el_line.lastchar; - if (el->el_map.type == MAP_VI) { + + el->el_line.cursor = el->el_line.lastchar; + if (el->el_map.type == MAP_VI) { #ifdef VI_MOVE - el->el_line.cursor--; + el->el_line.cursor--; #endif - if (el->el_chared.c_vcmd.action & DELETE) { - cv_delfini(el); - return CC_REFRESH; + if (el->el_chared.c_vcmd.action & DELETE) { + cv_delfini(el); + return (CC_REFRESH); + } } - } - return CC_CURSOR; + return (CC_CURSOR); } @@ -253,23 +254,21 @@ ed_move_to_end(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_move_to_beg(el, c) - EditLine *el; - int c; -{ - el->el_line.cursor = el->el_line.buffer; - - if (el->el_map.type == MAP_VI) { - /* 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) { - cv_delfini(el); - return CC_REFRESH; - } - } +ed_move_to_beg(EditLine *el, int c) +{ + + el->el_line.cursor = el->el_line.buffer; - return CC_CURSOR; + if (el->el_map.type == MAP_VI) { + /* 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) { + cv_delfini(el); + return (CC_REFRESH); + } + } + return (CC_CURSOR); } @@ -278,25 +277,23 @@ ed_move_to_beg(el, c) * [^T] [^T] */ protected el_action_t -ed_transpose_chars(el, c) - EditLine *el; - int c; +ed_transpose_chars(EditLine *el, int c) { - if (el->el_line.cursor < el->el_line.lastchar) { - if (el->el_line.lastchar <= &el->el_line.buffer[1]) - return CC_ERROR; - else - el->el_line.cursor++; - } - if (el->el_line.cursor > &el->el_line.buffer[1]) { - /* must have at least two chars entered */ - c = el->el_line.cursor[-2]; - el->el_line.cursor[-2] = el->el_line.cursor[-1]; - el->el_line.cursor[-1] = c; - return CC_REFRESH; - } - else - return CC_ERROR; + + if (el->el_line.cursor < el->el_line.lastchar) { + if (el->el_line.lastchar <= &el->el_line.buffer[1]) + return (CC_ERROR); + else + el->el_line.cursor++; + } + if (el->el_line.cursor > &el->el_line.buffer[1]) { + /* must have at least two chars entered */ + c = el->el_line.cursor[-2]; + el->el_line.cursor[-2] = el->el_line.cursor[-1]; + el->el_line.cursor[-1] = c; + return (CC_REFRESH); + } else + return (CC_ERROR); } @@ -306,24 +303,22 @@ ed_transpose_chars(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_next_char(el, c) - EditLine *el; - int c; +ed_next_char(EditLine *el, int c) { - if (el->el_line.cursor >= el->el_line.lastchar) - 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 >= el->el_line.lastchar) + return (CC_ERROR); - if (el->el_map.type == MAP_VI) - if (el->el_chared.c_vcmd.action & DELETE) { - cv_delfini(el); - return CC_REFRESH; - } + 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; - return CC_CURSOR; + if (el->el_map.type == MAP_VI) + if (el->el_chared.c_vcmd.action & DELETE) { + cv_delfini(el); + return (CC_REFRESH); + } + return (CC_CURSOR); } @@ -333,24 +328,23 @@ ed_next_char(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_word(el, c) - EditLine *el; - int c; +ed_prev_word(EditLine *el, int c) { - if (el->el_line.cursor == el->el_line.buffer) - return CC_ERROR; - el->el_line.cursor = c__prev_word(el->el_line.cursor, el->el_line.buffer, - el->el_state.argument, - ce__isword); + if (el->el_line.cursor == el->el_line.buffer) + return (CC_ERROR); - if (el->el_map.type == MAP_VI) - if (el->el_chared.c_vcmd.action & DELETE) { - cv_delfini(el); - return CC_REFRESH; - } + el->el_line.cursor = c__prev_word(el->el_line.cursor, + el->el_line.buffer, + el->el_state.argument, + ce__isword); - return CC_CURSOR; + if (el->el_map.type == MAP_VI) + if (el->el_chared.c_vcmd.action & DELETE) { + cv_delfini(el); + return (CC_REFRESH); + } + return (CC_CURSOR); } @@ -360,25 +354,22 @@ ed_prev_word(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_char(el, c) - EditLine *el; - int c; +ed_prev_char(EditLine *el, int c) { - if (el->el_line.cursor > el->el_line.buffer) { - el->el_line.cursor -= el->el_state.argument; - if (el->el_line.cursor < el->el_line.buffer) - el->el_line.cursor = el->el_line.buffer; - if (el->el_map.type == MAP_VI) - if (el->el_chared.c_vcmd.action & DELETE) { - cv_delfini(el); - return CC_REFRESH; - } + if (el->el_line.cursor > el->el_line.buffer) { + el->el_line.cursor -= el->el_state.argument; + if (el->el_line.cursor < el->el_line.buffer) + el->el_line.cursor = el->el_line.buffer; - return CC_CURSOR; - } - else - return CC_ERROR; + if (el->el_map.type == MAP_VI) + if (el->el_chared.c_vcmd.action & DELETE) { + cv_delfini(el); + return (CC_REFRESH); + } + return (CC_CURSOR); + } else + return (CC_ERROR); } @@ -387,21 +378,19 @@ ed_prev_char(el, c) * [^V] [^V] */ protected el_action_t -ed_quoted_insert(el, c) - EditLine *el; - int c; +ed_quoted_insert(EditLine *el, int c) { - int num; - char tc; + int num; + char tc; - tty_quotemode(el); - num = el_getc(el, &tc); - c = (unsigned char) tc; - tty_noquotemode(el); - if (num == 1) - return ed_insert(el, c); - else - return ed_end_of_file(el, 0); + tty_quotemode(el); + num = el_getc(el, &tc); + c = (unsigned char) tc; + tty_noquotemode(el); + if (num == 1) + return (ed_insert(el, c)); + else + return (ed_end_of_file(el, 0)); } @@ -409,41 +398,42 @@ ed_quoted_insert(el, c) * Adds to argument or enters a digit */ protected el_action_t -ed_digit(el, c) - EditLine *el; - int c; -{ - if (!isdigit((unsigned char) c)) - return CC_ERROR; - - if (el->el_state.doingarg) { - /* if doing an arg, add this in... */ - if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT) - el->el_state.argument = c - '0'; - else { - if (el->el_state.argument > 1000000) - return CC_ERROR; - el->el_state.argument = - (el->el_state.argument * 10) + (c - '0'); +ed_digit(EditLine *el, int c) +{ + + if (!isdigit((unsigned char) c)) + return (CC_ERROR); + + if (el->el_state.doingarg) { + /* if doing an arg, add this in... */ + if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT) + el->el_state.argument = c - '0'; + else { + if (el->el_state.argument > 1000000) + return (CC_ERROR); + el->el_state.argument = + (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_ARGHACK; - } - else { - if (el->el_line.lastchar + 1 >= el->el_line.limit) - 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 (CC_NORM); } @@ -452,23 +442,22 @@ ed_digit(el, c) * For ESC-n */ protected el_action_t -ed_argument_digit(el, c) - EditLine *el; - register int c; +ed_argument_digit(EditLine *el, int c) { - if (!isdigit((unsigned char) c)) - return CC_ERROR; - if (el->el_state.doingarg) { - if (el->el_state.argument > 1000000) - return CC_ERROR; - el->el_state.argument = (el->el_state.argument * 10) + (c - '0'); - } - else { /* else starting an argument */ - el->el_state.argument = c - '0'; - el->el_state.doingarg = 1; - } - return CC_ARGHACK; + if (!isdigit((unsigned char) c)) + return (CC_ERROR); + + if (el->el_state.doingarg) { + if (el->el_state.argument > 1000000) + return (CC_ERROR); + el->el_state.argument = (el->el_state.argument * 10) + + (c - '0'); + } else { /* else starting an argument */ + el->el_state.argument = c - '0'; + el->el_state.doingarg = 1; + } + return (CC_ARGHACK); } @@ -478,13 +467,12 @@ ed_argument_digit(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_unassigned(el, c) - EditLine *el; - int c; +ed_unassigned(EditLine *el, int c) { - term_beep(el); - term__flush(); - return CC_NORM; + + term_beep(el); + term__flush(); + return (CC_NORM); } @@ -498,11 +486,10 @@ ed_unassigned(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigint(el, c) - EditLine *el; - int c; +ed_tty_sigint(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -512,11 +499,10 @@ ed_tty_sigint(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_dsusp(el, c) - EditLine *el; - int c; +ed_tty_dsusp(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -526,11 +512,10 @@ ed_tty_dsusp(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_flush_output(el, c) - EditLine *el; - int c; +ed_tty_flush_output(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -540,11 +525,10 @@ ed_tty_flush_output(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigquit(el, c) - EditLine *el; - int c; +ed_tty_sigquit(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -554,11 +538,10 @@ ed_tty_sigquit(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_sigtstp(el, c) - EditLine *el; - int c; +ed_tty_sigtstp(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -568,11 +551,10 @@ ed_tty_sigtstp(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_stop_output(el, c) - EditLine *el; - int c; +ed_tty_stop_output(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -582,11 +564,10 @@ ed_tty_stop_output(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_tty_start_output(el, c) - EditLine *el; - int c; +ed_tty_start_output(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -596,16 +577,15 @@ ed_tty_start_output(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_newline(el, c) - EditLine *el; - int c; +ed_newline(EditLine *el, int c) { - 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; + + 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); } @@ -615,18 +595,17 @@ ed_newline(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_delete_prev_char(el, c) - EditLine *el; - int c; +ed_delete_prev_char(EditLine *el, int c) { - if (el->el_line.cursor <= el->el_line.buffer) - return CC_ERROR; - c_delbefore(el, el->el_state.argument); - el->el_line.cursor -= el->el_state.argument; - if (el->el_line.cursor < el->el_line.buffer) - el->el_line.cursor = el->el_line.buffer; - return CC_REFRESH; + if (el->el_line.cursor <= el->el_line.buffer) + return (CC_ERROR); + + c_delbefore(el, el->el_state.argument); + el->el_line.cursor -= el->el_state.argument; + if (el->el_line.cursor < el->el_line.buffer) + el->el_line.cursor = el->el_line.buffer; + return (CC_REFRESH); } @@ -636,13 +615,12 @@ ed_delete_prev_char(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_clear_screen(el, c) - EditLine *el; - int c; +ed_clear_screen(EditLine *el, int c) { - term_clear_screen(el); /* clear the whole real screen */ - re_clear_display(el); /* reset everything */ - return CC_REFRESH; + + term_clear_screen(el); /* clear the whole real screen */ + re_clear_display(el); /* reset everything */ + return (CC_REFRESH); } @@ -652,11 +630,10 @@ ed_clear_screen(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_redisplay(el, c) - EditLine *el; - int c; +ed_redisplay(EditLine *el, int c) { - return CC_REDISPLAY; + + return (CC_REDISPLAY); } @@ -666,12 +643,11 @@ ed_redisplay(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_start_over(el, c) - EditLine *el; - int c; +ed_start_over(EditLine *el, int c) { - ch_reset(el); - return CC_REFRESH; + + ch_reset(el); + return (CC_REFRESH); } @@ -681,11 +657,10 @@ ed_start_over(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_sequence_lead_in(el, c) - EditLine *el; - int c; +ed_sequence_lead_in(EditLine *el, int c) { - return CC_NORM; + + return (CC_NORM); } @@ -695,34 +670,32 @@ ed_sequence_lead_in(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_history(el, c) - EditLine *el; - int c; +ed_prev_history(EditLine *el, int c) { - char beep = 0; - - el->el_chared.c_undo.action = NOP; - *el->el_line.lastchar = '\0'; /* just in case */ + char beep = 0; - if (el->el_history.eventno == 0) { /* save the current buffer away */ - (void) strncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); - el->el_history.last = el->el_history.buf + - (el->el_line.lastchar - el->el_line.buffer); - } + el->el_chared.c_undo.action = NOP; + *el->el_line.lastchar = '\0'; /* just in case */ - el->el_history.eventno += el->el_state.argument; - - if (hist_get(el) == CC_ERROR) { - beep = 1; - /* el->el_history.eventno was fixed by first call */ - (void) hist_get(el); - } + if (el->el_history.eventno == 0) { /* save the current buffer + * away */ + (void) strncpy(el->el_history.buf, el->el_line.buffer, + EL_BUFSIZ); + el->el_history.last = el->el_history.buf + + (el->el_line.lastchar - el->el_line.buffer); + } + el->el_history.eventno += el->el_state.argument; - re_refresh(el); - if (beep) - return CC_ERROR; - else - return CC_NORM; /* was CC_UP_HIST */ + if (hist_get(el) == 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 */ } @@ -732,21 +705,19 @@ ed_prev_history(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_next_history(el, c) - EditLine *el; - int c; +ed_next_history(EditLine *el, int c) { - el->el_chared.c_undo.action = NOP; - *el->el_line.lastchar = '\0'; /* just in case */ - el->el_history.eventno -= el->el_state.argument; + el->el_chared.c_undo.action = NOP; + *el->el_line.lastchar = '\0'; /* just in case */ - if (el->el_history.eventno < 0) { - el->el_history.eventno = 0; - return CC_ERROR; /* make it beep */ - } + el->el_history.eventno -= el->el_state.argument; - return hist_get(el); + if (el->el_history.eventno < 0) { + el->el_history.eventno = 0; + return (CC_ERROR);/* make it beep */ + } + return (hist_get(el)); } @@ -756,69 +727,65 @@ ed_next_history(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_search_prev_history(el, c) - EditLine *el; - int c; -{ - 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_line.lastchar = '\0'; /* just in case */ - if (el->el_history.eventno < 0) { +ed_search_prev_history(EditLine *el, int c) +{ + 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_line.lastchar = '\0'; /* just in case */ + if (el->el_history.eventno < 0) { #ifdef DEBUG_EDIT - (void) fprintf(el->el_errfile, "e_prev_search_hist(): eventno < 0;\n"); + (void) fprintf(el->el_errfile, + "e_prev_search_hist(): eventno < 0;\n"); #endif - el->el_history.eventno = 0; - return CC_ERROR; - } - - if (el->el_history.eventno == 0) { - (void) strncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ); - el->el_history.last = el->el_history.buf + - (el->el_line.lastchar - el->el_line.buffer); - } - - - if (el->el_history.ref == NULL) - return CC_ERROR; + el->el_history.eventno = 0; + return (CC_ERROR); + } + if (el->el_history.eventno == 0) { + (void) strncpy(el->el_history.buf, el->el_line.buffer, + EL_BUFSIZ); + el->el_history.last = el->el_history.buf + + (el->el_line.lastchar - el->el_line.buffer); + } + if (el->el_history.ref == NULL) + return (CC_ERROR); - hp = HIST_FIRST(el); - if (hp == NULL) - return CC_ERROR; + hp = HIST_FIRST(el); + if (hp == NULL) + return (CC_ERROR); - c_setpat(el); /* Set search pattern !! */ + c_setpat(el); /* Set search pattern !! */ - for (h = 1; h <= el->el_history.eventno; h++) - hp = HIST_NEXT(el); + for (h = 1; h <= el->el_history.eventno; h++) + hp = HIST_NEXT(el); - while (hp != NULL) { + while (hp != NULL) { #ifdef SDEBUG - (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); + (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); #endif - if ((strncmp(hp, el->el_line.buffer, - el->el_line.lastchar - el->el_line.buffer) || - hp[el->el_line.lastchar-el->el_line.buffer]) && - c_hmatch(el, hp)) { - found++; - break; + if ((strncmp(hp, el->el_line.buffer, (size_t) + (el->el_line.lastchar - el->el_line.buffer)) || + hp[el->el_line.lastchar - el->el_line.buffer]) && + c_hmatch(el, hp)) { + found++; + break; + } + h++; + hp = HIST_NEXT(el); } - h++; - hp = HIST_NEXT(el); - } - if (!found) { + if (!found) { #ifdef SDEBUG - (void) fprintf(el->el_errfile, "not found\n"); + (void) fprintf(el->el_errfile, "not found\n"); #endif - return CC_ERROR; - } - - el->el_history.eventno = h; + return (CC_ERROR); + } + el->el_history.eventno = h; - return hist_get(el); + return (hist_get(el)); } @@ -828,54 +795,51 @@ ed_search_prev_history(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_search_next_history(el, c) - EditLine *el; - int c; +ed_search_next_history(EditLine *el, int c) { - const char *hp; - int h; - bool_t found = 0; + 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_line.lastchar = '\0'; /* just in case */ + el->el_chared.c_vcmd.action = NOP; + el->el_chared.c_undo.action = NOP; + *el->el_line.lastchar = '\0'; /* just in case */ - if (el->el_history.eventno == 0) - return CC_ERROR; + if (el->el_history.eventno == 0) + return (CC_ERROR); - if (el->el_history.ref == NULL) - return CC_ERROR; + if (el->el_history.ref == NULL) + return (CC_ERROR); - hp = HIST_FIRST(el); - if (hp == NULL) - return CC_ERROR; + hp = HIST_FIRST(el); + if (hp == NULL) + return (CC_ERROR); - c_setpat(el); /* Set search pattern !! */ + c_setpat(el); /* Set search pattern !! */ - for (h = 1; h < el->el_history.eventno && hp; h++) { + for (h = 1; h < el->el_history.eventno && hp; h++) { #ifdef SDEBUG - (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); + (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp); #endif - if ((strncmp(hp, el->el_line.buffer, - el->el_line.lastchar - el->el_line.buffer) || - hp[el->el_line.lastchar-el->el_line.buffer]) && - c_hmatch(el, hp)) - found = h; - hp = HIST_NEXT(el); - } - - if (!found) { /* is it the current history number? */ - if (!c_hmatch(el, el->el_history.buf)) { + if ((strncmp(hp, el->el_line.buffer, (size_t) + (el->el_line.lastchar - el->el_line.buffer)) || + hp[el->el_line.lastchar - el->el_line.buffer]) && + c_hmatch(el, hp)) + found = h; + hp = HIST_NEXT(el); + } + + if (!found) { /* is it the current history number? */ + if (!c_hmatch(el, el->el_history.buf)) { #ifdef SDEBUG - (void) fprintf(el->el_errfile, "not found\n"); + (void) fprintf(el->el_errfile, "not found\n"); #endif - return CC_ERROR; + return (CC_ERROR); + } } - } + el->el_history.eventno = found; - el->el_history.eventno = found; - - return hist_get(el); + return (hist_get(el)); } @@ -885,42 +849,40 @@ ed_search_next_history(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_prev_line(el, c) - EditLine *el; - int c; +ed_prev_line(EditLine *el, int c) { - char *ptr; - int nchars = c_hpos(el); + char *ptr; + int nchars = c_hpos(el); - /* - * Move to the line requested - */ - if (*(ptr = el->el_line.cursor) == '\n') - ptr--; + /* + * Move to the line requested + */ + if (*(ptr = el->el_line.cursor) == '\n') + ptr--; - for (; ptr >= el->el_line.buffer; ptr--) - if (*ptr == '\n' && --el->el_state.argument <= 0) - break; + for (; ptr >= el->el_line.buffer; ptr--) + if (*ptr == '\n' && --el->el_state.argument <= 0) + break; - if (el->el_state.argument > 0) - return CC_ERROR; + if (el->el_state.argument > 0) + return (CC_ERROR); - /* - * Move to the beginning of the line - */ - for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--) - continue; + /* + * Move to the beginning of the line + */ + for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--) + continue; - /* - * Move to the character requested - */ - for (ptr++; - nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; - ptr++) - continue; + /* + * Move to the character requested + */ + for (ptr++; + nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; + ptr++) + continue; - el->el_line.cursor = ptr; - return CC_CURSOR; + el->el_line.cursor = ptr; + return (CC_CURSOR); } @@ -930,33 +892,31 @@ ed_prev_line(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_next_line(el, c) - EditLine *el; - int c; +ed_next_line(EditLine *el, int c) { - char *ptr; - int nchars = c_hpos(el); + char *ptr; + int nchars = c_hpos(el); - /* - * Move to the line requested - */ - for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++) - if (*ptr == '\n' && --el->el_state.argument <= 0) - break; + /* + * Move to the line requested + */ + for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++) + if (*ptr == '\n' && --el->el_state.argument <= 0) + break; - if (el->el_state.argument > 0) - return CC_ERROR; + if (el->el_state.argument > 0) + return (CC_ERROR); - /* - * Move to the character requested - */ - for (ptr++; - nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; - ptr++) - continue; + /* + * Move to the character requested + */ + for (ptr++; + nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n'; + ptr++) + continue; - el->el_line.cursor = ptr; - return CC_CURSOR; + el->el_line.cursor = ptr; + return (CC_CURSOR); } @@ -966,32 +926,30 @@ ed_next_line(el, c) */ protected el_action_t /*ARGSUSED*/ -ed_command(el, c) - EditLine *el; - int c; -{ - 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); - 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 (parse_line(el, tmpbuf) == -1) - return CC_ERROR; - else - return CC_REFRESH; +ed_command(EditLine *el, int c) +{ + 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); + 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 (parse_line(el, tmpbuf) == -1) + return (CC_ERROR); + else + return (CC_REFRESH); } |