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