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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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 |
3519
|
50 int |
|
51 octave_rl_screen_height (void) |
|
52 { |
3779
|
53 int rows, cols; |
|
54 rl_get_screen_size (&rows, &cols); |
|
55 return rows; |
3519
|
56 } |
|
57 |
|
58 int |
|
59 octave_rl_screen_width (void) |
|
60 { |
3779
|
61 int rows, cols; |
|
62 rl_get_screen_size (&rows, &cols); |
|
63 return cols; |
3519
|
64 } |
|
65 |
|
66 void |
3779
|
67 octave_rl_enable_paren_matching (int val) |
3519
|
68 { |
3779
|
69 rl_variable_bind ("blink-matching-paren", val ? "1" : "0"); |
3519
|
70 } |
|
71 |
3946
|
72 /* It would be much simpler if we could just call _rl_clear_screen to |
|
73 only clear the screen, but it is not a public function, and on some |
|
74 systems, it is not exported from shared library versions of |
|
75 readline, so we can't use it. |
|
76 |
|
77 Instead, temporarily redefine the redisplay function to do nothing. |
|
78 |
|
79 XXX FIXME XXX -- It would be safer to do this when protected from |
|
80 interrupts... */ |
3856
|
81 |
|
82 static void |
5394
|
83 flush_stdout (void) |
3856
|
84 { |
5394
|
85 fflush (stdout); |
3856
|
86 } |
|
87 |
3519
|
88 void |
|
89 octave_rl_clear_screen (void) |
|
90 { |
3855
|
91 int ignore1 = 0; |
|
92 int ignore2 = 0; |
|
93 |
3856
|
94 rl_voidfunc_t *saved_redisplay_function = rl_redisplay_function; |
5394
|
95 rl_redisplay_function = flush_stdout; |
3855
|
96 |
|
97 rl_clear_screen (ignore1, ignore2); |
3856
|
98 |
|
99 rl_redisplay_function = saved_redisplay_function; |
3519
|
100 } |
|
101 |
|
102 void |
|
103 octave_rl_resize_terminal (void) |
|
104 { |
|
105 rl_resize_terminal (); |
|
106 } |
|
107 |
|
108 void |
|
109 octave_rl_restore_terminal_state () |
|
110 { |
|
111 if (rl_deprep_term_function) |
|
112 rl_deprep_term_function (); |
|
113 } |
|
114 |
|
115 void |
|
116 octave_rl_insert_text (const char *s) |
|
117 { |
|
118 rl_insert_text (s); |
|
119 } |
|
120 |
|
121 void |
|
122 octave_rl_newline (void) |
|
123 { |
3779
|
124 rl_newline (1, '\n'); |
3519
|
125 } |
|
126 |
|
127 void |
|
128 octave_rl_clear_undo_list (void) |
|
129 { |
|
130 if (rl_undo_list) |
|
131 { |
3779
|
132 rl_free_undo_list (); |
3519
|
133 |
|
134 rl_undo_list = 0; |
|
135 } |
|
136 } |
|
137 |
|
138 void |
|
139 octave_rl_set_name (const char *n) |
|
140 { |
3933
|
141 OCTAVE_RL_SAVE_STRING (nm, n); |
3519
|
142 |
|
143 rl_readline_name = nm; |
|
144 |
|
145 /* Since we've already called rl_initialize, we need to re-read the |
|
146 init file to take advantage of the conditional parsing feature |
|
147 based on rl_readline_name; */ |
|
148 |
3779
|
149 rl_re_read_init_file (0, 0); |
3519
|
150 } |
|
151 |
|
152 char * |
|
153 octave_rl_readline (const char *prompt) |
|
154 { |
|
155 return readline (prompt); |
|
156 } |
|
157 |
|
158 void |
|
159 octave_rl_set_input_stream (FILE *f) |
|
160 { |
|
161 rl_instream = f; |
|
162 } |
|
163 |
|
164 FILE * |
|
165 octave_rl_get_input_stream (void) |
|
166 { |
|
167 return rl_instream; |
|
168 } |
|
169 |
|
170 void |
|
171 octave_rl_set_output_stream (FILE *f) |
|
172 { |
|
173 rl_outstream = f; |
|
174 } |
|
175 |
|
176 FILE * |
|
177 octave_rl_get_output_stream (void) |
|
178 { |
|
179 return rl_outstream; |
|
180 } |
|
181 |
|
182 void |
|
183 octave_rl_read_init_file (const char *f) |
|
184 { |
|
185 if (f && *f) |
|
186 rl_read_init_file (f); |
|
187 else |
3779
|
188 rl_re_read_init_file (0, 0); |
3519
|
189 } |
|
190 |
4143
|
191 int |
|
192 octave_rl_filename_completion_desired (int arg) |
|
193 { |
|
194 int retval = rl_filename_completion_desired; |
|
195 rl_filename_completion_desired = arg; |
|
196 return retval; |
|
197 } |
|
198 |
4604
|
199 char * |
|
200 octave_rl_filename_completion_function (const char *text, int state) |
|
201 { |
|
202 return rl_filename_completion_function (text, state); |
|
203 } |
|
204 |
3519
|
205 void |
3933
|
206 octave_rl_set_basic_word_break_characters (const char *s) |
|
207 { |
|
208 OCTAVE_RL_SAVE_STRING (ss, s); |
|
209 |
|
210 rl_basic_word_break_characters = ss; |
|
211 } |
|
212 |
|
213 void |
|
214 octave_rl_set_completer_word_break_characters (const char *s) |
|
215 { |
|
216 OCTAVE_RL_SAVE_STRING (ss, s); |
|
217 |
|
218 rl_completer_word_break_characters = ss; |
|
219 } |
|
220 |
|
221 void |
3519
|
222 octave_rl_set_basic_quote_characters (const char *s) |
|
223 { |
3933
|
224 OCTAVE_RL_SAVE_STRING (ss, s); |
3519
|
225 |
|
226 rl_basic_quote_characters = ss; |
|
227 } |
|
228 |
|
229 void |
|
230 octave_rl_set_completion_append_character (char c) |
|
231 { |
|
232 rl_completion_append_character = c; |
|
233 } |
|
234 |
|
235 void |
|
236 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f) |
|
237 { |
|
238 rl_attempted_completion_function = f; |
|
239 } |
|
240 |
|
241 void |
|
242 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f) |
|
243 { |
4802
|
244 rl_startup_hook = f; |
3519
|
245 } |
|
246 |
|
247 rl_startup_hook_fcn_ptr |
|
248 octave_rl_get_startup_hook (void) |
|
249 { |
4802
|
250 return rl_startup_hook; |
3519
|
251 } |
|
252 |
|
253 void |
|
254 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f) |
|
255 { |
4802
|
256 rl_event_hook = f; |
3519
|
257 } |
|
258 |
|
259 rl_event_hook_fcn_ptr |
|
260 octave_rl_get_event_hook (void) |
|
261 { |
4802
|
262 return rl_event_hook; |
3519
|
263 } |
|
264 |
|
265 char ** |
|
266 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) |
|
267 { |
3779
|
268 return rl_completion_matches (text, f); |
3519
|
269 } |
|
270 |
|
271 char |
|
272 octave_rl_prompt_start_ignore (void) |
|
273 { |
|
274 return RL_PROMPT_START_IGNORE; |
|
275 } |
|
276 |
|
277 char |
|
278 octave_rl_prompt_end_ignore (void) |
|
279 { |
|
280 return RL_PROMPT_END_IGNORE; |
|
281 } |
|
282 |
|
283 void |
|
284 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key) |
|
285 { |
|
286 rl_add_defun (name, f, key); |
|
287 } |
|
288 |
|
289 void |
|
290 octave_rl_set_terminal_name (const char *term) |
|
291 { |
5303
|
292 rl_terminal_name = term; |
3519
|
293 } |
|
294 |
|
295 void |
|
296 octave_rl_initialize (void) |
|
297 { |
|
298 rl_initialize (); |
|
299 } |
|
300 |
|
301 int |
|
302 octave_rl_history_search_forward (int count, int ignore) |
|
303 { |
|
304 return rl_history_search_forward (count, ignore); |
|
305 } |
|
306 |
|
307 int |
|
308 octave_rl_history_search_backward (int count, int ignore) |
|
309 { |
|
310 return rl_history_search_backward (count, ignore); |
|
311 } |
|
312 |
|
313 char |
|
314 octave_rl_ctrl (char c) |
|
315 { |
|
316 return CTRL (c); |
|
317 } |
|
318 |
|
319 char |
|
320 octave_rl_meta (char c) |
|
321 { |
|
322 return META (c); |
|
323 } |
|
324 |
|
325 #endif |
|
326 |
|
327 /* |
|
328 ;;; Local Variables: *** |
|
329 ;;; mode: C++ *** |
|
330 ;;; End: *** |
|
331 */ |