Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libedit unbreak readline history.
details: https://anonhg.NetBSD.org/src/rev/ec2f196179d2
branches: trunk
changeset: 757712:ec2f196179d2
user: christos <christos%NetBSD.org@localhost>
date: Thu Sep 16 20:08:51 2010 +0000
description:
unbreak readline history.
diffstat:
lib/libedit/TEST/rl1.c | 59 +++++++++++++
lib/libedit/readline.c | 173 ++++++++++++++++++---------------------
lib/libedit/readline/readline.h | 3 +-
3 files changed, 142 insertions(+), 93 deletions(-)
diffs (truncated from 616 to 300 lines):
diff -r 3a277001193b -r ec2f196179d2 lib/libedit/TEST/rl1.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libedit/TEST/rl1.c Thu Sep 16 20:08:51 2010 +0000
@@ -0,0 +1,59 @@
+/* $NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $ */
+
+/*-
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#if !defined(lint)
+__RCSID("$NetBSD: rl1.c,v 1.1 2010/09/16 20:08:51 christos Exp $");
+#endif /* not lint */
+
+/*
+ * test.c: A little test program
+ */
+#include <stdio.h>
+#include <readline/readline.h>
+
+int
+main(int argc, char *argv[])
+{
+ char *p;
+ while ((p = readline("hi$")) != NULL) {
+ add_history(p);
+ printf("%d %s\n", history_length, p);
+ }
+ return 0;
+}
diff -r 3a277001193b -r ec2f196179d2 lib/libedit/readline.c
--- a/lib/libedit/readline.c Thu Sep 16 04:53:27 2010 +0000
+++ b/lib/libedit/readline.c Thu Sep 16 20:08:51 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $ */
+/* $NetBSD: readline.c,v 1.92 2010/09/16 20:08:51 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $");
+__RCSID("$NetBSD: readline.c,v 1.92 2010/09/16 20:08:51 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@@ -121,10 +121,6 @@
VFunction *rl_deprep_term_function = (VFunction *)rl_deprep_terminal;
KEYMAP_ENTRY_ARRAY emacs_meta_keymap;
-#ifdef WIDECHAR
-static ct_buffer_t conv;
-#endif
-
/*
* The current prompt string.
*/
@@ -157,7 +153,7 @@
/* stuff below is used internally by libedit for readline emulation */
-static TYPE(History) *h = NULL;
+static History *h = NULL;
static EditLine *e = NULL;
static Function *map[256];
static jmp_buf topbuf;
@@ -191,13 +187,13 @@
static HIST_ENTRY *
_move_history(int op)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
static HIST_ENTRY rl_he;
- if (FUNW(history)(h, &ev, op) != 0)
+ if (history(h, &ev, op) != 0)
return (HIST_ENTRY *) NULL;
- rl_he.line = ct_encode_string(ev.str, &conv);
+ rl_he.line = ev.str;
rl_he.data = NULL;
return (&rl_he);
@@ -282,14 +278,14 @@
int
rl_initialize(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int editmode = 1;
struct termios t;
if (e != NULL)
el_end(e);
if (h != NULL)
- FUN(history,end)(h);
+ history_end(h);
if (!rl_instream)
rl_instream = stdin;
@@ -305,13 +301,13 @@
e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr);
if (!editmode)
- FUN(el,set)(e, EL_EDITMODE, 0);
+ el_set(e, EL_EDITMODE, 0);
- h = FUN(history,init)();
+ h = history_init();
if (!e || !h)
return (-1);
- FUNW(history)(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
+ history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
history_length = 0;
max_input_history = INT_MAX;
el_set(e, EL_HIST, history, h);
@@ -325,7 +321,7 @@
/* for proper prompt printing in readline() */
if (rl_set_prompt("") == -1) {
- FUN(history,end)(h);
+ history_end(h);
el_end(e);
return -1;
}
@@ -381,7 +377,7 @@
char *
readline(const char *p)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
const char * volatile prompt = p;
int count;
const char *ret;
@@ -429,7 +425,7 @@
} else
buf = NULL;
- FUNW(history)(h, &ev, H_GETSIZE);
+ history(h, &ev, H_GETSIZE);
history_length = ev.num;
return buf;
@@ -509,7 +505,7 @@
size_t len;
char *pat;
const char *rptr;
- TYPE(HistEvent) ev;
+ HistEvent ev;
idx = *cindex;
if (cmd[idx++] != history_expansion_char)
@@ -517,10 +513,10 @@
/* find out which event to take */
if (cmd[idx] == history_expansion_char || cmd[idx] == '\0') {
- if (FUNW(history)(h, &ev, H_FIRST) != 0)
+ if (history(h, &ev, H_FIRST) != 0)
return(NULL);
*cindex = cmd[idx]? (idx + 1):idx;
- return ct_encode_string(ev.str, &conv);
+ return ev.str;
}
sign = 0;
if (cmd[idx] == '-') {
@@ -575,7 +571,7 @@
pat[len] = '\0';
}
- if (FUNW(history)(h, &ev, H_CURR) != 0) {
+ if (history(h, &ev, H_CURR) != 0) {
if (pat != last_search_pat)
free(pat);
return (NULL);
@@ -594,7 +590,7 @@
if (ret == -1) {
/* restore to end of list on failed search */
- FUNW(history)(h, &ev, H_FIRST);
+ history(h, &ev, H_FIRST);
(void)fprintf(rl_outstream, "%s: Event not found\n", pat);
if (pat != last_search_pat)
free(pat);
@@ -610,13 +606,13 @@
if (pat != last_search_pat)
free(pat);
- if (FUNW(history)(h, &ev, H_CURR) != 0)
+ if (history(h, &ev, H_CURR) != 0)
return(NULL);
*cindex = idx;
- rptr = ct_encode_string(ev.str, &conv);
+ rptr = ev.str;
/* roll back to original position */
- (void)FUNW(history)(h, &ev, H_SET, num);
+ (void)history(h, &ev, H_SET, num);
return rptr;
}
@@ -1126,12 +1122,12 @@
void
stifle_history(int max)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
- if (FUNW(history)(h, &ev, H_SETSIZE, max) == 0)
+ if (history(h, &ev, H_SETSIZE, max) == 0)
max_input_history = max;
}
@@ -1142,10 +1138,10 @@
int
unstifle_history(void)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
int omax;
- FUNW(history)(h, &ev, H_SETSIZE, INT_MAX);
+ history(h, &ev, H_SETSIZE, INT_MAX);
omax = max_input_history;
max_input_history = INT_MAX;
return (omax); /* some value _must_ be returned */
@@ -1303,13 +1299,13 @@
int
read_history(const char *filename)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (FUNW(history)(h, &ev, H_LOAD, filename) == -1 ?
+ return (history(h, &ev, H_LOAD, filename) == -1 ?
(errno ? errno : EINVAL) : 0);
}
@@ -1320,13 +1316,13 @@
int
write_history(const char *filename)
{
- TYPE(HistEvent) ev;
+ HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (FUNW(history)(h, &ev, H_SAVE, filename) == -1 ?
+ return (history(h, &ev, H_SAVE, filename) == -1 ?
(errno ? errno : EINVAL) : 0);
}
@@ -1340,29 +1336,29 @@
history_get(int num)
{
static HIST_ENTRY she;
Home |
Main Index |
Thread Index |
Old Index