1*cdf8408cSAntonio Huete Jimenez /* $NetBSD: readline.h,v 1.53 2022/02/19 17:45:02 christos Exp $ */ 232fe07f8SJohn Marino 332fe07f8SJohn Marino /*- 432fe07f8SJohn Marino * Copyright (c) 1997 The NetBSD Foundation, Inc. 532fe07f8SJohn Marino * All rights reserved. 632fe07f8SJohn Marino * 732fe07f8SJohn Marino * This code is derived from software contributed to The NetBSD Foundation 832fe07f8SJohn Marino * by Jaromir Dolecek. 932fe07f8SJohn Marino * 1032fe07f8SJohn Marino * Redistribution and use in source and binary forms, with or without 1132fe07f8SJohn Marino * modification, are permitted provided that the following conditions 1232fe07f8SJohn Marino * are met: 1332fe07f8SJohn Marino * 1. Redistributions of source code must retain the above copyright 1432fe07f8SJohn Marino * notice, this list of conditions and the following disclaimer. 1532fe07f8SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright 1632fe07f8SJohn Marino * notice, this list of conditions and the following disclaimer in the 1732fe07f8SJohn Marino * documentation and/or other materials provided with the distribution. 1832fe07f8SJohn Marino * 1932fe07f8SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2032fe07f8SJohn Marino * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2132fe07f8SJohn Marino * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2232fe07f8SJohn Marino * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2332fe07f8SJohn Marino * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2432fe07f8SJohn Marino * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2532fe07f8SJohn Marino * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2632fe07f8SJohn Marino * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2732fe07f8SJohn Marino * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2832fe07f8SJohn Marino * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2932fe07f8SJohn Marino * POSSIBILITY OF SUCH DAMAGE. 3032fe07f8SJohn Marino */ 3132fe07f8SJohn Marino #ifndef _READLINE_H_ 3232fe07f8SJohn Marino #define _READLINE_H_ 3332fe07f8SJohn Marino 3432fe07f8SJohn Marino #include <sys/types.h> 3532fe07f8SJohn Marino #include <stdio.h> 3632fe07f8SJohn Marino 3732fe07f8SJohn Marino /* list of readline stuff supported by editline library's readline wrapper */ 3832fe07f8SJohn Marino 3932fe07f8SJohn Marino /* typedefs */ 4032fe07f8SJohn Marino typedef int Function(const char *, int); 41ae19eda8Szrj typedef char *CPFunction(const char *, int); 4232fe07f8SJohn Marino typedef void VFunction(void); 4312db70c8Szrj typedef void rl_vcpfunc_t(char *); 4412db70c8Szrj typedef char **rl_completion_func_t(const char *, int, int); 4532fe07f8SJohn Marino typedef char *rl_compentry_func_t(const char *, int); 4632fe07f8SJohn Marino typedef int rl_command_func_t(int, int); 47ae19eda8Szrj typedef int rl_hook_func_t(void); 48*cdf8408cSAntonio Huete Jimenez typedef int rl_icppfunc_t(char **); 4932fe07f8SJohn Marino 5032fe07f8SJohn Marino /* only supports length */ 5132fe07f8SJohn Marino typedef struct { 5232fe07f8SJohn Marino int length; 5332fe07f8SJohn Marino } HISTORY_STATE; 5432fe07f8SJohn Marino 5532fe07f8SJohn Marino typedef void *histdata_t; 5632fe07f8SJohn Marino 5732fe07f8SJohn Marino typedef struct _hist_entry { 5832fe07f8SJohn Marino const char *line; 5932fe07f8SJohn Marino histdata_t data; 6032fe07f8SJohn Marino } HIST_ENTRY; 6132fe07f8SJohn Marino 6232fe07f8SJohn Marino typedef struct _keymap_entry { 6332fe07f8SJohn Marino char type; 6432fe07f8SJohn Marino #define ISFUNC 0 6532fe07f8SJohn Marino #define ISKMAP 1 6632fe07f8SJohn Marino #define ISMACR 2 6732fe07f8SJohn Marino Function *function; 6832fe07f8SJohn Marino } KEYMAP_ENTRY; 6932fe07f8SJohn Marino 7032fe07f8SJohn Marino #define KEYMAP_SIZE 256 7132fe07f8SJohn Marino 7232fe07f8SJohn Marino typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE]; 7332fe07f8SJohn Marino typedef KEYMAP_ENTRY *Keymap; 7432fe07f8SJohn Marino 7532fe07f8SJohn Marino #define control_character_threshold 0x20 7632fe07f8SJohn Marino #define control_character_bit 0x40 7732fe07f8SJohn Marino 7832fe07f8SJohn Marino #ifndef CTRL 7932fe07f8SJohn Marino #include <sys/ioctl.h> 8032fe07f8SJohn Marino #if !defined(__sun) && !defined(__hpux) && !defined(_AIX) 8132fe07f8SJohn Marino #include <sys/ttydefaults.h> 8232fe07f8SJohn Marino #endif 8332fe07f8SJohn Marino #ifndef CTRL 8432fe07f8SJohn Marino #define CTRL(c) ((c) & 037) 8532fe07f8SJohn Marino #endif 8632fe07f8SJohn Marino #endif 8732fe07f8SJohn Marino #ifndef UNCTRL 8832fe07f8SJohn Marino #define UNCTRL(c) (((c) - 'a' + 'A')|control_character_bit) 8932fe07f8SJohn Marino #endif 9032fe07f8SJohn Marino 9132fe07f8SJohn Marino #define RUBOUT 0x7f 9232fe07f8SJohn Marino #define ABORT_CHAR CTRL('G') 9332fe07f8SJohn Marino #define RL_READLINE_VERSION 0x0402 9432fe07f8SJohn Marino #define RL_PROMPT_START_IGNORE '\1' 9532fe07f8SJohn Marino #define RL_PROMPT_END_IGNORE '\2' 9632fe07f8SJohn Marino 97*cdf8408cSAntonio Huete Jimenez #define RL_STATE_NONE 0x000000 98*cdf8408cSAntonio Huete Jimenez #define RL_STATE_DONE 0x000001 99*cdf8408cSAntonio Huete Jimenez 100*cdf8408cSAntonio Huete Jimenez #define RL_SETSTATE(x) (rl_readline_state |= ((unsigned long) x)) 101*cdf8408cSAntonio Huete Jimenez #define RL_UNSETSTATE(x) (rl_readline_state &= ~((unsigned long) x)) 102*cdf8408cSAntonio Huete Jimenez #define RL_ISSTATE(x) (rl_readline_state & ((unsigned long) x)) 103*cdf8408cSAntonio Huete Jimenez 10432fe07f8SJohn Marino /* global variables used by readline enabled applications */ 10532fe07f8SJohn Marino #ifdef __cplusplus 10632fe07f8SJohn Marino extern "C" { 10732fe07f8SJohn Marino #endif 10832fe07f8SJohn Marino extern const char *rl_library_version; 10932fe07f8SJohn Marino extern int rl_readline_version; 110ae19eda8Szrj extern const char *rl_readline_name; 11132fe07f8SJohn Marino extern FILE *rl_instream; 11232fe07f8SJohn Marino extern FILE *rl_outstream; 11332fe07f8SJohn Marino extern char *rl_line_buffer; 11432fe07f8SJohn Marino extern int rl_point, rl_end; 11532fe07f8SJohn Marino extern int history_base, history_length; 11632fe07f8SJohn Marino extern int max_input_history; 117*cdf8408cSAntonio Huete Jimenez extern const char *rl_basic_quote_characters; 118ae19eda8Szrj extern const char *rl_basic_word_break_characters; 11932fe07f8SJohn Marino extern char *rl_completer_word_break_characters; 12060ecde0cSDaniel Fojt extern const char *rl_completer_quote_characters; 12112db70c8Szrj extern rl_compentry_func_t *rl_completion_entry_function; 122c8e4d2bfSJohn Marino extern char *(*rl_completion_word_break_hook)(void); 12312db70c8Szrj extern rl_completion_func_t *rl_attempted_completion_function; 12432fe07f8SJohn Marino extern int rl_attempted_completion_over; 12532fe07f8SJohn Marino extern int rl_completion_type; 12632fe07f8SJohn Marino extern int rl_completion_query_items; 127ae19eda8Szrj extern const char *rl_special_prefixes; 12832fe07f8SJohn Marino extern int rl_completion_append_character; 12932fe07f8SJohn Marino extern int rl_inhibit_completion; 130*cdf8408cSAntonio Huete Jimenez extern rl_hook_func_t *rl_pre_input_hook; 131*cdf8408cSAntonio Huete Jimenez extern rl_hook_func_t *rl_startup_hook; 13232fe07f8SJohn Marino extern char *rl_terminal_name; 13332fe07f8SJohn Marino extern int rl_already_prompted; 13432fe07f8SJohn Marino extern char *rl_prompt; 13512db70c8Szrj extern int rl_done; 13632fe07f8SJohn Marino /* 13732fe07f8SJohn Marino * The following is not implemented 13832fe07f8SJohn Marino */ 139*cdf8408cSAntonio Huete Jimenez extern unsigned long rl_readline_state; 14084b940c1SJohn Marino extern int rl_catch_signals; 14184b940c1SJohn Marino extern int rl_catch_sigwinch; 14232fe07f8SJohn Marino extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, 14332fe07f8SJohn Marino emacs_meta_keymap, 14432fe07f8SJohn Marino emacs_ctlx_keymap; 14532fe07f8SJohn Marino extern int rl_filename_completion_desired; 14632fe07f8SJohn Marino extern int rl_ignore_completion_duplicates; 14732fe07f8SJohn Marino extern int (*rl_getc_function)(FILE *); 14832fe07f8SJohn Marino extern VFunction *rl_redisplay_function; 14932fe07f8SJohn Marino extern VFunction *rl_completion_display_matches_hook; 15032fe07f8SJohn Marino extern VFunction *rl_prep_term_function; 15132fe07f8SJohn Marino extern VFunction *rl_deprep_term_function; 152ae19eda8Szrj extern rl_hook_func_t *rl_event_hook; 15332fe07f8SJohn Marino extern int readline_echoing_p; 15432fe07f8SJohn Marino extern int _rl_print_completions_horizontally; 155*cdf8408cSAntonio Huete Jimenez extern int _rl_complete_mark_directories; 156*cdf8408cSAntonio Huete Jimenez extern rl_icppfunc_t *rl_directory_completion_hook; 157*cdf8408cSAntonio Huete Jimenez extern int rl_completion_suppress_append; 158*cdf8408cSAntonio Huete Jimenez extern int rl_sort_completion_matches; 159*cdf8408cSAntonio Huete Jimenez extern int _rl_completion_prefix_display_length; 160*cdf8408cSAntonio Huete Jimenez extern int _rl_echoing_p; 161*cdf8408cSAntonio Huete Jimenez extern int history_max_entries; 162*cdf8408cSAntonio Huete Jimenez extern char *rl_display_prompt; 163*cdf8408cSAntonio Huete Jimenez extern int rl_erase_empty_line; 16432fe07f8SJohn Marino 16532fe07f8SJohn Marino /* supported functions */ 16632fe07f8SJohn Marino char *readline(const char *); 16732fe07f8SJohn Marino int rl_initialize(void); 16832fe07f8SJohn Marino 16932fe07f8SJohn Marino void using_history(void); 17032fe07f8SJohn Marino int add_history(const char *); 17132fe07f8SJohn Marino void clear_history(void); 172ae19eda8Szrj int append_history(int, const char *); 17332fe07f8SJohn Marino void stifle_history(int); 17432fe07f8SJohn Marino int unstifle_history(void); 17532fe07f8SJohn Marino int history_is_stifled(void); 17632fe07f8SJohn Marino int where_history(void); 17732fe07f8SJohn Marino HIST_ENTRY *current_history(void); 17832fe07f8SJohn Marino HIST_ENTRY *history_get(int); 17932fe07f8SJohn Marino HIST_ENTRY *remove_history(int); 18032fe07f8SJohn Marino HIST_ENTRY *replace_history_entry(int, const char *, histdata_t); 18132fe07f8SJohn Marino int history_total_bytes(void); 18232fe07f8SJohn Marino int history_set_pos(int); 18332fe07f8SJohn Marino HIST_ENTRY *previous_history(void); 18432fe07f8SJohn Marino HIST_ENTRY *next_history(void); 18512db70c8Szrj HIST_ENTRY **history_list(void); 18632fe07f8SJohn Marino int history_search(const char *, int); 18732fe07f8SJohn Marino int history_search_prefix(const char *, int); 18832fe07f8SJohn Marino int history_search_pos(const char *, int, int); 18932fe07f8SJohn Marino int read_history(const char *); 19032fe07f8SJohn Marino int write_history(const char *); 19132fe07f8SJohn Marino int history_truncate_file(const char *, int); 19232fe07f8SJohn Marino int history_expand(char *, char **); 19332fe07f8SJohn Marino char **history_tokenize(const char *); 19432fe07f8SJohn Marino const char *get_history_event(const char *, int *, int); 19532fe07f8SJohn Marino char *history_arg_extract(int, int, const char *); 19632fe07f8SJohn Marino 19732fe07f8SJohn Marino char *tilde_expand(char *); 19832fe07f8SJohn Marino char *filename_completion_function(const char *, int); 19932fe07f8SJohn Marino char *username_completion_function(const char *, int); 20032fe07f8SJohn Marino int rl_complete(int, int); 20132fe07f8SJohn Marino int rl_read_key(void); 202ae19eda8Szrj char **completion_matches(/* const */ char *, rl_compentry_func_t *); 20332fe07f8SJohn Marino void rl_display_match_list(char **, int, int); 20432fe07f8SJohn Marino 20532fe07f8SJohn Marino int rl_insert(int, int); 20632fe07f8SJohn Marino int rl_insert_text(const char *); 207ae19eda8Szrj int rl_reset_terminal(const char *); 208ae19eda8Szrj void rl_resize_terminal(void); 20932fe07f8SJohn Marino int rl_bind_key(int, rl_command_func_t *); 21032fe07f8SJohn Marino int rl_newline(int, int); 21132fe07f8SJohn Marino void rl_callback_read_char(void); 21212db70c8Szrj void rl_callback_handler_install(const char *, rl_vcpfunc_t *); 21332fe07f8SJohn Marino void rl_callback_handler_remove(void); 21432fe07f8SJohn Marino void rl_redisplay(void); 21532fe07f8SJohn Marino int rl_get_previous_history(int, int); 21632fe07f8SJohn Marino void rl_prep_terminal(int); 21732fe07f8SJohn Marino void rl_deprep_terminal(void); 21832fe07f8SJohn Marino int rl_read_init_file(const char *); 21932fe07f8SJohn Marino int rl_parse_and_bind(const char *); 22032fe07f8SJohn Marino int rl_variable_bind(const char *, const char *); 221ae19eda8Szrj int rl_stuff_char(int); 22212db70c8Szrj int rl_add_defun(const char *, rl_command_func_t *, int); 22332fe07f8SJohn Marino HISTORY_STATE *history_get_history_state(void); 22432fe07f8SJohn Marino void rl_get_screen_size(int *, int *); 22532fe07f8SJohn Marino void rl_set_screen_size(int, int); 22632fe07f8SJohn Marino char *rl_filename_completion_function(const char *, int); 22732fe07f8SJohn Marino int _rl_abort_internal(void); 22832fe07f8SJohn Marino int _rl_qsort_string_compare(char **, char **); 22932fe07f8SJohn Marino char **rl_completion_matches(const char *, rl_compentry_func_t *); 23032fe07f8SJohn Marino void rl_forced_update_display(void); 23132fe07f8SJohn Marino int rl_set_prompt(const char *); 23232fe07f8SJohn Marino int rl_on_new_line(void); 233ae19eda8Szrj void rl_reset_after_signal(void); 234ae19eda8Szrj void rl_echo_signal_char(int); 235*cdf8408cSAntonio Huete Jimenez int rl_crlf(void); 236*cdf8408cSAntonio Huete Jimenez int rl_ding(void); 237*cdf8408cSAntonio Huete Jimenez char *rl_copy_text(int, int); 238*cdf8408cSAntonio Huete Jimenez void rl_replace_line(const char *, int); 239*cdf8408cSAntonio Huete Jimenez int rl_delete_text(int, int); 240*cdf8408cSAntonio Huete Jimenez void rl_message(const char *format, ...) 241*cdf8408cSAntonio Huete Jimenez __attribute__((__format__(__printf__, 1, 2))); 242*cdf8408cSAntonio Huete Jimenez void rl_save_prompt(void); 243*cdf8408cSAntonio Huete Jimenez void rl_restore_prompt(void); 24432fe07f8SJohn Marino 24532fe07f8SJohn Marino /* 24632fe07f8SJohn Marino * The following are not implemented 24732fe07f8SJohn Marino */ 24832fe07f8SJohn Marino int rl_kill_text(int, int); 24932fe07f8SJohn Marino Keymap rl_get_keymap(void); 25032fe07f8SJohn Marino void rl_set_keymap(Keymap); 25132fe07f8SJohn Marino Keymap rl_make_bare_keymap(void); 25232fe07f8SJohn Marino int rl_generic_bind(int, const char *, const char *, Keymap); 25332fe07f8SJohn Marino int rl_bind_key_in_map(int, rl_command_func_t *, Keymap); 254*cdf8408cSAntonio Huete Jimenez int rl_set_key(const char *, rl_command_func_t *, Keymap); 25532fe07f8SJohn Marino void rl_cleanup_after_signal(void); 25632fe07f8SJohn Marino void rl_free_line_state(void); 25712db70c8Szrj int rl_set_keyboard_input_timeout(int); 258*cdf8408cSAntonio Huete Jimenez int rl_abort(int, int); 259*cdf8408cSAntonio Huete Jimenez int rl_set_keymap_name(const char *, Keymap); 260*cdf8408cSAntonio Huete Jimenez histdata_t free_history_entry(HIST_ENTRY *); 261*cdf8408cSAntonio Huete Jimenez void _rl_erase_entire_line(void); 26212db70c8Szrj 26332fe07f8SJohn Marino #ifdef __cplusplus 26432fe07f8SJohn Marino } 26532fe07f8SJohn Marino #endif 26632fe07f8SJohn Marino 26732fe07f8SJohn Marino #endif /* _READLINE_H_ */ 268