3519
|
1 /* |
|
2 |
|
3 Copyright (C) 2000 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #if defined (USE_READLINE) |
|
28 |
|
29 #include <stdio.h> |
|
30 #include <stdlib.h> |
|
31 |
|
32 #include <readline/readline.h> |
|
33 |
|
34 #include "oct-rl-edit.h" |
|
35 |
|
36 int |
|
37 octave_rl_screen_height (void) |
|
38 { |
3779
|
39 int rows, cols; |
|
40 rl_get_screen_size (&rows, &cols); |
|
41 return rows; |
3519
|
42 } |
|
43 |
|
44 int |
|
45 octave_rl_screen_width (void) |
|
46 { |
3779
|
47 int rows, cols; |
|
48 rl_get_screen_size (&rows, &cols); |
|
49 return cols; |
3519
|
50 } |
|
51 |
|
52 void |
3779
|
53 octave_rl_enable_paren_matching (int val) |
3519
|
54 { |
3779
|
55 rl_variable_bind ("blink-matching-paren", val ? "1" : "0"); |
3519
|
56 } |
|
57 |
3856
|
58 // It would be much simpler if we could just call _rl_clear_screen to |
|
59 // only clear the screen, but it is not a public function, and on some |
|
60 // systems, it is not exported from shared library versions of |
|
61 // readline, so we can't use it. |
|
62 // |
|
63 // Instead, temporarily redefine the redisplay function to do nothing. |
|
64 // |
|
65 // XXX FIXME XXX -- It would be safer to do this when protected from |
|
66 // interrupts... |
|
67 |
|
68 static void |
|
69 no_redisplay (void) |
|
70 { |
|
71 } |
|
72 |
3519
|
73 void |
|
74 octave_rl_clear_screen (void) |
|
75 { |
3855
|
76 int ignore1 = 0; |
|
77 int ignore2 = 0; |
|
78 |
3856
|
79 rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function; |
|
80 rl_redisplay_function = no_redisplay; |
3855
|
81 |
|
82 rl_clear_screen (ignore1, ignore2); |
3856
|
83 |
|
84 rl_redisplay_function = saved_redisplay_function; |
3519
|
85 } |
|
86 |
|
87 void |
|
88 octave_rl_resize_terminal (void) |
|
89 { |
|
90 rl_resize_terminal (); |
|
91 } |
|
92 |
|
93 void |
|
94 octave_rl_restore_terminal_state () |
|
95 { |
|
96 if (rl_deprep_term_function) |
|
97 rl_deprep_term_function (); |
|
98 } |
|
99 |
|
100 void |
|
101 octave_rl_insert_text (const char *s) |
|
102 { |
|
103 rl_insert_text (s); |
|
104 } |
|
105 |
|
106 void |
|
107 octave_rl_newline (void) |
|
108 { |
3779
|
109 rl_newline (1, '\n'); |
3519
|
110 } |
|
111 |
|
112 void |
|
113 octave_rl_clear_undo_list (void) |
|
114 { |
|
115 if (rl_undo_list) |
|
116 { |
3779
|
117 rl_free_undo_list (); |
3519
|
118 |
|
119 rl_undo_list = 0; |
|
120 } |
|
121 } |
|
122 |
|
123 void |
|
124 octave_rl_set_name (const char *n) |
|
125 { |
|
126 static char *nm = 0; |
|
127 |
|
128 if (nm) |
|
129 { |
|
130 free (nm); |
|
131 nm = 0; |
|
132 } |
|
133 |
|
134 nm = malloc (strlen (n + 1)); |
|
135 |
|
136 strcpy (nm, n); |
|
137 |
|
138 rl_readline_name = nm; |
|
139 |
|
140 /* Since we've already called rl_initialize, we need to re-read the |
|
141 init file to take advantage of the conditional parsing feature |
|
142 based on rl_readline_name; */ |
|
143 |
3779
|
144 rl_re_read_init_file (0, 0); |
3519
|
145 } |
|
146 |
|
147 char * |
|
148 octave_rl_readline (const char *prompt) |
|
149 { |
|
150 return readline (prompt); |
|
151 } |
|
152 |
|
153 void |
|
154 octave_rl_set_input_stream (FILE *f) |
|
155 { |
|
156 rl_instream = f; |
|
157 } |
|
158 |
|
159 FILE * |
|
160 octave_rl_get_input_stream (void) |
|
161 { |
|
162 return rl_instream; |
|
163 } |
|
164 |
|
165 void |
|
166 octave_rl_set_output_stream (FILE *f) |
|
167 { |
|
168 rl_outstream = f; |
|
169 } |
|
170 |
|
171 FILE * |
|
172 octave_rl_get_output_stream (void) |
|
173 { |
|
174 return rl_outstream; |
|
175 } |
|
176 |
|
177 void |
|
178 octave_rl_read_init_file (const char *f) |
|
179 { |
|
180 if (f && *f) |
|
181 rl_read_init_file (f); |
|
182 else |
3779
|
183 rl_re_read_init_file (0, 0); |
3519
|
184 } |
|
185 |
|
186 void |
|
187 octave_rl_set_basic_quote_characters (const char *s) |
|
188 { |
|
189 static char *ss = 0; |
|
190 |
|
191 if (ss) |
|
192 { |
|
193 free (ss); |
|
194 ss = 0; |
|
195 } |
|
196 |
|
197 ss = malloc (strlen (s) + 1); |
|
198 |
|
199 strcpy (ss, s); |
|
200 |
|
201 rl_basic_quote_characters = ss; |
|
202 } |
|
203 |
|
204 void |
|
205 octave_rl_set_completion_append_character (char c) |
|
206 { |
|
207 rl_completion_append_character = c; |
|
208 } |
|
209 |
|
210 void |
|
211 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f) |
|
212 { |
|
213 rl_attempted_completion_function = f; |
|
214 } |
|
215 |
|
216 void |
|
217 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f) |
|
218 { |
3578
|
219 void **fp = (void **) (&rl_startup_hook); |
3521
|
220 *fp = (void *) f; |
3519
|
221 } |
|
222 |
|
223 rl_startup_hook_fcn_ptr |
|
224 octave_rl_get_startup_hook (void) |
|
225 { |
3520
|
226 return (rl_startup_hook_fcn_ptr) rl_startup_hook; |
3519
|
227 } |
|
228 |
|
229 void |
|
230 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f) |
|
231 { |
3578
|
232 void **fp = (void **) (&rl_event_hook); |
3521
|
233 *fp = (void *) f; |
3519
|
234 } |
|
235 |
|
236 rl_event_hook_fcn_ptr |
|
237 octave_rl_get_event_hook (void) |
|
238 { |
3520
|
239 return (rl_event_hook_fcn_ptr) rl_event_hook; |
3519
|
240 } |
|
241 |
|
242 char ** |
|
243 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) |
|
244 { |
3779
|
245 return rl_completion_matches (text, f); |
3519
|
246 } |
|
247 |
|
248 char |
|
249 octave_rl_prompt_start_ignore (void) |
|
250 { |
|
251 return RL_PROMPT_START_IGNORE; |
|
252 } |
|
253 |
|
254 char |
|
255 octave_rl_prompt_end_ignore (void) |
|
256 { |
|
257 return RL_PROMPT_END_IGNORE; |
|
258 } |
|
259 |
|
260 void |
|
261 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key) |
|
262 { |
|
263 rl_add_defun (name, f, key); |
|
264 } |
|
265 |
|
266 void |
|
267 octave_rl_set_terminal_name (const char *term) |
|
268 { |
|
269 rl_terminal_name = (char *) term; |
|
270 } |
|
271 |
|
272 void |
|
273 octave_rl_initialize (void) |
|
274 { |
|
275 rl_initialize (); |
|
276 } |
|
277 |
|
278 int |
|
279 octave_rl_history_search_forward (int count, int ignore) |
|
280 { |
|
281 return rl_history_search_forward (count, ignore); |
|
282 } |
|
283 |
|
284 int |
|
285 octave_rl_history_search_backward (int count, int ignore) |
|
286 { |
|
287 return rl_history_search_backward (count, ignore); |
|
288 } |
|
289 |
|
290 char |
|
291 octave_rl_ctrl (char c) |
|
292 { |
|
293 return CTRL (c); |
|
294 } |
|
295 |
|
296 char |
|
297 octave_rl_meta (char c) |
|
298 { |
|
299 return META (c); |
|
300 } |
|
301 |
|
302 #endif |
|
303 |
|
304 /* |
|
305 ;;; Local Variables: *** |
|
306 ;;; mode: C++ *** |
|
307 ;;; End: *** |
|
308 */ |