Mercurial > hg > octave-lyh
annotate liboctave/oct-rl-edit.c @ 10396:a0b51ac0f88a
optimize accumdim with summation
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 05 Mar 2010 12:31:30 +0100 |
parents | 4c0cdbe0acca |
children | fd0a3ac60b0e |
rev | line source |
---|---|
3519 | 1 /* |
2 | |
8920 | 3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
7017 | 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 { | |
7757
4ff9a6fdde42
Load the default inputrc when calling read_readline_init_file()
Rafael Laboissiere <rafael@debian.org>
parents:
7017
diff
changeset
|
197 rl_read_init_file (f); |
3519 | 198 } |
199 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
200 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
201 octave_rl_re_read_init_file (void) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
202 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
203 rl_re_read_init_file (0, 0); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
204 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7757
diff
changeset
|
205 |
4143 | 206 int |
207 octave_rl_filename_completion_desired (int arg) | |
208 { | |
209 int retval = rl_filename_completion_desired; | |
210 rl_filename_completion_desired = arg; | |
211 return retval; | |
212 } | |
213 | |
6979 | 214 int |
215 octave_rl_filename_quoting_desired (int arg) | |
216 { | |
217 int retval = rl_filename_quoting_desired; | |
218 rl_filename_quoting_desired = arg; | |
219 return retval; | |
220 } | |
221 | |
4604 | 222 char * |
223 octave_rl_filename_completion_function (const char *text, int state) | |
224 { | |
225 return rl_filename_completion_function (text, state); | |
226 } | |
227 | |
3519 | 228 void |
3933 | 229 octave_rl_set_basic_word_break_characters (const char *s) |
230 { | |
231 OCTAVE_RL_SAVE_STRING (ss, s); | |
232 | |
233 rl_basic_word_break_characters = ss; | |
234 } | |
235 | |
236 void | |
237 octave_rl_set_completer_word_break_characters (const char *s) | |
238 { | |
239 OCTAVE_RL_SAVE_STRING (ss, s); | |
240 | |
241 rl_completer_word_break_characters = ss; | |
242 } | |
243 | |
244 void | |
3519 | 245 octave_rl_set_basic_quote_characters (const char *s) |
246 { | |
3933 | 247 OCTAVE_RL_SAVE_STRING (ss, s); |
3519 | 248 |
249 rl_basic_quote_characters = ss; | |
250 } | |
251 | |
252 void | |
6979 | 253 octave_rl_set_filename_quote_characters (const char *s) |
254 { | |
255 OCTAVE_RL_SAVE_STRING (ss, s); | |
256 | |
257 rl_filename_quote_characters = ss; | |
258 } | |
259 | |
260 void | |
261 octave_rl_set_completer_quote_characters (const char *s) | |
262 { | |
263 OCTAVE_RL_SAVE_STRING (ss, s); | |
264 | |
265 rl_completer_quote_characters = ss; | |
266 } | |
267 | |
268 void | |
3519 | 269 octave_rl_set_completion_append_character (char c) |
270 { | |
271 rl_completion_append_character = c; | |
272 } | |
273 | |
274 void | |
275 octave_rl_set_completion_function (rl_attempted_completion_fcn_ptr f) | |
276 { | |
277 rl_attempted_completion_function = f; | |
278 } | |
279 | |
280 void | |
6979 | 281 octave_rl_set_quoting_function (rl_quoting_fcn_ptr f) |
282 { | |
283 rl_filename_quoting_function = f; | |
284 } | |
285 | |
286 void | |
287 octave_rl_set_dequoting_function (rl_dequoting_fcn_ptr f) | |
288 { | |
289 rl_filename_dequoting_function = f; | |
290 } | |
291 | |
292 void | |
293 octave_rl_set_char_is_quoted_function (rl_char_is_quoted_fcn_ptr f) | |
294 { | |
295 rl_char_is_quoted_p = f; | |
296 } | |
297 | |
298 void | |
3519 | 299 octave_rl_set_startup_hook (rl_startup_hook_fcn_ptr f) |
300 { | |
4802 | 301 rl_startup_hook = f; |
3519 | 302 } |
303 | |
304 rl_startup_hook_fcn_ptr | |
305 octave_rl_get_startup_hook (void) | |
306 { | |
4802 | 307 return rl_startup_hook; |
3519 | 308 } |
309 | |
310 void | |
311 octave_rl_set_event_hook (rl_event_hook_fcn_ptr f) | |
312 { | |
4802 | 313 rl_event_hook = f; |
3519 | 314 } |
315 | |
316 rl_event_hook_fcn_ptr | |
317 octave_rl_get_event_hook (void) | |
318 { | |
4802 | 319 return rl_event_hook; |
3519 | 320 } |
321 | |
322 char ** | |
323 octave_rl_completion_matches (const char *text, rl_completer_fcn_ptr f) | |
324 { | |
3779 | 325 return rl_completion_matches (text, f); |
3519 | 326 } |
327 | |
328 char | |
329 octave_rl_prompt_start_ignore (void) | |
330 { | |
331 return RL_PROMPT_START_IGNORE; | |
332 } | |
333 | |
334 char | |
335 octave_rl_prompt_end_ignore (void) | |
336 { | |
337 return RL_PROMPT_END_IGNORE; | |
338 } | |
339 | |
340 void | |
341 octave_rl_add_defun (const char *name, rl_fcn_ptr f, char key) | |
342 { | |
343 rl_add_defun (name, f, key); | |
344 } | |
345 | |
346 void | |
347 octave_rl_set_terminal_name (const char *term) | |
348 { | |
10102
8b4e3388a254
oct-rl-edit.c (octave_rl_set_terminal_name): save term string before setting rl_terminal_name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
349 OCTAVE_RL_SAVE_STRING (saved_term, term); |
8b4e3388a254
oct-rl-edit.c (octave_rl_set_terminal_name): save term string before setting rl_terminal_name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
350 |
8b4e3388a254
oct-rl-edit.c (octave_rl_set_terminal_name): save term string before setting rl_terminal_name
John W. Eaton <jwe@octave.org>
parents:
8920
diff
changeset
|
351 rl_terminal_name = saved_term; |
3519 | 352 } |
353 | |
354 void | |
355 octave_rl_initialize (void) | |
356 { | |
357 rl_initialize (); | |
358 } | |
359 | |
360 int | |
361 octave_rl_history_search_forward (int count, int ignore) | |
362 { | |
363 return rl_history_search_forward (count, ignore); | |
364 } | |
365 | |
366 int | |
367 octave_rl_history_search_backward (int count, int ignore) | |
368 { | |
369 return rl_history_search_backward (count, ignore); | |
370 } | |
371 | |
372 char | |
373 octave_rl_ctrl (char c) | |
374 { | |
375 return CTRL (c); | |
376 } | |
377 | |
378 char | |
379 octave_rl_meta (char c) | |
380 { | |
381 return META (c); | |
382 } | |
383 | |
384 #endif |