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