PR/30747: David N. Williams: libedit is missing remove_history()

Added, please test.
This commit is contained in:
christos 2005-07-14 15:00:58 +00:00
parent a4c1884902
commit 45542456a5
5 changed files with 76 additions and 13 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: editline.3,v 1.46 2005/03/19 17:36:02 christos Exp $
.\" $NetBSD: editline.3,v 1.47 2005/07/14 15:00:58 christos Exp $
.\"
.\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
.\" All rights reserved.
@ -33,7 +33,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd March 19, 2005
.Dd July 14, 2005
.Os
.Dt EDITLINE 3
.Sh NAME
@ -634,6 +634,14 @@ the history.
.It Dv H_GETUNIQUE
Retrieve the current setting if if adjacent elements should be entered into
the history.
.It Dv H_DEL , Fa "int num"
Delete the event numbered
.Fa e .
This function is only provided for
.Xr readline 3
compatibility.
The caller is responsible for free'ing the string in the returned
.Fa HistEvent .
.El
.Pp
.Fn history

View File

@ -1,4 +1,4 @@
/* $NetBSD: histedit.h,v 1.27 2005/06/12 06:58:21 christos Exp $ */
/* $NetBSD: histedit.h,v 1.28 2005/07/14 15:00:58 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@ -197,6 +197,7 @@ int history(History *, HistEvent *, int, ...);
#define H_CLEAR 19 /* , void); */
#define H_SETUNIQUE 20 /* , int); */
#define H_GETUNIQUE 21 /* , void); */
#define H_DEL 22 /* , int); */
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: history.c,v 1.29 2005/07/06 21:13:02 christos Exp $ */
/* $NetBSD: history.c,v 1.30 2005/07/14 15:00:58 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.29 2005/07/06 21:13:02 christos Exp $");
__RCSID("$NetBSD: history.c,v 1.30 2005/07/14 15:00:58 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@ -72,6 +72,7 @@ struct history {
history_gfun_t h_prev; /* Get the previous element */
history_gfun_t h_curr; /* Get the current element */
history_sfun_t h_set; /* Set the current element */
history_sfun_t h_del; /* Set the given element */
history_vfun_t h_clear; /* Clear the history list */
history_efun_t h_enter; /* Add an element */
history_efun_t h_add; /* Append to an element */
@ -86,6 +87,7 @@ struct history {
#define HCLEAR(h, ev) (*(h)->h_clear)((h)->h_ref, ev)
#define HENTER(h, ev, str) (*(h)->h_enter)((h)->h_ref, ev, str)
#define HADD(h, ev, str) (*(h)->h_add)((h)->h_ref, ev, str)
#define HDEL(h, ev, n) (*(h)->h_del)((h)->h_ref, ev, n)
#define h_strdup(a) strdup(a)
#define h_malloc(a) malloc(a)
@ -133,16 +135,18 @@ typedef struct history_t {
#define H_UNIQUE 1 /* Store only unique elements */
} history_t;
private int history_def_first(ptr_t, HistEvent *);
private int history_def_last(ptr_t, HistEvent *);
private int history_def_next(ptr_t, HistEvent *);
private int history_def_first(ptr_t, HistEvent *);
private int history_def_prev(ptr_t, HistEvent *);
private int history_def_last(ptr_t, HistEvent *);
private int history_def_curr(ptr_t, HistEvent *);
private int history_def_set(ptr_t, HistEvent *, const int n);
private int history_def_set(ptr_t, HistEvent *, const int);
private void history_def_clear(ptr_t, HistEvent *);
private int history_def_enter(ptr_t, HistEvent *, const char *);
private int history_def_add(ptr_t, HistEvent *, const char *);
private int history_def_del(ptr_t, HistEvent *, const int);
private int history_def_init(ptr_t *, HistEvent *, int);
private void history_def_clear(ptr_t, HistEvent *);
private int history_def_insert(history_t *, HistEvent *, const char *);
private void history_def_delete(history_t *, HistEvent *, hentry_t *);
@ -364,6 +368,24 @@ history_def_add(ptr_t p, HistEvent *ev, const char *str)
}
/* history_def_del():
* Delete element hp of the h list
*/
/* ARGSUSED */
private int
history_def_del(ptr_t p, HistEvent *ev __attribute__((__unused__)),
const int num)
{
history_t *h = (history_t *) p;
if (history_def_set(h, ev, num) != 0)
return (-1);
ev->str = strdup(h->cursor->ev.str);
ev->num = h->cursor->ev.num;
history_def_delete(h, ev, h->cursor);
return (0);
}
/* history_def_delete():
* Delete element hp of the h list
*/
@ -375,6 +397,8 @@ history_def_delete(history_t *h,
HistEventPrivate *evp = (void *)&hp->ev;
if (hp == &h->list)
abort();
if (h->cursor == hp)
h->cursor = hp->prev;
hp->prev->next = hp->next;
hp->next->prev = hp->prev;
h_free((ptr_t) evp->str);
@ -609,7 +633,7 @@ history_set_fun(History *h, History *nh)
if (nh->h_first == NULL || nh->h_next == NULL || nh->h_last == NULL ||
nh->h_prev == NULL || nh->h_curr == NULL || nh->h_set == NULL ||
nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
nh->h_ref == NULL) {
nh->h_del == NULL || nh->h_ref == NULL) {
if (h->h_next != history_def_next) {
history_def_init(&h->h_ref, &ev, 0);
h->h_first = history_def_first;
@ -621,6 +645,7 @@ history_set_fun(History *h, History *nh)
h->h_clear = history_def_clear;
h->h_enter = history_def_enter;
h->h_add = history_def_add;
h->h_del = history_def_del;
}
return (-1);
}
@ -637,6 +662,7 @@ history_set_fun(History *h, History *nh)
h->h_clear = nh->h_clear;
h->h_enter = nh->h_enter;
h->h_add = nh->h_add;
h->h_del = nh->h_del;
return (0);
}
@ -853,6 +879,10 @@ history(History *h, HistEvent *ev, int fun, ...)
retval = HADD(h, ev, str);
break;
case H_DEL:
retval = HDEL(h, ev, va_arg(va, const int));
break;
case H_ENTER:
str = va_arg(va, const char *);
if ((retval = HENTER(h, ev, str)) != -1)
@ -937,6 +967,7 @@ history(History *h, HistEvent *ev, int fun, ...)
hf.h_clear = va_arg(va, history_vfun_t);
hf.h_enter = va_arg(va, history_efun_t);
hf.h_add = va_arg(va, history_efun_t);
hf.h_del = va_arg(va, history_sfun_t);
if ((retval = history_set_fun(h, &hf)) == -1)
he_seterrev(ev, _HE_PARAM_MISSING);

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.c,v 1.57 2005/06/11 18:18:59 christos Exp $ */
/* $NetBSD: readline.c,v 1.58 2005/07/14 15:00:58 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -38,7 +38,7 @@
#include "config.h"
#if !defined(lint) && !defined(SCCSID)
__RCSID("$NetBSD: readline.c,v 1.57 2005/06/11 18:18:59 christos Exp $");
__RCSID("$NetBSD: readline.c,v 1.58 2005/07/14 15:00:58 christos Exp $");
#endif /* not lint && not SCCSID */
#include <sys/types.h>
@ -1158,6 +1158,28 @@ add_history(const char *line)
}
/*
* remove the specified entry from the history list and return it.
*/
HIST_ENTRY *
remove_history(int num)
{
static HIST_ENTRY she;
HistEvent ev;
if (h == NULL || e == NULL)
rl_initialize();
if (history(h, &ev, H_DEL, num) != 0)
return NULL;
she.line = ev.str;
she.data = NULL;
return &she;
}
/*
* clear the history list - delete all entries
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: readline.h,v 1.16 2005/06/11 18:18:59 christos Exp $ */
/* $NetBSD: readline.h,v 1.17 2005/07/14 15:00:58 christos Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@ -141,6 +141,7 @@ int history_is_stifled(void);
int where_history(void);
HIST_ENTRY *current_history(void);
HIST_ENTRY *history_get(int);
HIST_ENTRY *remove_history(int);
int history_total_bytes(void);
int history_set_pos(int);
HIST_ENTRY *previous_history(void);