xref: /dflybsd-src/contrib/libedit/src/hist.h (revision 32fe07f89d87adfc65eebe9f2812a999af20d10f)
1*32fe07f8SJohn Marino /*	$NetBSD: hist.h,v 1.13 2011/07/28 20:50:55 christos Exp $	*/
2*32fe07f8SJohn Marino 
3*32fe07f8SJohn Marino /*-
4*32fe07f8SJohn Marino  * Copyright (c) 1992, 1993
5*32fe07f8SJohn Marino  *	The Regents of the University of California.  All rights reserved.
6*32fe07f8SJohn Marino  *
7*32fe07f8SJohn Marino  * This code is derived from software contributed to Berkeley by
8*32fe07f8SJohn Marino  * Christos Zoulas of Cornell University.
9*32fe07f8SJohn Marino  *
10*32fe07f8SJohn Marino  * Redistribution and use in source and binary forms, with or without
11*32fe07f8SJohn Marino  * modification, are permitted provided that the following conditions
12*32fe07f8SJohn Marino  * are met:
13*32fe07f8SJohn Marino  * 1. Redistributions of source code must retain the above copyright
14*32fe07f8SJohn Marino  *    notice, this list of conditions and the following disclaimer.
15*32fe07f8SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
16*32fe07f8SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
17*32fe07f8SJohn Marino  *    documentation and/or other materials provided with the distribution.
18*32fe07f8SJohn Marino  * 3. Neither the name of the University nor the names of its contributors
19*32fe07f8SJohn Marino  *    may be used to endorse or promote products derived from this software
20*32fe07f8SJohn Marino  *    without specific prior written permission.
21*32fe07f8SJohn Marino  *
22*32fe07f8SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*32fe07f8SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*32fe07f8SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*32fe07f8SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*32fe07f8SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*32fe07f8SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*32fe07f8SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*32fe07f8SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*32fe07f8SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*32fe07f8SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*32fe07f8SJohn Marino  * SUCH DAMAGE.
33*32fe07f8SJohn Marino  *
34*32fe07f8SJohn Marino  *	@(#)hist.h	8.1 (Berkeley) 6/4/93
35*32fe07f8SJohn Marino  */
36*32fe07f8SJohn Marino 
37*32fe07f8SJohn Marino /*
38*32fe07f8SJohn Marino  * el.hist.c: History functions
39*32fe07f8SJohn Marino  */
40*32fe07f8SJohn Marino #ifndef _h_el_hist
41*32fe07f8SJohn Marino #define	_h_el_hist
42*32fe07f8SJohn Marino 
43*32fe07f8SJohn Marino #include "histedit.h"
44*32fe07f8SJohn Marino 
45*32fe07f8SJohn Marino typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
46*32fe07f8SJohn Marino 
47*32fe07f8SJohn Marino typedef struct el_history_t {
48*32fe07f8SJohn Marino 	Char		*buf;		/* The history buffer		*/
49*32fe07f8SJohn Marino 	size_t		sz;		/* Size of history buffer	*/
50*32fe07f8SJohn Marino 	Char		*last;		/* The last character		*/
51*32fe07f8SJohn Marino 	int		 eventno;	/* Event we are looking for	*/
52*32fe07f8SJohn Marino 	void *		 ref;		/* Argument for history fcns	*/
53*32fe07f8SJohn Marino 	hist_fun_t	 fun;		/* Event access			*/
54*32fe07f8SJohn Marino 	TYPE(HistEvent)	 ev;		/* Event cookie			*/
55*32fe07f8SJohn Marino } el_history_t;
56*32fe07f8SJohn Marino 
57*32fe07f8SJohn Marino #define	HIST_FUN_INTERNAL(el, fn, arg)	\
58*32fe07f8SJohn Marino     ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
59*32fe07f8SJohn Marino 	fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
60*32fe07f8SJohn Marino #ifdef WIDECHAR
61*32fe07f8SJohn Marino #define HIST_FUN(el, fn, arg) \
62*32fe07f8SJohn Marino     (((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \
63*32fe07f8SJohn Marino 	HIST_FUN_INTERNAL(el, fn, arg))
64*32fe07f8SJohn Marino #else
65*32fe07f8SJohn Marino #define HIST_FUN(el, fn, arg) HIST_FUN_INTERNAL(el, fn, arg)
66*32fe07f8SJohn Marino #endif
67*32fe07f8SJohn Marino 
68*32fe07f8SJohn Marino 
69*32fe07f8SJohn Marino #define	HIST_NEXT(el)		HIST_FUN(el, H_NEXT, NULL)
70*32fe07f8SJohn Marino #define	HIST_FIRST(el)		HIST_FUN(el, H_FIRST, NULL)
71*32fe07f8SJohn Marino #define	HIST_LAST(el)		HIST_FUN(el, H_LAST, NULL)
72*32fe07f8SJohn Marino #define	HIST_PREV(el)		HIST_FUN(el, H_PREV, NULL)
73*32fe07f8SJohn Marino #define	HIST_SET(el, num)	HIST_FUN(el, H_SET, num)
74*32fe07f8SJohn Marino #define	HIST_LOAD(el, fname)	HIST_FUN(el, H_LOAD fname)
75*32fe07f8SJohn Marino #define	HIST_SAVE(el, fname)	HIST_FUN(el, H_SAVE fname)
76*32fe07f8SJohn Marino 
77*32fe07f8SJohn Marino protected int		hist_init(EditLine *);
78*32fe07f8SJohn Marino protected void		hist_end(EditLine *);
79*32fe07f8SJohn Marino protected el_action_t	hist_get(EditLine *);
80*32fe07f8SJohn Marino protected int		hist_set(EditLine *, hist_fun_t, void *);
81*32fe07f8SJohn Marino protected int		hist_command(EditLine *, int, const Char **);
82*32fe07f8SJohn Marino protected int		hist_enlargebuf(EditLine *, size_t, size_t);
83*32fe07f8SJohn Marino #ifdef WIDECHAR
84*32fe07f8SJohn Marino protected wchar_t 	*hist_convert(EditLine *, int, void *);
85*32fe07f8SJohn Marino #endif
86*32fe07f8SJohn Marino 
87*32fe07f8SJohn Marino #endif /* _h_el_hist */
88