1*7ccfa089Sschwarze /* $OpenBSD: readline.h,v 1.7 2016/03/20 23:48:27 schwarze Exp $ */ 25f805b19Sokan /* $NetBSD: readline.h,v 1.31 2010/08/04 20:29:18 christos Exp $ */ 3d484b7d0Sotto 4d484b7d0Sotto /*- 5d484b7d0Sotto * Copyright (c) 1997 The NetBSD Foundation, Inc. 6d484b7d0Sotto * All rights reserved. 7d484b7d0Sotto * 8d484b7d0Sotto * This code is derived from software contributed to The NetBSD Foundation 9d484b7d0Sotto * by Jaromir Dolecek. 10d484b7d0Sotto * 11d484b7d0Sotto * Redistribution and use in source and binary forms, with or without 12d484b7d0Sotto * modification, are permitted provided that the following conditions 13d484b7d0Sotto * are met: 14d484b7d0Sotto * 1. Redistributions of source code must retain the above copyright 15d484b7d0Sotto * notice, this list of conditions and the following disclaimer. 16d484b7d0Sotto * 2. Redistributions in binary form must reproduce the above copyright 17d484b7d0Sotto * notice, this list of conditions and the following disclaimer in the 18d484b7d0Sotto * documentation and/or other materials provided with the distribution. 19d484b7d0Sotto * 20d484b7d0Sotto * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21d484b7d0Sotto * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22d484b7d0Sotto * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23d484b7d0Sotto * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24d484b7d0Sotto * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25d484b7d0Sotto * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26d484b7d0Sotto * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27d484b7d0Sotto * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28d484b7d0Sotto * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29d484b7d0Sotto * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30d484b7d0Sotto * POSSIBILITY OF SUCH DAMAGE. 31d484b7d0Sotto */ 32d484b7d0Sotto #ifndef _READLINE_H_ 33d484b7d0Sotto #define _READLINE_H_ 34d484b7d0Sotto 35d484b7d0Sotto #include <sys/types.h> 36aed0ee81Snicm #include <stdio.h> 37d484b7d0Sotto 38d484b7d0Sotto /* list of readline stuff supported by editline library's readline wrapper */ 39d484b7d0Sotto 40d484b7d0Sotto /* typedefs */ 41d484b7d0Sotto typedef int Function(const char *, int); 42d484b7d0Sotto typedef void VFunction(void); 43aed0ee81Snicm typedef void VCPFunction(char *); 44d484b7d0Sotto typedef char *CPFunction(const char *, int); 45d484b7d0Sotto typedef char **CPPFunction(const char *, int, int); 46aed0ee81Snicm typedef char *rl_compentry_func_t(const char *, int); 47aed0ee81Snicm typedef int rl_command_func_t(int, int); 48aed0ee81Snicm 49aed0ee81Snicm /* only supports length */ 50aed0ee81Snicm typedef struct { 51aed0ee81Snicm int length; 52aed0ee81Snicm } HISTORY_STATE; 53aed0ee81Snicm 54aed0ee81Snicm typedef void *histdata_t; 55d484b7d0Sotto 56d484b7d0Sotto typedef struct _hist_entry { 57d484b7d0Sotto const char *line; 58aed0ee81Snicm histdata_t data; 59d484b7d0Sotto } HIST_ENTRY; 60d484b7d0Sotto 61d484b7d0Sotto typedef struct _keymap_entry { 62d484b7d0Sotto char type; 63d484b7d0Sotto #define ISFUNC 0 64d484b7d0Sotto #define ISKMAP 1 65d484b7d0Sotto #define ISMACR 2 66d484b7d0Sotto Function *function; 67d484b7d0Sotto } KEYMAP_ENTRY; 68d484b7d0Sotto 69d484b7d0Sotto #define KEYMAP_SIZE 256 70d484b7d0Sotto 71d484b7d0Sotto typedef KEYMAP_ENTRY KEYMAP_ENTRY_ARRAY[KEYMAP_SIZE]; 72d484b7d0Sotto typedef KEYMAP_ENTRY *Keymap; 73d484b7d0Sotto 74d484b7d0Sotto #define control_character_threshold 0x20 75d484b7d0Sotto #define control_character_bit 0x40 76d484b7d0Sotto 77d484b7d0Sotto #ifndef CTRL 78d484b7d0Sotto #include <sys/ioctl.h> 79aed0ee81Snicm #if !defined(__sun) && !defined(__hpux) && !defined(_AIX) 80d484b7d0Sotto #include <sys/ttydefaults.h> 81aed0ee81Snicm #endif 82d484b7d0Sotto #ifndef CTRL 83d484b7d0Sotto #define CTRL(c) ((c) & 037) 84d484b7d0Sotto #endif 85d484b7d0Sotto #endif 86d484b7d0Sotto #ifndef UNCTRL 87d484b7d0Sotto #define UNCTRL(c) (((c) - 'a' + 'A')|control_character_bit) 88d484b7d0Sotto #endif 89d484b7d0Sotto 90d484b7d0Sotto #define RUBOUT 0x7f 91d484b7d0Sotto #define ABORT_CHAR CTRL('G') 92aed0ee81Snicm #define RL_READLINE_VERSION 0x0402 93aed0ee81Snicm #define RL_PROMPT_START_IGNORE '\1' 94aed0ee81Snicm #define RL_PROMPT_END_IGNORE '\2' 95d484b7d0Sotto 96d484b7d0Sotto /* global variables used by readline enabled applications */ 97d484b7d0Sotto #ifdef __cplusplus 98d484b7d0Sotto extern "C" { 99d484b7d0Sotto #endif 100d484b7d0Sotto extern const char *rl_library_version; 101aed0ee81Snicm extern int rl_readline_version; 102d484b7d0Sotto extern char *rl_readline_name; 103d484b7d0Sotto extern FILE *rl_instream; 104d484b7d0Sotto extern FILE *rl_outstream; 105d484b7d0Sotto extern char *rl_line_buffer; 106d484b7d0Sotto extern int rl_point, rl_end; 107d484b7d0Sotto extern int history_base, history_length; 108d484b7d0Sotto extern int max_input_history; 109d484b7d0Sotto extern char *rl_basic_word_break_characters; 110d484b7d0Sotto extern char *rl_completer_word_break_characters; 111d484b7d0Sotto extern char *rl_completer_quote_characters; 112d484b7d0Sotto extern Function *rl_completion_entry_function; 113d484b7d0Sotto extern CPPFunction *rl_attempted_completion_function; 114aed0ee81Snicm extern int rl_attempted_completion_over; 115d484b7d0Sotto extern int rl_completion_type; 116d484b7d0Sotto extern int rl_completion_query_items; 117d484b7d0Sotto extern char *rl_special_prefixes; 118d484b7d0Sotto extern int rl_completion_append_character; 119aed0ee81Snicm extern int rl_inhibit_completion; 120d484b7d0Sotto extern Function *rl_pre_input_hook; 121d484b7d0Sotto extern Function *rl_startup_hook; 122d484b7d0Sotto extern char *rl_terminal_name; 123d484b7d0Sotto extern int rl_already_prompted; 124d484b7d0Sotto extern char *rl_prompt; 125d484b7d0Sotto /* 126d484b7d0Sotto * The following is not implemented 127d484b7d0Sotto */ 128d484b7d0Sotto extern KEYMAP_ENTRY_ARRAY emacs_standard_keymap, 129d484b7d0Sotto emacs_meta_keymap, 130d484b7d0Sotto emacs_ctlx_keymap; 131d484b7d0Sotto extern int rl_filename_completion_desired; 132d484b7d0Sotto extern int rl_ignore_completion_duplicates; 133aed0ee81Snicm extern int (*rl_getc_function)(FILE *); 134d484b7d0Sotto extern VFunction *rl_redisplay_function; 135d484b7d0Sotto extern VFunction *rl_completion_display_matches_hook; 136d484b7d0Sotto extern VFunction *rl_prep_term_function; 137d484b7d0Sotto extern VFunction *rl_deprep_term_function; 138aed0ee81Snicm extern int readline_echoing_p; 139aed0ee81Snicm extern int _rl_print_completions_horizontally; 140d484b7d0Sotto 141d484b7d0Sotto /* supported functions */ 142d484b7d0Sotto char *readline(const char *); 143d484b7d0Sotto int rl_initialize(void); 144d484b7d0Sotto 145d484b7d0Sotto void using_history(void); 146d484b7d0Sotto int add_history(const char *); 147d484b7d0Sotto void clear_history(void); 148d484b7d0Sotto void stifle_history(int); 149d484b7d0Sotto int unstifle_history(void); 150d484b7d0Sotto int history_is_stifled(void); 151d484b7d0Sotto int where_history(void); 152d484b7d0Sotto HIST_ENTRY *current_history(void); 153d484b7d0Sotto HIST_ENTRY *history_get(int); 154aed0ee81Snicm HIST_ENTRY *remove_history(int); 155aed0ee81Snicm HIST_ENTRY *replace_history_entry(int, const char *, histdata_t); 156d484b7d0Sotto int history_total_bytes(void); 157d484b7d0Sotto int history_set_pos(int); 158d484b7d0Sotto HIST_ENTRY *previous_history(void); 159d484b7d0Sotto HIST_ENTRY *next_history(void); 160d484b7d0Sotto int history_search(const char *, int); 161d484b7d0Sotto int history_search_prefix(const char *, int); 162d484b7d0Sotto int history_search_pos(const char *, int, int); 163d484b7d0Sotto int read_history(const char *); 164d484b7d0Sotto int write_history(const char *); 165aed0ee81Snicm int history_truncate_file (const char *, int); 166d484b7d0Sotto int history_expand(char *, char **); 167d484b7d0Sotto char **history_tokenize(const char *); 1686e02e073Sotto const char *get_history_event(const char *, int *, int); 1696e02e073Sotto char *history_arg_extract(int, int, const char *); 170d484b7d0Sotto 171d484b7d0Sotto char *tilde_expand(char *); 172d484b7d0Sotto char *filename_completion_function(const char *, int); 173d484b7d0Sotto char *username_completion_function(const char *, int); 174d484b7d0Sotto int rl_complete(int, int); 175d484b7d0Sotto int rl_read_key(void); 176d484b7d0Sotto char **completion_matches(const char *, CPFunction *); 177d484b7d0Sotto void rl_display_match_list(char **, int, int); 178d484b7d0Sotto 179d484b7d0Sotto int rl_insert(int, int); 180aed0ee81Snicm int rl_insert_text(const char *); 181d484b7d0Sotto void rl_reset_terminal(const char *); 182aed0ee81Snicm int rl_bind_key(int, rl_command_func_t *); 183d484b7d0Sotto int rl_newline(int, int); 184d484b7d0Sotto void rl_callback_read_char(void); 185aed0ee81Snicm void rl_callback_handler_install(const char *, VCPFunction *); 186d484b7d0Sotto void rl_callback_handler_remove(void); 187d484b7d0Sotto void rl_redisplay(void); 188d484b7d0Sotto int rl_get_previous_history(int, int); 1896e02e073Sotto void rl_prep_terminal(int); 1906e02e073Sotto void rl_deprep_terminal(void); 1916e02e073Sotto int rl_read_init_file(const char *); 1926e02e073Sotto int rl_parse_and_bind(const char *); 193aed0ee81Snicm int rl_variable_bind(const char *, const char *); 1946e02e073Sotto void rl_stuff_char(int); 1956e02e073Sotto int rl_add_defun(const char *, Function *, int); 196aed0ee81Snicm HISTORY_STATE *history_get_history_state(void); 197aed0ee81Snicm void rl_get_screen_size(int *, int *); 198aed0ee81Snicm void rl_set_screen_size(int, int); 199aed0ee81Snicm char *rl_filename_completion_function (const char *, int); 200aed0ee81Snicm int _rl_abort_internal(void); 201aed0ee81Snicm int _rl_qsort_string_compare(char **, char **); 202aed0ee81Snicm char **rl_completion_matches(const char *, rl_compentry_func_t *); 203aed0ee81Snicm void rl_forced_update_display(void); 204aed0ee81Snicm int rl_set_prompt(const char *); 2055f805b19Sokan int rl_on_new_line(void); 206d484b7d0Sotto 207d484b7d0Sotto /* 208d484b7d0Sotto * The following are not implemented 209d484b7d0Sotto */ 210aed0ee81Snicm int rl_kill_text(int, int); 211d484b7d0Sotto Keymap rl_get_keymap(void); 212aed0ee81Snicm void rl_set_keymap(Keymap); 213d484b7d0Sotto Keymap rl_make_bare_keymap(void); 214d484b7d0Sotto int rl_generic_bind(int, const char *, const char *, Keymap); 215aed0ee81Snicm int rl_bind_key_in_map(int, rl_command_func_t *, Keymap); 216aed0ee81Snicm void rl_cleanup_after_signal(void); 217aed0ee81Snicm void rl_free_line_state(void); 218e6f9da11Sreyk int rl_set_keyboard_input_timeout(int); 219d484b7d0Sotto #ifdef __cplusplus 220d484b7d0Sotto } 221d484b7d0Sotto #endif 222d484b7d0Sotto 223d484b7d0Sotto #endif /* _READLINE_H_ */ 224