Mercurial > hg > octave-lyh
annotate src/input.cc @ 7758:8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 05 May 2008 03:21:52 -0400 |
parents | 40c428ea3408 |
children | 6b521b1e3631 |
rev | line source |
---|---|
1 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
4 2002, 2003, 2004, 2005, 2006, 2007 John W. Eaton | |
1 | 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. | |
1 | 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/>. | |
1 | 21 |
22 */ | |
23 | |
2939 | 24 // Get command input interactively or from files. |
1 | 25 |
240 | 26 #ifdef HAVE_CONFIG_H |
1192 | 27 #include <config.h> |
1 | 28 #endif |
29 | |
1343 | 30 #include <cstdio> |
31 #include <cstdlib> | |
32 #include <cstring> | |
33 #include <cassert> | |
34 | |
3503 | 35 #include <iostream> |
5765 | 36 #include <sstream> |
1728 | 37 #include <string> |
38 | |
1350 | 39 #ifdef HAVE_UNISTD_H |
2442 | 40 #ifdef HAVE_SYS_TYPES_H |
529 | 41 #include <sys/types.h> |
2442 | 42 #endif |
529 | 43 #include <unistd.h> |
44 #endif | |
1343 | 45 |
2927 | 46 #include "cmd-edit.h" |
3189 | 47 #include "file-ops.h" |
4153 | 48 #include "quit.h" |
1755 | 49 #include "str-vec.h" |
50 | |
1352 | 51 #include "defun.h" |
52 #include "dirfns.h" | |
1 | 53 #include "error.h" |
2181 | 54 #include "gripes.h" |
3016 | 55 #include "help.h" |
1 | 56 #include "input.h" |
5832 | 57 #include "load-path.h" |
1352 | 58 #include "oct-map.h" |
1742 | 59 #include "oct-hist.h" |
1670 | 60 #include "toplev.h" |
1755 | 61 #include "oct-obj.h" |
1 | 62 #include "pager.h" |
529 | 63 #include "parse.h" |
1352 | 64 #include "pathlen.h" |
3772 | 65 #include "pt.h" |
1755 | 66 #include "pt-const.h" |
3805 | 67 #include "pt-stmt.h" |
1352 | 68 #include "sighandlers.h" |
1114 | 69 #include "sysdep.h" |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
70 #include "toplev.h" |
3098 | 71 #include "unwind-prot.h" |
1352 | 72 #include "utils.h" |
73 #include "variables.h" | |
529 | 74 |
2181 | 75 // Primary prompt string. |
5794 | 76 static std::string VPS1 = "\\s:\\#> "; |
2181 | 77 |
78 // Secondary prompt string. | |
5794 | 79 static std::string VPS2 = "> "; |
2181 | 80 |
81 // String printed before echoed input (enabled by --echo-input). | |
5794 | 82 std::string VPS4 = "+ "; |
2181 | 83 |
3019 | 84 // Echo commands as they are executed? |
85 // | |
86 // 1 ==> echo commands read from script files | |
87 // 2 ==> echo commands from functions | |
88 // 4 ==> echo commands read from command line | |
89 // | |
90 // more than one state can be active at once. | |
5794 | 91 int Vecho_executing_commands = ECHO_OFF; |
3019 | 92 |
3165 | 93 // The time we last printed a prompt. |
5832 | 94 octave_time Vlast_prompt_time = 0.0; |
3165 | 95 |
2181 | 96 // Character to append after successful command-line completion attempts. |
5794 | 97 static char Vcompletion_append_char = ' '; |
2181 | 98 |
1 | 99 // Global pointer for eval(). |
3523 | 100 std::string current_eval_string; |
1 | 101 |
3019 | 102 // TRUE means get input from current_eval_string. |
103 bool get_input_from_eval_string = false; | |
1 | 104 |
3877 | 105 // TRUE means we haven't been asked for the input from |
106 // current_eval_string yet. | |
107 bool input_from_eval_string_pending = false; | |
108 | |
5189 | 109 // TRUE means that input is coming from a file that was named on |
110 // the command line. | |
111 bool input_from_command_line_file = false; | |
112 | |
3019 | 113 // TRUE means we're parsing a function file. |
114 bool reading_fcn_file = false; | |
1 | 115 |
338 | 116 // Simple name of function file we are reading. |
3523 | 117 std::string curr_fcn_file_name; |
1606 | 118 |
119 // Full name of file we are reading. | |
3523 | 120 std::string curr_fcn_file_full_name; |
1 | 121 |
3019 | 122 // TRUE means we're parsing a script file. |
123 bool reading_script_file = false; | |
1 | 124 |
125 // If we are reading from an M-file, this is it. | |
529 | 126 FILE *ff_instream = 0; |
1 | 127 |
3019 | 128 // TRUE means this is an interactive shell. |
129 bool interactive = false; | |
1 | 130 |
3019 | 131 // TRUE means the user forced this shell to be interactive (-i). |
132 bool forced_interactive = false; | |
1 | 133 |
134 // Should we issue a prompt? | |
135 int promptflag = 1; | |
136 | |
137 // The current line of input, from wherever. | |
3523 | 138 std::string current_input_line; |
1 | 139 |
3804 | 140 // TRUE after a call to completion_matches. |
2299 | 141 bool octave_completion_matches_called = false; |
142 | |
6257 | 143 // TRUE if the plotting system has requested a call to drawnow at |
144 // the next user prompt. | |
7409 | 145 bool Vdrawnow_requested = false; |
6257 | 146 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
147 // TRUE if we are in debugging mode. |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
148 bool Vdebugging = false; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
149 |
7294 | 150 // TRUE if we are running in the Emacs GUD mode. |
151 static bool Vgud_mode = false; | |
152 | |
1044 | 153 static void |
3523 | 154 do_input_echo (const std::string& input_string) |
1044 | 155 { |
1588 | 156 int do_echo = reading_script_file ? |
2205 | 157 (Vecho_executing_commands & ECHO_SCRIPTS) |
2618 | 158 : (Vecho_executing_commands & ECHO_CMD_LINE) && ! forced_interactive; |
1588 | 159 |
160 if (do_echo) | |
1044 | 161 { |
1403 | 162 if (forced_interactive) |
163 { | |
1755 | 164 if (promptflag > 0) |
5794 | 165 octave_stdout << command_editor::decode_prompt_string (VPS1); |
1755 | 166 else |
5794 | 167 octave_stdout << command_editor::decode_prompt_string (VPS2); |
1403 | 168 } |
169 else | |
5794 | 170 octave_stdout << command_editor::decode_prompt_string (VPS4); |
1044 | 171 |
1755 | 172 if (! input_string.empty ()) |
1044 | 173 { |
2095 | 174 octave_stdout << input_string; |
1755 | 175 |
176 if (input_string[input_string.length () - 1] != '\n') | |
2095 | 177 octave_stdout << "\n"; |
1044 | 178 } |
179 } | |
180 } | |
181 | |
3536 | 182 std::string |
3523 | 183 gnu_readline (const std::string& s, bool force_readline) |
1822 | 184 { |
5142 | 185 OCTAVE_QUIT; |
186 | |
3523 | 187 std::string retval; |
1822 | 188 |
2927 | 189 if (line_editing || force_readline) |
1822 | 190 { |
3219 | 191 bool eof; |
1898 | 192 |
3219 | 193 retval = command_editor::readline (s, eof); |
194 | |
195 if (! eof && retval.empty ()) | |
2927 | 196 retval = "\n"; |
1822 | 197 } |
198 else | |
199 { | |
2927 | 200 if (! s.empty () && (interactive || forced_interactive)) |
2618 | 201 { |
2927 | 202 FILE *stream = command_editor::get_output_stream (); |
203 | |
204 fprintf (stream, s.c_str ()); | |
205 fflush (stream); | |
2618 | 206 } |
1822 | 207 |
2927 | 208 FILE *curr_stream = command_editor::get_input_stream (); |
209 | |
1822 | 210 if (reading_fcn_file || reading_script_file) |
211 curr_stream = ff_instream; | |
212 | |
2927 | 213 retval = octave_fgets (curr_stream); |
1822 | 214 } |
215 | |
216 return retval; | |
217 } | |
581 | 218 |
6257 | 219 static inline std::string |
7459
d3fe4d466bc2
don't inhibit drawnow in debug mode
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
220 interactive_input (const std::string& s, bool force_readline = false) |
6257 | 221 { |
222 Vlast_prompt_time.stamp (); | |
223 | |
7459
d3fe4d466bc2
don't inhibit drawnow in debug mode
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
224 if (Vdrawnow_requested && (interactive || forced_interactive)) |
6257 | 225 { |
226 feval ("drawnow"); | |
227 | |
6367 | 228 flush_octave_stdout (); |
229 | |
6305 | 230 // We set Vdrawnow_requested to false even if there is an error |
231 // in drawnow so that the error doesn't reappear at every prompt. | |
232 | |
6257 | 233 Vdrawnow_requested = false; |
6305 | 234 |
235 if (error_state) | |
236 return "\n"; | |
6257 | 237 } |
238 | |
239 return gnu_readline (s, force_readline); | |
240 } | |
241 | |
3536 | 242 static std::string |
1 | 243 octave_gets (void) |
244 { | |
5142 | 245 OCTAVE_QUIT; |
246 | |
3523 | 247 std::string retval; |
1 | 248 |
1822 | 249 if ((interactive || forced_interactive) |
5832 | 250 && (! (reading_fcn_file |
251 || reading_script_file | |
252 || input_from_startup_file | |
253 || input_from_command_line_file))) | |
1 | 254 { |
5794 | 255 std::string ps = (promptflag > 0) ? VPS1 : VPS2; |
1755 | 256 |
3523 | 257 std::string prompt = command_editor::decode_prompt_string (ps); |
1 | 258 |
2618 | 259 pipe_handler_error_count = 0; |
260 | |
261 flush_octave_stdout (); | |
1 | 262 |
2095 | 263 octave_diary << prompt; |
581 | 264 |
6257 | 265 retval = interactive_input (prompt); |
5832 | 266 |
267 // There is no need to update the load_path cache if there is no | |
268 // user input. | |
7336 | 269 if (! retval.empty () && retval.find_first_not_of (" \t\n\r") != NPOS) |
5832 | 270 load_path::update (); |
1 | 271 } |
272 else | |
1822 | 273 retval = gnu_readline (""); |
1 | 274 |
2927 | 275 current_input_line = retval; |
1 | 276 |
1822 | 277 if (! current_input_line.empty ()) |
1 | 278 { |
5189 | 279 if (! (input_from_startup_file || input_from_command_line_file)) |
2927 | 280 command_history::add (current_input_line); |
1 | 281 |
3176 | 282 if (! (reading_fcn_file || reading_script_file)) |
283 { | |
284 octave_diary << current_input_line; | |
285 | |
286 if (current_input_line[current_input_line.length () - 1] != '\n') | |
287 octave_diary << "\n"; | |
288 } | |
581 | 289 |
1822 | 290 do_input_echo (current_input_line); |
1 | 291 } |
3176 | 292 else if (! (reading_fcn_file || reading_script_file)) |
293 octave_diary << "\n"; | |
581 | 294 |
1822 | 295 return retval; |
1 | 296 } |
297 | |
581 | 298 // Read a line from the input stream. |
299 | |
3536 | 300 static std::string |
1822 | 301 get_user_input (void) |
1 | 302 { |
5142 | 303 OCTAVE_QUIT; |
304 | |
3523 | 305 std::string retval; |
1 | 306 |
307 if (get_input_from_eval_string) | |
308 { | |
3877 | 309 if (input_from_eval_string_pending) |
310 { | |
311 input_from_eval_string_pending = false; | |
312 | |
313 retval = current_eval_string; | |
1822 | 314 |
3877 | 315 size_t len = retval.length (); |
1822 | 316 |
6206 | 317 if (len > 0 && retval[len-1] != '\n') |
3877 | 318 retval.append ("\n"); |
319 } | |
1822 | 320 } |
321 else | |
322 retval = octave_gets (); | |
323 | |
2927 | 324 current_input_line = retval; |
1822 | 325 |
2114 | 326 if (! get_input_from_eval_string) |
327 input_line_number++; | |
1822 | 328 |
329 return retval; | |
330 } | |
331 | |
332 int | |
333 octave_read (char *buf, unsigned max_size) | |
334 { | |
5775 | 335 // FIXME -- is this a safe way to buffer the input? |
2927 | 336 |
4046 | 337 static const char * const eol = "\n"; |
3523 | 338 static std::string input_buf; |
2927 | 339 static const char *pos = 0; |
340 static size_t chars_left = 0; | |
1822 | 341 |
342 int status = 0; | |
4046 | 343 if (chars_left == 0) |
1822 | 344 { |
2927 | 345 pos = 0; |
346 | |
347 input_buf = get_user_input (); | |
1822 | 348 |
2927 | 349 chars_left = input_buf.length (); |
350 | |
351 pos = input_buf.c_str (); | |
1822 | 352 } |
353 | |
354 if (chars_left > 0) | |
355 { | |
4046 | 356 size_t len = max_size > chars_left ? chars_left : max_size; |
2927 | 357 assert (len > 0); |
358 | |
4046 | 359 memcpy (buf, pos, len); |
1822 | 360 |
4046 | 361 chars_left -= len; |
362 pos += len; | |
1822 | 363 |
4046 | 364 // Make sure input ends with a new line character. |
365 if (chars_left == 0 && buf[len-1] != '\n') | |
366 { | |
367 if (len < max_size) | |
368 { | |
369 // There is enough room to plug the newline character in | |
370 // the buffer. | |
371 buf[len++] = '\n'; | |
372 } | |
373 else | |
374 { | |
375 // There isn't enough room to plug the newline character | |
376 // in the buffer so make sure it is returned on the next | |
377 // octave_read call. | |
378 pos = eol; | |
379 chars_left = 1; | |
380 } | |
1 | 381 } |
1822 | 382 |
4046 | 383 status = len; |
1 | 384 |
1044 | 385 } |
1822 | 386 else if (chars_left == 0) |
2862 | 387 { |
388 status = 0; | |
389 } | |
1822 | 390 else |
391 status = -1; | |
1044 | 392 |
1 | 393 return status; |
394 } | |
395 | |
581 | 396 // Fix things up so that input can come from file `name', printing a |
397 // warning if the file doesn't exist. | |
398 | |
1 | 399 FILE * |
3523 | 400 get_input_from_file (const std::string& name, int warn) |
1 | 401 { |
529 | 402 FILE *instream = 0; |
1 | 403 |
1750 | 404 if (name.length () > 0) |
7728
13820b9f5fd9
more consistent handling of CR/CRLF/LF line endings in lexer and parser
John W. Eaton <jwe@octave.org>
parents:
7719
diff
changeset
|
405 instream = fopen (name.c_str (), "rb"); |
1 | 406 |
529 | 407 if (! instream && warn) |
1750 | 408 warning ("%s: no such file or directory", name.c_str ()); |
1 | 409 |
338 | 410 if (reading_fcn_file || reading_script_file) |
339 | 411 ff_instream = instream; |
1 | 412 else |
2927 | 413 command_editor::set_input_stream (instream); |
1 | 414 |
415 return instream; | |
416 } | |
417 | |
581 | 418 // Fix things up so that input can come from the standard input. This |
419 // may need to become much more complicated, which is why it's in a | |
420 // separate function. | |
421 | |
1 | 422 FILE * |
423 get_input_from_stdin (void) | |
424 { | |
2927 | 425 command_editor::set_input_stream (stdin); |
426 return command_editor::get_input_stream (); | |
1 | 427 } |
428 | |
5775 | 429 // FIXME -- make this generate file names when appropriate. |
2921 | 430 |
2247 | 431 static string_vector |
3523 | 432 generate_possible_completions (const std::string& text, std::string& prefix, |
433 std::string& hint) | |
1280 | 434 { |
2247 | 435 string_vector names; |
1280 | 436 |
2921 | 437 prefix = ""; |
1280 | 438 |
4604 | 439 if (looks_like_struct (text)) |
1430 | 440 names = generate_struct_completions (text, prefix, hint); |
441 else | |
2247 | 442 names = make_name_list (); |
1280 | 443 |
2944 | 444 // Sort and remove duplicates. |
2348 | 445 |
2944 | 446 names.qsort (true); |
2348 | 447 |
1280 | 448 return names; |
449 } | |
450 | |
3536 | 451 static std::string |
3523 | 452 generate_completion (const std::string& text, int state) |
1280 | 453 { |
3523 | 454 std::string retval; |
2944 | 455 |
3523 | 456 static std::string prefix; |
457 static std::string hint; | |
1280 | 458 |
2921 | 459 static size_t hint_len = 0; |
1280 | 460 |
1 | 461 static int list_index = 0; |
2921 | 462 static int name_list_len = 0; |
4604 | 463 static int name_list_total_len = 0; |
2247 | 464 static string_vector name_list; |
4604 | 465 static string_vector file_name_list; |
1 | 466 |
1280 | 467 static int matches = 0; |
1 | 468 |
469 if (state == 0) | |
470 { | |
471 list_index = 0; | |
472 | |
2921 | 473 prefix = ""; |
1280 | 474 |
2921 | 475 hint = text; |
1280 | 476 |
477 name_list = generate_possible_completions (text, prefix, hint); | |
478 | |
2921 | 479 name_list_len = name_list.length (); |
480 | |
4604 | 481 file_name_list = command_editor::generate_filename_completions (text); |
482 | |
483 name_list.append (file_name_list); | |
484 | |
485 name_list_total_len = name_list.length (); | |
486 | |
2921 | 487 hint_len = hint.length (); |
1280 | 488 |
489 matches = 0; | |
2247 | 490 |
2921 | 491 for (int i = 0; i < name_list_len; i++) |
3565 | 492 if (hint == name_list[i].substr (0, hint_len)) |
2247 | 493 matches++; |
1 | 494 } |
495 | |
4604 | 496 if (name_list_total_len > 0 && matches > 0) |
1 | 497 { |
4604 | 498 while (list_index < name_list_total_len) |
244 | 499 { |
3523 | 500 std::string name = name_list[list_index]; |
2247 | 501 |
1280 | 502 list_index++; |
2247 | 503 |
3565 | 504 if (hint == name.substr (0, hint_len)) |
1280 | 505 { |
4604 | 506 if (list_index <= name_list_len && ! prefix.empty ()) |
2944 | 507 retval = prefix + "." + name; |
508 else | |
509 retval = name; | |
1280 | 510 |
5775 | 511 // FIXME -- looks_like_struct is broken for now, |
4179 | 512 // so it always returns false. |
513 | |
6979 | 514 if (matches == 1 && looks_like_struct (retval)) |
4179 | 515 { |
516 // Don't append anything, since we don't know | |
517 // whether it should be '(' or '.'. | |
518 | |
519 command_editor::set_completion_append_character ('\0'); | |
520 } | |
521 else | |
522 command_editor::set_completion_append_character | |
523 (Vcompletion_append_char); | |
1280 | 524 |
2944 | 525 break; |
1280 | 526 } |
244 | 527 } |
1 | 528 } |
529 | |
2944 | 530 return retval; |
1 | 531 } |
532 | |
6979 | 533 static std::string |
534 quoting_filename (const std::string &text, int, char quote) | |
535 { | |
536 if (quote) | |
537 return text; | |
538 else | |
539 return (std::string ("'") + text); | |
540 } | |
541 | |
2927 | 542 void |
543 initialize_command_input (void) | |
544 { | |
545 // If we are using readline, this allows conditional parsing of the | |
546 // .inputrc file. | |
269 | 547 |
2927 | 548 command_editor::set_name ("Octave"); |
1358 | 549 |
5775 | 550 // FIXME -- this needs to include a comma too, but that |
3933 | 551 // causes trouble for the new struct element completion code. |
552 | |
4272 | 553 static const char *s = "\t\n !\"\'*+-/:;<=>(){}[\\]^`~"; |
3933 | 554 |
555 command_editor::set_basic_word_break_characters (s); | |
556 | |
557 command_editor::set_completer_word_break_characters (s); | |
558 | |
3004 | 559 command_editor::set_basic_quote_characters ("\""); |
2944 | 560 |
6979 | 561 command_editor::set_filename_quote_characters (" \t\n\\\"'@<>=;|&()#$`?*[!:{"); |
562 command_editor::set_completer_quote_characters ("'\""); | |
563 | |
2944 | 564 command_editor::set_completion_function (generate_completion); |
6979 | 565 |
566 command_editor::set_quoting_function (quoting_filename); | |
269 | 567 } |
568 | |
2927 | 569 static bool |
4170 | 570 match_sans_spaces_semi (const std::string& standard, const std::string& test) |
269 | 571 { |
3180 | 572 size_t beg = test.find_first_not_of (" \t"); |
573 | |
574 if (beg != NPOS) | |
575 { | |
4170 | 576 size_t end = test.find_last_not_of ("; \t"); |
269 | 577 |
3180 | 578 size_t len = end == NPOS ? NPOS : end - beg + 1; |
1 | 579 |
3484 | 580 return (test.substr (beg, len) == standard); |
3180 | 581 } |
582 | |
583 return false; | |
529 | 584 } |
585 | |
581 | 586 // If the user simply hits return, this will produce an empty matrix. |
587 | |
2086 | 588 static octave_value_list |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
589 get_user_input (const octave_value_list& args, int nargout) |
529 | 590 { |
3100 | 591 octave_value_list retval; |
529 | 592 |
593 int nargin = args.length (); | |
594 | |
595 int read_as_string = 0; | |
596 | |
712 | 597 if (nargin == 2) |
529 | 598 read_as_string++; |
599 | |
4975 | 600 std::string nm; |
601 int line = -1; | |
602 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
603 if (Vdebugging) |
4975 | 604 { |
7719
87eda1f8faaa
octave_user_code: new base class for octave_user_script and octave_user_function
John W. Eaton <jwe@octave.org>
parents:
7552
diff
changeset
|
605 octave_user_code *caller = octave_call_stack::caller_user_code (); |
5743 | 606 |
607 if (caller) | |
608 { | |
609 nm = caller->fcn_file_name (); | |
4975 | 610 |
5743 | 611 if (nm.empty ()) |
612 nm = caller->name (); | |
4975 | 613 |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7728
diff
changeset
|
614 line = octave_call_stack::current_line (); |
5743 | 615 } |
4975 | 616 } |
617 | |
5765 | 618 std::ostringstream buf; |
4975 | 619 |
620 if (! nm.empty ()) | |
621 { | |
7294 | 622 if (Vgud_mode) |
623 { | |
624 static char ctrl_z = 'Z' & 0x1f; | |
4975 | 625 |
7294 | 626 buf << ctrl_z << ctrl_z << nm << ":" << line; |
627 } | |
628 else | |
629 { | |
630 buf << "stopped in " << nm; | |
631 | |
632 if (line > 0) | |
633 buf << " at line " << line; | |
634 } | |
4975 | 635 } |
636 | |
5765 | 637 std::string msg = buf.str (); |
4975 | 638 |
639 if (! msg.empty ()) | |
7294 | 640 message (Vgud_mode ? 0 : "keyboard", msg.c_str ()); |
4975 | 641 |
642 std::string prompt = "debug> "; | |
1761 | 643 |
712 | 644 if (nargin > 0) |
3707 | 645 { |
646 prompt = args(0).string_value (); | |
636 | 647 |
3707 | 648 if (error_state) |
649 { | |
650 error ("input: unrecognized argument"); | |
651 return retval; | |
652 } | |
529 | 653 } |
654 | |
655 again: | |
656 | |
2095 | 657 flush_octave_stdout (); |
529 | 658 |
4565 | 659 octave_diary << prompt; |
660 | |
7459
d3fe4d466bc2
don't inhibit drawnow in debug mode
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
661 std::string input_buf = interactive_input (prompt.c_str (), true); |
529 | 662 |
7459
d3fe4d466bc2
don't inhibit drawnow in debug mode
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
663 if (! (error_state || input_buf.empty ())) |
529 | 664 { |
1799 | 665 if (! input_from_startup_file) |
2927 | 666 command_history::add (input_buf); |
529 | 667 |
2927 | 668 size_t len = input_buf.length (); |
529 | 669 |
4565 | 670 octave_diary << input_buf; |
671 | |
672 if (input_buf[len - 1] != '\n') | |
673 octave_diary << "\n"; | |
674 | |
529 | 675 if (len < 1) |
676 { | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
677 if (Vdebugging) |
529 | 678 goto again; |
679 else | |
4233 | 680 return read_as_string ? octave_value ("") : octave_value (Matrix ()); |
529 | 681 } |
682 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
683 if (Vdebugging) |
3772 | 684 { |
4170 | 685 if (match_sans_spaces_semi ("exit", input_buf) |
686 || match_sans_spaces_semi ("quit", input_buf) | |
687 || match_sans_spaces_semi ("return", input_buf) | |
5388 | 688 || match_sans_spaces_semi ("dbcont", input_buf)) |
3772 | 689 { |
690 return retval; | |
691 } | |
5388 | 692 else if (match_sans_spaces_semi ("dbstep", input_buf)) |
3772 | 693 { |
694 tree::break_next = true; | |
3805 | 695 |
696 tree::last_line = 0; | |
697 | |
5743 | 698 tree::break_function = octave_call_stack::current (); |
3805 | 699 |
700 return retval; | |
701 } | |
5388 | 702 else if (match_sans_spaces_semi ("dbnext", input_buf)) |
3805 | 703 { |
704 tree::break_next = true; | |
705 | |
7734
2dee19385d32
eliminate tree_statement_stack; handle current statement info in octave_call_stack
John W. Eaton <jwe@octave.org>
parents:
7728
diff
changeset
|
706 tree::last_line = octave_call_stack::current_line (); |
3805 | 707 |
5743 | 708 tree::break_function = octave_call_stack::current (); |
3805 | 709 |
3772 | 710 return retval; |
711 } | |
963 | 712 } |
3772 | 713 |
714 if (read_as_string) | |
963 | 715 { |
5775 | 716 // FIXME -- fix gnu_readline and octave_gets instead! |
3081 | 717 if (input_buf.length () == 1 && input_buf[0] == '\n') |
3100 | 718 retval(0) = ""; |
3081 | 719 else |
3100 | 720 retval(0) = input_buf; |
963 | 721 } |
529 | 722 else |
723 { | |
724 int parse_status = 0; | |
2900 | 725 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
726 bool silent = ! Vdebugging; |
2900 | 727 |
3100 | 728 retval = eval_string (input_buf, silent, parse_status, nargout); |
729 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
730 if (! Vdebugging && retval.length () == 0) |
3100 | 731 retval(0) = Matrix (); |
529 | 732 } |
733 } | |
734 else | |
735 error ("input: reading user-input failed!"); | |
736 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
737 if (Vdebugging) |
3098 | 738 { |
739 // Clear error_state so that if errors were encountered while | |
740 // evaluating user input, extra error messages will not be | |
741 // printed after we return. | |
742 | |
7459
d3fe4d466bc2
don't inhibit drawnow in debug mode
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
743 reset_error_handler (); |
3098 | 744 |
3100 | 745 retval = octave_value_list (); |
3098 | 746 |
747 goto again; | |
748 } | |
529 | 749 |
750 return retval; | |
751 } | |
752 | |
3100 | 753 DEFUN (input, args, nargout, |
3372 | 754 "-*- texinfo -*-\n\ |
755 @deftypefn {Built-in Function} {} input (@var{prompt})\n\ | |
756 @deftypefnx {Built-in Function} {} input (@var{prompt}, \"s\")\n\ | |
757 Print a prompt and wait for user input. For example,\n\ | |
758 \n\ | |
759 @example\n\ | |
760 input (\"Pick a number, any number! \")\n\ | |
761 @end example\n\ | |
762 \n\ | |
763 @noindent\n\ | |
764 prints the prompt\n\ | |
765 \n\ | |
766 @example\n\ | |
767 Pick a number, any number!\n\ | |
768 @end example\n\ | |
529 | 769 \n\ |
3372 | 770 @noindent\n\ |
771 and waits for the user to enter a value. The string entered by the user\n\ | |
772 is evaluated as an expression, so it may be a literal constant, a\n\ | |
773 variable name, or any other valid expression.\n\ | |
774 \n\ | |
775 Currently, @code{input} only returns one value, regardless of the number\n\ | |
776 of values produced by the evaluation of the expression.\n\ | |
777 \n\ | |
778 If you are only interested in getting a literal string value, you can\n\ | |
779 call @code{input} with the character string @code{\"s\"} as the second\n\ | |
780 argument. This tells Octave to return the string entered by the user\n\ | |
781 directly, without evaluating it first.\n\ | |
782 \n\ | |
783 Because there may be output waiting to be displayed by the pager, it is\n\ | |
784 a good idea to always call @code{fflush (stdout)} before calling\n\ | |
785 @code{input}. This will ensure that all pending output is written to\n\ | |
786 the screen before your prompt. @xref{Input and Output}.\n\ | |
787 @end deftypefn") | |
529 | 788 { |
2086 | 789 octave_value_list retval; |
529 | 790 |
791 int nargin = args.length (); | |
792 | |
712 | 793 if (nargin == 1 || nargin == 2) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
794 retval = get_user_input (args, nargout); |
529 | 795 else |
5823 | 796 print_usage (); |
529 | 797 |
798 return retval; | |
799 } | |
800 | |
5640 | 801 bool |
802 octave_yes_or_no (const std::string& prompt) | |
803 { | |
804 std::string prompt_string = prompt + "(yes or no) "; | |
805 | |
806 while (1) | |
807 { | |
7459
d3fe4d466bc2
don't inhibit drawnow in debug mode
John W. Eaton <jwe@octave.org>
parents:
7409
diff
changeset
|
808 std::string input_buf = interactive_input (prompt_string, true); |
5640 | 809 |
810 if (input_buf == "yes") | |
811 return true; | |
812 else if (input_buf == "no") | |
813 return false; | |
814 else | |
815 message (0, "Please answer yes or no."); | |
816 } | |
817 } | |
818 | |
819 DEFUN (yes_or_no, args, , | |
820 "-*- texinfo -*-\n\ | |
821 @deftypefn {Built-in Function} {} yes_or_no (@var{prompt})\n\ | |
822 Ask the user a yes-or-no question. Return 1 if the answer is yes.\n\ | |
823 Takes one argument, which is the string to display to ask the\n\ | |
824 question. It should end in a space; @samp{yes-or-no-p} adds\n\ | |
825 @samp{(yes or no) } to it. The user must confirm the answer with\n\ | |
826 RET and can edit it until it has been confirmed.\n\ | |
827 @end deftypefn") | |
828 { | |
829 octave_value retval; | |
830 | |
831 int nargin = args.length (); | |
832 | |
833 if (nargin == 0 || nargin == 1) | |
834 { | |
835 std::string prompt; | |
836 | |
837 if (nargin == 1) | |
838 { | |
839 prompt = args(0).string_value (); | |
840 | |
841 if (error_state) | |
842 { | |
843 error ("yes_or_no: expecting argument to be character string"); | |
844 return retval; | |
845 } | |
846 } | |
847 | |
848 retval = octave_yes_or_no (prompt); | |
849 } | |
850 else | |
5823 | 851 print_usage (); |
5640 | 852 |
853 return retval; | |
854 } | |
855 | |
3098 | 856 static void |
857 restore_command_history (void *) | |
858 { | |
859 command_history::ignore_entries (! Vsaving_history); | |
860 } | |
861 | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
862 static size_t saved_frame = 0; |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
863 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
864 static void |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
865 restore_frame (void *) |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
866 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
867 octave_call_stack::goto_frame (saved_frame); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
868 } |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
869 |
3707 | 870 octave_value |
871 do_keyboard (const octave_value_list& args) | |
872 { | |
873 octave_value retval; | |
874 | |
875 int nargin = args.length (); | |
876 | |
877 assert (nargin == 0 || nargin == 1); | |
878 | |
879 unwind_protect::begin_frame ("do_keyboard"); | |
880 | |
5775 | 881 // FIXME -- we shouldn't need both the |
3707 | 882 // command_history object and the |
883 // Vsaving_history variable... | |
884 command_history::ignore_entries (false); | |
885 | |
886 unwind_protect::add (restore_command_history, 0); | |
887 | |
888 unwind_protect_bool (Vsaving_history); | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
889 unwind_protect_bool (Vdebugging); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
890 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
891 saved_frame = octave_call_stack::current_frame (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
892 unwind_protect::add (restore_frame); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
893 unwind_protect_size_t (saved_frame); |
3707 | 894 |
895 Vsaving_history = true; | |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
896 Vdebugging = true; |
3707 | 897 |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
898 octave_value_list tmp = get_user_input (args, 0); |
4233 | 899 |
900 retval = tmp(0); | |
3707 | 901 |
902 unwind_protect::run_frame ("do_keyboard"); | |
903 | |
904 return retval; | |
905 } | |
906 | |
1957 | 907 DEFUN (keyboard, args, , |
3372 | 908 "-*- texinfo -*-\n\ |
909 @deftypefn {Built-in Function} {} keyboard (@var{prompt})\n\ | |
910 This function is normally used for simple debugging. When the\n\ | |
911 @code{keyboard} function is executed, Octave prints a prompt and waits\n\ | |
912 for user input. The input strings are then evaluated and the results\n\ | |
913 are printed. This makes it possible to examine the values of variables\n\ | |
914 within a function, and to assign new values to variables. No value is\n\ | |
915 returned from the @code{keyboard} function, and it continues to prompt\n\ | |
916 for input until the user types @samp{quit}, or @samp{exit}.\n\ | |
529 | 917 \n\ |
3372 | 918 If @code{keyboard} is invoked without any arguments, a default prompt of\n\ |
919 @samp{debug> } is used.\n\ | |
920 @end deftypefn") | |
529 | 921 { |
2086 | 922 octave_value_list retval; |
529 | 923 |
924 int nargin = args.length (); | |
925 | |
712 | 926 if (nargin == 0 || nargin == 1) |
7752
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
927 { |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
928 saved_frame = octave_call_stack::current_frame (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
929 unwind_protect::add (restore_frame); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
930 unwind_protect_size_t (saved_frame); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
931 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
932 // Skip the frame assigned to the keyboard function. |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
933 octave_call_stack::goto_frame (1); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
934 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
935 do_keyboard (args); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
936 |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
937 unwind_protect::run (); |
40c428ea3408
initial implementation of dbup and dbdown
John W. Eaton <jwe@octave.org>
parents:
7734
diff
changeset
|
938 } |
529 | 939 else |
5823 | 940 print_usage (); |
529 | 941 |
942 return retval; | |
943 } | |
944 | |
4208 | 945 DEFCMD (echo, args, , |
3332 | 946 "-*- texinfo -*-\n\ |
947 @deffn {Command} echo options\n\ | |
948 Control whether commands are displayed as they are executed. Valid\n\ | |
949 options are:\n\ | |
1588 | 950 \n\ |
3332 | 951 @table @code\n\ |
952 @item on\n\ | |
953 Enable echoing of commands as they are executed in script files.\n\ | |
954 \n\ | |
955 @item off\n\ | |
956 Disable echoing of commands as they are executed in script files.\n\ | |
1588 | 957 \n\ |
3332 | 958 @item on all\n\ |
959 Enable echoing of commands as they are executed in script files and\n\ | |
960 functions.\n\ | |
1588 | 961 \n\ |
3332 | 962 @item off all\n\ |
963 Disable echoing of commands as they are executed in script files and\n\ | |
964 functions.\n\ | |
965 @end table\n\ | |
966 \n\ | |
967 @noindent\n\ | |
968 If invoked without any arguments, @code{echo} toggles the current echo\n\ | |
969 state.\n\ | |
3333 | 970 @end deffn") |
1588 | 971 { |
2086 | 972 octave_value_list retval; |
1588 | 973 |
1755 | 974 int argc = args.length () + 1; |
975 | |
1968 | 976 string_vector argv = args.make_argv ("echo"); |
1755 | 977 |
978 if (error_state) | |
979 return retval; | |
1588 | 980 |
981 switch (argc) | |
982 { | |
983 case 1: | |
984 { | |
2205 | 985 if ((Vecho_executing_commands & ECHO_SCRIPTS) |
986 || (Vecho_executing_commands & ECHO_FUNCTIONS)) | |
5794 | 987 Vecho_executing_commands = ECHO_OFF; |
1588 | 988 else |
5794 | 989 Vecho_executing_commands = ECHO_SCRIPTS; |
1588 | 990 } |
991 break; | |
992 | |
993 case 2: | |
994 { | |
3523 | 995 std::string arg = argv[1]; |
1755 | 996 |
997 if (arg == "on") | |
5794 | 998 Vecho_executing_commands = ECHO_SCRIPTS; |
1755 | 999 else if (arg == "off") |
5794 | 1000 Vecho_executing_commands = ECHO_OFF; |
1588 | 1001 else |
5823 | 1002 print_usage (); |
1588 | 1003 } |
1004 break; | |
1005 | |
1006 case 3: | |
1007 { | |
3523 | 1008 std::string arg = argv[1]; |
1755 | 1009 |
1010 if (arg == "on" && argv[2] == "all") | |
2800 | 1011 { |
1012 int tmp = (ECHO_SCRIPTS | ECHO_FUNCTIONS); | |
5794 | 1013 Vecho_executing_commands = tmp; |
2800 | 1014 } |
1755 | 1015 else if (arg == "off" && argv[2] == "all") |
5794 | 1016 Vecho_executing_commands = ECHO_OFF; |
1588 | 1017 else |
5823 | 1018 print_usage (); |
1588 | 1019 } |
1020 break; | |
1021 | |
1022 default: | |
5823 | 1023 print_usage (); |
1588 | 1024 break; |
1025 } | |
1026 | |
1027 return retval; | |
1028 } | |
1029 | |
2234 | 1030 DEFUN (completion_matches, args, nargout, |
3332 | 1031 "-*- texinfo -*-\n\ |
1032 @deftypefn {Built-in Function} {} completion_matches (@var{hint})\n\ | |
1033 Generate possible completions given @var{hint}.\n\ | |
2299 | 1034 \n\ |
1035 This function is provided for the benefit of programs like Emacs which\n\ | |
3332 | 1036 might be controlling Octave and handling user input. The current\n\ |
1037 command number is not incremented when this function is called. This is\n\ | |
1038 a feature, not a bug.\n\ | |
3333 | 1039 @end deftypefn") |
2234 | 1040 { |
2281 | 1041 octave_value retval; |
2234 | 1042 |
1043 int nargin = args.length (); | |
1044 | |
1045 if (nargin == 1) | |
1046 { | |
3523 | 1047 std::string hint = args(0).string_value (); |
2234 | 1048 |
1049 if (! error_state) | |
1050 { | |
1051 int n = 32; | |
1052 | |
1053 string_vector list (n); | |
1054 | |
1055 int k = 0; | |
1056 | |
1057 for (;;) | |
1058 { | |
3523 | 1059 std::string cmd = generate_completion (hint, k); |
2234 | 1060 |
2944 | 1061 if (! cmd.empty ()) |
2234 | 1062 { |
2944 | 1063 if (k == n) |
2234 | 1064 { |
2944 | 1065 n *= 2; |
1066 list.resize (n); | |
1067 } | |
2235 | 1068 |
2944 | 1069 list[k++] = cmd; |
2234 | 1070 } |
1071 else | |
1072 { | |
1073 list.resize (k); | |
1074 break; | |
1075 } | |
1076 } | |
1077 | |
1078 if (nargout > 0) | |
2281 | 1079 { |
1080 if (! list.empty ()) | |
1081 retval = list; | |
2282 | 1082 else |
1083 retval = ""; | |
2281 | 1084 } |
2234 | 1085 else |
1086 { | |
2235 | 1087 // We don't use string_vector::list_in_columns here |
1088 // because it will be easier for Emacs if the names | |
1089 // appear in a single column. | |
1090 | |
2234 | 1091 int len = list.length (); |
1092 | |
1093 for (int i = 0; i < len; i++) | |
1094 octave_stdout << list[i] << "\n"; | |
1095 } | |
2299 | 1096 |
1097 octave_completion_matches_called = true; | |
2234 | 1098 } |
1099 } | |
1100 else | |
5823 | 1101 print_usage (); |
2234 | 1102 |
1103 return retval; | |
1104 } | |
1105 | |
3189 | 1106 DEFUN (read_readline_init_file, args, , |
3448 | 1107 "-*- texinfo -*-\n\ |
1108 @deftypefn {Built-in Function} {} read_readline_init_file (@var{file})\n\ | |
7007 | 1109 Read the readline library initialization file @var{file}. If\n\ |
3448 | 1110 @var{file} is omitted, read the default initialization file (normally\n\ |
6615 | 1111 @file{~/.inputrc}).\n\ |
1112 \n\ | |
1113 @xref{Readline Init File, , , readline, GNU Readline Library},\n\ | |
1114 for details.\n\ | |
3448 | 1115 @end deftypefn") |
3189 | 1116 { |
1117 octave_value_list retval; | |
1118 | |
1119 int nargin = args.length (); | |
1120 | |
1121 if (nargin == 0) | |
1122 command_editor::read_init_file (); | |
1123 else if (nargin == 1) | |
1124 { | |
5872 | 1125 std::string file = args(0).string_value (); |
3189 | 1126 |
1127 if (! error_state) | |
1128 command_editor::read_init_file (file); | |
1129 } | |
1130 else | |
5823 | 1131 print_usage (); |
3189 | 1132 |
1133 return retval; | |
1134 } | |
1135 | |
7758
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1136 DEFUN (re_read_readline_init_file, args, , |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1137 "-*- texinfo -*-\n\ |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1138 @deftypefn {Built-in Function} {} re_read_readline_init_file ()\n\ |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1139 Re-read the last readline library initialization file that was read.\n\ |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1140 @xref{Readline Init File, , , readline, GNU Readline Library},\n\ |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1141 for details.\n\ |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1142 @end deftypefn") |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1143 { |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1144 octave_value_list retval; |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1145 |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1146 if (args.length () == 0) |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1147 command_editor::re_read_init_file (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1148 else |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1149 print_usage (); |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1150 |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1151 return retval; |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1152 } |
8e14a01ffe9f
input.cc (Fre_read_readline_init_file): new function
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
1153 |
3523 | 1154 static std::string hook_fcn; |
3498 | 1155 static octave_value user_data; |
1156 | |
4802 | 1157 static int |
3519 | 1158 input_event_hook (void) |
3498 | 1159 { |
4526 | 1160 if (is_valid_function (hook_fcn)) |
1161 { | |
1162 if (user_data.is_defined ()) | |
1163 feval (hook_fcn, user_data, 0); | |
1164 else | |
1165 feval (hook_fcn, octave_value_list (), 0); | |
1166 } | |
3498 | 1167 else |
4526 | 1168 { |
1169 hook_fcn = std::string (); | |
1170 user_data = octave_value (); | |
1171 | |
6913 | 1172 command_editor::remove_event_hook (input_event_hook); |
4802 | 1173 } |
1174 | |
1175 return 0; | |
3498 | 1176 } |
1177 | |
1178 DEFUN (input_event_hook, args, , | |
1179 "-*- texinfo -*-\n\ | |
1180 @deftypefn {Built-in Function} {[@var{ofcn}, @var{odata}] =} input_event_hook (@var{fcn}, @var{data})\n\ | |
1181 Given the name of a function as a string and any Octave value object,\n\ | |
1182 install @var{fcn} as a function to call periodically, when Octave is\n\ | |
1183 waiting for input. The function should have the form\n\ | |
1184 @example\n\ | |
1185 @var{fcn} (@var{data})\n\ | |
1186 @end example\n\ | |
1187 \n\ | |
1188 If @var{data} is omitted, Octave calls the function without any\n\ | |
1189 arguments. If both @var{fcn} and @var{data} are omitted, Octave\n\ | |
1190 clears the hook. In all cases, the name of the previous hook function\n\ | |
1191 and the user data are returned.\n\ | |
1192 @end deftypefn") | |
1193 { | |
1194 octave_value_list retval; | |
1195 | |
1196 int nargin = args.length (); | |
1197 | |
1198 if (nargin > 2) | |
5823 | 1199 print_usage (); |
3498 | 1200 else |
1201 { | |
1202 octave_value tmp_user_data; | |
1203 | |
3523 | 1204 std::string tmp_hook_fcn; |
3498 | 1205 |
1206 if (nargin > 1) | |
1207 tmp_user_data = args(1); | |
1208 | |
1209 if (nargin > 0) | |
1210 { | |
1211 tmp_hook_fcn = args(0).string_value (); | |
1212 | |
1213 if (error_state) | |
1214 { | |
1215 error ("input_event_hook: expecting string as first arg"); | |
1216 return retval; | |
1217 } | |
1218 | |
6913 | 1219 command_editor::add_event_hook (input_event_hook); |
3498 | 1220 } |
1221 | |
1222 if (nargin == 0) | |
6913 | 1223 command_editor::remove_event_hook (input_event_hook); |
3498 | 1224 |
1225 retval(1) = user_data; | |
1226 retval(0) = hook_fcn; | |
1227 | |
1228 hook_fcn = tmp_hook_fcn; | |
1229 user_data = tmp_user_data; | |
1230 } | |
1231 | |
1232 return retval; | |
1233 } | |
1234 | |
5794 | 1235 DEFUN (PS1, args, nargout, |
1236 "-*- texinfo -*-\n\ | |
1237 @deftypefn {Built-in Function} {@var{val} =} PS1 ()\n\ | |
1238 @deftypefnx {Built-in Function} {@var{old_val} =} PS1 (@var{new_val})\n\ | |
1239 Query or set the primary prompt string. When executing interactively,\n\ | |
1240 Octave displays the primary prompt when it is ready to read a command.\n\ | |
3332 | 1241 \n\ |
5794 | 1242 The default value of the primary prompt string is @code{\"\\s:\\#> \"}.\n\ |
1243 To change it, use a command like\n\ | |
3332 | 1244 \n\ |
1245 @example\n\ | |
7097 | 1246 octave:13> PS1 (\"\\\\u@@\\\\H> \")\n\ |
3332 | 1247 @end example\n\ |
1248 \n\ | |
1249 @noindent\n\ | |
1250 which will result in the prompt @samp{boris@@kremvax> } for the user\n\ | |
1251 @samp{boris} logged in on the host @samp{kremvax.kgb.su}. Note that two\n\ | |
5794 | 1252 backslashes are required to enter a backslash into a double-quoted\n\ |
1253 character string.\n\ | |
3332 | 1254 @xref{Strings}.\n\ |
6373 | 1255 @seealso{PS2, PS4}\n\ |
5794 | 1256 @end deftypefn") |
1257 { | |
1258 return SET_INTERNAL_VARIABLE (PS1); | |
1259 } | |
2181 | 1260 |
5794 | 1261 DEFUN (PS2, args, nargout, |
1262 "-*- texinfo -*-\n\ | |
1263 @deftypefn {Built-in Function} {@var{val} =} PS2 ()\n\ | |
1264 @deftypefnx {Built-in Function} {@var{old_val} =} PS2 (@var{new_val})\n\ | |
1265 Query or set the secondary prompt string. The secondary prompt is\n\ | |
1266 printed when Octave is expecting additional input to complete a\n\ | |
1267 command. For example, if you are typing a for loop that spans several\n\ | |
1268 lines, Octave will print the secondary prompt at the beginning of\n\ | |
1269 each line after the first. The default value of the secondary prompt\n\ | |
1270 string is @code{\"> \"}.\n\ | |
1271 @seealso{PS1, PS4}\n\ | |
1272 @end deftypefn") | |
1273 { | |
1274 return SET_INTERNAL_VARIABLE (PS2); | |
1275 } | |
2181 | 1276 |
5794 | 1277 DEFUN (PS4, args, nargout, |
1278 "-*- texinfo -*-\n\ | |
1279 @deftypefn {Built-in Function} {@var{val} =} PS4 ()\n\ | |
1280 @deftypefnx {Built-in Function} {@var{old_val} =} PS4 (@var{new_val})\n\ | |
1281 Query or set the character string used to prefix output produced\n\ | |
1282 when echoing commands when @code{echo_executing_commands} is enabled.\n\ | |
6620 | 1283 The default value is @code{\"+ \"}.\n\ |
1284 @xref{Invoking Octave from the Command Line}, for a description of\n\ | |
1285 @code{--echo-commands}.\n\ | |
5794 | 1286 @seealso{echo_executing_commands, PS1, PS2}\n\ |
1287 @end deftypefn") | |
1288 { | |
1289 return SET_INTERNAL_VARIABLE (PS4); | |
1290 } | |
2181 | 1291 |
5794 | 1292 DEFUN (completion_append_char, args, nargout, |
1293 "-*- texinfo -*-\n\ | |
1294 @deftypefn {Built-in Function} {@var{val} =} completion_append_char ()\n\ | |
1295 @deftypefnx {Built-in Function} {@var{old_val} =} completion_append_char (@var{new_val})\n\ | |
1296 Query or set the internal character variable that is appended to\n\ | |
1297 successful command-line completion attempts. The default\n\ | |
3332 | 1298 value is @code{\" \"} (a single space).\n\ |
5794 | 1299 @end deftypefn") |
1300 { | |
1301 return SET_INTERNAL_VARIABLE (completion_append_char); | |
1302 } | |
3019 | 1303 |
5794 | 1304 DEFUN (echo_executing_commands, args, nargout, |
1305 "-*- texinfo -*-\n\ | |
1306 @deftypefn {Built-in Function} {@var{val} =} echo_executing_commands ()\n\ | |
1307 @deftypefnx {Built-in Function} {@var{old_val} =} echo_executing_commands (@var{new_val})\n\ | |
1308 Query or set the internal variable that controls the echo state.\n\ | |
1309 It may be the sum of the following values:\n\ | |
3332 | 1310 \n\ |
1311 @table @asis\n\ | |
1312 @item 1\n\ | |
1313 Echo commands read from script files.\n\ | |
1314 \n\ | |
1315 @item 2\n\ | |
1316 Echo commands from functions.\n\ | |
1317 \n\ | |
1318 @item 4\n\ | |
1319 Echo commands read from command line.\n\ | |
1320 @end table\n\ | |
1321 \n\ | |
1322 More than one state can be active at once. For example, a value of 3 is\n\ | |
1323 equivalent to the command @kbd{echo on all}.\n\ | |
1324 \n\ | |
1325 The value of @code{echo_executing_commands} is set by the @kbd{echo}\n\ | |
1326 command and the command line option @code{--echo-input}.\n\ | |
5794 | 1327 @end deftypefn") |
1328 { | |
1329 return SET_INTERNAL_VARIABLE (echo_executing_commands); | |
2181 | 1330 } |
1331 | |
6257 | 1332 DEFUN (__request_drawnow__, args, , |
1333 "-*- texinfo -*-\n\ | |
1334 @deftypefn {Built-in Function} {} __request_drawnow__ ()\n\ | |
1335 @deftypefnx {Built-in Function} {} __request_drawnow__ (@var{flag})\n\ | |
6945 | 1336 Undocumented internal function.\n\ |
6257 | 1337 @end deftypefn") |
1338 { | |
1339 octave_value retval; | |
1340 | |
1341 int nargin = args.length (); | |
1342 | |
1343 if (nargin == 0) | |
1344 Vdrawnow_requested = true; | |
1345 else if (nargin == 1) | |
1346 Vdrawnow_requested = args(0).bool_value (); | |
1347 else | |
1348 print_usage (); | |
1349 | |
1350 return retval; | |
1351 } | |
1352 | |
7294 | 1353 DEFUN (__gud_mode__, args, , |
1354 "-*- texinfo -*-\n\ | |
1355 @deftypefn {Built-in Function} {} __gud_mode__ ()\n\ | |
1356 Undocumented internal function.\n\ | |
1357 @end deftypefn") | |
1358 { | |
1359 octave_value retval; | |
1360 | |
1361 int nargin = args.length (); | |
1362 | |
1363 if (nargin == 0) | |
1364 retval = Vgud_mode; | |
1365 else if (nargin == 1) | |
1366 Vgud_mode = args(0).bool_value (); | |
1367 else | |
1368 print_usage (); | |
1369 | |
1370 return retval; | |
1371 } | |
1372 | |
1 | 1373 /* |
1374 ;;; Local Variables: *** | |
1375 ;;; mode: C++ *** | |
1376 ;;; End: *** | |
1377 */ |