1/*	$NetBSD: readline.h,v 1.3 2005/05/31 02:07:02 lukem Exp $	*/
2/*	from	NetBSD: readline.h,v 1.14 2005/05/27 11:35:07 agc Exp	*/
3
4/*-
5 * Copyright (c) 1997 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jaromir Dolecek.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgement:
21 *	This product includes software developed by the NetBSD
22 *	Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 *    contributors may be used to endorse or promote products derived
25 *    from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39#ifndef _READLINE_H_
40#define _READLINE_H_
41
42#include <sys/types.h>
43
44/* list of readline stuff supported by editline library's readline wrapper */
45
46/* typedefs */
47typedef int	  Function(const char *, int);
48typedef void	  VFunction(void);
49typedef void	  VCPFunction(char *);
50typedef char	 *CPFunction(const char *, int);
51typedef char	**CPPFunction(const char *, int, int);
52
53typedef struct _hist_entry {
54	const char	*line;
55	const char	*data;
56} HIST_ENTRY;
57
58typedef struct _keymap_entry {
59	char type;
60#define ISFUNC	0
61#define ISKMAP	1
62#define ISMACR	2
63	Function *function;
64} KEYMAP_ENTRY;
65
66#define KEYMAP_SIZE	256
67
68typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE];
69typedef KEYMAP_ENTRY *Keymap;
70
71#define control_character_threshold	0x20
72#define control_character_bit		0x40
73
74#ifndef CTRL
75#include <sys/ioctl.h>
76#if !defined(__sun__) && !defined(__hpux__)
77#include <sys/ttydefaults.h>
78#endif
79#ifndef CTRL
80#define CTRL(c)		((c) & 037)
81#endif
82#endif
83#ifndef UNCTRL
84#define UNCTRL(c)	(((c) - 'a' + 'A')|control_character_bit)
85#endif
86
87#define RUBOUT		0x7f
88#define ABORT_CHAR	CTRL('G')
89
90/* global variables used by readline enabled applications */
91#ifdef __cplusplus
92extern "C" {
93#endif
94extern const char	*rl_library_version;
95extern char		*rl_readline_name;
96extern FILE		*rl_instream;
97extern FILE		*rl_outstream;
98extern char		*rl_line_buffer;
99extern int		 rl_point, rl_end;
100extern int		 history_base, history_length;
101extern int		 max_input_history;
102extern char		*rl_basic_word_break_characters;
103extern char		*rl_completer_word_break_characters;
104extern char		*rl_completer_quote_characters;
105extern Function		*rl_completion_entry_function;
106extern CPPFunction	*rl_attempted_completion_function;
107extern int		 rl_attempted_completion_over;
108extern int		rl_completion_type;
109extern int		rl_completion_query_items;
110extern char		*rl_special_prefixes;
111extern int		rl_completion_append_character;
112extern int		rl_inhibit_completion;
113extern Function		*rl_pre_input_hook;
114extern Function		*rl_startup_hook;
115extern char		*rl_terminal_name;
116extern int		rl_already_prompted;
117extern char		*rl_prompt;
118/*
119 * The following is not implemented
120 */
121extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap,
122			emacs_meta_keymap,
123			emacs_ctlx_keymap;
124extern int		rl_filename_completion_desired;
125extern int		rl_ignore_completion_duplicates;
126extern Function		*rl_getc_function;
127extern VFunction	*rl_redisplay_function;
128extern VFunction	*rl_completion_display_matches_hook;
129extern VFunction	*rl_prep_term_function;
130extern VFunction	*rl_deprep_term_function;
131
132/* supported functions */
133char		*readline(const char *);
134int		 rl_initialize(void);
135
136void		 using_history(void);
137int		 add_history(const char *);
138void		 clear_history(void);
139void		 stifle_history(int);
140int		 unstifle_history(void);
141int		 history_is_stifled(void);
142int		 where_history(void);
143HIST_ENTRY	*current_history(void);
144HIST_ENTRY	*history_get(int);
145int		 history_total_bytes(void);
146int		 history_set_pos(int);
147HIST_ENTRY	*previous_history(void);
148HIST_ENTRY	*next_history(void);
149int		 history_search(const char *, int);
150int		 history_search_prefix(const char *, int);
151int		 history_search_pos(const char *, int, int);
152int		 read_history(const char *);
153int		 write_history(const char *);
154int		 history_expand(char *, char **);
155char	       **history_tokenize(const char *);
156const char	*get_history_event(const char *, int *, int);
157char		*history_arg_extract(int, int, const char *);
158
159char		*tilde_expand(char *);
160char		*filename_completion_function(const char *, int);
161char		*username_completion_function(const char *, int);
162int		 rl_complete(int, int);
163int		 rl_read_key(void);
164char	       **completion_matches(const char *, CPFunction *);
165void		 rl_display_match_list(char **, int, int);
166
167int		 rl_insert(int, int);
168void		 rl_reset_terminal(const char *);
169int		 rl_bind_key(int, int (*)(int, int));
170int		 rl_newline(int, int);
171void		 rl_callback_read_char(void);
172void		 rl_callback_handler_install(const char *, VCPFunction *);
173void		 rl_callback_handler_remove(void);
174void		 rl_redisplay(void);
175int		 rl_get_previous_history(int, int);
176void		 rl_prep_terminal(int);
177void		 rl_deprep_terminal(void);
178int		 rl_read_init_file(const char *);
179int		 rl_parse_and_bind(const char *);
180int		 rl_variable_bind(const char *, const char *);
181void		 rl_stuff_char(int);
182int		 rl_add_defun(const char *, Function *, int);
183
184/*
185 * The following are not implemented
186 */
187Keymap		 rl_get_keymap(void);
188Keymap		 rl_make_bare_keymap(void);
189int		 rl_generic_bind(int, const char *, const char *, Keymap);
190int		 rl_bind_key_in_map(int, Function *, Keymap);
191#ifdef __cplusplus
192}
193#endif
194
195#endif /* _READLINE_H_ */
196