+ Sync with NetBSD, bringing in feature enhancements.

+ Convert to ANSI-C function definitions
+ style(9)

Submitted by:	kris
This commit is contained in:
David E. O'Brien 2001-10-01 08:41:27 +00:00
parent c3aa3459b1
commit 3c19577344
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=84260
37 changed files with 9548 additions and 8454 deletions

View File

@ -1,8 +1,9 @@
# $NetBSD: Makefile,v 1.19 2000/08/15 12:01:40 mrg Exp $
# @(#)Makefile 8.1 (Berkeley) 6/4/93
# $FreeBSD$
LIB= edit
SHLIB_MAJOR= 3
SHLIB_MAJOR= 4
SHLIB_MINOR= 0
OSRCS= chared.c common.c el.c emacs.c fcns.c help.c hist.c key.c map.c \
@ -14,12 +15,13 @@ LDADD= -ltermcap
MAN= editline.3 editrc.5
MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \
editline.3 el_get.3 \
editline.3 el_gets.3 editline.3 el_getc.3 editline.3 el_push.3 \
editline.3 el_parse.3 editline.3 el_set.3 editline.3 el_source.3 \
editline.3 el_resize.3 editline.3 el_line.3 \
editline.3 el_insertstr.3 editline.3 el_deletestr.3 \
editline.3 history_init.3 editline.3 history_end.3 \
editline.3 history.3 editline.3 el_data_get.3 editline.3 el_data_set.3
editline.3 history.3
# For speed and debugging
#SRCS= ${OSRCS} tokenizer.c history.c
@ -27,6 +29,7 @@ MLINKS= editline.3 el_init.3 editline.3 el_end.3 editline.3 el_reset.3 \
SRCS= editline.c tokenizer.c history.c
SRCS+= common.h emacs.h fcns.h help.h vi.h
INCS= histedit.h
CLEANFILES+=common.h editline.c emacs.h fcns.c fcns.h help.c help.h vi.h
CFLAGS+=-I. -I${.CURDIR}
@ -57,11 +60,14 @@ help.c: ${ASRC} makelist
help.h: ${ASRC} makelist
sh ${.CURDIR}/makelist -bh ${ASRC} > ${.TARGET}
editline.c:
sh ${.CURDIR}/makelist -e ${OSRCS} > ${.TARGET}
editline.c: ${OSRCS}
sh ${.CURDIR}/makelist -e ${.ALLSRC:T} > ${.TARGET}
beforedepend editline.o editline.po editline.So: \
vi.h emacs.h common.h fcns.h fcns.c help.h help.c
# minimal dependency to make "make depend" optional
editline.o editline.po editline.So editline.ln: \
common.h emacs.h fcns.c fcns.h help.c help.h vi.h
test.o: ${.CURDIR}/TEST/test.c
test: test.o libedit.a ${DPADD} ${LIBTERMCAP}
${CC} ${CFLAGS} ${.ALLSRC} -o ${.TARGET} libedit.a ${LDADD}

View File

@ -34,15 +34,17 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
__COPYRIGHT("@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
__RCSID("$NetBSD: test.c,v 1.8 1999/09/21 00:07:03 lukem Exp $");
__FBSDID("$FreeBSD$");
/*
* test.c: A little test program
@ -63,179 +65,200 @@ static char sccsid[] = "@(#)test.c 8.1 (Berkeley) 6/4/93";
static int continuation = 0;
static EditLine *el = NULL;
static u_char complete(EditLine *, int);
int main(int, char **);
static char *prompt(EditLine *);
static void sig(int);
static char *
/*ARGSUSED*/
prompt(el)
EditLine *el;
prompt(EditLine *el)
{
static char a[] = "Edit$";
static char b[] = "Edit>";
return continuation ? b : a;
static char a[] = "Edit$";
static char b[] = "Edit>";
return (continuation ? b : a);
}
static void
sig(i)
int i;
sig(int i)
{
(void) fprintf(stderr, "Got signal %d.\n", i);
el_reset(el);
(void) fprintf(stderr, "Got signal %d.\n", i);
el_reset(el);
}
static unsigned char
/*ARGSUSED*/
complete(el, ch)
EditLine *el;
int ch;
complete(EditLine *el, int ch)
{
DIR *dd = opendir(".");
struct dirent *dp;
const char* ptr;
const LineInfo *lf = el_line(el);
int len;
DIR *dd = opendir(".");
struct dirent *dp;
const char* ptr;
const LineInfo *lf = el_line(el);
int len;
/*
* Find the last word
*/
for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
continue;
len = lf->cursor - ++ptr;
/*
* Find the last word
*/
for (ptr = lf->cursor - 1; !isspace(*ptr) && ptr > lf->buffer; ptr--)
continue;
len = lf->cursor - ++ptr;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1)
return CC_ERROR;
else
return CC_REFRESH;
for (dp = readdir(dd); dp != NULL; dp = readdir(dd)) {
if (len > strlen(dp->d_name))
continue;
if (strncmp(dp->d_name, ptr, len) == 0) {
closedir(dd);
if (el_insertstr(el, &dp->d_name[len]) == -1)
return (CC_ERROR);
else
return (CC_REFRESH);
}
}
}
closedir(dd);
return CC_ERROR;
closedir(dd);
return (CC_ERROR);
}
int
/*ARGSUSED*/
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
int num;
const char *buf;
Tokenizer *tok;
History *hist;
int num;
const char *buf;
Tokenizer *tok;
int lastevent = 0, ncontinuation;
History *hist;
HistEvent ev;
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
(void) signal(SIGTERM, sig);
(void) signal(SIGINT, sig);
(void) signal(SIGQUIT, sig);
(void) signal(SIGHUP, sig);
(void) signal(SIGTERM, sig);
hist = history_init(); /* Init the builtin history */
history(hist, H_EVENT, 100); /* Remember 100 events */
hist = history_init(); /* Init the builtin history */
/* Remember 100 events */
history(hist, &ev, H_SETSIZE, 100);
tok = tok_init(NULL); /* Initialize the tokenizer */
tok = tok_init(NULL); /* Initialize the tokenizer */
el = el_init(*argv, stdin, stdout); /* Initialize editline */
/* Initialize editline */
el = el_init(*argv, stdin, stdout, stderr);
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
el_set(el, EL_EDITOR, "vi"); /* Default editor is vi */
el_set(el, EL_SIGNAL, 1); /* Handle signals gracefully */
el_set(el, EL_PROMPT, prompt); /* Set the prompt function */
/* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist);
/* Tell editline to use this history interface */
el_set(el, EL_HIST, history, hist);
/* Add a user-defined function */
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
/* Add a user-defined function */
el_set(el, EL_ADDFN, "ed-complete", "Complete argument", complete);
el_set(el, EL_BIND, "^I", "ed-complete", NULL);/* Bind tab to it */
/* Bind tab to it */
el_set(el, EL_BIND, "^I", "ed-complete", NULL);
/*
* Bind j, k in vi command mode to previous and next line, instead
* of previous and next history.
*/
el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
/*
* Bind j, k in vi command mode to previous and next line, instead
* of previous and next history.
*/
el_set(el, EL_BIND, "-a", "k", "ed-prev-line", NULL);
el_set(el, EL_BIND, "-a", "j", "ed-next-line", NULL);
/*
* Source the user's defaults file.
*/
el_source(el, NULL);
/*
* Source the user's defaults file.
*/
el_source(el, NULL);
while ((buf = el_gets(el, &num)) != NULL && num != 0) {
int ac;
char **av;
while ((buf = el_gets(el, &num)) != NULL && num != 0) {
int ac;
char **av;
#ifdef DEBUG
(void) fprintf(stderr, "got %d %s", num, buf);
(void) fprintf(stderr, "got %d %s", num, buf);
#endif
if (!continuation && num == 1)
continue;
if (tok_line(tok, buf, &ac, &av) > 0) {
history(hist, continuation ? H_ADD : H_ENTER, buf);
continuation = 1;
continue;
if (!continuation && num == 1)
continue;
if (tok_line(tok, buf, &ac, &av) > 0)
ncontinuation = 1;
#if 0
if (continuation) {
/*
* Append to the right event in case the user
* moved around in history.
*/
if (history(hist, &ev, H_SET, lastevent) == -1)
err(1, "%d: %s\n", lastevent, ev.str);
history(hist, &ev, H_ADD , buf);
} else {
history(hist, &ev, H_ENTER, buf);
lastevent = ev.num;
}
#else
/* Simpler */
history(hist, &ev, continuation ? H_APPEND : H_ENTER, buf);
#endif
continuation = ncontinuation;
ncontinuation = 0;
if (strcmp(av[0], "history") == 0) {
int rv;
switch (ac) {
case 1:
for (rv = history(hist, &ev, H_LAST); rv != -1;
rv = history(hist, &ev, H_PREV))
(void) fprintf(stdout, "%4d %s",
ev.num, ev.str);
break;
case 2:
if (strcmp(av[1], "clear") == 0)
history(hist, &ev, H_CLEAR);
else
goto badhist;
break;
case 3:
if (strcmp(av[1], "load") == 0)
history(hist, &ev, H_LOAD, av[2]);
else if (strcmp(av[1], "save") == 0)
history(hist, &ev, H_SAVE, av[2]);
break;
badhist:
default:
(void) fprintf(stderr,
"Bad history arguments\n");
break;
}
} else if (el_parse(el, ac, av) == -1) {
switch (fork()) {
case 0:
execvp(av[0], av);
perror(av[0]);
_exit(1);
/*NOTREACHED*/
break;
case -1:
perror("fork");
break;
default:
if (wait(&num) == -1)
perror("wait");
(void) fprintf(stderr, "Exit %x\n", num);
break;
}
}
tok_reset(tok);
}
history(hist, continuation ? H_ADD : H_ENTER, buf);
continuation = 0;
el_end(el);
tok_end(tok);
history_end(hist);
if (strcmp(av[0], "history") == 0) {
const struct HistEvent *he;
switch (ac) {
case 1:
for (he = history(hist, H_LAST); he;
he = history(hist, H_PREV))
(void) fprintf(stdout, "%4d %s", he->num, he->str);
break;
case 2:
if (strcmp(av[1], "clear") == 0)
history(hist, H_CLEAR);
else
goto badhist;
break;
case 3:
if (strcmp(av[1], "load") == 0)
history(hist, H_LOAD, av[2]);
else if (strcmp(av[1], "save") == 0)
history(hist, H_SAVE, av[2]);
break;
badhist:
default:
(void) fprintf(stderr, "Bad history arguments\n");
break;
}
}
else if (el_parse(el, ac, av) == -1) {
switch (fork()) {
case 0:
execvp(av[0], av);
perror(av[0]);
_exit(1);
/*NOTREACHED*/
break;
case -1:
perror("fork");
break;
default:
if (wait(&num) == -1)
perror("wait");
(void) fprintf(stderr, "Exit %x\n", num);
break;
}
}
tok_reset(tok);
}
el_end(el);
tok_end(tok);
history_end(hist);
return 0;
return (0);
}

File diff suppressed because it is too large Load Diff

View File

@ -34,20 +34,22 @@
* SUCH DAMAGE.
*
* @(#)chared.h 8.1 (Berkeley) 6/4/93
* $NetBSD: chared.h,v 1.5 2000/09/04 22:06:29 lukem Exp $
* $FreeBSD$
*/
/*
* el.chared.h: Character editor interface
*/
#ifndef _h_el_chared
#define _h_el_chared
#define _h_el_chared
#include <ctype.h>
#include <string.h>
#include "histedit.h"
#define EL_MAXMACRO 10
#define EL_MAXMACRO 10
/*
* This is a issue of basic "vi" look-and-feel. Defining VI_MOVE works
@ -59,42 +61,42 @@
* Probably the best fix is to make all the editing commands aware of
* this fact.
*/
#define VI_MOVE
#define VI_MOVE
typedef struct c_macro_t {
int level;
char **macro;
char *nline;
int level;
char **macro;
char *nline;
} c_macro_t;
/*
* Undo information for both vi and emacs
*/
typedef struct c_undo_t {
int action;
int isize;
int dsize;
char *ptr;
char *buf;
int action;
size_t isize;
size_t dsize;
char *ptr;
char *buf;
} c_undo_t;
/*
* Current action information for vi
*/
typedef struct c_vcmd_t {
int action;
char *pos;
char *ins;
int action;
char *pos;
char *ins;
} c_vcmd_t;
/*
* Kill buffer for emacs
*/
typedef struct c_kill_t {
char *buf;
char *last;
char *mark;
char *buf;
char *last;
char *mark;
} c_kill_t;
/*
@ -102,30 +104,30 @@ typedef struct c_kill_t {
* commands from both editors!
*/
typedef struct el_chared_t {
c_undo_t c_undo;
c_kill_t c_kill;
c_vcmd_t c_vcmd;
c_macro_t c_macro;
c_undo_t c_undo;
c_kill_t c_kill;
c_vcmd_t c_vcmd;
c_macro_t c_macro;
} el_chared_t;
#define STReof "^D\b\b"
#define STRQQ "\"\""
#define STReof "^D\b\b"
#define STRQQ "\"\""
#define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (isprint(a))
#define isglob(a) (strchr("*[]?", (a)) != NULL)
#define isword(a) (isprint(a))
#define NOP 0x00
#define DELETE 0x01
#define INSERT 0x02
#define CHANGE 0x04
#define NOP 0x00
#define DELETE 0x01
#define INSERT 0x02
#define CHANGE 0x04
#define CHAR_FWD 0
#define CHAR_BACK 1
#define CHAR_FWD 0
#define CHAR_BACK 1
#define MODE_INSERT 0
#define MODE_REPLACE 1
#define MODE_REPLACE_1 2
#define MODE_INSERT 0
#define MODE_REPLACE 1
#define MODE_REPLACE_1 2
#include "common.h"
#include "vi.h"
@ -134,26 +136,25 @@ typedef struct el_chared_t {
#include "fcns.h"
protected int cv__isword __P((int));
protected void cv_delfini __P((EditLine *));
protected char *cv__endword __P((char *, char *, int));
protected int ce__isword __P((int));
protected int c___isword __P((int));
protected void cv_undo __P((EditLine *, int, int, char *));
protected char *cv_next_word __P((EditLine*, char *, char *, int,
int (*)(int)));
protected char *cv_prev_word __P((EditLine*, char *, char *, int,
int (*)(int)));
protected char *c__next_word __P((char *, char *, int, int (*)(int)));
protected char *c__prev_word __P((char *, char *, int, int (*)(int)));
protected void c_insert __P((EditLine *, int));
protected void c_delbefore __P((EditLine *, int));
protected void c_delafter __P((EditLine *, int));
protected int c_gets __P((EditLine *, char *));
protected int c_hpos __P((EditLine *));
protected int cv__isword(int);
protected void cv_delfini(EditLine *);
protected char *cv__endword(char *, char *, int);
protected int ce__isword(int);
protected int c___isword(int);
protected void cv_undo(EditLine *, int, size_t, char *);
protected char *cv_next_word(EditLine*, char *, char *, int, int (*)(int));
protected char *cv_prev_word(EditLine*, char *, char *, int, int (*)(int));
protected char *c__next_word(char *, char *, int, int (*)(int));
protected char *c__prev_word(char *, char *, int, int (*)(int));
protected void c_insert(EditLine *, int);
protected void c_delbefore(EditLine *, int);
protected void c_delafter(EditLine *, int);
protected int c_gets(EditLine *, char *);
protected int c_hpos(EditLine *);
protected int ch_init __P((EditLine *));
protected void ch_reset __P((EditLine *));
protected void ch_end __P((EditLine *));
protected int ch_init(EditLine *);
protected void ch_reset(EditLine *);
protected int ch_enlargebufs __P((EditLine *, size_t));
protected void ch_end(EditLine *);
#endif /* _h_el_chared */

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,7 @@
.\" $NetBSD: editline.3,v 1.4 1997/01/14 04:17:23 lukem Exp $
.\" $NetBSD: editline.3,v 1.20 2000/02/28 17:41:05 chopps Exp $
.\" $FreeBSD$
.\"
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
.\" Copyright (c) 1997-1999 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
@ -24,8 +25,8 @@
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@ -33,9 +34,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd January 11, 1997
.Dd November 12, 1999
.Os
.Dt EDITLINE 3
.Sh NAME
@ -53,8 +52,6 @@
.Nm el_line ,
.Nm el_insertstr ,
.Nm el_deletestr ,
.Nm el_data_set ,
.Nm el_data_get ,
.Nm history_init ,
.Nm history_end ,
.Nm history
@ -64,7 +61,7 @@
.Sh SYNOPSIS
.Fd #include <histedit.h>
.Ft EditLine *
.Fn el_init "const char *prog" "FILE *fin" "FILE *fout"
.Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
.Ft void
.Fn el_end "EditLine *e"
.Ft void
@ -80,25 +77,23 @@
.Ft int
.Fn el_set "EditLine *e" "int op" "..."
.Ft int
.Fn el_get "EditLine *e" "int op" "void *result"
.Ft int
.Fn el_source "EditLine *e" "const char *file"
.Ft void
.Fn el_resize "EditLine *e"
.Ft const LineInfo *
.Fn el_line "EditLine *e"
.Ft int
.Fn el_insertstr "EditLine *e" "char *str"
.Fn el_insertstr "EditLine *e" "const char *str"
.Ft void
.Fn el_deletestr "EditLine *e" "int count"
.Ft void
.Fn el_data_set "EditLine *e" "void *data"
.Ft void *
.Fn el_data_get "EditLine *e"
.Ft History *
.Fn history_init
.Ft void
.Fn history_end "History *h"
.Ft const HistEvent *
.Fn history "History *h" "int op" "..."
.Ft int
.Fn history "History *h" "HistEvent *ev" "int op" "..."
.Sh DESCRIPTION
The
.Nm
@ -130,10 +125,11 @@ to be used by all other line editing functions.
is the name of the invoking program, used when reading the
.Xr editrc 5
file to determine which settings to use.
.Fa fin
and
.Fa fin ,
.Fa fout
are the input and output streams (respectively) to use.
and
.Fa ferr
are the input, output, and error streams (respectively) to use.
In this documentation, references to
.Dq the tty
are actually to this input/output stream combination.
@ -197,17 +193,6 @@ didn't match, or
Refer to
.Xr editrc 5
for more information.
.Pp
.Em NOTE :
.Va argv[0]
may be modified by
.Fn el_parse .
The colon between
.Dq prog
and the command,
.Ar command ,
will be replaced with a NUL
.Pq Dq \e0 .
.It Fn el_set
Set
.Nm
@ -224,6 +209,10 @@ are supported, along with the required argument list:
Define prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
Define right side prompt printing function as
.Fa f ,
which is to return a string that contains the prompt.
.It Dv EL_TERMINAL , Fa "const char *type"
Define terminal type of the tty to be
.Fa type ,
@ -344,9 +333,11 @@ EOF was entered.
Expecting further command input as arguments, do nothing visually.
.It Dv CC_REFRESH
Refresh display.
.It Dv CC_REFRESH_BEEP
Refresh display, and beep.
.It Dv CC_CURSOR
Cursor moved, so update and perform
.Dv CC_REFRESH .
.Dv CC_REFRESH.
.It Dv CC_REDISPLAY
Redisplay entire input line.
This is useful if a key binding outputs extra information.
@ -365,6 +356,50 @@ Defines which history function to use, which is usually
.Fa ptr
should be the value returned by
.Fn history_init .
.It Dv EL_EDITMODE , Fa "int flag"
If
.Fa flag
is non-zero,
editing is enabled (the default).
Note that this is only an indication, and does not
affect the operation of
.Nm "" .
At this time, it is the caller's responsibility to
check this
(using
.Fn el_get )
to determine if editing should be enabled or not.
.El
.It Fn el_get
Get
.Nm
parameters.
.Fa op
determines which parameter to retrieve into
.Fa result .
.Pp
The following values for
.Fa op
are supported, along with actual type of
.Fa result :
.Bl -tag -width 4n
.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
Return a pointer to the function that displays the prompt.
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
Return a pointer to the function that displays the rightside prompt.
.It Dv EL_EDITOR , Fa "const char *"
Return the name of the editor, which will be one of
.Dq emacs
or
.Dq vi .
.It Dv EL_SIGNAL , Fa "int *"
Return non-zero if
.Nm
has installed private signal handlers (see
.Fn el_get
above).
.It Dv EL_EDITMODE, Fa "int *"
Return non-zero if editing is enabled.
.El
.It Fn el_source
Initialise
@ -379,6 +414,8 @@ If
is
.Dv NULL ,
try
.Pa $PWD/.editrc
then
.Pa $HOME/.editrc .
Refer to
.Xr editrc 5
@ -416,11 +453,6 @@ is empty or won't fit, and 0 otherwise.
Delete
.Fa num
characters before the cursor.
.It Fn el_data_set
Set the user data to
.Fa data .
.It Fn el_data_get
Get the user data.
.El
.Sh HISTORY LIST FUNCTIONS
The history functions use a common data structure,
@ -445,14 +477,18 @@ Perform operation
.Fa op
on the history list, with optional arguments as needed by the
operation.
.Fa ev
is changed accordingly to operation.
The following values for
.Fa op
are supported, along with the required argument list:
.Bl -tag -width 4n
.It Dv H_EVENT , Fa "int size"
.It Dv H_SETSIZE , Fa "int size"
Set size of history to
.Fa size
elements.
.It Dv H_GETSIZE
Get number of events currently in history.
.It Dv H_END
Cleans up and finishes with
.Fa h ,
@ -467,6 +503,7 @@ Clear the history.
.Fa "history_gfun_t last" ,
.Fa "history_gfun_t prev" ,
.Fa "history_gfun_t curr" ,
.Fa "history_sfun_t set" ,
.Fa "history_vfun_t clear" ,
.Fa "history_efun_t enter" ,
.Fa "history_efun_t add"
@ -484,12 +521,16 @@ Return the previous element in the history.
Return the next element in the history.
.It Dv H_CURR
Return the current element in the history.
.It Dv H_SET
Set the cursor to point to the requested element.
.It Dv H_ADD , Fa "const char *str"
Append
.Fa str
to the current element of the history, or create an element with
.Dv H_ENTER
if there isn't one.
.It Dv H_APPEND , Fa "const char *str"
Append
.Fa str
to the last new element of the history.
.It Dv H_ENTER , Fa "const char *str"
Add
.Fa str
@ -514,33 +555,66 @@ Load the history list stored in
Save the history list to
.Fa file .
.El
.Pp
.Fn history
returns 0 if the operation
.Fa op
succeeds. Otherwise, -1 is returned and
.Fa ev
is updated to contain more details about the error.
.El
.\"XXX.Sh EXAMPLES
.\"XXX: provide some examples
.Sh SEE ALSO
.Xr editrc 5 ,
.Xr sh 1 ,
.Xr signal 3 ,
.Xr termcap 3 ,
.Xr editrc 5
.Xr termcap 3
.Sh HISTORY
The
.Nm
library first appeared in
.Bx 4.4 .
.Dv CC_REDISPLAY
appeared in
.Nx 1.3 .
.Dv CC_REFRESH_BEEP ,
.Dv EL_EDITMODE
and the readline emulation appeared in
.Nx 1.4 .
.Dv EL_RPROMPT
appeared in
.Nx 1.5 .
.Sh AUTHORS
.An -nosplit
The
.Nm
library was written by
.An Christos Zoulas ,
and this manual was written by
.An Luke Mewburn .
library was written by Christos Zoulas.
Luke Mewburn wrote this manual and implemented
.Dv CC_REDISPLAY ,
.Dv CC_REFRESH_BEEP ,
.Dv EL_EDITMODE ,
and
.Dv EL_RPROMPT .
Jaromir Dolecek implemented the readline emulation.
.Sh BUGS
This documentation is probably incomplete.
The tokenization functions are not publically defined in
.Fd <histedit.h>.
.Pp
.Fn el_parse
should not modify the supplied
.Va argv[0] .
.Pp
The tokenization functions are not publicly defined in
.Li <histedit.h> .
At this time, it is the responsibility of the caller to
check the result of the
.Dv EL_EDITMODE
operation of
.Fn el_get
(after an
.Fn el_source
or
.Fn el_parse )
to determine if
.Nm
should be used for further input.
I.e.,
.Dv EL_EDITMODE
is purely an indication of the result of the most recent
.Xr editrc 5
.Ic edit
command.

View File

@ -1,6 +1,7 @@
.\" $NetBSD: editrc.5,v 1.4 1997/04/24 20:20:31 christos Exp $
.\" $NetBSD: editrc.5,v 1.10 2000/11/08 00:09:38 lukem Exp $
.\" $FreeBSD$
.\"
.\" Copyright (c) 1997 The NetBSD Foundation, Inc.
.\" Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
@ -24,8 +25,8 @@
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
.\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
@ -33,9 +34,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd January 11, 1997
.Dd November 8, 2000
.Os
.Dt EDITRC 5
.Sh NAME
@ -50,10 +49,8 @@ file defines various settings to be used by the
.Xr editline 3
library.
.Pp
The format of each line is either:
.Dl prog:command [arg [...]]
or
.Dl command [arg [...]]
The format of each line is:
.Dl [prog:]command [arg [...]]
.Pp
.Ar command
is one of the
@ -81,6 +78,12 @@ style
regular expression, in which case
.Ar command
will be executed for any program that matches the regular expression.
.Pp
If
.Ar prog
is absent,
.Ar command
is executed for all programs.
.Sh BUILTIN COMMANDS
The
.Nm editline
@ -120,7 +123,7 @@ Options include:
Bind all keys to the standard GNU Emacs-like bindings.
.It Fl v
Bind all keys to the standard
.Xr vi 1 Ns -like
.Xr vi 1 -like
bindings.
.It Fl a
List or change key bindings in the
@ -149,6 +152,11 @@ are themselves reinterpreted, and this continues for ten levels of
interpretation.
.El
.Pp
.Ar command
may be one of the commands documented in
.Sx "EDITOR COMMANDS"
below, or another key.
.Pp
.Ar key
and
.Ar command
@ -156,8 +164,10 @@ can contain control characters of the form
.Sm off
.Sq No ^ Ar character
.Sm on
(e.g.\&
.Sq ^A ) ,
.Po
e.g.
.Sq ^A
.Pc ,
and the following backslashed escape sequences:
.Pp
.Bl -tag -compact -offset indent -width 4n
@ -213,15 +223,19 @@ or
indicating that the terminal does or does not have that capability.
.Pp
.Fl s
returns an empty string for non-existent capabilities, rather than
returns an emptry string for non-existent capabilities, rather than
causing an error.
.Fl v
causes messages to be verbose.
.It Ic edit Op Li on | Li off
Enable or disable the
.Nm editline
functionality in a program.
.It Ic history
List the history.
.It Ic telltc
List the values of all the terminal capabilities (see
.Xr termcap 5 ) .
.Xr termcap 5 ).
.It Ic settc Ar cap Ar val
Set the terminal capability
.Ar cap
@ -259,9 +273,13 @@ set of tty modes respectively; defaulting to
Without other arguments,
.Ic setty
lists the modes in the chosen set which are fixed on
.Pq Sq +mode
.Po
.Sq +mode
.Pc
or off
.Pq Sq -mode .
.Po
.Sq -mode
.Pc .
.Fl a
lists all tty modes in the chosen set regardless of the setting.
With
@ -275,17 +293,200 @@ on or off or removes control of
.Ar mode
in the chosen set.
.El
.Sh EDITOR COMMANDS
The following editor commands are available for use in key bindings:
.\" Section automatically generated with makelist
.Bl -tag -width 4n
.It Ic vi-paste-next
Vi paste previous deletion to the right of the cursor.
.It Ic vi-paste-prev
Vi paste previous deletion to the left of the cursor.
.It Ic vi-prev-space-word
Vi move to the previous space delimited word.
.It Ic vi-prev-word
Vi move to the previous word.
.It Ic vi-next-space-word
Vi move to the next space delimited word.
.It Ic vi-next-word
Vi move to the next word.
.It Ic vi-change-case
Vi change case of character under the cursor and advance one character.
.It Ic vi-change-meta
Vi change prefix command.
.It Ic vi-insert-at-bol
Vi enter insert mode at the beginning of line.
.It Ic vi-replace-char
Vi replace character under the cursor with the next character typed.
.It Ic vi-replace-mode
Vi enter replace mode.
.It Ic vi-substitute-char
Vi replace character under the cursor and enter insert mode.
.It Ic vi-substitute-line
Vi substitute entire line.
.It Ic vi-change-to-eol
Vi change to end of line.
.It Ic vi-insert
Vi enter insert mode.
.It Ic vi-add
Vi enter insert mode after the cursor.
.It Ic vi-add-at-eol
Vi enter insert mode at end of line.
.It Ic vi-delete-meta
Vi delete prefix command.
.It Ic vi-end-word
Vi move to the end of the current space delimited word.
.It Ic vi-to-end-word
Vi move to the end of the current word.
.It Ic vi-undo
Vi undo last change.
.It Ic vi-command-mode
Vi enter command mode (use alternative key bindings).
.It Ic vi-zero
Vi move to the beginning of line.
.It Ic vi-delete-prev-char
Vi move to previous character (backspace).
.It Ic vi-list-or-eof
Vi list choices for completion or indicate end of file if empty line.
.It Ic vi-kill-line-prev
Vi cut from beginning of line to cursor.
.It Ic vi-search-prev
Vi search history previous.
.It Ic vi-search-next
Vi search history next.
.It Ic vi-repeat-search-next
Vi repeat current search in the same search direction.
.It Ic vi-repeat-search-prev
Vi repeat current search in the opposite search direction.
.It Ic vi-next-char
Vi move to the character specified next.
.It Ic vi-prev-char
Vi move to the character specified previous.
.It Ic vi-to-next-char
Vi move up to the character specified next.
.It Ic vi-to-prev-char
Vi move up to the character specified previous.
.It Ic vi-repeat-next-char
Vi repeat current character search in the same search direction.
.It Ic vi-repeat-prev-char
Vi repeat current character search in the opposite search direction.
.It Ic em-delete-or-list
Delete character under cursor or list completions if at end of line.
.It Ic em-delete-next-word
Cut from cursor to end of current word.
.It Ic em-yank
Paste cut buffer at cursor position.
.It Ic em-kill-line
Cut the entire line and save in cut buffer.
.It Ic em-kill-region
Cut area between mark and cursor and save in cut buffer.
.It Ic em-copy-region
Copy area between mark and cursor to cut buffer.
.It Ic em-gosmacs-traspose
Exchange the two characters before the cursor.
.It Ic em-next-word
Move next to end of current word.
.It Ic em-upper-case
Uppercase the characters from cursor to end of current word.
.It Ic em-capitol-case
Capitalize the characters from cursor to end of current word.
.It Ic em-lower-case
Lowercase the characters from cursor to end of current word.
.It Ic em-set-mark
Set the mark at cursor.
.It Ic em-exchange-mark
Exchange the cursor and mark.
.It Ic em-universal-argument
Universal argument (argument times 4).
.It Ic em-meta-next
Add 8th bit to next character typed.
.It Ic em-toggle-overwrite
Switch from insert to overwrite mode or vice versa.
.It Ic em-copy-prev-word
Copy current word to cursor.
.It Ic em-inc-search-next
Emacs incremental next search.
.It Ic em-inc-search-prev
Emacs incremental reverse search.
.It Ic ed-end-of-file
Indicate end of file.
.It Ic ed-insert
Add character to the line.
.It Ic ed-delete-prev-word
Delete from beginning of current word to cursor.
.It Ic ed-delete-next-char
Delete character under cursor.
.It Ic ed-kill-line
Cut to the end of line.
.It Ic ed-move-to-end
Move cursor to the end of line.
.It Ic ed-move-to-beg
Move cursor to the beginning of line.
.It Ic ed-transpose-chars
Exchange the character to the left of the cursor with the one under it.
.It Ic ed-next-char
Move to the right one character.
.It Ic ed-prev-word
Move to the beginning of the current word.
.It Ic ed-prev-char
Move to the left one character.
.It Ic ed-quoted-insert
Add the next character typed verbatim.
.It Ic ed-digit
Adds to argument or enters a digit.
.It Ic ed-argument-digit
Digit that starts argument.
.It Ic ed-unassigned
Indicates unbound character.
.It Ic ed-tty-sigint
Tty interrupt character.
.It Ic ed-tty-dsusp
Tty delayed suspend character.
.It Ic ed-tty-flush-output
Tty flush output characters.
.It Ic ed-tty-sigquit
Tty quit character.
.It Ic ed-tty-sigtstp
Tty suspend character.
.It Ic ed-tty-stop-output
Tty disallow output characters.
.It Ic ed-tty-start-output
Tty allow output characters.
.It Ic ed-newline
Execute command.
.It Ic ed-delete-prev-char
Delete the character to the left of the cursor.
.It Ic ed-clear-screen
Clear screen leaving current line at the top.
.It Ic ed-redisplay
Redisplay everything.
.It Ic ed-start-over
Erase current line and start from scratch.
.It Ic ed-sequence-lead-in
First character in a bound sequence.
.It Ic ed-prev-history
Move to the previous history line.
.It Ic ed-next-history
Move to the next history line.
.It Ic ed-search-prev-history
Search previous in history for a line matching the current.
.It Ic ed-search-next-history
Search next in history for a line matching the current.
.It Ic ed-prev-line
Move up one line.
.It Ic ed-next-line
Move down one line.
.It Ic ed-command
Editline extended command.
.El
.\" End of section automatically generated with makelist
.Sh SEE ALSO
.Xr editline 3 ,
.Xr regex 3 ,
.Xr termcap 5
.Sh AUTHORS
.An -nosplit
The
.Nm editline
library was written by
.An Christos Zoulas ,
and this manual was written by
.An Luke Mewburn ,
library was written by Christos Zoulas,
and this manual was written by Luke Mewburn,
with some sections inspired by
.Xr tcsh 1 .

View File

@ -32,15 +32,15 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: el.c,v 1.20 2000/11/11 22:18:57 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#endif
#endif /* not lint && not SCCSID */
/*
* el.c: EditLine interface functions
@ -49,106 +49,90 @@ static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#include <sys/types.h>
#include <sys/param.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#if __STDC__
# include <stdarg.h>
#else
# include <varargs.h>
#endif
#include <stdarg.h>
#include "el.h"
/* el_init():
* Initialize editline and set default parameters.
*/
public EditLine *
el_init(prog, fin, fout)
const char *prog;
FILE *fin, *fout;
el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
{
EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
EditLine *el = (EditLine *) el_malloc(sizeof(EditLine));
#ifdef DEBUG
char *tty;
char *tty;
#endif
if (el == NULL)
return NULL;
if (el == NULL)
return (NULL);
memset(el, 0, sizeof(EditLine));
memset(el, 0, sizeof(EditLine));
el->el_infd = fileno(fin);
el->el_outfile = fout;
el->el_prog = strdup(prog);
el->el_infd = fileno(fin);
el->el_outfile = fout;
el->el_errfile = ferr;
el->el_prog = strdup(prog);
#ifdef DEBUG
if (issetugid() == 0 && (tty = getenv("DEBUGTTY")) != NULL) {
el->el_errfile = fopen(tty, "w");
if (el->el_errfile == NULL) {
(void) fprintf(stderr, "Cannot open %s (%s).\n",
tty, strerror(errno));
return NULL;
}
}
else
#endif
el->el_errfile = stderr;
/*
* Initialize all the modules. Order is important!!!
*/
el->el_flags = 0;
/*
* Initialize all the modules. Order is important!!!
*/
(void) term_init(el);
(void) tty_init(el);
(void) key_init(el);
(void) map_init(el);
(void) ch_init(el);
(void) search_init(el);
(void) hist_init(el);
(void) prompt_init(el);
(void) sig_init(el);
el->el_flags = 0;
el->data = NULL;
(void) term_init(el);
(void) key_init(el);
(void) map_init(el);
if (tty_init(el) == -1)
el->el_flags |= NO_TTY;
(void) ch_init(el);
(void) search_init(el);
(void) hist_init(el);
(void) prompt_init(el);
(void) sig_init(el);
el->data = NULL;
return el;
} /* end el_init */
return (el);
}
/* el_end():
* Clean up.
*/
public void
el_end(el)
EditLine *el;
el_end(EditLine *el)
{
if (el == NULL)
return;
el_reset(el);
if (el == NULL)
return;
term_end(el);
tty_end(el);
key_end(el);
map_end(el);
ch_end(el);
search_end(el);
hist_end(el);
prompt_end(el);
sig_end(el);
el_reset(el);
el_free((ptr_t) el->el_prog);
el_free((ptr_t) el);
} /* end el_end */
term_end(el);
key_end(el);
map_end(el);
tty_end(el);
ch_end(el);
search_end(el);
hist_end(el);
prompt_end(el);
sig_end(el);
el_free((ptr_t) el->el_prog);
el_free((ptr_t) el);
}
/* el_reset():
* Reset the tty and the parser
*/
public void
el_reset(el)
EditLine *el;
el_reset(EditLine *el)
{
tty_cookedmode(el);
ch_reset(el); /* XXX: Do we want that? */
tty_cookedmode(el);
ch_reset(el); /* XXX: Do we want that? */
}
@ -156,187 +140,199 @@ el_reset(el)
* set the editline parameters
*/
public int
#if __STDC__
el_set(EditLine *el, int op, ...)
#else
el_set(va_alist)
va_dcl
#endif
{
va_list va;
int rv;
#if __STDC__
va_start(va, op);
#else
EditLine *el;
int op;
va_list va;
int rv;
va_start(va, op);
va_start(va);
el = va_arg(va, EditLine *);
op = va_arg(va, int);
#endif
if (el == NULL)
return (-1);
switch (op) {
case EL_PROMPT:
case EL_RPROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t), op);
break;
switch (op) {
case EL_PROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t));
break;
case EL_TERMINAL:
rv = term_set(el, va_arg(va, char *));
break;
case EL_TERMINAL:
rv = term_set(el, va_arg(va, char *));
break;
case EL_EDITOR:
rv = map_set_editor(el, va_arg(va, char *));
break;
case EL_EDITOR:
rv = map_set_editor(el, va_arg(va, char *));
break;
case EL_SIGNAL:
if (va_arg(va, int))
el->el_flags |= HANDLE_SIGNALS;
else
el->el_flags &= ~HANDLE_SIGNALS;
rv = 0;
break;
case EL_SIGNAL:
if (va_arg(va, int))
el->el_flags |= HANDLE_SIGNALS;
else
el->el_flags &= ~HANDLE_SIGNALS;
rv = 0;
break;
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
{
char *argv[20];
int i;
for (i = 1; i < 20; i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
break;
char *argv[20];
int i;
switch (op) {
case EL_BIND:
argv[0] = "bind";
rv = map_bind(el, i, argv);
for (i = 1; i < 20; i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
break;
switch (op) {
case EL_BIND:
argv[0] = "bind";
rv = map_bind(el, i, argv);
break;
case EL_TELLTC:
argv[0] = "telltc";
rv = term_telltc(el, i, argv);
break;
case EL_SETTC:
argv[0] = "settc";
rv = term_settc(el, i, argv);
break;
case EL_ECHOTC:
argv[0] = "echotc";
rv = term_echotc(el, i, argv);
break;
case EL_SETTY:
argv[0] = "setty";
rv = tty_stty(el, i, argv);
break;
default:
rv = -1;
EL_ABORT((el->el_errfile, "Bad op %d\n", op));
break;
}
break;
}
case EL_ADDFN:
{
char *name = va_arg(va, char *);
char *help = va_arg(va, char *);
el_func_t func = va_arg(va, el_func_t);
rv = map_addfunc(el, name, help, func);
break;
}
case EL_HIST:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
rv = hist_set(el, func, ptr);
break;
}
case EL_EDITMODE:
if (va_arg(va, int))
el->el_flags &= ~EDIT_DISABLED;
else
el->el_flags |= EDIT_DISABLED;
rv = 0;
break;
case EL_TELLTC:
argv[0] = "telltc";
rv = term_telltc(el, i, argv);
break;
case EL_SETTC:
argv[0] = "settc";
rv = term_settc(el, i, argv);
break;
case EL_ECHOTC:
argv[0] = "echotc";
rv = term_echotc(el, i, argv);
break;
case EL_SETTY:
argv[0] = "setty";
rv = tty_stty(el, i, argv);
break;
default:
default:
rv = -1;
abort();
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;
default:
rv = -1;
}
va_end(va);
return rv;
} /* end el_set */
/* el_line():
* Return editing info
*/
public const LineInfo *
el_line(el)
EditLine *el;
{
return (const LineInfo *) &el->el_line;
va_end(va);
return (rv);
}
static const char elpath[] = "/.editrc";
/* el_source():
* Source a file
/* el_get():
* retrieve the editline parameters
*/
public int
el_source(el, fname)
EditLine *el;
const char *fname;
el_get(EditLine *el, int op, void *ret)
{
FILE *fp;
size_t len;
char *ptr, path[MAXPATHLEN];
int rv;
if (fname == NULL) {
if (issetugid() != 0 || (ptr = getenv("HOME")) == NULL)
return -1;
(void) snprintf(path, sizeof(path), "%s%s", ptr, elpath);
fname = path;
}
if (el == NULL || ret == NULL)
return (-1);
switch (op) {
case EL_PROMPT:
case EL_RPROMPT:
rv = prompt_get(el, (el_pfunc_t *) & ret, op);
break;
if ((fp = fopen(fname, "r")) == NULL)
return -1;
case EL_EDITOR:
rv = map_get_editor(el, (const char **) &ret);
break;
while ((ptr = fgetln(fp, &len)) != NULL) {
if (ptr[len - 1] == '\n')
--len;
ptr[len] = '\0';
case EL_SIGNAL:
*((int *) ret) = (el->el_flags & HANDLE_SIGNALS);
rv = 0;
break;
if (parse_line(el, ptr) == -1) {
(void) fclose(fp);
return -1;
}
}
case EL_EDITMODE:
*((int *) ret) = (!(el->el_flags & EDIT_DISABLED));
rv = 0;
break;
(void) fclose(fp);
return 0;
}
#if 0 /* XXX */
case EL_TERMINAL:
rv = term_get(el, (const char *) &ret);
break;
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
{
char *argv[20];
int i;
/* el_resize():
* Called from program when terminal is resized
*/
public void
el_resize(el)
EditLine *el;
{
int lins, cols;
sigset_t oset, nset;
(void) sigemptyset(&nset);
(void) sigaddset(&nset, SIGWINCH);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
for (i = 1; i < 20; i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
break;
/* get the correct window size */
if (term_get_size(el, &lins, &cols))
term_change_size(el, lins, cols);
switch (op) {
case EL_BIND:
argv[0] = "bind";
rv = map_bind(el, i, argv);
break;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
case EL_TELLTC:
argv[0] = "telltc";
rv = term_telltc(el, i, argv);
break;
case EL_SETTC:
argv[0] = "settc";
rv = term_settc(el, i, argv);
break;
case EL_ECHOTC:
argv[0] = "echotc";
rv = term_echotc(el, i, argv);
break;
case EL_SETTY:
argv[0] = "setty";
rv = tty_stty(el, i, argv);
break;
default:
rv = -1;
EL_ABORT((el->errfile, "Bad op %d\n", op));
break;
}
break;
}
public void
@ -356,4 +352,141 @@ el_data_get (el)
if (el->data)
return (el->data);
return (NULL);
}
case EL_ADDFN:
{
char *name = va_arg(va, char *);
char *help = va_arg(va, char *);
el_func_t func = va_arg(va, el_func_t);
rv = map_addfunc(el, name, help, func);
break;
}
case EL_HIST:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
rv = hist_set(el, func, ptr);
}
break;
#endif /* XXX */
default:
rv = -1;
}
return (rv);
}
/* el_line():
* Return editing info
*/
public const LineInfo *
el_line(EditLine *el)
{
return (const LineInfo *) (void *) &el->el_line;
}
static const char elpath[] = "/.editrc";
/* el_source():
* Source a file
*/
public int
el_source(EditLine *el, const char *fname)
{
FILE *fp;
size_t len;
char *ptr, path[MAXPATHLEN];
fp = NULL;
if (fname == NULL) {
if (issetugid())
return (-1);
if ((ptr = getenv("HOME")) == NULL)
return (-1);
if (strlcpy(path, ptr, sizeof(path)) >= sizeof(path))
return (-1);
if (strlcat(path, elpath, sizeof(path)) >= sizeof(path))
return (-1);
fname = path;
}
if (fp == NULL)
fp = fopen(fname, "r");
if (fp == NULL)
return (-1);
while ((ptr = fgetln(fp, &len)) != NULL) {
if (len > 0 && ptr[len - 1] == '\n')
--len;
ptr[len] = '\0';
if (parse_line(el, ptr) == -1) {
(void) fclose(fp);
return (-1);
}
}
(void) fclose(fp);
return (0);
}
/* el_resize():
* Called from program when terminal is resized
*/
public void
el_resize(EditLine *el)
{
int lins, cols;
sigset_t oset, nset;
(void) sigemptyset(&nset);
(void) sigaddset(&nset, SIGWINCH);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
/* get the correct window size */
if (term_get_size(el, &lins, &cols))
term_change_size(el, lins, cols);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
/* el_beep():
* Called from the program to beep
*/
public void
el_beep(EditLine *el)
{
term_beep(el);
}
/* el_editmode()
* Set the state of EDIT_DISABLED from the `edit' command.
*/
protected int
/*ARGSUSED*/
el_editmode(EditLine *el, int argc, char **argv)
{
const char *how;
if (argv == NULL || argc != 2 || argv[1] == NULL)
return (-1);
how = argv[1];
if (strcmp(how, "on") == 0)
el->el_flags &= ~EDIT_DISABLED;
else if (strcmp(how, "off") == 0)
el->el_flags |= EDIT_DISABLED;
else {
(void) fprintf(el->el_errfile, "edit: Bad value `%s'.\n", how);
return (-1);
}
return (0);
}

View File

@ -34,60 +34,65 @@
* SUCH DAMAGE.
*
* @(#)el.h 8.1 (Berkeley) 6/4/93
* $NetBSD: el.h,v 1.7 2000/11/11 22:18:57 christos Exp $
* $FreeBSD$
*/
/*
* el.h: Internal structures.
*/
#ifndef _h_el
#define _h_el
#define _h_el
/*
* Local defaults
*/
#define KSHVI
#define VIDEFAULT
#define ANCHOR
#define KSHVI
#define VIDEFAULT
#define ANCHOR
#include <stdio.h>
#include <sys/types.h>
#define EL_BUFSIZ 1024 /* Maximum line size */
#define EL_BUFSIZ 1024 /* Maximum line size */
#define HANDLE_SIGNALS 1
#define HANDLE_SIGNALS 1<<0
#define NO_TTY 1<<1
#define EDIT_DISABLED 1<<2
typedef int bool_t; /* True or not */
typedef unsigned char el_action_t; /* Index to command array */
typedef struct coord_t { /* Position on the screen */
int h, v;
int h;
int v;
} coord_t;
typedef struct el_line_t {
char *buffer, /* Input line */
*cursor, /* Cursor position */
*lastchar, /* Last character */
*limit; /* Max position */
char *buffer; /* Input line */
char *cursor; /* Cursor position */
char *lastchar; /* Last character */
const char *limit; /* Max position */
} el_line_t;
/*
* Editor state
*/
typedef struct el_state_t {
int inputmode; /* What mode are we in? */
int doingarg; /* Are we getting an argument? */
int argument; /* Numeric argument */
int metanext; /* Is the next char a meta char */
el_action_t lastcmd; /* Previous command */
int inputmode; /* What mode are we in? */
int doingarg; /* Are we getting an argument? */
int argument; /* Numeric argument */
int metanext; /* Is the next char a meta char */
el_action_t lastcmd; /* Previous command */
} el_state_t;
/*
* Until we come up with something better...
*/
#define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b)
#define el_malloc(a) malloc(a)
#define el_realloc(a,b) realloc(a, b)
#define el_reallocf(a,b) reallocf(a, b)
#define el_free(a) free(a)
#define el_free(a) free(a)
#include "tty.h"
#include "prompt.h"
@ -104,29 +109,37 @@ typedef struct el_state_t {
#include "help.h"
struct editline {
char *el_prog; /* the program name */
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
int el_flags; /* Various flags. */
coord_t el_cursor; /* Cursor location */
char **el_display, /* Real screen image = what is there */
**el_vdisplay; /* Virtual screen image = what we see */
char *el_prog; /* the program name */
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */
int el_flags; /* Various flags. */
coord_t el_cursor; /* Cursor location */
char **el_display; /* Real screen image = what is there */
char **el_vdisplay; /* Virtual screen image = what we see */
el_line_t el_line; /* The current line information */
el_state_t el_state; /* Current editor state */
el_term_t el_term; /* Terminal dependent stuff */
el_tty_t el_tty; /* Tty dependent stuff */
el_refresh_t el_refresh; /* Refresh stuff */
el_prompt_t el_prompt; /* Prompt stuff */
el_prompt_t el_rprompt; /* Prompt stuff */
el_chared_t el_chared; /* Characted editor stuff */
el_map_t el_map; /* Key mapping stuff */
el_key_t el_key; /* Key binding stuff */
el_history_t el_history; /* History stuff */
el_search_t el_search; /* Search stuff */
el_signal_t el_signal; /* Signal handling stuff */
el_line_t el_line; /* The current line information */
el_state_t el_state; /* Current editor state */
el_term_t el_term; /* Terminal dependent stuff */
el_tty_t el_tty; /* Tty dependent stuff */
el_refresh_t el_refresh; /* Refresh stuff */
el_prompt_t el_prompt; /* Prompt stuff */
el_chared_t el_chared; /* Characted editor stuff */
el_map_t el_map; /* Key mapping stuff */
el_key_t el_key; /* Key binding stuff */
el_history_t el_history; /* History stuff */
el_search_t el_search; /* Search stuff */
el_signal_t el_signal; /* Signal handling stuff */
void *data; /* user data */
void *data; /* user data */
};
protected int el_editmode(EditLine *, int, char **);
#ifdef DEBUG
#define EL_ABORT(a) (void) (fprintf(el->el_errfile, "%s, %d: ", \
__FILE__, __LINE__), fprintf a, abort())
#else
#define EL_ABORT(a) abort()
#endif
#endif /* _h_el */

View File

@ -32,6 +32,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: emacs.c,v 1.8 2000/09/04 22:06:29 lukem Exp $
*/
#include <sys/cdefs.h>
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* emacs.c: Emacs functions
@ -52,28 +56,31 @@ static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
*/
protected el_action_t
/*ARGSUSED*/
em_delete_or_list(el, c)
EditLine *el;
int c;
em_delete_or_list(EditLine *el, int c)
{
if (el->el_line.cursor == el->el_line.lastchar) { /* if I'm at the end */
if (el->el_line.cursor == el->el_line.buffer) { /* and the beginning */
term_overwrite(el, STReof, 4);/* then do a EOF */
term__flush();
return CC_EOF;
if (el->el_line.cursor == el->el_line.lastchar) {
/* if I'm at the end */
if (el->el_line.cursor == el->el_line.buffer) {
/* and the beginning */
term_overwrite(el, STReof, 4); /* then do a EOF */
term__flush();
return (CC_EOF);
} else {
/*
* Here we could list completions, but it is an
* error right now
*/
term_beep(el);
return (CC_ERROR);
}
} else {
c_delafter(el, el->el_state.argument); /* delete after dot */
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
/* bounds check */
return (CC_REFRESH);
}
else {
/* Here we could list completions, but it is an error right now */
term_beep(el);
return CC_ERROR;
}
}
else {
c_delafter(el, el->el_state.argument); /* delete after dot */
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar; /* bounds check */
return CC_REFRESH;
}
}
@ -83,27 +90,26 @@ em_delete_or_list(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_delete_next_word(el, c)
EditLine *el;
int c;
em_delete_next_word(EditLine *el, int c)
{
char *cp, *p, *kp;
char *cp, *p, *kp;
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
if (el->el_line.cursor == el->el_line.lastchar)
return (CC_ERROR);
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
/* save the text */
*kp++ = *p;
el->el_chared.c_kill.last = kp;
for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
/* save the text */
*kp++ = *p;
el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.cursor); /* delete after dot */
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar; /* bounds check */
return CC_REFRESH;
c_delafter(el, cp - el->el_line.cursor); /* delete after dot */
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
/* bounds check */
return (CC_REFRESH);
}
@ -113,34 +119,34 @@ em_delete_next_word(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_yank(el, c)
EditLine *el;
int c;
em_yank(EditLine *el, int c)
{
char *kp, *cp;
char *kp, *cp;
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
return CC_ERROR;
if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) {
if (!ch_enlargebufs(el, 1))
return (CC_ERROR);
}
if (el->el_line.lastchar +
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
el->el_line.limit)
return CC_ERROR;
if (el->el_line.lastchar +
(el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
el->el_line.limit)
return (CC_ERROR);
el->el_chared.c_kill.mark = el->el_line.cursor;
cp = el->el_line.cursor;
el->el_chared.c_kill.mark = el->el_line.cursor;
cp = el->el_line.cursor;
/* open the space, */
c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
/* copy the chars */
for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
*cp++ = *kp;
/* open the space, */
c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
/* copy the chars */
for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
*cp++ = *kp;
/* if an arg, cursor at beginning else cursor at end */
if (el->el_state.argument == 1)
el->el_line.cursor = cp;
/* if an arg, cursor at beginning else cursor at end */
if (el->el_state.argument == 1)
el->el_line.cursor = cp;
return CC_REFRESH;
return (CC_REFRESH);
}
@ -150,20 +156,19 @@ em_yank(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_kill_line(el, c)
EditLine *el;
int c;
em_kill_line(EditLine *el, int c)
{
char *kp, *cp;
char *kp, *cp;
cp = el->el_line.buffer;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.lastchar)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
el->el_line.lastchar = el->el_line.buffer; /* zap! -- delete all of it */
el->el_line.cursor = el->el_line.buffer;
return CC_REFRESH;
cp = el->el_line.buffer;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.lastchar)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
/* zap! -- delete all of it */
el->el_line.lastchar = el->el_line.buffer;
el->el_line.cursor = el->el_line.buffer;
return (CC_REFRESH);
}
@ -173,33 +178,30 @@ em_kill_line(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_kill_region(el, c)
EditLine *el;
int c;
em_kill_region(EditLine *el, int c)
{
char *kp, *cp;
char *kp, *cp;
if (!el->el_chared.c_kill.mark)
return CC_ERROR;
if (!el->el_chared.c_kill.mark)
return (CC_ERROR);
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.cursor);
}
else { /* mark is before cursor */
cp = el->el_chared.c_kill.mark;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.cursor)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delbefore(el, cp - el->el_chared.c_kill.mark);
el->el_line.cursor = el->el_chared.c_kill.mark;
}
return CC_REFRESH;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delafter(el, cp - el->el_line.cursor);
} else { /* mark is before cursor */
cp = el->el_chared.c_kill.mark;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.cursor)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
c_delbefore(el, cp - el->el_chared.c_kill.mark);
el->el_line.cursor = el->el_chared.c_kill.mark;
}
return (CC_REFRESH);
}
@ -209,30 +211,27 @@ em_kill_region(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_copy_region(el, c)
EditLine *el;
int c;
em_copy_region(EditLine *el, int c)
{
char *kp, *cp;
char *kp, *cp;
if (el->el_chared.c_kill.mark)
return CC_ERROR;
if (el->el_chared.c_kill.mark)
return (CC_ERROR);
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
}
else {
cp = el->el_chared.c_kill.mark;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.cursor)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
}
return CC_NORM;
if (el->el_chared.c_kill.mark > el->el_line.cursor) {
cp = el->el_line.cursor;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_chared.c_kill.mark)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
} else {
cp = el->el_chared.c_kill.mark;
kp = el->el_chared.c_kill.buf;
while (cp < el->el_line.cursor)
*kp++ = *cp++; /* copy it */
el->el_chared.c_kill.last = kp;
}
return (CC_NORM);
}
@ -241,20 +240,17 @@ em_copy_region(el, c)
* Gosling emacs transpose chars [^T]
*/
protected el_action_t
em_gosmacs_traspose(el, c)
EditLine *el;
int c;
em_gosmacs_traspose(EditLine *el, int c)
{
if (el->el_line.cursor > &el->el_line.buffer[1]) {
/* must have at least two chars entered */
c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c;
return CC_REFRESH;
}
else
return CC_ERROR;
if (el->el_line.cursor > &el->el_line.buffer[1]) {
/* must have at least two chars entered */
c = el->el_line.cursor[-2];
el->el_line.cursor[-2] = el->el_line.cursor[-1];
el->el_line.cursor[-1] = c;
return (CC_REFRESH);
} else
return (CC_ERROR);
}
@ -264,49 +260,46 @@ em_gosmacs_traspose(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_next_word(el, c)
EditLine *el;
int c;
em_next_word(EditLine *el, int c)
{
if (el->el_line.cursor == el->el_line.lastchar)
return CC_ERROR;
if (el->el_line.cursor == el->el_line.lastchar)
return (CC_ERROR);
el->el_line.cursor = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument,
ce__isword);
el->el_line.cursor = c__next_word(el->el_line.cursor,
el->el_line.lastchar,
el->el_state.argument,
ce__isword);
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el);
return CC_REFRESH;
}
return CC_CURSOR;
if (el->el_map.type == MAP_VI)
if (el->el_chared.c_vcmd.action & DELETE) {
cv_delfini(el);
return (CC_REFRESH);
}
return (CC_CURSOR);
}
/* em_upper_case():
* Uppercase the characters from cursor to end of current word
* [M-u]
*/
protected el_action_t
/*ARGSUSED*/
em_upper_case(el, c)
EditLine *el;
int c;
em_upper_case(EditLine *el, int c)
{
char *cp, *ep;
char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
if (islower((unsigned char)*cp))
*cp = toupper((unsigned char)*cp);
for (cp = el->el_line.cursor; cp < ep; cp++)
if (islower((unsigned char) *cp))
*cp = toupper((unsigned char) *cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH;
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
return (CC_REFRESH);
}
@ -316,56 +309,53 @@ em_upper_case(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_capitol_case(el, c)
EditLine *el;
int c;
em_capitol_case(EditLine *el, int c)
{
char *cp, *ep;
char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++) {
if (isalpha((unsigned char)*cp)) {
if (islower((unsigned char)*cp))
*cp = toupper((unsigned char)*cp);
cp++;
break;
for (cp = el->el_line.cursor; cp < ep; cp++) {
if (isalpha((unsigned char) *cp)) {
if (islower((unsigned char) *cp))
*cp = toupper((unsigned char) *cp);
cp++;
break;
}
}
}
for (; cp < ep; cp++)
if (isupper((unsigned char)*cp))
*cp = tolower((unsigned char)*cp);
for (; cp < ep; cp++)
if (isupper((unsigned char) *cp))
*cp = tolower((unsigned char) *cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH;
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
return (CC_REFRESH);
}
/* em_lower_case():
* Lowercase the characters from cursor to end of current word
* [M-l]
*/
protected el_action_t
/*ARGSUSED*/
em_lower_case(el, c)
EditLine *el;
int c;
em_lower_case(EditLine *el, int c)
{
char *cp, *ep;
char *cp, *ep;
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
el->el_state.argument, ce__isword);
for (cp = el->el_line.cursor; cp < ep; cp++)
if (isupper((unsigned char)*cp))
*cp = tolower((unsigned char)*cp);
for (cp = el->el_line.cursor; cp < ep; cp++)
if (isupper((unsigned char) *cp))
*cp = tolower((unsigned char) *cp);
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH;
el->el_line.cursor = ep;
if (el->el_line.cursor > el->el_line.lastchar)
el->el_line.cursor = el->el_line.lastchar;
return (CC_REFRESH);
}
@ -375,12 +365,11 @@ em_lower_case(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_set_mark(el, c)
EditLine *el;
int c;
em_set_mark(EditLine *el, int c)
{
el->el_chared.c_kill.mark = el->el_line.cursor;
return CC_NORM;
el->el_chared.c_kill.mark = el->el_line.cursor;
return (CC_NORM);
}
@ -390,47 +379,45 @@ em_set_mark(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_exchange_mark(el, c)
EditLine *el;
int c;
em_exchange_mark(EditLine *el, int c)
{
register char *cp;
char *cp;
cp = el->el_line.cursor;
el->el_line.cursor = el->el_chared.c_kill.mark;
el->el_chared.c_kill.mark = cp;
return CC_CURSOR;
cp = el->el_line.cursor;
el->el_line.cursor = el->el_chared.c_kill.mark;
el->el_chared.c_kill.mark = cp;
return (CC_CURSOR);
}
/* em_universal_argument():
* Universal argument (argument times 4)
* [^U]
*/
protected el_action_t
/*ARGSUSED*/
em_universal_argument(el, c)
EditLine *el;
int c;
em_universal_argument(EditLine *el, int c)
{ /* multiply current argument by 4 */
if (el->el_state.argument > 1000000)
return CC_ERROR;
el->el_state.doingarg = 1;
el->el_state.argument *= 4;
return CC_ARGHACK;
if (el->el_state.argument > 1000000)
return (CC_ERROR);
el->el_state.doingarg = 1;
el->el_state.argument *= 4;
return (CC_ARGHACK);
}
/* em_meta_next():
* Add 8th bit to next character typed
* [<ESC>]
*/
protected el_action_t
/*ARGSUSED*/
em_meta_next(el, c)
EditLine *el;
int c;
em_meta_next(EditLine *el, int c)
{
el->el_state.metanext = 1;
return CC_ARGHACK;
el->el_state.metanext = 1;
return (CC_ARGHACK);
}
@ -439,13 +426,12 @@ em_meta_next(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_toggle_overwrite(el, c)
EditLine *el;
int c;
em_toggle_overwrite(EditLine *el, int c)
{
el->el_state.inputmode =
(el->el_state.inputmode == MODE_INSERT) ? MODE_REPLACE : MODE_INSERT;
return CC_NORM;
el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
MODE_REPLACE : MODE_INSERT;
return (CC_NORM);
}
@ -454,27 +440,25 @@ em_toggle_overwrite(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_copy_prev_word(el, c)
EditLine *el;
int c;
em_copy_prev_word(EditLine *el, int c)
{
char *cp, *oldc, *dp;
char *cp, *oldc, *dp;
if (el->el_line.cursor == el->el_line.buffer)
return CC_ERROR;
if (el->el_line.cursor == el->el_line.buffer)
return (CC_ERROR);
oldc = el->el_line.cursor;
/* does a bounds check */
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword);
oldc = el->el_line.cursor;
/* does a bounds check */
cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
el->el_state.argument, ce__isword);
c_insert(el, oldc - cp);
for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
*dp++ = *cp;
c_insert(el, oldc - cp);
for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
*dp++ = *cp;
el->el_line.cursor = dp; /* put cursor at end */
el->el_line.cursor = dp;/* put cursor at end */
return CC_REFRESH;
return (CC_REFRESH);
}
@ -483,12 +467,11 @@ em_copy_prev_word(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_inc_search_next(el, c)
EditLine *el;
int c;
em_inc_search_next(EditLine *el, int c)
{
el->el_search.patlen = 0;
return ce_inc_search(el, ED_SEARCH_NEXT_HISTORY);
el->el_search.patlen = 0;
return (ce_inc_search(el, ED_SEARCH_NEXT_HISTORY));
}
@ -497,10 +480,9 @@ em_inc_search_next(el, c)
*/
protected el_action_t
/*ARGSUSED*/
em_inc_search_prev(el, c)
EditLine *el;
int c;
em_inc_search_prev(EditLine *el, int c)
{
el->el_search.patlen = 0;
return ce_inc_search(el, ED_SEARCH_PREV_HISTORY);
el->el_search.patlen = 0;
return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
}

View File

@ -32,6 +32,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: hist.c,v 1.8 2001/01/10 07:45:41 jdolecek Exp $
*/
#include <sys/cdefs.h>
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* hist.c: History access functions
@ -51,14 +55,17 @@ static char sccsid[] = "@(#)hist.c 8.1 (Berkeley) 6/4/93";
* Initialization function.
*/
protected int
hist_init(el)
EditLine *el;
hist_init(EditLine *el)
{
el->el_history.fun = NULL;
el->el_history.ref = NULL;
el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
el->el_history.last = el->el_history.buf;
return 0;
el->el_history.fun = NULL;
el->el_history.ref = NULL;
el->el_history.buf = (char *) el_malloc(EL_BUFSIZ);
el->el_history.sz = EL_BUFSIZ;
if (el->el_history.buf == NULL)
return (-1);
el->el_history.last = el->el_history.buf;
return (0);
}
@ -66,11 +73,11 @@ hist_init(el)
* clean up history;
*/
protected void
hist_end(el)
EditLine *el;
hist_end(EditLine *el)
{
el_free((ptr_t) el->el_history.buf);
el->el_history.buf = NULL;
el_free((ptr_t) el->el_history.buf);
el->el_history.buf = NULL;
}
@ -78,15 +85,12 @@ hist_end(el)
* Set new history interface
*/
protected int
hist_set(el, fun, ptr)
EditLine *el;
hist_fun_t fun;
ptr_t ptr;
hist_set(EditLine *el, hist_fun_t fun, ptr_t ptr)
{
el->el_history.ref = ptr;
el->el_history.fun = fun;
return 0;
el->el_history.ref = ptr;
el->el_history.fun = fun;
return (0);
}
@ -95,78 +99,99 @@ hist_set(el, fun, ptr)
* eventno tells us the event to get.
*/
protected el_action_t
hist_get(el)
EditLine *el;
hist_get(EditLine *el)
{
const char *hp;
int h;
const char *hp;
int h;
if (el->el_history.eventno == 0) { /* if really the current line */
(void) strncpy(el->el_line.buffer, el->el_history.buf, EL_BUFSIZ);
el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf);
if (el->el_history.eventno == 0) { /* if really the current line */
(void) strncpy(el->el_line.buffer, el->el_history.buf,
el->el_history.sz);
el->el_line.lastchar = el->el_line.buffer +
(el->el_history.last - el->el_history.buf);
#ifdef KSHVI
if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer;
else
if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer;
else
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH;
}
if (el->el_history.ref == NULL)
return CC_ERROR;
hp = HIST_FIRST(el);
if (hp == NULL)
return CC_ERROR;
for (h = 1; h < el->el_history.eventno; h++)
if ((hp = HIST_NEXT(el)) == NULL) {
el->el_history.eventno = h;
return CC_ERROR;
return (CC_REFRESH);
}
if (el->el_history.ref == NULL)
return (CC_ERROR);
(void) strncpy(el->el_line.buffer, hp, EL_BUFSIZ);
el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
hp = HIST_FIRST(el);
if (el->el_line.lastchar > el->el_line.buffer) {
if (el->el_line.lastchar[-1] == '\n')
el->el_line.lastchar--;
if (el->el_line.lastchar[-1] == ' ')
el->el_line.lastchar--;
if (el->el_line.lastchar < el->el_line.buffer)
el->el_line.lastchar = el->el_line.buffer;
}
if (hp == NULL)
return (CC_ERROR);
for (h = 1; h < el->el_history.eventno; h++)
if ((hp = HIST_NEXT(el)) == NULL) {
el->el_history.eventno = h;
return (CC_ERROR);
}
(void) strncpy(el->el_line.buffer, hp,
(size_t)(el->el_line.limit - el->el_line.buffer));
el->el_line.lastchar = el->el_line.buffer + strlen(el->el_line.buffer);
if (el->el_line.lastchar > el->el_line.buffer) {
if (el->el_line.lastchar[-1] == '\n')
el->el_line.lastchar--;
if (el->el_line.lastchar[-1] == ' ')
el->el_line.lastchar--;
if (el->el_line.lastchar < el->el_line.buffer)
el->el_line.lastchar = el->el_line.buffer;
}
#ifdef KSHVI
if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer;
else
if (el->el_map.type == MAP_VI)
el->el_line.cursor = el->el_line.buffer;
else
#endif /* KSHVI */
el->el_line.cursor = el->el_line.lastchar;
el->el_line.cursor = el->el_line.lastchar;
return CC_REFRESH;
return (CC_REFRESH);
}
/* hist_list()
* List history entries
*/
protected int
/*ARGSUSED*/
hist_list(el, argc, argv)
EditLine *el;
int argc;
char **argv;
hist_list(EditLine *el, int argc, char **argv)
{
const char *str;
const char *str;
if (el->el_history.ref == NULL)
return -1;
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
(void) fprintf(el->el_outfile, "%d %s", el->el_history.ev->num, str);
return 0;
if (el->el_history.ref == NULL)
return (-1);
for (str = HIST_LAST(el); str != NULL; str = HIST_PREV(el))
(void) fprintf(el->el_outfile, "%d %s",
el->el_history.ev.num, str);
return (0);
}
/* hist_enlargebuf()
* Enlarge history buffer to specified value. Called from el_enlargebufs().
* Return 0 for failure, 1 for success.
*/
protected int
/*ARGSUSED*/
hist_enlargebuf(EditLine *el, size_t oldsz, size_t newsz)
{
char *newbuf;
newbuf = realloc(el->el_history.buf, newsz);
if (!newbuf)
return 0;
(void) memset(&newbuf[oldsz], '\0', newsz - oldsz);
el->el_history.last = newbuf +
(el->el_history.last - el->el_history.buf);
el->el_history.buf = newbuf;
el->el_history.sz = newsz;
return 1;
}

View File

@ -34,44 +34,47 @@
* SUCH DAMAGE.
*
* @(#)hist.h 8.1 (Berkeley) 6/4/93
* $NetBSD: hist.h,v 1.5 2000/09/04 22:06:30 lukem Exp $
* $FreeBSD$
*/
/*
* el.hist.c: History functions
*/
#ifndef _h_el_hist
#define _h_el_hist
#define _h_el_hist
#include "histedit.h"
typedef const HistEvent * (*hist_fun_t) __P((ptr_t, int, ...));
typedef int (*hist_fun_t)(ptr_t, HistEvent *, int, ...);
typedef struct el_history_t {
char *buf; /* The history buffer */
char *last; /* The last character */
int eventno; /* Event we are looking for */
ptr_t ref; /* Argument for history fcns */
hist_fun_t fun; /* Event access */
const HistEvent *ev; /* Event cookie */
char *buf; /* The history buffer */
size_t sz; /* Size of history buffer */
char *last; /* The last character */
int eventno; /* Event we are looking for */
ptr_t ref; /* Argument for history fcns */
hist_fun_t fun; /* Event access */
HistEvent ev; /* Event cookie */
} el_history_t;
#define HIST_FUN(el, fn, arg) \
((((el)->el_history.ev = \
(*(el)->el_history.fun)((el)->el_history.ref, fn, arg)) == NULL) ? \
NULL : (el)->el_history.ev->str)
#define HIST_FUN(el, fn, arg) \
((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
#define HIST_NEXT(el) HIST_FUN(el, H_NEXT, NULL)
#define HIST_FIRST(el) HIST_FUN(el, H_FIRST, NULL)
#define HIST_LAST(el) HIST_FUN(el, H_LAST, NULL)
#define HIST_PREV(el) HIST_FUN(el, H_PREV, NULL)
#define HIST_EVENT(el, num) HIST_FUN(el, H_EVENT, num)
#define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
#define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
protected int hist_init __P((EditLine *));
protected void hist_end __P((EditLine *));
protected el_action_t hist_get __P((EditLine *));
protected int hist_set __P((EditLine *, hist_fun_t, ptr_t));
protected int hist_list __P((EditLine *, int, char **));
protected int hist_init(EditLine *);
protected void hist_end(EditLine *);
protected el_action_t hist_get(EditLine *);
protected int hist_set(EditLine *, hist_fun_t, ptr_t);
protected int hist_list(EditLine *, int, char **);
protected int hist_enlargebuf(EditLine *, size_t, size_t);
#endif /* _h_el_hist */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -34,47 +34,45 @@
* SUCH DAMAGE.
*
* @(#)key.h 8.1 (Berkeley) 6/4/93
* $NetBSD: key.h,v 1.4 2000/09/04 22:06:30 lukem Exp $
* $FreeBSD$
*/
/*
* el.key.h: Key macro header
*/
#ifndef _h_el_key
#define _h_el_key
#define _h_el_key
typedef union key_value_t {
el_action_t cmd; /* If it is a command the # */
char *str; /* If it is a string... */
el_action_t cmd; /* If it is a command the # */
char *str; /* If it is a string... */
} key_value_t;
typedef struct key_node_t key_node_t;
typedef struct el_key_t {
char *buf; /* Key print buffer */
key_node_t *map; /* Key map */
key_value_t val; /* Local conversion buffer */
char *buf; /* Key print buffer */
key_node_t *map; /* Key map */
key_value_t val; /* Local conversion buffer */
} el_key_t;
#define XK_CMD 0
#define XK_STR 1
#define XK_NOD 2
#define XK_EXE 3
#define XK_CMD 0
#define XK_STR 1
#define XK_NOD 2
#define XK_EXE 3
protected int key_init __P((EditLine *));
protected void key_end __P((EditLine *));
protected key_value_t * key_map_cmd __P((EditLine *, int));
protected key_value_t * key_map_str __P((EditLine *, char *));
protected void key_reset __P((EditLine *));
protected int key_get __P((EditLine *, char *,
key_value_t *));
protected void key_add __P((EditLine *, char *, key_value_t *,
int));
protected void key_clear __P((EditLine *, el_action_t *,
char *));
protected int key_delete __P((EditLine *, char *));
protected void key_print __P((EditLine *, char *));
protected void key_kprint __P((EditLine *, char *,
key_value_t *, int));
protected char *key__decode_str __P((char *, char *, char *));
protected int key_init(EditLine *);
protected void key_end(EditLine *);
protected key_value_t *key_map_cmd(EditLine *, int);
protected key_value_t *key_map_str(EditLine *, char *);
protected void key_reset(EditLine *);
protected int key_get(EditLine *, char *, key_value_t *);
protected void key_add(EditLine *, const char *, key_value_t *, int);
protected void key_clear(EditLine *, el_action_t *, char *);
protected int key_delete(EditLine *, char *);
protected void key_print(EditLine *, char *);
protected void key_kprint(EditLine *, char *, key_value_t *, int);
protected char *key__decode_str(char *, char *, char *);
#endif /* _h_el_key */

View File

@ -1,4 +1,6 @@
#!/bin/sh -
# $NetBSD: makelist,v 1.6 2000/09/04 23:45:18 lukem Exp $
# $FreeBSD$
#
# Copyright (c) 1992, 1993
# The Regents of the University of California. All rights reserved.
@ -38,8 +40,8 @@
# makelist.sh: Automatically generate header files...
AWK=awk
USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh <filenames>"
AWK=/usr/bin/awk
USAGE="Usage: $0 -h|-e|-fc|-fh|-bc|-bh|-m <filenames>"
if [ "x$1" = "x" ]
then
@ -53,13 +55,12 @@ shift
FILES="$@"
case $FLAG in
# generate foo.h file from foo.c
#
-h)
fn=`basename $FILES`
OIFS="$IFS"
IFS=".$IFS"
set - $fn
IFS="$OIFS"
hdr="_h_$1_$2"
set - `echo $FILES | sed -e 's/\\./_/g'`
hdr="_h_`basename $1`"
cat $FILES | $AWK '
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
@ -69,18 +70,26 @@ case $FLAG in
pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") {
name = substr($2, 1, length($2) - 3);
printf("protected el_action_t\t%-25.25s __P((EditLine *, int));\n", name);
#
# XXX: need a space between name and prototype so that -fc and -fh
# parsing is much easier
#
printf("protected el_action_t\t%s (EditLine *, int);\n", name);
}
}
END {
printf("#endif /* %s */\n", "'$hdr'");
}';;
}'
;;
# generate help.c from various .c files
#
-bc)
cat $FILES | $AWK '
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
printf("#include \"sys.h\"\n#include \"el.h\"\n");
printf("private struct el_bindings_t el_func_help[] = {\n");
printf("private const struct el_bindings_t el_func_help[] = {\n");
low = "abcdefghijklmnopqrstuvwxyz_";
high = "ABCDEFGHIJKLMNOPQRSTUVWXYZ_";
for (i = 1; i <= length(low); i++)
@ -99,9 +108,9 @@ case $FLAG in
s = "-";
fname = fname s;
}
printf(" { %-30.30s %-30.30s\n","\"" fname "\",", uname ",");
ok = 1;
ok = 1;
}
}
/^ \*/ {
@ -116,41 +125,53 @@ case $FLAG in
END {
printf(" { NULL, 0, NULL }\n");
printf("};\n");
printf("\nprotected el_bindings_t* help__get()");
printf("\nprotected const el_bindings_t* help__get()");
printf("{ return el_func_help; }\n");
}';;
}'
;;
# generate help.h from various .c files
#
-bh)
$AWK '
BEGIN {
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
printf("#ifndef _h_help_c\n#define _h_help_c\n");
printf("protected el_bindings_t *help__get\t__P((void));\n");
printf("protected const el_bindings_t *help__get(void);\n");
printf("#endif /* _h_help_c */\n");
}' /dev/null;;
}' /dev/null
;;
# generate fcns.h from various .h files
#
-fh)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | \
sort | tr '[a-z]' '[A-Z]' | $AWK '
BEGIN {
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
printf("#ifndef _h_fcns_c\n#define _h_fcns_c\n");
count = 0;
count = 0;
}
{
{
printf("#define\t%-30.30s\t%3d\n", $1, count++);
}
END {
printf("#define\t%-30.30s\t%3d\n", "EL_NUM_FCNS", count);
printf("typedef el_action_t (*el_func_t) __P((EditLine *, int));");
printf("\nprotected el_func_t* func__get __P((void));\n");
printf("typedef el_action_t (*el_func_t)(EditLine *, int);");
printf("\nprotected const el_func_t* func__get(void);\n");
printf("#endif /* _h_fcns_c */\n");
}';;
}'
;;
# generate fcns.c from various .h files
#
-fc)
cat $FILES | $AWK '/el_action_t/ { print $3 }' | sort | $AWK '
BEGIN {
printf("/* Automatically generated file, do not edit */\n");
printf("#include \"sys.h\"\n#include \"el.h\"\n");
printf("private el_func_t el_func[] = {");
printf("private const el_func_t el_func[] = {");
maxlen = 80;
needn = 1;
len = 0;
@ -158,7 +179,7 @@ case $FLAG in
{
clen = 25 + 2;
len += clen;
if (len >= maxlen)
if (len >= maxlen)
needn = 1;
if (needn) {
printf("\n ");
@ -170,8 +191,12 @@ case $FLAG in
}
END {
printf("\n};\n");
printf("\nprotected el_func_t* func__get() { return el_func; }\n");
}';;
printf("\nprotected const el_func_t* func__get() { return el_func; }\n");
}'
;;
# generate editline.c from various .c files
#
-e)
echo "$FILES" | tr ' ' '\012' | $AWK '
BEGIN {
@ -181,8 +206,50 @@ case $FLAG in
}
{
printf("#include \"%s\"\n", $1);
}';;
}'
;;
# generate man page fragment from various .c files
#
-m)
cat $FILES | $AWK '
BEGIN {
printf(".\\\" Section automatically generated with makelist\n");
printf(".Bl -tag -width 4n\n");
}
/\(\):/ {
pr = substr($2, 1, 2);
if (pr == "vi" || pr == "em" || pr == "ed") {
name = substr($2, 1, length($2) - 3);
fname = "";
for (i = 1; i <= length(name); i++) {
s = substr(name, i, 1);
if (s == "_")
s = "-";
fname = fname s;
}
printf(".It Ic %s\n", fname);
ok = 1;
}
}
/^ \*/ {
if (ok) {
for (i = 2; i < NF; i++)
printf("%s ", $i);
printf("%s.\n", $i);
ok = 0;
}
}
END {
printf(".El\n");
printf(".\\\" End of section automatically generated with makelist\n");
}'
;;
*)
echo $USAGE 1>&2
exit 1;;
exit 1
;;
esac

File diff suppressed because it is too large Load Diff

View File

@ -34,44 +34,46 @@
* SUCH DAMAGE.
*
* @(#)map.h 8.1 (Berkeley) 6/4/93
* $NetBSD: map.h,v 1.5 2000/09/04 22:06:31 lukem Exp $
* $FreeBSD$
*/
/*
* el.map.h: Editor maps
*/
#ifndef _h_el_map
#define _h_el_map
#define _h_el_map
typedef struct el_bindings_t { /* for the "bind" shell command */
const char *name; /* function name for bind command */
int func; /* function numeric value */
const char *description; /* description of function */
const char *name; /* function name for bind command */
int func; /* function numeric value */
const char *description; /* description of function */
} el_bindings_t;
typedef struct el_map_t {
el_action_t *alt; /* The current alternate key map */
el_action_t *key; /* The current normal key map */
el_action_t *current; /* The keymap we are using */
el_action_t *emacs; /* The default emacs key map */
el_action_t *vic; /* The vi command mode key map */
el_action_t *vii; /* The vi insert mode key map */
int type; /* Emacs or vi */
el_bindings_t *help; /* The help for the editor functions */
el_func_t *func; /* List of available functions */
int nfunc; /* The number of functions/help items */
el_action_t *alt; /* The current alternate key map */
el_action_t *key; /* The current normal key map */
el_action_t *current; /* The keymap we are using */
const el_action_t *emacs; /* The default emacs key map */
const el_action_t *vic; /* The vi command mode key map */
const el_action_t *vii; /* The vi insert mode key map */
int type; /* Emacs or vi */
el_bindings_t *help; /* The help for the editor functions */
el_func_t *func; /* List of available functions */
int nfunc; /* The number of functions/help items */
} el_map_t;
#define MAP_EMACS 0
#define MAP_VI 1
#define MAP_EMACS 0
#define MAP_VI 1
protected int map_bind __P((EditLine *, int, char **));
protected int map_init __P((EditLine *));
protected void map_end __P((EditLine *));
protected void map_init_vi __P((EditLine *));
protected void map_init_emacs __P((EditLine *));
protected int map_set_editor __P((EditLine *, char *));
protected int map_addfunc __P((EditLine *, const char *,
const char *, el_func_t));
protected int map_bind(EditLine *, int, char **);
protected int map_init(EditLine *);
protected void map_end(EditLine *);
protected void map_init_vi(EditLine *);
protected void map_init_emacs(EditLine *);
protected int map_set_editor(EditLine *, char *);
protected int map_get_editor(EditLine *, const char **);
protected int map_addfunc(EditLine *, const char *, const char *, el_func_t);
#endif /* _h_el_map */

View File

@ -32,6 +32,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: parse.c,v 1.13 2000/09/04 22:06:31 lukem Exp $
*/
#include <sys/cdefs.h>
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* parse.c: parse an editline extended command
@ -47,7 +51,7 @@ static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
*
* bind
* echotc
* settc
* edit
* gettc
* history
* settc
@ -56,18 +60,20 @@ static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/4/93";
#include "sys.h"
#include "el.h"
#include "tokenizer.h"
#include <stdlib.h>
private struct {
char *name;
int (*func) __P((EditLine *, int, char **));
private const struct {
char *name;
int (*func)(EditLine *, int, char **);
} cmds[] = {
{ "bind", map_bind },
{ "echotc", term_echotc },
{ "history", hist_list },
{ "telltc", term_telltc },
{ "settc", term_settc },
{ "setty", tty_stty },
{ NULL, NULL }
{ "bind", map_bind },
{ "echotc", term_echotc },
{ "edit", el_editmode },
{ "history", hist_list },
{ "telltc", term_telltc },
{ "settc", term_settc },
{ "setty", tty_stty },
{ NULL, NULL }
};
@ -75,51 +81,58 @@ private struct {
* Parse a line and dispatch it
*/
protected int
parse_line(el, line)
EditLine *el;
const char *line;
parse_line(EditLine *el, const char *line)
{
char **argv;
int argc;
Tokenizer *tok;
char **argv;
int argc;
Tokenizer *tok;
tok = tok_init(NULL);
tok_line(tok, line, &argc, &argv);
argc = el_parse(el, argc, argv);
tok_end(tok);
return argc;
tok = tok_init(NULL);
tok_line(tok, line, &argc, &argv);
argc = el_parse(el, argc, argv);
tok_end(tok);
return (argc);
}
/* el_parse():
* Command dispatcher
*/
public int
el_parse(el, argc, argv)
EditLine *el;
int argc;
char *argv[];
el_parse(EditLine *el, int argc, char *argv[])
{
char *ptr;
int i;
char *ptr;
int i;
if (argc < 1)
return -1;
ptr = strchr(argv[0], ':');
if (ptr != NULL) {
*ptr++ = '\0';
if (! el_match(el->el_prog, argv[0]))
return 0;
}
else
ptr = argv[0];
if (argc < 1)
return (-1);
ptr = strchr(argv[0], ':');
if (ptr != NULL) {
char *tprog;
size_t l;
for (i = 0; cmds[i].name != NULL; i++)
if (strcmp(cmds[i].name, ptr) == 0) {
i = (*cmds[i].func)(el, argc, argv);
return -i;
}
if (ptr == argv[0])
return (0);
l = ptr - argv[0] - 1;
tprog = (char *) el_malloc(l + 1);
if (tprog == NULL)
return (0);
(void) strncpy(tprog, argv[0], l);
tprog[l] = '\0';
ptr++;
l = el_match(el->el_prog, tprog);
el_free(tprog);
if (!l)
return (0);
} else
ptr = argv[0];
return -1;
for (i = 0; cmds[i].name != NULL; i++)
if (strcmp(cmds[i].name, ptr) == 0) {
i = (*cmds[i].func) (el, argc, argv);
return (-i);
}
return (-1);
}
@ -128,125 +141,119 @@ el_parse(el, argc, argv)
* the appropriate character or -1 if the escape is not valid
*/
protected int
parse__escape(ptr)
const char ** const ptr;
parse__escape(const char **const ptr)
{
const char *p;
int c;
const char *p;
int c;
p = *ptr;
p = *ptr;
if (p[1] == 0)
return -1;
if (p[1] == 0)
return (-1);
if (*p == '\\') {
p++;
switch (*p) {
case 'a':
c = '\007'; /* Bell */
break;
case 'b':
c = '\010'; /* Backspace */
break;
case 't':
c = '\011'; /* Horizontal Tab */
break;
case 'n':
c = '\012'; /* New Line */
break;
case 'v':
c = '\013'; /* Vertical Tab */
break;
case 'f':
c = '\014'; /* Form Feed */
break;
case 'r':
c = '\015'; /* Carriage Return */
break;
case 'e':
c = '\033'; /* Escape */
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
int cnt, ch;
for (cnt = 0, c = 0; cnt < 3; cnt++) {
ch = *p++;
if (ch < '0' || ch > '7') {
p--;
if (*p == '\\') {
p++;
switch (*p) {
case 'a':
c = '\007'; /* Bell */
break;
}
c = (c << 3) | (ch - '0');
}
if ((c & 0xffffff00) != 0)
return -1;
--p;
}
break;
default:
c = *p;
break;
}
}
else if (*p == '^' && isascii(p[1]) && (p[1] == '?' || isalpha(p[1]))) {
p++;
c = (*p == '?') ? '\177' : (*p & 0237);
}
else
c = *p;
*ptr = ++p;
return (unsigned char)c;
}
case 'b':
c = '\010'; /* Backspace */
break;
case 't':
c = '\011'; /* Horizontal Tab */
break;
case 'n':
c = '\012'; /* New Line */
break;
case 'v':
c = '\013'; /* Vertical Tab */
break;
case 'f':
c = '\014'; /* Form Feed */
break;
case 'r':
c = '\015'; /* Carriage Return */
break;
case 'e':
c = '\033'; /* Escape */
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
{
int cnt, ch;
for (cnt = 0, c = 0; cnt < 3; cnt++) {
ch = *p++;
if (ch < '0' || ch > '7') {
p--;
break;
}
c = (c << 3) | (ch - '0');
}
if ((c & 0xffffff00) != 0)
return (-1);
--p;
break;
}
default:
c = *p;
break;
}
} else if (*p == '^' && isascii(p[1]) && (p[1] == '?' || isalpha(p[1]))) {
p++;
c = (*p == '?') ? '\177' : (*p & 0237);
} else
c = *p;
*ptr = ++p;
return ((unsigned char)c);
}
/* parse__string():
* Parse the escapes from in and put the raw string out
*/
protected char *
parse__string(out, in)
char *out;
const char *in;
parse__string(char *out, const char *in)
{
char *rv = out;
int n;
for (;;)
switch (*in) {
case '\0':
*out = '\0';
return rv;
char *rv = out;
int n;
case '\\':
case '^':
if ((n = parse__escape(&in)) == -1)
return NULL;
*out++ = n;
break;
for (;;)
switch (*in) {
case '\0':
*out = '\0';
return (rv);
default:
*out++ = *in++;
break;
}
case '\\':
case '^':
if ((n = parse__escape(&in)) == -1)
return (NULL);
*out++ = n;
break;
default:
*out++ = *in++;
break;
}
}
/* parse_cmd():
* Return the command number for the command string given
* or -1 if one is not found
*/
protected int
parse_cmd(el, cmd)
EditLine *el;
const char *cmd;
parse_cmd(EditLine *el, const char *cmd)
{
el_bindings_t *b;
el_bindings_t *b;
for (b = el->el_map.help; b->name != NULL; b++)
if (strcmp(b->name, cmd) == 0)
return b->func;
return -1;
for (b = el->el_map.help; b->name != NULL; b++)
if (strcmp(b->name, cmd) == 0)
return (b->func);
return (-1);
}

View File

@ -34,17 +34,19 @@
* SUCH DAMAGE.
*
* @(#)parse.h 8.1 (Berkeley) 6/4/93
* $NetBSD: parse.h,v 1.3 1999/07/02 15:21:26 simonb Exp $
* $FreeBSD$
*/
/*
* el.parse.h: Parser functions
*/
#ifndef _h_el_parse
#define _h_el_parse
#define _h_el_parse
protected int parse_line __P((EditLine *, const char *));
protected int parse__escape __P((const char ** const));
protected char * parse__string __P((char *, const char *));
protected int parse_cmd __P((EditLine *, const char *));
protected int parse_line(EditLine *, const char *);
protected int parse__escape(const char ** const);
protected char *parse__string(char *, const char *);
protected int parse_cmd(EditLine *, const char *);
#endif /* _h_el_parse */

View File

@ -32,6 +32,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: prompt.c,v 1.7 2000/09/04 22:06:31 lukem Exp $
*/
#include <sys/cdefs.h>
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* prompt.c: Prompt printing functions
@ -47,18 +51,32 @@ static char sccsid[] = "@(#)prompt.c 8.1 (Berkeley) 6/4/93";
#include <stdio.h>
#include "el.h"
private char *prompt_default __P((EditLine *));
private char *prompt_default(EditLine *);
private char *prompt_default_r(EditLine *);
/* prompt_default():
* Just a default prompt, in case the user did not provide one
*/
private char *
/*ARGSUSED*/
prompt_default(el)
EditLine *el;
prompt_default(EditLine *el)
{
static char a[3] = { '?', ' ', '\0' };
return a;
static char a[3] = {'?', ' ', '\0'};
return (a);
}
/* prompt_default_r():
* Just a default rprompt, in case the user did not provide one
*/
private char *
/*ARGSUSED*/
prompt_default_r(EditLine *el)
{
static char a[1] = {'\0'};
return (a);
}
@ -69,31 +87,39 @@ prompt_default(el)
* bit to flag them
*/
protected void
prompt_print(el)
EditLine *el;
prompt_print(EditLine *el, int op)
{
char *p = (*el->el_prompt.p_func)(el);
while (*p)
re_putc(el, *p++);
el_prompt_t *elp;
char *p;
el->el_prompt.p_pos.v = el->el_refresh.r_cursor.v;
el->el_prompt.p_pos.h = el->el_refresh.r_cursor.h;
if (op == EL_PROMPT)
elp = &el->el_prompt;
else
elp = &el->el_rprompt;
p = (elp->p_func) (el);
while (*p)
re_putc(el, *p++, 1);
} /* end prompt_print */
elp->p_pos.v = el->el_refresh.r_cursor.v;
elp->p_pos.h = el->el_refresh.r_cursor.h;
}
/* prompt_init():
* Initialize the prompt stuff
*/
protected int
prompt_init(el)
EditLine *el;
prompt_init(EditLine *el)
{
el->el_prompt.p_func = prompt_default;
el->el_prompt.p_pos.v = 0;
el->el_prompt.p_pos.h = 0;
return 0;
} /* end prompt_init */
el->el_prompt.p_func = prompt_default;
el->el_prompt.p_pos.v = 0;
el->el_prompt.p_pos.h = 0;
el->el_rprompt.p_func = prompt_default_r;
el->el_rprompt.p_pos.v = 0;
el->el_rprompt.p_pos.h = 0;
return (0);
}
/* prompt_end():
@ -101,25 +127,48 @@ prompt_init(el)
*/
protected void
/*ARGSUSED*/
prompt_end(el)
EditLine *el;
prompt_end(EditLine *el)
{
} /* end prompt_end */
}
/* prompt_set():
* Install a prompt printing function
*/
protected int
prompt_set(el, prf)
EditLine *el;
el_pfunc_t prf;
prompt_set(EditLine *el, el_pfunc_t prf, int op)
{
if (prf == NULL)
el->el_prompt.p_func = prompt_default;
else
el->el_prompt.p_func = prf;
el->el_prompt.p_pos.v = 0;
el->el_prompt.p_pos.h = 0;
return 0;
} /* end prompt_set */
el_prompt_t *p;
if (op == EL_PROMPT)
p = &el->el_prompt;
else
p = &el->el_rprompt;
if (prf == NULL) {
if (op == EL_PROMPT)
p->p_func = prompt_default;
else
p->p_func = prompt_default_r;
} else
p->p_func = prf;
p->p_pos.v = 0;
p->p_pos.h = 0;
return (0);
}
/* prompt_get():
* Retrieve the prompt printing function
*/
protected int
prompt_get(EditLine *el, el_pfunc_t *prf, int op)
{
if (prf == NULL)
return (-1);
if (op == EL_PROMPT)
*prf = el->el_prompt.p_func;
else
*prf = el->el_rprompt.p_func;
return (0);
}

View File

@ -34,26 +34,29 @@
* SUCH DAMAGE.
*
* @(#)prompt.h 8.1 (Berkeley) 6/4/93
* $NetBSD: prompt.h,v 1.4 1999/11/12 01:05:07 lukem Exp $
* $FreeBSD$
*/
/*
* el.prompt.h: Prompt printing stuff
*/
#ifndef _h_el_prompt
#define _h_el_prompt
#define _h_el_prompt
#include "histedit.h"
typedef char * (*el_pfunc_t) __P((EditLine*));
typedef char * (*el_pfunc_t)(EditLine*);
typedef struct el_prompt_t {
el_pfunc_t p_func; /* Function to return the prompt */
coord_t p_pos; /* position in the line after prompt */
el_pfunc_t p_func; /* Function to return the prompt */
coord_t p_pos; /* position in the line after prompt */
} el_prompt_t;
protected void prompt_print __P((EditLine *));
protected int prompt_set __P((EditLine *, el_pfunc_t));
protected int prompt_init __P((EditLine *));
protected void prompt_end __P((EditLine *));
protected void prompt_print(EditLine *, int);
protected int prompt_set(EditLine *, el_pfunc_t, int);
protected int prompt_get(EditLine *, el_pfunc_t *, int);
protected int prompt_init(EditLine *);
protected void prompt_end(EditLine *);
#endif /* _h_el_prompt */

View File

@ -32,16 +32,16 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: read.c,v 1.18 2000/11/11 22:18:58 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
#if 0
static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#endif
#endif /* not lint && not SCCSID */
/*
* read.c: Clean this junk up! This is horrible code.
* Terminal read functions
@ -53,85 +53,91 @@ static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include "el.h"
#define OKCMD -1
#define OKCMD -1
private int read__fixio __P((int, int));
private int read_preread __P((EditLine *));
private int read_getcmd __P((EditLine *, el_action_t *, char *));
private int read__fixio(int, int);
private int read_preread(EditLine *);
private int read_getcmd(EditLine *, el_action_t *, char *);
private int read_char(EditLine *, char *);
#ifdef DEBUG_EDIT
private void
read_debug(el)
EditLine *el;
read_debug(EditLine *el)
{
if (el->el_line.cursor > el->el_line.lastchar)
(void) fprintf(el->el_errfile, "cursor > lastchar\r\n");
if (el->el_line.cursor < el->el_line.buffer)
(void) fprintf(el->el_errfile, "cursor < buffer\r\n");
if (el->el_line.cursor > el->el_line.limit)
(void) fprintf(el->el_errfile, "cursor > limit\r\n");
if (el->el_line.lastchar > el->el_line.limit)
(void) fprintf(el->el_errfile, "lastchar > limit\r\n");
if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2])
(void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n");
if (el->el_line.cursor > el->el_line.lastchar)
(void) fprintf(el->el_errfile, "cursor > lastchar\r\n");
if (el->el_line.cursor < el->el_line.buffer)
(void) fprintf(el->el_errfile, "cursor < buffer\r\n");
if (el->el_line.cursor > el->el_line.limit)
(void) fprintf(el->el_errfile, "cursor > limit\r\n");
if (el->el_line.lastchar > el->el_line.limit)
(void) fprintf(el->el_errfile, "lastchar > limit\r\n");
if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2])
(void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n");
}
#endif /* DEBUG_EDIT */
/* read__fixio():
* Try to recover from a read error
*/
/* ARGSUSED */
private int
read__fixio(fd, e)
int fd, e;
read__fixio(int fd, int e)
{
switch (e) {
case -1: /* Make sure that the code is reachable */
switch (e) {
case -1: /* Make sure that the code is reachable */
#ifdef EWOULDBLOCK
case EWOULDBLOCK:
# ifndef TRY_AGAIN
# define TRY_AGAIN
# endif
case EWOULDBLOCK:
#ifndef TRY_AGAIN
#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK */
#if defined(POSIX) && defined(EAGAIN)
# if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN:
# ifndef TRY_AGAIN
# define TRY_AGAIN
# endif
# endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EAGAIN:
#ifndef TRY_AGAIN
#define TRY_AGAIN
#endif
#endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
#endif /* POSIX && EAGAIN */
e = 0;
e = 0;
#ifdef TRY_AGAIN
# if defined(F_SETFL) && defined(O_NDELAY)
if ((e = fcntl(fd, F_GETFL, 0)) == -1)
return -1;
#if defined(F_SETFL) && defined(O_NDELAY)
if ((e = fcntl(fd, F_GETFL, 0)) == -1)
return (-1);
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
return -1;
else
e = 1;
# endif /* F_SETFL && O_NDELAY */
if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
return (-1);
else
e = 1;
#endif /* F_SETFL && O_NDELAY */
# ifdef FIONBIO
if (ioctl(fd, FIONBIO, (ioctl_t) &e) == -1)
return -1;
else
e = 1;
# endif /* FIONBIO */
#ifdef FIONBIO
{
int zero = 0;
if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
return (-1);
else
e = 1;
}
#endif /* FIONBIO */
#endif /* TRY_AGAIN */
return e ? 0 : -1;
return (e ? 0 : -1);
case EINTR:
return 0;
case EINTR:
return (0);
default:
return -1;
}
default:
return (-1);
}
}
@ -139,34 +145,33 @@ read__fixio(fd, e)
* Try to read the stuff in the input queue;
*/
private int
read_preread(el)
EditLine *el;
read_preread(EditLine *el)
{
int chrs = 0;
int chrs = 0;
if (el->el_chared.c_macro.nline) {
el_free((ptr_t) el->el_chared.c_macro.nline);
el->el_chared.c_macro.nline = NULL;
}
if (el->el_tty.t_mode == ED_IO)
return 0;
if (el->el_chared.c_macro.nline) {
el_free((ptr_t) el->el_chared.c_macro.nline);
el->el_chared.c_macro.nline = NULL;
}
if (el->el_tty.t_mode == ED_IO)
return (0);
#ifdef FIONREAD
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) &chrs);
if (chrs > 0) {
char buf[EL_BUFSIZ];
chrs = read(el->el_infd, buf, (size_t) MIN(chrs, EL_BUFSIZ - 1));
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
if (chrs > 0) {
buf[chrs] = '\0';
el->el_chared.c_macro.nline = strdup(buf);
el_push(el->el_chared.c_macro.nline);
}
}
#endif /* FIONREAD */
char buf[EL_BUFSIZ];
return chrs > 0;
chrs = read(el->el_infd, buf,
(size_t) MIN(chrs, EL_BUFSIZ - 1));
if (chrs > 0) {
buf[chrs] = '\0';
el->el_chared.c_macro.nline = strdup(buf);
el_push(el, el->el_chared.c_macro.nline);
}
}
#endif /* FIONREAD */
return (chrs > 0);
}
@ -174,20 +179,18 @@ read_preread(el)
* Push a macro
*/
public void
el_push(el, str)
EditLine *el;
const char *str;
el_push(EditLine *el, const char *str)
{
c_macro_t *ma = &el->el_chared.c_macro;
c_macro_t *ma = &el->el_chared.c_macro;
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++;
ma->macro[ma->level] = (char *) str;
}
else {
term_beep(el);
term__flush();
}
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++;
/* LINTED const cast */
ma->macro[ma->level] = (char *) str;
} else {
term_beep(el);
term__flush();
}
}
@ -195,57 +198,74 @@ el_push(el, str)
* Return next command from the input stream.
*/
private int
read_getcmd(el, cmdnum, ch)
EditLine *el;
el_action_t *cmdnum;
char *ch;
read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
{
el_action_t cmd = ED_UNASSIGNED;
int num;
el_action_t cmd = ED_UNASSIGNED;
int num;
while (cmd == ED_UNASSIGNED || cmd == ED_SEQUENCE_LEAD_IN) {
if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
return num;
while (cmd == ED_UNASSIGNED || cmd == ED_SEQUENCE_LEAD_IN) {
if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
return (num);
#ifdef KANJI
if ((*ch & 0200)) {
el->el_state.metanext = 0;
cmd = CcViMap[' '];
break;
}
else
if ((*ch & 0200)) {
el->el_state.metanext = 0;
cmd = CcViMap[' '];
break;
} else
#endif /* KANJI */
if (el->el_state.metanext) {
el->el_state.metanext = 0;
*ch |= 0200;
}
cmd = el->el_map.current[(unsigned char) *ch];
if (cmd == ED_SEQUENCE_LEAD_IN) {
key_value_t val;
switch (key_get(el, ch, &val)) {
case XK_CMD:
cmd = val.cmd;
break;
case XK_STR:
el_push(el, val.str);
break;
if (el->el_state.metanext) {
el->el_state.metanext = 0;
*ch |= 0200;
}
cmd = el->el_map.current[(unsigned char) *ch];
if (cmd == ED_SEQUENCE_LEAD_IN) {
key_value_t val;
switch (key_get(el, ch, &val)) {
case XK_CMD:
cmd = val.cmd;
break;
case XK_STR:
el_push(el, val.str);
break;
#ifdef notyet
case XK_EXE:
/* XXX: In the future to run a user function */
RunCommand(val.str);
break;
case XK_EXE:
/* XXX: In the future to run a user function */
RunCommand(val.str);
break;
#endif
default:
abort();
break;
}
default:
EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
break;
}
}
if (el->el_map.alt == NULL)
el->el_map.current = el->el_map.key;
}
if (el->el_map.alt == NULL)
el->el_map.current = el->el_map.key;
}
*cmdnum = cmd;
return OKCMD;
*cmdnum = cmd;
return (OKCMD);
}
/* read_char():
* Read a character from the tty.
*/
private int
read_char(EditLine *el, char *cp)
{
int num_read;
int tried = 0;
while ((num_read = read(el->el_infd, cp, 1)) == -1)
if (!tried && read__fixio(el->el_infd, errno) == 0)
tried = 1;
else {
*cp = '\0';
return (-1);
}
return (num_read);
}
@ -253,198 +273,247 @@ read_getcmd(el, cmdnum, ch)
* Read a character
*/
public int
el_getc(el, cp)
EditLine *el;
char *cp;
el_getc(EditLine *el, char *cp)
{
int num_read;
unsigned char tcp;
int tried = 0;
int num_read;
c_macro_t *ma = &el->el_chared.c_macro;
c_macro_t *ma = &el->el_chared.c_macro;
term__flush();
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
break;
}
if (ma->level < 0)
break;
term__flush();
for (;;) {
if (ma->level < 0) {
if (!read_preread(el))
break;
if (*ma->macro[ma->level] == 0) {
ma->level--;
continue;
}
*cp = *ma->macro[ma->level]++ & 0377;
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode
* On */
ma->level--;
}
return (1);
}
if (ma->level < 0)
break;
if (*ma->macro[ma->level] == 0) {
ma->level--;
continue;
}
*cp = *ma->macro[ma->level]++ & 0377;
if (*ma->macro[ma->level] == 0) { /* Needed for QuoteMode On */
ma->level--;
}
return 1;
}
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Turning raw mode on\n");
(void) fprintf(el->el_errfile, "Turning raw mode on\n");
#endif /* DEBUG_READ */
if (tty_rawmode(el) < 0) /* make sure the tty is set up correctly */
return 0;
if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
return (0);
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Reading a character\n");
(void) fprintf(el->el_errfile, "Reading a character\n");
#endif /* DEBUG_READ */
while ((num_read = read(el->el_infd, (char *) &tcp, 1)) == -1)
if (!tried && read__fixio(el->el_infd, errno) == 0)
tried = 1;
else {
*cp = '\0';
return -1;
}
num_read = read_char(el, cp);
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Got it %c\n", tcp);
(void) fprintf(el->el_errfile, "Got it %c\n", *cp);
#endif /* DEBUG_READ */
*cp = tcp;
return num_read;
return (num_read);
}
public const char *
el_gets(el, nread)
EditLine *el;
int *nread;
el_gets(EditLine *el, int *nread)
{
int retval;
el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */
char ch;
if (el->el_flags & HANDLE_SIGNALS)
sig_set(el);
re_clear_display(el); /* reset the display stuff */
ch_reset(el);
int retval;
el_action_t cmdnum = 0;
int num; /* how many chars we have read at NL */
char ch;
#ifdef FIONREAD
if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
long chrs = 0;
(void) ioctl(el->el_infd, FIONREAD, (ioctl_t) &chrs);
if (chrs == 0) {
if (tty_rawmode(el) < 0) {
if (nread)
*nread = 0;
return NULL;
}
}
}
c_macro_t *ma = &el->el_chared.c_macro;
#endif /* FIONREAD */
re_refresh(el); /* print the prompt */
if (el->el_flags & HANDLE_SIGNALS)
sig_set(el);
for (num = OKCMD; num == OKCMD;) { /* while still editing this line */
if (el->el_flags & NO_TTY) {
char *cp = el->el_line.buffer;
size_t idx;
while (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 (read_char(el, cp) == 1) {
/* make sure there is space next character */
if (cp + 1 >= el->el_line.limit) {
idx = (cp - el->el_line.buffer);
if (!ch_enlargebufs(el, 2))
break;
cp = &el->el_line.buffer[idx];
}
cp++;
if (cp[-1] == '\r' || cp[-1] == '\n')
break;
}
el->el_line.cursor = el->el_line.lastchar = cp;
*cp = '\0';
if (nread)
*nread = el->el_line.cursor - el->el_line.buffer;
return (el->el_line.buffer);
}
for (num = OKCMD; num == OKCMD;) { /* while still editing this
* line */
#ifdef DEBUG_EDIT
read_debug(el);
read_debug(el);
#endif /* DEBUG_EDIT */
/* if EOF or error */
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
/* if EOF or error */
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Returning from el_gets %d\n", num);
(void) fprintf(el->el_errfile,
"Returning from el_gets %d\n", num);
#endif /* DEBUG_READ */
break;
}
if (cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
break;
}
if ((int) cmdnum >= el->el_map.nfunc) { /* BUG CHECK command */
#ifdef DEBUG_EDIT
(void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch);
(void) fprintf(el->el_errfile,
"ERROR: illegal command from key 0%o\r\n", ch);
#endif /* DEBUG_EDIT */
continue; /* try again */
continue; /* try again */
}
/* now do the real command */
#ifdef DEBUG_READ
{
el_bindings_t *b;
for (b = el->el_map.help; b->name; b++)
if (b->func == cmdnum)
break;
if (b->name)
(void) fprintf(el->el_errfile,
"Executing %s\n", b->name);
else
(void) fprintf(el->el_errfile,
"Error command = %d\n", cmdnum);
}
#endif /* DEBUG_READ */
retval = (*el->el_map.func[cmdnum]) (el, ch);
/* save the last command here */
el->el_state.lastcmd = cmdnum;
/* use any return value */
switch (retval) {
case CC_CURSOR:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh_cursor(el);
break;
case CC_REDISPLAY:
re_clear_lines(el);
re_clear_display(el);
/* FALLTHROUGH */
case CC_REFRESH:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh(el);
break;
case CC_REFRESH_BEEP:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh(el);
term_beep(el);
break;
case CC_NORM: /* normal char */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
break;
case CC_ARGHACK: /* Suggested by Rich Salz */
/* <rsalz@pineapple.bbn.com> */
break; /* keep going... */
case CC_EOF: /* end of file typed */
num = 0;
break;
case CC_NEWLINE: /* normal end of line */
num = el->el_line.lastchar - el->el_line.buffer;
break;
case CC_FATAL: /* fatal error, reset to known state */
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile,
"*** editor fatal ERROR ***\r\n\n");
#endif /* DEBUG_READ */
/* put (real) cursor in a known place */
re_clear_display(el); /* reset the display stuff */
ch_reset(el); /* reset the input pointers */
re_refresh(el); /* print the prompt again */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
break;
case CC_ERROR:
default: /* functions we don't know about */
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile,
"*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
term_beep(el);
term__flush();
break;
}
}
/* now do the real command */
#ifdef DEBUG_READ
{
el_bindings_t *b;
for (b = el->el_map.help; b->name; b++)
if (b->func == cmdnum)
break;
if (b->name)
(void) fprintf(el->el_errfile, "Executing %s\n", b->name);
else
(void) fprintf(el->el_errfile, "Error command = %d\n", cmdnum);
}
#endif /* DEBUG_READ */
retval = (*el->el_map.func[cmdnum])(el, ch);
/* save the last command here */
el->el_state.lastcmd = cmdnum;
/* use any return value */
switch (retval) {
case CC_CURSOR:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh_cursor(el);
break;
case CC_REDISPLAY:
re_clear_lines(el);
re_clear_display(el);
/* FALLTHROUGH */
case CC_REFRESH:
el->el_state.argument = 1;
el->el_state.doingarg = 0;
re_refresh(el);
break;
case CC_NORM: /* normal char */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
break;
case CC_ARGHACK: /* Suggested by Rich Salz */
/* <rsalz@pineapple.bbn.com> */
break; /* keep going... */
case CC_EOF: /* end of file typed */
num = 0;
break;
case CC_NEWLINE: /* normal end of line */
num = el->el_line.lastchar - el->el_line.buffer;
break;
case CC_FATAL: /* fatal error, reset to known state */
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "*** editor fatal ERROR ***\r\n\n");
#endif /* DEBUG_READ */
/* put (real) cursor in a known place */
re_clear_display(el); /* reset the display stuff */
ch_reset(el); /* reset the input pointers */
re_refresh(el); /* print the prompt again */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
break;
case CC_ERROR:
default: /* functions we don't know about */
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "*** editor ERROR ***\r\n\n");
#endif /* DEBUG_READ */
el->el_state.argument = 1;
el->el_state.doingarg = 0;
term_beep(el);
term__flush();
break;
}
}
term__flush(); /* flush any buffered output */
(void) tty_cookedmode(el); /* make sure the tty is set up correctly */
if (el->el_flags & HANDLE_SIGNALS)
sig_clr(el);
if (nread)
*nread = num;
return num ? el->el_line.buffer : NULL;
term__flush(); /* flush any buffered output */
/* make sure the tty is set up correctly */
(void) tty_cookedmode(el);
if (el->el_flags & HANDLE_SIGNALS)
sig_clr(el);
if (nread)
*nread = num;
return (num ? el->el_line.buffer : NULL);
}

File diff suppressed because it is too large Load Diff

View File

@ -34,27 +34,30 @@
* SUCH DAMAGE.
*
* @(#)refresh.h 8.1 (Berkeley) 6/4/93
* $NetBSD: refresh.h,v 1.3 2000/09/04 22:06:32 lukem Exp $
* $FreeBSD$
*/
/*
* el.refresh.h: Screen refresh functions
*/
#ifndef _h_el_refresh
#define _h_el_refresh
#define _h_el_refresh
#include "histedit.h"
typedef struct {
coord_t r_cursor; /* Refresh cursor position */
int r_oldcv, r_newcv; /* Vertical locations */
coord_t r_cursor; /* Refresh cursor position */
int r_oldcv; /* Vertical locations */
int r_newcv;
} el_refresh_t;
protected void re_putc __P((EditLine *, int));
protected void re_clear_lines __P((EditLine *));
protected void re_clear_display __P((EditLine *));
protected void re_refresh __P((EditLine *));
protected void re_refresh_cursor __P((EditLine *));
protected void re_fastaddc __P((EditLine *));
protected void re_goto_bottom __P((EditLine *));
protected void re_putc(EditLine *, int, int);
protected void re_clear_lines(EditLine *);
protected void re_clear_display(EditLine *);
protected void re_refresh(EditLine *);
protected void re_refresh_cursor(EditLine *);
protected void re_fastaddc(EditLine *);
protected void re_goto_bottom(EditLine *);
#endif /* _h_el_refresh */

File diff suppressed because it is too large Load Diff

View File

@ -34,35 +34,37 @@
* SUCH DAMAGE.
*
* @(#)search.h 8.1 (Berkeley) 6/4/93
* $NetBSD: search.h,v 1.4 1999/07/02 15:21:27 simonb Exp $
* $FreeBSD$
*/
/*
* el.search.h: Line and history searching utilities
*/
#ifndef _h_el_search
#define _h_el_search
#define _h_el_search
#include "histedit.h"
typedef struct el_search_t {
char *patbuf; /* The pattern buffer */
int patlen; /* Length of the pattern buffer */
int patdir; /* Direction of the last search */
int chadir; /* Character search direction */
char chacha; /* Character we are looking for */
char *patbuf; /* The pattern buffer */
size_t patlen; /* Length of the pattern buffer */
int patdir; /* Direction of the last search */
int chadir; /* Character search direction */
char chacha; /* Character we are looking for */
} el_search_t;
protected int el_match __P((const char *, const char *));
protected int search_init __P((EditLine *));
protected void search_end __P((EditLine *));
protected int c_hmatch __P((EditLine *, const char *));
protected void c_setpat __P((EditLine *));
protected el_action_t ce_inc_search __P((EditLine *, int));
protected el_action_t cv_search __P((EditLine *, int));
protected el_action_t ce_search_line __P((EditLine *, char *, int));
protected el_action_t cv_repeat_srch __P((EditLine *, int));
protected el_action_t cv_csearch_back __P((EditLine *, int, int, int));
protected el_action_t cv_csearch_fwd __P((EditLine *, int, int, int));
protected int el_match(const char *, const char *);
protected int search_init(EditLine *);
protected void search_end(EditLine *);
protected int c_hmatch(EditLine *, const char *);
protected void c_setpat(EditLine *);
protected el_action_t ce_inc_search(EditLine *, int);
protected el_action_t cv_search(EditLine *, int);
protected el_action_t ce_search_line(EditLine *, char *, int);
protected el_action_t cv_repeat_srch(EditLine *, int);
protected el_action_t cv_csearch_back(EditLine *, int, int, int);
protected el_action_t cv_csearch_fwd(EditLine *, int, int, int);
#endif /* _h_el_search */

View File

@ -32,13 +32,15 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: sig.c,v 1.7 2001/01/04 15:55:03 christos Exp $
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* sig.c: Signal handling stuff.
@ -51,14 +53,14 @@ static char sccsid[] = "@(#)sig.c 8.1 (Berkeley) 6/4/93";
private EditLine *sel = NULL;
private int sighdl[] = {
#define _DO(a) (a),
ALLSIGS
#undef _DO
-1
private const int sighdl[] = {
#define _DO(a) (a),
ALLSIGS
#undef _DO
- 1
};
private void sig_handler __P((int));
private void sig_handler(int);
/* sig_handler():
* This is the handler called for all signals
@ -66,40 +68,39 @@ private void sig_handler __P((int));
* state in a private variable
*/
private void
sig_handler(signo)
int signo;
sig_handler(int signo)
{
int i;
sigset_t nset, oset;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
(void) sigaddset(&nset, signo);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
(void) sigaddset(&nset, signo);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
switch (signo) {
case SIGCONT:
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
term__flush();
break;
switch (signo) {
case SIGCONT:
tty_rawmode(sel);
if (ed_redisplay(sel, 0) == CC_REFRESH)
re_refresh(sel);
term__flush();
break;
case SIGWINCH:
el_resize(sel);
break;
case SIGWINCH:
el_resize(sel);
break;
default:
tty_cookedmode(sel);
break;
}
default:
tty_cookedmode(sel);
break;
}
for (i = 0; sighdl[i] != -1; i++)
if (signo == sighdl[i])
break;
for (i = 0; sighdl[i] != -1; i++)
if (signo == sighdl[i])
break;
(void) signal(signo, sel->el_signal[i]);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) kill(0, signo);
(void) signal(signo, sel->el_signal[i]);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) kill(0, signo);
}
@ -107,27 +108,28 @@ sig_handler(signo)
* Initialize all signal stuff
*/
protected int
sig_init(el)
EditLine *el;
sig_init(EditLine *el)
{
int i;
sigset_t nset, oset;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
#define SIGSIZE (sizeof(sighdl) / sizeof(sighdl[0]) * sizeof(sig_t))
el->el_signal = (sig_t *) el_malloc(SIGSIZE);
for (i = 0; sighdl[i] != -1; i++)
el->el_signal[i] = SIG_ERR;
el->el_signal = (sig_t *) el_malloc(SIGSIZE);
if (el->el_signal == NULL)
return (-1);
for (i = 0; sighdl[i] != -1; i++)
el->el_signal[i] = SIG_ERR;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
return 0;
return (0);
}
@ -135,11 +137,11 @@ sig_init(el)
* Clear all signal stuff
*/
protected void
sig_end(el)
EditLine *el;
sig_end(EditLine *el)
{
el_free((ptr_t) el->el_signal);
el->el_signal = NULL;
el_free((ptr_t) el->el_signal);
el->el_signal = NULL;
}
@ -147,26 +149,25 @@ sig_end(el)
* set all the signal handlers
*/
protected void
sig_set(el)
EditLine *el;
sig_set(EditLine *el)
{
int i;
sigset_t nset, oset;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
for (i = 0; sighdl[i] != -1; i++) {
sig_t s;
/* This could happen if we get interrupted */
if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
el->el_signal[i] = s;
}
sel = el;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
for (i = 0; sighdl[i] != -1; i++) {
sig_t s;
/* This could happen if we get interrupted */
if ((s = signal(sighdl[i], sig_handler)) != sig_handler)
el->el_signal[i] = s;
}
sel = el;
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
@ -174,22 +175,22 @@ sig_set(el)
* clear all the signal handlers
*/
protected void
sig_clr(el)
EditLine *el;
sig_clr(EditLine *el)
{
int i;
sigset_t nset, oset;
int i;
sigset_t nset, oset;
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
(void) sigemptyset(&nset);
#define _DO(a) (void) sigaddset(&nset, a);
ALLSIGS
#undef _DO
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
for (i = 0; sighdl[i] != -1; i++)
if (el->el_signal[i] != SIG_ERR)
(void) signal(sighdl[i], el->el_signal[i]);
for (i = 0; sighdl[i] != -1; i++)
if (el->el_signal[i] != SIG_ERR)
(void) signal(sighdl[i], el->el_signal[i]);
sel = NULL; /* we are going to die if the handler is called */
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
sel = NULL; /* we are going to die if the handler is
* called */
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}

View File

@ -34,13 +34,15 @@
* SUCH DAMAGE.
*
* @(#)sig.h 8.1 (Berkeley) 6/4/93
* $NetBSD: sig.h,v 1.2 1997/01/11 06:48:11 lukem Exp $
* $FreeBSD$
*/
/*
* el.sig.h: Signal handling functions
*/
#ifndef _h_el_sig
#define _h_el_sig
#define _h_el_sig
#include <signal.h>
@ -50,21 +52,21 @@
* Define here all the signals we are going to handle
* The _DO macro is used to iterate in the source code
*/
#define ALLSIGS \
_DO(SIGINT) \
_DO(SIGTSTP) \
_DO(SIGSTOP) \
_DO(SIGQUIT) \
_DO(SIGHUP) \
_DO(SIGTERM) \
_DO(SIGCONT) \
_DO(SIGWINCH)
#define ALLSIGS \
_DO(SIGINT) \
_DO(SIGTSTP) \
_DO(SIGSTOP) \
_DO(SIGQUIT) \
_DO(SIGHUP) \
_DO(SIGTERM) \
_DO(SIGCONT) \
_DO(SIGWINCH)
typedef sig_t *el_signal_t;
typedef sig_t *el_signal_t;
protected void sig_end __P((EditLine*));
protected int sig_init __P((EditLine*));
protected void sig_set __P((EditLine*));
protected void sig_clr __P((EditLine*));
protected void sig_end(EditLine*);
protected int sig_init(EditLine*);
protected void sig_set(EditLine*);
protected void sig_clr(EditLine*);
#endif /* _h_el_sig */

View File

@ -34,13 +34,15 @@
* SUCH DAMAGE.
*
* @(#)sys.h 8.1 (Berkeley) 6/4/93
* $NetBSD: sys.h,v 1.3 1997/01/11 06:48:12 lukem Exp $
* $FreeBSD$
*/
/*
* sys.h: Put all the stupid compiler and system dependencies here...
*/
#ifndef _h_sys
#define _h_sys
#define _h_sys
#ifndef public
# define public /* Externally visible functions/variables */
@ -59,57 +61,50 @@
#ifndef _PTR_T
# define _PTR_T
# if __STDC__
typedef void* ptr_t;
# else
typedef char* ptr_t;
# endif
typedef void *ptr_t;
#endif
#ifndef _IOCTL_T
# define _IOCTL_T
# if __STDC__
typedef void* ioctl_t;
# else
typedef char* ioctl_t;
# endif
typedef void *ioctl_t;
#endif
#include <stdio.h>
#define REGEX /* Use POSIX.2 regular expression functions */
#undef REGEXP /* Use UNIX V8 regular expression functions */
#define REGEX /* Use POSIX.2 regular expression functions */
#undef REGEXP /* Use UNIX V8 regular expression functions */
#ifdef SUNOS
# undef REGEX
# undef REGEXP
# include <malloc.h>
typedef void (*sig_t)__P((int));
typedef void (*sig_t)(int);
# ifdef __GNUC__
/*
* Broken hdrs.
*/
extern char *getenv __P((const char *));
extern int fprintf __P((FILE *, const char *, ...));
extern int sigsetmask __P((int));
extern int sigblock __P((int));
extern int ioctl __P((int, int, void *));
extern int fputc __P((int, FILE *));
extern int fgetc __P((FILE *));
extern int fflush __P((FILE *));
extern int tolower __P((int));
extern int toupper __P((int));
extern char *getenv(const char *);
extern int fprintf(FILE *, const char *, ...);
extern int sigsetmask(int);
extern int sigblock(int);
extern int ioctl(int, int, void *);
extern int fputc(int, FILE *);
extern int fgetc(FILE *);
extern int fflush(FILE *);
extern int tolower(int);
extern int toupper(int);
extern int errno, sys_nerr;
extern char *sys_errlist[];
extern void perror __P((const char *));
extern int read __P((int, const char*, int));
extern void perror(const char *);
extern int read(int, const char*, int);
# include <string.h>
# define strerror(e) sys_errlist[e]
# endif
# ifdef SABER
extern ptr_t memcpy __P((ptr_t, const ptr_t, size_t));
extern ptr_t memset __P((ptr_t, int, size_t));
extern ptr_t memcpy(ptr_t, const ptr_t, size_t);
extern ptr_t memset(ptr_t, int, size_t);
# endif
extern char *fgetline __P((FILE *, int *));
extern char *fgetline(FILE *, int *);
#endif
#endif /* _h_sys */

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)term.h 8.1 (Berkeley) 6/4/93
*
* $NetBSD: term.h,v 1.11 2000/11/11 22:18:58 christos Exp $
* $FreeBSD$
*/
@ -42,81 +42,83 @@
* el.term.h: Termcap header
*/
#ifndef _h_el_term
#define _h_el_term
#define _h_el_term
#include "histedit.h"
typedef struct { /* Symbolic function key bindings */
char *name; /* name of the key */
int key; /* Index in termcap table */
key_value_t fun; /* Function bound to it */
int type; /* Type of function */
typedef struct { /* Symbolic function key bindings */
char *name; /* name of the key */
int key; /* Index in termcap table */
key_value_t fun; /* Function bound to it */
int type; /* Type of function */
} fkey_t;
typedef struct {
coord_t t_size; /* # lines and cols */
bool_t t_flags;
#define TERM_CAN_INSERT 0x01 /* Has insert cap */
#define TERM_CAN_DELETE 0x02 /* Has delete cap */
#define TERM_CAN_CEOL 0x04 /* Has CEOL cap */
#define TERM_CAN_TAB 0x08 /* Can use tabs */
#define TERM_CAN_ME 0x10 /* Can turn all attrs. */
#define TERM_CAN_UP 0x20 /* Can move up */
#define TERM_HAS_META 0x40 /* Has a meta key */
char *t_buf; /* Termcap buffer */
int t_loc; /* location used */
char **t_str; /* termcap strings */
int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
fkey_t *t_fkey; /* Array of keys */
coord_t t_size; /* # lines and cols */
int t_flags;
#define TERM_CAN_INSERT 0x001 /* Has insert cap */
#define TERM_CAN_DELETE 0x002 /* Has delete cap */
#define TERM_CAN_CEOL 0x004 /* Has CEOL cap */
#define TERM_CAN_TAB 0x008 /* Can use tabs */
#define TERM_CAN_ME 0x010 /* Can turn all attrs. */
#define TERM_CAN_UP 0x020 /* Can move up */
#define TERM_HAS_META 0x040 /* Has a meta key */
#define TERM_HAS_AUTO_MARGINS 0x080 /* Has auto margins */
#define TERM_HAS_MAGIC_MARGINS 0x100 /* Has magic margins */
char *t_buf; /* Termcap buffer */
int t_loc; /* location used */
char **t_str; /* termcap strings */
int *t_val; /* termcap values */
char *t_cap; /* Termcap buffer */
fkey_t *t_fkey; /* Array of keys */
} el_term_t;
/*
* fKey indexes
*/
#define A_K_DN 0
#define A_K_UP 1
#define A_K_LT 2
#define A_K_RT 3
#define A_K_HO 4
#define A_K_EN 5
#define A_K_NKEYS 6
#define A_K_DN 0
#define A_K_UP 1
#define A_K_LT 2
#define A_K_RT 3
#define A_K_HO 4
#define A_K_EN 5
#define A_K_NKEYS 6
protected void term_move_to_line __P((EditLine *, int));
protected void term_move_to_char __P((EditLine *, int));
protected void term_clear_EOL __P((EditLine *, int));
protected void term_overwrite __P((EditLine *, char *, int));
protected void term_insertwrite __P((EditLine *, char *, int));
protected void term_deletechars __P((EditLine *, int));
protected void term_clear_screen __P((EditLine *));
protected void term_beep __P((EditLine *));
protected void term_change_size __P((EditLine *, int, int));
protected int term_get_size __P((EditLine *, int *, int *));
protected int term_init __P((EditLine *));
protected void term_bind_arrow __P((EditLine *));
protected void term_print_arrow __P((EditLine *, char *));
protected int term_clear_arrow __P((EditLine *, char *));
protected int term_set_arrow __P((EditLine *, char *,
key_value_t *, int));
protected void term_end __P((EditLine *));
protected int term_set __P((EditLine *, char *));
protected int term_settc __P((EditLine *, int, char **));
protected int term_telltc __P((EditLine *, int, char **));
protected int term_echotc __P((EditLine *, int, char **));
protected int term__putc __P((int));
protected void term__flush __P((void));
protected void term_move_to_line(EditLine *, int);
protected void term_move_to_char(EditLine *, int);
protected void term_clear_EOL(EditLine *, int);
protected void term_overwrite(EditLine *, char *, int);
protected void term_insertwrite(EditLine *, char *, int);
protected void term_deletechars(EditLine *, int);
protected void term_clear_screen(EditLine *);
protected void term_beep(EditLine *);
protected int term_change_size(EditLine *, int, int);
protected int term_get_size(EditLine *, int *, int *);
protected int term_init(EditLine *);
protected void term_bind_arrow(EditLine *);
protected void term_print_arrow(EditLine *, char *);
protected int term_clear_arrow(EditLine *, char *);
protected int term_set_arrow(EditLine *, char *, key_value_t *, int);
protected void term_end(EditLine *);
protected int term_set(EditLine *, char *);
protected int term_settc(EditLine *, int, char **);
protected int term_telltc(EditLine *, int, char **);
protected int term_echotc(EditLine *, int, char **);
protected int term__putc(int);
protected void term__flush(void);
/*
* Easy access macros
*/
#define EL_FLAGS (el)->el_term.t_flags
#define EL_FLAGS (el)->el_term.t_flags
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
#define EL_HAS_META (EL_FLAGS & TERM_HAS_META)
#define EL_CAN_INSERT (EL_FLAGS & TERM_CAN_INSERT)
#define EL_CAN_DELETE (EL_FLAGS & TERM_CAN_DELETE)
#define EL_CAN_CEOL (EL_FLAGS & TERM_CAN_CEOL)
#define EL_CAN_TAB (EL_FLAGS & TERM_CAN_TAB)
#define EL_CAN_ME (EL_FLAGS & TERM_CAN_ME)
#define EL_HAS_META (EL_FLAGS & TERM_HAS_META)
#define EL_HAS_AUTO_MARGINS (EL_FLAGS & TERM_HAS_AUTO_MARGINS)
#define EL_HAS_MAGIC_MARGINS (EL_FLAGS & TERM_HAS_MAGIC_MARGINS)
#endif /* _h_el_term */

View File

@ -32,6 +32,8 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: tokenizer.c,v 1.6 2000/09/04 22:06:33 lukem Exp $
*/
#include <sys/cdefs.h>
@ -39,6 +41,8 @@ __FBSDID("$FreeBSD$");
#if !defined(lint) && !defined(SCCSID)
static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint && not SCCSID */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
/*
* tokenize.c: Bourne shell like tokenizer
@ -48,51 +52,53 @@ static char sccsid[] = "@(#)tokenizer.c 8.1 (Berkeley) 6/4/93";
#include <stdlib.h>
#include "tokenizer.h"
typedef enum { Q_none, Q_single, Q_double, Q_one, Q_doubleone } quote_t;
typedef enum {
Q_none, Q_single, Q_double, Q_one, Q_doubleone
} quote_t;
#define IFS "\t \n"
#define IFS "\t \n"
#define TOK_KEEP 1
#define TOK_EAT 2
#define TOK_KEEP 1
#define TOK_EAT 2
#define WINCR 20
#define AINCR 10
#define WINCR 20
#define AINCR 10
#define tok_malloc(a) malloc(a)
#define tok_free(a) free(a)
#define tok_realloc(a, b) realloc(a, b)
#define tok_malloc(a) malloc(a)
#define tok_free(a) free(a)
#define tok_realloc(a, b) realloc(a, b)
#define tok_reallocf(a, b) reallocf(a, b)
struct tokenizer {
char *ifs; /* In field separator */
int argc, amax; /* Current and maximum number of args */
char **argv; /* Argument list */
char *wptr, *wmax; /* Space and limit on the word buffer */
char *wstart; /* Beginning of next word */
char *wspace; /* Space of word buffer */
quote_t quote; /* Quoting state */
int flags; /* flags; */
char *ifs; /* In field separator */
int argc, amax; /* Current and maximum number of args */
char **argv; /* Argument list */
char *wptr, *wmax; /* Space and limit on the word buffer */
char *wstart; /* Beginning of next word */
char *wspace; /* Space of word buffer */
quote_t quote; /* Quoting state */
int flags; /* flags; */
};
private void tok_finish __P((Tokenizer *));
private void tok_finish(Tokenizer *);
/* tok_finish():
* Finish a word in the tokenizer.
*/
private void
tok_finish(tok)
Tokenizer *tok;
tok_finish(Tokenizer *tok)
{
*tok->wptr = '\0';
if ((tok->flags & TOK_KEEP) || tok->wptr != tok->wstart) {
tok->argv[tok->argc++] = tok->wstart;
tok->argv[tok->argc] = NULL;
tok->wstart = ++tok->wptr;
}
tok->flags &= ~TOK_KEEP;
*tok->wptr = '\0';
if ((tok->flags & TOK_KEEP) || tok->wptr != tok->wstart) {
tok->argv[tok->argc++] = tok->wstart;
tok->argv[tok->argc] = NULL;
tok->wstart = ++tok->wptr;
}
tok->flags &= ~TOK_KEEP;
}
@ -100,24 +106,27 @@ tok_finish(tok)
* Initialize the tokenizer
*/
public Tokenizer *
tok_init(ifs)
const char *ifs;
tok_init(const char *ifs)
{
Tokenizer* tok = (Tokenizer*) tok_malloc(sizeof(Tokenizer));
Tokenizer *tok = (Tokenizer *) tok_malloc(sizeof(Tokenizer));
tok->ifs = strdup(ifs ? ifs : IFS);
tok->argc = 0;
tok->amax = AINCR;
tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
tok->argv[0] = NULL;
tok->wspace = (char *) tok_malloc(WINCR);
tok->wmax = tok->wspace + WINCR;
tok->wstart = tok->wspace;
tok->wptr = tok->wspace;
tok->flags = 0;
tok->quote = Q_none;
tok->ifs = strdup(ifs ? ifs : IFS);
tok->argc = 0;
tok->amax = AINCR;
tok->argv = (char **) tok_malloc(sizeof(char *) * tok->amax);
if (tok->argv == NULL)
return (NULL);
tok->argv[0] = NULL;
tok->wspace = (char *) tok_malloc(WINCR);
if (tok->wspace == NULL)
return (NULL);
tok->wmax = tok->wspace + WINCR;
tok->wstart = tok->wspace;
tok->wptr = tok->wspace;
tok->flags = 0;
tok->quote = Q_none;
return tok;
return (tok);
}
@ -125,14 +134,14 @@ tok_init(ifs)
* Reset the tokenizer
*/
public void
tok_reset(tok)
Tokenizer *tok;
tok_reset(Tokenizer *tok)
{
tok->argc = 0;
tok->wstart = tok->wspace;
tok->wptr = tok->wspace;
tok->flags = 0;
tok->quote = Q_none;
tok->argc = 0;
tok->wstart = tok->wspace;
tok->wptr = tok->wspace;
tok->flags = 0;
tok->quote = Q_none;
}
@ -140,13 +149,13 @@ tok_reset(tok)
* Clean up
*/
public void
tok_end(tok)
Tokenizer *tok;
tok_end(Tokenizer *tok)
{
tok_free((ptr_t) tok->ifs);
tok_free((ptr_t) tok->wspace);
tok_free((ptr_t) tok->argv);
tok_free((ptr_t) tok);
tok_free((ptr_t) tok->ifs);
tok_free((ptr_t) tok->wspace);
tok_free((ptr_t) tok->argv);
tok_free((ptr_t) tok);
}
@ -161,228 +170,229 @@ tok_end(tok)
* 0: Ok
*/
public int
tok_line(tok, line, argc, argv)
Tokenizer *tok;
const char* line;
int *argc;
char ***argv;
tok_line(Tokenizer *tok, const char *line, int *argc, char ***argv)
{
const char *ptr;
const char *ptr;
while (1) {
switch (*(ptr = line++)) {
case '\'':
tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
tok->quote = Q_single; /* Enter single quote mode */
break;
for (;;) {
switch (*(ptr = line++)) {
case '\'':
tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
tok->quote = Q_single; /* Enter single quote
* mode */
break;
case Q_single: /* Exit single quote mode */
tok->quote = Q_none;
break;
case Q_single: /* Exit single quote mode */
tok->quote = Q_none;
break;
case Q_one: /* Quote this ' */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_one: /* Quote this ' */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_double: /* Stay in double quote mode */
*tok->wptr++ = *ptr;
break;
case Q_double: /* Stay in double quote mode */
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this ' */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this ' */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
return (-1);
}
break;
case '"':
tok->flags &= ~TOK_EAT;
tok->flags |= TOK_KEEP;
switch (tok->quote) {
case Q_none: /* Enter double quote mode */
tok->quote = Q_double;
break;
case '"':
tok->flags &= ~TOK_EAT;
tok->flags |= TOK_KEEP;
switch (tok->quote) {
case Q_none: /* Enter double quote mode */
tok->quote = Q_double;
break;
case Q_double:
tok->quote = Q_none; /* Exit double quote mode */
break;
case Q_double: /* Exit double quote mode */
tok->quote = Q_none;
break;
case Q_one: /* Quote this " */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_one: /* Quote this " */
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this " */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this " */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
return (-1);
}
break;
case '\\':
tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none: /* Quote next character */
tok->quote = Q_one;
break;
case '\\':
tok->flags |= TOK_KEEP;
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none: /* Quote next character */
tok->quote = Q_one;
break;
case Q_double:
tok->quote = Q_doubleone;/* Quote next character */
break;
case Q_double: /* Quote next character */
tok->quote = Q_doubleone;
break;
case Q_one:
*tok->wptr++ = *ptr;
tok->quote = Q_none; /* Quote this, restore state */
break;
case Q_one: /* Quote this, restore state */
*tok->wptr++ = *ptr;
tok->quote = Q_none;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_single: /* Stay in single quote mode */
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this \ */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_doubleone: /* Quote this \ */
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
return (-1);
}
break;
case '\n':
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return(0);
case '\n':
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return (0);
case Q_single:
case Q_double:
*tok->wptr++ = *ptr; /* Add the return */
break;
case Q_single:
case Q_double:
*tok->wptr++ = *ptr; /* Add the return */
break;
case Q_doubleone:
tok->flags |= TOK_EAT;
tok->quote = Q_double; /* Back to double, eat the '\n' */
break;
case Q_doubleone: /* Back to double, eat the '\n' */
tok->flags |= TOK_EAT;
tok->quote = Q_double;
break;
case Q_one:
tok->flags |= TOK_EAT;
tok->quote = Q_none; /* No quote, more eat the '\n' */
break;
case Q_one: /* No quote, more eat the '\n' */
tok->flags |= TOK_EAT;
tok->quote = Q_none;
break;
default:
return(0);
}
break;
default:
return (0);
}
break;
case '\0':
switch (tok->quote) {
case Q_none:
/* Finish word and return */
if (tok->flags & TOK_EAT) {
tok->flags &= ~TOK_EAT;
return 3;
case '\0':
switch (tok->quote) {
case Q_none:
/* Finish word and return */
if (tok->flags & TOK_EAT) {
tok->flags &= ~TOK_EAT;
return (3);
}
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return (0);
case Q_single:
return (1);
case Q_double:
return (2);
case Q_doubleone:
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return (-1);
}
break;
default:
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
if (strchr(tok->ifs, *ptr) != NULL)
tok_finish(tok);
else
*tok->wptr++ = *ptr;
break;
case Q_single:
case Q_double:
*tok->wptr++ = *ptr;
break;
case Q_doubleone:
*tok->wptr++ = '\\';
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return (-1);
}
break;
}
tok_finish(tok);
*argv = tok->argv;
*argc = tok->argc;
return(0);
case Q_single:
return(1);
if (tok->wptr >= tok->wmax - 4) {
size_t size = tok->wmax - tok->wspace + WINCR;
char *s = (char *) tok_realloc(tok->wspace, size);
/* SUPPRESS 22 */
int offs = s - tok->wspace;
if (s == NULL)
return (-1);
case Q_double:
return(2);
case Q_doubleone:
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
default:
tok->flags &= ~TOK_EAT;
switch (tok->quote) {
case Q_none:
if (strchr(tok->ifs, *ptr) != NULL)
tok_finish(tok);
else
*tok->wptr++ = *ptr;
break;
case Q_single:
case Q_double:
*tok->wptr++ = *ptr;
break;
case Q_doubleone:
*tok->wptr++ = '\\';
tok->quote = Q_double;
*tok->wptr++ = *ptr;
break;
case Q_one:
tok->quote = Q_none;
*tok->wptr++ = *ptr;
break;
default:
return(-1);
}
break;
if (offs != 0) {
int i;
for (i = 0; i < tok->argc; i++)
tok->argv[i] = tok->argv[i] + offs;
tok->wptr = tok->wptr + offs;
tok->wstart = tok->wstart + offs;
tok->wmax = s + size;
tok->wspace = s;
}
}
if (tok->argc >= tok->amax - 4) {
char **p;
tok->amax += AINCR;
p = (char **) tok_reallocf(tok->argv,
tok->amax * sizeof(char *));
if (p == NULL)
return (-1);
tok->argv = p;
}
}
if (tok->wptr >= tok->wmax - 4) {
size_t size = tok->wmax - tok->wspace + WINCR;
char *s = (char *) tok_realloc(tok->wspace, size);
/*SUPPRESS 22*/
int offs = s - tok->wspace;
if (offs != 0) {
int i;
for (i = 0; i < tok->argc; i++)
tok->argv[i] = tok->argv[i] + offs;
tok->wptr = tok->wptr + offs;
tok->wstart = tok->wstart + offs;
tok->wmax = s + size;
tok->wspace = s;
}
}
if (tok->argc >= tok->amax - 4) {
tok->amax += AINCR;
tok->argv = (char **) tok_reallocf(tok->argv,
tok->amax * sizeof(char*));
}
}
}

View File

@ -34,20 +34,21 @@
* SUCH DAMAGE.
*
* @(#)tokenizer.h 8.1 (Berkeley) 6/4/93
* $NetBSD: tokenizer.h,v 1.3 1999/07/02 15:21:27 simonb Exp $
* $FreeBSD$
*/
/*
* tokenizer.h: Header file for tokenizer routines
*/
#ifndef _h_tokenizer
#define _h_tokenizer
#define _h_tokenizer
typedef struct tokenizer Tokenizer;
Tokenizer *tok_init __P((const char *));
void tok_reset __P((Tokenizer *));
void tok_end __P((Tokenizer *));
int tok_line __P((Tokenizer *, const char *,
int *, char ***));
Tokenizer *tok_init(const char *);
void tok_reset(Tokenizer *);
void tok_end(Tokenizer *);
int tok_line(Tokenizer *, const char *, int *, char ***);
#endif /* _h_tokenizer */

File diff suppressed because it is too large Load Diff

View File

@ -34,19 +34,22 @@
* SUCH DAMAGE.
*
* @(#)tty.h 8.1 (Berkeley) 6/4/93
* $NetBSD: tty.h,v 1.7 1999/09/26 14:37:47 lukem Exp $
* $FreeBSD$
*/
/*
* el.tty.h: Local terminal header
*/
#ifndef _h_el_tty
#define _h_el_tty
#define _h_el_tty
#include "histedit.h"
#include <termios.h>
#include <unistd.h>
/* Define our own since everyone gets it wrong! */
#define CONTROL(A) ((A) & 037)
#define CONTROL(A) ((A) & 037)
/*
* Aix compatible names
@ -405,66 +408,66 @@
# endif /* NUMCC */
#endif /* !POSIX */
#define C_INTR 0
#define C_QUIT 1
#define C_ERASE 2
#define C_KILL 3
#define C_EOF 4
#define C_EOL 5
#define C_EOL2 6
#define C_SWTCH 7
#define C_DSWTCH 8
#define C_ERASE2 9
#define C_START 10
#define C_STOP 11
#define C_WERASE 12
#define C_SUSP 13
#define C_DSUSP 14
#define C_REPRINT 15
#define C_DISCARD 16
#define C_LNEXT 17
#define C_STATUS 18
#define C_PAGE 19
#define C_PGOFF 20
#define C_KILL2 21
#define C_BRK 22
#define C_MIN 23
#define C_TIME 24
#define C_NCC 25
#define C_SH(A) (1 << (A))
#define C_INTR 0
#define C_QUIT 1
#define C_ERASE 2
#define C_KILL 3
#define C_EOF 4
#define C_EOL 5
#define C_EOL2 6
#define C_SWTCH 7
#define C_DSWTCH 8
#define C_ERASE2 9
#define C_START 10
#define C_STOP 11
#define C_WERASE 12
#define C_SUSP 13
#define C_DSUSP 14
#define C_REPRINT 15
#define C_DISCARD 16
#define C_LNEXT 17
#define C_STATUS 18
#define C_PAGE 19
#define C_PGOFF 20
#define C_KILL2 21
#define C_BRK 22
#define C_MIN 23
#define C_TIME 24
#define C_NCC 25
#define C_SH(A) (1 << (A))
/*
* Terminal dependend data structures
*/
#define EX_IO 0 /* while we are executing */
#define ED_IO 1 /* while we are editing */
#define TS_IO 2 /* new mode from terminal */
#define QU_IO 2 /* used only for quoted chars */
#define NN_IO 3 /* The number of entries */
#define EX_IO 0 /* while we are executing */
#define ED_IO 1 /* while we are editing */
#define TS_IO 2 /* new mode from terminal */
#define QU_IO 2 /* used only for quoted chars */
#define NN_IO 3 /* The number of entries */
#define M_INP 0
#define M_OUT 1
#define M_CTL 2
#define M_LIN 3
#define M_CHAR 4
#define M_NN 5
#define MD_INP 0
#define MD_OUT 1
#define MD_CTL 2
#define MD_LIN 3
#define MD_CHAR 4
#define MD_NN 5
typedef struct {
char *t_name;
u_int t_setmask;
u_int t_clrmask;
} ttyperm_t[NN_IO][M_NN];
char *t_name;
u_int t_setmask;
u_int t_clrmask;
} ttyperm_t[NN_IO][MD_NN];
typedef unsigned char ttychar_t[NN_IO][C_NCC];
protected int tty_init __P((EditLine *));
protected void tty_end __P((EditLine *));
protected int tty_stty __P((EditLine *, int, char**));
protected int tty_rawmode __P((EditLine *));
protected int tty_cookedmode __P((EditLine *));
protected int tty_quotemode __P((EditLine *));
protected int tty_noquotemode __P((EditLine *));
protected void tty_bind_char __P((EditLine *, int));
protected int tty_init(EditLine *);
protected void tty_end(EditLine *);
protected int tty_stty(EditLine *, int, char**);
protected int tty_rawmode(EditLine *);
protected int tty_cookedmode(EditLine *);
protected int tty_quotemode(EditLine *);
protected int tty_noquotemode(EditLine *);
protected void tty_bind_char(EditLine *, int);
typedef struct {
ttyperm_t t_t;

File diff suppressed because it is too large Load Diff