diff options
author | 2016-05-20 15:30:17 +0000 | |
---|---|---|
committer | 2016-05-20 15:30:17 +0000 | |
commit | 04833be782e762289c5df37db589b7334e21f089 (patch) | |
tree | b1768bb3d49f8b18a0060506b6058aa95e369adb | |
parent | Please int3 guards around unused debug splx versions so we can stop (diff) | |
download | wireguard-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>.
-rw-r--r-- | lib/libedit/el.c | 13 | ||||
-rw-r--r-- | lib/libedit/el.h | 7 | ||||
-rw-r--r-- | lib/libedit/histedit.h | 4 | ||||
-rw-r--r-- | lib/libedit/read.c | 27 | ||||
-rw-r--r-- | lib/libedit/read.h | 12 |
5 files changed, 35 insertions, 28 deletions
diff --git a/lib/libedit/el.c b/lib/libedit/el.c index 846f9b54e96..28d91fad7d4 100644 --- a/lib/libedit/el.c +++ b/lib/libedit/el.c @@ -1,4 +1,4 @@ -/* $OpenBSD: el.c,v 1.34 2016/04/11 21:17:29 schwarze Exp $ */ +/* $OpenBSD: el.c,v 1.35 2016/05/20 15:30:17 schwarze Exp $ */ /* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */ /*- @@ -49,6 +49,7 @@ #include "el.h" #include "parse.h" +#include "read.h" /* el_init(): * Initialize editline and set default parameters. @@ -100,8 +101,10 @@ 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); - + if (read_init(el) == -1) { + el_end(el); + return NULL; + } return el; } @@ -281,7 +284,7 @@ el_wset(EditLine *el, int op, ...) case EL_GETCFN: { el_rfunc_t rc = va_arg(ap, el_rfunc_t); - rv = el_read_setfn(el, rc); + rv = el_read_setfn(el->el_read, rc); break; } @@ -429,7 +432,7 @@ el_wget(EditLine *el, int op, ...) } case EL_GETCFN: - *va_arg(ap, el_rfunc_t *) = el_read_getfn(el); + *va_arg(ap, el_rfunc_t *) = el_read_getfn(el->el_read); rv = 0; break; diff --git a/lib/libedit/el.h b/lib/libedit/el.h index 485ac4b983c..0c9c88b6dbf 100644 --- a/lib/libedit/el.h +++ b/lib/libedit/el.h @@ -1,4 +1,4 @@ -/* $OpenBSD: el.h,v 1.20 2016/05/06 13:12:52 schwarze Exp $ */ +/* $OpenBSD: el.h,v 1.21 2016/05/20 15:30:17 schwarze Exp $ */ /* $NetBSD: el.h,v 1.37 2016/04/18 17:01:19 christos Exp $ */ /*- @@ -96,7 +96,8 @@ typedef struct el_state_t { #include "hist.h" #include "map.h" #include "sig.h" -#include "read.h" + +struct el_read_t; struct editline { wchar_t *el_prog; /* the program name */ @@ -125,7 +126,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 */ + struct el_read_t *el_read; /* Character reading stuff */ ct_buffer_t el_scratch; /* Scratch conversion buffer */ ct_buffer_t el_lgcyconv; /* Buffer for legacy wrappers */ LineInfo el_lgcylinfo; /* Legacy LineInfo buffer */ diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h index cb65ba7fb05..092aa893f4f 100644 --- a/lib/libedit/histedit.h +++ b/lib/libedit/histedit.h @@ -1,4 +1,4 @@ -/* $OpenBSD: histedit.h,v 1.14 2016/03/20 23:48:27 schwarze Exp $ */ +/* $OpenBSD: histedit.h,v 1.15 2016/05/20 15:30:17 schwarze Exp $ */ /* $NetBSD: histedit.h,v 1.46 2010/04/15 00:50:03 christos Exp $ */ /*- @@ -261,6 +261,8 @@ typedef struct lineinfow { const wchar_t *lastchar; } LineInfoW; +typedef int (*el_rfunc_t)(EditLine *, wchar_t *); + const wchar_t *el_wgets(EditLine *, int *); int el_wgetc(EditLine *, wchar_t *); void el_wpush(EditLine *, const wchar_t *); 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) { diff --git a/lib/libedit/read.h b/lib/libedit/read.h index 0643d733a80..9487874a4e4 100644 --- a/lib/libedit/read.h +++ b/lib/libedit/read.h @@ -1,4 +1,4 @@ -/* $OpenBSD: read.h,v 1.5 2016/03/21 17:28:10 schwarze Exp $ */ +/* $OpenBSD: read.h,v 1.6 2016/05/20 15:30:17 schwarze Exp $ */ /* $NetBSD: read.h,v 1.9 2016/02/24 17:13:22 christos Exp $ */ /*- @@ -36,16 +36,10 @@ #ifndef _h_el_read #define _h_el_read -typedef int (*el_rfunc_t)(EditLine *, wchar_t *); - -typedef struct el_read_t { - el_rfunc_t read_char; /* Function to read a character */ -} el_read_t; - protected int read_init(EditLine *); protected void read_prepare(EditLine *); protected void read_finish(EditLine *); -protected int el_read_setfn(EditLine *, el_rfunc_t); -protected el_rfunc_t el_read_getfn(EditLine *); +protected int el_read_setfn(struct el_read_t *, el_rfunc_t); +protected el_rfunc_t el_read_getfn(struct el_read_t *); #endif /* _h_el_read */ |