xref: /netbsd-src/lib/libedit/readline/readline.h (revision 4ee547369c79e33850ff911fab3840da8be0b1d9)
1*4ee54736Schristos /*	$NetBSD: readline.h,v 1.55 2023/04/25 17:51:32 christos Exp $	*/
274c6c9c2Sjdolecek 
374c6c9c2Sjdolecek /*-
474c6c9c2Sjdolecek  * Copyright (c) 1997 The NetBSD Foundation, Inc.
574c6c9c2Sjdolecek  * All rights reserved.
674c6c9c2Sjdolecek  *
774c6c9c2Sjdolecek  * This code is derived from software contributed to The NetBSD Foundation
874c6c9c2Sjdolecek  * by Jaromir Dolecek.
974c6c9c2Sjdolecek  *
1074c6c9c2Sjdolecek  * Redistribution and use in source and binary forms, with or without
1174c6c9c2Sjdolecek  * modification, are permitted provided that the following conditions
1274c6c9c2Sjdolecek  * are met:
1374c6c9c2Sjdolecek  * 1. Redistributions of source code must retain the above copyright
1474c6c9c2Sjdolecek  *    notice, this list of conditions and the following disclaimer.
1574c6c9c2Sjdolecek  * 2. Redistributions in binary form must reproduce the above copyright
1674c6c9c2Sjdolecek  *    notice, this list of conditions and the following disclaimer in the
1774c6c9c2Sjdolecek  *    documentation and/or other materials provided with the distribution.
1874c6c9c2Sjdolecek  *
1974c6c9c2Sjdolecek  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2074c6c9c2Sjdolecek  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2174c6c9c2Sjdolecek  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2274c6c9c2Sjdolecek  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2374c6c9c2Sjdolecek  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2474c6c9c2Sjdolecek  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2574c6c9c2Sjdolecek  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2674c6c9c2Sjdolecek  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2774c6c9c2Sjdolecek  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2874c6c9c2Sjdolecek  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2974c6c9c2Sjdolecek  * POSSIBILITY OF SUCH DAMAGE.
3074c6c9c2Sjdolecek  */
3174c6c9c2Sjdolecek #ifndef _READLINE_H_
3274c6c9c2Sjdolecek #define _READLINE_H_
3374c6c9c2Sjdolecek 
3474c6c9c2Sjdolecek #include <sys/types.h>
358e714f4bSchristos #include <stdio.h>
3674c6c9c2Sjdolecek 
3774c6c9c2Sjdolecek /* list of readline stuff supported by editline library's readline wrapper */
3874c6c9c2Sjdolecek 
3974c6c9c2Sjdolecek /* typedefs */
40*4ee54736Schristos typedef int	  rl_linebuf_func_t(const char *, int);
41ef8fd189Schristos typedef void	  rl_voidfunc_t(void);
42ef8fd189Schristos typedef void	  rl_vintfunc_t(int);
430804279dSchristos typedef void	  rl_vcpfunc_t(char *);
440804279dSchristos typedef char	**rl_completion_func_t(const char *, int, int);
452d9dad6fSchristos typedef char     *rl_compentry_func_t(const char *, int);
46ef8fd189Schristos typedef void	  rl_compdisp_func_t(char **, int, int);
47ea3813edSchristos typedef int	  rl_command_func_t(int, int);
48a3c16b55Schristos typedef int	  rl_hook_func_t(void);
497f1c6a0bSchristos typedef int       rl_icppfunc_t(char **);
50ea3813edSchristos 
51ea3813edSchristos /* only supports length */
52ea3813edSchristos typedef struct {
53ea3813edSchristos 	int length;
54ea3813edSchristos } HISTORY_STATE;
55ea3813edSchristos 
56ea3813edSchristos typedef void *histdata_t;
5774c6c9c2Sjdolecek 
5874c6c9c2Sjdolecek typedef struct _hist_entry {
5974c6c9c2Sjdolecek 	const char	*line;
60ea3813edSchristos 	histdata_t	 data;
6174c6c9c2Sjdolecek } HIST_ENTRY;
6274c6c9c2Sjdolecek 
63166e18a7Schristos typedef struct _keymap_entry {
64166e18a7Schristos 	char type;
65166e18a7Schristos #define ISFUNC	0
66166e18a7Schristos #define ISKMAP	1
67166e18a7Schristos #define ISMACR	2
68*4ee54736Schristos 	rl_linebuf_func_t *function;
69166e18a7Schristos } KEYMAP_ENTRY;
70166e18a7Schristos 
71166e18a7Schristos #define KEYMAP_SIZE	256
72166e18a7Schristos 
73166e18a7Schristos typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE];
74166e18a7Schristos typedef KEYMAP_ENTRY *Keymap;
75166e18a7Schristos 
76166e18a7Schristos #define control_character_threshold	0x20
77166e18a7Schristos #define control_character_bit		0x40
78166e18a7Schristos 
79166e18a7Schristos #ifndef CTRL
802e7dfdfaSchristos #include <sys/ioctl.h>
81461d0372Schristos #if !defined(__sun) && !defined(__hpux) && !defined(_AIX)
82e9c2e92bStron #include <sys/ttydefaults.h>
83c8d67a7dSchristos #endif
842e7dfdfaSchristos #ifndef CTRL
85705c04f0Schristos #define CTRL(c)		((c) & 037)
86166e18a7Schristos #endif
872e7dfdfaSchristos #endif
88166e18a7Schristos #ifndef UNCTRL
89705c04f0Schristos #define UNCTRL(c)	(((c) - 'a' + 'A')|control_character_bit)
90166e18a7Schristos #endif
91166e18a7Schristos 
92166e18a7Schristos #define RUBOUT		0x7f
93166e18a7Schristos #define ABORT_CHAR	CTRL('G')
94ea3813edSchristos #define RL_READLINE_VERSION	0x0402
95e6ec3d06Schristos #define RL_PROMPT_START_IGNORE	'\1'
96e6ec3d06Schristos #define RL_PROMPT_END_IGNORE	'\2'
97166e18a7Schristos 
98ea988183Schristos #define RL_STATE_NONE		0x000000
99ea988183Schristos #define RL_STATE_DONE		0x000001
100ea988183Schristos 
101ea988183Schristos #define RL_SETSTATE(x)		(rl_readline_state |= ((unsigned long) x))
102ea988183Schristos #define RL_UNSETSTATE(x)	(rl_readline_state &= ~((unsigned long) x))
103ea988183Schristos #define RL_ISSTATE(x)		(rl_readline_state & ((unsigned long) x))
104ea988183Schristos 
10574c6c9c2Sjdolecek /* global variables used by readline enabled applications */
1060e0ac6b7Schristos #ifdef __cplusplus
1070e0ac6b7Schristos extern "C" {
1080e0ac6b7Schristos #endif
10974c6c9c2Sjdolecek extern const char	*rl_library_version;
110ea3813edSchristos extern int		rl_readline_version;
11152b10dfdSchristos extern const char	*rl_readline_name;
11274c6c9c2Sjdolecek extern FILE		*rl_instream;
11374c6c9c2Sjdolecek extern FILE		*rl_outstream;
11474c6c9c2Sjdolecek extern char		*rl_line_buffer;
11574c6c9c2Sjdolecek extern int		rl_point, rl_end;
1167f1c6a0bSchristos extern const char	*rl_basic_quote_characters;
11752b10dfdSchristos extern const char	*rl_basic_word_break_characters;
11874c6c9c2Sjdolecek extern char		*rl_completer_word_break_characters;
11972dd3db6Schristos extern const char	*rl_completer_quote_characters;
1200804279dSchristos extern rl_compentry_func_t *rl_completion_entry_function;
121f5b586b1Schristos extern char		*(*rl_completion_word_break_hook)(void);
1220804279dSchristos extern rl_completion_func_t *rl_attempted_completion_function;
123a76abbedSchristos extern int		 rl_attempted_completion_over;
12474c6c9c2Sjdolecek extern int		rl_completion_type;
12574c6c9c2Sjdolecek extern int		rl_completion_query_items;
12652b10dfdSchristos extern const char	*rl_special_prefixes;
12774c6c9c2Sjdolecek extern int		rl_completion_append_character;
128742c0a6bSchristos extern int		rl_inhibit_completion;
129a7c17a09Schristos extern rl_hook_func_t	*rl_pre_input_hook;
130a7c17a09Schristos extern rl_hook_func_t	*rl_startup_hook;
131166e18a7Schristos extern char		*rl_terminal_name;
132166e18a7Schristos extern int		rl_already_prompted;
133166e18a7Schristos extern char		*rl_prompt;
134931e76f2Schristos extern int		rl_done;
135*4ee54736Schristos extern rl_vcpfunc_t	*rl_linefunc;
136*4ee54736Schristos extern rl_hook_func_t   *rl_startup1_hook;
137*4ee54736Schristos extern char             *rl_prompt_saved;
138*4ee54736Schristos extern int		history_base, history_length;
139*4ee54736Schristos extern int		history_offset;
140*4ee54736Schristos extern char		history_expansion_char;
141*4ee54736Schristos extern char		history_subst_char;
142*4ee54736Schristos extern char		*history_no_expand_chars;
143*4ee54736Schristos extern rl_linebuf_func_t *history_inhibit_expansion_function;
144*4ee54736Schristos extern int		max_input_history;
145*4ee54736Schristos 
146166e18a7Schristos /*
147166e18a7Schristos  * The following is not implemented
148166e18a7Schristos  */
1497f1c6a0bSchristos extern unsigned long	rl_readline_state;
15045fd2d25Schristos extern int		rl_catch_signals;
15145fd2d25Schristos extern int		rl_catch_sigwinch;
152166e18a7Schristos extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
153166e18a7Schristos 			emacs_meta_keymap,
154166e18a7Schristos 			emacs_ctlx_keymap;
155166e18a7Schristos extern int		rl_filename_completion_desired;
156166e18a7Schristos extern int		rl_ignore_completion_duplicates;
1575f3802caSchristos extern int		(*rl_getc_function)(FILE *);
158ef8fd189Schristos extern rl_voidfunc_t	*rl_redisplay_function;
159ef8fd189Schristos extern rl_compdisp_func_t *rl_completion_display_matches_hook;
160ef8fd189Schristos extern rl_vintfunc_t	*rl_prep_term_function;
161ef8fd189Schristos extern rl_voidfunc_t	*rl_deprep_term_function;
162a3c16b55Schristos extern rl_hook_func_t	*rl_event_hook;
1636b8a7930Schristos extern int		readline_echoing_p;
1646b8a7930Schristos extern int		_rl_print_completions_horizontally;
1657f1c6a0bSchristos extern int		_rl_complete_mark_directories;
1667f1c6a0bSchristos extern rl_icppfunc_t	*rl_directory_completion_hook;
1677f1c6a0bSchristos extern int		rl_completion_suppress_append;
1687f1c6a0bSchristos extern int		rl_sort_completion_matches;
1697f1c6a0bSchristos extern int		_rl_completion_prefix_display_length;
1707f1c6a0bSchristos extern int		_rl_echoing_p;
1717f1c6a0bSchristos extern int		history_max_entries;
1727f1c6a0bSchristos extern char		*rl_display_prompt;
173b7e56637Schristos extern int		rl_erase_empty_line;
17474c6c9c2Sjdolecek 
17574c6c9c2Sjdolecek /* supported functions */
17674c6c9c2Sjdolecek char		*readline(const char *);
17774c6c9c2Sjdolecek int		 rl_initialize(void);
17874c6c9c2Sjdolecek 
17974c6c9c2Sjdolecek void		 using_history(void);
18074c6c9c2Sjdolecek int		 add_history(const char *);
18174c6c9c2Sjdolecek void		 clear_history(void);
18227916d7cSchristos int		 append_history(int, const char *);
18374c6c9c2Sjdolecek void		 stifle_history(int);
18474c6c9c2Sjdolecek int		 unstifle_history(void);
18574c6c9c2Sjdolecek int		 history_is_stifled(void);
18674c6c9c2Sjdolecek int		 where_history(void);
18774c6c9c2Sjdolecek HIST_ENTRY	*current_history(void);
18874c6c9c2Sjdolecek HIST_ENTRY	*history_get(int);
18945542456Schristos HIST_ENTRY	*remove_history(int);
190ea3813edSchristos HIST_ENTRY	*replace_history_entry(int, const char *, histdata_t);
19174c6c9c2Sjdolecek int		 history_total_bytes(void);
19274c6c9c2Sjdolecek int		 history_set_pos(int);
19374c6c9c2Sjdolecek HIST_ENTRY	*previous_history(void);
19474c6c9c2Sjdolecek HIST_ENTRY	*next_history(void);
19578abb1b9Schristos HIST_ENTRY     **history_list(void);
19674c6c9c2Sjdolecek int		 history_search(const char *, int);
19774c6c9c2Sjdolecek int		 history_search_prefix(const char *, int);
19874c6c9c2Sjdolecek int		 history_search_pos(const char *, int, int);
19974c6c9c2Sjdolecek int		 read_history(const char *);
20074c6c9c2Sjdolecek int		 write_history(const char *);
201ea3813edSchristos int		 history_truncate_file(const char *, int);
20274c6c9c2Sjdolecek int		 history_expand(char *, char **);
20374c6c9c2Sjdolecek char	       **history_tokenize(const char *);
2048b40dcaeSchristos const char	*get_history_event(const char *, int *, int);
2058b40dcaeSchristos char		*history_arg_extract(int, int, const char *);
20674c6c9c2Sjdolecek 
20719c38590Schristos char		*tilde_expand(char *);
20874c6c9c2Sjdolecek char		*filename_completion_function(const char *, int);
20974c6c9c2Sjdolecek char		*username_completion_function(const char *, int);
21074c6c9c2Sjdolecek int		 rl_complete(int, int);
21174c6c9c2Sjdolecek int		 rl_read_key(void);
212a3c16b55Schristos char	       **completion_matches(/* const */ char *, rl_compentry_func_t *);
21374c6c9c2Sjdolecek void		 rl_display_match_list(char **, int, int);
21474c6c9c2Sjdolecek 
21574c6c9c2Sjdolecek int		 rl_insert(int, int);
216ea3813edSchristos int		 rl_insert_text(const char *);
21752b10dfdSchristos int		 rl_reset_terminal(const char *);
21827916d7cSchristos void		 rl_resize_terminal(void);
219ea3813edSchristos int		 rl_bind_key(int, rl_command_func_t *);
220552716dcSchristos int		 rl_newline(int, int);
221552716dcSchristos void		 rl_callback_read_char(void);
2220804279dSchristos void		 rl_callback_handler_install(const char *, rl_vcpfunc_t *);
223552716dcSchristos void		 rl_callback_handler_remove(void);
224552716dcSchristos void		 rl_redisplay(void);
225552716dcSchristos int		 rl_get_previous_history(int, int);
2265d79eff8Schristos void		 rl_prep_terminal(int);
2275d79eff8Schristos void		 rl_deprep_terminal(void);
2285d79eff8Schristos int		 rl_read_init_file(const char *);
2295d79eff8Schristos int		 rl_parse_and_bind(const char *);
230a76abbedSchristos int		 rl_variable_bind(const char *, const char *);
23152b10dfdSchristos int		 rl_stuff_char(int);
2320b610931Schristos int		 rl_add_defun(const char *, rl_command_func_t *, int);
233ea3813edSchristos HISTORY_STATE	*history_get_history_state(void);
2346b8a7930Schristos void		 rl_get_screen_size(int *, int *);
2356b8a7930Schristos void		 rl_set_screen_size(int, int);
2366b8a7930Schristos char		*rl_filename_completion_function(const char *, int);
2376b8a7930Schristos int		 _rl_abort_internal(void);
2386b8a7930Schristos int		 _rl_qsort_string_compare(char **, char **);
2392d9dad6fSchristos char	       **rl_completion_matches(const char *, rl_compentry_func_t *);
2403bbc95f3Schristos void		 rl_forced_update_display(void);
241d052ee7bSchristos int		 rl_set_prompt(const char *);
2426e1c968dSchristos int		 rl_on_new_line(void);
24385390d73Schristos void		 rl_reset_after_signal(void);
24485390d73Schristos void		 rl_echo_signal_char(int);
2457f1c6a0bSchristos int		 rl_crlf(void);
2467f1c6a0bSchristos int		 rl_ding(void);
247b7e56637Schristos char 		*rl_copy_text(int, int);
248b7e56637Schristos void		 rl_replace_line(const char *, int);
249001f54a4Schristos int		 rl_delete_text(int, int);
250daa505a9Schristos void 		 rl_message(const char *format, ...)
251daa505a9Schristos     __attribute__((__format__(__printf__, 1, 2)));
252b7e56637Schristos void		 rl_save_prompt(void);
253b7e56637Schristos void		 rl_restore_prompt(void);
254166e18a7Schristos 
255166e18a7Schristos /*
256166e18a7Schristos  * The following are not implemented
257166e18a7Schristos  */
2586b8a7930Schristos int		 rl_kill_text(int, int);
259166e18a7Schristos Keymap		 rl_get_keymap(void);
2606b8a7930Schristos void		 rl_set_keymap(Keymap);
261166e18a7Schristos Keymap		 rl_make_bare_keymap(void);
262166e18a7Schristos int		 rl_generic_bind(int, const char *, const char *, Keymap);
263ea3813edSchristos int		 rl_bind_key_in_map(int, rl_command_func_t *, Keymap);
264001f54a4Schristos int		 rl_set_key(const char *, rl_command_func_t *, Keymap);
265ea3813edSchristos void		 rl_cleanup_after_signal(void);
266ea3813edSchristos void		 rl_free_line_state(void);
26792b17720Schristos int		 rl_set_keyboard_input_timeout(int);
2687f1c6a0bSchristos int		 rl_abort(int, int);
2697f1c6a0bSchristos int	         rl_set_keymap_name(const char *, Keymap);
2707f1c6a0bSchristos histdata_t	 free_history_entry(HIST_ENTRY *);
2717f1c6a0bSchristos void		 _rl_erase_entire_line(void);
27292b17720Schristos 
2730e0ac6b7Schristos #ifdef __cplusplus
2740e0ac6b7Schristos }
2750e0ac6b7Schristos #endif
27674c6c9c2Sjdolecek 
27774c6c9c2Sjdolecek #endif /* _READLINE_H_ */
278