diff options
author | sjg <sjg@FreeBSD.org> | 2015-05-27 01:19:58 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2015-05-27 01:19:58 +0000 |
commit | 65145fa4c81da358fcbc3b650156dab705dfa34e (patch) | |
tree | 55c065b6730aaac2afb6c29933ee6ec5fa4c4249 /lib/libedit/vi.c | |
parent | 60ff4eb0dff94a04d75d0d52a3957aaaf5f8c693 (diff) | |
parent | e6b664c390af88d4a87208bc042ce503da664c3b (diff) | |
download | FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.zip FreeBSD-src-65145fa4c81da358fcbc3b650156dab705dfa34e.tar.gz |
Merge sync of head
Diffstat (limited to 'lib/libedit/vi.c')
-rw-r--r-- | lib/libedit/vi.c | 349 |
1 files changed, 190 insertions, 159 deletions
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c index 4826901..dfd17e3 100644 --- a/lib/libedit/vi.c +++ b/lib/libedit/vi.c @@ -1,3 +1,5 @@ +/* $NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $ */ + /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -28,12 +30,20 @@ * 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: vi.c,v 1.30 2009/02/21 23:31:56 christos Exp $ */ +#include "config.h" +#include <stdlib.h> +#include <unistd.h> +#include <limits.h> +#include <sys/wait.h> + #if !defined(lint) && !defined(SCCSID) +#if 0 static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: vi.c,v 1.45 2014/06/18 18:12:28 christos Exp $"); +#endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); @@ -41,23 +51,21 @@ __FBSDID("$FreeBSD$"); /* * vi.c: Vi mode commands. */ -#include <sys/wait.h> -#include "sys.h" #include "el.h" -private el_action_t cv_action(EditLine *, int); -private el_action_t cv_paste(EditLine *, int); +private el_action_t cv_action(EditLine *, Int); +private el_action_t cv_paste(EditLine *, Int); /* cv_action(): * Handle vi actions. */ private el_action_t -cv_action(EditLine *el, int c) +cv_action(EditLine *el, Int c) { if (el->el_chared.c_vcmd.action != NOP) { /* 'cc', 'dd' and (possibly) friends */ - if (c != el->el_chared.c_vcmd.action) + if (c != (Int)el->el_chared.c_vcmd.action) return CC_ERROR; if (!(c & YANK)) @@ -73,24 +81,24 @@ cv_action(EditLine *el, int c) if (c & INSERT) el->el_map.current = el->el_map.key; - return (CC_REFRESH); + return CC_REFRESH; } el->el_chared.c_vcmd.pos = el->el_line.cursor; el->el_chared.c_vcmd.action = c; - return (CC_ARGHACK); + return CC_ARGHACK; } /* cv_paste(): * Paste previous deletion before or after the cursor */ private el_action_t -cv_paste(EditLine *el, int c) +cv_paste(EditLine *el, Int c) { c_kill_t *k = &el->el_chared.c_kill; size_t len = (size_t)(k->last - k->buf); if (k->buf == NULL || len == 0) - return (CC_ERROR); + return CC_ERROR; #ifdef DEBUG_PASTE (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf); #endif @@ -102,10 +110,11 @@ cv_paste(EditLine *el, int c) c_insert(el, (int)len); if (el->el_line.cursor + len > el->el_line.lastchar) - return (CC_ERROR); - (void) memcpy(el->el_line.cursor, k->buf, len); + return CC_ERROR; + (void) memcpy(el->el_line.cursor, k->buf, len * + sizeof(*el->el_line.cursor)); - return (CC_REFRESH); + return CC_REFRESH; } @@ -115,10 +124,10 @@ cv_paste(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_paste_next(EditLine *el, int c __unused) +vi_paste_next(EditLine *el, Int c __attribute__((__unused__))) { - return (cv_paste(el, 0)); + return cv_paste(el, 0); } @@ -128,10 +137,10 @@ vi_paste_next(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_paste_prev(EditLine *el, int c __unused) +vi_paste_prev(EditLine *el, Int c __attribute__((__unused__))) { - return (cv_paste(el, 1)); + return cv_paste(el, 1); } @@ -141,11 +150,11 @@ vi_paste_prev(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_prev_big_word(EditLine *el, int c) +vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) - return (CC_ERROR); + return CC_ERROR; el->el_line.cursor = cv_prev_word(el->el_line.cursor, el->el_line.buffer, @@ -154,9 +163,9 @@ vi_prev_big_word(EditLine *el, int c) if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } @@ -166,11 +175,11 @@ vi_prev_big_word(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_prev_word(EditLine *el, int c __unused) +vi_prev_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) - return (CC_ERROR); + return CC_ERROR; el->el_line.cursor = cv_prev_word(el->el_line.cursor, el->el_line.buffer, @@ -179,9 +188,9 @@ vi_prev_word(EditLine *el, int c __unused) if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } @@ -191,11 +200,11 @@ vi_prev_word(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_next_big_word(EditLine *el, int c) +vi_next_big_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) - return (CC_ERROR); + return CC_ERROR; el->el_line.cursor = cv_next_word(el, el->el_line.cursor, el->el_line.lastchar, el->el_state.argument, cv__isWord); @@ -203,9 +212,9 @@ vi_next_big_word(EditLine *el, int c) if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } @@ -215,11 +224,11 @@ vi_next_big_word(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_next_word(EditLine *el, int c __unused) +vi_next_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) - return (CC_ERROR); + return CC_ERROR; el->el_line.cursor = cv_next_word(el, el->el_line.cursor, el->el_line.lastchar, el->el_state.argument, cv__isword); @@ -227,9 +236,9 @@ vi_next_word(EditLine *el, int c __unused) if (el->el_map.type == MAP_VI) if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } @@ -238,20 +247,20 @@ vi_next_word(EditLine *el, int c __unused) * [~] */ protected el_action_t -vi_change_case(EditLine *el, int c) +vi_change_case(EditLine *el, Int c) { int i; if (el->el_line.cursor >= el->el_line.lastchar) - return (CC_ERROR); + return CC_ERROR; cv_undo(el); for (i = 0; i < el->el_state.argument; i++) { - c = *(unsigned char *)el->el_line.cursor; - if (isupper(c)) - *el->el_line.cursor = tolower(c); - else if (islower(c)) - *el->el_line.cursor = toupper(c); + c = *el->el_line.cursor; + if (Isupper(c)) + *el->el_line.cursor = Tolower(c); + else if (Islower(c)) + *el->el_line.cursor = Toupper(c); if (++el->el_line.cursor >= el->el_line.lastchar) { el->el_line.cursor--; @@ -270,14 +279,14 @@ vi_change_case(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_change_meta(EditLine *el, int c __unused) +vi_change_meta(EditLine *el, Int c __attribute__((__unused__))) { /* * Delete with insert == change: first we delete and then we leave in * insert mode. */ - return (cv_action(el, DELETE | INSERT)); + return cv_action(el, DELETE | INSERT); } @@ -287,13 +296,13 @@ vi_change_meta(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_insert_at_bol(EditLine *el, int c __unused) +vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; cv_undo(el); el->el_map.current = el->el_map.key; - return (CC_CURSOR); + return CC_CURSOR; } @@ -303,7 +312,7 @@ vi_insert_at_bol(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_replace_char(EditLine *el, int c __unused) +vi_replace_char(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar) @@ -312,7 +321,7 @@ vi_replace_char(EditLine *el, int c __unused) el->el_map.current = el->el_map.key; el->el_state.inputmode = MODE_REPLACE_1; cv_undo(el); - return (CC_ARGHACK); + return CC_ARGHACK; } @@ -322,13 +331,13 @@ vi_replace_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_replace_mode(EditLine *el, int c __unused) +vi_replace_mode(EditLine *el, Int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; el->el_state.inputmode = MODE_REPLACE; cv_undo(el); - return (CC_NORM); + return CC_NORM; } @@ -338,12 +347,12 @@ vi_replace_mode(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_substitute_char(EditLine *el, int c __unused) +vi_substitute_char(EditLine *el, Int c __attribute__((__unused__))) { c_delafter(el, el->el_state.argument); el->el_map.current = el->el_map.key; - return (CC_REFRESH); + return CC_REFRESH; } @@ -353,7 +362,7 @@ vi_substitute_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_substitute_line(EditLine *el, int c __unused) +vi_substitute_line(EditLine *el, Int c __attribute__((__unused__))) { cv_undo(el); @@ -361,7 +370,7 @@ vi_substitute_line(EditLine *el, int c __unused) (int)(el->el_line.lastchar - el->el_line.buffer)); (void) em_kill_line(el, 0); el->el_map.current = el->el_map.key; - return (CC_REFRESH); + return CC_REFRESH; } @@ -371,7 +380,7 @@ vi_substitute_line(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_change_to_eol(EditLine *el, int c __unused) +vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__))) { cv_undo(el); @@ -379,7 +388,7 @@ vi_change_to_eol(EditLine *el, int c __unused) (int)(el->el_line.lastchar - el->el_line.cursor)); (void) ed_kill_line(el, 0); el->el_map.current = el->el_map.key; - return (CC_REFRESH); + return CC_REFRESH; } @@ -389,12 +398,12 @@ vi_change_to_eol(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_insert(EditLine *el, int c __unused) +vi_insert(EditLine *el, Int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; cv_undo(el); - return (CC_NORM); + return CC_NORM; } @@ -404,7 +413,7 @@ vi_insert(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_add(EditLine *el, int c __unused) +vi_add(EditLine *el, Int c __attribute__((__unused__))) { int ret; @@ -419,7 +428,7 @@ vi_add(EditLine *el, int c __unused) cv_undo(el); - return (ret); + return (el_action_t)ret; } @@ -429,13 +438,13 @@ vi_add(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_add_at_eol(EditLine *el, int c __unused) +vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; el->el_line.cursor = el->el_line.lastchar; cv_undo(el); - return (CC_CURSOR); + return CC_CURSOR; } @@ -445,10 +454,10 @@ vi_add_at_eol(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_delete_meta(EditLine *el, int c __unused) +vi_delete_meta(EditLine *el, Int c __attribute__((__unused__))) { - return (cv_action(el, DELETE)); + return cv_action(el, DELETE); } @@ -458,11 +467,11 @@ vi_delete_meta(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_end_big_word(EditLine *el, int c) +vi_end_big_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) - return (CC_ERROR); + return CC_ERROR; el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar, el->el_state.argument, cv__isWord); @@ -470,9 +479,9 @@ vi_end_big_word(EditLine *el, int c) if (el->el_chared.c_vcmd.action != NOP) { el->el_line.cursor++; cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } @@ -482,11 +491,11 @@ vi_end_big_word(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_end_word(EditLine *el, int c __unused) +vi_end_word(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) - return (CC_ERROR); + return CC_ERROR; el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar, el->el_state.argument, cv__isword); @@ -494,9 +503,9 @@ vi_end_word(EditLine *el, int c __unused) if (el->el_chared.c_vcmd.action != NOP) { el->el_line.cursor++; cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } @@ -506,7 +515,7 @@ vi_end_word(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_undo(EditLine *el, int c __unused) +vi_undo(EditLine *el, Int c __attribute__((__unused__))) { c_undo_t un = el->el_chared.c_undo; @@ -523,7 +532,7 @@ vi_undo(EditLine *el, int c __unused) el->el_line.cursor = un.buf + un.cursor; el->el_line.lastchar = un.buf + un.len; - return (CC_REFRESH); + return CC_REFRESH; } @@ -533,7 +542,7 @@ vi_undo(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_command_mode(EditLine *el, int c __unused) +vi_command_mode(EditLine *el, Int c __attribute__((__unused__))) { /* [Esc] cancels pending action */ @@ -548,7 +557,7 @@ vi_command_mode(EditLine *el, int c __unused) if (el->el_line.cursor > el->el_line.buffer) el->el_line.cursor--; #endif - return (CC_CURSOR); + return CC_CURSOR; } @@ -557,7 +566,7 @@ vi_command_mode(EditLine *el, int c __unused) * [0] */ protected el_action_t -vi_zero(EditLine *el, int c) +vi_zero(EditLine *el, Int c) { if (el->el_state.doingarg) @@ -566,9 +575,9 @@ vi_zero(EditLine *el, int c) el->el_line.cursor = el->el_line.buffer; if (el->el_chared.c_vcmd.action != NOP) { cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } @@ -578,15 +587,15 @@ vi_zero(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_delete_prev_char(EditLine *el, int c __unused) +vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) - return (CC_ERROR); + return CC_ERROR; c_delbefore1(el); el->el_line.cursor--; - return (CC_REFRESH); + return CC_REFRESH; } @@ -596,32 +605,32 @@ vi_delete_prev_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_list_or_eof(EditLine *el, int c) +vi_list_or_eof(EditLine *el, Int c) { if (el->el_line.cursor == el->el_line.lastchar) { if (el->el_line.cursor == el->el_line.buffer) { - term_writec(el, c); /* then do a EOF */ - return (CC_EOF); + terminal_writec(el, c); /* then do a EOF */ + return CC_EOF; } else { /* * Here we could list completions, but it is an * error right now */ - term_beep(el); - return (CC_ERROR); + terminal_beep(el); + return CC_ERROR; } } else { #ifdef notyet re_goto_bottom(el); *el->el_line.lastchar = '\0'; /* just in case */ - return (CC_LIST_CHOICES); + return CC_LIST_CHOICES; #else /* * Just complain for now. */ - term_beep(el); - return (CC_ERROR); + terminal_beep(el); + return CC_ERROR; #endif } } @@ -633,9 +642,9 @@ vi_list_or_eof(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_kill_line_prev(EditLine *el, int c __unused) +vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__))) { - char *kp, *cp; + Char *kp, *cp; cp = el->el_line.buffer; kp = el->el_chared.c_kill.buf; @@ -644,7 +653,7 @@ vi_kill_line_prev(EditLine *el, int c __unused) el->el_chared.c_kill.last = kp; c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer)); el->el_line.cursor = el->el_line.buffer; /* zap! */ - return (CC_REFRESH); + return CC_REFRESH; } @@ -654,10 +663,10 @@ vi_kill_line_prev(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_search_prev(EditLine *el, int c __unused) +vi_search_prev(EditLine *el, Int c __attribute__((__unused__))) { - return (cv_search(el, ED_SEARCH_PREV_HISTORY)); + return cv_search(el, ED_SEARCH_PREV_HISTORY); } @@ -667,10 +676,10 @@ vi_search_prev(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_search_next(EditLine *el, int c __unused) +vi_search_next(EditLine *el, Int c __attribute__((__unused__))) { - return (cv_search(el, ED_SEARCH_NEXT_HISTORY)); + return cv_search(el, ED_SEARCH_NEXT_HISTORY); } @@ -680,13 +689,13 @@ vi_search_next(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_search_next(EditLine *el, int c __unused) +vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_search.patlen == 0) - return (CC_ERROR); + return CC_ERROR; else - return (cv_repeat_srch(el, el->el_search.patdir)); + return cv_repeat_srch(el, el->el_search.patdir); } @@ -696,11 +705,11 @@ vi_repeat_search_next(EditLine *el, int c __unused) */ /*ARGSUSED*/ protected el_action_t -vi_repeat_search_prev(EditLine *el, int c __unused) +vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__))) { if (el->el_search.patlen == 0) - return (CC_ERROR); + return CC_ERROR; else return (cv_repeat_srch(el, el->el_search.patdir == ED_SEARCH_PREV_HISTORY ? @@ -714,7 +723,7 @@ vi_repeat_search_prev(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_next_char(EditLine *el, int c __unused) +vi_next_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0); } @@ -726,7 +735,7 @@ vi_next_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_prev_char(EditLine *el, int c __unused) +vi_prev_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0); } @@ -738,7 +747,7 @@ vi_prev_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_to_next_char(EditLine *el, int c __unused) +vi_to_next_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1); } @@ -750,7 +759,7 @@ vi_to_next_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_to_prev_char(EditLine *el, int c __unused) +vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1); } @@ -762,7 +771,7 @@ vi_to_prev_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_next_char(EditLine *el, int c __unused) +vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__))) { return cv_csearch(el, el->el_search.chadir, el->el_search.chacha, @@ -776,7 +785,7 @@ vi_repeat_next_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_prev_char(EditLine *el, int c __unused) +vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__))) { el_action_t r; int dir = el->el_search.chadir; @@ -794,20 +803,20 @@ vi_repeat_prev_char(EditLine *el, int c __unused) */ protected el_action_t /*ARGSUSED*/ -vi_match(EditLine *el, int c) +vi_match(EditLine *el, Int c __attribute__((__unused__))) { - const char match_chars[] = "()[]{}"; - char *cp; + const Char match_chars[] = STR("()[]{}"); + Char *cp; size_t delta, i, count; - char o_ch, c_ch; + Char o_ch, c_ch; *el->el_line.lastchar = '\0'; /* just in case */ - i = strcspn(el->el_line.cursor, match_chars); + i = Strcspn(el->el_line.cursor, match_chars); o_ch = el->el_line.cursor[i]; if (o_ch == 0) return CC_ERROR; - delta = strchr(match_chars, o_ch) - match_chars; + delta = (size_t)(Strchr(match_chars, o_ch) - match_chars); c_ch = match_chars[delta ^ 1]; count = 1; delta = 1 - (delta & 1) * 2; @@ -830,9 +839,9 @@ vi_match(EditLine *el, int c) if (delta > 0) el->el_line.cursor++; cv_delfini(el); - return (CC_REFRESH); + return CC_REFRESH; } - return (CC_CURSOR); + return CC_CURSOR; } /* vi_undo_line(): @@ -841,7 +850,7 @@ vi_match(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_undo_line(EditLine *el, int c) +vi_undo_line(EditLine *el, Int c __attribute__((__unused__))) { cv_undo(el); @@ -855,7 +864,7 @@ vi_undo_line(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_to_column(EditLine *el, int c) +vi_to_column(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -869,7 +878,7 @@ vi_to_column(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_yank_end(EditLine *el, int c) +vi_yank_end(EditLine *el, Int c __attribute__((__unused__))) { cv_yank(el, el->el_line.cursor, @@ -883,7 +892,7 @@ vi_yank_end(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_yank(EditLine *el, int c) +vi_yank(EditLine *el, Int c __attribute__((__unused__))) { return cv_action(el, YANK); @@ -895,7 +904,7 @@ vi_yank(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_comment_out(EditLine *el, int c) +vi_comment_out(EditLine *el, Int c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -913,30 +922,24 @@ vi_comment_out(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_alias(EditLine *el, int c) +vi_alias(EditLine *el, Int c __attribute__((__unused__))) { -#ifdef __weak_extern char alias_name[3]; - char *alias_text; - extern char *get_alias_text(const char *); - __weak_extern(get_alias_text); + const char *alias_text; - if (get_alias_text == 0) { + if (el->el_chared.c_aliasfun == NULL) return CC_ERROR; - } alias_name[0] = '_'; alias_name[2] = 0; if (el_getc(el, &alias_name[1]) != 1) return CC_ERROR; - alias_text = get_alias_text(alias_name); + alias_text = (*el->el_chared.c_aliasfun)(el->el_chared.c_aliasarg, + alias_name); if (alias_text != NULL) - el_push(el, alias_text); + FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch)); return CC_NORM; -#else - return CC_ERROR; -#endif } /* vi_to_history_line(): @@ -945,14 +948,14 @@ vi_alias(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_to_history_line(EditLine *el, int c) +vi_to_history_line(EditLine *el, Int c __attribute__((__unused__))) { int sv_event_no = el->el_history.eventno; el_action_t rval; if (el->el_history.eventno == 0) { - (void) strncpy(el->el_history.buf, el->el_line.buffer, + (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); @@ -990,14 +993,16 @@ vi_to_history_line(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_histedit(EditLine *el, int c) +vi_histedit(EditLine *el, Int c __attribute__((__unused__))) { int fd; pid_t pid; ssize_t st; int status; char tempfile[] = "/tmp/histedit.XXXXXXXXXX"; - char *cp; + char *cp = NULL; + size_t len; + Char *line = NULL; if (el->el_state.doingarg) { if (vi_to_history_line(el, 0) == CC_ERROR) @@ -1007,15 +1012,25 @@ vi_histedit(EditLine *el, int c) fd = mkstemp(tempfile); if (fd < 0) return CC_ERROR; - cp = el->el_line.buffer; - write(fd, cp, (size_t)(el->el_line.lastchar - cp)); - write(fd, "\n", 1); + len = (size_t)(el->el_line.lastchar - el->el_line.buffer); +#define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX) + cp = el_malloc(TMP_BUFSIZ * sizeof(*cp)); + if (cp == NULL) + goto error; + line = el_malloc(len * sizeof(*line) + 1); + if (line == NULL) + goto error; + Strncpy(line, el->el_line.buffer, len); + line[len] = '\0'; + ct_wcstombs(cp, line, TMP_BUFSIZ - 1); + cp[TMP_BUFSIZ - 1] = '\0'; + len = strlen(cp); + write(fd, cp, len); + write(fd, "\n", (size_t)1); pid = fork(); switch (pid) { case -1: - close(fd); - unlink(tempfile); - return CC_ERROR; + goto error; case 0: close(fd); execlp("vi", "vi", tempfile, (char *)NULL); @@ -1025,11 +1040,20 @@ vi_histedit(EditLine *el, int c) while (waitpid(pid, &status, 0) != pid) continue; lseek(fd, (off_t)0, SEEK_SET); - st = read(fd, cp, (size_t)(el->el_line.limit - cp)); - if (st > 0 && cp[st - 1] == '\n') - st--; - el->el_line.cursor = cp; - el->el_line.lastchar = cp + st; + st = read(fd, cp, TMP_BUFSIZ); + if (st > 0) { + len = (size_t)(el->el_line.lastchar - + el->el_line.buffer); + len = ct_mbstowcs(el->el_line.buffer, cp, len); + if (len > 0 && el->el_line.buffer[len -1] == '\n') + --len; + } + else + len = 0; + el->el_line.cursor = el->el_line.buffer; + el->el_line.lastchar = el->el_line.buffer + len; + el_free(cp); + el_free(line); break; } @@ -1037,6 +1061,12 @@ vi_histedit(EditLine *el, int c) unlink(tempfile); /* return CC_REFRESH; */ return ed_newline(el, 0); +error: + el_free(line); + el_free(cp); + close(fd); + unlink(tempfile); + return CC_ERROR; } /* vi_history_word(): @@ -1047,28 +1077,29 @@ vi_histedit(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_history_word(EditLine *el, int c) +vi_history_word(EditLine *el, Int c __attribute__((__unused__))) { - const char *wp = HIST_FIRST(el); - const char *wep, *wsp; + const Char *wp = HIST_FIRST(el); + const Char *wep, *wsp; int len; - char *cp; - const char *lim; + Char *cp; + const Char *lim; if (wp == NULL) return CC_ERROR; wep = wsp = 0; do { - while (isspace((unsigned char)*wp)) + while (Isspace(*wp)) wp++; if (*wp == 0) break; wsp = wp; - while (*wp && !isspace((unsigned char)*wp)) + while (*wp && !Isspace(*wp)) wp++; wep = wp; - } while ((!el->el_state.doingarg || --el->el_state.argument > 0) && *wp != 0); + } while ((!el->el_state.doingarg || --el->el_state.argument > 0) + && *wp != 0); if (wsp == 0 || (el->el_state.doingarg && el->el_state.argument != 0)) return CC_ERROR; @@ -1096,7 +1127,7 @@ vi_history_word(EditLine *el, int c) */ protected el_action_t /*ARGSUSED*/ -vi_redo(EditLine *el, int c) +vi_redo(EditLine *el, Int c __attribute__((__unused__))) { c_redo_t *r = &el->el_chared.c_redo; @@ -1112,10 +1143,10 @@ vi_redo(EditLine *el, int c) /* sanity */ r->pos = r->lim - 1; r->pos[0] = 0; - el_push(el, r->buf); + FUN(el,push)(el, r->buf); } el->el_state.thiscmd = r->cmd; el->el_state.thisch = r->ch; - return (*el->el_map.func[r->cmd])(el, r->ch); + return (*el->el_map.func[r->cmd])(el, r->ch); } |