diff options
Diffstat (limited to 'vi.c')
| -rw-r--r-- | vi.c | 159 | 
1 files changed, 80 insertions, 79 deletions
| @@ -1,4 +1,4 @@ -/*	$NetBSD: vi.c,v 1.55 2016/03/02 19:24:20 christos Exp $	*/ +/*	$NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $	*/  /*-   * Copyright (c) 1992, 1993 @@ -37,7 +37,7 @@  #if 0  static char sccsid[] = "@(#)vi.c	8.1 (Berkeley) 6/4/93";  #else -__RCSID("$NetBSD: vi.c,v 1.55 2016/03/02 19:24:20 christos Exp $"); +__RCSID("$NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $");  #endif  #endif /* not lint && not SCCSID */ @@ -54,15 +54,16 @@ __RCSID("$NetBSD: vi.c,v 1.55 2016/03/02 19:24:20 christos Exp $");  #include "el.h"  #include "common.h"  #include "emacs.h" +#include "fcns.h"  #include "vi.h" -private el_action_t	cv_action(EditLine *, wint_t); -private el_action_t	cv_paste(EditLine *, wint_t); +static el_action_t	cv_action(EditLine *, wint_t); +static el_action_t	cv_paste(EditLine *, wint_t);  /* cv_action():   *	Handle vi actions.   */ -private el_action_t +static el_action_t  cv_action(EditLine *el, wint_t c)  { @@ -94,7 +95,7 @@ cv_action(EditLine *el, wint_t c)  /* cv_paste():   *	Paste previous deletion before or after the cursor   */ -private el_action_t +static el_action_t  cv_paste(EditLine *el, wint_t c)  {  	c_kill_t *k = &el->el_chared.c_kill; @@ -103,7 +104,7 @@ cv_paste(EditLine *el, wint_t c)  	if (k->buf == NULL || len == 0)  		return CC_ERROR;  #ifdef DEBUG_PASTE -	(void) fprintf(el->el_errfile, "Paste: \"" FSTARSTR "\"\n", (int)len, +	(void) fprintf(el->el_errfile, "Paste: \"%.*ls\"\n", (int)len,  	    k->buf);  #endif @@ -126,7 +127,7 @@ cv_paste(EditLine *el, wint_t c)   *	Vi paste previous deletion to the right of the cursor   *	[p]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -139,7 +140,7 @@ vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi paste previous deletion to the left of the cursor   *	[P]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -152,7 +153,7 @@ vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the previous space delimited word   *	[B]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -177,7 +178,7 @@ vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the previous word   *	[b]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -202,7 +203,7 @@ vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the next space delimited word   *	[W]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -226,7 +227,7 @@ vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the next word   *	[w]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_next_word(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -250,7 +251,7 @@ vi_next_word(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi change case of character under the cursor and advance one character   *	[~]   */ -protected el_action_t +libedit_private el_action_t  vi_change_case(EditLine *el, wint_t c)  {  	int i; @@ -261,10 +262,10 @@ vi_change_case(EditLine *el, wint_t c)  	for (i = 0; i < el->el_state.argument; i++) {  		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 (iswupper(c)) +			*el->el_line.cursor = towlower(c); +		else if (iswlower(c)) +			*el->el_line.cursor = towupper(c);  		if (++el->el_line.cursor >= el->el_line.lastchar) {  			el->el_line.cursor--; @@ -281,7 +282,7 @@ vi_change_case(EditLine *el, wint_t c)   *	Vi change prefix command   *	[c]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -298,7 +299,7 @@ vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi enter insert mode at the beginning of line   *	[I]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -314,7 +315,7 @@ vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi replace character under the cursor with the next character typed   *	[r]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -333,7 +334,7 @@ vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi enter replace mode   *	[R]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -349,7 +350,7 @@ vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi replace character under the cursor and enter insert mode   *	[s]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -364,7 +365,7 @@ vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi substitute entire line   *	[S]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -382,7 +383,7 @@ vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi change to end of line   *	[C]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -400,7 +401,7 @@ vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi enter insert mode   *	[i]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_insert(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -415,7 +416,7 @@ vi_insert(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi enter insert mode after the cursor   *	[a]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_add(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -440,7 +441,7 @@ vi_add(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi enter insert mode at end of line   *	[A]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -456,7 +457,7 @@ vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi delete prefix command   *	[d]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -469,7 +470,7 @@ vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the end of the current space delimited word   *	[E]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -493,7 +494,7 @@ vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the end of the current word   *	[e]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_end_word(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -517,7 +518,7 @@ vi_end_word(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi undo last change   *	[u]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_undo(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -544,7 +545,7 @@ vi_undo(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi enter command mode (use alternative key bindings)   *	[<ESC>]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -569,7 +570,7 @@ vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the beginning of line   *	[0]   */ -protected el_action_t +libedit_private el_action_t  vi_zero(EditLine *el, wint_t c)  { @@ -589,7 +590,7 @@ vi_zero(EditLine *el, wint_t c)   *	Vi move to previous character (backspace)   *	[^H] in insert mode only   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -607,7 +608,7 @@ vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi list choices for completion or indicate end of file if empty line   *	[^D]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_list_or_eof(EditLine *el, wint_t c)  { @@ -644,11 +645,11 @@ vi_list_or_eof(EditLine *el, wint_t c)   *	Vi cut from beginning of line to cursor   *	[^U]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__)))  { -	Char *kp, *cp; +	wchar_t *kp, *cp;  	cp = el->el_line.buffer;  	kp = el->el_chared.c_kill.buf; @@ -665,7 +666,7 @@ vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi search history previous   *	[?]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -678,7 +679,7 @@ vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi search history next   *	[/]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_search_next(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -691,7 +692,7 @@ vi_search_next(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi repeat current search in the same search direction   *	[n]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -708,7 +709,7 @@ vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__)))   *	[N]   */  /*ARGSUSED*/ -protected el_action_t +libedit_private el_action_t  vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -725,7 +726,7 @@ vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the character specified next   *	[f]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_next_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -737,7 +738,7 @@ vi_next_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move to the character specified previous   *	[F]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -749,7 +750,7 @@ vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move up to the character specified next   *	[t]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -761,7 +762,7 @@ vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi move up to the character specified previous   *	[T]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -773,7 +774,7 @@ vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi repeat current character search in the same search direction   *	[;]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -787,7 +788,7 @@ vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi repeat current character search in the opposite search direction   *	[,]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -805,22 +806,22 @@ vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi go to matching () {} or []   *	[%]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_match(EditLine *el, wint_t c __attribute__((__unused__)))  { -	const Char match_chars[] = STR("()[]{}"); -	Char *cp; +	const wchar_t match_chars[] = L"()[]{}"; +	wchar_t *cp;  	size_t delta, i, count; -	Char o_ch, c_ch; +	wchar_t o_ch, c_ch;  	*el->el_line.lastchar = '\0';		/* just in case */ -	i = Strcspn(el->el_line.cursor, match_chars); +	i = wcscspn(el->el_line.cursor, match_chars);  	o_ch = el->el_line.cursor[i];  	if (o_ch == 0)  		return CC_ERROR; -	delta = (size_t)(Strchr(match_chars, o_ch) - match_chars); +	delta = (size_t)(wcschr(match_chars, o_ch) - match_chars);  	c_ch = match_chars[delta ^ 1];  	count = 1;  	delta = 1 - (delta & 1) * 2; @@ -852,7 +853,7 @@ vi_match(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi undo all changes to line   *	[U]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -866,7 +867,7 @@ vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__)))   *	[|]   * NB netbsd vi goes to screen column 'n', posix says nth character   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_to_column(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -880,7 +881,7 @@ vi_to_column(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi yank to end of line   *	[Y]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -894,7 +895,7 @@ vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi yank   *	[y]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_yank(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -906,7 +907,7 @@ vi_yank(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi comment out current command   *	[#]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -924,7 +925,7 @@ vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__)))   * NB: posix implies that we should enter insert mode, however   * this is against historical precedent...   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_alias(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -942,7 +943,7 @@ vi_alias(EditLine *el, wint_t c __attribute__((__unused__)))  	alias_text = (*el->el_chared.c_aliasfun)(el->el_chared.c_aliasarg,  	    alias_name);  	if (alias_text != NULL) -		FUN(el,push)(el, ct_decode_string(alias_text, &el->el_scratch)); +		el_wpush(el, ct_decode_string(alias_text, &el->el_scratch));  	return CC_NORM;  } @@ -950,7 +951,7 @@ vi_alias(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi go to specified history file line.   *	[G]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -959,7 +960,7 @@ vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__)))  	if (el->el_history.eventno == 0) { -		 (void) Strncpy(el->el_history.buf, el->el_line.buffer, +		 (void) wcsncpy(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); @@ -995,7 +996,7 @@ vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi edit history line with vi   *	[v]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -1006,7 +1007,7 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))  	char tempfile[] = "/tmp/histedit.XXXXXXXXXX";  	char *cp = NULL;  	size_t len; -	Char *line = NULL; +	wchar_t *line = NULL;  	if (el->el_state.doingarg) {  		if (vi_to_history_line(el, 0) == CC_ERROR) @@ -1024,9 +1025,9 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))  	line = el_malloc(len * sizeof(*line) + 1);  	if (line == NULL)  		goto error; -	Strncpy(line, el->el_line.buffer, len); +	wcsncpy(line, el->el_line.buffer, len);  	line[len] = '\0'; -	ct_wcstombs(cp, line, TMP_BUFSIZ - 1); +	wcstombs(cp, line, TMP_BUFSIZ - 1);  	cp[TMP_BUFSIZ - 1] = '\0';  	len = strlen(cp);  	write(fd, cp, len); @@ -1048,7 +1049,7 @@ vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))  		if (st > 0) {  			cp[st] = '\0';  			len = (size_t)(el->el_line.limit - el->el_line.buffer); -			len = ct_mbstowcs(el->el_line.buffer, cp, len); +			len = mbstowcs(el->el_line.buffer, cp, len);  			if (len > 0 && el->el_line.buffer[len - 1] == '\n')  				--len;  		} @@ -1079,33 +1080,33 @@ error:   * Who knows where this one came from!   * '_' in vi means 'entire current line', so 'cc' is a synonym for 'c_'   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_history_word(EditLine *el, wint_t c __attribute__((__unused__)))  { -	const Char *wp = HIST_FIRST(el); -	const Char *wep, *wsp; +	const wchar_t *wp = HIST_FIRST(el); +	const wchar_t *wep, *wsp;  	int len; -	Char *cp; -	const Char *lim; +	wchar_t *cp; +	const wchar_t *lim;  	if (wp == NULL)  		return CC_ERROR; -	wep = wsp = 0; +	wep = wsp = NULL;  	do { -		while (Isspace(*wp)) +		while (iswspace(*wp))  			wp++;  		if (*wp == 0)  			break;  		wsp = wp; -		while (*wp && !Isspace(*wp)) +		while (*wp && !iswspace(*wp))  			wp++;  		wep = wp;  	} while ((!el->el_state.doingarg || --el->el_state.argument > 0)  	    && *wp != 0); -	if (wsp == 0 || (el->el_state.doingarg && el->el_state.argument != 0)) +	if (wsp == NULL || (el->el_state.doingarg && el->el_state.argument != 0))  		return CC_ERROR;  	cv_undo(el); @@ -1129,7 +1130,7 @@ vi_history_word(EditLine *el, wint_t c __attribute__((__unused__)))   *	Vi redo last non-motion command   *	[.]   */ -protected el_action_t +libedit_private el_action_t  /*ARGSUSED*/  vi_redo(EditLine *el, wint_t c __attribute__((__unused__)))  { @@ -1147,7 +1148,7 @@ vi_redo(EditLine *el, wint_t c __attribute__((__unused__)))  			/* sanity */  			r->pos = r->lim - 1;  		r->pos[0] = 0; -		FUN(el,push)(el, r->buf); +		el_wpush(el, r->buf);  	}  	el->el_state.thiscmd = r->cmd; | 
