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