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