summaryrefslogtreecommitdiffstats
path: root/lib/libedit/read.c
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2016-05-20 15:30:17 +0000
committerschwarze <schwarze@openbsd.org>2016-05-20 15:30:17 +0000
commit04833be782e762289c5df37db589b7334e21f089 (patch)
treeb1768bb3d49f8b18a0060506b6058aa95e369adb /lib/libedit/read.c
parentPlease int3 guards around unused debug splx versions so we can stop (diff)
downloadwireguard-openbsd-04833be782e762289c5df37db589b7334e21f089.tar.xz
wireguard-openbsd-04833be782e762289c5df37db589b7334e21f089.zip
Move the declaration of the function pointer type el_rfunc_t
from the private header "read.h" to the public header <histedit.h>. That's not an interface change, it was already used and documented publicly, merely not properly declared. Improve encapsulation: Make el_read a pointer to an opaque struct in struct editline, such that "read.h" no longer needs to be included from "el.h" but only from the two files using it, read.c and el.c. Only pass the required el_read_t to el_read_{s,g}etfn(), do not pass the full struct editline. OK czarkoff@, also proofread by Christian Heckendorf <mbie at ulmus dot me>.
Diffstat (limited to 'lib/libedit/read.c')
-rw-r--r--lib/libedit/read.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index dd19b6ffcaf..65b43f93013 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: read.c,v 1.39 2016/05/06 13:12:52 schwarze Exp $ */
+/* $OpenBSD: read.c,v 1.40 2016/05/20 15:30:17 schwarze Exp $ */
/* $NetBSD: read.c,v 1.94 2016/04/18 17:01:19 christos Exp $ */
/*-
@@ -49,6 +49,11 @@
#include "el.h"
#include "fcns.h"
+#include "read.h"
+
+struct el_read_t {
+ el_rfunc_t read_char; /* Function to read a character. */
+};
static int read__fixio(int, int);
static int read_char(EditLine *, wchar_t *);
@@ -61,8 +66,10 @@ static void read_pop(c_macro_t *);
protected int
read_init(EditLine *el)
{
+ if ((el->el_read = malloc(sizeof(*el->el_read))) == NULL)
+ return -1;
/* builtin read_char */
- el->el_read.read_char = read_char;
+ el->el_read->read_char = read_char;
return 0;
}
@@ -72,9 +79,9 @@ read_init(EditLine *el)
* 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_read_setfn(struct el_read_t *el_read, el_rfunc_t rc)
{
- el->el_read.read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc;
+ el_read->read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc;
return 0;
}
@@ -84,10 +91,10 @@ el_read_setfn(EditLine *el, el_rfunc_t rc)
* if it is the default one
*/
protected el_rfunc_t
-el_read_getfn(EditLine *el)
+el_read_getfn(struct el_read_t *el_read)
{
- return el->el_read.read_char == read_char ?
- EL_BUILTIN_GETCFN : el->el_read.read_char;
+ return el_read->read_char == read_char ?
+ EL_BUILTIN_GETCFN : el_read->read_char;
}
@@ -384,7 +391,7 @@ el_wgetc(EditLine *el, wchar_t *cp)
#ifdef DEBUG_READ
(void) fprintf(el->el_errfile, "Reading a character\n");
#endif /* DEBUG_READ */
- num_read = (*el->el_read.read_char)(el, cp);
+ num_read = (*el->el_read->read_char)(el, cp);
if (num_read < 0)
el->el_errno = errno;
#ifdef DEBUG_READ
@@ -442,7 +449,7 @@ el_wgets(EditLine *el, int *nread)
size_t idx;
cp = el->el_line.buffer;
- while ((num = (*el->el_read.read_char)(el, &wc)) == 1) {
+ while ((num = (*el->el_read->read_char)(el, &wc)) == 1) {
*cp = wc;
/* make sure there is space for next character */
if (cp + 1 >= el->el_line.limit) {
@@ -495,7 +502,7 @@ el_wgets(EditLine *el, int *nread)
terminal__flush(el);
- while ((num = (*el->el_read.read_char)(el, &wc)) == 1) {
+ while ((num = (*el->el_read->read_char)(el, &wc)) == 1) {
*cp = wc;
/* make sure there is space next character */
if (cp + 1 >= el->el_line.limit) {