xref: /minix3/lib/libedit/hist.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: hist.h,v 1.14 2014/05/11 01:05:17 christos Exp $	*/
23e1db26aSLionel Sambuc 
33e1db26aSLionel Sambuc /*-
43e1db26aSLionel Sambuc  * Copyright (c) 1992, 1993
53e1db26aSLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
63e1db26aSLionel Sambuc  *
73e1db26aSLionel Sambuc  * This code is derived from software contributed to Berkeley by
83e1db26aSLionel Sambuc  * Christos Zoulas of Cornell University.
93e1db26aSLionel Sambuc  *
103e1db26aSLionel Sambuc  * Redistribution and use in source and binary forms, with or without
113e1db26aSLionel Sambuc  * modification, are permitted provided that the following conditions
123e1db26aSLionel Sambuc  * are met:
133e1db26aSLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
143e1db26aSLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
153e1db26aSLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
163e1db26aSLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
173e1db26aSLionel Sambuc  *    documentation and/or other materials provided with the distribution.
183e1db26aSLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
193e1db26aSLionel Sambuc  *    may be used to endorse or promote products derived from this software
203e1db26aSLionel Sambuc  *    without specific prior written permission.
213e1db26aSLionel Sambuc  *
223e1db26aSLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233e1db26aSLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243e1db26aSLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253e1db26aSLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263e1db26aSLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273e1db26aSLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283e1db26aSLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293e1db26aSLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303e1db26aSLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313e1db26aSLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323e1db26aSLionel Sambuc  * SUCH DAMAGE.
333e1db26aSLionel Sambuc  *
343e1db26aSLionel Sambuc  *	@(#)hist.h	8.1 (Berkeley) 6/4/93
353e1db26aSLionel Sambuc  */
363e1db26aSLionel Sambuc 
373e1db26aSLionel Sambuc /*
383e1db26aSLionel Sambuc  * el.hist.c: History functions
393e1db26aSLionel Sambuc  */
403e1db26aSLionel Sambuc #ifndef _h_el_hist
413e1db26aSLionel Sambuc #define	_h_el_hist
423e1db26aSLionel Sambuc 
433e1db26aSLionel Sambuc #include "histedit.h"
443e1db26aSLionel Sambuc 
453e1db26aSLionel Sambuc typedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
463e1db26aSLionel Sambuc 
473e1db26aSLionel Sambuc typedef struct el_history_t {
483e1db26aSLionel Sambuc 	Char		*buf;		/* The history buffer		*/
493e1db26aSLionel Sambuc 	size_t		sz;		/* Size of history buffer	*/
503e1db26aSLionel Sambuc 	Char		*last;		/* The last character		*/
513e1db26aSLionel Sambuc 	int		 eventno;	/* Event we are looking for	*/
523e1db26aSLionel Sambuc 	void *		 ref;		/* Argument for history fcns	*/
533e1db26aSLionel Sambuc 	hist_fun_t	 fun;		/* Event access			*/
543e1db26aSLionel Sambuc 	TYPE(HistEvent)	 ev;		/* Event cookie			*/
553e1db26aSLionel Sambuc } el_history_t;
563e1db26aSLionel Sambuc 
573e1db26aSLionel Sambuc #define	HIST_FUN_INTERNAL(el, fn, arg)	\
583e1db26aSLionel Sambuc     ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
593e1db26aSLionel Sambuc 	fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
603e1db26aSLionel Sambuc #ifdef WIDECHAR
613e1db26aSLionel Sambuc #define HIST_FUN(el, fn, arg) \
623e1db26aSLionel Sambuc     (((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \
633e1db26aSLionel Sambuc 	HIST_FUN_INTERNAL(el, fn, arg))
643e1db26aSLionel Sambuc #else
653e1db26aSLionel Sambuc #define HIST_FUN(el, fn, arg) HIST_FUN_INTERNAL(el, fn, arg)
663e1db26aSLionel Sambuc #endif
673e1db26aSLionel Sambuc 
683e1db26aSLionel Sambuc 
693e1db26aSLionel Sambuc #define	HIST_NEXT(el)		HIST_FUN(el, H_NEXT, NULL)
703e1db26aSLionel Sambuc #define	HIST_FIRST(el)		HIST_FUN(el, H_FIRST, NULL)
713e1db26aSLionel Sambuc #define	HIST_LAST(el)		HIST_FUN(el, H_LAST, NULL)
723e1db26aSLionel Sambuc #define	HIST_PREV(el)		HIST_FUN(el, H_PREV, NULL)
733e1db26aSLionel Sambuc #define	HIST_SET(el, num)	HIST_FUN(el, H_SET, num)
743e1db26aSLionel Sambuc #define	HIST_LOAD(el, fname)	HIST_FUN(el, H_LOAD fname)
753e1db26aSLionel Sambuc #define	HIST_SAVE(el, fname)	HIST_FUN(el, H_SAVE fname)
76*0a6a1f1dSLionel Sambuc #define	HIST_SAVE_FP(el, fp)	HIST_FUN(el, H_SAVE_FP fp)
773e1db26aSLionel Sambuc 
783e1db26aSLionel Sambuc protected int		hist_init(EditLine *);
793e1db26aSLionel Sambuc protected void		hist_end(EditLine *);
803e1db26aSLionel Sambuc protected el_action_t	hist_get(EditLine *);
813e1db26aSLionel Sambuc protected int		hist_set(EditLine *, hist_fun_t, void *);
823e1db26aSLionel Sambuc protected int		hist_command(EditLine *, int, const Char **);
833e1db26aSLionel Sambuc protected int		hist_enlargebuf(EditLine *, size_t, size_t);
843e1db26aSLionel Sambuc #ifdef WIDECHAR
853e1db26aSLionel Sambuc protected wchar_t 	*hist_convert(EditLine *, int, void *);
863e1db26aSLionel Sambuc #endif
873e1db26aSLionel Sambuc 
883e1db26aSLionel Sambuc #endif /* _h_el_hist */
89