+ Sync with NetBSD, bringing in feature enhancements.
+ Convert to ANSI-C function definitions + style(9) Submitted by: kris
This commit is contained in:
parent
c3aa3459b1
commit
3c19577344
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=84260
@ -1,8 +1,9 @@
|
||||
# $NetBSD: Makefile,v 1.19 2000/08/15 12:01:40 mrg Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/4/93
|
||||
# $FreeBSD$
|
||||
|
||||
LIB= edit
|
||||
SHLIB_MAJOR= 3
|
||||
SHLIB_MAJOR= 4
|
||||
SHLIB_MINOR= 0
|
||||
|
||||
OSRCS= chared.c common.c el.c emacs.c fcns.c help.c hist.c key.c map.c \
|
||||
@ -14,12 +15,13 @@ LDADD= -ltermcap
|
||||
MAN= editline.3 editrc.5
|
||||
|
||||
MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \
|
||||
editline.3 el_get.3 \
|
||||
editline.3 el_gets.3 editline.3 el_getc.3 editline.3 el_push.3 \
|
||||
editline.3 el_parse.3 editline.3 el_set.3 editline.3 el_source.3 \
|
||||
editline.3 el_resize.3 editline.3 el_line.3 \
|
||||
editline.3 el_insertstr.3 editline.3 el_deletestr.3 \
|
||||
editline.3 history_init.3 editline.3 history_end.3 \
|
||||
editline.3 history.3 editline.3 el_data_get.3 editline.3 el_data_set.3
|
||||
editline.3 history.3
|
||||
|
||||
# For speed and debugging
|
||||
#SRCS= ${OSRCS} tokenizer.c history.c
|
||||
@ -27,6 +29,7 @@ MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \
|
||||
SRCS= editline.c tokenizer.c history.c
|
||||
|
||||
SRCS+= common.h emacs.h fcns.h help.h vi.h
|
||||
INCS= histedit.h
|
||||
|
||||
CLEANFILES+=common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h
|
||||
CFLAGS+=-I. -I${.CURDIR}
|
||||
@ -57,11 +60,14 @@ help.c: ${ASRC} makelist
|
||||
help.h: ${ASRC} makelist
|
||||
sh ${.CURDIR}/makelist -bh ${ASRC} > ${.TARGET}
|
||||
|
||||
editline.c:
|
||||
sh ${.CURDIR}/makelist -e ${OSRCS} > ${.TARGET}
|
||||
editline.c: ${OSRCS}
|
||||
sh ${.CURDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET}
|
||||
|
||||
beforedepend editline.o editline.po editline.So: \
|
||||
vi.h emacs.h common.h fcns.h fcns.c help.h help.c
|
||||
# minimal dependency to make "make depend" optional
|
||||
editline.o editline.po editline.So editline.ln: \
|
||||
common.h emacs.h fcns.c fcns.h help.c help.h vi.h
|
||||
|
||||
test.o: ${.CURDIR}/TEST/test.c
|
||||
|
||||
test: test.o libedit.a ${DPADD} ${LIBTERMCAP}
|
||||
${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD}
|
||||
|
@ -34,15 +34,17 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
static char copyright[] =
|
||||
"@(#) Copyright (c) 1992, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n");
|
||||
#endif /* not lint */
|
||||
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
__RCSID("$NetBSD: test.c,v 1.8 1999/09/21 00:07:03 lukem Exp $");
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* test.c: A little test program
|
||||
@ -63,29 +65,30 @@ static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
|
||||
static int continuation = 0;
|
||||
static EditLine *el = NULL;
|
||||
|
||||
static u_char complete(EditLine *, int);
|
||||
int main(int, char **);
|
||||
static char *prompt(EditLine *);
|
||||
static void sig(int);
|
||||
|
||||
static char *
|
||||
/*ARGSUSED*/
|
||||
prompt(el)
|
||||
EditLine *el;
|
||||
prompt(EditLine *el)
|
||||
{
|
||||
static char a[] = "Edit$";
|
||||
static char b[] = "Edit>";
|
||||
return continuation ? b : a;
|
||||
|
||||
return (continuation ? b : a);
|
||||
}
|
||||
|
||||
static void
|
||||
sig(i)
|
||||
int i;
|
||||
sig(int i)
|
||||
{
|
||||
|
||||
(void) fprintf(stderr, "Got signal %d.\n", i);
|
||||
el_reset(el);
|
||||
}
|
||||
|
||||
static unsigned char
|
||||
/*ARGSUSED*/
|
||||
complete(el, ch)
|
||||
EditLine *el;
|
||||
int ch;
|
||||
complete(EditLine *el, int ch)
|
||||
{
|
||||
DIR *dd = opendir(".");
|
||||
struct dirent *dp;
|
||||
@ -106,26 +109,25 @@ complete(el, ch)
|
||||
if (strncmp(dp->d_name, ptr, len) == 0) {
|
||||
closedir(dd);
|
||||
if (el_insertstr(el, &dp->d_name[len]) == -1)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
else
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
}
|
||||
|
||||
closedir(dd);
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
int
|
||||
/*ARGSUSED*/
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int num;
|
||||
const char *buf;
|
||||
Tokenizer *tok;
|
||||
int lastevent = 0, ncontinuation;
|
||||
History *hist;
|
||||
HistEvent ev;
|
||||
|
||||
(void) signal(SIGINT, sig);
|
||||
(void) signal(SIGQUIT, sig);
|
||||
@ -133,11 +135,13 @@ main(argc, argv)
|
||||
(void) signal(SIGTERM, sig);
|
||||
|
||||
hist = history_init(); /* Init the builtin history */
|
||||
history(hist, H_EVENT, 100); /* Remember 100 events */
|
||||
/* Remember 100 events */
|
||||
history(hist, &ev, H_SETSIZE, 100);
|
||||
|
||||
tok = tok_init(NULL); /* Initialize the tokenizer */
|
||||
|
||||
el = el_init(*argv, stdin, stdout); /* Initialize editline */
|
||||
/* Initialize editline */
|
||||
el = el_init(*argv, stdin, stdout, stderr);
|
||||
|
||||
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
|
||||
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
|
||||
@ -149,7 +153,8 @@ main(argc, argv)
|
||||
/* Add a user-defined function */
|
||||
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
|
||||
|
||||
el_set(el, EL_BIND, "^I", "ed-complete", NULL);/* Bind tab to it */
|
||||
/* Bind tab to it */
|
||||
el_set(el, EL_BIND, "^I", "ed-complete", NULL);
|
||||
|
||||
/*
|
||||
* Bind j, k in vi command mode to previous and next line, instead
|
||||
@ -171,46 +176,63 @@ main(argc, argv)
|
||||
#endif
|
||||
if (!continuation && num == 1)
|
||||
continue;
|
||||
if (tok_line(tok, buf, &ac, &av) > 0) {
|
||||
history(hist, continuation ? H_ADD : H_ENTER, buf);
|
||||
continuation = 1;
|
||||
continue;
|
||||
}
|
||||
history(hist, continuation ? H_ADD : H_ENTER, buf);
|
||||
|
||||
continuation = 0;
|
||||
if (tok_line(tok, buf, &ac, &av) > 0)
|
||||
ncontinuation = 1;
|
||||
|
||||
#if 0
|
||||
if (continuation) {
|
||||
/*
|
||||
* Append to the right event in case the user
|
||||
* moved around in history.
|
||||
*/
|
||||
if (history(hist, &ev, H_SET, lastevent) == -1)
|
||||
err(1, "%d: %s\n", lastevent, ev.str);
|
||||
history(hist, &ev, H_ADD , buf);
|
||||
} else {
|
||||
history(hist, &ev, H_ENTER, buf);
|
||||
lastevent = ev.num;
|
||||
}
|
||||
#else
|
||||
/* Simpler */
|
||||
history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
|
||||
#endif
|
||||
|
||||
continuation = ncontinuation;
|
||||
ncontinuation = 0;
|
||||
|
||||
if (strcmp(av[0], "history") == 0) {
|
||||
const struct HistEvent *he;
|
||||
int rv;
|
||||
|
||||
switch (ac) {
|
||||
case 1:
|
||||
for (he = history(hist, H_LAST); he;
|
||||
he = history(hist, H_PREV))
|
||||
(void) fprintf(stdout, "%4d %s", he->num, he->str);
|
||||
for (rv = history(hist, &ev, H_LAST); rv != -1;
|
||||
rv = history(hist, &ev, H_PREV))
|
||||
(void) fprintf(stdout, "%4d %s",
|
||||
ev.num, ev.str);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if (strcmp(av[1], "clear") == 0)
|
||||
history(hist, H_CLEAR);
|
||||
history(hist, &ev, H_CLEAR);
|
||||
else
|
||||
goto badhist;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if (strcmp(av[1], "load") == 0)
|
||||
history(hist, H_LOAD, av[2]);
|
||||
history(hist, &ev, H_LOAD, av[2]);
|
||||
else if (strcmp(av[1], "save") == 0)
|
||||
history(hist, H_SAVE, av[2]);
|
||||
history(hist, &ev, H_SAVE, av[2]);
|
||||
break;
|
||||
|
||||
badhist:
|
||||
default:
|
||||
(void) fprintf(stderr, "Bad history arguments\n");
|
||||
(void) fprintf(stderr,
|
||||
"Bad history arguments\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (el_parse(el, ac, av) == -1) {
|
||||
} else if (el_parse(el, ac, av) == -1) {
|
||||
switch (fork()) {
|
||||
case 0:
|
||||
execvp(av[0], av);
|
||||
@ -230,6 +252,7 @@ main(argc, argv)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tok_reset(tok);
|
||||
}
|
||||
|
||||
@ -237,5 +260,5 @@ main(argc, argv)
|
||||
tok_end(tok);
|
||||
history_end(hist);
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
@ -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: chared.c,v 1.13 2001/04/13 01:04:19 lukem Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* chared.c: Character editor utilities
|
||||
@ -48,14 +52,14 @@ static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <stdlib.h>
|
||||
#include "el.h"
|
||||
|
||||
/* value to leave unused in line buffer */
|
||||
#define EL_LEAVE 2
|
||||
|
||||
/* cv_undo():
|
||||
* Handle state for the vi undo command
|
||||
*/
|
||||
protected void
|
||||
cv_undo(el, action, size, ptr)
|
||||
EditLine *el;
|
||||
int action, size;
|
||||
char *ptr;
|
||||
cv_undo(EditLine *el,int action, size_t size, char *ptr)
|
||||
{
|
||||
c_undo_t *vu = &el->el_chared.c_undo;
|
||||
vu->action = action;
|
||||
@ -73,9 +77,7 @@ cv_undo(el, action, size, ptr)
|
||||
* Insert num characters
|
||||
*/
|
||||
protected void
|
||||
c_insert(el, num)
|
||||
EditLine *el;
|
||||
int num;
|
||||
c_insert(EditLine *el, int num)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
@ -88,16 +90,14 @@ c_insert(el, num)
|
||||
cp[num] = *cp;
|
||||
}
|
||||
el->el_line.lastchar += num;
|
||||
} /* end c_insert */
|
||||
}
|
||||
|
||||
|
||||
/* c_delafter():
|
||||
* Delete num characters after the cursor
|
||||
*/
|
||||
protected void
|
||||
c_delafter(el, num)
|
||||
EditLine *el;
|
||||
int num;
|
||||
c_delafter(EditLine *el, int num)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor + num > el->el_line.lastchar)
|
||||
@ -107,7 +107,7 @@ c_delafter(el, num)
|
||||
char *cp;
|
||||
|
||||
if (el->el_map.current != el->el_map.emacs)
|
||||
cv_undo(el, INSERT, num, el->el_line.cursor);
|
||||
cv_undo(el, INSERT, (size_t)num, el->el_line.cursor);
|
||||
|
||||
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
|
||||
*cp = cp[num];
|
||||
@ -121,9 +121,7 @@ c_delafter(el, num)
|
||||
* Delete num characters before the cursor
|
||||
*/
|
||||
protected void
|
||||
c_delbefore(el, num)
|
||||
EditLine *el;
|
||||
int num;
|
||||
c_delbefore(EditLine *el, int num)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor - num < el->el_line.buffer)
|
||||
@ -133,9 +131,12 @@ c_delbefore(el, num)
|
||||
char *cp;
|
||||
|
||||
if (el->el_map.current != el->el_map.emacs)
|
||||
cv_undo(el, INSERT, num, el->el_line.cursor - num);
|
||||
cv_undo(el, INSERT, (size_t)num,
|
||||
el->el_line.cursor - num);
|
||||
|
||||
for (cp = el->el_line.cursor - num; cp <= el->el_line.lastchar; cp++)
|
||||
for (cp = el->el_line.cursor - num;
|
||||
cp <= el->el_line.lastchar;
|
||||
cp++)
|
||||
*cp = cp[num];
|
||||
|
||||
el->el_line.lastchar -= num;
|
||||
@ -147,10 +148,9 @@ c_delbefore(el, num)
|
||||
* Return if p is part of a word according to emacs
|
||||
*/
|
||||
protected int
|
||||
ce__isword(p)
|
||||
int p;
|
||||
ce__isword(int p)
|
||||
{
|
||||
return isalpha((unsigned char) p) || isdigit((unsigned char) p) || strchr("*?_-.[]~=", p) != NULL;
|
||||
return (isalpha((unsigned char)p) || isdigit((unsigned char)p) || strchr("*?_-.[]~=", p) != NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -158,8 +158,7 @@ ce__isword(p)
|
||||
* Return type of word for p according to vi
|
||||
*/
|
||||
protected int
|
||||
cv__isword(p)
|
||||
int p;
|
||||
cv__isword(int p)
|
||||
{
|
||||
if (isspace((unsigned char) p))
|
||||
return 0;
|
||||
@ -184,10 +183,7 @@ c___isword(p)
|
||||
* Find the previous word
|
||||
*/
|
||||
protected char *
|
||||
c__prev_word(p, low, n, wtest)
|
||||
register char *p, *low;
|
||||
register int n;
|
||||
int (*wtest) __P((int));
|
||||
c__prev_word(char *p, char *low, int n, int (*wtest)(int))
|
||||
{
|
||||
p--;
|
||||
|
||||
@ -203,7 +199,7 @@ c__prev_word(p, low, n, wtest)
|
||||
if (p < low)
|
||||
p = low;
|
||||
/* cp now points where we want it */
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
|
||||
|
||||
@ -211,10 +207,7 @@ c__prev_word(p, low, n, wtest)
|
||||
* Find the next word
|
||||
*/
|
||||
protected char *
|
||||
c__next_word(p, high, n, wtest)
|
||||
register char *p, *high;
|
||||
register int n;
|
||||
int (*wtest) __P((int));
|
||||
c__next_word(char *p, char *high, int n, int (*wtest)(int))
|
||||
{
|
||||
while (n--) {
|
||||
while ((p < high) && !(*wtest)((unsigned char) *p))
|
||||
@ -225,18 +218,14 @@ c__next_word(p, high, n, wtest)
|
||||
if (p > high)
|
||||
p = high;
|
||||
/* p now points where we want it */
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
|
||||
/* cv_next_word():
|
||||
* Find the next word vi style
|
||||
*/
|
||||
protected char *
|
||||
cv_next_word(el, p, high, n, wtest)
|
||||
EditLine *el;
|
||||
register char *p, *high;
|
||||
register int n;
|
||||
int (*wtest) __P((int));
|
||||
cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int))
|
||||
{
|
||||
int test;
|
||||
|
||||
@ -255,9 +244,9 @@ cv_next_word(el, p, high, n, wtest)
|
||||
|
||||
/* p now points where we want it */
|
||||
if (p > high)
|
||||
return high;
|
||||
return (high);
|
||||
else
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
|
||||
|
||||
@ -265,11 +254,7 @@ cv_next_word(el, p, high, n, wtest)
|
||||
* Find the previous word vi style
|
||||
*/
|
||||
protected char *
|
||||
cv_prev_word(el, p, low, n, wtest)
|
||||
EditLine *el;
|
||||
register char *p, *low;
|
||||
register int n;
|
||||
int (*wtest) __P((int));
|
||||
cv_prev_word(EditLine *el, char *p, char *low, int n, int (*wtest)(int))
|
||||
{
|
||||
int test;
|
||||
|
||||
@ -292,9 +277,9 @@ cv_prev_word(el, p, low, n, wtest)
|
||||
|
||||
/* p now points where we want it */
|
||||
if (p < low)
|
||||
return low;
|
||||
return (low);
|
||||
else
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
|
||||
|
||||
@ -305,22 +290,22 @@ cv_prev_word(el, p, low, n, wtest)
|
||||
* Return p pointing to last char used.
|
||||
*/
|
||||
protected char *
|
||||
c__number(p, num, dval)
|
||||
char *p; /* character position */
|
||||
int *num; /* Return value */
|
||||
int dval; /* dval is the number to subtract from like $-3 */
|
||||
c__number(
|
||||
char *p, /* character position */
|
||||
int *num, /* Return value */
|
||||
int dval) /* dval is the number to subtract from like $-3 */
|
||||
{
|
||||
register int i;
|
||||
register int sign = 1;
|
||||
int i;
|
||||
int sign = 1;
|
||||
|
||||
if (*++p == '^') {
|
||||
*num = 1;
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
if (*p == '$') {
|
||||
if (*++p != '-') {
|
||||
*num = 0x7fffffff; /* Handle $ */
|
||||
return --p;
|
||||
return (--p);
|
||||
}
|
||||
sign = -1; /* Handle $- */
|
||||
++p;
|
||||
@ -328,7 +313,7 @@ c__number(p, num, dval)
|
||||
for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0')
|
||||
continue;
|
||||
*num = (sign < 0 ? dval - i : i);
|
||||
return --p;
|
||||
return (--p);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -336,10 +321,9 @@ c__number(p, num, dval)
|
||||
* Finish vi delete action
|
||||
*/
|
||||
protected void
|
||||
cv_delfini(el)
|
||||
EditLine *el;
|
||||
cv_delfini(EditLine *el)
|
||||
{
|
||||
register int size;
|
||||
int size;
|
||||
int oaction;
|
||||
|
||||
if (el->el_chared.c_vcmd.action & INSERT)
|
||||
@ -357,12 +341,10 @@ cv_delfini(el)
|
||||
c_delbefore(el, size);
|
||||
el->el_line.cursor = el->el_chared.c_vcmd.pos;
|
||||
re_refresh_cursor(el);
|
||||
}
|
||||
else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) {
|
||||
} else if (el->el_line.cursor < el->el_chared.c_vcmd.pos) {
|
||||
size = (int)(el->el_chared.c_vcmd.pos - el->el_line.cursor);
|
||||
c_delafter(el, size);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
size = 1;
|
||||
c_delafter(el, size);
|
||||
}
|
||||
@ -376,7 +358,7 @@ cv_delfini(el)
|
||||
case NOP:
|
||||
case INSERT:
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad oaction %d\n", oaction));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -391,9 +373,7 @@ cv_delfini(el)
|
||||
* Go to the end of this word according to emacs
|
||||
*/
|
||||
protected char *
|
||||
ce__endword(p, high, n)
|
||||
char *p, *high;
|
||||
int n;
|
||||
ce__endword(char *p, char *high, int n)
|
||||
{
|
||||
p++;
|
||||
|
||||
@ -405,7 +385,7 @@ ce__endword(p, high, n)
|
||||
}
|
||||
|
||||
p--;
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -414,9 +394,7 @@ ce__endword(p, high, n)
|
||||
* Go to the end of this word according to vi
|
||||
*/
|
||||
protected char *
|
||||
cv__endword(p, high, n)
|
||||
char *p, *high;
|
||||
int n;
|
||||
cv__endword(char *p, char *high, int n)
|
||||
{
|
||||
p++;
|
||||
|
||||
@ -433,23 +411,27 @@ cv__endword(p, high, n)
|
||||
p++;
|
||||
}
|
||||
p--;
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
|
||||
/* ch_init():
|
||||
* Initialize the character editor
|
||||
*/
|
||||
protected int
|
||||
ch_init(el)
|
||||
EditLine *el;
|
||||
ch_init(EditLine *el)
|
||||
{
|
||||
el->el_line.buffer = (char *) el_malloc(EL_BUFSIZ);
|
||||
if (el->el_line.buffer == NULL)
|
||||
return (-1);
|
||||
|
||||
(void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - 2];
|
||||
|
||||
el->el_chared.c_undo.buf = (char *) el_malloc(EL_BUFSIZ);
|
||||
if (el->el_chared.c_undo.buf == NULL)
|
||||
return (-1);
|
||||
(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
|
||||
el->el_chared.c_undo.action = NOP;
|
||||
el->el_chared.c_undo.isize = 0;
|
||||
@ -461,6 +443,8 @@ ch_init(el)
|
||||
el->el_chared.c_vcmd.ins = el->el_line.buffer;
|
||||
|
||||
el->el_chared.c_kill.buf = (char *) el_malloc(EL_BUFSIZ);
|
||||
if (el->el_chared.c_kill.buf == NULL)
|
||||
return (-1);
|
||||
(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ);
|
||||
el->el_chared.c_kill.mark = el->el_line.buffer;
|
||||
el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
|
||||
@ -477,15 +461,16 @@ ch_init(el)
|
||||
el->el_chared.c_macro.level = -1;
|
||||
el->el_chared.c_macro.macro = (char **) el_malloc(EL_MAXMACRO *
|
||||
sizeof(char *));
|
||||
return 0;
|
||||
if (el->el_chared.c_macro.macro == NULL)
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* ch_reset():
|
||||
* Reset the character editor
|
||||
*/
|
||||
protected void
|
||||
ch_reset(el)
|
||||
EditLine *el;
|
||||
ch_reset(EditLine *el)
|
||||
{
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
@ -514,13 +499,89 @@ ch_reset(el)
|
||||
el->el_history.eventno = 0;
|
||||
}
|
||||
|
||||
/* ch_enlargebufs():
|
||||
* Enlarge line buffer to be able to hold twice as much characters.
|
||||
* Returns 1 if successful, 0 if not.
|
||||
*/
|
||||
protected int
|
||||
ch_enlargebufs(el, addlen)
|
||||
EditLine *el;
|
||||
size_t addlen;
|
||||
{
|
||||
size_t sz, newsz;
|
||||
char *newbuffer, *oldbuf, *oldkbuf;
|
||||
|
||||
sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
|
||||
newsz = sz * 2;
|
||||
/*
|
||||
* If newly required length is longer than current buffer, we need
|
||||
* to make the buffer big enough to hold both old and new stuff.
|
||||
*/
|
||||
if (addlen > sz) {
|
||||
while(newsz - sz < addlen)
|
||||
newsz *= 2;
|
||||
}
|
||||
|
||||
/*
|
||||
* Reallocate line buffer.
|
||||
*/
|
||||
newbuffer = el_realloc(el->el_line.buffer, newsz);
|
||||
if (!newbuffer)
|
||||
return 0;
|
||||
|
||||
/* zero the newly added memory, leave old data in */
|
||||
(void) memset(&newbuffer[sz], 0, newsz - sz);
|
||||
|
||||
oldbuf = el->el_line.buffer;
|
||||
|
||||
el->el_line.buffer = newbuffer;
|
||||
el->el_line.cursor = newbuffer + (el->el_line.cursor - oldbuf);
|
||||
el->el_line.lastchar = newbuffer + (el->el_line.lastchar - oldbuf);
|
||||
el->el_line.limit = &newbuffer[newsz - EL_LEAVE];
|
||||
|
||||
/*
|
||||
* Reallocate kill buffer.
|
||||
*/
|
||||
newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
|
||||
if (!newbuffer)
|
||||
return 0;
|
||||
|
||||
/* zero the newly added memory, leave old data in */
|
||||
(void) memset(&newbuffer[sz], 0, newsz - sz);
|
||||
|
||||
oldkbuf = el->el_chared.c_kill.buf;
|
||||
|
||||
el->el_chared.c_kill.buf = newbuffer;
|
||||
el->el_chared.c_kill.last = newbuffer +
|
||||
(el->el_chared.c_kill.last - oldkbuf);
|
||||
el->el_chared.c_kill.mark = el->el_line.buffer +
|
||||
(el->el_chared.c_kill.mark - oldbuf);
|
||||
|
||||
/*
|
||||
* Reallocate undo buffer.
|
||||
*/
|
||||
newbuffer = el_realloc(el->el_chared.c_undo.buf, newsz);
|
||||
if (!newbuffer)
|
||||
return 0;
|
||||
|
||||
/* zero the newly added memory, leave old data in */
|
||||
(void) memset(&newbuffer[sz], 0, newsz - sz);
|
||||
|
||||
el->el_chared.c_undo.ptr = el->el_line.buffer +
|
||||
(el->el_chared.c_undo.ptr - oldbuf);
|
||||
el->el_chared.c_undo.buf = newbuffer;
|
||||
|
||||
if (!hist_enlargebuf(el, sz, newsz))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ch_end():
|
||||
* Free the data structures used by the editor
|
||||
*/
|
||||
protected void
|
||||
ch_end(el)
|
||||
EditLine *el;
|
||||
ch_end(EditLine *el)
|
||||
{
|
||||
el_free((ptr_t) el->el_line.buffer);
|
||||
el->el_line.buffer = NULL;
|
||||
@ -539,21 +600,21 @@ ch_end(el)
|
||||
* Insert string at cursorI
|
||||
*/
|
||||
public int
|
||||
el_insertstr(el, s)
|
||||
EditLine *el;
|
||||
char *s;
|
||||
el_insertstr(EditLine *el, const char *s)
|
||||
{
|
||||
int len;
|
||||
size_t len;
|
||||
|
||||
if ((len = strlen(s)) == 0)
|
||||
return -1;
|
||||
if (el->el_line.lastchar + len >= el->el_line.limit)
|
||||
return -1;
|
||||
return (-1);
|
||||
if (el->el_line.lastchar + len >= el->el_line.limit) {
|
||||
if (!ch_enlargebufs(el, len))
|
||||
return (-1);
|
||||
}
|
||||
|
||||
c_insert(el, len);
|
||||
c_insert(el, (int)len);
|
||||
while (*s)
|
||||
*el->el_line.cursor++ = *s++;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -561,9 +622,7 @@ el_insertstr(el, s)
|
||||
* Delete num characters before the cursor
|
||||
*/
|
||||
public void
|
||||
el_deletestr(el, n)
|
||||
EditLine *el;
|
||||
int n;
|
||||
el_deletestr(EditLine *el, int n)
|
||||
{
|
||||
if (n <= 0)
|
||||
return;
|
||||
@ -581,16 +640,14 @@ el_deletestr(el, n)
|
||||
* Get a string
|
||||
*/
|
||||
protected int
|
||||
c_gets(el, buf)
|
||||
EditLine *el;
|
||||
char *buf;
|
||||
c_gets(EditLine *el, char *buf)
|
||||
{
|
||||
char ch;
|
||||
int len = 0;
|
||||
|
||||
for (ch = 0; ch == 0;) {
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return ed_end_of_file(el, 0);
|
||||
return (ed_end_of_file(el, 0));
|
||||
switch (ch) {
|
||||
case '\010': /* Delete and backspace */
|
||||
case '\177':
|
||||
@ -598,12 +655,11 @@ c_gets(el, buf)
|
||||
*el->el_line.cursor-- = '\0';
|
||||
el->el_line.lastchar = el->el_line.cursor;
|
||||
buf[len--] = '\0';
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
el->el_line.buffer[0] = '\0';
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
re_refresh(el);
|
||||
ch = 0;
|
||||
@ -628,7 +684,7 @@ c_gets(el, buf)
|
||||
}
|
||||
}
|
||||
buf[len] = ch;
|
||||
return len;
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
@ -636,8 +692,7 @@ c_gets(el, buf)
|
||||
* Return the current horizontal position of the cursor
|
||||
*/
|
||||
protected int
|
||||
c_hpos(el)
|
||||
EditLine *el;
|
||||
c_hpos(EditLine *el)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
@ -645,12 +700,12 @@ c_hpos(el)
|
||||
* Find how many characters till the beginning of this line.
|
||||
*/
|
||||
if (el->el_line.cursor == el->el_line.buffer)
|
||||
return 0;
|
||||
return (0);
|
||||
else {
|
||||
for (ptr = el->el_line.cursor - 1;
|
||||
ptr >= el->el_line.buffer && *ptr != '\n';
|
||||
ptr--)
|
||||
continue;
|
||||
return el->el_line.cursor - ptr - 1;
|
||||
return (el->el_line.cursor - ptr - 1);
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)chared.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: chared.h,v 1.5 2000/09/04 22:06:29 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -73,8 +75,8 @@ typedef struct c_macro_t {
|
||||
*/
|
||||
typedef struct c_undo_t {
|
||||
int action;
|
||||
int isize;
|
||||
int dsize;
|
||||
size_t isize;
|
||||
size_t dsize;
|
||||
char *ptr;
|
||||
char *buf;
|
||||
} c_undo_t;
|
||||
@ -134,26 +136,25 @@ typedef struct el_chared_t {
|
||||
#include "fcns.h"
|
||||
|
||||
|
||||
protected int cv__isword __P((int));
|
||||
protected void cv_delfini __P((EditLine *));
|
||||
protected char *cv__endword __P((char *, char *, int));
|
||||
protected int ce__isword __P((int));
|
||||
protected int c___isword __P((int));
|
||||
protected void cv_undo __P((EditLine *, int, int, char *));
|
||||
protected char *cv_next_word __P((EditLine*, char *, char *, int,
|
||||
int (*)(int)));
|
||||
protected char *cv_prev_word __P((EditLine*, char *, char *, int,
|
||||
int (*)(int)));
|
||||
protected char *c__next_word __P((char *, char *, int, int (*)(int)));
|
||||
protected char *c__prev_word __P((char *, char *, int, int (*)(int)));
|
||||
protected void c_insert __P((EditLine *, int));
|
||||
protected void c_delbefore __P((EditLine *, int));
|
||||
protected void c_delafter __P((EditLine *, int));
|
||||
protected int c_gets __P((EditLine *, char *));
|
||||
protected int c_hpos __P((EditLine *));
|
||||
protected int cv__isword(int);
|
||||
protected void cv_delfini(EditLine *);
|
||||
protected char *cv__endword(char *, char *, int);
|
||||
protected int ce__isword(int);
|
||||
protected int c___isword(int);
|
||||
protected void cv_undo(EditLine *, int, size_t, char *);
|
||||
protected char *cv_next_word(EditLine*, char *, char *, int, int (*)(int));
|
||||
protected char *cv_prev_word(EditLine*, char *, char *, int, int (*)(int));
|
||||
protected char *c__next_word(char *, char *, int, int (*)(int));
|
||||
protected char *c__prev_word(char *, char *, int, int (*)(int));
|
||||
protected void c_insert(EditLine *, int);
|
||||
protected void c_delbefore(EditLine *, int);
|
||||
protected void c_delafter(EditLine *, int);
|
||||
protected int c_gets(EditLine *, char *);
|
||||
protected int c_hpos(EditLine *);
|
||||
|
||||
protected int ch_init __P((EditLine *));
|
||||
protected void ch_reset __P((EditLine *));
|
||||
protected void ch_end __P((EditLine *));
|
||||
protected int ch_init(EditLine *);
|
||||
protected void ch_reset(EditLine *);
|
||||
protected int ch_enlargebufs __P((EditLine *, size_t));
|
||||
protected void ch_end(EditLine *);
|
||||
|
||||
#endif /* _h_el_chared */
|
||||
|
@ -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;
|
||||
return (CC_EOF);
|
||||
}
|
||||
|
||||
|
||||
@ -67,44 +70,43 @@ 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;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (el->el_line.lastchar + el->el_state.argument >=
|
||||
el->el_line.limit)
|
||||
return CC_ERROR; /* end of buffer space */
|
||||
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.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';
|
||||
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 {
|
||||
} 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';
|
||||
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--)
|
||||
@ -112,13 +114,14 @@ ed_insert(el, c)
|
||||
re_refresh(el);
|
||||
}
|
||||
|
||||
if (el->el_state.inputmode == MODE_REPLACE_1 || el->el_state.inputmode == MODE_REPLACE)
|
||||
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 (vi_command_mode(el, 0));
|
||||
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -128,14 +131,12 @@ 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;
|
||||
|
||||
if (el->el_line.cursor == el->el_line.buffer)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
|
||||
el->el_state.argument, ce__isword);
|
||||
@ -148,7 +149,7 @@ ed_delete_prev_word(el, c)
|
||||
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;
|
||||
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;
|
||||
ed_delete_next_char(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);
|
||||
(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_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_overwrite(el, STReof, 4);
|
||||
/* then do a EOF */
|
||||
term__flush();
|
||||
return CC_EOF;
|
||||
return (CC_EOF);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
#ifdef KSHVI
|
||||
el->el_line.cursor--;
|
||||
#else
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (el->el_line.cursor != el->el_line.buffer)
|
||||
el->el_line.cursor--;
|
||||
else
|
||||
return CC_ERROR;
|
||||
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;
|
||||
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,9 +210,7 @@ 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;
|
||||
|
||||
@ -218,8 +219,9 @@ ed_kill_line(el, c)
|
||||
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;
|
||||
/* zap! -- delete to end */
|
||||
el->el_line.lastchar = el->el_line.cursor;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -229,10 +231,9 @@ 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) {
|
||||
#ifdef VI_MOVE
|
||||
@ -240,10 +241,10 @@ ed_move_to_end(el, c)
|
||||
#endif
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
}
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -253,10 +254,9 @@ ed_move_to_end(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
ed_move_to_beg(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
ed_move_to_beg(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
|
||||
if (el->el_map.type == MAP_VI) {
|
||||
@ -265,11 +265,10 @@ ed_move_to_beg(el, c)
|
||||
el->el_line.cursor++;
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -278,13 +277,12 @@ 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;
|
||||
return (CC_ERROR);
|
||||
else
|
||||
el->el_line.cursor++;
|
||||
}
|
||||
@ -293,10 +291,9 @@ ed_transpose_chars(el, 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;
|
||||
}
|
||||
else
|
||||
return CC_ERROR;
|
||||
return (CC_REFRESH);
|
||||
} else
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@ -306,12 +303,11 @@ 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;
|
||||
return (CC_ERROR);
|
||||
|
||||
el->el_line.cursor += el->el_state.argument;
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
@ -320,10 +316,9 @@ ed_next_char(el, c)
|
||||
if (el->el_map.type == MAP_VI)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
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,
|
||||
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_map.type == MAP_VI)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -360,10 +354,9 @@ 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)
|
||||
@ -372,13 +365,11 @@ ed_prev_char(el, c)
|
||||
if (el->el_map.type == MAP_VI)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
}
|
||||
else
|
||||
return CC_ERROR;
|
||||
return (CC_CURSOR);
|
||||
} else
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@ -387,9 +378,7 @@ 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;
|
||||
@ -399,9 +388,9 @@ ed_quoted_insert(el, c)
|
||||
c = (unsigned char) tc;
|
||||
tty_noquotemode(el);
|
||||
if (num == 1)
|
||||
return ed_insert(el, c);
|
||||
return (ed_insert(el, c));
|
||||
else
|
||||
return ed_end_of_file(el, 0);
|
||||
return (ed_end_of_file(el, 0));
|
||||
}
|
||||
|
||||
|
||||
@ -409,12 +398,11 @@ ed_quoted_insert(el, c)
|
||||
* Adds to argument or enters a digit
|
||||
*/
|
||||
protected el_action_t
|
||||
ed_digit(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
ed_digit(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (!isdigit((unsigned char) c))
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (el->el_state.doingarg) {
|
||||
/* if doing an arg, add this in... */
|
||||
@ -422,20 +410,22 @@ ed_digit(el, c)
|
||||
el->el_state.argument = c - '0';
|
||||
else {
|
||||
if (el->el_state.argument > 1000000)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
el->el_state.argument =
|
||||
(el->el_state.argument * 10) + (c - '0');
|
||||
}
|
||||
return CC_ARGHACK;
|
||||
return (CC_ARGHACK);
|
||||
} else {
|
||||
if (el->el_line.lastchar + 1 >= el->el_line.limit) {
|
||||
if (!ch_enlargebufs(el, 1))
|
||||
return (CC_ERROR);
|
||||
}
|
||||
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';
|
||||
el->el_chared.c_undo.buf[el->el_chared.c_undo.isize] =
|
||||
'\0';
|
||||
c_delafter(el, 1);
|
||||
}
|
||||
c_insert(el, 1);
|
||||
@ -443,7 +433,7 @@ ed_digit(el, 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;
|
||||
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 */
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
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,21 +670,20 @@ 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 */
|
||||
|
||||
if (el->el_history.eventno == 0) { /* save the current buffer away */
|
||||
(void) strncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ);
|
||||
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;
|
||||
|
||||
if (hist_get(el) == CC_ERROR) {
|
||||
@ -717,12 +691,11 @@ ed_prev_history(el, c)
|
||||
/* el->el_history.eventno was fixed by first call */
|
||||
(void) hist_get(el);
|
||||
}
|
||||
|
||||
re_refresh(el);
|
||||
if (beep)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
else
|
||||
return CC_NORM; /* was CC_UP_HIST */
|
||||
return (CC_NORM); /* was CC_UP_HIST */
|
||||
}
|
||||
|
||||
|
||||
@ -732,10 +705,9 @@ 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 */
|
||||
|
||||
@ -743,10 +715,9 @@ ed_next_history(el, c)
|
||||
|
||||
if (el->el_history.eventno < 0) {
|
||||
el->el_history.eventno = 0;
|
||||
return CC_ERROR; /* make it beep */
|
||||
return (CC_ERROR);/* make it beep */
|
||||
}
|
||||
|
||||
return hist_get(el);
|
||||
return (hist_get(el));
|
||||
}
|
||||
|
||||
|
||||
@ -756,9 +727,7 @@ ed_next_history(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
ed_search_prev_history(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
ed_search_prev_history(EditLine *el, int c)
|
||||
{
|
||||
const char *hp;
|
||||
int h;
|
||||
@ -769,25 +738,24 @@ ed_search_prev_history(el, c)
|
||||
*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;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
if (el->el_history.eventno == 0) {
|
||||
(void) strncpy(el->el_history.buf, el->el_line.buffer, EL_BUFSIZ);
|
||||
(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;
|
||||
return (CC_ERROR);
|
||||
|
||||
hp = HIST_FIRST(el);
|
||||
if (hp == NULL)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
c_setpat(el); /* Set search pattern !! */
|
||||
|
||||
@ -798,8 +766,8 @@ ed_search_prev_history(el, c)
|
||||
#ifdef SDEBUG
|
||||
(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) ||
|
||||
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++;
|
||||
@ -813,12 +781,11 @@ ed_search_prev_history(el, c)
|
||||
#ifdef SDEBUG
|
||||
(void) fprintf(el->el_errfile, "not found\n");
|
||||
#endif
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
el->el_history.eventno = h;
|
||||
|
||||
return hist_get(el);
|
||||
return (hist_get(el));
|
||||
}
|
||||
|
||||
|
||||
@ -828,9 +795,7 @@ 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;
|
||||
@ -841,14 +806,14 @@ ed_search_next_history(el, c)
|
||||
*el->el_line.lastchar = '\0'; /* just in case */
|
||||
|
||||
if (el->el_history.eventno == 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (el->el_history.ref == NULL)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
hp = HIST_FIRST(el);
|
||||
if (hp == NULL)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
c_setpat(el); /* Set search pattern !! */
|
||||
|
||||
@ -856,8 +821,8 @@ ed_search_next_history(el, c)
|
||||
#ifdef SDEBUG
|
||||
(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) ||
|
||||
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;
|
||||
@ -869,13 +834,12 @@ ed_search_next_history(el, c)
|
||||
#ifdef SDEBUG
|
||||
(void) fprintf(el->el_errfile, "not found\n");
|
||||
#endif
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
el->el_history.eventno = found;
|
||||
|
||||
return hist_get(el);
|
||||
return (hist_get(el));
|
||||
}
|
||||
|
||||
|
||||
@ -885,9 +849,7 @@ 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);
|
||||
@ -903,7 +865,7 @@ ed_prev_line(el, c)
|
||||
break;
|
||||
|
||||
if (el->el_state.argument > 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
/*
|
||||
* Move to the beginning of the line
|
||||
@ -920,7 +882,7 @@ ed_prev_line(el, c)
|
||||
continue;
|
||||
|
||||
el->el_line.cursor = ptr;
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -930,9 +892,7 @@ 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);
|
||||
@ -945,7 +905,7 @@ ed_next_line(el, c)
|
||||
break;
|
||||
|
||||
if (el->el_state.argument > 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
/*
|
||||
* Move to the character requested
|
||||
@ -956,7 +916,7 @@ ed_next_line(el, c)
|
||||
continue;
|
||||
|
||||
el->el_line.cursor = ptr;
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -966,9 +926,7 @@ ed_next_line(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
ed_command(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
ed_command(EditLine *el, int c)
|
||||
{
|
||||
char tmpbuf[EL_BUFSIZ];
|
||||
int tmplen;
|
||||
@ -991,7 +949,7 @@ ed_command(el, c)
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
|
||||
if (parse_line(el, tmpbuf) == -1)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
else
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
.\" $NetBSD: editline.3,v 1.4 1997/01/14 04:17:23 lukem Exp $
|
||||
.\" $NetBSD: editline.3,v 1.20 2000/02/28 17:41:05 chopps Exp $
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
.\" Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
|
||||
@ -24,8 +25,8 @@
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
@ -33,9 +34,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd January 11, 1997
|
||||
.Dd November 12, 1999
|
||||
.Os
|
||||
.Dt EDITLINE 3
|
||||
.Sh NAME
|
||||
@ -53,8 +52,6 @@
|
||||
.Nm el_line ,
|
||||
.Nm el_insertstr ,
|
||||
.Nm el_deletestr ,
|
||||
.Nm el_data_set ,
|
||||
.Nm el_data_get ,
|
||||
.Nm history_init ,
|
||||
.Nm history_end ,
|
||||
.Nm history
|
||||
@ -64,7 +61,7 @@
|
||||
.Sh SYNOPSIS
|
||||
.Fd #include <histedit.h>
|
||||
.Ft EditLine *
|
||||
.Fn el_init "const char *prog" "FILE *fin" "FILE *fout"
|
||||
.Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
|
||||
.Ft void
|
||||
.Fn el_end "EditLine *e"
|
||||
.Ft void
|
||||
@ -80,25 +77,23 @@
|
||||
.Ft int
|
||||
.Fn el_set "EditLine *e" "int op" "..."
|
||||
.Ft int
|
||||
.Fn el_get "EditLine *e" "int op" "void *result"
|
||||
.Ft int
|
||||
.Fn el_source "EditLine *e" "const char *file"
|
||||
.Ft void
|
||||
.Fn el_resize "EditLine *e"
|
||||
.Ft const LineInfo *
|
||||
.Fn el_line "EditLine *e"
|
||||
.Ft int
|
||||
.Fn el_insertstr "EditLine *e" "char *str"
|
||||
.Fn el_insertstr "EditLine *e" "const char *str"
|
||||
.Ft void
|
||||
.Fn el_deletestr "EditLine *e" "int count"
|
||||
.Ft void
|
||||
.Fn el_data_set "EditLine *e" "void *data"
|
||||
.Ft void *
|
||||
.Fn el_data_get "EditLine *e"
|
||||
.Ft History *
|
||||
.Fn history_init
|
||||
.Ft void
|
||||
.Fn history_end "History *h"
|
||||
.Ft const HistEvent *
|
||||
.Fn history "History *h" "int op" "..."
|
||||
.Ft int
|
||||
.Fn history "History *h" "HistEvent *ev" "int op" "..."
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
@ -130,10 +125,11 @@ to be used by all other line editing functions.
|
||||
is the name of the invoking program, used when reading the
|
||||
.Xr editrc 5
|
||||
file to determine which settings to use.
|
||||
.Fa fin
|
||||
and
|
||||
.Fa fin ,
|
||||
.Fa fout
|
||||
are the input and output streams (respectively) to use.
|
||||
and
|
||||
.Fa ferr
|
||||
are the input, output, and error streams (respectively) to use.
|
||||
In this documentation, references to
|
||||
.Dq the tty
|
||||
are actually to this input/output stream combination.
|
||||
@ -197,17 +193,6 @@ didn't match, or
|
||||
Refer to
|
||||
.Xr editrc 5
|
||||
for more information.
|
||||
.Pp
|
||||
.Em NOTE :
|
||||
.Va argv[0]
|
||||
may be modified by
|
||||
.Fn el_parse .
|
||||
The colon between
|
||||
.Dq prog
|
||||
and the command,
|
||||
.Ar command ,
|
||||
will be replaced with a NUL
|
||||
.Pq Dq \e0 .
|
||||
.It Fn el_set
|
||||
Set
|
||||
.Nm
|
||||
@ -224,6 +209,10 @@ are supported, along with the required argument list:
|
||||
Define prompt printing function as
|
||||
.Fa f ,
|
||||
which is to return a string that contains the prompt.
|
||||
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
|
||||
Define right side prompt printing function as
|
||||
.Fa f ,
|
||||
which is to return a string that contains the prompt.
|
||||
.It Dv EL_TERMINAL , Fa "const char *type"
|
||||
Define terminal type of the tty to be
|
||||
.Fa type ,
|
||||
@ -344,6 +333,8 @@ EOF was entered.
|
||||
Expecting further command input as arguments, do nothing visually.
|
||||
.It Dv CC_REFRESH
|
||||
Refresh display.
|
||||
.It Dv CC_REFRESH_BEEP
|
||||
Refresh display, and beep.
|
||||
.It Dv CC_CURSOR
|
||||
Cursor moved, so update and perform
|
||||
.Dv CC_REFRESH.
|
||||
@ -365,6 +356,50 @@ Defines which history function to use, which is usually
|
||||
.Fa ptr
|
||||
should be the value returned by
|
||||
.Fn history_init .
|
||||
.It Dv EL_EDITMODE , Fa "int flag"
|
||||
If
|
||||
.Fa flag
|
||||
is non-zero,
|
||||
editing is enabled (the default).
|
||||
Note that this is only an indication, and does not
|
||||
affect the operation of
|
||||
.Nm "" .
|
||||
At this time, it is the caller's responsibility to
|
||||
check this
|
||||
(using
|
||||
.Fn el_get )
|
||||
to determine if editing should be enabled or not.
|
||||
.El
|
||||
.It Fn el_get
|
||||
Get
|
||||
.Nm
|
||||
parameters.
|
||||
.Fa op
|
||||
determines which parameter to retrieve into
|
||||
.Fa result .
|
||||
.Pp
|
||||
The following values for
|
||||
.Fa op
|
||||
are supported, along with actual type of
|
||||
.Fa result :
|
||||
.Bl -tag -width 4n
|
||||
.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
|
||||
Return a pointer to the function that displays the prompt.
|
||||
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
|
||||
Return a pointer to the function that displays the rightside prompt.
|
||||
.It Dv EL_EDITOR , Fa "const char *"
|
||||
Return the name of the editor, which will be one of
|
||||
.Dq emacs
|
||||
or
|
||||
.Dq vi .
|
||||
.It Dv EL_SIGNAL , Fa "int *"
|
||||
Return non-zero if
|
||||
.Nm
|
||||
has installed private signal handlers (see
|
||||
.Fn el_get
|
||||
above).
|
||||
.It Dv EL_EDITMODE, Fa "int *"
|
||||
Return non-zero if editing is enabled.
|
||||
.El
|
||||
.It Fn el_source
|
||||
Initialise
|
||||
@ -379,6 +414,8 @@ If
|
||||
is
|
||||
.Dv NULL ,
|
||||
try
|
||||
.Pa $PWD/.editrc
|
||||
then
|
||||
.Pa $HOME/.editrc .
|
||||
Refer to
|
||||
.Xr editrc 5
|
||||
@ -416,11 +453,6 @@ is empty or won't fit, and 0 otherwise.
|
||||
Delete
|
||||
.Fa num
|
||||
characters before the cursor.
|
||||
.It Fn el_data_set
|
||||
Set the user data to
|
||||
.Fa data .
|
||||
.It Fn el_data_get
|
||||
Get the user data.
|
||||
.El
|
||||
.Sh HISTORY LIST FUNCTIONS
|
||||
The history functions use a common data structure,
|
||||
@ -445,14 +477,18 @@ Perform operation
|
||||
.Fa op
|
||||
on the history list, with optional arguments as needed by the
|
||||
operation.
|
||||
.Fa ev
|
||||
is changed accordingly to operation.
|
||||
The following values for
|
||||
.Fa op
|
||||
are supported, along with the required argument list:
|
||||
.Bl -tag -width 4n
|
||||
.It Dv H_EVENT , Fa "int size"
|
||||
.It Dv H_SETSIZE , Fa "int size"
|
||||
Set size of history to
|
||||
.Fa size
|
||||
elements.
|
||||
.It Dv H_GETSIZE
|
||||
Get number of events currently in history.
|
||||
.It Dv H_END
|
||||
Cleans up and finishes with
|
||||
.Fa h ,
|
||||
@ -467,6 +503,7 @@ Clear the history.
|
||||
.Fa "history_gfun_t last" ,
|
||||
.Fa "history_gfun_t prev" ,
|
||||
.Fa "history_gfun_t curr" ,
|
||||
.Fa "history_sfun_t set" ,
|
||||
.Fa "history_vfun_t clear" ,
|
||||
.Fa "history_efun_t enter" ,
|
||||
.Fa "history_efun_t add"
|
||||
@ -484,12 +521,16 @@ Return the previous element in the history.
|
||||
Return the next element in the history.
|
||||
.It Dv H_CURR
|
||||
Return the current element in the history.
|
||||
.It Dv H_SET
|
||||
Set the cursor to point to the requested element.
|
||||
.It Dv H_ADD , Fa "const char *str"
|
||||
Append
|
||||
.Fa str
|
||||
to the current element of the history, or create an element with
|
||||
.Dv H_ENTER
|
||||
if there isn't one.
|
||||
.It Dv H_APPEND , Fa "const char *str"
|
||||
Append
|
||||
.Fa str
|
||||
to the last new element of the history.
|
||||
.It Dv H_ENTER , Fa "const char *str"
|
||||
Add
|
||||
.Fa str
|
||||
@ -514,33 +555,66 @@ Load the history list stored in
|
||||
Save the history list to
|
||||
.Fa file .
|
||||
.El
|
||||
.Pp
|
||||
.Fn history
|
||||
returns 0 if the operation
|
||||
.Fa op
|
||||
succeeds. Otherwise, -1 is returned and
|
||||
.Fa ev
|
||||
is updated to contain more details about the error.
|
||||
.El
|
||||
.\"XXX.Sh EXAMPLES
|
||||
.\"XXX: provide some examples
|
||||
.Sh SEE ALSO
|
||||
.Xr editrc 5 ,
|
||||
.Xr sh 1 ,
|
||||
.Xr signal 3 ,
|
||||
.Xr termcap 3 ,
|
||||
.Xr editrc 5
|
||||
.Xr termcap 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm
|
||||
library first appeared in
|
||||
.Bx 4.4 .
|
||||
.Dv CC_REDISPLAY
|
||||
appeared in
|
||||
.Nx 1.3 .
|
||||
.Dv CC_REFRESH_BEEP ,
|
||||
.Dv EL_EDITMODE
|
||||
and the readline emulation appeared in
|
||||
.Nx 1.4 .
|
||||
.Dv EL_RPROMPT
|
||||
appeared in
|
||||
.Nx 1.5 .
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
The
|
||||
.Nm
|
||||
library was written by
|
||||
.An Christos Zoulas ,
|
||||
and this manual was written by
|
||||
.An Luke Mewburn .
|
||||
library was written by Christos Zoulas.
|
||||
Luke Mewburn wrote this manual and implemented
|
||||
.Dv CC_REDISPLAY ,
|
||||
.Dv CC_REFRESH_BEEP ,
|
||||
.Dv EL_EDITMODE ,
|
||||
and
|
||||
.Dv EL_RPROMPT .
|
||||
Jaromir Dolecek implemented the readline emulation.
|
||||
.Sh BUGS
|
||||
This documentation is probably incomplete.
|
||||
The tokenization functions are not publically defined in
|
||||
.Fd <histedit.h>.
|
||||
.Pp
|
||||
.Fn el_parse
|
||||
should not modify the supplied
|
||||
.Va argv[0] .
|
||||
.Pp
|
||||
The tokenization functions are not publicly defined in
|
||||
.Li <histedit.h> .
|
||||
At this time, it is the responsibility of the caller to
|
||||
check the result of the
|
||||
.Dv EL_EDITMODE
|
||||
operation of
|
||||
.Fn el_get
|
||||
(after an
|
||||
.Fn el_source
|
||||
or
|
||||
.Fn el_parse )
|
||||
to determine if
|
||||
.Nm
|
||||
should be used for further input.
|
||||
I.e.,
|
||||
.Dv EL_EDITMODE
|
||||
is purely an indication of the result of the most recent
|
||||
.Xr editrc 5
|
||||
.Ic edit
|
||||
command.
|
||||
|
@ -1,6 +1,7 @@
|
||||
.\" $NetBSD: editrc.5,v 1.4 1997/04/24 20:20:31 christos Exp $
|
||||
.\" $NetBSD: editrc.5,v 1.10 2000/11/08 00:09:38 lukem Exp $
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
|
||||
@ -24,8 +25,8 @@
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
|
||||
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
@ -33,9 +34,7 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd January 11, 1997
|
||||
.Dd November 8, 2000
|
||||
.Os
|
||||
.Dt EDITRC 5
|
||||
.Sh NAME
|
||||
@ -50,10 +49,8 @@ file defines various settings to be used by the
|
||||
.Xr editline 3
|
||||
library.
|
||||
.Pp
|
||||
The format of each line is either:
|
||||
.Dl prog:command [arg [...]]
|
||||
or
|
||||
.Dl command [arg [...]]
|
||||
The format of each line is:
|
||||
.Dl [prog:]command [arg [...]]
|
||||
.Pp
|
||||
.Ar command
|
||||
is one of the
|
||||
@ -81,6 +78,12 @@ style
|
||||
regular expression, in which case
|
||||
.Ar command
|
||||
will be executed for any program that matches the regular expression.
|
||||
.Pp
|
||||
If
|
||||
.Ar prog
|
||||
is absent,
|
||||
.Ar command
|
||||
is executed for all programs.
|
||||
.Sh BUILTIN COMMANDS
|
||||
The
|
||||
.Nm editline
|
||||
@ -120,7 +123,7 @@ Options include:
|
||||
Bind all keys to the standard GNU Emacs-like bindings.
|
||||
.It Fl v
|
||||
Bind all keys to the standard
|
||||
.Xr vi 1 Ns -like
|
||||
.Xr vi 1 -like
|
||||
bindings.
|
||||
.It Fl a
|
||||
List or change key bindings in the
|
||||
@ -149,6 +152,11 @@ are themselves reinterpreted, and this continues for ten levels of
|
||||
interpretation.
|
||||
.El
|
||||
.Pp
|
||||
.Ar command
|
||||
may be one of the commands documented in
|
||||
.Sx "EDITOR COMMANDS"
|
||||
below, or another key.
|
||||
.Pp
|
||||
.Ar key
|
||||
and
|
||||
.Ar command
|
||||
@ -156,8 +164,10 @@ can contain control characters of the form
|
||||
.Sm off
|
||||
.Sq No ^ Ar character
|
||||
.Sm on
|
||||
(e.g.\&
|
||||
.Sq ^A ) ,
|
||||
.Po
|
||||
e.g.
|
||||
.Sq ^A
|
||||
.Pc ,
|
||||
and the following backslashed escape sequences:
|
||||
.Pp
|
||||
.Bl -tag -compact -offset indent -width 4n
|
||||
@ -213,10 +223,14 @@ or
|
||||
indicating that the terminal does or does not have that capability.
|
||||
.Pp
|
||||
.Fl s
|
||||
returns an empty string for non-existent capabilities, rather than
|
||||
returns an emptry string for non-existent capabilities, rather than
|
||||
causing an error.
|
||||
.Fl v
|
||||
causes messages to be verbose.
|
||||
.It Ic edit Op Li on | Li off
|
||||
Enable or disable the
|
||||
.Nm editline
|
||||
functionality in a program.
|
||||
.It Ic history
|
||||
List the history.
|
||||
.It Ic telltc
|
||||
@ -259,9 +273,13 @@ set of tty modes respectively; defaulting to
|
||||
Without other arguments,
|
||||
.Ic setty
|
||||
lists the modes in the chosen set which are fixed on
|
||||
.Pq Sq +mode
|
||||
.Po
|
||||
.Sq +mode
|
||||
.Pc
|
||||
or off
|
||||
.Pq Sq -mode .
|
||||
.Po
|
||||
.Sq -mode
|
||||
.Pc .
|
||||
.Fl a
|
||||
lists all tty modes in the chosen set regardless of the setting.
|
||||
With
|
||||
@ -275,17 +293,200 @@ on or off or removes control of
|
||||
.Ar mode
|
||||
in the chosen set.
|
||||
.El
|
||||
.Sh EDITOR COMMANDS
|
||||
The following editor commands are available for use in key bindings:
|
||||
.\" Section automatically generated with makelist
|
||||
.Bl -tag -width 4n
|
||||
.It Ic vi-paste-next
|
||||
Vi paste previous deletion to the right of the cursor.
|
||||
.It Ic vi-paste-prev
|
||||
Vi paste previous deletion to the left of the cursor.
|
||||
.It Ic vi-prev-space-word
|
||||
Vi move to the previous space delimited word.
|
||||
.It Ic vi-prev-word
|
||||
Vi move to the previous word.
|
||||
.It Ic vi-next-space-word
|
||||
Vi move to the next space delimited word.
|
||||
.It Ic vi-next-word
|
||||
Vi move to the next word.
|
||||
.It Ic vi-change-case
|
||||
Vi change case of character under the cursor and advance one character.
|
||||
.It Ic vi-change-meta
|
||||
Vi change prefix command.
|
||||
.It Ic vi-insert-at-bol
|
||||
Vi enter insert mode at the beginning of line.
|
||||
.It Ic vi-replace-char
|
||||
Vi replace character under the cursor with the next character typed.
|
||||
.It Ic vi-replace-mode
|
||||
Vi enter replace mode.
|
||||
.It Ic vi-substitute-char
|
||||
Vi replace character under the cursor and enter insert mode.
|
||||
.It Ic vi-substitute-line
|
||||
Vi substitute entire line.
|
||||
.It Ic vi-change-to-eol
|
||||
Vi change to end of line.
|
||||
.It Ic vi-insert
|
||||
Vi enter insert mode.
|
||||
.It Ic vi-add
|
||||
Vi enter insert mode after the cursor.
|
||||
.It Ic vi-add-at-eol
|
||||
Vi enter insert mode at end of line.
|
||||
.It Ic vi-delete-meta
|
||||
Vi delete prefix command.
|
||||
.It Ic vi-end-word
|
||||
Vi move to the end of the current space delimited word.
|
||||
.It Ic vi-to-end-word
|
||||
Vi move to the end of the current word.
|
||||
.It Ic vi-undo
|
||||
Vi undo last change.
|
||||
.It Ic vi-command-mode
|
||||
Vi enter command mode (use alternative key bindings).
|
||||
.It Ic vi-zero
|
||||
Vi move to the beginning of line.
|
||||
.It Ic vi-delete-prev-char
|
||||
Vi move to previous character (backspace).
|
||||
.It Ic vi-list-or-eof
|
||||
Vi list choices for completion or indicate end of file if empty line.
|
||||
.It Ic vi-kill-line-prev
|
||||
Vi cut from beginning of line to cursor.
|
||||
.It Ic vi-search-prev
|
||||
Vi search history previous.
|
||||
.It Ic vi-search-next
|
||||
Vi search history next.
|
||||
.It Ic vi-repeat-search-next
|
||||
Vi repeat current search in the same search direction.
|
||||
.It Ic vi-repeat-search-prev
|
||||
Vi repeat current search in the opposite search direction.
|
||||
.It Ic vi-next-char
|
||||
Vi move to the character specified next.
|
||||
.It Ic vi-prev-char
|
||||
Vi move to the character specified previous.
|
||||
.It Ic vi-to-next-char
|
||||
Vi move up to the character specified next.
|
||||
.It Ic vi-to-prev-char
|
||||
Vi move up to the character specified previous.
|
||||
.It Ic vi-repeat-next-char
|
||||
Vi repeat current character search in the same search direction.
|
||||
.It Ic vi-repeat-prev-char
|
||||
Vi repeat current character search in the opposite search direction.
|
||||
.It Ic em-delete-or-list
|
||||
Delete character under cursor or list completions if at end of line.
|
||||
.It Ic em-delete-next-word
|
||||
Cut from cursor to end of current word.
|
||||
.It Ic em-yank
|
||||
Paste cut buffer at cursor position.
|
||||
.It Ic em-kill-line
|
||||
Cut the entire line and save in cut buffer.
|
||||
.It Ic em-kill-region
|
||||
Cut area between mark and cursor and save in cut buffer.
|
||||
.It Ic em-copy-region
|
||||
Copy area between mark and cursor to cut buffer.
|
||||
.It Ic em-gosmacs-traspose
|
||||
Exchange the two characters before the cursor.
|
||||
.It Ic em-next-word
|
||||
Move next to end of current word.
|
||||
.It Ic em-upper-case
|
||||
Uppercase the characters from cursor to end of current word.
|
||||
.It Ic em-capitol-case
|
||||
Capitalize the characters from cursor to end of current word.
|
||||
.It Ic em-lower-case
|
||||
Lowercase the characters from cursor to end of current word.
|
||||
.It Ic em-set-mark
|
||||
Set the mark at cursor.
|
||||
.It Ic em-exchange-mark
|
||||
Exchange the cursor and mark.
|
||||
.It Ic em-universal-argument
|
||||
Universal argument (argument times 4).
|
||||
.It Ic em-meta-next
|
||||
Add 8th bit to next character typed.
|
||||
.It Ic em-toggle-overwrite
|
||||
Switch from insert to overwrite mode or vice versa.
|
||||
.It Ic em-copy-prev-word
|
||||
Copy current word to cursor.
|
||||
.It Ic em-inc-search-next
|
||||
Emacs incremental next search.
|
||||
.It Ic em-inc-search-prev
|
||||
Emacs incremental reverse search.
|
||||
.It Ic ed-end-of-file
|
||||
Indicate end of file.
|
||||
.It Ic ed-insert
|
||||
Add character to the line.
|
||||
.It Ic ed-delete-prev-word
|
||||
Delete from beginning of current word to cursor.
|
||||
.It Ic ed-delete-next-char
|
||||
Delete character under cursor.
|
||||
.It Ic ed-kill-line
|
||||
Cut to the end of line.
|
||||
.It Ic ed-move-to-end
|
||||
Move cursor to the end of line.
|
||||
.It Ic ed-move-to-beg
|
||||
Move cursor to the beginning of line.
|
||||
.It Ic ed-transpose-chars
|
||||
Exchange the character to the left of the cursor with the one under it.
|
||||
.It Ic ed-next-char
|
||||
Move to the right one character.
|
||||
.It Ic ed-prev-word
|
||||
Move to the beginning of the current word.
|
||||
.It Ic ed-prev-char
|
||||
Move to the left one character.
|
||||
.It Ic ed-quoted-insert
|
||||
Add the next character typed verbatim.
|
||||
.It Ic ed-digit
|
||||
Adds to argument or enters a digit.
|
||||
.It Ic ed-argument-digit
|
||||
Digit that starts argument.
|
||||
.It Ic ed-unassigned
|
||||
Indicates unbound character.
|
||||
.It Ic ed-tty-sigint
|
||||
Tty interrupt character.
|
||||
.It Ic ed-tty-dsusp
|
||||
Tty delayed suspend character.
|
||||
.It Ic ed-tty-flush-output
|
||||
Tty flush output characters.
|
||||
.It Ic ed-tty-sigquit
|
||||
Tty quit character.
|
||||
.It Ic ed-tty-sigtstp
|
||||
Tty suspend character.
|
||||
.It Ic ed-tty-stop-output
|
||||
Tty disallow output characters.
|
||||
.It Ic ed-tty-start-output
|
||||
Tty allow output characters.
|
||||
.It Ic ed-newline
|
||||
Execute command.
|
||||
.It Ic ed-delete-prev-char
|
||||
Delete the character to the left of the cursor.
|
||||
.It Ic ed-clear-screen
|
||||
Clear screen leaving current line at the top.
|
||||
.It Ic ed-redisplay
|
||||
Redisplay everything.
|
||||
.It Ic ed-start-over
|
||||
Erase current line and start from scratch.
|
||||
.It Ic ed-sequence-lead-in
|
||||
First character in a bound sequence.
|
||||
.It Ic ed-prev-history
|
||||
Move to the previous history line.
|
||||
.It Ic ed-next-history
|
||||
Move to the next history line.
|
||||
.It Ic ed-search-prev-history
|
||||
Search previous in history for a line matching the current.
|
||||
.It Ic ed-search-next-history
|
||||
Search next in history for a line matching the current.
|
||||
.It Ic ed-prev-line
|
||||
Move up one line.
|
||||
.It Ic ed-next-line
|
||||
Move down one line.
|
||||
.It Ic ed-command
|
||||
Editline extended command.
|
||||
.El
|
||||
.\" End of section automatically generated with makelist
|
||||
.Sh SEE ALSO
|
||||
.Xr editline 3 ,
|
||||
.Xr regex 3 ,
|
||||
.Xr termcap 5
|
||||
.Sh AUTHORS
|
||||
.An -nosplit
|
||||
The
|
||||
.Nm editline
|
||||
library was written by
|
||||
.An Christos Zoulas ,
|
||||
and this manual was written by
|
||||
.An Luke Mewburn ,
|
||||
library was written by Christos Zoulas,
|
||||
and this manual was written by Luke Mewburn,
|
||||
with some sections inspired by
|
||||
.Xr tcsh 1 .
|
||||
|
357
lib/libedit/el.c
357
lib/libedit/el.c
@ -32,15 +32,15 @@
|
||||
* 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: el.c,v 1.20 2000/11/11 22:18:57 christos Exp $
|
||||
*/
|
||||
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
/*
|
||||
* el.c: EditLine interface functions
|
||||
@ -49,86 +49,70 @@ static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#if __STDC__
|
||||
#include <stdarg.h>
|
||||
#else
|
||||
# include <varargs.h>
|
||||
#endif
|
||||
#include "el.h"
|
||||
|
||||
/* el_init():
|
||||
* Initialize editline and set default parameters.
|
||||
*/
|
||||
public EditLine *
|
||||
el_init(prog, fin, fout)
|
||||
const char *prog;
|
||||
FILE *fin, *fout;
|
||||
el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
|
||||
{
|
||||
|
||||
EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
|
||||
#ifdef DEBUG
|
||||
char *tty;
|
||||
#endif
|
||||
|
||||
if (el == NULL)
|
||||
return NULL;
|
||||
return (NULL);
|
||||
|
||||
memset(el, 0, sizeof(EditLine));
|
||||
|
||||
el->el_infd = fileno(fin);
|
||||
el->el_outfile = fout;
|
||||
el->el_errfile = ferr;
|
||||
el->el_prog = strdup(prog);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (issetugid() == 0 && (tty = getenv("DEBUGTTY")) != NULL) {
|
||||
el->el_errfile = fopen(tty, "w");
|
||||
if (el->el_errfile == NULL) {
|
||||
(void) fprintf(stderr, "Cannot open %s (%s).\n",
|
||||
tty, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
el->el_errfile = stderr;
|
||||
|
||||
/*
|
||||
* Initialize all the modules. Order is important!!!
|
||||
*/
|
||||
el->el_flags = 0;
|
||||
|
||||
(void) term_init(el);
|
||||
(void) tty_init(el);
|
||||
(void) key_init(el);
|
||||
(void) map_init(el);
|
||||
if (tty_init(el) == -1)
|
||||
el->el_flags |= NO_TTY;
|
||||
(void) ch_init(el);
|
||||
(void) search_init(el);
|
||||
(void) hist_init(el);
|
||||
(void) prompt_init(el);
|
||||
(void) sig_init(el);
|
||||
el->el_flags = 0;
|
||||
el->data = NULL;
|
||||
|
||||
return el;
|
||||
} /* end el_init */
|
||||
return (el);
|
||||
}
|
||||
|
||||
|
||||
/* el_end():
|
||||
* Clean up.
|
||||
*/
|
||||
public void
|
||||
el_end(el)
|
||||
EditLine *el;
|
||||
el_end(EditLine *el)
|
||||
{
|
||||
|
||||
if (el == NULL)
|
||||
return;
|
||||
|
||||
el_reset(el);
|
||||
|
||||
term_end(el);
|
||||
tty_end(el);
|
||||
key_end(el);
|
||||
map_end(el);
|
||||
tty_end(el);
|
||||
ch_end(el);
|
||||
search_end(el);
|
||||
hist_end(el);
|
||||
@ -137,16 +121,16 @@ el_end(el)
|
||||
|
||||
el_free((ptr_t) el->el_prog);
|
||||
el_free((ptr_t) el);
|
||||
} /* end el_end */
|
||||
}
|
||||
|
||||
|
||||
/* el_reset():
|
||||
* Reset the tty and the parser
|
||||
*/
|
||||
public void
|
||||
el_reset(el)
|
||||
EditLine *el;
|
||||
el_reset(EditLine *el)
|
||||
{
|
||||
|
||||
tty_cookedmode(el);
|
||||
ch_reset(el); /* XXX: Do we want that? */
|
||||
}
|
||||
@ -156,29 +140,18 @@ el_reset(el)
|
||||
* set the editline parameters
|
||||
*/
|
||||
public int
|
||||
#if __STDC__
|
||||
el_set(EditLine *el, int op, ...)
|
||||
#else
|
||||
el_set(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list va;
|
||||
int rv;
|
||||
#if __STDC__
|
||||
va_start(va, op);
|
||||
#else
|
||||
EditLine *el;
|
||||
int op;
|
||||
|
||||
va_start(va);
|
||||
el = va_arg(va, EditLine *);
|
||||
op = va_arg(va, int);
|
||||
#endif
|
||||
|
||||
if (el == NULL)
|
||||
return (-1);
|
||||
switch (op) {
|
||||
case EL_PROMPT:
|
||||
rv = prompt_set(el, va_arg(va, el_pfunc_t));
|
||||
case EL_RPROMPT:
|
||||
rv = prompt_set(el, va_arg(va, el_pfunc_t), op);
|
||||
break;
|
||||
|
||||
case EL_TERMINAL:
|
||||
@ -205,6 +178,7 @@ el_set(va_alist)
|
||||
{
|
||||
char *argv[20];
|
||||
int i;
|
||||
|
||||
for (i = 1; i < 20; i++)
|
||||
if ((argv[i] = va_arg(va, char *)) == NULL)
|
||||
break;
|
||||
@ -237,27 +211,37 @@ el_set(va_alist)
|
||||
|
||||
default:
|
||||
rv = -1;
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad op %d\n", op));
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EL_ADDFN:
|
||||
{
|
||||
char *name = va_arg(va, char *);
|
||||
char *help = va_arg(va, char *);
|
||||
el_func_t func = va_arg(va, el_func_t);
|
||||
|
||||
rv = map_addfunc(el, name, help, func);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case EL_HIST:
|
||||
{
|
||||
hist_fun_t func = va_arg(va, hist_fun_t);
|
||||
ptr_t ptr = va_arg(va, char *);
|
||||
|
||||
rv = hist_set(el, func, ptr);
|
||||
break;
|
||||
}
|
||||
|
||||
case EL_EDITMODE:
|
||||
if (va_arg(va, int))
|
||||
el->el_flags &= ~EDIT_DISABLED;
|
||||
else
|
||||
el->el_flags |= EDIT_DISABLED;
|
||||
rv = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -265,78 +249,90 @@ el_set(va_alist)
|
||||
}
|
||||
|
||||
va_end(va);
|
||||
return rv;
|
||||
} /* end el_set */
|
||||
|
||||
|
||||
/* el_line():
|
||||
* Return editing info
|
||||
*/
|
||||
public const LineInfo *
|
||||
el_line(el)
|
||||
EditLine *el;
|
||||
{
|
||||
return (const LineInfo *) &el->el_line;
|
||||
return (rv);
|
||||
}
|
||||
|
||||
static const char elpath[] = "/.editrc";
|
||||
|
||||
/* el_source():
|
||||
* Source a file
|
||||
/* el_get():
|
||||
* retrieve the editline parameters
|
||||
*/
|
||||
public int
|
||||
el_source(el, fname)
|
||||
EditLine *el;
|
||||
const char *fname;
|
||||
el_get(EditLine *el, int op, void *ret)
|
||||
{
|
||||
FILE *fp;
|
||||
size_t len;
|
||||
char *ptr, path[MAXPATHLEN];
|
||||
int rv;
|
||||
|
||||
if (fname == NULL) {
|
||||
if (issetugid() != 0 || (ptr = getenv("HOME")) == NULL)
|
||||
return -1;
|
||||
(void) snprintf(path, sizeof(path), "%s%s", ptr, elpath);
|
||||
fname = path;
|
||||
}
|
||||
if (el == NULL || ret == NULL)
|
||||
return (-1);
|
||||
switch (op) {
|
||||
case EL_PROMPT:
|
||||
case EL_RPROMPT:
|
||||
rv = prompt_get(el, (el_pfunc_t *) & ret, op);
|
||||
break;
|
||||
|
||||
if ((fp = fopen(fname, "r")) == NULL)
|
||||
return -1;
|
||||
case EL_EDITOR:
|
||||
rv = map_get_editor(el, (const char **) &ret);
|
||||
break;
|
||||
|
||||
while ((ptr = fgetln(fp, &len)) != NULL) {
|
||||
if (ptr[len - 1] == '\n')
|
||||
--len;
|
||||
ptr[len] = '\0';
|
||||
case EL_SIGNAL:
|
||||
*((int *) ret) = (el->el_flags & HANDLE_SIGNALS);
|
||||
rv = 0;
|
||||
break;
|
||||
|
||||
if (parse_line(el, ptr) == -1) {
|
||||
(void) fclose(fp);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
case EL_EDITMODE:
|
||||
*((int *) ret) = (!(el->el_flags & EDIT_DISABLED));
|
||||
rv = 0;
|
||||
break;
|
||||
|
||||
(void) fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
#if 0 /* XXX */
|
||||
case EL_TERMINAL:
|
||||
rv = term_get(el, (const char *) &ret);
|
||||
break;
|
||||
|
||||
|
||||
/* el_resize():
|
||||
* Called from program when terminal is resized
|
||||
*/
|
||||
public void
|
||||
el_resize(el)
|
||||
EditLine *el;
|
||||
case EL_BIND:
|
||||
case EL_TELLTC:
|
||||
case EL_SETTC:
|
||||
case EL_ECHOTC:
|
||||
case EL_SETTY:
|
||||
{
|
||||
int lins, cols;
|
||||
sigset_t oset, nset;
|
||||
(void) sigemptyset(&nset);
|
||||
(void) sigaddset(&nset, SIGWINCH);
|
||||
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
||||
char *argv[20];
|
||||
int i;
|
||||
|
||||
/* get the correct window size */
|
||||
if (term_get_size(el, &lins, &cols))
|
||||
term_change_size(el, lins, cols);
|
||||
for (i = 1; i < 20; i++)
|
||||
if ((argv[i] = va_arg(va, char *)) == NULL)
|
||||
break;
|
||||
|
||||
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
switch (op) {
|
||||
case EL_BIND:
|
||||
argv[0] = "bind";
|
||||
rv = map_bind(el, i, argv);
|
||||
break;
|
||||
|
||||
case EL_TELLTC:
|
||||
argv[0] = "telltc";
|
||||
rv = term_telltc(el, i, argv);
|
||||
break;
|
||||
|
||||
case EL_SETTC:
|
||||
argv[0] = "settc";
|
||||
rv = term_settc(el, i, argv);
|
||||
break;
|
||||
|
||||
case EL_ECHOTC:
|
||||
argv[0] = "echotc";
|
||||
rv = term_echotc(el, i, argv);
|
||||
break;
|
||||
|
||||
case EL_SETTY:
|
||||
argv[0] = "setty";
|
||||
rv = tty_stty(el, i, argv);
|
||||
break;
|
||||
|
||||
default:
|
||||
rv = -1;
|
||||
EL_ABORT((el->errfile, "Bad op %d\n", op));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
public void
|
||||
@ -357,3 +353,140 @@ el_data_get (el)
|
||||
return (el->data);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
case EL_ADDFN:
|
||||
{
|
||||
char *name = va_arg(va, char *);
|
||||
char *help = va_arg(va, char *);
|
||||
el_func_t func = va_arg(va, el_func_t);
|
||||
|
||||
rv = map_addfunc(el, name, help, func);
|
||||
break;
|
||||
}
|
||||
|
||||
case EL_HIST:
|
||||
{
|
||||
hist_fun_t func = va_arg(va, hist_fun_t);
|
||||
ptr_t ptr = va_arg(va, char *);
|
||||
rv = hist_set(el, func, ptr);
|
||||
}
|
||||
break;
|
||||
#endif /* XXX */
|
||||
|
||||
default:
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
return (rv);
|
||||
}
|
||||
|
||||
|
||||
/* el_line():
|
||||
* Return editing info
|
||||
*/
|
||||
public const LineInfo *
|
||||
el_line(EditLine *el)
|
||||
{
|
||||
|
||||
return (const LineInfo *) (void *) &el->el_line;
|
||||
}
|
||||
|
||||
static const char elpath[] = "/.editrc";
|
||||
|
||||
/* el_source():
|
||||
* Source a file
|
||||
*/
|
||||
public int
|
||||
el_source(EditLine *el, const char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
size_t len;
|
||||
char *ptr, path[MAXPATHLEN];
|
||||
|
||||
fp = NULL;
|
||||
if (fname == NULL) {
|
||||
if (issetugid())
|
||||
return (-1);
|
||||
if ((ptr = getenv("HOME")) == NULL)
|
||||
return (-1);
|
||||
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
|
||||
return (-1);
|
||||
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
|
||||
return (-1);
|
||||
fname = path;
|
||||
}
|
||||
if (fp == NULL)
|
||||
fp = fopen(fname, "r");
|
||||
if (fp == NULL)
|
||||
return (-1);
|
||||
|
||||
while ((ptr = fgetln(fp, &len)) != NULL) {
|
||||
if (len > 0 && ptr[len - 1] == '\n')
|
||||
--len;
|
||||
ptr[len] = '\0';
|
||||
if (parse_line(el, ptr) == -1) {
|
||||
(void) fclose(fp);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
(void) fclose(fp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* el_resize():
|
||||
* Called from program when terminal is resized
|
||||
*/
|
||||
public void
|
||||
el_resize(EditLine *el)
|
||||
{
|
||||
int lins, cols;
|
||||
sigset_t oset, nset;
|
||||
|
||||
(void) sigemptyset(&nset);
|
||||
(void) sigaddset(&nset, SIGWINCH);
|
||||
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
||||
|
||||
/* get the correct window size */
|
||||
if (term_get_size(el, &lins, &cols))
|
||||
term_change_size(el, lins, cols);
|
||||
|
||||
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
}
|
||||
|
||||
|
||||
/* el_beep():
|
||||
* Called from the program to beep
|
||||
*/
|
||||
public void
|
||||
el_beep(EditLine *el)
|
||||
{
|
||||
|
||||
term_beep(el);
|
||||
}
|
||||
|
||||
|
||||
/* el_editmode()
|
||||
* Set the state of EDIT_DISABLED from the `edit' command.
|
||||
*/
|
||||
protected int
|
||||
/*ARGSUSED*/
|
||||
el_editmode(EditLine *el, int argc, char **argv)
|
||||
{
|
||||
const char *how;
|
||||
|
||||
if (argv == NULL || argc != 2 || argv[1] == NULL)
|
||||
return (-1);
|
||||
|
||||
how = argv[1];
|
||||
if (strcmp(how, "on") == 0)
|
||||
el->el_flags &= ~EDIT_DISABLED;
|
||||
else if (strcmp(how, "off") == 0)
|
||||
el->el_flags |= EDIT_DISABLED;
|
||||
else {
|
||||
(void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
|
||||
return (-1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)el.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: el.h,v 1.7 2000/11/11 22:18:57 christos Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -53,21 +55,24 @@
|
||||
|
||||
#define EL_BUFSIZ 1024 /* Maximum line size */
|
||||
|
||||
#define HANDLE_SIGNALS 1
|
||||
#define HANDLE_SIGNALS 1<<0
|
||||
#define NO_TTY 1<<1
|
||||
#define EDIT_DISABLED 1<<2
|
||||
|
||||
typedef int bool_t; /* True or not */
|
||||
|
||||
typedef unsigned char el_action_t; /* Index to command array */
|
||||
|
||||
typedef struct coord_t { /* Position on the screen */
|
||||
int h, v;
|
||||
int h;
|
||||
int v;
|
||||
} coord_t;
|
||||
|
||||
typedef struct el_line_t {
|
||||
char *buffer, /* Input line */
|
||||
*cursor, /* Cursor position */
|
||||
*lastchar, /* Last character */
|
||||
*limit; /* Max position */
|
||||
char *buffer; /* Input line */
|
||||
char *cursor; /* Cursor position */
|
||||
char *lastchar; /* Last character */
|
||||
const char *limit; /* Max position */
|
||||
} el_line_t;
|
||||
|
||||
/*
|
||||
@ -110,15 +115,15 @@ struct editline {
|
||||
int el_infd; /* Input file descriptor */
|
||||
int el_flags; /* Various flags. */
|
||||
coord_t el_cursor; /* Cursor location */
|
||||
char **el_display, /* Real screen image = what is there */
|
||||
**el_vdisplay; /* Virtual screen image = what we see */
|
||||
|
||||
char **el_display; /* Real screen image = what is there */
|
||||
char **el_vdisplay; /* Virtual screen image = what we see */
|
||||
el_line_t el_line; /* The current line information */
|
||||
el_state_t el_state; /* Current editor state */
|
||||
el_term_t el_term; /* Terminal dependent stuff */
|
||||
el_tty_t el_tty; /* Tty dependent stuff */
|
||||
el_refresh_t el_refresh; /* Refresh stuff */
|
||||
el_prompt_t el_prompt; /* Prompt stuff */
|
||||
el_prompt_t el_rprompt; /* Prompt stuff */
|
||||
el_chared_t el_chared; /* Characted editor stuff */
|
||||
el_map_t el_map; /* Key mapping stuff */
|
||||
el_key_t el_key; /* Key binding stuff */
|
||||
@ -129,4 +134,12 @@ struct editline {
|
||||
void *data; /* user data */
|
||||
};
|
||||
|
||||
protected int el_editmode(EditLine *, int, char **);
|
||||
|
||||
#ifdef DEBUG
|
||||
#define EL_ABORT(a) (void) (fprintf(el->el_errfile, "%s, %d: ", \
|
||||
__FILE__, __LINE__), fprintf a, abort())
|
||||
#else
|
||||
#define EL_ABORT(a) abort()
|
||||
#endif
|
||||
#endif /* _h_el */
|
||||
|
@ -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: emacs.c,v 1.8 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[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* emacs.c: Emacs functions
|
||||
@ -52,27 +56,30 @@ static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_delete_or_list(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_delete_or_list(EditLine *el, int 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 */
|
||||
|
||||
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_overwrite(el, STReof, 4); /* then do a EOF */
|
||||
term__flush();
|
||||
return CC_EOF;
|
||||
}
|
||||
else {
|
||||
/* Here we could list completions, but it is an error right now */
|
||||
return (CC_EOF);
|
||||
} else {
|
||||
/*
|
||||
* Here we could list completions, but it is an
|
||||
* error right now
|
||||
*/
|
||||
term_beep(el);
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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.lastchar; /* bounds check */
|
||||
return CC_REFRESH;
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
/* bounds check */
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,14 +90,12 @@ em_delete_or_list(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_delete_next_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_delete_next_word(EditLine *el, int c)
|
||||
{
|
||||
char *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);
|
||||
@ -102,8 +107,9 @@ em_delete_next_word(el, c)
|
||||
|
||||
c_delafter(el, cp - el->el_line.cursor); /* delete after dot */
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar; /* bounds check */
|
||||
return CC_REFRESH;
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
/* bounds check */
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -113,19 +119,19 @@ em_delete_next_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_yank(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_yank(EditLine *el, int c)
|
||||
{
|
||||
char *kp, *cp;
|
||||
|
||||
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
|
||||
return CC_ERROR;
|
||||
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) {
|
||||
if (!ch_enlargebufs(el, 1))
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
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;
|
||||
@ -140,7 +146,7 @@ em_yank(el, c)
|
||||
if (el->el_state.argument == 1)
|
||||
el->el_line.cursor = cp;
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -150,9 +156,7 @@ em_yank(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_kill_line(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_kill_line(EditLine *el, int c)
|
||||
{
|
||||
char *kp, *cp;
|
||||
|
||||
@ -161,9 +165,10 @@ em_kill_line(el, c)
|
||||
while (cp < el->el_line.lastchar)
|
||||
*kp++ = *cp++; /* copy it */
|
||||
el->el_chared.c_kill.last = kp;
|
||||
el->el_line.lastchar = el->el_line.buffer; /* zap! -- delete all of it */
|
||||
/* 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 +178,12 @@ em_kill_line(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_kill_region(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_kill_region(EditLine *el, int c)
|
||||
{
|
||||
char *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;
|
||||
@ -189,8 +192,7 @@ em_kill_region(el, c)
|
||||
*kp++ = *cp++; /* copy it */
|
||||
el->el_chared.c_kill.last = kp;
|
||||
c_delafter(el, cp - el->el_line.cursor);
|
||||
}
|
||||
else { /* mark is before cursor */
|
||||
} else { /* mark is before cursor */
|
||||
cp = el->el_chared.c_kill.mark;
|
||||
kp = el->el_chared.c_kill.buf;
|
||||
while (cp < el->el_line.cursor)
|
||||
@ -199,7 +201,7 @@ em_kill_region(el, c)
|
||||
c_delbefore(el, cp - el->el_chared.c_kill.mark);
|
||||
el->el_line.cursor = el->el_chared.c_kill.mark;
|
||||
}
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -209,14 +211,12 @@ em_kill_region(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_copy_region(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_copy_region(EditLine *el, int c)
|
||||
{
|
||||
char *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;
|
||||
@ -224,15 +224,14 @@ em_copy_region(el, c)
|
||||
while (cp < el->el_chared.c_kill.mark)
|
||||
*kp++ = *cp++; /* copy it */
|
||||
el->el_chared.c_kill.last = kp;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cp = el->el_chared.c_kill.mark;
|
||||
kp = el->el_chared.c_kill.buf;
|
||||
while (cp < el->el_line.cursor)
|
||||
*kp++ = *cp++; /* copy it */
|
||||
el->el_chared.c_kill.last = kp;
|
||||
}
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -241,9 +240,7 @@ em_copy_region(el, c)
|
||||
* Gosling emacs transpose chars [^T]
|
||||
*/
|
||||
protected el_action_t
|
||||
em_gosmacs_traspose(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_gosmacs_traspose(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor > &el->el_line.buffer[1]) {
|
||||
@ -251,10 +248,9 @@ em_gosmacs_traspose(el, 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;
|
||||
}
|
||||
else
|
||||
return CC_ERROR;
|
||||
return (CC_REFRESH);
|
||||
} else
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@ -264,25 +260,24 @@ em_gosmacs_traspose(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_next_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_next_word(EditLine *el, int c)
|
||||
{
|
||||
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,
|
||||
el->el_line.cursor = c__next_word(el->el_line.cursor,
|
||||
el->el_line.lastchar,
|
||||
el->el_state.argument,
|
||||
ce__isword);
|
||||
|
||||
if (el->el_map.type == MAP_VI)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
}
|
||||
|
||||
/* em_upper_case():
|
||||
* Uppercase the characters from cursor to end of current word
|
||||
@ -290,9 +285,7 @@ em_next_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_upper_case(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_upper_case(EditLine *el, int c)
|
||||
{
|
||||
char *cp, *ep;
|
||||
|
||||
@ -306,7 +299,7 @@ em_upper_case(el, c)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -316,9 +309,7 @@ em_upper_case(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_capitol_case(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_capitol_case(EditLine *el, int c)
|
||||
{
|
||||
char *cp, *ep;
|
||||
|
||||
@ -340,18 +331,17 @@ em_capitol_case(el, c)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/* em_lower_case():
|
||||
* Lowercase the characters from cursor to end of current word
|
||||
* [M-l]
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_lower_case(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_lower_case(EditLine *el, int c)
|
||||
{
|
||||
char *cp, *ep;
|
||||
|
||||
@ -365,7 +355,7 @@ em_lower_case(el, c)
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -375,12 +365,11 @@ em_lower_case(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_set_mark(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_set_mark(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_chared.c_kill.mark = el->el_line.cursor;
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -390,47 +379,45 @@ em_set_mark(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_exchange_mark(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_exchange_mark(EditLine *el, int c)
|
||||
{
|
||||
register char *cp;
|
||||
char *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);
|
||||
}
|
||||
|
||||
|
||||
/* em_universal_argument():
|
||||
* Universal argument (argument times 4)
|
||||
* [^U]
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_universal_argument(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_universal_argument(EditLine *el, int c)
|
||||
{ /* 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);
|
||||
}
|
||||
|
||||
|
||||
/* em_meta_next():
|
||||
* Add 8th bit to next character typed
|
||||
* [<ESC>]
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_meta_next(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_meta_next(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_state.metanext = 1;
|
||||
return CC_ARGHACK;
|
||||
return (CC_ARGHACK);
|
||||
}
|
||||
|
||||
|
||||
@ -439,13 +426,12 @@ em_meta_next(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_toggle_overwrite(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_toggle_overwrite(EditLine *el, int c)
|
||||
{
|
||||
el->el_state.inputmode =
|
||||
(el->el_state.inputmode == MODE_INSERT) ? MODE_REPLACE : MODE_INSERT;
|
||||
return CC_NORM;
|
||||
|
||||
el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
|
||||
MODE_REPLACE : MODE_INSERT;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -454,14 +440,12 @@ em_toggle_overwrite(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_copy_prev_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_copy_prev_word(EditLine *el, int c)
|
||||
{
|
||||
char *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 */
|
||||
@ -474,7 +458,7 @@ em_copy_prev_word(el, c)
|
||||
|
||||
el->el_line.cursor = dp;/* put cursor at end */
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -483,12 +467,11 @@ em_copy_prev_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_inc_search_next(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_inc_search_next(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_search.patlen = 0;
|
||||
return ce_inc_search(el, ED_SEARCH_NEXT_HISTORY);
|
||||
return (ce_inc_search(el, ED_SEARCH_NEXT_HISTORY));
|
||||
}
|
||||
|
||||
|
||||
@ -497,10 +480,9 @@ em_inc_search_next(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
em_inc_search_prev(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
em_inc_search_prev(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_search.patlen = 0;
|
||||
return ce_inc_search(el, ED_SEARCH_PREV_HISTORY);
|
||||
return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
|
||||
}
|
||||
|
@ -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: hist.c,v 1.8 2001/01/10 07:45:41 jdolecek Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* hist.c: History access functions
|
||||
@ -51,14 +55,17 @@ static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
|
||||
* Initialization function.
|
||||
*/
|
||||
protected int
|
||||
hist_init(el)
|
||||
EditLine *el;
|
||||
hist_init(EditLine *el)
|
||||
{
|
||||
|
||||
el->el_history.fun = NULL;
|
||||
el->el_history.ref = NULL;
|
||||
el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
|
||||
el->el_history.sz = EL_BUFSIZ;
|
||||
if (el->el_history.buf == NULL)
|
||||
return (-1);
|
||||
el->el_history.last = el->el_history.buf;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -66,9 +73,9 @@ hist_init(el)
|
||||
* clean up history;
|
||||
*/
|
||||
protected void
|
||||
hist_end(el)
|
||||
EditLine *el;
|
||||
hist_end(EditLine *el)
|
||||
{
|
||||
|
||||
el_free((ptr_t) el->el_history.buf);
|
||||
el->el_history.buf = NULL;
|
||||
}
|
||||
@ -78,15 +85,12 @@ hist_end(el)
|
||||
* Set new history interface
|
||||
*/
|
||||
protected int
|
||||
hist_set(el, fun, ptr)
|
||||
EditLine *el;
|
||||
hist_fun_t fun;
|
||||
ptr_t ptr;
|
||||
|
||||
hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
|
||||
{
|
||||
|
||||
el->el_history.ref = ptr;
|
||||
el->el_history.fun = fun;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -95,14 +99,14 @@ hist_set(el, fun, ptr)
|
||||
* eventno tells us the event to get.
|
||||
*/
|
||||
protected el_action_t
|
||||
hist_get(el)
|
||||
EditLine *el;
|
||||
hist_get(EditLine *el)
|
||||
{
|
||||
const char *hp;
|
||||
int h;
|
||||
|
||||
if (el->el_history.eventno == 0) { /* if really the current line */
|
||||
(void) strncpy(el->el_line.buffer, el->el_history.buf, EL_BUFSIZ);
|
||||
(void) strncpy(el->el_line.buffer, el->el_history.buf,
|
||||
el->el_history.sz);
|
||||
el->el_line.lastchar = el->el_line.buffer +
|
||||
(el->el_history.last - el->el_history.buf);
|
||||
|
||||
@ -113,24 +117,23 @@ hist_get(el)
|
||||
#endif /* KSHVI */
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
if (el->el_history.ref == NULL)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
hp = HIST_FIRST(el);
|
||||
|
||||
if (hp == NULL)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
for (h = 1; h < el->el_history.eventno; h++)
|
||||
if ((hp = HIST_NEXT(el)) == NULL) {
|
||||
el->el_history.eventno = h;
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
(void) strncpy(el->el_line.buffer, hp, EL_BUFSIZ);
|
||||
(void) strncpy(el->el_line.buffer, hp,
|
||||
(size_t)(el->el_line.limit - el->el_line.buffer));
|
||||
el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
|
||||
|
||||
if (el->el_line.lastchar > el->el_line.buffer) {
|
||||
@ -141,7 +144,6 @@ hist_get(el)
|
||||
if (el->el_line.lastchar < el->el_line.buffer)
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
}
|
||||
|
||||
#ifdef KSHVI
|
||||
if (el->el_map.type == MAP_VI)
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
@ -149,24 +151,47 @@ hist_get(el)
|
||||
#endif /* KSHVI */
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
/* hist_list()
|
||||
* List history entries
|
||||
*/
|
||||
protected int
|
||||
/*ARGSUSED*/
|
||||
hist_list(el, argc, argv)
|
||||
EditLine *el;
|
||||
int argc;
|
||||
char **argv;
|
||||
hist_list(EditLine *el, int argc, char **argv)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
if (el->el_history.ref == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
|
||||
(void) fprintf(el->el_outfile, "%d %s", el->el_history.ev->num, str);
|
||||
return 0;
|
||||
(void) fprintf(el->el_outfile, "%d %s",
|
||||
el->el_history.ev.num, str);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* hist_enlargebuf()
|
||||
* Enlarge history buffer to specified value. Called from el_enlargebufs().
|
||||
* Return 0 for failure, 1 for success.
|
||||
*/
|
||||
protected int
|
||||
/*ARGSUSED*/
|
||||
hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
|
||||
{
|
||||
char *newbuf;
|
||||
|
||||
newbuf = realloc(el->el_history.buf, newsz);
|
||||
if (!newbuf)
|
||||
return 0;
|
||||
|
||||
(void) memset(&newbuf[oldsz], '\0', newsz - oldsz);
|
||||
|
||||
el->el_history.last = newbuf +
|
||||
(el->el_history.last - el->el_history.buf);
|
||||
el->el_history.buf = newbuf;
|
||||
el->el_history.sz = newsz;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)hist.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: hist.h,v 1.5 2000/09/04 22:06:30 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -44,21 +46,21 @@
|
||||
|
||||
#include "histedit.h"
|
||||
|
||||
typedef const HistEvent * (*hist_fun_t) __P((ptr_t, int, ...));
|
||||
typedef int (*hist_fun_t)(ptr_t, HistEvent *, int, ...);
|
||||
|
||||
typedef struct el_history_t {
|
||||
char *buf; /* The history buffer */
|
||||
size_t sz; /* Size of history buffer */
|
||||
char *last; /* The last character */
|
||||
int eventno; /* Event we are looking for */
|
||||
ptr_t ref; /* Argument for history fcns */
|
||||
hist_fun_t fun; /* Event access */
|
||||
const HistEvent *ev; /* Event cookie */
|
||||
HistEvent ev; /* Event cookie */
|
||||
} el_history_t;
|
||||
|
||||
#define HIST_FUN(el, fn, arg) \
|
||||
((((el)->el_history.ev = \
|
||||
(*(el)->el_history.fun)((el)->el_history.ref, fn, arg)) == NULL) ? \
|
||||
NULL : (el)->el_history.ev->str)
|
||||
((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
|
||||
fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
|
||||
|
||||
#define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL)
|
||||
#define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL)
|
||||
@ -68,10 +70,11 @@ typedef struct el_history_t {
|
||||
#define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
|
||||
#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
|
||||
|
||||
protected int hist_init __P((EditLine *));
|
||||
protected void hist_end __P((EditLine *));
|
||||
protected el_action_t hist_get __P((EditLine *));
|
||||
protected int hist_set __P((EditLine *, hist_fun_t, ptr_t));
|
||||
protected int hist_list __P((EditLine *, int, char **));
|
||||
protected int hist_init(EditLine *);
|
||||
protected void hist_end(EditLine *);
|
||||
protected el_action_t hist_get(EditLine *);
|
||||
protected int hist_set(EditLine *, hist_fun_t, ptr_t);
|
||||
protected int hist_list(EditLine *, int, char **);
|
||||
protected int hist_enlargebuf(EditLine *, size_t, size_t);
|
||||
|
||||
#endif /* _h_el_hist */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -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: key.c,v 1.11 2001/01/23 15:55:30 jdolecek Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* key.c: This module contains the procedures for maintaining
|
||||
@ -80,17 +84,16 @@ struct key_node_t {
|
||||
struct key_node_t *sibling; /* ptr to another key with same prefix*/
|
||||
};
|
||||
|
||||
private int node_trav __P((EditLine *, key_node_t *, char *,
|
||||
key_value_t *));
|
||||
private int node__try __P((key_node_t *, char *,
|
||||
key_value_t *, int));
|
||||
private key_node_t *node__get __P((int));
|
||||
private void node__put __P((key_node_t *));
|
||||
private int node__delete __P((key_node_t **, char *));
|
||||
private int node_lookup __P((EditLine *, char *, key_node_t *,
|
||||
int));
|
||||
private int node_enum __P((EditLine *, key_node_t *, int));
|
||||
private int key__decode_char __P((char *, int, int));
|
||||
private int node_trav(EditLine *, key_node_t *, char *,
|
||||
key_value_t *);
|
||||
private int node__try(EditLine *, key_node_t *, const char *,
|
||||
key_value_t *, int);
|
||||
private key_node_t *node__get(int);
|
||||
private void node__put(EditLine *, key_node_t *);
|
||||
private int node__delete(EditLine *, key_node_t **, char *);
|
||||
private int node_lookup(EditLine *, char *, key_node_t *, int);
|
||||
private int node_enum(EditLine *, key_node_t *, int);
|
||||
private int key__decode_char(char *, int, int);
|
||||
|
||||
#define KEY_BUFSIZ EL_BUFSIZ
|
||||
|
||||
@ -99,13 +102,15 @@ private int key__decode_char __P((char *, int, int));
|
||||
* Initialize the key maps
|
||||
*/
|
||||
protected int
|
||||
key_init(el)
|
||||
EditLine *el;
|
||||
key_init(EditLine *el)
|
||||
{
|
||||
|
||||
el->el_key.buf = (char *) el_malloc(KEY_BUFSIZ);
|
||||
if (el->el_key.buf == NULL)
|
||||
return (-1);
|
||||
el->el_key.map = NULL;
|
||||
key_reset(el);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -113,9 +118,9 @@ key_init(el)
|
||||
* Free the key maps
|
||||
*/
|
||||
protected void
|
||||
key_end(el)
|
||||
EditLine *el;
|
||||
key_end(EditLine *el)
|
||||
{
|
||||
|
||||
el_free((ptr_t) el->el_key.buf);
|
||||
el->el_key.buf = NULL;
|
||||
/* XXX: provide a function to clear the keys */
|
||||
@ -127,12 +132,11 @@ key_end(el)
|
||||
* Associate cmd with a key value
|
||||
*/
|
||||
protected key_value_t *
|
||||
key_map_cmd(el, cmd)
|
||||
EditLine *el;
|
||||
int cmd;
|
||||
key_map_cmd(EditLine *el, int cmd)
|
||||
{
|
||||
|
||||
el->el_key.val.cmd = (el_action_t) cmd;
|
||||
return &el->el_key.val;
|
||||
return (&el->el_key.val);
|
||||
}
|
||||
|
||||
|
||||
@ -140,12 +144,11 @@ key_map_cmd(el, cmd)
|
||||
* Associate str with a key value
|
||||
*/
|
||||
protected key_value_t *
|
||||
key_map_str(el, str)
|
||||
EditLine *el;
|
||||
char *str;
|
||||
key_map_str(EditLine *el, char *str)
|
||||
{
|
||||
|
||||
el->el_key.val.str = str;
|
||||
return &el->el_key.val;
|
||||
return (&el->el_key.val);
|
||||
}
|
||||
|
||||
|
||||
@ -155,10 +158,10 @@ key_map_str(el, str)
|
||||
* [Always bind the ansi arrow keys?]
|
||||
*/
|
||||
protected void
|
||||
key_reset(el)
|
||||
EditLine *el;
|
||||
key_reset(EditLine *el)
|
||||
{
|
||||
node__put(el->el_key.map);
|
||||
|
||||
node__put(el, el->el_key.map);
|
||||
el->el_key.map = NULL;
|
||||
return;
|
||||
}
|
||||
@ -173,14 +176,11 @@ key_reset(el)
|
||||
* The last character read is returned in *ch.
|
||||
*/
|
||||
protected int
|
||||
key_get(el, ch, val)
|
||||
EditLine *el;
|
||||
char *ch;
|
||||
key_value_t *val;
|
||||
key_get(EditLine *el, char *ch, key_value_t *val)
|
||||
{
|
||||
return node_trav(el, el->el_key.map, ch, val);
|
||||
}
|
||||
|
||||
return (node_trav(el, el->el_key.map, ch, val));
|
||||
}
|
||||
|
||||
|
||||
/* key_add():
|
||||
@ -190,30 +190,26 @@ key_get(el, ch, val)
|
||||
* out str or a unix command.
|
||||
*/
|
||||
protected void
|
||||
key_add(el, key, val, ntype)
|
||||
EditLine *el;
|
||||
char *key;
|
||||
key_value_t *val;
|
||||
int ntype;
|
||||
key_add(EditLine *el, const char *key, key_value_t *val, int ntype)
|
||||
{
|
||||
|
||||
if (key[0] == '\0') {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"key_add: Null extended-key not allowed.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (ntype == XK_CMD && val->cmd == ED_SEQUENCE_LEAD_IN) {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"key_add: sequence-lead-in command not allowed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (el->el_key.map == NULL)
|
||||
/* tree is initially empty. Set up new node to match key[0] */
|
||||
el->el_key.map = node__get(key[0]); /* it is properly initialized */
|
||||
el->el_key.map = node__get(key[0]);
|
||||
/* it is properly initialized */
|
||||
|
||||
/* Now recurse through el->el_key.map */
|
||||
(void) node__try(el->el_key.map, key, val, ntype);
|
||||
(void) node__try(el, el->el_key.map, key, val, ntype);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -222,11 +218,9 @@ key_add(el, key, val, ntype)
|
||||
*
|
||||
*/
|
||||
protected void
|
||||
key_clear(el, map, in)
|
||||
EditLine *el;
|
||||
el_action_t *map;
|
||||
char *in;
|
||||
key_clear(EditLine *el, el_action_t *map, char *in)
|
||||
{
|
||||
|
||||
if ((map[(unsigned char)*in] == ED_SEQUENCE_LEAD_IN) &&
|
||||
((map == el->el_map.key &&
|
||||
el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) ||
|
||||
@ -241,21 +235,19 @@ key_clear(el, map, in)
|
||||
* they exists.
|
||||
*/
|
||||
protected int
|
||||
key_delete(el, key)
|
||||
EditLine *el;
|
||||
char *key;
|
||||
key_delete(EditLine *el, char *key)
|
||||
{
|
||||
|
||||
if (key[0] == '\0') {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"key_delete: Null extended-key not allowed.\n");
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (el->el_key.map == NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
(void) node__delete(&el->el_key.map, key);
|
||||
return 0;
|
||||
(void) node__delete(el, &el->el_key.map, key);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -264,10 +256,9 @@ key_delete(el, key)
|
||||
* Print entire el->el_key.map if null
|
||||
*/
|
||||
protected void
|
||||
key_print(el, key)
|
||||
EditLine *el;
|
||||
char *key;
|
||||
key_print(EditLine *el, char *key)
|
||||
{
|
||||
|
||||
/* do nothing if el->el_key.map is empty and null key specified */
|
||||
if (el->el_key.map == NULL && *key == 0)
|
||||
return;
|
||||
@ -275,7 +266,8 @@ key_print(el, key)
|
||||
el->el_key.buf[0] = '"';
|
||||
if (node_lookup(el, key, el->el_key.map, 1) <= -1)
|
||||
/* key is not bound */
|
||||
(void) fprintf(el->el_errfile, "Unbound extended key \"%s\"\n", key);
|
||||
(void) fprintf(el->el_errfile, "Unbound extended key \"%s\"\n",
|
||||
key);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -285,39 +277,34 @@ key_print(el, key)
|
||||
* found. May read in more characters.
|
||||
*/
|
||||
private int
|
||||
node_trav(el, ptr, ch, val)
|
||||
EditLine *el;
|
||||
key_node_t *ptr;
|
||||
char *ch;
|
||||
key_value_t *val;
|
||||
node_trav(EditLine *el, key_node_t *ptr, char *ch, key_value_t *val)
|
||||
{
|
||||
|
||||
if (ptr->ch == *ch) {
|
||||
/* match found */
|
||||
if (ptr->next) {
|
||||
/* key not complete so get next char */
|
||||
if (el_getc(el, ch) != 1) { /* if EOF or error */
|
||||
val->cmd = ED_END_OF_FILE;
|
||||
return XK_CMD;/* PWP: Pretend we just read an end-of-file */
|
||||
return (XK_CMD);
|
||||
/* PWP: Pretend we just read an end-of-file */
|
||||
}
|
||||
return node_trav(el, ptr->next, ch, val);
|
||||
}
|
||||
else {
|
||||
return (node_trav(el, ptr->next, ch, val));
|
||||
} else {
|
||||
*val = ptr->val;
|
||||
if (ptr->type != XK_CMD)
|
||||
*ch = '\0';
|
||||
return ptr->type;
|
||||
return (ptr->type);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* no match found here */
|
||||
if (ptr->sibling) {
|
||||
/* try next sibling */
|
||||
return node_trav(el, ptr->sibling, ch, val);
|
||||
}
|
||||
else {
|
||||
return (node_trav(el, ptr->sibling, ch, val));
|
||||
} else {
|
||||
/* no next sibling -- mismatch */
|
||||
val->str = NULL;
|
||||
return XK_STR;
|
||||
return (XK_STR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -327,12 +314,9 @@ node_trav(el, ptr, ch, val)
|
||||
* Find a node that matches *str or allocate a new one
|
||||
*/
|
||||
private int
|
||||
node__try(ptr, str, val, ntype)
|
||||
key_node_t *ptr;
|
||||
char *str;
|
||||
key_value_t *val;
|
||||
int ntype;
|
||||
node__try(EditLine *el, key_node_t *ptr, const char *str, key_value_t *val, int ntype)
|
||||
{
|
||||
|
||||
if (ptr->ch != *str) {
|
||||
key_node_t *xm;
|
||||
|
||||
@ -343,11 +327,11 @@ node__try(ptr, str, val, ntype)
|
||||
xm->sibling = node__get(*str); /* setup new node */
|
||||
ptr = xm->sibling;
|
||||
}
|
||||
|
||||
if (*++str == '\0') {
|
||||
/* we're there */
|
||||
if (ptr->next != NULL) {
|
||||
node__put(ptr->next); /* lose longer keys with this prefix */
|
||||
node__put(el, ptr->next);
|
||||
/* lose longer keys with this prefix */
|
||||
ptr->next = NULL;
|
||||
}
|
||||
switch (ptr->type) {
|
||||
@ -360,7 +344,8 @@ node__try(ptr, str, val, ntype)
|
||||
el_free((ptr_t) ptr->val.str);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
|
||||
ptr->type));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -373,17 +358,16 @@ node__try(ptr, str, val, ntype)
|
||||
ptr->val.str = strdup(val->str);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* still more chars to go */
|
||||
if (ptr->next == NULL)
|
||||
ptr->next = node__get(*str); /* setup new node */
|
||||
(void) node__try(ptr->next, str, val, ntype);
|
||||
(void) node__try(el, ptr->next, str, val, ntype);
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -391,9 +375,7 @@ node__try(ptr, str, val, ntype)
|
||||
* Delete node that matches str
|
||||
*/
|
||||
private int
|
||||
node__delete(inptr, str)
|
||||
key_node_t **inptr;
|
||||
char *str;
|
||||
node__delete(EditLine *el, key_node_t **inptr, char *str)
|
||||
{
|
||||
key_node_t *ptr;
|
||||
key_node_t *prev_ptr = NULL;
|
||||
@ -407,11 +389,10 @@ node__delete(inptr, str)
|
||||
if (xm->sibling->ch == *str)
|
||||
break;
|
||||
if (xm->sibling == NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
prev_ptr = xm;
|
||||
ptr = xm->sibling;
|
||||
}
|
||||
|
||||
if (*++str == '\0') {
|
||||
/* we're there */
|
||||
if (prev_ptr == NULL)
|
||||
@ -419,41 +400,39 @@ node__delete(inptr, str)
|
||||
else
|
||||
prev_ptr->sibling = ptr->sibling;
|
||||
ptr->sibling = NULL;
|
||||
node__put(ptr);
|
||||
return 1;
|
||||
}
|
||||
else if (ptr->next != NULL && node__delete(&ptr->next, str) == 1) {
|
||||
node__put(el, ptr);
|
||||
return (1);
|
||||
} else if (ptr->next != NULL &&
|
||||
node__delete(el, &ptr->next, str) == 1) {
|
||||
if (ptr->next != NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
if (prev_ptr == NULL)
|
||||
*inptr = ptr->sibling;
|
||||
else
|
||||
prev_ptr->sibling = ptr->sibling;
|
||||
ptr->sibling = NULL;
|
||||
node__put(ptr);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
node__put(el, ptr);
|
||||
return (1);
|
||||
} else {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* node__put():
|
||||
* Puts a tree of nodes onto free list using free(3).
|
||||
*/
|
||||
private void
|
||||
node__put(ptr)
|
||||
key_node_t *ptr;
|
||||
node__put(EditLine *el, key_node_t *ptr)
|
||||
{
|
||||
if (ptr == NULL)
|
||||
return;
|
||||
|
||||
if (ptr->next != NULL) {
|
||||
node__put(ptr->next);
|
||||
node__put(el, ptr->next);
|
||||
ptr->next = NULL;
|
||||
}
|
||||
|
||||
node__put(ptr->sibling);
|
||||
node__put(el, ptr->sibling);
|
||||
|
||||
switch (ptr->type) {
|
||||
case XK_CMD:
|
||||
@ -465,7 +444,7 @@ node__put(ptr)
|
||||
el_free((ptr_t) ptr->val.str);
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type));
|
||||
break;
|
||||
}
|
||||
el_free((ptr_t) ptr);
|
||||
@ -476,18 +455,19 @@ node__put(ptr)
|
||||
* Returns pointer to an key_node_t for ch.
|
||||
*/
|
||||
private key_node_t *
|
||||
node__get(ch)
|
||||
int ch;
|
||||
node__get(int ch)
|
||||
{
|
||||
key_node_t *ptr;
|
||||
|
||||
ptr = (key_node_t *) el_malloc((size_t) sizeof(key_node_t));
|
||||
if (ptr == NULL)
|
||||
return NULL;
|
||||
ptr->ch = ch;
|
||||
ptr->type = XK_NOD;
|
||||
ptr->val.str = NULL;
|
||||
ptr->next = NULL;
|
||||
ptr->sibling = NULL;
|
||||
return ptr;
|
||||
return (ptr);
|
||||
}
|
||||
|
||||
|
||||
@ -497,23 +477,18 @@ node__get(ch)
|
||||
* Print if last node
|
||||
*/
|
||||
private int
|
||||
node_lookup(el, str, ptr, cnt)
|
||||
EditLine *el;
|
||||
char *str;
|
||||
key_node_t *ptr;
|
||||
int cnt;
|
||||
node_lookup(EditLine *el, char *str, key_node_t *ptr, int cnt)
|
||||
{
|
||||
int ncnt;
|
||||
|
||||
if (ptr == NULL)
|
||||
return -1; /* cannot have null ptr */
|
||||
return (-1); /* cannot have null ptr */
|
||||
|
||||
if (*str == 0) {
|
||||
/* no more chars in str. node_enum from here. */
|
||||
(void) node_enum(el, ptr, cnt);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return (0);
|
||||
} else {
|
||||
/* If match put this char into el->el_key.buf. Recurse */
|
||||
if (ptr->ch == *str) {
|
||||
/* match found */
|
||||
@ -521,25 +496,27 @@ node_lookup(el, str, ptr, cnt)
|
||||
(unsigned char) ptr->ch);
|
||||
if (ptr->next != NULL)
|
||||
/* not yet at leaf */
|
||||
return node_lookup(el, str + 1, ptr->next, ncnt + 1);
|
||||
return (node_lookup(el, str + 1, ptr->next,
|
||||
ncnt + 1));
|
||||
else {
|
||||
/* next node is null so key should be complete */
|
||||
if (str[1] == 0) {
|
||||
el->el_key.buf[ncnt + 1] = '"';
|
||||
el->el_key.buf[ncnt + 2] = '\0';
|
||||
key_kprint(el, el->el_key.buf, &ptr->val, ptr->type);
|
||||
return 0;
|
||||
key_kprint(el, el->el_key.buf,
|
||||
&ptr->val, ptr->type);
|
||||
return (0);
|
||||
} else
|
||||
return (-1);
|
||||
/* mismatch -- str still has chars */
|
||||
}
|
||||
else
|
||||
return -1;/* mismatch -- str still has chars */
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
/* no match found try sibling */
|
||||
if (ptr->sibling)
|
||||
return node_lookup(el, str, ptr->sibling, cnt);
|
||||
return (node_lookup(el, str, ptr->sibling,
|
||||
cnt));
|
||||
else
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -549,10 +526,7 @@ node_lookup(el, str, ptr, cnt)
|
||||
* Traverse the node printing the characters it is bound in buffer
|
||||
*/
|
||||
private int
|
||||
node_enum(el, ptr, cnt)
|
||||
EditLine *el;
|
||||
key_node_t *ptr;
|
||||
int cnt;
|
||||
node_enum(EditLine *el, key_node_t *ptr, int cnt)
|
||||
{
|
||||
int ncnt;
|
||||
|
||||
@ -562,16 +536,15 @@ node_enum(el, ptr, cnt)
|
||||
(void) fprintf(el->el_errfile,
|
||||
"Some extended keys too long for internal print buffer");
|
||||
(void) fprintf(el->el_errfile, " \"%s...\"\n", el->el_key.buf);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (ptr == NULL) {
|
||||
#ifdef DEBUG_EDIT
|
||||
(void) fprintf(el->el_errfile, "node_enum: BUG!! Null ptr passed\n!");
|
||||
(void) fprintf(el->el_errfile,
|
||||
"node_enum: BUG!! Null ptr passed\n!");
|
||||
#endif
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* put this char at end of str */
|
||||
ncnt = key__decode_char(el->el_key.buf, cnt, (unsigned char) ptr->ch);
|
||||
if (ptr->next == NULL) {
|
||||
@ -579,14 +552,13 @@ node_enum(el, ptr, cnt)
|
||||
el->el_key.buf[ncnt + 1] = '"';
|
||||
el->el_key.buf[ncnt + 2] = '\0';
|
||||
key_kprint(el, el->el_key.buf, &ptr->val, ptr->type);
|
||||
}
|
||||
else
|
||||
} else
|
||||
(void) node_enum(el, ptr->next, ncnt + 1);
|
||||
|
||||
/* go to sibling if there is one */
|
||||
if (ptr->sibling)
|
||||
(void) node_enum(el, ptr->sibling, cnt);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -595,11 +567,7 @@ node_enum(el, ptr, cnt)
|
||||
* function specified by val
|
||||
*/
|
||||
protected void
|
||||
key_kprint(el, key, val, ntype)
|
||||
EditLine *el;
|
||||
char *key;
|
||||
key_value_t *val;
|
||||
int ntype;
|
||||
key_kprint(EditLine *el, char *key, key_value_t *val, int ntype)
|
||||
{
|
||||
el_bindings_t *fp;
|
||||
char unparsbuf[EL_BUFSIZ];
|
||||
@ -609,28 +577,30 @@ key_kprint(el, key, val, ntype)
|
||||
switch (ntype) {
|
||||
case XK_STR:
|
||||
case XK_EXE:
|
||||
(void) fprintf(el->el_errfile, fmt, key,
|
||||
(void) fprintf(el->el_outfile, fmt, key,
|
||||
key__decode_str(val->str, unparsbuf,
|
||||
ntype == XK_STR ? "\"\"" : "[]"));
|
||||
break;
|
||||
case XK_CMD:
|
||||
for (fp = el->el_map.help; fp->name; fp++)
|
||||
if (val->cmd == fp->func) {
|
||||
(void) fprintf(el->el_errfile, fmt, key, fp->name);
|
||||
(void) fprintf(el->el_outfile, fmt,
|
||||
key, fp->name);
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG_KEY
|
||||
if (fp->name == NULL)
|
||||
(void) fprintf(el->el_errfile, "BUG! Command not found.\n");
|
||||
(void) fprintf(el->el_outfile,
|
||||
"BUG! Command not found.\n");
|
||||
#endif
|
||||
|
||||
break;
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
|
||||
break;
|
||||
}
|
||||
else
|
||||
(void) fprintf(el->el_errfile, fmt, key, "no input");
|
||||
(void) fprintf(el->el_outfile, fmt, key, "no input");
|
||||
}
|
||||
|
||||
|
||||
@ -638,53 +608,43 @@ key_kprint(el, key, val, ntype)
|
||||
* Put a printable form of char in buf.
|
||||
*/
|
||||
private int
|
||||
key__decode_char(buf, cnt, ch)
|
||||
char *buf;
|
||||
int cnt, ch;
|
||||
key__decode_char(char *buf, int cnt, int ch)
|
||||
{
|
||||
ch = (unsigned char)ch;
|
||||
|
||||
if (ch == 0) {
|
||||
buf[cnt++] = '^';
|
||||
buf[cnt] = '@';
|
||||
return cnt;
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
if (iscntrl(ch)) {
|
||||
buf[cnt++] = '^';
|
||||
if (ch == 0177)
|
||||
buf[cnt] = '?';
|
||||
else
|
||||
buf[cnt] = toascii(ch) | 0100;
|
||||
}
|
||||
else if (ch == '^') {
|
||||
} else if (ch == '^') {
|
||||
buf[cnt++] = '\\';
|
||||
buf[cnt] = '^';
|
||||
}
|
||||
else if (ch == '\\') {
|
||||
} else if (ch == '\\') {
|
||||
buf[cnt++] = '\\';
|
||||
buf[cnt] = '\\';
|
||||
}
|
||||
else if (ch == ' ' || (isprint(ch) && !isspace(ch))) {
|
||||
} else if (ch == ' ' || (isprint(ch) && !isspace(ch))) {
|
||||
buf[cnt] = ch;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
buf[cnt++] = '\\';
|
||||
buf[cnt++] = ((ch >> 6) & 7) + '0';
|
||||
buf[cnt++] = ((ch >> 3) & 7) + '0';
|
||||
buf[cnt++] = (((unsigned int) ch >> 6) & 7) + '0';
|
||||
buf[cnt++] = (((unsigned int) ch >> 3) & 7) + '0';
|
||||
buf[cnt] = (ch & 7) + '0';
|
||||
}
|
||||
return cnt;
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
/* key__decode_str():
|
||||
* Make a printable version of the ey
|
||||
*/
|
||||
protected char *
|
||||
key__decode_str(str, buf, sep)
|
||||
char *str;
|
||||
char *buf;
|
||||
char *sep;
|
||||
key__decode_str(char *str, char *buf, char *sep)
|
||||
{
|
||||
char *b, *p;
|
||||
|
||||
@ -697,9 +657,8 @@ key__decode_str(str, buf, sep)
|
||||
if (sep[0] != '\0' && sep[1] != '\0')
|
||||
*b++ = sep[1];
|
||||
*b++ = 0;
|
||||
return buf;
|
||||
return (buf);
|
||||
}
|
||||
|
||||
for (p = str; *p != 0; p++) {
|
||||
if (iscntrl((unsigned char) *p)) {
|
||||
*b++ = '^';
|
||||
@ -707,24 +666,21 @@ key__decode_str(str, buf, sep)
|
||||
*b++ = '?';
|
||||
else
|
||||
*b++ = toascii(*p) | 0100;
|
||||
}
|
||||
else if (*p == '^' || *p == '\\') {
|
||||
} else if (*p == '^' || *p == '\\') {
|
||||
*b++ = '\\';
|
||||
*b++ = *p;
|
||||
}
|
||||
else if (*p == ' ' || (isprint((unsigned char) *p) &&
|
||||
} else if (*p == ' ' || (isprint((unsigned char) *p) &&
|
||||
!isspace((unsigned char) *p))) {
|
||||
*b++ = *p;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
*b++ = '\\';
|
||||
*b++ = ((*p >> 6) & 7) + '0';
|
||||
*b++ = ((*p >> 3) & 7) + '0';
|
||||
*b++ = (((unsigned int) *p >> 6) & 7) + '0';
|
||||
*b++ = (((unsigned int) *p >> 3) & 7) + '0';
|
||||
*b++ = (*p & 7) + '0';
|
||||
}
|
||||
}
|
||||
if (sep[0] != '\0' && sep[1] != '\0')
|
||||
*b++ = sep[1];
|
||||
*b++ = 0;
|
||||
return buf; /* should check for overflow */
|
||||
return (buf); /* should check for overflow */
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)key.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: key.h,v 1.4 2000/09/04 22:06:30 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -60,21 +62,17 @@ typedef struct el_key_t {
|
||||
#define XK_NOD 2
|
||||
#define XK_EXE 3
|
||||
|
||||
protected int key_init __P((EditLine *));
|
||||
protected void key_end __P((EditLine *));
|
||||
protected key_value_t * key_map_cmd __P((EditLine *, int));
|
||||
protected key_value_t * key_map_str __P((EditLine *, char *));
|
||||
protected void key_reset __P((EditLine *));
|
||||
protected int key_get __P((EditLine *, char *,
|
||||
key_value_t *));
|
||||
protected void key_add __P((EditLine *, char *, key_value_t *,
|
||||
int));
|
||||
protected void key_clear __P((EditLine *, el_action_t *,
|
||||
char *));
|
||||
protected int key_delete __P((EditLine *, char *));
|
||||
protected void key_print __P((EditLine *, char *));
|
||||
protected void key_kprint __P((EditLine *, char *,
|
||||
key_value_t *, int));
|
||||
protected char *key__decode_str __P((char *, char *, char *));
|
||||
protected int key_init(EditLine *);
|
||||
protected void key_end(EditLine *);
|
||||
protected key_value_t *key_map_cmd(EditLine *, int);
|
||||
protected key_value_t *key_map_str(EditLine *, char *);
|
||||
protected void key_reset(EditLine *);
|
||||
protected int key_get(EditLine *, char *, key_value_t *);
|
||||
protected void key_add(EditLine *, const char *, key_value_t *, int);
|
||||
protected void key_clear(EditLine *, el_action_t *, char *);
|
||||
protected int key_delete(EditLine *, char *);
|
||||
protected void key_print(EditLine *, char *);
|
||||
protected void key_kprint(EditLine *, char *, key_value_t *, int);
|
||||
protected char *key__decode_str(char *, char *, char *);
|
||||
|
||||
#endif /* _h_el_key */
|
||||
|
@ -1,4 +1,6 @@
|
||||
#!/bin/sh -
|
||||
# $NetBSD: makelist,v 1.6 2000/09/04 23:45:18 lukem Exp $
|
||||
# $FreeBSD$
|
||||
#
|
||||
# Copyright (c) 1992, 1993
|
||||
# The Regents of the University of California. All rights reserved.
|
||||
@ -38,8 +40,8 @@
|
||||
|
||||
# makelist.sh: Automatically generate header files...
|
||||
|
||||
AWK=awk
|
||||
USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>"
|
||||
AWK=/usr/bin/awk
|
||||
USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
|
||||
|
||||
if [ "x$1" = "x" ]
|
||||
then
|
||||
@ -53,13 +55,12 @@ shift
|
||||
FILES="$@"
|
||||
|
||||
case $FLAG in
|
||||
|
||||
# generate foo.h file from foo.c
|
||||
#
|
||||
-h)
|
||||
fn=`basename $FILES`
|
||||
OIFS="$IFS"
|
||||
IFS=".$IFS"
|
||||
set - $fn
|
||||
IFS="$OIFS"
|
||||
hdr="_h_$1_$2"
|
||||
set - `echo $FILES | sed -e 's/\\./_/g'`
|
||||
hdr="_h_`basename $1`"
|
||||
cat $FILES | $AWK '
|
||||
BEGIN {
|
||||
printf("/* Automatically generated file, do not edit */\n");
|
||||
@ -69,18 +70,26 @@ case $FLAG in
|
||||
pr = substr($2, 1, 2);
|
||||
if (pr == "vi" || pr == "em" || pr == "ed") {
|
||||
name = substr($2, 1, length($2) - 3);
|
||||
printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name);
|
||||
#
|
||||
# XXX: need a space between name and prototype so that -fc and -fh
|
||||
# parsing is much easier
|
||||
#
|
||||
printf("protected el_action_t\t%s (EditLine *, int);\n", name);
|
||||
}
|
||||
}
|
||||
END {
|
||||
printf("#endif /* %s */\n", "'$hdr'");
|
||||
}';;
|
||||
}'
|
||||
;;
|
||||
|
||||
# generate help.c from various .c files
|
||||
#
|
||||
-bc)
|
||||
cat $FILES | $AWK '
|
||||
BEGIN {
|
||||
printf("/* Automatically generated file, do not edit */\n");
|
||||
printf("#include \"sys.h\"\n#include \"el.h\"\n");
|
||||
printf("private struct el_bindings_t el_func_help[] = {\n");
|
||||
printf("private const struct el_bindings_t el_func_help[] = {\n");
|
||||
low = "abcdefghijklmnopqrstuvwxyz_";
|
||||
high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
|
||||
for (i = 1; i <= length(low); i++)
|
||||
@ -116,17 +125,25 @@ case $FLAG in
|
||||
END {
|
||||
printf(" { NULL, 0, NULL }\n");
|
||||
printf("};\n");
|
||||
printf("\nprotected el_bindings_t* help__get()");
|
||||
printf("\nprotected const el_bindings_t* help__get()");
|
||||
printf("{ return el_func_help; }\n");
|
||||
}';;
|
||||
}'
|
||||
;;
|
||||
|
||||
# generate help.h from various .c files
|
||||
#
|
||||
-bh)
|
||||
$AWK '
|
||||
BEGIN {
|
||||
printf("/* Automatically generated file, do not edit */\n");
|
||||
printf("#ifndef _h_help_c\n#define _h_help_c\n");
|
||||
printf("protected el_bindings_t *help__get\t__P((void));\n");
|
||||
printf("protected const el_bindings_t *help__get(void);\n");
|
||||
printf("#endif /* _h_help_c */\n");
|
||||
}' /dev/null;;
|
||||
}' /dev/null
|
||||
;;
|
||||
|
||||
# generate fcns.h from various .h files
|
||||
#
|
||||
-fh)
|
||||
cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
|
||||
sort | tr '[a-z]' '[A-Z]' | $AWK '
|
||||
@ -141,16 +158,20 @@ case $FLAG in
|
||||
END {
|
||||
printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
|
||||
|
||||
printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));");
|
||||
printf("\nprotected el_func_t* func__get __P((void));\n");
|
||||
printf("typedef el_action_t (*el_func_t)(EditLine *, int);");
|
||||
printf("\nprotected const el_func_t* func__get(void);\n");
|
||||
printf("#endif /* _h_fcns_c */\n");
|
||||
}';;
|
||||
}'
|
||||
;;
|
||||
|
||||
# generate fcns.c from various .h files
|
||||
#
|
||||
-fc)
|
||||
cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
|
||||
BEGIN {
|
||||
printf("/* Automatically generated file, do not edit */\n");
|
||||
printf("#include \"sys.h\"\n#include \"el.h\"\n");
|
||||
printf("private el_func_t el_func[] = {");
|
||||
printf("private const el_func_t el_func[] = {");
|
||||
maxlen = 80;
|
||||
needn = 1;
|
||||
len = 0;
|
||||
@ -170,8 +191,12 @@ case $FLAG in
|
||||
}
|
||||
END {
|
||||
printf("\n};\n");
|
||||
printf("\nprotected el_func_t* func__get() { return el_func; }\n");
|
||||
}';;
|
||||
printf("\nprotected const el_func_t* func__get() { return el_func; }\n");
|
||||
}'
|
||||
;;
|
||||
|
||||
# generate editline.c from various .c files
|
||||
#
|
||||
-e)
|
||||
echo "$FILES" | tr ' ' '\012' | $AWK '
|
||||
BEGIN {
|
||||
@ -181,8 +206,50 @@ case $FLAG in
|
||||
}
|
||||
{
|
||||
printf("#include \"%s\"\n", $1);
|
||||
}';;
|
||||
}'
|
||||
;;
|
||||
|
||||
# generate man page fragment from various .c files
|
||||
#
|
||||
-m)
|
||||
cat $FILES | $AWK '
|
||||
BEGIN {
|
||||
printf(".\\\" Section automatically generated with makelist\n");
|
||||
printf(".Bl -tag -width 4n\n");
|
||||
}
|
||||
/\(\):/ {
|
||||
pr = substr($2, 1, 2);
|
||||
if (pr == "vi" || pr == "em" || pr == "ed") {
|
||||
name = substr($2, 1, length($2) - 3);
|
||||
fname = "";
|
||||
for (i = 1; i <= length(name); i++) {
|
||||
s = substr(name, i, 1);
|
||||
if (s == "_")
|
||||
s = "-";
|
||||
fname = fname s;
|
||||
}
|
||||
|
||||
printf(".It Ic %s\n", fname);
|
||||
ok = 1;
|
||||
}
|
||||
}
|
||||
/^ \*/ {
|
||||
if (ok) {
|
||||
for (i = 2; i < NF; i++)
|
||||
printf("%s ", $i);
|
||||
printf("%s.\n", $i);
|
||||
ok = 0;
|
||||
}
|
||||
}
|
||||
END {
|
||||
printf(".El\n");
|
||||
printf(".\\\" End of section automatically generated with makelist\n");
|
||||
}'
|
||||
;;
|
||||
|
||||
*)
|
||||
echo $USAGE 1>&2
|
||||
exit 1;;
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
|
@ -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: map.c,v 1.13 2001/01/04 15:56:32 christos Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* map.c: Editor function definitions
|
||||
@ -49,15 +53,16 @@ static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
#define N_KEYS 256
|
||||
|
||||
private void map_print_key __P((EditLine *, el_action_t *, char *));
|
||||
private void map_print_some_keys __P((EditLine *, el_action_t *, int, int));
|
||||
private void map_print_all_keys __P((EditLine *));
|
||||
private void map_init_nls __P((EditLine *));
|
||||
private void map_init_meta __P((EditLine *));
|
||||
private void map_print_key(EditLine *, el_action_t *, char *);
|
||||
private void map_print_some_keys(EditLine *, el_action_t *, int, int);
|
||||
private void map_print_all_keys(EditLine *);
|
||||
private void map_init_nls(EditLine *);
|
||||
private void map_init_meta(EditLine *);
|
||||
|
||||
/* keymap tables ; should be N_KEYS*sizeof(KEYCMD) bytes long */
|
||||
|
||||
private el_action_t el_map_emacs[] = {
|
||||
|
||||
private const el_action_t el_map_emacs[] = {
|
||||
/* 0 */ EM_SET_MARK, /* ^@ */
|
||||
/* 1 */ ED_MOVE_TO_BEG, /* ^A */
|
||||
/* 2 */ ED_PREV_CHAR, /* ^B */
|
||||
@ -317,13 +322,14 @@ private el_action_t el_map_emacs[] = {
|
||||
/* 255 */
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* keymap table for vi. Each index into above tbl; should be
|
||||
* N_KEYS entries long. Vi mode uses a sticky-extend to do command mode:
|
||||
* insert mode characters are in the normal keymap, and command mode
|
||||
* in the extended keymap.
|
||||
*/
|
||||
private el_action_t el_map_vi_insert[] = {
|
||||
private const el_action_t el_map_vi_insert[] = {
|
||||
#ifdef KSHVI
|
||||
/* 0 */ ED_UNASSIGNED, /* ^@ */
|
||||
/* 1 */ ED_INSERT, /* ^A */
|
||||
@ -348,7 +354,8 @@ private el_action_t el_map_vi_insert[] = {
|
||||
/* 20 */ ED_INSERT, /* ^T */
|
||||
/* 21 */ VI_KILL_LINE_PREV, /* ^U */
|
||||
/* 22 */ ED_QUOTED_INSERT, /* ^V */
|
||||
/* 23 */ ED_DELETE_PREV_WORD, /* ^W */ /* Only until strt edit pos */
|
||||
/* 23 */ ED_DELETE_PREV_WORD, /* ^W */
|
||||
/* ED_DELETE_PREV_WORD: Only until strt edit pos */
|
||||
/* 24 */ ED_INSERT, /* ^X */
|
||||
/* 25 */ ED_INSERT, /* ^Y */
|
||||
/* 26 */ ED_INSERT, /* ^Z */
|
||||
@ -358,13 +365,19 @@ private el_action_t el_map_vi_insert[] = {
|
||||
/* 30 */ ED_INSERT, /* ^^ */
|
||||
/* 31 */ ED_INSERT, /* ^_ */
|
||||
#else /* !KSHVI */
|
||||
/* 0 */ ED_UNASSIGNED, /* ^@ */ /* NOTE: These mappings do */
|
||||
/* 1 */ ED_MOVE_TO_BEG, /* ^A */ /* NOT Correspond well to */
|
||||
/* 2 */ ED_PREV_CHAR, /* ^B */ /* the KSH VI editing as- */
|
||||
/* 3 */ ED_TTY_SIGINT, /* ^C */ /* signments. On the other */
|
||||
/* 4 */ VI_LIST_OR_EOF, /* ^D */ /* hand they are convenient*/
|
||||
/* 5 */ ED_MOVE_TO_END, /* ^E */ /* and many people have */
|
||||
/* 6 */ ED_NEXT_CHAR, /* ^F */ /* have gotten used to them*/
|
||||
/*
|
||||
* NOTE: These mappings do NOT Correspond well
|
||||
* to the KSH VI editing assignments.
|
||||
* On the other and they are convenient and
|
||||
* many people have have gotten used to them.
|
||||
*/
|
||||
/* 0 */ ED_UNASSIGNED, /* ^@ */
|
||||
/* 1 */ ED_MOVE_TO_BEG, /* ^A */
|
||||
/* 2 */ ED_PREV_CHAR, /* ^B */
|
||||
/* 3 */ ED_TTY_SIGINT, /* ^C */
|
||||
/* 4 */ VI_LIST_OR_EOF, /* ^D */
|
||||
/* 5 */ ED_MOVE_TO_END, /* ^E */
|
||||
/* 6 */ ED_NEXT_CHAR, /* ^F */
|
||||
/* 7 */ ED_UNASSIGNED, /* ^G */
|
||||
/* 8 */ ED_DELETE_PREV_CHAR, /* ^H */ /* BackSpace key */
|
||||
/* 9 */ ED_UNASSIGNED, /* ^I */ /* Tab Key */
|
||||
@ -617,7 +630,7 @@ private el_action_t el_map_vi_insert[] = {
|
||||
/* 255 */ ED_UNASSIGNED /* M-^? */
|
||||
};
|
||||
|
||||
private el_action_t el_map_vi_command[] = {
|
||||
private const el_action_t el_map_vi_command[] = {
|
||||
/* 0 */ ED_UNASSIGNED, /* ^@ */
|
||||
/* 1 */ ED_MOVE_TO_BEG, /* ^A */
|
||||
/* 2 */ ED_UNASSIGNED, /* ^B */
|
||||
@ -881,8 +894,7 @@ private el_action_t el_map_vi_command[] = {
|
||||
* Initialize and allocate the maps
|
||||
*/
|
||||
protected int
|
||||
map_init(el)
|
||||
EditLine *el;
|
||||
map_init(EditLine *el)
|
||||
{
|
||||
|
||||
/*
|
||||
@ -890,23 +902,32 @@ map_init(el)
|
||||
*/
|
||||
#ifdef MAP_DEBUG
|
||||
if (sizeof(el_map_emacs) != N_KEYS * sizeof(el_action_t))
|
||||
abort();
|
||||
EL_ABORT((el->errfile, "Emacs map incorrect\n"));
|
||||
if (sizeof(el_map_vi_command) != N_KEYS * sizeof(el_action_t))
|
||||
abort();
|
||||
EL_ABORT((el->errfile, "Vi command map incorrect\n"));
|
||||
if (sizeof(el_map_vi_insert) != N_KEYS * sizeof(el_action_t))
|
||||
abort();
|
||||
EL_ABORT((el->errfile, "Vi insert map incorrect\n"));
|
||||
#endif
|
||||
|
||||
el->el_map.alt = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
|
||||
if (el->el_map.alt == NULL)
|
||||
return (-1);
|
||||
el->el_map.key = (el_action_t *)el_malloc(sizeof(el_action_t) * N_KEYS);
|
||||
if (el->el_map.key == NULL)
|
||||
return (-1);
|
||||
el->el_map.emacs = el_map_emacs;
|
||||
el->el_map.vic = el_map_vi_command;
|
||||
el->el_map.vii = el_map_vi_insert;
|
||||
el->el_map.help = (el_bindings_t *) el_malloc(sizeof(el_bindings_t) *
|
||||
EL_NUM_FCNS);
|
||||
if (el->el_map.help == NULL)
|
||||
return (-1);
|
||||
(void) memcpy(el->el_map.help, help__get(),
|
||||
sizeof(el_bindings_t) * EL_NUM_FCNS);
|
||||
el->el_map.func = (el_func_t *) el_malloc(sizeof(el_func_t) * EL_NUM_FCNS);
|
||||
el->el_map.func = (el_func_t *)el_malloc(sizeof(el_func_t) *
|
||||
EL_NUM_FCNS);
|
||||
if (el->el_map.func == NULL)
|
||||
return (-1);
|
||||
memcpy(el->el_map.func, func__get(), sizeof(el_func_t) * EL_NUM_FCNS);
|
||||
el->el_map.nfunc = EL_NUM_FCNS;
|
||||
|
||||
@ -915,7 +936,7 @@ map_init(el)
|
||||
#else
|
||||
map_init_emacs(el);
|
||||
#endif /* VIDEFAULT */
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -923,9 +944,9 @@ map_init(el)
|
||||
* Free the space taken by the editor maps
|
||||
*/
|
||||
protected void
|
||||
map_end(el)
|
||||
EditLine *el;
|
||||
map_end(EditLine *el)
|
||||
{
|
||||
|
||||
el_free((ptr_t) el->el_map.alt);
|
||||
el->el_map.alt = NULL;
|
||||
el_free((ptr_t) el->el_map.key);
|
||||
@ -944,10 +965,10 @@ map_end(el)
|
||||
* Find all the printable keys and bind them to self insert
|
||||
*/
|
||||
private void
|
||||
map_init_nls(el)
|
||||
EditLine *el;
|
||||
map_init_nls(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
|
||||
el_action_t *map = el->el_map.key;
|
||||
|
||||
for (i = 0200; i <= 0377; i++)
|
||||
@ -960,11 +981,10 @@ map_init_nls(el)
|
||||
* Bind all the meta keys to the appropriate ESC-<key> sequence
|
||||
*/
|
||||
private void
|
||||
map_init_meta(el)
|
||||
EditLine *el;
|
||||
map_init_meta(EditLine *el)
|
||||
{
|
||||
char buf[3];
|
||||
register int i;
|
||||
int i;
|
||||
el_action_t *map = el->el_map.key;
|
||||
el_action_t *alt = el->el_map.alt;
|
||||
|
||||
@ -978,8 +998,7 @@ map_init_meta(el)
|
||||
i = 033;
|
||||
if (el->el_map.type == MAP_VI)
|
||||
map = alt;
|
||||
}
|
||||
else
|
||||
} else
|
||||
map = alt;
|
||||
}
|
||||
buf[0] = (char) i;
|
||||
@ -995,7 +1014,7 @@ map_init_meta(el)
|
||||
key_add(el, buf, key_map_cmd(el, (int) map[i]), XK_CMD);
|
||||
break;
|
||||
}
|
||||
map[buf[0]] = ED_SEQUENCE_LEAD_IN;
|
||||
map[(int) buf[0]] = ED_SEQUENCE_LEAD_IN;
|
||||
}
|
||||
|
||||
|
||||
@ -1003,14 +1022,13 @@ map_init_meta(el)
|
||||
* Initialize the vi bindings
|
||||
*/
|
||||
protected void
|
||||
map_init_vi(el)
|
||||
EditLine *el;
|
||||
map_init_vi(EditLine *el)
|
||||
{
|
||||
register int i;
|
||||
int i;
|
||||
el_action_t *key = el->el_map.key;
|
||||
el_action_t *alt = el->el_map.alt;
|
||||
el_action_t *vii = el->el_map.vii;
|
||||
el_action_t *vic = el->el_map.vic;
|
||||
const el_action_t *vii = el->el_map.vii;
|
||||
const el_action_t *vic = el->el_map.vic;
|
||||
|
||||
el->el_map.type = MAP_VI;
|
||||
el->el_map.current = el->el_map.key;
|
||||
@ -1023,10 +1041,7 @@ map_init_vi(el)
|
||||
}
|
||||
|
||||
map_init_meta(el);
|
||||
#ifdef notyet
|
||||
if (0 /* XXX: USER has set LC_CTYPE */)
|
||||
map_init_nls(el);
|
||||
#endif
|
||||
|
||||
tty_bind_char(el, 1);
|
||||
term_bind_arrow(el);
|
||||
@ -1037,14 +1052,13 @@ map_init_vi(el)
|
||||
* Initialize the emacs bindings
|
||||
*/
|
||||
protected void
|
||||
map_init_emacs(el)
|
||||
EditLine *el;
|
||||
map_init_emacs(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
char buf[3];
|
||||
el_action_t *key = el->el_map.key;
|
||||
el_action_t *alt = el->el_map.alt;
|
||||
el_action_t *emacs = el->el_map.emacs;
|
||||
const el_action_t *emacs = el->el_map.emacs;
|
||||
|
||||
el->el_map.type = MAP_EMACS;
|
||||
el->el_map.current = el->el_map.key;
|
||||
@ -1056,10 +1070,6 @@ map_init_emacs(el)
|
||||
}
|
||||
|
||||
map_init_meta(el);
|
||||
#ifdef notyet
|
||||
if (0 /* XXX: USER has set LC_CTYPE */)
|
||||
map_init_nls(el);
|
||||
#endif
|
||||
map_init_nls(el);
|
||||
|
||||
buf[0] = CONTROL('X');
|
||||
@ -1076,19 +1086,39 @@ map_init_emacs(el)
|
||||
* Set the editor
|
||||
*/
|
||||
protected int
|
||||
map_set_editor(el, editor)
|
||||
EditLine *el;
|
||||
char *editor;
|
||||
map_set_editor(EditLine *el, char *editor)
|
||||
{
|
||||
|
||||
if (strcmp(editor, "emacs") == 0) {
|
||||
map_init_emacs(el);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
if (strcmp(editor, "vi") == 0) {
|
||||
map_init_vi(el);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
/* map_get_editor():
|
||||
* Retrieve the editor
|
||||
*/
|
||||
protected int
|
||||
map_get_editor(EditLine *el, const char **editor)
|
||||
{
|
||||
|
||||
if (editor == NULL)
|
||||
return (-1);
|
||||
switch (el->el_map.type) {
|
||||
case MAP_EMACS:
|
||||
*editor = "emacs";
|
||||
return (0);
|
||||
case MAP_VI:
|
||||
*editor = "vi";
|
||||
return (0);
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
@ -1096,10 +1126,7 @@ map_set_editor(el, editor)
|
||||
* Print the function description for 1 key
|
||||
*/
|
||||
private void
|
||||
map_print_key(el, map, in)
|
||||
EditLine *el;
|
||||
el_action_t *map;
|
||||
char *in;
|
||||
map_print_key(EditLine *el, el_action_t *map, char *in)
|
||||
{
|
||||
char outbuf[EL_BUFSIZ];
|
||||
el_bindings_t *bp;
|
||||
@ -1112,8 +1139,7 @@ map_print_key(el, map, in)
|
||||
"%s\t->\t%s\n", outbuf, bp->name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
key_print(el, in);
|
||||
}
|
||||
|
||||
@ -1122,10 +1148,7 @@ map_print_key(el, map, in)
|
||||
* Print keys from first to last
|
||||
*/
|
||||
private void
|
||||
map_print_some_keys(el, map, first, last)
|
||||
EditLine *el;
|
||||
el_action_t *map;
|
||||
int first, last;
|
||||
map_print_some_keys(EditLine *el, el_action_t *map, int first, int last)
|
||||
{
|
||||
el_bindings_t *bp;
|
||||
char firstbuf[2], lastbuf[2];
|
||||
@ -1137,20 +1160,20 @@ map_print_some_keys(el, map, first, last)
|
||||
lastbuf[1] = 0;
|
||||
if (map[first] == ED_UNASSIGNED) {
|
||||
if (first == last)
|
||||
(void) fprintf(el->el_outfile, "%-15s-> is undefined\n",
|
||||
(void) fprintf(el->el_outfile,
|
||||
"%-15s-> is undefined\n",
|
||||
key__decode_str(firstbuf, unparsbuf, STRQQ));
|
||||
return;
|
||||
}
|
||||
|
||||
for (bp = el->el_map.help; bp->name != NULL; bp++) {
|
||||
if (bp->func == map[first]) {
|
||||
if (first == last) {
|
||||
(void) fprintf(el->el_outfile, "%-15s-> %s\n",
|
||||
key__decode_str(firstbuf, unparsbuf, STRQQ),
|
||||
bp->name);
|
||||
}
|
||||
else {
|
||||
(void) fprintf(el->el_outfile, "%-4s to %-7s-> %s\n",
|
||||
} else {
|
||||
(void) fprintf(el->el_outfile,
|
||||
"%-4s to %-7s-> %s\n",
|
||||
key__decode_str(firstbuf, unparsbuf, STRQQ),
|
||||
key__decode_str(lastbuf, extrabuf, STRQQ),
|
||||
bp->name);
|
||||
@ -1160,19 +1183,20 @@ map_print_some_keys(el, map, first, last)
|
||||
}
|
||||
#ifdef MAP_DEBUG
|
||||
if (map == el->el_map.key) {
|
||||
(void) fprintf(el->el_outfile, "BUG!!! %s isn't bound to anything.\n",
|
||||
(void) fprintf(el->el_outfile,
|
||||
"BUG!!! %s isn't bound to anything.\n",
|
||||
key__decode_str(firstbuf, unparsbuf, STRQQ));
|
||||
(void) fprintf(el->el_outfile, "el->el_map.key[%d] == %d\n",
|
||||
first, el->el_map.key[first]);
|
||||
}
|
||||
else {
|
||||
(void) fprintf(el->el_outfile, "BUG!!! %s isn't bound to anything.\n",
|
||||
} else {
|
||||
(void) fprintf(el->el_outfile,
|
||||
"BUG!!! %s isn't bound to anything.\n",
|
||||
key__decode_str(firstbuf, unparsbuf, STRQQ));
|
||||
(void) fprintf(el->el_outfile, "el->el_map.alt[%d] == %d\n",
|
||||
first, el->el_map.alt[first]);
|
||||
}
|
||||
#endif
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Error printing keys\n"));
|
||||
}
|
||||
|
||||
|
||||
@ -1180,8 +1204,7 @@ map_print_some_keys(el, map, first, last)
|
||||
* Print the function description for all keys.
|
||||
*/
|
||||
private void
|
||||
map_print_all_keys(el)
|
||||
EditLine *el;
|
||||
map_print_all_keys(EditLine *el)
|
||||
{
|
||||
int prev, i;
|
||||
|
||||
@ -1216,13 +1239,10 @@ map_print_all_keys(el)
|
||||
* Add/remove/change bindings
|
||||
*/
|
||||
protected int
|
||||
map_bind(el, argc, argv)
|
||||
EditLine *el;
|
||||
int argc;
|
||||
char **argv;
|
||||
map_bind(EditLine *el, int argc, char **argv)
|
||||
{
|
||||
el_action_t *map;
|
||||
int ntype, remove;
|
||||
int ntype, rem;
|
||||
char *p;
|
||||
char inbuf[EL_BUFSIZ];
|
||||
char outbuf[EL_BUFSIZ];
|
||||
@ -1233,11 +1253,11 @@ map_bind(el, argc, argv)
|
||||
int key;
|
||||
|
||||
if (argv == NULL)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
map = el->el_map.key;
|
||||
ntype = XK_CMD;
|
||||
key = remove = 0;
|
||||
key = rem = 0;
|
||||
for (argc = 1; (p = argv[argc]) != NULL; argc++)
|
||||
if (p[0] == '-')
|
||||
switch (p[1]) {
|
||||
@ -1258,24 +1278,27 @@ map_bind(el, argc, argv)
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
remove = 1;
|
||||
rem = 1;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
map_init_vi(el);
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
case 'e':
|
||||
map_init_emacs(el);
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
case 'l':
|
||||
for (bp = el->el_map.help; bp->name != NULL; bp++)
|
||||
(void) fprintf(el->el_outfile, "%s\n\t%s\n",
|
||||
for (bp = el->el_map.help; bp->name != NULL;
|
||||
bp++)
|
||||
(void) fprintf(el->el_outfile,
|
||||
"%s\n\t%s\n",
|
||||
bp->name, bp->description);
|
||||
return 0;
|
||||
return (0);
|
||||
default:
|
||||
(void) fprintf(el->el_errfile, "%s: Invalid switch `%c'.\n",
|
||||
(void) fprintf(el->el_errfile,
|
||||
"%s: Invalid switch `%c'.\n",
|
||||
argv[0], p[1]);
|
||||
}
|
||||
else
|
||||
@ -1283,22 +1306,20 @@ map_bind(el, argc, argv)
|
||||
|
||||
if (argv[argc] == NULL) {
|
||||
map_print_all_keys(el);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (key)
|
||||
in = argv[argc++];
|
||||
else
|
||||
if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
|
||||
(void) fprintf(el->el_errfile, "%s: Invalid \\ or ^ in instring.\n",
|
||||
else if ((in = parse__string(inbuf, argv[argc++])) == NULL) {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"%s: Invalid \\ or ^ in instring.\n",
|
||||
argv[0]);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (remove) {
|
||||
if (rem) {
|
||||
if (key) {
|
||||
(void) term_clear_arrow(el, in);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
if (in[1])
|
||||
(void) key_delete(el, in);
|
||||
@ -1306,21 +1327,19 @@ map_bind(el, argc, argv)
|
||||
(void) key_delete(el, in);
|
||||
else
|
||||
map[(unsigned char) *in] = ED_UNASSIGNED;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (argv[argc] == NULL) {
|
||||
if (key)
|
||||
term_print_arrow(el, in);
|
||||
else
|
||||
map_print_key(el, map, in);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
#ifdef notyet
|
||||
if (argv[argc + 1] != NULL) {
|
||||
bindkey_usage();
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1330,7 +1349,7 @@ map_bind(el, argc, argv)
|
||||
if ((out = parse__string(outbuf, argv[argc])) == NULL) {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"%s: Invalid \\ or ^ in outstring.\n", argv[0]);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
if (key)
|
||||
term_set_arrow(el, in, key_map_str(el, out), ntype);
|
||||
@ -1343,7 +1362,7 @@ map_bind(el, argc, argv)
|
||||
if ((cmd = parse_cmd(el, argv[argc])) == -1) {
|
||||
(void) fprintf(el->el_errfile,
|
||||
"%s: Invalid command `%s'.\n", argv[0], argv[argc]);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
if (key)
|
||||
term_set_arrow(el, in, key_map_str(el, out), ntype);
|
||||
@ -1351,8 +1370,7 @@ map_bind(el, argc, argv)
|
||||
if (in[1]) {
|
||||
key_add(el, in, key_map_cmd(el, cmd), ntype);
|
||||
map[(unsigned char) *in] = ED_SEQUENCE_LEAD_IN;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
key_clear(el, map, in);
|
||||
map[(unsigned char) *in] = cmd;
|
||||
}
|
||||
@ -1360,10 +1378,10 @@ map_bind(el, argc, argv)
|
||||
break;
|
||||
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype));
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -1371,20 +1389,21 @@ map_bind(el, argc, argv)
|
||||
* add a user defined function
|
||||
*/
|
||||
protected int
|
||||
map_addfunc(el, name, help, func)
|
||||
EditLine *el;
|
||||
const char *name;
|
||||
const char *help;
|
||||
el_func_t func;
|
||||
map_addfunc(EditLine *el, const char *name, const char *help, el_func_t func)
|
||||
{
|
||||
void *p;
|
||||
int nf = el->el_map.nfunc + 2;
|
||||
if (name == NULL || help == NULL || func == NULL)
|
||||
return -1;
|
||||
|
||||
el->el_map.func = (el_func_t *)
|
||||
el_reallocf(el->el_map.func, nf * sizeof(el_func_t));
|
||||
el->el_map.help = (el_bindings_t *)
|
||||
el_reallocf(el->el_map.help, nf * sizeof(el_bindings_t));
|
||||
if (name == NULL || help == NULL || func == NULL)
|
||||
return (-1);
|
||||
|
||||
if ((p = el_reallocf(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
|
||||
return (-1);
|
||||
el->el_map.func = (el_func_t *) p;
|
||||
if ((p = el_reallocf(el->el_map.help, nf * sizeof(el_bindings_t)))
|
||||
== NULL)
|
||||
return (-1);
|
||||
el->el_map.help = (el_bindings_t *) p;
|
||||
|
||||
nf = el->el_map.nfunc;
|
||||
el->el_map.func[nf] = func;
|
||||
@ -1395,5 +1414,5 @@ map_addfunc(el, name, help, func)
|
||||
el->el_map.help[++nf].name = NULL;
|
||||
el->el_map.nfunc++;
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)map.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: map.h,v 1.5 2000/09/04 22:06:31 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -53,9 +55,9 @@ typedef struct el_map_t {
|
||||
el_action_t *alt; /* The current alternate key map */
|
||||
el_action_t *key; /* The current normal key map */
|
||||
el_action_t *current; /* The keymap we are using */
|
||||
el_action_t *emacs; /* The default emacs key map */
|
||||
el_action_t *vic; /* The vi command mode key map */
|
||||
el_action_t *vii; /* The vi insert mode key map */
|
||||
const el_action_t *emacs; /* The default emacs key map */
|
||||
const el_action_t *vic; /* The vi command mode key map */
|
||||
const el_action_t *vii; /* The vi insert mode key map */
|
||||
int type; /* Emacs or vi */
|
||||
el_bindings_t *help; /* The help for the editor functions */
|
||||
el_func_t *func; /* List of available functions */
|
||||
@ -65,13 +67,13 @@ typedef struct el_map_t {
|
||||
#define MAP_EMACS 0
|
||||
#define MAP_VI 1
|
||||
|
||||
protected int map_bind __P((EditLine *, int, char **));
|
||||
protected int map_init __P((EditLine *));
|
||||
protected void map_end __P((EditLine *));
|
||||
protected void map_init_vi __P((EditLine *));
|
||||
protected void map_init_emacs __P((EditLine *));
|
||||
protected int map_set_editor __P((EditLine *, char *));
|
||||
protected int map_addfunc __P((EditLine *, const char *,
|
||||
const char *, el_func_t));
|
||||
protected int map_bind(EditLine *, int, char **);
|
||||
protected int map_init(EditLine *);
|
||||
protected void map_end(EditLine *);
|
||||
protected void map_init_vi(EditLine *);
|
||||
protected void map_init_emacs(EditLine *);
|
||||
protected int map_set_editor(EditLine *, char *);
|
||||
protected int map_get_editor(EditLine *, const char **);
|
||||
protected int map_addfunc(EditLine *, const char *, const char *, el_func_t);
|
||||
|
||||
#endif /* _h_el_map */
|
||||
|
@ -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: parse.c,v 1.13 2000/09/04 22:06:31 lukem Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* parse.c: parse an editline extended command
|
||||
@ -47,7 +51,7 @@ static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
|
||||
*
|
||||
* bind
|
||||
* echotc
|
||||
* settc
|
||||
* edit
|
||||
* gettc
|
||||
* history
|
||||
* settc
|
||||
@ -56,13 +60,15 @@ static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
|
||||
#include "sys.h"
|
||||
#include "el.h"
|
||||
#include "tokenizer.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
private struct {
|
||||
private const struct {
|
||||
char *name;
|
||||
int (*func) __P((EditLine *, int, char **));
|
||||
int (*func)(EditLine *, int, char **);
|
||||
} cmds[] = {
|
||||
{ "bind", map_bind },
|
||||
{ "echotc", term_echotc },
|
||||
{ "edit", el_editmode },
|
||||
{ "history", hist_list },
|
||||
{ "telltc", term_telltc },
|
||||
{ "settc", term_settc },
|
||||
@ -75,9 +81,7 @@ private struct {
|
||||
* Parse a line and dispatch it
|
||||
*/
|
||||
protected int
|
||||
parse_line(el, line)
|
||||
EditLine *el;
|
||||
const char *line;
|
||||
parse_line(EditLine *el, const char *line)
|
||||
{
|
||||
char **argv;
|
||||
int argc;
|
||||
@ -87,39 +91,48 @@ parse_line(el, line)
|
||||
tok_line(tok, line, &argc, &argv);
|
||||
argc = el_parse(el, argc, argv);
|
||||
tok_end(tok);
|
||||
return argc;
|
||||
return (argc);
|
||||
}
|
||||
|
||||
|
||||
/* el_parse():
|
||||
* Command dispatcher
|
||||
*/
|
||||
public int
|
||||
el_parse(el, argc, argv)
|
||||
EditLine *el;
|
||||
int argc;
|
||||
char *argv[];
|
||||
el_parse(EditLine *el, int argc, char *argv[])
|
||||
{
|
||||
char *ptr;
|
||||
int i;
|
||||
|
||||
if (argc < 1)
|
||||
return -1;
|
||||
return (-1);
|
||||
ptr = strchr(argv[0], ':');
|
||||
if (ptr != NULL) {
|
||||
*ptr++ = '\0';
|
||||
if (! el_match(el->el_prog, argv[0]))
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
char *tprog;
|
||||
size_t l;
|
||||
|
||||
if (ptr == argv[0])
|
||||
return (0);
|
||||
l = ptr - argv[0] - 1;
|
||||
tprog = (char *) el_malloc(l + 1);
|
||||
if (tprog == NULL)
|
||||
return (0);
|
||||
(void) strncpy(tprog, argv[0], l);
|
||||
tprog[l] = '\0';
|
||||
ptr++;
|
||||
l = el_match(el->el_prog, tprog);
|
||||
el_free(tprog);
|
||||
if (!l)
|
||||
return (0);
|
||||
} else
|
||||
ptr = argv[0];
|
||||
|
||||
for (i = 0; cmds[i].name != NULL; i++)
|
||||
if (strcmp(cmds[i].name, ptr) == 0) {
|
||||
i = (*cmds[i].func) (el, argc, argv);
|
||||
return -i;
|
||||
return (-i);
|
||||
}
|
||||
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
@ -128,8 +141,7 @@ el_parse(el, argc, argv)
|
||||
* the appropriate character or -1 if the escape is not valid
|
||||
*/
|
||||
protected int
|
||||
parse__escape(ptr)
|
||||
const char ** const ptr;
|
||||
parse__escape(const char **const ptr)
|
||||
{
|
||||
const char *p;
|
||||
int c;
|
||||
@ -137,7 +149,7 @@ parse__escape(ptr)
|
||||
p = *ptr;
|
||||
|
||||
if (p[1] == 0)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (*p == '\\') {
|
||||
p++;
|
||||
@ -186,45 +198,41 @@ parse__escape(ptr)
|
||||
c = (c << 3) | (ch - '0');
|
||||
}
|
||||
if ((c & 0xffffff00) != 0)
|
||||
return -1;
|
||||
return (-1);
|
||||
--p;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
c = *p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (*p == '^' && isascii(p[1]) && (p[1] == '?' || isalpha(p[1]))) {
|
||||
} else if (*p == '^' && isascii(p[1]) && (p[1] == '?' || isalpha(p[1]))) {
|
||||
p++;
|
||||
c = (*p == '?') ? '\177' : (*p & 0237);
|
||||
}
|
||||
else
|
||||
} else
|
||||
c = *p;
|
||||
*ptr = ++p;
|
||||
return (unsigned char)c;
|
||||
return ((unsigned char)c);
|
||||
}
|
||||
|
||||
/* parse__string():
|
||||
* Parse the escapes from in and put the raw string out
|
||||
*/
|
||||
protected char *
|
||||
parse__string(out, in)
|
||||
char *out;
|
||||
const char *in;
|
||||
parse__string(char *out, const char *in)
|
||||
{
|
||||
char *rv = out;
|
||||
int n;
|
||||
|
||||
for (;;)
|
||||
switch (*in) {
|
||||
case '\0':
|
||||
*out = '\0';
|
||||
return rv;
|
||||
return (rv);
|
||||
|
||||
case '\\':
|
||||
case '^':
|
||||
if ((n = parse__escape(&in)) == -1)
|
||||
return NULL;
|
||||
return (NULL);
|
||||
*out++ = n;
|
||||
break;
|
||||
|
||||
@ -234,19 +242,18 @@ parse__string(out, in)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* parse_cmd():
|
||||
* Return the command number for the command string given
|
||||
* or -1 if one is not found
|
||||
*/
|
||||
protected int
|
||||
parse_cmd(el, cmd)
|
||||
EditLine *el;
|
||||
const char *cmd;
|
||||
parse_cmd(EditLine *el, const char *cmd)
|
||||
{
|
||||
el_bindings_t *b;
|
||||
|
||||
for (b = el->el_map.help; b->name != NULL; b++)
|
||||
if (strcmp(b->name, cmd) == 0)
|
||||
return b->func;
|
||||
return -1;
|
||||
return (b->func);
|
||||
return (-1);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)parse.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: parse.h,v 1.3 1999/07/02 15:21:26 simonb Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -42,9 +44,9 @@
|
||||
#ifndef _h_el_parse
|
||||
#define _h_el_parse
|
||||
|
||||
protected int parse_line __P((EditLine *, const char *));
|
||||
protected int parse__escape __P((const char ** const));
|
||||
protected char * parse__string __P((char *, const char *));
|
||||
protected int parse_cmd __P((EditLine *, const char *));
|
||||
protected int parse_line(EditLine *, const char *);
|
||||
protected int parse__escape(const char ** const);
|
||||
protected char *parse__string(char *, const char *);
|
||||
protected int parse_cmd(EditLine *, const char *);
|
||||
|
||||
#endif /* _h_el_parse */
|
||||
|
@ -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: prompt.c,v 1.7 2000/09/04 22:06:31 lukem Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* prompt.c: Prompt printing functions
|
||||
@ -47,18 +51,32 @@ static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <stdio.h>
|
||||
#include "el.h"
|
||||
|
||||
private char *prompt_default __P((EditLine *));
|
||||
private char *prompt_default(EditLine *);
|
||||
private char *prompt_default_r(EditLine *);
|
||||
|
||||
/* prompt_default():
|
||||
* Just a default prompt, in case the user did not provide one
|
||||
*/
|
||||
private char *
|
||||
/*ARGSUSED*/
|
||||
prompt_default(el)
|
||||
EditLine *el;
|
||||
prompt_default(EditLine *el)
|
||||
{
|
||||
static char a[3] = {'?', ' ', '\0'};
|
||||
return a;
|
||||
|
||||
return (a);
|
||||
}
|
||||
|
||||
|
||||
/* prompt_default_r():
|
||||
* Just a default rprompt, in case the user did not provide one
|
||||
*/
|
||||
private char *
|
||||
/*ARGSUSED*/
|
||||
prompt_default_r(EditLine *el)
|
||||
{
|
||||
static char a[1] = {'\0'};
|
||||
|
||||
return (a);
|
||||
}
|
||||
|
||||
|
||||
@ -69,31 +87,39 @@ prompt_default(el)
|
||||
* bit to flag them
|
||||
*/
|
||||
protected void
|
||||
prompt_print(el)
|
||||
EditLine *el;
|
||||
prompt_print(EditLine *el, int op)
|
||||
{
|
||||
char *p = (*el->el_prompt.p_func)(el);
|
||||
el_prompt_t *elp;
|
||||
char *p;
|
||||
|
||||
if (op == EL_PROMPT)
|
||||
elp = &el->el_prompt;
|
||||
else
|
||||
elp = &el->el_rprompt;
|
||||
p = (elp->p_func) (el);
|
||||
while (*p)
|
||||
re_putc(el, *p++);
|
||||
re_putc(el, *p++, 1);
|
||||
|
||||
el->el_prompt.p_pos.v = el->el_refresh.r_cursor.v;
|
||||
el->el_prompt.p_pos.h = el->el_refresh.r_cursor.h;
|
||||
|
||||
} /* end prompt_print */
|
||||
elp->p_pos.v = el->el_refresh.r_cursor.v;
|
||||
elp->p_pos.h = el->el_refresh.r_cursor.h;
|
||||
}
|
||||
|
||||
|
||||
/* prompt_init():
|
||||
* Initialize the prompt stuff
|
||||
*/
|
||||
protected int
|
||||
prompt_init(el)
|
||||
EditLine *el;
|
||||
prompt_init(EditLine *el)
|
||||
{
|
||||
|
||||
el->el_prompt.p_func = prompt_default;
|
||||
el->el_prompt.p_pos.v = 0;
|
||||
el->el_prompt.p_pos.h = 0;
|
||||
return 0;
|
||||
} /* end prompt_init */
|
||||
el->el_rprompt.p_func = prompt_default_r;
|
||||
el->el_rprompt.p_pos.v = 0;
|
||||
el->el_rprompt.p_pos.h = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* prompt_end():
|
||||
@ -101,25 +127,48 @@ prompt_init(el)
|
||||
*/
|
||||
protected void
|
||||
/*ARGSUSED*/
|
||||
prompt_end(el)
|
||||
EditLine *el;
|
||||
prompt_end(EditLine *el)
|
||||
{
|
||||
} /* end prompt_end */
|
||||
}
|
||||
|
||||
|
||||
/* prompt_set():
|
||||
* Install a prompt printing function
|
||||
*/
|
||||
protected int
|
||||
prompt_set(el, prf)
|
||||
EditLine *el;
|
||||
el_pfunc_t prf;
|
||||
prompt_set(EditLine *el, el_pfunc_t prf, int op)
|
||||
{
|
||||
if (prf == NULL)
|
||||
el->el_prompt.p_func = prompt_default;
|
||||
el_prompt_t *p;
|
||||
|
||||
if (op == EL_PROMPT)
|
||||
p = &el->el_prompt;
|
||||
else
|
||||
el->el_prompt.p_func = prf;
|
||||
el->el_prompt.p_pos.v = 0;
|
||||
el->el_prompt.p_pos.h = 0;
|
||||
return 0;
|
||||
} /* end prompt_set */
|
||||
p = &el->el_rprompt;
|
||||
if (prf == NULL) {
|
||||
if (op == EL_PROMPT)
|
||||
p->p_func = prompt_default;
|
||||
else
|
||||
p->p_func = prompt_default_r;
|
||||
} else
|
||||
p->p_func = prf;
|
||||
p->p_pos.v = 0;
|
||||
p->p_pos.h = 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* prompt_get():
|
||||
* Retrieve the prompt printing function
|
||||
*/
|
||||
protected int
|
||||
prompt_get(EditLine *el, el_pfunc_t *prf, int op)
|
||||
{
|
||||
|
||||
if (prf == NULL)
|
||||
return (-1);
|
||||
if (op == EL_PROMPT)
|
||||
*prf = el->el_prompt.p_func;
|
||||
else
|
||||
*prf = el->el_rprompt.p_func;
|
||||
return (0);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)prompt.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: prompt.h,v 1.4 1999/11/12 01:05:07 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -44,16 +46,17 @@
|
||||
|
||||
#include "histedit.h"
|
||||
|
||||
typedef char * (*el_pfunc_t) __P((EditLine*));
|
||||
typedef char * (*el_pfunc_t)(EditLine*);
|
||||
|
||||
typedef struct el_prompt_t {
|
||||
el_pfunc_t p_func; /* Function to return the prompt */
|
||||
coord_t p_pos; /* position in the line after prompt */
|
||||
} el_prompt_t;
|
||||
|
||||
protected void prompt_print __P((EditLine *));
|
||||
protected int prompt_set __P((EditLine *, el_pfunc_t));
|
||||
protected int prompt_init __P((EditLine *));
|
||||
protected void prompt_end __P((EditLine *));
|
||||
protected void prompt_print(EditLine *, int);
|
||||
protected int prompt_set(EditLine *, el_pfunc_t, int);
|
||||
protected int prompt_get(EditLine *, el_pfunc_t *, int);
|
||||
protected int prompt_init(EditLine *);
|
||||
protected void prompt_end(EditLine *);
|
||||
|
||||
#endif /* _h_el_prompt */
|
||||
|
@ -32,16 +32,16 @@
|
||||
* 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: read.c,v 1.18 2000/11/11 22:18:58 christos Exp $
|
||||
*/
|
||||
|
||||
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
/*
|
||||
* read.c: Clean this junk up! This is horrible code.
|
||||
* Terminal read functions
|
||||
@ -55,14 +55,14 @@ static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
#define OKCMD -1
|
||||
|
||||
private int read__fixio __P((int, int));
|
||||
private int read_preread __P((EditLine *));
|
||||
private int read_getcmd __P((EditLine *, el_action_t *, char *));
|
||||
private int read__fixio(int, int);
|
||||
private int read_preread(EditLine *);
|
||||
private int read_getcmd(EditLine *, el_action_t *, char *);
|
||||
private int read_char(EditLine *, char *);
|
||||
|
||||
#ifdef DEBUG_EDIT
|
||||
private void
|
||||
read_debug(el)
|
||||
EditLine *el;
|
||||
read_debug(EditLine *el)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
@ -78,13 +78,15 @@ read_debug(el)
|
||||
}
|
||||
#endif /* DEBUG_EDIT */
|
||||
|
||||
|
||||
/* read__fixio():
|
||||
* Try to recover from a read error
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
private int
|
||||
read__fixio(fd, e)
|
||||
int fd, e;
|
||||
read__fixio(int fd, int e)
|
||||
{
|
||||
|
||||
switch (e) {
|
||||
case -1: /* Make sure that the code is reachable */
|
||||
|
||||
@ -108,29 +110,33 @@ read__fixio(fd, e)
|
||||
#ifdef TRY_AGAIN
|
||||
#if defined(F_SETFL) && defined(O_NDELAY)
|
||||
if ((e = fcntl(fd, F_GETFL, 0)) == -1)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
|
||||
return -1;
|
||||
return (-1);
|
||||
else
|
||||
e = 1;
|
||||
#endif /* F_SETFL && O_NDELAY */
|
||||
|
||||
#ifdef FIONBIO
|
||||
if (ioctl(fd, FIONBIO, (ioctl_t) &e) == -1)
|
||||
return -1;
|
||||
{
|
||||
int zero = 0;
|
||||
|
||||
if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
|
||||
return (-1);
|
||||
else
|
||||
e = 1;
|
||||
}
|
||||
#endif /* FIONBIO */
|
||||
|
||||
#endif /* TRY_AGAIN */
|
||||
return e ? 0 : -1;
|
||||
return (e ? 0 : -1);
|
||||
|
||||
case EINTR:
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
default:
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,8 +145,7 @@ read__fixio(fd, e)
|
||||
* Try to read the stuff in the input queue;
|
||||
*/
|
||||
private int
|
||||
read_preread(el)
|
||||
EditLine *el;
|
||||
read_preread(EditLine *el)
|
||||
{
|
||||
int chrs = 0;
|
||||
|
||||
@ -148,25 +153,25 @@ read_preread(el)
|
||||
el_free((ptr_t) el->el_chared.c_macro.nline);
|
||||
el->el_chared.c_macro.nline = NULL;
|
||||
}
|
||||
|
||||
if (el->el_tty.t_mode == ED_IO)
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
#ifdef FIONREAD
|
||||
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
|
||||
if (chrs > 0) {
|
||||
char buf[EL_BUFSIZ];
|
||||
|
||||
chrs = read(el->el_infd, buf, (size_t) MIN(chrs, EL_BUFSIZ - 1));
|
||||
chrs = read(el->el_infd, buf,
|
||||
(size_t) MIN(chrs, EL_BUFSIZ - 1));
|
||||
if (chrs > 0) {
|
||||
buf[chrs] = '\0';
|
||||
el->el_chared.c_macro.nline = strdup(buf);
|
||||
el_push(el->el_chared.c_macro.nline);
|
||||
el_push(el, el->el_chared.c_macro.nline);
|
||||
}
|
||||
}
|
||||
#endif /* FIONREAD */
|
||||
|
||||
return chrs > 0;
|
||||
return (chrs > 0);
|
||||
}
|
||||
|
||||
|
||||
@ -174,17 +179,15 @@ read_preread(el)
|
||||
* Push a macro
|
||||
*/
|
||||
public void
|
||||
el_push(el, str)
|
||||
EditLine *el;
|
||||
const char *str;
|
||||
el_push(EditLine *el, const char *str)
|
||||
{
|
||||
c_macro_t *ma = &el->el_chared.c_macro;
|
||||
|
||||
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
|
||||
ma->level++;
|
||||
/* LINTED const cast */
|
||||
ma->macro[ma->level] = (char *) str;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
term_beep(el);
|
||||
term__flush();
|
||||
}
|
||||
@ -195,25 +198,21 @@ el_push(el, str)
|
||||
* Return next command from the input stream.
|
||||
*/
|
||||
private int
|
||||
read_getcmd(el, cmdnum, ch)
|
||||
EditLine *el;
|
||||
el_action_t *cmdnum;
|
||||
char *ch;
|
||||
read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
|
||||
{
|
||||
el_action_t cmd = ED_UNASSIGNED;
|
||||
int num;
|
||||
|
||||
while (cmd == ED_UNASSIGNED || cmd == ED_SEQUENCE_LEAD_IN) {
|
||||
if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
|
||||
return num;
|
||||
return (num);
|
||||
|
||||
#ifdef KANJI
|
||||
if ((*ch & 0200)) {
|
||||
el->el_state.metanext = 0;
|
||||
cmd = CcViMap[' '];
|
||||
break;
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif /* KANJI */
|
||||
|
||||
if (el->el_state.metanext) {
|
||||
@ -237,7 +236,7 @@ read_getcmd(el, cmdnum, ch)
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -245,7 +244,28 @@ read_getcmd(el, cmdnum, ch)
|
||||
el->el_map.current = el->el_map.key;
|
||||
}
|
||||
*cmdnum = cmd;
|
||||
return OKCMD;
|
||||
return (OKCMD);
|
||||
}
|
||||
|
||||
|
||||
/* read_char():
|
||||
* Read a character from the tty.
|
||||
*/
|
||||
private int
|
||||
read_char(EditLine *el, char *cp)
|
||||
{
|
||||
int num_read;
|
||||
int tried = 0;
|
||||
|
||||
while ((num_read = read(el->el_infd, cp, 1)) == -1)
|
||||
if (!tried && read__fixio(el->el_infd, errno) == 0)
|
||||
tried = 1;
|
||||
else {
|
||||
*cp = '\0';
|
||||
return (-1);
|
||||
}
|
||||
|
||||
return (num_read);
|
||||
}
|
||||
|
||||
|
||||
@ -253,14 +273,9 @@ read_getcmd(el, cmdnum, ch)
|
||||
* Read a character
|
||||
*/
|
||||
public int
|
||||
el_getc(el, cp)
|
||||
EditLine *el;
|
||||
char *cp;
|
||||
el_getc(EditLine *el, char *cp)
|
||||
{
|
||||
int num_read;
|
||||
unsigned char tcp;
|
||||
int tried = 0;
|
||||
|
||||
c_macro_t *ma = &el->el_chared.c_macro;
|
||||
|
||||
term__flush();
|
||||
@ -277,50 +292,67 @@ el_getc(el, cp)
|
||||
continue;
|
||||
}
|
||||
*cp = *ma->macro[ma->level]++ & 0377;
|
||||
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode On */
|
||||
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode
|
||||
* On */
|
||||
ma->level--;
|
||||
}
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_READ
|
||||
(void) fprintf(el->el_errfile, "Turning raw mode on\n");
|
||||
#endif /* DEBUG_READ */
|
||||
if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
#ifdef DEBUG_READ
|
||||
(void) fprintf(el->el_errfile, "Reading a character\n");
|
||||
#endif /* DEBUG_READ */
|
||||
while ((num_read = read(el->el_infd, (char *) &tcp, 1)) == -1)
|
||||
if (!tried && read__fixio(el->el_infd, errno) == 0)
|
||||
tried = 1;
|
||||
else {
|
||||
*cp = '\0';
|
||||
return -1;
|
||||
}
|
||||
num_read = read_char(el, cp);
|
||||
#ifdef DEBUG_READ
|
||||
(void) fprintf(el->el_errfile, "Got it %c\n", tcp);
|
||||
(void) fprintf(el->el_errfile, "Got it %c\n", *cp);
|
||||
#endif /* DEBUG_READ */
|
||||
*cp = tcp;
|
||||
return num_read;
|
||||
return (num_read);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public const char *
|
||||
el_gets(el, nread)
|
||||
EditLine *el;
|
||||
int *nread;
|
||||
el_gets(EditLine *el, int *nread)
|
||||
{
|
||||
int retval;
|
||||
el_action_t cmdnum = 0;
|
||||
int num; /* how many chars we have read at NL */
|
||||
char ch;
|
||||
#ifdef FIONREAD
|
||||
c_macro_t *ma = &el->el_chared.c_macro;
|
||||
#endif /* FIONREAD */
|
||||
|
||||
if (el->el_flags & HANDLE_SIGNALS)
|
||||
sig_set(el);
|
||||
|
||||
if (el->el_flags & NO_TTY) {
|
||||
char *cp = el->el_line.buffer;
|
||||
size_t idx;
|
||||
|
||||
while (read_char(el, cp) == 1) {
|
||||
/* make sure there is space for next character */
|
||||
if (cp + 1 >= el->el_line.limit) {
|
||||
idx = (cp - el->el_line.buffer);
|
||||
if (!ch_enlargebufs(el, 2))
|
||||
break;
|
||||
cp = &el->el_line.buffer[idx];
|
||||
}
|
||||
cp++;
|
||||
if (cp[-1] == '\r' || cp[-1] == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
el->el_line.cursor = el->el_line.lastchar = cp;
|
||||
*cp = '\0';
|
||||
if (nread)
|
||||
*nread = el->el_line.cursor - el->el_line.buffer;
|
||||
return (el->el_line.buffer);
|
||||
}
|
||||
re_clear_display(el); /* reset the display stuff */
|
||||
ch_reset(el);
|
||||
|
||||
@ -333,7 +365,7 @@ el_gets(el, nread)
|
||||
if (tty_rawmode(el) < 0) {
|
||||
if (nread)
|
||||
*nread = 0;
|
||||
return NULL;
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -341,26 +373,51 @@ el_gets(el, nread)
|
||||
|
||||
re_refresh(el); /* print the prompt */
|
||||
|
||||
for (num = OKCMD; num == OKCMD;) { /* while still editing this line */
|
||||
if (el->el_flags & EDIT_DISABLED) {
|
||||
char *cp = el->el_line.buffer;
|
||||
size_t idx;
|
||||
|
||||
term__flush();
|
||||
|
||||
while (read_char(el, cp) == 1) {
|
||||
/* make sure there is space next character */
|
||||
if (cp + 1 >= el->el_line.limit) {
|
||||
idx = (cp - el->el_line.buffer);
|
||||
if (!ch_enlargebufs(el, 2))
|
||||
break;
|
||||
cp = &el->el_line.buffer[idx];
|
||||
}
|
||||
cp++;
|
||||
if (cp[-1] == '\r' || cp[-1] == '\n')
|
||||
break;
|
||||
}
|
||||
|
||||
el->el_line.cursor = el->el_line.lastchar = cp;
|
||||
*cp = '\0';
|
||||
if (nread)
|
||||
*nread = el->el_line.cursor - el->el_line.buffer;
|
||||
return (el->el_line.buffer);
|
||||
}
|
||||
for (num = OKCMD; num == OKCMD;) { /* while still editing this
|
||||
* line */
|
||||
#ifdef DEBUG_EDIT
|
||||
read_debug(el);
|
||||
#endif /* DEBUG_EDIT */
|
||||
/* if EOF or error */
|
||||
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
|
||||
#ifdef DEBUG_READ
|
||||
(void) fprintf(el->el_errfile, "Returning from el_gets %d\n", num);
|
||||
(void) fprintf(el->el_errfile,
|
||||
"Returning from el_gets %d\n", num);
|
||||
#endif /* DEBUG_READ */
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
|
||||
if ((int) cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
|
||||
#ifdef DEBUG_EDIT
|
||||
(void) fprintf(el->el_errfile,
|
||||
"ERROR: illegal command from key 0%o\r\n", ch);
|
||||
#endif /* DEBUG_EDIT */
|
||||
continue; /* try again */
|
||||
}
|
||||
|
||||
/* now do the real command */
|
||||
#ifdef DEBUG_READ
|
||||
{
|
||||
@ -369,9 +426,11 @@ el_gets(el, nread)
|
||||
if (b->func == cmdnum)
|
||||
break;
|
||||
if (b->name)
|
||||
(void) fprintf(el->el_errfile, "Executing %s\n", b->name);
|
||||
(void) fprintf(el->el_errfile,
|
||||
"Executing %s\n", b->name);
|
||||
else
|
||||
(void) fprintf(el->el_errfile, "Error command = %d\n", cmdnum);
|
||||
(void) fprintf(el->el_errfile,
|
||||
"Error command = %d\n", cmdnum);
|
||||
}
|
||||
#endif /* DEBUG_READ */
|
||||
retval = (*el->el_map.func[cmdnum]) (el, ch);
|
||||
@ -398,6 +457,13 @@ el_gets(el, nread)
|
||||
re_refresh(el);
|
||||
break;
|
||||
|
||||
case CC_REFRESH_BEEP:
|
||||
el->el_state.argument = 1;
|
||||
el->el_state.doingarg = 0;
|
||||
re_refresh(el);
|
||||
term_beep(el);
|
||||
break;
|
||||
|
||||
case CC_NORM: /* normal char */
|
||||
el->el_state.argument = 1;
|
||||
el->el_state.doingarg = 0;
|
||||
@ -417,7 +483,8 @@ el_gets(el, nread)
|
||||
|
||||
case CC_FATAL: /* fatal error, reset to known state */
|
||||
#ifdef DEBUG_READ
|
||||
(void) fprintf(el->el_errfile, "*** editor fatal ERROR ***\r\n\n");
|
||||
(void) fprintf(el->el_errfile,
|
||||
"*** editor fatal ERROR ***\r\n\n");
|
||||
#endif /* DEBUG_READ */
|
||||
/* put (real) cursor in a known place */
|
||||
re_clear_display(el); /* reset the display stuff */
|
||||
@ -430,7 +497,8 @@ el_gets(el, nread)
|
||||
case CC_ERROR:
|
||||
default: /* functions we don't know about */
|
||||
#ifdef DEBUG_READ
|
||||
(void) fprintf(el->el_errfile, "*** editor ERROR ***\r\n\n");
|
||||
(void) fprintf(el->el_errfile,
|
||||
"*** editor ERROR ***\r\n\n");
|
||||
#endif /* DEBUG_READ */
|
||||
el->el_state.argument = 1;
|
||||
el->el_state.doingarg = 0;
|
||||
@ -441,10 +509,11 @@ el_gets(el, nread)
|
||||
}
|
||||
|
||||
term__flush(); /* flush any buffered output */
|
||||
(void) tty_cookedmode(el); /* make sure the tty is set up correctly */
|
||||
/* make sure the tty is set up correctly */
|
||||
(void) tty_cookedmode(el);
|
||||
if (el->el_flags & HANDLE_SIGNALS)
|
||||
sig_clr(el);
|
||||
if (nread)
|
||||
*nread = num;
|
||||
return num ? el->el_line.buffer : NULL;
|
||||
return (num ? el->el_line.buffer : NULL);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)refresh.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: refresh.h,v 1.3 2000/09/04 22:06:32 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -46,15 +48,16 @@
|
||||
|
||||
typedef struct {
|
||||
coord_t r_cursor; /* Refresh cursor position */
|
||||
int r_oldcv, r_newcv; /* Vertical locations */
|
||||
int r_oldcv; /* Vertical locations */
|
||||
int r_newcv;
|
||||
} el_refresh_t;
|
||||
|
||||
protected void re_putc __P((EditLine *, int));
|
||||
protected void re_clear_lines __P((EditLine *));
|
||||
protected void re_clear_display __P((EditLine *));
|
||||
protected void re_refresh __P((EditLine *));
|
||||
protected void re_refresh_cursor __P((EditLine *));
|
||||
protected void re_fastaddc __P((EditLine *));
|
||||
protected void re_goto_bottom __P((EditLine *));
|
||||
protected void re_putc(EditLine *, int, int);
|
||||
protected void re_clear_lines(EditLine *);
|
||||
protected void re_clear_display(EditLine *);
|
||||
protected void re_refresh(EditLine *);
|
||||
protected void re_refresh_cursor(EditLine *);
|
||||
protected void re_fastaddc(EditLine *);
|
||||
protected void re_goto_bottom(EditLine *);
|
||||
|
||||
#endif /* _h_el_refresh */
|
||||
|
@ -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: search.c,v 1.10 2001/01/04 15:56:32 christos Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* search.c: History and character search functions
|
||||
@ -63,15 +67,17 @@ static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
|
||||
* Initialize the search stuff
|
||||
*/
|
||||
protected int
|
||||
search_init(el)
|
||||
EditLine *el;
|
||||
search_init(EditLine *el)
|
||||
{
|
||||
|
||||
el->el_search.patbuf = (char *) el_malloc(EL_BUFSIZ);
|
||||
if (el->el_search.patbuf == NULL)
|
||||
return (-1);
|
||||
el->el_search.patlen = 0;
|
||||
el->el_search.patdir = -1;
|
||||
el->el_search.chacha = '\0';
|
||||
el->el_search.chadir = -1;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -79,32 +85,31 @@ search_init(el)
|
||||
* Initialize the search stuff
|
||||
*/
|
||||
protected void
|
||||
search_end(el)
|
||||
EditLine *el;
|
||||
search_end(EditLine *el)
|
||||
{
|
||||
|
||||
el_free((ptr_t) el->el_search.patbuf);
|
||||
el->el_search.patbuf = NULL;
|
||||
}
|
||||
|
||||
|
||||
#ifdef REGEXP
|
||||
/* regerror():
|
||||
* Handle regular expression errors
|
||||
*/
|
||||
public void
|
||||
/*ARGSUSED*/
|
||||
regerror(msg)
|
||||
const char *msg;
|
||||
regerror(const char *msg)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* el_match():
|
||||
* Return if string matches pattern
|
||||
*/
|
||||
protected int
|
||||
el_match(str, pat)
|
||||
const char *str;
|
||||
const char *pat;
|
||||
el_match(const char *str, const char *pat)
|
||||
{
|
||||
#if defined (REGEX)
|
||||
regex_t re;
|
||||
@ -113,12 +118,12 @@ el_match(str, pat)
|
||||
regexp *rp;
|
||||
int rv;
|
||||
#else
|
||||
extern char *re_comp __P((const char *));
|
||||
extern int re_exec __P((const char *));
|
||||
extern char *re_comp(const char *);
|
||||
extern int re_exec(const char *);
|
||||
#endif
|
||||
|
||||
if (strstr(str, pat) != NULL)
|
||||
return 1;
|
||||
return (1);
|
||||
|
||||
#if defined(REGEX)
|
||||
if (regcomp(&re, pat, 0) == 0) {
|
||||
@ -127,7 +132,7 @@ el_match(str, pat)
|
||||
} else {
|
||||
rv = 0;
|
||||
}
|
||||
return rv;
|
||||
return (rv);
|
||||
#elif defined(REGEXP)
|
||||
if ((re = regcomp(pat)) != NULL) {
|
||||
rv = regexec(re, str);
|
||||
@ -135,12 +140,12 @@ el_match(str, pat)
|
||||
} else {
|
||||
rv = 0;
|
||||
}
|
||||
return rv;
|
||||
return (rv);
|
||||
#else
|
||||
if (re_comp(pat) != NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
else
|
||||
return re_exec(str) == 1;
|
||||
return (re_exec(str) == 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -149,16 +154,14 @@ el_match(str, pat)
|
||||
* return True if the pattern matches the prefix
|
||||
*/
|
||||
protected int
|
||||
c_hmatch(el, str)
|
||||
EditLine *el;
|
||||
const char *str;
|
||||
c_hmatch(EditLine *el, const char *str)
|
||||
{
|
||||
#ifdef SDEBUG
|
||||
(void) fprintf(el->el_errfile, "match `%s' with `%s'\n",
|
||||
el->el_search.patbuf, str);
|
||||
#endif /* SDEBUG */
|
||||
|
||||
return el_match(str, el->el_search.patbuf);
|
||||
return (el_match(str, el->el_search.patbuf));
|
||||
}
|
||||
|
||||
|
||||
@ -166,26 +169,26 @@ c_hmatch(el, str)
|
||||
* Set the history seatch pattern
|
||||
*/
|
||||
protected void
|
||||
c_setpat(el)
|
||||
EditLine *el;
|
||||
c_setpat(EditLine *el)
|
||||
{
|
||||
if (el->el_state.lastcmd != ED_SEARCH_PREV_HISTORY &&
|
||||
el->el_state.lastcmd != ED_SEARCH_NEXT_HISTORY) {
|
||||
el->el_search.patlen = EL_CURSOR(el) - el->el_line.buffer;
|
||||
if (el->el_search.patlen >= EL_BUFSIZ)
|
||||
el->el_search.patlen = EL_BUFSIZ - 1;
|
||||
if (el->el_search.patlen >= 0) {
|
||||
if (el->el_search.patlen != 0) {
|
||||
(void) strncpy(el->el_search.patbuf, el->el_line.buffer,
|
||||
el->el_search.patlen);
|
||||
el->el_search.patbuf[el->el_search.patlen] = '\0';
|
||||
}
|
||||
else
|
||||
} else
|
||||
el->el_search.patlen = strlen(el->el_search.patbuf);
|
||||
}
|
||||
#ifdef SDEBUG
|
||||
(void) fprintf(el->el_errfile, "\neventno = %d\n", el->el_history.eventno);
|
||||
(void) fprintf(el->el_errfile, "\neventno = %d\n",
|
||||
el->el_history.eventno);
|
||||
(void) fprintf(el->el_errfile, "patlen = %d\n", el->el_search.patlen);
|
||||
(void) fprintf(el->el_errfile, "patbuf = \"%s\"\n", el->el_search.patbuf);
|
||||
(void) fprintf(el->el_errfile, "patbuf = \"%s\"\n",
|
||||
el->el_search.patbuf);
|
||||
(void) fprintf(el->el_errfile, "cursor %d lastchar %d\n",
|
||||
EL_CURSOR(el) - el->el_line.buffer,
|
||||
el->el_line.lastchar - el->el_line.buffer);
|
||||
@ -197,26 +200,25 @@ c_setpat(el)
|
||||
* Emacs incremental search
|
||||
*/
|
||||
protected el_action_t
|
||||
ce_inc_search(el, dir)
|
||||
EditLine *el;
|
||||
int dir;
|
||||
ce_inc_search(EditLine *el, int dir)
|
||||
{
|
||||
static char STRfwd[] = { 'f', 'w', 'd', '\0' },
|
||||
static const char STRfwd[] = {'f', 'w', 'd', '\0'},
|
||||
STRbck[] = {'b', 'c', 'k', '\0'};
|
||||
static char pchar = ':';/* ':' = normal, '?' = failed */
|
||||
static char endcmd[2] = {'\0', '\0'};
|
||||
char ch, *cp, *ocursor = el->el_line.cursor, oldpchar = pchar;
|
||||
char ch, *ocursor = el->el_line.cursor, oldpchar = pchar;
|
||||
const char *cp;
|
||||
|
||||
el_action_t ret = CC_NORM;
|
||||
|
||||
int ohisteventno = el->el_history.eventno,
|
||||
oldpatlen = el->el_search.patlen,
|
||||
newdir = dir,
|
||||
done, redo;
|
||||
int ohisteventno = el->el_history.eventno;
|
||||
int oldpatlen = el->el_search.patlen;
|
||||
int newdir = dir;
|
||||
int done, redo;
|
||||
|
||||
if (el->el_line.lastchar + sizeof(STRfwd) / sizeof(char) + 2 +
|
||||
el->el_search.patlen >= el->el_line.limit)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
for (;;) {
|
||||
|
||||
@ -229,7 +231,7 @@ ce_inc_search(el, dir)
|
||||
}
|
||||
done = redo = 0;
|
||||
*el->el_line.lastchar++ = '\n';
|
||||
for (cp = newdir == ED_SEARCH_PREV_HISTORY ? STRbck : STRfwd;
|
||||
for (cp = (newdir == ED_SEARCH_PREV_HISTORY) ? STRbck : STRfwd;
|
||||
*cp; *el->el_line.lastchar++ = *cp++)
|
||||
continue;
|
||||
*el->el_line.lastchar++ = pchar;
|
||||
@ -241,7 +243,7 @@ ce_inc_search(el, dir)
|
||||
re_refresh(el);
|
||||
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return ed_end_of_file(el, 0);
|
||||
return (ed_end_of_file(el, 0));
|
||||
|
||||
switch (el->el_map.current[(unsigned char) ch]) {
|
||||
case ED_INSERT:
|
||||
@ -249,7 +251,8 @@ ce_inc_search(el, dir)
|
||||
if (el->el_search.patlen > EL_BUFSIZ - 3)
|
||||
term_beep(el);
|
||||
else {
|
||||
el->el_search.patbuf[el->el_search.patlen++] = ch;
|
||||
el->el_search.patbuf[el->el_search.patlen++] =
|
||||
ch;
|
||||
*el->el_line.lastchar++ = ch;
|
||||
*el->el_line.lastchar = '\0';
|
||||
re_refresh(el);
|
||||
@ -284,18 +287,22 @@ ce_inc_search(el, dir)
|
||||
/* No can do if globbing characters in pattern */
|
||||
for (cp = &el->el_search.patbuf[1];; cp++)
|
||||
if (cp >= &el->el_search.patbuf[el->el_search.patlen]) {
|
||||
el->el_line.cursor += el->el_search.patlen - 1;
|
||||
el->el_line.cursor +=
|
||||
el->el_search.patlen - 1;
|
||||
cp = c__next_word(el->el_line.cursor,
|
||||
el->el_line.lastchar, 1, ce__isword);
|
||||
el->el_line.lastchar, 1,
|
||||
ce__isword);
|
||||
while (el->el_line.cursor < cp &&
|
||||
*el->el_line.cursor != '\n') {
|
||||
if (el->el_search.patlen > EL_BUFSIZ - 3) {
|
||||
if (el->el_search.patlen >
|
||||
EL_BUFSIZ - 3) {
|
||||
term_beep(el);
|
||||
break;
|
||||
}
|
||||
el->el_search.patbuf[el->el_search.patlen++] =
|
||||
*el->el_line.cursor;
|
||||
*el->el_line.lastchar++ = *el->el_line.cursor++;
|
||||
*el->el_line.lastchar++ =
|
||||
*el->el_line.cursor++;
|
||||
}
|
||||
el->el_line.cursor = ocursor;
|
||||
*el->el_line.lastchar = '\0';
|
||||
@ -328,55 +335,73 @@ ce_inc_search(el, dir)
|
||||
if (!done) {
|
||||
|
||||
/* Can't search if unmatched '[' */
|
||||
for (cp = &el->el_search.patbuf[el->el_search.patlen-1], ch = ']';
|
||||
cp > el->el_search.patbuf; cp--)
|
||||
for (cp = &el->el_search.patbuf[el->el_search.patlen-1],
|
||||
ch = ']';
|
||||
cp > el->el_search.patbuf;
|
||||
cp--)
|
||||
if (*cp == '[' || *cp == ']') {
|
||||
ch = *cp;
|
||||
break;
|
||||
}
|
||||
|
||||
if (el->el_search.patlen > 1 && ch != '[') {
|
||||
if (redo && newdir == dir) {
|
||||
if (pchar == '?') { /* wrap around */
|
||||
el->el_history.eventno =
|
||||
newdir == ED_SEARCH_PREV_HISTORY ? 0 : 0x7fffffff;
|
||||
if (hist_get(el) == CC_ERROR)
|
||||
/* el->el_history.eventno was fixed by first call */
|
||||
/* el->el_history.event
|
||||
* no was fixed by
|
||||
* first call */
|
||||
(void) hist_get(el);
|
||||
el->el_line.cursor = newdir == ED_SEARCH_PREV_HISTORY ?
|
||||
el->el_line.lastchar : el->el_line.buffer;
|
||||
el->el_line.cursor = newdir ==
|
||||
ED_SEARCH_PREV_HISTORY ?
|
||||
el->el_line.lastchar :
|
||||
el->el_line.buffer;
|
||||
} else
|
||||
el->el_line.cursor +=
|
||||
newdir == ED_SEARCH_PREV_HISTORY ? -1 : 1;
|
||||
newdir ==
|
||||
ED_SEARCH_PREV_HISTORY ?
|
||||
-1 : 1;
|
||||
}
|
||||
#ifdef ANCHOR
|
||||
el->el_search.patbuf[el->el_search.patlen++] = '.';
|
||||
el->el_search.patbuf[el->el_search.patlen++] = '*';
|
||||
el->el_search.patbuf[el->el_search.patlen++] =
|
||||
'.';
|
||||
el->el_search.patbuf[el->el_search.patlen++] =
|
||||
'*';
|
||||
#endif
|
||||
el->el_search.patbuf[el->el_search.patlen] = '\0';
|
||||
el->el_search.patbuf[el->el_search.patlen] =
|
||||
'\0';
|
||||
if (el->el_line.cursor < el->el_line.buffer ||
|
||||
el->el_line.cursor > el->el_line.lastchar ||
|
||||
(ret = ce_search_line(el, &el->el_search.patbuf[1],
|
||||
(ret = ce_search_line(el,
|
||||
&el->el_search.patbuf[1],
|
||||
newdir)) == CC_ERROR) {
|
||||
/* avoid c_setpat */
|
||||
el->el_state.lastcmd = (el_action_t) newdir;
|
||||
el->el_state.lastcmd =
|
||||
(el_action_t) newdir;
|
||||
ret = newdir == ED_SEARCH_PREV_HISTORY ?
|
||||
ed_search_prev_history(el, 0) :
|
||||
ed_search_next_history(el, 0);
|
||||
if (ret != CC_ERROR) {
|
||||
el->el_line.cursor = newdir == ED_SEARCH_PREV_HISTORY ?
|
||||
el->el_line.lastchar : el->el_line.buffer;
|
||||
(void) ce_search_line(el, &el->el_search.patbuf[1],
|
||||
el->el_line.cursor = newdir ==
|
||||
ED_SEARCH_PREV_HISTORY ?
|
||||
el->el_line.lastchar :
|
||||
el->el_line.buffer;
|
||||
(void) ce_search_line(el,
|
||||
&el->el_search.patbuf[1],
|
||||
newdir);
|
||||
}
|
||||
}
|
||||
el->el_search.patbuf[--el->el_search.patlen] = '\0';
|
||||
el->el_search.patbuf[--el->el_search.patlen] =
|
||||
'\0';
|
||||
if (ret == CC_ERROR) {
|
||||
term_beep(el);
|
||||
if (el->el_history.eventno != ohisteventno) {
|
||||
el->el_history.eventno = ohisteventno;
|
||||
if (el->el_history.eventno !=
|
||||
ohisteventno) {
|
||||
el->el_history.eventno =
|
||||
ohisteventno;
|
||||
if (hist_get(el) == CC_ERROR)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
el->el_line.cursor = ocursor;
|
||||
pchar = '?';
|
||||
@ -384,15 +409,16 @@ ce_inc_search(el, dir)
|
||||
pchar = ':';
|
||||
}
|
||||
}
|
||||
|
||||
ret = ce_inc_search(el, newdir);
|
||||
|
||||
if (ret == CC_ERROR && pchar == '?' && oldpchar == ':')
|
||||
/* break abort of failed search at last non-failed */
|
||||
/*
|
||||
* break abort of failed search at last
|
||||
* non-failed
|
||||
*/
|
||||
ret = CC_NORM;
|
||||
|
||||
}
|
||||
|
||||
if (ret == CC_NORM || (ret == CC_ERROR && oldpatlen == 0)) {
|
||||
/* restore on normal return or error exit */
|
||||
pchar = oldpchar;
|
||||
@ -400,14 +426,14 @@ ce_inc_search(el, dir)
|
||||
if (el->el_history.eventno != ohisteventno) {
|
||||
el->el_history.eventno = ohisteventno;
|
||||
if (hist_get(el) == CC_ERROR)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
el->el_line.cursor = ocursor;
|
||||
if (ret == CC_ERROR)
|
||||
re_refresh(el);
|
||||
}
|
||||
if (done || ret != CC_NORM)
|
||||
return ret;
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
|
||||
@ -416,9 +442,7 @@ ce_inc_search(el, dir)
|
||||
* Vi search.
|
||||
*/
|
||||
protected el_action_t
|
||||
cv_search(el, dir)
|
||||
EditLine *el;
|
||||
int dir;
|
||||
cv_search(EditLine *el, int dir)
|
||||
{
|
||||
char ch;
|
||||
char tmpbuf[EL_BUFSIZ];
|
||||
@ -459,22 +483,24 @@ cv_search(el, dir)
|
||||
el->el_line.lastchar = el->el_line.buffer;
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
re_refresh(el);
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
#ifdef ANCHOR
|
||||
if (el->el_search.patbuf[0] != '.' && el->el_search.patbuf[0] != '*') {
|
||||
(void)strncpy(tmpbuf, el->el_search.patbuf, sizeof(tmpbuf) - 1);
|
||||
if (el->el_search.patbuf[0] != '.' &&
|
||||
el->el_search.patbuf[0] != '*') {
|
||||
(void) strncpy(tmpbuf, el->el_search.patbuf,
|
||||
sizeof(tmpbuf) - 1);
|
||||
el->el_search.patbuf[0] = '.';
|
||||
el->el_search.patbuf[1] = '*';
|
||||
(void)strncpy(&el->el_search.patbuf[2], tmpbuf, EL_BUFSIZ - 3);
|
||||
(void) strncpy(&el->el_search.patbuf[2], tmpbuf,
|
||||
EL_BUFSIZ - 3);
|
||||
el->el_search.patlen++;
|
||||
el->el_search.patbuf[el->el_search.patlen++] = '.';
|
||||
el->el_search.patbuf[el->el_search.patlen++] = '*';
|
||||
el->el_search.patbuf[el->el_search.patlen] = '\0';
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
#ifdef ANCHOR
|
||||
tmpbuf[tmplen++] = '.';
|
||||
tmpbuf[tmplen++] = '*';
|
||||
@ -488,18 +514,16 @@ cv_search(el, dir)
|
||||
if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) :
|
||||
ed_search_next_history(el, 0)) == CC_ERROR) {
|
||||
re_refresh(el);
|
||||
return CC_ERROR;
|
||||
}
|
||||
else {
|
||||
return (CC_ERROR);
|
||||
} else {
|
||||
if (ch == 0033) {
|
||||
re_refresh(el);
|
||||
*el->el_line.lastchar++ = '\n';
|
||||
*el->el_line.lastchar = '\0';
|
||||
re_goto_bottom(el);
|
||||
return CC_NEWLINE;
|
||||
}
|
||||
else
|
||||
return CC_REFRESH;
|
||||
return (CC_NEWLINE);
|
||||
} else
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
}
|
||||
|
||||
@ -508,10 +532,7 @@ cv_search(el, dir)
|
||||
* Look for a pattern inside a line
|
||||
*/
|
||||
protected el_action_t
|
||||
ce_search_line(el, pattern, dir)
|
||||
EditLine *el;
|
||||
char *pattern;
|
||||
int dir;
|
||||
ce_search_line(EditLine *el, char *pattern, int dir)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
@ -519,17 +540,17 @@ ce_search_line(el, pattern, dir)
|
||||
for (cp = el->el_line.cursor; cp >= el->el_line.buffer; cp--)
|
||||
if (el_match(cp, pattern)) {
|
||||
el->el_line.cursor = cp;
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
} else {
|
||||
for (cp = el->el_line.cursor; *cp != '\0' &&
|
||||
cp < el->el_line.limit; cp++)
|
||||
if (el_match(cp, pattern)) {
|
||||
el->el_line.cursor = cp;
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -538,10 +559,9 @@ ce_search_line(el, pattern, dir)
|
||||
* Vi repeat search
|
||||
*/
|
||||
protected el_action_t
|
||||
cv_repeat_srch(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
cv_repeat_srch(EditLine *el, int c)
|
||||
{
|
||||
|
||||
#ifdef SDEBUG
|
||||
(void) fprintf(el->el_errfile, "dir %d patlen %d patbuf %s\n",
|
||||
c, el->el_search.patlen, el->el_search.patbuf);
|
||||
@ -552,11 +572,11 @@ cv_repeat_srch(el, c)
|
||||
|
||||
switch (c) {
|
||||
case ED_SEARCH_NEXT_HISTORY:
|
||||
return ed_search_next_history(el, 0);
|
||||
return (ed_search_next_history(el, 0));
|
||||
case ED_SEARCH_PREV_HISTORY:
|
||||
return ed_search_prev_history(el, 0);
|
||||
return (ed_search_prev_history(el, 0));
|
||||
default:
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -565,9 +585,7 @@ cv_repeat_srch(el, c)
|
||||
* Vi character search reverse
|
||||
*/
|
||||
protected el_action_t
|
||||
cv_csearch_back(el, ch, count, tflag)
|
||||
EditLine *el;
|
||||
int ch, count, tflag;
|
||||
cv_csearch_back(EditLine *el, int ch, int count, int tflag)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
@ -580,7 +598,7 @@ cv_csearch_back(el, ch, count, tflag)
|
||||
}
|
||||
|
||||
if (cp < el->el_line.buffer || (cp == el->el_line.buffer && *cp != ch))
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (*cp == ch && tflag)
|
||||
cp++;
|
||||
@ -590,11 +608,10 @@ cv_csearch_back(el, ch, count, tflag)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
el->el_line.cursor++;
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
re_refresh_cursor(el);
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -602,9 +619,7 @@ cv_csearch_back(el, ch, count, tflag)
|
||||
* Vi character search forward
|
||||
*/
|
||||
protected el_action_t
|
||||
cv_csearch_fwd(el, ch, count, tflag)
|
||||
EditLine *el;
|
||||
int ch, count, tflag;
|
||||
cv_csearch_fwd(EditLine *el, int ch, int count, int tflag)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
@ -617,7 +632,7 @@ cv_csearch_fwd(el, ch, count, tflag)
|
||||
}
|
||||
|
||||
if (cp >= el->el_line.lastchar)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (*cp == ch && tflag)
|
||||
cp--;
|
||||
@ -627,8 +642,8 @@ cv_csearch_fwd(el, ch, count, tflag)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
el->el_line.cursor++;
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
re_refresh_cursor(el);
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)search.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: search.h,v 1.4 1999/07/02 15:21:27 simonb Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -46,23 +48,23 @@
|
||||
|
||||
typedef struct el_search_t {
|
||||
char *patbuf; /* The pattern buffer */
|
||||
int patlen; /* Length of the pattern buffer */
|
||||
size_t patlen; /* Length of the pattern buffer */
|
||||
int patdir; /* Direction of the last search */
|
||||
int chadir; /* Character search direction */
|
||||
char chacha; /* Character we are looking for */
|
||||
} el_search_t;
|
||||
|
||||
|
||||
protected int el_match __P((const char *, const char *));
|
||||
protected int search_init __P((EditLine *));
|
||||
protected void search_end __P((EditLine *));
|
||||
protected int c_hmatch __P((EditLine *, const char *));
|
||||
protected void c_setpat __P((EditLine *));
|
||||
protected el_action_t ce_inc_search __P((EditLine *, int));
|
||||
protected el_action_t cv_search __P((EditLine *, int));
|
||||
protected el_action_t ce_search_line __P((EditLine *, char *, int));
|
||||
protected el_action_t cv_repeat_srch __P((EditLine *, int));
|
||||
protected el_action_t cv_csearch_back __P((EditLine *, int, int, int));
|
||||
protected el_action_t cv_csearch_fwd __P((EditLine *, int, int, int));
|
||||
protected int el_match(const char *, const char *);
|
||||
protected int search_init(EditLine *);
|
||||
protected void search_end(EditLine *);
|
||||
protected int c_hmatch(EditLine *, const char *);
|
||||
protected void c_setpat(EditLine *);
|
||||
protected el_action_t ce_inc_search(EditLine *, int);
|
||||
protected el_action_t cv_search(EditLine *, int);
|
||||
protected el_action_t ce_search_line(EditLine *, char *, int);
|
||||
protected el_action_t cv_repeat_srch(EditLine *, int);
|
||||
protected el_action_t cv_csearch_back(EditLine *, int, int, int);
|
||||
protected el_action_t cv_csearch_fwd(EditLine *, int, int, int);
|
||||
|
||||
#endif /* _h_el_search */
|
||||
|
@ -32,13 +32,15 @@
|
||||
* 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: sig.c,v 1.7 2001/01/04 15:55:03 christos Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* sig.c: Signal handling stuff.
|
||||
@ -51,14 +53,14 @@ static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
private EditLine *sel = NULL;
|
||||
|
||||
private int sighdl[] = {
|
||||
private const int sighdl[] = {
|
||||
#define _DO(a) (a),
|
||||
ALLSIGS
|
||||
#undef _DO
|
||||
- 1
|
||||
};
|
||||
|
||||
private void sig_handler __P((int));
|
||||
private void sig_handler(int);
|
||||
|
||||
/* sig_handler():
|
||||
* This is the handler called for all signals
|
||||
@ -66,8 +68,7 @@ private void sig_handler __P((int));
|
||||
* state in a private variable
|
||||
*/
|
||||
private void
|
||||
sig_handler(signo)
|
||||
int signo;
|
||||
sig_handler(int signo)
|
||||
{
|
||||
int i;
|
||||
sigset_t nset, oset;
|
||||
@ -107,8 +108,7 @@ sig_handler(signo)
|
||||
* Initialize all signal stuff
|
||||
*/
|
||||
protected int
|
||||
sig_init(el)
|
||||
EditLine *el;
|
||||
sig_init(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
sigset_t nset, oset;
|
||||
@ -122,12 +122,14 @@ sig_init(el)
|
||||
#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
|
||||
|
||||
el->el_signal = (sig_t *) el_malloc(SIGSIZE);
|
||||
if (el->el_signal == NULL)
|
||||
return (-1);
|
||||
for (i = 0; sighdl[i] != -1; i++)
|
||||
el->el_signal[i] = SIG_ERR;
|
||||
|
||||
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -135,9 +137,9 @@ sig_init(el)
|
||||
* Clear all signal stuff
|
||||
*/
|
||||
protected void
|
||||
sig_end(el)
|
||||
EditLine *el;
|
||||
sig_end(EditLine *el)
|
||||
{
|
||||
|
||||
el_free((ptr_t) el->el_signal);
|
||||
el->el_signal = NULL;
|
||||
}
|
||||
@ -147,8 +149,7 @@ sig_end(el)
|
||||
* set all the signal handlers
|
||||
*/
|
||||
protected void
|
||||
sig_set(el)
|
||||
EditLine *el;
|
||||
sig_set(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
sigset_t nset, oset;
|
||||
@ -174,8 +175,7 @@ sig_set(el)
|
||||
* clear all the signal handlers
|
||||
*/
|
||||
protected void
|
||||
sig_clr(el)
|
||||
EditLine *el;
|
||||
sig_clr(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
sigset_t nset, oset;
|
||||
@ -190,6 +190,7 @@ sig_clr(el)
|
||||
if (el->el_signal[i] != SIG_ERR)
|
||||
(void) signal(sighdl[i], el->el_signal[i]);
|
||||
|
||||
sel = NULL; /* we are going to die if the handler is called */
|
||||
sel = NULL; /* we are going to die if the handler is
|
||||
* called */
|
||||
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)sig.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: sig.h,v 1.2 1997/01/11 06:48:11 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -62,9 +64,9 @@
|
||||
|
||||
typedef sig_t *el_signal_t;
|
||||
|
||||
protected void sig_end __P((EditLine*));
|
||||
protected int sig_init __P((EditLine*));
|
||||
protected void sig_set __P((EditLine*));
|
||||
protected void sig_clr __P((EditLine*));
|
||||
protected void sig_end(EditLine*);
|
||||
protected int sig_init(EditLine*);
|
||||
protected void sig_set(EditLine*);
|
||||
protected void sig_clr(EditLine*);
|
||||
|
||||
#endif /* _h_el_sig */
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)sys.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: sys.h,v 1.3 1997/01/11 06:48:12 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -59,23 +61,16 @@
|
||||
|
||||
#ifndef _PTR_T
|
||||
# define _PTR_T
|
||||
# if __STDC__
|
||||
typedef void *ptr_t;
|
||||
# else
|
||||
typedef char* ptr_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _IOCTL_T
|
||||
# define _IOCTL_T
|
||||
# if __STDC__
|
||||
typedef void *ioctl_t;
|
||||
# else
|
||||
typedef char* ioctl_t;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define REGEX /* Use POSIX.2 regular expression functions */
|
||||
#undef REGEXP /* Use UNIX V8 regular expression functions */
|
||||
|
||||
@ -83,33 +78,33 @@ typedef char* ioctl_t;
|
||||
# undef REGEX
|
||||
# undef REGEXP
|
||||
# include <malloc.h>
|
||||
typedef void (*sig_t)__P((int));
|
||||
typedef void (*sig_t)(int);
|
||||
# ifdef __GNUC__
|
||||
/*
|
||||
* Broken hdrs.
|
||||
*/
|
||||
extern char *getenv __P((const char *));
|
||||
extern int fprintf __P((FILE *, const char *, ...));
|
||||
extern int sigsetmask __P((int));
|
||||
extern int sigblock __P((int));
|
||||
extern int ioctl __P((int, int, void *));
|
||||
extern int fputc __P((int, FILE *));
|
||||
extern int fgetc __P((FILE *));
|
||||
extern int fflush __P((FILE *));
|
||||
extern int tolower __P((int));
|
||||
extern int toupper __P((int));
|
||||
extern char *getenv(const char *);
|
||||
extern int fprintf(FILE *, const char *, ...);
|
||||
extern int sigsetmask(int);
|
||||
extern int sigblock(int);
|
||||
extern int ioctl(int, int, void *);
|
||||
extern int fputc(int, FILE *);
|
||||
extern int fgetc(FILE *);
|
||||
extern int fflush(FILE *);
|
||||
extern int tolower(int);
|
||||
extern int toupper(int);
|
||||
extern int errno, sys_nerr;
|
||||
extern char *sys_errlist[];
|
||||
extern void perror __P((const char *));
|
||||
extern int read __P((int, const char*, int));
|
||||
extern void perror(const char *);
|
||||
extern int read(int, const char*, int);
|
||||
# include <string.h>
|
||||
# define strerror(e) sys_errlist[e]
|
||||
# endif
|
||||
# ifdef SABER
|
||||
extern ptr_t memcpy __P((ptr_t, const ptr_t, size_t));
|
||||
extern ptr_t memset __P((ptr_t, int, size_t));
|
||||
extern ptr_t memcpy(ptr_t, const ptr_t, size_t);
|
||||
extern ptr_t memset(ptr_t, int, size_t);
|
||||
# endif
|
||||
extern char *fgetline __P((FILE *, int *));
|
||||
extern char *fgetline(FILE *, int *);
|
||||
#endif
|
||||
|
||||
#endif /* _h_sys */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -34,7 +34,7 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)term.h 8.1 (Berkeley) 6/4/93
|
||||
*
|
||||
* $NetBSD: term.h,v 1.11 2000/11/11 22:18:58 christos Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
@ -55,14 +55,16 @@ typedef struct { /* Symbolic function key bindings */
|
||||
|
||||
typedef struct {
|
||||
coord_t t_size; /* # lines and cols */
|
||||
bool_t t_flags;
|
||||
#define TERM_CAN_INSERT 0x01 /* Has insert cap */
|
||||
#define TERM_CAN_DELETE 0x02 /* Has delete cap */
|
||||
#define TERM_CAN_CEOL 0x04 /* Has CEOL cap */
|
||||
#define TERM_CAN_TAB 0x08 /* Can use tabs */
|
||||
#define TERM_CAN_ME 0x10 /* Can turn all attrs. */
|
||||
#define TERM_CAN_UP 0x20 /* Can move up */
|
||||
#define TERM_HAS_META 0x40 /* Has a meta key */
|
||||
int t_flags;
|
||||
#define TERM_CAN_INSERT 0x001 /* Has insert cap */
|
||||
#define TERM_CAN_DELETE 0x002 /* Has delete cap */
|
||||
#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */
|
||||
#define TERM_CAN_TAB 0x008 /* Can use tabs */
|
||||
#define TERM_CAN_ME 0x010 /* Can turn all attrs. */
|
||||
#define TERM_CAN_UP 0x020 /* Can move up */
|
||||
#define TERM_HAS_META 0x040 /* Has a meta key */
|
||||
#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
|
||||
#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
|
||||
char *t_buf; /* Termcap buffer */
|
||||
int t_loc; /* location used */
|
||||
char **t_str; /* termcap strings */
|
||||
@ -82,30 +84,28 @@ typedef struct {
|
||||
#define A_K_EN 5
|
||||
#define A_K_NKEYS 6
|
||||
|
||||
protected void term_move_to_line __P((EditLine *, int));
|
||||
protected void term_move_to_char __P((EditLine *, int));
|
||||
protected void term_clear_EOL __P((EditLine *, int));
|
||||
protected void term_overwrite __P((EditLine *, char *, int));
|
||||
protected void term_insertwrite __P((EditLine *, char *, int));
|
||||
protected void term_deletechars __P((EditLine *, int));
|
||||
protected void term_clear_screen __P((EditLine *));
|
||||
protected void term_beep __P((EditLine *));
|
||||
protected void term_change_size __P((EditLine *, int, int));
|
||||
protected int term_get_size __P((EditLine *, int *, int *));
|
||||
protected int term_init __P((EditLine *));
|
||||
protected void term_bind_arrow __P((EditLine *));
|
||||
protected void term_print_arrow __P((EditLine *, char *));
|
||||
protected int term_clear_arrow __P((EditLine *, char *));
|
||||
protected int term_set_arrow __P((EditLine *, char *,
|
||||
key_value_t *, int));
|
||||
protected void term_end __P((EditLine *));
|
||||
protected int term_set __P((EditLine *, char *));
|
||||
protected int term_settc __P((EditLine *, int, char **));
|
||||
protected int term_telltc __P((EditLine *, int, char **));
|
||||
protected int term_echotc __P((EditLine *, int, char **));
|
||||
|
||||
protected int term__putc __P((int));
|
||||
protected void term__flush __P((void));
|
||||
protected void term_move_to_line(EditLine *, int);
|
||||
protected void term_move_to_char(EditLine *, int);
|
||||
protected void term_clear_EOL(EditLine *, int);
|
||||
protected void term_overwrite(EditLine *, char *, int);
|
||||
protected void term_insertwrite(EditLine *, char *, int);
|
||||
protected void term_deletechars(EditLine *, int);
|
||||
protected void term_clear_screen(EditLine *);
|
||||
protected void term_beep(EditLine *);
|
||||
protected int term_change_size(EditLine *, int, int);
|
||||
protected int term_get_size(EditLine *, int *, int *);
|
||||
protected int term_init(EditLine *);
|
||||
protected void term_bind_arrow(EditLine *);
|
||||
protected void term_print_arrow(EditLine *, char *);
|
||||
protected int term_clear_arrow(EditLine *, char *);
|
||||
protected int term_set_arrow(EditLine *, char *, key_value_t *, int);
|
||||
protected void term_end(EditLine *);
|
||||
protected int term_set(EditLine *, char *);
|
||||
protected int term_settc(EditLine *, int, char **);
|
||||
protected int term_telltc(EditLine *, int, char **);
|
||||
protected int term_echotc(EditLine *, int, char **);
|
||||
protected int term__putc(int);
|
||||
protected void term__flush(void);
|
||||
|
||||
/*
|
||||
* Easy access macros
|
||||
@ -118,5 +118,7 @@ protected void term__flush __P((void));
|
||||
#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
|
||||
#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
|
||||
#define EL_HAS_META (EL_FLAGS & TERM_HAS_META)
|
||||
#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
|
||||
#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
|
||||
|
||||
#endif /* _h_el_term */
|
||||
|
@ -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: tokenizer.c,v 1.6 2000/09/04 22:06:33 lukem Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* tokenize.c: Bourne shell like tokenizer
|
||||
@ -48,7 +52,9 @@ static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
|
||||
#include <stdlib.h>
|
||||
#include "tokenizer.h"
|
||||
|
||||
typedef enum { Q_none, Q_single, Q_double, Q_one, Q_doubleone } quote_t;
|
||||
typedef enum {
|
||||
Q_none, Q_single, Q_double, Q_one, Q_doubleone
|
||||
} quote_t;
|
||||
|
||||
#define IFS "\t \n"
|
||||
|
||||
@ -76,16 +82,16 @@ struct tokenizer {
|
||||
};
|
||||
|
||||
|
||||
private void tok_finish __P((Tokenizer *));
|
||||
private void tok_finish(Tokenizer *);
|
||||
|
||||
|
||||
/* tok_finish():
|
||||
* Finish a word in the tokenizer.
|
||||
*/
|
||||
private void
|
||||
tok_finish(tok)
|
||||
Tokenizer *tok;
|
||||
tok_finish(Tokenizer *tok)
|
||||
{
|
||||
|
||||
*tok->wptr = '\0';
|
||||
if ((tok->flags & TOK_KEEP) || tok->wptr != tok->wstart) {
|
||||
tok->argv[tok->argc++] = tok->wstart;
|
||||
@ -100,8 +106,7 @@ tok_finish(tok)
|
||||
* Initialize the tokenizer
|
||||
*/
|
||||
public Tokenizer *
|
||||
tok_init(ifs)
|
||||
const char *ifs;
|
||||
tok_init(const char *ifs)
|
||||
{
|
||||
Tokenizer *tok = (Tokenizer *) tok_malloc(sizeof(Tokenizer));
|
||||
|
||||
@ -109,15 +114,19 @@ tok_init(ifs)
|
||||
tok->argc = 0;
|
||||
tok->amax = AINCR;
|
||||
tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
|
||||
if (tok->argv == NULL)
|
||||
return (NULL);
|
||||
tok->argv[0] = NULL;
|
||||
tok->wspace = (char *) tok_malloc(WINCR);
|
||||
if (tok->wspace == NULL)
|
||||
return (NULL);
|
||||
tok->wmax = tok->wspace + WINCR;
|
||||
tok->wstart = tok->wspace;
|
||||
tok->wptr = tok->wspace;
|
||||
tok->flags = 0;
|
||||
tok->quote = Q_none;
|
||||
|
||||
return tok;
|
||||
return (tok);
|
||||
}
|
||||
|
||||
|
||||
@ -125,9 +134,9 @@ tok_init(ifs)
|
||||
* Reset the tokenizer
|
||||
*/
|
||||
public void
|
||||
tok_reset(tok)
|
||||
Tokenizer *tok;
|
||||
tok_reset(Tokenizer *tok)
|
||||
{
|
||||
|
||||
tok->argc = 0;
|
||||
tok->wstart = tok->wspace;
|
||||
tok->wptr = tok->wspace;
|
||||
@ -140,9 +149,9 @@ tok_reset(tok)
|
||||
* Clean up
|
||||
*/
|
||||
public void
|
||||
tok_end(tok)
|
||||
Tokenizer *tok;
|
||||
tok_end(Tokenizer *tok)
|
||||
{
|
||||
|
||||
tok_free((ptr_t) tok->ifs);
|
||||
tok_free((ptr_t) tok->wspace);
|
||||
tok_free((ptr_t) tok->argv);
|
||||
@ -161,22 +170,19 @@ tok_end(tok)
|
||||
* 0: Ok
|
||||
*/
|
||||
public int
|
||||
tok_line(tok, line, argc, argv)
|
||||
Tokenizer *tok;
|
||||
const char* line;
|
||||
int *argc;
|
||||
char ***argv;
|
||||
tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv)
|
||||
{
|
||||
const char *ptr;
|
||||
|
||||
while (1) {
|
||||
for (;;) {
|
||||
switch (*(ptr = line++)) {
|
||||
case '\'':
|
||||
tok->flags |= TOK_KEEP;
|
||||
tok->flags &= ~TOK_EAT;
|
||||
switch (tok->quote) {
|
||||
case Q_none:
|
||||
tok->quote = Q_single; /* Enter single quote mode */
|
||||
tok->quote = Q_single; /* Enter single quote
|
||||
* mode */
|
||||
break;
|
||||
|
||||
case Q_single: /* Exit single quote mode */
|
||||
@ -210,8 +216,8 @@ tok_line(tok, line, argc, argv)
|
||||
tok->quote = Q_double;
|
||||
break;
|
||||
|
||||
case Q_double:
|
||||
tok->quote = Q_none; /* Exit double quote mode */
|
||||
case Q_double: /* Exit double quote mode */
|
||||
tok->quote = Q_none;
|
||||
break;
|
||||
|
||||
case Q_one: /* Quote this " */
|
||||
@ -241,13 +247,13 @@ tok_line(tok, line, argc, argv)
|
||||
tok->quote = Q_one;
|
||||
break;
|
||||
|
||||
case Q_double:
|
||||
tok->quote = Q_doubleone;/* Quote next character */
|
||||
case Q_double: /* Quote next character */
|
||||
tok->quote = Q_doubleone;
|
||||
break;
|
||||
|
||||
case Q_one:
|
||||
case Q_one: /* Quote this, restore state */
|
||||
*tok->wptr++ = *ptr;
|
||||
tok->quote = Q_none; /* Quote this, restore state */
|
||||
tok->quote = Q_none;
|
||||
break;
|
||||
|
||||
case Q_single: /* Stay in single quote mode */
|
||||
@ -278,14 +284,14 @@ tok_line(tok, line, argc, argv)
|
||||
*tok->wptr++ = *ptr; /* Add the return */
|
||||
break;
|
||||
|
||||
case Q_doubleone:
|
||||
case Q_doubleone: /* Back to double, eat the '\n' */
|
||||
tok->flags |= TOK_EAT;
|
||||
tok->quote = Q_double; /* Back to double, eat the '\n' */
|
||||
tok->quote = Q_double;
|
||||
break;
|
||||
|
||||
case Q_one:
|
||||
case Q_one: /* No quote, more eat the '\n' */
|
||||
tok->flags |= TOK_EAT;
|
||||
tok->quote = Q_none; /* No quote, more eat the '\n' */
|
||||
tok->quote = Q_none;
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -299,7 +305,7 @@ tok_line(tok, line, argc, argv)
|
||||
/* Finish word and return */
|
||||
if (tok->flags & TOK_EAT) {
|
||||
tok->flags &= ~TOK_EAT;
|
||||
return 3;
|
||||
return (3);
|
||||
}
|
||||
tok_finish(tok);
|
||||
*argv = tok->argv;
|
||||
@ -366,6 +372,8 @@ tok_line(tok, line, argc, argv)
|
||||
char *s = (char *) tok_realloc(tok->wspace, size);
|
||||
/* SUPPRESS 22 */
|
||||
int offs = s - tok->wspace;
|
||||
if (s == NULL)
|
||||
return (-1);
|
||||
|
||||
if (offs != 0) {
|
||||
int i;
|
||||
@ -377,12 +385,14 @@ tok_line(tok, line, argc, argv)
|
||||
tok->wspace = s;
|
||||
}
|
||||
}
|
||||
|
||||
if (tok->argc >= tok->amax - 4) {
|
||||
char **p;
|
||||
tok->amax += AINCR;
|
||||
tok->argv = (char **) tok_reallocf(tok->argv,
|
||||
p = (char **) tok_reallocf(tok->argv,
|
||||
tok->amax * sizeof(char *));
|
||||
}
|
||||
|
||||
if (p == NULL)
|
||||
return (-1);
|
||||
tok->argv = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tokenizer.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: tokenizer.h,v 1.3 1999/07/02 15:21:27 simonb Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -44,10 +46,9 @@
|
||||
|
||||
typedef struct tokenizer Tokenizer;
|
||||
|
||||
Tokenizer *tok_init __P((const char *));
|
||||
void tok_reset __P((Tokenizer *));
|
||||
void tok_end __P((Tokenizer *));
|
||||
int tok_line __P((Tokenizer *, const char *,
|
||||
int *, char ***));
|
||||
Tokenizer *tok_init(const char *);
|
||||
void tok_reset(Tokenizer *);
|
||||
void tok_end(Tokenizer *);
|
||||
int tok_line(Tokenizer *, const char *, int *, char ***);
|
||||
|
||||
#endif /* _h_tokenizer */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)tty.h 8.1 (Berkeley) 6/4/93
|
||||
* $NetBSD: tty.h,v 1.7 1999/09/26 14:37:47 lukem Exp $
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -44,6 +46,7 @@
|
||||
|
||||
#include "histedit.h"
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* Define our own since everyone gets it wrong! */
|
||||
#define CONTROL(A) ((A) & 037)
|
||||
@ -442,29 +445,29 @@
|
||||
#define QU_IO 2 /* used only for quoted chars */
|
||||
#define NN_IO 3 /* The number of entries */
|
||||
|
||||
#define M_INP 0
|
||||
#define M_OUT 1
|
||||
#define M_CTL 2
|
||||
#define M_LIN 3
|
||||
#define M_CHAR 4
|
||||
#define M_NN 5
|
||||
#define MD_INP 0
|
||||
#define MD_OUT 1
|
||||
#define MD_CTL 2
|
||||
#define MD_LIN 3
|
||||
#define MD_CHAR 4
|
||||
#define MD_NN 5
|
||||
|
||||
typedef struct {
|
||||
char *t_name;
|
||||
u_int t_setmask;
|
||||
u_int t_clrmask;
|
||||
} ttyperm_t[NN_IO][M_NN];
|
||||
} ttyperm_t[NN_IO][MD_NN];
|
||||
|
||||
typedef unsigned char ttychar_t[NN_IO][C_NCC];
|
||||
|
||||
protected int tty_init __P((EditLine *));
|
||||
protected void tty_end __P((EditLine *));
|
||||
protected int tty_stty __P((EditLine *, int, char**));
|
||||
protected int tty_rawmode __P((EditLine *));
|
||||
protected int tty_cookedmode __P((EditLine *));
|
||||
protected int tty_quotemode __P((EditLine *));
|
||||
protected int tty_noquotemode __P((EditLine *));
|
||||
protected void tty_bind_char __P((EditLine *, int));
|
||||
protected int tty_init(EditLine *);
|
||||
protected void tty_end(EditLine *);
|
||||
protected int tty_stty(EditLine *, int, char**);
|
||||
protected int tty_rawmode(EditLine *);
|
||||
protected int tty_cookedmode(EditLine *);
|
||||
protected int tty_quotemode(EditLine *);
|
||||
protected int tty_noquotemode(EditLine *);
|
||||
protected void tty_bind_char(EditLine *, int);
|
||||
|
||||
typedef struct {
|
||||
ttyperm_t t_t;
|
||||
|
404
lib/libedit/vi.c
404
lib/libedit/vi.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: vi.c,v 1.7 1999/07/02 15:21:28 simonb Exp $
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
|
||||
#endif /* not lint && not SCCSID */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
/*
|
||||
* vi.c: Vi mode commands.
|
||||
@ -46,17 +50,16 @@ static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
|
||||
#include "sys.h"
|
||||
#include "el.h"
|
||||
|
||||
private el_action_t cv_action __P((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(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
cv_action(EditLine *el, int c)
|
||||
{
|
||||
register char *cp, *kp;
|
||||
char *cp, *kp;
|
||||
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
el->el_chared.c_vcmd.action = NOP;
|
||||
@ -77,26 +80,25 @@ cv_action(el, 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);
|
||||
|
||||
#ifdef notdef
|
||||
/*
|
||||
* I don't think that this is needed. But we keep it for now
|
||||
*/
|
||||
else if (el_chared.c_vcmd.action == NOP) {
|
||||
else
|
||||
if (el_chared.c_vcmd.action == NOP) {
|
||||
el->el_chared.c_vcmd.pos = el->el_line.cursor;
|
||||
el->el_chared.c_vcmd.action = c;
|
||||
return CC_ARGHACK;
|
||||
}
|
||||
else {
|
||||
return (CC_ARGHACK);
|
||||
} else {
|
||||
el->el_chared.c_vcmd.action = 0;
|
||||
el->el_chared.c_vcmd.pos = 0;
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -105,29 +107,28 @@ cv_action(el, c)
|
||||
/* cv_paste():
|
||||
* Paste previous deletion before or after the cursor
|
||||
*/
|
||||
protected el_action_t
|
||||
cv_paste(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
private el_action_t
|
||||
cv_paste(EditLine *el, int c)
|
||||
{
|
||||
char *ptr;
|
||||
c_undo_t *un = &el->el_chared.c_undo;
|
||||
|
||||
#ifdef DEBUG_PASTE
|
||||
(void) fprintf(el->el_errfile, "Paste: %x \"%s\" +%d -%d\n",
|
||||
un->action, un->buf, un->isize, un->dsize);
|
||||
#endif
|
||||
if (un->isize == 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (!c && el->el_line.cursor < el->el_line.lastchar)
|
||||
el->el_line.cursor++;
|
||||
ptr = el->el_line.cursor;
|
||||
|
||||
c_insert(el, un->isize);
|
||||
c_insert(el, (int) un->isize);
|
||||
if (el->el_line.cursor + un->isize > el->el_line.lastchar)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
(void) memcpy(ptr, un->buf, un->isize);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -137,11 +138,10 @@ cv_paste(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_paste_next(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_paste_next(EditLine *el, int c)
|
||||
{
|
||||
return cv_paste(el, 0);
|
||||
|
||||
return (cv_paste(el, 0));
|
||||
}
|
||||
|
||||
|
||||
@ -151,11 +151,10 @@ vi_paste_next(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_paste_prev(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_paste_prev(EditLine *el, int c)
|
||||
{
|
||||
return cv_paste(el, 1);
|
||||
|
||||
return (cv_paste(el, 1));
|
||||
}
|
||||
|
||||
|
||||
@ -165,12 +164,11 @@ vi_paste_prev(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_prev_space_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_prev_space_word(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor == el->el_line.buffer)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
|
||||
el->el_line.buffer,
|
||||
@ -179,10 +177,9 @@ vi_prev_space_word(el, c)
|
||||
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -192,12 +189,11 @@ vi_prev_space_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_prev_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_prev_word(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor == el->el_line.buffer)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
el->el_line.cursor = cv_prev_word(el, el->el_line.cursor,
|
||||
el->el_line.buffer,
|
||||
@ -206,10 +202,9 @@ vi_prev_word(el, c)
|
||||
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -219,12 +214,11 @@ vi_prev_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_next_space_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_next_space_word(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
|
||||
el->el_line.lastchar,
|
||||
@ -234,11 +228,11 @@ vi_next_space_word(el, c)
|
||||
if (el->el_map.type == MAP_VI)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
}
|
||||
|
||||
/* vi_next_word():
|
||||
* Vi move to the next word
|
||||
@ -246,12 +240,11 @@ vi_next_space_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_next_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_next_word(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
|
||||
el->el_line.lastchar,
|
||||
@ -261,23 +254,20 @@ vi_next_word(el, c)
|
||||
if (el->el_map.type == MAP_VI)
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* vi_change_case():
|
||||
* Vi change case of character under the cursor and advance one character
|
||||
* [~]
|
||||
*/
|
||||
protected el_action_t
|
||||
vi_change_case(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_change_case(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor < el->el_line.lastchar) {
|
||||
c = (unsigned char)*el->el_line.cursor;
|
||||
if (isupper(c))
|
||||
@ -287,9 +277,9 @@ vi_change_case(el, c)
|
||||
else
|
||||
el->el_line.cursor++;
|
||||
re_fastaddc(el);
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@ -299,15 +289,14 @@ vi_change_case(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_change_meta(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_change_meta(EditLine *el, int c)
|
||||
{
|
||||
|
||||
/*
|
||||
* 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));
|
||||
}
|
||||
|
||||
|
||||
@ -317,10 +306,9 @@ vi_change_meta(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_insert_at_bol(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_insert_at_bol(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
el->el_chared.c_vcmd.ins = el->el_line.cursor;
|
||||
|
||||
@ -328,7 +316,7 @@ vi_insert_at_bol(el, c)
|
||||
el->el_chared.c_undo.action = DELETE;
|
||||
|
||||
el->el_map.current = el->el_map.key;
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -338,17 +326,16 @@ vi_insert_at_bol(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_replace_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_replace_char(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_map.current = el->el_map.key;
|
||||
el->el_state.inputmode = MODE_REPLACE_1;
|
||||
el->el_chared.c_undo.action = CHANGE;
|
||||
el->el_chared.c_undo.ptr = el->el_line.cursor;
|
||||
el->el_chared.c_undo.isize = 0;
|
||||
el->el_chared.c_undo.dsize = 0;
|
||||
return CC_ARGHACK;
|
||||
return (CC_ARGHACK);
|
||||
}
|
||||
|
||||
|
||||
@ -358,17 +345,16 @@ vi_replace_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_replace_mode(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_replace_mode(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_map.current = el->el_map.key;
|
||||
el->el_state.inputmode = MODE_REPLACE;
|
||||
el->el_chared.c_undo.action = CHANGE;
|
||||
el->el_chared.c_undo.ptr = el->el_line.cursor;
|
||||
el->el_chared.c_undo.isize = 0;
|
||||
el->el_chared.c_undo.dsize = 0;
|
||||
return CC_ARGHACK;
|
||||
return (CC_ARGHACK);
|
||||
}
|
||||
|
||||
|
||||
@ -378,13 +364,12 @@ vi_replace_mode(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_substitute_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_substitute_char(EditLine *el, int c)
|
||||
{
|
||||
|
||||
c_delafter(el, el->el_state.argument);
|
||||
el->el_map.current = el->el_map.key;
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -394,13 +379,12 @@ vi_substitute_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_substitute_line(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_substitute_line(EditLine *el, int c)
|
||||
{
|
||||
|
||||
(void) em_kill_line(el, 0);
|
||||
el->el_map.current = el->el_map.key;
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -410,13 +394,12 @@ vi_substitute_line(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_change_to_eol(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_change_to_eol(EditLine *el, int c)
|
||||
{
|
||||
|
||||
(void) ed_kill_line(el, 0);
|
||||
el->el_map.current = el->el_map.key;
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -426,17 +409,16 @@ vi_change_to_eol(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_insert(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_insert(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_map.current = el->el_map.key;
|
||||
|
||||
el->el_chared.c_vcmd.ins = el->el_line.cursor;
|
||||
el->el_chared.c_undo.ptr = el->el_line.cursor;
|
||||
el->el_chared.c_undo.action = DELETE;
|
||||
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -446,9 +428,7 @@ vi_insert(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_add(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_add(EditLine *el, int c)
|
||||
{
|
||||
el_action_t ret;
|
||||
|
||||
@ -458,15 +438,14 @@ vi_add(el, c)
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
ret = CC_CURSOR;
|
||||
}
|
||||
else
|
||||
} else
|
||||
ret = CC_NORM;
|
||||
|
||||
el->el_chared.c_vcmd.ins = el->el_line.cursor;
|
||||
el->el_chared.c_undo.ptr = el->el_line.cursor;
|
||||
el->el_chared.c_undo.action = DELETE;
|
||||
|
||||
return ret;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
@ -476,10 +455,9 @@ vi_add(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_add_at_eol(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_add_at_eol(EditLine *el, int c)
|
||||
{
|
||||
|
||||
el->el_map.current = el->el_map.key;
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
|
||||
@ -487,7 +465,7 @@ vi_add_at_eol(el, c)
|
||||
el->el_chared.c_vcmd.ins = el->el_line.lastchar;
|
||||
el->el_chared.c_undo.ptr = el->el_line.lastchar;
|
||||
el->el_chared.c_undo.action = DELETE;
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -497,11 +475,10 @@ vi_add_at_eol(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_delete_meta(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_delete_meta(EditLine *el, int c)
|
||||
{
|
||||
return cv_action(el, DELETE);
|
||||
|
||||
return (cv_action(el, DELETE));
|
||||
}
|
||||
|
||||
|
||||
@ -511,23 +488,21 @@ vi_delete_meta(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_end_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_end_word(EditLine *el, int c)
|
||||
{
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return CC_ERROR;
|
||||
|
||||
el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar,
|
||||
el->el_state.argument);
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return (CC_ERROR);
|
||||
|
||||
el->el_line.cursor = cv__endword(el->el_line.cursor,
|
||||
el->el_line.lastchar, el->el_state.argument);
|
||||
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
el->el_line.cursor++;
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -537,23 +512,21 @@ vi_end_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_to_end_word(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_to_end_word(EditLine *el, int c)
|
||||
{
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return CC_ERROR;
|
||||
|
||||
el->el_line.cursor = cv__endword(el->el_line.cursor, el->el_line.lastchar,
|
||||
el->el_state.argument);
|
||||
if (el->el_line.cursor == el->el_line.lastchar)
|
||||
return (CC_ERROR);
|
||||
|
||||
el->el_line.cursor = cv__endword(el->el_line.cursor,
|
||||
el->el_line.lastchar, el->el_state.argument);
|
||||
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
el->el_line.cursor++;
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -563,9 +536,7 @@ vi_to_end_word(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_undo(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_undo(EditLine *el, int c)
|
||||
{
|
||||
char *cp, *kp;
|
||||
char temp;
|
||||
@ -579,7 +550,7 @@ vi_undo(el, c)
|
||||
switch (un->action) {
|
||||
case DELETE:
|
||||
if (un->dsize == 0)
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
|
||||
(void) memcpy(un->buf, un->ptr, un->dsize);
|
||||
for (cp = un->ptr; cp <= el->el_line.lastchar; cp++)
|
||||
@ -614,8 +585,7 @@ vi_undo(el, c)
|
||||
*kp++ = *cp;
|
||||
*cp++ = temp;
|
||||
}
|
||||
}
|
||||
else if (size < 0) {
|
||||
} else if (size < 0) {
|
||||
size = -size;
|
||||
for (; cp <= el->el_line.lastchar; cp++) {
|
||||
*kp++ = *cp;
|
||||
@ -631,11 +601,11 @@ vi_undo(el, c)
|
||||
|
||||
case INSERT:
|
||||
if (un->isize == 0)
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
|
||||
el->el_line.cursor = un->ptr;
|
||||
c_insert(el, un->isize);
|
||||
memcpy(un->ptr, un->buf, un->isize);
|
||||
c_insert(el, (int) un->isize);
|
||||
(void) memcpy(un->ptr, un->buf, un->isize);
|
||||
un->action = DELETE;
|
||||
un->dsize = un->isize;
|
||||
un->isize = 0;
|
||||
@ -643,7 +613,7 @@ vi_undo(el, c)
|
||||
|
||||
case CHANGE:
|
||||
if (un->isize == 0)
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
|
||||
el->el_line.cursor = un->ptr;
|
||||
size = (int) (el->el_line.cursor - el->el_line.lastchar);
|
||||
@ -660,10 +630,10 @@ vi_undo(el, c)
|
||||
break;
|
||||
|
||||
default:
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -673,9 +643,7 @@ vi_undo(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_undo_line(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_undo_line(EditLine *el, int c)
|
||||
{
|
||||
|
||||
return hist_get(el);
|
||||
@ -688,11 +656,10 @@ vi_undo_line(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_command_mode(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_command_mode(EditLine *el, int c)
|
||||
{
|
||||
int size;
|
||||
|
||||
/* [Esc] cancels pending action */
|
||||
el->el_chared.c_vcmd.ins = 0;
|
||||
el->el_chared.c_vcmd.action = NOP;
|
||||
@ -714,32 +681,31 @@ vi_command_mode(el, c)
|
||||
if (el->el_line.cursor > el->el_line.buffer)
|
||||
el->el_line.cursor--;
|
||||
#endif
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
/* vi_zero():
|
||||
* Vi move to the beginning of line
|
||||
* [0]
|
||||
*/
|
||||
protected el_action_t
|
||||
vi_zero(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_zero(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_state.doingarg) {
|
||||
if (el->el_state.argument > 1000000)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
el->el_state.argument =
|
||||
(el->el_state.argument * 10) + (c - '0');
|
||||
return CC_ARGHACK;
|
||||
}
|
||||
else {
|
||||
return (CC_ARGHACK);
|
||||
} else {
|
||||
el->el_line.cursor = el->el_line.buffer;
|
||||
if (el->el_chared.c_vcmd.action & DELETE) {
|
||||
cv_delfini(el);
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
}
|
||||
|
||||
@ -750,22 +716,21 @@ vi_zero(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_delete_prev_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_delete_prev_char(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_chared.c_vcmd.ins == 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (el->el_chared.c_vcmd.ins >
|
||||
el->el_line.cursor - el->el_state.argument)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
c_delbefore(el, el->el_state.argument);
|
||||
el->el_line.cursor -= el->el_state.argument;
|
||||
|
||||
return CC_REFRESH;
|
||||
} /* end v_del_char_prev */
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
/* vi_list_or_eof():
|
||||
@ -774,23 +739,21 @@ vi_delete_prev_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_list_or_eof(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_list_or_eof(EditLine *el, int c)
|
||||
{
|
||||
|
||||
#ifdef notyet
|
||||
if (el->el_line.cursor == el->el_line.lastchar &&
|
||||
el->el_line.cursor == el->el_line.buffer) {
|
||||
#endif
|
||||
term_overwrite(el, STReof, 4); /* then do a EOF */
|
||||
term__flush();
|
||||
return CC_EOF;
|
||||
return (CC_EOF);
|
||||
#ifdef notyet
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
re_goto_bottom(el);
|
||||
*el->el_line.lastchar = '\0'; /* just in case */
|
||||
return CC_LIST_CHOICES;
|
||||
return (CC_LIST_CHOICES);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -802,9 +765,7 @@ vi_list_or_eof(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_kill_line_prev(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_kill_line_prev(EditLine *el, int c)
|
||||
{
|
||||
char *kp, *cp;
|
||||
|
||||
@ -815,7 +776,7 @@ vi_kill_line_prev(el, c)
|
||||
el->el_chared.c_kill.last = kp;
|
||||
c_delbefore(el, el->el_line.cursor - el->el_line.buffer);
|
||||
el->el_line.cursor = el->el_line.buffer; /* zap! */
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -825,11 +786,10 @@ vi_kill_line_prev(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_search_prev(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_search_prev(EditLine *el, int c)
|
||||
{
|
||||
return cv_search(el, ED_SEARCH_PREV_HISTORY);
|
||||
|
||||
return (cv_search(el, ED_SEARCH_PREV_HISTORY));
|
||||
}
|
||||
|
||||
|
||||
@ -839,11 +799,10 @@ vi_search_prev(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_search_next(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_search_next(EditLine *el, int c)
|
||||
{
|
||||
return cv_search(el, ED_SEARCH_NEXT_HISTORY);
|
||||
|
||||
return (cv_search(el, ED_SEARCH_NEXT_HISTORY));
|
||||
}
|
||||
|
||||
|
||||
@ -853,14 +812,13 @@ vi_search_next(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_repeat_search_next(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_repeat_search_next(EditLine *el, int c)
|
||||
{
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@ -870,16 +828,15 @@ vi_repeat_search_next(el, c)
|
||||
*/
|
||||
/*ARGSUSED*/
|
||||
protected el_action_t
|
||||
vi_repeat_search_prev(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_repeat_search_prev(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_search.patlen == 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
else
|
||||
return cv_repeat_srch(el,
|
||||
return (cv_repeat_srch(el,
|
||||
el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
|
||||
ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY);
|
||||
ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY));
|
||||
}
|
||||
|
||||
|
||||
@ -889,19 +846,17 @@ vi_repeat_search_prev(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_next_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_next_char(EditLine *el, int c)
|
||||
{
|
||||
char ch;
|
||||
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return ed_end_of_file(el, 0);
|
||||
return (ed_end_of_file(el, 0));
|
||||
|
||||
el->el_search.chadir = CHAR_FWD;
|
||||
el->el_search.chacha = ch;
|
||||
|
||||
return cv_csearch_fwd(el, ch, el->el_state.argument, 0);
|
||||
return (cv_csearch_fwd(el, ch, el->el_state.argument, 0));
|
||||
|
||||
}
|
||||
|
||||
@ -912,19 +867,17 @@ vi_next_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_prev_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_prev_char(EditLine *el, int c)
|
||||
{
|
||||
char ch;
|
||||
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return ed_end_of_file(el, 0);
|
||||
return (ed_end_of_file(el, 0));
|
||||
|
||||
el->el_search.chadir = CHAR_BACK;
|
||||
el->el_search.chacha = ch;
|
||||
|
||||
return cv_csearch_back(el, ch, el->el_state.argument, 0);
|
||||
return (cv_csearch_back(el, ch, el->el_state.argument, 0));
|
||||
}
|
||||
|
||||
|
||||
@ -934,16 +887,14 @@ vi_prev_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_to_next_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_to_next_char(EditLine *el, int c)
|
||||
{
|
||||
char ch;
|
||||
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return ed_end_of_file(el, 0);
|
||||
return (ed_end_of_file(el, 0));
|
||||
|
||||
return cv_csearch_fwd(el, ch, el->el_state.argument, 1);
|
||||
return (cv_csearch_fwd(el, ch, el->el_state.argument, 1));
|
||||
|
||||
}
|
||||
|
||||
@ -954,15 +905,14 @@ vi_to_next_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_to_prev_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_to_prev_char(EditLine *el, int c)
|
||||
{
|
||||
char ch;
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return ed_end_of_file(el, 0);
|
||||
|
||||
return cv_csearch_back(el, ch, el->el_state.argument, 1);
|
||||
if (el_getc(el, &ch) != 1)
|
||||
return (ed_end_of_file(el, 0));
|
||||
|
||||
return (cv_csearch_back(el, ch, el->el_state.argument, 1));
|
||||
}
|
||||
|
||||
|
||||
@ -972,16 +922,17 @@ vi_to_prev_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_repeat_next_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_repeat_next_char(EditLine *el, int c)
|
||||
{
|
||||
if (el->el_search.chacha == 0)
|
||||
return CC_ERROR;
|
||||
|
||||
return el->el_search.chadir == CHAR_FWD ?
|
||||
cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :
|
||||
cv_csearch_back(el, el->el_search.chacha, el->el_state.argument, 0);
|
||||
if (el->el_search.chacha == 0)
|
||||
return (CC_ERROR);
|
||||
|
||||
return (el->el_search.chadir == CHAR_FWD
|
||||
? cv_csearch_fwd(el, el->el_search.chacha,
|
||||
el->el_state.argument, 0)
|
||||
: cv_csearch_back(el, el->el_search.chacha,
|
||||
el->el_state.argument, 0));
|
||||
}
|
||||
|
||||
|
||||
@ -991,12 +942,11 @@ vi_repeat_next_char(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_repeat_prev_char(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_repeat_prev_char(EditLine *el, int c)
|
||||
{
|
||||
|
||||
if (el->el_search.chacha == 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
return el->el_search.chadir == CHAR_BACK ?
|
||||
cv_csearch_fwd(el, el->el_search.chacha, el->el_state.argument, 0) :
|
||||
|
Loading…
Reference in New Issue
Block a user