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