histedit.h revision 170547
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.
16148834Sstefanf * 3. Neither the name of the University nor the names of its contributors
171841Swollman *    may be used to endorse or promote products derived from this software
181841Swollman *    without specific prior written permission.
191841Swollman *
201841Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211841Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221841Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231841Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241841Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251841Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261841Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271841Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281841Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291841Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301841Swollman * SUCH DAMAGE.
311841Swollman *
321841Swollman *	@(#)histedit.h	8.2 (Berkeley) 1/3/94
33170547Sstefanf *	$NetBSD: histedit.h,v 1.32 2007/06/10 20:20:28 christos Exp $
3484326Sobrien * $FreeBSD: head/include/histedit.h 170547 2007-06-11 06:25:19Z stefanf $
351841Swollman */
361841Swollman
371841Swollman/*
381841Swollman * histedit.h: Line editor and history interface.
391841Swollman */
4084326Sobrien#ifndef _HISTEDIT_H_
4184326Sobrien#define	_HISTEDIT_H_
421841Swollman
431841Swollman#include <sys/types.h>
441841Swollman#include <stdio.h>
451841Swollman
46117556Simp__BEGIN_DECLS
47117556Simp
481841Swollman/*
491841Swollman * ==== Editing ====
501841Swollman */
51148834Sstefanf
521841Swollmantypedef struct editline EditLine;
531841Swollman
541841Swollman/*
551841Swollman * For user-defined function interface
561841Swollman */
571841Swollmantypedef struct lineinfo {
5884326Sobrien	const char	*buffer;
5984326Sobrien	const char	*cursor;
6084326Sobrien	const char	*lastchar;
611841Swollman} LineInfo;
621841Swollman
631841Swollman/*
641841Swollman * EditLine editor function return codes.
651841Swollman * For user-defined function interface
661841Swollman */
671841Swollman#define	CC_NORM		0
681841Swollman#define	CC_NEWLINE	1
691841Swollman#define	CC_EOF		2
7084326Sobrien#define	CC_ARGHACK	3
7184326Sobrien#define	CC_REFRESH	4
721841Swollman#define	CC_CURSOR	5
731841Swollman#define	CC_ERROR	6
7484326Sobrien#define	CC_FATAL	7
7584326Sobrien#define	CC_REDISPLAY	8
7684325Sobrien#define	CC_REFRESH_BEEP	9
771841Swollman
781841Swollman/*
791841Swollman * Initialization, cleanup, and resetting
801841Swollman */
8184326SobrienEditLine	*el_init(const char *, FILE *, FILE *, FILE *);
82148834Sstefanfvoid		 el_end(EditLine *);
8384326Sobrienvoid		 el_reset(EditLine *);
841841Swollman
851841Swollman/*
861841Swollman * Get a line, a character or push a string back in the input queue
871841Swollman */
8884326Sobrienconst char	*el_gets(EditLine *, int *);
8984326Sobrienint		 el_getc(EditLine *, char *);
90148834Sstefanfvoid		 el_push(EditLine *, char *);
911841Swollman
921841Swollman/*
9384325Sobrien * Beep!
9484325Sobrien */
9584325Sobrienvoid		 el_beep(EditLine *);
9684325Sobrien
9784325Sobrien/*
981841Swollman * High level function internals control
991841Swollman * Parses argc, argv array and executes builtin editline commands
1001841Swollman */
101148834Sstefanfint		 el_parse(EditLine *, int, const char **);
1021841Swollman
1031841Swollman/*
10484326Sobrien * Low level editline access functions
1051841Swollman */
10684326Sobrienint		 el_set(EditLine *, int, ...);
107170511Sstefanfint		 el_get(EditLine *, int, ...);
108148834Sstefanf#if 0
109148834Sstefanfunsigned char	_el_fn_complete(EditLine *, int);
110148834Sstefanf#endif
1111841Swollman
1121841Swollman/*
1131841Swollman * el_set/el_get parameters
1141841Swollman */
11584326Sobrien#define	EL_PROMPT	0	/* , el_pfunc_t);		*/
11684326Sobrien#define	EL_TERMINAL	1	/* , const char *);		*/
11784326Sobrien#define	EL_EDITOR	2	/* , const char *);		*/
11884326Sobrien#define	EL_SIGNAL	3	/* , int);			*/
1191841Swollman#define	EL_BIND		4	/* , const char *, ..., NULL);	*/
1201841Swollman#define	EL_TELLTC	5	/* , const char *, ..., NULL);	*/
1211841Swollman#define	EL_SETTC	6	/* , const char *, ..., NULL);	*/
1221841Swollman#define	EL_ECHOTC	7	/* , const char *, ..., NULL);	*/
1231841Swollman#define	EL_SETTY	8	/* , const char *, ..., NULL);	*/
1241841Swollman#define	EL_ADDFN	9	/* , const char *, const char *	*/
1251841Swollman				/* , el_func_t);		*/
12684326Sobrien#define	EL_HIST		10	/* , hist_fun_t, const char *);	*/
12784325Sobrien#define	EL_EDITMODE	11	/* , int);			*/
12884325Sobrien#define	EL_RPROMPT	12	/* , el_pfunc_t);		*/
129148834Sstefanf#define	EL_GETCFN	13	/* , el_rfunc_t);		*/
130148834Sstefanf#define	EL_CLIENTDATA	14	/* , void *);			*/
131148834Sstefanf#define	EL_UNBUFFERED	15	/* , int);			*/
132148834Sstefanf#define	EL_PREP_TERM    16      /* , int);                      */
133170511Sstefanf#define	EL_GETTC	17	/* , const char *, ..., NULL);	*/
134170547Sstefanf#define	EL_GETFP	18	/* , int, FILE **)		*/
135170547Sstefanf#define	EL_SETFP	19	/* , int, FILE *)		*/
1361841Swollman
137170547Sstefanf#define	EL_BUILTIN_GETCFN	(NULL)
138148834Sstefanf
1391841Swollman/*
1401841Swollman * Source named file or $PWD/.editrc or $HOME/.editrc
1411841Swollman */
14284326Sobrienint		el_source(EditLine *, const char *);
1431841Swollman
1441841Swollman/*
1451841Swollman * Must be called when the terminal changes size; If EL_SIGNAL
1461841Swollman * is set this is done automatically otherwise it is the responsibility
1471841Swollman * of the application
1481841Swollman */
14984326Sobrienvoid		 el_resize(EditLine *);
1501841Swollman
1511841Swollman
1521841Swollman/*
15398293Smdodd * Set user private data.
15498293Smdodd */
15598293Smdoddvoid            el_data_set    __P((EditLine *, void *));
15698293Smdoddvoid *          el_data_get    __P((EditLine *));
15798293Smdodd
15898293Smdodd/*
1591841Swollman * User-defined function interface.
1601841Swollman */
16184326Sobrienconst LineInfo	*el_line(EditLine *);
16284326Sobrienint		 el_insertstr(EditLine *, const char *);
16384326Sobrienvoid		 el_deletestr(EditLine *, int);
1641841Swollman
165148834Sstefanf
1661841Swollman/*
1671841Swollman * ==== History ====
1681841Swollman */
1691841Swollman
1701841Swollmantypedef struct history History;
1711841Swollman
1721841Swollmantypedef struct HistEvent {
17384326Sobrien	int		 num;
17484326Sobrien	const char	*str;
1751841Swollman} HistEvent;
1761841Swollman
1771841Swollman/*
1781841Swollman * History access functions.
1791841Swollman */
18084326SobrienHistory *	history_init(void);
18184326Sobrienvoid		history_end(History *);
1821841Swollman
18384326Sobrienint		history(History *, HistEvent *, int, ...);
1841841Swollman
18584326Sobrien#define	H_FUNC		 0	/* , UTSL		*/
18684325Sobrien#define	H_SETSIZE	 1	/* , const int);	*/
187170547Sstefanf#define	H_EVENT		 1	/* , const int);	*/
18884325Sobrien#define	H_GETSIZE	 2	/* , void);		*/
18984325Sobrien#define	H_FIRST		 3	/* , void);		*/
19084325Sobrien#define	H_LAST		 4	/* , void);		*/
19184325Sobrien#define	H_PREV		 5	/* , void);		*/
19284325Sobrien#define	H_NEXT		 6	/* , void);		*/
19384325Sobrien#define	H_CURR		 8	/* , const int);	*/
194148834Sstefanf#define	H_SET		 7	/* , int);		*/
19584325Sobrien#define	H_ADD		 9	/* , const char *);	*/
19684325Sobrien#define	H_ENTER		10	/* , const char *);	*/
19784325Sobrien#define	H_APPEND	11	/* , const char *);	*/
19884325Sobrien#define	H_END		12	/* , void);		*/
19984325Sobrien#define	H_NEXT_STR	13	/* , const char *);	*/
20084325Sobrien#define	H_PREV_STR	14	/* , const char *);	*/
20184325Sobrien#define	H_NEXT_EVENT	15	/* , const int);	*/
20284325Sobrien#define	H_PREV_EVENT	16	/* , const int);	*/
20384325Sobrien#define	H_LOAD		17	/* , const char *);	*/
20484325Sobrien#define	H_SAVE		18	/* , const char *);	*/
20584325Sobrien#define	H_CLEAR		19	/* , void);		*/
206148834Sstefanf#define	H_SETUNIQUE	20	/* , int);		*/
207148834Sstefanf#define	H_GETUNIQUE	21	/* , void);		*/
208148834Sstefanf#define	H_DEL		22	/* , int);		*/
2091841Swollman
210148834Sstefanf
211148834Sstefanf/*
212148834Sstefanf * ==== Tokenization ====
213148834Sstefanf */
214148834Sstefanf
215148834Sstefanftypedef struct tokenizer Tokenizer;
216148834Sstefanf
217148834Sstefanf/*
218148834Sstefanf * String tokenization functions, using simplified sh(1) quoting rules
219148834Sstefanf */
220148834SstefanfTokenizer	*tok_init(const char *);
221148834Sstefanfvoid		 tok_end(Tokenizer *);
222148834Sstefanfvoid		 tok_reset(Tokenizer *);
223148834Sstefanfint		 tok_line(Tokenizer *, const LineInfo *,
224148834Sstefanf		    int *, const char ***, int *, int *);
225148834Sstefanfint		 tok_str(Tokenizer *, const char *,
226148834Sstefanf		    int *, const char ***);
227148834Sstefanf
228117556Simp__END_DECLS
229117556Simp
23084326Sobrien#endif /* _HISTEDIT_H_ */
231