Merge NetBSD changes, among them:

el.c 1.44, el.h 1.17, editline.3 1.53, histedit.h 1.31:
# add EL_GETFP, and EL_SETFP.

el.c 1.42, term.c 1.46, term.h 1.18, editline.3 1.52, histedit.h 1.29:
# - Add more readline functions, enough for gdb-6.5
# - Make el_get varyadic, and implement EL_GETTC.
# - XXX: the EL_SETTC api will change in the future.

Note: The latter change breaks the ABI of the el_get() function.

Approved by:	re (kensmith)
This commit is contained in:
Stefan Farfeleder 2007-06-10 19:06:09 +00:00
parent 9cd40e64b4
commit 47517a7042
6 changed files with 264 additions and 119 deletions

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)histedit.h 8.2 (Berkeley) 1/3/94
* $NetBSD: histedit.h,v 1.28 2005/07/14 15:00:58 christos Exp $
* $NetBSD: histedit.h,v 1.31 2006/12/15 22:13:33 christos Exp $
* $FreeBSD$
*/
@ -104,7 +104,7 @@ int el_parse(EditLine *, int, const char **);
* Low level editline access functions
*/
int el_set(EditLine *, int, ...);
int el_get(EditLine *, int, void *);
int el_get(EditLine *, int, ...);
#if 0
unsigned char _el_fn_complete(EditLine *, int);
#endif
@ -130,6 +130,9 @@ unsigned char _el_fn_complete(EditLine *, int);
#define EL_CLIENTDATA 14 /* , void *); */
#define EL_UNBUFFERED 15 /* , int); */
#define EL_PREP_TERM 16 /* , int); */
#define EL_GETTC 17 /* , const char *, ..., NULL); */
#define EL_GETFP 18 /* , int, FILE **) */
#define EL_SETFP 19 /* , int, FILE *) */
#define EL_BUILTIN_GETCFN (NULL)

View File

@ -1,4 +1,4 @@
.\" $NetBSD: editline.3,v 1.51 2006/08/21 12:45:30 christos Exp $
.\" $NetBSD: editline.3,v 1.55 2007/01/12 16:31:13 christos Exp $
.\"
.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -31,7 +31,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd October 4, 2005
.Dd January 12, 2007
.Os
.Dt EDITLINE 3
.Sh NAME
@ -80,7 +80,7 @@
.Ft int
.Fn el_set "EditLine *e" "int op" "..."
.Ft int
.Fn el_get "EditLine *e" "int op" "void *result"
.Fn el_get "EditLine *e" "int op" "..."
.Ft int
.Fn el_source "EditLine *e" "const char *file"
.Ft void
@ -404,6 +404,25 @@ to be associated with this EditLine structure.
It can be retrieved with the corresponding
.Fn el_get
call.
.It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
Set the current
.Nm editline
file pointer for
.Dq input
.Fa fd
=
.Dv 0 ,
.Dq output
.Fa fd
=
.Dv 1 ,
or
.Dq error
.Fa fd
=
.Dv 2
from
.Fa fp .
.El
.It Fn el_get
Get
@ -428,15 +447,24 @@ Return the name of the editor, which will be one of
.Dq emacs
or
.Dq vi .
.It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
Return non-zero if
.Fa name
is a valid
.Xr termcap 5
capability
and set
.Fa value
to the current value of that capability.
.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 *"
.It Dv EL_EDITMODE , Fa "int *"
Return non-zero if editing is enabled.
.It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)"
.It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
Return a pointer to the function that read characters, which is equal to
.Dv EL_BUILTIN_GETCFN
in the case of the default builtin function.
@ -446,13 +474,32 @@ Retrieve
previously registered with the corresponding
.Fn el_set
call.
.It Dv EL_UNBUFFERED, Fa "int"
.It Dv EL_UNBUFFERED , Fa "int"
Sets or clears unbuffered mode.
In this mode,
.Fn el_gets
will return immediately after processing a single character.
.It Dv EL_PREP_TERM, Fa "int"
.It Dv EL_PREP_TERM , Fa "int"
Sets or clears terminal editing mode.
.It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
Return in
.Fa fp
the current
.Nm editline
file pointer for
.Dq input
.Fa fd
=
.Dv 0 ,
.Dq output
.Fa fd
=
.Dv 1 ,
or
.Dq error
.Fa fd
=
.Dv 2 .
.El
.It Fn el_source
Initialise
@ -514,7 +561,7 @@ Returns \-1 if
is empty or will not fit, and 0 otherwise.
.It Fn el_deletestr
Delete
.Fa num
.Fa count
characters before the cursor.
.El
.Sh HISTORY LIST FUNCTIONS
@ -638,7 +685,7 @@ into the history.
.It Dv H_GETUNIQUE
Retrieve the current setting if adjacent identical elements should
be entered into the history.
.It Dv H_DEL , Fa "int num"
.It Dv H_DEL , Fa "int e"
Delete the event numbered
.Fa e .
This function is only provided for
@ -733,7 +780,8 @@ is a NUL terminated string to tokenize.
.Xr sh 1 ,
.Xr signal 3 ,
.Xr termcap 3 ,
.Xr editrc 5
.Xr editrc 5 ,
.Xr termcap 5
.Sh HISTORY
The
.Nm

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: el.c,v 1.41 2005/08/19 04:21:47 christos Exp $
* $NetBSD: el.c,v 1.44 2006/12/15 22:13:33 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@ -66,9 +66,12 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr)
memset(el, 0, sizeof(EditLine));
el->el_infd = fileno(fin);
el->el_infile = fin;
el->el_outfile = fout;
el->el_errfile = ferr;
el->el_infd = fileno(fin);
if ((el->el_prog = el_strdup(prog)) == NULL) {
el_free(el);
return NULL;
@ -144,29 +147,29 @@ el_reset(EditLine *el)
public int
el_set(EditLine *el, int op, ...)
{
va_list va;
va_list ap;
int rv = 0;
if (el == NULL)
return (-1);
va_start(va, op);
va_start(ap, op);
switch (op) {
case EL_PROMPT:
case EL_RPROMPT:
rv = prompt_set(el, va_arg(va, el_pfunc_t), op);
rv = prompt_set(el, va_arg(ap, el_pfunc_t), op);
break;
case EL_TERMINAL:
rv = term_set(el, va_arg(va, char *));
rv = term_set(el, va_arg(ap, char *));
break;
case EL_EDITOR:
rv = map_set_editor(el, va_arg(va, char *));
rv = map_set_editor(el, va_arg(ap, char *));
break;
case EL_SIGNAL:
if (va_arg(va, int))
if (va_arg(ap, int))
el->el_flags |= HANDLE_SIGNALS;
else
el->el_flags &= ~HANDLE_SIGNALS;
@ -175,6 +178,7 @@ el_set(EditLine *el, int op, ...)
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_GETTC:
case EL_ECHOTC:
case EL_SETTY:
{
@ -182,7 +186,7 @@ el_set(EditLine *el, int op, ...)
int i;
for (i = 1; i < 20; i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
if ((argv[i] = va_arg(ap, char *)) == NULL)
break;
switch (op) {
@ -221,9 +225,9 @@ el_set(EditLine *el, int op, ...)
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);
char *name = va_arg(ap, char *);
char *help = va_arg(ap, char *);
el_func_t func = va_arg(ap, el_func_t);
rv = map_addfunc(el, name, help, func);
break;
@ -231,15 +235,15 @@ el_set(EditLine *el, int op, ...)
case EL_HIST:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
hist_fun_t func = va_arg(ap, hist_fun_t);
ptr_t ptr = va_arg(ap, char *);
rv = hist_set(el, func, ptr);
break;
}
case EL_EDITMODE:
if (va_arg(va, int))
if (va_arg(ap, int))
el->el_flags &= ~EDIT_DISABLED;
else
el->el_flags |= EDIT_DISABLED;
@ -248,17 +252,17 @@ el_set(EditLine *el, int op, ...)
case EL_GETCFN:
{
el_rfunc_t rc = va_arg(va, el_rfunc_t);
el_rfunc_t rc = va_arg(ap, el_rfunc_t);
rv = el_read_setfn(el, rc);
break;
}
case EL_CLIENTDATA:
el->el_data = va_arg(va, void *);
el->el_data = va_arg(ap, void *);
break;
case EL_UNBUFFERED:
rv = va_arg(va, int);
rv = va_arg(ap, int);
if (rv && !(el->el_flags & UNBUFFERED)) {
el->el_flags |= UNBUFFERED;
read_prepare(el);
@ -270,7 +274,7 @@ el_set(EditLine *el, int op, ...)
break;
case EL_PREP_TERM:
rv = va_arg(va, int);
rv = va_arg(ap, int);
if (rv)
(void) tty_rawmode(el);
else
@ -278,12 +282,39 @@ el_set(EditLine *el, int op, ...)
rv = 0;
break;
case EL_SETFP:
{
FILE *fp;
int what;
what = va_arg(ap, int);
fp = va_arg(ap, FILE *);
rv = 0;
switch (what) {
case 0:
el->el_infile = fp;
el->el_infd = fileno(fp);
break;
case 1:
el->el_outfile = fp;
break;
case 2:
el->el_errfile = fp;
break;
default:
rv = -1;
break;
}
break;
}
default:
rv = -1;
break;
}
va_end(va);
va_end(ap);
return (rv);
}
@ -292,90 +323,71 @@ el_set(EditLine *el, int op, ...)
* retrieve the editline parameters
*/
public int
el_get(EditLine *el, int op, void *ret)
el_get(EditLine *el, int op, ...)
{
va_list ap;
int rv;
if (el == NULL || ret == NULL)
return (-1);
if (el == NULL)
return -1;
va_start(ap, op);
switch (op) {
case EL_PROMPT:
case EL_RPROMPT:
rv = prompt_get(el, (el_pfunc_t *) ret, op);
rv = prompt_get(el, va_arg(ap, el_pfunc_t *), op);
break;
case EL_EDITOR:
rv = map_get_editor(el, (const char **)ret);
rv = map_get_editor(el, va_arg(ap, const char **));
break;
case EL_SIGNAL:
*((int *) ret) = (el->el_flags & HANDLE_SIGNALS);
*va_arg(ap, int *) = (el->el_flags & HANDLE_SIGNALS);
rv = 0;
break;
case EL_EDITMODE:
*((int *) ret) = (!(el->el_flags & EDIT_DISABLED));
*va_arg(ap, int *) = !(el->el_flags & EDIT_DISABLED);
rv = 0;
break;
case EL_TERMINAL:
term_get(el, (const char **)ret);
term_get(el, va_arg(ap, const char **));
rv = 0;
break;
#if 0 /* XXX */
case EL_BIND:
case EL_TELLTC:
case EL_SETTC:
case EL_ECHOTC:
case EL_SETTY:
case EL_GETTC:
{
const char *argv[20];
static char name[] = "gettc";
char *argv[20];
int i;
for (i = 1; i < sizeof(argv) / sizeof(argv[0]); i++)
if ((argv[i] = va_arg(va, char *)) == NULL)
if ((argv[i] = va_arg(ap, 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);
case EL_GETTC:
argv[0] = name;
rv = term_gettc(el, i, argv);
break;
default:
rv = -1;
EL_ABORT((el->errfile, "Bad op %d\n", op));
EL_ABORT((el->el_errfile, "Bad op %d\n", op));
break;
}
break;
}
#if 0 /* XXX */
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);
char *name = va_arg(ap, char *);
char *help = va_arg(ap, char *);
el_func_t func = va_arg(ap, el_func_t);
rv = map_addfunc(el, name, help, func);
break;
@ -383,31 +395,57 @@ el_get(EditLine *el, int op, void *ret)
case EL_HIST:
{
hist_fun_t func = va_arg(va, hist_fun_t);
ptr_t ptr = va_arg(va, char *);
hist_fun_t func = va_arg(ap, hist_fun_t);
ptr_t ptr = va_arg(ap, char *);
rv = hist_set(el, func, ptr);
}
break;
#endif /* XXX */
case EL_GETCFN:
*((el_rfunc_t *)ret) = el_read_getfn(el);
*va_arg(ap, el_rfunc_t *) = el_read_getfn(el);
rv = 0;
break;
case EL_CLIENTDATA:
*((void **)ret) = el->el_data;
*va_arg(ap, void **) = el->el_data;
rv = 0;
break;
case EL_UNBUFFERED:
*((int *) ret) = (!(el->el_flags & UNBUFFERED));
*va_arg(ap, int *) = (!(el->el_flags & UNBUFFERED));
rv = 0;
break;
case EL_GETFP:
{
int what;
FILE **fpp;
what = va_arg(ap, int);
fpp = va_arg(ap, FILE **);
rv = 0;
switch (what) {
case 0:
*fpp = el->el_infile;
break;
case 1:
*fpp = el->el_outfile;
break;
case 2:
*fpp = el->el_errfile;
break;
default:
rv = -1;
break;
}
break;
}
default:
rv = -1;
break;
}
va_end(ap);
return (rv);
}

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)el.h 8.1 (Berkeley) 6/4/93
* $NetBSD: el.h,v 1.16 2003/10/18 23:48:42 christos Exp $
* $NetBSD: el.h,v 1.17 2006/12/15 22:13:33 christos Exp $
* $FreeBSD$
*/
@ -110,6 +110,7 @@ typedef struct el_state_t {
struct editline {
char *el_prog; /* the program name */
FILE *el_infile; /* Stdio stuff */
FILE *el_outfile; /* Stdio stuff */
FILE *el_errfile; /* Stdio stuff */
int el_infd; /* Input file descriptor */

View File

@ -29,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $NetBSD: term.c,v 1.45 2006/03/18 19:23:14 christos Exp $
* $NetBSD: term.c,v 1.46 2006/11/24 00:01:17 christos Exp $
*/
#if !defined(lint) && !defined(SCCSID)
@ -1322,7 +1322,7 @@ term_settc(EditLine *el, int argc __unused,
const char *what, *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return (-1);
return -1;
what = argv[1];
how = argv[2];
@ -1337,7 +1337,7 @@ term_settc(EditLine *el, int argc __unused,
if (ts->name != NULL) {
term_alloc(el, ts, how);
term_setflags(el);
return (0);
return 0;
}
/*
* Do the numeric ones second
@ -1346,46 +1346,100 @@ term_settc(EditLine *el, int argc __unused,
if (strcmp(tv->name, what) == 0)
break;
if (tv->name != NULL) {
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
if (strcmp(how, "yes") == 0)
el->el_term.t_val[tv - tval] = 1;
else if (strcmp(how, "no") == 0)
el->el_term.t_val[tv - tval] = 0;
else {
(void) fprintf(el->el_errfile,
"settc: Bad value `%s'.\n", how);
return (-1);
}
term_setflags(el);
if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
return (-1);
return (0);
} else {
long i;
char *ep;
if (tv->name != NULL)
return -1;
i = strtol(how, &ep, 10);
if (*ep != '\0') {
(void) fprintf(el->el_errfile,
"settc: Bad value `%s'.\n", how);
return (-1);
}
el->el_term.t_val[tv - tval] = (int) i;
el->el_term.t_size.v = Val(T_co);
el->el_term.t_size.h = Val(T_li);
if (tv == &tval[T_co] || tv == &tval[T_li])
if (term_change_size(el, Val(T_li), Val(T_co))
== -1)
return (-1);
return (0);
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
if (strcmp(how, "yes") == 0)
el->el_term.t_val[tv - tval] = 1;
else if (strcmp(how, "no") == 0)
el->el_term.t_val[tv - tval] = 0;
else {
(void) fprintf(el->el_errfile,
"%s: Bad value `%s'.\n", argv[0], how);
return -1;
}
term_setflags(el);
if (term_change_size(el, Val(T_li), Val(T_co)) == -1)
return -1;
return 0;
} else {
long i;
char *ep;
i = strtol(how, &ep, 10);
if (*ep != '\0') {
(void) fprintf(el->el_errfile,
"%s: Bad value `%s'.\n", argv[0], how);
return -1;
}
el->el_term.t_val[tv - tval] = (int) i;
el->el_term.t_size.v = Val(T_co);
el->el_term.t_size.h = Val(T_li);
if (tv == &tval[T_co] || tv == &tval[T_li])
if (term_change_size(el, Val(T_li), Val(T_co))
== -1)
return -1;
return 0;
}
return (-1);
}
/* term_gettc():
* Get the current terminal characteristics
*/
protected int
/*ARGSUSED*/
term_gettc(EditLine *el, int argc __unused, char **argv)
{
const struct termcapstr *ts;
const struct termcapval *tv;
char *what;
void *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return (-1);
what = argv[1];
how = argv[2];
/*
* Do the strings first
*/
for (ts = tstr; ts->name != NULL; ts++)
if (strcmp(ts->name, what) == 0)
break;
if (ts->name != NULL) {
*(char **)how = el->el_term.t_str[ts - tstr];
return 0;
}
/*
* Do the numeric ones second
*/
for (tv = tval; tv->name != NULL; tv++)
if (strcmp(tv->name, what) == 0)
break;
if (tv->name == NULL)
return -1;
if (tv == &tval[T_pt] || tv == &tval[T_km] ||
tv == &tval[T_am] || tv == &tval[T_xn]) {
static char yes[] = "yes";
static char no[] = "no";
if (el->el_term.t_val[tv - tval])
*(char **)how = yes;
else
*(char **)how = no;
return 0;
} else {
*(int *)how = el->el_term.t_val[tv - tval];
return 0;
}
}
/* term_echotc():
* Print the termcap string out with variable substitution
*/

View File

@ -30,7 +30,7 @@
* SUCH DAMAGE.
*
* @(#)term.h 8.1 (Berkeley) 6/4/93
* $NetBSD: term.h,v 1.17 2006/03/06 21:11:56 christos Exp $
* $NetBSD: term.h,v 1.18 2006/11/24 00:01:17 christos Exp $
* $FreeBSD$
*/
@ -100,6 +100,7 @@ protected void term_end(EditLine *);
protected void term_get(EditLine *, const char **);
protected int term_set(EditLine *, const char *);
protected int term_settc(EditLine *, int, const char **);
protected int term_gettc(EditLine *, int, char **);
protected int term_telltc(EditLine *, int, const char **);
protected int term_echotc(EditLine *, int, const char **);
protected void term_writec(EditLine *, int);