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