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