1998-12-12 22:52:51 +03:00
|
|
|
/* $NetBSD: history.c,v 1.11 1998/12/12 19:52:51 christos Exp $ */
|
1997-01-11 09:47:47 +03:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Christos Zoulas of Cornell University.
|
|
|
|
*
|
|
|
|
* 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 University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
|
|
|
|
*/
|
|
|
|
|
1997-07-06 22:25:21 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-05-06 10:01:42 +04:00
|
|
|
#if !defined(lint) && !defined(SCCSID)
|
1997-07-06 22:25:21 +04:00
|
|
|
#if 0
|
1994-05-06 10:01:42 +04:00
|
|
|
static char sccsid[] = "@(#)history.c 8.1 (Berkeley) 6/4/93";
|
1997-07-06 22:25:21 +04:00
|
|
|
#else
|
1998-12-12 22:52:51 +03:00
|
|
|
__RCSID("$NetBSD: history.c,v 1.11 1998/12/12 19:52:51 christos Exp $");
|
1997-07-06 22:25:21 +04:00
|
|
|
#endif
|
1994-05-06 10:01:42 +04:00
|
|
|
#endif /* not lint && not SCCSID */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hist.c: History access functions
|
|
|
|
*/
|
|
|
|
#include "sys.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
1997-04-11 21:52:44 +04:00
|
|
|
#ifdef __STDC__
|
1994-05-06 10:01:42 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
|
|
|
#endif
|
|
|
|
|
1995-10-15 22:42:05 +03:00
|
|
|
static const char hist_cookie[] = "_HiStOrY_V1_\n";
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
#include "histedit.h"
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
typedef int (*history_gfun_t) __P((ptr_t, HistEvent *));
|
|
|
|
typedef int (*history_efun_t) __P((ptr_t, HistEvent *, const char *));
|
|
|
|
typedef void (*history_vfun_t) __P((ptr_t, HistEvent *));
|
1998-05-20 05:02:38 +04:00
|
|
|
typedef int (*history_sfun_t) __P((ptr_t, HistEvent *, const int));
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
struct history {
|
|
|
|
ptr_t h_ref; /* Argument for history fcns */
|
1998-05-20 05:37:54 +04:00
|
|
|
int h_ent; /* Last entry point for history */
|
1994-05-06 10:01:42 +04:00
|
|
|
history_gfun_t h_first; /* Get the first element */
|
|
|
|
history_gfun_t h_next; /* Get the next element */
|
|
|
|
history_gfun_t h_last; /* Get the last element */
|
|
|
|
history_gfun_t h_prev; /* Get the previous element */
|
|
|
|
history_gfun_t h_curr; /* Get the current element */
|
1998-05-20 05:02:38 +04:00
|
|
|
history_sfun_t h_set; /* Set the current element */
|
1995-10-15 22:42:05 +03:00
|
|
|
history_vfun_t h_clear; /* Clear the history list */
|
1994-05-06 10:01:42 +04:00
|
|
|
history_efun_t h_enter; /* Add an element */
|
|
|
|
history_efun_t h_add; /* Append to an element */
|
|
|
|
};
|
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
#define HNEXT(h, ev) (*(h)->h_next)((h)->h_ref, ev)
|
|
|
|
#define HFIRST(h, ev) (*(h)->h_first)((h)->h_ref, ev)
|
|
|
|
#define HPREV(h, ev) (*(h)->h_prev)((h)->h_ref, ev)
|
|
|
|
#define HLAST(h, ev) (*(h)->h_last)((h)->h_ref, ev)
|
|
|
|
#define HCURR(h, ev) (*(h)->h_curr)((h)->h_ref, ev)
|
|
|
|
#define HSET(h, ev, n) (*(h)->h_set)((h)->h_ref, ev, n)
|
|
|
|
#define HCLEAR(h, ev) (*(h)->h_clear)((h)->h_ref, ev)
|
1997-10-14 19:05:49 +04:00
|
|
|
#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)
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
#define h_malloc(a) malloc(a)
|
|
|
|
#define h_free(a) free(a)
|
|
|
|
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
private int history_set_num __P((History *, HistEvent *, int));
|
|
|
|
private int history_get_size __P((History *, HistEvent *));
|
|
|
|
private int history_set_fun __P((History *, History *));
|
|
|
|
private int history_load __P((History *, const char *));
|
|
|
|
private int history_save __P((History *, const char *));
|
|
|
|
private int history_prev_event __P((History *, HistEvent *, int));
|
|
|
|
private int history_next_event __P((History *, HistEvent *, int));
|
|
|
|
private int history_next_string __P((History *, HistEvent *, const char *));
|
|
|
|
private int history_prev_string __P((History *, HistEvent *, const char *));
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Builtin- history implementation
|
|
|
|
*/
|
|
|
|
typedef struct hentry_t {
|
|
|
|
HistEvent ev; /* What we return */
|
|
|
|
struct hentry_t *next; /* Next entry */
|
|
|
|
struct hentry_t *prev; /* Previous entry */
|
|
|
|
} hentry_t;
|
|
|
|
|
|
|
|
typedef struct history_t {
|
|
|
|
hentry_t list; /* Fake list header element */
|
|
|
|
hentry_t *cursor; /* Current element in the list */
|
|
|
|
int max; /* Maximum number of events */
|
|
|
|
int cur; /* Current number of events */
|
1997-10-14 19:05:49 +04:00
|
|
|
int eventid; /* For generation of unique event id */
|
1994-05-06 10:01:42 +04:00
|
|
|
} history_t;
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
private int history_def_first __P((ptr_t, HistEvent *));
|
|
|
|
private int history_def_last __P((ptr_t, HistEvent *));
|
|
|
|
private int history_def_next __P((ptr_t, HistEvent *));
|
|
|
|
private int history_def_prev __P((ptr_t, HistEvent *));
|
|
|
|
private int history_def_curr __P((ptr_t, HistEvent *));
|
1998-05-20 05:02:38 +04:00
|
|
|
private int history_def_set __P((ptr_t, HistEvent *, const int n));
|
1997-10-14 19:05:49 +04:00
|
|
|
private int history_def_enter __P((ptr_t, HistEvent *, const char *));
|
|
|
|
private int history_def_add __P((ptr_t, HistEvent *, const char *));
|
|
|
|
private void history_def_init __P((ptr_t *, HistEvent *, int));
|
|
|
|
private void history_def_clear __P((ptr_t, HistEvent *));
|
|
|
|
private int history_def_insert __P((history_t *, HistEvent *,const char *));
|
|
|
|
private void history_def_delete __P((history_t *, HistEvent *, hentry_t *));
|
1994-05-06 10:01:42 +04:00
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
#define history_def_setsize(p, num)(void) (((history_t *) p)->max = (num))
|
1997-10-14 19:05:49 +04:00
|
|
|
#define history_def_getsize(p) (((history_t *) p)->cur)
|
|
|
|
|
|
|
|
#define he_strerror(code) he_errlist[code]
|
|
|
|
#define he_seterrev(evp, code) {\
|
|
|
|
evp->num = code;\
|
|
|
|
evp->str = he_strerror(code);\
|
|
|
|
}
|
|
|
|
|
|
|
|
/* error messages */
|
|
|
|
static const char *const he_errlist[] = {
|
1998-05-20 05:02:38 +04:00
|
|
|
"OK",
|
1998-12-12 22:52:51 +03:00
|
|
|
"unknown error"
|
1998-05-20 05:02:38 +04:00
|
|
|
"malloc() failed",
|
|
|
|
"first event not found",
|
|
|
|
"last event not found",
|
|
|
|
"empty list",
|
|
|
|
"no next event",
|
|
|
|
"no previous event",
|
|
|
|
"current event is invalid",
|
|
|
|
"event not found",
|
|
|
|
"can't read history from file",
|
|
|
|
"can't write history",
|
|
|
|
"required parameter(s) not supplied",
|
|
|
|
"history size negative",
|
|
|
|
"function not allowed with other history-functions-set the default",
|
|
|
|
"bad parameters"
|
1997-10-14 19:05:49 +04:00
|
|
|
};
|
1994-05-06 10:01:42 +04:00
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
/* error codes */
|
|
|
|
#define _HE_OK 0
|
|
|
|
#define _HE_UNKNOWN 1
|
|
|
|
#define _HE_MALLOC_FAILED 2
|
|
|
|
#define _HE_FIRST_NOTFOUND 3
|
|
|
|
#define _HE_LAST_NOTFOUND 4
|
|
|
|
#define _HE_EMPTY_LIST 5
|
|
|
|
#define _HE_END_REACHED 6
|
|
|
|
#define _HE_START_REACHED 7
|
|
|
|
#define _HE_CURR_INVALID 8
|
|
|
|
#define _HE_NOT_FOUND 9
|
|
|
|
#define _HE_HIST_READ 10
|
|
|
|
#define _HE_HIST_WRITE 11
|
|
|
|
#define _HE_PARAM_MISSING 12
|
|
|
|
#define _HE_SIZE_NEGATIVE 13
|
|
|
|
#define _HE_NOT_ALLOWED 14
|
|
|
|
#define _HE_BAD_PARAM 15
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
/* history_def_first():
|
|
|
|
* Default function to return the first event in the history.
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_first(p, ev)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
1997-10-14 19:05:49 +04:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
h->cursor = h->list.next;
|
|
|
|
if (h->cursor != &h->list)
|
1997-10-14 19:05:49 +04:00
|
|
|
*ev = h->cursor->ev;
|
|
|
|
else {
|
|
|
|
he_seterrev(ev, _HE_FIRST_NOTFOUND);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/* history_def_last():
|
|
|
|
* Default function to return the last event in the history.
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_last(p, ev)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
1997-10-14 19:05:49 +04:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
h->cursor = h->list.prev;
|
|
|
|
if (h->cursor != &h->list)
|
1997-10-14 19:05:49 +04:00
|
|
|
*ev = h->cursor->ev;
|
|
|
|
else {
|
|
|
|
he_seterrev(ev, _HE_LAST_NOTFOUND);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/* history_def_next():
|
|
|
|
* Default function to return the next event in the history.
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_next(p, ev)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
|
|
|
|
|
|
|
if (h->cursor != &h->list)
|
|
|
|
h->cursor = h->cursor->next;
|
1997-10-14 19:05:49 +04:00
|
|
|
else {
|
|
|
|
he_seterrev(ev, _HE_EMPTY_LIST);
|
|
|
|
return -1;
|
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
if (h->cursor != &h->list)
|
1997-10-14 19:05:49 +04:00
|
|
|
*ev = h->cursor->ev;
|
|
|
|
else {
|
|
|
|
he_seterrev(ev, _HE_END_REACHED);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_def_prev():
|
|
|
|
* Default function to return the previous event in the history.
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_prev(p, ev)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1998-05-20 05:02:38 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
|
|
|
|
|
|
|
if (h->cursor != &h->list)
|
|
|
|
h->cursor = h->cursor->prev;
|
1997-10-14 19:05:49 +04:00
|
|
|
else {
|
|
|
|
he_seterrev(ev, (h->cur > 0) ? _HE_END_REACHED : _HE_EMPTY_LIST);
|
|
|
|
return -1;
|
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
if (h->cursor != &h->list)
|
1997-10-14 19:05:49 +04:00
|
|
|
*ev = h->cursor->ev;
|
|
|
|
else {
|
|
|
|
he_seterrev(ev, _HE_START_REACHED);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_def_curr():
|
|
|
|
* Default function to return the current event in the history.
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_curr(p, ev)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1998-05-20 05:02:38 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
|
|
|
|
|
|
|
if (h->cursor != &h->list)
|
1997-10-14 19:05:49 +04:00
|
|
|
*ev = h->cursor->ev;
|
|
|
|
else {
|
|
|
|
he_seterrev(ev, (h->cur > 0) ? _HE_CURR_INVALID : _HE_EMPTY_LIST);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
|
|
|
|
/* history_def_set():
|
|
|
|
* Default function to set the current event in the history to the
|
|
|
|
* given one.
|
|
|
|
*/
|
|
|
|
private int
|
|
|
|
history_def_set(p, ev, n)
|
|
|
|
ptr_t p;
|
|
|
|
HistEvent *ev;
|
|
|
|
int n;
|
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
|
|
|
|
|
|
|
if (h->cur == 0) {
|
|
|
|
he_seterrev(ev, _HE_EMPTY_LIST);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->cursor == &h->list || h->cursor->ev.num != n) {
|
|
|
|
for (h->cursor = h->list.next; h->cursor != &h->list;
|
|
|
|
h->cursor = h->cursor->next)
|
|
|
|
if (h->cursor->ev.num == n)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->cursor == &h->list) {
|
|
|
|
he_seterrev(ev, _HE_NOT_FOUND);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/* history_def_add():
|
|
|
|
* Append string to element
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_add(p, ev, str)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
|
|
|
size_t len;
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
if (h->cursor == &h->list)
|
1997-10-14 19:05:49 +04:00
|
|
|
return (history_def_enter(p, ev, str));
|
1994-05-06 10:01:42 +04:00
|
|
|
len = strlen(h->cursor->ev.str) + strlen(str) + 1;
|
|
|
|
s = (char *) h_malloc(len);
|
1997-10-14 19:05:49 +04:00
|
|
|
if (!s) {
|
|
|
|
he_seterrev(ev, _HE_MALLOC_FAILED);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
(void)strcpy(s, h->cursor->ev.str); /* XXX strcpy is safe */
|
1997-01-23 17:01:45 +03:00
|
|
|
(void)strcat(s, str); /* XXX strcat is safe */
|
1998-12-12 22:52:51 +03:00
|
|
|
/* LINTED const cast */
|
1994-05-06 10:01:42 +04:00
|
|
|
h_free((ptr_t) h->cursor->ev.str);
|
|
|
|
h->cursor->ev.str = s;
|
1997-10-14 19:05:49 +04:00
|
|
|
*ev = h->cursor->ev;
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_def_delete():
|
|
|
|
* Delete element hp of the h list
|
|
|
|
*/
|
1998-12-12 22:52:51 +03:00
|
|
|
/* ARGSUSED */
|
1994-05-06 10:01:42 +04:00
|
|
|
private void
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_delete(h, ev, hp)
|
1994-05-06 10:01:42 +04:00
|
|
|
history_t *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
hentry_t *hp;
|
|
|
|
{
|
|
|
|
if (hp == &h->list)
|
|
|
|
abort();
|
|
|
|
hp->prev->next = hp->next;
|
|
|
|
hp->next->prev = hp->prev;
|
1998-12-12 22:52:51 +03:00
|
|
|
/* LINTED const cast */
|
1994-05-06 10:01:42 +04:00
|
|
|
h_free((ptr_t) hp->ev.str);
|
|
|
|
h_free(hp);
|
|
|
|
h->cur--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_def_insert():
|
|
|
|
* Insert element with string str in the h list
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_insert(h, ev, str)
|
1994-05-06 10:01:42 +04:00
|
|
|
history_t *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
h->cursor = (hentry_t *) h_malloc(sizeof(hentry_t));
|
1997-10-14 19:05:49 +04:00
|
|
|
if (h->cursor)
|
|
|
|
h->cursor->ev.str = strdup(str);
|
|
|
|
if (!h->cursor || !h->cursor->ev.str) {
|
|
|
|
he_seterrev(ev, _HE_MALLOC_FAILED);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
h->cursor->ev.num = ++h->eventid;
|
1994-05-06 10:01:42 +04:00
|
|
|
h->cursor->next = h->list.next;
|
|
|
|
h->cursor->prev = &h->list;
|
|
|
|
h->list.next->prev = h->cursor;
|
|
|
|
h->list.next = h->cursor;
|
|
|
|
h->cur++;
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
*ev = h->cursor->ev;
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_def_enter():
|
|
|
|
* Default function to enter an item in the history
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_def_enter(p, ev, str)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
const char *str;
|
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
if (history_def_insert(h, ev, str) == -1)
|
|
|
|
return -1; /* error, keep error message */
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Always keep at least one entry.
|
|
|
|
* This way we don't have to check for the empty list.
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
while (h->cur - 1 > h->max)
|
|
|
|
history_def_delete(h, ev, h->list.prev);
|
|
|
|
|
|
|
|
return 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_def_init():
|
|
|
|
* Default history initialization function
|
|
|
|
*/
|
1998-12-12 22:52:51 +03:00
|
|
|
/* ARGSUSED */
|
1994-05-06 10:01:42 +04:00
|
|
|
private void
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_init(p, ev, n)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t *p;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
int n;
|
|
|
|
{
|
|
|
|
history_t *h = (history_t *) h_malloc(sizeof(history_t));
|
|
|
|
if (n <= 0)
|
|
|
|
n = 0;
|
1997-10-14 19:05:49 +04:00
|
|
|
h->eventid = 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
h->cur = 0;
|
|
|
|
h->max = n;
|
|
|
|
h->list.next = h->list.prev = &h->list;
|
|
|
|
h->list.ev.str = NULL;
|
|
|
|
h->list.ev.num = 0;
|
|
|
|
h->cursor = &h->list;
|
|
|
|
*p = (ptr_t) h;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-15 22:42:05 +03:00
|
|
|
/* history_def_clear():
|
1994-05-06 10:01:42 +04:00
|
|
|
* Default history cleanup function
|
|
|
|
*/
|
|
|
|
private void
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_clear(p, ev)
|
1994-05-06 10:01:42 +04:00
|
|
|
ptr_t p;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
|
|
|
history_t *h = (history_t *) p;
|
|
|
|
|
|
|
|
while (h->list.prev != &h->list)
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_delete(h, ev, h->list.prev);
|
|
|
|
h->eventid = 0;
|
1995-10-15 22:42:05 +03:00
|
|
|
h->cur = 0;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
1995-10-15 22:42:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
/* history_init():
|
|
|
|
* Initialization function.
|
|
|
|
*/
|
|
|
|
public History *
|
|
|
|
history_init()
|
|
|
|
{
|
|
|
|
History *h = (History *) h_malloc(sizeof(History));
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_init(&h->h_ref, &ev, 0);
|
1998-05-20 05:37:54 +04:00
|
|
|
h->h_ent = -1;
|
1994-05-06 10:01:42 +04:00
|
|
|
h->h_next = history_def_next;
|
|
|
|
h->h_first = history_def_first;
|
|
|
|
h->h_last = history_def_last;
|
|
|
|
h->h_prev = history_def_prev;
|
|
|
|
h->h_curr = history_def_curr;
|
1998-05-20 05:02:38 +04:00
|
|
|
h->h_set = history_def_set;
|
1995-10-15 22:42:05 +03:00
|
|
|
h->h_clear = history_def_clear;
|
1994-05-06 10:01:42 +04:00
|
|
|
h->h_enter = history_def_enter;
|
|
|
|
h->h_add = history_def_add;
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_end():
|
|
|
|
* clean up history;
|
|
|
|
*/
|
|
|
|
public void
|
|
|
|
history_end(h)
|
|
|
|
History *h;
|
|
|
|
{
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
if (h->h_next == history_def_next)
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_clear(h->h_ref, &ev);
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* history_set_num():
|
|
|
|
* Set history number of events
|
|
|
|
*/
|
|
|
|
private int
|
1997-10-14 19:05:49 +04:00
|
|
|
history_set_num(h, ev, num)
|
1994-05-06 10:01:42 +04:00
|
|
|
History *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
int num;
|
|
|
|
{
|
1997-10-14 19:05:49 +04:00
|
|
|
if (h->h_next != history_def_next) {
|
|
|
|
he_seterrev(ev, _HE_NOT_ALLOWED);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num < 0) {
|
|
|
|
he_seterrev(ev, _HE_BAD_PARAM);
|
1994-05-06 10:01:42 +04:00
|
|
|
return -1;
|
1997-10-14 19:05:49 +04:00
|
|
|
}
|
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
history_def_setsize(h->h_ref, num);
|
1994-05-06 10:01:42 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
/* history_get_size():
|
|
|
|
* Get number of events currently in history
|
|
|
|
*/
|
|
|
|
private int
|
|
|
|
history_get_size(h, ev)
|
|
|
|
History *h;
|
|
|
|
HistEvent *ev;
|
|
|
|
{
|
|
|
|
int retval=0;
|
|
|
|
|
|
|
|
if (h->h_next != history_def_next) {
|
|
|
|
he_seterrev(ev, _HE_NOT_ALLOWED);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
retval = history_def_getsize(h->h_ref);
|
|
|
|
if (retval < -1) {
|
|
|
|
he_seterrev(ev, _HE_SIZE_NEGATIVE);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev->num = retval;
|
|
|
|
return 0;
|
|
|
|
}
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
/* history_set_fun():
|
|
|
|
* Set history functions
|
|
|
|
*/
|
|
|
|
private int
|
1995-10-15 22:42:05 +03:00
|
|
|
history_set_fun(h, nh)
|
1997-10-14 19:05:49 +04:00
|
|
|
History *h;
|
|
|
|
History *nh;
|
1994-05-06 10:01:42 +04:00
|
|
|
{
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent ev;
|
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
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 ||
|
1995-10-15 22:42:05 +03:00
|
|
|
nh->h_enter == NULL || nh->h_add == NULL || nh->h_clear == NULL ||
|
|
|
|
nh->h_ref == NULL) {
|
1994-05-06 10:01:42 +04:00
|
|
|
if (h->h_next != history_def_next) {
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_init(&h->h_ref, &ev, 0);
|
1994-05-06 10:01:42 +04:00
|
|
|
h->h_first = history_def_first;
|
|
|
|
h->h_next = history_def_next;
|
|
|
|
h->h_last = history_def_last;
|
|
|
|
h->h_prev = history_def_prev;
|
|
|
|
h->h_curr = history_def_curr;
|
1998-05-20 05:02:38 +04:00
|
|
|
h->h_set = history_def_set;
|
1995-10-15 22:42:05 +03:00
|
|
|
h->h_clear = history_def_clear;
|
1994-05-06 10:01:42 +04:00
|
|
|
h->h_enter = history_def_enter;
|
|
|
|
h->h_add = history_def_add;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h->h_next == history_def_next)
|
1997-10-14 19:05:49 +04:00
|
|
|
history_def_clear(h->h_ref, &ev);
|
1995-10-15 22:42:05 +03:00
|
|
|
|
1998-05-20 05:37:54 +04:00
|
|
|
h->h_ent = -1;
|
1995-10-15 22:42:05 +03:00
|
|
|
h->h_first = nh->h_first;
|
|
|
|
h->h_next = nh->h_next;
|
|
|
|
h->h_last = nh->h_last;
|
|
|
|
h->h_prev = nh->h_prev;
|
|
|
|
h->h_curr = nh->h_curr;
|
1998-05-20 05:02:38 +04:00
|
|
|
h->h_set = nh->h_set;
|
1995-10-15 22:42:05 +03:00
|
|
|
h->h_clear = nh->h_clear;
|
|
|
|
h->h_enter = nh->h_enter;
|
|
|
|
h->h_add = nh->h_add;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-15 22:42:05 +03:00
|
|
|
/* history_load():
|
|
|
|
* History load function
|
|
|
|
*/
|
|
|
|
private int
|
|
|
|
history_load(h, fname)
|
|
|
|
History *h;
|
|
|
|
const char *fname;
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char *line;
|
|
|
|
size_t sz;
|
|
|
|
int i = -1;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent ev;
|
1995-10-15 22:42:05 +03:00
|
|
|
|
|
|
|
if ((fp = fopen(fname, "r")) == NULL)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
if ((line = fgetln(fp, &sz)) == NULL)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (strncmp(line, hist_cookie, sz) != 0)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
for (i = 0; (line = fgetln(fp, &sz)) != NULL; i++) {
|
|
|
|
char c = line[sz];
|
|
|
|
line[sz] = '\0';
|
1997-10-14 19:05:49 +04:00
|
|
|
HENTER(h, &ev, line);
|
1995-10-15 22:42:05 +03:00
|
|
|
line[sz] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
(void) fclose(fp);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_save():
|
|
|
|
* History save function
|
|
|
|
*/
|
|
|
|
private int
|
|
|
|
history_save(h, fname)
|
|
|
|
History *h;
|
|
|
|
const char *fname;
|
|
|
|
{
|
|
|
|
FILE *fp;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent ev;
|
|
|
|
int i = 0, retval;
|
1995-10-15 22:42:05 +03:00
|
|
|
|
|
|
|
if ((fp = fopen(fname, "w")) == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
(void) fputs(hist_cookie, fp);
|
1997-10-14 19:05:49 +04:00
|
|
|
for (retval = HLAST(h, &ev); retval != -1; retval = HPREV(h, &ev), i++)
|
|
|
|
(void) fprintf(fp, "%s", ev.str);
|
1995-10-15 22:42:05 +03:00
|
|
|
(void) fclose(fp);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/* history_prev_event():
|
|
|
|
* Find the previous event, with number given
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_prev_event(h, ev, num)
|
1994-05-06 10:01:42 +04:00
|
|
|
History *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
int num;
|
|
|
|
{
|
1997-10-14 19:05:49 +04:00
|
|
|
int retval;
|
|
|
|
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
|
1994-05-06 10:01:42 +04:00
|
|
|
if (ev->num == num)
|
1997-10-14 19:05:49 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
he_seterrev(ev, _HE_NOT_FOUND);
|
|
|
|
return -1;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_next_event():
|
|
|
|
* Find the next event, with number given
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_next_event(h, ev, num)
|
1994-05-06 10:01:42 +04:00
|
|
|
History *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
int num;
|
|
|
|
{
|
1997-10-14 19:05:49 +04:00
|
|
|
int retval;
|
|
|
|
for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
|
1994-05-06 10:01:42 +04:00
|
|
|
if (ev->num == num)
|
1997-10-14 19:05:49 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
he_seterrev(ev, _HE_NOT_FOUND);
|
1998-12-03 20:51:16 +03:00
|
|
|
return -1;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history_prev_string():
|
|
|
|
* Find the previous event beginning with string
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_prev_string(h, ev, str)
|
1994-05-06 10:01:42 +04:00
|
|
|
History *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
const char* str;
|
|
|
|
{
|
|
|
|
size_t len = strlen(str);
|
1997-10-14 19:05:49 +04:00
|
|
|
int retval;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
for (retval = HCURR(h, ev); retval != -1; retval = HNEXT(h, ev))
|
1994-05-06 10:01:42 +04:00
|
|
|
if (strncmp(str, ev->str, len) == 0)
|
1997-10-14 19:05:49 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
he_seterrev(ev, _HE_NOT_FOUND);
|
|
|
|
return -1;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-10-15 22:42:05 +03:00
|
|
|
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
/* history_next_string():
|
|
|
|
* Find the next event beginning with string
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
private int
|
|
|
|
history_next_string(h, ev, str)
|
1994-05-06 10:01:42 +04:00
|
|
|
History *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
const char* str;
|
|
|
|
{
|
|
|
|
size_t len = strlen(str);
|
1997-10-14 19:05:49 +04:00
|
|
|
int retval;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
for (retval = HCURR(h, ev); retval != -1; retval = HPREV(h, ev))
|
1994-05-06 10:01:42 +04:00
|
|
|
if (strncmp(str, ev->str, len) == 0)
|
1997-10-14 19:05:49 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
he_seterrev(ev, _HE_NOT_FOUND);
|
|
|
|
return -1;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* history():
|
|
|
|
* User interface to history functions.
|
|
|
|
*/
|
1997-10-14 19:05:49 +04:00
|
|
|
int
|
1997-04-11 21:52:44 +04:00
|
|
|
#ifdef __STDC__
|
1997-10-14 19:05:49 +04:00
|
|
|
history(History *h, HistEvent *ev, int fun, ...)
|
1994-05-06 10:01:42 +04:00
|
|
|
#else
|
|
|
|
history(va_alist)
|
|
|
|
va_dcl
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
const char *str;
|
1997-10-14 19:05:49 +04:00
|
|
|
int retval;
|
1994-05-06 10:01:42 +04:00
|
|
|
|
1997-04-11 21:52:44 +04:00
|
|
|
#ifdef __STDC__
|
1994-05-06 10:01:42 +04:00
|
|
|
va_start(va, fun);
|
|
|
|
#else
|
|
|
|
History *h;
|
1997-10-14 19:05:49 +04:00
|
|
|
HistEvent *ev;
|
1994-05-06 10:01:42 +04:00
|
|
|
int fun;
|
|
|
|
va_start(va);
|
|
|
|
h = va_arg(va, History *);
|
1997-10-14 19:05:49 +04:00
|
|
|
ev = va_arg(va, HistEvent *);
|
1994-05-06 10:01:42 +04:00
|
|
|
fun = va_arg(va, int);
|
|
|
|
#endif
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
he_seterrev(ev, _HE_OK);
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
switch (fun) {
|
1998-05-20 05:02:38 +04:00
|
|
|
case H_GETSIZE:
|
|
|
|
retval = history_get_size(h, ev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case H_SETSIZE:
|
|
|
|
retval = history_set_num(h, ev, va_arg(va, int));
|
|
|
|
break;
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
case H_ADD:
|
|
|
|
str = va_arg(va, const char *);
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = HADD(h, ev, str);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_ENTER:
|
|
|
|
str = va_arg(va, const char *);
|
1998-05-20 05:37:54 +04:00
|
|
|
if ((retval = HENTER(h, ev, str)) != -1)
|
|
|
|
h->h_ent = ev->num;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case H_APPEND:
|
|
|
|
str = va_arg(va, const char *);
|
|
|
|
if ((retval = HSET(h, ev, h->h_ent)) != -1)
|
|
|
|
retval = HADD(h, ev, str);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_FIRST:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = HFIRST(h, ev);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_NEXT:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = HNEXT(h, ev);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_LAST:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = HLAST(h, ev);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_PREV:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = HPREV(h, ev);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_CURR:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = HCURR(h, ev);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
1998-05-20 05:02:38 +04:00
|
|
|
case H_SET:
|
|
|
|
retval = HSET(h, ev, va_arg(va, const int));
|
|
|
|
break;
|
|
|
|
|
1995-10-15 22:42:05 +03:00
|
|
|
case H_CLEAR:
|
1997-10-14 19:05:49 +04:00
|
|
|
HCLEAR(h, ev);
|
|
|
|
retval = 0;
|
1995-10-15 22:42:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_LOAD:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = history_load(h, va_arg(va, const char *));
|
|
|
|
if (retval == -1)
|
|
|
|
he_seterrev(ev, _HE_HIST_READ);
|
1995-10-15 22:42:05 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_SAVE:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = history_save(h, va_arg(va, const char *));
|
|
|
|
if (retval == -1)
|
|
|
|
he_seterrev(ev, _HE_HIST_WRITE);
|
1995-10-15 22:42:05 +03:00
|
|
|
break;
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
case H_PREV_EVENT:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = history_prev_event(h, ev, va_arg(va, int));
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_NEXT_EVENT:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = history_next_event(h, ev, va_arg(va, int));
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_PREV_STR:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = history_prev_string(h, ev, va_arg(va, const char*));
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_NEXT_STR:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = history_next_string(h, ev, va_arg(va, const char*));
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case H_FUNC:
|
|
|
|
{
|
1995-10-15 22:42:05 +03:00
|
|
|
History hf;
|
1998-05-20 05:02:38 +04:00
|
|
|
|
1995-10-15 22:42:05 +03:00
|
|
|
hf.h_ref = va_arg(va, ptr_t);
|
1998-05-20 05:37:54 +04:00
|
|
|
h->h_ent = -1;
|
1995-10-15 22:42:05 +03:00
|
|
|
hf.h_first = va_arg(va, history_gfun_t);
|
|
|
|
hf.h_next = va_arg(va, history_gfun_t);
|
|
|
|
hf.h_last = va_arg(va, history_gfun_t);
|
|
|
|
hf.h_prev = va_arg(va, history_gfun_t);
|
|
|
|
hf.h_curr = va_arg(va, history_gfun_t);
|
1998-05-20 05:02:38 +04:00
|
|
|
hf.h_set = va_arg(va, history_sfun_t);
|
1995-10-15 22:42:05 +03:00
|
|
|
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);
|
|
|
|
|
1997-10-14 19:05:49 +04:00
|
|
|
if ((retval = history_set_fun(h, &hf)) == -1)
|
|
|
|
he_seterrev(ev, _HE_PARAM_MISSING);
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case H_END:
|
|
|
|
history_end(h);
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = 0;
|
|
|
|
break;
|
|
|
|
|
1994-05-06 10:01:42 +04:00
|
|
|
default:
|
1997-10-14 19:05:49 +04:00
|
|
|
retval = -1;
|
|
|
|
he_seterrev(ev, _HE_UNKNOWN);
|
1994-05-06 10:01:42 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
va_end(va);
|
1997-10-14 19:05:49 +04:00
|
|
|
return retval;
|
1994-05-06 10:01:42 +04:00
|
|
|
}
|