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 |
|
58 void |
|
59 octave_rl_clear_screen (void) |
|
60 { |
3854
|
61 rl_clear_screen (); |
3519
|
62 } |
|
63 |
|
64 void |
|
65 octave_rl_resize_terminal (void) |
|
66 { |
|
67 rl_resize_terminal (); |
|
68 } |
|
69 |
|
70 void |
|
71 octave_rl_restore_terminal_state () |
|
72 { |
|
73 if (rl_deprep_term_function) |
|
74 rl_deprep_term_function (); |
|
75 } |
|
76 |
|
77 void |
|
78 octave_rl_insert_text (const char *s) |
|
79 { |
|
80 rl_insert_text (s); |
|
81 } |
|
82 |
|
83 void |
|
84 octave_rl_newline (void) |
|
85 { |
3779
|
86 rl_newline (1, '\n'); |
3519
|
87 } |
|
88 |
|
89 void |
|
90 octave_rl_clear_undo_list (void) |
|
91 { |
|
92 if (rl_undo_list) |
|
93 { |
3779
|
94 rl_free_undo_list (); |
3519
|
95 |
|
96 rl_undo_list = 0; |
|
97 } |
|
98 } |
|
99 |
|
100 void |
|
101 octave_rl_set_name (const char *n) |
|
102 { |
|
103 static char *nm = 0; |
|
104 |
|
105 if (nm) |
|
106 { |
|
107 free (nm); |
|
108 nm = 0; |
|
109 } |
|
110 |
|
111 nm = malloc (strlen (n + 1)); |
|
112 |
|
113 strcpy (nm, n); |
|
114 |
|
115 rl_readline_name = nm; |
|
116 |
|
117 /* Since we've already called rl_initialize, we need to re-read the |
|
118 init file to take advantage of the conditional parsing feature |
|
119 based on rl_readline_name; */ |
|
120 |
3779
|
121 rl_re_read_init_file (0, 0); |
3519
|
122 } |
|
123 |
|
124 char * |
|
125 octave_rl_readline (const char *prompt) |
|
126 { |
|
127 return readline (prompt); |
|
128 } |
|
129 |
|
130 void |
|
131 octave_rl_set_input_stream (FILE *f) |
|
132 { |
|
133 rl_instream = f; |
|
134 } |
|
135 |
|
136 FILE * |
|
137 octave_rl_get_input_stream (void) |
|
138 { |
|
139 return rl_instream; |
|
140 } |
|
141 |
|
142 void |
|
143 octave_rl_set_output_stream (FILE *f) |
|
144 { |
|
145 rl_outstream = f; |
|
146 } |
|
147 |
|
148 FILE * |
|
149 octave_rl_get_output_stream (void) |
|
150 { |
|
151 return rl_outstream; |
|
152 } |
|
153 |
|
154 void |
|
155 octave_rl_read_init_file (const char *f) |
|
156 { |
|
157 if (f && *f) |
|
158 rl_read_init_file (f); |
|
159 else |
3779
|
160 rl_re_read_init_file (0, 0); |
3519
|
161 } |
|
162 |
|
163 void |
|
164 octave_rl_set_basic_quote_characters (const char *s) |
|
165 { |
|
166 static char *ss = 0; |
|
167 |
|
168 if (ss) |
|
169 { |
|
170 free (ss); |
|
171 ss = 0; |
|
172 } |
|
173 |
|
174 ss = malloc (strlen (s) + 1); |
|
175 |
|
176 strcpy (ss, s); |
|
177 |
|
178 rl_basic_quote_characters = ss; |
|
179 } |
|
180 |
|
181 void |
|
182 octave_rl_set_completion_append_character (char c) |
|
183 { |
|
184 rl_completion_append_character = c; |
|
185 } |
|
186 |
|
187 void |
|
188 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f) |
|
189 { |
|
190 rl_attempted_completion_function = f; |
|
191 } |
|
192 |
|
193 void |
|
194 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f) |
|
195 { |
3578
|
196 void **fp = (void **) (&rl_startup_hook); |
3521
|
197 *fp = (void *) f; |
3519
|
198 } |
|
199 |
|
200 rl_startup_hook_fcn_ptr |
|
201 octave_rl_get_startup_hook (void) |
|
202 { |
3520
|
203 return (rl_startup_hook_fcn_ptr) rl_startup_hook; |
3519
|
204 } |
|
205 |
|
206 void |
|
207 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f) |
|
208 { |
3578
|
209 void **fp = (void **) (&rl_event_hook); |
3521
|
210 *fp = (void *) f; |
3519
|
211 } |
|
212 |
|
213 rl_event_hook_fcn_ptr |
|
214 octave_rl_get_event_hook (void) |
|
215 { |
3520
|
216 return (rl_event_hook_fcn_ptr) rl_event_hook; |
3519
|
217 } |
|
218 |
|
219 char ** |
|
220 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) |
|
221 { |
3779
|
222 return rl_completion_matches (text, f); |
3519
|
223 } |
|
224 |
|
225 char |
|
226 octave_rl_prompt_start_ignore (void) |
|
227 { |
|
228 return RL_PROMPT_START_IGNORE; |
|
229 } |
|
230 |
|
231 char |
|
232 octave_rl_prompt_end_ignore (void) |
|
233 { |
|
234 return RL_PROMPT_END_IGNORE; |
|
235 } |
|
236 |
|
237 void |
|
238 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key) |
|
239 { |
|
240 rl_add_defun (name, f, key); |
|
241 } |
|
242 |
|
243 void |
|
244 octave_rl_set_terminal_name (const char *term) |
|
245 { |
|
246 rl_terminal_name = (char *) term; |
|
247 } |
|
248 |
|
249 void |
|
250 octave_rl_initialize (void) |
|
251 { |
|
252 rl_initialize (); |
|
253 } |
|
254 |
|
255 int |
|
256 octave_rl_history_search_forward (int count, int ignore) |
|
257 { |
|
258 return rl_history_search_forward (count, ignore); |
|
259 } |
|
260 |
|
261 int |
|
262 octave_rl_history_search_backward (int count, int ignore) |
|
263 { |
|
264 return rl_history_search_backward (count, ignore); |
|
265 } |
|
266 |
|
267 char |
|
268 octave_rl_ctrl (char c) |
|
269 { |
|
270 return CTRL (c); |
|
271 } |
|
272 |
|
273 char |
|
274 octave_rl_meta (char c) |
|
275 { |
|
276 return META (c); |
|
277 } |
|
278 |
|
279 #endif |
|
280 |
|
281 /* |
|
282 ;;; Local Variables: *** |
|
283 ;;; mode: C++ *** |
|
284 ;;; End: *** |
|
285 */ |