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$
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
47220370Sobrien#ifdef __cplusplus
48220370Sobrienextern "C" {
49220370Sobrien#endif
50117556Simp
511841Swollman/*
521841Swollman * ==== Editing ====
531841Swollman */
54148834Sstefanf
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 * EditLine editor function return codes.
681841Swollman * For user-defined function interface
691841Swollman */
701841Swollman#define	CC_NORM		0
711841Swollman#define	CC_NEWLINE	1
721841Swollman#define	CC_EOF		2
7384326Sobrien#define	CC_ARGHACK	3
7484326Sobrien#define	CC_REFRESH	4
751841Swollman#define	CC_CURSOR	5
761841Swollman#define	CC_ERROR	6
7784326Sobrien#define	CC_FATAL	7
7884326Sobrien#define	CC_REDISPLAY	8
7984325Sobrien#define	CC_REFRESH_BEEP	9
801841Swollman
811841Swollman/*
821841Swollman * Initialization, cleanup, and resetting
831841Swollman */
8484326SobrienEditLine	*el_init(const char *, FILE *, FILE *, FILE *);
85148834Sstefanfvoid		 el_end(EditLine *);
8684326Sobrienvoid		 el_reset(EditLine *);
871841Swollman
881841Swollman/*
891841Swollman * Get a line, a character or push a string back in the input queue
901841Swollman */
9184326Sobrienconst char	*el_gets(EditLine *, int *);
9284326Sobrienint		 el_getc(EditLine *, char *);
93220370Sobrienvoid		 el_push(EditLine *, const char *);
941841Swollman
951841Swollman/*
9684325Sobrien * Beep!
9784325Sobrien */
9884325Sobrienvoid		 el_beep(EditLine *);
9984325Sobrien
10084325Sobrien/*
1011841Swollman * High level function internals control
1021841Swollman * Parses argc, argv array and executes builtin editline commands
1031841Swollman */
104148834Sstefanfint		 el_parse(EditLine *, int, const char **);
1051841Swollman
1061841Swollman/*
10784326Sobrien * Low level editline access functions
1081841Swollman */
10984326Sobrienint		 el_set(EditLine *, int, ...);
110170511Sstefanfint		 el_get(EditLine *, int, ...);
111148834Sstefanfunsigned char	_el_fn_complete(EditLine *, int);
112209219Sjillesunsigned char	_el_fn_sh_complete(EditLine *, int);
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);		*/
131148834Sstefanf#define	EL_GETCFN	13	/* , el_rfunc_t);		*/
132148834Sstefanf#define	EL_CLIENTDATA	14	/* , void *);			*/
133148834Sstefanf#define	EL_UNBUFFERED	15	/* , int);			*/
134237448Spfg#define	EL_PREP_TERM    16	/* , int);                      */
135170511Sstefanf#define	EL_GETTC	17	/* , const char *, ..., NULL);	*/
136237448Spfg#define	EL_GETFP	18	/* , int, FILE **);		*/
137237448Spfg#define	EL_SETFP	19	/* , int, FILE *);		*/
138220370Sobrien#define	EL_REFRESH	20	/* , void);			      set     */
139220370Sobrien#define	EL_PROMPT_ESC	21	/* , prompt_func, Char);	      set/get */
140220370Sobrien#define	EL_RPROMPT_ESC	22	/* , prompt_func, Char);	      set/get */
141220370Sobrien#define	EL_RESIZE	23	/* , el_zfunc_t, void *);	      set     */
1421841Swollman
143170547Sstefanf#define	EL_BUILTIN_GETCFN	(NULL)
144148834Sstefanf
1451841Swollman/*
1461841Swollman * Source named file or $PWD/.editrc or $HOME/.editrc
1471841Swollman */
14884326Sobrienint		el_source(EditLine *, const char *);
1491841Swollman
1501841Swollman/*
1511841Swollman * Must be called when the terminal changes size; If EL_SIGNAL
1521841Swollman * is set this is done automatically otherwise it is the responsibility
1531841Swollman * of the application
1541841Swollman */
15584326Sobrienvoid		 el_resize(EditLine *);
1561841Swollman
1571841Swollman/*
1581841Swollman * User-defined function interface.
1591841Swollman */
16084326Sobrienconst LineInfo	*el_line(EditLine *);
16184326Sobrienint		 el_insertstr(EditLine *, const char *);
16284326Sobrienvoid		 el_deletestr(EditLine *, int);
1631841Swollman
164148834Sstefanf
1651841Swollman/*
1661841Swollman * ==== History ====
1671841Swollman */
1681841Swollman
1691841Swollmantypedef struct history History;
1701841Swollman
1711841Swollmantypedef struct HistEvent {
17284326Sobrien	int		 num;
17384326Sobrien	const char	*str;
1741841Swollman} HistEvent;
1751841Swollman
1761841Swollman/*
1771841Swollman * History access functions.
1781841Swollman */
17984326SobrienHistory *	history_init(void);
18084326Sobrienvoid		history_end(History *);
1811841Swollman
18284326Sobrienint		history(History *, HistEvent *, int, ...);
1831841Swollman
18484326Sobrien#define	H_FUNC		 0	/* , UTSL		*/
18584325Sobrien#define	H_SETSIZE	 1	/* , const int);	*/
186170547Sstefanf#define	H_EVENT		 1	/* , const int);	*/
18784325Sobrien#define	H_GETSIZE	 2	/* , void);		*/
18884325Sobrien#define	H_FIRST		 3	/* , void);		*/
18984325Sobrien#define	H_LAST		 4	/* , void);		*/
19084325Sobrien#define	H_PREV		 5	/* , void);		*/
19184325Sobrien#define	H_NEXT		 6	/* , void);		*/
19284325Sobrien#define	H_CURR		 8	/* , const int);	*/
193148834Sstefanf#define	H_SET		 7	/* , int);		*/
19484325Sobrien#define	H_ADD		 9	/* , const char *);	*/
19584325Sobrien#define	H_ENTER		10	/* , const char *);	*/
19684325Sobrien#define	H_APPEND	11	/* , const char *);	*/
19784325Sobrien#define	H_END		12	/* , void);		*/
19884325Sobrien#define	H_NEXT_STR	13	/* , const char *);	*/
19984325Sobrien#define	H_PREV_STR	14	/* , const char *);	*/
20084325Sobrien#define	H_NEXT_EVENT	15	/* , const int);	*/
20184325Sobrien#define	H_PREV_EVENT	16	/* , const int);	*/
20284325Sobrien#define	H_LOAD		17	/* , const char *);	*/
20384325Sobrien#define	H_SAVE		18	/* , const char *);	*/
20484325Sobrien#define	H_CLEAR		19	/* , void);		*/
205148834Sstefanf#define	H_SETUNIQUE	20	/* , int);		*/
206148834Sstefanf#define	H_GETUNIQUE	21	/* , void);		*/
207148834Sstefanf#define	H_DEL		22	/* , int);		*/
208220370Sobrien#define	H_NEXT_EVDATA	23	/* , const int, histdata_t *);	*/
209220370Sobrien#define	H_DELDATA	24	/* , int, histdata_t *);*/
210220370Sobrien#define	H_REPLACE	25	/* , const char *, histdata_t);	*/
2111841Swollman
212148834Sstefanf
213148834Sstefanf/*
214148834Sstefanf * ==== Tokenization ====
215148834Sstefanf */
216148834Sstefanf
217148834Sstefanftypedef struct tokenizer Tokenizer;
218148834Sstefanf
219148834Sstefanf/*
220148834Sstefanf * String tokenization functions, using simplified sh(1) quoting rules
221148834Sstefanf */
222148834SstefanfTokenizer	*tok_init(const char *);
223148834Sstefanfvoid		 tok_end(Tokenizer *);
224148834Sstefanfvoid		 tok_reset(Tokenizer *);
225148834Sstefanfint		 tok_line(Tokenizer *, const LineInfo *,
226148834Sstefanf		    int *, const char ***, int *, int *);
227148834Sstefanfint		 tok_str(Tokenizer *, const char *,
228148834Sstefanf		    int *, const char ***);
229148834Sstefanf
230117556Simp__END_DECLS
231220370Sobrien#ifdef __cplusplus
232220370Sobrien}
233220370Sobrien#endif
234117556Simp
23584326Sobrien#endif /* _HISTEDIT_H_ */
236