1 /* $OpenBSD: readline.h,v 1.7 2016/03/20 23:48:27 schwarze Exp $ */ 2 /* $NetBSD: readline.h,v 1.31 2010/08/04 20:29:18 christos 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 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 #ifndef _READLINE_H_ 33 #define _READLINE_H_ 34 35 #include <sys/types.h> 36 #include <stdio.h> 37 38 /* list of readline stuff supported by editline library's readline wrapper */ 39 40 /* typedefs */ 41 typedef int Function(const char *, int); 42 typedef void VFunction(void); 43 typedef void VCPFunction(char *); 44 typedef char *CPFunction(const char *, int); 45 typedef char **CPPFunction(const char *, int, int); 46 typedef char *rl_compentry_func_t(const char *, int); 47 typedef int rl_command_func_t(int, int); 48 49 /* only supports length */ 50 typedef struct { 51 int length; 52 } HISTORY_STATE; 53 54 typedef void *histdata_t; 55 56 typedef struct _hist_entry { 57 const char *line; 58 histdata_t data; 59 } HIST_ENTRY; 60 61 typedef 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 71 typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE]; 72 typedef 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 98 extern "C" { 99 #endif 100 extern const char *rl_library_version; 101 extern int rl_readline_version; 102 extern char *rl_readline_name; 103 extern FILE *rl_instream; 104 extern FILE *rl_outstream; 105 extern char *rl_line_buffer; 106 extern int rl_point, rl_end; 107 extern int history_base, history_length; 108 extern int max_input_history; 109 extern char *rl_basic_word_break_characters; 110 extern char *rl_completer_word_break_characters; 111 extern char *rl_completer_quote_characters; 112 extern Function *rl_completion_entry_function; 113 extern CPPFunction *rl_attempted_completion_function; 114 extern int rl_attempted_completion_over; 115 extern int rl_completion_type; 116 extern int rl_completion_query_items; 117 extern char *rl_special_prefixes; 118 extern int rl_completion_append_character; 119 extern int rl_inhibit_completion; 120 extern Function *rl_pre_input_hook; 121 extern Function *rl_startup_hook; 122 extern char *rl_terminal_name; 123 extern int rl_already_prompted; 124 extern char *rl_prompt; 125 /* 126 * The following is not implemented 127 */ 128 extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, 129 emacs_meta_keymap, 130 emacs_ctlx_keymap; 131 extern int rl_filename_completion_desired; 132 extern int rl_ignore_completion_duplicates; 133 extern int (*rl_getc_function)(FILE *); 134 extern VFunction *rl_redisplay_function; 135 extern VFunction *rl_completion_display_matches_hook; 136 extern VFunction *rl_prep_term_function; 137 extern VFunction *rl_deprep_term_function; 138 extern int readline_echoing_p; 139 extern int _rl_print_completions_horizontally; 140 141 /* supported functions */ 142 char *readline(const char *); 143 int rl_initialize(void); 144 145 void using_history(void); 146 int add_history(const char *); 147 void clear_history(void); 148 void stifle_history(int); 149 int unstifle_history(void); 150 int history_is_stifled(void); 151 int where_history(void); 152 HIST_ENTRY *current_history(void); 153 HIST_ENTRY *history_get(int); 154 HIST_ENTRY *remove_history(int); 155 HIST_ENTRY *replace_history_entry(int, const char *, histdata_t); 156 int history_total_bytes(void); 157 int history_set_pos(int); 158 HIST_ENTRY *previous_history(void); 159 HIST_ENTRY *next_history(void); 160 int history_search(const char *, int); 161 int history_search_prefix(const char *, int); 162 int history_search_pos(const char *, int, int); 163 int read_history(const char *); 164 int write_history(const char *); 165 int history_truncate_file (const char *, int); 166 int history_expand(char *, char **); 167 char **history_tokenize(const char *); 168 const char *get_history_event(const char *, int *, int); 169 char *history_arg_extract(int, int, const char *); 170 171 char *tilde_expand(char *); 172 char *filename_completion_function(const char *, int); 173 char *username_completion_function(const char *, int); 174 int rl_complete(int, int); 175 int rl_read_key(void); 176 char **completion_matches(const char *, CPFunction *); 177 void rl_display_match_list(char **, int, int); 178 179 int rl_insert(int, int); 180 int rl_insert_text(const char *); 181 void rl_reset_terminal(const char *); 182 int rl_bind_key(int, rl_command_func_t *); 183 int rl_newline(int, int); 184 void rl_callback_read_char(void); 185 void rl_callback_handler_install(const char *, VCPFunction *); 186 void rl_callback_handler_remove(void); 187 void rl_redisplay(void); 188 int rl_get_previous_history(int, int); 189 void rl_prep_terminal(int); 190 void rl_deprep_terminal(void); 191 int rl_read_init_file(const char *); 192 int rl_parse_and_bind(const char *); 193 int rl_variable_bind(const char *, const char *); 194 void rl_stuff_char(int); 195 int rl_add_defun(const char *, Function *, int); 196 HISTORY_STATE *history_get_history_state(void); 197 void rl_get_screen_size(int *, int *); 198 void rl_set_screen_size(int, int); 199 char *rl_filename_completion_function (const char *, int); 200 int _rl_abort_internal(void); 201 int _rl_qsort_string_compare(char **, char **); 202 char **rl_completion_matches(const char *, rl_compentry_func_t *); 203 void rl_forced_update_display(void); 204 int rl_set_prompt(const char *); 205 int rl_on_new_line(void); 206 207 /* 208 * The following are not implemented 209 */ 210 int rl_kill_text(int, int); 211 Keymap rl_get_keymap(void); 212 void rl_set_keymap(Keymap); 213 Keymap rl_make_bare_keymap(void); 214 int rl_generic_bind(int, const char *, const char *, Keymap); 215 int rl_bind_key_in_map(int, rl_command_func_t *, Keymap); 216 void rl_cleanup_after_signal(void); 217 void rl_free_line_state(void); 218 int rl_set_keyboard_input_timeout(int); 219 #ifdef __cplusplus 220 } 221 #endif 222 223 #endif /* _READLINE_H_ */ 224