3519
|
1 /* |
|
2 |
7017
|
3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
|
4 John W. Eaton |
3519
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
7016
|
10 Free Software Foundation; either version 3 of the License, or (at your |
|
11 option) any later version. |
3519
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
7016
|
19 along with Octave; see the file COPYING. If not, see |
|
20 <http://www.gnu.org/licenses/>. |
3519
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #if defined (USE_READLINE) |
|
29 |
|
30 #include <stdio.h> |
|
31 #include <stdlib.h> |
|
32 |
|
33 #include <readline/readline.h> |
|
34 |
|
35 #include "oct-rl-edit.h" |
|
36 |
3933
|
37 #define OCTAVE_RL_SAVE_STRING(ss, s) \ |
|
38 static char *ss = 0; \ |
|
39 \ |
|
40 if (ss) \ |
|
41 { \ |
|
42 free (ss); \ |
|
43 ss = 0; \ |
|
44 } \ |
|
45 \ |
|
46 ss = malloc (strlen (s) + 1); \ |
|
47 \ |
|
48 strcpy (ss, s) |
|
49 |
6979
|
50 void |
|
51 octave_rl_redisplay (void) |
|
52 { |
|
53 rl_redisplay (); |
|
54 } |
|
55 |
3519
|
56 int |
|
57 octave_rl_screen_height (void) |
|
58 { |
3779
|
59 int rows, cols; |
|
60 rl_get_screen_size (&rows, &cols); |
|
61 return rows; |
3519
|
62 } |
|
63 |
|
64 int |
|
65 octave_rl_screen_width (void) |
|
66 { |
3779
|
67 int rows, cols; |
|
68 rl_get_screen_size (&rows, &cols); |
|
69 return cols; |
3519
|
70 } |
|
71 |
|
72 void |
3779
|
73 octave_rl_enable_paren_matching (int val) |
3519
|
74 { |
3779
|
75 rl_variable_bind ("blink-matching-paren", val ? "1" : "0"); |
3519
|
76 } |
|
77 |
3946
|
78 /* It would be much simpler if we could just call _rl_clear_screen to |
|
79 only clear the screen, but it is not a public function, and on some |
|
80 systems, it is not exported from shared library versions of |
|
81 readline, so we can't use it. |
|
82 |
|
83 Instead, temporarily redefine the redisplay function to do nothing. |
|
84 |
5775
|
85 FIXME -- It would be safer to do this when protected from |
3946
|
86 interrupts... */ |
3856
|
87 |
|
88 static void |
5394
|
89 flush_stdout (void) |
3856
|
90 { |
5394
|
91 fflush (stdout); |
3856
|
92 } |
|
93 |
3519
|
94 void |
|
95 octave_rl_clear_screen (void) |
|
96 { |
3855
|
97 int ignore1 = 0; |
|
98 int ignore2 = 0; |
|
99 |
3856
|
100 rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function; |
5394
|
101 rl_redisplay_function = flush_stdout; |
3855
|
102 |
|
103 rl_clear_screen (ignore1, ignore2); |
3856
|
104 |
|
105 rl_redisplay_function = saved_redisplay_function; |
3519
|
106 } |
|
107 |
|
108 void |
|
109 octave_rl_resize_terminal (void) |
|
110 { |
|
111 rl_resize_terminal (); |
|
112 } |
|
113 |
|
114 void |
|
115 octave_rl_restore_terminal_state () |
|
116 { |
|
117 if (rl_deprep_term_function) |
|
118 rl_deprep_term_function (); |
|
119 } |
|
120 |
|
121 void |
|
122 octave_rl_insert_text (const char *s) |
|
123 { |
|
124 rl_insert_text (s); |
|
125 } |
|
126 |
6979
|
127 int |
|
128 octave_rl_newline (int count, int key) |
3519
|
129 { |
6979
|
130 return rl_newline (count, key); |
|
131 } |
|
132 |
|
133 const char * |
|
134 octave_rl_line_buffer (void) |
|
135 { |
|
136 return rl_line_buffer; |
3519
|
137 } |
|
138 |
|
139 void |
|
140 octave_rl_clear_undo_list (void) |
|
141 { |
|
142 if (rl_undo_list) |
|
143 { |
3779
|
144 rl_free_undo_list (); |
3519
|
145 |
|
146 rl_undo_list = 0; |
|
147 } |
|
148 } |
|
149 |
|
150 void |
|
151 octave_rl_set_name (const char *n) |
|
152 { |
3933
|
153 OCTAVE_RL_SAVE_STRING (nm, n); |
3519
|
154 |
|
155 rl_readline_name = nm; |
|
156 |
|
157 /* Since we've already called rl_initialize, we need to re-read the |
|
158 init file to take advantage of the conditional parsing feature |
|
159 based on rl_readline_name; */ |
|
160 |
3779
|
161 rl_re_read_init_file (0, 0); |
3519
|
162 } |
|
163 |
|
164 char * |
|
165 octave_rl_readline (const char *prompt) |
|
166 { |
|
167 return readline (prompt); |
|
168 } |
|
169 |
|
170 void |
|
171 octave_rl_set_input_stream (FILE *f) |
|
172 { |
|
173 rl_instream = f; |
|
174 } |
|
175 |
|
176 FILE * |
|
177 octave_rl_get_input_stream (void) |
|
178 { |
|
179 return rl_instream; |
|
180 } |
|
181 |
|
182 void |
|
183 octave_rl_set_output_stream (FILE *f) |
|
184 { |
|
185 rl_outstream = f; |
|
186 } |
|
187 |
|
188 FILE * |
|
189 octave_rl_get_output_stream (void) |
|
190 { |
|
191 return rl_outstream; |
|
192 } |
|
193 |
|
194 void |
|
195 octave_rl_read_init_file (const char *f) |
|
196 { |
|
197 if (f && *f) |
|
198 rl_read_init_file (f); |
|
199 else |
3779
|
200 rl_re_read_init_file (0, 0); |
3519
|
201 } |
|
202 |
4143
|
203 int |
|
204 octave_rl_filename_completion_desired (int arg) |
|
205 { |
|
206 int retval = rl_filename_completion_desired; |
|
207 rl_filename_completion_desired = arg; |
|
208 return retval; |
|
209 } |
|
210 |
6979
|
211 int |
|
212 octave_rl_filename_quoting_desired (int arg) |
|
213 { |
|
214 int retval = rl_filename_quoting_desired; |
|
215 rl_filename_quoting_desired = arg; |
|
216 return retval; |
|
217 } |
|
218 |
4604
|
219 char * |
|
220 octave_rl_filename_completion_function (const char *text, int state) |
|
221 { |
|
222 return rl_filename_completion_function (text, state); |
|
223 } |
|
224 |
3519
|
225 void |
3933
|
226 octave_rl_set_basic_word_break_characters (const char *s) |
|
227 { |
|
228 OCTAVE_RL_SAVE_STRING (ss, s); |
|
229 |
|
230 rl_basic_word_break_characters = ss; |
|
231 } |
|
232 |
|
233 void |
|
234 octave_rl_set_completer_word_break_characters (const char *s) |
|
235 { |
|
236 OCTAVE_RL_SAVE_STRING (ss, s); |
|
237 |
|
238 rl_completer_word_break_characters = ss; |
|
239 } |
|
240 |
|
241 void |
3519
|
242 octave_rl_set_basic_quote_characters (const char *s) |
|
243 { |
3933
|
244 OCTAVE_RL_SAVE_STRING (ss, s); |
3519
|
245 |
|
246 rl_basic_quote_characters = ss; |
|
247 } |
|
248 |
|
249 void |
6979
|
250 octave_rl_set_filename_quote_characters (const char *s) |
|
251 { |
|
252 OCTAVE_RL_SAVE_STRING (ss, s); |
|
253 |
|
254 rl_filename_quote_characters = ss; |
|
255 } |
|
256 |
|
257 void |
|
258 octave_rl_set_completer_quote_characters (const char *s) |
|
259 { |
|
260 OCTAVE_RL_SAVE_STRING (ss, s); |
|
261 |
|
262 rl_completer_quote_characters = ss; |
|
263 } |
|
264 |
|
265 void |
3519
|
266 octave_rl_set_completion_append_character (char c) |
|
267 { |
|
268 rl_completion_append_character = c; |
|
269 } |
|
270 |
|
271 void |
|
272 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f) |
|
273 { |
|
274 rl_attempted_completion_function = f; |
|
275 } |
|
276 |
|
277 void |
6979
|
278 octave_rl_set_quoting_function (rl_quoting_fcn_ptr f) |
|
279 { |
|
280 rl_filename_quoting_function = f; |
|
281 } |
|
282 |
|
283 void |
|
284 octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr f) |
|
285 { |
|
286 rl_filename_dequoting_function = f; |
|
287 } |
|
288 |
|
289 void |
|
290 octave_rl_set_char_is_quoted_function (rl_char_is_quoted_fcn_ptr f) |
|
291 { |
|
292 rl_char_is_quoted_p = f; |
|
293 } |
|
294 |
|
295 void |
3519
|
296 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f) |
|
297 { |
4802
|
298 rl_startup_hook = f; |
3519
|
299 } |
|
300 |
|
301 rl_startup_hook_fcn_ptr |
|
302 octave_rl_get_startup_hook (void) |
|
303 { |
4802
|
304 return rl_startup_hook; |
3519
|
305 } |
|
306 |
|
307 void |
|
308 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f) |
|
309 { |
4802
|
310 rl_event_hook = f; |
3519
|
311 } |
|
312 |
|
313 rl_event_hook_fcn_ptr |
|
314 octave_rl_get_event_hook (void) |
|
315 { |
4802
|
316 return rl_event_hook; |
3519
|
317 } |
|
318 |
|
319 char ** |
|
320 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) |
|
321 { |
3779
|
322 return rl_completion_matches (text, f); |
3519
|
323 } |
|
324 |
|
325 char |
|
326 octave_rl_prompt_start_ignore (void) |
|
327 { |
|
328 return RL_PROMPT_START_IGNORE; |
|
329 } |
|
330 |
|
331 char |
|
332 octave_rl_prompt_end_ignore (void) |
|
333 { |
|
334 return RL_PROMPT_END_IGNORE; |
|
335 } |
|
336 |
|
337 void |
|
338 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key) |
|
339 { |
|
340 rl_add_defun (name, f, key); |
|
341 } |
|
342 |
|
343 void |
|
344 octave_rl_set_terminal_name (const char *term) |
|
345 { |
5303
|
346 rl_terminal_name = term; |
3519
|
347 } |
|
348 |
|
349 void |
|
350 octave_rl_initialize (void) |
|
351 { |
|
352 rl_initialize (); |
|
353 } |
|
354 |
|
355 int |
|
356 octave_rl_history_search_forward (int count, int ignore) |
|
357 { |
|
358 return rl_history_search_forward (count, ignore); |
|
359 } |
|
360 |
|
361 int |
|
362 octave_rl_history_search_backward (int count, int ignore) |
|
363 { |
|
364 return rl_history_search_backward (count, ignore); |
|
365 } |
|
366 |
|
367 char |
|
368 octave_rl_ctrl (char c) |
|
369 { |
|
370 return CTRL (c); |
|
371 } |
|
372 |
|
373 char |
|
374 octave_rl_meta (char c) |
|
375 { |
|
376 return META (c); |
|
377 } |
|
378 |
|
379 #endif |
|
380 |
|
381 /* |
|
382 ;;; Local Variables: *** |
|
383 ;;; mode: C++ *** |
|
384 ;;; End: *** |
|
385 */ |