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 # @(#)Makefile 8.1 (Berkeley) 6/4/93
LIB= edit 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 \ 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_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_parse.3 editline.3 el_set.3 editline.3 el_get.3 \
editline.3 el_resize.3 editline.3 el_line.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 el_insertstr.3 editline.3 el_deletestr.3 \
editline.3 history_init.3 editline.3 history_end.3 editline.3 history.3 editline.3 history_init.3 editline.3 history_end.3 editline.3 history.3
# For speed and debugging # For speed and debugging
#SRCS= ${OSRCS} tokenizer.c history.c #SRCS= ${OSRCS} tokenizer.c history.c readline.c
# For protection # 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 SRCS+= common.h emacs.h fcns.h help.h vi.h
LIBEDITDIR?=${.CURDIR}
INCS= histedit.h INCS= histedit.h
INCSDIR=/usr/include INCSDIR=/usr/include
CLEANFILES+=common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h CLEANFILES+=common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h
CFLAGS+=-I. -I${.CURDIR} CLEANFILES+=common.h.tmp editline.c.tmp emacs.h.tmp fcns.c.tmp fcns.h.tmp
CFLAGS+=#-DDEBUG_TTY -DDEBUG_KEY -DDEBUG_READ -DDEBUG -DDEBUG_REFRESH CLEANFILES+=help.c.tmp help.h.tmp vi.h.tmp
CFLAGS+=#-DDEBUG_PASTE 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 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 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 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 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 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 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 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 help.h: ${ASRC} makelist
sh ${.CURDIR}/makelist -bh ${ASRC} > ${.TARGET} sh ${LIBEDITDIR}/makelist -bh ${ASRC} > ${.TARGET}.tmp && \
mv ${.TARGET}.tmp ${.TARGET}
editline.c: ${OSRCS} 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 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.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 * Copyright (c) 1992, 1993
@ -36,17 +36,17 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#ifndef lint #ifndef lint
static char copyright[] = __COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
"@(#) Copyright (c) 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n");
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
#else #else
static char rcsid[] = "$NetBSD"; __RCSID("$NetBSD: test.c,v 1.9 2000/09/04 23:36:41 lukem Exp $");
#endif #endif
#endif /* not lint && not SCCSID */ #endif /* not lint && not SCCSID */
@ -69,182 +69,200 @@ static char rcsid[] = "$NetBSD";
static int continuation = 0; static int continuation = 0;
static EditLine *el = NULL; static EditLine *el = NULL;
static u_char complete(EditLine *, int);
int main(int, char **);
static char *prompt(EditLine *);
static void sig(int);
static char * static char *
/*ARGSUSED*/ prompt(EditLine *el)
prompt(el)
EditLine *el;
{ {
static char a[] = "Edit$"; static char a[] = "Edit$";
static char b[] = "Edit>"; static char b[] = "Edit>";
return continuation ? b : a;
return (continuation ? b : a);
} }
static void static void
sig(i) sig(int i)
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 static unsigned char
/*ARGSUSED*/ complete(EditLine *el, int ch)
complete(el, ch)
EditLine *el;
int ch;
{ {
DIR *dd = opendir("."); DIR *dd = opendir(".");
struct dirent *dp; struct dirent *dp;
const char* ptr; const char* ptr;
const LineInfo *lf = el_line(el); const LineInfo *lf = el_line(el);
int len; int len;
/* /*
* Find the last word * Find the last word
*/ */
for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--) for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
continue; continue;
len = lf->cursor - ++ptr; len = lf->cursor - ++ptr;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) { for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name)) if (len > strlen(dp->d_name))
continue; continue;
if (strncmp(dp->d_name, ptr, len) == 0) { if (strncmp(dp->d_name, ptr, len) == 0) {
closedir(dd); closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1) if (el_insertstr(el, &dp->d_name[len]) == -1)
return CC_ERROR; return (CC_ERROR);
else else
return CC_REFRESH; return (CC_REFRESH);
}
} }
}
closedir(dd); closedir(dd);
return CC_ERROR; return (CC_ERROR);
} }
int int
/*ARGSUSED*/ main(int argc, char *argv[])
main(argc, argv)
int argc;
char *argv[];
{ {
int num; int num;
const char *buf; const char *buf;
Tokenizer *tok; Tokenizer *tok;
History *hist; int lastevent = 0, ncontinuation;
History *hist;
HistEvent ev;
(void) signal(SIGINT, sig); (void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig); (void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig); (void) signal(SIGHUP, sig);
(void) signal(SIGTERM, sig); (void) signal(SIGTERM, sig);
hist = history_init(); /* Init the builtin history */ hist = history_init(); /* Init the builtin history */
history(hist, H_EVENT, 100); /* Remember 100 events */ /* Remember 100 events */
history(hist, &ev, H_SETSIZE, 100);
tok = tok_init(NULL); /* Initialize the tokenizer */ 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_EDITOR, "vi"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */ el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
el_set(el, EL_PROMPT, prompt); /* Set the prompt function */ el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
/* Tell editline to use this history interface */ /* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist); el_set(el, EL_HIST, history, hist);
/* Add a user-defined function */ /* Add a user-defined function */
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete); 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 * Bind j, k in vi command mode to previous and next line, instead
* of previous and next history. * of previous and next history.
*/ */
el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL); el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL); el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
/* /*
* Source the user's defaults file. * Source the user's defaults file.
*/ */
el_source(el, NULL); el_source(el, NULL);
while ((buf = el_gets(el, &num)) != NULL && num != 0) { while ((buf = el_gets(el, &num)) != NULL && num != 0) {
int ac; int ac;
char **av; char **av;
#ifdef DEBUG #ifdef DEBUG
(void) fprintf(stderr, "got %d %s", num, buf); (void) fprintf(stderr, "got %d %s", num, buf);
#endif #endif
if (!continuation && num == 1) if (!continuation && num == 1)
continue; continue;
if (tok_line(tok, buf, &ac, &av) > 0) { if (tok_line(tok, buf, &ac, &av) > 0)
history(hist, continuation ? H_ADD : H_ENTER, buf); ncontinuation = 1;
continuation = 1;
continue; #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; return (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;
} }

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 * Copyright (c) 1992, 1993
@ -42,61 +42,61 @@
* el.chared.h: Character editor interface * el.chared.h: Character editor interface
*/ */
#ifndef _h_el_chared #ifndef _h_el_chared
#define _h_el_chared #define _h_el_chared
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include "histedit.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 * 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 * like real vi: i.e. the transition from command<->insert modes moves
* the cursor. * 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. * 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 * Probably the best fix is to make all the editing commands aware of
* this fact. * this fact.
*/ */
#define VI_MOVE #define VI_MOVE
typedef struct c_macro_t { typedef struct c_macro_t {
int level; int level;
char **macro; char **macro;
char *nline; char *nline;
} c_macro_t; } c_macro_t;
/* /*
* Undo information for both vi and emacs * Undo information for both vi and emacs
*/ */
typedef struct c_undo_t { typedef struct c_undo_t {
int action; int action;
int isize; size_t isize;
int dsize; size_t dsize;
char *ptr; char *ptr;
char *buf; char *buf;
} c_undo_t; } c_undo_t;
/* /*
* Current action information for vi * Current action information for vi
*/ */
typedef struct c_vcmd_t { typedef struct c_vcmd_t {
int action; int action;
char *pos; char *pos;
char *ins; char *ins;
} c_vcmd_t; } c_vcmd_t;
/* /*
* Kill buffer for emacs * Kill buffer for emacs
*/ */
typedef struct c_kill_t { typedef struct c_kill_t {
char *buf; char *buf;
char *last; char *last;
char *mark; char *mark;
} c_kill_t; } c_kill_t;
/* /*
@ -104,30 +104,30 @@ typedef struct c_kill_t {
* commands from both editors! * commands from both editors!
*/ */
typedef struct el_chared_t { typedef struct el_chared_t {
c_undo_t c_undo; c_undo_t c_undo;
c_kill_t c_kill; c_kill_t c_kill;
c_vcmd_t c_vcmd; c_vcmd_t c_vcmd;
c_macro_t c_macro; c_macro_t c_macro;
} el_chared_t; } el_chared_t;
#define STReof "^D\b\b" #define STReof "^D\b\b"
#define STRQQ "\"\"" #define STRQQ "\"\""
#define isglob(a) (strchr("*[]?", (a)) != NULL) #define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (isprint(a)) #define isword(a) (isprint(a))
#define NOP 0x00 #define NOP 0x00
#define DELETE 0x01 #define DELETE 0x01
#define INSERT 0x02 #define INSERT 0x02
#define CHANGE 0x04 #define CHANGE 0x04
#define CHAR_FWD 0 #define CHAR_FWD 0
#define CHAR_BACK 1 #define CHAR_BACK 1
#define MODE_INSERT 0 #define MODE_INSERT 0
#define MODE_REPLACE 1 #define MODE_REPLACE 1
#define MODE_REPLACE_1 2 #define MODE_REPLACE_1 2
#include "common.h" #include "common.h"
#include "vi.h" #include "vi.h"
@ -136,25 +136,24 @@ typedef struct el_chared_t {
#include "fcns.h" #include "fcns.h"
protected int cv__isword __P((int)); protected int cv__isword(int);
protected void cv_delfini __P((EditLine *)); protected void cv_delfini(EditLine *);
protected char *cv__endword __P((char *, char *, int)); protected char *cv__endword(char *, char *, int);
protected int ce__isword __P((int)); protected int ce__isword(int);
protected void cv_undo __P((EditLine *, int, int, char *)); protected void cv_undo(EditLine *, int, size_t, char *);
protected char *cv_next_word __P((EditLine*, char *, char *, int, protected char *cv_next_word(EditLine*, char *, char *, int, int (*)(int));
int (*)(int))); protected char *cv_prev_word(EditLine*, char *, char *, int, int (*)(int));
protected char *cv_prev_word __P((EditLine*, char *, char *, int, protected char *c__next_word(char *, char *, int, int (*)(int));
int (*)(int))); protected char *c__prev_word(char *, char *, int, int (*)(int));
protected char *c__next_word __P((char *, char *, int, int (*)(int))); protected void c_insert(EditLine *, int);
protected char *c__prev_word __P((char *, char *, int, int (*)(int))); protected void c_delbefore(EditLine *, int);
protected void c_insert __P((EditLine *, int)); protected void c_delafter(EditLine *, int);
protected void c_delbefore __P((EditLine *, int)); protected int c_gets(EditLine *, char *);
protected void c_delafter __P((EditLine *, int)); protected int c_hpos(EditLine *);
protected int c_gets __P((EditLine *, char *));
protected int c_hpos __P((EditLine *));
protected int ch_init __P((EditLine *)); protected int ch_init(EditLine *);
protected void ch_reset __P((EditLine *)); protected void ch_reset(EditLine *);
protected void ch_end __P((EditLine *)); protected int ch_enlargebufs __P((EditLine *, size_t));
protected void ch_end(EditLine *);
#endif /* _h_el_chared */ #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. .\" All rights reserved.
.\" .\"
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn. .\" 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 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" 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 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE. .\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd January 11, 1997 .Dd November 12, 1999
.Os BSD 4.4 .Os
.Dt EDITLINE 3 .Dt EDITLINE 3
.Sh NAME .Sh NAME
.Nm editline , .Nm editline ,
@ -55,10 +55,12 @@
.Nm history_end , .Nm history_end ,
.Nm history .Nm history
.Nd line editor and history functions .Nd line editor and history functions
.Sh LIBRARY
.Lb libedit
.Sh SYNOPSIS .Sh SYNOPSIS
.Fd #include <histedit.h> .Fd #include <histedit.h>
.Ft EditLine * .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 .Ft void
.Fn el_end "EditLine *e" .Fn el_end "EditLine *e"
.Ft void .Ft void
@ -74,21 +76,23 @@
.Ft int .Ft int
.Fn el_set "EditLine *e" "int op" "..." .Fn el_set "EditLine *e" "int op" "..."
.Ft int .Ft int
.Fn el_get "EditLine *e" "int op" "void *result"
.Ft int
.Fn el_source "EditLine *e" "const char *file" .Fn el_source "EditLine *e" "const char *file"
.Ft void .Ft void
.Fn el_resize "EditLine *e" .Fn el_resize "EditLine *e"
.Ft const LineInfo * .Ft const LineInfo *
.Fn el_line "EditLine *e" .Fn el_line "EditLine *e"
.Ft int .Ft int
.Fn el_insertstr "EditLine *e" "char *str" .Fn el_insertstr "EditLine *e" "const char *str"
.Ft void .Ft void
.Fn el_deletestr "EditLine *e" "int count" .Fn el_deletestr "EditLine *e" "int count"
.Ft History * .Ft History *
.Fn history_init .Fn history_init
.Ft void .Ft void
.Fn history_end "History *h" .Fn history_end "History *h"
.Ft HistEvent * .Ft int
.Fn history "History h" "int op" "..." .Fn history "History *h" "HistEvent *ev" "int op" "..."
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Nm .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 is the name of the invoking program, used when reading the
.Xr editrc 5 .Xr editrc 5
file to determine which settings to use. file to determine which settings to use.
.Fa fin .Fa fin ,
and
.Fa fout .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 In this documentation, references to
.Dq the tty .Dq the tty
are actually to this input/output stream combination. are actually to this input/output stream combination.
@ -187,19 +192,6 @@ didn't match, or
Refer to Refer to
.Xr editrc 5 .Xr editrc 5
for more information. 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 .It Fn el_set
Set Set
.Nm .Nm
@ -216,6 +208,10 @@ are supported, along with the required argument list:
Define prompt printing function as Define prompt printing function as
.Fa f , .Fa f ,
which is to return a string that contains the prompt. 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" .It Dv EL_TERMINAL , Fa "const char *type"
Define terminal type of the tty to be Define terminal type of the tty to be
.Fa type , .Fa type ,
@ -257,7 +253,7 @@ Otherwise, the current signal handlers will be used.
Perform the Perform the
.Ic bind .Ic bind
builtin command. builtin command.
Refer to Refer to
.Xr editrc 5 .Xr editrc 5
for more information. for more information.
.It Dv EL_ECHOTC , Xo .It Dv EL_ECHOTC , Xo
@ -268,7 +264,7 @@ for more information.
Perform the Perform the
.Ic echotc .Ic echotc
builtin command. builtin command.
Refer to Refer to
.Xr editrc 5 .Xr editrc 5
for more information. for more information.
.It Dv EL_SETTC , Xo .It Dv EL_SETTC , Xo
@ -279,7 +275,7 @@ for more information.
Perform the Perform the
.Ic settc .Ic settc
builtin command. builtin command.
Refer to Refer to
.Xr editrc 5 .Xr editrc 5
for more information. for more information.
.It Dv EL_SETTY , Xo .It Dv EL_SETTY , Xo
@ -290,7 +286,7 @@ for more information.
Perform the Perform the
.Ic setty .Ic setty
builtin command. builtin command.
Refer to Refer to
.Xr editrc 5 .Xr editrc 5
for more information. for more information.
.It Dv EL_TELLTC , Xo .It Dv EL_TELLTC , Xo
@ -301,7 +297,7 @@ for more information.
Perform the Perform the
.Ic telltc .Ic telltc
builtin command. builtin command.
Refer to Refer to
.Xr editrc 5 .Xr editrc 5
for more information. for more information.
.It Dv EL_ADDFN , Xo .It Dv EL_ADDFN , Xo
@ -336,6 +332,8 @@ EOF was entered.
Expecting further command input as arguments, do nothing visually. Expecting further command input as arguments, do nothing visually.
.It Dv CC_REFRESH .It Dv CC_REFRESH
Refresh display. Refresh display.
.It Dv CC_REFRESH_BEEP
Refresh display, and beep.
.It Dv CC_CURSOR .It Dv CC_CURSOR
Cursor moved, so update and perform Cursor moved, so update and perform
.Dv CC_REFRESH. .Dv CC_REFRESH.
@ -357,11 +355,69 @@ Defines which history function to use, which is usually
.Fa ptr .Fa ptr
should be the value returned by should be the value returned by
.Fn history_init . .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 .El
.It Fn el_source .It Fn el_source
Initialise Initialise
.Nm .Nm
by reading the contents of by reading the contents of
.Fa file . .Fa file .
.Fn el_parse .Fn el_parse
is called for each line in is called for each line in
@ -434,14 +490,18 @@ Perform operation
.Fa op .Fa op
on the history list, with optional arguments as needed by the on the history list, with optional arguments as needed by the
operation. operation.
.Fa ev
is changed accordingly to operation.
The following values for The following values for
.Fa op .Fa op
are supported, along with the required argument list: are supported, along with the required argument list:
.Bl -tag -width 4n .Bl -tag -width 4n
.It Dv H_EVENT , Fa "int size" .It Dv H_SETSIZE , Fa "int size"
Set size of history to Set size of history to
.Fa size .Fa size
elements. elements.
.It Dv H_GETSIZE
Get number of events currently in history.
.It Dv H_END .It Dv H_END
Cleans up and finishes with Cleans up and finishes with
.Fa h , .Fa h ,
@ -456,6 +516,7 @@ Clear the history.
.Fa "history_gfun_t last" , .Fa "history_gfun_t last" ,
.Fa "history_gfun_t prev" , .Fa "history_gfun_t prev" ,
.Fa "history_gfun_t curr" , .Fa "history_gfun_t curr" ,
.Fa "history_sfun_t set" ,
.Fa "history_vfun_t clear" , .Fa "history_vfun_t clear" ,
.Fa "history_efun_t enter" , .Fa "history_efun_t enter" ,
.Fa "history_efun_t add" .Fa "history_efun_t add"
@ -473,16 +534,20 @@ Return the previous element in the history.
Return the next element in the history. Return the next element in the history.
.It Dv H_CURR .It Dv H_CURR
Return the current element in the history. 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" .It Dv H_ADD , Fa "const char *str"
Append Append
.Fa str .Fa str
to the current element of the history, or create an element with to the current element of the history, or create an element with
.Dv H_ENTER .It Dv H_APPEND , Fa "const char *str"
if there isn't one. Append
.Fa str
to the last new element of the history.
.It Dv H_ENTER , Fa "const char *str" .It Dv H_ENTER , Fa "const char *str"
Add Add
.Fa str .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. removing the oldest entry to keep the list to the created size.
.It Dv H_PREV_STR , Fa "const char *str" .It Dv H_PREV_STR , Fa "const char *str"
Return the closest previous event that starts with Return the closest previous event that starts with
@ -503,6 +568,13 @@ Load the history list stored in
Save the history list to Save the history list to
.Fa file . .Fa file .
.El .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 .El
.\"XXX.Sh EXAMPLES .\"XXX.Sh EXAMPLES
.\"XXX: provide some examples .\"XXX: provide some examples
@ -516,17 +588,46 @@ The
.Nm .Nm
library first appeared in library first appeared in
.Bx 4.4 . .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 .Sh AUTHORS
The The
.Nm .Nm
library was written by Christos Zoulas, library was written by Christos Zoulas.
and this manual was written by Luke Mewburn. 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 .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 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. .\" All rights reserved.
.\" .\"
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn. .\" 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 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" 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 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE. .\" POSSIBILITY OF SUCH DAMAGE.
.\" .\"
.Dd January 11, 1997 .Dd November 8, 2000
.Os BSD 4.4 .Os
.Dt EDITRC 5 .Dt EDITRC 5
.Sh NAME .Sh NAME
.Nm editrc .Nm editrc
@ -48,10 +48,8 @@ file defines various settings to be used by the
.Xr editline 3 .Xr editline 3
library. library.
.Pp .Pp
The format of each line is either: The format of each line is:
.Dl prog:command [arg [...]] .Dl [prog:]command [arg [...]]
or
.Dl command [arg [...]]
.Pp .Pp
.Ar command .Ar command
is one of the is one of the
@ -61,7 +59,7 @@ Refer to
.Sx BUILTIN COMMANDS .Sx BUILTIN COMMANDS
for more information. for more information.
.Pp .Pp
.Ar prog .Ar prog
is the program name string that a program defines when it calls is the program name string that a program defines when it calls
.Xr el_init 3 .Xr el_init 3
to setup to setup
@ -79,6 +77,12 @@ style
regular expression, in which case regular expression, in which case
.Ar command .Ar command
will be executed for any program that matches the regular expression. 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 .Sh BUILTIN COMMANDS
The The
.Nm editline .Nm editline
@ -117,11 +121,11 @@ Options include:
.It Fl e .It Fl e
Bind all keys to the standard GNU Emacs-like bindings. Bind all keys to the standard GNU Emacs-like bindings.
.It Fl v .It Fl v
Bind all keys to the standard Bind all keys to the standard
.Xr vi 1 -like .Xr vi 1 -like
bindings. bindings.
.It Fl a .It Fl a
List or change key bindings in the List or change key bindings in the
.Xr vi 1 .Xr vi 1
mode alternate (command mode) key map. mode alternate (command mode) key map.
.It Fl k .It Fl k
@ -147,6 +151,11 @@ are themselves reinterpreted, and this continues for ten levels of
interpretation. interpretation.
.El .El
.Pp .Pp
.Ar command
may be one of the commands documented in
.Sx "EDITOR COMMANDS"
below, or another key.
.Pp
.Ar key .Ar key
and and
.Ar command .Ar command
@ -213,10 +222,14 @@ or
indicating that the terminal does or does not have that capability. indicating that the terminal does or does not have that capability.
.Pp .Pp
.Fl s .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. causing an error.
.Fl v .Fl v
causes messages to be verbose. 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 .It Ic history
List the history. List the history.
.It Ic telltc .It Ic telltc
@ -279,6 +292,192 @@ on or off or removes control of
.Ar mode .Ar mode
in the chosen set. in the chosen set.
.El .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 .Sh SEE ALSO
.Xr editline 3 , .Xr editline 3 ,
.Xr regex 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 * Copyright (c) 1992, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else #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
#endif /* not lint && not SCCSID */ #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 <sys/param.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef __STDC__ #include <stdarg.h>
# include <stdarg.h>
#else
# include <varargs.h>
#endif
#include "el.h" #include "el.h"
/* el_init(): /* el_init():
* Initialize editline and set default parameters. * Initialize editline and set default parameters.
*/ */
public EditLine * public EditLine *
el_init(prog, fin, fout) el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
const char *prog;
FILE *fin, *fout;
{ {
EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
#ifdef DEBUG #ifdef DEBUG
char *tty; char *tty;
#endif #endif
if (el == NULL) if (el == NULL)
return NULL; return (NULL);
memset(el, 0, sizeof(EditLine)); memset(el, 0, sizeof(EditLine));
el->el_infd = fileno(fin); el->el_infd = fileno(fin);
el->el_outfile = fout; el->el_outfile = fout;
el->el_prog = strdup(prog); el->el_errfile = ferr;
el->el_prog = strdup(prog);
#ifdef DEBUG /*
if ((tty = getenv("DEBUGTTY")) != NULL) { * Initialize all the modules. Order is important!!!
el->el_errfile = fopen(tty, "w"); */
if (el->el_errfile == NULL) { el->el_flags = 0;
extern errno;
(void) fprintf(stderr, "Cannot open %s (%s).\n",
tty, strerror(errno));
return NULL;
}
}
else
#endif
el->el_errfile = stderr;
/* (void) term_init(el);
* Initialize all the modules. Order is important!!! (void) key_init(el);
*/ (void) map_init(el);
(void) term_init(el); if (tty_init(el) == -1)
(void) tty_init(el); el->el_flags |= NO_TTY;
(void) key_init(el); (void) ch_init(el);
(void) map_init(el); (void) search_init(el);
(void) ch_init(el); (void) hist_init(el);
(void) search_init(el); (void) prompt_init(el);
(void) hist_init(el); (void) sig_init(el);
(void) prompt_init(el); (void) read_init(el);
(void) sig_init(el);
el->el_flags = 0;
return el; return (el);
} /* end el_init */ }
/* el_end(): /* el_end():
* Clean up. * Clean up.
*/ */
public void public void
el_end(el) el_end(EditLine *el)
EditLine *el;
{ {
if (el == NULL)
return;
el_reset(el); if (el == NULL)
return;
term_end(el); el_reset(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_free((ptr_t) el->el_prog); term_end(el);
el_free((ptr_t) el); key_end(el);
} /* end el_end */ 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(): /* el_reset():
* Reset the tty and the parser * Reset the tty and the parser
*/ */
public void public void
el_reset(el) el_reset(EditLine *el)
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 * set the editline parameters
*/ */
public int public int
#ifdef __STDC__
el_set(EditLine *el, int op, ...) el_set(EditLine *el, int op, ...)
#else
el_set(va_alist)
va_dcl
#endif
{ {
va_list va; va_list va;
int rv; int rv;
#ifdef __STDC__
va_start(va, op);
#else
EditLine *el;
int op;
va_start(va); if (el == NULL)
el = va_arg(va, EditLine *); return (-1);
op = va_arg(va, int); va_start(va, op);
#endif
switch (op) {
case EL_PROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t));
break;
case EL_TERMINAL: switch (op) {
rv = term_set(el, va_arg(va, char *)); case EL_PROMPT:
break; case EL_RPROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t), op);
break;
case EL_EDITOR: case EL_TERMINAL:
rv = map_set_editor(el, va_arg(va, char *)); rv = term_set(el, va_arg(va, char *));
break; break;
case EL_SIGNAL: case EL_EDITOR:
if (va_arg(va, int)) rv = map_set_editor(el, va_arg(va, char *));
el->el_flags |= HANDLE_SIGNALS; break;
else
el->el_flags &= ~HANDLE_SIGNALS;
rv = 0;
break;
case EL_BIND: case EL_SIGNAL:
case EL_TELLTC: if (va_arg(va, int))
case EL_SETTC: el->el_flags |= HANDLE_SIGNALS;
case EL_ECHOTC: else
case EL_SETTY: 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]; char *argv[20];
int i; int i;
for (i = 1; i < 20; i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
break;
switch (op) { for (i = 1; i < 20; i++)
case EL_BIND: if ((argv[i] = va_arg(va, char *)) == NULL)
argv[0] = "bind"; break;
rv = map_bind(el, i, argv);
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; break;
case EL_TELLTC: case EL_GETCFN:
argv[0] = "telltc"; {
rv = term_telltc(el, i, argv); el_rfunc_t rc = va_arg(va, el_rfunc_t);
rv = el_read_setfn(el, rc);
break; break;
}
case EL_SETTC: default:
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; 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_EDITOR:
break; rv = map_get_editor(el, (const char **) &ret);
break;
case EL_ADDFN:
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 *argv[20];
char *help = va_arg(va, char *); int i;
el_func_t func = va_arg(va, el_func_t);
rv = map_addfunc(el, name, help, func);
}
break;
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); char *name = va_arg(va, char *);
ptr_t ptr = va_arg(va, char *); char *help = va_arg(va, char *);
rv = hist_set(el, func, ptr); el_func_t func = va_arg(va, el_func_t);
rv = map_addfunc(el, name, help, func);
break;
} }
break;
default: case EL_HIST:
rv = -1; {
} 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); case EL_GETCFN:
return rv; *((el_rfunc_t *)ret) = el_read_getfn(el);
} /* end el_set */ rv = 0;
break;
default:
rv = -1;
}
return (rv);
}
/* el_line(): /* el_line():
* Return editing info * Return editing info
*/ */
public const LineInfo * public const LineInfo *
el_line(el) el_line(EditLine *el)
EditLine *el;
{ {
return (const LineInfo *) &el->el_line;
return (const LineInfo *) (void *) &el->el_line;
} }
static const char elpath[] = "/.editrc"; static const char elpath[] = "/.editrc";
@ -286,39 +394,41 @@ static const char elpath[] = "/.editrc";
* Source a file * Source a file
*/ */
public int public int
el_source(el, fname) el_source(EditLine *el, const char *fname)
EditLine *el;
const char *fname;
{ {
FILE *fp; FILE *fp;
size_t len; size_t len;
char *ptr, path[MAXPATHLEN]; char *ptr, path[MAXPATHLEN];
if (fname == NULL) { fp = NULL;
fname = &elpath[1]; if (fname == NULL) {
if ((fp = fopen(fname, "r")) == NULL) { if (issetugid())
if ((ptr = getenv("HOME")) == NULL) return (-1);
return -1; if ((ptr = getenv("HOME")) == NULL)
(void)snprintf(path, sizeof(path), "%s%s", ptr, elpath); return (-1);
fname = path; 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) while ((ptr = fgetln(fp, &len)) != NULL) {
return -1; if (len > 0 && ptr[len - 1] == '\n')
--len;
while ((ptr = fgetln(fp, &len)) != NULL) { ptr[len] = '\0';
if (ptr[len - 1] == '\n') if (parse_line(el, ptr) == -1) {
--len; (void) fclose(fp);
ptr[len] = '\0'; return (-1);
if (parse_line(el, ptr) == -1) { }
(void) fclose(fp);
return -1;
} }
}
(void) fclose(fp); (void) fclose(fp);
return 0; return (0);
} }
@ -326,18 +436,54 @@ el_source(el, fname)
* Called from program when terminal is resized * Called from program when terminal is resized
*/ */
public void public void
el_resize(el) el_resize(EditLine *el)
EditLine *el;
{ {
int lins, cols; int lins, cols;
sigset_t oset, nset; sigset_t oset, nset;
(void) sigemptyset(&nset);
(void) sigaddset(&nset, SIGWINCH);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
/* get the correct window size */ (void) sigemptyset(&nset);
if (term_get_size(el, &lins, &cols)) (void) sigaddset(&nset, SIGWINCH);
term_change_size(el, lins, cols); (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 * Copyright (c) 1992, 1993
@ -42,53 +42,56 @@
* el.h: Internal structures. * el.h: Internal structures.
*/ */
#ifndef _h_el #ifndef _h_el
#define _h_el #define _h_el
/* /*
* Local defaults * Local defaults
*/ */
#define KSHVI #define KSHVI
#define VIDEFAULT #define VIDEFAULT
#define ANCHOR #define ANCHOR
#include <stdio.h> #include <stdio.h>
#include <sys/types.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 int bool_t; /* True or not */
typedef unsigned char el_action_t; /* Index to command array */ typedef unsigned char el_action_t; /* Index to command array */
typedef struct coord_t { /* Position on the screen */ typedef struct coord_t { /* Position on the screen */
int h, v; int h;
int v;
} coord_t; } coord_t;
typedef struct el_line_t { typedef struct el_line_t {
char *buffer, /* Input line */ char *buffer; /* Input line */
*cursor, /* Cursor position */ char *cursor; /* Cursor position */
*lastchar, /* Last character */ char *lastchar; /* Last character */
*limit; /* Max position */ const char *limit; /* Max position */
} el_line_t; } el_line_t;
/* /*
* Editor state * Editor state
*/ */
typedef struct el_state_t { typedef struct el_state_t {
int inputmode; /* What mode are we in? */ int inputmode; /* What mode are we in? */
int doingarg; /* Are we getting an argument? */ int doingarg; /* Are we getting an argument? */
int argument; /* Numeric argument */ int argument; /* Numeric argument */
int metanext; /* Is the next char a meta char */ int metanext; /* Is the next char a meta char */
el_action_t lastcmd; /* Previous command */ el_action_t lastcmd; /* Previous command */
} el_state_t; } el_state_t;
/* /*
* Until we come up with something better... * Until we come up with something better...
*/ */
#define el_malloc(a) malloc(a) #define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b) #define el_realloc(a,b) realloc(a, b)
#define el_free(a) free(a) #define el_free(a) free(a)
#include "tty.h" #include "tty.h"
#include "prompt.h" #include "prompt.h"
@ -103,29 +106,39 @@ typedef struct el_state_t {
#include "parse.h" #include "parse.h"
#include "sig.h" #include "sig.h"
#include "help.h" #include "help.h"
#include "read.h"
struct editline { struct editline {
char *el_prog; /* the program name */ char *el_prog; /* the program name */
FILE *el_outfile; /* Stdio stuff */ FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */ FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */ int el_infd; /* Input file descriptor */
int el_flags; /* Various flags. */ int el_flags; /* Various flags. */
coord_t el_cursor; /* Cursor location */ coord_t el_cursor; /* Cursor location */
char **el_display, /* Real screen image = what is there */ char **el_display; /* Real screen image = what is there */
**el_vdisplay; /* Virtual screen image = what we see */ char **el_vdisplay; /* Virtual screen image = what we see */
el_line_t el_line; /* The current line information */
el_line_t el_line; /* The current line information */ el_state_t el_state; /* Current editor state */
el_state_t el_state; /* Current editor state */ el_term_t el_term; /* Terminal dependent stuff */
el_term_t el_term; /* Terminal dependent stuff */ el_tty_t el_tty; /* Tty dependent stuff */
el_tty_t el_tty; /* Tty dependent stuff */ el_refresh_t el_refresh; /* Refresh stuff */
el_refresh_t el_refresh; /* Refresh stuff */ el_prompt_t el_prompt; /* Prompt stuff */
el_prompt_t el_prompt; /* Prompt stuff */ el_prompt_t el_rprompt; /* Prompt stuff */
el_chared_t el_chared; /* Characted editor stuff */ el_chared_t el_chared; /* Characted editor stuff */
el_map_t el_map; /* Key mapping stuff */ el_map_t el_map; /* Key mapping stuff */
el_key_t el_key; /* Key binding stuff */ el_key_t el_key; /* Key binding stuff */
el_history_t el_history; /* History stuff */ el_history_t el_history; /* History stuff */
el_search_t el_search; /* Search stuff */ el_search_t el_search; /* Search stuff */
el_signal_t el_signal; /* Signal handling 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 */ #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 * Copyright (c) 1992, 1993
@ -36,15 +36,16 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
#else #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
#endif /* not lint && not SCCSID */ #endif /* not lint && not SCCSID */
/* /*
* emacs.c: Emacs functions * emacs.c: Emacs functions
*/ */
#include "sys.h" #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 protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_delete_or_list(el, c) em_delete_or_list(EditLine *el, int c)
EditLine *el;
int c;
{ {
if (el->el_line.cursor == el->el_line.lastchar) { /* if I'm at the end */
if (el->el_line.cursor == el->el_line.buffer) { /* and the beginning */ if (el->el_line.cursor == el->el_line.lastchar) {
term_overwrite(el, STReof, 4);/* then do a EOF */ /* if I'm at the end */
term__flush(); if (el->el_line.cursor == el->el_line.buffer) {
return CC_EOF; /* 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 protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_delete_next_word(el, c) em_delete_next_word(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *cp, *p, *kp; char *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.lastchar) if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR; return (CC_ERROR);
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar, cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword); el->el_state.argument, ce__isword);
for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++) for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
/* save the text */ /* save the text */
*kp++ = *p; *kp++ = *p;
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.cursor); /* delete after dot */ c_delafter(el, cp - el->el_line.cursor); /* delete after dot */
if (el->el_line.cursor > el->el_line.lastchar) if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar; /* bounds check */ el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH; /* bounds check */
return (CC_REFRESH);
} }
@ -117,34 +120,34 @@ em_delete_next_word(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_yank(el, c) em_yank(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *kp, *cp; char *kp, *cp;
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) {
return CC_ERROR; if (!ch_enlargebufs(el, 1))
return (CC_ERROR);
}
if (el->el_line.lastchar + if (el->el_line.lastchar +
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >= (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
el->el_line.limit) el->el_line.limit)
return CC_ERROR; return (CC_ERROR);
el->el_chared.c_kill.mark = el->el_line.cursor; el->el_chared.c_kill.mark = el->el_line.cursor;
cp = el->el_line.cursor; cp = el->el_line.cursor;
/* open the space, */ /* open the space, */
c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf); c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
/* copy the chars */ /* copy the chars */
for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++) for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
*cp++ = *kp; *cp++ = *kp;
/* if an arg, cursor at beginning else cursor at end */ /* if an arg, cursor at beginning else cursor at end */
if (el->el_state.argument == 1) if (el->el_state.argument == 1)
el->el_line.cursor = cp; el->el_line.cursor = cp;
return CC_REFRESH; return (CC_REFRESH);
} }
@ -154,20 +157,19 @@ em_yank(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_kill_line(el, c) em_kill_line(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *kp, *cp; char *kp, *cp;
cp = el->el_line.buffer; cp = el->el_line.buffer;
kp = el->el_chared.c_kill.buf; kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.lastchar) while (cp < el->el_line.lastchar)
*kp++ = *cp++; /* copy it */ *kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
el->el_line.lastchar = el->el_line.buffer; /* zap! -- delete all of it */ /* zap! -- delete all of it */
el->el_line.cursor = el->el_line.buffer; el->el_line.lastchar = el->el_line.buffer;
return CC_REFRESH; el->el_line.cursor = el->el_line.buffer;
return (CC_REFRESH);
} }
@ -177,33 +179,30 @@ em_kill_line(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_kill_region(el, c) em_kill_region(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *kp, *cp; char *kp, *cp;
if (!el->el_chared.c_kill.mark) if (!el->el_chared.c_kill.mark)
return CC_ERROR; return (CC_ERROR);
if (el->el_chared.c_kill.mark > el->el_line.cursor) { if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor; cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf; kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark) while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */ *kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.cursor); c_delafter(el, cp - el->el_line.cursor);
} } else { /* mark is before cursor */
else { /* mark is before cursor */ cp = el->el_chared.c_kill.mark;
cp = el->el_chared.c_kill.mark; kp = el->el_chared.c_kill.buf;
kp = el->el_chared.c_kill.buf; while (cp < el->el_line.cursor)
while (cp < el->el_line.cursor) *kp++ = *cp++; /* copy it */
*kp++ = *cp++; /* copy it */ el->el_chared.c_kill.last = kp;
el->el_chared.c_kill.last = kp; c_delbefore(el, cp - el->el_chared.c_kill.mark);
c_delbefore(el, cp - el->el_chared.c_kill.mark); el->el_line.cursor = el->el_chared.c_kill.mark;
el->el_line.cursor = el->el_chared.c_kill.mark; }
} return (CC_REFRESH);
return CC_REFRESH;
} }
@ -213,30 +212,27 @@ em_kill_region(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_copy_region(el, c) em_copy_region(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *kp, *cp; char *kp, *cp;
if (el->el_chared.c_kill.mark) if (el->el_chared.c_kill.mark)
return CC_ERROR; return (CC_ERROR);
if (el->el_chared.c_kill.mark > el->el_line.cursor) { if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor; cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf; kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark) while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */ *kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp; el->el_chared.c_kill.last = kp;
} } else {
else { cp = el->el_chared.c_kill.mark;
cp = el->el_chared.c_kill.mark; kp = el->el_chared.c_kill.buf;
kp = el->el_chared.c_kill.buf; while (cp < el->el_line.cursor)
while (cp < el->el_line.cursor) *kp++ = *cp++; /* copy it */
*kp++ = *cp++; /* copy it */ el->el_chared.c_kill.last = kp;
el->el_chared.c_kill.last = kp; }
} return (CC_NORM);
return CC_NORM;
} }
@ -245,20 +241,17 @@ em_copy_region(el, c)
* Gosling emacs transpose chars [^T] * Gosling emacs transpose chars [^T]
*/ */
protected el_action_t protected el_action_t
em_gosmacs_traspose(el, c) em_gosmacs_traspose(EditLine *el, int c)
EditLine *el;
int c;
{ {
if (el->el_line.cursor > &el->el_line.buffer[1]) { if (el->el_line.cursor > &el->el_line.buffer[1]) {
/* must have at least two chars entered */ /* must have at least two chars entered */
c = el->el_line.cursor[-2]; c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1]; el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c; el->el_line.cursor[-1] = c;
return CC_REFRESH; return (CC_REFRESH);
} } else
else return (CC_ERROR);
return CC_ERROR;
} }
@ -268,49 +261,46 @@ em_gosmacs_traspose(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_next_word(el, c) em_next_word(EditLine *el, int c)
EditLine *el;
int c;
{ {
if (el->el_line.cursor == el->el_line.lastchar) if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR; return (CC_ERROR);
el->el_line.cursor = c__next_word(el->el_line.cursor, el->el_line.lastchar, el->el_line.cursor = c__next_word(el->el_line.cursor,
el->el_state.argument, el->el_line.lastchar,
ce__isword); el->el_state.argument,
ce__isword);
if (el->el_map.type == MAP_VI) if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action & DELETE) { if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el); cv_delfini(el);
return CC_REFRESH; return (CC_REFRESH);
} }
return (CC_CURSOR);
return CC_CURSOR;
} }
/* em_upper_case(): /* em_upper_case():
* Uppercase the characters from cursor to end of current word * Uppercase the characters from cursor to end of current word
* [M-u] * [M-u]
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_upper_case(el, c) em_upper_case(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *cp, *ep; char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar, ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword); el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++) for (cp = el->el_line.cursor; cp < ep; cp++)
if (islower(*cp)) if (islower((unsigned char) *cp))
*cp = toupper(*cp); *cp = toupper(*cp);
el->el_line.cursor = ep; el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar) if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH; return (CC_REFRESH);
} }
@ -320,56 +310,53 @@ em_upper_case(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_capitol_case(el, c) em_capitol_case(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *cp, *ep; char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar, ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword); el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++) { for (cp = el->el_line.cursor; cp < ep; cp++) {
if (isalpha(*cp)) { if (isalpha((unsigned char) *cp)) {
if (islower(*cp)) if (islower((unsigned char) *cp))
*cp = toupper(*cp); *cp = toupper(*cp);
cp++; cp++;
break; break;
}
} }
} for (; cp < ep; cp++)
for (; cp < ep; cp++) if (isupper((unsigned char) *cp))
if (isupper(*cp)) *cp = tolower(*cp);
*cp = tolower(*cp);
el->el_line.cursor = ep; el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar) if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH; return (CC_REFRESH);
} }
/* em_lower_case(): /* em_lower_case():
* Lowercase the characters from cursor to end of current word * Lowercase the characters from cursor to end of current word
* [M-l] * [M-l]
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_lower_case(el, c) em_lower_case(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *cp, *ep; char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar, ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword); el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++) for (cp = el->el_line.cursor; cp < ep; cp++)
if (isupper(*cp)) if (isupper((unsigned char) *cp))
*cp = tolower(*cp); *cp = tolower(*cp);
el->el_line.cursor = ep; el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar) if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH; return (CC_REFRESH);
} }
@ -379,62 +366,59 @@ em_lower_case(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_set_mark(el, c) em_set_mark(EditLine *el, int c)
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(): /* em_exchange_mark():
* Exchange the cursor and mark * Exchange the cursor and mark
* [^X^X] * [^X^X]
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_exchange_mark(el, c) em_exchange_mark(EditLine *el, int c)
EditLine *el;
int c;
{ {
register char *cp; char *cp;
cp = el->el_line.cursor; cp = el->el_line.cursor;
el->el_line.cursor = el->el_chared.c_kill.mark; el->el_line.cursor = el->el_chared.c_kill.mark;
el->el_chared.c_kill.mark = cp; el->el_chared.c_kill.mark = cp;
return CC_CURSOR; return (CC_CURSOR);
} }
/* em_universal_argument(): /* em_universal_argument():
* Universal argument (argument times 4) * Universal argument (argument times 4)
* [^U] * [^U]
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_universal_argument(el, c) em_universal_argument(EditLine *el, int c)
EditLine *el;
int c;
{ /* multiply current argument by 4 */ { /* multiply current argument by 4 */
if (el->el_state.argument > 1000000)
return CC_ERROR; if (el->el_state.argument > 1000000)
el->el_state.doingarg = 1; return (CC_ERROR);
el->el_state.argument *= 4; el->el_state.doingarg = 1;
return CC_ARGHACK; el->el_state.argument *= 4;
return (CC_ARGHACK);
} }
/* em_meta_next(): /* em_meta_next():
* Add 8th bit to next character typed * Add 8th bit to next character typed
* [<ESC>] * [<ESC>]
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_meta_next(el, c) em_meta_next(EditLine *el, int c)
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 protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_toggle_overwrite(el, c) em_toggle_overwrite(EditLine *el, int c)
EditLine *el;
int c;
{ {
el->el_state.inputmode =
(el->el_state.inputmode == MODE_INSERT) ? MODE_REPLACE : MODE_INSERT; el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
return CC_NORM; MODE_REPLACE : MODE_INSERT;
return (CC_NORM);
} }
@ -458,27 +441,25 @@ em_toggle_overwrite(el, c)
*/ */
protected el_action_t protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_copy_prev_word(el, c) em_copy_prev_word(EditLine *el, int c)
EditLine *el;
int c;
{ {
char *cp, *oldc, *dp; char *cp, *oldc, *dp;
if (el->el_line.cursor == el->el_line.buffer) if (el->el_line.cursor == el->el_line.buffer)
return CC_ERROR; return (CC_ERROR);
oldc = el->el_line.cursor; oldc = el->el_line.cursor;
/* does a bounds check */ /* does a bounds check */
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer, cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword); el->el_state.argument, ce__isword);
c_insert(el, oldc - cp); c_insert(el, oldc - cp);
for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++) for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
*dp++ = *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 protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_inc_search_next(el, c) em_inc_search_next(EditLine *el, int c)
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 protected el_action_t
/*ARGSUSED*/ /*ARGSUSED*/
em_inc_search_prev(el, c) em_inc_search_prev(EditLine *el, int c)
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 * Copyright (c) 1992, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
#else #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
#endif /* not lint && not SCCSID */ #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. * Initialization function.
*/ */
protected int protected int
hist_init(el) hist_init(EditLine *el)
EditLine *el;
{ {
el->el_history.fun = NULL;
el->el_history.ref = NULL; el->el_history.fun = NULL;
el->el_history.buf = (char *) el_malloc(EL_BUFSIZ); el->el_history.ref = NULL;
el->el_history.last = el->el_history.buf; el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
return 0; 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; * clean up history;
*/ */
protected void protected void
hist_end(el) hist_end(EditLine *el)
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 * Set new history interface
*/ */
protected int protected int
hist_set(el, fun, ptr) hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
EditLine *el;
hist_fun_t fun;
ptr_t ptr;
{ {
el->el_history.ref = ptr;
el->el_history.fun = fun; el->el_history.ref = ptr;
return 0; el->el_history.fun = fun;
return (0);
} }
@ -99,78 +100,99 @@ hist_set(el, fun, ptr)
* eventno tells us the event to get. * eventno tells us the event to get.
*/ */
protected el_action_t protected el_action_t
hist_get(el) hist_get(EditLine *el)
EditLine *el;
{ {
const char *hp; const char *hp;
int h; int h;
if (el->el_history.eventno == 0) { /* if really the current line */ if (el->el_history.eventno == 0) { /* if really the current line */
(void) strncpy(el->el_line.buffer, el->el_history.buf, EL_BUFSIZ); (void) strncpy(el->el_line.buffer, el->el_history.buf,
el->el_line.lastchar = el->el_line.buffer + el->el_history.sz);
(el->el_history.last - el->el_history.buf); el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf);
#ifdef KSHVI #ifdef KSHVI
if (el->el_map.type == MAP_VI) if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer;
else else
#endif /* KSHVI */ #endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar; el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH; 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;
} }
if (el->el_history.ref == NULL)
return (CC_ERROR);
(void) strncpy(el->el_line.buffer, hp, EL_BUFSIZ); hp = HIST_FIRST(el);
el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
if (el->el_line.lastchar > el->el_line.buffer) { if (hp == NULL)
if (el->el_line.lastchar[-1] == '\n') return (CC_ERROR);
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;
}
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 #ifdef KSHVI
if (el->el_map.type == MAP_VI) if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer; el->el_line.cursor = el->el_line.buffer;
else else
#endif /* KSHVI */ #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() /* hist_list()
* List history entries * List history entries
*/ */
protected int protected int
/*ARGSUSED*/ /*ARGSUSED*/
hist_list(el, argc, argv) hist_list(EditLine *el, int argc, char **argv)
EditLine *el;
int argc;
char **argv;
{ {
const char *str; const char *str;
if (el->el_history.ref == NULL) if (el->el_history.ref == NULL)
return -1; return (-1);
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el)) for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
(void) fprintf(el->el_outfile, "%d %s", el->el_history.ev->num, str); (void) fprintf(el->el_outfile, "%d %s",
return 0; 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 * Copyright (c) 1992, 1993
@ -42,25 +42,25 @@
* el.hist.c: History functions * el.hist.c: History functions
*/ */
#ifndef _h_el_hist #ifndef _h_el_hist
#define _h_el_hist #define _h_el_hist
#include "histedit.h" #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 { typedef struct el_history_t {
char *buf; /* The history buffer */ char *buf; /* The history buffer */
char *last; /* The last character */ size_t sz; /* Size of history buffer */
int eventno; /* Event we are looking for */ char *last; /* The last character */
ptr_t ref; /* Argument for history fcns */ int eventno; /* Event we are looking for */
hist_fun_t fun; /* Event access */ ptr_t ref; /* Argument for history fcns */
const HistEvent *ev; /* Event cookie */ hist_fun_t fun; /* Event access */
HistEvent ev; /* Event cookie */
} el_history_t; } el_history_t;
#define HIST_FUN(el, fn, arg) \ #define HIST_FUN(el, fn, arg) \
((((el)->el_history.ev = \ ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
(*(el)->el_history.fun)((el)->el_history.ref, fn, arg)) == NULL) ? \ fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
NULL : (el)->el_history.ev->str)
#define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL) #define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL)
#define HIST_FIRST(el) HIST_FUN(el, H_FIRST, 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_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname) #define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
protected int hist_init __P((EditLine *)); protected int hist_init(EditLine *);
protected void hist_end __P((EditLine *)); protected void hist_end(EditLine *);
protected el_action_t hist_get __P((EditLine *)); protected el_action_t hist_get(EditLine *);
protected int hist_set __P((EditLine *, hist_fun_t, ptr_t)); protected int hist_set(EditLine *, hist_fun_t, ptr_t);
protected int hist_list __P((EditLine *, int, char **)); protected int hist_list(EditLine *, int, char **);
protected int hist_enlargebuf(EditLine *, size_t, size_t);
#endif /* _h_el_hist */ #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 * Copyright (c) 1992, 1993
@ -41,8 +41,8 @@
/* /*
* histedit.h: Line editor and history interface. * histedit.h: Line editor and history interface.
*/ */
#ifndef _h_editline #ifndef _HISTEDIT_H_
#define _h_editline #define _HISTEDIT_H_
#include <sys/types.h> #include <sys/types.h>
#include <stdio.h> #include <stdio.h>
@ -56,9 +56,9 @@ typedef struct editline EditLine;
* For user-defined function interface * For user-defined function interface
*/ */
typedef struct lineinfo { typedef struct lineinfo {
const char *buffer; const char *buffer;
const char *cursor; const char *cursor;
const char *lastchar; const char *lastchar;
} LineInfo; } LineInfo;
@ -69,46 +69,53 @@ typedef struct lineinfo {
#define CC_NORM 0 #define CC_NORM 0
#define CC_NEWLINE 1 #define CC_NEWLINE 1
#define CC_EOF 2 #define CC_EOF 2
#define CC_ARGHACK 3 #define CC_ARGHACK 3
#define CC_REFRESH 4 #define CC_REFRESH 4
#define CC_CURSOR 5 #define CC_CURSOR 5
#define CC_ERROR 6 #define CC_ERROR 6
#define CC_FATAL 7 #define CC_FATAL 7
#define CC_REDISPLAY 8 #define CC_REDISPLAY 8
#define CC_REFRESH_BEEP 9
/* /*
* Initialization, cleanup, and resetting * Initialization, cleanup, and resetting
*/ */
EditLine *el_init __P((const char *, FILE *, FILE *)); EditLine *el_init(const char *, FILE *, FILE *, FILE *);
void el_reset __P((EditLine *)); void el_reset(EditLine *);
void el_end __P((EditLine *)); void el_end(EditLine *);
/* /*
* Get a line, a character or push a string back in the input queue * Get a line, a character or push a string back in the input queue
*/ */
const char *el_gets __P((EditLine *, int *)); const char *el_gets(EditLine *, int *);
int el_getc __P((EditLine *, char *)); int el_getc(EditLine *, char *);
void el_push __P((EditLine *, const char *)); void el_push(EditLine *, const char *);
/*
* Beep!
*/
void el_beep(EditLine *);
/* /*
* High level function internals control * High level function internals control
* Parses argc, argv array and executes builtin editline commands * 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 * el_set/el_get parameters
*/ */
#define EL_PROMPT 0 /* , el_pfunc_t); */ #define EL_PROMPT 0 /* , el_pfunc_t); */
#define EL_TERMINAL 1 /* , const char *); */ #define EL_TERMINAL 1 /* , const char *); */
#define EL_EDITOR 2 /* , const char *); */ #define EL_EDITOR 2 /* , const char *); */
#define EL_SIGNAL 3 /* , int); */ #define EL_SIGNAL 3 /* , int); */
#define EL_BIND 4 /* , const char *, ..., NULL); */ #define EL_BIND 4 /* , const char *, ..., NULL); */
#define EL_TELLTC 5 /* , const char *, ..., NULL); */ #define EL_TELLTC 5 /* , const char *, ..., NULL); */
#define EL_SETTC 6 /* , 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_SETTY 8 /* , const char *, ..., NULL); */
#define EL_ADDFN 9 /* , const char *, const char * */ #define EL_ADDFN 9 /* , const char *, const char * */
/* , el_func_t); */ /* , 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 * 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 * Must be called when the terminal changes size; If EL_SIGNAL
* is set this is done automatically otherwise it is the responsibility * is set this is done automatically otherwise it is the responsibility
* of the application * of the application
*/ */
void el_resize __P((EditLine *)); void el_resize(EditLine *);
/* /*
* User-defined function interface. * User-defined function interface.
*/ */
const LineInfo *el_line __P((EditLine *)); const LineInfo *el_line(EditLine *);
int el_insertstr __P((EditLine *, char *)); int el_insertstr(EditLine *, const char *);
void el_deletestr __P((EditLine *, int)); void el_deletestr(EditLine *, int);
/* /*
* ==== History ==== * ==== History ====
@ -145,34 +157,37 @@ void el_deletestr __P((EditLine *, int));
typedef struct history History; typedef struct history History;
typedef struct HistEvent { typedef struct HistEvent {
int num; int num;
const char *str; const char *str;
} HistEvent; } HistEvent;
/* /*
* History access functions. * History access functions.
*/ */
History * history_init __P((void)); History * history_init(void);
void history_end __P((History *)); void history_end(History *);
const HistEvent * history __P((History *, int, ...)); int history(History *, HistEvent *, int, ...);
#define H_FUNC 0 /* , UTSL */ #define H_FUNC 0 /* , UTSL */
#define H_EVENT 1 /* , const int); */ #define H_SETSIZE 1 /* , const int); */
#define H_FIRST 2 /* , void); */ #define H_GETSIZE 2 /* , void); */
#define H_LAST 3 /* , void); */ #define H_FIRST 3 /* , void); */
#define H_PREV 4 /* , void); */ #define H_LAST 4 /* , void); */
#define H_NEXT 5 /* , void); */ #define H_PREV 5 /* , void); */
#define H_CURR 6 /* , void); */ #define H_NEXT 6 /* , void); */
#define H_ADD 7 /* , const char*); */ #define H_CURR 8 /* , const int); */
#define H_ENTER 8 /* , const char*); */ #define H_SET 7 /* , void); */
#define H_END 9 /* , void); */ #define H_ADD 9 /* , const char *); */
#define H_NEXT_STR 10 /* , const char*); */ #define H_ENTER 10 /* , const char *); */
#define H_PREV_STR 11 /* , const char*); */ #define H_APPEND 11 /* , const char *); */
#define H_NEXT_EVENT 12 /* , const int); */ #define H_END 12 /* , void); */
#define H_PREV_EVENT 13 /* , const int); */ #define H_NEXT_STR 13 /* , const char *); */
#define H_LOAD 14 /* , const char *); */ #define H_PREV_STR 14 /* , const char *); */
#define H_SAVE 15 /* , const char *); */ #define H_NEXT_EVENT 15 /* , const int); */
#define H_CLEAR 16 /* , void); */ #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 * Copyright (c) 1992, 1993
@ -42,41 +42,37 @@
* el.key.h: Key macro header * el.key.h: Key macro header
*/ */
#ifndef _h_el_key #ifndef _h_el_key
#define _h_el_key #define _h_el_key
typedef union key_value_t { typedef union key_value_t {
el_action_t cmd; /* If it is a command the # */ el_action_t cmd; /* If it is a command the # */
char *str; /* If it is a string... */ char *str; /* If it is a string... */
} key_value_t; } key_value_t;
typedef struct key_node_t key_node_t; typedef struct key_node_t key_node_t;
typedef struct el_key_t { typedef struct el_key_t {
char *buf; /* Key print buffer */ char *buf; /* Key print buffer */
key_node_t *map; /* Key map */ key_node_t *map; /* Key map */
key_value_t val; /* Local conversion buffer */ key_value_t val; /* Local conversion buffer */
} el_key_t; } el_key_t;
#define XK_CMD 0 #define XK_CMD 0
#define XK_STR 1 #define XK_STR 1
#define XK_NOD 2 #define XK_NOD 2
#define XK_EXE 3 #define XK_EXE 3
protected int key_init __P((EditLine *)); protected int key_init(EditLine *);
protected void key_end __P((EditLine *)); protected void key_end(EditLine *);
protected key_value_t * key_map_cmd __P((EditLine *, int)); protected key_value_t *key_map_cmd(EditLine *, int);
protected key_value_t * key_map_str __P((EditLine *, char *)); protected key_value_t *key_map_str(EditLine *, char *);
protected void key_reset __P((EditLine *)); protected void key_reset(EditLine *);
protected int key_get __P((EditLine *, char *, protected int key_get(EditLine *, char *, key_value_t *);
key_value_t *)); protected void key_add(EditLine *, const char *, key_value_t *, int);
protected void key_add __P((EditLine *, char *, key_value_t *, protected void key_clear(EditLine *, el_action_t *, char *);
int)); protected int key_delete(EditLine *, char *);
protected void key_clear __P((EditLine *, el_action_t *, protected void key_print(EditLine *, char *);
char *)); protected void key_kprint(EditLine *, char *, key_value_t *, int);
protected int key_delete __P((EditLine *, char *)); protected char *key__decode_str(char *, char *, 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 *));
#endif /* _h_el_key */ #endif /* _h_el_key */

117
makelist
View File

@ -1,5 +1,5 @@
#!/bin/sh - #!/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 # Copyright (c) 1992, 1993
# The Regents of the University of California. All rights reserved. # The Regents of the University of California. All rights reserved.
@ -40,7 +40,7 @@
# makelist.sh: Automatically generate header files... # makelist.sh: Automatically generate header files...
AWK=/usr/bin/awk 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" ] if [ "x$1" = "x" ]
then then
@ -54,6 +54,9 @@ shift
FILES="$@" FILES="$@"
case $FLAG in case $FLAG in
# generate foo.h file from foo.c
#
-h) -h)
set - `echo $FILES | sed -e 's/\\./_/g'` set - `echo $FILES | sed -e 's/\\./_/g'`
hdr="_h_`basename $1`" hdr="_h_`basename $1`"
@ -66,18 +69,26 @@ case $FLAG in
pr = substr($2, 1, 2); pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") { if (pr == "vi" || pr == "em" || pr == "ed") {
name = substr($2, 1, length($2) - 3); 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 { END {
printf("#endif /* %s */\n", "'$hdr'"); printf("#endif /* %s */\n", "'$hdr'");
}';; }'
;;
# generate help.c from various .c files
#
-bc) -bc)
cat $FILES | $AWK ' cat $FILES | $AWK '
BEGIN { BEGIN {
printf("/* Automatically generated file, do not edit */\n"); printf("/* Automatically generated file, do not edit */\n");
printf("#include \"sys.h\"\n#include \"el.h\"\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_"; low = "abcdefghijklmnopqrstuvwxyz_";
high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"; high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
for (i = 1; i <= length(low); i++) for (i = 1; i <= length(low); i++)
@ -96,9 +107,9 @@ case $FLAG in
s = "-"; s = "-";
fname = fname s; fname = fname s;
} }
printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ","); printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
ok = 1; ok = 1;
} }
} }
/^ \*/ { /^ \*/ {
@ -113,41 +124,53 @@ case $FLAG in
END { END {
printf(" { NULL, 0, NULL }\n"); printf(" { NULL, 0, NULL }\n");
printf("};\n"); printf("};\n");
printf("\nprotected el_bindings_t* help__get()"); printf("\nprotected const el_bindings_t* help__get()");
printf("{ return el_func_help; }\n"); printf("{ return el_func_help; }\n");
}';; }'
;;
# generate help.h from various .c files
#
-bh) -bh)
$AWK ' $AWK '
BEGIN { BEGIN {
printf("/* Automatically generated file, do not edit */\n"); printf("/* Automatically generated file, do not edit */\n");
printf("#ifndef _h_help_c\n#define _h_help_c\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"); printf("#endif /* _h_help_c */\n");
}' /dev/null;; }' /dev/null
;;
# generate fcns.h from various .h files
#
-fh) -fh)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | \ cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
sort | tr '[a-z]' '[A-Z]' | $AWK ' sort | tr '[a-z]' '[A-Z]' | $AWK '
BEGIN { BEGIN {
printf("/* Automatically generated file, do not edit */\n"); printf("/* Automatically generated file, do not edit */\n");
printf("#ifndef _h_fcns_c\n#define _h_fcns_c\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++); printf("#define\t%-30.30s\t%3d\n", $1, count++);
} }
END { END {
printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count); printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));"); printf("typedef el_action_t (*el_func_t)(EditLine *, int);");
printf("\nprotected el_func_t* func__get __P((void));\n"); printf("\nprotected const el_func_t* func__get(void);\n");
printf("#endif /* _h_fcns_c */\n"); printf("#endif /* _h_fcns_c */\n");
}';; }'
;;
# generate fcns.c from various .h files
#
-fc) -fc)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK ' cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
BEGIN { BEGIN {
printf("/* Automatically generated file, do not edit */\n"); printf("/* Automatically generated file, do not edit */\n");
printf("#include \"sys.h\"\n#include \"el.h\"\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; maxlen = 80;
needn = 1; needn = 1;
len = 0; len = 0;
@ -155,7 +178,7 @@ case $FLAG in
{ {
clen = 25 + 2; clen = 25 + 2;
len += clen; len += clen;
if (len >= maxlen) if (len >= maxlen)
needn = 1; needn = 1;
if (needn) { if (needn) {
printf("\n "); printf("\n ");
@ -167,8 +190,12 @@ case $FLAG in
} }
END { END {
printf("\n};\n"); 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) -e)
echo "$FILES" | tr ' ' '\012' | $AWK ' echo "$FILES" | tr ' ' '\012' | $AWK '
BEGIN { BEGIN {
@ -178,8 +205,50 @@ case $FLAG in
} }
{ {
printf("#include \"%s\"\n", $1); 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 echo $USAGE 1>&2
exit 1;; exit 1
;;
esac 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 * Copyright (c) 1992, 1993
@ -42,38 +42,38 @@
* el.map.h: Editor maps * el.map.h: Editor maps
*/ */
#ifndef _h_el_map #ifndef _h_el_map
#define _h_el_map #define _h_el_map
typedef struct el_bindings_t { /* for the "bind" shell command */ typedef struct el_bindings_t { /* for the "bind" shell command */
const char *name; /* function name for bind command */ const char *name; /* function name for bind command */
int func; /* function numeric value */ int func; /* function numeric value */
const char *description; /* description of function */ const char *description; /* description of function */
} el_bindings_t; } el_bindings_t;
typedef struct el_map_t { typedef struct el_map_t {
el_action_t *alt; /* The current alternate key map */ el_action_t *alt; /* The current alternate key map */
el_action_t *key; /* The current normal key map */ el_action_t *key; /* The current normal key map */
el_action_t *current; /* The keymap we are using */ el_action_t *current; /* The keymap we are using */
el_action_t *emacs; /* The default emacs key map */ const el_action_t *emacs; /* The default emacs key map */
el_action_t *vic; /* The vi command mode key map */ const el_action_t *vic; /* The vi command mode key map */
el_action_t *vii; /* The vi insert mode key map */ const el_action_t *vii; /* The vi insert mode key map */
int type; /* Emacs or vi */ int type; /* Emacs or vi */
el_bindings_t *help; /* The help for the editor functions */ el_bindings_t *help; /* The help for the editor functions */
el_func_t *func; /* List of available functions */ el_func_t *func; /* List of available functions */
int nfunc; /* The number of functions/help items */ int nfunc; /* The number of functions/help items */
} el_map_t; } el_map_t;
#define MAP_EMACS 0 #define MAP_EMACS 0
#define MAP_VI 1 #define MAP_VI 1
protected int map_bind __P((EditLine *, int, char **)); protected int map_bind(EditLine *, int, char **);
protected int map_init __P((EditLine *)); protected int map_init(EditLine *);
protected void map_end __P((EditLine *)); protected void map_end(EditLine *);
protected void map_init_vi __P((EditLine *)); protected void map_init_vi(EditLine *);
protected void map_init_emacs __P((EditLine *)); protected void map_init_emacs(EditLine *);
protected int map_set_editor __P((EditLine *, char *)); protected int map_set_editor(EditLine *, char *);
protected int map_addfunc __P((EditLine *, const char *, protected int map_get_editor(EditLine *, const char **);
const char *, el_func_t)); protected int map_addfunc(EditLine *, const char *, const char *, el_func_t);
#endif /* _h_el_map */ #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 * Copyright (c) 1992, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
#else #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
#endif /* not lint && not SCCSID */ #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 * bind
* echotc * echotc
* edit
* gettc * gettc
* history * history
* settc * 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 "sys.h"
#include "el.h" #include "el.h"
#include "tokenizer.h" #include "tokenizer.h"
#include <stdlib.h>
private struct { private const struct {
char *name; char *name;
int (*func) __P((EditLine *, int, char **)); int (*func)(EditLine *, int, char **);
} cmds[] = { } cmds[] = {
{ "bind", map_bind }, { "bind", map_bind },
{ "echotc", term_echotc }, { "echotc", term_echotc },
{ "history", hist_list }, { "edit", el_editmode },
{ "telltc", term_telltc }, { "history", hist_list },
{ "settc", term_settc }, { "telltc", term_telltc },
{ "setty", tty_stty }, { "settc", term_settc },
{ NULL, NULL } { "setty", tty_stty },
{ NULL, NULL }
}; };
@ -78,51 +82,58 @@ private struct {
* Parse a line and dispatch it * Parse a line and dispatch it
*/ */
protected int protected int
parse_line(el, line) parse_line(EditLine *el, const char *line)
EditLine *el;
const char *line;
{ {
char **argv; char **argv;
int argc; int argc;
Tokenizer *tok; Tokenizer *tok;
tok = tok_init(NULL); tok = tok_init(NULL);
tok_line(tok, line, &argc, &argv); tok_line(tok, line, &argc, &argv);
argc = el_parse(el, argc, argv); argc = el_parse(el, argc, argv);
tok_end(tok); tok_end(tok);
return argc; return (argc);
} }
/* el_parse(): /* el_parse():
* Command dispatcher * Command dispatcher
*/ */
public int public int
el_parse(el, argc, argv) el_parse(EditLine *el, int argc, char *argv[])
EditLine *el;
int argc;
char *argv[];
{ {
char *ptr; char *ptr;
int i; int i;
if (argc < 1) if (argc < 1)
return -1; return (-1);
ptr = strchr(argv[0], ':'); ptr = strchr(argv[0], ':');
if (ptr != NULL) { if (ptr != NULL) {
*ptr++ = '\0'; char *tprog;
if (! el_match(el->el_prog, argv[0])) size_t l;
return 0;
}
else
ptr = argv[0];
for (i = 0; cmds[i].name != NULL; i++) if (ptr == argv[0])
if (strcmp(cmds[i].name, ptr) == 0) { return (0);
i = (*cmds[i].func)(el, argc, argv); l = ptr - argv[0] - 1;
return -i; 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 * the appropriate character or -1 if the escape is not valid
*/ */
protected int protected int
parse__escape(ptr) parse__escape(const char **const ptr)
const char ** const ptr;
{ {
const char *p; const char *p;
int c; int c;
p = *ptr; p = *ptr;
if (p[1] == 0) if (p[1] == 0)
return -1; return (-1);
if (*p == '\\') { if (*p == '\\') {
p++; p++;
switch (*p) { switch (*p) {
case 'a': case 'a':
c = '\007'; /* Bell */ 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--;
break; break;
} case 'b':
c = (c << 3) | (ch - '0'); c = '\010'; /* Backspace */
} break;
if ((c & 0xffffff00) != 0) case 't':
return -1; c = '\011'; /* Horizontal Tab */
--p; break;
} case 'n':
break; c = '\012'; /* New Line */
default: break;
c = *p; case 'v':
break; c = '\013'; /* Vertical Tab */
} break;
} case 'f':
else if (*p == '^' && isalpha((unsigned char) p[1])) { c = '\014'; /* Form Feed */
p++; break;
c = (*p == '?') ? '\177' : (*p & 0237); case 'r':
} c = '\015'; /* Carriage Return */
else break;
c = *p; case 'e':
*ptr = ++p; c = '\033'; /* Escape */
return c; 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__string():
* Parse the escapes from in and put the raw string out * Parse the escapes from in and put the raw string out
*/ */
protected char * protected char *
parse__string(out, in) parse__string(char *out, const char *in)
char *out;
const char *in;
{ {
char *rv = out; char *rv = out;
int n; int n;
for (;;)
switch (*in) {
case '\0':
*out = '\0';
return rv;
case '\\': for (;;)
case '^': switch (*in) {
if ((n = parse__escape(&in)) == -1) case '\0':
return NULL; *out = '\0';
*out++ = n; return (rv);
break;
default: case '\\':
*out++ = *in++; case '^':
break; if ((n = parse__escape(&in)) == -1)
} return (NULL);
*out++ = n;
break;
default:
*out++ = *in++;
break;
}
} }
/* parse_cmd(): /* parse_cmd():
* Return the command number for the command string given * Return the command number for the command string given
* or -1 if one is not found * or -1 if one is not found
*/ */
protected int protected int
parse_cmd(el, cmd) parse_cmd(EditLine *el, const char *cmd)
EditLine *el;
const char *cmd;
{ {
el_bindings_t *b; el_bindings_t *b;
for (b = el->el_map.help; b->name != NULL; b++) for (b = el->el_map.help; b->name != NULL; b++)
if (strcmp(b->name, cmd) == 0) if (strcmp(b->name, cmd) == 0)
return b->func; return (b->func);
return -1; 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 * Copyright (c) 1992, 1993
@ -42,11 +42,11 @@
* el.parse.h: Parser functions * el.parse.h: Parser functions
*/ */
#ifndef _h_el_parse #ifndef _h_el_parse
#define _h_el_parse #define _h_el_parse
protected int parse_line __P((EditLine *, const char *)); protected int parse_line(EditLine *, const char *);
protected int parse__escape __P((const char ** const)); protected int parse__escape(const char ** const);
protected char * parse__string __P((char *, const char *)); protected char *parse__string(char *, const char *);
protected int parse_cmd __P((EditLine *, const char *)); protected int parse_cmd(EditLine *, const char *);
#endif /* _h_el_parse */ #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 * Copyright (c) 1992, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
#else #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
#endif /* not lint && not SCCSID */ #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 <stdio.h>
#include "el.h" #include "el.h"
private char *prompt_default __P((EditLine *)); private char *prompt_default(EditLine *);
private char *prompt_default_r(EditLine *);
/* prompt_default(): /* prompt_default():
* Just a default prompt, in case the user did not provide one * Just a default prompt, in case the user did not provide one
*/ */
private char * private char *
/*ARGSUSED*/ /*ARGSUSED*/
prompt_default(el) prompt_default(EditLine *el)
EditLine *el;
{ {
static char a[3] = { '?', ' ', '\0' }; static char a[3] = {'?', ' ', '\0'};
return a;
return (a);
}
/* prompt_default_r():
* Just a default rprompt, in case the user did not provide one
*/
private char *
/*ARGSUSED*/
prompt_default_r(EditLine *el)
{
static char a[1] = {'\0'};
return (a);
} }
@ -73,57 +88,88 @@ prompt_default(el)
* bit to flag them * bit to flag them
*/ */
protected void protected void
prompt_print(el) prompt_print(EditLine *el, int op)
EditLine *el;
{ {
char *p = (*el->el_prompt.p_func)(el); el_prompt_t *elp;
while (*p) char *p;
re_putc(el, *p++);
el->el_prompt.p_pos.v = el->el_refresh.r_cursor.v; if (op == EL_PROMPT)
el->el_prompt.p_pos.h = el->el_refresh.r_cursor.h; 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(): /* prompt_init():
* Initialize the prompt stuff * Initialize the prompt stuff
*/ */
protected int protected int
prompt_init(el) prompt_init(EditLine *el)
EditLine *el;
{ {
el->el_prompt.p_func = prompt_default;
el->el_prompt.p_pos.v = 0; el->el_prompt.p_func = prompt_default;
el->el_prompt.p_pos.h = 0; el->el_prompt.p_pos.v = 0;
return 0; el->el_prompt.p_pos.h = 0;
} /* end prompt_init */ el->el_rprompt.p_func = prompt_default_r;
el->el_rprompt.p_pos.v = 0;
el->el_rprompt.p_pos.h = 0;
return (0);
}
/* prompt_end(): /* prompt_end():
* Clean up the prompt stuff * Clean up the prompt stuff
*/ */
protected void protected void
/*ARGSUSED*/ /*ARGSUSED*/
prompt_end(el) prompt_end(EditLine *el)
EditLine *el;
{ {
} /* end prompt_end */ }
/* prompt_set(): /* prompt_set():
* Install a prompt printing function * Install a prompt printing function
*/ */
protected int protected int
prompt_set(el, prf) prompt_set(EditLine *el, el_pfunc_t prf, int op)
EditLine *el;
el_pfunc_t prf;
{ {
if (prf == NULL) el_prompt_t *p;
el->el_prompt.p_func = prompt_default;
else if (op == EL_PROMPT)
el->el_prompt.p_func = prf; p = &el->el_prompt;
el->el_prompt.p_pos.v = 0; else
el->el_prompt.p_pos.h = 0; p = &el->el_rprompt;
return 0; if (prf == NULL) {
} /* end prompt_set */ 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 * Copyright (c) 1992, 1993
@ -42,20 +42,21 @@
* el.prompt.h: Prompt printing stuff * el.prompt.h: Prompt printing stuff
*/ */
#ifndef _h_el_prompt #ifndef _h_el_prompt
#define _h_el_prompt #define _h_el_prompt
#include "histedit.h" #include "histedit.h"
typedef char * (*el_pfunc_t) __P((EditLine*)); typedef char * (*el_pfunc_t)(EditLine*);
typedef struct el_prompt_t { typedef struct el_prompt_t {
el_pfunc_t p_func; /* Function to return the prompt */ el_pfunc_t p_func; /* Function to return the prompt */
coord_t p_pos; /* position in the line after prompt */ coord_t p_pos; /* position in the line after prompt */
} el_prompt_t; } el_prompt_t;
protected void prompt_print __P((EditLine *)); protected void prompt_print(EditLine *, int);
protected int prompt_set __P((EditLine *, el_pfunc_t)); protected int prompt_set(EditLine *, el_pfunc_t, int);
protected int prompt_init __P((EditLine *)); protected int prompt_get(EditLine *, el_pfunc_t *, int);
protected void prompt_end __P((EditLine *)); protected int prompt_init(EditLine *);
protected void prompt_end(EditLine *);
#endif /* _h_el_prompt */ #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 * Copyright (c) 1992, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#else #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
#endif /* not lint && not SCCSID */ #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 * Terminal read functions
*/ */
#include "sys.h" #include "sys.h"
#include <sys/errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
extern int errno;
#include "el.h" #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 #ifdef DEBUG_EDIT
private void private void
read_debug(el) read_debug(EditLine *el)
EditLine *el;
{ {
if (el->el_line.cursor > el->el_line.lastchar) if (el->el_line.cursor > el->el_line.lastchar)
(void) fprintf(el->el_errfile, "cursor > lastchar\r\n"); (void) fprintf(el->el_errfile, "cursor > lastchar\r\n");
if (el->el_line.cursor < el->el_line.buffer) if (el->el_line.cursor < el->el_line.buffer)
(void) fprintf(el->el_errfile, "cursor < buffer\r\n"); (void) fprintf(el->el_errfile, "cursor < buffer\r\n");
if (el->el_line.cursor > el->el_line.limit) if (el->el_line.cursor > el->el_line.limit)
(void) fprintf(el->el_errfile, "cursor > limit\r\n"); (void) fprintf(el->el_errfile, "cursor > limit\r\n");
if (el->el_line.lastchar > el->el_line.limit) if (el->el_line.lastchar > el->el_line.limit)
(void) fprintf(el->el_errfile, "lastchar > limit\r\n"); (void) fprintf(el->el_errfile, "lastchar > limit\r\n");
if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2]) if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2])
(void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n"); (void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n");
} }
#endif /* DEBUG_EDIT */ #endif /* DEBUG_EDIT */
/* read__fixio(): /* read__fixio():
* Try to recover from a read error * Try to recover from a read error
*/ */
/* ARGSUSED */
private int private int
read__fixio(fd, e) read__fixio(int fd, int e)
int fd, 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 #ifdef EWOULDBLOCK
case EWOULDBLOCK: case EWOULDBLOCK:
# ifndef TRY_AGAIN #ifndef TRY_AGAIN
# define TRY_AGAIN #define TRY_AGAIN
# endif #endif
#endif /* EWOULDBLOCK */ #endif /* EWOULDBLOCK */
#if defined(POSIX) && defined(EAGAIN) #if defined(POSIX) && defined(EAGAIN)
# if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN: case EAGAIN:
# ifndef TRY_AGAIN #ifndef TRY_AGAIN
# define TRY_AGAIN #define TRY_AGAIN
# endif #endif
# endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */ #endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#endif /* POSIX && EAGAIN */ #endif /* POSIX && EAGAIN */
e = 0; e = 0;
#ifdef TRY_AGAIN #ifdef TRY_AGAIN
# if defined(F_SETFL) && defined(O_NDELAY) #if defined(F_SETFL) && defined(O_NDELAY)
if ((e = fcntl(fd, F_GETFL, 0)) == -1) if ((e = fcntl(fd, F_GETFL, 0)) == -1)
return -1; return (-1);
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1) if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
return -1; return (-1);
else else
e = 1; e = 1;
# endif /* F_SETFL && O_NDELAY */ #endif /* F_SETFL && O_NDELAY */
# ifdef FIONBIO #ifdef FIONBIO
if (ioctl(fd, FIONBIO, (ioctl_t) &e) == -1) {
return -1; int zero = 0;
else
e = 1; if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
# endif /* FIONBIO */ return (-1);
else
e = 1;
}
#endif /* FIONBIO */
#endif /* TRY_AGAIN */ #endif /* TRY_AGAIN */
return e ? 0 : -1; return (e ? 0 : -1);
case EINTR: case EINTR:
return 0; return (0);
default: default:
return -1; return (-1);
} }
} }
@ -141,34 +183,33 @@ read__fixio(fd, e)
* Try to read the stuff in the input queue; * Try to read the stuff in the input queue;
*/ */
private int private int
read_preread(el) read_preread(EditLine *el)
EditLine *el;
{ {
int chrs = 0; int chrs = 0;
if (el->el_chared.c_macro.nline) { if (el->el_chared.c_macro.nline) {
el_free((ptr_t) el->el_chared.c_macro.nline); el_free((ptr_t) el->el_chared.c_macro.nline);
el->el_chared.c_macro.nline = NULL; el->el_chared.c_macro.nline = NULL;
} }
if (el->el_tty.t_mode == ED_IO)
if (el->el_tty.t_mode == ED_IO) return (0);
return 0;
#ifdef FIONREAD #ifdef FIONREAD
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) &chrs); (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));
if (chrs > 0) { if (chrs > 0) {
buf[chrs] = '\0'; char buf[EL_BUFSIZ];
el->el_chared.c_macro.nline = strdup(buf);
el_push(el->el_chared.c_macro.nline);
}
}
#endif /* FIONREAD */
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 * Push a macro
*/ */
public void public void
el_push(el, str) el_push(EditLine *el, const char *str)
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) { if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++; ma->level++;
ma->macro[ma->level] = (char *) str; /* LINTED const cast */
} ma->macro[ma->level] = (char *) str;
else { } else {
term_beep(el); term_beep(el);
term__flush(); term__flush();
} }
} }
@ -197,57 +236,74 @@ el_push(el, str)
* Return next command from the input stream. * Return next command from the input stream.
*/ */
private int private int
read_getcmd(el, cmdnum, ch) read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
EditLine *el;
el_action_t *cmdnum;
char *ch;
{ {
el_action_t cmd = 0; el_action_t cmd = ED_UNASSIGNED;
int num; int num;
while (cmd == 0 || cmd == ED_SEQUENCE_LEAD_IN) { while (cmd == ED_UNASSIGNED || cmd == ED_SEQUENCE_LEAD_IN) {
if ((num = el_getc(el, ch)) != 1) /* if EOF or error */ if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
return num; return (num);
#ifdef KANJI #ifdef KANJI
if ((*ch & 0200)) { if ((*ch & 0200)) {
el->el_state.metanext = 0; el->el_state.metanext = 0;
cmd = CcViMap[' ']; cmd = CcViMap[' '];
break; break;
} } else
else
#endif /* KANJI */ #endif /* KANJI */
if (el->el_state.metanext) { if (el->el_state.metanext) {
el->el_state.metanext = 0; el->el_state.metanext = 0;
*ch |= 0200; *ch |= 0200;
} }
cmd = el->el_map.current[(unsigned char) *ch]; cmd = el->el_map.current[(unsigned char) *ch];
if (cmd == ED_SEQUENCE_LEAD_IN) { if (cmd == ED_SEQUENCE_LEAD_IN) {
key_value_t val; key_value_t val;
switch (key_get(el, ch, &val)) { switch (key_get(el, ch, &val)) {
case XK_CMD: case XK_CMD:
cmd = val.cmd; cmd = val.cmd;
break; break;
case XK_STR: case XK_STR:
el_push(el, val.str); el_push(el, val.str);
break; break;
#ifdef notyet #ifdef notyet
case XK_EXE: case XK_EXE:
/* XXX: In the future to run a user function */ /* XXX: In the future to run a user function */
RunCommand(val.str); RunCommand(val.str);
break; break;
#endif #endif
default: default:
abort(); EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
break; break;
} }
}
if (el->el_map.alt == NULL)
el->el_map.current = el->el_map.key;
} }
if (el->el_map.alt == NULL) *cmdnum = cmd;
el->el_map.current = el->el_map.key; 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 * Read a character
*/ */
public int public int
el_getc(el, cp) el_getc(EditLine *el, char *cp)
EditLine *el;
char *cp;
{ {
int num_read; int num_read;
unsigned char tcp; c_macro_t *ma = &el->el_chared.c_macro;
int tried = 0;
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(); if (*ma->macro[ma->level] == 0) {
for (;;) { ma->level--;
if (ma->level < 0) { continue;
if (!read_preread(el)) }
break; *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 #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 */ #endif /* DEBUG_READ */
if (tty_rawmode(el) < 0) /* make sure the tty is set up correctly */ if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
return 0; return (0);
#ifdef DEBUG_READ #ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Reading a character\n"); (void) fprintf(el->el_errfile, "Reading a character\n");
#endif /* DEBUG_READ */ #endif /* DEBUG_READ */
while ((num_read = read(el->el_infd, (char *) &tcp, 1)) == -1) num_read = (*el->el_read.read_char)(el, cp);
if (!tried && read__fixio(el->el_infd, errno) == 0)
tried = 1;
else {
*cp = '\0';
return -1;
}
#ifdef DEBUG_READ #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 */ #endif /* DEBUG_READ */
*cp = tcp; return (num_read);
return num_read;
} }
public const char * public const char *
el_gets(el, nread) el_gets(EditLine *el, int *nread)
EditLine *el;
int *nread;
{ {
int retval; int retval;
el_action_t cmdnum = 0; el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */ int num; /* how many chars we have read at NL */
char ch; char ch;
if (el->el_flags & HANDLE_SIGNALS)
sig_set(el);
re_clear_display(el); /* reset the display stuff */
ch_reset(el);
#ifdef FIONREAD #ifdef FIONREAD
if (el->el_tty.t_mode == EX_IO && ma->level < 0) { c_macro_t *ma = &el->el_chared.c_macro;
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 */ #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 #ifdef DEBUG_EDIT
read_debug(el); read_debug(el);
#endif /* DEBUG_EDIT */ #endif /* DEBUG_EDIT */
/* if EOF or error */ /* if EOF or error */
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) { if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
#ifdef DEBUG_READ #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 */ #endif /* DEBUG_READ */
break; break;
} }
if ((int) cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
if (cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
#ifdef DEBUG_EDIT #ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile, (void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch); "ERROR: illegal command from key 0%o\r\n", ch);
#endif /* DEBUG_EDIT */ #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 */ /* make sure the tty is set up correctly */
#ifdef DEBUG_READ (void) tty_cookedmode(el);
{ term__flush(); /* flush any buffered output */
el_bindings_t *b; if (el->el_flags & HANDLE_SIGNALS)
for (b = el->el_map.help; b->name; b++) sig_clr(el);
if (b->func == cmdnum) if (nread)
break; *nread = num;
if (b->name) return (num ? el->el_line.buffer : NULL);
(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;
} }

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 * Copyright (c) 1992, 1993
@ -42,21 +42,22 @@
* el.refresh.h: Screen refresh functions * el.refresh.h: Screen refresh functions
*/ */
#ifndef _h_el_refresh #ifndef _h_el_refresh
#define _h_el_refresh #define _h_el_refresh
#include "histedit.h" #include "histedit.h"
typedef struct { typedef struct {
coord_t r_cursor; /* Refresh cursor position */ coord_t r_cursor; /* Refresh cursor position */
int r_oldcv, r_newcv; /* Vertical locations */ int r_oldcv; /* Vertical locations */
int r_newcv;
} el_refresh_t; } el_refresh_t;
protected void re_putc __P((EditLine *, int)); protected void re_putc(EditLine *, int, int);
protected void re_clear_lines __P((EditLine *)); protected void re_clear_lines(EditLine *);
protected void re_clear_display __P((EditLine *)); protected void re_clear_display(EditLine *);
protected void re_refresh __P((EditLine *)); protected void re_refresh(EditLine *);
protected void re_refresh_cursor __P((EditLine *)); protected void re_refresh_cursor(EditLine *);
protected void re_fastaddc __P((EditLine *)); protected void re_fastaddc(EditLine *);
protected void re_goto_bottom __P((EditLine *)); protected void re_goto_bottom(EditLine *);
#endif /* _h_el_refresh */ #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 * Copyright (c) 1992, 1993
@ -41,30 +41,30 @@
/* /*
* el.search.h: Line and history searching utilities * el.search.h: Line and history searching utilities
*/ */
#ifndef _h_el_search #ifndef _h_el_search
#define _h_el_search #define _h_el_search
#include "histedit.h" #include "histedit.h"
typedef struct el_search_t { typedef struct el_search_t {
char *patbuf; /* The pattern buffer */ char *patbuf; /* The pattern buffer */
int patlen; /* Length of the pattern buffer */ size_t patlen; /* Length of the pattern buffer */
int patdir; /* Direction of the last search */ int patdir; /* Direction of the last search */
int chadir; /* Character search direction */ int chadir; /* Character search direction */
char chacha; /* Character we are looking for */ char chacha; /* Character we are looking for */
} el_search_t; } el_search_t;
protected int el_match __P((const char *, const char *)); protected int el_match(const char *, const char *);
protected int search_init __P((EditLine *)); protected int search_init(EditLine *);
protected void search_end __P((EditLine *)); protected void search_end(EditLine *);
protected int c_hmatch __P((EditLine *, const char *)); protected int c_hmatch(EditLine *, const char *);
protected void c_setpat __P((EditLine *)); protected void c_setpat(EditLine *);
protected el_action_t ce_inc_search __P((EditLine *, int)); protected el_action_t ce_inc_search(EditLine *, int);
protected el_action_t cv_search __P((EditLine *, int)); protected el_action_t cv_search(EditLine *, int);
protected el_action_t ce_search_line __P((EditLine *, char *, int)); protected el_action_t ce_search_line(EditLine *, char *, int);
protected el_action_t cv_repeat_srch __P((EditLine *, int)); protected el_action_t cv_repeat_srch(EditLine *, int);
protected el_action_t cv_csearch_back __P((EditLine *, int, int, int)); protected el_action_t cv_csearch_back(EditLine *, int, int, int);
protected el_action_t cv_csearch_fwd __P((EditLine *, int, int, int)); protected el_action_t cv_csearch_fwd(EditLine *, int, int, int);
#endif /* _h_el_search */ #endif /* _h_el_search */

View File

@ -1,2 +1,5 @@
major=0 # $NetBSD: shlib_version,v 1.11 2001/01/01 15:54:07 jdolecek Exp $
minor=0 # 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 * Copyright (c) 1992, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
#else #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
#endif /* not lint && not SCCSID */ #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 EditLine *sel = NULL;
private int sighdl[] = { private const int sighdl[] = {
#define _DO(a) (a), #define _DO(a) (a),
ALLSIGS ALLSIGS
#undef _DO #undef _DO
-1 - 1
}; };
private void sig_handler __P((int)); private void sig_handler(int);
/* sig_handler(): /* sig_handler():
* This is the handler called for all signals * This is the handler called for all signals
@ -70,40 +71,39 @@ private void sig_handler __P((int));
* state in a private variable * state in a private variable
*/ */
private void private void
sig_handler(signo) sig_handler(int signo)
int signo;
{ {
int i; int i;
sigset_t nset, oset; sigset_t nset, oset;
(void) sigemptyset(&nset); (void) sigemptyset(&nset);
(void) sigaddset(&nset, signo); (void) sigaddset(&nset, signo);
(void) sigprocmask(SIG_BLOCK, &nset, &oset); (void) sigprocmask(SIG_BLOCK, &nset, &oset);
switch (signo) { switch (signo) {
case SIGCONT: case SIGCONT:
tty_rawmode(sel); tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH) if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel); re_refresh(sel);
term__flush(); term__flush();
break; break;
case SIGWINCH: case SIGWINCH:
el_resize(sel); el_resize(sel);
break; break;
default: default:
tty_cookedmode(sel); tty_cookedmode(sel);
break; break;
} }
for (i = 0; sighdl[i] != -1; i++) for (i = 0; sighdl[i] != -1; i++)
if (signo == sighdl[i]) if (signo == sighdl[i])
break; break;
(void) signal(signo, sel->el_signal[i]); (void) signal(signo, sel->el_signal[i]);
(void) sigprocmask(SIG_SETMASK, &oset, NULL); (void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) kill(0, signo); (void) kill(0, signo);
} }
@ -111,27 +111,28 @@ sig_handler(signo)
* Initialize all signal stuff * Initialize all signal stuff
*/ */
protected int protected int
sig_init(el) sig_init(EditLine *el)
EditLine *el;
{ {
int i; int i;
sigset_t nset, oset; sigset_t nset, oset;
(void) sigemptyset(&nset); (void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, SIGWINCH); #define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS ALLSIGS
#undef _DO #undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset); (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); el->el_signal = (sig_t *) el_malloc(SIGSIZE);
for (i = 0; sighdl[i] != -1; i++) if (el->el_signal == NULL)
el->el_signal[i] = SIG_ERR; 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 * Clear all signal stuff
*/ */
protected void protected void
sig_end(el) sig_end(EditLine *el)
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 * set all the signal handlers
*/ */
protected void protected void
sig_set(el) sig_set(EditLine *el)
EditLine *el;
{ {
int i; int i;
sigset_t nset, oset; sigset_t nset, oset;
(void) sigemptyset(&nset); (void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, SIGWINCH); #define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS ALLSIGS
#undef _DO #undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset); (void) sigprocmask(SIG_BLOCK, &nset, &oset);
for (i = 0; sighdl[i] != -1; i++) { for (i = 0; sighdl[i] != -1; i++) {
sig_t s; sig_t s;
/* This could happen if we get interrupted */ /* This could happen if we get interrupted */
if ((s = signal(sighdl[i], sig_handler)) != sig_handler) if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
el->el_signal[i] = s; el->el_signal[i] = s;
} }
sel = el; sel = el;
(void) sigprocmask(SIG_SETMASK, &oset, NULL); (void) sigprocmask(SIG_SETMASK, &oset, NULL);
} }
@ -178,22 +178,22 @@ sig_set(el)
* clear all the signal handlers * clear all the signal handlers
*/ */
protected void protected void
sig_clr(el) sig_clr(EditLine *el)
EditLine *el;
{ {
int i; int i;
sigset_t nset, oset; sigset_t nset, oset;
(void) sigemptyset(&nset); (void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, SIGWINCH); #define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS ALLSIGS
#undef _DO #undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset); (void) sigprocmask(SIG_BLOCK, &nset, &oset);
for (i = 0; sighdl[i] != -1; i++) for (i = 0; sighdl[i] != -1; i++)
if (el->el_signal[i] != SIG_ERR) if (el->el_signal[i] != SIG_ERR)
(void) signal(sighdl[i], el->el_signal[i]); (void) signal(sighdl[i], el->el_signal[i]);
sel = NULL; /* we are going to die if the handler is called */ sel = NULL; /* we are going to die if the handler is
(void) sigprocmask(SIG_SETMASK, &oset, NULL); * 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 * Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
* el.sig.h: Signal handling functions * el.sig.h: Signal handling functions
*/ */
#ifndef _h_el_sig #ifndef _h_el_sig
#define _h_el_sig #define _h_el_sig
#include <signal.h> #include <signal.h>
@ -52,21 +52,21 @@
* Define here all the signals we are going to handle * Define here all the signals we are going to handle
* The _DO macro is used to iterate in the source code * The _DO macro is used to iterate in the source code
*/ */
#define ALLSIGS \ #define ALLSIGS \
_DO(SIGINT) \ _DO(SIGINT) \
_DO(SIGTSTP) \ _DO(SIGTSTP) \
_DO(SIGSTOP) \ _DO(SIGSTOP) \
_DO(SIGQUIT) \ _DO(SIGQUIT) \
_DO(SIGHUP) \ _DO(SIGHUP) \
_DO(SIGTERM) \ _DO(SIGTERM) \
_DO(SIGCONT) \ _DO(SIGCONT) \
_DO(SIGWINCH) _DO(SIGWINCH)
typedef sig_t *el_signal_t; typedef sig_t *el_signal_t;
protected void sig_end __P((EditLine*)); protected void sig_end(EditLine*);
protected int sig_init __P((EditLine*)); protected int sig_init(EditLine*);
protected void sig_set __P((EditLine*)); protected void sig_set(EditLine*);
protected void sig_clr __P((EditLine*)); protected void sig_clr(EditLine*);
#endif /* _h_el_sig */ #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 * Copyright (c) 1992, 1993
@ -42,7 +42,7 @@
* sys.h: Put all the stupid compiler and system dependencies here... * sys.h: Put all the stupid compiler and system dependencies here...
*/ */
#ifndef _h_sys #ifndef _h_sys
#define _h_sys #define _h_sys
#ifndef public #ifndef public
# define public /* Externally visible functions/variables */ # define public /* Externally visible functions/variables */
@ -61,20 +61,12 @@
#ifndef _PTR_T #ifndef _PTR_T
# define _PTR_T # define _PTR_T
# if __STDC__ typedef void *ptr_t;
typedef void* ptr_t;
# else
typedef char* ptr_t;
# endif
#endif #endif
#ifndef _IOCTL_T #ifndef _IOCTL_T
# define _IOCTL_T # define _IOCTL_T
# if __STDC__ typedef void *ioctl_t;
typedef void* ioctl_t;
# else
typedef char* ioctl_t;
# endif
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -86,33 +78,33 @@ typedef char* ioctl_t;
# undef REGEX # undef REGEX
# undef REGEXP # undef REGEXP
# include <malloc.h> # include <malloc.h>
typedef void (*sig_t)__P((int)); typedef void (*sig_t)(int);
# ifdef __GNUC__ # ifdef __GNUC__
/* /*
* Broken hdrs. * Broken hdrs.
*/ */
extern char *getenv __P((const char *)); extern char *getenv(const char *);
extern int fprintf __P((FILE *, const char *, ...)); extern int fprintf(FILE *, const char *, ...);
extern int sigsetmask __P((int)); extern int sigsetmask(int);
extern int sigblock __P((int)); extern int sigblock(int);
extern int ioctl __P((int, int, void *)); extern int ioctl(int, int, void *);
extern int fputc __P((int, FILE *)); extern int fputc(int, FILE *);
extern int fgetc __P((FILE *)); extern int fgetc(FILE *);
extern int fflush __P((FILE *)); extern int fflush(FILE *);
extern int tolower __P((int)); extern int tolower(int);
extern int toupper __P((int)); extern int toupper(int);
extern int errno, sys_nerr; extern int errno, sys_nerr;
extern char *sys_errlist[]; extern char *sys_errlist[];
extern void perror __P((const char *)); extern void perror(const char *);
extern int read __P((int, const char*, int)); extern int read(int, const char*, int);
# include <string.h> # include <string.h>
# define strerror(e) sys_errlist[e] # define strerror(e) sys_errlist[e]
# endif # endif
# ifdef SABER # ifdef SABER
extern ptr_t memcpy __P((ptr_t, const ptr_t, size_t)); extern ptr_t memcpy(ptr_t, const ptr_t, size_t);
extern ptr_t memset __P((ptr_t, int, size_t)); extern ptr_t memset(ptr_t, int, size_t);
# endif # endif
extern char *fgetline __P((FILE *, int *)); extern char *fgetline(FILE *, int *);
#endif #endif
#endif /* _h_sys */ #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 * Copyright (c) 1992, 1993
@ -42,79 +42,83 @@
* el.term.h: Termcap header * el.term.h: Termcap header
*/ */
#ifndef _h_el_term #ifndef _h_el_term
#define _h_el_term #define _h_el_term
#include "histedit.h" #include "histedit.h"
typedef struct { /* Symbolic function key bindings */ typedef struct { /* Symbolic function key bindings */
char *name; /* name of the key */ char *name; /* name of the key */
int key; /* Index in termcap table */ int key; /* Index in termcap table */
key_value_t fun; /* Function bound to it */ key_value_t fun; /* Function bound to it */
int type; /* Type of function */ int type; /* Type of function */
} fkey_t; } fkey_t;
typedef struct { typedef struct {
coord_t t_size; /* # lines and cols */ coord_t t_size; /* # lines and cols */
bool_t t_flags; int t_flags;
#define TERM_CAN_INSERT 0x01 /* Has insert cap */ #define TERM_CAN_INSERT 0x001 /* Has insert cap */
#define TERM_CAN_DELETE 0x02 /* Has delete cap */ #define TERM_CAN_DELETE 0x002 /* Has delete cap */
#define TERM_CAN_CEOL 0x04 /* Has CEOL cap */ #define TERM_CAN_CEOL 0x004 /* Has CEOL cap */
#define TERM_CAN_TAB 0x08 /* Can use tabs */ #define TERM_CAN_TAB 0x008 /* Can use tabs */
#define TERM_CAN_ME 0x10 /* Can turn all attrs. */ #define TERM_CAN_ME 0x010 /* Can turn all attrs. */
#define TERM_CAN_UP 0x20 /* Can move up */ #define TERM_CAN_UP 0x020 /* Can move up */
#define TERM_HAS_META 0x40 /* Has a meta key */ #define TERM_HAS_META 0x040 /* Has a meta key */
char *t_buf; /* Termcap buffer */ #define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
int t_loc; /* location used */ #define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
char **t_str; /* termcap strings */ char *t_buf; /* Termcap buffer */
int *t_val; /* termcap values */ int t_loc; /* location used */
char *t_cap; /* Termcap buffer */ char **t_str; /* termcap strings */
fkey_t *t_fkey; /* Array of keys */ int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
fkey_t *t_fkey; /* Array of keys */
} el_term_t; } el_term_t;
/* /*
* fKey indexes * fKey indexes
*/ */
#define A_K_DN 0 #define A_K_DN 0
#define A_K_UP 1 #define A_K_UP 1
#define A_K_LT 2 #define A_K_LT 2
#define A_K_RT 3 #define A_K_RT 3
#define A_K_NKEYS 4 #define A_K_HO 4
#define A_K_EN 5
#define A_K_NKEYS 6
protected void term_move_to_line __P((EditLine *, int)); protected void term_move_to_line(EditLine *, int);
protected void term_move_to_char __P((EditLine *, int)); protected void term_move_to_char(EditLine *, int);
protected void term_clear_EOL __P((EditLine *, int)); protected void term_clear_EOL(EditLine *, int);
protected void term_overwrite __P((EditLine *, char *, int)); protected void term_overwrite(EditLine *, char *, int);
protected void term_insertwrite __P((EditLine *, char *, int)); protected void term_insertwrite(EditLine *, char *, int);
protected void term_deletechars __P((EditLine *, int)); protected void term_deletechars(EditLine *, int);
protected void term_clear_screen __P((EditLine *)); protected void term_clear_screen(EditLine *);
protected void term_beep __P((EditLine *)); protected void term_beep(EditLine *);
protected void term_change_size __P((EditLine *, int, int)); protected int term_change_size(EditLine *, int, int);
protected int term_get_size __P((EditLine *, int *, int *)); protected int term_get_size(EditLine *, int *, int *);
protected int term_init __P((EditLine *)); protected int term_init(EditLine *);
protected void term_bind_arrow __P((EditLine *)); protected void term_bind_arrow(EditLine *);
protected void term_print_arrow __P((EditLine *, char *)); protected void term_print_arrow(EditLine *, char *);
protected int term_clear_arrow __P((EditLine *, char *)); protected int term_clear_arrow(EditLine *, char *);
protected int term_set_arrow __P((EditLine *, char *, protected int term_set_arrow(EditLine *, char *, key_value_t *, int);
key_value_t *, int)); protected void term_end(EditLine *);
protected void term_end __P((EditLine *)); protected int term_set(EditLine *, char *);
protected int term_set __P((EditLine *, char *)); protected int term_settc(EditLine *, int, char **);
protected int term_settc __P((EditLine *, int, char **)); protected int term_telltc(EditLine *, int, char **);
protected int term_telltc __P((EditLine *, int, char **)); protected int term_echotc(EditLine *, int, char **);
protected int term_echotc __P((EditLine *, int, char **)); protected int term__putc(int);
protected void term__flush(void);
protected void term__putc __P((int));
protected void term__flush __P((void));
/* /*
* Easy access macros * 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_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE) #define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL) #define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB) #define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME) #define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
#define EL_HAS_META (EL_FLAGS & TERM_HAS_META) #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 */ #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 * Copyright (c) 1992, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
#include <sys/cdefs.h>
#if !defined(lint) && !defined(SCCSID) #if !defined(lint) && !defined(SCCSID)
#if 0 #if 0
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
#else #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
#endif /* not lint && not SCCSID */ #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 <stdlib.h>
#include "tokenizer.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_KEEP 1
#define TOK_EAT 2 #define TOK_EAT 2
#define WINCR 20 #define WINCR 20
#define AINCR 10 #define AINCR 10
#define tok_malloc(a) malloc(a) #define tok_malloc(a) malloc(a)
#define tok_free(a) free(a) #define tok_free(a) free(a)
#define tok_realloc(a, b) realloc(a, b) #define tok_realloc(a, b) realloc(a, b)
struct tokenizer { struct tokenizer {
char *ifs; /* In field separator */ char *ifs; /* In field separator */
int argc, amax; /* Current and maximum number of args */ int argc, amax; /* Current and maximum number of args */
char **argv; /* Argument list */ char **argv; /* Argument list */
char *wptr, *wmax; /* Space and limit on the word buffer */ char *wptr, *wmax; /* Space and limit on the word buffer */
char *wstart; /* Beginning of next word */ char *wstart; /* Beginning of next word */
char *wspace; /* Space of word buffer */ char *wspace; /* Space of word buffer */
quote_t quote; /* Quoting state */ quote_t quote; /* Quoting state */
int flags; /* flags; */ int flags; /* flags; */
}; };
private void tok_finish __P((Tokenizer *)); private void tok_finish(Tokenizer *);
/* tok_finish(): /* tok_finish():
* Finish a word in the tokenizer. * Finish a word in the tokenizer.
*/ */
private void private void
tok_finish(tok) tok_finish(Tokenizer *tok)
Tokenizer *tok;
{ {
*tok->wptr = '\0';
if ((tok->flags & TOK_KEEP) || tok->wptr != tok->wstart) { *tok->wptr = '\0';
tok->argv[tok->argc++] = tok->wstart; if ((tok->flags & TOK_KEEP) || tok->wptr != tok->wstart) {
tok->argv[tok->argc] = NULL; tok->argv[tok->argc++] = tok->wstart;
tok->wstart = ++tok->wptr; tok->argv[tok->argc] = NULL;
} tok->wstart = ++tok->wptr;
tok->flags &= ~TOK_KEEP; }
tok->flags &= ~TOK_KEEP;
} }
@ -103,24 +106,27 @@ tok_finish(tok)
* Initialize the tokenizer * Initialize the tokenizer
*/ */
public Tokenizer * public Tokenizer *
tok_init(ifs) tok_init(const char *ifs)
const char *ifs;
{ {
Tokenizer* tok = (Tokenizer*) tok_malloc(sizeof(Tokenizer)); Tokenizer *tok = (Tokenizer *) tok_malloc(sizeof(Tokenizer));
tok->ifs = strdup(ifs ? ifs : IFS); tok->ifs = strdup(ifs ? ifs : IFS);
tok->argc = 0; tok->argc = 0;
tok->amax = AINCR; tok->amax = AINCR;
tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax); tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
tok->argv[0] = NULL; if (tok->argv == NULL)
tok->wspace = (char *) tok_malloc(WINCR); return (NULL);
tok->wmax = tok->wspace + WINCR; tok->argv[0] = NULL;
tok->wstart = tok->wspace; tok->wspace = (char *) tok_malloc(WINCR);
tok->wptr = tok->wspace; if (tok->wspace == NULL)
tok->flags = 0; return (NULL);
tok->quote = Q_none; 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 * Reset the tokenizer
*/ */
public void public void
tok_reset(tok) tok_reset(Tokenizer *tok)
Tokenizer *tok;
{ {
tok->argc = 0;
tok->wstart = tok->wspace; tok->argc = 0;
tok->wptr = tok->wspace; tok->wstart = tok->wspace;
tok->flags = 0; tok->wptr = tok->wspace;
tok->quote = Q_none; tok->flags = 0;
tok->quote = Q_none;
} }
@ -143,13 +149,13 @@ tok_reset(tok)
* Clean up * Clean up
*/ */
public void public void
tok_end(tok) tok_end(Tokenizer *tok)
Tokenizer *tok;
{ {
tok_free((ptr_t) tok->ifs);
tok_free((ptr_t) tok->wspace); tok_free((ptr_t) tok->ifs);
tok_free((ptr_t) tok->argv); tok_free((ptr_t) tok->wspace);
tok_free((ptr_t) tok); tok_free((ptr_t) tok->argv);
tok_free((ptr_t) tok);
} }
@ -161,231 +167,232 @@ tok_end(tok)
* 3: Quoted return * 3: Quoted return
* 2: Unmatched double quote * 2: Unmatched double quote
* 1: Unmatched single quote * 1: Unmatched single quote
* 0: Ok * 0: Ok
*/ */
public int public int
tok_line(tok, line, argc, argv) tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv)
Tokenizer *tok;
const char* line;
int *argc;
char ***argv;
{ {
const char *ptr; const char *ptr;
while (1) { for (;;) {
switch (*(ptr = line++)) { switch (*(ptr = line++)) {
case '\'': case '\'':
tok->flags |= TOK_KEEP; tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT; tok->flags &= ~TOK_EAT;
switch (tok->quote) { switch (tok->quote) {
case Q_none: case Q_none:
tok->quote = Q_single; /* Enter single quote mode */ tok->quote = Q_single; /* Enter single quote
break; * mode */
break;
case Q_single: /* Exit single quote mode */ case Q_single: /* Exit single quote mode */
tok->quote = Q_none; tok->quote = Q_none;
break; break;
case Q_one: /* Quote this ' */ case Q_one: /* Quote this ' */
tok->quote = Q_none; tok->quote = Q_none;
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
case Q_double: /* Stay in double quote mode */ case Q_double: /* Stay in double quote mode */
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
case Q_doubleone: /* Quote this ' */ case Q_doubleone: /* Quote this ' */
tok->quote = Q_double; tok->quote = Q_double;
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
default: default:
return(-1); return (-1);
} }
break; break;
case '"': case '"':
tok->flags &= ~TOK_EAT; tok->flags &= ~TOK_EAT;
tok->flags |= TOK_KEEP; tok->flags |= TOK_KEEP;
switch (tok->quote) { switch (tok->quote) {
case Q_none: /* Enter double quote mode */ case Q_none: /* Enter double quote mode */
tok->quote = Q_double; tok->quote = Q_double;
break; break;
case Q_double: case Q_double: /* Exit double quote mode */
tok->quote = Q_none; /* Exit double quote mode */ tok->quote = Q_none;
break; break;
case Q_one: /* Quote this " */ case Q_one: /* Quote this " */
tok->quote = Q_none; tok->quote = Q_none;
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
case Q_single: /* Stay in single quote mode */ case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
case Q_doubleone: /* Quote this " */ case Q_doubleone: /* Quote this " */
tok->quote = Q_double; tok->quote = Q_double;
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
default: default:
return(-1); return (-1);
} }
break; break;
case '\\': case '\\':
tok->flags |= TOK_KEEP; tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT; tok->flags &= ~TOK_EAT;
switch (tok->quote) { switch (tok->quote) {
case Q_none: /* Quote next character */ case Q_none: /* Quote next character */
tok->quote = Q_one; tok->quote = Q_one;
break; break;
case Q_double: case Q_double: /* Quote next character */
tok->quote = Q_doubleone;/* Quote next character */ tok->quote = Q_doubleone;
break; break;
case Q_one: case Q_one: /* Quote this, restore state */
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
tok->quote = Q_none; /* Quote this, restore state */ tok->quote = Q_none;
break; break;
case Q_single: /* Stay in single quote mode */ case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
case Q_doubleone: /* Quote this \ */ case Q_doubleone: /* Quote this \ */
tok->quote = Q_double; tok->quote = Q_double;
*tok->wptr++ = *ptr; *tok->wptr++ = *ptr;
break; break;
default: default:
return(-1); return (-1);
} }
break; break;
case '\n': case '\n':
tok->flags &= ~TOK_EAT; tok->flags &= ~TOK_EAT;
switch (tok->quote) { switch (tok->quote) {
case Q_none: case Q_none:
tok_finish(tok); tok_finish(tok);
*argv = tok->argv; *argv = tok->argv;
*argc = tok->argc; *argc = tok->argc;
return(0); return (0);
case Q_single: case Q_single:
case Q_double: case Q_double:
*tok->wptr++ = *ptr; /* Add the return */ *tok->wptr++ = *ptr; /* Add the return */
break; break;
case Q_doubleone:
tok->flags |= TOK_EAT;
tok->quote = Q_double; /* Back to double, eat the '\n' */
break;
case Q_one: case Q_doubleone: /* Back to double, eat the '\n' */
tok->flags |= TOK_EAT; tok->flags |= TOK_EAT;
tok->quote = Q_none; /* No quote, more eat the '\n' */ tok->quote = Q_double;
break; break;
default: case Q_one: /* No quote, more eat the '\n' */
return(0); tok->flags |= TOK_EAT;
} tok->quote = Q_none;
break; break;
case '\0': default:
switch (tok->quote) { return (0);
case Q_none: }
/* Finish word and return */ break;
if (tok->flags & TOK_EAT) {
tok->flags &= ~TOK_EAT; case '\0':
return 3; 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: if (tok->wptr >= tok->wmax - 4) {
return(1); 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: if (offs != 0) {
return(2); int i;
for (i = 0; i < tok->argc; i++)
case Q_doubleone: tok->argv[i] = tok->argv[i] + offs;
tok->quote = Q_double; tok->wptr = tok->wptr + offs;
*tok->wptr++ = *ptr; tok->wstart = tok->wstart + offs;
break; tok->wmax = s + size;
tok->wspace = s;
case Q_one: }
tok->quote = Q_none; }
*tok->wptr++ = *ptr; if (tok->argc >= tok->amax - 4) {
break; char **p;
tok->amax += AINCR;
default: p = (char **) tok_realloc(tok->argv,
return(-1); tok->amax * sizeof(char *));
} if (p == NULL)
break; return (-1);
tok->argv = p;
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 (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 * Copyright (c) 1992, 1993
@ -42,14 +42,13 @@
* tokenizer.h: Header file for tokenizer routines * tokenizer.h: Header file for tokenizer routines
*/ */
#ifndef _h_tokenizer #ifndef _h_tokenizer
#define _h_tokenizer #define _h_tokenizer
typedef struct tokenizer Tokenizer; typedef struct tokenizer Tokenizer;
Tokenizer *tok_init __P((const char *)); Tokenizer *tok_init(const char *);
void tok_reset __P((Tokenizer *)); void tok_reset(Tokenizer *);
void tok_end __P((Tokenizer *)); void tok_end(Tokenizer *);
int tok_line __P((Tokenizer *, const char *, int tok_line(Tokenizer *, const char *, int *, char ***);
int *, char ***));
#endif /* _h_tokenizer */ #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 * Copyright (c) 1992, 1993
@ -42,13 +42,14 @@
* el.tty.h: Local terminal header * el.tty.h: Local terminal header
*/ */
#ifndef _h_el_tty #ifndef _h_el_tty
#define _h_el_tty #define _h_el_tty
#include "histedit.h" #include "histedit.h"
#include <termios.h> #include <termios.h>
#include <unistd.h>
/* Define our own since everyone gets it wrong! */ /* Define our own since everyone gets it wrong! */
#define CONTROL(A) ((A) & 037) #define CONTROL(A) ((A) & 037)
/* /*
* Aix compatible names * Aix compatible names
@ -407,66 +408,66 @@
# endif /* NUMCC */ # endif /* NUMCC */
#endif /* !POSIX */ #endif /* !POSIX */
#define C_INTR 0 #define C_INTR 0
#define C_QUIT 1 #define C_QUIT 1
#define C_ERASE 2 #define C_ERASE 2
#define C_KILL 3 #define C_KILL 3
#define C_EOF 4 #define C_EOF 4
#define C_EOL 5 #define C_EOL 5
#define C_EOL2 6 #define C_EOL2 6
#define C_SWTCH 7 #define C_SWTCH 7
#define C_DSWTCH 8 #define C_DSWTCH 8
#define C_ERASE2 9 #define C_ERASE2 9
#define C_START 10 #define C_START 10
#define C_STOP 11 #define C_STOP 11
#define C_WERASE 12 #define C_WERASE 12
#define C_SUSP 13 #define C_SUSP 13
#define C_DSUSP 14 #define C_DSUSP 14
#define C_REPRINT 15 #define C_REPRINT 15
#define C_DISCARD 16 #define C_DISCARD 16
#define C_LNEXT 17 #define C_LNEXT 17
#define C_STATUS 18 #define C_STATUS 18
#define C_PAGE 19 #define C_PAGE 19
#define C_PGOFF 20 #define C_PGOFF 20
#define C_KILL2 21 #define C_KILL2 21
#define C_BRK 22 #define C_BRK 22
#define C_MIN 23 #define C_MIN 23
#define C_TIME 24 #define C_TIME 24
#define C_NCC 25 #define C_NCC 25
#define C_SH(A) (1 << (A)) #define C_SH(A) (1 << (A))
/* /*
* Terminal dependend data structures * Terminal dependend data structures
*/ */
#define EX_IO 0 /* while we are executing */ #define EX_IO 0 /* while we are executing */
#define ED_IO 1 /* while we are editing */ #define ED_IO 1 /* while we are editing */
#define TS_IO 2 /* new mode from terminal */ #define TS_IO 2 /* new mode from terminal */
#define QU_IO 2 /* used only for quoted chars */ #define QU_IO 2 /* used only for quoted chars */
#define NN_IO 3 /* The number of entries */ #define NN_IO 3 /* The number of entries */
#define M_INP 0 #define MD_INP 0
#define M_OUT 1 #define MD_OUT 1
#define M_CTL 2 #define MD_CTL 2
#define M_LIN 3 #define MD_LIN 3
#define M_CHAR 4 #define MD_CHAR 4
#define M_NN 5 #define MD_NN 5
typedef struct { typedef struct {
char *t_name; char *t_name;
u_int t_setmask; u_int t_setmask;
u_int t_clrmask; u_int t_clrmask;
} ttyperm_t[NN_IO][M_NN]; } ttyperm_t[NN_IO][MD_NN];
typedef unsigned char ttychar_t[NN_IO][C_NCC]; typedef unsigned char ttychar_t[NN_IO][C_NCC];
protected int tty_init __P((EditLine *)); protected int tty_init(EditLine *);
protected void tty_end __P((EditLine *)); protected void tty_end(EditLine *);
protected int tty_stty __P((EditLine *, int, char**)); protected int tty_stty(EditLine *, int, char**);
protected int tty_rawmode __P((EditLine *)); protected int tty_rawmode(EditLine *);
protected int tty_cookedmode __P((EditLine *)); protected int tty_cookedmode(EditLine *);
protected int tty_quotemode __P((EditLine *)); protected int tty_quotemode(EditLine *);
protected int tty_noquotemode __P((EditLine *)); protected int tty_noquotemode(EditLine *);
protected void tty_bind_char __P((EditLine *, int)); protected void tty_bind_char(EditLine *, int);
typedef struct { typedef struct {
ttyperm_t t_t; ttyperm_t t_t;

1012
vi.c

File diff suppressed because it is too large Load Diff