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