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