Mercurial > hg > octave-nkf
annotate liboctave/util/cmd-edit.cc @ 16537:106a38d7b396
optionall disable redisplay in command editor clear screen function
* oct-rl-edit.c (octave_rl_clear_screen): Likewise. If skip_redisplay
is true, override rl_redisplay_function. Otherwise, just call
rl_clear_screen.
* cmd-edit.h, cmd-edit.cc (command_editor::clear_screen,
command_editor::do_clear_screen, gnu_readline::do_clear_screen):
New arg, skip_redisplay.
* sysdep.cc (Fclc): Pass true to command_editor::clear_screen.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 18 Apr 2013 02:02:59 -0400 |
parents | 6ebd1e1a6b73 |
children | 8ea8df0747e9 |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13983
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2926 | 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. | |
2926 | 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/>. | |
2926 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
27 #include <cstdlib> |
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstring> |
2926 | 29 |
30 #include <string> | |
31 | |
32 #include <sys/types.h> | |
33 #include <unistd.h> | |
34 | |
5247 | 35 #include "quit.h" |
36 | |
2926 | 37 #include "cmd-edit.h" |
38 #include "cmd-hist.h" | |
5872 | 39 #include "file-ops.h" |
2926 | 40 #include "lo-error.h" |
41 #include "lo-utils.h" | |
42 #include "oct-env.h" | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
43 #include "oct-mutex.h" |
3260 | 44 #include "oct-time.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
45 #include "singleton-cleanup.h" |
2926 | 46 |
47 command_editor *command_editor::instance = 0; | |
48 | |
6913 | 49 std::set<command_editor::startup_hook_fcn> command_editor::startup_hook_set; |
50 | |
51 std::set<command_editor::event_hook_fcn> command_editor::event_hook_set; | |
52 | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
53 static octave_mutex event_hook_lock; |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
54 |
2926 | 55 #if defined (USE_READLINE) |
56 | |
57 #include <cstdio> | |
58 #include <cstdlib> | |
59 | |
3519 | 60 #include "oct-rl-edit.h" |
2926 | 61 |
62 class | |
63 gnu_readline : public command_editor | |
64 { | |
65 public: | |
66 | |
3519 | 67 typedef command_editor::startup_hook_fcn startup_hook_fcn; |
68 | |
6913 | 69 typedef command_editor::event_hook_fcn event_hook_fcn; |
2926 | 70 |
2941 | 71 typedef command_editor::completion_fcn completion_fcn; |
72 | |
2926 | 73 gnu_readline (void); |
74 | |
75 ~gnu_readline (void) { } | |
76 | |
3504 | 77 void do_set_name (const std::string& n); |
2926 | 78 |
3504 | 79 std::string do_readline (const std::string& prompt, bool& eof); |
2926 | 80 |
81 void do_set_input_stream (FILE *f); | |
82 | |
83 FILE *do_get_input_stream (void); | |
84 | |
85 void do_set_output_stream (FILE *f); | |
86 | |
87 FILE *do_get_output_stream (void); | |
88 | |
89 int do_terminal_rows (void); | |
90 | |
91 int do_terminal_cols (void); | |
92 | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
93 void do_clear_screen (bool skip_redisplay); |
2926 | 94 |
3281 | 95 void do_resize_terminal (void); |
96 | |
3504 | 97 std::string newline_chars (void); |
2926 | 98 |
99 void do_restore_terminal_state (void); | |
100 | |
101 void do_blink_matching_paren (bool flag); | |
102 | |
3933 | 103 void do_set_basic_word_break_characters (const std::string& s); |
104 | |
105 void do_set_completer_word_break_characters (const std::string& s); | |
106 | |
3504 | 107 void do_set_basic_quote_characters (const std::string& s); |
2926 | 108 |
6979 | 109 void do_set_filename_quote_characters (const std::string& s); |
110 | |
111 void do_set_completer_quote_characters (const std::string& s); | |
112 | |
2926 | 113 void do_set_completion_append_character (char c); |
114 | |
2941 | 115 void do_set_completion_function (completion_fcn f); |
116 | |
6979 | 117 void do_set_quoting_function (quoting_fcn f); |
118 | |
119 void do_set_dequoting_function (dequoting_fcn f); | |
120 | |
121 void do_set_char_is_quoted_function (char_is_quoted_fcn f); | |
122 | |
123 void do_set_user_accept_line_function (user_accept_line_fcn f); | |
124 | |
2941 | 125 completion_fcn do_get_completion_function (void) const; |
2926 | 126 |
6979 | 127 quoting_fcn do_get_quoting_function (void) const; |
128 | |
129 dequoting_fcn do_get_dequoting_function (void) const; | |
130 | |
131 char_is_quoted_fcn do_get_char_is_quoted_function (void) const; | |
132 | |
133 user_accept_line_fcn do_get_user_accept_line_function (void) const; | |
134 | |
4604 | 135 string_vector |
136 do_generate_filename_completions (const std::string& text); | |
137 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
138 std::string do_get_line_buffer (void) const; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
139 |
3504 | 140 void do_insert_text (const std::string& text); |
2926 | 141 |
142 void do_newline (void); | |
143 | |
6979 | 144 void do_accept_line (void); |
145 | |
2926 | 146 void do_clear_undo_list (void); |
147 | |
6913 | 148 void set_startup_hook (startup_hook_fcn f); |
149 | |
150 void restore_startup_hook (void); | |
2926 | 151 |
6913 | 152 void set_event_hook (event_hook_fcn f); |
2926 | 153 |
6913 | 154 void restore_event_hook (void); |
3215 | 155 |
156 void do_restore_event_hook (void); | |
157 | |
3504 | 158 void do_read_init_file (const std::string& file); |
3189 | 159 |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
160 void do_re_read_init_file (void); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
161 |
4143 | 162 bool do_filename_completion_desired (bool); |
163 | |
6979 | 164 bool do_filename_quoting_desired (bool); |
165 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
166 void do_interrupt (bool); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
167 |
3519 | 168 static int operate_and_get_next (int, int); |
2926 | 169 |
3951 | 170 static int history_search_backward (int, int); |
171 | |
172 static int history_search_forward (int, int); | |
173 | |
2926 | 174 private: |
175 | |
3519 | 176 startup_hook_fcn previous_startup_hook; |
2926 | 177 |
3519 | 178 event_hook_fcn previous_event_hook; |
3215 | 179 |
2941 | 180 completion_fcn completion_function; |
181 | |
6979 | 182 quoting_fcn quoting_function; |
183 | |
184 dequoting_fcn dequoting_function; | |
185 | |
186 char_is_quoted_fcn char_is_quoted_function; | |
187 | |
188 user_accept_line_fcn user_accept_line_function; | |
189 | |
2941 | 190 static char *command_generator (const char *text, int state); |
191 | |
6979 | 192 static char *command_quoter (char *text, int match_type, char *quote_pointer); |
193 static char *command_dequoter (char *text, int match_type); | |
194 | |
195 static int command_char_is_quoted (char *text, int index); | |
196 | |
197 static int command_accept_line (int count, int key); | |
198 | |
3519 | 199 static char **command_completer (const char *text, int start, int end); |
2926 | 200 }; |
201 | |
202 gnu_readline::gnu_readline () | |
3215 | 203 : command_editor (), previous_startup_hook (0), |
6979 | 204 previous_event_hook (0), completion_function (0), |
205 quoting_function (0), dequoting_function (0), | |
206 char_is_quoted_function (0), user_accept_line_function (0) | |
2926 | 207 { |
5775 | 208 // FIXME -- need interface to rl_add_defun, rl_initialize, and |
3519 | 209 // a function to set rl_terminal_name |
3225 | 210 |
3520 | 211 std::string term = octave_env::getenv ("TERM"); |
3519 | 212 |
213 octave_rl_set_terminal_name (term.c_str ()); | |
214 | |
215 octave_rl_initialize (); | |
2926 | 216 |
217 do_blink_matching_paren (true); | |
218 | |
5452 | 219 // Bind operate-and-get-next. |
2926 | 220 |
3519 | 221 octave_rl_add_defun ("operate-and-get-next", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
222 gnu_readline::operate_and_get_next, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
223 octave_rl_ctrl ('O')); |
2926 | 224 |
5452 | 225 // And the history search functions. |
2926 | 226 |
3519 | 227 octave_rl_add_defun ("history-search-backward", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
228 gnu_readline::history_search_backward, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
229 octave_rl_meta ('P')); |
2926 | 230 |
3519 | 231 octave_rl_add_defun ("history-search-forward", |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
232 gnu_readline::history_search_forward, |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
233 octave_rl_meta ('N')); |
2926 | 234 } |
235 | |
236 void | |
3519 | 237 gnu_readline::do_set_name (const std::string& nm) |
2926 | 238 { |
3519 | 239 ::octave_rl_set_name (nm.c_str ()); |
2926 | 240 } |
241 | |
3504 | 242 std::string |
243 gnu_readline::do_readline (const std::string& prompt, bool& eof) | |
2926 | 244 { |
3504 | 245 std::string retval; |
2926 | 246 |
3219 | 247 eof = false; |
248 | |
5247 | 249 char *line = 0; |
250 | |
5336 | 251 const char *p = prompt.c_str (); |
252 | |
5452 | 253 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
5247 | 254 |
5336 | 255 line = ::octave_rl_readline (p); |
5247 | 256 |
5452 | 257 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
2926 | 258 |
259 if (line) | |
260 { | |
261 retval = line; | |
262 | |
263 free (line); | |
264 } | |
3219 | 265 else |
266 eof = true; | |
2926 | 267 |
268 return retval; | |
269 } | |
270 | |
271 void | |
272 gnu_readline::do_set_input_stream (FILE *f) | |
273 { | |
3519 | 274 ::octave_rl_set_input_stream (f); |
2926 | 275 } |
276 | |
277 FILE * | |
278 gnu_readline::do_get_input_stream (void) | |
279 { | |
3519 | 280 return ::octave_rl_get_input_stream (); |
2926 | 281 } |
282 | |
283 void | |
284 gnu_readline::do_set_output_stream (FILE *f) | |
285 { | |
3519 | 286 ::octave_rl_set_output_stream (f); |
2926 | 287 } |
288 | |
289 FILE * | |
290 gnu_readline::do_get_output_stream (void) | |
291 { | |
3519 | 292 return ::octave_rl_get_output_stream (); |
2926 | 293 } |
294 | |
295 // GNU readline handles SIGWINCH, so these values have a good chance | |
296 // of being correct even if the window changes size (they may be | |
297 // wrong if, for example, the luser changes the window size while the | |
298 // pager is running, and the signal is handled by the pager instead of | |
299 // us. | |
300 | |
301 int | |
302 gnu_readline::do_terminal_rows (void) | |
303 { | |
3519 | 304 int sh = ::octave_rl_screen_height (); |
305 | |
306 return sh > 0 ? sh : 24; | |
2926 | 307 } |
308 | |
309 int | |
310 gnu_readline::do_terminal_cols (void) | |
311 { | |
3519 | 312 int sw = ::octave_rl_screen_width (); |
313 | |
314 return sw > 0 ? sw : 80; | |
2926 | 315 } |
316 | |
317 void | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
318 gnu_readline::do_clear_screen (bool skip_redisplay) |
2926 | 319 { |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
320 ::octave_rl_clear_screen (skip_redisplay); |
2926 | 321 } |
322 | |
3281 | 323 void |
324 gnu_readline::do_resize_terminal (void) | |
325 { | |
3519 | 326 ::octave_rl_resize_terminal (); |
3281 | 327 } |
328 | |
3504 | 329 std::string |
2926 | 330 gnu_readline::newline_chars (void) |
331 { | |
332 return "\r\n"; | |
333 } | |
334 | |
335 void | |
336 gnu_readline::do_restore_terminal_state (void) | |
337 { | |
3519 | 338 ::octave_rl_restore_terminal_state (); |
2926 | 339 } |
340 | |
341 void | |
342 gnu_readline::do_blink_matching_paren (bool flag) | |
343 { | |
3779 | 344 ::octave_rl_enable_paren_matching (flag ? 1 : 0); |
2926 | 345 } |
346 | |
347 void | |
3933 | 348 gnu_readline::do_set_basic_word_break_characters (const std::string& s) |
349 { | |
350 ::octave_rl_set_basic_word_break_characters (s.c_str ()); | |
351 } | |
352 | |
353 void | |
354 gnu_readline::do_set_completer_word_break_characters (const std::string& s) | |
355 { | |
356 ::octave_rl_set_completer_word_break_characters (s.c_str ()); | |
357 } | |
358 | |
359 void | |
3504 | 360 gnu_readline::do_set_basic_quote_characters (const std::string& s) |
2926 | 361 { |
3519 | 362 ::octave_rl_set_basic_quote_characters (s.c_str ()); |
2926 | 363 } |
364 | |
365 void | |
6979 | 366 gnu_readline::do_set_filename_quote_characters (const std::string& s) |
367 { | |
368 ::octave_rl_set_filename_quote_characters (s.c_str ()); | |
369 } | |
370 | |
371 void | |
372 gnu_readline::do_set_completer_quote_characters (const std::string& s) | |
373 { | |
374 ::octave_rl_set_completer_quote_characters (s.c_str ()); | |
375 } | |
376 | |
377 void | |
2926 | 378 gnu_readline::do_set_completion_append_character (char c) |
379 { | |
3519 | 380 ::octave_rl_set_completion_append_character (c); |
2926 | 381 } |
382 | |
383 void | |
2941 | 384 gnu_readline::do_set_completion_function (completion_fcn f) |
2926 | 385 { |
2941 | 386 completion_function = f; |
387 | |
3519 | 388 rl_attempted_completion_fcn_ptr fp |
389 = f ? gnu_readline::command_completer : 0; | |
2941 | 390 |
3519 | 391 ::octave_rl_set_completion_function (fp); |
2941 | 392 } |
393 | |
6979 | 394 void |
395 gnu_readline::do_set_quoting_function (quoting_fcn f) | |
396 { | |
397 quoting_function = f; | |
398 | |
399 rl_quoting_fcn_ptr fp | |
400 = f ? gnu_readline::command_quoter : 0; | |
401 | |
402 ::octave_rl_set_quoting_function (fp); | |
403 } | |
404 | |
405 void | |
406 gnu_readline::do_set_dequoting_function (dequoting_fcn f) | |
407 { | |
408 dequoting_function = f; | |
409 | |
410 rl_dequoting_fcn_ptr fp | |
411 = f ? gnu_readline::command_dequoter : 0; | |
412 | |
413 ::octave_rl_set_dequoting_function (fp); | |
414 } | |
415 | |
416 void | |
417 gnu_readline::do_set_char_is_quoted_function (char_is_quoted_fcn f) | |
418 { | |
419 char_is_quoted_function = f; | |
420 | |
421 rl_char_is_quoted_fcn_ptr fp | |
422 = f ? gnu_readline::command_char_is_quoted : 0; | |
423 | |
424 ::octave_rl_set_char_is_quoted_function (fp); | |
425 } | |
426 | |
427 void | |
428 gnu_readline::do_set_user_accept_line_function (user_accept_line_fcn f) | |
429 { | |
430 user_accept_line_function = f; | |
431 | |
432 if (f) | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
433 octave_rl_add_defun ("accept-line", gnu_readline::command_accept_line, |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
434 ::octave_rl_ctrl ('M')); |
6979 | 435 else |
436 octave_rl_add_defun ("accept-line", ::octave_rl_newline, | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
437 ::octave_rl_ctrl ('M')); |
6979 | 438 } |
439 | |
2941 | 440 gnu_readline::completion_fcn |
441 gnu_readline::do_get_completion_function (void) const | |
442 { | |
443 return completion_function; | |
2926 | 444 } |
445 | |
6979 | 446 gnu_readline::quoting_fcn |
447 gnu_readline::do_get_quoting_function (void) const | |
448 { | |
449 return quoting_function; | |
450 } | |
451 | |
452 gnu_readline::dequoting_fcn | |
453 gnu_readline::do_get_dequoting_function (void) const | |
454 { | |
455 return dequoting_function; | |
456 } | |
457 | |
458 gnu_readline::char_is_quoted_fcn | |
459 gnu_readline::do_get_char_is_quoted_function (void) const | |
460 { | |
461 return char_is_quoted_function; | |
462 } | |
463 | |
464 gnu_readline::user_accept_line_fcn | |
465 gnu_readline::do_get_user_accept_line_function (void) const | |
466 { | |
467 return user_accept_line_function; | |
468 } | |
469 | |
4604 | 470 string_vector |
471 gnu_readline::do_generate_filename_completions (const std::string& text) | |
472 { | |
473 string_vector retval; | |
474 | |
475 int n = 0; | |
476 int count = 0; | |
477 | |
478 char *fn = 0; | |
479 | |
480 while (1) | |
481 { | |
482 fn = ::octave_rl_filename_completion_function (text.c_str (), count); | |
483 | |
484 if (fn) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
485 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
486 if (count == n) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
487 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
488 // Famous last words: Most large directories will not |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
489 // have more than a few hundred files, so we should not |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
490 // resize too many times even if the growth is linear... |
4604 | 491 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
492 n += 100; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
493 retval.resize (n); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
494 } |
4604 | 495 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
496 retval[count++] = fn; |
4604 | 497 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
498 free (fn); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
499 } |
4604 | 500 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
501 break; |
4604 | 502 } |
503 | |
504 retval.resize (count); | |
505 | |
506 return retval; | |
507 } | |
508 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
509 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
510 gnu_readline::do_get_line_buffer (void) const |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
511 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
512 return ::octave_rl_line_buffer (); |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
513 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
514 |
2926 | 515 void |
3504 | 516 gnu_readline::do_insert_text (const std::string& text) |
2926 | 517 { |
3519 | 518 ::octave_rl_insert_text (text.c_str ()); |
2926 | 519 } |
520 | |
521 void | |
522 gnu_readline::do_newline (void) | |
523 { | |
6979 | 524 ::octave_rl_newline (1, '\n'); |
525 } | |
526 | |
527 void | |
528 gnu_readline::do_accept_line (void) | |
529 { | |
530 command_accept_line (1, '\n'); | |
2926 | 531 } |
532 | |
533 void | |
534 gnu_readline::do_clear_undo_list () | |
535 { | |
3519 | 536 ::octave_rl_clear_undo_list (); |
2926 | 537 } |
538 | |
539 void | |
6913 | 540 gnu_readline::set_startup_hook (startup_hook_fcn f) |
2926 | 541 { |
3519 | 542 previous_startup_hook = ::octave_rl_get_startup_hook (); |
2926 | 543 |
6917 | 544 if (f != previous_startup_hook) |
545 ::octave_rl_set_startup_hook (f); | |
2926 | 546 } |
547 | |
548 void | |
6913 | 549 gnu_readline::restore_startup_hook (void) |
2926 | 550 { |
3519 | 551 ::octave_rl_set_startup_hook (previous_startup_hook); |
2926 | 552 } |
553 | |
554 void | |
6913 | 555 gnu_readline::set_event_hook (event_hook_fcn f) |
3215 | 556 { |
3519 | 557 previous_event_hook = octave_rl_get_event_hook (); |
3215 | 558 |
3519 | 559 ::octave_rl_set_event_hook (f); |
3215 | 560 } |
561 | |
562 void | |
6913 | 563 gnu_readline::restore_event_hook (void) |
3215 | 564 { |
3519 | 565 ::octave_rl_set_event_hook (previous_event_hook); |
3215 | 566 } |
567 | |
568 void | |
3504 | 569 gnu_readline::do_read_init_file (const std::string& file) |
3189 | 570 { |
3519 | 571 ::octave_rl_read_init_file (file.c_str ()); |
3189 | 572 } |
573 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
574 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
575 gnu_readline::do_re_read_init_file (void) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
576 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
577 ::octave_rl_re_read_init_file (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
578 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
579 |
4143 | 580 bool |
581 gnu_readline::do_filename_completion_desired (bool arg) | |
582 { | |
583 return ::octave_rl_filename_completion_desired (arg); | |
584 } | |
585 | |
6979 | 586 bool |
587 gnu_readline::do_filename_quoting_desired (bool arg) | |
588 { | |
589 return ::octave_rl_filename_quoting_desired (arg); | |
590 } | |
591 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
592 void |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
593 gnu_readline::do_interrupt (bool arg) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
594 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
595 ::octave_rl_done (arg); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
596 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
597 |
3519 | 598 int |
2926 | 599 gnu_readline::operate_and_get_next (int /* count */, int /* c */) |
600 { | |
601 // Accept the current line. | |
602 | |
6979 | 603 command_editor::accept_line (); |
2926 | 604 |
605 // Find the current line, and find the next line to use. | |
606 | |
607 int x_where = command_history::where (); | |
608 | |
609 int x_length = command_history::length (); | |
610 | |
611 if ((command_history::is_stifled () | |
612 && (x_length >= command_history::max_input_history ())) | |
613 || (x_where >= x_length - 1)) | |
614 command_history::set_mark (x_where); | |
615 else | |
616 command_history::set_mark (x_where + 1); | |
617 | |
6913 | 618 command_editor::add_startup_hook (command_history::goto_mark); |
3519 | 619 |
620 return 0; | |
2926 | 621 } |
622 | |
3951 | 623 int |
624 gnu_readline::history_search_backward (int count, int c) | |
625 { | |
626 return octave_rl_history_search_backward (count, c); | |
627 } | |
628 | |
629 int | |
630 gnu_readline::history_search_forward (int count, int c) | |
631 { | |
632 return octave_rl_history_search_forward (count, c); | |
633 } | |
634 | |
2941 | 635 char * |
636 gnu_readline::command_generator (const char *text, int state) | |
637 { | |
638 char *retval = 0; | |
639 | |
640 completion_fcn f = command_editor::get_completion_function (); | |
641 | |
3504 | 642 std::string tmp = f (text, state); |
2941 | 643 |
644 size_t len = tmp.length (); | |
645 | |
646 if (len > 0) | |
647 { | |
10411 | 648 retval = static_cast<char *> (gnulib::malloc (len+1)); |
2941 | 649 |
650 strcpy (retval, tmp.c_str ()); | |
651 } | |
652 | |
653 return retval; | |
654 } | |
655 | |
6979 | 656 char * |
657 gnu_readline::command_quoter (char *text, int matches, char *qcp) | |
658 { | |
659 char *retval = 0; | |
660 | |
661 quoting_fcn f = command_editor::get_quoting_function (); | |
662 | |
663 std::string tmp = f (text, matches, *qcp); | |
664 | |
665 size_t len = tmp.length (); | |
666 | |
667 if (len > 0) | |
668 { | |
10411 | 669 retval = static_cast<char *> (gnulib::malloc (len+1)); |
6979 | 670 |
671 strcpy (retval, tmp.c_str ()); | |
672 } | |
673 | |
674 return retval; | |
675 } | |
676 | |
677 char * | |
678 gnu_readline::command_dequoter (char *text, int quote) | |
679 { | |
680 char *retval = 0; | |
681 | |
682 dequoting_fcn f = command_editor::get_dequoting_function (); | |
683 | |
684 std::string tmp = f (text, quote); | |
685 | |
686 size_t len = tmp.length (); | |
687 | |
688 if (len > 0) | |
689 { | |
10411 | 690 retval = static_cast<char *> (gnulib::malloc (len+1)); |
6979 | 691 |
692 strcpy (retval, tmp.c_str ()); | |
693 } | |
694 | |
695 return retval; | |
696 } | |
697 | |
698 int | |
699 gnu_readline::command_char_is_quoted (char *text, int quote) | |
700 { | |
701 char_is_quoted_fcn f = command_editor::get_char_is_quoted_function (); | |
702 | |
703 return f (text, quote); | |
704 } | |
705 | |
706 int | |
707 gnu_readline::command_accept_line (int count, int key) | |
708 { | |
709 user_accept_line_fcn f = command_editor::get_user_accept_line_function (); | |
710 | |
711 if (f) | |
712 f (::octave_rl_line_buffer ()); | |
713 | |
714 ::octave_rl_redisplay (); | |
715 | |
716 return ::octave_rl_newline (count, key); | |
717 } | |
718 | |
2941 | 719 char ** |
3519 | 720 gnu_readline::command_completer (const char *text, int, int) |
2941 | 721 { |
722 char **matches = 0; | |
3519 | 723 matches |
724 = ::octave_rl_completion_matches (text, gnu_readline::command_generator); | |
2941 | 725 return matches; |
726 } | |
727 | |
2926 | 728 #endif |
729 | |
730 class | |
731 default_command_editor : public command_editor | |
732 { | |
733 public: | |
734 | |
735 default_command_editor (void) | |
736 : command_editor (), input_stream (stdin), output_stream (stdout) { } | |
737 | |
738 ~default_command_editor (void) { } | |
739 | |
3504 | 740 std::string do_readline (const std::string& prompt, bool& eof); |
2926 | 741 |
742 void do_set_input_stream (FILE *f); | |
743 | |
744 FILE *do_get_input_stream (void); | |
745 | |
746 void do_set_output_stream (FILE *f); | |
747 | |
748 FILE *do_get_output_stream (void); | |
749 | |
4604 | 750 string_vector do_generate_filename_completions (const std::string& text); |
751 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
752 std::string do_get_line_buffer (void) const; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
753 |
3504 | 754 void do_insert_text (const std::string&); |
2926 | 755 |
756 void do_newline (void); | |
757 | |
6979 | 758 void do_accept_line (void); |
759 | |
2926 | 760 private: |
761 | |
762 FILE *input_stream; | |
763 | |
764 FILE *output_stream; | |
12153
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
765 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
766 // No copying! |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
767 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
768 default_command_editor (const default_command_editor&); |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
769 |
e0e50f48df37
Explicitly disallow copying in some classes
Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
parents:
11586
diff
changeset
|
770 default_command_editor& operator = (const default_command_editor&); |
2926 | 771 }; |
772 | |
3504 | 773 std::string |
774 default_command_editor::do_readline (const std::string& prompt, bool& eof) | |
2926 | 775 { |
10411 | 776 gnulib::fputs (prompt.c_str (), output_stream); |
12912
e116dd862879
use gnulib:: qualifiers for more stdio functions
John W. Eaton <jwe@octave.org>
parents:
12153
diff
changeset
|
777 gnulib::fflush (output_stream); |
2926 | 778 |
4527 | 779 return octave_fgetl (input_stream, eof); |
2926 | 780 } |
781 | |
782 void | |
783 default_command_editor::do_set_input_stream (FILE *f) | |
784 { | |
785 input_stream = f; | |
786 } | |
787 | |
788 FILE * | |
789 default_command_editor::do_get_input_stream (void) | |
790 { | |
791 return input_stream; | |
792 } | |
793 | |
794 void | |
795 default_command_editor::do_set_output_stream (FILE *f) | |
796 { | |
797 output_stream = f; | |
798 } | |
799 | |
800 FILE * | |
801 default_command_editor::do_get_output_stream (void) | |
802 { | |
803 return output_stream; | |
804 } | |
805 | |
4604 | 806 string_vector |
4663 | 807 default_command_editor::do_generate_filename_completions (const std::string&) |
4604 | 808 { |
5775 | 809 // FIXME |
4604 | 810 return string_vector (); |
811 } | |
812 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
813 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
814 default_command_editor::do_get_line_buffer (void) const |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
815 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
816 return ""; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
817 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
818 |
2926 | 819 void |
3504 | 820 default_command_editor::do_insert_text (const std::string&) |
2926 | 821 { |
5775 | 822 // FIXME |
2926 | 823 } |
824 | |
825 void | |
826 default_command_editor::do_newline (void) | |
827 { | |
5775 | 828 // FIXME |
2926 | 829 } |
830 | |
6979 | 831 void |
832 default_command_editor::do_accept_line (void) | |
833 { | |
834 // FIXME | |
835 } | |
836 | |
2926 | 837 bool |
838 command_editor::instance_ok (void) | |
839 { | |
840 bool retval = true; | |
841 | |
842 if (! instance) | |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
843 { |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
844 make_command_editor (); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
845 |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
846 if (instance) |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
847 singleton_cleanup_list::add (cleanup_instance); |
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
13924
diff
changeset
|
848 } |
2926 | 849 |
850 if (! instance) | |
851 { | |
2941 | 852 current_liboctave_error_handler |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
853 ("unable to create command history object!"); |
2926 | 854 |
855 retval = false; | |
856 } | |
857 | |
858 return retval; | |
859 } | |
860 | |
861 void | |
862 command_editor::make_command_editor (void) | |
863 { | |
864 #if defined (USE_READLINE) | |
865 instance = new gnu_readline (); | |
866 #else | |
867 instance = new default_command_editor (); | |
868 #endif | |
869 } | |
870 | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
871 void |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
872 command_editor::force_default_editor (void) |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
873 { |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
874 delete instance; |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
875 instance = new default_command_editor (); |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
876 } |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
877 |
6913 | 878 int |
879 command_editor::startup_handler (void) | |
880 { | |
881 for (startup_hook_set_iterator p = startup_hook_set.begin (); | |
882 p != startup_hook_set.end (); p++) | |
883 { | |
884 startup_hook_fcn f = *p; | |
885 | |
886 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
887 f (); |
6913 | 888 } |
889 | |
890 return 0; | |
891 } | |
892 | |
893 int | |
894 command_editor::event_handler (void) | |
895 { | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
896 event_hook_lock.lock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
897 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
898 std::set<event_hook_fcn> hook_set (event_hook_set); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
899 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
900 event_hook_lock.unlock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
901 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
902 for (event_hook_set_iterator p = hook_set.begin (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
903 p != hook_set.end (); p++) |
6913 | 904 { |
905 event_hook_fcn f = *p; | |
906 | |
907 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
908 f (); |
6913 | 909 } |
910 | |
911 return 0; | |
912 } | |
913 | |
2926 | 914 void |
3504 | 915 command_editor::set_name (const std::string& n) |
2926 | 916 { |
917 if (instance_ok ()) | |
918 instance->do_set_name (n); | |
919 } | |
920 | |
3504 | 921 std::string |
922 command_editor::readline (const std::string& prompt) | |
2926 | 923 { |
3219 | 924 bool eof; |
925 | |
926 return readline (prompt, eof); | |
927 } | |
928 | |
3504 | 929 std::string |
930 command_editor::readline (const std::string& prompt, bool& eof) | |
3219 | 931 { |
2926 | 932 return (instance_ok ()) |
3504 | 933 ? instance->do_readline (prompt, eof) : std::string (); |
2926 | 934 } |
935 | |
936 void | |
937 command_editor::set_input_stream (FILE *f) | |
938 { | |
939 if (instance_ok ()) | |
940 instance->do_set_input_stream (f); | |
941 } | |
942 | |
943 FILE * | |
944 command_editor::get_input_stream (void) | |
945 { | |
946 return (instance_ok ()) | |
947 ? instance->do_get_input_stream () : 0; | |
948 } | |
949 | |
950 void | |
951 command_editor::set_output_stream (FILE *f) | |
952 { | |
953 if (instance_ok ()) | |
954 instance->do_set_output_stream (f); | |
955 } | |
956 | |
957 FILE * | |
958 command_editor::get_output_stream (void) | |
959 { | |
960 return (instance_ok ()) | |
961 ? instance->do_get_output_stream () : 0; | |
962 } | |
963 | |
964 int | |
965 command_editor::terminal_rows (void) | |
966 { | |
967 return (instance_ok ()) | |
968 ? instance->do_terminal_rows () : -1; | |
969 } | |
970 | |
971 int | |
972 command_editor::terminal_cols (void) | |
973 { | |
974 return (instance_ok ()) | |
975 ? instance->do_terminal_cols () : -1; | |
976 } | |
977 | |
978 void | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
979 command_editor::clear_screen (bool skip_redisplay) |
2926 | 980 { |
981 if (instance_ok ()) | |
16537
106a38d7b396
optionall disable redisplay in command editor clear screen function
John W. Eaton <jwe@octave.org>
parents:
16535
diff
changeset
|
982 instance->do_clear_screen (skip_redisplay); |
2926 | 983 } |
984 | |
3281 | 985 void |
986 command_editor::resize_terminal (void) | |
987 { | |
988 if (instance_ok ()) | |
989 instance->do_resize_terminal (); | |
990 } | |
991 | |
3504 | 992 std::string |
993 command_editor::decode_prompt_string (const std::string& s) | |
2926 | 994 { |
995 return (instance_ok ()) | |
3504 | 996 ? instance->do_decode_prompt_string (s) : std::string (); |
2926 | 997 } |
998 | |
999 int | |
1000 command_editor::current_command_number (void) | |
1001 { | |
1002 return (instance_ok ()) | |
1003 ? instance->command_number : 0; | |
1004 } | |
1005 | |
1006 void | |
1007 command_editor::reset_current_command_number (int n) | |
1008 { | |
1009 if (instance_ok ()) | |
1010 instance->command_number = n; | |
1011 } | |
1012 | |
1013 void | |
2967 | 1014 command_editor::increment_current_command_number (void) |
1015 { | |
1016 if (instance_ok ()) | |
1017 instance->command_number++; | |
1018 } | |
1019 | |
1020 void | |
2926 | 1021 command_editor::restore_terminal_state (void) |
1022 { | |
1023 if (instance_ok ()) | |
1024 instance->do_restore_terminal_state (); | |
1025 } | |
1026 | |
1027 void | |
1028 command_editor::blink_matching_paren (bool flag) | |
1029 { | |
1030 if (instance_ok ()) | |
1031 instance->do_blink_matching_paren (flag); | |
1032 } | |
1033 | |
1034 void | |
3933 | 1035 command_editor::set_basic_word_break_characters (const std::string& s) |
1036 { | |
1037 if (instance_ok ()) | |
1038 instance->do_set_basic_word_break_characters (s); | |
1039 } | |
1040 | |
1041 void | |
1042 command_editor::set_completer_word_break_characters (const std::string& s) | |
1043 { | |
1044 if (instance_ok ()) | |
1045 instance->do_set_completer_word_break_characters (s); | |
1046 } | |
1047 | |
1048 void | |
3504 | 1049 command_editor::set_basic_quote_characters (const std::string& s) |
2926 | 1050 { |
1051 if (instance_ok ()) | |
3004 | 1052 instance->do_set_basic_quote_characters (s); |
2926 | 1053 } |
1054 | |
1055 void | |
6979 | 1056 command_editor::set_filename_quote_characters (const std::string& s) |
1057 { | |
1058 if (instance_ok ()) | |
1059 instance->do_set_filename_quote_characters (s); | |
1060 } | |
1061 | |
1062 void | |
1063 command_editor::set_completer_quote_characters (const std::string& s) | |
1064 { | |
1065 if (instance_ok ()) | |
1066 instance->do_set_completer_quote_characters (s); | |
1067 } | |
1068 | |
1069 void | |
2926 | 1070 command_editor::set_completion_append_character (char c) |
1071 { | |
1072 if (instance_ok ()) | |
1073 instance->do_set_completion_append_character (c); | |
1074 } | |
1075 | |
1076 void | |
2941 | 1077 command_editor::set_completion_function (completion_fcn f) |
2926 | 1078 { |
1079 if (instance_ok ()) | |
2941 | 1080 instance->do_set_completion_function (f); |
1081 } | |
1082 | |
6979 | 1083 void |
1084 command_editor::set_quoting_function (quoting_fcn f) | |
1085 { | |
1086 if (instance_ok ()) | |
1087 instance->do_set_quoting_function (f); | |
1088 } | |
1089 | |
1090 void | |
1091 command_editor::set_dequoting_function (dequoting_fcn f) | |
1092 { | |
1093 if (instance_ok ()) | |
1094 instance->do_set_dequoting_function (f); | |
1095 } | |
1096 | |
1097 void | |
1098 command_editor::set_char_is_quoted_function (char_is_quoted_fcn f) | |
1099 { | |
1100 if (instance_ok ()) | |
1101 instance->do_set_char_is_quoted_function (f); | |
1102 } | |
1103 | |
1104 void | |
1105 command_editor::set_user_accept_line_function (user_accept_line_fcn f) | |
1106 { | |
1107 if (instance_ok ()) | |
1108 instance->do_set_user_accept_line_function (f); | |
1109 } | |
1110 | |
2941 | 1111 command_editor::completion_fcn |
1112 command_editor::get_completion_function (void) | |
1113 { | |
1114 return (instance_ok ()) | |
1115 ? instance->do_get_completion_function () : 0; | |
2926 | 1116 } |
1117 | |
6979 | 1118 command_editor::quoting_fcn |
1119 command_editor::get_quoting_function (void) | |
1120 { | |
1121 return (instance_ok ()) | |
1122 ? instance->do_get_quoting_function () : 0; | |
1123 } | |
1124 | |
1125 command_editor::dequoting_fcn | |
1126 command_editor::get_dequoting_function (void) | |
1127 { | |
1128 return (instance_ok ()) | |
1129 ? instance->do_get_dequoting_function () : 0; | |
1130 } | |
1131 | |
1132 command_editor::char_is_quoted_fcn | |
1133 command_editor::get_char_is_quoted_function (void) | |
1134 { | |
1135 return (instance_ok ()) | |
1136 ? instance->do_get_char_is_quoted_function () : 0; | |
1137 } | |
1138 | |
1139 command_editor::user_accept_line_fcn | |
1140 command_editor::get_user_accept_line_function (void) | |
1141 { | |
1142 return (instance_ok ()) | |
1143 ? instance->do_get_user_accept_line_function () : 0; | |
1144 } | |
1145 | |
4604 | 1146 string_vector |
1147 command_editor::generate_filename_completions (const std::string& text) | |
1148 { | |
1149 return (instance_ok ()) | |
1150 ? instance->do_generate_filename_completions (text) : string_vector (); | |
1151 } | |
1152 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1153 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1154 command_editor::get_line_buffer (void) |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1155 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1156 return (instance_ok ()) ? instance->do_get_line_buffer () : ""; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1157 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1158 |
2926 | 1159 void |
3504 | 1160 command_editor::insert_text (const std::string& text) |
2926 | 1161 { |
1162 if (instance_ok ()) | |
1163 instance->do_insert_text (text); | |
1164 } | |
1165 | |
1166 void | |
1167 command_editor::newline (void) | |
1168 { | |
1169 if (instance_ok ()) | |
1170 instance->do_newline (); | |
1171 } | |
1172 | |
1173 void | |
6979 | 1174 command_editor::accept_line (void) |
1175 { | |
1176 if (instance_ok ()) | |
1177 instance->do_accept_line (); | |
1178 } | |
1179 | |
1180 void | |
2926 | 1181 command_editor::clear_undo_list (void) |
1182 { | |
1183 if (instance_ok ()) | |
1184 instance->do_clear_undo_list (); | |
1185 } | |
1186 | |
1187 void | |
6913 | 1188 command_editor::add_startup_hook (startup_hook_fcn f) |
2926 | 1189 { |
1190 if (instance_ok ()) | |
6913 | 1191 { |
1192 startup_hook_set.insert (f); | |
1193 | |
1194 instance->set_startup_hook (startup_handler); | |
1195 } | |
2926 | 1196 } |
1197 | |
1198 void | |
6913 | 1199 command_editor::remove_startup_hook (startup_hook_fcn f) |
2926 | 1200 { |
1201 if (instance_ok ()) | |
6913 | 1202 { |
1203 startup_hook_set_iterator p = startup_hook_set.find (f); | |
1204 | |
1205 if (p != startup_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1206 startup_hook_set.erase (p); |
6913 | 1207 |
1208 if (startup_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1209 instance->restore_startup_hook (); |
6913 | 1210 } |
2926 | 1211 } |
1212 | |
3189 | 1213 void |
6913 | 1214 command_editor::add_event_hook (event_hook_fcn f) |
3215 | 1215 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1216 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1217 |
3215 | 1218 if (instance_ok ()) |
6913 | 1219 { |
1220 event_hook_set.insert (f); | |
1221 | |
1222 instance->set_event_hook (event_handler); | |
1223 } | |
3215 | 1224 } |
1225 | |
1226 void | |
6913 | 1227 command_editor::remove_event_hook (event_hook_fcn f) |
3215 | 1228 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1229 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1230 |
3215 | 1231 if (instance_ok ()) |
6913 | 1232 { |
1233 event_hook_set_iterator p = event_hook_set.find (f); | |
1234 | |
1235 if (p != event_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1236 event_hook_set.erase (p); |
6913 | 1237 |
1238 if (event_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1239 instance->restore_event_hook (); |
6913 | 1240 } |
3215 | 1241 } |
1242 | |
1243 void | |
13924
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1244 command_editor::run_event_hooks (void) |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1245 { |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1246 event_handler (); |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1247 } |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1248 |
3b654a0753b1
Implement waitfor, uiwait and uiresume.
Michael Goffioul <michael.goffioul@gmail.com>
parents:
12912
diff
changeset
|
1249 void |
5872 | 1250 command_editor::read_init_file (const std::string& file_arg) |
3189 | 1251 { |
1252 if (instance_ok ()) | |
5872 | 1253 { |
1254 std::string file = file_ops::tilde_expand (file_arg); | |
1255 | |
1256 instance->do_read_init_file (file); | |
1257 } | |
3189 | 1258 } |
1259 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1260 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1261 command_editor::re_read_init_file (void) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1262 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1263 if (instance_ok ()) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1264 instance->do_re_read_init_file (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1265 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1266 |
4143 | 1267 bool |
1268 command_editor::filename_completion_desired (bool arg) | |
1269 { | |
1270 return (instance_ok ()) | |
1271 ? instance->do_filename_completion_desired (arg) : false; | |
1272 } | |
1273 | |
6979 | 1274 bool |
1275 command_editor::filename_quoting_desired (bool arg) | |
1276 { | |
1277 return (instance_ok ()) | |
1278 ? instance->do_filename_quoting_desired (arg) : false; | |
1279 } | |
1280 | |
16382
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1281 bool |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1282 command_editor::interrupt (bool arg) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1283 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1284 bool retval; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1285 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1286 if (instance_ok ()) |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1287 { |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1288 // Return the current interrupt state. |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1289 retval = instance->interrupted; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1290 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1291 instance->do_interrupt (arg); |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1292 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1293 instance->interrupted = arg; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1294 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1295 else |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1296 retval = false; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1297 |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1298 return retval; |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1299 } |
389b09a914e2
allow gui to force readline to return from its idle/read loop
John W. Eaton <jwe@octave.org>
parents:
15467
diff
changeset
|
1300 |
2926 | 1301 // Return a string which will be printed as a prompt. The string may |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1302 // contain special characters which are decoded as follows: |
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1303 // |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1304 // \a bell (ascii 07) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1305 // \d the date |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1306 // \e escape (ascii 033) |
15466
d174210ce1ec
use ' instead of ` in error messages, warnings and most comments
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
1307 // \h the hostname up to the first '.' |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1308 // \H the hostname |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1309 // \n CRLF |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1310 // \r CR |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1311 // \s the name of the shell (program) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1312 // \t the time |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1313 // \T the time in 12-hour hh:mm:ss format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1314 // \@ the time in 12-hour hh:mm am/pm format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1315 // \A the time in 24-hour hh:mm format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1316 // \u your username |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1317 // \w the current working directory |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1318 // \W the last element of PWD |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1319 // \! the history number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1320 // \# the command number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1321 // \$ a $ or a # if you are root |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1322 // \nnn character code nnn in octal |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1323 // \\ a backslash |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1324 // \[ begin a sequence of non-printing chars |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1325 // \] end a sequence of non-printing chars |
2926 | 1326 |
3504 | 1327 std::string |
1328 command_editor::do_decode_prompt_string (const std::string& s) | |
2926 | 1329 { |
3504 | 1330 std::string result; |
1331 std::string temp; | |
2926 | 1332 size_t i = 0; |
1333 size_t slen = s.length (); | |
1334 int c; | |
1335 | |
1336 while (i < slen) | |
1337 { | |
1338 c = s[i]; | |
1339 | |
1340 i++; | |
1341 | |
1342 if (c == '\\') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1343 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1344 c = s[i]; |
2926 | 1345 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1346 switch (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1347 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1348 case '0': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1349 case '1': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1350 case '2': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1351 case '3': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1352 case '4': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1353 case '5': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1354 case '6': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1355 case '7': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1356 // Maybe convert an octal number. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1357 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1358 int n = read_octal (s.substr (i, 3)); |
2926 | 1359 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1360 temp = "\\"; |
2926 | 1361 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1362 if (n != -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1363 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1364 i += 3; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1365 temp[0] = n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1366 } |
2926 | 1367 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1368 c = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1369 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1370 } |
5442 | 1371 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1372 case 'a': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1373 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1374 temp = '\a'; |
5442 | 1375 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1376 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1377 } |
5442 | 1378 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1379 case 'e': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1380 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1381 temp = '\033'; |
5442 | 1382 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1383 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1384 } |
5442 | 1385 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1386 case 'r': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1387 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1388 temp = '\r'; |
5442 | 1389 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1390 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1391 } |
5442 | 1392 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1393 case 'd': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1394 case 't': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1395 case 'T': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1396 case '@': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1397 case 'A': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1398 // Make the current time/date into a string. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1399 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1400 octave_localtime now; |
2926 | 1401 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1402 if (c == 'd') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1403 temp = now.strftime ("%a %b %d"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1404 else if (c == 't') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1405 temp = now.strftime ("%H:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1406 else if (c == 'T') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1407 temp = now.strftime ("%I:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1408 else if (c == '@') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1409 temp = now.strftime ("%I:%M %p"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1410 else if (c == 'A') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1411 temp = now.strftime ("%H:%M"); |
2926 | 1412 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1413 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1414 } |
2926 | 1415 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1416 case 'n': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1417 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1418 temp = newline_chars (); |
2926 | 1419 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1420 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1421 } |
2926 | 1422 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1423 case 's': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1424 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1425 temp = octave_env::get_program_name (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1426 temp = octave_env::base_pathname (temp); |
2926 | 1427 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1428 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1429 } |
5442 | 1430 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1431 case 'w': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1432 case 'W': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1433 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1434 temp = octave_env::get_current_directory (); |
2926 | 1435 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1436 std::string home_dir = octave_env::get_home_directory (); |
5442 | 1437 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1438 if (c == 'W' && (home_dir.empty () || temp != home_dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1439 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1440 if (temp != "/" && temp != "//") |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1441 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1442 size_t pos = temp.rfind ('/'); |
2926 | 1443 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1444 if (pos != std::string::npos && pos != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1445 temp = temp.substr (pos + 1); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1446 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1447 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1448 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1449 temp = octave_env::polite_directory_format (temp); |
2926 | 1450 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1451 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1452 } |
5442 | 1453 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1454 case 'u': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1455 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1456 temp = octave_env::get_user_name (); |
2926 | 1457 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1458 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1459 } |
2926 | 1460 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1461 case 'H': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1462 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1463 temp = octave_env::get_host_name (); |
2926 | 1464 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1465 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1466 } |
2926 | 1467 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1468 case 'h': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1469 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1470 temp = octave_env::get_host_name (); |
2926 | 1471 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1472 size_t pos = temp.find ('.'); |
2926 | 1473 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1474 if (pos != std::string::npos) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1475 temp.resize (pos); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
1476 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1477 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1478 } |
2926 | 1479 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1480 case '#': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1481 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1482 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1483 sprintf (number_buffer, "%d", command_number); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1484 temp = number_buffer; |
2926 | 1485 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1486 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1487 } |
2926 | 1488 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1489 case '!': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1490 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1491 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1492 int num = command_history::current_number (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1493 if (num > 0) |
2926 | 1494 sprintf (number_buffer, "%d", num); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1495 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1496 strcpy (number_buffer, "!"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1497 temp = number_buffer; |
2926 | 1498 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1499 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1500 } |
2926 | 1501 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1502 case '$': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1503 { |
4062 | 1504 #if defined (HAVE_GETEUID) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1505 temp = (::geteuid () == 0 ? "#" : "$"); |
4062 | 1506 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1507 temp = "$"; |
4062 | 1508 #endif |
2926 | 1509 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1510 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1511 } |
2926 | 1512 |
1513 #if defined (USE_READLINE) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1514 case '[': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1515 case ']': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1516 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1517 temp.resize (1); |
2926 | 1518 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1519 temp[0] = ((c == '[') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1520 ? ::octave_rl_prompt_start_ignore () |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1521 : ::octave_rl_prompt_end_ignore ()); |
2926 | 1522 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1523 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1524 } |
2926 | 1525 #endif |
1526 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1527 case '\\': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1528 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1529 temp = "\\"; |
2926 | 1530 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1531 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1532 } |
2926 | 1533 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1534 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1535 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1536 temp = "\\ "; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1537 temp[1] = c; |
2926 | 1538 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1539 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1540 } |
2926 | 1541 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1542 add_string: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1543 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1544 if (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1545 i++; |
2926 | 1546 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1547 result.append (temp); |
2926 | 1548 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1549 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1550 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1551 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1552 } |
2926 | 1553 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1554 result += c; |
2926 | 1555 } |
1556 | |
1557 return result; | |
1558 } | |
1559 | |
1560 // Return the octal number parsed from STRING, or -1 to indicate that | |
1561 // the string contained a bad number. | |
1562 | |
1563 int | |
3504 | 1564 command_editor::read_octal (const std::string& s) |
2926 | 1565 { |
1566 int result = 0; | |
1567 int digits = 0; | |
1568 | |
1569 size_t i = 0; | |
1570 size_t slen = s.length (); | |
1571 | |
1572 while (i < slen && s[i] >= '0' && s[i] < '8') | |
1573 { | |
1574 digits++; | |
1575 result = (result * 8) + s[i] - '0'; | |
1576 i++; | |
1577 } | |
1578 | |
1579 if (! digits || result > 0777 || i < slen) | |
1580 result = -1; | |
1581 | |
1582 return result; | |
1583 } | |
1584 | |
1585 void | |
1586 command_editor::error (int err_num) | |
1587 { | |
10411 | 1588 current_liboctave_error_handler ("%s", gnulib::strerror (err_num)); |
2926 | 1589 } |
1590 | |
1591 void | |
3504 | 1592 command_editor::error (const std::string& s) |
2926 | 1593 { |
2941 | 1594 current_liboctave_error_handler ("%s", s.c_str ()); |
2926 | 1595 } |