1 /*
2  * Copyright (c) 1992, 1993  Simmule Turner and Rich Salz
3  * All rights reserved.
4  *
5  * This software is not subject to any license of the American Telephone
6  * and Telegraph Company or of the Regents of the University of California.
7  *
8  * Permission is granted to anyone to use this software for any purpose on
9  * any computer system, and to alter it and redistribute it freely, subject
10  * to the following restrictions:
11  * 1. The authors are not responsible for the consequences of use of this
12  *    software, no matter how awful, even if they arise from flaws in it.
13  * 2. The origin of this software must not be misrepresented, either by
14  *    explicit claim or by omission.  Since few users ever read sources,
15  *    credits must appear in the documentation.
16  * 3. Altered versions must be plainly marked as such, and must not be
17  *    misrepresented as being the original software.  Since few users
18  *    ever read sources, credits must appear in the documentation.
19  * 4. This notice may not be removed or altered.
20  */
21 #ifndef EDITLINE_H_
22 #define EDITLINE_H_
23 
24 /* Handy macros when binding keys. */
25 #define CTL(x)          ((x) & 0x1F)
26 #define ISCTL(x)        ((x) && (x) < ' ')
27 #define UNCTL(x)        ((x) + 64)
28 #define META(x)         ((x) | 0x80)
29 #define ISMETA(x)       ((x) & 0x80)
30 #define UNMETA(x)       ((x) & 0x7F)
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /* Command status codes. */
37 typedef enum {
38     CSdone = 0,                 /* OK */
39     CSeof,                      /* Error, or EOF */
40     CSmove,
41     CSdispatch,
42     CSstay,
43     CSsignal
44 } el_status_t;
45 
46 /* Editline specific types, despite rl_ prefix.  From Heimdal project. */
47 typedef int rl_list_possib_func_t(char*, char***);
48 typedef el_status_t el_keymap_func_t(void);
49 typedef int  rl_hook_func_t(void);
50 typedef int  rl_getc_func_t(void);
51 typedef void rl_voidfunc_t(void);
52 typedef void rl_vintfunc_t(int);
53 typedef void rl_vcpfunc_t(char *);
54 
55 /* FSF Readline compat tupes */
56 typedef char  *rl_complete_func_t   (char *, int*);
57 typedef char  *rl_compentry_func_t  (const char *, int);
58 typedef char **rl_completion_func_t (const char *, int, int);
59 
60 /* Display 8-bit chars "as-is" or as `M-x'? Toggle with M-m. (Default:0 - "as-is") */
61 extern int rl_meta_chars;
62 
63 /* Editline specific functions. */
64 extern char *      el_find_word(void);
65 extern void        el_print_columns(int ac, char **av);
66 extern el_status_t el_ring_bell(void);
67 extern el_status_t el_del_char(void);
68 
69 extern el_status_t el_bind_key(int key, el_keymap_func_t function);
70 extern el_status_t el_bind_key_in_metamap(int key, el_keymap_func_t function);
71 
72 extern const char *el_next_hist(void);
73 extern const char *el_prev_hist(void);
74 
75 extern char       *rl_complete(char *token, int *match);
76 extern int         rl_list_possib(char *token, char ***av);
77 extern char      **rl_completion_matches(const char *token, rl_compentry_func_t *generator);
78 extern char       *rl_filename_completion_function(const char *text, int state);
79 
80 /* For compatibility with FSF readline. */
81 extern int         rl_point;
82 extern int         rl_mark;
83 extern int         rl_end;
84 extern int         rl_inhibit_complete;
85 extern char       *rl_line_buffer;
86 extern const char *rl_readline_name;
87 extern FILE       *rl_instream;  /* The stdio stream from which input is read. Defaults to stdin if NULL - Not supported yet! */
88 extern FILE       *rl_outstream; /* The stdio stream to which output is flushed. Defaults to stdout if NULL - Not supported yet! */
89 extern int         el_no_echo;   /* E.g under emacs, don't echo except prompt */
90 extern int         el_no_hist;   /* Disable auto-save of and access to history -- e.g. for password prompts or wizards */
91 extern int         el_hist_size; /* size of history scrollback buffer, default: 15 */
92 
93 extern void  rl_initialize      (void);
94 extern void  rl_reset_terminal  (const char *terminal_name);
95 extern void  rl_uninitialize    (void);
96 
97 extern void  rl_save_prompt     (void);
98 extern void  rl_restore_prompt  (void);
99 extern void  rl_set_prompt      (const char *prompt);
100 
101 extern void  rl_clear_message   (void);
102 extern void  rl_forced_update_display(void);
103 
104 extern void  rl_prep_terminal   (int meta_flag);
105 extern void  rl_deprep_terminal (void);
106 
107 extern int   rl_getc(void);
108 extern int   rl_insert_text     (const char *text);
109 extern int   rl_refresh_line    (int ignore1, int ignore2);
110 
111 extern char *readline           (const char *prompt);
112 
113 extern void  add_history        (const char *line);
114 extern int   read_history       (const char *filename);
115 extern int   write_history      (const char *filename);
116 
117 extern rl_getc_func_t *rl_set_getc_func(rl_getc_func_t *func);
118 
119 extern rl_completion_func_t  *rl_attempted_completion_function;
120 extern rl_complete_func_t    *rl_set_complete_func    (rl_complete_func_t *func);
121 extern rl_list_possib_func_t *rl_set_list_possib_func (rl_list_possib_func_t *func);
122 
123 /* Alternate interface to plain readline(), for event loops */
124 extern void rl_callback_handler_install (const char *prompt, rl_vcpfunc_t *lhandler);
125 extern void rl_callback_read_char       (void);
126 extern void rl_callback_handler_remove  (void);
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif  /* EDITLINE_H_ */
133