xref: /freebsd/contrib/libedit/readline/readline.h (revision 7f39937557052c004d7ebf55dd973108323756f3)
1*7f399375SBaptiste Daroussin /*	$NetBSD: readline.h,v 1.53 2022/02/19 17:45:02 christos Exp $	*/
2d0ef721eSBaptiste Daroussin 
3d0ef721eSBaptiste Daroussin /*-
4d0ef721eSBaptiste Daroussin  * Copyright (c) 1997 The NetBSD Foundation, Inc.
5d0ef721eSBaptiste Daroussin  * All rights reserved.
6d0ef721eSBaptiste Daroussin  *
7d0ef721eSBaptiste Daroussin  * This code is derived from software contributed to The NetBSD Foundation
8d0ef721eSBaptiste Daroussin  * by Jaromir Dolecek.
9d0ef721eSBaptiste Daroussin  *
10d0ef721eSBaptiste Daroussin  * Redistribution and use in source and binary forms, with or without
11d0ef721eSBaptiste Daroussin  * modification, are permitted provided that the following conditions
12d0ef721eSBaptiste Daroussin  * are met:
13d0ef721eSBaptiste Daroussin  * 1. Redistributions of source code must retain the above copyright
14d0ef721eSBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer.
15d0ef721eSBaptiste Daroussin  * 2. Redistributions in binary form must reproduce the above copyright
16d0ef721eSBaptiste Daroussin  *    notice, this list of conditions and the following disclaimer in the
17d0ef721eSBaptiste Daroussin  *    documentation and/or other materials provided with the distribution.
18d0ef721eSBaptiste Daroussin  *
19d0ef721eSBaptiste Daroussin  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d0ef721eSBaptiste Daroussin  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d0ef721eSBaptiste Daroussin  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d0ef721eSBaptiste Daroussin  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d0ef721eSBaptiste Daroussin  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d0ef721eSBaptiste Daroussin  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d0ef721eSBaptiste Daroussin  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d0ef721eSBaptiste Daroussin  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d0ef721eSBaptiste Daroussin  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d0ef721eSBaptiste Daroussin  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d0ef721eSBaptiste Daroussin  * POSSIBILITY OF SUCH DAMAGE.
30d0ef721eSBaptiste Daroussin  */
31d0ef721eSBaptiste Daroussin #ifndef _READLINE_H_
32d0ef721eSBaptiste Daroussin #define _READLINE_H_
33d0ef721eSBaptiste Daroussin 
34d0ef721eSBaptiste Daroussin #include <sys/types.h>
35d0ef721eSBaptiste Daroussin #include <stdio.h>
36d0ef721eSBaptiste Daroussin 
37d0ef721eSBaptiste Daroussin /* list of readline stuff supported by editline library's readline wrapper */
38d0ef721eSBaptiste Daroussin 
39d0ef721eSBaptiste Daroussin /* typedefs */
40d0ef721eSBaptiste Daroussin typedef int	  Function(const char *, int);
41d0ef721eSBaptiste Daroussin typedef char     *CPFunction(const char *, int);
42d0ef721eSBaptiste Daroussin typedef void	  VFunction(void);
43d0ef721eSBaptiste Daroussin typedef void	  rl_vcpfunc_t(char *);
44d0ef721eSBaptiste Daroussin typedef char	**rl_completion_func_t(const char *, int, int);
45d0ef721eSBaptiste Daroussin typedef char     *rl_compentry_func_t(const char *, int);
46d0ef721eSBaptiste Daroussin typedef int	  rl_command_func_t(int, int);
47d0ef721eSBaptiste Daroussin typedef int	  rl_hook_func_t(void);
4891f76417SBaptiste Daroussin typedef int       rl_icppfunc_t(char **);
49d0ef721eSBaptiste Daroussin 
50d0ef721eSBaptiste Daroussin /* only supports length */
51d0ef721eSBaptiste Daroussin typedef struct {
52d0ef721eSBaptiste Daroussin 	int length;
53d0ef721eSBaptiste Daroussin } HISTORY_STATE;
54d0ef721eSBaptiste Daroussin 
55d0ef721eSBaptiste Daroussin typedef void *histdata_t;
56d0ef721eSBaptiste Daroussin 
57d0ef721eSBaptiste Daroussin typedef struct _hist_entry {
58d0ef721eSBaptiste Daroussin 	const char	*line;
59d0ef721eSBaptiste Daroussin 	histdata_t	 data;
60d0ef721eSBaptiste Daroussin } HIST_ENTRY;
61d0ef721eSBaptiste Daroussin 
62d0ef721eSBaptiste Daroussin typedef struct _keymap_entry {
63d0ef721eSBaptiste Daroussin 	char type;
64d0ef721eSBaptiste Daroussin #define ISFUNC	0
65d0ef721eSBaptiste Daroussin #define ISKMAP	1
66d0ef721eSBaptiste Daroussin #define ISMACR	2
67d0ef721eSBaptiste Daroussin 	Function *function;
68d0ef721eSBaptiste Daroussin } KEYMAP_ENTRY;
69d0ef721eSBaptiste Daroussin 
70d0ef721eSBaptiste Daroussin #define KEYMAP_SIZE	256
71d0ef721eSBaptiste Daroussin 
72d0ef721eSBaptiste Daroussin typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE];
73d0ef721eSBaptiste Daroussin typedef KEYMAP_ENTRY *Keymap;
74d0ef721eSBaptiste Daroussin 
75d0ef721eSBaptiste Daroussin #define control_character_threshold	0x20
76d0ef721eSBaptiste Daroussin #define control_character_bit		0x40
77d0ef721eSBaptiste Daroussin 
78d0ef721eSBaptiste Daroussin #ifndef CTRL
79d0ef721eSBaptiste Daroussin #include <sys/ioctl.h>
80d0ef721eSBaptiste Daroussin #if !defined(__sun) && !defined(__hpux) && !defined(_AIX)
81d0ef721eSBaptiste Daroussin #include <sys/ttydefaults.h>
82d0ef721eSBaptiste Daroussin #endif
83d0ef721eSBaptiste Daroussin #ifndef CTRL
84d0ef721eSBaptiste Daroussin #define CTRL(c)		((c) & 037)
85d0ef721eSBaptiste Daroussin #endif
86d0ef721eSBaptiste Daroussin #endif
87d0ef721eSBaptiste Daroussin #ifndef UNCTRL
88d0ef721eSBaptiste Daroussin #define UNCTRL(c)	(((c) - 'a' + 'A')|control_character_bit)
89d0ef721eSBaptiste Daroussin #endif
90d0ef721eSBaptiste Daroussin 
91d0ef721eSBaptiste Daroussin #define RUBOUT		0x7f
92d0ef721eSBaptiste Daroussin #define ABORT_CHAR	CTRL('G')
93d0ef721eSBaptiste Daroussin #define RL_READLINE_VERSION	0x0402
94d0ef721eSBaptiste Daroussin #define RL_PROMPT_START_IGNORE	'\1'
95d0ef721eSBaptiste Daroussin #define RL_PROMPT_END_IGNORE	'\2'
96d0ef721eSBaptiste Daroussin 
97*7f399375SBaptiste Daroussin #define RL_STATE_NONE		0x000000
98*7f399375SBaptiste Daroussin #define RL_STATE_DONE		0x000001
99*7f399375SBaptiste Daroussin 
100*7f399375SBaptiste Daroussin #define RL_SETSTATE(x)		(rl_readline_state |= ((unsigned long) x))
101*7f399375SBaptiste Daroussin #define RL_UNSETSTATE(x)	(rl_readline_state &= ~((unsigned long) x))
102*7f399375SBaptiste Daroussin #define RL_ISSTATE(x)		(rl_readline_state & ((unsigned long) x))
103*7f399375SBaptiste Daroussin 
104d0ef721eSBaptiste Daroussin /* global variables used by readline enabled applications */
105d0ef721eSBaptiste Daroussin #ifdef __cplusplus
106d0ef721eSBaptiste Daroussin extern "C" {
107d0ef721eSBaptiste Daroussin #endif
108d0ef721eSBaptiste Daroussin extern const char	*rl_library_version;
109d0ef721eSBaptiste Daroussin extern int		rl_readline_version;
110d0ef721eSBaptiste Daroussin extern const char	*rl_readline_name;
111d0ef721eSBaptiste Daroussin extern FILE		*rl_instream;
112d0ef721eSBaptiste Daroussin extern FILE		*rl_outstream;
113d0ef721eSBaptiste Daroussin extern char		*rl_line_buffer;
114d0ef721eSBaptiste Daroussin extern int		 rl_point, rl_end;
115d0ef721eSBaptiste Daroussin extern int		 history_base, history_length;
116d0ef721eSBaptiste Daroussin extern int		 max_input_history;
11791f76417SBaptiste Daroussin extern const char	*rl_basic_quote_characters;
118d0ef721eSBaptiste Daroussin extern const char	*rl_basic_word_break_characters;
119d0ef721eSBaptiste Daroussin extern char		*rl_completer_word_break_characters;
120d0ef721eSBaptiste Daroussin extern const char	*rl_completer_quote_characters;
121d0ef721eSBaptiste Daroussin extern rl_compentry_func_t *rl_completion_entry_function;
122d0ef721eSBaptiste Daroussin extern char		*(*rl_completion_word_break_hook)(void);
123d0ef721eSBaptiste Daroussin extern rl_completion_func_t *rl_attempted_completion_function;
124d0ef721eSBaptiste Daroussin extern int		 rl_attempted_completion_over;
125d0ef721eSBaptiste Daroussin extern int		rl_completion_type;
126d0ef721eSBaptiste Daroussin extern int		rl_completion_query_items;
127d0ef721eSBaptiste Daroussin extern const char	*rl_special_prefixes;
128d0ef721eSBaptiste Daroussin extern int		rl_completion_append_character;
129d0ef721eSBaptiste Daroussin extern int		rl_inhibit_completion;
130*7f399375SBaptiste Daroussin extern rl_hook_func_t		*rl_pre_input_hook;
131*7f399375SBaptiste Daroussin extern rl_hook_func_t		*rl_startup_hook;
132d0ef721eSBaptiste Daroussin extern char		*rl_terminal_name;
133d0ef721eSBaptiste Daroussin extern int		rl_already_prompted;
134d0ef721eSBaptiste Daroussin extern char		*rl_prompt;
135d0ef721eSBaptiste Daroussin extern int		rl_done;
136d0ef721eSBaptiste Daroussin /*
137d0ef721eSBaptiste Daroussin  * The following is not implemented
138d0ef721eSBaptiste Daroussin  */
13991f76417SBaptiste Daroussin extern unsigned long	rl_readline_state;
140d0ef721eSBaptiste Daroussin extern int		rl_catch_signals;
141d0ef721eSBaptiste Daroussin extern int		rl_catch_sigwinch;
142d0ef721eSBaptiste Daroussin extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
143d0ef721eSBaptiste Daroussin 			emacs_meta_keymap,
144d0ef721eSBaptiste Daroussin 			emacs_ctlx_keymap;
145d0ef721eSBaptiste Daroussin extern int		rl_filename_completion_desired;
146d0ef721eSBaptiste Daroussin extern int		rl_ignore_completion_duplicates;
147d0ef721eSBaptiste Daroussin extern int		(*rl_getc_function)(FILE *);
148d0ef721eSBaptiste Daroussin extern VFunction	*rl_redisplay_function;
149d0ef721eSBaptiste Daroussin extern VFunction	*rl_completion_display_matches_hook;
150d0ef721eSBaptiste Daroussin extern VFunction	*rl_prep_term_function;
151d0ef721eSBaptiste Daroussin extern VFunction	*rl_deprep_term_function;
152d0ef721eSBaptiste Daroussin extern rl_hook_func_t	*rl_event_hook;
153d0ef721eSBaptiste Daroussin extern int		readline_echoing_p;
154d0ef721eSBaptiste Daroussin extern int		_rl_print_completions_horizontally;
15591f76417SBaptiste Daroussin extern int		_rl_complete_mark_directories;
15691f76417SBaptiste Daroussin extern rl_icppfunc_t	*rl_directory_completion_hook;
15791f76417SBaptiste Daroussin extern int		rl_completion_suppress_append;
15891f76417SBaptiste Daroussin extern int		rl_sort_completion_matches;
15991f76417SBaptiste Daroussin extern int		_rl_completion_prefix_display_length;
16091f76417SBaptiste Daroussin extern int		_rl_echoing_p;
16191f76417SBaptiste Daroussin extern int		history_max_entries;
16291f76417SBaptiste Daroussin extern char		*rl_display_prompt;
163*7f399375SBaptiste Daroussin extern int		rl_erase_empty_line;
164d0ef721eSBaptiste Daroussin 
165d0ef721eSBaptiste Daroussin /* supported functions */
166d0ef721eSBaptiste Daroussin char		*readline(const char *);
167d0ef721eSBaptiste Daroussin int		 rl_initialize(void);
168d0ef721eSBaptiste Daroussin 
169d0ef721eSBaptiste Daroussin void		 using_history(void);
170d0ef721eSBaptiste Daroussin int		 add_history(const char *);
171d0ef721eSBaptiste Daroussin void		 clear_history(void);
172d0ef721eSBaptiste Daroussin int		 append_history(int, const char *);
173d0ef721eSBaptiste Daroussin void		 stifle_history(int);
174d0ef721eSBaptiste Daroussin int		 unstifle_history(void);
175d0ef721eSBaptiste Daroussin int		 history_is_stifled(void);
176d0ef721eSBaptiste Daroussin int		 where_history(void);
177d0ef721eSBaptiste Daroussin HIST_ENTRY	*current_history(void);
178d0ef721eSBaptiste Daroussin HIST_ENTRY	*history_get(int);
179d0ef721eSBaptiste Daroussin HIST_ENTRY	*remove_history(int);
180d0ef721eSBaptiste Daroussin HIST_ENTRY	*replace_history_entry(int, const char *, histdata_t);
181d0ef721eSBaptiste Daroussin int		 history_total_bytes(void);
182d0ef721eSBaptiste Daroussin int		 history_set_pos(int);
183d0ef721eSBaptiste Daroussin HIST_ENTRY	*previous_history(void);
184d0ef721eSBaptiste Daroussin HIST_ENTRY	*next_history(void);
185d0ef721eSBaptiste Daroussin HIST_ENTRY     **history_list(void);
186d0ef721eSBaptiste Daroussin int		 history_search(const char *, int);
187d0ef721eSBaptiste Daroussin int		 history_search_prefix(const char *, int);
188d0ef721eSBaptiste Daroussin int		 history_search_pos(const char *, int, int);
189d0ef721eSBaptiste Daroussin int		 read_history(const char *);
190d0ef721eSBaptiste Daroussin int		 write_history(const char *);
191d0ef721eSBaptiste Daroussin int		 history_truncate_file(const char *, int);
192d0ef721eSBaptiste Daroussin int		 history_expand(char *, char **);
193d0ef721eSBaptiste Daroussin char	       **history_tokenize(const char *);
194d0ef721eSBaptiste Daroussin const char	*get_history_event(const char *, int *, int);
195d0ef721eSBaptiste Daroussin char		*history_arg_extract(int, int, const char *);
196d0ef721eSBaptiste Daroussin 
197d0ef721eSBaptiste Daroussin char		*tilde_expand(char *);
198d0ef721eSBaptiste Daroussin char		*filename_completion_function(const char *, int);
199d0ef721eSBaptiste Daroussin char		*username_completion_function(const char *, int);
200d0ef721eSBaptiste Daroussin int		 rl_complete(int, int);
201d0ef721eSBaptiste Daroussin int		 rl_read_key(void);
202d0ef721eSBaptiste Daroussin char	       **completion_matches(/* const */ char *, rl_compentry_func_t *);
203d0ef721eSBaptiste Daroussin void		 rl_display_match_list(char **, int, int);
204d0ef721eSBaptiste Daroussin 
205d0ef721eSBaptiste Daroussin int		 rl_insert(int, int);
206d0ef721eSBaptiste Daroussin int		 rl_insert_text(const char *);
207d0ef721eSBaptiste Daroussin int		 rl_reset_terminal(const char *);
208d0ef721eSBaptiste Daroussin void		 rl_resize_terminal(void);
209d0ef721eSBaptiste Daroussin int		 rl_bind_key(int, rl_command_func_t *);
210d0ef721eSBaptiste Daroussin int		 rl_newline(int, int);
211d0ef721eSBaptiste Daroussin void		 rl_callback_read_char(void);
212d0ef721eSBaptiste Daroussin void		 rl_callback_handler_install(const char *, rl_vcpfunc_t *);
213d0ef721eSBaptiste Daroussin void		 rl_callback_handler_remove(void);
214d0ef721eSBaptiste Daroussin void		 rl_redisplay(void);
215d0ef721eSBaptiste Daroussin int		 rl_get_previous_history(int, int);
216d0ef721eSBaptiste Daroussin void		 rl_prep_terminal(int);
217d0ef721eSBaptiste Daroussin void		 rl_deprep_terminal(void);
218d0ef721eSBaptiste Daroussin int		 rl_read_init_file(const char *);
219d0ef721eSBaptiste Daroussin int		 rl_parse_and_bind(const char *);
220d0ef721eSBaptiste Daroussin int		 rl_variable_bind(const char *, const char *);
221d0ef721eSBaptiste Daroussin int		 rl_stuff_char(int);
222d0ef721eSBaptiste Daroussin int		 rl_add_defun(const char *, rl_command_func_t *, int);
223d0ef721eSBaptiste Daroussin HISTORY_STATE	*history_get_history_state(void);
224d0ef721eSBaptiste Daroussin void		 rl_get_screen_size(int *, int *);
225d0ef721eSBaptiste Daroussin void		 rl_set_screen_size(int, int);
226d0ef721eSBaptiste Daroussin char		*rl_filename_completion_function(const char *, int);
227d0ef721eSBaptiste Daroussin int		 _rl_abort_internal(void);
228d0ef721eSBaptiste Daroussin int		 _rl_qsort_string_compare(char **, char **);
229d0ef721eSBaptiste Daroussin char	       **rl_completion_matches(const char *, rl_compentry_func_t *);
230d0ef721eSBaptiste Daroussin void		 rl_forced_update_display(void);
231d0ef721eSBaptiste Daroussin int		 rl_set_prompt(const char *);
232d0ef721eSBaptiste Daroussin int		 rl_on_new_line(void);
233d0ef721eSBaptiste Daroussin void		 rl_reset_after_signal(void);
234d0ef721eSBaptiste Daroussin void		 rl_echo_signal_char(int);
23591f76417SBaptiste Daroussin int		 rl_crlf(void);
23691f76417SBaptiste Daroussin int		 rl_ding(void);
237*7f399375SBaptiste Daroussin char 		*rl_copy_text(int, int);
238*7f399375SBaptiste Daroussin void		 rl_replace_line(const char *, int);
239*7f399375SBaptiste Daroussin int		 rl_delete_text(int, int);
240*7f399375SBaptiste Daroussin void 		 rl_message(const char *format, ...)
241*7f399375SBaptiste Daroussin     __attribute__((__format__(__printf__, 1, 2)));
242*7f399375SBaptiste Daroussin void		 rl_save_prompt(void);
243*7f399375SBaptiste Daroussin void		 rl_restore_prompt(void);
244d0ef721eSBaptiste Daroussin 
245d0ef721eSBaptiste Daroussin /*
246d0ef721eSBaptiste Daroussin  * The following are not implemented
247d0ef721eSBaptiste Daroussin  */
248d0ef721eSBaptiste Daroussin int		 rl_kill_text(int, int);
249d0ef721eSBaptiste Daroussin Keymap		 rl_get_keymap(void);
250d0ef721eSBaptiste Daroussin void		 rl_set_keymap(Keymap);
251d0ef721eSBaptiste Daroussin Keymap		 rl_make_bare_keymap(void);
252d0ef721eSBaptiste Daroussin int		 rl_generic_bind(int, const char *, const char *, Keymap);
253d0ef721eSBaptiste Daroussin int		 rl_bind_key_in_map(int, rl_command_func_t *, Keymap);
254*7f399375SBaptiste Daroussin int		 rl_set_key(const char *, rl_command_func_t *, Keymap);
255d0ef721eSBaptiste Daroussin void		 rl_cleanup_after_signal(void);
256d0ef721eSBaptiste Daroussin void		 rl_free_line_state(void);
257d0ef721eSBaptiste Daroussin int		 rl_set_keyboard_input_timeout(int);
25891f76417SBaptiste Daroussin int		 rl_abort(int, int);
25991f76417SBaptiste Daroussin int	         rl_set_keymap_name(const char *, Keymap);
26091f76417SBaptiste Daroussin histdata_t	 free_history_entry(HIST_ENTRY *);
26191f76417SBaptiste Daroussin void		 _rl_erase_entire_line(void);
262d0ef721eSBaptiste Daroussin 
263d0ef721eSBaptiste Daroussin #ifdef __cplusplus
264d0ef721eSBaptiste Daroussin }
265d0ef721eSBaptiste Daroussin #endif
266d0ef721eSBaptiste Daroussin 
267d0ef721eSBaptiste Daroussin #endif /* _READLINE_H_ */
268