| 1 | /* $NetBSD: readline.h,v 1.47 2021/08/21 12:34:59 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 */ |
| 40 | typedef int Function(const char *, int); |
| 41 | typedef char *CPFunction(const char *, int); |
| 42 | typedef void VFunction(void); |
| 43 | typedef void rl_vcpfunc_t(char *); |
| 44 | typedef char **rl_completion_func_t(const char *, int, int); |
| 45 | typedef char *rl_compentry_func_t(const char *, int); |
| 46 | typedef int rl_command_func_t(int, int); |
| 47 | typedef int rl_hook_func_t(void); |
| 48 | typedef int rl_icppfunc_t(char **); |
| 49 | |
| 50 | /* only supports length */ |
| 51 | typedef struct { |
| 52 | int length; |
| 53 | } HISTORY_STATE; |
| 54 | |
| 55 | typedef void *histdata_t; |
| 56 | |
| 57 | typedef struct _hist_entry { |
| 58 | const char *line; |
| 59 | histdata_t data; |
| 60 | } HIST_ENTRY; |
| 61 | |
| 62 | typedef 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 | |
| 72 | typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE]; |
| 73 | typedef 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 | /* global variables used by readline enabled applications */ |
| 98 | #ifdef __cplusplus |
| 99 | extern "C" { |
| 100 | #endif |
| 101 | extern const char *rl_library_version; |
| 102 | extern int rl_readline_version; |
| 103 | extern const char *rl_readline_name; |
| 104 | extern FILE *rl_instream; |
| 105 | extern FILE *rl_outstream; |
| 106 | extern char *rl_line_buffer; |
| 107 | extern int rl_point, rl_end; |
| 108 | extern int history_base, history_length; |
| 109 | extern int max_input_history; |
| 110 | extern const char *rl_basic_quote_characters; |
| 111 | extern const char *rl_basic_word_break_characters; |
| 112 | extern char *rl_completer_word_break_characters; |
| 113 | extern const char *rl_completer_quote_characters; |
| 114 | extern rl_compentry_func_t *rl_completion_entry_function; |
| 115 | extern char *(*rl_completion_word_break_hook)(void); |
| 116 | extern rl_completion_func_t *rl_attempted_completion_function; |
| 117 | extern int rl_attempted_completion_over; |
| 118 | extern int rl_completion_type; |
| 119 | extern int rl_completion_query_items; |
| 120 | extern const char *rl_special_prefixes; |
| 121 | extern int rl_completion_append_character; |
| 122 | extern int rl_inhibit_completion; |
| 123 | extern Function *rl_pre_input_hook; |
| 124 | extern Function *rl_startup_hook; |
| 125 | extern char *rl_terminal_name; |
| 126 | extern int rl_already_prompted; |
| 127 | extern char *rl_prompt; |
| 128 | extern int rl_done; |
| 129 | /* |
| 130 | * The following is not implemented |
| 131 | */ |
| 132 | extern unsigned long rl_readline_state; |
| 133 | extern int rl_catch_signals; |
| 134 | extern int rl_catch_sigwinch; |
| 135 | extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, |
| 136 | emacs_meta_keymap, |
| 137 | emacs_ctlx_keymap; |
| 138 | extern int rl_filename_completion_desired; |
| 139 | extern int rl_ignore_completion_duplicates; |
| 140 | extern int (*rl_getc_function)(FILE *); |
| 141 | extern VFunction *rl_redisplay_function; |
| 142 | extern VFunction *rl_completion_display_matches_hook; |
| 143 | extern VFunction *rl_prep_term_function; |
| 144 | extern VFunction *rl_deprep_term_function; |
| 145 | extern rl_hook_func_t *rl_event_hook; |
| 146 | extern int readline_echoing_p; |
| 147 | extern int _rl_print_completions_horizontally; |
| 148 | extern int _rl_complete_mark_directories; |
| 149 | extern rl_icppfunc_t *rl_directory_completion_hook; |
| 150 | extern int rl_completion_suppress_append; |
| 151 | extern int rl_sort_completion_matches; |
| 152 | extern int _rl_completion_prefix_display_length; |
| 153 | extern int _rl_echoing_p; |
| 154 | extern int history_max_entries; |
| 155 | extern char *rl_display_prompt; |
| 156 | |
| 157 | /* supported functions */ |
| 158 | char *readline(const char *); |
| 159 | int rl_initialize(void); |
| 160 | |
| 161 | void using_history(void); |
| 162 | int add_history(const char *); |
| 163 | void clear_history(void); |
| 164 | int append_history(int, const char *); |
| 165 | void stifle_history(int); |
| 166 | int unstifle_history(void); |
| 167 | int history_is_stifled(void); |
| 168 | int where_history(void); |
| 169 | HIST_ENTRY *current_history(void); |
| 170 | HIST_ENTRY *history_get(int); |
| 171 | HIST_ENTRY *remove_history(int); |
| 172 | HIST_ENTRY *replace_history_entry(int, const char *, histdata_t); |
| 173 | int history_total_bytes(void); |
| 174 | int history_set_pos(int); |
| 175 | HIST_ENTRY *previous_history(void); |
| 176 | HIST_ENTRY *next_history(void); |
| 177 | HIST_ENTRY **history_list(void); |
| 178 | int history_search(const char *, int); |
| 179 | int history_search_prefix(const char *, int); |
| 180 | int history_search_pos(const char *, int, int); |
| 181 | int read_history(const char *); |
| 182 | int write_history(const char *); |
| 183 | int history_truncate_file (const char *, int); |
| 184 | int history_expand(char *, char **); |
| 185 | char **history_tokenize(const char *); |
| 186 | const char *get_history_event(const char *, int *, int); |
| 187 | char *(int, int, const char *); |
| 188 | |
| 189 | char *tilde_expand(char *); |
| 190 | char *filename_completion_function(const char *, int); |
| 191 | char *username_completion_function(const char *, int); |
| 192 | int rl_complete(int, int); |
| 193 | int rl_read_key(void); |
| 194 | char **completion_matches(/* const */ char *, rl_compentry_func_t *); |
| 195 | void rl_display_match_list(char **, int, int); |
| 196 | |
| 197 | int rl_insert(int, int); |
| 198 | int rl_insert_text(const char *); |
| 199 | int rl_reset_terminal(const char *); |
| 200 | void rl_resize_terminal(void); |
| 201 | int rl_bind_key(int, rl_command_func_t *); |
| 202 | int rl_newline(int, int); |
| 203 | void rl_callback_read_char(void); |
| 204 | void rl_callback_handler_install(const char *, rl_vcpfunc_t *); |
| 205 | void rl_callback_handler_remove(void); |
| 206 | void rl_redisplay(void); |
| 207 | int rl_get_previous_history(int, int); |
| 208 | void rl_prep_terminal(int); |
| 209 | void rl_deprep_terminal(void); |
| 210 | int rl_read_init_file(const char *); |
| 211 | int rl_parse_and_bind(const char *); |
| 212 | int rl_variable_bind(const char *, const char *); |
| 213 | int rl_stuff_char(int); |
| 214 | int rl_add_defun(const char *, rl_command_func_t *, int); |
| 215 | HISTORY_STATE *history_get_history_state(void); |
| 216 | void rl_get_screen_size(int *, int *); |
| 217 | void rl_set_screen_size(int, int); |
| 218 | char *rl_filename_completion_function (const char *, int); |
| 219 | int _rl_abort_internal(void); |
| 220 | int _rl_qsort_string_compare(char **, char **); |
| 221 | char **rl_completion_matches(const char *, rl_compentry_func_t *); |
| 222 | void rl_forced_update_display(void); |
| 223 | int rl_set_prompt(const char *); |
| 224 | int rl_on_new_line(void); |
| 225 | void rl_reset_after_signal(void); |
| 226 | void rl_echo_signal_char(int); |
| 227 | int rl_crlf(void); |
| 228 | int rl_ding(void); |
| 229 | |
| 230 | /* |
| 231 | * The following are not implemented |
| 232 | */ |
| 233 | int rl_kill_text(int, int); |
| 234 | Keymap rl_get_keymap(void); |
| 235 | void rl_set_keymap(Keymap); |
| 236 | Keymap rl_make_bare_keymap(void); |
| 237 | int rl_generic_bind(int, const char *, const char *, Keymap); |
| 238 | int rl_bind_key_in_map(int, rl_command_func_t *, Keymap); |
| 239 | void rl_cleanup_after_signal(void); |
| 240 | void rl_free_line_state(void); |
| 241 | int rl_set_keyboard_input_timeout(int); |
| 242 | int rl_abort(int, int); |
| 243 | int rl_set_keymap_name(const char *, Keymap); |
| 244 | histdata_t free_history_entry(HIST_ENTRY *); |
| 245 | void _rl_erase_entire_line(void); |
| 246 | |
| 247 | #ifdef __cplusplus |
| 248 | } |
| 249 | #endif |
| 250 | |
| 251 | #endif /* _READLINE_H_ */ |
| 252 | |