Updated libedit to NetBSD upstream
Note: This unconditionally assumes wchar_t support. May need revision if some platforms prove problematic.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* $NetBSD: emacs.c,v 1.23 2009/12/30 22:37:40 christos Exp $ */
|
||||
/* $NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@@ -37,37 +37,41 @@
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: emacs.c,v 1.23 2009/12/30 22:37:40 christos Exp $");
|
||||
__RCSID("$NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
/*
|
||||
* emacs.c: Emacs functions
|
||||
*/
|
||||
#include <ctype.h>
|
||||
|
||||
#include "el.h"
|
||||
#include "emacs.h"
|
||||
#include "fcns.h"
|
||||
|
||||
/* em_delete_or_list():
|
||||
* Delete character under cursor or list completions if at end of line
|
||||
* [^D]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_delete_or_list(EditLine *el, Int c)
|
||||
em_delete_or_list(EditLine *el, wint_t c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor == el->el_line.lastchar) {
|
||||
/* if I'm at the end */
|
||||
if (el->el_line.cursor == el->el_line.buffer) {
|
||||
/* and the beginning */
|
||||
term_writec(el, c); /* then do an EOF */
|
||||
return (CC_EOF);
|
||||
terminal_writec(el, c); /* then do an 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 {
|
||||
if (el->el_state.doingarg)
|
||||
@@ -77,7 +81,7 @@ em_delete_or_list(EditLine *el, Int c)
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
/* bounds check */
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,14 +90,14 @@ em_delete_or_list(EditLine *el, Int c)
|
||||
* Cut from cursor to end of current word
|
||||
* [M-d]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_delete_next_word(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_delete_next_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *cp, *p, *kp;
|
||||
wchar_t *cp, *p, *kp;
|
||||
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
|
||||
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
|
||||
el->el_state.argument, ce__isword);
|
||||
@@ -107,7 +111,7 @@ em_delete_next_word(EditLine *el, Int c __attribute__((__unused__)))
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
/* bounds check */
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
@@ -115,19 +119,19 @@ em_delete_next_word(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Paste cut buffer at cursor position
|
||||
* [^Y]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_yank(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_yank(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *kp, *cp;
|
||||
wchar_t *kp, *cp;
|
||||
|
||||
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
|
||||
return (CC_NORM);
|
||||
return CC_NORM;
|
||||
|
||||
if (el->el_line.lastchar +
|
||||
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
|
||||
el->el_line.limit)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
|
||||
el->el_chared.c_kill.mark = el->el_line.cursor;
|
||||
cp = el->el_line.cursor;
|
||||
@@ -143,7 +147,7 @@ em_yank(EditLine *el, Int c __attribute__((__unused__)))
|
||||
if (el->el_state.argument == 1)
|
||||
el->el_line.cursor = cp;
|
||||
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
@@ -151,11 +155,11 @@ em_yank(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Cut the entire line and save in cut buffer
|
||||
* [^U]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_kill_line(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_kill_line(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;
|
||||
@@ -165,7 +169,7 @@ em_kill_line(EditLine *el, Int c __attribute__((__unused__)))
|
||||
/* zap! -- delete all of it */
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
@@ -173,14 +177,14 @@ em_kill_line(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Cut area between mark and cursor and save in cut buffer
|
||||
* [^W]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_kill_region(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_kill_region(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *kp, *cp;
|
||||
wchar_t *kp, *cp;
|
||||
|
||||
if (!el->el_chared.c_kill.mark)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
|
||||
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
|
||||
cp = el->el_line.cursor;
|
||||
@@ -198,7 +202,7 @@ em_kill_region(EditLine *el, Int c __attribute__((__unused__)))
|
||||
c_delbefore(el, (int)(cp - el->el_chared.c_kill.mark));
|
||||
el->el_line.cursor = el->el_chared.c_kill.mark;
|
||||
}
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
@@ -206,14 +210,14 @@ em_kill_region(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Copy area between mark and cursor to cut buffer
|
||||
* [M-W]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_copy_region(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_copy_region(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *kp, *cp;
|
||||
wchar_t *kp, *cp;
|
||||
|
||||
if (!el->el_chared.c_kill.mark)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
|
||||
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
|
||||
cp = el->el_line.cursor;
|
||||
@@ -228,7 +232,7 @@ em_copy_region(EditLine *el, Int c __attribute__((__unused__)))
|
||||
*kp++ = *cp++; /* copy it */
|
||||
el->el_chared.c_kill.last = kp;
|
||||
}
|
||||
return (CC_NORM);
|
||||
return CC_NORM;
|
||||
}
|
||||
|
||||
|
||||
@@ -236,8 +240,8 @@ em_copy_region(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Exchange the two characters before the cursor
|
||||
* Gosling emacs transpose chars [^T]
|
||||
*/
|
||||
protected el_action_t
|
||||
em_gosmacs_transpose(EditLine *el, Int c)
|
||||
libedit_private el_action_t
|
||||
em_gosmacs_transpose(EditLine *el, wint_t c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor > &el->el_line.buffer[1]) {
|
||||
@@ -245,9 +249,9 @@ em_gosmacs_transpose(EditLine *el, Int c)
|
||||
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);
|
||||
return CC_REFRESH;
|
||||
} else
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -255,12 +259,12 @@ em_gosmacs_transpose(EditLine *el, Int c)
|
||||
* Move next to end of current word
|
||||
* [M-f]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_next_word(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_next_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
|
||||
el->el_line.cursor = c__next_word(el->el_line.cursor,
|
||||
el->el_line.lastchar,
|
||||
@@ -270,9 +274,9 @@ em_next_word(EditLine *el, Int c __attribute__((__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;
|
||||
}
|
||||
|
||||
|
||||
@@ -280,23 +284,23 @@ em_next_word(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Uppercase the characters from cursor to end of current word
|
||||
* [M-u]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_upper_case(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_upper_case(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *cp, *ep;
|
||||
wchar_t *cp, *ep;
|
||||
|
||||
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
|
||||
el->el_state.argument, ce__isword);
|
||||
|
||||
for (cp = el->el_line.cursor; cp < ep; cp++)
|
||||
if (Islower(*cp))
|
||||
*cp = Toupper(*cp);
|
||||
if (iswlower(*cp))
|
||||
*cp = towupper(*cp);
|
||||
|
||||
el->el_line.cursor = ep;
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
@@ -304,31 +308,31 @@ em_upper_case(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Capitalize the characters from cursor to end of current word
|
||||
* [M-c]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_capitol_case(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_capitol_case(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *cp, *ep;
|
||||
wchar_t *cp, *ep;
|
||||
|
||||
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
|
||||
el->el_state.argument, ce__isword);
|
||||
|
||||
for (cp = el->el_line.cursor; cp < ep; cp++) {
|
||||
if (Isalpha(*cp)) {
|
||||
if (Islower(*cp))
|
||||
*cp = Toupper(*cp);
|
||||
if (iswalpha(*cp)) {
|
||||
if (iswlower(*cp))
|
||||
*cp = towupper(*cp);
|
||||
cp++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; cp < ep; cp++)
|
||||
if (Isupper(*cp))
|
||||
*cp = Tolower(*cp);
|
||||
if (iswupper(*cp))
|
||||
*cp = towlower(*cp);
|
||||
|
||||
el->el_line.cursor = ep;
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
@@ -336,23 +340,23 @@ em_capitol_case(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Lowercase the characters from cursor to end of current word
|
||||
* [M-l]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_lower_case(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_lower_case(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *cp, *ep;
|
||||
wchar_t *cp, *ep;
|
||||
|
||||
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
|
||||
el->el_state.argument, ce__isword);
|
||||
|
||||
for (cp = el->el_line.cursor; cp < ep; cp++)
|
||||
if (Isupper(*cp))
|
||||
*cp = Tolower(*cp);
|
||||
if (iswupper(*cp))
|
||||
*cp = towlower(*cp);
|
||||
|
||||
el->el_line.cursor = ep;
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
@@ -360,13 +364,13 @@ em_lower_case(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Set the mark at cursor
|
||||
* [^@]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_set_mark(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_set_mark(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
|
||||
el->el_chared.c_kill.mark = el->el_line.cursor;
|
||||
return (CC_NORM);
|
||||
return CC_NORM;
|
||||
}
|
||||
|
||||
|
||||
@@ -374,16 +378,16 @@ em_set_mark(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Exchange the cursor and mark
|
||||
* [^X^X]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_exchange_mark(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_exchange_mark(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *cp;
|
||||
wchar_t *cp;
|
||||
|
||||
cp = el->el_line.cursor;
|
||||
el->el_line.cursor = el->el_chared.c_kill.mark;
|
||||
el->el_chared.c_kill.mark = cp;
|
||||
return (CC_CURSOR);
|
||||
return CC_CURSOR;
|
||||
}
|
||||
|
||||
|
||||
@@ -391,16 +395,16 @@ em_exchange_mark(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Universal argument (argument times 4)
|
||||
* [^U]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_universal_argument(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_universal_argument(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{ /* multiply current argument by 4 */
|
||||
|
||||
if (el->el_state.argument > 1000000)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
el->el_state.doingarg = 1;
|
||||
el->el_state.argument *= 4;
|
||||
return (CC_ARGHACK);
|
||||
return CC_ARGHACK;
|
||||
}
|
||||
|
||||
|
||||
@@ -408,41 +412,41 @@ em_universal_argument(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Add 8th bit to next character typed
|
||||
* [<ESC>]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_meta_next(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_meta_next(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
|
||||
el->el_state.metanext = 1;
|
||||
return (CC_ARGHACK);
|
||||
return CC_ARGHACK;
|
||||
}
|
||||
|
||||
|
||||
/* em_toggle_overwrite():
|
||||
* Switch from insert to overwrite mode or vice versa
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_toggle_overwrite(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_toggle_overwrite(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
|
||||
el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
|
||||
MODE_REPLACE : MODE_INSERT;
|
||||
return (CC_NORM);
|
||||
return CC_NORM;
|
||||
}
|
||||
|
||||
|
||||
/* em_copy_prev_word():
|
||||
* Copy current word to cursor
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_copy_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
Char *cp, *oldc, *dp;
|
||||
wchar_t *cp, *oldc, *dp;
|
||||
|
||||
if (el->el_line.cursor == el->el_line.buffer)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
|
||||
oldc = el->el_line.cursor;
|
||||
/* does a bounds check */
|
||||
@@ -455,33 +459,33 @@ em_copy_prev_word(EditLine *el, Int c __attribute__((__unused__)))
|
||||
|
||||
el->el_line.cursor = dp;/* put cursor at end */
|
||||
|
||||
return (CC_REFRESH);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
||||
|
||||
/* em_inc_search_next():
|
||||
* Emacs incremental next search
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_inc_search_next(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_inc_search_next(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
|
||||
el->el_search.patlen = 0;
|
||||
return (ce_inc_search(el, ED_SEARCH_NEXT_HISTORY));
|
||||
return ce_inc_search(el, ED_SEARCH_NEXT_HISTORY);
|
||||
}
|
||||
|
||||
|
||||
/* em_inc_search_prev():
|
||||
* Emacs incremental reverse search
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_inc_search_prev(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_inc_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
|
||||
el->el_search.patlen = 0;
|
||||
return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
|
||||
return ce_inc_search(el, ED_SEARCH_PREV_HISTORY);
|
||||
}
|
||||
|
||||
|
||||
@@ -489,13 +493,13 @@ em_inc_search_prev(EditLine *el, Int c __attribute__((__unused__)))
|
||||
* Delete the character to the left of the cursor
|
||||
* [^?]
|
||||
*/
|
||||
protected el_action_t
|
||||
libedit_private el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
|
||||
em_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
|
||||
{
|
||||
|
||||
if (el->el_line.cursor <= el->el_line.buffer)
|
||||
return (CC_ERROR);
|
||||
return CC_ERROR;
|
||||
|
||||
if (el->el_state.doingarg)
|
||||
c_delbefore(el, el->el_state.argument);
|
||||
@@ -504,5 +508,5 @@ em_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
|
||||
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);
|
||||
return CC_REFRESH;
|
||||
}
|
||||
|
Reference in New Issue
Block a user