1/*	$NetBSD: readline.h,v 1.53 2022/02/19 17:45:02 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	  Function(const char *, int);
41typedef char     *CPFunction(const char *, int);
42typedef void	  VFunction(void);
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 int	  rl_command_func_t(int, int);
47typedef int	  rl_hook_func_t(void);
48typedef int       rl_icppfunc_t(char **);
49
50/* only supports length */
51typedef struct {
52	int length;
53} HISTORY_STATE;
54
55typedef void *histdata_t;
56
57typedef struct _hist_entry {
58	const char	*line;
59	histdata_t	 data;
60} HIST_ENTRY;
61
62typedef struct _keymap_entry {
63	char type;
64#define ISFUNC	0
65#define ISKMAP	1
66#define ISMACR	2
67	Function *function;
68} KEYMAP_ENTRY;
69
70#define KEYMAP_SIZE	256
71
72typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE];
73typedef KEYMAP_ENTRY *Keymap;
74
75#define control_character_threshold	0x20
76#define control_character_bit		0x40
77
78#ifndef CTRL
79#include <sys/ioctl.h>
80#if !defined(__sun) && !defined(__hpux) && !defined(_AIX)
81#include <sys/ttydefaults.h>
82#endif
83#ifndef CTRL
84#define CTRL(c)		((c) & 037)
85#endif
86#endif
87#ifndef UNCTRL
88#define UNCTRL(c)	(((c) - 'a' + 'A')|control_character_bit)
89#endif
90
91#define RUBOUT		0x7f
92#define ABORT_CHAR	CTRL('G')
93#define RL_READLINE_VERSION	0x0402
94#define RL_PROMPT_START_IGNORE	'\1'
95#define RL_PROMPT_END_IGNORE	'\2'
96
97#define RL_STATE_NONE		0x000000
98#define RL_STATE_DONE		0x000001
99
100#define RL_SETSTATE(x)		(rl_readline_state |= ((unsigned long) x))
101#define RL_UNSETSTATE(x)	(rl_readline_state &= ~((unsigned long) x))
102#define RL_ISSTATE(x)		(rl_readline_state & ((unsigned long) x))
103
104/* global variables used by readline enabled applications */
105#ifdef __cplusplus
106extern "C" {
107#endif
108extern const char	*rl_library_version;
109extern int		rl_readline_version;
110extern const char	*rl_readline_name;
111extern FILE		*rl_instream;
112extern FILE		*rl_outstream;
113extern char		*rl_line_buffer;
114extern int		 rl_point, rl_end;
115extern int		 history_base, history_length;
116extern int		 max_input_history;
117extern const char	*rl_basic_quote_characters;
118extern const char	*rl_basic_word_break_characters;
119extern char		*rl_completer_word_break_characters;
120extern const char	*rl_completer_quote_characters;
121extern rl_compentry_func_t *rl_completion_entry_function;
122extern char		*(*rl_completion_word_break_hook)(void);
123extern rl_completion_func_t *rl_attempted_completion_function;
124extern int		 rl_attempted_completion_over;
125extern int		rl_completion_type;
126extern int		rl_completion_query_items;
127extern const char	*rl_special_prefixes;
128extern int		rl_completion_append_character;
129extern int		rl_inhibit_completion;
130extern rl_hook_func_t		*rl_pre_input_hook;
131extern rl_hook_func_t		*rl_startup_hook;
132extern char		*rl_terminal_name;
133extern int		rl_already_prompted;
134extern char		*rl_prompt;
135extern int		rl_done;
136/*
137 * The following is not implemented
138 */
139extern unsigned long	rl_readline_state;
140extern int		rl_catch_signals;
141extern int		rl_catch_sigwinch;
142extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
143			emacs_meta_keymap,
144			emacs_ctlx_keymap;
145extern int		rl_filename_completion_desired;
146extern int		rl_ignore_completion_duplicates;
147extern int		(*rl_getc_function)(FILE *);
148extern VFunction	*rl_redisplay_function;
149extern VFunction	*rl_completion_display_matches_hook;
150extern VFunction	*rl_prep_term_function;
151extern VFunction	*rl_deprep_term_function;
152extern rl_hook_func_t	*rl_event_hook;
153extern int		readline_echoing_p;
154extern int		_rl_print_completions_horizontally;
155extern int		_rl_complete_mark_directories;
156extern rl_icppfunc_t	*rl_directory_completion_hook;
157extern int		rl_completion_suppress_append;
158extern int		rl_sort_completion_matches;
159extern int		_rl_completion_prefix_display_length;
160extern int		_rl_echoing_p;
161extern int		history_max_entries;
162extern char		*rl_display_prompt;
163extern int		rl_erase_empty_line;
164
165/* supported functions */
166char		*readline(const char *);
167int		 rl_initialize(void);
168
169void		 using_history(void);
170int		 add_history(const char *);
171void		 clear_history(void);
172int		 append_history(int, const char *);
173void		 stifle_history(int);
174int		 unstifle_history(void);
175int		 history_is_stifled(void);
176int		 where_history(void);
177HIST_ENTRY	*current_history(void);
178HIST_ENTRY	*history_get(int);
179HIST_ENTRY	*remove_history(int);
180HIST_ENTRY	*replace_history_entry(int, const char *, histdata_t);
181int		 history_total_bytes(void);
182int		 history_set_pos(int);
183HIST_ENTRY	*previous_history(void);
184HIST_ENTRY	*next_history(void);
185HIST_ENTRY     **history_list(void);
186int		 history_search(const char *, int);
187int		 history_search_prefix(const char *, int);
188int		 history_search_pos(const char *, int, int);
189int		 read_history(const char *);
190int		 write_history(const char *);
191int		 history_truncate_file(const char *, int);
192int		 history_expand(char *, char **);
193char	       **history_tokenize(const char *);
194const char	*get_history_event(const char *, int *, int);
195char		*history_arg_extract(int, int, const char *);
196
197char		*tilde_expand(char *);
198char		*filename_completion_function(const char *, int);
199char		*username_completion_function(const char *, int);
200int		 rl_complete(int, int);
201int		 rl_read_key(void);
202char	       **completion_matches(/* const */ char *, rl_compentry_func_t *);
203void		 rl_display_match_list(char **, int, int);
204
205int		 rl_insert(int, int);
206int		 rl_insert_text(const char *);
207int		 rl_reset_terminal(const char *);
208void		 rl_resize_terminal(void);
209int		 rl_bind_key(int, rl_command_func_t *);
210int		 rl_newline(int, int);
211void		 rl_callback_read_char(void);
212void		 rl_callback_handler_install(const char *, rl_vcpfunc_t *);
213void		 rl_callback_handler_remove(void);
214void		 rl_redisplay(void);
215int		 rl_get_previous_history(int, int);
216void		 rl_prep_terminal(int);
217void		 rl_deprep_terminal(void);
218int		 rl_read_init_file(const char *);
219int		 rl_parse_and_bind(const char *);
220int		 rl_variable_bind(const char *, const char *);
221int		 rl_stuff_char(int);
222int		 rl_add_defun(const char *, rl_command_func_t *, int);
223HISTORY_STATE	*history_get_history_state(void);
224void		 rl_get_screen_size(int *, int *);
225void		 rl_set_screen_size(int, int);
226char		*rl_filename_completion_function(const char *, int);
227int		 _rl_abort_internal(void);
228int		 _rl_qsort_string_compare(char **, char **);
229char	       **rl_completion_matches(const char *, rl_compentry_func_t *);
230void		 rl_forced_update_display(void);
231int		 rl_set_prompt(const char *);
232int		 rl_on_new_line(void);
233void		 rl_reset_after_signal(void);
234void		 rl_echo_signal_char(int);
235int		 rl_crlf(void);
236int		 rl_ding(void);
237char 		*rl_copy_text(int, int);
238void		 rl_replace_line(const char *, int);
239int		 rl_delete_text(int, int);
240void 		 rl_message(const char *format, ...)
241    __attribute__((__format__(__printf__, 1, 2)));
242void		 rl_save_prompt(void);
243void		 rl_restore_prompt(void);
244
245/*
246 * The following are not implemented
247 */
248int		 rl_kill_text(int, int);
249Keymap		 rl_get_keymap(void);
250void		 rl_set_keymap(Keymap);
251Keymap		 rl_make_bare_keymap(void);
252int		 rl_generic_bind(int, const char *, const char *, Keymap);
253int		 rl_bind_key_in_map(int, rl_command_func_t *, Keymap);
254int		 rl_set_key(const char *, rl_command_func_t *, Keymap);
255void		 rl_cleanup_after_signal(void);
256void		 rl_free_line_state(void);
257int		 rl_set_keyboard_input_timeout(int);
258int		 rl_abort(int, int);
259int	         rl_set_keymap_name(const char *, Keymap);
260histdata_t	 free_history_entry(HIST_ENTRY *);
261void		 _rl_erase_entire_line(void);
262
263#ifdef __cplusplus
264}
265#endif
266
267#endif /* _READLINE_H_ */
268