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