jpayne@69
|
1 /* $NetBSD: histedit.h,v 1.62 2023/02/03 22:01:42 christos Exp $ */
|
jpayne@69
|
2
|
jpayne@69
|
3 /*-
|
jpayne@69
|
4 * Copyright (c) 1992, 1993
|
jpayne@69
|
5 * The Regents of the University of California. All rights reserved.
|
jpayne@69
|
6 *
|
jpayne@69
|
7 * This code is derived from software contributed to Berkeley by
|
jpayne@69
|
8 * Christos Zoulas of Cornell University.
|
jpayne@69
|
9 *
|
jpayne@69
|
10 * Redistribution and use in source and binary forms, with or without
|
jpayne@69
|
11 * modification, are permitted provided that the following conditions
|
jpayne@69
|
12 * are met:
|
jpayne@69
|
13 * 1. Redistributions of source code must retain the above copyright
|
jpayne@69
|
14 * notice, this list of conditions and the following disclaimer.
|
jpayne@69
|
15 * 2. Redistributions in binary form must reproduce the above copyright
|
jpayne@69
|
16 * notice, this list of conditions and the following disclaimer in the
|
jpayne@69
|
17 * documentation and/or other materials provided with the distribution.
|
jpayne@69
|
18 * 3. Neither the name of the University nor the names of its contributors
|
jpayne@69
|
19 * may be used to endorse or promote products derived from this software
|
jpayne@69
|
20 * without specific prior written permission.
|
jpayne@69
|
21 *
|
jpayne@69
|
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
jpayne@69
|
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
jpayne@69
|
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
jpayne@69
|
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
jpayne@69
|
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
jpayne@69
|
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
jpayne@69
|
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
jpayne@69
|
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
jpayne@69
|
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
jpayne@69
|
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
jpayne@69
|
32 * SUCH DAMAGE.
|
jpayne@69
|
33 *
|
jpayne@69
|
34 * @(#)histedit.h 8.2 (Berkeley) 1/3/94
|
jpayne@69
|
35 */
|
jpayne@69
|
36
|
jpayne@69
|
37 /*
|
jpayne@69
|
38 * histedit.h: Line editor and history interface.
|
jpayne@69
|
39 */
|
jpayne@69
|
40 #ifndef _HISTEDIT_H_
|
jpayne@69
|
41 #define _HISTEDIT_H_
|
jpayne@69
|
42
|
jpayne@69
|
43 #define LIBEDIT_MAJOR 2
|
jpayne@69
|
44 #define LIBEDIT_MINOR 11
|
jpayne@69
|
45
|
jpayne@69
|
46 #include <sys/types.h>
|
jpayne@69
|
47 #include <stdio.h>
|
jpayne@69
|
48
|
jpayne@69
|
49 #ifdef __cplusplus
|
jpayne@69
|
50 extern "C" {
|
jpayne@69
|
51 #endif
|
jpayne@69
|
52
|
jpayne@69
|
53 /*
|
jpayne@69
|
54 * ==== Editing ====
|
jpayne@69
|
55 */
|
jpayne@69
|
56
|
jpayne@69
|
57 typedef struct editline EditLine;
|
jpayne@69
|
58
|
jpayne@69
|
59 /*
|
jpayne@69
|
60 * For user-defined function interface
|
jpayne@69
|
61 */
|
jpayne@69
|
62 typedef struct lineinfo {
|
jpayne@69
|
63 const char *buffer;
|
jpayne@69
|
64 const char *cursor;
|
jpayne@69
|
65 const char *lastchar;
|
jpayne@69
|
66 } LineInfo;
|
jpayne@69
|
67
|
jpayne@69
|
68 /*
|
jpayne@69
|
69 * EditLine editor function return codes.
|
jpayne@69
|
70 * For user-defined function interface
|
jpayne@69
|
71 */
|
jpayne@69
|
72 #define CC_NORM 0
|
jpayne@69
|
73 #define CC_NEWLINE 1
|
jpayne@69
|
74 #define CC_EOF 2
|
jpayne@69
|
75 #define CC_ARGHACK 3
|
jpayne@69
|
76 #define CC_REFRESH 4
|
jpayne@69
|
77 #define CC_CURSOR 5
|
jpayne@69
|
78 #define CC_ERROR 6
|
jpayne@69
|
79 #define CC_FATAL 7
|
jpayne@69
|
80 #define CC_REDISPLAY 8
|
jpayne@69
|
81 #define CC_REFRESH_BEEP 9
|
jpayne@69
|
82
|
jpayne@69
|
83 /*
|
jpayne@69
|
84 * Initialization, cleanup, and resetting
|
jpayne@69
|
85 */
|
jpayne@69
|
86 EditLine *el_init(const char *, FILE *, FILE *, FILE *);
|
jpayne@69
|
87 EditLine *el_init_fd(const char *, FILE *, FILE *, FILE *,
|
jpayne@69
|
88 int, int, int);
|
jpayne@69
|
89 void el_end(EditLine *);
|
jpayne@69
|
90 void el_reset(EditLine *);
|
jpayne@69
|
91
|
jpayne@69
|
92 /*
|
jpayne@69
|
93 * Get a line, a character or push a string back in the input queue
|
jpayne@69
|
94 */
|
jpayne@69
|
95 const char *el_gets(EditLine *, int *);
|
jpayne@69
|
96 int el_getc(EditLine *, char *);
|
jpayne@69
|
97 void el_push(EditLine *, const char *);
|
jpayne@69
|
98
|
jpayne@69
|
99 /*
|
jpayne@69
|
100 * Beep!
|
jpayne@69
|
101 */
|
jpayne@69
|
102 void el_beep(EditLine *);
|
jpayne@69
|
103
|
jpayne@69
|
104 /*
|
jpayne@69
|
105 * High level function internals control
|
jpayne@69
|
106 * Parses argc, argv array and executes builtin editline commands
|
jpayne@69
|
107 */
|
jpayne@69
|
108 int el_parse(EditLine *, int, const char **);
|
jpayne@69
|
109
|
jpayne@69
|
110 /*
|
jpayne@69
|
111 * Low level editline access functions
|
jpayne@69
|
112 */
|
jpayne@69
|
113 int el_set(EditLine *, int, ...);
|
jpayne@69
|
114 int el_get(EditLine *, int, ...);
|
jpayne@69
|
115 unsigned char _el_fn_complete(EditLine *, int);
|
jpayne@69
|
116 unsigned char _el_fn_sh_complete(EditLine *, int);
|
jpayne@69
|
117
|
jpayne@69
|
118 /*
|
jpayne@69
|
119 * el_set/el_get parameters
|
jpayne@69
|
120 *
|
jpayne@69
|
121 * When using el_wset/el_wget (as opposed to el_set/el_get):
|
jpayne@69
|
122 * Char is wchar_t, otherwise it is char.
|
jpayne@69
|
123 * prompt_func is el_wpfunc_t, otherwise it is el_pfunc_t .
|
jpayne@69
|
124
|
jpayne@69
|
125 * Prompt function prototypes are:
|
jpayne@69
|
126 * typedef char *(*el_pfunct_t) (EditLine *);
|
jpayne@69
|
127 * typedef wchar_t *(*el_wpfunct_t) (EditLine *);
|
jpayne@69
|
128 *
|
jpayne@69
|
129 * For operations that support set or set/get, the argument types listed are for
|
jpayne@69
|
130 * the "set" operation. For "get", each listed type must be a pointer.
|
jpayne@69
|
131 * E.g. EL_EDITMODE takes an int when set, but an int* when get.
|
jpayne@69
|
132 *
|
jpayne@69
|
133 * Operations that only support "get" have the correct argument types listed.
|
jpayne@69
|
134 */
|
jpayne@69
|
135 #define EL_PROMPT 0 /* , prompt_func); set/get */
|
jpayne@69
|
136 #define EL_TERMINAL 1 /* , const char *); set/get */
|
jpayne@69
|
137 #define EL_EDITOR 2 /* , const Char *); set/get */
|
jpayne@69
|
138 #define EL_SIGNAL 3 /* , int); set/get */
|
jpayne@69
|
139 #define EL_BIND 4 /* , const Char *, ..., NULL); set */
|
jpayne@69
|
140 #define EL_TELLTC 5 /* , const Char *, ..., NULL); set */
|
jpayne@69
|
141 #define EL_SETTC 6 /* , const Char *, ..., NULL); set */
|
jpayne@69
|
142 #define EL_ECHOTC 7 /* , const Char *, ..., NULL); set */
|
jpayne@69
|
143 #define EL_SETTY 8 /* , const Char *, ..., NULL); set */
|
jpayne@69
|
144 #define EL_ADDFN 9 /* , const Char *, const Char, set */
|
jpayne@69
|
145 /* el_func_t); */
|
jpayne@69
|
146 #define EL_HIST 10 /* , hist_fun_t, const void *); set */
|
jpayne@69
|
147 #define EL_EDITMODE 11 /* , int); set/get */
|
jpayne@69
|
148 #define EL_RPROMPT 12 /* , prompt_func); set/get */
|
jpayne@69
|
149 #define EL_GETCFN 13 /* , el_rfunc_t); set/get */
|
jpayne@69
|
150 #define EL_CLIENTDATA 14 /* , void *); set/get */
|
jpayne@69
|
151 #define EL_UNBUFFERED 15 /* , int); set/get */
|
jpayne@69
|
152 #define EL_PREP_TERM 16 /* , int); set */
|
jpayne@69
|
153 #define EL_GETTC 17 /* , const Char *, ..., NULL); get */
|
jpayne@69
|
154 #define EL_GETFP 18 /* , int, FILE **); get */
|
jpayne@69
|
155 #define EL_SETFP 19 /* , int, FILE *); set */
|
jpayne@69
|
156 #define EL_REFRESH 20 /* , void); set */
|
jpayne@69
|
157 #define EL_PROMPT_ESC 21 /* , prompt_func, Char); set/get */
|
jpayne@69
|
158 #define EL_RPROMPT_ESC 22 /* , prompt_func, Char); set/get */
|
jpayne@69
|
159 #define EL_RESIZE 23 /* , el_zfunc_t, void *); set */
|
jpayne@69
|
160 #define EL_ALIAS_TEXT 24 /* , el_afunc_t, void *); set */
|
jpayne@69
|
161 #define EL_SAFEREAD 25 /* , int); set/get */
|
jpayne@69
|
162
|
jpayne@69
|
163 #define EL_BUILTIN_GETCFN (NULL)
|
jpayne@69
|
164
|
jpayne@69
|
165 /*
|
jpayne@69
|
166 * Source named file or $PWD/.editrc or $HOME/.editrc
|
jpayne@69
|
167 */
|
jpayne@69
|
168 int el_source(EditLine *, const char *);
|
jpayne@69
|
169
|
jpayne@69
|
170 /*
|
jpayne@69
|
171 * Must be called when the terminal changes size; If EL_SIGNAL
|
jpayne@69
|
172 * is set this is done automatically otherwise it is the responsibility
|
jpayne@69
|
173 * of the application
|
jpayne@69
|
174 */
|
jpayne@69
|
175 void el_resize(EditLine *);
|
jpayne@69
|
176
|
jpayne@69
|
177 /*
|
jpayne@69
|
178 * User-defined function interface.
|
jpayne@69
|
179 */
|
jpayne@69
|
180 const LineInfo *el_line(EditLine *);
|
jpayne@69
|
181 int el_insertstr(EditLine *, const char *);
|
jpayne@69
|
182 void el_deletestr(EditLine *, int);
|
jpayne@69
|
183 int el_replacestr(EditLine *, const char *);
|
jpayne@69
|
184 int el_deletestr1(EditLine *, int, int);
|
jpayne@69
|
185
|
jpayne@69
|
186 /*
|
jpayne@69
|
187 * ==== History ====
|
jpayne@69
|
188 */
|
jpayne@69
|
189
|
jpayne@69
|
190 typedef struct history History;
|
jpayne@69
|
191
|
jpayne@69
|
192 typedef struct HistEvent {
|
jpayne@69
|
193 int num;
|
jpayne@69
|
194 const char *str;
|
jpayne@69
|
195 } HistEvent;
|
jpayne@69
|
196
|
jpayne@69
|
197 /*
|
jpayne@69
|
198 * History access functions.
|
jpayne@69
|
199 */
|
jpayne@69
|
200 History * history_init(void);
|
jpayne@69
|
201 void history_end(History *);
|
jpayne@69
|
202
|
jpayne@69
|
203 int history(History *, HistEvent *, int, ...);
|
jpayne@69
|
204
|
jpayne@69
|
205 #define H_FUNC 0 /* , UTSL */
|
jpayne@69
|
206 #define H_SETSIZE 1 /* , const int); */
|
jpayne@69
|
207 #define H_GETSIZE 2 /* , void); */
|
jpayne@69
|
208 #define H_FIRST 3 /* , void); */
|
jpayne@69
|
209 #define H_LAST 4 /* , void); */
|
jpayne@69
|
210 #define H_PREV 5 /* , void); */
|
jpayne@69
|
211 #define H_NEXT 6 /* , void); */
|
jpayne@69
|
212 #define H_CURR 8 /* , const int); */
|
jpayne@69
|
213 #define H_SET 7 /* , int); */
|
jpayne@69
|
214 #define H_ADD 9 /* , const wchar_t *); */
|
jpayne@69
|
215 #define H_ENTER 10 /* , const wchar_t *); */
|
jpayne@69
|
216 #define H_APPEND 11 /* , const wchar_t *); */
|
jpayne@69
|
217 #define H_END 12 /* , void); */
|
jpayne@69
|
218 #define H_NEXT_STR 13 /* , const wchar_t *); */
|
jpayne@69
|
219 #define H_PREV_STR 14 /* , const wchar_t *); */
|
jpayne@69
|
220 #define H_NEXT_EVENT 15 /* , const int); */
|
jpayne@69
|
221 #define H_PREV_EVENT 16 /* , const int); */
|
jpayne@69
|
222 #define H_LOAD 17 /* , const char *); */
|
jpayne@69
|
223 #define H_SAVE 18 /* , const char *); */
|
jpayne@69
|
224 #define H_CLEAR 19 /* , void); */
|
jpayne@69
|
225 #define H_SETUNIQUE 20 /* , int); */
|
jpayne@69
|
226 #define H_GETUNIQUE 21 /* , void); */
|
jpayne@69
|
227 #define H_DEL 22 /* , int); */
|
jpayne@69
|
228 #define H_NEXT_EVDATA 23 /* , const int, histdata_t *); */
|
jpayne@69
|
229 #define H_DELDATA 24 /* , int, histdata_t *);*/
|
jpayne@69
|
230 #define H_REPLACE 25 /* , const char *, histdata_t); */
|
jpayne@69
|
231 #define H_SAVE_FP 26 /* , FILE *); */
|
jpayne@69
|
232 #define H_NSAVE_FP 27 /* , size_t, FILE *); */
|
jpayne@69
|
233
|
jpayne@69
|
234
|
jpayne@69
|
235
|
jpayne@69
|
236 /*
|
jpayne@69
|
237 * ==== Tokenization ====
|
jpayne@69
|
238 */
|
jpayne@69
|
239
|
jpayne@69
|
240 typedef struct tokenizer Tokenizer;
|
jpayne@69
|
241
|
jpayne@69
|
242 /*
|
jpayne@69
|
243 * String tokenization functions, using simplified sh(1) quoting rules
|
jpayne@69
|
244 */
|
jpayne@69
|
245 Tokenizer *tok_init(const char *);
|
jpayne@69
|
246 void tok_end(Tokenizer *);
|
jpayne@69
|
247 void tok_reset(Tokenizer *);
|
jpayne@69
|
248 int tok_line(Tokenizer *, const LineInfo *,
|
jpayne@69
|
249 int *, const char ***, int *, int *);
|
jpayne@69
|
250 int tok_str(Tokenizer *, const char *,
|
jpayne@69
|
251 int *, const char ***);
|
jpayne@69
|
252
|
jpayne@69
|
253 /*
|
jpayne@69
|
254 * Begin Wide Character Support
|
jpayne@69
|
255 */
|
jpayne@69
|
256 #include <wchar.h>
|
jpayne@69
|
257 #include <wctype.h>
|
jpayne@69
|
258
|
jpayne@69
|
259 #ifndef HAVE_WCSDUP
|
jpayne@69
|
260 wchar_t * wcsdup(const wchar_t *str);
|
jpayne@69
|
261 #endif
|
jpayne@69
|
262
|
jpayne@69
|
263 /*
|
jpayne@69
|
264 * ==== Editing ====
|
jpayne@69
|
265 */
|
jpayne@69
|
266 typedef struct lineinfow {
|
jpayne@69
|
267 const wchar_t *buffer;
|
jpayne@69
|
268 const wchar_t *cursor;
|
jpayne@69
|
269 const wchar_t *lastchar;
|
jpayne@69
|
270 } LineInfoW;
|
jpayne@69
|
271
|
jpayne@69
|
272 typedef int (*el_rfunc_t)(EditLine *, wchar_t *);
|
jpayne@69
|
273
|
jpayne@69
|
274 const wchar_t *el_wgets(EditLine *, int *);
|
jpayne@69
|
275 int el_wgetc(EditLine *, wchar_t *);
|
jpayne@69
|
276 void el_wpush(EditLine *, const wchar_t *);
|
jpayne@69
|
277
|
jpayne@69
|
278 int el_wparse(EditLine *, int, const wchar_t **);
|
jpayne@69
|
279
|
jpayne@69
|
280 int el_wset(EditLine *, int, ...);
|
jpayne@69
|
281 int el_wget(EditLine *, int, ...);
|
jpayne@69
|
282
|
jpayne@69
|
283 int el_cursor(EditLine *, int);
|
jpayne@69
|
284 const LineInfoW *el_wline(EditLine *);
|
jpayne@69
|
285 int el_winsertstr(EditLine *, const wchar_t *);
|
jpayne@69
|
286 #define el_wdeletestr el_deletestr
|
jpayne@69
|
287 int el_wreplacestr(EditLine *, const wchar_t *);
|
jpayne@69
|
288
|
jpayne@69
|
289 /*
|
jpayne@69
|
290 * ==== History ====
|
jpayne@69
|
291 */
|
jpayne@69
|
292 typedef struct histeventW {
|
jpayne@69
|
293 int num;
|
jpayne@69
|
294 const wchar_t *str;
|
jpayne@69
|
295 } HistEventW;
|
jpayne@69
|
296
|
jpayne@69
|
297 typedef struct historyW HistoryW;
|
jpayne@69
|
298
|
jpayne@69
|
299 HistoryW * history_winit(void);
|
jpayne@69
|
300 void history_wend(HistoryW *);
|
jpayne@69
|
301
|
jpayne@69
|
302 int history_w(HistoryW *, HistEventW *, int, ...);
|
jpayne@69
|
303
|
jpayne@69
|
304 /*
|
jpayne@69
|
305 * ==== Tokenization ====
|
jpayne@69
|
306 */
|
jpayne@69
|
307 typedef struct tokenizerW TokenizerW;
|
jpayne@69
|
308
|
jpayne@69
|
309 /* Wide character tokenizer support */
|
jpayne@69
|
310 TokenizerW *tok_winit(const wchar_t *);
|
jpayne@69
|
311 void tok_wend(TokenizerW *);
|
jpayne@69
|
312 void tok_wreset(TokenizerW *);
|
jpayne@69
|
313 int tok_wline(TokenizerW *, const LineInfoW *,
|
jpayne@69
|
314 int *, const wchar_t ***, int *, int *);
|
jpayne@69
|
315 int tok_wstr(TokenizerW *, const wchar_t *,
|
jpayne@69
|
316 int *, const wchar_t ***);
|
jpayne@69
|
317
|
jpayne@69
|
318 #ifdef __cplusplus
|
jpayne@69
|
319 }
|
jpayne@69
|
320 #endif
|
jpayne@69
|
321
|
jpayne@69
|
322 #endif /* _HISTEDIT_H_ */
|