hist.h revision 276881
1276881Sbapt/*	$NetBSD: hist.h,v 1.14 2014/05/11 01:05:17 christos Exp $	*/
2276881Sbapt
31573Srgrimes/*-
41573Srgrimes * Copyright (c) 1992, 1993
51573Srgrimes *	The Regents of the University of California.  All rights reserved.
61573Srgrimes *
71573Srgrimes * This code is derived from software contributed to Berkeley by
81573Srgrimes * Christos Zoulas of Cornell University.
91573Srgrimes *
101573Srgrimes * Redistribution and use in source and binary forms, with or without
111573Srgrimes * modification, are permitted provided that the following conditions
121573Srgrimes * are met:
131573Srgrimes * 1. Redistributions of source code must retain the above copyright
141573Srgrimes *    notice, this list of conditions and the following disclaimer.
151573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
161573Srgrimes *    notice, this list of conditions and the following disclaimer in the
171573Srgrimes *    documentation and/or other materials provided with the distribution.
18148834Sstefanf * 3. Neither the name of the University nor the names of its contributors
191573Srgrimes *    may be used to endorse or promote products derived from this software
201573Srgrimes *    without specific prior written permission.
211573Srgrimes *
221573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321573Srgrimes * SUCH DAMAGE.
331573Srgrimes *
341573Srgrimes *	@(#)hist.h	8.1 (Berkeley) 6/4/93
3584260Sobrien * $FreeBSD: head/lib/libedit/hist.h 276881 2015-01-09 07:40:56Z bapt $
361573Srgrimes */
371573Srgrimes
381573Srgrimes/*
391573Srgrimes * el.hist.c: History functions
401573Srgrimes */
411573Srgrimes#ifndef _h_el_hist
4284260Sobrien#define	_h_el_hist
431573Srgrimes
441573Srgrimes#include "histedit.h"
451573Srgrimes
46276881Sbapttypedef int (*hist_fun_t)(void *, TYPE(HistEvent) *, int, ...);
471573Srgrimes
481573Srgrimestypedef struct el_history_t {
49276881Sbapt	Char		*buf;		/* The history buffer		*/
5084260Sobrien	size_t		sz;		/* Size of history buffer	*/
51276881Sbapt	Char		*last;		/* The last character		*/
5284260Sobrien	int		 eventno;	/* Event we are looking for	*/
53276881Sbapt	void *		 ref;		/* Argument for history fcns	*/
5484260Sobrien	hist_fun_t	 fun;		/* Event access			*/
55276881Sbapt	TYPE(HistEvent)	 ev;		/* Event cookie			*/
561573Srgrimes} el_history_t;
571573Srgrimes
58276881Sbapt#define	HIST_FUN_INTERNAL(el, fn, arg)	\
5984260Sobrien    ((((*(el)->el_history.fun) ((el)->el_history.ref, &(el)->el_history.ev, \
6084260Sobrien	fn, arg)) == -1) ? NULL : (el)->el_history.ev.str)
61276881Sbapt#ifdef WIDECHAR
62276881Sbapt#define HIST_FUN(el, fn, arg) \
63276881Sbapt    (((el)->el_flags & NARROW_HISTORY) ? hist_convert(el, fn, arg) : \
64276881Sbapt	HIST_FUN_INTERNAL(el, fn, arg))
65276881Sbapt#else
66276881Sbapt#define HIST_FUN(el, fn, arg) HIST_FUN_INTERNAL(el, fn, arg)
67276881Sbapt#endif
681573Srgrimes
69276881Sbapt
701573Srgrimes#define	HIST_NEXT(el)		HIST_FUN(el, H_NEXT, NULL)
711573Srgrimes#define	HIST_FIRST(el)		HIST_FUN(el, H_FIRST, NULL)
721573Srgrimes#define	HIST_LAST(el)		HIST_FUN(el, H_LAST, NULL)
731573Srgrimes#define	HIST_PREV(el)		HIST_FUN(el, H_PREV, NULL)
74148834Sstefanf#define	HIST_SET(el, num)	HIST_FUN(el, H_SET, num)
7584260Sobrien#define	HIST_LOAD(el, fname)	HIST_FUN(el, H_LOAD fname)
7684260Sobrien#define	HIST_SAVE(el, fname)	HIST_FUN(el, H_SAVE fname)
77265863Seadler#define	HIST_SAVE_FP(el, fp)	HIST_FUN(el, H_SAVE_FP fp)
781573Srgrimes
7984260Sobrienprotected int		hist_init(EditLine *);
8084260Sobrienprotected void		hist_end(EditLine *);
8184260Sobrienprotected el_action_t	hist_get(EditLine *);
82276881Sbaptprotected int		hist_set(EditLine *, hist_fun_t, void *);
83276881Sbaptprotected int		hist_command(EditLine *, int, const Char **);
8484260Sobrienprotected int		hist_enlargebuf(EditLine *, size_t, size_t);
85276881Sbapt#ifdef WIDECHAR
86276881Sbaptprotected wchar_t 	*hist_convert(EditLine *, int, void *);
87276881Sbapt#endif
881573Srgrimes
891573Srgrimes#endif /* _h_el_hist */
90