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