summaryrefslogtreecommitdiff
path: root/lib/libedit
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2014-05-19 08:58:35 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2014-05-19 08:58:35 +0000
commitb12e99ddcf61a0a6938dd02d7bd6a6e109db1aff (patch)
tree90c9f5f8ebfe902a71eb999c8276ae2e3e472e4e /lib/libedit
parent205f64a57ed21efc2f7bda9917c34b90b5a15419 (diff)
Add a H_SAVE_FP operation to history() which lets the history be saved
to an open file pointer. From NetBSD via Eitan Adler. ok millert
Diffstat (limited to 'lib/libedit')
-rw-r--r--lib/libedit/editline.39
-rw-r--r--lib/libedit/hist.h3
-rw-r--r--lib/libedit/histedit.h3
-rw-r--r--lib/libedit/history.c37
-rw-r--r--lib/libedit/shlib_version2
5 files changed, 41 insertions, 13 deletions
diff --git a/lib/libedit/editline.3 b/lib/libedit/editline.3
index 98d69618154..c6a35b0c01f 100644
--- a/lib/libedit/editline.3
+++ b/lib/libedit/editline.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: editline.3,v 1.33 2013/01/10 14:21:47 jmc Exp $
+.\" $OpenBSD: editline.3,v 1.34 2014/05/19 08:58:34 nicm Exp $
.\" $NetBSD: editline.3,v 1.73 2010/01/03 19:05:26 wiz Exp $
.\"
.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: January 10 2013 $
+.Dd $Mdocdate: May 19 2014 $
.Dt EDITLINE 3
.Os
.Sh NAME
@@ -735,6 +735,11 @@ Load the history list stored in
.It Dv H_SAVE , Fa "const char *file"
Save the history list to
.Fa file .
+.It Dv H_SAVE_FP , Fa "FILE *fp"
+Save the history list to the opened
+.Fa fp
+.Ft FILE
+pointer .
.It Dv H_SETUNIQUE , Fa "int unique"
Set flag that adjacent identical event strings should not be entered
into the history.
diff --git a/lib/libedit/hist.h b/lib/libedit/hist.h
index 1f14fd9dec0..246d4d974c3 100644
--- a/lib/libedit/hist.h
+++ b/lib/libedit/hist.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hist.h,v 1.8 2010/06/30 00:05:35 nicm Exp $ */
+/* $OpenBSD: hist.h,v 1.9 2014/05/19 08:58:34 nicm Exp $ */
/* $NetBSD: hist.h,v 1.12 2009/12/30 23:54:52 christos Exp $ */
/*-
@@ -74,6 +74,7 @@ typedef struct el_history_t {
#define HIST_SET(el, num) HIST_FUN(el, H_SET, num)
#define HIST_LOAD(el, fname) HIST_FUN(el, H_LOAD fname)
#define HIST_SAVE(el, fname) HIST_FUN(el, H_SAVE fname)
+#define HIST_SAVE_FP(el, fp) HIST_FUN(el, H_SAVE_FP fp)
protected int hist_init(EditLine *);
protected void hist_end(EditLine *);
diff --git a/lib/libedit/histedit.h b/lib/libedit/histedit.h
index 3c049e6aa93..7213c4e0b4d 100644
--- a/lib/libedit/histedit.h
+++ b/lib/libedit/histedit.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: histedit.h,v 1.11 2011/07/07 05:40:42 okan Exp $ */
+/* $OpenBSD: histedit.h,v 1.12 2014/05/19 08:58:34 nicm Exp $ */
/* $NetBSD: histedit.h,v 1.46 2010/04/15 00:50:03 christos Exp $ */
/*-
@@ -225,6 +225,7 @@ int history(History *, HistEvent *, int, ...);
#define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */
#define H_DELDATA 24 /* , int, histdata_t *);*/
#define H_REPLACE 25 /* , const char *, histdata_t); */
+#define H_SAVE_FP 26 /* , FILE *); */
diff --git a/lib/libedit/history.c b/lib/libedit/history.c
index 76b0d70bc0c..1c8290b621f 100644
--- a/lib/libedit/history.c
+++ b/lib/libedit/history.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: history.c,v 1.17 2014/01/19 11:48:54 tobias Exp $ */
+/* $OpenBSD: history.c,v 1.18 2014/05/19 08:58:34 nicm Exp $ */
/* $NetBSD: history.c,v 1.37 2010/01/03 18:27:10 christos Exp $ */
/*-
@@ -103,6 +103,7 @@ private int history_getunique(TYPE(History) *, TYPE(HistEvent) *);
private int history_set_fun(TYPE(History) *, TYPE(History) *);
private int history_load(TYPE(History) *, const char *);
private int history_save(TYPE(History) *, const char *);
+private int history_save_fp(TYPE(History) *, FILE *);
private int history_prev_event(TYPE(History) *, TYPE(HistEvent) *, int);
private int history_next_event(TYPE(History) *, TYPE(HistEvent) *, int);
private int history_next_string(TYPE(History) *, TYPE(HistEvent) *, const Char *);
@@ -784,13 +785,12 @@ done:
}
-/* history_save():
+/* history_save_fp():
* TYPE(History) save function
*/
private int
-history_save(TYPE(History) *h, const char *fname)
+history_save_fp(TYPE(History) *h, FILE *fp)
{
- FILE *fp;
TYPE(HistEvent) ev;
int i = -1, retval;
size_t len, max_size;
@@ -799,9 +799,6 @@ history_save(TYPE(History) *h, const char *fname)
static ct_buffer_t conv;
#endif
- if ((fp = fopen(fname, "w")) == NULL)
- return (-1);
-
if (fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1)
goto done;
if (fputs(hist_cookie, fp) == EOF)
@@ -830,11 +827,29 @@ history_save(TYPE(History) *h, const char *fname)
oomem:
h_free((ptr_t)ptr);
done:
- (void) fclose(fp);
return (i);
}
+/* history_save():
+ * History save function
+ */
+private int
+history_save(TYPE(History) *h, const char *fname)
+{
+ FILE *fp;
+ int i;
+
+ if ((fp = fopen(fname, "w")) == NULL)
+ return -1;
+
+ i = history_save_fp(h, fp);
+
+ (void) fclose(fp);
+ return i;
+}
+
+
/* history_prev_event():
* Find the previous event, with number given
*/
@@ -1015,6 +1030,12 @@ FUNW(history)(TYPE(History) *h, TYPE(HistEvent) *ev, int fun, ...)
he_seterrev(ev, _HE_HIST_WRITE);
break;
+ case H_SAVE_FP:
+ retval = history_save_fp(h, va_arg(va, FILE *));
+ if (retval == -1)
+ he_seterrev(ev, _HE_HIST_WRITE);
+ break;
+
case H_PREV_EVENT:
retval = history_prev_event(h, ev, va_arg(va, int));
break;
diff --git a/lib/libedit/shlib_version b/lib/libedit/shlib_version
index 3066b9771e7..900b4048a96 100644
--- a/lib/libedit/shlib_version
+++ b/lib/libedit/shlib_version
@@ -1,2 +1,2 @@
major=5
-minor=0
+minor=1