- 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.
This commit is contained in:
christos 2006-11-24 00:01:17 +00:00
parent 4e48d71604
commit 6b8a793080
8 changed files with 240 additions and 94 deletions

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.52 2006/11/24 00:01:17 christos Exp $
.\"
.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -29,7 +29,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 9, 2005
.Dd November 23, 2006
.Os
.Dt EDITLINE 3
.Sh NAME
@ -78,7 +78,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
@ -422,6 +422,15 @@ 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 7
capability
and set
.Fa value
to the current value of that capability.
.It Dv EL_SIGNAL , Fa "int *"
Return non-zero if
.Nm

View File

@ -1,4 +1,4 @@
/* $NetBSD: el.c,v 1.41 2005/08/19 04:21:47 christos Exp $ */
/* $NetBSD: el.c,v 1.42 2006/11/24 00:01:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94";
#else
__RCSID("$NetBSD: el.c,v 1.41 2005/08/19 04:21:47 christos Exp $");
__RCSID("$NetBSD: el.c,v 1.42 2006/11/24 00:01:17 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -174,6 +174,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:
{
@ -291,75 +292,55 @@ 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:
@ -370,6 +351,7 @@ el_get(EditLine *el, int op, void *ret)
break;
}
#if 0 /* XXX */
case EL_ADDFN:
{
char *name = va_arg(va, char *);
@ -390,23 +372,24 @@ el_get(EditLine *el, int op, void *ret)
#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;
default:
rv = -1;
}
va_end(ap);
return (rv);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: histedit.h,v 1.28 2005/07/14 15:00:58 christos Exp $ */
/* $NetBSD: histedit.h,v 1.29 2006/11/24 00:01:17 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -109,7 +109,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, ...);
unsigned char _el_fn_complete(EditLine *, int);
/*
@ -133,6 +133,7 @@ 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_BUILTIN_GETCFN (NULL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.c,v 1.69 2006/08/21 12:45:30 christos Exp $ */
/* $NetBSD: readline.c,v 1.70 2006/11/24 00:01:17 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: readline.c,v 1.69 2006/08/21 12:45:30 christos Exp $");
__RCSID("$NetBSD: readline.c,v 1.70 2006/11/24 00:01:17 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@ -49,6 +49,7 @@ __RCSID("$NetBSD: readline.c,v 1.69 2006/08/21 12:45:30 christos Exp $");
#include <limits.h>
#include <errno.h>
#include <fcntl.h>
#include <setjmp.h>
#ifdef HAVE_VIS_H
#include <vis.h>
#else
@ -88,6 +89,9 @@ char *rl_line_buffer = NULL;
VCPFunction *rl_linefunc = NULL;
int rl_done = 0;
VFunction *rl_event_hook = NULL;
KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
emacs_meta_keymap,
emacs_ctlx_keymap;
int history_base = 1; /* probably never subject to change */
int history_length = 0;
@ -113,6 +117,8 @@ int rl_already_prompted = 0;
int rl_filename_completion_desired = 0;
int rl_ignore_completion_duplicates = 0;
int rl_catch_signals = 1;
int readline_echoing_p = 1;
int _rl_print_completions_horizontally = 0;
VFunction *rl_redisplay_function = NULL;
Function *rl_startup_hook = NULL;
VFunction *rl_completion_display_matches_hook = NULL;
@ -154,6 +160,7 @@ int rl_completion_append_character = ' ';
static History *h = NULL;
static EditLine *e = NULL;
static Function *map[256];
static jmp_buf topbuf;
/* internal functions */
static unsigned char _el_rl_complete(EditLine *, int);
@ -322,9 +329,10 @@ rl_initialize(void)
* trailing newline (if there is any)
*/
char *
readline(const char *prompt)
readline(const char *p)
{
HistEvent ev;
const char * volatile prompt = p;
int count;
const char *ret;
char *buf;
@ -335,6 +343,8 @@ readline(const char *prompt)
rl_done = 0;
(void)setjmp(topbuf);
/* update prompt accordingly to what has been passed */
if (!prompt)
prompt = "";
@ -1805,3 +1815,82 @@ _rl_update_pos(void)
rl_point = li->cursor - li->buffer;
rl_end = li->lastchar - li->buffer;
}
void
rl_get_screen_size(int *rows, int *cols)
{
if (rows)
el_get(e, EL_GETTC, "li", rows);
if (cols)
el_get(e, EL_GETTC, "co", cols);
}
void
rl_set_screen_size(int rows, int cols)
{
char buf[64];
(void)snprintf(buf, sizeof(buf), "%d", rows);
el_set(e, EL_SETTC, "li", buf);
(void)snprintf(buf, sizeof(buf), "%d", cols);
el_set(e, EL_SETTC, "co", buf);
}
char *
rl_filename_completion_function (const char *text, int state)
{
return fn_filename_completion_function(text, state);
}
int
_rl_abort_internal(void)
{
el_beep(e);
longjmp(topbuf, 1);
/*NOTREACHED*/
}
int
_rl_qsort_string_compare(char **s1, char **s2)
{
return strcoll(*s1, *s2);
}
int
/*ARGSUSED*/
rl_kill_text(int from, int to)
{
return 0;
}
Keymap
rl_make_bare_keymap(void)
{
return NULL;
}
Keymap
rl_get_keymap(void)
{
return NULL;
}
void
/*ARGSUSED*/
rl_set_keymap(Keymap k)
{
}
int
/*ARGSUSED*/
rl_generic_bind(int type, const char * keyseq, const char * data, Keymap k)
{
return 0;
}
int
/*ARGSUSED*/
rl_bind_key_in_map(int key, Function *fun, Keymap k)
{
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.h,v 1.18 2006/08/21 12:45:30 christos Exp $ */
/* $NetBSD: readline.h,v 1.19 2006/11/24 00:01:17 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -123,6 +123,8 @@ extern VFunction *rl_redisplay_function;
extern VFunction *rl_completion_display_matches_hook;
extern VFunction *rl_prep_term_function;
extern VFunction *rl_deprep_term_function;
extern int readline_echoing_p;
extern int _rl_print_completions_horizontally;
/* supported functions */
char *readline(const char *);
@ -176,11 +178,18 @@ int rl_parse_and_bind(const char *);
int rl_variable_bind(const char *, const char *);
void rl_stuff_char(int);
int rl_add_defun(const char *, Function *, int);
void rl_get_screen_size(int *, int *);
void rl_set_screen_size(int, int);
char *rl_filename_completion_function (const char *, int);
int _rl_abort_internal(void);
int _rl_qsort_string_compare(char **, char **);
/*
* The following are not implemented
*/
int rl_kill_text(int, int);
Keymap rl_get_keymap(void);
void rl_set_keymap(Keymap);
Keymap rl_make_bare_keymap(void);
int rl_generic_bind(int, const char *, const char *, Keymap);
int rl_bind_key_in_map(int, Function *, Keymap);

View File

@ -1,5 +1,5 @@
# $NetBSD: shlib_version,v 1.15 2003/12/05 13:37:48 lukem Exp $
# $NetBSD: shlib_version,v 1.16 2006/11/24 00:01:17 christos Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=2
minor=9
minor=10

View File

@ -1,4 +1,4 @@
/* $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 $ */
/*-
* Copyright (c) 1992, 1993
@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)term.c 8.2 (Berkeley) 4/30/95";
#else
__RCSID("$NetBSD: term.c,v 1.45 2006/03/18 19:23:14 christos Exp $");
__RCSID("$NetBSD: term.c,v 1.46 2006/11/24 00:01:17 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -1328,7 +1328,7 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
const char *what, *how;
if (argv == NULL || argv[1] == NULL || argv[2] == NULL)
return (-1);
return -1;
what = argv[1];
how = argv[2];
@ -1343,7 +1343,7 @@ term_settc(EditLine *el, int argc __attribute__((__unused__)),
if (ts->name != NULL) {
term_alloc(el, ts, how);
term_setflags(el);
return (0);
return 0;
}
/*
* Do the numeric ones second
@ -1352,46 +1352,100 @@ term_settc(EditLine *el, int argc __attribute__((__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 __attribute__((__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

@ -1,4 +1,4 @@
/* $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 $ */
/*-
* Copyright (c) 1992, 1993
@ -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);