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