diff options
Diffstat (limited to 'lib/libedit/vi.c')
-rw-r--r-- | lib/libedit/vi.c | 130 |
1 files changed, 68 insertions, 62 deletions
diff --git a/lib/libedit/vi.c b/lib/libedit/vi.c index 6b0a775..02d7e29 100644 --- a/lib/libedit/vi.c +++ b/lib/libedit/vi.c @@ -1,4 +1,4 @@ -/* $NetBSD: vi.c,v 1.47 2015/10/21 21:45:30 christos Exp $ */ +/* $NetBSD: vi.c,v 1.55 2016/03/02 19:24:20 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -33,16 +33,11 @@ */ #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.47 2015/10/21 21:45:30 christos Exp $"); +__RCSID("$NetBSD: vi.c,v 1.55 2016/03/02 19:24:20 christos Exp $"); #endif #endif /* not lint && not SCCSID */ #include <sys/cdefs.h> @@ -51,21 +46,31 @@ __FBSDID("$FreeBSD$"); /* * vi.c: Vi mode commands. */ +#include <sys/wait.h> +#include <ctype.h> +#include <limits.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + #include "el.h" +#include "common.h" +#include "emacs.h" +#include "vi.h" -private el_action_t cv_action(EditLine *, Int); -private el_action_t cv_paste(EditLine *, Int); +private el_action_t cv_action(EditLine *, wint_t); +private el_action_t cv_paste(EditLine *, wint_t); /* cv_action(): * Handle vi actions. */ private el_action_t -cv_action(EditLine *el, Int c) +cv_action(EditLine *el, wint_t c) { if (el->el_chared.c_vcmd.action != NOP) { /* 'cc', 'dd' and (possibly) friends */ - if (c != (Int)el->el_chared.c_vcmd.action) + if (c != (wint_t)el->el_chared.c_vcmd.action) return CC_ERROR; if (!(c & YANK)) @@ -92,7 +97,7 @@ cv_action(EditLine *el, Int c) * Paste previous deletion before or after the cursor */ private el_action_t -cv_paste(EditLine *el, Int c) +cv_paste(EditLine *el, wint_t c) { c_kill_t *k = &el->el_chared.c_kill; size_t len = (size_t)(k->last - k->buf); @@ -100,7 +105,8 @@ cv_paste(EditLine *el, Int c) if (k->buf == NULL || len == 0) return CC_ERROR; #ifdef DEBUG_PASTE - (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", (int)len, k->buf); + (void) fprintf(el->el_errfile, "Paste: \"" FSTARSTR "\"\n", (int)len, + k->buf); #endif cv_undo(el); @@ -124,7 +130,7 @@ cv_paste(EditLine *el, Int c) */ protected el_action_t /*ARGSUSED*/ -vi_paste_next(EditLine *el, Int c __attribute__((__unused__))) +vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_paste(el, 0); @@ -137,7 +143,7 @@ vi_paste_next(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_paste_prev(EditLine *el, Int c __attribute__((__unused__))) +vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_paste(el, 1); @@ -150,7 +156,7 @@ vi_paste_prev(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__))) +vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -175,7 +181,7 @@ vi_prev_big_word(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_prev_word(EditLine *el, Int c __attribute__((__unused__))) +vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.buffer) @@ -200,7 +206,7 @@ vi_prev_word(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_next_big_word(EditLine *el, Int c __attribute__((__unused__))) +vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -224,7 +230,7 @@ vi_next_big_word(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_next_word(EditLine *el, Int c __attribute__((__unused__))) +vi_next_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar - 1) @@ -247,7 +253,7 @@ vi_next_word(EditLine *el, Int c __attribute__((__unused__))) * [~] */ protected el_action_t -vi_change_case(EditLine *el, Int c) +vi_change_case(EditLine *el, wint_t c) { int i; @@ -279,7 +285,7 @@ vi_change_case(EditLine *el, Int c) */ protected el_action_t /*ARGSUSED*/ -vi_change_meta(EditLine *el, Int c __attribute__((__unused__))) +vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__))) { /* @@ -296,7 +302,7 @@ vi_change_meta(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__))) +vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -312,7 +318,7 @@ vi_insert_at_bol(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_replace_char(EditLine *el, Int c __attribute__((__unused__))) +vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor >= el->el_line.lastchar) @@ -331,7 +337,7 @@ vi_replace_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_replace_mode(EditLine *el, Int c __attribute__((__unused__))) +vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -347,7 +353,7 @@ vi_replace_mode(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_substitute_char(EditLine *el, Int c __attribute__((__unused__))) +vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__))) { c_delafter(el, el->el_state.argument); @@ -362,7 +368,7 @@ vi_substitute_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_substitute_line(EditLine *el, Int c __attribute__((__unused__))) +vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__))) { cv_undo(el); @@ -380,7 +386,7 @@ vi_substitute_line(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__))) +vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__))) { cv_undo(el); @@ -398,7 +404,7 @@ vi_change_to_eol(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_insert(EditLine *el, Int c __attribute__((__unused__))) +vi_insert(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -413,7 +419,7 @@ vi_insert(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_add(EditLine *el, Int c __attribute__((__unused__))) +vi_add(EditLine *el, wint_t c __attribute__((__unused__))) { int ret; @@ -438,7 +444,7 @@ vi_add(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__))) +vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_map.current = el->el_map.key; @@ -454,7 +460,7 @@ vi_add_at_eol(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_delete_meta(EditLine *el, Int c __attribute__((__unused__))) +vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_action(el, DELETE); @@ -467,7 +473,7 @@ vi_delete_meta(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_end_big_word(EditLine *el, Int c __attribute__((__unused__))) +vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) @@ -491,7 +497,7 @@ vi_end_big_word(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_end_word(EditLine *el, Int c __attribute__((__unused__))) +vi_end_word(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor == el->el_line.lastchar) @@ -515,7 +521,7 @@ vi_end_word(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_undo(EditLine *el, Int c __attribute__((__unused__))) +vi_undo(EditLine *el, wint_t c __attribute__((__unused__))) { c_undo_t un = el->el_chared.c_undo; @@ -542,7 +548,7 @@ vi_undo(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_command_mode(EditLine *el, Int c __attribute__((__unused__))) +vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__))) { /* [Esc] cancels pending action */ @@ -566,7 +572,7 @@ vi_command_mode(EditLine *el, Int c __attribute__((__unused__))) * [0] */ protected el_action_t -vi_zero(EditLine *el, Int c) +vi_zero(EditLine *el, wint_t c) { if (el->el_state.doingarg) @@ -582,12 +588,12 @@ vi_zero(EditLine *el, Int c) /* vi_delete_prev_char(): - * Vi move to previous character (backspace) + * Vi move to previous character (backspace) * [^H] in insert mode only */ protected el_action_t /*ARGSUSED*/ -vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_line.cursor <= el->el_line.buffer) @@ -605,7 +611,7 @@ vi_delete_prev_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_list_or_eof(EditLine *el, Int c) +vi_list_or_eof(EditLine *el, wint_t c) { if (el->el_line.cursor == el->el_line.lastchar) { @@ -642,7 +648,7 @@ vi_list_or_eof(EditLine *el, Int c) */ protected el_action_t /*ARGSUSED*/ -vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__))) +vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__))) { Char *kp, *cp; @@ -663,7 +669,7 @@ vi_kill_line_prev(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_search_prev(EditLine *el, Int c __attribute__((__unused__))) +vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_search(el, ED_SEARCH_PREV_HISTORY); @@ -676,7 +682,7 @@ vi_search_prev(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_search_next(EditLine *el, Int c __attribute__((__unused__))) +vi_search_next(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_search(el, ED_SEARCH_NEXT_HISTORY); @@ -689,7 +695,7 @@ vi_search_next(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__))) +vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -705,7 +711,7 @@ vi_repeat_search_next(EditLine *el, Int c __attribute__((__unused__))) */ /*ARGSUSED*/ protected el_action_t -vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__))) +vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__))) { if (el->el_search.patlen == 0) @@ -723,7 +729,7 @@ vi_repeat_search_prev(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_next_char(EditLine *el, Int c __attribute__((__unused__))) +vi_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0); } @@ -735,7 +741,7 @@ vi_next_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0); } @@ -747,7 +753,7 @@ vi_prev_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_next_char(EditLine *el, Int c __attribute__((__unused__))) +vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1); } @@ -759,7 +765,7 @@ vi_to_next_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1); } @@ -771,7 +777,7 @@ vi_to_prev_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__))) +vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_csearch(el, el->el_search.chadir, el->el_search.chacha, @@ -785,7 +791,7 @@ vi_repeat_next_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__))) +vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__))) { el_action_t r; int dir = el->el_search.chadir; @@ -803,7 +809,7 @@ vi_repeat_prev_char(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_match(EditLine *el, Int c __attribute__((__unused__))) +vi_match(EditLine *el, wint_t c __attribute__((__unused__))) { const Char match_chars[] = STR("()[]{}"); Char *cp; @@ -850,7 +856,7 @@ vi_match(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_undo_line(EditLine *el, Int c __attribute__((__unused__))) +vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__))) { cv_undo(el); @@ -864,7 +870,7 @@ vi_undo_line(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_column(EditLine *el, Int c __attribute__((__unused__))) +vi_to_column(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -878,7 +884,7 @@ vi_to_column(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_yank_end(EditLine *el, Int c __attribute__((__unused__))) +vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__))) { cv_yank(el, el->el_line.cursor, @@ -892,7 +898,7 @@ vi_yank_end(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_yank(EditLine *el, Int c __attribute__((__unused__))) +vi_yank(EditLine *el, wint_t c __attribute__((__unused__))) { return cv_action(el, YANK); @@ -904,7 +910,7 @@ vi_yank(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_comment_out(EditLine *el, Int c __attribute__((__unused__))) +vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__))) { el->el_line.cursor = el->el_line.buffer; @@ -922,7 +928,7 @@ vi_comment_out(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_alias(EditLine *el, Int c __attribute__((__unused__))) +vi_alias(EditLine *el, wint_t c __attribute__((__unused__))) { char alias_name[3]; const char *alias_text; @@ -948,7 +954,7 @@ vi_alias(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_to_history_line(EditLine *el, Int c __attribute__((__unused__))) +vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__))) { int sv_event_no = el->el_history.eventno; el_action_t rval; @@ -974,7 +980,7 @@ vi_to_history_line(EditLine *el, Int c __attribute__((__unused__))) el->el_history.eventno = 1; if (hist_get(el) == CC_ERROR) return CC_ERROR; - el->el_history.eventno = 1 + el->el_history.ev.num + el->el_history.eventno = 1 + el->el_history.ev.num - el->el_state.argument; if (el->el_history.eventno < 0) { el->el_history.eventno = sv_event_no; @@ -993,7 +999,7 @@ vi_to_history_line(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_histedit(EditLine *el, Int c __attribute__((__unused__))) +vi_histedit(EditLine *el, wint_t c __attribute__((__unused__))) { int fd; pid_t pid; @@ -1077,7 +1083,7 @@ error: */ protected el_action_t /*ARGSUSED*/ -vi_history_word(EditLine *el, Int c __attribute__((__unused__))) +vi_history_word(EditLine *el, wint_t c __attribute__((__unused__))) { const Char *wp = HIST_FIRST(el); const Char *wep, *wsp; @@ -1127,7 +1133,7 @@ vi_history_word(EditLine *el, Int c __attribute__((__unused__))) */ protected el_action_t /*ARGSUSED*/ -vi_redo(EditLine *el, Int c __attribute__((__unused__))) +vi_redo(EditLine *el, wint_t c __attribute__((__unused__))) { c_redo_t *r = &el->el_chared.c_redo; |