Vendor import NetBSD's libedit of "2001/09/29 17:52:10 UTC".

Obtained from:	NetBSD
This commit is contained in:
David E. O'Brien 2011-03-31 01:00:31 +00:00
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
44 changed files with 11585 additions and 8712 deletions

View File

@ -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>

View File

@ -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,182 +69,200 @@ 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;
static char a[] = "Edit$";
static char b[] = "Edit>";
return (continuation ? b : a);
}
static void
sig(i)
int i;
sig(int i)
{
(void) fprintf(stderr, "Got signal %d.\n", i);
el_reset(el);
(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;
const char* ptr;
const LineInfo *lf = el_line(el);
int len;
DIR *dd = opendir(".");
struct dirent *dp;
const char* ptr;
const LineInfo *lf = el_line(el);
int len;
/*
* Find the last word
*/
for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
continue;
len = lf->cursor - ++ptr;
/*
* Find the last word
*/
for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
continue;
len = lf->cursor - ++ptr;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1)
return CC_ERROR;
else
return CC_REFRESH;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1)
return (CC_ERROR);
else
return (CC_REFRESH);
}
}
}
closedir(dd);
return CC_ERROR;
closedir(dd);
return (CC_ERROR);
}
int
/*ARGSUSED*/
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
int num;
const char *buf;
Tokenizer *tok;
History *hist;
int num;
const char *buf;
Tokenizer *tok;
int lastevent = 0, ncontinuation;
History *hist;
HistEvent ev;
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
(void) signal(SIGTERM, sig);
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
(void) signal(SIGTERM, sig);
hist = history_init(); /* Init the builtin history */
history(hist, H_EVENT, 100); /* Remember 100 events */
hist = history_init(); /* Init the builtin history */
/* Remember 100 events */
history(hist, &ev, H_SETSIZE, 100);
tok = tok_init(NULL); /* Initialize the tokenizer */
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 */
el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
/* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist);
/* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist);
/* Add a user-defined function */
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
/* 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
* of previous and next history.
*/
el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
/*
* Bind j, k in vi command mode to previous and next line, instead
* of previous and next history.
*/
el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
/*
* Source the user's defaults file.
*/
el_source(el, NULL);
/*
* Source the user's defaults file.
*/
el_source(el, NULL);
while ((buf = el_gets(el, &num)) != NULL && num != 0) {
int ac;
char **av;
while ((buf = el_gets(el, &num)) != NULL && num != 0) {
int ac;
char **av;
#ifdef DEBUG
(void) fprintf(stderr, "got %d %s", num, buf);
(void) fprintf(stderr, "got %d %s", num, buf);
#endif
if (!continuation && num == 1)
continue;
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
continuation = ncontinuation;
ncontinuation = 0;
if (strcmp(av[0], "history") == 0) {
int rv;
switch (ac) {
case 1:
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, &ev, H_CLEAR);
else
goto badhist;
break;
case 3:
if (strcmp(av[1], "load") == 0)
history(hist, &ev, H_LOAD, av[2]);
else if (strcmp(av[1], "save") == 0)
history(hist, &ev, H_SAVE, av[2]);
break;
badhist:
default:
(void) fprintf(stderr,
"Bad history arguments\n");
break;
}
} else if (el_parse(el, ac, av) == -1) {
switch (fork()) {
case 0:
execvp(av[0], av);
perror(av[0]);
_exit(1);
/*NOTREACHED*/
break;
case -1:
perror("fork");
break;
default:
if (wait(&num) == -1)
perror("wait");
(void) fprintf(stderr, "Exit %x\n", num);
break;
}
}
tok_reset(tok);
}
history(hist, continuation ? H_ADD : H_ENTER, buf);
el_end(el);
tok_end(tok);
history_end(hist);
continuation = 0;
if (strcmp(av[0], "history") == 0) {
const struct HistEvent *he;
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);
break;
case 2:
if (strcmp(av[1], "clear") == 0)
history(hist, H_CLEAR);
else
goto badhist;
break;
case 3:
if (strcmp(av[1], "load") == 0)
history(hist, H_LOAD, av[2]);
else if (strcmp(av[1], "save") == 0)
history(hist, H_SAVE, av[2]);
break;
badhist:
default:
(void) fprintf(stderr, "Bad history arguments\n");
break;
}
}
else if (el_parse(el, ac, av) == -1) {
switch (fork()) {
case 0:
execvp(av[0], av);
perror(av[0]);
_exit(1);
/*NOTREACHED*/
break;
case -1:
perror("fork");
break;
default:
if (wait(&num) == -1)
perror("wait");
(void) fprintf(stderr, "Exit %x\n", num);
break;
}
}
tok_reset(tok);
}
el_end(el);
tok_end(tok);
history_end(hist);
return 0;
return (0);
}

798
chared.c

File diff suppressed because it is too large Load Diff

111
chared.h
View File

@ -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
@ -42,61 +42,61 @@
* el.chared.h: Character editor interface
*/
#ifndef _h_el_chared
#define _h_el_chared
#define _h_el_chared
#include <ctype.h>
#include <string.h>
#include "histedit.h"
#define EL_MAXMACRO 10
#define EL_MAXMACRO 10
/*
* This is a issue of basic "vi" look-and-feel. Defining VI_MOVE works
* like real vi: i.e. the transition from command<->insert modes moves
* the cursor.
*
* On the other hand we really don't want to move the cursor, because
* On the other hand we really don't want to move the cursor, because
* all the editing commands don't include the character under the cursor.
* Probably the best fix is to make all the editing commands aware of
* this fact.
*/
#define VI_MOVE
#define VI_MOVE
typedef struct c_macro_t {
int level;
char **macro;
char *nline;
int level;
char **macro;
char *nline;
} c_macro_t;
/*
/*
* Undo information for both vi and emacs
*/
typedef struct c_undo_t {
int action;
int isize;
int dsize;
char *ptr;
char *buf;
int action;
size_t isize;
size_t dsize;
char *ptr;
char *buf;
} c_undo_t;
/*
* Current action information for vi
*/
typedef struct c_vcmd_t {
int action;
char *pos;
char *ins;
int action;
char *pos;
char *ins;
} c_vcmd_t;
/*
* Kill buffer for emacs
*/
typedef struct c_kill_t {
char *buf;
char *last;
char *mark;
char *buf;
char *last;
char *mark;
} c_kill_t;
/*
@ -104,30 +104,30 @@ typedef struct c_kill_t {
* commands from both editors!
*/
typedef struct el_chared_t {
c_undo_t c_undo;
c_kill_t c_kill;
c_vcmd_t c_vcmd;
c_macro_t c_macro;
c_undo_t c_undo;
c_kill_t c_kill;
c_vcmd_t c_vcmd;
c_macro_t c_macro;
} el_chared_t;
#define STReof "^D\b\b"
#define STRQQ "\"\""
#define STReof "^D\b\b"
#define STRQQ "\"\""
#define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (isprint(a))
#define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (isprint(a))
#define NOP 0x00
#define DELETE 0x01
#define INSERT 0x02
#define CHANGE 0x04
#define NOP 0x00
#define DELETE 0x01
#define INSERT 0x02
#define CHANGE 0x04
#define CHAR_FWD 0
#define CHAR_BACK 1
#define CHAR_FWD 0
#define CHAR_BACK 1
#define MODE_INSERT 0
#define MODE_REPLACE 1
#define MODE_REPLACE_1 2
#define MODE_INSERT 0
#define MODE_REPLACE 1
#define MODE_REPLACE_1 2
#include "common.h"
#include "vi.h"
@ -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 */

1074
common.c

File diff suppressed because it is too large Load Diff

View File

@ -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 ,
@ -257,7 +253,7 @@ Otherwise, the current signal handlers will be used.
Perform the
.Ic bind
builtin command.
Refer to
Refer to
.Xr editrc 5
for more information.
.It Dv EL_ECHOTC , Xo
@ -268,7 +264,7 @@ for more information.
Perform the
.Ic echotc
builtin command.
Refer to
Refer to
.Xr editrc 5
for more information.
.It Dv EL_SETTC , Xo
@ -279,7 +275,7 @@ for more information.
Perform the
.Ic settc
builtin command.
Refer to
Refer to
.Xr editrc 5
for more information.
.It Dv EL_SETTY , Xo
@ -290,7 +286,7 @@ for more information.
Perform the
.Ic setty
builtin command.
Refer to
Refer to
.Xr editrc 5
for more information.
.It Dv EL_TELLTC , Xo
@ -301,7 +297,7 @@ for more information.
Perform the
.Ic telltc
builtin command.
Refer to
Refer to
.Xr editrc 5
for more information.
.It Dv EL_ADDFN , Xo
@ -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,11 +355,69 @@ 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
.Nm
by reading the contents of
by reading the contents of
.Fa file .
.Fn el_parse
is called for each line in
@ -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,16 +534,20 @@ 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
as a new element to the history, and, if necessary,
as a new element to the history, and, if necessary,
removing the oldest entry to keep the list to the created size.
.It Dv H_PREV_STR , Fa "const char *str"
Return the closest previous event that starts with
@ -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.

227
editrc.5
View File

@ -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
@ -61,7 +59,7 @@ Refer to
.Sx BUILTIN COMMANDS
for more information.
.Pp
.Ar prog
.Ar prog
is the program name string that a program defines when it calls
.Xr el_init 3
to setup
@ -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
@ -117,11 +121,11 @@ Options include:
.It Fl e
Bind all keys to the standard GNU Emacs-like bindings.
.It Fl v
Bind all keys to the standard
Bind all keys to the standard
.Xr vi 1 -like
bindings.
.It Fl a
List or change key bindings in the
List or change key bindings in the
.Xr vi 1
mode alternate (command mode) key map.
.It Fl k
@ -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 ,

542
el.c
View File

@ -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,103 +54,88 @@ 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 <stdarg.h>
#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));
EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
#ifdef DEBUG
char *tty;
char *tty;
#endif
if (el == NULL)
return NULL;
if (el == NULL)
return (NULL);
memset(el, 0, sizeof(EditLine));
memset(el, 0, sizeof(EditLine));
el->el_infd = fileno(fin);
el->el_outfile = fout;
el->el_prog = strdup(prog);
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;
/*
* Initialize all the modules. Order is important!!!
*/
(void) term_init(el);
(void) tty_init(el);
(void) key_init(el);
(void) map_init(el);
(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) term_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);
(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);
if (el == NULL)
return;
term_end(el);
tty_end(el);
key_end(el);
map_end(el);
ch_end(el);
search_end(el);
hist_end(el);
prompt_end(el);
sig_end(el);
el_reset(el);
el_free((ptr_t) el->el_prog);
el_free((ptr_t) el);
} /* end el_end */
term_end(el);
key_end(el);
map_end(el);
tty_end(el);
ch_end(el);
search_end(el);
hist_end(el);
prompt_end(el);
sig_end(el);
el_free((ptr_t) el->el_prog);
el_free((ptr_t) el);
}
/* 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? */
tty_cookedmode(el);
ch_reset(el); /* XXX: Do we want that? */
}
@ -157,127 +143,249 @@ 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_list va;
int rv;
va_start(va);
el = va_arg(va, EditLine *);
op = va_arg(va, int);
#endif
switch (op) {
case EL_PROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t));
break;
if (el == NULL)
return (-1);
va_start(va, op);
case EL_TERMINAL:
rv = term_set(el, va_arg(va, char *));
break;
switch (op) {
case EL_PROMPT:
case EL_RPROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t), op);
break;
case EL_EDITOR:
rv = map_set_editor(el, va_arg(va, char *));
break;
case EL_TERMINAL:
rv = term_set(el, va_arg(va, char *));
break;
case EL_SIGNAL:
if (va_arg(va, int))
el->el_flags |= HANDLE_SIGNALS;
else
el->el_flags &= ~HANDLE_SIGNALS;
rv = 0;
break;
case EL_EDITOR:
rv = map_set_editor(el, va_arg(va, char *));
break;
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
case EL_SIGNAL:
if (va_arg(va, int))
el->el_flags |= HANDLE_SIGNALS;
else
el->el_flags &= ~HANDLE_SIGNALS;
rv = 0;
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;
char *argv[20];
int i;
switch (op) {
case EL_BIND:
argv[0] = "bind";
rv = map_bind(el, i, argv);
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->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_TELLTC:
argv[0] = "telltc";
rv = term_telltc(el, i, argv);
case EL_GETCFN:
{
el_rfunc_t rc = va_arg(va, el_rfunc_t);
rv = el_read_setfn(el, rc);
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:
default:
rv = -1;
abort();
}
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;
}
}
break;
case EL_ADDFN:
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 *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;
char *argv[20];
int i;
case EL_HIST:
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:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
rv = hist_set(el, func, ptr);
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;
}
break;
default:
rv = -1;
}
case EL_HIST:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
rv = hist_set(el, func, ptr);
}
break;
#endif /* XXX */
va_end(va);
return rv;
} /* end el_set */
case EL_GETCFN:
*((el_rfunc_t *)ret) = el_read_getfn(el);
rv = 0;
break;
default:
rv = -1;
}
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];
FILE *fp;
size_t len;
char *ptr, path[MAXPATHLEN];
if (fname == NULL) {
fname = &elpath[1];
if ((fp = fopen(fname, "r")) == NULL) {
if ((ptr = getenv("HOME")) == NULL)
return -1;
(void)snprintf(path, sizeof(path), "%s%s", ptr, elpath);
fname = path;
fp = NULL;
if (fname == NULL) {
if (issetugid())
return (-1);
if ((ptr = getenv("HOME")) == NULL)
return (-1);
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
return (-1);
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
return (-1);
fname = path;
}
}
if (fp == NULL)
fp = fopen(fname, "r");
if (fp == NULL)
return (-1);
if ((fp = fopen(fname, "r")) == NULL)
return -1;
while ((ptr = fgetln(fp, &len)) != NULL) {
if (ptr[len - 1] == '\n')
--len;
ptr[len] = '\0';
if (parse_line(el, ptr) == -1) {
(void) fclose(fp);
return -1;
while ((ptr = fgetln(fp, &len)) != NULL) {
if (len > 0 && ptr[len - 1] == '\n')
--len;
ptr[len] = '\0';
if (parse_line(el, ptr) == -1) {
(void) fclose(fp);
return (-1);
}
}
}
(void) fclose(fp);
return 0;
(void) fclose(fp);
return (0);
}
@ -326,18 +436,54 @@ 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);
int lins, cols;
sigset_t oset, nset;
/* get the correct window size */
if (term_get_size(el, &lins, &cols))
term_change_size(el, lins, cols);
(void) sigemptyset(&nset);
(void) sigaddset(&nset, SIGWINCH);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
/* get the correct window size */
if (term_get_size(el, &lins, &cols))
term_change_size(el, lins, cols);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
/* el_beep():
* Called from the program to beep
*/
public void
el_beep(EditLine *el)
{
term_beep(el);
}
/* el_editmode()
* Set the state of EDIT_DISABLED from the `edit' command.
*/
protected int
/*ARGSUSED*/
el_editmode(EditLine *el, int argc, char **argv)
{
const char *how;
if (argv == NULL || argc != 2 || argv[1] == NULL)
return (-1);
how = argv[1];
if (strcmp(how, "on") == 0)
el->el_flags &= ~EDIT_DISABLED;
else if (strcmp(how, "off") == 0)
el->el_flags |= EDIT_DISABLED;
else {
(void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
return (-1);
}
return (0);
}

95
el.h
View File

@ -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
@ -42,53 +42,56 @@
* el.h: Internal structures.
*/
#ifndef _h_el
#define _h_el
#define _h_el
/*
* Local defaults
*/
#define KSHVI
#define VIDEFAULT
#define ANCHOR
#define KSHVI
#define VIDEFAULT
#define ANCHOR
#include <stdio.h>
#include <sys/types.h>
#define EL_BUFSIZ 1024 /* Maximum line size */
#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;
/*
* Editor state
*/
typedef struct el_state_t {
int inputmode; /* What mode are we in? */
int doingarg; /* Are we getting an argument? */
int argument; /* Numeric argument */
int metanext; /* Is the next char a meta char */
el_action_t lastcmd; /* Previous command */
int inputmode; /* What mode are we in? */
int doingarg; /* Are we getting an argument? */
int argument; /* Numeric argument */
int metanext; /* Is the next char a meta char */
el_action_t lastcmd; /* Previous command */
} el_state_t;
/*
* Until we come up with something better...
*/
#define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b)
#define el_free(a) free(a)
#define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b)
#define el_free(a) free(a)
#include "tty.h"
#include "prompt.h"
@ -103,29 +106,39 @@ 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 */
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
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 */
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_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 */
char *el_prog; /* the program name */
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
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 */
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 */

475
emacs.c
View File

@ -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,15 +36,16 @@
* 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 */
/*
/*
* emacs.c: Emacs functions
*/
#include "sys.h"
@ -56,28 +57,31 @@ 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 */
term_overwrite(el, STReof, 4);/* then do a EOF */
term__flush();
return CC_EOF;
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
*/
term_beep(el);
return (CC_ERROR);
}
} 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);
}
else {
/* Here we could list completions, but it is an error right now */
term_beep(el);
return CC_ERROR;
}
}
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;
}
}
@ -87,27 +91,26 @@ 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;
char *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
if (el->el_line.cursor == el->el_line.lastchar)
return (CC_ERROR);
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
/* save the text */
*kp++ = *p;
el->el_chared.c_kill.last = kp;
for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
/* save the text */
*kp++ = *p;
el->el_chared.c_kill.last = kp;
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;
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);
}
@ -117,34 +120,34 @@ 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;
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;
if (el->el_line.lastchar +
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
el->el_line.limit)
return (CC_ERROR);
el->el_chared.c_kill.mark = el->el_line.cursor;
cp = el->el_line.cursor;
el->el_chared.c_kill.mark = el->el_line.cursor;
cp = el->el_line.cursor;
/* open the space, */
c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
/* copy the chars */
for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
*cp++ = *kp;
/* open the space, */
c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
/* copy the chars */
for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
*cp++ = *kp;
/* if an arg, cursor at beginning else cursor at end */
if (el->el_state.argument == 1)
el->el_line.cursor = cp;
/* if an arg, cursor at beginning else cursor at end */
if (el->el_state.argument == 1)
el->el_line.cursor = cp;
return CC_REFRESH;
return (CC_REFRESH);
}
@ -154,20 +157,19 @@ 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;
char *kp, *cp;
cp = el->el_line.buffer;
kp = el->el_chared.c_kill.buf;
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 */
el->el_line.cursor = el->el_line.buffer;
return CC_REFRESH;
cp = el->el_line.buffer;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.lastchar)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
/* zap! -- delete all of it */
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
return (CC_REFRESH);
}
@ -177,33 +179,30 @@ 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;
char *kp, *cp;
if (!el->el_chared.c_kill.mark)
return CC_ERROR;
if (!el->el_chared.c_kill.mark)
return (CC_ERROR);
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.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)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delbefore(el, cp - el->el_chared.c_kill.mark);
el->el_line.cursor = el->el_chared.c_kill.mark;
}
return CC_REFRESH;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.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)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delbefore(el, cp - el->el_chared.c_kill.mark);
el->el_line.cursor = el->el_chared.c_kill.mark;
}
return (CC_REFRESH);
}
@ -213,30 +212,27 @@ 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;
char *kp, *cp;
if (el->el_chared.c_kill.mark)
return CC_ERROR;
if (el->el_chared.c_kill.mark)
return (CC_ERROR);
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
}
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;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
} 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);
}
@ -245,20 +241,17 @@ 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]) {
/* must have at least two chars entered */
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;
if (el->el_line.cursor > &el->el_line.buffer[1]) {
/* must have at least two chars entered */
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);
}
@ -268,49 +261,46 @@ 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;
if (el->el_line.cursor == el->el_line.lastchar)
return (CC_ERROR);
el->el_line.cursor = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument,
ce__isword);
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_CURSOR;
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el);
return (CC_REFRESH);
}
return (CC_CURSOR);
}
/* em_upper_case():
* Uppercase the characters from cursor to end of current word
* [M-u]
*/
protected el_action_t
/*ARGSUSED*/
em_upper_case(el, c)
EditLine *el;
int c;
em_upper_case(EditLine *el, int c)
{
char *cp, *ep;
char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
if (islower(*cp))
*cp = toupper(*cp);
for (cp = el->el_line.cursor; cp < ep; 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;
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);
}
@ -320,56 +310,53 @@ 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;
char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++) {
if (isalpha(*cp)) {
if (islower(*cp))
*cp = toupper(*cp);
cp++;
break;
for (cp = el->el_line.cursor; cp < ep; cp++) {
if (isalpha((unsigned char) *cp)) {
if (islower((unsigned char) *cp))
*cp = toupper(*cp);
cp++;
break;
}
}
}
for (; cp < ep; cp++)
if (isupper(*cp))
*cp = tolower(*cp);
for (; cp < ep; 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;
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);
}
/* 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;
char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
if (isupper(*cp))
*cp = tolower(*cp);
for (cp = el->el_line.cursor; cp < ep; 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;
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);
}
@ -379,62 +366,59 @@ 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;
el->el_chared.c_kill.mark = el->el_line.cursor;
return (CC_NORM);
}
/* em_exchange_mark():
* Exchange the cursor and mark
* Exchange the cursor and mark
* [^X^X]
*/
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;
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);
}
/* 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;
el->el_state.doingarg = 1;
el->el_state.argument *= 4;
return CC_ARGHACK;
if (el->el_state.argument > 1000000)
return (CC_ERROR);
el->el_state.doingarg = 1;
el->el_state.argument *= 4;
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;
el->el_state.metanext = 1;
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,27 +441,25 @@ 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;
char *cp, *oldc, *dp;
if (el->el_line.cursor == el->el_line.buffer)
return CC_ERROR;
if (el->el_line.cursor == el->el_line.buffer)
return (CC_ERROR);
oldc = el->el_line.cursor;
/* does a bounds check */
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword);
oldc = el->el_line.cursor;
/* does a bounds check */
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword);
c_insert(el, oldc - cp);
for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
*dp++ = *cp;
c_insert(el, oldc - cp);
for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
*dp++ = *cp;
el->el_line.cursor = dp; /* put cursor at end */
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);
el->el_search.patlen = 0;
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);
el->el_search.patlen = 0;
return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
}

168
hist.c
View File

@ -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.last = el->el_history.buf;
return 0;
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);
}
@ -70,11 +74,11 @@ 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;
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;
el->el_history.ref = ptr;
el->el_history.fun = fun;
return (0);
}
@ -99,78 +100,99 @@ 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;
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);
el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf);
if (el->el_history.eventno == 0) { /* if really the current line */
(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);
#ifdef KSHVI
if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer;
else
if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer;
else
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH;
}
if (el->el_history.ref == NULL)
return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
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_REFRESH);
}
if (el->el_history.ref == NULL)
return (CC_ERROR);
(void) strncpy(el->el_line.buffer, hp, EL_BUFSIZ);
el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
hp = HIST_FIRST(el);
if (el->el_line.lastchar > el->el_line.buffer) {
if (el->el_line.lastchar[-1] == '\n')
el->el_line.lastchar--;
if (el->el_line.lastchar[-1] == ' ')
el->el_line.lastchar--;
if (el->el_line.lastchar < el->el_line.buffer)
el->el_line.lastchar = el->el_line.buffer;
}
if (hp == NULL)
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);
}
(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) {
if (el->el_line.lastchar[-1] == '\n')
el->el_line.lastchar--;
if (el->el_line.lastchar[-1] == ' ')
el->el_line.lastchar--;
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;
else
if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer;
else
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
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;
const char *str;
if (el->el_history.ref == NULL)
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;
if (el->el_history.ref == NULL)
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);
}
/* 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;
}

37
hist.h
View File

@ -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
@ -42,25 +42,25 @@
* el.hist.c: History functions
*/
#ifndef _h_el_hist
#define _h_el_hist
#define _h_el_hist
#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 */
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 */
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 */
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)
#define HIST_FUN(el, fn, arg) \
((((*(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 */

View File

@ -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>
@ -56,9 +56,9 @@ typedef struct editline EditLine;
* For user-defined function interface
*/
typedef struct lineinfo {
const char *buffer;
const char *cursor;
const char *lastchar;
const char *buffer;
const char *cursor;
const char *lastchar;
} LineInfo;
@ -69,46 +69,53 @@ typedef struct lineinfo {
#define CC_NORM 0
#define CC_NEWLINE 1
#define CC_EOF 2
#define CC_ARGHACK 3
#define CC_REFRESH 4
#define CC_ARGHACK 3
#define CC_REFRESH 4
#define CC_CURSOR 5
#define CC_ERROR 6
#define CC_FATAL 7
#define CC_REDISPLAY 8
#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
*/
#define EL_PROMPT 0 /* , el_pfunc_t); */
#define EL_TERMINAL 1 /* , const char *); */
#define EL_EDITOR 2 /* , const char *); */
#define EL_SIGNAL 3 /* , int); */
#define EL_PROMPT 0 /* , el_pfunc_t); */
#define EL_TERMINAL 1 /* , const char *); */
#define EL_EDITOR 2 /* , const char *); */
#define EL_SIGNAL 3 /* , int); */
#define EL_BIND 4 /* , const char *, ..., NULL); */
#define EL_TELLTC 5 /* , const char *, ..., NULL); */
#define EL_SETTC 6 /* , const char *, ..., NULL); */
@ -116,27 +123,32 @@ int el_set __P((EditLine *, int, ...));
#define EL_SETTY 8 /* , const char *, ..., NULL); */
#define EL_ADDFN 9 /* , const char *, const char * */
/* , el_func_t); */
#define EL_HIST 10 /* , hist_fun_t, const char *); */
#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 ====
@ -145,34 +157,37 @@ void el_deletestr __P((EditLine *, int));
typedef struct history History;
typedef struct HistEvent {
int num;
const char *str;
int num;
const char *str;
} 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_FUNC 0 /* , UTSL */
#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_ */

996
history.c

File diff suppressed because it is too large Load Diff

866
key.c

File diff suppressed because it is too large Load Diff

50
key.h
View File

@ -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
@ -42,41 +42,37 @@
* el.key.h: Key macro header
*/
#ifndef _h_el_key
#define _h_el_key
#define _h_el_key
typedef union key_value_t {
el_action_t cmd; /* If it is a command the # */
char *str; /* If it is a string... */
el_action_t cmd; /* If it is a command the # */
char *str; /* If it is a string... */
} key_value_t;
typedef struct key_node_t key_node_t;
typedef struct el_key_t {
char *buf; /* Key print buffer */
key_node_t *map; /* Key map */
key_value_t val; /* Local conversion buffer */
char *buf; /* Key print buffer */
key_node_t *map; /* Key map */
key_value_t val; /* Local conversion buffer */
} el_key_t;
#define XK_CMD 0
#define XK_STR 1
#define XK_NOD 2
#define XK_EXE 3
#define XK_CMD 0
#define XK_STR 1
#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 */

117
makelist
View File

@ -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++)
@ -96,9 +107,9 @@ case $FLAG in
s = "-";
fname = fname s;
}
printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
ok = 1;
ok = 1;
}
}
/^ \*/ {
@ -113,41 +124,53 @@ 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 {
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 '
BEGIN {
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
count = 0;
count = 0;
}
{
{
printf("#define\t%-30.30s\t%3d\n", $1, count++);
}
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;
@ -155,7 +178,7 @@ case $FLAG in
{
clen = 25 + 2;
len += clen;
if (len >= maxlen)
if (len >= maxlen)
needn = 1;
if (needn) {
printf("\n ");
@ -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

2388
map.c

File diff suppressed because it is too large Load Diff

50
map.h
View File

@ -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
@ -42,38 +42,38 @@
* el.map.h: Editor maps
*/
#ifndef _h_el_map
#define _h_el_map
#define _h_el_map
typedef struct el_bindings_t { /* for the "bind" shell command */
const char *name; /* function name for bind command */
int func; /* function numeric value */
const char *description; /* description of function */
const char *name; /* function name for bind command */
int func; /* function numeric value */
const char *description; /* description of function */
} el_bindings_t;
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 */
int type; /* Emacs or vi */
el_bindings_t *help; /* The help for the editor functions */
el_func_t *func; /* List of available functions */
int nfunc; /* The number of functions/help items */
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 */
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 */
int nfunc; /* The number of functions/help items */
} el_map_t;
#define MAP_EMACS 0
#define MAP_VI 1
#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 */

293
parse.c
View File

@ -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,18 +61,20 @@ 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 {
char *name;
int (*func) __P((EditLine *, int, char **));
private const struct {
char *name;
int (*func)(EditLine *, int, char **);
} cmds[] = {
{ "bind", map_bind },
{ "echotc", term_echotc },
{ "history", hist_list },
{ "telltc", term_telltc },
{ "settc", term_settc },
{ "setty", tty_stty },
{ NULL, NULL }
{ "bind", map_bind },
{ "echotc", term_echotc },
{ "edit", el_editmode },
{ "history", hist_list },
{ "telltc", term_telltc },
{ "settc", term_settc },
{ "setty", tty_stty },
{ NULL, NULL }
};
@ -78,51 +82,58 @@ 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;
Tokenizer *tok;
char **argv;
int argc;
Tokenizer *tok;
tok = tok_init(NULL);
tok_line(tok, line, &argc, &argv);
argc = el_parse(el, argc, argv);
tok_end(tok);
return argc;
tok = tok_init(NULL);
tok_line(tok, line, &argc, &argv);
argc = el_parse(el, argc, argv);
tok_end(tok);
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;
char *ptr;
int i;
if (argc < 1)
return -1;
ptr = strchr(argv[0], ':');
if (ptr != NULL) {
*ptr++ = '\0';
if (! el_match(el->el_prog, argv[0]))
return 0;
}
else
ptr = argv[0];
if (argc < 1)
return (-1);
ptr = strchr(argv[0], ':');
if (ptr != NULL) {
char *tprog;
size_t l;
for (i = 0; cmds[i].name != NULL; i++)
if (strcmp(cmds[i].name, ptr) == 0) {
i = (*cmds[i].func)(el, argc, argv);
return -i;
}
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];
return -1;
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 (-1);
}
@ -131,125 +142,119 @@ 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;
const char *p;
int c;
p = *ptr;
p = *ptr;
if (p[1] == 0)
return -1;
if (p[1] == 0)
return (-1);
if (*p == '\\') {
p++;
switch (*p) {
case 'a':
c = '\007'; /* Bell */
break;
case 'b':
c = '\010'; /* Backspace */
break;
case 't':
c = '\011'; /* Horizontal Tab */
break;
case 'n':
c = '\012'; /* New Line */
break;
case 'v':
c = '\013'; /* Vertical Tab */
break;
case 'f':
c = '\014'; /* Form Feed */
break;
case 'r':
c = '\015'; /* Carriage Return */
break;
case 'e':
c = '\033'; /* Escape */
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
int cnt, ch;
for (cnt = 0, c = 0; cnt < 3; cnt++) {
ch = *p++;
if (ch < '0' || ch > '7') {
p--;
if (*p == '\\') {
p++;
switch (*p) {
case 'a':
c = '\007'; /* Bell */
break;
}
c = (c << 3) | (ch - '0');
}
if ((c & 0xffffff00) != 0)
return -1;
--p;
}
break;
default:
c = *p;
break;
}
}
else if (*p == '^' && isalpha((unsigned char) p[1])) {
p++;
c = (*p == '?') ? '\177' : (*p & 0237);
}
else
c = *p;
*ptr = ++p;
return c;
}
case 'b':
c = '\010'; /* Backspace */
break;
case 't':
c = '\011'; /* Horizontal Tab */
break;
case 'n':
c = '\012'; /* New Line */
break;
case 'v':
c = '\013'; /* Vertical Tab */
break;
case 'f':
c = '\014'; /* Form Feed */
break;
case 'r':
c = '\015'; /* Carriage Return */
break;
case 'e':
c = '\033'; /* Escape */
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
int cnt, ch;
for (cnt = 0, c = 0; cnt < 3; cnt++) {
ch = *p++;
if (ch < '0' || ch > '7') {
p--;
break;
}
c = (c << 3) | (ch - '0');
}
if ((c & 0xffffff00) != 0)
return (-1);
--p;
break;
}
default:
c = *p;
break;
}
} else if (*p == '^' && isalpha((unsigned char) p[1])) {
p++;
c = (*p == '?') ? '\177' : (*p & 0237);
} else
c = *p;
*ptr = ++p;
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;
char *rv = out;
int n;
case '\\':
case '^':
if ((n = parse__escape(&in)) == -1)
return NULL;
*out++ = n;
break;
for (;;)
switch (*in) {
case '\0':
*out = '\0';
return (rv);
default:
*out++ = *in++;
break;
}
case '\\':
case '^':
if ((n = parse__escape(&in)) == -1)
return (NULL);
*out++ = n;
break;
default:
*out++ = *in++;
break;
}
}
/* 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;
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;
for (b = el->el_map.help; b->name != NULL; b++)
if (strcmp(b->name, cmd) == 0)
return (b->func);
return (-1);
}

12
parse.h
View File

@ -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
@ -42,11 +42,11 @@
* el.parse.h: Parser functions
*/
#ifndef _h_el_parse
#define _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 */

124
prompt.c
View File

@ -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;
static char a[3] = {'?', ' ', '\0'};
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,57 +88,88 @@ 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);
while (*p)
re_putc(el, *p++);
el_prompt_t *elp;
char *p;
el->el_prompt.p_pos.v = el->el_refresh.r_cursor.v;
el->el_prompt.p_pos.h = el->el_refresh.r_cursor.h;
if (op == EL_PROMPT)
elp = &el->el_prompt;
else
elp = &el->el_rprompt;
p = (elp->p_func) (el);
while (*p)
re_putc(el, *p++, 1);
} /* 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;
protected int
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_prompt.p_func = prompt_default;
el->el_prompt.p_pos.v = 0;
el->el_prompt.p_pos.h = 0;
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():
* Clean up the prompt stuff
*/
protected void
/*ARGSUSED*/
prompt_end(el)
EditLine *el;
/*ARGSUSED*/
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;
protected int
prompt_set(EditLine *el, el_pfunc_t prf, int op)
{
if (prf == NULL)
el->el_prompt.p_func = prompt_default;
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 */
el_prompt_t *p;
if (op == EL_PROMPT)
p = &el->el_prompt;
else
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);
}

View File

@ -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
@ -42,20 +42,21 @@
* el.prompt.h: Prompt printing stuff
*/
#ifndef _h_el_prompt
#define _h_el_prompt
#define _h_el_prompt
#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_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 */

697
read.c
View File

@ -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,91 +50,132 @@ 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
#define OKCMD -1
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;
}
private int read__fixio __P((int, int));
private int read_preread __P((EditLine *));
private int read_getcmd __P((EditLine *, el_action_t *, char *));
#ifdef DEBUG_EDIT
private void
read_debug(el)
EditLine *el;
read_debug(EditLine *el)
{
if (el->el_line.cursor > el->el_line.lastchar)
(void) fprintf(el->el_errfile, "cursor > lastchar\r\n");
if (el->el_line.cursor < el->el_line.buffer)
(void) fprintf(el->el_errfile, "cursor < buffer\r\n");
if (el->el_line.cursor > el->el_line.limit)
(void) fprintf(el->el_errfile, "cursor > limit\r\n");
if (el->el_line.lastchar > el->el_line.limit)
(void) fprintf(el->el_errfile, "lastchar > limit\r\n");
if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2])
(void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n");
if (el->el_line.cursor > el->el_line.lastchar)
(void) fprintf(el->el_errfile, "cursor > lastchar\r\n");
if (el->el_line.cursor < el->el_line.buffer)
(void) fprintf(el->el_errfile, "cursor < buffer\r\n");
if (el->el_line.cursor > el->el_line.limit)
(void) fprintf(el->el_errfile, "cursor > limit\r\n");
if (el->el_line.lastchar > el->el_line.limit)
(void) fprintf(el->el_errfile, "lastchar > limit\r\n");
if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2])
(void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n");
}
#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 */
switch (e) {
case -1: /* Make sure that the code is reachable */
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
# ifndef TRY_AGAIN
# define TRY_AGAIN
# endif
case EWOULDBLOCK:
#ifndef TRY_AGAIN
#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK */
#if defined(POSIX) && defined(EAGAIN)
# if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN:
# ifndef TRY_AGAIN
# define TRY_AGAIN
# endif
# endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN:
#ifndef TRY_AGAIN
#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#endif /* POSIX && EAGAIN */
e = 0;
e = 0;
#ifdef TRY_AGAIN
# if defined(F_SETFL) && defined(O_NDELAY)
if ((e = fcntl(fd, F_GETFL, 0)) == -1)
return -1;
#if defined(F_SETFL) && defined(O_NDELAY)
if ((e = fcntl(fd, F_GETFL, 0)) == -1)
return (-1);
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
return -1;
else
e = 1;
# endif /* F_SETFL && O_NDELAY */
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
return (-1);
else
e = 1;
#endif /* F_SETFL && O_NDELAY */
# ifdef FIONBIO
if (ioctl(fd, FIONBIO, (ioctl_t) &e) == -1)
return -1;
else
e = 1;
# endif /* FIONBIO */
#ifdef FIONBIO
{
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;
case EINTR:
return (0);
default:
return -1;
}
default:
return (-1);
}
}
@ -141,34 +183,33 @@ 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;
int chrs = 0;
if (el->el_chared.c_macro.nline) {
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;
if (el->el_chared.c_macro.nline) {
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);
#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));
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
if (chrs > 0) {
buf[chrs] = '\0';
el->el_chared.c_macro.nline = strdup(buf);
el_push(el->el_chared.c_macro.nline);
}
}
#endif /* FIONREAD */
char buf[EL_BUFSIZ];
return chrs > 0;
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->el_chared.c_macro.nline);
}
}
#endif /* FIONREAD */
return (chrs > 0);
}
@ -176,20 +217,18 @@ 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;
c_macro_t *ma = &el->el_chared.c_macro;
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++;
ma->macro[ma->level] = (char *) str;
}
else {
term_beep(el);
term__flush();
}
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++;
/* LINTED const cast */
ma->macro[ma->level] = (char *) str;
} else {
term_beep(el);
term__flush();
}
}
@ -197,57 +236,74 @@ 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;
int num;
el_action_t cmd = ED_UNASSIGNED;
int num;
while (cmd == 0 || cmd == ED_SEQUENCE_LEAD_IN) {
if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
return num;
while (cmd == ED_UNASSIGNED || cmd == ED_SEQUENCE_LEAD_IN) {
if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
return (num);
#ifdef KANJI
if ((*ch & 0200)) {
el->el_state.metanext = 0;
cmd = CcViMap[' '];
break;
}
else
if ((*ch & 0200)) {
el->el_state.metanext = 0;
cmd = CcViMap[' '];
break;
} else
#endif /* KANJI */
if (el->el_state.metanext) {
el->el_state.metanext = 0;
*ch |= 0200;
}
cmd = el->el_map.current[(unsigned char) *ch];
if (cmd == ED_SEQUENCE_LEAD_IN) {
key_value_t val;
switch (key_get(el, ch, &val)) {
case XK_CMD:
cmd = val.cmd;
break;
case XK_STR:
el_push(el, val.str);
break;
if (el->el_state.metanext) {
el->el_state.metanext = 0;
*ch |= 0200;
}
cmd = el->el_map.current[(unsigned char) *ch];
if (cmd == ED_SEQUENCE_LEAD_IN) {
key_value_t val;
switch (key_get(el, ch, &val)) {
case XK_CMD:
cmd = val.cmd;
break;
case XK_STR:
el_push(el, val.str);
break;
#ifdef notyet
case XK_EXE:
/* XXX: In the future to run a user function */
RunCommand(val.str);
break;
case XK_EXE:
/* XXX: In the future to run a user function */
RunCommand(val.str);
break;
#endif
default:
abort();
break;
}
default:
EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
break;
}
}
if (el->el_map.alt == NULL)
el->el_map.current = el->el_map.key;
}
if (el->el_map.alt == NULL)
el->el_map.current = el->el_map.key;
}
*cmdnum = cmd;
return OKCMD;
*cmdnum = cmd;
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,198 +311,247 @@ 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;
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
c_macro_t *ma = &el->el_chared.c_macro;
term__flush();
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
break;
}
if (ma->level < 0)
break;
term__flush();
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
break;
if (*ma->macro[ma->level] == 0) {
ma->level--;
continue;
}
*cp = *ma->macro[ma->level]++ & 0377;
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode
* On */
ma->level--;
}
return (1);
}
if (ma->level < 0)
break;
if (*ma->macro[ma->level] == 0) {
ma->level--;
continue;
}
*cp = *ma->macro[ma->level]++ & 0377;
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode On */
ma->level--;
}
return 1;
}
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Turning raw mode on\n");
(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;
if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
return (0);
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Reading a character\n");
(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;
if (el->el_flags & HANDLE_SIGNALS)
sig_set(el);
re_clear_display(el); /* reset the display stuff */
ch_reset(el);
int retval;
el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */
char ch;
#ifdef FIONREAD
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
long chrs = 0;
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) &chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
if (nread)
*nread = 0;
return NULL;
}
}
}
c_macro_t *ma = &el->el_chared.c_macro;
#endif /* FIONREAD */
re_refresh(el); /* print the prompt */
if (el->el_flags & HANDLE_SIGNALS)
sig_set(el);
for (num = OKCMD; num == OKCMD;) { /* while still editing this line */
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);
#ifdef FIONREAD
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
long chrs = 0;
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
if (nread)
*nread = 0;
return (NULL);
}
}
}
#endif /* FIONREAD */
re_refresh(el); /* print the prompt */
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);
read_debug(el);
#endif /* DEBUG_EDIT */
/* if EOF or error */
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
/* 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 */
break;
}
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);
(void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch);
#endif /* DEBUG_EDIT */
continue; /* try again */
continue; /* try again */
}
/* now do the real command */
#ifdef DEBUG_READ
{
el_bindings_t *b;
for (b = el->el_map.help; b->name; b++)
if (b->func == cmdnum)
break;
if (b->name)
(void) fprintf(el->el_errfile,
"Executing %s\n", b->name);
else
(void) fprintf(el->el_errfile,
"Error command = %d\n", cmdnum);
}
#endif /* DEBUG_READ */
retval = (*el->el_map.func[cmdnum]) (el, ch);
/* save the last command here */
el->el_state.lastcmd = cmdnum;
/* use any return value */
switch (retval) {
case CC_CURSOR:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh_cursor(el);
break;
case CC_REDISPLAY:
re_clear_lines(el);
re_clear_display(el);
/* FALLTHROUGH */
case CC_REFRESH:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
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;
break;
case CC_ARGHACK: /* Suggested by Rich Salz */
/* <rsalz@pineapple.bbn.com> */
break; /* keep going... */
case CC_EOF: /* end of file typed */
num = 0;
break;
case CC_NEWLINE: /* normal end of line */
num = el->el_line.lastchar - el->el_line.buffer;
break;
case CC_FATAL: /* fatal error, reset to known state */
#ifdef DEBUG_READ
(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 */
ch_reset(el); /* reset the input pointers */
re_refresh(el); /* print the prompt again */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
break;
case CC_ERROR:
default: /* functions we don't know about */
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile,
"*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
term_beep(el);
term__flush();
break;
}
}
/* now do the real command */
#ifdef DEBUG_READ
{
el_bindings_t *b;
for (b = el->el_map.help; b->name; b++)
if (b->func == cmdnum)
break;
if (b->name)
(void) fprintf(el->el_errfile, "Executing %s\n", b->name);
else
(void) fprintf(el->el_errfile, "Error command = %d\n", cmdnum);
}
#endif /* DEBUG_READ */
retval = (*el->el_map.func[cmdnum])(el, ch);
/* save the last command here */
el->el_state.lastcmd = cmdnum;
/* use any return value */
switch (retval) {
case CC_CURSOR:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh_cursor(el);
break;
case CC_REDISPLAY:
re_clear_lines(el);
re_clear_display(el);
/* FALLTHROUGH */
case CC_REFRESH:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh(el);
break;
case CC_NORM: /* normal char */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
break;
case CC_ARGHACK: /* Suggested by Rich Salz */
/* <rsalz@pineapple.bbn.com> */
break; /* keep going... */
case CC_EOF: /* end of file typed */
num = 0;
break;
case CC_NEWLINE: /* normal end of line */
num = el->el_line.lastchar - el->el_line.buffer;
break;
case CC_FATAL: /* fatal error, reset to known state */
#ifdef DEBUG_READ
(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 */
ch_reset(el); /* reset the input pointers */
re_refresh(el); /* print the prompt again */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
break;
case CC_ERROR:
default: /* functions we don't know about */
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
term_beep(el);
term__flush();
break;
}
}
(void) tty_cookedmode(el); /* make sure the tty is set up correctly */
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;
/* 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);
}

55
read.h Normal file
View 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

File diff suppressed because it is too large Load Diff

13
readline/Makefile Normal file
View 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
View 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_ */

1616
refresh.c

File diff suppressed because it is too large Load Diff

View File

@ -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
@ -42,21 +42,22 @@
* el.refresh.h: Screen refresh functions
*/
#ifndef _h_el_refresh
#define _h_el_refresh
#define _h_el_refresh
#include "histedit.h"
typedef struct {
coord_t r_cursor; /* Refresh cursor position */
int r_oldcv, r_newcv; /* Vertical locations */
coord_t r_cursor; /* Refresh cursor position */
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 */

876
search.c

File diff suppressed because it is too large Load Diff

View File

@ -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
@ -41,30 +41,30 @@
/*
* el.search.h: Line and history searching utilities
*/
#ifndef _h_el_search
#define _h_el_search
#ifndef _h_el_search
#define _h_el_search
#include "histedit.h"
typedef struct el_search_t {
char *patbuf; /* The pattern buffer */
int 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 */
char *patbuf; /* 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 */

View File

@ -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

170
sig.c
View File

@ -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[] = {
#define _DO(a) (a),
ALLSIGS
#undef _DO
-1
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,40 +71,39 @@ 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;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
(void) sigaddset(&nset, signo);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
(void) sigaddset(&nset, signo);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
switch (signo) {
case SIGCONT:
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
term__flush();
break;
switch (signo) {
case SIGCONT:
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
term__flush();
break;
case SIGWINCH:
el_resize(sel);
break;
case SIGWINCH:
el_resize(sel);
break;
default:
tty_cookedmode(sel);
break;
}
default:
tty_cookedmode(sel);
break;
}
for (i = 0; sighdl[i] != -1; i++)
if (signo == sighdl[i])
break;
for (i = 0; sighdl[i] != -1; i++)
if (signo == sighdl[i])
break;
(void) signal(signo, sel->el_signal[i]);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) kill(0, signo);
(void) signal(signo, sel->el_signal[i]);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) kill(0, signo);
}
@ -111,27 +111,28 @@ sig_handler(signo)
* Initialize all signal stuff
*/
protected int
sig_init(el)
EditLine *el;
sig_init(EditLine *el)
{
int i;
sigset_t nset, oset;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, SIGWINCH);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
el->el_signal = (sig_t *) el_malloc(SIGSIZE);
for (i = 0; sighdl[i] != -1; i++)
el->el_signal[i] = SIG_ERR;
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);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
return 0;
return (0);
}
@ -139,11 +140,11 @@ 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;
el_free((ptr_t) el->el_signal);
el->el_signal = NULL;
}
@ -151,26 +152,25 @@ 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;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, SIGWINCH);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
for (i = 0; sighdl[i] != -1; i++) {
sig_t s;
/* This could happen if we get interrupted */
if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
el->el_signal[i] = s;
}
sel = el;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
for (i = 0; sighdl[i] != -1; i++) {
sig_t s;
/* This could happen if we get interrupted */
if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
el->el_signal[i] = s;
}
sel = el;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
@ -178,22 +178,22 @@ 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;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, SIGWINCH);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
for (i = 0; sighdl[i] != -1; i++)
if (el->el_signal[i] != SIG_ERR)
(void) signal(sighdl[i], el->el_signal[i]);
for (i = 0; sighdl[i] != -1; i++)
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 */
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
sel = NULL; /* we are going to die if the handler is
* called */
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}

32
sig.h
View File

@ -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
@ -42,7 +42,7 @@
* el.sig.h: Signal handling functions
*/
#ifndef _h_el_sig
#define _h_el_sig
#define _h_el_sig
#include <signal.h>
@ -52,21 +52,21 @@
* Define here all the signals we are going to handle
* The _DO macro is used to iterate in the source code
*/
#define ALLSIGS \
_DO(SIGINT) \
_DO(SIGTSTP) \
_DO(SIGSTOP) \
_DO(SIGQUIT) \
_DO(SIGHUP) \
_DO(SIGTERM) \
_DO(SIGCONT) \
_DO(SIGWINCH)
#define ALLSIGS \
_DO(SIGINT) \
_DO(SIGTSTP) \
_DO(SIGSTOP) \
_DO(SIGQUIT) \
_DO(SIGHUP) \
_DO(SIGTERM) \
_DO(SIGCONT) \
_DO(SIGWINCH)
typedef sig_t *el_signal_t;
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 */

48
sys.h
View File

@ -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
@ -42,7 +42,7 @@
* sys.h: Put all the stupid compiler and system dependencies here...
*/
#ifndef _h_sys
#define _h_sys
#define _h_sys
#ifndef public
# define public /* Externally visible functions/variables */
@ -61,20 +61,12 @@
#ifndef _PTR_T
# define _PTR_T
# if __STDC__
typedef void* ptr_t;
# else
typedef char* ptr_t;
# endif
typedef void *ptr_t;
#endif
#ifndef _IOCTL_T
# define _IOCTL_T
# if __STDC__
typedef void* ioctl_t;
# else
typedef char* ioctl_t;
# endif
typedef void *ioctl_t;
#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 */

2102
term.c

File diff suppressed because it is too large Load Diff

120
term.h
View File

@ -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
@ -42,79 +42,83 @@
* el.term.h: Termcap header
*/
#ifndef _h_el_term
#define _h_el_term
#define _h_el_term
#include "histedit.h"
typedef struct { /* Symbolic function key bindings */
char *name; /* name of the key */
int key; /* Index in termcap table */
key_value_t fun; /* Function bound to it */
int type; /* Type of function */
typedef struct { /* Symbolic function key bindings */
char *name; /* name of the key */
int key; /* Index in termcap table */
key_value_t fun; /* Function bound to it */
int type; /* Type of function */
} fkey_t;
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 */
char *t_buf; /* Termcap buffer */
int t_loc; /* location used */
char **t_str; /* termcap strings */
int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
fkey_t *t_fkey; /* Array of keys */
coord_t t_size; /* # lines and cols */
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 */
int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
fkey_t *t_fkey; /* Array of keys */
} el_term_t;
/*
* fKey indexes
*/
#define A_K_DN 0
#define A_K_UP 1
#define A_K_LT 2
#define A_K_RT 3
#define A_K_NKEYS 4
#define A_K_DN 0
#define A_K_UP 1
#define A_K_LT 2
#define A_K_RT 3
#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
*/
#define EL_FLAGS (el)->el_term.t_flags
#define EL_FLAGS (el)->el_term.t_flags
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
#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_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
#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 */

View File

@ -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 */

View File

@ -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,50 +53,52 @@ 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"
#define IFS "\t \n"
#define TOK_KEEP 1
#define TOK_EAT 2
#define TOK_KEEP 1
#define TOK_EAT 2
#define WINCR 20
#define AINCR 10
#define WINCR 20
#define AINCR 10
#define tok_malloc(a) malloc(a)
#define tok_free(a) free(a)
#define tok_realloc(a, b) realloc(a, b)
#define tok_malloc(a) malloc(a)
#define tok_free(a) free(a)
#define tok_realloc(a, b) realloc(a, b)
struct tokenizer {
char *ifs; /* In field separator */
int argc, amax; /* Current and maximum number of args */
char **argv; /* Argument list */
char *wptr, *wmax; /* Space and limit on the word buffer */
char *wstart; /* Beginning of next word */
char *wspace; /* Space of word buffer */
quote_t quote; /* Quoting state */
int flags; /* flags; */
char *ifs; /* In field separator */
int argc, amax; /* Current and maximum number of args */
char **argv; /* Argument list */
char *wptr, *wmax; /* Space and limit on the word buffer */
char *wstart; /* Beginning of next word */
char *wspace; /* Space of word buffer */
quote_t quote; /* Quoting state */
int flags; /* flags; */
};
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;
tok->argv[tok->argc] = NULL;
tok->wstart = ++tok->wptr;
}
tok->flags &= ~TOK_KEEP;
*tok->wptr = '\0';
if ((tok->flags & TOK_KEEP) || tok->wptr != tok->wstart) {
tok->argv[tok->argc++] = tok->wstart;
tok->argv[tok->argc] = NULL;
tok->wstart = ++tok->wptr;
}
tok->flags &= ~TOK_KEEP;
}
@ -103,24 +106,27 @@ 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));
Tokenizer *tok = (Tokenizer *) tok_malloc(sizeof(Tokenizer));
tok->ifs = strdup(ifs ? ifs : IFS);
tok->argc = 0;
tok->amax = AINCR;
tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
tok->argv[0] = NULL;
tok->wspace = (char *) tok_malloc(WINCR);
tok->wmax = tok->wspace + WINCR;
tok->wstart = tok->wspace;
tok->wptr = tok->wspace;
tok->flags = 0;
tok->quote = Q_none;
tok->ifs = strdup(ifs ? ifs : 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,14 +134,14 @@ 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;
tok->flags = 0;
tok->quote = Q_none;
tok->argc = 0;
tok->wstart = tok->wspace;
tok->wptr = tok->wspace;
tok->flags = 0;
tok->quote = Q_none;
}
@ -143,13 +149,13 @@ 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);
tok_free((ptr_t) tok);
tok_free((ptr_t) tok->ifs);
tok_free((ptr_t) tok->wspace);
tok_free((ptr_t) tok->argv);
tok_free((ptr_t) tok);
}
@ -161,231 +167,232 @@ tok_end(tok)
* 3: Quoted return
* 2: Unmatched double quote
* 1: Unmatched single quote
* 0: Ok
* 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;
const char *ptr;
while (1) {
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 */
break;
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 */
break;
case Q_single: /* Exit single quote mode */
tok->quote = Q_none;
break;
case Q_single: /* Exit single quote mode */
tok->quote = Q_none;
break;
case Q_one: /* Quote this ' */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_one: /* Quote this ' */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_double: /* Stay in double quote mode */
*tok->wptr++ = *ptr;
break;
case Q_double: /* Stay in double quote mode */
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this ' */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this ' */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
return (-1);
}
break;
case '"':
tok->flags &= ~TOK_EAT;
tok->flags |= TOK_KEEP;
switch (tok->quote) {
case Q_none: /* Enter double quote mode */
tok->quote = Q_double;
break;
case '"':
tok->flags &= ~TOK_EAT;
tok->flags |= TOK_KEEP;
switch (tok->quote) {
case Q_none: /* Enter double quote mode */
tok->quote = Q_double;
break;
case Q_double:
tok->quote = Q_none; /* Exit double quote mode */
break;
case Q_double: /* Exit double quote mode */
tok->quote = Q_none;
break;
case Q_one: /* Quote this " */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_one: /* Quote this " */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this " */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this " */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
return (-1);
}
break;
case '\\':
tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none: /* Quote next character */
tok->quote = Q_one;
break;
case '\\':
tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none: /* Quote next character */
tok->quote = Q_one;
break;
case Q_double:
tok->quote = Q_doubleone;/* Quote next character */
break;
case Q_double: /* Quote next character */
tok->quote = Q_doubleone;
break;
case Q_one:
*tok->wptr++ = *ptr;
tok->quote = Q_none; /* Quote this, restore state */
break;
case Q_one: /* Quote this, restore state */
*tok->wptr++ = *ptr;
tok->quote = Q_none;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this \ */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this \ */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
return (-1);
}
break;
case '\n':
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return(0);
case '\n':
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return (0);
case Q_single:
case Q_double:
*tok->wptr++ = *ptr; /* Add the return */
break;
case Q_doubleone:
tok->flags |= TOK_EAT;
tok->quote = Q_double; /* Back to double, eat the '\n' */
break;
case Q_single:
case Q_double:
*tok->wptr++ = *ptr; /* Add the return */
break;
case Q_one:
tok->flags |= TOK_EAT;
tok->quote = Q_none; /* No quote, more eat the '\n' */
break;
case Q_doubleone: /* Back to double, eat the '\n' */
tok->flags |= TOK_EAT;
tok->quote = Q_double;
break;
default:
return(0);
}
break;
case Q_one: /* No quote, more eat the '\n' */
tok->flags |= TOK_EAT;
tok->quote = Q_none;
break;
case '\0':
switch (tok->quote) {
case Q_none:
/* Finish word and return */
if (tok->flags & TOK_EAT) {
tok->flags &= ~TOK_EAT;
return 3;
default:
return (0);
}
break;
case '\0':
switch (tok->quote) {
case Q_none:
/* Finish word and return */
if (tok->flags & TOK_EAT) {
tok->flags &= ~TOK_EAT;
return (3);
}
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return (0);
case Q_single:
return (1);
case Q_double:
return (2);
case Q_doubleone:
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return (-1);
}
break;
default:
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
if (strchr(tok->ifs, *ptr) != NULL)
tok_finish(tok);
else
*tok->wptr++ = *ptr;
break;
case Q_single:
case Q_double:
*tok->wptr++ = *ptr;
break;
case Q_doubleone:
*tok->wptr++ = '\\';
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return (-1);
}
break;
}
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return(0);
case Q_single:
return(1);
if (tok->wptr >= tok->wmax - 4) {
size_t size = tok->wmax - tok->wspace + WINCR;
char *s = (char *) tok_realloc(tok->wspace, size);
/* SUPPRESS 22 */
int offs = s - tok->wspace;
if (s == NULL)
return (-1);
case Q_double:
return(2);
case Q_doubleone:
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
if (strchr(tok->ifs, *ptr) != NULL)
tok_finish(tok);
else
*tok->wptr++ = *ptr;
break;
case Q_single:
case Q_double:
*tok->wptr++ = *ptr;
break;
case Q_doubleone:
*tok->wptr++ = '\\';
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
if (offs != 0) {
int i;
for (i = 0; i < tok->argc; i++)
tok->argv[i] = tok->argv[i] + offs;
tok->wptr = tok->wptr + offs;
tok->wstart = tok->wstart + offs;
tok->wmax = s + size;
tok->wspace = s;
}
}
if (tok->argc >= tok->amax - 4) {
char **p;
tok->amax += AINCR;
p = (char **) tok_realloc(tok->argv,
tok->amax * sizeof(char *));
if (p == NULL)
return (-1);
tok->argv = p;
}
}
if (tok->wptr >= tok->wmax - 4) {
size_t size = tok->wmax - tok->wspace + WINCR;
char *s = (char *) tok_realloc(tok->wspace, size);
/*SUPPRESS 22*/
int offs = s - tok->wspace;
if (offs != 0) {
int i;
for (i = 0; i < tok->argc; i++)
tok->argv[i] = tok->argv[i] + offs;
tok->wptr = tok->wptr + offs;
tok->wstart = tok->wstart + offs;
tok->wmax = s + size;
tok->wspace = s;
}
}
if (tok->argc >= tok->amax - 4) {
tok->amax += AINCR;
tok->argv = (char **) tok_realloc(tok->argv,
tok->amax * sizeof(char*));
}
}
}

View File

@ -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
@ -42,14 +42,13 @@
* tokenizer.h: Header file for tokenizer routines
*/
#ifndef _h_tokenizer
#define _h_tokenizer
#define _h_tokenizer
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 */

1893
tty.c

File diff suppressed because it is too large Load Diff

109
tty.h
View File

@ -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
@ -42,13 +42,14 @@
* el.tty.h: Local terminal header
*/
#ifndef _h_el_tty
#define _h_el_tty
#define _h_el_tty
#include "histedit.h"
#include <termios.h>
#include <unistd.h>
/* Define our own since everyone gets it wrong! */
#define CONTROL(A) ((A) & 037)
#define CONTROL(A) ((A) & 037)
/*
* Aix compatible names
@ -407,66 +408,66 @@
# endif /* NUMCC */
#endif /* !POSIX */
#define C_INTR 0
#define C_QUIT 1
#define C_ERASE 2
#define C_KILL 3
#define C_EOF 4
#define C_EOL 5
#define C_EOL2 6
#define C_SWTCH 7
#define C_DSWTCH 8
#define C_ERASE2 9
#define C_START 10
#define C_STOP 11
#define C_WERASE 12
#define C_SUSP 13
#define C_DSUSP 14
#define C_REPRINT 15
#define C_DISCARD 16
#define C_LNEXT 17
#define C_STATUS 18
#define C_PAGE 19
#define C_PGOFF 20
#define C_KILL2 21
#define C_BRK 22
#define C_MIN 23
#define C_TIME 24
#define C_NCC 25
#define C_SH(A) (1 << (A))
#define C_INTR 0
#define C_QUIT 1
#define C_ERASE 2
#define C_KILL 3
#define C_EOF 4
#define C_EOL 5
#define C_EOL2 6
#define C_SWTCH 7
#define C_DSWTCH 8
#define C_ERASE2 9
#define C_START 10
#define C_STOP 11
#define C_WERASE 12
#define C_SUSP 13
#define C_DSUSP 14
#define C_REPRINT 15
#define C_DISCARD 16
#define C_LNEXT 17
#define C_STATUS 18
#define C_PAGE 19
#define C_PGOFF 20
#define C_KILL2 21
#define C_BRK 22
#define C_MIN 23
#define C_TIME 24
#define C_NCC 25
#define C_SH(A) (1 << (A))
/*
* Terminal dependend data structures
*/
#define EX_IO 0 /* while we are executing */
#define ED_IO 1 /* while we are editing */
#define TS_IO 2 /* new mode from terminal */
#define QU_IO 2 /* used only for quoted chars */
#define NN_IO 3 /* The number of entries */
#define EX_IO 0 /* while we are executing */
#define ED_IO 1 /* while we are editing */
#define TS_IO 2 /* new mode from terminal */
#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];
typedef struct {
char *t_name;
u_int t_setmask;
u_int t_clrmask;
} 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;

1012
vi.c

File diff suppressed because it is too large Load Diff