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