Vendor import NetBSD's libedit of "2001/09/29 17:52:10 UTC".
Obtained from: NetBSD
This commit is contained in:
parent
4d860275f5
commit
f592be44eb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/vendor/NetBSD/libedit/dist/; revision=220176 svn path=/vendor/NetBSD/libedit/2001-09-29/; revision=220177; tag=vendor/NetBSD/libedit/2001-09-29
60
Makefile
60
Makefile
@ -1,4 +1,4 @@
|
||||
# $NetBSD: Makefile,v 1.8 1997/05/09 07:50:14 mycroft Exp $
|
||||
# $NetBSD: Makefile,v 1.20 2001/01/05 21:15:49 jdolecek Exp $
|
||||
# @(#)Makefile 8.1 (Berkeley) 6/4/93
|
||||
|
||||
LIB= edit
|
||||
@ -10,54 +10,78 @@ MAN= editline.3 editrc.5
|
||||
|
||||
MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.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_parse.3 editline.3 el_set.3 editline.3 el_get.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
|
||||
|
||||
# For speed and debugging
|
||||
#SRCS= ${OSRCS} tokenizer.c history.c
|
||||
#SRCS= ${OSRCS} tokenizer.c history.c readline.c
|
||||
# For protection
|
||||
SRCS= editline.c tokenizer.c history.c
|
||||
SRCS= editline.c tokenizer.c history.c readline.c
|
||||
|
||||
SRCS+= common.h emacs.h fcns.h help.h vi.h
|
||||
|
||||
LIBEDITDIR?=${.CURDIR}
|
||||
|
||||
INCS= histedit.h
|
||||
INCSDIR=/usr/include
|
||||
|
||||
CLEANFILES+=common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h
|
||||
CFLAGS+=-I. -I${.CURDIR}
|
||||
CFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
|
||||
CFLAGS+=#-DDEBUG_PASTE
|
||||
CLEANFILES+=common.h.tmp editline.c.tmp emacs.h.tmp fcns.c.tmp fcns.h.tmp
|
||||
CLEANFILES+=help.c.tmp help.h.tmp vi.h.tmp
|
||||
CPPFLAGS+=-I. -I${LIBEDITDIR}
|
||||
CPPFLAGS+=-I. -I${.CURDIR}
|
||||
CPPFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH
|
||||
CPPFLAGS+=#-DDEBUG_PASTE
|
||||
|
||||
AHDR=vi.h emacs.h common.h
|
||||
ASRC=${.CURDIR}/vi.c ${.CURDIR}/emacs.c ${.CURDIR}/common.c
|
||||
ASRC=${LIBEDITDIR}/vi.c ${LIBEDITDIR}/emacs.c ${LIBEDITDIR}/common.c
|
||||
|
||||
SUBDIR= readline
|
||||
|
||||
vi.h: vi.c makelist
|
||||
sh ${.CURDIR}/makelist -h ${.CURDIR}/vi.c > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/vi.c > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
emacs.h: emacs.c makelist
|
||||
sh ${.CURDIR}/makelist -h ${.CURDIR}/emacs.c > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/emacs.c > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
common.h: common.c makelist
|
||||
sh ${.CURDIR}/makelist -h ${.CURDIR}/common.c > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -h ${LIBEDITDIR}/common.c > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
fcns.h: ${AHDR} makelist
|
||||
sh ${.CURDIR}/makelist -fh ${AHDR} > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -fh ${AHDR} > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
fcns.c: ${AHDR} fcns.h makelist
|
||||
sh ${.CURDIR}/makelist -fc ${AHDR} > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -fc ${AHDR} > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
help.c: ${ASRC} makelist
|
||||
sh ${.CURDIR}/makelist -bc ${ASRC} > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -bc ${ASRC} > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
help.h: ${ASRC} makelist
|
||||
sh ${.CURDIR}/makelist -bh ${ASRC} > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -bh ${ASRC} > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
editline.c: ${OSRCS}
|
||||
sh ${.CURDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET}
|
||||
sh ${LIBEDITDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET}.tmp && \
|
||||
mv ${.TARGET}.tmp ${.TARGET}
|
||||
|
||||
test.o: ${LIBEDITDIR}/TEST/test.c
|
||||
|
||||
test: libedit.a test.o
|
||||
${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermcap
|
||||
${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD} -ltermcap
|
||||
|
||||
# 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
|
||||
readline.o readline.po readline.so readline.ln: \
|
||||
common.h emacs.h fcns.h help.h vi.h
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
.include <bsd.subdir.mk>
|
||||
|
104
TEST/test.c
104
TEST/test.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD */
|
||||
/* $NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,17 +36,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)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD";
|
||||
__RCSID("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -69,29 +69,30 @@ static char rcsid[] = "$NetBSD";
|
||||
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;
|
||||
@ -112,26 +113,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);
|
||||
@ -139,11 +139,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 */
|
||||
@ -155,7 +157,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
|
||||
@ -178,47 +181,62 @@ main(argc, argv)
|
||||
if (!continuation && num == 1)
|
||||
continue;
|
||||
|
||||
if (tok_line(tok, buf, &ac, &av) > 0) {
|
||||
history(hist, continuation ? H_ADD : H_ENTER, buf);
|
||||
continuation = 1;
|
||||
continue;
|
||||
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
|
||||
|
||||
history(hist, continuation ? H_ADD : H_ENTER, buf);
|
||||
|
||||
continuation = 0;
|
||||
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);
|
||||
@ -246,5 +264,5 @@ main(argc, argv)
|
||||
tok_end(tok);
|
||||
history_end(hist);
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
262
chared.c
262
chared.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: chared.c,v 1.2 1997/01/11 06:47:48 lukem Exp $ */
|
||||
/* $NetBSD: chared.c,v 1.14 2001/05/17 01:02:17 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: chared.c,v 1.2 1997/01/11 06:47:48 lukem Exp $";
|
||||
__RCSID("$NetBSD: chared.c,v 1.14 2001/05/17 01:02:17 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -52,14 +53,14 @@ static char rcsid[] = "$NetBSD: chared.c,v 1.2 1997/01/11 06:47:48 lukem Exp $";
|
||||
#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;
|
||||
@ -77,9 +78,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;
|
||||
|
||||
@ -92,16 +91,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)
|
||||
@ -111,7 +108,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];
|
||||
@ -125,9 +122,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)
|
||||
@ -137,9 +132,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;
|
||||
@ -151,10 +149,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(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL;
|
||||
return (isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -162,10 +159,9 @@ ce__isword(p)
|
||||
* Return if p is part of a word according to vi
|
||||
*/
|
||||
protected int
|
||||
cv__isword(p)
|
||||
int p;
|
||||
cv__isword(int p)
|
||||
{
|
||||
return !isspace(p);
|
||||
return (!isspace(p));
|
||||
}
|
||||
|
||||
|
||||
@ -173,10 +169,7 @@ cv__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--;
|
||||
|
||||
@ -192,7 +185,7 @@ c__prev_word(p, low, n, wtest)
|
||||
if (p < low)
|
||||
p = low;
|
||||
/* cp now points where we want it */
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
|
||||
|
||||
@ -200,10 +193,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))
|
||||
@ -214,18 +204,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;
|
||||
|
||||
@ -244,9 +230,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);
|
||||
}
|
||||
|
||||
|
||||
@ -254,11 +240,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;
|
||||
|
||||
@ -281,9 +263,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);
|
||||
}
|
||||
|
||||
|
||||
@ -294,22 +276,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;
|
||||
@ -317,7 +299,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
|
||||
|
||||
@ -325,10 +307,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)
|
||||
@ -346,12 +327,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);
|
||||
}
|
||||
@ -365,7 +344,7 @@ cv_delfini(el)
|
||||
case NOP:
|
||||
case INSERT:
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad oaction %d\n", oaction));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -380,9 +359,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++;
|
||||
|
||||
@ -394,7 +371,7 @@ ce__endword(p, high, n)
|
||||
}
|
||||
|
||||
p--;
|
||||
return p;
|
||||
return (p);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -403,9 +380,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++;
|
||||
|
||||
@ -422,23 +397,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;
|
||||
@ -450,6 +429,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;
|
||||
@ -466,15 +447,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;
|
||||
@ -503,13 +485,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;
|
||||
@ -528,21 +586,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);
|
||||
}
|
||||
|
||||
|
||||
@ -550,9 +608,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;
|
||||
@ -570,16 +626,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 0010: /* Delete and backspace */
|
||||
case 0177:
|
||||
@ -587,12 +641,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;
|
||||
@ -617,7 +670,7 @@ c_gets(el, buf)
|
||||
}
|
||||
}
|
||||
buf[len] = ch;
|
||||
return len;
|
||||
return (len);
|
||||
}
|
||||
|
||||
|
||||
@ -625,8 +678,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;
|
||||
|
||||
@ -634,12 +686,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);
|
||||
}
|
||||
}
|
||||
|
43
chared.h
43
chared.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: chared.h,v 1.2 1997/01/11 06:47:49 lukem Exp $ */
|
||||
/* $NetBSD: chared.h,v 1.6 2001/01/10 07:45:41 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -75,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;
|
||||
@ -136,25 +136,24 @@ 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 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 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 */
|
||||
|
418
common.c
418
common.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: common.c,v 1.3 1997/01/14 04:17:22 lukem Exp $ */
|
||||
/* $NetBSD: common.c,v 1.10 2001/01/10 07:45:41 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: common.c,v 1.3 1997/01/14 04:17:22 lukem Exp $";
|
||||
__RCSID("$NetBSD: common.c,v 1.10 2001/01/10 07:45:41 jdolecek Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -56,13 +57,12 @@ static char rcsid[] = "$NetBSD: common.c,v 1.3 1997/01/14 04:17:22 lukem Exp $";
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -71,44 +71,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--)
|
||||
@ -119,7 +118,7 @@ ed_insert(el, c)
|
||||
if (el->el_state.inputmode == MODE_REPLACE_1)
|
||||
(void) vi_command_mode(el, 0);
|
||||
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -129,14 +128,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);
|
||||
@ -149,7 +146,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);
|
||||
}
|
||||
|
||||
|
||||
@ -159,46 +156,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);
|
||||
}
|
||||
|
||||
|
||||
@ -208,9 +207,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;
|
||||
|
||||
@ -219,8 +216,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);
|
||||
}
|
||||
|
||||
|
||||
@ -230,10 +228,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
|
||||
@ -241,10 +238,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);
|
||||
}
|
||||
|
||||
|
||||
@ -254,23 +251,21 @@ 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) {
|
||||
/* We want FIRST non space character */
|
||||
while (isspace(*el->el_line.cursor))
|
||||
while (isspace((unsigned char) *el->el_line.cursor))
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -279,13 +274,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++;
|
||||
}
|
||||
@ -294,10 +288,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);
|
||||
}
|
||||
|
||||
|
||||
@ -307,12 +300,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)
|
||||
@ -321,10 +313,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);
|
||||
}
|
||||
|
||||
|
||||
@ -334,24 +325,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);
|
||||
}
|
||||
|
||||
|
||||
@ -361,10 +351,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)
|
||||
@ -373,13 +362,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);
|
||||
}
|
||||
|
||||
|
||||
@ -388,9 +375,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;
|
||||
@ -400,9 +385,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));
|
||||
}
|
||||
|
||||
|
||||
@ -410,12 +395,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(c))
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
if (el->el_state.doingarg) {
|
||||
/* if doing an arg, add this in... */
|
||||
@ -423,20 +407,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);
|
||||
@ -444,7 +430,7 @@ ed_digit(el, c)
|
||||
el->el_state.doingarg = 0;
|
||||
re_fastaddc(el);
|
||||
}
|
||||
return CC_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -453,23 +439,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(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);
|
||||
}
|
||||
|
||||
|
||||
@ -479,13 +464,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);
|
||||
}
|
||||
|
||||
|
||||
@ -499,11 +483,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);
|
||||
}
|
||||
|
||||
|
||||
@ -513,11 +496,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);
|
||||
}
|
||||
|
||||
|
||||
@ -527,11 +509,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);
|
||||
}
|
||||
|
||||
|
||||
@ -541,11 +522,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);
|
||||
}
|
||||
|
||||
|
||||
@ -555,11 +535,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);
|
||||
}
|
||||
|
||||
|
||||
@ -569,11 +548,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);
|
||||
}
|
||||
|
||||
|
||||
@ -583,11 +561,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);
|
||||
}
|
||||
|
||||
|
||||
@ -597,16 +574,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);
|
||||
}
|
||||
|
||||
|
||||
@ -616,18 +592,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);
|
||||
}
|
||||
|
||||
|
||||
@ -637,13 +612,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);
|
||||
}
|
||||
|
||||
|
||||
@ -653,11 +627,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);
|
||||
}
|
||||
|
||||
|
||||
@ -667,12 +640,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);
|
||||
}
|
||||
|
||||
|
||||
@ -682,11 +654,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);
|
||||
}
|
||||
|
||||
|
||||
@ -696,21 +667,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) {
|
||||
@ -718,12 +688,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 */
|
||||
}
|
||||
|
||||
|
||||
@ -733,10 +702,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 */
|
||||
|
||||
@ -744,10 +712,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));
|
||||
}
|
||||
|
||||
|
||||
@ -757,9 +724,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;
|
||||
@ -770,25 +735,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 !! */
|
||||
|
||||
@ -799,8 +763,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++;
|
||||
@ -814,12 +778,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));
|
||||
}
|
||||
|
||||
|
||||
@ -829,9 +792,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;
|
||||
@ -842,14 +803,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 !! */
|
||||
|
||||
@ -857,8 +818,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;
|
||||
@ -870,13 +831,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));
|
||||
}
|
||||
|
||||
|
||||
@ -886,9 +846,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);
|
||||
@ -904,7 +862,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
|
||||
@ -921,7 +879,7 @@ ed_prev_line(el, c)
|
||||
continue;
|
||||
|
||||
el->el_line.cursor = ptr;
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -931,9 +889,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);
|
||||
@ -946,7 +902,7 @@ ed_next_line(el, c)
|
||||
break;
|
||||
|
||||
if (el->el_state.argument > 0)
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
|
||||
/*
|
||||
* Move to the character requested
|
||||
@ -957,7 +913,7 @@ ed_next_line(el, c)
|
||||
continue;
|
||||
|
||||
el->el_line.cursor = ptr;
|
||||
return CC_CURSOR;
|
||||
return (CC_CURSOR);
|
||||
}
|
||||
|
||||
|
||||
@ -967,9 +923,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;
|
||||
@ -992,7 +946,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);
|
||||
}
|
||||
|
177
editline.3
177
editline.3
@ -1,6 +1,6 @@
|
||||
.\" $NetBSD: editline.3,v 1.4 1997/01/14 04:17:23 lukem Exp $
|
||||
.\" $NetBSD: editline.3,v 1.22 2001/09/27 19:29:50 christos Exp $
|
||||
.\"
|
||||
.\" 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 +24,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,8 +33,8 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 11, 1997
|
||||
.Os BSD 4.4
|
||||
.Dd November 12, 1999
|
||||
.Os
|
||||
.Dt EDITLINE 3
|
||||
.Sh NAME
|
||||
.Nm editline ,
|
||||
@ -55,10 +55,12 @@
|
||||
.Nm history_end ,
|
||||
.Nm history
|
||||
.Nd line editor and history functions
|
||||
.Sh LIBRARY
|
||||
.Lb libedit
|
||||
.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
|
||||
@ -74,21 +76,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 History *
|
||||
.Fn history_init
|
||||
.Ft void
|
||||
.Fn history_end "History *h"
|
||||
.Ft HistEvent *
|
||||
.Fn history "History h" "int op" "..."
|
||||
.Ft int
|
||||
.Fn history "History *h" "HistEvent *ev" "int op" "..."
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
@ -120,10 +124,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.
|
||||
@ -187,19 +192,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
|
||||
.Po
|
||||
.Dq \e0
|
||||
.Pc .
|
||||
.It Fn el_set
|
||||
Set
|
||||
.Nm
|
||||
@ -216,6 +208,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 ,
|
||||
@ -336,6 +332,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.
|
||||
@ -357,6 +355,64 @@ 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.
|
||||
.It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
|
||||
Define the character reading function as
|
||||
.Fa f ,
|
||||
which is to return the number of characters read and store them in
|
||||
.Fa c .
|
||||
This function is called internally by
|
||||
.Fn el_gets
|
||||
and
|
||||
.Fn el_getc .
|
||||
The builtin function can be set or restored with the special function
|
||||
name ``EL_BUILTIN_GETCFN''.
|
||||
.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.
|
||||
.It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)"
|
||||
Return a pointer to the function that read characters, which is equal to
|
||||
``EL_BUILTIN_GETCFN'' in the case of the default builtin function.
|
||||
.El
|
||||
.It Fn el_source
|
||||
Initialise
|
||||
@ -434,14 +490,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 ,
|
||||
@ -456,6 +516,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"
|
||||
@ -473,12 +534,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
|
||||
@ -503,6 +568,13 @@ 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
|
||||
@ -516,17 +588,46 @@ 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
|
||||
The
|
||||
.Nm
|
||||
library was written by Christos Zoulas,
|
||||
and this manual was written by 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.
|
||||
.Pp
|
||||
.Fn el_parse
|
||||
should not modify the supplied
|
||||
.Va argv[0] .
|
||||
.Pp
|
||||
The tokenization functions are not publically defined in
|
||||
.Fd <histedit.h>
|
||||
.Fd <histedit.h>.
|
||||
.Pp
|
||||
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.
|
||||
|
221
editrc.5
221
editrc.5
@ -1,6 +1,6 @@
|
||||
.\" $NetBSD: editrc.5,v 1.4 1997/04/24 20:20:31 christos Exp $
|
||||
.\" $NetBSD: editrc.5,v 1.11 2001/06/19 13:42:09 wiz Exp $
|
||||
.\"
|
||||
.\" 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 +24,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,8 +33,8 @@
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd January 11, 1997
|
||||
.Os BSD 4.4
|
||||
.Dd November 8, 2000
|
||||
.Os
|
||||
.Dt EDITRC 5
|
||||
.Sh NAME
|
||||
.Nm editrc
|
||||
@ -48,10 +48,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
|
||||
@ -79,6 +77,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
|
||||
@ -147,6 +151,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
|
||||
@ -213,10 +222,14 @@ or
|
||||
indicating that the terminal does or does not have that capability.
|
||||
.Pp
|
||||
.Fl s
|
||||
returns an emptry string for non-existant 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
|
||||
@ -279,6 +292,192 @@ 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 ,
|
||||
|
292
el.c
292
el.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: el.c,v 1.6 1997/04/24 18:54:16 christos Exp $ */
|
||||
/* $NetBSD: el.c,v 1.23 2001/09/27 19:29:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: el.c,v 1.6 1997/04/24 18:54:16 christos Exp $";
|
||||
__RCSID("$NetBSD: el.c,v 1.23 2001/09/27 19:29:50 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -53,83 +54,68 @@ static char rcsid[] = "$NetBSD: el.c,v 1.6 1997/04/24 18:54:16 christos Exp $";
|
||||
#include <sys/param.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef __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 ((tty = getenv("DEBUGTTY")) != NULL) {
|
||||
el->el_errfile = fopen(tty, "w");
|
||||
if (el->el_errfile == NULL) {
|
||||
extern errno;
|
||||
(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;
|
||||
(void) read_init(el);
|
||||
|
||||
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);
|
||||
@ -138,16 +124,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? */
|
||||
}
|
||||
@ -157,29 +143,19 @@ el_reset(el)
|
||||
* set the editline parameters
|
||||
*/
|
||||
public int
|
||||
#ifdef __STDC__
|
||||
el_set(EditLine *el, int op, ...)
|
||||
#else
|
||||
el_set(va_alist)
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list va;
|
||||
int rv;
|
||||
#ifdef __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);
|
||||
va_start(va, op);
|
||||
|
||||
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:
|
||||
@ -206,6 +182,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;
|
||||
@ -238,20 +215,146 @@ 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;
|
||||
|
||||
case EL_GETCFN:
|
||||
{
|
||||
el_rfunc_t rc = va_arg(va, el_rfunc_t);
|
||||
rv = el_read_setfn(el, rc);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
va_end(va);
|
||||
return (rv);
|
||||
}
|
||||
|
||||
|
||||
/* el_get():
|
||||
* retrieve the editline parameters
|
||||
*/
|
||||
public int
|
||||
el_get(EditLine *el, int op, void *ret)
|
||||
{
|
||||
int rv;
|
||||
|
||||
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;
|
||||
|
||||
case EL_EDITOR:
|
||||
rv = map_get_editor(el, (const char **) &ret);
|
||||
break;
|
||||
|
||||
case EL_SIGNAL:
|
||||
*((int *) ret) = (el->el_flags & HANDLE_SIGNALS);
|
||||
rv = 0;
|
||||
break;
|
||||
|
||||
case EL_EDITMODE:
|
||||
*((int *) ret) = (!(el->el_flags & EDIT_DISABLED));
|
||||
rv = 0;
|
||||
break;
|
||||
|
||||
#if 0 /* XXX */
|
||||
case EL_TERMINAL:
|
||||
rv = term_get(el, (const char *) &ret);
|
||||
break;
|
||||
|
||||
case EL_BIND:
|
||||
case EL_TELLTC:
|
||||
case EL_SETTC:
|
||||
case EL_ECHOTC:
|
||||
case EL_SETTY:
|
||||
{
|
||||
char *argv[20];
|
||||
int i;
|
||||
|
||||
for (i = 1; i < 20; i++)
|
||||
if ((argv[i] = va_arg(va, char *)) == NULL)
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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:
|
||||
{
|
||||
@ -260,24 +363,29 @@ el_set(va_alist)
|
||||
rv = hist_set(el, func, ptr);
|
||||
}
|
||||
break;
|
||||
#endif /* XXX */
|
||||
|
||||
case EL_GETCFN:
|
||||
*((el_rfunc_t *)ret) = el_read_getfn(el);
|
||||
rv = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
va_end(va);
|
||||
return rv;
|
||||
} /* end el_set */
|
||||
return (rv);
|
||||
}
|
||||
|
||||
|
||||
/* el_line():
|
||||
* Return editing info
|
||||
*/
|
||||
public const LineInfo *
|
||||
el_line(el)
|
||||
EditLine *el;
|
||||
el_line(EditLine *el)
|
||||
{
|
||||
return (const LineInfo *) &el->el_line;
|
||||
|
||||
return (const LineInfo *) (void *) &el->el_line;
|
||||
}
|
||||
|
||||
static const char elpath[] = "/.editrc";
|
||||
@ -286,39 +394,41 @@ static const char elpath[] = "/.editrc";
|
||||
* Source a file
|
||||
*/
|
||||
public int
|
||||
el_source(el, fname)
|
||||
EditLine *el;
|
||||
const char *fname;
|
||||
el_source(EditLine *el, const char *fname)
|
||||
{
|
||||
FILE *fp;
|
||||
size_t len;
|
||||
char *ptr, path[MAXPATHLEN];
|
||||
|
||||
fp = NULL;
|
||||
if (fname == NULL) {
|
||||
fname = &elpath[1];
|
||||
if ((fp = fopen(fname, "r")) == NULL) {
|
||||
if (issetugid())
|
||||
return (-1);
|
||||
if ((ptr = getenv("HOME")) == NULL)
|
||||
return -1;
|
||||
(void)snprintf(path, sizeof(path), "%s%s", ptr, elpath);
|
||||
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 = fopen(fname, "r")) == NULL)
|
||||
return -1;
|
||||
if (fp == NULL)
|
||||
fp = fopen(fname, "r");
|
||||
if (fp == NULL)
|
||||
return (-1);
|
||||
|
||||
while ((ptr = fgetln(fp, &len)) != NULL) {
|
||||
if (ptr[len - 1] == '\n')
|
||||
if (len > 0 && ptr[len - 1] == '\n')
|
||||
--len;
|
||||
ptr[len] = '\0';
|
||||
if (parse_line(el, ptr) == -1) {
|
||||
(void) fclose(fp);
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
|
||||
(void) fclose(fp);
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -326,11 +436,11 @@ el_source(el, fname)
|
||||
* Called from program when terminal is resized
|
||||
*/
|
||||
public void
|
||||
el_resize(el)
|
||||
EditLine *el;
|
||||
el_resize(EditLine *el)
|
||||
{
|
||||
int lins, cols;
|
||||
sigset_t oset, nset;
|
||||
|
||||
(void) sigemptyset(&nset);
|
||||
(void) sigaddset(&nset, SIGWINCH);
|
||||
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
||||
@ -341,3 +451,39 @@ el_resize(el)
|
||||
|
||||
(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);
|
||||
}
|
||||
|
33
el.h
33
el.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: el.h,v 1.2 1997/01/11 06:47:53 lukem Exp $ */
|
||||
/* $NetBSD: el.h,v 1.9 2001/09/27 19:29:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -55,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;
|
||||
|
||||
/*
|
||||
@ -103,6 +106,7 @@ typedef struct el_state_t {
|
||||
#include "parse.h"
|
||||
#include "sig.h"
|
||||
#include "help.h"
|
||||
#include "read.h"
|
||||
|
||||
struct editline {
|
||||
char *el_prog; /* the program name */
|
||||
@ -111,21 +115,30 @@ 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 */
|
||||
el_history_t el_history; /* History stuff */
|
||||
el_search_t el_search; /* Search stuff */
|
||||
el_signal_t el_signal; /* Signal handling stuff */
|
||||
el_read_t el_read; /* Character reading stuff */
|
||||
};
|
||||
|
||||
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 */
|
||||
|
213
emacs.c
213
emacs.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: emacs.c,v 1.3 1997/01/11 06:47:54 lukem Exp $ */
|
||||
/* $NetBSD: emacs.c,v 1.9 2001/01/10 07:45:41 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: emacs.c,v 1.3 1997/01/11 06:47:54 lukem Exp $";
|
||||
__RCSID("$NetBSD: emacs.c,v 1.9 2001/01/10 07:45:41 jdolecek Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -56,27 +57,30 @@ static char rcsid[] = "$NetBSD: emacs.c,v 1.3 1997/01/11 06:47:54 lukem Exp $";
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,14 +91,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);
|
||||
@ -106,8 +108,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);
|
||||
}
|
||||
|
||||
|
||||
@ -117,19 +120,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;
|
||||
@ -144,7 +147,7 @@ em_yank(el, c)
|
||||
if (el->el_state.argument == 1)
|
||||
el->el_line.cursor = cp;
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -154,9 +157,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;
|
||||
|
||||
@ -165,9 +166,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);
|
||||
}
|
||||
|
||||
|
||||
@ -177,14 +179,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;
|
||||
@ -193,8 +193,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)
|
||||
@ -203,7 +202,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);
|
||||
}
|
||||
|
||||
|
||||
@ -213,14 +212,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;
|
||||
@ -228,15 +225,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);
|
||||
}
|
||||
|
||||
|
||||
@ -245,9 +241,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]) {
|
||||
@ -255,10 +249,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);
|
||||
}
|
||||
|
||||
|
||||
@ -268,25 +261,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
|
||||
@ -294,9 +286,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;
|
||||
|
||||
@ -304,13 +294,13 @@ em_upper_case(el, c)
|
||||
el->el_state.argument, ce__isword);
|
||||
|
||||
for (cp = el->el_line.cursor; cp < ep; cp++)
|
||||
if (islower(*cp))
|
||||
if (islower((unsigned char) *cp))
|
||||
*cp = toupper(*cp);
|
||||
|
||||
el->el_line.cursor = ep;
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -320,9 +310,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;
|
||||
|
||||
@ -330,32 +318,31 @@ em_capitol_case(el, c)
|
||||
el->el_state.argument, ce__isword);
|
||||
|
||||
for (cp = el->el_line.cursor; cp < ep; cp++) {
|
||||
if (isalpha(*cp)) {
|
||||
if (islower(*cp))
|
||||
if (isalpha((unsigned char) *cp)) {
|
||||
if (islower((unsigned char) *cp))
|
||||
*cp = toupper(*cp);
|
||||
cp++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; cp < ep; cp++)
|
||||
if (isupper(*cp))
|
||||
if (isupper((unsigned char) *cp))
|
||||
*cp = tolower(*cp);
|
||||
|
||||
el->el_line.cursor = ep;
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
@ -363,13 +350,13 @@ em_lower_case(el, c)
|
||||
el->el_state.argument, ce__isword);
|
||||
|
||||
for (cp = el->el_line.cursor; cp < ep; cp++)
|
||||
if (isupper(*cp))
|
||||
if (isupper((unsigned char) *cp))
|
||||
*cp = tolower(*cp);
|
||||
|
||||
el->el_line.cursor = ep;
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
el->el_line.cursor = el->el_line.lastchar;
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -379,12 +366,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);
|
||||
}
|
||||
|
||||
|
||||
@ -394,47 +380,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);
|
||||
}
|
||||
|
||||
|
||||
@ -443,13 +427,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);
|
||||
}
|
||||
|
||||
|
||||
@ -458,14 +441,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 */
|
||||
@ -478,7 +459,7 @@ em_copy_prev_word(el, c)
|
||||
|
||||
el->el_line.cursor = dp;/* put cursor at end */
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -487,12 +468,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));
|
||||
}
|
||||
|
||||
|
||||
@ -501,10 +481,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));
|
||||
}
|
||||
|
86
hist.c
86
hist.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: hist.c,v 1.2 1997/01/11 06:47:55 lukem Exp $ */
|
||||
/* $NetBSD: hist.c,v 1.9 2001/05/17 01:02:17 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: hist.c,v 1.2 1997/01/11 06:47:55 lukem Exp $";
|
||||
__RCSID("$NetBSD: hist.c,v 1.9 2001/05/17 01:02:17 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -55,14 +56,17 @@ static char rcsid[] = "$NetBSD: hist.c,v 1.2 1997/01/11 06:47:55 lukem Exp $";
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
@ -70,9 +74,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;
|
||||
}
|
||||
@ -82,15 +86,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);
|
||||
}
|
||||
|
||||
|
||||
@ -99,14 +100,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);
|
||||
|
||||
@ -117,24 +118,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) {
|
||||
@ -145,7 +145,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;
|
||||
@ -153,24 +152,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;
|
||||
}
|
||||
|
23
hist.h
23
hist.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: hist.h,v 1.3 1997/01/11 06:47:56 lukem Exp $ */
|
||||
/* $NetBSD: hist.h,v 1.6 2001/01/10 07:45:41 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -46,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)
|
||||
@ -70,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 */
|
||||
|
89
histedit.h
89
histedit.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: histedit.h,v 1.5 1997/04/11 17:52:45 christos Exp $ */
|
||||
/* $NetBSD: histedit.h,v 1.17 2001/09/27 19:29:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -41,8 +41,8 @@
|
||||
/*
|
||||
* histedit.h: Line editor and history interface.
|
||||
*/
|
||||
#ifndef _h_editline
|
||||
#define _h_editline
|
||||
#ifndef _HISTEDIT_H_
|
||||
#define _HISTEDIT_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
@ -75,32 +75,39 @@ typedef struct lineinfo {
|
||||
#define CC_ERROR 6
|
||||
#define CC_FATAL 7
|
||||
#define CC_REDISPLAY 8
|
||||
#define CC_REFRESH_BEEP 9
|
||||
|
||||
/*
|
||||
* Initialization, cleanup, and resetting
|
||||
*/
|
||||
EditLine *el_init __P((const char *, FILE *, FILE *));
|
||||
void el_reset __P((EditLine *));
|
||||
void el_end __P((EditLine *));
|
||||
EditLine *el_init(const char *, FILE *, FILE *, FILE *);
|
||||
void el_reset(EditLine *);
|
||||
void el_end(EditLine *);
|
||||
|
||||
|
||||
/*
|
||||
* Get a line, a character or push a string back in the input queue
|
||||
*/
|
||||
const char *el_gets __P((EditLine *, int *));
|
||||
int el_getc __P((EditLine *, char *));
|
||||
void el_push __P((EditLine *, const char *));
|
||||
const char *el_gets(EditLine *, int *);
|
||||
int el_getc(EditLine *, char *);
|
||||
void el_push(EditLine *, const char *);
|
||||
|
||||
/*
|
||||
* Beep!
|
||||
*/
|
||||
void el_beep(EditLine *);
|
||||
|
||||
/*
|
||||
* High level function internals control
|
||||
* Parses argc, argv array and executes builtin editline commands
|
||||
*/
|
||||
int el_parse __P((EditLine *, int, char **));
|
||||
int el_parse(EditLine *, int, char **);
|
||||
|
||||
/*
|
||||
* Low level editline access function
|
||||
* Low level editline access functions
|
||||
*/
|
||||
int el_set __P((EditLine *, int, ...));
|
||||
int el_set(EditLine *, int, ...);
|
||||
int el_get(EditLine *, int, void *);
|
||||
|
||||
/*
|
||||
* el_set/el_get parameters
|
||||
@ -117,26 +124,31 @@ int el_set __P((EditLine *, int, ...));
|
||||
#define EL_ADDFN 9 /* , const char *, const char * */
|
||||
/* , el_func_t); */
|
||||
#define EL_HIST 10 /* , hist_fun_t, const char *); */
|
||||
#define EL_EDITMODE 11 /* , int); */
|
||||
#define EL_RPROMPT 12 /* , el_pfunc_t); */
|
||||
#define EL_GETCFN 13 /* , el_rfunc_t); */
|
||||
|
||||
#define EL_BUILTIN_GETCFN (NULL)
|
||||
|
||||
/*
|
||||
* Source named file or $PWD/.editrc or $HOME/.editrc
|
||||
*/
|
||||
int el_source __P((EditLine *, const char *));
|
||||
int el_source(EditLine *, const char *);
|
||||
|
||||
/*
|
||||
* Must be called when the terminal changes size; If EL_SIGNAL
|
||||
* is set this is done automatically otherwise it is the responsibility
|
||||
* of the application
|
||||
*/
|
||||
void el_resize __P((EditLine *));
|
||||
void el_resize(EditLine *);
|
||||
|
||||
|
||||
/*
|
||||
* User-defined function interface.
|
||||
*/
|
||||
const LineInfo *el_line __P((EditLine *));
|
||||
int el_insertstr __P((EditLine *, char *));
|
||||
void el_deletestr __P((EditLine *, int));
|
||||
const LineInfo *el_line(EditLine *);
|
||||
int el_insertstr(EditLine *, const char *);
|
||||
void el_deletestr(EditLine *, int);
|
||||
|
||||
/*
|
||||
* ==== History ====
|
||||
@ -152,27 +164,30 @@ typedef struct HistEvent {
|
||||
/*
|
||||
* History access functions.
|
||||
*/
|
||||
History * history_init __P((void));
|
||||
void history_end __P((History *));
|
||||
History * history_init(void);
|
||||
void history_end(History *);
|
||||
|
||||
const HistEvent * history __P((History *, int, ...));
|
||||
int history(History *, HistEvent *, int, ...);
|
||||
|
||||
#define H_FUNC 0 /* , UTSL */
|
||||
#define H_EVENT 1 /* , const int); */
|
||||
#define H_FIRST 2 /* , void); */
|
||||
#define H_LAST 3 /* , void); */
|
||||
#define H_PREV 4 /* , void); */
|
||||
#define H_NEXT 5 /* , void); */
|
||||
#define H_CURR 6 /* , void); */
|
||||
#define H_ADD 7 /* , const char*); */
|
||||
#define H_ENTER 8 /* , const char*); */
|
||||
#define H_END 9 /* , void); */
|
||||
#define H_NEXT_STR 10 /* , const char*); */
|
||||
#define H_PREV_STR 11 /* , const char*); */
|
||||
#define H_NEXT_EVENT 12 /* , const int); */
|
||||
#define H_PREV_EVENT 13 /* , const int); */
|
||||
#define H_LOAD 14 /* , const char *); */
|
||||
#define H_SAVE 15 /* , const char *); */
|
||||
#define H_CLEAR 16 /* , void); */
|
||||
#define H_SETSIZE 1 /* , const int); */
|
||||
#define H_GETSIZE 2 /* , void); */
|
||||
#define H_FIRST 3 /* , void); */
|
||||
#define H_LAST 4 /* , void); */
|
||||
#define H_PREV 5 /* , void); */
|
||||
#define H_NEXT 6 /* , void); */
|
||||
#define H_CURR 8 /* , const int); */
|
||||
#define H_SET 7 /* , void); */
|
||||
#define H_ADD 9 /* , const char *); */
|
||||
#define H_ENTER 10 /* , const char *); */
|
||||
#define H_APPEND 11 /* , const char *); */
|
||||
#define H_END 12 /* , void); */
|
||||
#define H_NEXT_STR 13 /* , const char *); */
|
||||
#define H_PREV_STR 14 /* , const char *); */
|
||||
#define H_NEXT_EVENT 15 /* , const int); */
|
||||
#define H_PREV_EVENT 16 /* , const int); */
|
||||
#define H_LOAD 17 /* , const char *); */
|
||||
#define H_SAVE 18 /* , const char *); */
|
||||
#define H_CLEAR 19 /* , void); */
|
||||
|
||||
#endif /* _h_editline */
|
||||
#endif /* _HISTEDIT_H_ */
|
||||
|
326
key.c
326
key.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: key.c,v 1.2 1997/01/11 06:47:58 lukem Exp $ */
|
||||
/* $NetBSD: key.c,v 1.12 2001/05/17 01:02:17 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)key.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: key.c,v 1.2 1997/01/11 06:47:58 lukem Exp $";
|
||||
__RCSID("$NetBSD: key.c,v 1.12 2001/05/17 01:02:17 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -84,17 +85,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
|
||||
|
||||
@ -103,13 +103,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);
|
||||
}
|
||||
|
||||
|
||||
@ -117,9 +119,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 */
|
||||
@ -131,12 +133,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);
|
||||
}
|
||||
|
||||
|
||||
@ -144,12 +145,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);
|
||||
}
|
||||
|
||||
|
||||
@ -159,10 +159,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;
|
||||
}
|
||||
@ -177,14 +177,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():
|
||||
@ -194,30 +191,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;
|
||||
}
|
||||
|
||||
@ -226,11 +219,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) ||
|
||||
@ -245,21 +236,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);
|
||||
}
|
||||
|
||||
|
||||
@ -268,10 +257,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;
|
||||
@ -279,7 +267,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;
|
||||
}
|
||||
|
||||
@ -289,39 +278,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -331,12 +315,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;
|
||||
|
||||
@ -347,11 +328,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) {
|
||||
@ -364,7 +345,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;
|
||||
}
|
||||
|
||||
@ -377,17 +359,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);
|
||||
}
|
||||
|
||||
|
||||
@ -395,9 +376,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;
|
||||
@ -411,11 +390,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)
|
||||
@ -423,41 +401,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:
|
||||
@ -469,7 +445,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);
|
||||
@ -480,18 +456,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);
|
||||
}
|
||||
|
||||
|
||||
@ -501,23 +478,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 */
|
||||
@ -525,25 +497,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -553,10 +527,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;
|
||||
|
||||
@ -566,16 +537,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) {
|
||||
@ -583,14 +553,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);
|
||||
}
|
||||
|
||||
|
||||
@ -599,42 +568,40 @@ 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];
|
||||
static char *fmt = "%-15s-> %s\n";
|
||||
static const char fmt[] = "%-15s-> %s\n";
|
||||
|
||||
if (val != NULL)
|
||||
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");
|
||||
}
|
||||
|
||||
|
||||
@ -642,51 +609,42 @@ 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)
|
||||
{
|
||||
if (ch == 0) {
|
||||
buf[cnt++] = '^';
|
||||
buf[cnt] = '@';
|
||||
return cnt;
|
||||
return (cnt);
|
||||
}
|
||||
|
||||
if (iscntrl(ch)) {
|
||||
buf[cnt++] = '^';
|
||||
if (ch == '\177')
|
||||
buf[cnt] = '?';
|
||||
else
|
||||
buf[cnt] = 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;
|
||||
|
||||
@ -699,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++ = '^';
|
||||
@ -709,24 +666,21 @@ key__decode_str(str, buf, sep)
|
||||
*b++ = '?';
|
||||
else
|
||||
*b++ = *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 */
|
||||
}
|
||||
|
30
key.h
30
key.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: key.h,v 1.2 1997/01/11 06:47:59 lukem Exp $ */
|
||||
/* $NetBSD: key.h,v 1.5 2001/01/23 15:55:30 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -62,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 */
|
||||
|
103
makelist
103
makelist
@ -1,5 +1,5 @@
|
||||
#!/bin/sh -
|
||||
# $NetBSD: makelist,v 1.3 1997/01/11 06:48:00 lukem Exp $
|
||||
# $NetBSD: makelist,v 1.7 2001/01/09 19:22:31 jdolecek Exp $
|
||||
#
|
||||
# Copyright (c) 1992, 1993
|
||||
# The Regents of the University of California. All rights reserved.
|
||||
@ -40,7 +40,7 @@
|
||||
# makelist.sh: Automatically generate header files...
|
||||
|
||||
AWK=/usr/bin/awk
|
||||
USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>"
|
||||
USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
|
||||
|
||||
if [ "x$1" = "x" ]
|
||||
then
|
||||
@ -54,6 +54,9 @@ shift
|
||||
FILES="$@"
|
||||
|
||||
case $FLAG in
|
||||
|
||||
# generate foo.h file from foo.c
|
||||
#
|
||||
-h)
|
||||
set - `echo $FILES | sed -e 's/\\./_/g'`
|
||||
hdr="_h_`basename $1`"
|
||||
@ -66,18 +69,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++)
|
||||
@ -113,17 +124,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 '
|
||||
@ -138,16 +157,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;
|
||||
@ -167,8 +190,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 {
|
||||
@ -178,8 +205,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
|
||||
|
264
map.c
264
map.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: map.c,v 1.3 1997/01/11 06:48:00 lukem Exp $ */
|
||||
/* $NetBSD: map.c,v 1.14 2001/01/09 17:22:09 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)map.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: map.c,v 1.3 1997/01/11 06:48:00 lukem Exp $";
|
||||
__RCSID("$NetBSD: map.c,v 1.14 2001/01/09 17:22:09 jdolecek Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -53,15 +54,16 @@ static char rcsid[] = "$NetBSD: map.c,v 1.3 1997/01/11 06:48:00 lukem Exp $";
|
||||
|
||||
#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 */
|
||||
@ -321,13 +323,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 */
|
||||
@ -352,7 +355,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 */
|
||||
@ -362,13 +366,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 */
|
||||
@ -621,7 +631,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 */
|
||||
@ -885,8 +895,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)
|
||||
{
|
||||
|
||||
/*
|
||||
@ -894,23 +903,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;
|
||||
|
||||
@ -919,7 +937,7 @@ map_init(el)
|
||||
#else
|
||||
map_init_emacs(el);
|
||||
#endif /* VIDEFAULT */
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -927,9 +945,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);
|
||||
@ -948,10 +966,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++)
|
||||
@ -964,11 +982,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;
|
||||
|
||||
@ -982,8 +999,7 @@ map_init_meta(el)
|
||||
i = 033;
|
||||
if (el->el_map.type == MAP_VI)
|
||||
map = alt;
|
||||
}
|
||||
else
|
||||
} else
|
||||
map = alt;
|
||||
}
|
||||
buf[0] = (char) i;
|
||||
@ -999,7 +1015,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;
|
||||
}
|
||||
|
||||
|
||||
@ -1007,14 +1023,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;
|
||||
@ -1027,10 +1042,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);
|
||||
@ -1041,14 +1053,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;
|
||||
@ -1060,10 +1071,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');
|
||||
@ -1080,19 +1087,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);
|
||||
}
|
||||
|
||||
|
||||
@ -1100,10 +1127,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;
|
||||
@ -1116,8 +1140,7 @@ map_print_key(el, map, in)
|
||||
"%s\t->\t%s\n", outbuf, bp->name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
} else
|
||||
key_print(el, in);
|
||||
}
|
||||
|
||||
@ -1126,10 +1149,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];
|
||||
@ -1141,20 +1161,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);
|
||||
@ -1164,19 +1184,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"));
|
||||
}
|
||||
|
||||
|
||||
@ -1184,8 +1205,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;
|
||||
|
||||
@ -1220,13 +1240,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];
|
||||
@ -1237,11 +1254,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]) {
|
||||
@ -1262,24 +1279,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
|
||||
@ -1287,22 +1307,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);
|
||||
@ -1310,21 +1328,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
|
||||
|
||||
@ -1334,7 +1350,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);
|
||||
@ -1347,7 +1363,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);
|
||||
@ -1355,8 +1371,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;
|
||||
}
|
||||
@ -1364,10 +1379,10 @@ map_bind(el, argc, argv)
|
||||
break;
|
||||
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type\n", ntype));
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
@ -1375,20 +1390,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_realloc(el->el_map.func, nf * sizeof(el_func_t));
|
||||
el->el_map.help = (el_bindings_t *)
|
||||
el_realloc(el->el_map.help, nf * sizeof(el_bindings_t));
|
||||
if (name == NULL || help == NULL || func == NULL)
|
||||
return (-1);
|
||||
|
||||
if ((p = el_realloc(el->el_map.func, nf * sizeof(el_func_t))) == NULL)
|
||||
return (-1);
|
||||
el->el_map.func = (el_func_t *) p;
|
||||
if ((p = el_realloc(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;
|
||||
@ -1399,5 +1415,5 @@ map_addfunc(el, name, help, func)
|
||||
el->el_map.help[++nf].name = NULL;
|
||||
el->el_map.nfunc++;
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
24
map.h
24
map.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: map.h,v 1.2 1997/01/11 06:48:01 lukem Exp $ */
|
||||
/* $NetBSD: map.h,v 1.6 2001/01/09 17:22:09 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -55,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 */
|
||||
@ -67,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 */
|
||||
|
89
parse.c
89
parse.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: parse.c,v 1.5 1997/01/11 09:57:08 lukem Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.14 2001/01/23 15:55:30 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: parse.c,v 1.5 1997/01/11 09:57:08 lukem Exp $";
|
||||
__RCSID("$NetBSD: parse.c,v 1.14 2001/01/23 15:55:30 jdolecek Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -51,6 +52,7 @@ static char rcsid[] = "$NetBSD: parse.c,v 1.5 1997/01/11 09:57:08 lukem Exp $";
|
||||
*
|
||||
* bind
|
||||
* echotc
|
||||
* edit
|
||||
* gettc
|
||||
* history
|
||||
* settc
|
||||
@ -59,13 +61,15 @@ static char rcsid[] = "$NetBSD: parse.c,v 1.5 1997/01/11 09:57:08 lukem Exp $";
|
||||
#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 },
|
||||
@ -78,9 +82,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;
|
||||
@ -90,39 +92,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);
|
||||
}
|
||||
|
||||
|
||||
@ -131,8 +142,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;
|
||||
@ -140,7 +150,7 @@ parse__escape(ptr)
|
||||
p = *ptr;
|
||||
|
||||
if (p[1] == 0)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (*p == '\\') {
|
||||
p++;
|
||||
@ -189,45 +199,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 == '^' && isalpha((unsigned char) p[1])) {
|
||||
} else if (*p == '^' && isalpha((unsigned char) p[1])) {
|
||||
p++;
|
||||
c = (*p == '?') ? '\177' : (*p & 0237);
|
||||
}
|
||||
else
|
||||
} else
|
||||
c = *p;
|
||||
*ptr = ++p;
|
||||
return c;
|
||||
return (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;
|
||||
|
||||
@ -237,19 +243,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);
|
||||
}
|
||||
|
10
parse.h
10
parse.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: parse.h,v 1.2 1997/01/11 06:48:03 lukem Exp $ */
|
||||
/* $NetBSD: parse.h,v 1.4 2000/09/04 22:06:31 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -44,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 */
|
||||
|
108
prompt.c
108
prompt.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: prompt.c,v 1.2 1997/01/11 06:48:04 lukem Exp $ */
|
||||
/* $NetBSD: prompt.c,v 1.8 2001/01/10 07:45:41 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: prompt.c,v 1.2 1997/01/11 06:48:04 lukem Exp $";
|
||||
__RCSID("$NetBSD: prompt.c,v 1.8 2001/01/10 07:45:41 jdolecek Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -51,18 +52,32 @@ static char rcsid[] = "$NetBSD: prompt.c,v 1.2 1997/01/11 06:48:04 lukem Exp $";
|
||||
#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);
|
||||
}
|
||||
|
||||
|
||||
@ -73,31 +88,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():
|
||||
@ -105,25 +128,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);
|
||||
}
|
||||
|
13
prompt.h
13
prompt.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: prompt.h,v 1.2 1997/01/11 06:48:05 lukem Exp $ */
|
||||
/* $NetBSD: prompt.h,v 1.5 2000/09/04 22:06:31 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -46,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 */
|
||||
|
257
read.c
257
read.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: read.c,v 1.4 1997/04/11 17:52:47 christos Exp $ */
|
||||
/* $NetBSD: read.c,v 1.20 2001/09/27 19:29:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: read.c,v 1.4 1997/04/11 17:52:47 christos Exp $";
|
||||
__RCSID("$NetBSD: read.c,v 1.20 2001/09/27 19:29:50 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -49,22 +50,57 @@ static char rcsid[] = "$NetBSD: read.c,v 1.4 1997/04/11 17:52:47 christos Exp $"
|
||||
* Terminal read functions
|
||||
*/
|
||||
#include "sys.h"
|
||||
#include <sys/errno.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
extern int errno;
|
||||
#include "el.h"
|
||||
|
||||
#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_char(EditLine *, char *);
|
||||
private int read_getcmd(EditLine *, el_action_t *, char *);
|
||||
|
||||
/* read_init():
|
||||
* Initialize the read stuff
|
||||
*/
|
||||
protected int
|
||||
read_init(EditLine *el)
|
||||
{
|
||||
/* builtin read_char */
|
||||
el->el_read.read_char = read_char;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* el_read_setfn():
|
||||
* Set the read char function to the one provided.
|
||||
* If it is set to EL_BUILTIN_GETCFN, then reset to the builtin one.
|
||||
*/
|
||||
protected int
|
||||
el_read_setfn(EditLine *el, el_rfunc_t rc)
|
||||
{
|
||||
el->el_read.read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* el_read_getfn():
|
||||
* return the current read char function, or EL_BUILTIN_GETCFN
|
||||
* if it is the default one
|
||||
*/
|
||||
protected el_rfunc_t
|
||||
el_read_getfn(EditLine *el)
|
||||
{
|
||||
return (el->el_read.read_char == read_char) ?
|
||||
EL_BUILTIN_GETCFN : el->el_read.read_char;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG_EDIT
|
||||
private void
|
||||
read_debug(el)
|
||||
EditLine *el;
|
||||
read_debug(EditLine *el)
|
||||
{
|
||||
|
||||
if (el->el_line.cursor > el->el_line.lastchar)
|
||||
@ -80,13 +116,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 */
|
||||
|
||||
@ -110,29 +148,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,8 +183,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;
|
||||
|
||||
@ -150,25 +191,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);
|
||||
}
|
||||
|
||||
|
||||
@ -176,17 +217,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();
|
||||
}
|
||||
@ -197,25 +236,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 = 0;
|
||||
el_action_t cmd = ED_UNASSIGNED;
|
||||
int num;
|
||||
|
||||
while (cmd == 0 || cmd == ED_SEQUENCE_LEAD_IN) {
|
||||
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) {
|
||||
@ -239,7 +274,7 @@ read_getcmd(el, cmdnum, ch)
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
abort();
|
||||
EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -247,7 +282,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);
|
||||
}
|
||||
|
||||
|
||||
@ -255,14 +311,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();
|
||||
@ -279,50 +330,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 = (*el->el_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 ((*el->el_read.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);
|
||||
|
||||
@ -335,7 +403,7 @@ el_gets(el, nread)
|
||||
if (tty_rawmode(el) < 0) {
|
||||
if (nread)
|
||||
*nread = 0;
|
||||
return NULL;
|
||||
return (NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -343,26 +411,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 ((*el->el_read.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
|
||||
{
|
||||
@ -371,9 +464,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);
|
||||
@ -400,6 +495,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;
|
||||
@ -419,7 +521,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 */
|
||||
@ -432,7 +535,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;
|
||||
@ -442,11 +546,12 @@ el_gets(el, nread)
|
||||
}
|
||||
}
|
||||
|
||||
(void) tty_cookedmode(el); /* make sure the tty is set up correctly */
|
||||
/* make sure the tty is set up correctly */
|
||||
(void) tty_cookedmode(el);
|
||||
term__flush(); /* flush any buffered output */
|
||||
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);
|
||||
}
|
||||
|
55
read.h
Normal file
55
read.h
Normal file
@ -0,0 +1,55 @@
|
||||
/* $NetBSD: read.h,v 1.1 2001/09/27 19:29:50 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2001 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Anthony Mallet.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 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 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
|
||||
* CONTRACT, STRICT 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* el.read.h: Character reading functions
|
||||
*/
|
||||
#ifndef _h_el_read
|
||||
#define _h_el_read
|
||||
|
||||
typedef int (*el_rfunc_t)(EditLine *, char *);
|
||||
|
||||
typedef struct el_read_t {
|
||||
el_rfunc_t read_char; /* Function to read a character */
|
||||
} el_read_t;
|
||||
|
||||
protected int read_init(EditLine *);
|
||||
protected int el_read_setfn(EditLine *, el_rfunc_t);
|
||||
protected el_rfunc_t el_read_getfn(EditLine *);
|
||||
|
||||
#endif /* _h_el_read */
|
1664
readline.c
Normal file
1664
readline.c
Normal file
File diff suppressed because it is too large
Load Diff
13
readline/Makefile
Normal file
13
readline/Makefile
Normal file
@ -0,0 +1,13 @@
|
||||
# $NetBSD: Makefile,v 1.4 2001/05/16 07:09:26 enami Exp $
|
||||
|
||||
.PATH: ${CURDIR}/..
|
||||
|
||||
INCS= readline.h
|
||||
INCSDIR= /usr/include/readline
|
||||
SYMLINKS= readline.h ${INCSDIR}/history.h
|
||||
|
||||
MKOBJ= no
|
||||
|
||||
incinstall:: linksinstall
|
||||
|
||||
.include <bsd.prog.mk>
|
114
readline/readline.h
Normal file
114
readline/readline.h
Normal file
@ -0,0 +1,114 @@
|
||||
/* $NetBSD: readline.h,v 1.1 2001/01/05 21:15:50 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Jaromir Dolecek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 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 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
|
||||
* CONTRACT, STRICT 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.
|
||||
*/
|
||||
#ifndef _READLINE_H_
|
||||
#define _READLINE_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* list of readline stuff supported by editline library's readline wrapper */
|
||||
|
||||
/* typedefs */
|
||||
typedef int Function(const char *, int);
|
||||
typedef void VFunction(void);
|
||||
typedef char *CPFunction(const char *, int);
|
||||
typedef char **CPPFunction(const char *, int, int);
|
||||
|
||||
typedef struct _hist_entry {
|
||||
const char *line;
|
||||
const char *data;
|
||||
} HIST_ENTRY;
|
||||
|
||||
/* global variables used by readline enabled applications */
|
||||
__BEGIN_DECLS
|
||||
extern const char *rl_library_version;
|
||||
extern char *rl_readline_name;
|
||||
extern FILE *rl_instream;
|
||||
extern FILE *rl_outstream;
|
||||
extern char *rl_line_buffer;
|
||||
extern int rl_point, rl_end;
|
||||
extern int history_base, history_length;
|
||||
extern int max_input_history;
|
||||
extern char *rl_basic_word_break_characters;
|
||||
extern char *rl_completer_word_break_characters;
|
||||
extern char *rl_completer_quote_characters;
|
||||
extern CPFunction *rl_completion_entry_function;
|
||||
extern CPPFunction *rl_attempted_completion_function;
|
||||
extern int rl_completion_type;
|
||||
extern int rl_completion_query_items;
|
||||
extern char *rl_special_prefixes;
|
||||
extern int rl_completion_append_character;
|
||||
|
||||
/* supported functions */
|
||||
char *readline(const char *);
|
||||
int rl_initialize(void);
|
||||
|
||||
void using_history(void);
|
||||
int add_history(const char *);
|
||||
void clear_history(void);
|
||||
void stifle_history(int);
|
||||
int unstifle_history(void);
|
||||
int history_is_stifled(void);
|
||||
int where_history(void);
|
||||
HIST_ENTRY *current_history(void);
|
||||
HIST_ENTRY *history_get(int);
|
||||
int history_total_bytes(void);
|
||||
int history_set_pos(int);
|
||||
HIST_ENTRY *previous_history(void);
|
||||
HIST_ENTRY *next_history(void);
|
||||
int history_search(const char *, int);
|
||||
int history_search_prefix(const char *, int);
|
||||
int history_search_pos(const char *, int, int);
|
||||
int read_history(const char *);
|
||||
int write_history(const char *);
|
||||
int history_expand(char *, char **);
|
||||
char **history_tokenize(const char *);
|
||||
|
||||
char *tilde_expand(char *);
|
||||
char *filename_completion_function(const char *, int);
|
||||
char *username_completion_function(const char *, int);
|
||||
int rl_complete(int, int);
|
||||
int rl_read_key(void);
|
||||
char **completion_matches(const char *, CPFunction *);
|
||||
void rl_display_match_list(char **, int, int);
|
||||
|
||||
int rl_insert(int, int);
|
||||
void rl_reset_terminal(const char *);
|
||||
int rl_bind_key(int, int (*)(int, int));
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _READLINE_H_ */
|
19
refresh.h
19
refresh.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: refresh.h,v 1.2 1997/01/11 06:48:08 lukem Exp $ */
|
||||
/* $NetBSD: refresh.h,v 1.4 2001/01/10 07:45:42 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -48,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 */
|
||||
|
242
search.c
242
search.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: search.c,v 1.4 1997/01/23 14:02:47 mrg Exp $ */
|
||||
/* $NetBSD: search.c,v 1.11 2001/01/23 15:55:31 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: search.c,v 1.4 1997/01/23 14:02:47 mrg Exp $";
|
||||
__RCSID("$NetBSD: search.c,v 1.11 2001/01/23 15:55:31 jdolecek Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -67,15 +68,17 @@ static char rcsid[] = "$NetBSD: search.c,v 1.4 1997/01/23 14:02:47 mrg Exp $";
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
@ -83,32 +86,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;
|
||||
@ -117,12 +119,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) {
|
||||
@ -131,7 +133,7 @@ el_match(str, pat)
|
||||
} else {
|
||||
rv = 0;
|
||||
}
|
||||
return rv;
|
||||
return (rv);
|
||||
#elif defined(REGEXP)
|
||||
if ((re = regcomp(pat)) != NULL) {
|
||||
rv = regexec(re, str);
|
||||
@ -139,12 +141,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
|
||||
}
|
||||
|
||||
@ -153,16 +155,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));
|
||||
}
|
||||
|
||||
|
||||
@ -170,26 +170,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);
|
||||
@ -201,26 +201,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 (;;) {
|
||||
|
||||
@ -233,7 +232,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;
|
||||
@ -245,7 +244,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:
|
||||
@ -253,7 +252,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);
|
||||
@ -288,18 +288,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';
|
||||
@ -332,55 +336,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 = '?';
|
||||
@ -388,15 +410,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;
|
||||
@ -404,14 +427,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -420,9 +443,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];
|
||||
@ -463,30 +484,30 @@ 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,
|
||||
sizeof(el->el_search.patbuf) - 3);
|
||||
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++] = '*';
|
||||
#endif
|
||||
tmpbuf[tmplen] = '\0';
|
||||
(void)strncpy(el->el_search.patbuf, tmpbuf,
|
||||
sizeof(el->el_search.patbuf) - 1);
|
||||
(void) strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
|
||||
el->el_search.patlen = tmplen;
|
||||
}
|
||||
el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
|
||||
@ -494,18 +515,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -514,10 +533,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;
|
||||
|
||||
@ -525,17 +541,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -544,10 +560,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);
|
||||
@ -558,11 +573,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -571,9 +586,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;
|
||||
|
||||
@ -586,7 +599,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++;
|
||||
@ -596,11 +609,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);
|
||||
}
|
||||
|
||||
|
||||
@ -608,9 +620,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;
|
||||
|
||||
@ -623,7 +633,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--;
|
||||
@ -633,8 +643,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);
|
||||
}
|
||||
|
26
search.h
26
search.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: search.h,v 1.2 1997/01/11 06:48:09 lukem Exp $ */
|
||||
/* $NetBSD: search.h,v 1.5 2000/09/04 22:06:32 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -48,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 */
|
||||
|
@ -1,2 +1,5 @@
|
||||
major=0
|
||||
minor=0
|
||||
# $NetBSD: shlib_version,v 1.11 2001/01/01 15:54:07 jdolecek Exp $
|
||||
# Remember to update distrib/sets/lists/base/shl.* when changing
|
||||
#
|
||||
major=2
|
||||
minor=5
|
||||
|
38
sig.c
38
sig.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sig.c,v 1.3 1997/04/11 17:52:48 christos Exp $ */
|
||||
/* $NetBSD: sig.c,v 1.8 2001/01/09 17:31:04 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: sig.c,v 1.3 1997/04/11 17:52:48 christos Exp $";
|
||||
__RCSID("$NetBSD: sig.c,v 1.8 2001/01/09 17:31:04 jdolecek Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -55,14 +56,14 @@ static char rcsid[] = "$NetBSD: sig.c,v 1.3 1997/04/11 17:52:48 christos Exp $";
|
||||
|
||||
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
|
||||
@ -70,8 +71,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;
|
||||
@ -111,14 +111,13 @@ sig_handler(signo)
|
||||
* Initialize all signal stuff
|
||||
*/
|
||||
protected int
|
||||
sig_init(el)
|
||||
EditLine *el;
|
||||
sig_init(EditLine *el)
|
||||
{
|
||||
int i;
|
||||
sigset_t nset, oset;
|
||||
|
||||
(void) sigemptyset(&nset);
|
||||
#define _DO(a) (void) sigaddset(&nset, SIGWINCH);
|
||||
#define _DO(a) (void) sigaddset(&nset, a);
|
||||
ALLSIGS
|
||||
#undef _DO
|
||||
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
||||
@ -126,12 +125,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);
|
||||
}
|
||||
|
||||
|
||||
@ -139,9 +140,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;
|
||||
}
|
||||
@ -151,14 +152,13 @@ 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;
|
||||
|
||||
(void) sigemptyset(&nset);
|
||||
#define _DO(a) (void) sigaddset(&nset, SIGWINCH);
|
||||
#define _DO(a) (void) sigaddset(&nset, a);
|
||||
ALLSIGS
|
||||
#undef _DO
|
||||
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
||||
@ -178,14 +178,13 @@ 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;
|
||||
|
||||
(void) sigemptyset(&nset);
|
||||
#define _DO(a) (void) sigaddset(&nset, SIGWINCH);
|
||||
#define _DO(a) (void) sigaddset(&nset, a);
|
||||
ALLSIGS
|
||||
#undef _DO
|
||||
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
|
||||
@ -194,6 +193,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);
|
||||
}
|
||||
|
10
sig.h
10
sig.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sig.h,v 1.2 1997/01/11 06:48:11 lukem Exp $ */
|
||||
/* $NetBSD: sig.h,v 1.3 2000/09/04 22:06:32 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -64,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 */
|
||||
|
42
sys.h
42
sys.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sys.h,v 1.3 1997/01/11 06:48:12 lukem Exp $ */
|
||||
/* $NetBSD: sys.h,v 1.4 2000/09/04 22:06:32 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -61,20 +61,12 @@
|
||||
|
||||
#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>
|
||||
@ -86,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 */
|
||||
|
72
term.h
72
term.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: term.h,v 1.4 1997/01/11 06:48:14 lukem Exp $ */
|
||||
/* $NetBSD: term.h,v 1.12 2001/01/04 15:56:32 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -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 */
|
||||
@ -78,32 +80,32 @@ typedef struct {
|
||||
#define A_K_UP 1
|
||||
#define A_K_LT 2
|
||||
#define A_K_RT 3
|
||||
#define A_K_NKEYS 4
|
||||
#define A_K_HO 4
|
||||
#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 void 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
|
||||
@ -116,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 */
|
||||
|
54
termcap.h
54
termcap.h
@ -1,54 +0,0 @@
|
||||
/* $NetBSD: termcap.h,v 1.2 1997/01/11 06:48:14 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Christos Zoulas of Cornell University.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 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 CONTRACT, STRICT
|
||||
* 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.
|
||||
*
|
||||
* @(#)termcap.h 8.1 (Berkeley) 6/4/93
|
||||
*/
|
||||
|
||||
/*
|
||||
* termcap.h: I cannot find those in any include files...
|
||||
*/
|
||||
#ifndef _h_termcap
|
||||
#define _h_termcap
|
||||
|
||||
int tgetent __P((char *, char *));
|
||||
char *tgetstr __P((char *, char **));
|
||||
int tgetflag __P((char *));
|
||||
int tgetnum __P((char *));
|
||||
char *tgoto __P((char *, int, int));
|
||||
char *tputs __P((char *, int, void (*)(int)));
|
||||
|
||||
#endif /* _h_termcap */
|
77
tokenizer.c
77
tokenizer.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tokenizer.c,v 1.2 1997/01/11 06:48:15 lukem Exp $ */
|
||||
/* $NetBSD: tokenizer.c,v 1.7 2001/01/04 15:56:32 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: tokenizer.c,v 1.2 1997/01/11 06:48:15 lukem Exp $";
|
||||
__RCSID("$NetBSD: tokenizer.c,v 1.7 2001/01/04 15:56:32 christos Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -52,7 +53,9 @@ static char rcsid[] = "$NetBSD: tokenizer.c,v 1.2 1997/01/11 06:48:15 lukem Exp
|
||||
#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"
|
||||
|
||||
@ -79,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;
|
||||
@ -103,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));
|
||||
|
||||
@ -112,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);
|
||||
}
|
||||
|
||||
|
||||
@ -128,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;
|
||||
@ -143,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);
|
||||
@ -164,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 */
|
||||
@ -213,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 " */
|
||||
@ -244,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 */
|
||||
@ -281,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:
|
||||
@ -302,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;
|
||||
@ -369,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;
|
||||
@ -380,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_realloc(tok->argv,
|
||||
p = (char **) tok_realloc(tok->argv,
|
||||
tok->amax * sizeof(char *));
|
||||
}
|
||||
|
||||
if (p == NULL)
|
||||
return (-1);
|
||||
tok->argv = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
11
tokenizer.h
11
tokenizer.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tokenizer.h,v 1.2 1997/01/11 06:48:16 lukem Exp $ */
|
||||
/* $NetBSD: tokenizer.h,v 1.4 2000/09/04 22:06:33 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -46,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 */
|
||||
|
33
tty.h
33
tty.h
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: tty.h,v 1.4 1997/04/11 21:38:02 christos Exp $ */
|
||||
/* $NetBSD: tty.h,v 1.8 2000/09/04 22:06:33 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -46,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)
|
||||
@ -444,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;
|
||||
|
402
vi.c
402
vi.c
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: vi.c,v 1.2 1997/01/11 06:48:19 lukem Exp $ */
|
||||
/* $NetBSD: vi.c,v 1.8 2000/09/04 22:06:33 lukem Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1992, 1993
|
||||
@ -36,11 +36,12 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(lint) && !defined(SCCSID)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
static char rcsid[] = "$NetBSD: vi.c,v 1.2 1997/01/11 06:48:19 lukem Exp $";
|
||||
__RCSID("$NetBSD: vi.c,v 1.8 2000/09/04 22:06:33 lukem Exp $");
|
||||
#endif
|
||||
#endif /* not lint && not SCCSID */
|
||||
|
||||
@ -50,17 +51,16 @@ static char rcsid[] = "$NetBSD: vi.c,v 1.2 1997/01/11 06:48:19 lukem Exp $";
|
||||
#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;
|
||||
@ -81,26 +81,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
|
||||
}
|
||||
@ -109,29 +108,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);
|
||||
}
|
||||
|
||||
|
||||
@ -141,11 +139,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));
|
||||
}
|
||||
|
||||
|
||||
@ -155,11 +152,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));
|
||||
}
|
||||
|
||||
|
||||
@ -169,12 +165,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,
|
||||
@ -183,10 +178,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);
|
||||
}
|
||||
|
||||
|
||||
@ -196,12 +190,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,
|
||||
@ -210,10 +203,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);
|
||||
}
|
||||
|
||||
|
||||
@ -223,12 +215,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,
|
||||
@ -238,11 +229,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
|
||||
@ -250,12 +241,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,
|
||||
@ -265,23 +255,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 = *el->el_line.cursor;
|
||||
if (isupper(c))
|
||||
@ -291,9 +278,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);
|
||||
}
|
||||
|
||||
|
||||
@ -303,15 +290,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));
|
||||
}
|
||||
|
||||
|
||||
@ -321,10 +307,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;
|
||||
|
||||
@ -332,7 +317,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);
|
||||
}
|
||||
|
||||
|
||||
@ -342,17 +327,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_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -362,17 +346,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_NORM;
|
||||
return (CC_NORM);
|
||||
}
|
||||
|
||||
|
||||
@ -382,13 +365,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);
|
||||
}
|
||||
|
||||
|
||||
@ -398,13 +380,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);
|
||||
}
|
||||
|
||||
|
||||
@ -414,13 +395,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);
|
||||
}
|
||||
|
||||
|
||||
@ -430,17 +410,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);
|
||||
}
|
||||
|
||||
|
||||
@ -450,26 +429,24 @@ vi_insert(el, c)
|
||||
*/
|
||||
protected el_action_t
|
||||
/*ARGSUSED*/
|
||||
vi_add(el, c)
|
||||
EditLine *el;
|
||||
int c;
|
||||
vi_add(EditLine *el, int c)
|
||||
{
|
||||
int ret;
|
||||
|
||||
el->el_map.current = el->el_map.key;
|
||||
if (el->el_line.cursor < el->el_line.lastchar) {
|
||||
el->el_line.cursor++;
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -479,10 +456,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;
|
||||
|
||||
@ -490,7 +466,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);
|
||||
}
|
||||
|
||||
|
||||
@ -500,11 +476,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));
|
||||
}
|
||||
|
||||
|
||||
@ -514,23 +489,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);
|
||||
}
|
||||
|
||||
|
||||
@ -540,23 +513,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);
|
||||
}
|
||||
|
||||
|
||||
@ -566,9 +537,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;
|
||||
@ -582,7 +551,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++)
|
||||
@ -617,8 +586,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;
|
||||
@ -634,11 +602,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;
|
||||
@ -646,7 +614,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);
|
||||
@ -663,10 +631,10 @@ vi_undo(el, c)
|
||||
break;
|
||||
|
||||
default:
|
||||
return CC_ERROR;
|
||||
return (CC_ERROR);
|
||||
}
|
||||
|
||||
return CC_REFRESH;
|
||||
return (CC_REFRESH);
|
||||
}
|
||||
|
||||
|
||||
@ -676,11 +644,10 @@ vi_undo(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;
|
||||
@ -702,32 +669,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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -738,22 +704,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():
|
||||
@ -762,23 +727,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
|
||||
}
|
||||
@ -790,9 +753,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;
|
||||
|
||||
@ -803,7 +764,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);
|
||||
}
|
||||
|
||||
|
||||
@ -813,11 +774,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));
|
||||
}
|
||||
|
||||
|
||||
@ -827,11 +787,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));
|
||||
}
|
||||
|
||||
|
||||
@ -841,14 +800,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));
|
||||
}
|
||||
|
||||
|
||||
@ -858,16 +816,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));
|
||||
}
|
||||
|
||||
|
||||
@ -877,19 +834,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));
|
||||
|
||||
}
|
||||
|
||||
@ -900,19 +855,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));
|
||||
}
|
||||
|
||||
|
||||
@ -922,16 +875,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));
|
||||
|
||||
}
|
||||
|
||||
@ -942,15 +893,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));
|
||||
}
|
||||
|
||||
|
||||
@ -960,16 +910,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));
|
||||
}
|
||||
|
||||
|
||||
@ -979,12 +930,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