xref: /openbsd-src/lib/libedit/histedit.h (revision db3296cf5c1dd9058ceecc3a29fe4aaa0bd26000)
1 /*	$OpenBSD: histedit.h,v 1.7 2003/06/02 20:18:40 millert Exp $	*/
2 /*	$NetBSD: histedit.h,v 1.5 1997/04/11 17:52:45 christos Exp $	*/
3 
4 /*-
5  * Copyright (c) 1992, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Christos Zoulas of Cornell University.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)histedit.h	8.2 (Berkeley) 1/3/94
36  */
37 
38 /*
39  * histedit.h: Line editor and history interface.
40  */
41 #ifndef _h_editline
42 #define _h_editline
43 
44 #include <sys/types.h>
45 #include <stdio.h>
46 
47 /*
48  * ==== Editing ====
49  */
50 typedef struct editline EditLine;
51 
52 /*
53  * For user-defined function interface
54  */
55 typedef struct lineinfo {
56     const char *buffer;
57     const char *cursor;
58     const char *lastchar;
59 } LineInfo;
60 
61 
62 /*
63  * EditLine editor function return codes.
64  * For user-defined function interface
65  */
66 #define	CC_NORM		0
67 #define	CC_NEWLINE	1
68 #define	CC_EOF		2
69 #define CC_ARGHACK	3
70 #define CC_REFRESH	4
71 #define	CC_CURSOR	5
72 #define	CC_ERROR	6
73 #define CC_FATAL	7
74 #define CC_REDISPLAY	8
75 
76 /*
77  * Initialization, cleanup, and resetting
78  */
79 EditLine	*el_init(const char *, FILE *, FILE *);
80 void		 el_reset(EditLine *);
81 void		 el_end(EditLine *);
82 
83 
84 /*
85  * Get a line, a character or push a string back in the input queue
86  */
87 const char	*el_gets(EditLine *, int *);
88 int		 el_getc(EditLine *, char *);
89 void		 el_push(EditLine *, const char *);
90 
91 /*
92  * High level function internals control
93  * Parses argc, argv array and executes builtin editline commands
94  */
95 int		 el_parse(EditLine *, int, char **);
96 
97 /*
98  * Low level editline access function
99  */
100 int 		 el_set(EditLine *, int, ...);
101 
102 /*
103  * el_set/el_get parameters
104  */
105 #define EL_PROMPT	0	/* , el_pfunc_t);		*/
106 #define EL_TERMINAL	1	/* , const char *);		*/
107 #define EL_EDITOR	2	/* , const char *);		*/
108 #define EL_SIGNAL	3	/* , int);			*/
109 #define	EL_BIND		4	/* , const char *, ..., NULL);	*/
110 #define	EL_TELLTC	5	/* , const char *, ..., NULL);	*/
111 #define	EL_SETTC	6	/* , const char *, ..., NULL);	*/
112 #define	EL_ECHOTC	7	/* , const char *, ..., NULL);	*/
113 #define	EL_SETTY	8	/* , const char *, ..., NULL);	*/
114 #define	EL_ADDFN	9	/* , const char *, const char *	*/
115 				/* , el_func_t);		*/
116 #define EL_HIST		10	/* , hist_fun_t, const char *);	*/
117 
118 /*
119  * Source named file or $PWD/.editrc or $HOME/.editrc
120  */
121 int		el_source(EditLine *, const char *);
122 
123 /*
124  * Must be called when the terminal changes size; If EL_SIGNAL
125  * is set this is done automatically otherwise it is the responsibility
126  * of the application
127  */
128 void		 el_resize(EditLine *);
129 
130 
131 /*
132  * User-defined function interface.
133  */
134 const LineInfo   *el_line(EditLine *);
135 int   		  el_insertstr(EditLine *, char *);
136 void		  el_deletestr(EditLine *, int);
137 
138 /*
139  * ==== History ====
140  */
141 
142 typedef struct history History;
143 
144 typedef struct HistEvent {
145     int 	  num;
146     const char   *str;
147 } HistEvent;
148 
149 /*
150  * History access functions.
151  */
152 History *		history_init(void);
153 void 			history_end(History *);
154 
155 const HistEvent *	history(History *, int, ...);
156 
157 #define H_FUNC		 0	/* , UTSL		*/
158 #define H_EVENT		 1	/* , const int);	*/
159 #define H_FIRST		 2	/* , void);		*/
160 #define H_LAST		 3	/* , void);		*/
161 #define H_PREV		 4	/* , void);		*/
162 #define H_NEXT		 5	/* , void);		*/
163 #define H_CURR		 6	/* , void);		*/
164 #define H_ADD		 7	/* , const char*);	*/
165 #define H_ENTER		 8	/* , const char*);	*/
166 #define H_END		 9	/* , void);		*/
167 #define H_NEXT_STR	10	/* , const char*);	*/
168 #define H_PREV_STR	11	/* , const char*);	*/
169 #define H_NEXT_EVENT	12	/* , const int);	*/
170 #define H_PREV_EVENT	13	/* , const int);	*/
171 #define H_LOAD		14	/* , const char *);	*/
172 #define H_SAVE		15	/* , const char *);	*/
173 #define H_CLEAR		16	/* , void);		*/
174 
175 #endif /* _h_editline */
176