summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-05-22 23:09:57 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-05-22 23:09:57 +0000
commitef8b1b00aed61bc6a471a607fb8bc029f404b1ce (patch)
treecc77b1ee87c8106f606e0fd4d3d3854f5587399b
parent469fa820a861fd8f53dc72da4af67bbbbfdd2bc8 (diff)
Improve modularization at the chared/read boundary, no functional change.
Stop the read.c module from poking the el_chared.c_macro data structure that used to belong to the chared.c module. Given that no other module, not even chared itself, is using that data, move it into the read modules's own opaque data structure, struct el_read_t. That gets rid of one struct, one #define, one struct member, and one function argument in the chared.h interface. OK czarkoff@
-rw-r--r--lib/libedit/chared.c29
-rw-r--r--lib/libedit/chared.h14
-rw-r--r--lib/libedit/common.c4
-rw-r--r--lib/libedit/el.c5
-rw-r--r--lib/libedit/read.c59
-rw-r--r--lib/libedit/read.h5
6 files changed, 63 insertions, 53 deletions
diff --git a/lib/libedit/chared.c b/lib/libedit/chared.c
index 68efae17e87..18e3d0295f2 100644
--- a/lib/libedit/chared.c
+++ b/lib/libedit/chared.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chared.c,v 1.26 2016/05/06 13:12:52 schwarze Exp $ */
+/* $OpenBSD: chared.c,v 1.27 2016/05/22 23:09:56 schwarze Exp $ */
/* $NetBSD: chared.c,v 1.28 2009/12/30 22:37:40 christos Exp $ */
/*-
@@ -46,8 +46,6 @@
#include "common.h"
#include "fcns.h"
-static void ch__clearmacro (EditLine *);
-
/* value to leave unused in line buffer */
#define EL_LEAVE 2
@@ -392,8 +390,6 @@ cv__endword(wchar_t *p, wchar_t *high, int n, int (*wtest)(wint_t))
protected int
ch_init(EditLine *el)
{
- c_macro_t *ma = &el->el_chared.c_macro;
-
el->el_line.buffer = reallocarray(NULL, EL_BUFSIZ,
sizeof(*el->el_line.buffer));
if (el->el_line.buffer == NULL)
@@ -443,12 +439,6 @@ ch_init(EditLine *el)
el->el_state.argument = 1;
el->el_state.lastcmd = ED_UNASSIGNED;
- ma->level = -1;
- ma->offset = 0;
- ma->macro = reallocarray(NULL, EL_MAXMACRO,
- sizeof(*ma->macro));
- if (ma->macro == NULL)
- return -1;
return 0;
}
@@ -456,7 +446,7 @@ ch_init(EditLine *el)
* Reset the character editor
*/
protected void
-ch_reset(EditLine *el, int mclear)
+ch_reset(EditLine *el)
{
el->el_line.cursor = el->el_line.buffer;
el->el_line.lastchar = el->el_line.buffer;
@@ -478,17 +468,6 @@ ch_reset(EditLine *el, int mclear)
el->el_state.lastcmd = ED_UNASSIGNED;
el->el_history.eventno = 0;
-
- if (mclear)
- ch__clearmacro(el);
-}
-
-static void
-ch__clearmacro(EditLine *el)
-{
- c_macro_t *ma = &el->el_chared.c_macro;
- while (ma->level >= 0)
- free(ma->macro[ma->level--]);
}
/* ch_enlargebufs():
@@ -600,9 +579,7 @@ ch_end(EditLine *el)
el->el_chared.c_redo.cmd = ED_UNASSIGNED;
free(el->el_chared.c_kill.buf);
el->el_chared.c_kill.buf = NULL;
- ch_reset(el, 1);
- free(el->el_chared.c_macro.macro);
- el->el_chared.c_macro.macro = NULL;
+ ch_reset(el);
}
diff --git a/lib/libedit/chared.h b/lib/libedit/chared.h
index 8de380a30e6..41e7db78d09 100644
--- a/lib/libedit/chared.h
+++ b/lib/libedit/chared.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: chared.h,v 1.14 2016/04/11 20:43:33 schwarze Exp $ */
+/* $OpenBSD: chared.h,v 1.15 2016/05/22 23:09:56 schwarze Exp $ */
/* $NetBSD: chared.h,v 1.20 2010/04/15 00:57:33 christos Exp $ */
/*-
@@ -41,8 +41,6 @@
#ifndef _h_el_chared
#define _h_el_chared
-#define EL_MAXMACRO 10
-
/*
* This is an issue of basic "vi" look-and-feel. Defining VI_MOVE works
* like real vi: i.e. the transition from command<->insert modes moves
@@ -55,13 +53,6 @@
*/
#define VI_MOVE
-
-typedef struct c_macro_t {
- int level;
- int offset;
- wchar_t **macro;
-} c_macro_t;
-
/*
* Undo information for vi - no undo in emacs (yet)
*/
@@ -110,7 +101,6 @@ typedef struct el_chared_t {
c_kill_t c_kill;
c_redo_t c_redo;
c_vcmd_t c_vcmd;
- c_macro_t c_macro;
el_zfunc_t c_resizefun;
void * c_resizearg;
} el_chared_t;
@@ -154,7 +144,7 @@ protected int c_gets(EditLine *, wchar_t *, const wchar_t *);
protected int c_hpos(EditLine *);
protected int ch_init(EditLine *);
-protected void ch_reset(EditLine *, int);
+protected void ch_reset(EditLine *);
protected int ch_resizefun(EditLine *, el_zfunc_t, void *);
protected int ch_enlargebufs(EditLine *, size_t);
protected void ch_end(EditLine *);
diff --git a/lib/libedit/common.c b/lib/libedit/common.c
index 9dc424a2b1e..8d20c480066 100644
--- a/lib/libedit/common.c
+++ b/lib/libedit/common.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: common.c,v 1.21 2016/05/06 13:12:52 schwarze Exp $ */
+/* $OpenBSD: common.c,v 1.22 2016/05/22 23:09:56 schwarze Exp $ */
/* $NetBSD: common.c,v 1.24 2009/12/30 22:37:40 christos Exp $ */
/*-
@@ -526,7 +526,7 @@ protected el_action_t
ed_start_over(EditLine *el, wint_t c __attribute__((__unused__)))
{
- ch_reset(el, 0);
+ ch_reset(el);
return CC_REFRESH;
}
diff --git a/lib/libedit/el.c b/lib/libedit/el.c
index 28d91fad7d4..3999744baa9 100644
--- a/lib/libedit/el.c
+++ b/lib/libedit/el.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: el.c,v 1.35 2016/05/20 15:30:17 schwarze Exp $ */
+/* $OpenBSD: el.c,v 1.36 2016/05/22 23:09:56 schwarze Exp $ */
/* $NetBSD: el.c,v 1.61 2011/01/27 23:11:40 christos Exp $ */
/*-
@@ -126,6 +126,7 @@ el_end(EditLine *el)
map_end(el);
tty_end(el);
ch_end(el);
+ read_end(el->el_read);
search_end(el);
hist_end(el);
prompt_end(el);
@@ -148,7 +149,7 @@ el_reset(EditLine *el)
{
tty_cookedmode(el);
- ch_reset(el, 0); /* XXX: Do we want that? */
+ ch_reset(el); /* XXX: Do we want that? */
}
diff --git a/lib/libedit/read.c b/lib/libedit/read.c
index 65b43f93013..9b3805fae57 100644
--- a/lib/libedit/read.c
+++ b/lib/libedit/read.c
@@ -1,5 +1,5 @@
-/* $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 $ */
+/* $OpenBSD: read.c,v 1.41 2016/05/22 23:09:56 schwarze Exp $ */
+/* $NetBSD: read.c,v 1.97 2016/05/22 19:44:26 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -51,14 +51,24 @@
#include "fcns.h"
#include "read.h"
+#define EL_MAXMACRO 10
+
+struct macros {
+ wchar_t **macro;
+ int level;
+ int offset;
+};
+
struct el_read_t {
+ struct macros macros;
el_rfunc_t read_char; /* Function to read a character. */
};
static int read__fixio(int, int);
static int read_char(EditLine *, wchar_t *);
static int read_getcmd(EditLine *, el_action_t *, wchar_t *);
-static void read_pop(c_macro_t *);
+static void read_clearmacros(struct macros *);
+static void read_pop(struct macros *);
/* read_init():
* Initialize the read stuff
@@ -66,13 +76,35 @@ static void read_pop(c_macro_t *);
protected int
read_init(EditLine *el)
{
+ struct macros *ma;
+
if ((el->el_read = malloc(sizeof(*el->el_read))) == NULL)
return -1;
+
+ ma = &el->el_read->macros;
+ if ((ma->macro = reallocarray(NULL, EL_MAXMACRO,
+ sizeof(*ma->macro))) == NULL) {
+ free(el->el_read);
+ return -1;
+ }
+ ma->level = -1;
+ ma->offset = 0;
+
/* builtin read_char */
el->el_read->read_char = read_char;
return 0;
}
+/* el_read_end():
+ * Free the data structures used by the read stuff.
+ */
+protected void
+read_end(struct el_read_t *el_read)
+{
+ read_clearmacros(&el_read->macros);
+ free(el_read->macros.macro);
+ el_read->macros.macro = NULL;
+}
/* el_read_setfn():
* Set the read char function to the one provided.
@@ -185,7 +217,7 @@ read__fixio(int fd __attribute__((__unused__)), int e)
void
el_wpush(EditLine *el, const wchar_t *str)
{
- c_macro_t *ma = &el->el_chared.c_macro;
+ struct macros *ma = &el->el_read->macros;
if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
ma->level++;
@@ -342,7 +374,7 @@ read_char(EditLine *el, wchar_t *cp)
* Pop a macro from the stack
*/
static void
-read_pop(c_macro_t *ma)
+read_pop(struct macros *ma)
{
int i;
@@ -353,14 +385,22 @@ read_pop(c_macro_t *ma)
ma->offset = 0;
}
+static void
+read_clearmacros(struct macros *ma)
+{
+ while (ma->level >= 0)
+ free(ma->macro[ma->level--]);
+ ma->offset = 0;
+}
+
/* el_wgetc():
* Read a wide character
*/
int
el_wgetc(EditLine *el, wchar_t *cp)
{
+ struct macros *ma = &el->el_read->macros;
int num_read;
- c_macro_t *ma = &el->el_chared.c_macro;
terminal__flush(el);
for (;;) {
@@ -414,7 +454,7 @@ read_prepare(EditLine *el)
we have the wrong size. */
el_resize(el);
re_clear_display(el); /* reset the display stuff */
- ch_reset(el, 0);
+ ch_reset(el);
re_refresh(el); /* print the prompt */
if (el->el_flags & UNBUFFERED)
@@ -475,7 +515,7 @@ el_wgets(EditLine *el, int *nread)
#ifdef FIONREAD
- if (el->el_tty.t_mode == EX_IO && el->el_chared.c_macro.level < 0) {
+ if (el->el_tty.t_mode == EX_IO && el->el_read->macros.level < 0) {
int chrs = 0;
(void) ioctl(el->el_infd, FIONREAD, &chrs);
@@ -638,7 +678,8 @@ el_wgets(EditLine *el, int *nread)
#endif /* DEBUG_READ */
/* put (real) cursor in a known place */
re_clear_display(el); /* reset the display stuff */
- ch_reset(el, 1); /* reset the input pointers */
+ ch_reset(el); /* reset the input pointers */
+ read_clearmacros(&el->el_read->macros);
re_refresh(el); /* print the prompt again */
break;
diff --git a/lib/libedit/read.h b/lib/libedit/read.h
index 9487874a4e4..bb75a3547b5 100644
--- a/lib/libedit/read.h
+++ b/lib/libedit/read.h
@@ -1,5 +1,5 @@
-/* $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 $ */
+/* $OpenBSD: read.h,v 1.7 2016/05/22 23:09:56 schwarze Exp $ */
+/* $NetBSD: read.h,v 1.12 2016/05/22 19:44:26 christos Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -37,6 +37,7 @@
#define _h_el_read
protected int read_init(EditLine *);
+protected void read_end(struct el_read_t *);
protected void read_prepare(EditLine *);
protected void read_finish(EditLine *);
protected int el_read_setfn(struct el_read_t *, el_rfunc_t);