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