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