1 /* $OpenBSD: readline.h,v 1.3 2008/06/26 05:42:05 ray Exp $ */ 2 /* $NetBSD: readline.h,v 1.10 2003/10/27 22:26:35 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 37 /* list of readline stuff supported by editline library's readline wrapper */ 38 39 /* typedefs */ 40 typedef int Function(const char *, int); 41 typedef void VFunction(void); 42 typedef char *CPFunction(const char *, int); 43 typedef char **CPPFunction(const char *, int, int); 44 45 typedef struct _hist_entry { 46 const char *line; 47 const char *data; 48 } HIST_ENTRY; 49 50 typedef struct _keymap_entry { 51 char type; 52 #define ISFUNC 0 53 #define ISKMAP 1 54 #define ISMACR 2 55 Function *function; 56 } KEYMAP_ENTRY; 57 58 #define KEYMAP_SIZE 256 59 60 typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE]; 61 typedef KEYMAP_ENTRY *Keymap; 62 63 #define control_character_threshold 0x20 64 #define control_character_bit 0x40 65 66 #ifndef CTRL 67 #include <sys/ioctl.h> 68 #include <sys/ttydefaults.h> 69 #ifndef CTRL 70 #define CTRL(c) ((c) & 037) 71 #endif 72 #endif 73 #ifndef UNCTRL 74 #define UNCTRL(c) (((c) - 'a' + 'A')|control_character_bit) 75 #endif 76 77 #define RUBOUT 0x7f 78 #define ABORT_CHAR CTRL('G') 79 80 /* global variables used by readline enabled applications */ 81 #ifdef __cplusplus 82 extern "C" { 83 #endif 84 extern const char *rl_library_version; 85 extern char *rl_readline_name; 86 extern FILE *rl_instream; 87 extern FILE *rl_outstream; 88 extern char *rl_line_buffer; 89 extern int rl_point, rl_end; 90 extern int history_base, history_length; 91 extern int max_input_history; 92 extern char *rl_basic_word_break_characters; 93 extern char *rl_completer_word_break_characters; 94 extern char *rl_completer_quote_characters; 95 extern Function *rl_completion_entry_function; 96 extern CPPFunction *rl_attempted_completion_function; 97 extern int rl_completion_type; 98 extern int rl_completion_query_items; 99 extern char *rl_special_prefixes; 100 extern int rl_completion_append_character; 101 extern Function *rl_pre_input_hook; 102 extern Function *rl_startup_hook; 103 extern char *rl_terminal_name; 104 extern int rl_already_prompted; 105 extern char *rl_prompt; 106 extern VFunction *rl_event_hook; 107 108 /* 109 * The following is not implemented 110 */ 111 extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, 112 emacs_meta_keymap, 113 emacs_ctlx_keymap; 114 extern int rl_filename_completion_desired; 115 extern int rl_ignore_completion_duplicates; 116 extern Function *rl_getc_function; 117 extern VFunction *rl_redisplay_function; 118 extern VFunction *rl_completion_display_matches_hook; 119 extern VFunction *rl_prep_term_function; 120 extern VFunction *rl_deprep_term_function; 121 122 /* supported functions */ 123 char *readline(const char *); 124 int rl_initialize(void); 125 126 void using_history(void); 127 int add_history(const char *); 128 void clear_history(void); 129 void stifle_history(int); 130 int unstifle_history(void); 131 int history_is_stifled(void); 132 int where_history(void); 133 HIST_ENTRY *current_history(void); 134 HIST_ENTRY *history_get(int); 135 int history_total_bytes(void); 136 int history_set_pos(int); 137 HIST_ENTRY *previous_history(void); 138 HIST_ENTRY *next_history(void); 139 int history_search(const char *, int); 140 int history_search_prefix(const char *, int); 141 int history_search_pos(const char *, int, int); 142 int read_history(const char *); 143 int write_history(const char *); 144 int history_expand(char *, char **); 145 char **history_tokenize(const char *); 146 const char *get_history_event(const char *, int *, int); 147 char *history_arg_extract(int, int, const char *); 148 149 char *tilde_expand(char *); 150 char *filename_completion_function(const char *, int); 151 char *username_completion_function(const char *, int); 152 int rl_complete(int, int); 153 int rl_read_key(void); 154 char **completion_matches(const char *, CPFunction *); 155 void rl_display_match_list(char **, int, int); 156 157 int rl_insert(int, int); 158 void rl_reset_terminal(const char *); 159 int rl_bind_key(int, int (*)(int, int)); 160 int rl_newline(int, int); 161 void rl_callback_read_char(void); 162 void rl_callback_handler_install(const char *, VFunction *); 163 void rl_callback_handler_remove(void); 164 void rl_redisplay(void); 165 int rl_get_previous_history(int, int); 166 void rl_prep_terminal(int); 167 void rl_deprep_terminal(void); 168 int rl_read_init_file(const char *); 169 int rl_parse_and_bind(const char *); 170 void rl_stuff_char(int); 171 int rl_add_defun(const char *, Function *, int); 172 173 /* 174 * The following are not implemented 175 */ 176 Keymap rl_get_keymap(void); 177 Keymap rl_make_bare_keymap(void); 178 int rl_generic_bind(int, const char *, const char *, Keymap); 179 int rl_bind_key_in_map(int, Function *, Keymap); 180 #ifdef __cplusplus 181 } 182 #endif 183 184 #endif /* _READLINE_H_ */ 185