Module Name:    src
Committed By:   christos
Date:           Sun May 11 01:05:17 UTC 2014

Modified Files:
        src/lib/libedit: editline.3 hist.h histedit.h history.c

Log Message:
Add a history function that takes a FILE pointer; needed for Capsicum.
>From Eitan Adler


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/lib/libedit/editline.3
cvs rdiff -u -r1.13 -r1.14 src/lib/libedit/hist.h
cvs rdiff -u -r1.51 -r1.52 src/lib/libedit/histedit.h
cvs rdiff -u -r1.46 -r1.47 src/lib/libedit/history.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libedit/editline.3
diff -u src/lib/libedit/editline.3:1.80 src/lib/libedit/editline.3:1.81
--- src/lib/libedit/editline.3:1.80	Fri Jul 12 13:48:29 2013
+++ src/lib/libedit/editline.3	Sat May 10 21:05:17 2014
@@ -1,6 +1,6 @@
-.\"	$NetBSD: editline.3,v 1.80 2013/07/12 17:48:29 christos Exp $
+.\"	$NetBSD: editline.3,v 1.81 2014/05/11 01:05:17 christos Exp $
 .\"
-.\" Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
+.\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc.
 .\" All rights reserved.
 .\"
 .\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
@@ -26,7 +26,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd July 12, 2013
+.Dd May 10, 2014
 .Dt EDITLINE 3
 .Os
 .Sh NAME
@@ -761,6 +761,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.

Index: src/lib/libedit/hist.h
diff -u src/lib/libedit/hist.h:1.13 src/lib/libedit/hist.h:1.14
--- src/lib/libedit/hist.h:1.13	Thu Jul 28 16:50:55 2011
+++ src/lib/libedit/hist.h	Sat May 10 21:05:17 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: hist.h,v 1.13 2011/07/28 20:50:55 christos Exp $	*/
+/*	$NetBSD: hist.h,v 1.14 2014/05/11 01:05:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -73,6 +73,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 *);

Index: src/lib/libedit/histedit.h
diff -u src/lib/libedit/histedit.h:1.51 src/lib/libedit/histedit.h:1.52
--- src/lib/libedit/histedit.h:1.51	Fri Jul 12 13:48:29 2013
+++ src/lib/libedit/histedit.h	Sat May 10 21:05:17 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: histedit.h,v 1.51 2013/07/12 17:48:29 christos Exp $	*/
+/*	$NetBSD: histedit.h,v 1.52 2014/05/11 01:05:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -224,6 +224,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 *);		*/
 
 
 

Index: src/lib/libedit/history.c
diff -u src/lib/libedit/history.c:1.46 src/lib/libedit/history.c:1.47
--- src/lib/libedit/history.c:1.46	Fri Nov 18 15:39:18 2011
+++ src/lib/libedit/history.c	Sat May 10 21:05:17 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $	*/
+/*	$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)history.c	8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: history.c,v 1.46 2011/11/18 20:39:18 christos Exp $");
+__RCSID("$NetBSD: history.c,v 1.47 2014/05/11 01:05:17 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -105,6 +105,7 @@ private int history_getunique(TYPE(Histo
 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;
@@ -800,9 +800,6 @@ history_save(TYPE(History) *h, const cha
 	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)
@@ -831,11 +828,29 @@ history_save(TYPE(History) *h, const cha
 oomem:
 	h_free(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
  */
@@ -1016,6 +1031,12 @@ FUNW(history)(TYPE(History) *h, TYPE(His
 			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;

Reply via email to