histedit.h revision 117556
11841Swollman/*-
21841Swollman * Copyright (c) 1992, 1993
31841Swollman *	The Regents of the University of California.  All rights reserved.
41841Swollman *
51841Swollman * This code is derived from software contributed to Berkeley by
61841Swollman * Christos Zoulas of Cornell University.
71841Swollman *
81841Swollman * Redistribution and use in source and binary forms, with or without
91841Swollman * modification, are permitted provided that the following conditions
101841Swollman * are met:
111841Swollman * 1. Redistributions of source code must retain the above copyright
121841Swollman *    notice, this list of conditions and the following disclaimer.
131841Swollman * 2. Redistributions in binary form must reproduce the above copyright
141841Swollman *    notice, this list of conditions and the following disclaimer in the
151841Swollman *    documentation and/or other materials provided with the distribution.
161841Swollman * 3. All advertising materials mentioning features or use of this software
171841Swollman *    must display the following acknowledgement:
181841Swollman *	This product includes software developed by the University of
191841Swollman *	California, Berkeley and its contributors.
201841Swollman * 4. Neither the name of the University nor the names of its contributors
211841Swollman *    may be used to endorse or promote products derived from this software
221841Swollman *    without specific prior written permission.
231841Swollman *
241841Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251841Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261841Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271841Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281841Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291841Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301841Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311841Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321841Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331841Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341841Swollman * SUCH DAMAGE.
351841Swollman *
361841Swollman *	@(#)histedit.h	8.2 (Berkeley) 1/3/94
3784326Sobrien *	$NetBSD: histedit.h,v 1.15 2000/02/28 17:41:05 chopps Exp $
3884326Sobrien * $FreeBSD: head/include/histedit.h 117556 2003-07-14 16:31:20Z imp $
391841Swollman */
401841Swollman
411841Swollman/*
421841Swollman * histedit.h: Line editor and history interface.
431841Swollman */
4484326Sobrien#ifndef _HISTEDIT_H_
4584326Sobrien#define	_HISTEDIT_H_
461841Swollman
471841Swollman#include <sys/types.h>
481841Swollman#include <stdio.h>
491841Swollman
50117556Simp__BEGIN_DECLS
51117556Simp
521841Swollman/*
531841Swollman * ==== Editing ====
541841Swollman */
551841Swollmantypedef struct editline EditLine;
561841Swollman
571841Swollman/*
581841Swollman * For user-defined function interface
591841Swollman */
601841Swollmantypedef struct lineinfo {
6184326Sobrien	const char	*buffer;
6284326Sobrien	const char	*cursor;
6384326Sobrien	const char	*lastchar;
641841Swollman} LineInfo;
651841Swollman
661841Swollman
671841Swollman/*
681841Swollman * EditLine editor function return codes.
691841Swollman * For user-defined function interface
701841Swollman */
711841Swollman#define	CC_NORM		0
721841Swollman#define	CC_NEWLINE	1
731841Swollman#define	CC_EOF		2
7484326Sobrien#define	CC_ARGHACK	3
7584326Sobrien#define	CC_REFRESH	4
761841Swollman#define	CC_CURSOR	5
771841Swollman#define	CC_ERROR	6
7884326Sobrien#define	CC_FATAL	7
7984326Sobrien#define	CC_REDISPLAY	8
8084325Sobrien#define	CC_REFRESH_BEEP	9
811841Swollman
821841Swollman/*
831841Swollman * Initialization, cleanup, and resetting
841841Swollman */
8584326SobrienEditLine	*el_init(const char *, FILE *, FILE *, FILE *);
8684326Sobrienvoid		 el_reset(EditLine *);
8784326Sobrienvoid		 el_end(EditLine *);
881841Swollman
891841Swollman
901841Swollman/*
911841Swollman * Get a line, a character or push a string back in the input queue
921841Swollman */
9384326Sobrienconst char	*el_gets(EditLine *, int *);
9484326Sobrienint		 el_getc(EditLine *, char *);
9584326Sobrienvoid		 el_push(EditLine *, const char *);
961841Swollman
971841Swollman/*
9884325Sobrien * Beep!
9984325Sobrien */
10084325Sobrienvoid		 el_beep(EditLine *);
10184325Sobrien
10284325Sobrien/*
1031841Swollman * High level function internals control
1041841Swollman * Parses argc, argv array and executes builtin editline commands
1051841Swollman */
10684326Sobrienint		 el_parse(EditLine *, int, char **);
1071841Swollman
1081841Swollman/*
10984326Sobrien * Low level editline access functions
1101841Swollman */
11184326Sobrienint		 el_set(EditLine *, int, ...);
11284326Sobrienint		 el_get(EditLine *, int, void *);
1131841Swollman
1141841Swollman/*
1151841Swollman * el_set/el_get parameters
1161841Swollman */
11784326Sobrien#define	EL_PROMPT	0	/* , el_pfunc_t);		*/
11884326Sobrien#define	EL_TERMINAL	1	/* , const char *);		*/
11984326Sobrien#define	EL_EDITOR	2	/* , const char *);		*/
12084326Sobrien#define	EL_SIGNAL	3	/* , int);			*/
1211841Swollman#define	EL_BIND		4	/* , const char *, ..., NULL);	*/
1221841Swollman#define	EL_TELLTC	5	/* , const char *, ..., NULL);	*/
1231841Swollman#define	EL_SETTC	6	/* , const char *, ..., NULL);	*/
1241841Swollman#define	EL_ECHOTC	7	/* , const char *, ..., NULL);	*/
1251841Swollman#define	EL_SETTY	8	/* , const char *, ..., NULL);	*/
1261841Swollman#define	EL_ADDFN	9	/* , const char *, const char *	*/
1271841Swollman				/* , el_func_t);		*/
12884326Sobrien#define	EL_HIST		10	/* , hist_fun_t, const char *);	*/
12984325Sobrien#define	EL_EDITMODE	11	/* , int);			*/
13084325Sobrien#define	EL_RPROMPT	12	/* , el_pfunc_t);		*/
1311841Swollman
1321841Swollman/*
1331841Swollman * Source named file or $PWD/.editrc or $HOME/.editrc
1341841Swollman */
13584326Sobrienint		el_source(EditLine *, const char *);
1361841Swollman
1371841Swollman/*
1381841Swollman * Must be called when the terminal changes size; If EL_SIGNAL
1391841Swollman * is set this is done automatically otherwise it is the responsibility
1401841Swollman * of the application
1411841Swollman */
14284326Sobrienvoid		 el_resize(EditLine *);
1431841Swollman
1441841Swollman
1451841Swollman/*
14698293Smdodd * Set user private data.
14798293Smdodd */
14898293Smdoddvoid            el_data_set    __P((EditLine *, void *));
14998293Smdoddvoid *          el_data_get    __P((EditLine *));
15098293Smdodd
15198293Smdodd/*
1521841Swollman * User-defined function interface.
1531841Swollman */
15484326Sobrienconst LineInfo	*el_line(EditLine *);
15584326Sobrienint		 el_insertstr(EditLine *, const char *);
15684326Sobrienvoid		 el_deletestr(EditLine *, int);
1571841Swollman
1581841Swollman/*
1591841Swollman * ==== History ====
1601841Swollman */
1611841Swollman
1621841Swollmantypedef struct history History;
1631841Swollman
1641841Swollmantypedef struct HistEvent {
16584326Sobrien	int		 num;
16684326Sobrien	const char	*str;
1671841Swollman} HistEvent;
1681841Swollman
1691841Swollman/*
1701841Swollman * History access functions.
1711841Swollman */
17284326SobrienHistory *	history_init(void);
17384326Sobrienvoid		history_end(History *);
1741841Swollman
17584326Sobrienint		history(History *, HistEvent *, int, ...);
1761841Swollman
17784326Sobrien#define	H_FUNC		 0	/* , UTSL		*/
17884325Sobrien#define	H_SETSIZE	 1	/* , const int);	*/
1791841Swollman#define H_EVENT		 1	/* , const int);	*/
18084325Sobrien#define	H_GETSIZE	 2	/* , void);		*/
18184325Sobrien#define	H_FIRST		 3	/* , void);		*/
18284325Sobrien#define	H_LAST		 4	/* , void);		*/
18384325Sobrien#define	H_PREV		 5	/* , void);		*/
18484325Sobrien#define	H_NEXT		 6	/* , void);		*/
18584325Sobrien#define	H_CURR		 8	/* , const int);	*/
18684325Sobrien#define	H_SET		 7	/* , void);		*/
18784325Sobrien#define	H_ADD		 9	/* , const char *);	*/
18884325Sobrien#define	H_ENTER		10	/* , const char *);	*/
18984325Sobrien#define	H_APPEND	11	/* , const char *);	*/
19084325Sobrien#define	H_END		12	/* , void);		*/
19184325Sobrien#define	H_NEXT_STR	13	/* , const char *);	*/
19284325Sobrien#define	H_PREV_STR	14	/* , const char *);	*/
19384325Sobrien#define	H_NEXT_EVENT	15	/* , const int);	*/
19484325Sobrien#define	H_PREV_EVENT	16	/* , const int);	*/
19584325Sobrien#define	H_LOAD		17	/* , const char *);	*/
19684325Sobrien#define	H_SAVE		18	/* , const char *);	*/
19784325Sobrien#define	H_CLEAR		19	/* , void);		*/
1981841Swollman
199117556Simp__END_DECLS
200117556Simp
20184326Sobrien#endif /* _HISTEDIT_H_ */
202