diff options
| author | christos <christos@NetBSD.org> | 2001-09-27 19:29:50 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2001-09-27 19:29:50 +0000 |
| commit | eabba8b5072a7eb67a64dee7c83bb5d0ebe086de (patch) | |
| tree | 05f5529fc0a31f8c9f0fb98cbb2daa1a5e48eb86 /lib/libedit | |
| parent | 7462273dbc2a5be4fde363f9c596ab0bae575eab (diff) | |
PR/14067: Anthony Mallet: Provide a programmatic way to set the read_char
function via a new el_set() operation.
Thanks, nicely done :-)
Diffstat (limited to 'lib/libedit')
| -rw-r--r-- | lib/libedit/editline.3 | 16 | ||||
| -rw-r--r-- | lib/libedit/el.c | 17 | ||||
| -rw-r--r-- | lib/libedit/el.h | 4 | ||||
| -rw-r--r-- | lib/libedit/histedit.h | 5 | ||||
| -rw-r--r-- | lib/libedit/read.c | 48 | ||||
| -rw-r--r-- | lib/libedit/read.h | 55 |
6 files changed, 134 insertions, 11 deletions
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3 index 1b812ebcc79..f74849114f5 100644 --- a/lib/libedit/editline.3 +++ b/lib/libedit/editline.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: editline.3,v 1.21 2001/04/02 18:29:49 wiz Exp $ +.\" $NetBSD: editline.3,v 1.22 2001/09/27 19:29:50 christos Exp $ .\" .\" Copyright (c) 1997-1999 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -368,6 +368,17 @@ check this (using .Fn el_get ) to determine if editing should be enabled or not. +.It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)" +Define the character reading function as +.Fa f , +which is to return the number of characters read and store them in +.Fa c . +This function is called internally by +.Fn el_gets +and +.Fn el_getc . +The builtin function can be set or restored with the special function +name ``EL_BUILTIN_GETCFN''. .El .It Fn el_get Get @@ -399,6 +410,9 @@ has installed private signal handlers (see above). .It Dv EL_EDITMODE, Fa "int *" Return non-zero if editing is enabled. +.It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)" +Return a pointer to the function that read characters, which is equal to +``EL_BUILTIN_GETCFN'' in the case of the default builtin function. .El .It Fn el_source Initialise diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 7c68284909d..3cff2861a56 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $NetBSD: el.c,v 1.22 2001/09/24 13:22:30 wiz Exp $ */ +/* $NetBSD: el.c,v 1.23 2001/09/27 19:29:50 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)el.c 8.2 (Berkeley) 1/3/94"; #else -__RCSID("$NetBSD: el.c,v 1.22 2001/09/24 13:22:30 wiz Exp $"); +__RCSID("$NetBSD: el.c,v 1.23 2001/09/27 19:29:50 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -94,6 +94,7 @@ el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr) (void) hist_init(el); (void) prompt_init(el); (void) sig_init(el); + (void) read_init(el); return (el); } @@ -247,6 +248,13 @@ el_set(EditLine *el, int op, ...) rv = 0; break; + case EL_GETCFN: + { + el_rfunc_t rc = va_arg(va, el_rfunc_t); + rv = el_read_setfn(el, rc); + break; + } + default: rv = -1; } @@ -357,6 +365,11 @@ el_get(EditLine *el, int op, void *ret) break; #endif /* XXX */ + case EL_GETCFN: + *((el_rfunc_t *)ret) = el_read_getfn(el); + rv = 0; + break; + default: rv = -1; } diff --git a/lib/libedit/el.h b/lib/libedit/el.h index b670fdb728c..ac28d0c20fd 100644 --- a/lib/libedit/el.h +++ b/lib/libedit/el.h @@ -1,4 +1,4 @@ -/* $NetBSD: el.h,v 1.8 2001/01/06 14:44:50 jdolecek Exp $ */ +/* $NetBSD: el.h,v 1.9 2001/09/27 19:29:50 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -106,6 +106,7 @@ typedef struct el_state_t { #include "parse.h" #include "sig.h" #include "help.h" +#include "read.h" struct editline { char *el_prog; /* the program name */ @@ -129,6 +130,7 @@ struct editline { el_history_t el_history; /* History stuff */ el_search_t el_search; /* Search stuff */ el_signal_t el_signal; /* Signal handling stuff */ + el_read_t el_read; /* Character reading stuff */ }; protected int el_editmode(EditLine *, int, char **); diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h index 56f98f5ea6b..9c3a2dc2401 100644 --- a/lib/libedit/histedit.h +++ b/lib/libedit/histedit.h @@ -1,4 +1,4 @@ -/* $NetBSD: histedit.h,v 1.16 2000/09/04 22:06:30 lukem Exp $ */ +/* $NetBSD: histedit.h,v 1.17 2001/09/27 19:29:50 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -126,6 +126,9 @@ int el_get(EditLine *, int, void *); #define EL_HIST 10 /* , hist_fun_t, const char *); */ #define EL_EDITMODE 11 /* , int); */ #define EL_RPROMPT 12 /* , el_pfunc_t); */ +#define EL_GETCFN 13 /* , el_rfunc_t); */ + +#define EL_BUILTIN_GETCFN (NULL) /* * Source named file or $PWD/.editrc or $HOME/.editrc diff --git a/lib/libedit/read.c b/lib/libedit/read.c index 53f0a6173e5..0103fb33597 100644 --- a/lib/libedit/read.c +++ b/lib/libedit/read.c @@ -1,4 +1,4 @@ -/* $NetBSD: read.c,v 1.19 2001/01/10 07:45:41 jdolecek Exp $ */ +/* $NetBSD: read.c,v 1.20 2001/09/27 19:29:50 christos Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -41,7 +41,7 @@ #if 0 static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; #else -__RCSID("$NetBSD: read.c,v 1.19 2001/01/10 07:45:41 jdolecek Exp $"); +__RCSID("$NetBSD: read.c,v 1.20 2001/09/27 19:29:50 christos Exp $"); #endif #endif /* not lint && not SCCSID */ @@ -59,8 +59,44 @@ __RCSID("$NetBSD: read.c,v 1.19 2001/01/10 07:45:41 jdolecek Exp $"); 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 *); +private int read_getcmd(EditLine *, el_action_t *, char *); + +/* read_init(): + * Initialize the read stuff + */ +protected int +read_init(EditLine *el) +{ + /* builtin read_char */ + el->el_read.read_char = read_char; + return 0; +} + + +/* el_read_setfn(): + * Set the read char function to the one provided. + * If it is set to EL_BUILTIN_GETCFN, then reset to the builtin one. + */ +protected int +el_read_setfn(EditLine *el, el_rfunc_t rc) +{ + el->el_read.read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc; + return 0; +} + + +/* el_read_getfn(): + * return the current read char function, or EL_BUILTIN_GETCFN + * if it is the default one + */ +protected el_rfunc_t +el_read_getfn(EditLine *el) +{ + return (el->el_read.read_char == read_char) ? + EL_BUILTIN_GETCFN : el->el_read.read_char; +} + #ifdef DEBUG_EDIT private void @@ -310,7 +346,7 @@ el_getc(EditLine *el, char *cp) #ifdef DEBUG_READ (void) fprintf(el->el_errfile, "Reading a character\n"); #endif /* DEBUG_READ */ - num_read = read_char(el, cp); + num_read = (*el->el_read.read_char)(el, cp); #ifdef DEBUG_READ (void) fprintf(el->el_errfile, "Got it %c\n", *cp); #endif /* DEBUG_READ */ @@ -336,7 +372,7 @@ el_gets(EditLine *el, int *nread) char *cp = el->el_line.buffer; size_t idx; - while (read_char(el, cp) == 1) { + while ((*el->el_read.read_char)(el, cp) == 1) { /* make sure there is space for next character */ if (cp + 1 >= el->el_line.limit) { idx = (cp - el->el_line.buffer); @@ -381,7 +417,7 @@ el_gets(EditLine *el, int *nread) term__flush(); - while (read_char(el, cp) == 1) { + while ((*el->el_read.read_char)(el, cp) == 1) { /* make sure there is space next character */ if (cp + 1 >= el->el_line.limit) { idx = (cp - el->el_line.buffer); diff --git a/lib/libedit/read.h b/lib/libedit/read.h new file mode 100644 index 00000000000..b01e77db239 --- /dev/null +++ b/lib/libedit/read.h @@ -0,0 +1,55 @@ +/* $NetBSD: read.h,v 1.1 2001/09/27 19:29:50 christos Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Anthony Mallet. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * el.read.h: Character reading functions + */ +#ifndef _h_el_read +#define _h_el_read + +typedef int (*el_rfunc_t)(EditLine *, char *); + +typedef struct el_read_t { + el_rfunc_t read_char; /* Function to read a character */ +} el_read_t; + +protected int read_init(EditLine *); +protected int el_read_setfn(EditLine *, el_rfunc_t); +protected el_rfunc_t el_read_getfn(EditLine *); + +#endif /* _h_el_read */ |
