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