histedit.h revision 84325
1173412Skevlo/* $FreeBSD: head/include/histedit.h 84325 2001-10-01 21:06:25Z obrien $ */
278344Sobrien/*	$NetBSD: histedit.h,v 1.15 2000/02/28 17:41:05 chopps Exp $	*/
378344Sobrien
478344Sobrien/*-
578344Sobrien * Copyright (c) 1992, 1993
678344Sobrien *	The Regents of the University of California.  All rights reserved.
778344Sobrien *
878344Sobrien * This code is derived from software contributed to Berkeley by
978344Sobrien * Christos Zoulas of Cornell University.
1078344Sobrien *
1178344Sobrien * Redistribution and use in source and binary forms, with or without
1278344Sobrien * modification, are permitted provided that the following conditions
1378344Sobrien * are met:
1478344Sobrien * 1. Redistributions of source code must retain the above copyright
1578344Sobrien *    notice, this list of conditions and the following disclaimer.
1678344Sobrien * 2. Redistributions in binary form must reproduce the above copyright
1778344Sobrien *    notice, this list of conditions and the following disclaimer in the
1878344Sobrien *    documentation and/or other materials provided with the distribution.
1978344Sobrien * 3. All advertising materials mentioning features or use of this software
2078344Sobrien *    must display the following acknowledgement:
2178344Sobrien *	This product includes software developed by the University of
2278344Sobrien *	California, Berkeley and its contributors.
2378344Sobrien * 4. Neither the name of the University nor the names of its contributors
2478344Sobrien *    may be used to endorse or promote products derived from this software
2578344Sobrien *    without specific prior written permission.
2678344Sobrien *
2778344Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2878344Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2978344Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3078344Sobrien * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3178344Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3278344Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3378344Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3478344Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3578344Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3678344Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3778344Sobrien * SUCH DAMAGE.
3878344Sobrien *
3978344Sobrien *	@(#)histedit.h	8.2 (Berkeley) 1/3/94
4078344Sobrien */
4178344Sobrien
4278344Sobrien/*
4378344Sobrien * histedit.h: Line editor and history interface.
4478344Sobrien */
4578344Sobrien#ifndef _h_editline
4678344Sobrien#define _h_editline
4778344Sobrien
4878344Sobrien#include <sys/types.h>
4978344Sobrien#include <stdio.h>
5078344Sobrien
5178344Sobrien/*
5278344Sobrien * ==== Editing ====
5378344Sobrien */
54173412Skevlotypedef struct editline EditLine;
5578344Sobrien
5678344Sobrien/*
5778344Sobrien * For user-defined function interface
5878344Sobrien */
5978344Sobrientypedef struct lineinfo {
6078344Sobrien    const char *buffer;
6178344Sobrien    const char *cursor;
6278344Sobrien    const char *lastchar;
6378344Sobrien} LineInfo;
6478344Sobrien
6578344Sobrien
6678344Sobrien/*
6778344Sobrien * EditLine editor function return codes.
6878344Sobrien * For user-defined function interface
6978344Sobrien */
7078344Sobrien#define	CC_NORM		0
7178344Sobrien#define	CC_NEWLINE	1
7278344Sobrien#define	CC_EOF		2
7378344Sobrien#define CC_ARGHACK	3
7478344Sobrien#define CC_REFRESH	4
7578344Sobrien#define	CC_CURSOR	5
7678344Sobrien#define	CC_ERROR	6
7778344Sobrien#define CC_FATAL	7
7878344Sobrien#define CC_REDISPLAY	8
7978344Sobrien#define	CC_REFRESH_BEEP	9
8078344Sobrien
8178344Sobrien/*
8278344Sobrien * Initialization, cleanup, and resetting
8378344Sobrien */
8478344SobrienEditLine	*el_init	__P((const char *, FILE *, FILE *, FILE *));
8578344Sobrienvoid		 el_reset	__P((EditLine *));
8678344Sobrienvoid		 el_end		__P((EditLine *));
8778344Sobrien
8878344Sobrien
8978344Sobrien/*
9078344Sobrien * Get a line, a character or push a string back in the input queue
9178344Sobrien */
9278344Sobrienconst char    *el_gets	__P((EditLine *, int *));
9378344Sobrienint		 el_getc	__P((EditLine *, char *));
9478344Sobrienvoid		 el_push	__P((EditLine *, const char *));
9578344Sobrien
9678344Sobrien/*
9778344Sobrien * Beep!
9878344Sobrien */
9978344Sobrienvoid		 el_beep(EditLine *);
10078344Sobrien
10178344Sobrien/*
10278344Sobrien * High level function internals control
10378344Sobrien * Parses argc, argv array and executes builtin editline commands
10478344Sobrien */
10578344Sobrienint		 el_parse	__P((EditLine *, int, char **));
10678344Sobrien
10778344Sobrien/*
10878344Sobrien * Low level editline access function
10978344Sobrien */
11078344Sobrienint 		 el_set		__P((EditLine *, int, ...));
11178344Sobrienint		 el_get		__P((EditLine *, int, void *));
11278344Sobrien
11378344Sobrien/*
11478344Sobrien * el_set/el_get parameters
11578344Sobrien */
11678344Sobrien#define EL_PROMPT	0	/* , el_pfunc_t);		*/
11778344Sobrien#define EL_TERMINAL	1	/* , const char *);		*/
11878344Sobrien#define EL_EDITOR	2	/* , const char *);		*/
11978344Sobrien#define EL_SIGNAL	3	/* , int);			*/
12078344Sobrien#define	EL_BIND		4	/* , const char *, ..., NULL);	*/
12178344Sobrien#define	EL_TELLTC	5	/* , const char *, ..., NULL);	*/
12278344Sobrien#define	EL_SETTC	6	/* , const char *, ..., NULL);	*/
12378344Sobrien#define	EL_ECHOTC	7	/* , const char *, ..., NULL);	*/
12478344Sobrien#define	EL_SETTY	8	/* , const char *, ..., NULL);	*/
125#define	EL_ADDFN	9	/* , const char *, const char *	*/
126				/* , el_func_t);		*/
127#define EL_HIST		10	/* , hist_fun_t, const char *);	*/
128#define	EL_EDITMODE	11	/* , int);			*/
129#define	EL_RPROMPT	12	/* , el_pfunc_t);		*/
130
131/*
132 * Source named file or $PWD/.editrc or $HOME/.editrc
133 */
134int		el_source	__P((EditLine *, const char *));
135
136/*
137 * Must be called when the terminal changes size; If EL_SIGNAL
138 * is set this is done automatically otherwise it is the responsibility
139 * of the application
140 */
141void		 el_resize	__P((EditLine *));
142
143
144/*
145 * User-defined function interface.
146 */
147const LineInfo *el_line	__P((EditLine *));
148int   		  el_insertstr	__P((EditLine *, const char *));
149void		  el_deletestr	__P((EditLine *, int));
150
151/*
152 * ==== History ====
153 */
154
155typedef struct history History;
156
157typedef struct HistEvent {
158    int 	  num;
159    const char *str;
160} HistEvent;
161
162/*
163 * History access functions.
164 */
165History *		history_init	__P((void));
166void 			history_end	__P((History *));
167
168int			history		__P((History *, HistEvent *, int, ...));
169
170#define H_FUNC		 0	/* , UTSL		*/
171#define	H_SETSIZE	 1	/* , const int);	*/
172#define H_EVENT		 1	/* , const int);	*/
173#define	H_GETSIZE	 2	/* , void);		*/
174#define	H_FIRST		 3	/* , void);		*/
175#define	H_LAST		 4	/* , void);		*/
176#define	H_PREV		 5	/* , void);		*/
177#define	H_NEXT		 6	/* , void);		*/
178#define	H_CURR		 8	/* , const int);	*/
179#define	H_SET		 7	/* , void);		*/
180#define	H_ADD		 9	/* , const char *);	*/
181#define	H_ENTER		10	/* , const char *);	*/
182#define	H_APPEND	11	/* , const char *);	*/
183#define	H_END		12	/* , void);		*/
184#define	H_NEXT_STR	13	/* , const char *);	*/
185#define	H_PREV_STR	14	/* , const char *);	*/
186#define	H_NEXT_EVENT	15	/* , const int);	*/
187#define	H_PREV_EVENT	16	/* , const int);	*/
188#define	H_LOAD		17	/* , const char *);	*/
189#define	H_SAVE		18	/* , const char *);	*/
190#define	H_CLEAR		19	/* , void);		*/
191
192#endif /* _h_editline */
193