Mercurial > hg > octave-nkf
annotate liboctave/cmd-edit.cc @ 10447:12d25a1d84bf
Use gnulib headers instead of C++ std headers where needed.
author | David Grundberg <davidg@cs.umu.se> |
---|---|
date | Wed, 24 Mar 2010 17:27:58 +0100 |
parents | 479cc8a0a846 |
children | bbe99b2a5ba7 |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, |
8920 | 4 2006, 2007, 2008, 2009 John W. Eaton |
2926 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2926 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2926 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
10447
12d25a1d84bf
Use gnulib headers instead of C++ std headers where needed.
David Grundberg <davidg@cs.umu.se>
parents:
10411
diff
changeset
|
28 #include "stdlib.h" |
12d25a1d84bf
Use gnulib headers instead of C++ std headers where needed.
David Grundberg <davidg@cs.umu.se>
parents:
10411
diff
changeset
|
29 #include "string.h" |
2926 | 30 |
31 #include <string> | |
32 | |
33 #include <sys/types.h> | |
34 #include <unistd.h> | |
35 | |
5247 | 36 #include "quit.h" |
37 | |
2926 | 38 #include "cmd-edit.h" |
39 #include "cmd-hist.h" | |
5872 | 40 #include "file-ops.h" |
2926 | 41 #include "lo-error.h" |
42 #include "lo-utils.h" | |
43 #include "oct-env.h" | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
44 #include "oct-mutex.h" |
3260 | 45 #include "oct-time.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) | |
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; | |
757 }; | |
758 | |
3504 | 759 std::string |
760 default_command_editor::do_readline (const std::string& prompt, bool& eof) | |
2926 | 761 { |
10411 | 762 gnulib::fputs (prompt.c_str (), output_stream); |
2926 | 763 fflush (output_stream); |
764 | |
4527 | 765 return octave_fgetl (input_stream, eof); |
2926 | 766 } |
767 | |
768 void | |
769 default_command_editor::do_set_input_stream (FILE *f) | |
770 { | |
771 input_stream = f; | |
772 } | |
773 | |
774 FILE * | |
775 default_command_editor::do_get_input_stream (void) | |
776 { | |
777 return input_stream; | |
778 } | |
779 | |
780 void | |
781 default_command_editor::do_set_output_stream (FILE *f) | |
782 { | |
783 output_stream = f; | |
784 } | |
785 | |
786 FILE * | |
787 default_command_editor::do_get_output_stream (void) | |
788 { | |
789 return output_stream; | |
790 } | |
791 | |
4604 | 792 string_vector |
4663 | 793 default_command_editor::do_generate_filename_completions (const std::string&) |
4604 | 794 { |
5775 | 795 // FIXME |
4604 | 796 return string_vector (); |
797 } | |
798 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
799 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
800 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
|
801 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
802 return ""; |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
803 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
804 |
2926 | 805 void |
3504 | 806 default_command_editor::do_insert_text (const std::string&) |
2926 | 807 { |
5775 | 808 // FIXME |
2926 | 809 } |
810 | |
811 void | |
812 default_command_editor::do_newline (void) | |
813 { | |
5775 | 814 // FIXME |
2926 | 815 } |
816 | |
6979 | 817 void |
818 default_command_editor::do_accept_line (void) | |
819 { | |
820 // FIXME | |
821 } | |
822 | |
2926 | 823 bool |
824 command_editor::instance_ok (void) | |
825 { | |
826 bool retval = true; | |
827 | |
828 if (! instance) | |
829 make_command_editor (); | |
830 | |
831 if (! instance) | |
832 { | |
2941 | 833 current_liboctave_error_handler |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
834 ("unable to create command history object!"); |
2926 | 835 |
836 retval = false; | |
837 } | |
838 | |
839 return retval; | |
840 } | |
841 | |
842 void | |
843 command_editor::make_command_editor (void) | |
844 { | |
845 #if defined (USE_READLINE) | |
846 instance = new gnu_readline (); | |
847 #else | |
848 instance = new default_command_editor (); | |
849 #endif | |
850 } | |
851 | |
9321
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
852 void |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
853 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
|
854 { |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
855 delete instance; |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
856 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
|
857 } |
9b87aeb24ea9
avoid using readline at all when line editing suppressed or interpreter embedded
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
858 |
6913 | 859 int |
860 command_editor::startup_handler (void) | |
861 { | |
862 for (startup_hook_set_iterator p = startup_hook_set.begin (); | |
863 p != startup_hook_set.end (); p++) | |
864 { | |
865 startup_hook_fcn f = *p; | |
866 | |
867 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
868 f (); |
6913 | 869 } |
870 | |
871 return 0; | |
872 } | |
873 | |
874 int | |
875 command_editor::event_handler (void) | |
876 { | |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
877 event_hook_lock.lock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
878 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
879 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
|
880 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
881 event_hook_lock.unlock (); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
882 |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
883 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
|
884 p != hook_set.end (); p++) |
6913 | 885 { |
886 event_hook_fcn f = *p; | |
887 | |
888 if (f) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
889 f (); |
6913 | 890 } |
891 | |
892 return 0; | |
893 } | |
894 | |
2926 | 895 void |
3504 | 896 command_editor::set_name (const std::string& n) |
2926 | 897 { |
898 if (instance_ok ()) | |
899 instance->do_set_name (n); | |
900 } | |
901 | |
3504 | 902 std::string |
903 command_editor::readline (const std::string& prompt) | |
2926 | 904 { |
3219 | 905 bool eof; |
906 | |
907 return readline (prompt, eof); | |
908 } | |
909 | |
3504 | 910 std::string |
911 command_editor::readline (const std::string& prompt, bool& eof) | |
3219 | 912 { |
2926 | 913 return (instance_ok ()) |
3504 | 914 ? instance->do_readline (prompt, eof) : std::string (); |
2926 | 915 } |
916 | |
917 void | |
918 command_editor::set_input_stream (FILE *f) | |
919 { | |
920 if (instance_ok ()) | |
921 instance->do_set_input_stream (f); | |
922 } | |
923 | |
924 FILE * | |
925 command_editor::get_input_stream (void) | |
926 { | |
927 return (instance_ok ()) | |
928 ? instance->do_get_input_stream () : 0; | |
929 } | |
930 | |
931 void | |
932 command_editor::set_output_stream (FILE *f) | |
933 { | |
934 if (instance_ok ()) | |
935 instance->do_set_output_stream (f); | |
936 } | |
937 | |
938 FILE * | |
939 command_editor::get_output_stream (void) | |
940 { | |
941 return (instance_ok ()) | |
942 ? instance->do_get_output_stream () : 0; | |
943 } | |
944 | |
945 int | |
946 command_editor::terminal_rows (void) | |
947 { | |
948 return (instance_ok ()) | |
949 ? instance->do_terminal_rows () : -1; | |
950 } | |
951 | |
952 int | |
953 command_editor::terminal_cols (void) | |
954 { | |
955 return (instance_ok ()) | |
956 ? instance->do_terminal_cols () : -1; | |
957 } | |
958 | |
959 void | |
960 command_editor::clear_screen (void) | |
961 { | |
962 if (instance_ok ()) | |
963 instance->do_clear_screen (); | |
964 } | |
965 | |
3281 | 966 void |
967 command_editor::resize_terminal (void) | |
968 { | |
969 if (instance_ok ()) | |
970 instance->do_resize_terminal (); | |
971 } | |
972 | |
3504 | 973 std::string |
974 command_editor::decode_prompt_string (const std::string& s) | |
2926 | 975 { |
976 return (instance_ok ()) | |
3504 | 977 ? instance->do_decode_prompt_string (s) : std::string (); |
2926 | 978 } |
979 | |
980 int | |
981 command_editor::current_command_number (void) | |
982 { | |
983 return (instance_ok ()) | |
984 ? instance->command_number : 0; | |
985 } | |
986 | |
987 void | |
988 command_editor::reset_current_command_number (int n) | |
989 { | |
990 if (instance_ok ()) | |
991 instance->command_number = n; | |
992 } | |
993 | |
994 void | |
2967 | 995 command_editor::increment_current_command_number (void) |
996 { | |
997 if (instance_ok ()) | |
998 instance->command_number++; | |
999 } | |
1000 | |
1001 void | |
2926 | 1002 command_editor::restore_terminal_state (void) |
1003 { | |
1004 if (instance_ok ()) | |
1005 instance->do_restore_terminal_state (); | |
1006 } | |
1007 | |
1008 void | |
1009 command_editor::blink_matching_paren (bool flag) | |
1010 { | |
1011 if (instance_ok ()) | |
1012 instance->do_blink_matching_paren (flag); | |
1013 } | |
1014 | |
1015 void | |
3933 | 1016 command_editor::set_basic_word_break_characters (const std::string& s) |
1017 { | |
1018 if (instance_ok ()) | |
1019 instance->do_set_basic_word_break_characters (s); | |
1020 } | |
1021 | |
1022 void | |
1023 command_editor::set_completer_word_break_characters (const std::string& s) | |
1024 { | |
1025 if (instance_ok ()) | |
1026 instance->do_set_completer_word_break_characters (s); | |
1027 } | |
1028 | |
1029 void | |
3504 | 1030 command_editor::set_basic_quote_characters (const std::string& s) |
2926 | 1031 { |
1032 if (instance_ok ()) | |
3004 | 1033 instance->do_set_basic_quote_characters (s); |
2926 | 1034 } |
1035 | |
1036 void | |
6979 | 1037 command_editor::set_filename_quote_characters (const std::string& s) |
1038 { | |
1039 if (instance_ok ()) | |
1040 instance->do_set_filename_quote_characters (s); | |
1041 } | |
1042 | |
1043 void | |
1044 command_editor::set_completer_quote_characters (const std::string& s) | |
1045 { | |
1046 if (instance_ok ()) | |
1047 instance->do_set_completer_quote_characters (s); | |
1048 } | |
1049 | |
1050 void | |
2926 | 1051 command_editor::set_completion_append_character (char c) |
1052 { | |
1053 if (instance_ok ()) | |
1054 instance->do_set_completion_append_character (c); | |
1055 } | |
1056 | |
1057 void | |
2941 | 1058 command_editor::set_completion_function (completion_fcn f) |
2926 | 1059 { |
1060 if (instance_ok ()) | |
2941 | 1061 instance->do_set_completion_function (f); |
1062 } | |
1063 | |
6979 | 1064 void |
1065 command_editor::set_quoting_function (quoting_fcn f) | |
1066 { | |
1067 if (instance_ok ()) | |
1068 instance->do_set_quoting_function (f); | |
1069 } | |
1070 | |
1071 void | |
1072 command_editor::set_dequoting_function (dequoting_fcn f) | |
1073 { | |
1074 if (instance_ok ()) | |
1075 instance->do_set_dequoting_function (f); | |
1076 } | |
1077 | |
1078 void | |
1079 command_editor::set_char_is_quoted_function (char_is_quoted_fcn f) | |
1080 { | |
1081 if (instance_ok ()) | |
1082 instance->do_set_char_is_quoted_function (f); | |
1083 } | |
1084 | |
1085 void | |
1086 command_editor::set_user_accept_line_function (user_accept_line_fcn f) | |
1087 { | |
1088 if (instance_ok ()) | |
1089 instance->do_set_user_accept_line_function (f); | |
1090 } | |
1091 | |
2941 | 1092 command_editor::completion_fcn |
1093 command_editor::get_completion_function (void) | |
1094 { | |
1095 return (instance_ok ()) | |
1096 ? instance->do_get_completion_function () : 0; | |
2926 | 1097 } |
1098 | |
6979 | 1099 command_editor::quoting_fcn |
1100 command_editor::get_quoting_function (void) | |
1101 { | |
1102 return (instance_ok ()) | |
1103 ? instance->do_get_quoting_function () : 0; | |
1104 } | |
1105 | |
1106 command_editor::dequoting_fcn | |
1107 command_editor::get_dequoting_function (void) | |
1108 { | |
1109 return (instance_ok ()) | |
1110 ? instance->do_get_dequoting_function () : 0; | |
1111 } | |
1112 | |
1113 command_editor::char_is_quoted_fcn | |
1114 command_editor::get_char_is_quoted_function (void) | |
1115 { | |
1116 return (instance_ok ()) | |
1117 ? instance->do_get_char_is_quoted_function () : 0; | |
1118 } | |
1119 | |
1120 command_editor::user_accept_line_fcn | |
1121 command_editor::get_user_accept_line_function (void) | |
1122 { | |
1123 return (instance_ok ()) | |
1124 ? instance->do_get_user_accept_line_function () : 0; | |
1125 } | |
1126 | |
4604 | 1127 string_vector |
1128 command_editor::generate_filename_completions (const std::string& text) | |
1129 { | |
1130 return (instance_ok ()) | |
1131 ? instance->do_generate_filename_completions (text) : string_vector (); | |
1132 } | |
1133 | |
9485
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1134 std::string |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1135 command_editor::get_line_buffer (void) |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1136 { |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1137 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
|
1138 } |
3cee58bf4acf
selectively complete filenames in some cases
John W. Eaton <jwe@octave.org>
parents:
9321
diff
changeset
|
1139 |
2926 | 1140 void |
3504 | 1141 command_editor::insert_text (const std::string& text) |
2926 | 1142 { |
1143 if (instance_ok ()) | |
1144 instance->do_insert_text (text); | |
1145 } | |
1146 | |
1147 void | |
1148 command_editor::newline (void) | |
1149 { | |
1150 if (instance_ok ()) | |
1151 instance->do_newline (); | |
1152 } | |
1153 | |
1154 void | |
6979 | 1155 command_editor::accept_line (void) |
1156 { | |
1157 if (instance_ok ()) | |
1158 instance->do_accept_line (); | |
1159 } | |
1160 | |
1161 void | |
2926 | 1162 command_editor::clear_undo_list (void) |
1163 { | |
1164 if (instance_ok ()) | |
1165 instance->do_clear_undo_list (); | |
1166 } | |
1167 | |
1168 void | |
6913 | 1169 command_editor::add_startup_hook (startup_hook_fcn f) |
2926 | 1170 { |
1171 if (instance_ok ()) | |
6913 | 1172 { |
1173 startup_hook_set.insert (f); | |
1174 | |
1175 instance->set_startup_hook (startup_handler); | |
1176 } | |
2926 | 1177 } |
1178 | |
1179 void | |
6913 | 1180 command_editor::remove_startup_hook (startup_hook_fcn f) |
2926 | 1181 { |
1182 if (instance_ok ()) | |
6913 | 1183 { |
1184 startup_hook_set_iterator p = startup_hook_set.find (f); | |
1185 | |
1186 if (p != startup_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1187 startup_hook_set.erase (p); |
6913 | 1188 |
1189 if (startup_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1190 instance->restore_startup_hook (); |
6913 | 1191 } |
2926 | 1192 } |
1193 | |
3189 | 1194 void |
6913 | 1195 command_editor::add_event_hook (event_hook_fcn f) |
3215 | 1196 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1197 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1198 |
3215 | 1199 if (instance_ok ()) |
6913 | 1200 { |
1201 event_hook_set.insert (f); | |
1202 | |
1203 instance->set_event_hook (event_handler); | |
1204 } | |
3215 | 1205 } |
1206 | |
1207 void | |
6913 | 1208 command_editor::remove_event_hook (event_hook_fcn f) |
3215 | 1209 { |
7936
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1210 octave_autolock guard (event_hook_lock); |
78400fde223e
Support for backend-to-octave event management
John W. Eaton <jwe@octave.org>
parents:
7758
diff
changeset
|
1211 |
3215 | 1212 if (instance_ok ()) |
6913 | 1213 { |
1214 event_hook_set_iterator p = event_hook_set.find (f); | |
1215 | |
1216 if (p != event_hook_set.end ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1217 event_hook_set.erase (p); |
6913 | 1218 |
1219 if (event_hook_set.empty ()) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1220 instance->restore_event_hook (); |
6913 | 1221 } |
3215 | 1222 } |
1223 | |
1224 void | |
5872 | 1225 command_editor::read_init_file (const std::string& file_arg) |
3189 | 1226 { |
1227 if (instance_ok ()) | |
5872 | 1228 { |
1229 std::string file = file_ops::tilde_expand (file_arg); | |
1230 | |
1231 instance->do_read_init_file (file); | |
1232 } | |
3189 | 1233 } |
1234 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1235 void |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1236 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
|
1237 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1238 if (instance_ok ()) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1239 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
|
1240 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
1241 |
4143 | 1242 bool |
1243 command_editor::filename_completion_desired (bool arg) | |
1244 { | |
1245 return (instance_ok ()) | |
1246 ? instance->do_filename_completion_desired (arg) : false; | |
1247 } | |
1248 | |
6979 | 1249 bool |
1250 command_editor::filename_quoting_desired (bool arg) | |
1251 { | |
1252 return (instance_ok ()) | |
1253 ? instance->do_filename_quoting_desired (arg) : false; | |
1254 } | |
1255 | |
2926 | 1256 // Return a string which will be printed as a prompt. The string may |
1257 // contain special characters which are decoded as follows: | |
1258 // | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1259 // \a bell (ascii 07) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1260 // \d the date |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1261 // \e escape (ascii 033) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1262 // \h the hostname up to the first `.' |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1263 // \H the hostname |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1264 // \n CRLF |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1265 // \r CR |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1266 // \s the name of the shell (program) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1267 // \t the time |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1268 // \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
|
1269 // \@ 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
|
1270 // \A the time in 24-hour hh:mm format |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1271 // \u your username |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1272 // \w the current working directory |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1273 // \W the last element of PWD |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1274 // \! the history number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1275 // \# the command number of this command |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1276 // \$ a $ or a # if you are root |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1277 // \nnn character code nnn in octal |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1278 // \\ a backslash |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1279 // \[ begin a sequence of non-printing chars |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1280 // \] end a sequence of non-printing chars |
2926 | 1281 |
3504 | 1282 std::string |
1283 command_editor::do_decode_prompt_string (const std::string& s) | |
2926 | 1284 { |
3504 | 1285 std::string result; |
1286 std::string temp; | |
2926 | 1287 size_t i = 0; |
1288 size_t slen = s.length (); | |
1289 int c; | |
1290 | |
1291 while (i < slen) | |
1292 { | |
1293 c = s[i]; | |
1294 | |
1295 i++; | |
1296 | |
1297 if (c == '\\') | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1298 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1299 c = s[i]; |
2926 | 1300 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1301 switch (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1302 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1303 case '0': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1304 case '1': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1305 case '2': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1306 case '3': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1307 case '4': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1308 case '5': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1309 case '6': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1310 case '7': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1311 // Maybe convert an octal number. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1312 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1313 int n = read_octal (s.substr (i, 3)); |
2926 | 1314 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1315 temp = "\\"; |
2926 | 1316 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1317 if (n != -1) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1318 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1319 i += 3; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1320 temp[0] = n; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1321 } |
2926 | 1322 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1323 c = 0; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1324 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1325 } |
5442 | 1326 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1327 case 'a': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1328 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1329 temp = '\a'; |
5442 | 1330 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1331 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1332 } |
5442 | 1333 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1334 case 'e': |
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 temp = '\033'; |
5442 | 1337 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1338 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1339 } |
5442 | 1340 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1341 case 'r': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1342 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1343 temp = '\r'; |
5442 | 1344 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1345 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1346 } |
5442 | 1347 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1348 case 'd': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1349 case 't': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1350 case 'T': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1351 case '@': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1352 case 'A': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1353 // Make the current time/date into a string. |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1354 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1355 octave_localtime now; |
2926 | 1356 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1357 if (c == 'd') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1358 temp = now.strftime ("%a %b %d"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1359 else if (c == 't') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1360 temp = now.strftime ("%H:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1361 else if (c == 'T') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1362 temp = now.strftime ("%I:%M:%S"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1363 else if (c == '@') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1364 temp = now.strftime ("%I:%M %p"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1365 else if (c == 'A') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1366 temp = now.strftime ("%H:%M"); |
2926 | 1367 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1368 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1369 } |
2926 | 1370 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1371 case 'n': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1372 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1373 temp = newline_chars (); |
2926 | 1374 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1375 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1376 } |
2926 | 1377 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1378 case 's': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1379 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1380 temp = octave_env::get_program_name (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1381 temp = octave_env::base_pathname (temp); |
2926 | 1382 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1383 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1384 } |
5442 | 1385 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1386 case 'w': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1387 case 'W': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1388 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1389 temp = octave_env::get_current_directory (); |
2926 | 1390 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1391 std::string home_dir = octave_env::get_home_directory (); |
5442 | 1392 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1393 if (c == 'W' && (home_dir.empty () || temp != home_dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1394 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1395 if (temp != "/" && temp != "//") |
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 size_t pos = temp.rfind ('/'); |
2926 | 1398 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1399 if (pos != std::string::npos && pos != 0) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1400 temp = temp.substr (pos + 1); |
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 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1403 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1404 temp = octave_env::polite_directory_format (temp); |
2926 | 1405 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1406 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1407 } |
5442 | 1408 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1409 case 'u': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1410 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1411 temp = octave_env::get_user_name (); |
2926 | 1412 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1413 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1414 } |
2926 | 1415 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1416 case 'H': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1417 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1418 temp = octave_env::get_host_name (); |
2926 | 1419 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1420 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1421 } |
2926 | 1422 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1423 case 'h': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1424 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1425 temp = octave_env::get_host_name (); |
2926 | 1426 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1427 size_t pos = temp.find ('.'); |
2926 | 1428 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1429 if (pos != std::string::npos) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1430 temp.resize (pos); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1431 |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1432 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1433 } |
2926 | 1434 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1435 case '#': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1436 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1437 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1438 sprintf (number_buffer, "%d", command_number); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1439 temp = number_buffer; |
2926 | 1440 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1441 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1442 } |
2926 | 1443 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1444 case '!': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1445 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1446 char number_buffer[128]; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1447 int num = command_history::current_number (); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1448 if (num > 0) |
2926 | 1449 sprintf (number_buffer, "%d", num); |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1450 else |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1451 strcpy (number_buffer, "!"); |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1452 temp = number_buffer; |
2926 | 1453 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1454 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1455 } |
2926 | 1456 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1457 case '$': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1458 { |
4062 | 1459 #if defined (HAVE_GETEUID) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1460 temp = (::geteuid () == 0 ? "#" : "$"); |
4062 | 1461 #else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1462 temp = "$"; |
4062 | 1463 #endif |
2926 | 1464 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1465 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1466 } |
2926 | 1467 |
1468 #if defined (USE_READLINE) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1469 case '[': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1470 case ']': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1471 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1472 temp.resize (1); |
2926 | 1473 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1474 temp[0] = ((c == '[') |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1475 ? ::octave_rl_prompt_start_ignore () |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1476 : ::octave_rl_prompt_end_ignore ()); |
2926 | 1477 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1478 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1479 } |
2926 | 1480 #endif |
1481 | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1482 case '\\': |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1483 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1484 temp = "\\"; |
2926 | 1485 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1486 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1487 } |
2926 | 1488 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1489 default: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1490 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1491 temp = "\\ "; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1492 temp[1] = c; |
2926 | 1493 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1494 goto add_string; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1495 } |
2926 | 1496 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1497 add_string: |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1498 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1499 if (c) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1500 i++; |
2926 | 1501 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1502 result.append (temp); |
2926 | 1503 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1504 break; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1505 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1506 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1507 } |
2926 | 1508 else |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10250
diff
changeset
|
1509 result += c; |
2926 | 1510 } |
1511 | |
1512 return result; | |
1513 } | |
1514 | |
1515 // Return the octal number parsed from STRING, or -1 to indicate that | |
1516 // the string contained a bad number. | |
1517 | |
1518 int | |
3504 | 1519 command_editor::read_octal (const std::string& s) |
2926 | 1520 { |
1521 int result = 0; | |
1522 int digits = 0; | |
1523 | |
1524 size_t i = 0; | |
1525 size_t slen = s.length (); | |
1526 | |
1527 while (i < slen && s[i] >= '0' && s[i] < '8') | |
1528 { | |
1529 digits++; | |
1530 result = (result * 8) + s[i] - '0'; | |
1531 i++; | |
1532 } | |
1533 | |
1534 if (! digits || result > 0777 || i < slen) | |
1535 result = -1; | |
1536 | |
1537 return result; | |
1538 } | |
1539 | |
1540 void | |
1541 command_editor::error (int err_num) | |
1542 { | |
10411 | 1543 current_liboctave_error_handler ("%s", gnulib::strerror (err_num)); |
2926 | 1544 } |
1545 | |
1546 void | |
3504 | 1547 command_editor::error (const std::string& s) |
2926 | 1548 { |
2941 | 1549 current_liboctave_error_handler ("%s", s.c_str ()); |
2926 | 1550 } |